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 (defcustom gnus-article-menu-hook nil
474 "*Hook run after the creation of the article mode menu."
476 :group 'gnus-article-various)
478 (defcustom gnus-article-prepare-hook nil
479 "*A hook called after an article has been prepared in the article buffer."
481 :group 'gnus-article-various)
483 (defcustom gnus-article-hide-pgp-hook nil
484 "*A hook called after successfully hiding a PGP signature."
486 :group 'gnus-article-various)
488 (defcustom gnus-article-button-face 'bold
489 "Face used for highlighting buttons in the article buffer.
491 An article button is a piece of text that you can activate by pressing
492 `RET' or `mouse-2' above it."
494 :group 'gnus-article-buttons)
496 (defcustom gnus-article-mouse-face 'highlight
497 "Face used for mouse highlighting in the article buffer.
499 Article buttons will be displayed in this face when the cursor is
502 :group 'gnus-article-buttons)
504 (defcustom gnus-signature-face 'gnus-signature-face
505 "Face used for highlighting a signature in the article buffer.
506 Obsolete; use the face `gnus-signature-face' for customizations instead."
508 :group 'gnus-article-highlight
509 :group 'gnus-article-signature)
511 (defface gnus-signature-face
514 "Face used for highlighting a signature in the article buffer."
515 :group 'gnus-article-highlight
516 :group 'gnus-article-signature)
518 (defface gnus-header-from-face
521 (:foreground "spring green"))
524 (:foreground "red3"))
527 "Face used for displaying from headers."
528 :group 'gnus-article-headers
529 :group 'gnus-article-highlight)
531 (defface gnus-header-subject-face
534 (:foreground "SeaGreen3"))
537 (:foreground "red4"))
539 (:bold t :italic t)))
540 "Face used for displaying subject headers."
541 :group 'gnus-article-headers
542 :group 'gnus-article-highlight)
544 (defface gnus-header-newsgroups-face
547 (:foreground "yellow" :italic t))
550 (:foreground "MidnightBlue" :italic t))
553 "Face used for displaying newsgroups headers."
554 :group 'gnus-article-headers
555 :group 'gnus-article-highlight)
557 (defface gnus-header-name-face
560 (:foreground "SeaGreen"))
563 (:foreground "maroon"))
566 "Face used for displaying header names."
567 :group 'gnus-article-headers
568 :group 'gnus-article-highlight)
570 (defface gnus-header-content-face
573 (:foreground "forest green" :italic t))
576 (:foreground "indianred4" :italic t))
578 (:italic t))) "Face used for displaying header content."
579 :group 'gnus-article-headers
580 :group 'gnus-article-highlight)
582 (defcustom gnus-header-face-alist
583 '(("From" nil gnus-header-from-face)
584 ("Subject" nil gnus-header-subject-face)
585 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
586 ("" gnus-header-name-face gnus-header-content-face))
587 "*Controls highlighting of article header.
589 An alist of the form (HEADER NAME CONTENT).
591 HEADER is a regular expression which should match the name of an
592 header header and NAME and CONTENT are either face names or nil.
594 The name of each header field will be displayed using the face
595 specified by the first element in the list where HEADER match the
596 header name and NAME is non-nil. Similarly, the content will be
597 displayed by the first non-nil matching CONTENT face."
598 :group 'gnus-article-headers
599 :group 'gnus-article-highlight
600 :type '(repeat (list (regexp :tag "Header")
602 (item :tag "skip" nil)
603 (face :value default))
604 (choice :tag "Content"
605 (item :tag "skip" nil)
606 (face :value default)))))
608 (defcustom gnus-article-decode-hook
609 '(article-decode-charset article-decode-encoded-words)
610 "*Hook run to decode charsets in articles."
611 :group 'gnus-article-headers
614 (defcustom gnus-display-mime-function 'gnus-display-mime
615 "Function to display MIME articles."
616 :group 'gnus-article-mime
619 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
620 "Function used to decode headers.")
622 (defvar gnus-article-dumbquotes-map
641 "Table for MS-to-Latin1 translation.")
643 (defcustom gnus-ignored-mime-types nil
644 "List of MIME types that should be ignored by Gnus."
646 :group 'gnus-article-mime
647 :type '(repeat regexp))
649 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
650 "List of MIME types that should not be given buttons when rendered inline."
652 :group 'gnus-article-mime
653 :type '(repeat regexp))
655 (defcustom gnus-article-mime-part-function nil
656 "Function called with a MIME handle as the argument.
657 This is meant for people who want to do something automatic based
658 on parts -- for instance, adding Vcard info to a database."
659 :group 'gnus-article-mime
662 (defcustom gnus-mime-multipart-functions nil
663 "An alist of MIME types to functions to display them."
665 :group 'gnus-article-mime
668 (defcustom gnus-article-date-lapsed-new-header nil
669 "Whether the X-Sent and Date headers can coexist.
670 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
671 either replace the old \"Date:\" header (if this variable is nil), or
672 be added below it (otherwise)."
674 :group 'gnus-article-headers
677 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
678 "Function called with a MIME handle as the argument.
679 This is meant for people who want to view first matched part.
680 For `undisplayed-alternative' (default), the first undisplayed
681 part or alternative part is used. For `undisplayed', the first
682 undisplayed part is used. For a function, the first part which
683 the function return `t' is used. For `nil', the first part is
686 :group 'gnus-article-mime
688 (item :tag "first" :value nil)
689 (item :tag "undisplayed" :value undisplayed)
690 (item :tag "undisplayed or alternative"
691 :value undisplayed-alternative)
694 (defcustom gnus-mime-action-alist
695 '(("save to file" . gnus-mime-save-part)
696 ("save and strip" . gnus-mime-save-part-and-strip)
697 ("display as text" . gnus-mime-inline-part)
698 ("view the part" . gnus-mime-view-part)
699 ("pipe to command" . gnus-mime-pipe-part)
700 ("toggle display" . gnus-article-press-button)
701 ("toggle display" . gnus-article-view-part-as-charset)
702 ("view as type" . gnus-mime-view-part-as-type)
703 ("internalize type" . gnus-mime-internalize-part)
704 ("externalize type" . gnus-mime-externalize-part))
705 "An alist of actions that run on the MIME attachment."
706 :group 'gnus-article-mime
707 :type '(repeat (cons (string :tag "name")
710 (defcustom gnus-mime-action-alist
711 '(("save to file" . gnus-mime-save-part)
712 ("display as text" . gnus-mime-inline-part)
713 ("view the part" . gnus-mime-view-part)
714 ("pipe to command" . gnus-mime-pipe-part)
715 ("toggle display" . gnus-article-press-button)
716 ("view as type" . gnus-mime-view-part-as-type)
717 ("internalize type" . gnus-mime-internalize-part)
718 ("externalize type" . gnus-mime-externalize-part))
719 "An alist of actions that run on the MIME attachment."
721 :group 'gnus-article-mime
722 :type '(repeat (cons (string :tag "name")
726 ;;; The treatment variables
729 (defvar gnus-part-display-hook nil
730 "Hook called on parts that are to receive treatment.")
732 (defvar gnus-article-treat-custom
733 '(choice (const :tag "Off" nil)
735 (const :tag "Header" head)
736 (const :tag "Last" last)
737 (integer :tag "Less")
738 (repeat :tag "Groups" regexp)
739 (sexp :tag "Predicate")))
741 (defvar gnus-article-treat-head-custom
742 '(choice (const :tag "Off" nil)
743 (const :tag "Header" head)))
745 (defvar gnus-article-treat-types '("text/plain")
748 (defvar gnus-inhibit-treatment nil
749 "Whether to inhibit treatment.")
751 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
752 "Highlight the signature.
753 Valid values are nil, t, `head', `last', an integer or a predicate.
754 See the manual for details."
755 :group 'gnus-article-treat
756 :type gnus-article-treat-custom)
757 (put 'gnus-treat-highlight-signature 'highlight t)
759 (defcustom gnus-treat-buttonize 100000
761 Valid values are nil, t, `head', `last', an integer or a predicate.
762 See the manual for details."
763 :group 'gnus-article-treat
764 :type gnus-article-treat-custom)
765 (put 'gnus-treat-buttonize 'highlight t)
767 (defcustom gnus-treat-buttonize-head 'head
768 "Add buttons to the head.
769 Valid values are nil, t, `head', `last', an integer or a predicate.
770 See the manual for details."
771 :group 'gnus-article-treat
772 :type gnus-article-treat-head-custom)
773 (put 'gnus-treat-buttonize-head 'highlight t)
775 (defcustom gnus-treat-emphasize
776 (and (or window-system
778 (>= (string-to-number emacs-version) 21))
781 Valid values are nil, t, `head', `last', an integer or a predicate.
782 See the manual for details."
783 :group 'gnus-article-treat
784 :type gnus-article-treat-custom)
785 (put 'gnus-treat-emphasize 'highlight t)
787 (defcustom gnus-treat-strip-cr nil
788 "Remove carriage returns.
789 Valid values are nil, t, `head', `last', an integer or a predicate.
790 See the manual for details."
791 :group 'gnus-article-treat
792 :type gnus-article-treat-custom)
794 (defcustom gnus-treat-hide-headers 'head
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-head-custom)
801 (defcustom gnus-treat-hide-boring-headers nil
802 "Hide boring headers.
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-signature nil
810 Valid values are nil, t, `head', `last', an integer or a predicate.
811 See the manual for details."
812 :group 'gnus-article-treat
813 :type gnus-article-treat-custom)
815 (defcustom gnus-treat-fill-article 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-hide-citation 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-maybe 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-strip-list-identifiers 'head
844 "Strip list identifiers from `gnus-list-identifiers`.
845 Valid values are nil, t, `head', `last', an integer or a predicate.
846 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-custom)
851 (defcustom gnus-treat-strip-pgp t
852 "Strip PGP signatures.
853 Valid values are nil, t, `head', `last', an integer or a predicate.
854 See the manual for details."
855 :group 'gnus-article-treat
856 :type gnus-article-treat-custom)
858 (defcustom gnus-treat-strip-pem nil
859 "Strip PEM 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-banner t
866 "Strip banners from articles.
867 The banner to be stripped is specified in the `banner' group parameter.
868 Valid values are nil, t, `head', `last', an integer or a predicate.
869 See the manual for details."
870 :group 'gnus-article-treat
871 :type gnus-article-treat-custom)
873 (defcustom gnus-treat-highlight-headers 'head
874 "Highlight the headers.
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-head-custom)
879 (put 'gnus-treat-highlight-headers 'highlight t)
881 (defcustom gnus-treat-highlight-citation t
882 "Highlight cited text.
883 Valid values are nil, t, `head', `last', an integer or a predicate.
884 See the manual for details."
885 :group 'gnus-article-treat
886 :type gnus-article-treat-custom)
887 (put 'gnus-treat-highlight-citation 'highlight t)
889 (defcustom gnus-treat-date-ut nil
890 "Display the Date in UT (GMT).
891 Valid values are nil, t, `head', `last', an integer or a predicate.
892 See the manual for details."
893 :group 'gnus-article-treat
894 :type gnus-article-treat-head-custom)
896 (defcustom gnus-treat-date-local nil
897 "Display the Date in the local timezone.
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-english nil
904 "Display the Date in a format that can be read aloud in English.
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-lapsed nil
911 "Display the Date header in a way that says how much time has elapsed.
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-original nil
918 "Display the date in the original timezone.
919 Valid values are nil, t, `head', `last', an integer or a predicate.
920 See the manual for details."
921 :group 'gnus-article-treat
922 :type gnus-article-treat-head-custom)
924 (defcustom gnus-treat-date-iso8601 nil
925 "Display the date in the ISO8601 format.
926 Valid values are nil, t, `head', `last', an integer or a predicate.
927 See the manual for details."
929 :group 'gnus-article-treat
930 :type gnus-article-treat-head-custom)
932 (defcustom gnus-treat-date-user-defined nil
933 "Display the date in a user-defined format.
934 The format is defined by the `gnus-article-time-format' variable.
935 Valid values are nil, t, `head', `last', an integer or a predicate.
936 See the manual for details."
937 :group 'gnus-article-treat
938 :type gnus-article-treat-head-custom)
940 (defcustom gnus-treat-strip-headers-in-body t
941 "Strip the X-No-Archive header line from the beginning of the body.
942 Valid values are nil, t, `head', `last', an integer or a predicate.
943 See the manual for details."
945 :group 'gnus-article-treat
946 :type gnus-article-treat-custom)
948 (defcustom gnus-treat-strip-trailing-blank-lines nil
949 "Strip trailing blank lines.
950 Valid values are nil, t, `head', `last', an integer or a predicate.
951 See the manual for details."
952 :group 'gnus-article-treat
953 :type gnus-article-treat-custom)
955 (defcustom gnus-treat-strip-leading-blank-lines nil
956 "Strip leading 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-multiple-blank-lines nil
963 "Strip multiple 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-overstrike t
970 "Treat overstrike highlighting.
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)
975 (put 'gnus-treat-overstrike 'highlight t)
977 (defcustom gnus-treat-display-xface
978 (and (or (and (fboundp 'image-type-available-p)
979 (image-type-available-p 'xbm)
980 (string-match "^0x" (shell-command-to-string "uncompface")))
981 (and (featurep 'xemacs) (featurep 'xface)))
983 "Display X-Face headers.
984 Valid values are nil, t, `head', `last', an integer or a predicate.
985 See the manual for details."
986 :group 'gnus-article-treat
987 :type gnus-article-treat-head-custom)
988 (put 'gnus-treat-display-xface 'highlight t)
990 (defcustom gnus-treat-display-smileys
991 (if (or (and (featurep 'xemacs)
993 (and (fboundp 'image-type-available-p)
994 (image-type-available-p 'pbm)))
997 Valid values are nil, t, `head', `last', an integer or a predicate.
998 See the manual for details."
999 :group 'gnus-article-treat
1000 :type gnus-article-treat-custom)
1001 (put 'gnus-treat-display-smileys 'highlight t)
1003 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1005 Valid values are nil, t, `head', `last', an integer or a predicate.
1006 See the manual for details."
1007 :group 'gnus-article-treat
1008 :type gnus-article-treat-head-custom)
1009 (put 'gnus-treat-display-picons 'highlight t)
1011 (defcustom gnus-treat-capitalize-sentences nil
1012 "Capitalize sentence-starting words.
1013 Valid values are nil, t, `head', `last', an integer or a predicate.
1014 See the manual for details."
1016 :group 'gnus-article-treat
1017 :type gnus-article-treat-custom)
1019 (defcustom gnus-treat-fill-long-lines nil
1021 Valid values are nil, t, `head', `last', an integer or a predicate.
1022 See the manual for details."
1023 :group 'gnus-article-treat
1024 :type gnus-article-treat-custom)
1026 (defcustom gnus-treat-play-sounds nil
1028 Valid values are nil, t, `head', `last', an integer or a predicate.
1029 See the manual for details."
1031 :group 'gnus-article-treat
1032 :type gnus-article-treat-custom)
1034 (defcustom gnus-treat-translate nil
1035 "Translate articles from one language to another.
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See the manual for details."
1039 :group 'gnus-article-treat
1040 :type gnus-article-treat-custom)
1042 (defcustom gnus-treat-x-pgp-sig nil
1044 To automatically treat X-PGP-Sig, set it to head.
1045 Valid values are nil, t, `head', `last', an integer or a predicate.
1046 See the manual for details."
1047 :group 'gnus-article-treat
1048 :group 'mime-security
1049 :type gnus-article-treat-custom)
1051 (defvar gnus-article-encrypt-protocol-alist
1052 '(("PGP" . mml2015-self-encrypt)))
1054 ;; Set to nil if more than one protocol added to
1055 ;; gnus-article-encrypt-protocol-alist.
1056 (defcustom gnus-article-encrypt-protocol "PGP"
1057 "The protocol used for encrypt articles.
1058 It is a string, such as \"PGP\". If nil, ask user."
1060 :group 'mime-security)
1062 ;;; Internal variables
1064 (defvar gnus-english-month-names
1065 '("January" "February" "March" "April" "May" "June" "July" "August"
1066 "September" "October" "November" "December"))
1068 (defvar article-goto-body-goes-to-point-min-p nil)
1069 (defvar gnus-article-wash-types nil)
1070 (defvar gnus-article-emphasis-alist nil)
1072 (defvar gnus-article-mime-handle-alist-1 nil)
1073 (defvar gnus-treatment-function-alist
1074 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1075 (gnus-treat-strip-banner gnus-article-strip-banner)
1076 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1077 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1078 (gnus-treat-buttonize gnus-article-add-buttons)
1079 (gnus-treat-fill-article gnus-article-fill-cited-article)
1080 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1081 (gnus-treat-strip-cr gnus-article-remove-cr)
1082 (gnus-treat-emphasize gnus-article-emphasize)
1083 (gnus-treat-display-xface gnus-article-display-x-face)
1084 (gnus-treat-date-ut gnus-article-date-ut)
1085 (gnus-treat-date-local gnus-article-date-local)
1086 (gnus-treat-date-english gnus-article-date-english)
1087 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1088 (gnus-treat-date-original gnus-article-date-original)
1089 (gnus-treat-date-user-defined gnus-article-date-user)
1090 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1091 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1092 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1093 (gnus-treat-hide-signature gnus-article-hide-signature)
1094 (gnus-treat-hide-citation gnus-article-hide-citation)
1095 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1096 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1097 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1098 (gnus-treat-strip-pem gnus-article-hide-pem)
1099 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1100 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1101 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1102 (gnus-treat-strip-trailing-blank-lines
1103 gnus-article-remove-trailing-blank-lines)
1104 (gnus-treat-strip-leading-blank-lines
1105 gnus-article-strip-leading-blank-lines)
1106 (gnus-treat-strip-multiple-blank-lines
1107 gnus-article-strip-multiple-blank-lines)
1108 (gnus-treat-overstrike gnus-article-treat-overstrike)
1109 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1110 (gnus-treat-display-smileys gnus-smiley-display)
1111 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1112 (gnus-treat-display-picons gnus-article-display-picons)
1113 (gnus-treat-play-sounds gnus-earcon-display)))
1115 (defvar gnus-article-mime-handle-alist nil)
1116 (defvar article-lapsed-timer nil)
1117 (defvar gnus-article-current-summary nil)
1119 (defvar gnus-article-mode-syntax-table
1120 (let ((table (copy-syntax-table text-mode-syntax-table)))
1121 ;; This causes the citation match run O(2^n).
1122 ;; (modify-syntax-entry ?- "w" table)
1123 (modify-syntax-entry ?> ")" table)
1124 (modify-syntax-entry ?< "(" table)
1126 "Syntax table used in article mode buffers.
1127 Initialized from `text-mode-syntax-table.")
1129 (defvar gnus-save-article-buffer nil)
1131 (defvar gnus-article-mode-line-format-alist
1132 (nconc '((?w (gnus-article-wash-status) ?s)
1133 (?m (gnus-article-mime-part-status) ?s))
1134 gnus-summary-mode-line-format-alist))
1136 (defvar gnus-number-of-articles-to-be-saved nil)
1138 (defvar gnus-inhibit-hiding nil)
1140 (defsubst gnus-article-hide-text (b e props)
1141 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1142 (gnus-add-text-properties-when 'article-type nil b e props)
1143 (when (memq 'intangible props)
1145 (max (1- b) (point-min))
1146 b 'intangible (cddr (memq 'intangible props)))))
1148 (defsubst gnus-article-unhide-text (b e)
1149 "Remove hidden text properties from region between B and E."
1150 (remove-text-properties b e gnus-hidden-properties)
1151 (when (memq 'intangible gnus-hidden-properties)
1152 (put-text-property (max (1- b) (point-min))
1153 b 'intangible nil)))
1155 (defun gnus-article-hide-text-type (b e type)
1156 "Hide text of TYPE between B and E."
1157 (push type gnus-article-wash-types)
1158 (gnus-article-hide-text
1159 b e (cons 'article-type (cons type gnus-hidden-properties))))
1161 (defun gnus-article-unhide-text-type (b e type)
1162 "Unhide text of TYPE between B and E."
1163 (setq gnus-article-wash-types
1164 (delq type gnus-article-wash-types))
1165 (remove-text-properties
1166 b e (cons 'article-type (cons type gnus-hidden-properties)))
1167 (when (memq 'intangible gnus-hidden-properties)
1168 (put-text-property (max (1- b) (point-min))
1169 b 'intangible nil)))
1171 (defun gnus-article-hide-text-of-type (type)
1172 "Hide text of TYPE in the current buffer."
1174 (let ((b (point-min))
1176 (while (setq b (text-property-any b e 'article-type type))
1177 (add-text-properties b (incf b) gnus-hidden-properties)))))
1179 (defun gnus-article-delete-text-of-type (type)
1180 "Delete text of TYPE in the current buffer."
1182 (let ((b (point-min)))
1183 (while (setq b (text-property-any b (point-max) 'article-type type))
1185 b (or (text-property-not-all b (point-max) 'article-type type)
1188 (defun gnus-article-delete-invisible-text ()
1189 "Delete all invisible text in the current buffer."
1191 (let ((b (point-min)))
1192 (while (setq b (text-property-any b (point-max) 'invisible t))
1194 b (or (text-property-not-all b (point-max) 'invisible t)
1197 (defun gnus-article-text-type-exists-p (type)
1198 "Say whether any text of type TYPE exists in the buffer."
1199 (text-property-any (point-min) (point-max) 'article-type type))
1201 (defsubst gnus-article-header-rank ()
1202 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1203 (let ((list gnus-sorted-header-list)
1206 (when (looking-at (car list))
1208 (setq list (cdr list))
1212 (defun article-hide-headers (&optional arg delete)
1213 "Hide unwanted headers and possibly sort them as well."
1215 ;; This function might be inhibited.
1216 (unless gnus-inhibit-hiding
1219 (let ((buffer-read-only nil)
1220 (case-fold-search t)
1221 (max (1+ (length gnus-sorted-header-list)))
1222 (ignored (when (not gnus-visible-headers)
1223 (cond ((stringp gnus-ignored-headers)
1224 gnus-ignored-headers)
1225 ((listp gnus-ignored-headers)
1226 (mapconcat 'identity gnus-ignored-headers
1229 (cond ((stringp gnus-visible-headers)
1230 gnus-visible-headers)
1231 ((and gnus-visible-headers
1232 (listp gnus-visible-headers))
1233 (mapconcat 'identity gnus-visible-headers "\\|"))))
1234 (inhibit-point-motion-hooks t)
1236 ;; First we narrow to just the headers.
1237 (article-narrow-to-head)
1238 ;; Hide any "From " lines at the beginning of (mail) articles.
1239 (while (looking-at "From ")
1242 (delete-region (point-min) (point)))
1243 ;; Then treat the rest of the header lines.
1244 ;; Then we use the two regular expressions
1245 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1246 ;; select which header lines is to remain visible in the
1248 (while (re-search-forward "^[^ \t]*:" nil t)
1250 ;; Mark the rank of the header.
1252 (point) (1+ (point)) 'message-rank
1253 (if (or (and visible (looking-at visible))
1255 (not (looking-at ignored))))
1256 (gnus-article-header-rank)
1259 (message-sort-headers-1)
1260 (when (setq beg (text-property-any
1261 (point-min) (point-max) 'message-rank (+ 2 max)))
1262 ;; We delete the unwanted headers.
1263 (push 'headers gnus-article-wash-types)
1264 (add-text-properties (point-min) (+ 5 (point-min))
1265 '(article-type headers dummy-invisible t))
1266 (delete-region beg (point-max))))))))
1268 (defun article-hide-boring-headers (&optional arg)
1269 "Toggle hiding of headers that aren't very interesting.
1270 If given a negative prefix, always show; if given a positive prefix,
1272 (interactive (gnus-article-hidden-arg))
1273 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1274 (not gnus-show-all-headers))
1277 (let ((buffer-read-only nil)
1278 (list gnus-boring-article-headers)
1279 (inhibit-point-motion-hooks t)
1281 (article-narrow-to-head)
1283 (setq elem (pop list))
1284 (goto-char (point-min))
1286 ;; Hide empty headers.
1288 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1290 (gnus-article-hide-text-type
1291 (progn (beginning-of-line) (point))
1294 (if (re-search-forward "^[^ \t]" nil t)
1298 ;; Hide boring Newsgroups header.
1299 ((eq elem 'newsgroups)
1300 (when (equal (gnus-fetch-field "newsgroups")
1301 (gnus-group-real-name
1302 (if (boundp 'gnus-newsgroup-name)
1305 (gnus-article-hide-header "newsgroups")))
1306 ((eq elem 'followup-to)
1307 (when (equal (message-fetch-field "followup-to")
1308 (message-fetch-field "newsgroups"))
1309 (gnus-article-hide-header "followup-to")))
1310 ((eq elem 'reply-to)
1311 (let ((from (message-fetch-field "from"))
1312 (reply-to (message-fetch-field "reply-to")))
1317 (nth 1 (mail-extract-address-components from))
1318 (nth 1 (mail-extract-address-components reply-to)))))
1319 (gnus-article-hide-header "reply-to"))))
1321 (let ((date (message-fetch-field "date")))
1323 (< (days-between (current-time-string) date)
1325 (gnus-article-hide-header "date"))))
1327 (let ((to (message-fetch-field "to"))
1328 (cc (message-fetch-field "cc")))
1329 (when (> (length to) 1024)
1330 (gnus-article-hide-header "to"))
1331 (when (> (length cc) 1024)
1332 (gnus-article-hide-header "cc"))))
1336 (goto-char (point-min))
1337 (while (re-search-forward "^to:" nil t)
1338 (setq to-count (1+ to-count)))
1339 (when (> to-count 1)
1340 (while (> to-count 0)
1341 (goto-char (point-min))
1343 (re-search-forward "^to:" nil nil to-count)
1345 (narrow-to-region (point) (point-max))
1346 (gnus-article-hide-header "to"))
1347 (setq to-count (1- to-count))))
1348 (goto-char (point-min))
1349 (while (re-search-forward "^cc:" nil t)
1350 (setq cc-count (1+ cc-count)))
1351 (when (> cc-count 1)
1352 (while (> cc-count 0)
1353 (goto-char (point-min))
1355 (re-search-forward "^cc:" nil nil cc-count)
1357 (narrow-to-region (point) (point-max))
1358 (gnus-article-hide-header "cc"))
1359 (setq cc-count (1- cc-count)))))))))))))
1361 (defun gnus-article-hide-header (header)
1363 (goto-char (point-min))
1364 (when (re-search-forward (concat "^" header ":") nil t)
1365 (gnus-article-hide-text-type
1366 (progn (beginning-of-line) (point))
1369 (if (re-search-forward "^[^ \t]" nil t)
1374 (defvar gnus-article-normalized-header-length 40
1375 "Length of normalized headers.")
1377 (defun article-normalize-headers ()
1378 "Make all header lines 40 characters long."
1380 (let ((buffer-read-only nil)
1384 (article-narrow-to-head)
1387 ((< (setq column (- (gnus-point-at-eol) (point)))
1388 gnus-article-normalized-header-length)
1390 (insert (make-string
1391 (- gnus-article-normalized-header-length column)
1393 ((> column gnus-article-normalized-header-length)
1394 (gnus-put-text-property
1396 (forward-char gnus-article-normalized-header-length)
1403 (forward-line 1))))))
1405 (defun article-treat-dumbquotes ()
1406 "Translate M****s*** sm*rtq**t*s into proper text.
1407 Note that this function guesses whether a character is a sm*rtq**t* or
1408 not, so it should only be used interactively.
1410 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1411 in an attempt to provide more quoting characters. If you see
1412 something like \\222 or \\264 where you're expecting some kind of
1413 apostrophe or quotation mark, then try this wash."
1415 (article-translate-strings gnus-article-dumbquotes-map))
1417 (defun article-translate-characters (from to)
1418 "Translate all characters in the body of the article according to FROM and TO.
1419 FROM is a string of characters to translate from; to is a string of
1420 characters to translate to."
1422 (when (article-goto-body)
1423 (let ((buffer-read-only nil)
1424 (x (make-string 225 ?x))
1426 (while (< (incf i) (length x))
1429 (while (< i (length from))
1430 (aset x (aref from i) (aref to i))
1432 (translate-region (point) (point-max) x)))))
1434 (defun article-translate-strings (map)
1435 "Translate all string in the body of the article according to MAP.
1436 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1438 (when (article-goto-body)
1439 (let ((buffer-read-only nil)
1441 (while (setq elem (pop map))
1443 (while (search-forward (car elem) nil t)
1444 (replace-match (cadr elem)))))))))
1446 (defun article-treat-overstrike ()
1447 "Translate overstrikes into bold text."
1450 (when (article-goto-body)
1451 (let ((buffer-read-only nil))
1452 (while (search-forward "\b" nil t)
1453 (let ((next (char-after))
1454 (previous (char-after (- (point) 2))))
1455 ;; We do the boldification/underlining by hiding the
1456 ;; overstrikes and putting the proper text property
1460 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1461 (put-text-property (point) (1+ (point)) 'face 'bold))
1463 (gnus-article-hide-text-type
1464 (1- (point)) (1+ (point)) 'overstrike)
1466 (- (point) 2) (1- (point)) 'face 'underline))
1468 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1470 (point) (1+ (point)) 'face 'underline)))))))))
1472 (defun article-fill-long-lines ()
1473 "Fill lines that are wider than the window width."
1476 (let ((buffer-read-only nil)
1477 (width (window-width (get-buffer-window (current-buffer)))))
1480 (let ((adaptive-fill-mode nil))
1483 (when (>= (current-column) (min fill-column width))
1484 (narrow-to-region (point) (gnus-point-at-bol))
1485 (fill-paragraph nil)
1486 (goto-char (point-max))
1488 (forward-line 1)))))))
1490 (defun article-capitalize-sentences ()
1491 "Capitalize the first word in each sentence."
1494 (let ((buffer-read-only nil)
1495 (paragraph-start "^[\n\^L]"))
1499 (forward-sentence)))))
1501 (defun article-remove-cr ()
1502 "Remove trailing CRs and then translate remaining CRs into LFs."
1505 (let ((buffer-read-only nil))
1506 (goto-char (point-min))
1507 (while (re-search-forward "\r+$" nil t)
1508 (replace-match "" t t))
1509 (goto-char (point-min))
1510 (while (search-forward "\r" nil t)
1511 (replace-match "\n" t t)))))
1513 (defun article-remove-trailing-blank-lines ()
1514 "Remove all trailing blank lines from the article."
1517 (let ((buffer-read-only nil))
1518 (goto-char (point-max))
1522 (while (and (not (bobp))
1523 (looking-at "^[ \t]*$")
1524 (not (gnus-annotation-in-region-p
1525 (point) (gnus-point-at-eol))))
1530 (defun article-display-x-face (&optional force)
1531 "Look for an X-Face header and display it if present."
1532 (interactive (list 'force))
1534 ;; Delete the old process, if any.
1535 (when (process-status "article-x-face")
1536 (delete-process "article-x-face"))
1537 (let ((inhibit-point-motion-hooks t)
1538 (case-fold-search t)
1541 (article-narrow-to-head)
1542 (goto-char (point-min))
1543 (setq from (message-fetch-field "from"))
1544 (goto-char (point-min))
1545 (while (and gnus-article-x-face-command
1548 ;; Check whether this face is censored.
1549 (not gnus-article-x-face-too-ugly)
1550 (and gnus-article-x-face-too-ugly from
1551 (not (string-match gnus-article-x-face-too-ugly
1553 ;; Has to be present.
1554 (re-search-forward "^X-Face: " nil t))
1555 ;; This used to try to do multiple faces (`while' instead of
1556 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1557 ;; work (b) it can crash some versions of Emacs (c) are
1558 ;; multiple faces really something to encourage?
1559 (when (stringp gnus-article-x-face-command)
1561 ;; We now have the area of the buffer where the X-Face is stored.
1564 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1565 ;; We display the face.
1566 (if (symbolp gnus-article-x-face-command)
1567 ;; The command is a lisp function, so we call it.
1568 (if (gnus-functionp gnus-article-x-face-command)
1569 (funcall gnus-article-x-face-command beg end)
1570 (error "%s is not a function" gnus-article-x-face-command))
1571 ;; The command is a string, so we interpret the command
1572 ;; as a, well, command, and fork it off.
1573 (let ((process-connection-type nil))
1574 (process-kill-without-query
1576 "article-x-face" nil shell-file-name shell-command-switch
1577 gnus-article-x-face-command))
1578 (process-send-region "article-x-face" beg end)
1579 (process-send-eof "article-x-face"))))))))))
1581 (defun article-decode-mime-words ()
1582 "Decode all MIME-encoded words in the article."
1585 (set-buffer gnus-article-buffer)
1586 (let ((inhibit-point-motion-hooks t)
1588 (mail-parse-charset gnus-newsgroup-charset)
1589 (mail-parse-ignored-charsets
1590 (save-excursion (set-buffer gnus-summary-buffer)
1591 gnus-newsgroup-ignored-charsets)))
1592 (mail-decode-encoded-word-region (point-min) (point-max)))))
1594 (defun article-decode-charset (&optional prompt)
1595 "Decode charset-encoded text in the article.
1596 If PROMPT (the prefix), prompt for a coding system to use."
1598 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1600 (mail-parse-charset gnus-newsgroup-charset)
1601 (mail-parse-ignored-charsets
1602 (save-excursion (condition-case nil
1603 (set-buffer gnus-summary-buffer)
1605 gnus-newsgroup-ignored-charsets))
1606 ct cte ctl charset format)
1609 (article-narrow-to-head)
1610 (setq ct (message-fetch-field "Content-Type" t)
1611 cte (message-fetch-field "Content-Transfer-Encoding" t)
1612 ctl (and ct (ignore-errors
1613 (mail-header-parse-content-type ct)))
1616 (mm-read-coding-system "Charset to decode: "))
1618 (mail-content-type-get ctl 'charset)))
1619 format (and ctl (mail-content-type-get ctl 'format)))
1621 (setq cte (mail-header-strip cte)))
1622 (if (and ctl (not (string-match "/" (car ctl))))
1624 (goto-char (point-max)))
1627 (narrow-to-region (point) (point-max))
1628 (when (and (eq mail-parse-charset 'gnus-decoded)
1629 (eq (mm-body-7-or-8) '8bit))
1630 ;; The text code could have been decoded.
1631 (setq charset mail-parse-charset))
1632 (when (and (or (not ctl)
1633 (equal (car ctl) "text/plain"))
1634 (not format)) ;; article with format will decode later.
1636 charset (and cte (intern (downcase
1637 (gnus-strip-whitespace cte))))
1640 (defun article-decode-encoded-words ()
1641 "Remove encoded-word encoding from headers."
1642 (let ((inhibit-point-motion-hooks t)
1643 (mail-parse-charset gnus-newsgroup-charset)
1644 (mail-parse-ignored-charsets
1645 (save-excursion (condition-case nil
1646 (set-buffer gnus-summary-buffer)
1648 gnus-newsgroup-ignored-charsets))
1651 (article-narrow-to-head)
1652 (funcall gnus-decode-header-function (point-min) (point-max)))))
1654 (defun article-de-quoted-unreadable (&optional force)
1655 "Translate a quoted-printable-encoded article.
1656 If FORCE, decode the article whether it is marked as quoted-printable
1658 (interactive (list 'force))
1660 (let ((buffer-read-only nil) type charset)
1661 (if (gnus-buffer-live-p gnus-original-article-buffer)
1662 (with-current-buffer gnus-original-article-buffer
1664 (gnus-fetch-field "content-transfer-encoding"))
1665 (let* ((ct (gnus-fetch-field "content-type"))
1668 (mail-header-parse-content-type ct)))))
1669 (setq charset (and ctl
1670 (mail-content-type-get ctl 'charset)))
1671 (if (stringp charset)
1672 (setq charset (intern (downcase charset)))))))
1674 (setq charset gnus-newsgroup-charset))
1676 (and type (let ((case-fold-search t))
1677 (string-match "quoted-printable" type))))
1679 (quoted-printable-decode-region
1680 (point) (point-max) (mm-charset-to-coding-system charset))))))
1682 (defun article-de-base64-unreadable (&optional force)
1683 "Translate a base64 article.
1684 If FORCE, decode the article whether it is marked as base64 not."
1685 (interactive (list 'force))
1687 (let ((buffer-read-only nil) type charset)
1688 (if (gnus-buffer-live-p gnus-original-article-buffer)
1689 (with-current-buffer gnus-original-article-buffer
1691 (gnus-fetch-field "content-transfer-encoding"))
1692 (let* ((ct (gnus-fetch-field "content-type"))
1695 (mail-header-parse-content-type ct)))))
1696 (setq charset (and ctl
1697 (mail-content-type-get ctl 'charset)))
1698 (if (stringp charset)
1699 (setq charset (intern (downcase charset)))))))
1701 (setq charset gnus-newsgroup-charset))
1703 (and type (let ((case-fold-search t))
1704 (string-match "base64" type))))
1707 (narrow-to-region (point) (point-max))
1708 (base64-decode-region (point-min) (point-max))
1709 (mm-decode-coding-region
1710 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1715 (defun article-decode-HZ ()
1716 "Translate a HZ-encoded article."
1720 (let ((buffer-read-only nil))
1721 (rfc1843-decode-region (point-min) (point-max)))))
1723 (defun article-wash-html ()
1724 "Format an html article."
1727 (let ((buffer-read-only nil)
1729 (if (gnus-buffer-live-p gnus-original-article-buffer)
1730 (with-current-buffer gnus-original-article-buffer
1731 (let* ((ct (gnus-fetch-field "content-type"))
1734 (mail-header-parse-content-type ct)))))
1735 (setq charset (and ctl
1736 (mail-content-type-get ctl 'charset)))
1737 (if (stringp charset)
1738 (setq charset (intern (downcase charset)))))))
1740 (setq charset gnus-newsgroup-charset))
1742 (save-window-excursion
1744 (narrow-to-region (point) (point-max))
1746 (let ((w3-strict-width (window-width))
1747 (url-standalone-mode t))
1749 (w3-region (point-min) (point-max))
1752 (defun article-hide-list-identifiers ()
1753 "Remove list identifies from the Subject header.
1754 The `gnus-list-identifiers' variable specifies what to do."
1758 (let ((inhibit-point-motion-hooks t)
1760 (article-narrow-to-head)
1761 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1762 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1764 (goto-char (point-min))
1765 (when (re-search-forward
1766 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1767 " *\\)\\)+\\(Re: +\\)?\\)")
1769 (let ((s (or (match-string 3) (match-string 5))))
1770 (delete-region (match-beginning 1) (match-end 1))
1772 (goto-char (match-beginning 1))
1775 (defun article-hide-pgp ()
1776 "Remove any PGP headers and signatures in the current article."
1780 (let ((inhibit-point-motion-hooks t)
1781 buffer-read-only beg end)
1783 ;; Hide the "header".
1784 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1785 (push 'pgp gnus-article-wash-types)
1786 (delete-region (match-beginning 0) (match-end 0))
1787 ;; Remove armor headers (rfc2440 6.2)
1788 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1791 ;; Hide the actual signature.
1792 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1793 (setq end (1+ (match-beginning 0)))
1796 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1798 ;; Perhaps we shouldn't hide to the end of the buffer
1799 ;; if there is no end to the signature?
1801 ;; Hide "- " PGP quotation markers.
1803 (narrow-to-region beg end)
1804 (goto-char (point-min))
1805 (while (re-search-forward "^- " nil t)
1807 (match-beginning 0) (match-end 0)))
1809 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1811 (defun article-hide-pem (&optional arg)
1812 "Toggle hiding of any PEM headers and signatures in the current article.
1813 If given a negative prefix, always show; if given a positive prefix,
1815 (interactive (gnus-article-hidden-arg))
1816 (unless (gnus-article-check-hidden-text 'pem arg)
1818 (let (buffer-read-only end)
1819 (goto-char (point-min))
1820 ;; Hide the horrendously ugly "header".
1821 (when (and (search-forward
1822 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1824 (setq end (1+ (match-beginning 0))))
1825 (push 'pem gnus-article-wash-types)
1826 (gnus-article-hide-text-type
1828 (if (search-forward "\n\n" nil t)
1832 ;; Hide the trailer as well
1833 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1835 (gnus-article-hide-text-type
1836 (match-beginning 0) (match-end 0) 'pem)))))))
1838 (defun article-strip-banner ()
1839 "Strip the banner specified by the `banner' group parameter."
1843 (let ((inhibit-point-motion-hooks t)
1844 (banner (gnus-parameter-banner gnus-newsgroup-name))
1845 (gnus-signature-limit nil)
1846 buffer-read-only beg end)
1850 ((eq banner 'signature)
1851 (when (gnus-article-narrow-to-signature)
1854 (delete-region (point) (point-max))))
1856 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1857 (while (re-search-forward banner nil t)
1858 (delete-region (match-beginning 0) (match-end 0)))))
1860 (while (re-search-forward banner nil t)
1861 (delete-region (match-beginning 0) (match-end 0))))))))))
1863 (defun article-babel ()
1864 "Translate article using an online translation service."
1868 (set-buffer gnus-article-buffer)
1869 (when (article-goto-body)
1870 (let* ((buffer-read-only nil)
1873 (orig (buffer-substring start end))
1874 (trans (babel-as-string orig)))
1876 (narrow-to-region start end)
1877 (delete-region start end)
1880 (defun article-hide-signature (&optional arg)
1881 "Hide the signature in the current article.
1882 If given a negative prefix, always show; if given a positive prefix,
1884 (interactive (gnus-article-hidden-arg))
1885 (unless (gnus-article-check-hidden-text 'signature arg)
1888 (let ((buffer-read-only nil))
1889 (when (gnus-article-narrow-to-signature)
1890 (gnus-article-hide-text-type
1891 (point-min) (point-max) 'signature)))))))
1893 (defun article-strip-headers-in-body ()
1894 "Strip offensive headers from bodies."
1898 (let ((case-fold-search t))
1899 (when (looking-at "x-no-archive:")
1900 (gnus-delete-line)))))
1902 (defun article-strip-leading-blank-lines ()
1903 "Remove all blank lines from the beginning of the article."
1906 (let ((inhibit-point-motion-hooks t)
1908 (when (article-goto-body)
1909 (while (and (not (eobp))
1910 (looking-at "[ \t]*$"))
1911 (gnus-delete-line))))))
1913 (defun article-narrow-to-head ()
1914 "Narrow the buffer to the head of the message.
1915 Point is left at the beginning of the narrowed-to region."
1917 (goto-char (point-min))
1918 (if (search-forward "\n\n" nil 1)
1921 (goto-char (point-min)))
1923 (defun article-goto-body ()
1924 "Place point at the start of the body."
1925 (goto-char (point-min))
1927 ;; This variable is only bound when dealing with separate
1929 (article-goto-body-goes-to-point-min-p
1931 ((search-forward "\n\n" nil t)
1934 (goto-char (point-max))
1937 (defun article-strip-multiple-blank-lines ()
1938 "Replace consecutive blank lines with one empty line."
1941 (let ((inhibit-point-motion-hooks t)
1943 ;; First make all blank lines empty.
1945 (while (re-search-forward "^[ \t]+$" nil t)
1946 (unless (gnus-annotation-in-region-p
1947 (match-beginning 0) (match-end 0))
1948 (replace-match "" nil t)))
1949 ;; Then replace multiple empty lines with a single empty line.
1951 (while (re-search-forward "\n\n\n+" nil t)
1952 (unless (gnus-annotation-in-region-p
1953 (match-beginning 0) (match-end 0))
1954 (replace-match "\n\n" t t))))))
1956 (defun article-strip-leading-space ()
1957 "Remove all white space from the beginning of the lines in the article."
1960 (let ((inhibit-point-motion-hooks t)
1963 (while (re-search-forward "^[ \t]+" nil t)
1964 (replace-match "" t t)))))
1966 (defun article-strip-trailing-space ()
1967 "Remove all white space from the end of the lines in the article."
1970 (let ((inhibit-point-motion-hooks t)
1973 (while (re-search-forward "[ \t]+$" nil t)
1974 (replace-match "" t t)))))
1976 (defun article-strip-blank-lines ()
1977 "Strip leading, trailing and multiple blank lines."
1979 (article-strip-leading-blank-lines)
1980 (article-remove-trailing-blank-lines)
1981 (article-strip-multiple-blank-lines))
1983 (defun article-strip-all-blank-lines ()
1984 "Strip all blank lines."
1987 (let ((inhibit-point-motion-hooks t)
1990 (while (re-search-forward "^[ \t]*\n" nil t)
1991 (replace-match "" t t)))))
1993 (defun gnus-article-narrow-to-signature ()
1994 "Narrow to the signature; return t if a signature is found, else nil."
1995 (let ((inhibit-point-motion-hooks t))
1996 (when (gnus-article-search-signature)
1998 ;; Check whether we have some limits to what we consider
1999 ;; to be a signature.
2000 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2001 (list gnus-signature-limit)))
2003 (while (setq limit (pop limits))
2004 (if (or (and (integerp limit)
2005 (< (- (point-max) (point)) limit))
2007 (< (count-lines (point) (point-max)) limit))
2008 (and (gnus-functionp limit)
2010 (and (stringp limit)
2011 (not (re-search-forward limit nil t))))
2012 () ; This limit did not succeed.
2016 (narrow-to-region (point) (point-max))
2019 (defun gnus-article-search-signature ()
2020 "Search the current buffer for the signature separator.
2021 Put point at the beginning of the signature separator."
2022 (let ((cur (point)))
2023 (goto-char (point-max))
2024 (if (if (stringp gnus-signature-separator)
2025 (re-search-backward gnus-signature-separator nil t)
2026 (let ((seps gnus-signature-separator))
2028 (not (re-search-backward (car seps) nil t)))
2035 (defun gnus-article-hidden-arg ()
2036 "Return the current prefix arg as a number, or 0 if no prefix."
2037 (list (if current-prefix-arg
2038 (prefix-numeric-value current-prefix-arg)
2041 (defun gnus-article-check-hidden-text (type arg)
2042 "Return nil if hiding is necessary.
2043 Arg can be nil or a number. Nil and positive means hide, negative
2044 means show, 0 means toggle."
2047 (let ((hide (gnus-article-hidden-text-p type)))
2053 (gnus-article-show-hidden-text type)
2056 (if (eq hide 'hidden)
2058 (gnus-article-show-hidden-text type)
2062 (defun gnus-article-hidden-text-p (type)
2063 "Say whether the current buffer contains hidden text of type TYPE."
2064 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2066 (not (get-text-property pos 'invisible))
2067 (not (get-text-property pos 'dummy-invisible)))
2069 (text-property-any (1+ pos) (point-max) 'article-type type)))
2074 (defun gnus-article-show-hidden-text (type &optional dummy)
2075 "Show all hidden text of type TYPE.
2076 Originally it is hide instead of DUMMY."
2077 (let ((buffer-read-only nil)
2078 (inhibit-point-motion-hooks t))
2079 (gnus-remove-text-properties-when
2081 (point-min) (point-max)
2082 (cons 'article-type (cons type
2083 gnus-hidden-properties)))))
2085 (defconst article-time-units
2086 `((year . ,(* 365.25 24 60 60))
2087 (week . ,(* 7 24 60 60))
2088 (day . ,(* 24 60 60))
2092 "Mapping from time units to seconds.")
2094 (defun article-date-ut (&optional type highlight header)
2095 "Convert DATE date to universal time in the current article.
2096 If TYPE is `local', convert to local time; if it is `lapsed', output
2097 how much time has lapsed since DATE. For `lapsed', the value of
2098 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2099 should replace the \"Date:\" one, or should be added below it."
2100 (interactive (list 'ut t))
2101 (let* ((header (or header
2102 (message-fetch-field "date")
2104 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2107 ((not gnus-article-date-lapsed-new-header)
2113 (date (if (vectorp header) (mail-header-date header)
2115 (inhibit-point-motion-hooks t)
2120 (article-narrow-to-head)
2121 (when (re-search-forward tdate-regexp nil t)
2122 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2123 date (or (get-text-property (gnus-point-at-bol)
2126 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2128 (when (and date (not (string= date "")))
2129 (goto-char (point-min))
2130 (let ((buffer-read-only nil))
2131 ;; Delete any old Date headers.
2132 (while (re-search-forward date-regexp nil t)
2134 (delete-region (progn (beginning-of-line) (point))
2135 (progn (forward-line 1) (point)))
2136 (delete-region (progn (beginning-of-line) (point))
2137 (progn (end-of-line) (point)))
2138 (setq pos (point))))
2139 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2141 (if pos (goto-char pos))
2142 (insert (article-make-date-line date (or type 'ut)))
2148 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2149 (put-text-property (match-beginning 1) (1+ (match-end 1))
2150 'original-date date)
2151 (put-text-property (match-beginning 1) (1+ (match-end 1))
2153 (put-text-property (match-beginning 2) (match-end 2)
2156 (defun article-make-date-line (date type)
2157 "Return a DATE line of TYPE."
2158 (let ((time (condition-case ()
2162 ;; Convert to the local timezone. We have to slap a
2163 ;; `condition-case' round the calls to the timezone
2164 ;; functions since they aren't particularly resistant to
2167 (let ((tz (car (current-time-zone time))))
2168 (format "Date: %s %s%02d%02d" (current-time-string time)
2169 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2170 (/ (% (abs tz) 3600) 60))))
2171 ;; Convert to Universal Time.
2174 (current-time-string
2175 (let* ((e (parse-time-string date))
2176 (tm (apply 'encode-time e))
2178 (ls (- (cadr tm) (car (current-time-zone time)))))
2179 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2180 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2183 ;; Get the original date from the article.
2184 ((eq type 'original)
2185 (concat "Date: " (if (string-match "\n+$" date)
2186 (substring date 0 (match-beginning 0))
2188 ;; Let the user define the format.
2190 (if (gnus-functionp gnus-article-time-format)
2191 (funcall gnus-article-time-format time)
2194 (format-time-string gnus-article-time-format time))))
2197 (let ((tz (car (current-time-zone time))))
2200 (format-time-string "%Y%m%dT%H%M%S" time)
2201 (format "%s%02d%02d"
2202 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2203 (/ (% (abs tz) 3600) 60)))))
2204 ;; Do an X-Sent lapsed format.
2206 ;; If the date is seriously mangled, the timezone functions are
2207 ;; liable to bug out, so we ignore all errors.
2208 (let* ((now (current-time))
2209 (real-time (subtract-time now time))
2210 (real-sec (and real-time
2211 (+ (* (float (car real-time)) 65536)
2213 (sec (and real-time (abs real-sec)))
2223 ;; This is a bit convoluted, but basically we go
2224 ;; through the time units for years, weeks, etc,
2225 ;; and divide things to see whether that results
2226 ;; in positive answers.
2229 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2230 ;; The (remaining) seconds are too few to
2231 ;; be divided into this time unit.
2233 ;; It's big enough, so we output it.
2234 (setq sec (- sec (* num (cdr unit))))
2236 (concat (if prev ", " "") (int-to-string
2238 " " (symbol-name (car unit))
2239 (if (> num 1) "s" ""))
2241 article-time-units "")
2242 ;; If dates are odd, then it might appear like the
2243 ;; article was sent in the future.
2246 " in the future"))))))
2247 ;; Display the date in proper English
2249 (let ((dtime (decode-time time)))
2252 (number-to-string (nth 3 dtime))
2253 (let ((digit (% (nth 3 dtime) 10)))
2260 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2262 (number-to-string (nth 5 dtime))
2264 (format "%02d" (nth 2 dtime))
2266 (format "%02d" (nth 1 dtime)))))
2268 (error "Unknown conversion type: %s" type)))))
2270 (defun article-date-local (&optional highlight)
2271 "Convert the current article date to the local timezone."
2272 (interactive (list t))
2273 (article-date-ut 'local highlight))
2275 (defun article-date-english (&optional highlight)
2276 "Convert the current article date to something that is proper English."
2277 (interactive (list t))
2278 (article-date-ut 'english highlight))
2280 (defun article-date-original (&optional highlight)
2281 "Convert the current article date to what it was originally.
2282 This is only useful if you have used some other date conversion
2283 function and want to see what the date was before converting."
2284 (interactive (list t))
2285 (article-date-ut 'original highlight))
2287 (defun article-date-lapsed (&optional highlight)
2288 "Convert the current article date to time lapsed since it was sent."
2289 (interactive (list t))
2290 (article-date-ut 'lapsed highlight))
2292 (defun article-update-date-lapsed ()
2293 "Function to be run from a timer to update the lapsed time line."
2294 (let (deactivate-mark)
2299 (set-buffer (window-buffer w))
2300 (when (eq major-mode 'gnus-article-mode)
2301 (goto-char (point-min))
2302 (when (re-search-forward "^X-Sent:" nil t)
2303 (article-date-lapsed t))))
2306 (defun gnus-start-date-timer (&optional n)
2307 "Start a timer to update the X-Sent header in the article buffers.
2308 The numerical prefix says how frequently (in seconds) the function
2313 (gnus-stop-date-timer)
2314 (setq article-lapsed-timer
2315 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2317 (defun gnus-stop-date-timer ()
2318 "Stop the X-Sent timer."
2320 (when article-lapsed-timer
2321 (nnheader-cancel-timer article-lapsed-timer)
2322 (setq article-lapsed-timer nil)))
2324 (defun article-date-user (&optional highlight)
2325 "Convert the current article date to the user-defined format.
2326 This format is defined by the `gnus-article-time-format' variable."
2327 (interactive (list t))
2328 (article-date-ut 'user highlight))
2330 (defun article-date-iso8601 (&optional highlight)
2331 "Convert the current article date to ISO8601."
2332 (interactive (list t))
2333 (article-date-ut 'iso8601 highlight))
2335 (defun article-show-all ()
2336 "Show all hidden text in the article buffer."
2339 (let ((buffer-read-only nil))
2340 (gnus-article-unhide-text (point-min) (point-max)))))
2342 (defun article-emphasize (&optional arg)
2343 "Emphasize text according to `gnus-emphasis-alist'."
2344 (interactive (gnus-article-hidden-arg))
2345 (unless (gnus-article-check-hidden-text 'emphasis arg)
2349 (with-current-buffer gnus-summary-buffer
2350 gnus-article-emphasis-alist)
2352 gnus-emphasis-alist))
2353 (buffer-read-only nil)
2354 (props (append '(article-type emphasis)
2355 gnus-hidden-properties))
2356 regexp elem beg invisible visible face)
2359 (while (setq elem (pop alist))
2361 (setq regexp (car elem)
2362 invisible (nth 1 elem)
2363 visible (nth 2 elem)
2365 (while (re-search-forward regexp nil t)
2366 (when (and (match-beginning visible) (match-beginning invisible))
2367 (push 'emphasis gnus-article-wash-types)
2368 (gnus-article-hide-text
2369 (match-beginning invisible) (match-end invisible) props)
2370 (gnus-article-unhide-text-type
2371 (match-beginning visible) (match-end visible) 'emphasis)
2372 (gnus-put-text-property-excluding-newlines
2373 (match-beginning visible) (match-end visible) 'face face)
2374 (goto-char (match-end invisible)))))))))
2376 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2377 "Setup newsgroup emphasis alist."
2378 (unless gnus-article-emphasis-alist
2379 (let ((name (and gnus-newsgroup-name
2380 (gnus-group-real-name gnus-newsgroup-name))))
2381 (make-local-variable 'gnus-article-emphasis-alist)
2382 (setq gnus-article-emphasis-alist
2384 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2385 (while (setq elem (pop alist))
2386 (when (and name (string-match (car elem) name))
2388 highlight (copy-sequence (cdr elem)))))
2390 (copy-sequence highlight-words)
2391 (if gnus-newsgroup-name
2392 (copy-sequence (gnus-group-find-parameter
2393 gnus-newsgroup-name 'highlight-words t)))
2394 gnus-emphasis-alist)))))
2396 (defvar gnus-summary-article-menu)
2397 (defvar gnus-summary-post-menu)
2399 ;;; Saving functions.
2401 (defun gnus-article-save (save-buffer file &optional num)
2402 "Save the currently selected article."
2403 (unless gnus-save-all-headers
2404 ;; Remove headers according to `gnus-saved-headers'.
2405 (let ((gnus-visible-headers
2406 (or gnus-saved-headers gnus-visible-headers))
2407 (gnus-article-buffer save-buffer))
2409 (set-buffer save-buffer)
2410 (article-hide-headers 1 t))))
2411 (save-window-excursion
2412 (if (not gnus-default-article-saver)
2413 (error "No default saver is defined")
2414 ;; !!! Magic! The saving functions all save
2415 ;; `gnus-save-article-buffer' (or so they think), but we
2416 ;; bind that variable to our save-buffer.
2417 (set-buffer gnus-article-buffer)
2418 (let* ((gnus-save-article-buffer save-buffer)
2421 ((not gnus-prompt-before-saving) 'default)
2422 ((eq gnus-prompt-before-saving 'always) nil)
2424 (gnus-number-of-articles-to-be-saved
2425 (when (eq gnus-prompt-before-saving t)
2427 (set-buffer gnus-article-current-summary)
2428 (funcall gnus-default-article-saver filename)))))
2430 (defun gnus-read-save-file-name (prompt &optional filename
2431 function group headers variable)
2433 (funcall function group headers (symbol-value variable)))
2438 ((eq filename 'default)
2444 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2447 (if (and gnus-number-of-articles-to-be-saved
2448 (> gnus-number-of-articles-to-be-saved 1))
2449 (format "these %d articles"
2450 gnus-number-of-articles-to-be-saved)
2453 ;; Let the split methods have their say.
2455 ;; No split name was found.
2458 (concat prompt " (default "
2459 (file-name-nondirectory default-name) ") ")
2460 (file-name-directory default-name)
2462 ;; A single group name is returned.
2463 ((stringp split-name)
2465 (funcall function split-name headers
2466 (symbol-value variable)))
2468 (concat prompt " (default "
2469 (file-name-nondirectory default-name) ") ")
2470 (file-name-directory default-name)
2472 ;; A single split name was found
2473 ((= 1 (length split-name))
2474 (let* ((name (expand-file-name
2476 gnus-article-save-directory))
2477 (dir (cond ((file-directory-p name)
2478 (file-name-as-directory name))
2479 ((file-exists-p name) name)
2480 (t gnus-article-save-directory))))
2482 (concat prompt " (default " name ") ")
2484 ;; A list of splits was found.
2486 (setq split-name (nreverse split-name))
2488 (let ((file-name-history
2489 (nconc split-name file-name-history)))
2493 (concat prompt " (`M-p' for defaults) ")
2494 gnus-article-save-directory
2496 gnus-article-save-directory)))
2497 (car (push result file-name-history)))))))
2498 ;; Create the directory.
2499 (gnus-make-directory (file-name-directory file))
2500 ;; If we have read a directory, we append the default file name.
2501 (when (file-directory-p file)
2502 (setq file (expand-file-name (file-name-nondirectory
2504 (file-name-as-directory file))))
2505 ;; Possibly translate some characters.
2506 (nnheader-translate-file-chars file))))))
2507 (gnus-make-directory (file-name-directory result))
2508 (set variable result)))
2510 (defun gnus-article-archive-name (group)
2511 "Return the first instance of an \"Archive-name\" in the current buffer."
2512 (let ((case-fold-search t))
2513 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2514 (nnheader-concat gnus-article-save-directory
2515 (match-string 1)))))
2517 (defun gnus-article-nndoc-name (group)
2518 "If GROUP is an nndoc group, return the name of the parent group."
2519 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2520 (gnus-group-get-parameter group 'save-article-group)))
2522 (defun gnus-summary-save-in-rmail (&optional filename)
2523 "Append this article to Rmail file.
2524 Optional argument FILENAME specifies file name.
2525 Directory to save to is default to `gnus-article-save-directory'."
2526 (setq filename (gnus-read-save-file-name
2527 "Save %s in rmail file:" filename
2528 gnus-rmail-save-name gnus-newsgroup-name
2529 gnus-current-headers 'gnus-newsgroup-last-rmail))
2530 (gnus-eval-in-buffer-window gnus-save-article-buffer
2534 (gnus-output-to-rmail filename))))
2537 (defun gnus-summary-save-in-mail (&optional filename)
2538 "Append this article to Unix mail file.
2539 Optional argument FILENAME specifies file name.
2540 Directory to save to is default to `gnus-article-save-directory'."
2541 (setq filename (gnus-read-save-file-name
2542 "Save %s in Unix mail file:" filename
2543 gnus-mail-save-name gnus-newsgroup-name
2544 gnus-current-headers 'gnus-newsgroup-last-mail))
2545 (gnus-eval-in-buffer-window gnus-save-article-buffer
2549 (if (and (file-readable-p filename)
2550 (mail-file-babyl-p filename))
2551 (rmail-output-to-rmail-file filename t)
2552 (gnus-output-to-mail filename)))))
2555 (defun gnus-summary-save-in-file (&optional filename overwrite)
2556 "Append this article to file.
2557 Optional argument FILENAME specifies file name.
2558 Directory to save to is default to `gnus-article-save-directory'."
2559 (setq filename (gnus-read-save-file-name
2560 "Save %s in file:" filename
2561 gnus-file-save-name gnus-newsgroup-name
2562 gnus-current-headers 'gnus-newsgroup-last-file))
2563 (gnus-eval-in-buffer-window gnus-save-article-buffer
2567 (when (and overwrite
2568 (file-exists-p filename))
2569 (delete-file filename))
2570 (gnus-output-to-file filename))))
2573 (defun gnus-summary-write-to-file (&optional filename)
2574 "Write this article to a file.
2575 Optional argument FILENAME specifies file name.
2576 The directory to save in defaults to `gnus-article-save-directory'."
2577 (gnus-summary-save-in-file nil t))
2579 (defun gnus-summary-save-body-in-file (&optional filename)
2580 "Append this article body to a file.
2581 Optional argument FILENAME specifies file name.
2582 The directory to save in defaults to `gnus-article-save-directory'."
2583 (setq filename (gnus-read-save-file-name
2584 "Save %s body in file:" filename
2585 gnus-file-save-name gnus-newsgroup-name
2586 gnus-current-headers 'gnus-newsgroup-last-file))
2587 (gnus-eval-in-buffer-window gnus-save-article-buffer
2591 (when (article-goto-body)
2592 (narrow-to-region (point) (point-max)))
2593 (gnus-output-to-file filename))))
2596 (defun gnus-summary-save-in-pipe (&optional command)
2597 "Pipe this article to subprocess."
2599 (cond ((and (eq command 'default)
2600 gnus-last-shell-command)
2601 gnus-last-shell-command)
2605 "Shell command on %s: "
2606 (if (and gnus-number-of-articles-to-be-saved
2607 (> gnus-number-of-articles-to-be-saved 1))
2608 (format "these %d articles"
2609 gnus-number-of-articles-to-be-saved)
2611 gnus-last-shell-command))))
2612 (when (string-equal command "")
2613 (setq command gnus-last-shell-command))
2614 (gnus-eval-in-buffer-window gnus-article-buffer
2617 (shell-command-on-region (point-min) (point-max) command nil)))
2618 (setq gnus-last-shell-command command))
2620 ;;; Article file names when saving.
2622 (defun gnus-capitalize-newsgroup (newsgroup)
2623 "Capitalize NEWSGROUP name."
2624 (when (not (zerop (length newsgroup)))
2625 (concat (char-to-string (upcase (aref newsgroup 0)))
2626 (substring newsgroup 1))))
2628 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2629 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2630 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2631 Otherwise, it is like ~/News/news/group/num."
2634 (concat (if (gnus-use-long-file-name 'not-save)
2635 (gnus-capitalize-newsgroup newsgroup)
2636 (gnus-newsgroup-directory-form newsgroup))
2637 "/" (int-to-string (mail-header-number headers)))
2638 gnus-article-save-directory)))
2640 (string-equal (file-name-directory default)
2641 (file-name-directory last-file))
2642 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2644 (or last-file default))))
2646 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2647 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2648 If variable `gnus-use-long-file-name' is non-nil, it is
2649 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2652 (concat (if (gnus-use-long-file-name 'not-save)
2654 (gnus-newsgroup-directory-form newsgroup))
2655 "/" (int-to-string (mail-header-number headers)))
2656 gnus-article-save-directory)))
2658 (string-equal (file-name-directory default)
2659 (file-name-directory last-file))
2660 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2662 (or last-file default))))
2664 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2665 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2666 If variable `gnus-use-long-file-name' is non-nil, it is
2667 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2670 (if (gnus-use-long-file-name 'not-save)
2672 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2673 gnus-article-save-directory)))
2675 (defun article-verify-x-pgp-sig ()
2678 (if (gnus-buffer-live-p gnus-original-article-buffer)
2679 (let ((sig (with-current-buffer gnus-original-article-buffer
2680 (gnus-fetch-field "X-PGP-Sig")))
2684 (mml2015-clear-verify-function))
2686 (insert-buffer gnus-original-article-buffer)
2687 (setq items (split-string sig))
2688 (message-narrow-to-head)
2689 (let ((inhibit-point-motion-hooks t)
2690 (case-fold-search t))
2691 ;; Don't verify multiple headers.
2692 (setq headers (mapconcat (lambda (header)
2694 (mail-fetch-field header) "\n"))
2695 (split-string (nth 1 items) ",") "")))
2696 (delete-region (point-min) (point-max))
2697 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2698 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2703 (if (looking-at "^-")
2706 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2707 (insert "Version: " (car items) "\n\n")
2708 (insert (mapconcat 'identity (cddr items) "\n"))
2709 (insert "\n-----END PGP SIGNATURE-----\n")
2710 (let ((mm-security-handle (list (format "multipart/signed"))))
2711 (mml2015-clean-buffer)
2712 (let ((coding-system-for-write (or gnus-newsgroup-charset
2714 (funcall (mml2015-clear-verify-function)))
2716 (or (mm-handle-multipart-ctl-parameter
2717 mm-security-handle 'gnus-details)
2718 (mm-handle-multipart-ctl-parameter
2719 mm-security-handle 'gnus-info)))))
2721 (let (buffer-read-only bface eface)
2723 (message-narrow-to-head)
2724 (goto-char (point-max))
2726 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2727 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2728 (message-remove-header "X-Gnus-PGP-Verify")
2729 (if (re-search-forward "^X-PGP-Sig:" nil t)
2731 (goto-char (point-max)))
2732 (narrow-to-region (point) (point))
2733 (insert "X-Gnus-PGP-Verify: " info "\n")
2734 (goto-char (point-min))
2737 (if (not (looking-at "^[ \t]"))
2741 (goto-char (point-min))
2742 (when (looking-at "\\([^:]+\\): *")
2743 (put-text-property (match-beginning 1) (1+ (match-end 1))
2745 (put-text-property (match-end 0) (point-max)
2746 'face eface)))))))))
2753 (setq afunc (car func)
2756 gfunc (intern (format "gnus-%s" func))))
2759 `(lambda (&optional interactive &rest args)
2760 ,(documentation afunc t)
2761 (interactive (list t))
2763 (set-buffer gnus-article-buffer)
2765 (call-interactively ',afunc)
2766 (apply ',afunc args))))))))
2767 '(article-hide-headers
2768 article-verify-x-pgp-sig
2769 article-hide-boring-headers
2770 article-treat-overstrike
2771 article-fill-long-lines
2772 article-capitalize-sentences
2774 article-display-x-face
2775 article-de-quoted-unreadable
2776 article-de-base64-unreadable
2779 article-hide-list-identifiers
2781 article-strip-banner
2784 article-hide-signature
2785 article-strip-headers-in-body
2786 article-remove-trailing-blank-lines
2787 article-strip-leading-blank-lines
2788 article-strip-multiple-blank-lines
2789 article-strip-leading-space
2790 article-strip-trailing-space
2791 article-strip-blank-lines
2792 article-strip-all-blank-lines
2794 article-date-english
2795 article-date-iso8601
2796 article-date-original
2798 article-decode-mime-words
2799 article-decode-charset
2800 article-decode-encoded-words
2804 article-treat-dumbquotes
2805 article-normalize-headers
2806 (article-show-all . gnus-article-show-all-headers))))
2809 ;;; Gnus article mode
2812 (put 'gnus-article-mode 'mode-class 'special)
2814 (set-keymap-parent gnus-article-mode-map widget-keymap)
2816 (gnus-define-keys gnus-article-mode-map
2817 " " gnus-article-goto-next-page
2818 "\177" gnus-article-goto-prev-page
2819 [delete] gnus-article-goto-prev-page
2820 [backspace] gnus-article-goto-prev-page
2821 "\C-c^" gnus-article-refer-article
2822 "h" gnus-article-show-summary
2823 "s" gnus-article-show-summary
2824 "\C-c\C-m" gnus-article-mail
2825 "?" gnus-article-describe-briefly
2826 "e" gnus-summary-edit-article
2827 "<" beginning-of-buffer
2829 "\C-c\C-i" gnus-info-find-node
2831 "\C-hk" gnus-article-describe-key
2832 "\C-hc" gnus-article-describe-key-briefly
2834 "\C-d" gnus-article-read-summary-keys
2835 "\M-*" gnus-article-read-summary-keys
2836 "\M-#" gnus-article-read-summary-keys
2837 "\M-^" gnus-article-read-summary-keys
2838 "\M-g" gnus-article-read-summary-keys)
2840 (substitute-key-definition
2841 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
2844 (defvar gnus-article-commands-menu))
2846 (defun gnus-article-make-menu-bar ()
2847 (gnus-turn-off-edit-menu 'article)
2848 (unless (boundp 'gnus-article-article-menu)
2850 gnus-article-article-menu gnus-article-mode-map ""
2852 ["Scroll forwards" gnus-article-goto-next-page t]
2853 ["Scroll backwards" gnus-article-goto-prev-page t]
2854 ["Show summary" gnus-article-show-summary t]
2855 ["Fetch Message-ID at point" gnus-article-refer-article t]
2856 ["Mail to address at point" gnus-article-mail t]
2857 ["Send a bug report" gnus-bug t]))
2860 gnus-article-treatment-menu gnus-article-mode-map ""
2861 ;; Fixme: this should use :active (and maybe :visible).
2863 ["Hide headers" gnus-article-hide-headers t]
2864 ["Hide signature" gnus-article-hide-signature t]
2865 ["Hide citation" gnus-article-hide-citation t]
2866 ["Treat overstrike" gnus-article-treat-overstrike t]
2867 ["Remove carriage return" gnus-article-remove-cr t]
2868 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
2869 ["Remove base64" gnus-article-de-base64-unreadable t]
2870 ["Treat html" gnus-article-wash-html t]
2871 ["Decode HZ" gnus-article-decode-HZ t]))
2873 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2875 (when (boundp 'gnus-summary-post-menu)
2876 (define-key gnus-article-mode-map [menu-bar post]
2877 (cons "Post" gnus-summary-post-menu)))
2879 (gnus-run-hooks 'gnus-article-menu-hook))
2881 (when (boundp 'gnus-article-commands-menu)
2882 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2883 (when (boundp 'gnus-summary-post-menu)
2884 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2886 ;; Fixme: do something for the Emacs tool bar in Article mode a la
2889 (defun gnus-article-mode ()
2890 "Major mode for displaying an article.
2892 All normal editing commands are switched off.
2894 The following commands are available in addition to all summary mode
2896 \\<gnus-article-mode-map>
2897 \\[gnus-article-next-page]\t Scroll the article one page forwards
2898 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2899 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2900 \\[gnus-article-show-summary]\t Display the summary buffer
2901 \\[gnus-article-mail]\t Send a reply to the address near point
2902 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
2903 \\[gnus-info-find-node]\t Go to the Gnus info node"
2905 (when (gnus-visual-p 'article-menu 'menu)
2906 (gnus-article-make-menu-bar))
2907 (gnus-simplify-mode-line)
2908 (setq mode-name "Article")
2909 (setq major-mode 'gnus-article-mode)
2910 (make-local-variable 'minor-mode-alist)
2911 (use-local-map gnus-article-mode-map)
2912 (gnus-update-format-specifications nil 'article-mode)
2913 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
2914 (make-local-variable 'gnus-page-broken)
2915 (make-local-variable 'gnus-button-marker-list)
2916 (make-local-variable 'gnus-article-current-summary)
2917 (make-local-variable 'gnus-article-mime-handles)
2918 (make-local-variable 'gnus-article-decoded-p)
2919 (make-local-variable 'gnus-article-mime-handle-alist)
2920 (make-local-variable 'gnus-article-wash-types)
2921 (make-local-variable 'gnus-article-charset)
2922 (make-local-variable 'gnus-article-ignored-charsets)
2923 (gnus-set-default-directory)
2924 (buffer-disable-undo)
2925 (setq buffer-read-only t)
2926 (set-syntax-table gnus-article-mode-syntax-table)
2927 (mm-enable-multibyte)
2928 (gnus-run-hooks 'gnus-article-mode-hook))
2930 (defun gnus-article-setup-buffer ()
2931 "Initialize the article buffer."
2932 (let* ((name (if gnus-single-article-buffer "*Article*"
2933 (concat "*Article " gnus-newsgroup-name "*")))
2935 (progn (string-match "\\*Article" name)
2936 (concat " *Original Article"
2937 (substring name (match-end 0))))))
2938 (setq gnus-article-buffer name)
2939 (setq gnus-original-article-buffer original)
2940 (setq gnus-article-mime-handle-alist nil)
2941 ;; This might be a variable local to the summary buffer.
2942 (unless gnus-single-article-buffer
2944 (set-buffer gnus-summary-buffer)
2945 (setq gnus-article-buffer name)
2946 (setq gnus-original-article-buffer original)
2947 (gnus-set-global-variables)))
2948 (gnus-article-setup-highlight-words)
2949 ;; Init original article buffer.
2951 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
2952 (mm-enable-multibyte)
2953 (setq major-mode 'gnus-original-article-mode)
2954 (make-local-variable 'gnus-original-article))
2955 (if (get-buffer name)
2958 (when gnus-article-mime-handles
2959 (mm-destroy-parts gnus-article-mime-handles)
2960 (setq gnus-article-mime-handles nil))
2961 ;; Set it to nil in article-buffer!
2962 (setq gnus-article-mime-handle-alist nil)
2963 (buffer-disable-undo)
2964 (setq buffer-read-only t)
2965 (unless (eq major-mode 'gnus-article-mode)
2966 (gnus-article-mode))
2969 (set-buffer (gnus-get-buffer-create name))
2971 (make-local-variable 'gnus-summary-buffer)
2972 (gnus-summary-set-local-parameters gnus-newsgroup-name)
2973 (current-buffer)))))
2975 ;; Set article window start at LINE, where LINE is the number of lines
2976 ;; from the head of the article.
2977 (defun gnus-article-set-window-start (&optional line)
2979 (get-buffer-window gnus-article-buffer t)
2981 (set-buffer gnus-article-buffer)
2982 (goto-char (point-min))
2985 (gnus-message 6 "Moved to bookmark")
2986 (search-forward "\n\n" nil t)
2990 (defun gnus-article-prepare (article &optional all-headers header)
2991 "Prepare ARTICLE in article mode buffer.
2992 ARTICLE should either be an article number or a Message-ID.
2993 If ARTICLE is an id, HEADER should be the article headers.
2994 If ALL-HEADERS is non-nil, no headers are hidden."
2996 ;; Make sure we start in a summary buffer.
2997 (unless (eq major-mode 'gnus-summary-mode)
2998 (set-buffer gnus-summary-buffer))
2999 (setq gnus-summary-buffer (current-buffer))
3000 (let* ((gnus-article (if header (mail-header-number header) article))
3001 (summary-buffer (current-buffer))
3002 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3003 (group gnus-newsgroup-name)
3006 (gnus-article-setup-buffer)
3007 (set-buffer gnus-article-buffer)
3008 ;; Deactivate active regions.
3009 (when (and (boundp 'transient-mark-mode)
3010 transient-mark-mode)
3011 (setq mark-active nil))
3012 (if (not (setq result (let ((buffer-read-only nil))
3013 (gnus-request-article-this-buffer
3015 ;; There is no such article.
3017 (when (and (numberp article)
3018 (not (memq article gnus-newsgroup-sparse)))
3019 (setq gnus-article-current
3020 (cons gnus-newsgroup-name article))
3021 (set-buffer gnus-summary-buffer)
3022 (setq gnus-current-article article)
3023 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3025 (gnus-summary-set-agent-mark article)
3026 (message "Message marked for downloading"))
3027 (gnus-summary-mark-article article gnus-canceled-mark)
3028 (unless (memq article gnus-newsgroup-sparse)
3029 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3030 (if (or (eq result 'pseudo)
3031 (eq result 'nneething))
3034 (set-buffer summary-buffer)
3035 (push article gnus-newsgroup-history)
3036 (setq gnus-last-article gnus-current-article
3037 gnus-current-article 0
3038 gnus-current-headers nil
3039 gnus-article-current nil)
3040 (if (eq result 'nneething)
3041 (gnus-configure-windows 'summary)
3042 (gnus-configure-windows 'article))
3043 (gnus-set-global-variables))
3044 (let ((gnus-article-mime-handle-alist-1
3045 gnus-article-mime-handle-alist))
3046 (gnus-set-mode-line 'article)))
3047 ;; The result from the `request' was an actual article -
3048 ;; or at least some text that is now displayed in the
3050 (when (and (numberp article)
3051 (not (eq article gnus-current-article)))
3052 ;; Seems like a new article has been selected.
3053 ;; `gnus-current-article' must be an article number.
3055 (set-buffer summary-buffer)
3056 (push article gnus-newsgroup-history)
3057 (setq gnus-last-article gnus-current-article
3058 gnus-current-article article
3059 gnus-current-headers
3060 (gnus-summary-article-header gnus-current-article)
3061 gnus-article-current
3062 (cons gnus-newsgroup-name gnus-current-article))
3063 (unless (vectorp gnus-current-headers)
3064 (setq gnus-current-headers nil))
3065 (gnus-summary-goto-subject gnus-current-article)
3066 (when (gnus-summary-show-thread)
3067 ;; If the summary buffer really was folded, the
3068 ;; previous goto may not actually have gone to
3069 ;; the right article, but the thread root instead.
3071 (gnus-summary-goto-subject gnus-current-article))
3072 (gnus-run-hooks 'gnus-mark-article-hook)
3073 (gnus-set-mode-line 'summary)
3074 (when (gnus-visual-p 'article-highlight 'highlight)
3075 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3076 ;; Set the global newsgroup variables here.
3077 (gnus-set-global-variables)
3078 (setq gnus-have-all-headers
3079 (or all-headers gnus-show-all-headers))))
3081 (gnus-configure-windows 'article))
3082 (when (or (numberp article)
3084 (gnus-article-prepare-display)
3086 (goto-char (point-min))
3087 (setq gnus-page-broken
3088 (when gnus-break-pages
3089 (gnus-narrow-to-page)
3091 (let ((gnus-article-mime-handle-alist-1
3092 gnus-article-mime-handle-alist))
3093 (gnus-set-mode-line 'article))
3095 (set-window-point (get-buffer-window (current-buffer)) (point))
3096 (gnus-configure-windows 'article)
3100 (defun gnus-article-prepare-display ()
3101 "Make the current buffer look like a nice article."
3102 ;; Hooks for getting information from the article.
3103 ;; This hook must be called before being narrowed.
3104 (let ((gnus-article-buffer (current-buffer))
3106 (unless (eq major-mode 'gnus-article-mode)
3107 (gnus-article-mode))
3108 (setq buffer-read-only nil
3109 gnus-article-wash-types nil)
3110 (gnus-run-hooks 'gnus-tmp-internal-hook)
3111 (when gnus-display-mime-function
3112 (funcall gnus-display-mime-function))
3113 (gnus-run-hooks 'gnus-article-prepare-hook)))
3116 ;;; Gnus MIME viewing functions
3119 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3120 "The following specs can be used:
3122 %T MIME type, along with additional info
3123 %n The `name' parameter
3124 %d The description, if any
3125 %l The length of the encoded part
3126 %p The part identifier number
3127 %e Dots if the part isn't displayed")
3129 (defvar gnus-mime-button-line-format-alist
3130 '((?t gnus-tmp-type ?s)
3131 (?T gnus-tmp-type-long ?s)
3132 (?n gnus-tmp-name ?s)
3133 (?d gnus-tmp-description ?s)
3135 (?l gnus-tmp-length ?d)
3136 (?e gnus-tmp-dots ?s)))
3138 (defvar gnus-mime-button-commands
3139 '((gnus-article-press-button "\r" "Toggle Display")
3140 (gnus-mime-view-part "v" "View Interactively...")
3141 (gnus-mime-view-part-as-type "t" "View As Type...")
3142 (gnus-mime-view-part-as-charset "C" "View As charset...")
3143 (gnus-mime-save-part "o" "Save...")
3144 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3145 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3146 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3147 (gnus-mime-internalize-part "E" "View Internally")
3148 (gnus-mime-externalize-part "e" "View Externally")
3149 (gnus-mime-pipe-part "|" "Pipe To Command...")
3150 (gnus-mime-action-on-part "." "Take action on the part")))
3152 (defun gnus-article-mime-part-status ()
3153 (if gnus-article-mime-handle-alist-1
3154 (format " (%d parts)" (length gnus-article-mime-handle-alist-1))
3157 (defvar gnus-mime-button-map
3158 (let ((map (make-sparse-keymap)))
3159 (unless (>= (string-to-number emacs-version) 21)
3160 ;; XEmacs doesn't care.
3161 (set-keymap-parent map gnus-article-mode-map))
3162 (define-key map gnus-mouse-2 'gnus-article-push-button)
3163 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3164 (dolist (c gnus-mime-button-commands)
3165 (define-key map (cadr c) (car c)))
3168 (defun gnus-mime-button-menu (event)
3169 "Construct a context-sensitive menu of MIME commands."
3171 (save-window-excursion
3172 (let ((pos (event-start event)))
3173 (select-window (posn-window pos))
3174 (goto-char (posn-point pos))
3175 (gnus-article-check-buffer)
3176 (let ((response (x-popup-menu
3178 ("" ,@(mapcar (lambda (c)
3179 (cons (caddr c) (car c)))
3180 gnus-mime-button-commands))))))
3182 (call-interactively response))))))
3184 (defun gnus-mime-view-all-parts (&optional handles)
3185 "View all the MIME parts."
3187 (save-current-buffer
3188 (set-buffer gnus-article-buffer)
3189 (let ((handles (or handles gnus-article-mime-handles))
3190 (mail-parse-charset gnus-newsgroup-charset)
3191 (mail-parse-ignored-charsets
3192 (with-current-buffer gnus-summary-buffer
3193 gnus-newsgroup-ignored-charsets)))
3195 (mm-remove-parts handles)
3196 (goto-char (point-min))
3197 (or (search-forward "\n\n") (goto-char (point-max)))
3198 (let (buffer-read-only)
3199 (delete-region (point) (point-max)))
3200 (mm-display-parts handles)))))
3202 (defun gnus-mime-save-part-and-strip ()
3203 "Save the MIME part under point then replace it with an external body."
3205 (gnus-article-check-buffer)
3206 (let* ((data (get-text-property (point) 'gnus-data))
3207 (file (and data (mm-save-part data)))
3210 (with-current-buffer (mm-handle-buffer data)
3212 (insert "Content-Type: " (mm-handle-media-type data))
3213 (mml-insert-parameter-string (cdr (mm-handle-type data))
3216 (insert "Content-ID: " (message-make-message-id) "\n")
3217 (insert "Content-Transfer-Encoding: binary\n")
3220 (cdr (mm-make-handle nil
3221 `("message/external-body"
3222 (access-type . "LOCAL-FILE")
3224 (set-buffer gnus-summary-buffer)
3225 (gnus-article-edit-article
3228 (let ((mail-parse-charset (or gnus-article-charset
3229 ',gnus-newsgroup-charset))
3230 (mail-parse-ignored-charsets
3231 (or gnus-article-ignored-charsets
3232 ',gnus-newsgroup-ignored-charsets))
3233 (mbl mml-buffer-list))
3234 (setq mml-buffer-list nil)
3235 (insert-buffer gnus-original-article-buffer)
3236 (mime-to-mml gnus-article-mime-handles)
3237 (setq gnus-article-mime-handles nil)
3238 (make-local-hook 'kill-buffer-hook)
3239 (let ((mbl1 mml-buffer-list))
3240 (setq mml-buffer-list mbl)
3241 (set (make-local-variable 'mml-buffer-list) mbl1))
3242 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3243 `(lambda (no-highlight)
3244 (let ((mail-parse-charset (or gnus-article-charset
3245 ',gnus-newsgroup-charset))
3246 (message-options message-options)
3247 (message-options-set-recipient)
3248 (mail-parse-ignored-charsets
3249 (or gnus-article-ignored-charsets
3250 ',gnus-newsgroup-ignored-charsets)))
3252 (mml-destroy-buffers)
3253 (remove-hook 'kill-buffer-hook
3254 'mml-destroy-buffers t)
3255 (kill-local-variable 'mml-buffer-list))
3256 (gnus-summary-edit-article-done
3257 ,(or (mail-header-references gnus-current-headers) "")
3258 ,(gnus-group-read-only-p)
3259 ,gnus-summary-buffer no-highlight))))))
3261 (defun gnus-mime-save-part ()
3262 "Save the MIME part under point."
3264 (gnus-article-check-buffer)
3265 (let ((data (get-text-property (point) 'gnus-data)))
3267 (mm-save-part data))))
3269 (defun gnus-mime-pipe-part ()
3270 "Pipe the MIME part under point to a process."
3272 (gnus-article-check-buffer)
3273 (let ((data (get-text-property (point) 'gnus-data)))
3275 (mm-pipe-part data))))
3277 (defun gnus-mime-view-part ()
3278 "Interactively choose a viewing method for the MIME part under point."
3280 (gnus-article-check-buffer)
3281 (let ((data (get-text-property (point) 'gnus-data)))
3283 (mm-interactively-view-part data))))
3285 (defun gnus-mime-view-part-as-type-internal ()
3286 (gnus-article-check-buffer)
3287 (let* ((name (mail-content-type-get
3288 (mm-handle-type (get-text-property (point) 'gnus-data))
3290 (def-type (and name (mm-default-file-encoding name))))
3291 (and def-type (cons def-type 0))))
3293 (defun gnus-mime-view-part-as-type (mime-type)
3294 "Choose a MIME media type, and view the part as such."
3296 (list (completing-read
3297 "View as MIME type: "
3298 (mapcar #'list (mailcap-mime-types))
3300 (gnus-mime-view-part-as-type-internal))))
3301 (gnus-article-check-buffer)
3302 (let ((handle (get-text-property (point) 'gnus-data)))
3304 (gnus-mm-display-part
3305 (mm-make-handle (mm-handle-buffer handle)
3306 (cons mime-type (cdr (mm-handle-type handle)))
3307 (mm-handle-encoding handle)
3308 (mm-handle-undisplayer handle)
3309 (mm-handle-disposition handle)
3310 (mm-handle-description handle)
3311 (mm-handle-cache handle)
3312 (mm-handle-id handle))))))
3314 (defun gnus-mime-copy-part (&optional handle)
3315 "Put the the MIME part under point into a new buffer."
3317 (gnus-article-check-buffer)
3318 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3319 (contents (and handle (mm-get-part handle)))
3321 (file-name-nondirectory
3323 (mail-content-type-get (mm-handle-type handle) 'name)
3324 (mail-content-type-get (mm-handle-type handle)
3327 (buffer (and base (generate-new-buffer base))))
3329 (switch-to-buffer buffer)
3331 ;; We do it this way to make `normal-mode' set the appropriate mode.
3334 (setq buffer-file-name (expand-file-name base))
3336 (setq buffer-file-name nil))
3337 (goto-char (point-min)))))
3339 (defun gnus-mime-inline-part (&optional handle arg)
3340 "Insert the MIME part under point into the current buffer."
3341 (interactive (list nil current-prefix-arg))
3342 (gnus-article-check-buffer)
3343 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3348 (if (and (not arg) (mm-handle-undisplayer handle))
3349 (mm-remove-part handle)
3350 (setq contents (mm-get-part handle))
3353 (setq charset (or (mail-content-type-get
3354 (mm-handle-type handle) 'charset)
3355 gnus-newsgroup-charset)))
3357 (if (mm-handle-undisplayer handle)
3358 (mm-remove-part handle))
3361 gnus-summary-show-article-charset-alist))
3362 (read-coding-system "Charset: ")))))
3364 (mm-insert-inline handle
3366 (setq charset (mm-charset-to-coding-system
3368 (not (eq charset 'ascii)))
3369 (mm-decode-coding-string contents charset)
3373 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3374 "Insert the MIME part under point into the current buffer."
3375 (interactive (list nil current-prefix-arg))
3376 (gnus-article-check-buffer)
3377 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3382 (if (mm-handle-undisplayer handle)
3383 (mm-remove-part handle))
3384 (let ((gnus-newsgroup-charset
3386 gnus-summary-show-article-charset-alist))
3387 (read-coding-system "Charset: ")))
3388 (gnus-newsgroup-ignored-charsets 'gnus-all))
3389 (gnus-article-press-button)))))
3391 (defun gnus-mime-externalize-part (&optional handle)
3392 "View the MIME part under point with an external viewer."
3394 (gnus-article-check-buffer)
3395 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3396 (mm-user-display-methods nil)
3397 (mm-inlined-types nil)
3398 (mail-parse-charset gnus-newsgroup-charset)
3399 (mail-parse-ignored-charsets
3400 (save-excursion (set-buffer gnus-summary-buffer)
3401 gnus-newsgroup-ignored-charsets)))
3403 (if (mm-handle-undisplayer handle)
3404 (mm-remove-part handle)
3405 (mm-display-part handle)))))
3407 (defun gnus-mime-internalize-part (&optional handle)
3408 "View the MIME part under point with an internal viewer.
3409 In no internal viewer is available, use an external viewer."
3411 (gnus-article-check-buffer)
3412 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3413 (mm-inlined-types '(".*"))
3414 (mm-inline-large-images t)
3415 (mail-parse-charset gnus-newsgroup-charset)
3416 (mail-parse-ignored-charsets
3417 (save-excursion (set-buffer gnus-summary-buffer)
3418 gnus-newsgroup-ignored-charsets)))
3420 (if (mm-handle-undisplayer handle)
3421 (mm-remove-part handle)
3422 (mm-display-part handle)))))
3424 (defun gnus-mime-action-on-part (&optional action)
3425 "Do something with the MIME attachment at \(point\)."
3427 (list (completing-read "Action: " gnus-mime-action-alist)))
3428 (gnus-article-check-buffer)
3429 (let ((action-pair (assoc action gnus-mime-action-alist)))
3431 (funcall (cdr action-pair)))))
3433 (defun gnus-article-part-wrapper (n function)
3434 (save-current-buffer
3435 (set-buffer gnus-article-buffer)
3436 (when (> n (length gnus-article-mime-handle-alist))
3437 (error "No such part"))
3438 (gnus-article-goto-part n)
3439 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3440 (funcall function handle))))
3442 (defun gnus-article-pipe-part (n)
3443 "Pipe MIME part N, which is the numerical prefix."
3445 (gnus-article-part-wrapper n 'mm-pipe-part))
3447 (defun gnus-article-save-part (n)
3448 "Save MIME part N, which is the numerical prefix."
3450 (gnus-article-part-wrapper n 'mm-save-part))
3452 (defun gnus-article-interactively-view-part (n)
3453 "View MIME part N interactively, which is the numerical prefix."
3455 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3457 (defun gnus-article-copy-part (n)
3458 "Copy MIME part N, which is the numerical prefix."
3460 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3462 (defun gnus-article-view-part-as-charset (n)
3463 "Copy MIME part N, which is the numerical prefix."
3465 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3467 (defun gnus-article-externalize-part (n)
3468 "View MIME part N externally, which is the numerical prefix."
3470 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3472 (defun gnus-article-inline-part (n)
3473 "Inline MIME part N, which is the numerical prefix."
3475 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3477 (defun gnus-article-mime-match-handle-first (condition)
3479 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3480 (while (setq ihandle (pop alist))
3482 ((functionp condition)
3483 (funcall condition (cdr ihandle)))
3484 ((eq condition 'undisplayed)
3485 (not (or (mm-handle-undisplayer (cdr ihandle))
3486 (equal (mm-handle-media-type (cdr ihandle))
3487 "multipart/alternative"))))
3488 ((eq condition 'undisplayed-alternative)
3489 (not (mm-handle-undisplayer (cdr ihandle))))
3491 (gnus-article-goto-part (car ihandle))
3492 (or (not n) (< (car ihandle) n)))
3493 (setq n (car ihandle))))
3497 (defun gnus-article-view-part (&optional n)
3498 "View MIME part N, which is the numerical prefix."
3500 (save-current-buffer
3501 (set-buffer gnus-article-buffer)
3502 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3503 gnus-article-mime-match-handle-function)))
3504 (when (> n (length gnus-article-mime-handle-alist))
3505 (error "No such part"))
3506 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3507 (when (gnus-article-goto-part n)
3508 (if (equal (car handle) "multipart/alternative")
3509 (gnus-article-press-button)
3510 (when (eq (gnus-mm-display-part handle) 'internal)
3511 (gnus-set-window-start)))))))
3513 (defsubst gnus-article-mime-total-parts ()
3514 (if (bufferp (car gnus-article-mime-handles))
3516 (1- (length gnus-article-mime-handles))))
3518 (defun gnus-mm-display-part (handle)
3519 "Display HANDLE and fix MIME button."
3520 (let ((id (get-text-property (point) 'gnus-part))
3525 (let ((window (selected-window))
3526 (mail-parse-charset gnus-newsgroup-charset)
3527 (mail-parse-ignored-charsets
3528 (save-excursion (set-buffer gnus-summary-buffer)
3529 gnus-newsgroup-ignored-charsets)))
3532 (let ((win (get-buffer-window (current-buffer) t))
3535 (select-window win))
3538 (if (mm-handle-displayed-p handle)
3539 ;; This will remove the part.
3540 (mm-display-part handle)
3542 (narrow-to-region (point) (1+ (point)))
3543 (mm-display-part handle)
3544 ;; We narrow to the part itself and
3545 ;; then call the treatment functions.
3546 (goto-char (point-min))
3548 (narrow-to-region (point) (point-max))
3551 (gnus-article-mime-total-parts)
3552 (mm-handle-media-type handle)))))
3553 (select-window window))))
3555 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3556 (gnus-insert-mime-button
3557 handle id (list (mm-handle-displayed-p handle)))
3558 (goto-char point))))
3560 (defun gnus-article-goto-part (n)
3561 "Go to MIME part N."
3562 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3564 (goto-char point))))
3566 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3567 (let ((gnus-tmp-name
3568 (or (mail-content-type-get (mm-handle-type handle)
3570 (mail-content-type-get (mm-handle-disposition handle)
3572 (mail-content-type-get (mm-handle-type handle)
3575 (gnus-tmp-type (mm-handle-media-type handle))
3576 (gnus-tmp-description
3577 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3580 (if (if displayed (car displayed)
3581 (mm-handle-displayed-p handle))
3583 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3585 gnus-tmp-type-long b e)
3586 (when (string-match ".*/" gnus-tmp-name)
3587 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3588 (setq gnus-tmp-type-long (concat gnus-tmp-type
3589 (and (not (equal gnus-tmp-name ""))
3590 (concat "; " gnus-tmp-name))))
3591 (or (equal gnus-tmp-description "")
3592 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3597 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3598 `(keymap ,gnus-mime-button-map
3599 ,@(if (>= (string-to-number emacs-version) 21)
3601 (list 'local-map gnus-mime-button-map))
3602 gnus-callback gnus-mm-display-part
3603 gnus-part ,gnus-tmp-id
3604 article-type annotation
3607 (widget-convert-button
3610 :action 'gnus-widget-press-button
3611 :button-keymap gnus-mime-button-map
3613 (lambda (widget/window &optional overlay pos)
3614 ;; Needed to properly clear the message due to a bug in
3615 ;; wid-edit (XEmacs only).
3616 (if (boundp 'help-echo-owns-message)
3617 (setq help-echo-owns-message t))
3619 "%S: %s the MIME part; %S: more options"
3620 (aref gnus-mouse-2 0)
3621 ;; XEmacs will get a single widget arg; Emacs 21 will get
3622 ;; window, overlay, position.
3623 (if (mm-handle-displayed-p
3625 (with-current-buffer (gnus-overlay-buffer overlay)
3626 (widget-get (widget-at (gnus-overlay-start overlay))
3628 (widget-get widget/window :mime-handle)))
3630 (aref gnus-down-mouse-3 0))))))
3632 (defun gnus-widget-press-button (elems el)
3633 (goto-char (widget-get elems :from))
3634 (gnus-article-press-button))
3636 (defvar gnus-displaying-mime nil)
3638 (defun gnus-display-mime (&optional ihandles)
3639 "Display the MIME parts."
3641 (save-selected-window
3642 (let ((window (get-buffer-window gnus-article-buffer))
3645 (select-window window)
3646 ;; We have to do this since selecting the window
3647 ;; may change the point. So we set the window point.
3648 (set-window-point window point)))
3649 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3650 buffer-read-only handle name type b e display)
3651 (when (and (not ihandles)
3652 (not gnus-displaying-mime))
3653 ;; Top-level call; we clean up.
3654 (when gnus-article-mime-handles
3655 (mm-destroy-parts gnus-article-mime-handles)
3656 (setq gnus-article-mime-handle-alist nil));; A trick.
3657 (setq gnus-article-mime-handles handles)
3658 ;; We allow users to glean info from the handles.
3659 (when gnus-article-mime-part-function
3660 (gnus-mime-part-function handles)))
3662 (or (not (stringp (car handles)))
3665 (when (and (not ihandles)
3666 (not gnus-displaying-mime))
3667 ;; Clean up for mime parts.
3669 (delete-region (point) (point-max)))
3670 (let ((gnus-displaying-mime t))
3671 (gnus-mime-display-part handles)))
3674 (narrow-to-region (point) (point-max))
3675 (gnus-treat-article nil 1 1)
3678 ;; Highlight the headers.
3682 (narrow-to-region (point-min) (point))
3683 (gnus-treat-article 'head))))))))
3685 (defvar gnus-mime-display-multipart-as-mixed nil)
3687 (defun gnus-mime-display-part (handle)
3690 ((not (stringp (car handle)))
3691 (gnus-mime-display-single handle))
3692 ;; User-defined multipart
3693 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3694 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3696 ;; multipart/alternative
3697 ((and (equal (car handle) "multipart/alternative")
3698 (not gnus-mime-display-multipart-as-mixed))
3699 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3700 (push (cons id handle) gnus-article-mime-handle-alist)
3701 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3702 ;; multipart/related
3703 ((and (equal (car handle) "multipart/related")
3704 (not gnus-mime-display-multipart-as-mixed))
3705 ;;;!!!We should find the start part, but we just default
3706 ;;;!!!to the first part.
3707 ;;(gnus-mime-display-part (cadr handle))
3708 ;;;!!! Most multipart/related is an HTML message plus images.
3709 ;;;!!! Unfortunately we are unable to let W3 display those
3710 ;;;!!! included images, so we just display it as a mixed multipart.
3711 ;;(gnus-mime-display-mixed (cdr handle))
3712 ;;;!!! No, w3 can display everything just fine.
3713 (gnus-mime-display-part (cadr handle)))
3714 ((equal (car handle) "multipart/signed")
3715 (or (memq 'signed gnus-article-wash-types)
3716 (push 'signed gnus-article-wash-types))
3717 (gnus-mime-display-security handle))
3718 ((equal (car handle) "multipart/encrypted")
3719 (or (memq 'encrypted gnus-article-wash-types)
3720 (push 'encrypted gnus-article-wash-types))
3721 (gnus-mime-display-security handle))
3722 ;; Other multiparts are handled like multipart/mixed.
3724 (gnus-mime-display-mixed (cdr handle)))))
3726 (defun gnus-mime-part-function (handles)
3727 (if (stringp (car handles))
3728 (mapcar 'gnus-mime-part-function (cdr handles))
3729 (funcall gnus-article-mime-part-function handles)))
3731 (defun gnus-mime-display-mixed (handles)
3732 (mapcar 'gnus-mime-display-part handles))
3734 (defun gnus-mime-display-single (handle)
3735 (let ((type (mm-handle-media-type handle))
3736 (ignored gnus-ignored-mime-types)
3743 (when (string-match (pop ignored) type)
3744 (throw 'ignored nil)))
3745 (if (and (setq not-attachment
3746 (and (not (mm-inline-override-p handle))
3747 (or (not (mm-handle-disposition handle))
3748 (equal (car (mm-handle-disposition handle))
3750 (mm-attachment-override-p handle))))
3751 (mm-automatic-display-p handle)
3752 (or (mm-inlined-p handle)
3753 (mm-automatic-external-display-p type)))
3755 (when (equal (mm-handle-media-supertype handle) "text")
3757 (let ((id (1+ (length gnus-article-mime-handle-alist)))
3759 (push (cons id handle) gnus-article-mime-handle-alist)
3760 (when (or (not display)
3761 (not (gnus-unbuttonized-mime-type-p type)))
3762 ;(gnus-article-insert-newline)
3763 (gnus-insert-mime-button
3764 handle id (list (or display (and not-attachment text))))
3765 (gnus-article-insert-newline)
3766 ;(gnus-article-insert-newline)
3767 ;; Remember modify the number of forward lines.
3775 (let ((mail-parse-charset gnus-newsgroup-charset)
3776 (mail-parse-ignored-charsets
3777 (save-excursion (condition-case ()
3778 (set-buffer gnus-summary-buffer)
3780 gnus-newsgroup-ignored-charsets)))
3781 (mm-display-part handle t))
3782 (goto-char (point-max)))
3783 ((and text not-attachment)
3787 (gnus-article-insert-newline)
3788 (mm-insert-inline handle (mm-get-part handle))
3789 (goto-char (point-max))))
3793 (narrow-to-region beg (point))
3796 (gnus-article-mime-total-parts)
3797 (mm-handle-media-type handle)))))))))
3799 (defun gnus-unbuttonized-mime-type-p (type)
3800 "Say whether TYPE is to be unbuttonized."
3801 (unless gnus-inhibit-mime-unbuttonizing
3803 (let ((types gnus-unbuttonized-mime-types))
3805 (when (string-match (pop types) type)
3806 (throw 'found t)))))))
3808 (defun gnus-article-insert-newline ()
3809 "Insert a newline, but mark it as undeletable."
3810 (gnus-put-text-property
3811 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
3813 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
3814 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
3817 handle buffer-read-only from props begend not-pref)
3818 (save-window-excursion
3821 (narrow-to-region (car ibegend)
3824 (goto-char (car ibegend))
3827 (delete-region (point-min) (point-max))
3828 (mm-remove-parts handles))
3829 (setq begend (list (point-marker)))
3831 (unless (setq not-pref (cadr (member preferred ihandles)))
3832 (setq not-pref (car ihandles)))
3835 (not (gnus-unbuttonized-mime-type-p
3836 "multipart/alternative")))
3837 (gnus-add-text-properties
3840 (insert (format "%d. " id))
3844 (unless ,(not ibegend)
3845 (setq gnus-article-mime-handle-alist
3846 ',gnus-article-mime-handle-alist))
3847 (gnus-mime-display-alternative
3848 ',ihandles ',not-pref ',begend ,id))
3849 ,@(if (>= (string-to-number emacs-version) 21)
3850 nil ;; XEmacs doesn't care
3851 (list 'local-map gnus-mime-button-map))
3852 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3853 face ,gnus-article-button-face
3854 keymap ,gnus-mime-button-map
3857 (widget-convert-button 'link from (point)
3858 :action 'gnus-widget-press-button
3859 :button-keymap gnus-widget-button-keymap)
3861 (while (setq handle (pop handles))
3862 (gnus-add-text-properties
3865 (insert (format "(%c) %-18s"
3866 (if (equal handle preferred) ?* ? )
3867 (mm-handle-media-type handle)))
3871 (unless ,(not ibegend)
3872 (setq gnus-article-mime-handle-alist
3873 ',gnus-article-mime-handle-alist))
3874 (gnus-mime-display-alternative
3875 ',ihandles ',handle ',begend ,id))
3876 ,@(if (>= (string-to-number emacs-version) 21)
3877 nil ;; XEmacs doesn't care
3878 (list 'local-map gnus-mime-button-map))
3879 ,gnus-mouse-face-prop ,gnus-article-mouse-face
3880 face ,gnus-article-button-face
3881 keymap ,gnus-mime-button-map
3884 (widget-convert-button 'link from (point)
3885 :action 'gnus-widget-press-button
3886 :button-keymap gnus-widget-button-keymap)
3890 (if (stringp (car preferred))
3891 (gnus-display-mime preferred)
3892 (let ((mail-parse-charset gnus-newsgroup-charset)
3893 (mail-parse-ignored-charsets
3894 (save-excursion (set-buffer gnus-summary-buffer)
3895 gnus-newsgroup-ignored-charsets)))
3896 (mm-display-part preferred)
3900 (narrow-to-region (car begend) (point-max))
3902 nil (length gnus-article-mime-handle-alist)
3903 (gnus-article-mime-total-parts)
3904 (mm-handle-media-type handle))))))
3905 (goto-char (point-max))
3906 (setcdr begend (point-marker)))))
3908 (goto-char point))))
3910 (defun gnus-article-wash-status ()
3911 "Return a string which display status of article washing."
3913 (set-buffer gnus-article-buffer)
3914 (let ((cite (memq 'cite gnus-article-wash-types))
3915 (headers (memq 'headers gnus-article-wash-types))
3916 (boring (memq 'boring-headers gnus-article-wash-types))
3917 (pgp (memq 'pgp gnus-article-wash-types))
3918 (pem (memq 'pem gnus-article-wash-types))
3919 (signed (memq 'signed gnus-article-wash-types))
3920 (encrypted (memq 'encrypted gnus-article-wash-types))
3921 (signature (memq 'signature gnus-article-wash-types))
3922 (overstrike (memq 'overstrike gnus-article-wash-types))
3923 (emphasis (memq 'emphasis gnus-article-wash-types)))
3924 (format "%c%c%c%c%c%c"
3926 (if (or headers boring) ?h ? )
3927 (if (or pgp pem signed encrypted) ?p ? )
3928 (if signature ?s ? )
3929 (if overstrike ?o ? )
3930 (if emphasis ?e ? )))))
3932 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
3934 (defun gnus-article-maybe-hide-headers ()
3935 "Hide unwanted headers if `gnus-have-all-headers' is nil.
3936 Provided for backwards compatibility."
3937 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
3938 (not (save-excursion (set-buffer gnus-summary-buffer)
3939 gnus-have-all-headers)))
3940 (not gnus-inhibit-hiding))
3941 (gnus-article-hide-headers)))
3945 (defun gnus-output-to-file (file-name)
3946 "Append the current article to a file named FILE-NAME."
3947 (let ((artbuf (current-buffer)))
3949 (insert-buffer-substring artbuf)
3950 ;; Append newline at end of the buffer as separator, and then
3952 (goto-char (point-max))
3954 (mm-append-to-file (point-min) (point-max) file-name)
3957 (defun gnus-narrow-to-page (&optional arg)
3958 "Narrow the article buffer to a page.
3959 If given a numerical ARG, move forward ARG pages."
3961 (setq arg (if arg (prefix-numeric-value arg) 0))
3963 (set-buffer gnus-article-buffer)
3964 (goto-char (point-min))
3966 ;; Remove any old next/prev buttons.
3967 (when (gnus-visual-p 'page-marker)
3968 (let ((buffer-read-only nil))
3969 (gnus-remove-text-with-property 'gnus-prev)
3970 (gnus-remove-text-with-property 'gnus-next)))
3973 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
3975 (re-search-forward page-delimiter nil 'move arg)))
3976 (goto-char (match-end 0)))
3979 (if (re-search-forward page-delimiter nil 'move)
3982 (when (and (gnus-visual-p 'page-marker)
3983 (not (= (point-min) 1)))
3985 (goto-char (point-min))
3986 (gnus-insert-prev-page-button)))
3987 (when (and (gnus-visual-p 'page-marker)
3988 (< (+ (point-max) 2) (buffer-size)))
3990 (goto-char (point-max))
3991 (gnus-insert-next-page-button)))))
3993 ;; Article mode commands
3995 (defun gnus-article-goto-next-page ()
3996 "Show the next page of the article."
3998 (when (gnus-article-next-page)
3999 (goto-char (point-min))
4000 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4002 (defun gnus-article-goto-prev-page ()
4003 "Show the next page of the article."
4005 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4006 (gnus-article-prev-page nil)))
4008 (defun gnus-article-next-page (&optional lines)
4009 "Show the next page of the current article.
4010 If end of article, return non-nil. Otherwise return nil.
4011 Argument LINES specifies lines to be scrolled up."
4013 (move-to-window-line -1)
4016 (and (pos-visible-in-window-p) ;Not continuation line.
4018 ;; Nothing in this page.
4019 (if (or (not gnus-page-broken)
4022 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4024 (gnus-narrow-to-page 1) ;Go to next page.
4026 ;; More in this page.
4027 (let ((scroll-in-place nil))
4031 ;; Long lines may cause an end-of-buffer error.
4032 (goto-char (point-max)))))
4033 (move-to-window-line 0)
4036 (defun gnus-article-prev-page (&optional lines)
4037 "Show previous page of current article.
4038 Argument LINES specifies lines to be scrolled down."
4040 (move-to-window-line 0)
4041 (if (and gnus-page-broken
4043 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4045 (gnus-narrow-to-page -1) ;Go to previous page.
4046 (goto-char (point-max))
4048 (let ((scroll-in-place nil))
4052 (beginning-of-buffer
4053 (goto-char (point-min))))
4054 (move-to-window-line 0)))))
4056 (defun gnus-article-refer-article ()
4057 "Read article specified by message-id around point."
4059 (let ((point (point)))
4060 (search-forward ">" nil t) ;Move point to end of "<....>".
4061 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4062 (let ((message-id (match-string 1)))
4064 (set-buffer gnus-summary-buffer)
4065 (gnus-summary-refer-article message-id))
4067 (error "No references around point"))))
4069 (defun gnus-article-show-summary ()
4070 "Reconfigure windows to show summary buffer."
4072 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4073 (error "There is no summary buffer for this article buffer")
4074 (gnus-article-set-globals)
4075 (gnus-configure-windows 'article)
4076 (gnus-summary-goto-subject gnus-current-article)
4077 (gnus-summary-position-point)))
4079 (defun gnus-article-describe-briefly ()
4080 "Describe article mode commands briefly."
4082 (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")))
4084 (defun gnus-article-summary-command ()
4085 "Execute the last keystroke in the summary buffer."
4087 (let ((obuf (current-buffer))
4088 (owin (current-window-configuration))
4090 (switch-to-buffer gnus-article-current-summary 'norecord)
4091 (setq func (lookup-key (current-local-map) (this-command-keys)))
4092 (call-interactively func)
4094 (set-window-configuration owin)
4095 (set-window-point (get-buffer-window (current-buffer)) (point))))
4097 (defun gnus-article-summary-command-nosave ()
4098 "Execute the last keystroke in the summary buffer."
4101 (pop-to-buffer gnus-article-current-summary 'norecord)
4102 (setq func (lookup-key (current-local-map) (this-command-keys)))
4103 (call-interactively func)))
4105 (defun gnus-article-check-buffer ()
4106 "Beep if not in an article buffer."
4107 (unless (equal major-mode 'gnus-article-mode)
4108 (error "Command invoked outside of a Gnus article buffer")))
4110 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4111 "Read a summary buffer key sequence and execute it from the article buffer."
4113 (gnus-article-check-buffer)
4115 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4116 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4117 "=" "^" "\M-^" "|"))
4123 '("n" "Gn" "p" "Gp"))
4126 (set-buffer gnus-article-current-summary)
4127 (let (gnus-pick-mode)
4128 (push (or key last-command-event) unread-command-events)
4129 (setq keys (if (featurep 'xemacs)
4130 (events-to-keys (read-key-sequence nil))
4131 (read-key-sequence nil)))))
4135 (if (or (member keys nosaves)
4136 (member keys nosave-but-article)
4137 (member keys nosave-in-article))
4139 (save-window-excursion
4140 (pop-to-buffer gnus-article-current-summary 'norecord)
4141 ;; We disable the pick minor mode commands.
4142 (let (gnus-pick-mode)
4143 (setq func (lookup-key (current-local-map) keys))))
4147 (unless (member keys nosave-in-article)
4148 (set-buffer gnus-article-current-summary))
4149 (call-interactively func)
4150 (setq new-sum-point (point)))
4151 (when (member keys nosave-but-article)
4152 (pop-to-buffer gnus-article-buffer 'norecord)))
4153 ;; These commands should restore window configuration.
4154 (let ((obuf (current-buffer))
4155 (owin (current-window-configuration))
4157 (summary gnus-article-current-summary)
4158 func in-buffer selected)
4159 (if not-restore-window
4160 (pop-to-buffer summary 'norecord)
4161 (switch-to-buffer summary 'norecord))
4162 (setq in-buffer (current-buffer))
4163 ;; We disable the pick minor mode commands.
4164 (if (and (setq func (let (gnus-pick-mode)
4165 (lookup-key (current-local-map) keys)))
4168 (call-interactively func)
4169 (setq new-sum-point (point))
4170 (when (eq in-buffer (current-buffer))
4171 (setq selected (gnus-summary-select-article))
4173 (unless not-restore-window
4174 (set-window-configuration owin))
4175 (when (eq selected 'old)
4177 (set-window-start (get-buffer-window (current-buffer))
4179 (set-window-point (get-buffer-window (current-buffer))
4181 (let ((win (get-buffer-window gnus-article-current-summary)))
4183 (set-window-point win new-sum-point)))) )
4184 (switch-to-buffer gnus-article-buffer)
4187 (defun gnus-article-describe-key (key)
4188 "Display documentation of the function invoked by KEY. KEY is a string."
4189 (interactive "kDescribe key: ")
4190 (gnus-article-check-buffer)
4191 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4193 (set-buffer gnus-article-current-summary)
4194 (let (gnus-pick-mode)
4195 (push (elt key 0) unread-command-events)
4196 (setq key (if (featurep 'xemacs)
4197 (events-to-keys (read-key-sequence "Describe key: "))
4198 (read-key-sequence "Describe key: "))))
4200 (describe-key key)))
4202 (defun gnus-article-describe-key-briefly (key &optional insert)
4203 "Display documentation of the function invoked by KEY. KEY is a string."
4204 (interactive "kDescribe key: \nP")
4205 (gnus-article-check-buffer)
4206 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4208 (set-buffer gnus-article-current-summary)
4209 (let (gnus-pick-mode)
4210 (push (elt key 0) unread-command-events)
4211 (setq key (if (featurep 'xemacs)
4212 (events-to-keys (read-key-sequence "Describe key: "))
4213 (read-key-sequence "Describe key: "))))
4214 (describe-key-briefly key insert))
4215 (describe-key-briefly key insert)))
4217 (defun gnus-article-hide (&optional arg force)
4218 "Hide all the gruft in the current article.
4219 This means that PGP stuff, signatures, cited text and (some)
4220 headers will be hidden.
4221 If given a prefix, show the hidden text instead."
4222 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4223 (gnus-article-hide-headers arg)
4224 (gnus-article-hide-list-identifiers arg)
4225 (gnus-article-hide-pgp arg)
4226 (gnus-article-hide-citation-maybe arg force)
4227 (gnus-article-hide-signature arg))
4229 (defun gnus-article-maybe-highlight ()
4230 "Do some article highlighting if article highlighting is requested."
4231 (when (gnus-visual-p 'article-highlight 'highlight)
4232 (gnus-article-highlight-some)))
4234 (defun gnus-check-group-server ()
4235 ;; Make sure the connection to the server is alive.
4236 (unless (gnus-server-opened
4237 (gnus-find-method-for-group gnus-newsgroup-name))
4238 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4239 (gnus-request-group gnus-newsgroup-name t)))
4241 (defun gnus-request-article-this-buffer (article group)
4242 "Get an article and insert it into this buffer."
4243 (let (do-update-line sparse-header)
4247 (gnus-kill-all-overlays)
4248 (setq group (or group gnus-newsgroup-name))
4250 ;; Using `gnus-request-article' directly will insert the article into
4251 ;; `nntp-server-buffer' - so we'll save some time by not having to
4252 ;; copy it from the server buffer into the article buffer.
4254 ;; We only request an article by message-id when we do not have the
4255 ;; headers for it, so we'll have to get those.
4256 (when (stringp article)
4257 (gnus-read-header article))
4259 ;; If the article number is negative, that means that this article
4260 ;; doesn't belong in this newsgroup (possibly), so we find its
4261 ;; message-id and request it by id instead of number.
4262 (when (and (numberp article)
4264 (get-buffer gnus-summary-buffer)
4265 (gnus-buffer-exists-p gnus-summary-buffer))
4267 (set-buffer gnus-summary-buffer)
4268 (let ((header (gnus-summary-article-header article)))
4271 ((memq article gnus-newsgroup-sparse)
4272 ;; This is a sparse gap article.
4273 (setq do-update-line article)
4274 (setq article (mail-header-id header))
4275 (setq sparse-header (gnus-read-header article))
4276 (setq gnus-newsgroup-sparse
4277 (delq article gnus-newsgroup-sparse)))
4279 ;; It's a real article.
4280 (setq article (mail-header-id header)))
4282 ;; It is an extracted pseudo-article.
4283 (setq article 'pseudo)
4284 (gnus-request-pseudo-article header))))
4286 (let ((method (gnus-find-method-for-group
4287 gnus-newsgroup-name)))
4288 (when (and (eq (car method) 'nneething)
4290 (let ((dir (expand-file-name
4291 (mail-header-subject header)
4292 (file-name-as-directory
4293 (or (cadr (assq 'nneething-address method))
4295 (when (file-directory-p dir)
4296 (setq article 'nneething)
4297 (gnus-group-enter-directory dir))))))))
4300 ;; Refuse to select canceled articles.
4301 ((and (numberp article)
4303 (get-buffer gnus-summary-buffer)
4304 (gnus-buffer-exists-p gnus-summary-buffer)
4305 (eq (cdr (save-excursion
4306 (set-buffer gnus-summary-buffer)
4307 (assq article gnus-newsgroup-reads)))
4308 gnus-canceled-mark))
4310 ;; We first check `gnus-original-article-buffer'.
4311 ((and (get-buffer gnus-original-article-buffer)
4314 (set-buffer gnus-original-article-buffer)
4315 (and (equal (car gnus-original-article) group)
4316 (eq (cdr gnus-original-article) article))))
4317 (insert-buffer-substring gnus-original-article-buffer)
4319 ;; Check the backlog.
4320 ((and gnus-keep-backlog
4321 (gnus-backlog-request-article group article (current-buffer)))
4323 ;; Check asynchronous pre-fetch.
4324 ((gnus-async-request-fetched-article group article (current-buffer))
4325 (gnus-async-prefetch-next group article gnus-summary-buffer)
4326 (when (and (numberp article) gnus-keep-backlog)
4327 (gnus-backlog-enter-article group article (current-buffer)))
4330 ((and gnus-use-cache
4332 (gnus-cache-request-article article group))
4334 ;; Get the article and put into the article buffer.
4335 ((or (stringp article)
4337 (let ((gnus-override-method gnus-override-method)
4338 (methods (and (stringp article)
4339 gnus-refer-article-method))
4341 (buffer-read-only nil))
4342 (if (or (not (listp methods))
4343 (and (symbolp (car methods))
4344 (assq (car methods) nnoo-definition-alist)))
4345 (setq methods (list methods)))
4346 (when (and (null gnus-override-method)
4348 (setq gnus-override-method (pop methods)))
4350 (when (eq gnus-override-method 'current)
4351 (setq gnus-override-method gnus-current-select-method))
4353 (gnus-kill-all-overlays)
4354 (let ((gnus-newsgroup-name group))
4355 (gnus-check-group-server))
4356 (when (gnus-request-article article group (current-buffer))
4357 (when (numberp article)
4358 (gnus-async-prefetch-next group article
4359 gnus-summary-buffer)
4360 (when gnus-keep-backlog
4361 (gnus-backlog-enter-article
4362 group article (current-buffer))))
4363 (setq result 'article))
4366 (setq gnus-override-method (pop methods))
4367 (setq result 'done))))
4368 (and (eq result 'article) 'article)))
4372 ;; Associate this article with the current summary buffer.
4373 (setq gnus-article-current-summary gnus-summary-buffer)
4375 ;; Take the article from the original article buffer
4376 ;; and place it in the buffer it's supposed to be in.
4377 (when (and (get-buffer gnus-article-buffer)
4378 (equal (buffer-name (current-buffer))
4379 (buffer-name (get-buffer gnus-article-buffer))))
4381 (if (get-buffer gnus-original-article-buffer)
4382 (set-buffer gnus-original-article-buffer)
4383 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4384 (buffer-disable-undo)
4385 (setq major-mode 'gnus-original-article-mode)
4386 (setq buffer-read-only t))
4387 (let (buffer-read-only)
4389 (insert-buffer-substring gnus-article-buffer))
4390 (setq gnus-original-article (cons group article)))
4393 (run-hooks 'gnus-article-decode-hook)
4394 ;; Mark article as decoded or not.
4395 (setq gnus-article-decoded-p gnus-article-decode-hook))
4397 ;; Update sparse articles.
4398 (when (and do-update-line
4399 (or (numberp article)
4401 (let ((buf (current-buffer)))
4402 (set-buffer gnus-summary-buffer)
4403 (gnus-summary-update-article do-update-line sparse-header)
4404 (gnus-summary-goto-subject do-update-line nil t)
4405 (set-window-point (get-buffer-window (current-buffer) t)
4407 (set-buffer buf))))))
4413 (defcustom gnus-article-edit-mode-hook nil
4414 "Hook run in article edit mode buffers."
4415 :group 'gnus-article-various
4418 (defvar gnus-article-edit-done-function nil)
4420 (defvar gnus-article-edit-mode-map nil)
4422 ;; Should we be using derived.el for this?
4423 (unless gnus-article-edit-mode-map
4424 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4425 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4427 (gnus-define-keys gnus-article-edit-mode-map
4428 "\C-c\C-c" gnus-article-edit-done
4429 "\C-c\C-k" gnus-article-edit-exit)
4431 (gnus-define-keys (gnus-article-edit-wash-map
4432 "\C-c\C-w" gnus-article-edit-mode-map)
4433 "f" gnus-article-edit-full-stops))
4435 (defun gnus-article-edit-mode ()
4436 "Major mode for editing articles.
4437 This is an extended text-mode.
4439 \\{gnus-article-edit-mode-map}"
4441 (setq major-mode 'gnus-article-edit-mode)
4442 (setq mode-name "Article Edit")
4443 (use-local-map gnus-article-edit-mode-map)
4444 (make-local-variable 'gnus-article-edit-done-function)
4445 (make-local-variable 'gnus-prev-winconf)
4446 (setq buffer-read-only nil)
4447 (buffer-enable-undo)
4449 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4451 (defun gnus-article-edit (&optional force)
4452 "Edit the current article.
4453 This will have permanent effect only in mail groups.
4454 If FORCE is non-nil, allow editing of articles even in read-only
4457 (when (and (not force)
4458 (gnus-group-read-only-p))
4459 (error "The current newsgroup does not support article editing"))
4460 (gnus-article-date-original)
4461 (gnus-article-edit-article
4463 `(lambda (no-highlight)
4465 (gnus-summary-edit-article-done
4466 ,(or (mail-header-references gnus-current-headers) "")
4467 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4469 (defun gnus-article-edit-article (start-func exit-func)
4470 "Start editing the contents of the current article buffer."
4471 (let ((winconf (current-window-configuration)))
4472 (set-buffer gnus-article-buffer)
4473 (gnus-article-edit-mode)
4474 (funcall start-func)
4475 (gnus-configure-windows 'edit-article)
4476 (setq gnus-article-edit-done-function exit-func)
4477 (setq gnus-prev-winconf winconf)
4478 (gnus-message 6 "C-c C-c to end edits")))
4480 (defun gnus-article-edit-done (&optional arg)
4481 "Update the article edits and exit."
4483 (let ((func gnus-article-edit-done-function)
4484 (buf (current-buffer))
4485 (start (window-start)))
4486 (gnus-article-edit-exit)
4489 (let ((buffer-read-only nil))
4491 ;; The cache and backlog have to be flushed somewhat.
4492 (when gnus-keep-backlog
4493 (gnus-backlog-remove-article
4494 (car gnus-article-current) (cdr gnus-article-current)))
4495 ;; Flush original article as well.
4497 (when (get-buffer gnus-original-article-buffer)
4498 (set-buffer gnus-original-article-buffer)
4499 (setq gnus-original-article nil)))
4500 (when gnus-use-cache
4501 (gnus-cache-update-article
4502 (car gnus-article-current) (cdr gnus-article-current))))
4504 (set-window-start (get-buffer-window buf) start)
4505 (set-window-point (get-buffer-window buf) (point))))
4507 (defun gnus-article-edit-exit ()
4508 "Exit the article editing without updating."
4510 ;; We remove all text props from the article buffer.
4511 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4512 (curbuf (current-buffer))
4514 (window-start (window-start)))
4517 (let ((winconf gnus-prev-winconf))
4519 (set-window-configuration winconf)
4520 ;; Tippy-toe some to make sure that point remains where it was.
4521 (save-current-buffer
4523 (set-window-start (get-buffer-window (current-buffer)) window-start)
4526 (defun gnus-article-edit-full-stops ()
4527 "Interactively repair spacing at end of sentences."
4530 (goto-char (point-min))
4531 (search-forward-regexp "^$" nil t)
4532 (let ((case-fold-search nil))
4533 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4536 ;;; Article highlights
4539 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4541 ;;; Internal Variables:
4543 (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\\)\\)"
4544 "Regular expression that matches URLs."
4545 :group 'gnus-article-buttons
4548 (defcustom gnus-button-alist
4549 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4550 0 t gnus-button-message-id 2)
4551 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4552 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4554 gnus-button-fetch-group 4)
4555 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4556 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4557 t gnus-button-message-id 3)
4558 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4559 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4560 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4561 ;; This is how URLs _should_ be embedded in text...
4562 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4564 (,gnus-button-url-regexp 0 t browse-url 0))
4565 "*Alist of regexps matching buttons in article bodies.
4567 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4568 REGEXP: is the string matching text around the button,
4569 BUTTON: is the number of the regexp grouping actually matching the button,
4570 FORM: is a lisp expression which must eval to true for the button to
4572 CALLBACK: is the function to call when the user push this button, and each
4573 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4575 CALLBACK can also be a variable, in that case the value of that
4576 variable it the real callback function."
4577 :group 'gnus-article-buttons
4578 :type '(repeat (list regexp
4579 (integer :tag "Button")
4581 (function :tag "Callback")
4584 (integer :tag "Regexp group")))))
4586 (defcustom gnus-header-button-alist
4587 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4588 0 t gnus-button-message-id 0)
4589 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4590 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4591 0 t gnus-button-mailto 0)
4592 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4593 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4594 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4595 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4596 gnus-button-message-id 3))
4597 "*Alist of headers and regexps to match buttons in article heads.
4599 This alist is very similar to `gnus-button-alist', except that each
4600 alist has an additional HEADER element first in each entry:
4602 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4604 HEADER is a regexp to match a header. For a fuller explanation, see
4605 `gnus-button-alist'."
4606 :group 'gnus-article-buttons
4607 :group 'gnus-article-headers
4608 :type '(repeat (list (regexp :tag "Header")
4610 (integer :tag "Button")
4612 (function :tag "Callback")
4615 (integer :tag "Regexp group")))))
4617 (defvar gnus-button-regexp nil)
4618 (defvar gnus-button-marker-list nil)
4619 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4621 (defvar gnus-button-last nil)
4622 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4626 (defun gnus-article-push-button (event)
4627 "Check text under the mouse pointer for a callback function.
4628 If the text under the mouse pointer has a `gnus-callback' property,
4629 call it with the value of the `gnus-data' text property."
4631 (set-buffer (window-buffer (posn-window (event-start event))))
4632 (let* ((pos (posn-point (event-start event)))
4633 (data (get-text-property pos 'gnus-data))
4634 (fun (get-text-property pos 'gnus-callback)))
4637 (funcall fun data))))
4639 (defun gnus-article-press-button ()
4640 "Check text at point for a callback function.
4641 If the text at point has a `gnus-callback' property,
4642 call it with the value of the `gnus-data' text property."
4644 (let* ((data (get-text-property (point) 'gnus-data))
4645 (fun (get-text-property (point) 'gnus-callback)))
4647 (funcall fun data))))
4649 (defun gnus-article-highlight (&optional force)
4650 "Highlight current article.
4651 This function calls `gnus-article-highlight-headers',
4652 `gnus-article-highlight-citation',
4653 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
4654 do the highlighting. See the documentation for those functions."
4655 (interactive (list 'force))
4656 (gnus-article-highlight-headers)
4657 (gnus-article-highlight-citation force)
4658 (gnus-article-highlight-signature)
4659 (gnus-article-add-buttons force)
4660 (gnus-article-add-buttons-to-head))
4662 (defun gnus-article-highlight-some (&optional force)
4663 "Highlight current article.
4664 This function calls `gnus-article-highlight-headers',
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-signature)
4670 (gnus-article-add-buttons))
4672 (defun gnus-article-highlight-headers ()
4673 "Highlight article headers as specified by `gnus-header-face-alist'."
4676 (set-buffer gnus-article-buffer)
4678 (let ((alist gnus-header-face-alist)
4679 (buffer-read-only nil)
4680 (case-fold-search t)
4681 (inhibit-point-motion-hooks t)
4682 entry regexp header-face field-face from hpoints fpoints)
4683 (article-narrow-to-head)
4684 (while (setq entry (pop alist))
4685 (goto-char (point-min))
4686 (setq regexp (concat "^\\("
4687 (if (string-equal "" (nth 0 entry))
4691 header-face (nth 1 entry)
4692 field-face (nth 2 entry))
4693 (while (and (re-search-forward regexp nil t)
4697 (unless (search-forward ":" nil t)
4699 (when (and header-face
4700 (not (memq (point) hpoints)))
4701 (push (point) hpoints)
4702 (gnus-put-text-property from (point) 'face header-face))
4703 (when (and field-face
4704 (not (memq (setq from (point)) fpoints)))
4706 (if (re-search-forward "^[^ \t]" nil t)
4708 (goto-char (point-max)))
4709 (gnus-put-text-property from (point) 'face field-face))))))))
4711 (defun gnus-article-highlight-signature ()
4712 "Highlight the signature in an article.
4713 It does this by highlighting everything after
4714 `gnus-signature-separator' using `gnus-signature-face'."
4717 (set-buffer gnus-article-buffer)
4718 (let ((buffer-read-only nil)
4719 (inhibit-point-motion-hooks t))
4721 (when (and gnus-signature-face
4722 (gnus-article-narrow-to-signature))
4723 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
4724 'face gnus-signature-face)
4726 (gnus-article-search-signature)
4727 (let ((start (match-beginning 0))
4728 (end (set-marker (make-marker) (1+ (match-end 0)))))
4729 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
4732 (defun gnus-button-in-region-p (b e prop)
4733 "Say whether PROP exists in the region."
4734 (text-property-not-all b e prop nil))
4736 (defun gnus-article-add-buttons (&optional force)
4737 "Find external references in the article and make buttons of them.
4738 \"External references\" are things like Message-IDs and URLs, as
4739 specified by `gnus-button-alist'."
4740 (interactive (list 'force))
4742 (set-buffer gnus-article-buffer)
4743 (let ((buffer-read-only nil)
4744 (inhibit-point-motion-hooks t)
4745 (case-fold-search t)
4746 (alist gnus-button-alist)
4748 ;; Remove all old markers.
4749 (let (marker entry new-list)
4750 (while (setq marker (pop gnus-button-marker-list))
4751 (if (or (< marker (point-min)) (>= marker (point-max)))
4752 (push marker new-list)
4754 (when (setq entry (gnus-button-entry))
4755 (put-text-property (match-beginning (nth 1 entry))
4756 (match-end (nth 1 entry))
4757 'gnus-callback nil))
4758 (set-marker marker nil)))
4759 (setq gnus-button-marker-list new-list))
4760 ;; We skip the headers.
4763 (while (setq entry (pop alist))
4764 (setq regexp (car entry))
4766 (while (re-search-forward regexp nil t)
4767 (let* ((start (and entry (match-beginning (nth 1 entry))))
4768 (end (and entry (match-end (nth 1 entry))))
4769 (from (match-beginning 0)))
4770 (when (and (or (eq t (nth 2 entry))
4771 (eval (nth 2 entry)))
4772 (not (gnus-button-in-region-p
4773 start end 'gnus-callback)))
4774 ;; That optional form returned non-nil, so we add the
4776 (gnus-article-add-button
4777 start end 'gnus-button-push
4778 (car (push (set-marker (make-marker) from)
4779 gnus-button-marker-list))))))))))
4781 ;; Add buttons to the head of an article.
4782 (defun gnus-article-add-buttons-to-head ()
4783 "Add buttons to the head of the article."
4786 (set-buffer gnus-article-buffer)
4788 (let ((buffer-read-only nil)
4789 (inhibit-point-motion-hooks t)
4790 (case-fold-search t)
4791 (alist gnus-header-button-alist)
4793 (article-narrow-to-head)
4795 ;; Each alist entry.
4796 (setq entry (car alist)
4798 (goto-char (point-min))
4799 (while (re-search-forward (car entry) nil t)
4800 ;; Each header matching the entry.
4801 (setq beg (match-beginning 0))
4802 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
4803 (match-beginning 0))
4806 (while (re-search-forward (nth 1 entry) end t)
4807 ;; Each match within a header.
4808 (let* ((entry (cdr entry))
4809 (start (match-beginning (nth 1 entry)))
4810 (end (match-end (nth 1 entry)))
4811 (form (nth 2 entry)))
4812 (goto-char (match-end 0))
4814 (gnus-article-add-button
4815 start end (nth 3 entry)
4816 (buffer-substring (match-beginning (nth 4 entry))
4817 (match-end (nth 4 entry)))))))
4818 (goto-char end)))))))
4820 ;;; External functions:
4822 (defun gnus-article-add-button (from to fun &optional data)
4823 "Create a button between FROM and TO with callback FUN and data DATA."
4824 (when gnus-article-button-face
4825 (gnus-overlay-put (gnus-make-overlay from to)
4826 'face gnus-article-button-face))
4827 (gnus-add-text-properties
4829 (nconc (and gnus-article-mouse-face
4830 (list gnus-mouse-face-prop gnus-article-mouse-face))
4831 (list 'gnus-callback fun)
4832 (and data (list 'gnus-data data))))
4833 (widget-convert-button 'link from to :action 'gnus-widget-press-button
4834 :button-keymap gnus-widget-button-keymap))
4836 ;;; Internal functions:
4838 (defun gnus-article-set-globals ()
4840 (set-buffer gnus-summary-buffer)
4841 (gnus-set-global-variables)))
4843 (defun gnus-signature-toggle (end)
4845 (set-buffer gnus-article-buffer)
4846 (let ((buffer-read-only nil)
4847 (inhibit-point-motion-hooks t))
4848 (if (text-property-any end (point-max) 'article-type 'signature)
4849 (gnus-remove-text-properties-when
4850 'article-type 'signature end (point-max)
4851 (cons 'article-type (cons 'signature
4852 gnus-hidden-properties)))
4853 (gnus-add-text-properties-when
4854 'article-type nil end (point-max)
4855 (cons 'article-type (cons 'signature
4856 gnus-hidden-properties)))))))
4858 (defun gnus-button-entry ()
4859 ;; Return the first entry in `gnus-button-alist' matching this place.
4860 (let ((alist gnus-button-alist)
4863 (setq entry (pop alist))
4864 (if (looking-at (car entry))
4869 (defun gnus-button-push (marker)
4870 ;; Push button starting at MARKER.
4873 (let* ((entry (gnus-button-entry))
4874 (inhibit-point-motion-hooks t)
4876 (args (mapcar (lambda (group)
4877 (let ((string (match-string group)))
4878 (gnus-set-text-properties
4879 0 (length string) nil string)
4886 (fboundp (symbol-value fun)))
4887 (apply (symbol-value fun) args))
4889 (gnus-message 1 "You must define `%S' to use this button"
4890 (cons fun args)))))))
4892 (defun gnus-button-message-id (message-id)
4895 (set-buffer gnus-summary-buffer)
4896 (gnus-summary-refer-article message-id)))
4898 (defun gnus-button-fetch-group (address)
4899 "Fetch GROUP specified by ADDRESS."
4900 (if (not (string-match "[:/]" address))
4901 ;; This is just a simple group url.
4902 (gnus-group-read-ephemeral-group address gnus-select-method)
4903 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
4905 (error "Can't parse %s" address)
4906 (gnus-group-read-ephemeral-group
4907 (match-string 4 address)
4908 `(nntp ,(match-string 1 address)
4909 (nntp-address ,(match-string 1 address))
4910 (nntp-port-number ,(if (match-end 3)
4911 (match-string 3 address)
4914 (defun gnus-url-parse-query-string (query &optional downcase)
4915 (let (retval pairs cur key val)
4916 (setq pairs (split-string query "&"))
4918 (setq cur (car pairs)
4920 (if (not (string-match "=" cur))
4922 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
4923 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
4925 (setq key (downcase key)))
4926 (setq cur (assoc key retval))
4928 (setcdr cur (cons val (cdr cur)))
4929 (setq retval (cons (list key val) retval)))))
4932 (defun gnus-url-unhex (x)
4939 (defun gnus-url-unhex-string (str &optional allow-newlines)
4940 "Remove %XXX embedded spaces, etc in a url.
4941 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
4942 decoding of carriage returns and line feeds in the string, which is normally
4943 forbidden in URL encoding."
4944 (setq str (or str ""))
4946 (case-fold-search t))
4947 (while (string-match "%[0-9a-f][0-9a-f]" str)
4948 (let* ((start (match-beginning 0))
4949 (ch1 (gnus-url-unhex (elt str (+ start 1))))
4951 (gnus-url-unhex (elt str (+ start 2))))))
4953 tmp (substring str 0 start)
4956 (char-to-string code))
4957 ((or (= code ?\n) (= code ?\r))
4959 (t (char-to-string code))))
4960 str (substring str (match-end 0)))))
4961 (setq tmp (concat tmp str))
4964 (defun gnus-url-mailto (url)
4965 ;; Send mail to someone
4966 (when (string-match "mailto:/*\\(.*\\)" url)
4967 (setq url (substring url (match-beginning 1) nil)))
4968 (let (to args subject func)
4969 (if (string-match (regexp-quote "?") url)
4970 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
4971 args (gnus-url-parse-query-string
4972 (substring url (match-end 0) nil) t))
4973 (setq to (gnus-url-unhex-string url)))
4974 (setq args (cons (list "to" to) args)
4975 subject (cdr-safe (assoc "subject" args)))
4978 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
4981 (message-position-on-field (caar args)))
4982 (insert (mapconcat 'identity (cdar args) ", "))
4983 (setq args (cdr args)))
4986 (message-goto-subject))))
4988 (defun gnus-button-mailto (address)
4990 (set-buffer (gnus-copy-article-buffer))
4991 (message-reply address))
4993 (defalias 'gnus-button-reply 'message-reply)
4995 (defun gnus-button-embedded-url (address)
4996 "Activate ADDRESS with `browse-url'."
4997 (browse-url (gnus-strip-whitespace address)))
4999 ;;; Next/prev buttons in the article buffer.
5001 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5002 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5004 (defvar gnus-prev-page-map nil)
5005 (unless gnus-prev-page-map
5006 (setq gnus-prev-page-map (make-sparse-keymap))
5007 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5008 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5010 (defun gnus-insert-prev-page-button ()
5011 (let ((buffer-read-only nil))
5013 gnus-prev-page-line-format nil
5014 `(gnus-prev t local-map ,gnus-prev-page-map
5015 gnus-callback gnus-article-button-prev-page
5016 article-type annotation))))
5018 (defvar gnus-next-page-map nil)
5019 (unless gnus-next-page-map
5020 (setq gnus-next-page-map (make-keymap))
5021 (suppress-keymap gnus-prev-page-map)
5022 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5023 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5025 (defun gnus-button-next-page ()
5026 "Go to the next page."
5028 (let ((win (selected-window)))
5029 (select-window (get-buffer-window gnus-article-buffer t))
5030 (gnus-article-next-page)
5031 (select-window win)))
5033 (defun gnus-button-prev-page ()
5034 "Go to the prev page."
5036 (let ((win (selected-window)))
5037 (select-window (get-buffer-window gnus-article-buffer t))
5038 (gnus-article-prev-page)
5039 (select-window win)))
5041 (defun gnus-insert-next-page-button ()
5042 (let ((buffer-read-only nil))
5043 (gnus-eval-format gnus-next-page-line-format nil
5045 t local-map ,gnus-next-page-map
5046 gnus-callback gnus-article-button-next-page
5047 article-type annotation))))
5049 (defun gnus-article-button-next-page (arg)
5050 "Go to the next page."
5052 (let ((win (selected-window)))
5053 (select-window (get-buffer-window gnus-article-buffer t))
5054 (gnus-article-next-page)
5055 (select-window win)))
5057 (defun gnus-article-button-prev-page (arg)
5058 "Go to the prev page."
5060 (let ((win (selected-window)))
5061 (select-window (get-buffer-window gnus-article-buffer t))
5062 (gnus-article-prev-page)
5063 (select-window win)))
5065 (defvar gnus-decode-header-methods
5066 '(mail-decode-encoded-word-region)
5067 "List of methods used to decode headers.
5069 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5070 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5071 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5072 whose names match REGEXP.
5075 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5076 mail-decode-encoded-word-region
5077 (\"chinese\" . rfc1843-decode-region))
5080 (defvar gnus-decode-header-methods-cache nil)
5082 (defun gnus-multi-decode-header (start end)
5083 "Apply the functions from `gnus-encoded-word-methods' that match."
5084 (unless (and gnus-decode-header-methods-cache
5085 (eq gnus-newsgroup-name
5086 (car gnus-decode-header-methods-cache)))
5087 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5090 (nconc gnus-decode-header-methods-cache (list x))
5091 (if (and gnus-newsgroup-name
5092 (string-match (car x) gnus-newsgroup-name))
5093 (nconc gnus-decode-header-methods-cache
5095 gnus-decode-header-methods))
5096 (let ((xlist gnus-decode-header-methods-cache))
5099 (narrow-to-region start end)
5101 (funcall (pop xlist) (point-min) (point-max))))))
5104 ;;; Treatment top-level handling.
5107 (defun gnus-treat-article (condition &optional part-number total-parts type)
5108 (let ((length (- (point-max) (point-min)))
5109 (alist gnus-treatment-function-alist)
5110 (article-goto-body-goes-to-point-min-p t)
5114 (let ((list gnus-article-treat-types))
5116 (when (string-match (pop list) type)
5117 (throw 'found t)))))))
5118 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5120 (gnus-run-hooks 'gnus-part-display-hook)
5121 (while (setq elem (pop alist))
5124 (if (gnus-buffer-live-p gnus-summary-buffer)
5125 (set-buffer gnus-summary-buffer))
5126 (symbol-value (car elem))))
5127 (when (and (or (consp val)
5129 (gnus-treat-predicate val)
5130 (or (not (get (car elem) 'highlight))
5133 (funcall (cadr elem)))))))
5135 ;; Dynamic variables.
5137 (defvar part-number)
5138 (defvar total-parts)
5143 (defun gnus-treat-predicate (val)
5148 (stringp (car val)))
5149 (apply 'gnus-or (mapcar `(lambda (s)
5150 (string-match s ,(or gnus-newsgroup-name "")))
5153 (let ((pred (pop val)))
5156 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5158 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5160 (not (gnus-treat-predicate (car val))))
5162 (equal (car val) type))
5164 (error "%S is not a valid predicate" pred)))))
5172 (eq part-number total-parts))
5176 (error "%S is not a valid value" val))))
5178 (defun gnus-article-encrypt-body (protocol &optional n)
5179 "Encrypt the article body."
5182 (or gnus-article-encrypt-protocol
5183 (completing-read "Encrypt protocol: "
5184 gnus-article-encrypt-protocol-alist
5186 current-prefix-arg))
5187 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5189 (error (format "Can't find the encrypt protocol %s" protocol)))
5190 (if (equal gnus-newsgroup-name "nndraft:drafts")
5191 (error "Can't encrypt the article in group nndraft:drafts."))
5192 (if (equal gnus-newsgroup-name "nndraft:queue")
5193 (error "Don't encrypt the article in group nndraft:queue."))
5194 (gnus-summary-iterate n
5196 (set-buffer gnus-summary-buffer)
5197 (let ((mail-parse-charset gnus-newsgroup-charset)
5198 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5199 (summary-buffer gnus-summary-buffer)
5201 (gnus-set-global-variables)
5202 (when (gnus-group-read-only-p)
5203 (error "The current newsgroup does not support article encrypt"))
5204 (gnus-summary-show-article t)
5206 (or (mail-header-references gnus-current-headers) ""))
5207 (set-buffer gnus-article-buffer)
5208 (let* ((buffer-read-only nil)
5210 (mapcar (lambda (field)
5211 (and (save-restriction
5212 (message-narrow-to-head)
5213 (goto-char (point-min))
5214 (search-forward field nil t))
5216 (message-narrow-to-field)
5217 (buffer-substring (point-min) (point-max))
5218 (delete-region (point-min) (point-max))
5220 '("Content-Type:" "Content-Transfer-Encoding:"
5221 "Content-Disposition:"))))
5222 (message-narrow-to-head)
5223 (message-remove-header "MIME-Version")
5224 (goto-char (point-max))
5225 (setq point (point))
5226 (insert (apply 'concat headers))
5228 (narrow-to-region point (point-max))
5229 (let ((message-options message-options))
5230 (message-options-set 'message-sender user-mail-address)
5231 (message-options-set 'message-recipients user-mail-address)
5232 (message-options-set 'message-sign-encrypt 'not)
5234 (goto-char (point-min))
5235 (insert "MIME-Version: 1.0\n")
5237 (gnus-summary-edit-article-done
5238 references nil summary-buffer t))
5239 (when gnus-keep-backlog
5240 (gnus-backlog-remove-article
5241 (car gnus-article-current) (cdr gnus-article-current)))
5243 (when (get-buffer gnus-original-article-buffer)
5244 (set-buffer gnus-original-article-buffer)
5245 (setq gnus-original-article nil)))
5246 (when gnus-use-cache
5247 (gnus-cache-update-article
5248 (car gnus-article-current) (cdr gnus-article-current))))))))
5250 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5251 "The following specs can be used:
5252 %t The security MIME type
5255 %D Details if button is pressed")
5257 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5258 "The following specs can be used:
5259 %t The security MIME type
5262 %D Details if button is pressed")
5264 (defvar gnus-mime-security-button-line-format-alist
5265 '((?t gnus-tmp-type ?s)
5266 (?i gnus-tmp-info ?s)
5267 (?d gnus-tmp-details ?s)
5268 (?D gnus-tmp-pressed-details ?s)))
5270 (defvar gnus-mime-security-button-map
5271 (let ((map (make-sparse-keymap)))
5272 (unless (>= (string-to-number emacs-version) 21)
5273 (set-keymap-parent map gnus-article-mode-map))
5274 (define-key map gnus-mouse-2 'gnus-article-push-button)
5275 (define-key map "\r" 'gnus-article-press-button)
5278 (defvar gnus-mime-security-details-buffer nil)
5280 (defvar gnus-mime-security-button-pressed nil)
5282 (defvar gnus-mime-security-show-details-inline t
5283 "If non-nil, show details in the article buffer.")
5285 (defun gnus-mime-security-verify-or-decrypt (handle)
5286 (mm-remove-parts (cdr handle))
5287 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5290 (delete-region (car region) (cdr region))
5291 (set-marker (car region) nil)
5292 (set-marker (cdr region) nil)))
5293 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5294 (let* ((mm-verify-option 'known)
5295 (mm-decrypt-option 'known)
5296 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5297 (unless (eq nparts (cdr handle))
5298 (mm-destroy-parts (cdr handle))
5299 (setcdr handle nparts))))
5300 (let ((point (point))
5302 (gnus-mime-display-security handle)
5305 (defun gnus-mime-security-show-details (handle)
5306 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5308 (if gnus-mime-security-show-details-inline
5309 (let ((gnus-mime-security-button-pressed t)
5310 (gnus-mime-security-button-line-format
5311 (get-text-property (point) 'gnus-line-format))
5314 (while (eq (get-text-property (point) 'gnus-line-format)
5315 gnus-mime-security-button-line-format)
5318 (delete-region (point)
5319 (or (text-property-not-all
5322 gnus-mime-security-button-line-format)
5324 (gnus-insert-mime-security-button handle))
5325 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5326 (with-current-buffer gnus-mime-security-details-buffer
5329 (setq gnus-mime-security-details-buffer
5330 (gnus-get-buffer-create "*MIME Security Details*")))
5331 (with-current-buffer gnus-mime-security-details-buffer
5333 (goto-char (point-min)))
5334 (pop-to-buffer gnus-mime-security-details-buffer))
5335 (gnus-message 5 "No details."))))
5337 (defun gnus-mime-security-press-button (handle)
5338 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5339 (gnus-mime-security-show-details handle)
5340 (gnus-mime-security-verify-or-decrypt handle)))
5342 (defun gnus-insert-mime-security-button (handle &optional displayed)
5343 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5346 (or (nth 2 (assoc protocol mm-verify-function-alist))
5347 (nth 2 (assoc protocol mm-decrypt-function-alist))
5349 (if (equal (car handle) "multipart/signed")
5350 " Signed" " Encrypted")
5353 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5356 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5357 gnus-tmp-pressed-details
5359 (setq gnus-tmp-details
5360 (if gnus-tmp-details
5361 (concat "\n" gnus-tmp-details) ""))
5362 (setq gnus-tmp-pressed-details
5363 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5368 gnus-mime-security-button-line-format
5369 gnus-mime-security-button-line-format-alist
5370 `(keymap ,gnus-mime-security-button-map
5371 ,@(if (>= (string-to-number emacs-version) 21)
5372 nil ;; XEmacs doesn't care
5373 (list 'local-map gnus-mime-security-button-map))
5374 gnus-callback gnus-mime-security-press-button
5375 gnus-line-format ,gnus-mime-security-button-line-format
5376 article-type annotation
5379 (widget-convert-button
5382 :action 'gnus-widget-press-button
5383 :button-keymap gnus-mime-security-button-map
5385 (lambda (widget/window &optional overlay pos)
5386 ;; Needed to properly clear the message due to a bug in
5387 ;; wid-edit (XEmacs only).
5388 (if (boundp 'help-echo-owns-message)
5389 (setq help-echo-owns-message t))
5392 (aref gnus-mouse-2 0))))))
5394 (defun gnus-mime-display-security (handle)
5396 (narrow-to-region (point) (point))
5397 (gnus-insert-mime-security-button handle)
5398 (gnus-mime-display-mixed (cdr handle))
5401 (let ((gnus-mime-security-button-line-format
5402 gnus-mime-security-button-end-line-format))
5403 (gnus-insert-mime-security-button handle))
5404 (mm-set-handle-multipart-parameter
5406 (cons (set-marker (make-marker) (point-min))
5407 (set-marker (make-marker) (point-max))))))
5413 (run-hooks 'gnus-art-load-hook)
5415 ;;; gnus-art.el ends here