1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'static))
43 ;; Avoid byte-compile warnings.
52 (autoload 'gnus-msg-mail "gnus-msg" nil t)
53 (autoload 'gnus-button-mailto "gnus-msg")
54 (autoload 'gnus-button-reply "gnus-msg" nil t)
56 (defgroup gnus-article nil
58 :link '(custom-manual "(gnus)The Article Buffer")
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
77 (defgroup gnus-article-signature nil
79 :link '(custom-manual "(gnus)Article Signature")
82 (defgroup gnus-article-headers nil
84 :link '(custom-manual "(gnus)Hiding Headers")
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
97 (defgroup gnus-article-saving nil
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
118 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
119 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
120 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
121 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
122 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
123 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
124 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
125 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
126 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
127 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
128 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
129 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
130 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
131 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
132 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
133 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
134 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
135 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
136 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
137 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
138 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
139 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
140 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
141 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
142 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
143 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
144 "^X-Received:" "^Content-length:" "X-precedence:"
145 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
146 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
148 "*All headers that start with this regexp will be hidden.
149 This variable can also be a list of regexps of headers to be ignored.
150 If `gnus-visible-headers' is non-nil, this variable will be ignored."
151 :type '(choice :custom-show nil
154 :group 'gnus-article-hiding)
156 (defcustom gnus-visible-headers
157 "^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:"
158 "*All headers that do not match this regexp will be hidden.
159 This variable can also be a list of regexp of headers to remain visible.
160 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
161 :type '(repeat :value-to-internal (lambda (widget value)
162 (custom-split-regexp-maybe value))
163 :match (lambda (widget value)
165 (widget-editable-list-match widget value)))
167 :group 'gnus-article-hiding)
169 (defcustom gnus-sorted-header-list
170 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
171 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
172 "*This variable is a list of regular expressions.
173 If it is non-nil, headers that match the regular expressions will
174 be placed first in the article buffer in the sequence specified by
176 :type '(repeat regexp)
177 :group 'gnus-article-hiding)
179 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
180 "Headers that are only to be displayed if they have interesting data.
181 Possible values in this list are `empty', `newsgroups', `followup-to',
182 `to-address', `reply-to', `date', `long-to', and `many-to'."
183 :type '(set (const :tag "Headers with no content." empty)
184 (const :tag "Newsgroups with only one group." newsgroups)
185 (const :tag "To identical to to-address." to-address)
186 (const :tag "Followup-to identical to newsgroups." followup-to)
187 (const :tag "Reply-to identical to from." reply-to)
188 (const :tag "Date less than four days old." date)
189 (const :tag "Very long To and/or Cc header." long-to)
190 (const :tag "Multiple To and/or Cc headers." many-to))
191 :group 'gnus-article-hiding)
193 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
194 "Regexp matching signature separator.
195 This can also be a list of regexps. In that case, it will be checked
196 from head to tail looking for a separator. Searches will be done from
197 the end of the buffer."
198 :type '(repeat string)
199 :group 'gnus-article-signature)
201 (defcustom gnus-signature-limit nil
202 "Provide a limit to what is considered a signature.
203 If it is a number, no signature may not be longer (in characters) than
204 that number. If it is a floating point number, no signature may be
205 longer (in lines) than that number. If it is a function, the function
206 will be called without any parameters, and if it returns nil, there is
207 no signature in the buffer. If it is a string, it will be used as a
208 regexp. If it matches, the text in question is not a signature."
209 :type '(choice (integer :value 200)
211 (function :value fun)
212 (regexp :value ".*"))
213 :group 'gnus-article-signature)
215 (defcustom gnus-hidden-properties '(invisible t intangible t)
216 "Property list to use for hiding text."
218 :group 'gnus-article-hiding)
220 ;; Fixme: This isn't the right thing for mixed graphical and and
221 ;; non-graphical frames in a session.
222 ;; gnus-xmas.el overrides this for XEmacs.
223 (defcustom gnus-article-x-face-command
225 ((and (fboundp 'image-type-available-p)
226 (module-installed-p 'x-face-e21))
227 'x-face-decode-message-header)
228 ((and (fboundp 'image-type-available-p)
229 (image-type-available-p 'xbm))
230 'gnus-article-display-xface)
231 ((and (not (featurep 'xemacs))
233 (module-installed-p 'x-face-mule))
234 'x-face-mule-gnus-article-display-x-face)
235 (gnus-article-compface-xbm
236 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -")
238 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
240 "*String or function to be executed to display an X-Face header.
241 If it is a string, the command will be executed in a sub-shell
242 asynchronously. The compressed face will be piped to this command."
243 :type '(choice string
245 :tag "x-face-decode-message-header (x-face-e21)"
246 x-face-decode-message-header)
247 (function-item gnus-article-display-xface)
248 (function-item x-face-mule-gnus-article-display-x-face)
250 :group 'gnus-article-washing)
252 (defcustom gnus-article-x-face-too-ugly nil
253 "Regexp matching posters whose face shouldn't be shown automatically."
254 :type '(choice regexp (const nil))
255 :group 'gnus-article-washing)
257 (defcustom gnus-article-banner-alist nil
258 "Banner alist for stripping.
260 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
262 :type '(repeat (cons symbol regexp))
263 :group 'gnus-article-washing)
265 (gnus-define-group-parameter
268 "Alist of regexps (to match group names) and banner."
269 :variable-group gnus-article-washing
271 '(choice :tag "Banner"
273 (const :tag "Remove signature" signature)
274 (symbol :tag "Item in `gnus-article-banner-alist'" none)
276 (const :tag "None" nil))
278 "If non-nil, specify how to remove `banners' from articles.
280 Symbol `signature' means to remove signatures delimited by
281 `gnus-signature-separator'. Any other symbol is used to look up a
282 regular expression to match the banner in `gnus-article-banner-alist'.
283 A string is used as a regular expression to match the banner
286 (defcustom gnus-emphasis-alist
288 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
290 '(("_" "_" underline)
293 ("_/" "/_" underline-italic)
294 ("_\\*" "\\*_" underline-bold)
295 ("\\*/" "/\\*" bold-italic)
296 ("_\\*/" "/\\*_" underline-bold-italic))))
297 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
298 2 3 gnus-emphasis-underline)
302 (format format (car spec) (car (cdr spec)))
303 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
305 "*Alist that says how to fontify certain phrases.
306 Each item looks like this:
308 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
310 The first element is a regular expression to be matched. The second
311 is a number that says what regular expression grouping used to find
312 the entire emphasized word. The third is a number that says what
313 regexp grouping should be displayed and highlighted. The fourth
314 is the face used for highlighting."
315 :type '(repeat (list :value ("" 0 0 default)
317 (integer :tag "Match group")
318 (integer :tag "Emphasize group")
320 :group 'gnus-article-emphasis)
322 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
323 "A regexp to describe whitespace which should not be emphasized.
324 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
325 The former avoids underlining of leading and trailing whitespace,
326 and the latter avoids underlining any whitespace at all."
328 :group 'gnus-article-emphasis
331 (defface gnus-emphasis-bold '((t (:bold t)))
332 "Face used for displaying strong emphasized text (*word*)."
333 :group 'gnus-article-emphasis)
335 (defface gnus-emphasis-italic '((t (:italic t)))
336 "Face used for displaying italic emphasized text (/word/)."
337 :group 'gnus-article-emphasis)
339 (defface gnus-emphasis-underline '((t (:underline t)))
340 "Face used for displaying underlined emphasized text (_word_)."
341 :group 'gnus-article-emphasis)
343 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
344 "Face used for displaying underlined bold emphasized text (_*word*_)."
345 :group 'gnus-article-emphasis)
347 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
348 "Face used for displaying underlined italic emphasized text (_/word/_)."
349 :group 'gnus-article-emphasis)
351 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
352 "Face used for displaying bold italic emphasized text (/*word*/)."
353 :group 'gnus-article-emphasis)
355 (defface gnus-emphasis-underline-bold-italic
356 '((t (:bold t :italic t :underline t)))
357 "Face used for displaying underlined bold italic emphasized text.
358 Esample: (_/*word*/_)."
359 :group 'gnus-article-emphasis)
361 (defface gnus-emphasis-highlight-words
362 '((t (:background "black" :foreground "yellow")))
363 "Face used for displaying highlighted words."
364 :group 'gnus-article-emphasis)
366 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
367 "Format for display of Date headers in article bodies.
368 See `format-time-string' for the possible values.
370 The variable can also be function, which should return a complete Date
371 header. The function is called with one argument, the time, which can
372 be fed to `format-time-string'."
373 :type '(choice string symbol)
374 :link '(custom-manual "(gnus)Article Date")
375 :group 'gnus-article-washing)
378 (autoload 'mail-extract-address-components "mail-extr"))
380 (defcustom gnus-save-all-headers t
381 "*If non-nil, don't remove any headers before saving."
382 :group 'gnus-article-saving
385 (defcustom gnus-prompt-before-saving 'always
386 "*This variable says how much prompting is to be done when saving articles.
387 If it is nil, no prompting will be done, and the articles will be
388 saved to the default files. If this variable is `always', each and
389 every article that is saved will be preceded by a prompt, even when
390 saving large batches of articles. If this variable is neither nil not
391 `always', there the user will be prompted once for a file name for
392 each invocation of the saving commands."
393 :group 'gnus-article-saving
394 :type '(choice (item always)
395 (item :tag "never" nil)
396 (sexp :tag "once" :format "%t\n" :value t)))
398 (defcustom gnus-saved-headers gnus-visible-headers
399 "Headers to keep if `gnus-save-all-headers' is nil.
400 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
401 If that variable is nil, however, all headers that match this regexp
402 will be kept while the rest will be deleted before saving."
403 :group 'gnus-article-saving
406 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
407 "A function to save articles in your favourite format.
408 The function must be interactively callable (in other words, it must
409 be an Emacs command).
411 Gnus provides the following functions:
413 * gnus-summary-save-in-rmail (Rmail format)
414 * gnus-summary-save-in-mail (Unix mail format)
415 * gnus-summary-save-in-folder (MH folder)
416 * gnus-summary-save-in-file (article format)
417 * gnus-summary-save-in-vm (use VM's folder format)
418 * gnus-summary-write-to-file (article format -- overwrite)."
419 :group 'gnus-article-saving
420 :type '(radio (function-item gnus-summary-save-in-rmail)
421 (function-item gnus-summary-save-in-mail)
422 (function-item gnus-summary-save-in-folder)
423 (function-item gnus-summary-save-in-file)
424 (function-item gnus-summary-save-in-vm)
425 (function-item gnus-summary-write-to-file)))
427 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
428 "A function generating a file name to save articles in Rmail format.
429 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
430 :group 'gnus-article-saving
433 (defcustom gnus-mail-save-name 'gnus-plain-save-name
434 "A function generating a file name to save articles in Unix mail format.
435 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
436 :group 'gnus-article-saving
439 (defcustom gnus-folder-save-name 'gnus-folder-save-name
440 "A function generating a file name to save articles in MH folder.
441 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
442 :group 'gnus-article-saving
445 (defcustom gnus-file-save-name 'gnus-numeric-save-name
446 "A function generating a file name to save articles in article format.
447 The function is called with NEWSGROUP, HEADERS, and optional
449 :group 'gnus-article-saving
452 (defcustom gnus-split-methods
453 '((gnus-article-archive-name)
454 (gnus-article-nndoc-name))
455 "*Variable used to suggest where articles are to be saved.
456 For instance, if you would like to save articles related to Gnus in
457 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
458 you could set this variable to something like:
460 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
461 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
463 This variable is an alist where the where the key is the match and the
464 value is a list of possible files to save in if the match is non-nil.
466 If the match is a string, it is used as a regexp match on the
467 article. If the match is a symbol, that symbol will be funcalled
468 from the buffer of the article to be saved with the newsgroup as the
469 parameter. If it is a list, it will be evaled in the same buffer.
471 If this form or function returns a string, this string will be used as
472 a possible file name; and if it returns a non-nil list, that list will
473 be used as possible file names."
474 :group 'gnus-article-saving
475 :type '(repeat (choice (list :value (fun) function)
476 (cons :value ("" "") regexp (repeat string))
479 (defcustom gnus-article-display-method-for-mime
480 'gnus-article-display-mime-message
481 "Function to display a MIME message.
482 The function is called from the article buffer."
483 :group 'gnus-article-mime
486 (defcustom gnus-article-display-method-for-traditional
487 'gnus-article-display-traditional-message
488 "*Function to display a traditional message.
489 The function is called from the article buffer."
490 :group 'gnus-article-mime
493 (defcustom gnus-page-delimiter "^\^L"
494 "*Regexp describing what to use as article page delimiters.
495 The default value is \"^\^L\", which is a form linefeed at the
496 beginning of a line."
498 :group 'gnus-article-various)
500 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
501 "*The format specification for the article mode line.
502 See `gnus-summary-mode-line-format' for a closer description.
504 The following additional specs are available:
506 %w The article washing status.
507 %m The number of MIME parts in the article."
509 :group 'gnus-article-various)
511 (defcustom gnus-article-mode-hook nil
512 "*A hook for Gnus article mode."
514 :group 'gnus-article-various)
516 (when (featurep 'xemacs)
517 ;; Extracted from gnus-xmas-define in order to preserve user settings
518 (when (fboundp 'turn-off-scroll-in-place)
519 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
520 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
521 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
523 (defcustom gnus-article-menu-hook nil
524 "*Hook run after the creation of the article mode menu."
526 :group 'gnus-article-various)
528 (defcustom gnus-article-prepare-hook nil
529 "*A hook called after an article has been prepared in the article buffer."
531 :group 'gnus-article-various)
533 (defcustom gnus-article-hide-pgp-hook nil
534 "*A hook called after successfully hiding a PGP signature."
536 :group 'gnus-article-various)
538 (defcustom gnus-article-button-face 'bold
539 "Face used for highlighting buttons in the article buffer.
541 An article button is a piece of text that you can activate by pressing
542 `RET' or `mouse-2' above it."
544 :group 'gnus-article-buttons)
546 (defcustom gnus-article-mouse-face 'highlight
547 "Face used for mouse highlighting in the article buffer.
549 Article buttons will be displayed in this face when the cursor is
552 :group 'gnus-article-buttons)
554 (defcustom gnus-signature-face 'gnus-signature-face
555 "Face used for highlighting a signature in the article buffer.
556 Obsolete; use the face `gnus-signature-face' for customizations instead."
558 :group 'gnus-article-highlight
559 :group 'gnus-article-signature)
561 (defface gnus-signature-face
564 "Face used for highlighting a signature in the article buffer."
565 :group 'gnus-article-highlight
566 :group 'gnus-article-signature)
568 (defface gnus-header-from-face
571 (:foreground "spring green"))
574 (:foreground "red3"))
577 "Face used for displaying from headers."
578 :group 'gnus-article-headers
579 :group 'gnus-article-highlight)
581 (defface gnus-header-subject-face
584 (:foreground "SeaGreen3"))
587 (:foreground "red4"))
589 (:bold t :italic t)))
590 "Face used for displaying subject headers."
591 :group 'gnus-article-headers
592 :group 'gnus-article-highlight)
594 (defface gnus-header-newsgroups-face
597 (:foreground "yellow" :italic t))
600 (:foreground "MidnightBlue" :italic t))
603 "Face used for displaying newsgroups headers."
604 :group 'gnus-article-headers
605 :group 'gnus-article-highlight)
607 (defface gnus-header-name-face
610 (:foreground "SeaGreen"))
613 (:foreground "maroon"))
616 "Face used for displaying header names."
617 :group 'gnus-article-headers
618 :group 'gnus-article-highlight)
620 (defface gnus-header-content-face
623 (:foreground "forest green" :italic t))
626 (:foreground "indianred4" :italic t))
628 (:italic t))) "Face used for displaying header content."
629 :group 'gnus-article-headers
630 :group 'gnus-article-highlight)
632 (defcustom gnus-header-face-alist
633 '(("From" nil gnus-header-from-face)
634 ("Subject" nil gnus-header-subject-face)
635 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
636 ("" gnus-header-name-face gnus-header-content-face))
637 "*Controls highlighting of article header.
639 An alist of the form (HEADER NAME CONTENT).
641 HEADER is a regular expression which should match the name of an
642 header header and NAME and CONTENT are either face names or nil.
644 The name of each header field will be displayed using the face
645 specified by the first element in the list where HEADER match the
646 header name and NAME is non-nil. Similarly, the content will be
647 displayed by the first non-nil matching CONTENT face."
648 :group 'gnus-article-headers
649 :group 'gnus-article-highlight
650 :type '(repeat (list (regexp :tag "Header")
652 (item :tag "skip" nil)
653 (face :value default))
654 (choice :tag "Content"
655 (item :tag "skip" nil)
656 (face :value default)))))
658 (defcustom gnus-article-decode-hook nil
659 "*Hook run to decode charsets in articles."
660 :group 'gnus-article-headers
663 (defcustom gnus-display-mime-function 'gnus-display-mime
664 "Function to display MIME articles."
665 :group 'gnus-article-mime
668 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
669 "Function used to decode headers.")
671 (defvar gnus-article-dumbquotes-map
690 "Table for MS-to-Latin1 translation.")
692 (defcustom gnus-ignored-mime-types nil
693 "List of MIME types that should be ignored by Gnus."
695 :group 'gnus-article-mime
696 :type '(repeat regexp))
698 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
699 "List of MIME types that should not be given buttons when rendered inline."
701 :group 'gnus-article-mime
702 :type '(repeat regexp))
704 (defcustom gnus-article-mime-part-function nil
705 "Function called with a MIME handle as the argument.
706 This is meant for people who want to do something automatic based
707 on parts -- for instance, adding Vcard info to a database."
708 :group 'gnus-article-mime
711 (defcustom gnus-mime-multipart-functions nil
712 "An alist of MIME types to functions to display them."
714 :group 'gnus-article-mime
717 (defcustom gnus-article-date-lapsed-new-header nil
718 "Whether the X-Sent and Date headers can coexist.
719 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
720 either replace the old \"Date:\" header (if this variable is nil), or
721 be added below it (otherwise)."
723 :group 'gnus-article-headers
726 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
727 "Function called with a MIME handle as the argument.
728 This is meant for people who want to view first matched part.
729 For `undisplayed-alternative' (default), the first undisplayed
730 part or alternative part is used. For `undisplayed', the first
731 undisplayed part is used. For a function, the first part which
732 the function return `t' is used. For `nil', the first part is
735 :group 'gnus-article-mime
737 (item :tag "first" :value nil)
738 (item :tag "undisplayed" :value undisplayed)
739 (item :tag "undisplayed or alternative"
740 :value undisplayed-alternative)
743 (defcustom gnus-mime-action-alist
744 '(("save to file" . gnus-mime-save-part)
745 ("save and strip" . gnus-mime-save-part-and-strip)
746 ("display as text" . gnus-mime-inline-part)
747 ("view the part" . gnus-mime-view-part)
748 ("pipe to command" . gnus-mime-pipe-part)
749 ("toggle display" . gnus-article-press-button)
750 ("toggle display" . gnus-article-view-part-as-charset)
751 ("view as type" . gnus-mime-view-part-as-type)
752 ("internalize type" . gnus-mime-internalize-part)
753 ("externalize type" . gnus-mime-externalize-part))
754 "An alist of actions that run on the MIME attachment."
755 :group 'gnus-article-mime
756 :type '(repeat (cons (string :tag "name")
759 (defcustom gnus-mime-action-alist
760 '(("save to file" . gnus-mime-save-part)
761 ("display as text" . gnus-mime-inline-part)
762 ("view the part" . gnus-mime-view-part)
763 ("pipe to command" . gnus-mime-pipe-part)
764 ("toggle display" . gnus-article-press-button)
765 ("view as type" . gnus-mime-view-part-as-type)
766 ("internalize type" . gnus-mime-internalize-part)
767 ("externalize type" . gnus-mime-externalize-part))
768 "An alist of actions that run on the MIME attachment."
770 :group 'gnus-article-mime
771 :type '(repeat (cons (string :tag "name")
775 ;;; The treatment variables
778 (defvar gnus-part-display-hook nil
779 "Hook called on parts that are to receive treatment.")
781 (defvar gnus-article-treat-custom
782 '(choice (const :tag "Off" nil)
784 (const :tag "Header" head)
785 (const :tag "Last" last)
786 (const :tag "Mime" mime)
787 (integer :tag "Less")
788 (repeat :tag "Groups" regexp)
789 (sexp :tag "Predicate")))
791 (defvar gnus-article-treat-head-custom
792 '(choice (const :tag "Off" nil)
793 (const :tag "Header" head)))
795 (defvar gnus-article-treat-types '("text/plain")
798 (defvar gnus-inhibit-treatment nil
799 "Whether to inhibit treatment.")
801 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
802 "Highlight the signature.
803 Valid values are nil, t, `head', `last', an integer or a predicate.
804 See the manual for details."
805 :group 'gnus-article-treat
806 :type gnus-article-treat-custom)
807 (put 'gnus-treat-highlight-signature 'highlight t)
809 (defcustom gnus-treat-buttonize 100000
811 Valid values are nil, t, `head', `last', an integer or a predicate.
812 See the manual for details."
813 :group 'gnus-article-treat
814 :type gnus-article-treat-custom)
815 (put 'gnus-treat-buttonize 'highlight t)
817 (defcustom gnus-treat-buttonize-head 'head
818 "Add buttons to the head.
819 Valid values are nil, t, `head', `last', an integer or a predicate.
820 See the manual for details."
821 :group 'gnus-article-treat
822 :type gnus-article-treat-head-custom)
823 (put 'gnus-treat-buttonize-head 'highlight t)
825 (defcustom gnus-treat-emphasize
826 (and (or window-system
828 (>= (string-to-number emacs-version) 21))
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)
835 (put 'gnus-treat-emphasize 'highlight t)
837 (defcustom gnus-treat-strip-cr nil
838 "Remove carriage returns.
839 Valid values are nil, t, `head', `last', an integer or a predicate.
840 See the manual for details."
841 :group 'gnus-article-treat
842 :type gnus-article-treat-custom)
844 (defcustom gnus-treat-hide-headers 'head
846 Valid values are nil, t, `head', `last', an integer or a predicate.
847 See the manual for details."
848 :group 'gnus-article-treat
849 :type gnus-article-treat-head-custom)
851 (defcustom gnus-treat-hide-boring-headers nil
852 "Hide boring headers.
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-head-custom)
858 (defcustom gnus-treat-hide-signature nil
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-fill-article nil
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-custom)
872 (defcustom gnus-treat-hide-citation nil
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-custom)
879 (defcustom gnus-treat-hide-citation-maybe nil
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-custom)
886 (defcustom gnus-treat-hide-citation-maybe nil
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-custom)
893 (defcustom gnus-treat-strip-list-identifiers 'head
894 "Strip list identifiers from `gnus-list-identifiers`.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
898 :group 'gnus-article-treat
899 :type gnus-article-treat-custom)
901 (defcustom gnus-treat-strip-pgp t
902 "Strip PGP signatures.
903 Valid values are nil, t, `head', `last', an integer or a predicate.
904 See the manual for details."
905 :group 'gnus-article-treat
906 :type gnus-article-treat-custom)
908 (defcustom gnus-treat-strip-pem nil
909 "Strip PEM signatures.
910 Valid values are nil, t, `head', `last', an integer or a predicate.
911 See the manual for details."
912 :group 'gnus-article-treat
913 :type gnus-article-treat-custom)
915 (defcustom gnus-treat-strip-banner t
916 "Strip banners from articles.
917 The banner to be stripped is specified in the `banner' group parameter.
918 Valid values are nil, t, `head', `last', an integer or a predicate.
919 See the manual for details."
920 :group 'gnus-article-treat
921 :type gnus-article-treat-custom)
923 (defcustom gnus-treat-highlight-headers 'head
924 "Highlight the headers.
925 Valid values are nil, t, `head', `last', an integer or a predicate.
926 See the manual for details."
927 :group 'gnus-article-treat
928 :type gnus-article-treat-head-custom)
929 (put 'gnus-treat-highlight-headers 'highlight t)
931 (defcustom gnus-treat-highlight-citation t
932 "Highlight cited text.
933 Valid values are nil, t, `head', `last', an integer or a predicate.
934 See the manual for details."
935 :group 'gnus-article-treat
936 :type gnus-article-treat-custom)
937 (put 'gnus-treat-highlight-citation 'highlight t)
939 (defcustom gnus-treat-date-ut nil
940 "Display the Date in UT (GMT).
941 Valid values are nil, t, `head', `last', an integer or a predicate.
942 See the manual for details."
943 :group 'gnus-article-treat
944 :type gnus-article-treat-head-custom)
946 (defcustom gnus-treat-date-local nil
947 "Display the Date in the local timezone.
948 Valid values are nil, t, `head', `last', an integer or a predicate.
949 See the manual for details."
950 :group 'gnus-article-treat
951 :type gnus-article-treat-head-custom)
953 (defcustom gnus-treat-date-english nil
954 "Display the Date in a format that can be read aloud in English.
955 Valid values are nil, t, `head', `last', an integer or a predicate.
956 See the manual for details."
957 :group 'gnus-article-treat
958 :type gnus-article-treat-head-custom)
960 (defcustom gnus-treat-date-lapsed nil
961 "Display the Date header in a way that says how much time has elapsed.
962 Valid values are nil, t, `head', `last', an integer or a predicate.
963 See the manual for details."
964 :group 'gnus-article-treat
965 :type gnus-article-treat-head-custom)
967 (defcustom gnus-treat-date-original nil
968 "Display the date in the original timezone.
969 Valid values are nil, t, `head', `last', an integer or a predicate.
970 See the manual for details."
971 :group 'gnus-article-treat
972 :type gnus-article-treat-head-custom)
974 (defcustom gnus-treat-date-iso8601 nil
975 "Display the date in the ISO8601 format.
976 Valid values are nil, t, `head', `last', an integer or a predicate.
977 See the manual for details."
979 :group 'gnus-article-treat
980 :type gnus-article-treat-head-custom)
982 (defcustom gnus-treat-date-user-defined nil
983 "Display the date in a user-defined format.
984 The format is defined by the `gnus-article-time-format' variable.
985 Valid values are nil, t, `head', `last', an integer or a predicate.
986 See the manual for details."
987 :group 'gnus-article-treat
988 :type gnus-article-treat-head-custom)
990 (defcustom gnus-treat-strip-headers-in-body t
991 "Strip the X-No-Archive header line from the beginning of the body.
992 Valid values are nil, t, `head', `last', an integer or a predicate.
993 See the manual for details."
995 :group 'gnus-article-treat
996 :type gnus-article-treat-custom)
998 (defcustom gnus-treat-strip-trailing-blank-lines nil
999 "Strip trailing blank lines.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See the manual for details."
1002 :group 'gnus-article-treat
1003 :type gnus-article-treat-custom)
1005 (defcustom gnus-treat-strip-leading-blank-lines nil
1006 "Strip leading blank lines.
1007 Valid values are nil, t, `head', `last', an integer or a predicate.
1008 See the manual for details."
1009 :group 'gnus-article-treat
1010 :type gnus-article-treat-custom)
1012 (defcustom gnus-treat-strip-multiple-blank-lines nil
1013 "Strip multiple blank lines.
1014 Valid values are nil, t, `head', `last', an integer or a predicate.
1015 See the manual for details."
1016 :group 'gnus-article-treat
1017 :type gnus-article-treat-custom)
1019 (defcustom gnus-treat-overstrike t
1020 "Treat overstrike highlighting.
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)
1025 (put 'gnus-treat-overstrike 'highlight t)
1027 (defcustom gnus-treat-display-xface
1028 (and (or (and (fboundp 'image-type-available-p)
1029 (image-type-available-p 'xbm)
1030 (string-match "^0x" (shell-command-to-string "uncompface")))
1031 (and (featurep 'xemacs) (featurep 'xface))
1032 (eq 'x-face-mule-gnus-article-display-x-face
1033 gnus-article-x-face-command))
1035 "Display X-Face headers.
1036 Valid values are nil, t, `head', `last', an integer or a predicate.
1037 See the manual for details."
1038 :group 'gnus-article-treat
1039 :type gnus-article-treat-head-custom)
1040 (put 'gnus-treat-display-xface 'highlight t)
1042 (defcustom gnus-treat-display-smileys
1043 (if (or (and (featurep 'xemacs)
1045 (and (fboundp 'image-type-available-p)
1046 (image-type-available-p 'pbm))
1047 (and (not (featurep 'xemacs))
1049 (module-installed-p 'smiley-mule)))
1053 Valid values are nil, t, `head', `last', an integer or a predicate.
1054 See the manual for details."
1055 :group 'gnus-article-treat
1056 :type gnus-article-treat-custom)
1057 (put 'gnus-treat-display-smileys 'highlight t)
1059 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
1061 Valid values are nil, t, `head', `last', an integer or a predicate.
1062 See the manual for details."
1063 :group 'gnus-article-treat
1064 :type gnus-article-treat-head-custom)
1065 (put 'gnus-treat-display-picons 'highlight t)
1067 (defcustom gnus-treat-capitalize-sentences nil
1068 "Capitalize sentence-starting words.
1069 Valid values are nil, t, `head', `last', an integer or a predicate.
1070 See the manual for details."
1072 :group 'gnus-article-treat
1073 :type gnus-article-treat-custom)
1075 (defcustom gnus-treat-fill-long-lines nil
1077 Valid values are nil, t, `head', `last', an integer or a predicate.
1078 See the manual for details."
1079 :group 'gnus-article-treat
1080 :type gnus-article-treat-custom)
1082 (defcustom gnus-treat-play-sounds nil
1084 Valid values are nil, t, `head', `last', an integer or a predicate.
1085 See the manual for details."
1087 :group 'gnus-article-treat
1088 :type gnus-article-treat-custom)
1090 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1091 "Decode an article as `default-mime-charset'. For instance, if you want to
1092 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1093 you could set this variable to something like: nil for don't decode, t for
1094 decode the body, '(or header t) for the whole article, etc."
1095 :group 'gnus-article-treat
1096 :type '(radio (const :tag "Off" nil)
1097 (const :tag "Decode body" t)
1098 (const :tag "Decode all" (or head t))))
1100 (defcustom gnus-treat-translate nil
1101 "Translate articles from one language to another.
1102 Valid values are nil, t, `head', `last', an integer or a predicate.
1103 See the manual for details."
1105 :group 'gnus-article-treat
1106 :type gnus-article-treat-custom)
1108 (defcustom gnus-treat-x-pgp-sig nil
1110 To automatically treat X-PGP-Sig, set it to head.
1111 Valid values are nil, t, `head', `last', an integer or a predicate.
1112 See the manual for details."
1113 :group 'gnus-article-treat
1114 :group 'mime-security
1115 :type gnus-article-treat-custom)
1117 (defvar gnus-article-encrypt-protocol-alist
1118 '(("PGP" . mml2015-self-encrypt)))
1120 ;; Set to nil if more than one protocol added to
1121 ;; gnus-article-encrypt-protocol-alist.
1122 (defcustom gnus-article-encrypt-protocol "PGP"
1123 "The protocol used for encrypt articles.
1124 It is a string, such as \"PGP\". If nil, ask user."
1126 :group 'mime-security)
1128 ;;; Internal variables
1130 (defvar gnus-english-month-names
1131 '("January" "February" "March" "April" "May" "June" "July" "August"
1132 "September" "October" "November" "December"))
1134 (defvar article-goto-body-goes-to-point-min-p nil)
1135 (defvar gnus-article-wash-types nil)
1136 (defvar gnus-article-emphasis-alist nil)
1138 (defvar gnus-article-mime-handle-alist-1 nil)
1139 (defvar gnus-treatment-function-alist
1140 `((gnus-treat-decode-article-as-default-mime-charset
1141 gnus-article-decode-article-as-default-mime-charset)
1142 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1143 (gnus-treat-strip-banner gnus-article-strip-banner)
1144 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1145 (gnus-treat-buttonize gnus-article-add-buttons)
1146 (gnus-treat-fill-article gnus-article-fill-cited-article)
1147 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1148 (gnus-treat-strip-cr gnus-article-remove-cr)
1149 (gnus-treat-display-xface gnus-article-display-x-face)
1150 (gnus-treat-date-ut gnus-article-date-ut)
1151 (gnus-treat-date-local gnus-article-date-local)
1152 (gnus-treat-date-english gnus-article-date-english)
1153 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1154 (gnus-treat-date-original gnus-article-date-original)
1155 (gnus-treat-date-user-defined gnus-article-date-user)
1156 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1157 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1158 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1159 (gnus-treat-hide-signature gnus-article-hide-signature)
1160 (gnus-treat-hide-citation gnus-article-hide-citation)
1161 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1162 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1163 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1164 (gnus-treat-strip-pem gnus-article-hide-pem)
1165 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1166 (gnus-treat-emphasize gnus-article-emphasize)
1167 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1168 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1169 (gnus-treat-strip-trailing-blank-lines
1170 gnus-article-remove-trailing-blank-lines)
1171 (gnus-treat-strip-leading-blank-lines
1172 gnus-article-strip-leading-blank-lines)
1173 (gnus-treat-strip-multiple-blank-lines
1174 gnus-article-strip-multiple-blank-lines)
1175 (gnus-treat-overstrike gnus-article-treat-overstrike)
1176 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1177 (gnus-treat-display-smileys ,(if (or (featurep 'xemacs)
1178 (>= emacs-major-version 21))
1179 'gnus-smiley-display
1180 'gnus-article-smiley-display))
1181 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1182 (gnus-treat-display-picons gnus-article-display-picons)
1183 (gnus-treat-play-sounds gnus-earcon-display)))
1185 (defvar gnus-article-mime-handle-alist nil)
1186 (defvar article-lapsed-timer nil)
1187 (defvar gnus-article-current-summary nil)
1189 (defvar gnus-article-mode-syntax-table
1190 (let ((table (copy-syntax-table text-mode-syntax-table)))
1191 ;; This causes the citation match run O(2^n).
1192 ;; (modify-syntax-entry ?- "w" table)
1193 (modify-syntax-entry ?> ")" table)
1194 (modify-syntax-entry ?< "(" table)
1196 "Syntax table used in article mode buffers.
1197 Initialized from `text-mode-syntax-table.")
1199 (defvar gnus-save-article-buffer nil)
1201 (defvar gnus-article-mode-line-format-alist
1202 (nconc '((?w (gnus-article-wash-status) ?s)
1203 (?m (gnus-article-mime-part-status) ?s))
1204 gnus-summary-mode-line-format-alist))
1206 (defvar gnus-number-of-articles-to-be-saved nil)
1208 (defvar gnus-inhibit-hiding nil)
1210 (defsubst gnus-article-hide-text (b e props)
1211 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1212 (gnus-add-text-properties-when 'article-type nil b e props)
1213 (when (memq 'intangible props)
1215 (max (1- b) (point-min))
1216 b 'intangible (cddr (memq 'intangible props)))))
1218 (defsubst gnus-article-unhide-text (b e)
1219 "Remove hidden text properties from region between B and E."
1220 (remove-text-properties b e gnus-hidden-properties)
1221 (when (memq 'intangible gnus-hidden-properties)
1222 (put-text-property (max (1- b) (point-min))
1223 b 'intangible nil)))
1225 (defun gnus-article-hide-text-type (b e type)
1226 "Hide text of TYPE between B and E."
1227 (push type gnus-article-wash-types)
1228 (gnus-article-hide-text
1229 b e (cons 'article-type (cons type gnus-hidden-properties))))
1231 (defun gnus-article-unhide-text-type (b e type)
1232 "Unhide text of TYPE between B and E."
1233 (setq gnus-article-wash-types
1234 (delq type gnus-article-wash-types))
1235 (remove-text-properties
1236 b e (cons 'article-type (cons type gnus-hidden-properties)))
1237 (when (memq 'intangible gnus-hidden-properties)
1238 (put-text-property (max (1- b) (point-min))
1239 b 'intangible nil)))
1241 (defun gnus-article-hide-text-of-type (type)
1242 "Hide text of TYPE in the current buffer."
1244 (let ((b (point-min))
1246 (while (setq b (text-property-any b e 'article-type type))
1247 (add-text-properties b (incf b) gnus-hidden-properties)))))
1249 (defun gnus-article-delete-text-of-type (type)
1250 "Delete text of TYPE in the current buffer."
1252 (let ((b (point-min)))
1253 (while (setq b (text-property-any b (point-max) 'article-type type))
1255 b (or (text-property-not-all b (point-max) 'article-type type)
1258 (defun gnus-article-delete-invisible-text ()
1259 "Delete all invisible text in the current buffer."
1261 (let ((b (point-min)))
1262 (while (setq b (text-property-any b (point-max) 'invisible t))
1264 b (or (text-property-not-all b (point-max) 'invisible t)
1267 (defun gnus-article-text-type-exists-p (type)
1268 "Say whether any text of type TYPE exists in the buffer."
1269 (text-property-any (point-min) (point-max) 'article-type type))
1271 (defsubst gnus-article-header-rank ()
1272 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1273 (let ((list gnus-sorted-header-list)
1276 (when (looking-at (car list))
1278 (setq list (cdr list))
1282 (defun article-hide-headers (&optional arg delete)
1283 "Hide unwanted headers and possibly sort them as well."
1284 (interactive (gnus-article-hidden-arg))
1285 ;; Lars said that this function might be inhibited.
1286 (if (gnus-article-check-hidden-text 'headers arg)
1288 ;; Show boring headers as well.
1289 (gnus-article-show-hidden-text 'boring-headers)
1290 (when (eq 1 (point-min))
1291 (set-window-start (get-buffer-window (current-buffer)) 1)))
1292 (unless gnus-inhibit-hiding
1295 (let ((buffer-read-only nil)
1296 (inhibit-read-only t)
1297 (case-fold-search t)
1298 (max (1+ (length gnus-sorted-header-list)))
1299 (ignored (when (not gnus-visible-headers)
1300 (cond ((stringp gnus-ignored-headers)
1301 gnus-ignored-headers)
1302 ((listp gnus-ignored-headers)
1303 (mapconcat 'identity gnus-ignored-headers
1306 (cond ((stringp gnus-visible-headers)
1307 gnus-visible-headers)
1308 ((and gnus-visible-headers
1309 (listp gnus-visible-headers))
1310 (mapconcat 'identity gnus-visible-headers "\\|"))))
1311 (inhibit-point-motion-hooks t)
1313 ;; First we narrow to just the headers.
1314 (article-narrow-to-head)
1315 ;; Hide any "From " lines at the beginning of (mail) articles.
1316 (while (looking-at "From ")
1320 (delete-region (point-min) (point))
1321 (gnus-article-hide-text (point-min) (point)
1322 (nconc (list 'article-type 'headers)
1323 gnus-hidden-properties))))
1324 ;; Then treat the rest of the header lines.
1325 ;; Then we use the two regular expressions
1326 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1327 ;; select which header lines is to remain visible in the
1329 (while (re-search-forward "^[^ \t]*:" nil t)
1331 ;; Mark the rank of the header.
1333 (point) (1+ (point)) 'message-rank
1334 (if (or (and visible (looking-at visible))
1336 (not (looking-at ignored))))
1337 (gnus-article-header-rank)
1340 (message-sort-headers-1)
1341 (when (setq beg (text-property-any
1342 (point-min) (point-max) 'message-rank (+ 2 max)))
1343 ;; We delete or make invisible the unwanted headers.
1344 (push 'headers gnus-article-wash-types)
1347 (add-text-properties
1348 (point-min) (+ 5 (point-min))
1349 '(article-type headers dummy-invisible t))
1350 (delete-region beg (point-max)))
1351 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1354 (defun article-hide-boring-headers (&optional arg)
1355 "Toggle hiding of headers that aren't very interesting.
1356 If given a negative prefix, always show; if given a positive prefix,
1358 (interactive (gnus-article-hidden-arg))
1359 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1360 (not gnus-show-all-headers))
1363 (let ((buffer-read-only nil)
1364 (list gnus-boring-article-headers)
1365 (inhibit-point-motion-hooks t)
1367 (article-narrow-to-head)
1369 (setq elem (pop list))
1370 (goto-char (point-min))
1372 ;; Hide empty headers.
1374 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1376 (gnus-article-hide-text-type
1377 (progn (beginning-of-line) (point))
1380 (if (re-search-forward "^[^ \t]" nil t)
1384 ;; Hide boring Newsgroups header.
1385 ((eq elem 'newsgroups)
1386 (when (equal (gnus-fetch-field "newsgroups")
1387 (gnus-group-real-name
1388 (if (boundp 'gnus-newsgroup-name)
1391 (gnus-article-hide-header "newsgroups")))
1392 ((eq elem 'to-address)
1393 (let ((to (message-fetch-field "to"))
1395 (gnus-group-find-parameter
1396 (if (boundp 'gnus-newsgroup-name)
1397 gnus-newsgroup-name "") 'to-address)))
1398 (when (and to to-address
1401 ;; only one address in To
1402 (nth 1 (mail-extract-address-components to))
1404 (gnus-article-hide-header "to"))))
1405 ((eq elem 'followup-to)
1406 (when (equal (message-fetch-field "followup-to")
1407 (message-fetch-field "newsgroups"))
1408 (gnus-article-hide-header "followup-to")))
1409 ((eq elem 'reply-to)
1410 (let ((from (message-fetch-field "from"))
1411 (reply-to (message-fetch-field "reply-to")))
1416 (nth 1 (funcall gnus-extract-address-components from))
1417 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1418 (gnus-article-hide-header "reply-to"))))
1420 (let ((date (message-fetch-field "date")))
1422 (< (days-between (current-time-string) date)
1424 (gnus-article-hide-header "date"))))
1426 (let ((to (message-fetch-field "to"))
1427 (cc (message-fetch-field "cc")))
1428 (when (> (length to) 1024)
1429 (gnus-article-hide-header "to"))
1430 (when (> (length cc) 1024)
1431 (gnus-article-hide-header "cc"))))
1435 (goto-char (point-min))
1436 (while (re-search-forward "^to:" nil t)
1437 (setq to-count (1+ to-count)))
1438 (when (> to-count 1)
1439 (while (> to-count 0)
1440 (goto-char (point-min))
1442 (re-search-forward "^to:" nil nil to-count)
1444 (narrow-to-region (point) (point-max))
1445 (gnus-article-hide-header "to"))
1446 (setq to-count (1- to-count))))
1447 (goto-char (point-min))
1448 (while (re-search-forward "^cc:" nil t)
1449 (setq cc-count (1+ cc-count)))
1450 (when (> cc-count 1)
1451 (while (> cc-count 0)
1452 (goto-char (point-min))
1454 (re-search-forward "^cc:" nil nil cc-count)
1456 (narrow-to-region (point) (point-max))
1457 (gnus-article-hide-header "cc"))
1458 (setq cc-count (1- cc-count)))))))))))))
1460 (defun gnus-article-hide-header (header)
1462 (goto-char (point-min))
1463 (when (re-search-forward (concat "^" header ":") nil t)
1464 (gnus-article-hide-text-type
1465 (progn (beginning-of-line) (point))
1468 (if (re-search-forward "^[^ \t]" nil t)
1473 (defun article-toggle-headers (&optional arg)
1474 "Toggle hiding of headers. If given a negative prefix, always show;
1475 if given a positive prefix, always hide."
1476 (interactive (gnus-article-hidden-arg))
1477 (let ((force (when (numberp arg)
1478 (cond ((> arg 0) 'always-hide)
1479 ((< arg 0) 'always-show))))
1480 (window (get-buffer-window gnus-article-buffer))
1481 (header-end (point-min))
1482 header-start field-end field-start
1483 (inhibit-point-motion-hooks t)
1484 (inhibit-read-only t)
1488 (while (and (setq header-start
1489 (text-property-any header-end (point-max)
1490 'article-treated-header t))
1492 (text-property-not-all header-start (point-max)
1493 'article-treated-header t)))
1494 (setq field-end header-start)
1496 (;; Hide exposed invisible fields.
1497 (and (not (eq 'always-show force))
1499 (text-property-any field-end header-end
1500 'exposed-invisible-field t)))
1501 (while (and field-start
1502 (setq field-end (text-property-not-all
1503 field-start header-end
1504 'exposed-invisible-field t)))
1505 (add-text-properties field-start field-end gnus-hidden-properties)
1506 (setq field-start (text-property-any field-end header-end
1507 'exposed-invisible-field t)))
1508 (put-text-property header-start header-end
1509 'exposed-invisible-field nil))
1510 (;; Expose invisible fields.
1511 (and (not (eq 'always-hide force))
1513 (text-property-any field-end header-end 'invisible t)))
1514 (while (and field-start
1515 (setq field-end (text-property-not-all
1516 field-start header-end
1518 ;; If the invisible text is not terminated with newline, we
1519 ;; won't expose it. Because it may be created by x-face-mule.
1520 ;; BTW, XEmacs sometimes fail in putting a invisible text
1521 ;; property with `gnus-article-hide-text' (really?). In that
1522 ;; case, the invisible text might be started from the middle of
1523 ;; a line so we will expose the sort of thing.
1524 (when (or (not (or (eq header-start field-start)
1525 (eq ?\n (char-before field-start))))
1526 (eq ?\n (char-before field-end)))
1527 (remove-text-properties field-start field-end
1528 gnus-hidden-properties)
1529 (put-text-property field-start field-end
1530 'exposed-invisible-field t))
1531 (setq field-start (text-property-any field-end header-end
1534 (not (eq 'always-show force))
1535 (narrow-to-region header-start header-end)
1536 (article-hide-headers)
1537 ;; Re-display X-Face image under XEmacs.
1538 (when (and (featurep 'xemacs)
1539 (gnus-functionp gnus-article-x-face-command))
1540 (let ((func (cadr (assq 'gnus-treat-display-xface
1541 gnus-treatment-function-alist)))
1543 (when (and (not gnus-inhibit-treatment)
1545 (gnus-treat-predicate gnus-treat-display-xface))
1547 (put-text-property header-start header-end 'read-only nil))))
1550 (goto-char (point-min))
1552 (set-window-start window (point-min))))))
1554 (defvar gnus-article-normalized-header-length 40
1555 "Length of normalized headers.")
1557 (defun article-normalize-headers ()
1558 "Make all header lines 40 characters long."
1560 (let ((buffer-read-only nil)
1564 (article-narrow-to-head)
1567 ((< (setq column (- (gnus-point-at-eol) (point)))
1568 gnus-article-normalized-header-length)
1570 (insert (make-string
1571 (- gnus-article-normalized-header-length column)
1573 ((> column gnus-article-normalized-header-length)
1574 (gnus-put-text-property
1576 (forward-char gnus-article-normalized-header-length)
1583 (forward-line 1))))))
1585 (defun article-treat-dumbquotes ()
1586 "Translate M****s*** sm*rtq**t*s into proper text.
1587 Note that this function guesses whether a character is a sm*rtq**t* or
1588 not, so it should only be used interactively.
1590 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1591 in an attempt to provide more quoting characters. If you see
1592 something like \\222 or \\264 where you're expecting some kind of
1593 apostrophe or quotation mark, then try this wash."
1595 (article-translate-strings gnus-article-dumbquotes-map))
1597 (defun article-translate-characters (from to)
1598 "Translate all characters in the body of the article according to FROM and TO.
1599 FROM is a string of characters to translate from; to is a string of
1600 characters to translate to."
1602 (when (article-goto-body)
1603 (let ((buffer-read-only nil)
1604 (x (make-string 225 ?x))
1606 (while (< (incf i) (length x))
1609 (while (< i (length from))
1610 (aset x (aref from i) (aref to i))
1612 (translate-region (point) (point-max) x)))))
1614 (defun article-translate-strings (map)
1615 "Translate all string in the body of the article according to MAP.
1616 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1618 (when (article-goto-body)
1619 (let ((buffer-read-only nil)
1621 (while (setq elem (pop map))
1623 (while (search-forward (car elem) nil t)
1624 (replace-match (cadr elem)))))))))
1626 (defun article-treat-overstrike ()
1627 "Translate overstrikes into bold text."
1630 (when (article-goto-body)
1631 (let ((buffer-read-only nil))
1632 (while (search-forward "\b" nil t)
1633 (let ((next (char-after))
1637 previous (char-after))
1641 ;; We do the boldification/underlining by hiding the
1642 ;; overstrikes and putting the proper text property
1646 (gnus-article-hide-text-type start (point) 'overstrike)
1647 (put-text-property (point) end 'face 'bold))
1649 (gnus-article-hide-text-type
1650 (1- (point)) (1+ (point)) 'overstrike)
1652 start (1- (point)) 'face 'underline))
1654 (gnus-article-hide-text-type start (point) 'overstrike)
1656 (point) end 'face 'underline)))))))))
1658 (defun article-fill-long-lines ()
1659 "Fill lines that are wider than the window width."
1662 (let ((buffer-read-only nil)
1663 (width (window-width (get-buffer-window (current-buffer)))))
1666 (let ((adaptive-fill-mode nil))
1669 (when (>= (current-column) (min fill-column width))
1670 (narrow-to-region (point) (gnus-point-at-bol))
1671 (fill-paragraph nil)
1672 (goto-char (point-max))
1674 (forward-line 1)))))))
1676 (defun article-capitalize-sentences ()
1677 "Capitalize the first word in each sentence."
1680 (let ((buffer-read-only nil)
1681 (paragraph-start "^[\n\^L]"))
1685 (forward-sentence)))))
1687 (defun article-remove-cr ()
1688 "Remove trailing CRs and then translate remaining CRs into LFs."
1691 (let ((buffer-read-only nil))
1692 (goto-char (point-min))
1693 (while (re-search-forward "\r+$" nil t)
1694 (replace-match "" t t))
1695 (goto-char (point-min))
1696 (while (search-forward "\r" nil t)
1697 (replace-match "\n" t t)))))
1699 (defun article-remove-trailing-blank-lines ()
1700 "Remove all trailing blank lines from the article."
1703 (let ((buffer-read-only nil))
1704 (goto-char (point-max))
1708 (while (and (not (bobp))
1709 (looking-at "^[ \t]*$")
1710 (not (gnus-annotation-in-region-p
1711 (point) (gnus-point-at-eol))))
1716 (defun article-display-x-face (&optional force)
1717 "Look for an X-Face header and display it if present."
1718 (interactive (list 'force))
1720 ;; Delete the old process, if any.
1721 (when (process-status "article-x-face")
1722 (delete-process "article-x-face"))
1723 (let ((inhibit-point-motion-hooks t)
1725 (case-fold-search t)
1728 (article-narrow-to-head)
1729 (when (and buffer-read-only ;; When type `W f'
1731 (goto-char (point-min))
1732 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1733 (gnus-buffer-live-p gnus-original-article-buffer))
1734 (with-current-buffer gnus-original-article-buffer
1736 (article-narrow-to-head)
1737 (while (re-search-forward "^X-Face:" nil t)
1743 (1- (re-search-forward
1744 "^\\($\\|[^ \t]\\)" nil t))))))))
1746 (let (point start bface eface buffer-read-only)
1747 (goto-char (point-max))
1749 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1750 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1751 (goto-char (point-max))
1752 (setq point (point))
1755 (while (looking-at "\\([^:]+\\): *")
1756 (put-text-property (match-beginning 1) (1+ (match-end 1))
1758 (setq start (match-end 0))
1760 (while (looking-at "[\t ]")
1762 (put-text-property start (point)
1764 (goto-char (point-min))
1765 (setq from (message-fetch-field "from"))
1766 (goto-char (point-min))
1767 (while (and gnus-article-x-face-command
1770 ;; Check whether this face is censored.
1771 (not gnus-article-x-face-too-ugly)
1772 (and gnus-article-x-face-too-ugly from
1773 (not (string-match gnus-article-x-face-too-ugly
1775 ;; Has to be present.
1776 (re-search-forward "^X-Face:[\t ]*" nil t))
1777 ;; This used to try to do multiple faces (`while' instead of
1778 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1779 ;; work (b) it can crash some versions of Emacs (c) are
1780 ;; multiple faces really something to encourage?
1781 (when (stringp gnus-article-x-face-command)
1783 ;; We now have the area of the buffer where the X-Face is stored.
1786 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1787 ;; We display the face.
1788 (if (symbolp gnus-article-x-face-command)
1789 ;; The command is a lisp function, so we call it.
1790 (if (gnus-functionp gnus-article-x-face-command)
1791 (funcall gnus-article-x-face-command beg end)
1792 (error "%s is not a function" gnus-article-x-face-command))
1793 ;; The command is a string, so we interpret the command
1794 ;; as a, well, command, and fork it off.
1795 (let ((process-connection-type nil))
1796 (process-kill-without-query
1798 "article-x-face" nil shell-file-name shell-command-switch
1799 gnus-article-x-face-command))
1800 (process-send-region "article-x-face" beg end)
1801 (process-send-eof "article-x-face"))))))))))
1803 (defun article-decode-mime-words ()
1804 "Decode all MIME-encoded words in the article."
1807 (set-buffer gnus-article-buffer)
1808 (let ((inhibit-point-motion-hooks t)
1810 (mail-parse-charset gnus-newsgroup-charset)
1811 (mail-parse-ignored-charsets
1812 (save-excursion (set-buffer gnus-summary-buffer)
1813 gnus-newsgroup-ignored-charsets)))
1814 (mail-decode-encoded-word-region (point-min) (point-max)))))
1816 (defun article-decode-charset (&optional prompt)
1817 "Decode charset-encoded text in the article.
1818 If PROMPT (the prefix), prompt for a coding system to use."
1820 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1822 (mail-parse-charset gnus-newsgroup-charset)
1823 (mail-parse-ignored-charsets
1824 (save-excursion (condition-case nil
1825 (set-buffer gnus-summary-buffer)
1827 gnus-newsgroup-ignored-charsets))
1828 ct cte ctl charset format)
1831 (article-narrow-to-head)
1832 (setq ct (message-fetch-field "Content-Type" t)
1833 cte (message-fetch-field "Content-Transfer-Encoding" t)
1834 ctl (and ct (ignore-errors
1835 (mail-header-parse-content-type ct)))
1838 (mm-read-coding-system "Charset to decode: "))
1840 (mail-content-type-get ctl 'charset)))
1841 format (and ctl (mail-content-type-get ctl 'format)))
1843 (setq cte (mail-header-strip cte)))
1844 (if (and ctl (not (string-match "/" (car ctl))))
1846 (goto-char (point-max)))
1849 (narrow-to-region (point) (point-max))
1850 (when (and (eq mail-parse-charset 'gnus-decoded)
1851 (eq (mm-body-7-or-8) '8bit))
1852 ;; The text code could have been decoded.
1853 (setq charset mail-parse-charset))
1854 (when (and (or (not ctl)
1855 (equal (car ctl) "text/plain"))
1856 (not format)) ;; article with format will decode later.
1858 charset (and cte (intern (downcase
1859 (gnus-strip-whitespace cte))))
1862 (defun article-decode-encoded-words ()
1863 "Remove encoded-word encoding from headers."
1864 (let (buffer-read-only)
1865 (let ((charset (save-excursion
1866 (set-buffer gnus-summary-buffer)
1867 default-mime-charset)))
1868 (mime-decode-header-in-buffer charset)
1871 (defun article-de-quoted-unreadable (&optional force)
1872 "Translate a quoted-printable-encoded article.
1873 If FORCE, decode the article whether it is marked as quoted-printable
1875 (interactive (list 'force))
1877 (let ((buffer-read-only nil) type charset)
1878 (if (gnus-buffer-live-p gnus-original-article-buffer)
1879 (with-current-buffer gnus-original-article-buffer
1881 (gnus-fetch-field "content-transfer-encoding"))
1882 (let* ((ct (gnus-fetch-field "content-type"))
1885 (mail-header-parse-content-type ct)))))
1886 (setq charset (and ctl
1887 (mail-content-type-get ctl 'charset)))
1888 (if (stringp charset)
1889 (setq charset (intern (downcase charset)))))))
1891 (setq charset gnus-newsgroup-charset))
1893 (and type (let ((case-fold-search t))
1894 (string-match "quoted-printable" type))))
1896 (quoted-printable-decode-region
1897 (point) (point-max) (mm-charset-to-coding-system charset))))))
1899 (defun article-de-base64-unreadable (&optional force)
1900 "Translate a base64 article.
1901 If FORCE, decode the article whether it is marked as base64 not."
1902 (interactive (list 'force))
1904 (let ((buffer-read-only nil) type charset)
1905 (if (gnus-buffer-live-p gnus-original-article-buffer)
1906 (with-current-buffer gnus-original-article-buffer
1908 (gnus-fetch-field "content-transfer-encoding"))
1909 (let* ((ct (gnus-fetch-field "content-type"))
1912 (mail-header-parse-content-type ct)))))
1913 (setq charset (and ctl
1914 (mail-content-type-get ctl 'charset)))
1915 (if (stringp charset)
1916 (setq charset (intern (downcase charset)))))))
1918 (setq charset gnus-newsgroup-charset))
1920 (and type (let ((case-fold-search t))
1921 (string-match "base64" type))))
1924 (narrow-to-region (point) (point-max))
1925 (base64-decode-region (point-min) (point-max))
1926 (mm-decode-coding-region
1927 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1932 (defun article-decode-HZ ()
1933 "Translate a HZ-encoded article."
1937 (let ((buffer-read-only nil))
1938 (rfc1843-decode-region (point-min) (point-max)))))
1940 (defun article-wash-html ()
1941 "Format an html article."
1944 (let ((buffer-read-only nil)
1946 (if (gnus-buffer-live-p gnus-original-article-buffer)
1947 (with-current-buffer gnus-original-article-buffer
1948 (let* ((ct (gnus-fetch-field "content-type"))
1951 (mail-header-parse-content-type ct)))))
1952 (setq charset (and ctl
1953 (mail-content-type-get ctl 'charset)))
1954 (if (stringp charset)
1955 (setq charset (intern (downcase charset)))))))
1957 (setq charset gnus-newsgroup-charset))
1959 (save-window-excursion
1961 (narrow-to-region (point) (point-max))
1963 (let ((w3-strict-width (window-width))
1964 (url-standalone-mode t))
1966 (w3-region (point-min) (point-max))
1969 (defun article-hide-list-identifiers ()
1970 "Remove list identifies from the Subject header.
1971 The `gnus-list-identifiers' variable specifies what to do."
1975 (let ((inhibit-point-motion-hooks t)
1977 (article-narrow-to-head)
1978 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1979 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1981 (goto-char (point-min))
1982 (when (re-search-forward
1983 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1984 " *\\)\\)+\\(Re: +\\)?\\)")
1986 (let ((s (or (match-string 3) (match-string 5))))
1987 (delete-region (match-beginning 1) (match-end 1))
1989 (goto-char (match-beginning 1))
1992 (defun article-hide-pgp ()
1993 "Remove any PGP headers and signatures in the current article."
1997 (let ((inhibit-point-motion-hooks t)
1998 buffer-read-only beg end)
2000 ;; Hide the "header".
2001 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2002 (push 'pgp gnus-article-wash-types)
2003 (delete-region (match-beginning 0) (match-end 0))
2004 ;; Remove armor headers (rfc2440 6.2)
2005 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2008 ;; Hide the actual signature.
2009 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2010 (setq end (1+ (match-beginning 0)))
2013 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2015 ;; Perhaps we shouldn't hide to the end of the buffer
2016 ;; if there is no end to the signature?
2018 ;; Hide "- " PGP quotation markers.
2020 (narrow-to-region beg end)
2021 (goto-char (point-min))
2022 (while (re-search-forward "^- " nil t)
2024 (match-beginning 0) (match-end 0)))
2026 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2028 (defun article-hide-pem (&optional arg)
2029 "Toggle hiding of any PEM headers and signatures in the current article.
2030 If given a negative prefix, always show; if given a positive prefix,
2032 (interactive (gnus-article-hidden-arg))
2033 (unless (gnus-article-check-hidden-text 'pem arg)
2035 (let (buffer-read-only end)
2036 (goto-char (point-min))
2037 ;; Hide the horrendously ugly "header".
2038 (when (and (search-forward
2039 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2041 (setq end (1+ (match-beginning 0))))
2042 (push 'pem gnus-article-wash-types)
2043 (gnus-article-hide-text-type
2045 (if (search-forward "\n\n" nil t)
2049 ;; Hide the trailer as well
2050 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2052 (gnus-article-hide-text-type
2053 (match-beginning 0) (match-end 0) 'pem)))))))
2055 (defun article-strip-banner ()
2056 "Strip the banner specified by the `banner' group parameter."
2060 (let ((inhibit-point-motion-hooks t)
2061 (banner (gnus-parameter-banner gnus-newsgroup-name))
2062 (gnus-signature-limit nil)
2063 buffer-read-only beg end)
2067 ((eq banner 'signature)
2068 (when (gnus-article-narrow-to-signature)
2071 (delete-region (point) (point-max))))
2073 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2074 (while (re-search-forward banner nil t)
2075 (delete-region (match-beginning 0) (match-end 0)))))
2077 (while (re-search-forward banner nil t)
2078 (delete-region (match-beginning 0) (match-end 0))))))))))
2080 (defun article-babel ()
2081 "Translate article using an online translation service."
2085 (set-buffer gnus-article-buffer)
2086 (when (article-goto-body)
2087 (let* ((buffer-read-only nil)
2090 (orig (buffer-substring start end))
2091 (trans (babel-as-string orig)))
2093 (narrow-to-region start end)
2094 (delete-region start end)
2097 (defun article-hide-signature (&optional arg)
2098 "Hide the signature in the current article.
2099 If given a negative prefix, always show; if given a positive prefix,
2101 (interactive (gnus-article-hidden-arg))
2107 (article-goto-body))
2108 (goto-char (point-min)))
2109 (unless (gnus-article-check-hidden-text 'signature arg)
2110 (let ((buffer-read-only nil)
2112 (while (setq button (text-property-any button (point-max)
2114 'gnus-signature-toggle))
2115 (setq button (text-property-not-all button (point-max)
2117 'gnus-signature-toggle))
2118 (when (and button (not (eobp)))
2119 (gnus-article-hide-text-type
2121 (next-single-property-change (1+ button) 'mime-view-entity
2125 (defun article-strip-headers-in-body ()
2126 "Strip offensive headers from bodies."
2130 (let ((case-fold-search t))
2131 (when (looking-at "x-no-archive:")
2132 (gnus-delete-line)))))
2134 (defun article-strip-leading-blank-lines ()
2135 "Remove all blank lines from the beginning of the article."
2138 (let ((inhibit-point-motion-hooks t)
2140 (when (article-goto-body)
2141 (while (and (not (eobp))
2142 (looking-at "[ \t]*$"))
2143 (gnus-delete-line))))))
2145 (defun article-narrow-to-head ()
2146 "Narrow the buffer to the head of the message.
2147 Point is left at the beginning of the narrowed-to region."
2149 (goto-char (point-min))
2150 (if (search-forward "\n\n" nil 1)
2153 (goto-char (point-min)))
2155 (defun article-goto-body ()
2156 "Place point at the start of the body."
2157 (goto-char (point-min))
2159 ;; This variable is only bound when dealing with separate
2161 (article-goto-body-goes-to-point-min-p
2163 ((search-forward "\n\n" nil t)
2166 (goto-char (point-max))
2169 (defun article-strip-multiple-blank-lines ()
2170 "Replace consecutive blank lines with one empty line."
2173 (let ((inhibit-point-motion-hooks t)
2175 ;; First make all blank lines empty.
2177 (while (re-search-forward "^[ \t]+$" nil t)
2178 (unless (gnus-annotation-in-region-p
2179 (match-beginning 0) (match-end 0))
2180 (replace-match "" nil t)))
2181 ;; Then replace multiple empty lines with a single empty line.
2183 (while (re-search-forward "\n\n\n+" nil t)
2184 (unless (gnus-annotation-in-region-p
2185 (match-beginning 0) (match-end 0))
2186 (replace-match "\n\n" t t))))))
2188 (defun article-strip-leading-space ()
2189 "Remove all white space from the beginning of the lines in the article."
2192 (let ((inhibit-point-motion-hooks t)
2195 (while (re-search-forward "^[ \t]+" nil t)
2196 (replace-match "" t t)))))
2198 (defun article-strip-trailing-space ()
2199 "Remove all white space from the end of the lines in the article."
2202 (let ((inhibit-point-motion-hooks t)
2205 (while (re-search-forward "[ \t]+$" nil t)
2206 (replace-match "" t t)))))
2208 (defun article-strip-blank-lines ()
2209 "Strip leading, trailing and multiple blank lines."
2211 (article-strip-leading-blank-lines)
2212 (article-remove-trailing-blank-lines)
2213 (article-strip-multiple-blank-lines))
2215 (defun article-strip-all-blank-lines ()
2216 "Strip all blank lines."
2219 (let ((inhibit-point-motion-hooks t)
2222 (while (re-search-forward "^[ \t]*\n" nil t)
2223 (replace-match "" t t)))))
2225 (defun gnus-article-narrow-to-signature ()
2226 "Narrow to the signature; return t if a signature is found, else nil."
2227 (let ((inhibit-point-motion-hooks t))
2228 (when (gnus-article-search-signature)
2230 ;; Check whether we have some limits to what we consider
2231 ;; to be a signature.
2232 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2233 (list gnus-signature-limit)))
2235 (while (setq limit (pop limits))
2236 (if (or (and (integerp limit)
2237 (< (- (point-max) (point)) limit))
2239 (< (count-lines (point) (point-max)) limit))
2240 (and (gnus-functionp limit)
2242 (and (stringp limit)
2243 (not (re-search-forward limit nil t))))
2244 () ; This limit did not succeed.
2248 (narrow-to-region (point) (point-max))
2251 (defun gnus-article-search-signature ()
2252 "Search the current buffer for the signature separator.
2253 Put point at the beginning of the signature separator."
2254 (let ((cur (point)))
2255 (goto-char (point-max))
2256 (if (if (stringp gnus-signature-separator)
2257 (re-search-backward gnus-signature-separator nil t)
2258 (let ((seps gnus-signature-separator))
2260 (not (re-search-backward (car seps) nil t)))
2267 (defun gnus-article-hidden-arg ()
2268 "Return the current prefix arg as a number, or 0 if no prefix."
2269 (list (if current-prefix-arg
2270 (prefix-numeric-value current-prefix-arg)
2273 (defun gnus-article-check-hidden-text (type arg)
2274 "Return nil if hiding is necessary.
2275 Arg can be nil or a number. Nil and positive means hide, negative
2276 means show, 0 means toggle."
2279 (let ((hide (gnus-article-hidden-text-p type)))
2285 (gnus-article-show-hidden-text type)
2288 (if (eq hide 'hidden)
2290 (gnus-article-show-hidden-text type)
2294 (defun gnus-article-hidden-text-p (type)
2295 "Say whether the current buffer contains hidden text of type TYPE."
2296 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2298 (not (get-text-property pos 'invisible))
2299 (not (get-text-property pos 'dummy-invisible)))
2301 (text-property-any (1+ pos) (point-max) 'article-type type)))
2306 (defun gnus-article-show-hidden-text (type &optional dummy)
2307 "Show all hidden text of type TYPE.
2308 Originally it is hide instead of DUMMY."
2309 (let ((buffer-read-only nil)
2310 (inhibit-point-motion-hooks t))
2311 (gnus-remove-text-properties-when
2313 (point-min) (point-max)
2314 (cons 'article-type (cons type
2315 gnus-hidden-properties)))))
2317 (defconst article-time-units
2318 `((year . ,(* 365.25 24 60 60))
2319 (week . ,(* 7 24 60 60))
2320 (day . ,(* 24 60 60))
2324 "Mapping from time units to seconds.")
2326 (defun article-date-ut (&optional type highlight header)
2327 "Convert DATE date to universal time in the current article.
2328 If TYPE is `local', convert to local time; if it is `lapsed', output
2329 how much time has lapsed since DATE. For `lapsed', the value of
2330 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2331 should replace the \"Date:\" one, or should be added below it."
2332 (interactive (list 'ut t))
2333 (let* ((header (or header
2334 (and (eq 1 (point-min))
2335 (mail-header-date (save-excursion
2336 (set-buffer gnus-summary-buffer)
2337 gnus-current-headers)))
2338 (message-fetch-field "date")
2340 (date (if (vectorp header) (mail-header-date header)
2342 (inhibit-point-motion-hooks t)
2343 bface eface date-pos)
2344 (when (and date (not (string= date "")))
2347 (article-narrow-to-head)
2348 (when (or (and (eq type 'lapsed)
2349 gnus-article-date-lapsed-new-header
2350 ;; Attempt to get the face of X-Sent first.
2351 (re-search-forward "^X-Sent:[ \t]" nil t))
2352 (re-search-forward "^Date:[ \t]" nil t)
2353 ;; If Date is missing, try again for X-Sent.
2354 (re-search-forward "^X-Sent:[ \t]" nil t))
2355 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2356 date (or (get-text-property (gnus-point-at-bol)
2359 eface (get-text-property (1- (gnus-point-at-eol))
2361 (let ((buffer-read-only nil))
2362 ;; Delete any old X-Sent headers.
2363 (when (setq date-pos
2364 (text-property-any (point-min) (point-max)
2365 'article-date-lapsed t))
2366 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2367 (delete-region (match-beginning 0)
2368 (progn (forward-line 1) (point))))
2369 (goto-char (point-min))
2370 ;; Delete any old Date headers.
2371 (while (re-search-forward "^Date:[ \t]" nil t)
2373 (setq date-pos (match-beginning 0)))
2374 (unless (and (eq type 'lapsed)
2375 gnus-article-date-lapsed-new-header)
2376 (delete-region (match-beginning 0)
2377 (progn (message-next-header) (point)))))
2380 (goto-char date-pos)
2382 ;; Possibly, Date has been deleted.
2384 (when (and (eq type 'lapsed)
2385 gnus-article-date-lapsed-new-header
2386 (looking-at "Date:"))
2388 (goto-char (point-min)))
2389 (insert (article-make-date-line date type))
2390 (when (eq type 'lapsed)
2391 (put-text-property (gnus-point-at-bol) (point)
2392 'article-date-lapsed t))
2396 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2397 (put-text-property (match-beginning 1) (1+ (match-end 1))
2398 'original-date date)
2399 (put-text-property (match-beginning 1) (1+ (match-end 1))
2401 (put-text-property (match-beginning 2) (match-end 2)
2404 (defun article-make-date-line (date type)
2405 "Return a DATE line of TYPE."
2406 (let ((time (condition-case ()
2410 ;; Convert to the local timezone. We have to slap a
2411 ;; `condition-case' round the calls to the timezone
2412 ;; functions since they aren't particularly resistant to
2415 (let ((tz (car (current-time-zone time))))
2416 (format "Date: %s %s%02d%02d" (current-time-string time)
2417 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2418 (/ (% (abs tz) 3600) 60))))
2419 ;; Convert to Universal Time.
2422 (current-time-string
2423 (let* ((e (parse-time-string date))
2424 (tm (apply 'encode-time e))
2426 (ls (- (cadr tm) (car (current-time-zone time)))))
2427 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2428 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2431 ;; Get the original date from the article.
2432 ((eq type 'original)
2433 (concat "Date: " (if (string-match "\n+$" date)
2434 (substring date 0 (match-beginning 0))
2436 ;; Let the user define the format.
2438 (if (gnus-functionp gnus-article-time-format)
2439 (funcall gnus-article-time-format time)
2442 (format-time-string gnus-article-time-format time))))
2445 (let ((tz (car (current-time-zone time))))
2448 (format-time-string "%Y%m%dT%H%M%S" time)
2449 (format "%s%02d%02d"
2450 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2451 (/ (% (abs tz) 3600) 60)))))
2452 ;; Do an X-Sent lapsed format.
2454 ;; If the date is seriously mangled, the timezone functions are
2455 ;; liable to bug out, so we ignore all errors.
2456 (let* ((now (current-time))
2457 (real-time (subtract-time now time))
2458 (real-sec (and real-time
2459 (+ (* (float (car real-time)) 65536)
2461 (sec (and real-time (abs real-sec)))
2471 ;; This is a bit convoluted, but basically we go
2472 ;; through the time units for years, weeks, etc,
2473 ;; and divide things to see whether that results
2474 ;; in positive answers.
2477 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2478 ;; The (remaining) seconds are too few to
2479 ;; be divided into this time unit.
2481 ;; It's big enough, so we output it.
2482 (setq sec (- sec (* num (cdr unit))))
2484 (concat (if prev ", " "") (int-to-string
2486 " " (symbol-name (car unit))
2487 (if (> num 1) "s" ""))
2489 article-time-units "")
2490 ;; If dates are odd, then it might appear like the
2491 ;; article was sent in the future.
2494 " in the future"))))))
2495 ;; Display the date in proper English
2497 (let ((dtime (decode-time time)))
2500 (number-to-string (nth 3 dtime))
2501 (let ((digit (% (nth 3 dtime) 10)))
2503 ((memq (nth 3 dtime) '(11 12 13)) "th")
2509 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2511 (number-to-string (nth 5 dtime))
2513 (format "%02d" (nth 2 dtime))
2515 (format "%02d" (nth 1 dtime)))))
2517 (error "Unknown conversion type: %s" type)))))
2519 (defun article-date-local (&optional highlight)
2520 "Convert the current article date to the local timezone."
2521 (interactive (list t))
2522 (article-date-ut 'local highlight))
2524 (defun article-date-english (&optional highlight)
2525 "Convert the current article date to something that is proper English."
2526 (interactive (list t))
2527 (article-date-ut 'english highlight))
2529 (defun article-date-original (&optional highlight)
2530 "Convert the current article date to what it was originally.
2531 This is only useful if you have used some other date conversion
2532 function and want to see what the date was before converting."
2533 (interactive (list t))
2534 (article-date-ut 'original highlight))
2536 (defun article-date-lapsed (&optional highlight)
2537 "Convert the current article date to time lapsed since it was sent."
2538 (interactive (list t))
2539 (article-date-ut 'lapsed highlight))
2541 (defun article-update-date-lapsed ()
2542 "Function to be run from a timer to update the lapsed time line."
2543 (let (deactivate-mark)
2548 (set-buffer (window-buffer w))
2549 (when (eq major-mode 'gnus-article-mode)
2550 (goto-char (point-min))
2551 (when (re-search-forward "^X-Sent:" nil t)
2552 (article-date-lapsed t))))
2555 (defun gnus-start-date-timer (&optional n)
2556 "Start a timer to update the X-Sent header in the article buffers.
2557 The numerical prefix says how frequently (in seconds) the function
2562 (gnus-stop-date-timer)
2563 (setq article-lapsed-timer
2564 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2566 (defun gnus-stop-date-timer ()
2567 "Stop the X-Sent timer."
2569 (when article-lapsed-timer
2570 (nnheader-cancel-timer article-lapsed-timer)
2571 (setq article-lapsed-timer nil)))
2573 (defun article-date-user (&optional highlight)
2574 "Convert the current article date to the user-defined format.
2575 This format is defined by the `gnus-article-time-format' variable."
2576 (interactive (list t))
2577 (article-date-ut 'user highlight))
2579 (defun article-date-iso8601 (&optional highlight)
2580 "Convert the current article date to ISO8601."
2581 (interactive (list t))
2582 (article-date-ut 'iso8601 highlight))
2584 (defun article-show-all ()
2585 "Show all hidden text in the article buffer."
2589 (let ((buffer-read-only nil))
2590 (gnus-article-unhide-text (point-min) (point-max))
2591 (gnus-remove-text-with-property 'gnus-prev)
2592 (gnus-remove-text-with-property 'gnus-next))))
2594 (defun article-show-all-headers ()
2595 "Show all hidden headers in the article buffer."
2600 (article-narrow-to-head)
2601 (let ((buffer-read-only nil))
2602 (gnus-article-unhide-text (point-min) (point-max))))))
2604 (defun article-emphasize (&optional arg)
2605 "Emphasize text according to `gnus-emphasis-alist'."
2606 (interactive (gnus-article-hidden-arg))
2607 (unless (gnus-article-check-hidden-text 'emphasis arg)
2611 (with-current-buffer gnus-summary-buffer
2612 gnus-article-emphasis-alist)
2614 gnus-emphasis-alist))
2615 (buffer-read-only nil)
2616 (props (append '(article-type emphasis)
2617 gnus-hidden-properties))
2618 regexp elem beg invisible visible face)
2621 (while (setq elem (pop alist))
2623 (setq regexp (car elem)
2624 invisible (nth 1 elem)
2625 visible (nth 2 elem)
2627 (while (re-search-forward regexp nil t)
2628 (when (and (match-beginning visible) (match-beginning invisible))
2629 (push 'emphasis gnus-article-wash-types)
2630 (gnus-article-hide-text
2631 (match-beginning invisible) (match-end invisible) props)
2632 (gnus-article-unhide-text-type
2633 (match-beginning visible) (match-end visible) 'emphasis)
2634 (gnus-put-text-property-excluding-newlines
2635 (match-beginning visible) (match-end visible) 'face face)
2636 (goto-char (match-end invisible)))))))))
2638 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2639 "Setup newsgroup emphasis alist."
2640 (unless gnus-article-emphasis-alist
2641 (let ((name (and gnus-newsgroup-name
2642 (gnus-group-real-name gnus-newsgroup-name))))
2643 (make-local-variable 'gnus-article-emphasis-alist)
2644 (setq gnus-article-emphasis-alist
2646 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2647 (while (setq elem (pop alist))
2648 (when (and name (string-match (car elem) name))
2650 highlight (copy-sequence (cdr elem)))))
2652 (copy-sequence highlight-words)
2653 (if gnus-newsgroup-name
2654 (copy-sequence (gnus-group-find-parameter
2655 gnus-newsgroup-name 'highlight-words t)))
2656 gnus-emphasis-alist)))))
2658 (defvar gnus-summary-article-menu)
2659 (defvar gnus-summary-post-menu)
2661 ;;; Saving functions.
2663 (defun gnus-article-save (save-buffer file &optional num)
2664 "Save the currently selected article."
2665 (unless gnus-save-all-headers
2666 ;; Remove headers according to `gnus-saved-headers'.
2667 (let ((gnus-visible-headers
2668 (or gnus-saved-headers gnus-visible-headers))
2669 (gnus-article-buffer save-buffer))
2671 (set-buffer save-buffer)
2672 (article-hide-headers 1 t))))
2673 (save-window-excursion
2674 (if (not gnus-default-article-saver)
2675 (error "No default saver is defined")
2676 ;; !!! Magic! The saving functions all save
2677 ;; `gnus-save-article-buffer' (or so they think), but we
2678 ;; bind that variable to our save-buffer.
2679 (set-buffer gnus-article-buffer)
2680 (let* ((gnus-save-article-buffer save-buffer)
2683 ((not gnus-prompt-before-saving) 'default)
2684 ((eq gnus-prompt-before-saving 'always) nil)
2686 (gnus-number-of-articles-to-be-saved
2687 (when (eq gnus-prompt-before-saving t)
2689 (set-buffer gnus-article-current-summary)
2690 (funcall gnus-default-article-saver filename)))))
2692 (defun gnus-read-save-file-name (prompt &optional filename
2693 function group headers variable)
2695 (funcall function group headers (symbol-value variable)))
2700 ((eq filename 'default)
2706 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2709 (if (and gnus-number-of-articles-to-be-saved
2710 (> gnus-number-of-articles-to-be-saved 1))
2711 (format "these %d articles"
2712 gnus-number-of-articles-to-be-saved)
2715 ;; Let the split methods have their say.
2717 ;; No split name was found.
2720 (concat prompt " (default "
2721 (file-name-nondirectory default-name) ") ")
2722 (file-name-directory default-name)
2724 ;; A single group name is returned.
2725 ((stringp split-name)
2727 (funcall function split-name headers
2728 (symbol-value variable)))
2730 (concat prompt " (default "
2731 (file-name-nondirectory default-name) ") ")
2732 (file-name-directory default-name)
2734 ;; A single split name was found
2735 ((= 1 (length split-name))
2736 (let* ((name (expand-file-name
2738 gnus-article-save-directory))
2739 (dir (cond ((file-directory-p name)
2740 (file-name-as-directory name))
2741 ((file-exists-p name) name)
2742 (t gnus-article-save-directory))))
2744 (concat prompt " (default " name ") ")
2746 ;; A list of splits was found.
2748 (setq split-name (nreverse split-name))
2750 (let ((file-name-history
2751 (nconc split-name file-name-history)))
2755 (concat prompt " (`M-p' for defaults) ")
2756 gnus-article-save-directory
2758 gnus-article-save-directory)))
2759 (car (push result file-name-history)))))))
2760 ;; Create the directory.
2761 (gnus-make-directory (file-name-directory file))
2762 ;; If we have read a directory, we append the default file name.
2763 (when (file-directory-p file)
2764 (setq file (expand-file-name (file-name-nondirectory
2766 (file-name-as-directory file))))
2767 ;; Possibly translate some characters.
2768 (nnheader-translate-file-chars file))))))
2769 (gnus-make-directory (file-name-directory result))
2770 (set variable result)))
2772 (defun gnus-article-archive-name (group)
2773 "Return the first instance of an \"Archive-name\" in the current buffer."
2774 (let ((case-fold-search t))
2775 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2776 (nnheader-concat gnus-article-save-directory
2777 (match-string 1)))))
2779 (defun gnus-article-nndoc-name (group)
2780 "If GROUP is an nndoc group, return the name of the parent group."
2781 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2782 (gnus-group-get-parameter group 'save-article-group)))
2784 (defun gnus-summary-save-in-rmail (&optional filename)
2785 "Append this article to Rmail file.
2786 Optional argument FILENAME specifies file name.
2787 Directory to save to is default to `gnus-article-save-directory'."
2788 (setq filename (gnus-read-save-file-name
2789 "Save %s in rmail file:" filename
2790 gnus-rmail-save-name gnus-newsgroup-name
2791 gnus-current-headers 'gnus-newsgroup-last-rmail))
2792 (gnus-eval-in-buffer-window gnus-save-article-buffer
2796 (gnus-output-to-rmail filename))))
2799 (defun gnus-summary-save-in-mail (&optional filename)
2800 "Append this article to Unix mail file.
2801 Optional argument FILENAME specifies file name.
2802 Directory to save to is default to `gnus-article-save-directory'."
2803 (setq filename (gnus-read-save-file-name
2804 "Save %s in Unix mail file:" filename
2805 gnus-mail-save-name gnus-newsgroup-name
2806 gnus-current-headers 'gnus-newsgroup-last-mail))
2807 (gnus-eval-in-buffer-window gnus-save-article-buffer
2811 (if (and (file-readable-p filename)
2812 (mail-file-babyl-p filename))
2813 (rmail-output-to-rmail-file filename t)
2814 (gnus-output-to-mail filename)))))
2817 (defun gnus-summary-save-in-file (&optional filename overwrite)
2818 "Append this article to file.
2819 Optional argument FILENAME specifies file name.
2820 Directory to save to is default to `gnus-article-save-directory'."
2821 (setq filename (gnus-read-save-file-name
2822 "Save %s in file:" filename
2823 gnus-file-save-name gnus-newsgroup-name
2824 gnus-current-headers 'gnus-newsgroup-last-file))
2825 (gnus-eval-in-buffer-window gnus-save-article-buffer
2829 (when (and overwrite
2830 (file-exists-p filename))
2831 (delete-file filename))
2832 (gnus-output-to-file filename))))
2835 (defun gnus-summary-write-to-file (&optional filename)
2836 "Write this article to a file.
2837 Optional argument FILENAME specifies file name.
2838 The directory to save in defaults to `gnus-article-save-directory'."
2839 (gnus-summary-save-in-file nil t))
2841 (defun gnus-summary-save-body-in-file (&optional filename)
2842 "Append this article body to a file.
2843 Optional argument FILENAME specifies file name.
2844 The directory to save in defaults to `gnus-article-save-directory'."
2845 (setq filename (gnus-read-save-file-name
2846 "Save %s body in file:" filename
2847 gnus-file-save-name gnus-newsgroup-name
2848 gnus-current-headers 'gnus-newsgroup-last-file))
2849 (gnus-eval-in-buffer-window gnus-save-article-buffer
2853 (when (article-goto-body)
2854 (narrow-to-region (point) (point-max)))
2855 (gnus-output-to-file filename))))
2858 (defun gnus-summary-save-in-pipe (&optional command)
2859 "Pipe this article to subprocess."
2861 (cond ((and (eq command 'default)
2862 gnus-last-shell-command)
2863 gnus-last-shell-command)
2868 "Shell command on %s: "
2869 (if (and gnus-number-of-articles-to-be-saved
2870 (> gnus-number-of-articles-to-be-saved 1))
2871 (format "these %d articles"
2872 gnus-number-of-articles-to-be-saved)
2874 gnus-last-shell-command))))
2875 (when (string-equal command "")
2876 (if gnus-last-shell-command
2877 (setq command gnus-last-shell-command)
2878 (error "A command is required.")))
2879 (gnus-eval-in-buffer-window gnus-article-buffer
2882 (shell-command-on-region (point-min) (point-max) command nil)))
2883 (setq gnus-last-shell-command command))
2885 ;;; Article file names when saving.
2887 (defun gnus-capitalize-newsgroup (newsgroup)
2888 "Capitalize NEWSGROUP name."
2889 (when (not (zerop (length newsgroup)))
2890 (concat (char-to-string (upcase (aref newsgroup 0)))
2891 (substring newsgroup 1))))
2893 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2894 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2895 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2896 Otherwise, it is like ~/News/news/group/num."
2899 (concat (if (gnus-use-long-file-name 'not-save)
2900 (gnus-capitalize-newsgroup newsgroup)
2901 (gnus-newsgroup-directory-form newsgroup))
2902 "/" (int-to-string (mail-header-number headers)))
2903 gnus-article-save-directory)))
2905 (string-equal (file-name-directory default)
2906 (file-name-directory last-file))
2907 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2909 (or last-file default))))
2911 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2912 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2913 If variable `gnus-use-long-file-name' is non-nil, it is
2914 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2917 (concat (if (gnus-use-long-file-name 'not-save)
2919 (gnus-newsgroup-directory-form newsgroup))
2920 "/" (int-to-string (mail-header-number headers)))
2921 gnus-article-save-directory)))
2923 (string-equal (file-name-directory default)
2924 (file-name-directory last-file))
2925 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2927 (or last-file default))))
2929 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2930 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2931 If variable `gnus-use-long-file-name' is non-nil, it is
2932 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2935 (if (gnus-use-long-file-name 'not-save)
2937 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2938 gnus-article-save-directory)))
2940 (defun article-verify-x-pgp-sig ()
2943 (if (gnus-buffer-live-p gnus-original-article-buffer)
2944 (let ((sig (with-current-buffer gnus-original-article-buffer
2945 (gnus-fetch-field "X-PGP-Sig")))
2949 (mml2015-clear-verify-function))
2951 (insert-buffer gnus-original-article-buffer)
2952 (setq items (split-string sig))
2953 (message-narrow-to-head)
2954 (let ((inhibit-point-motion-hooks t)
2955 (case-fold-search t))
2956 ;; Don't verify multiple headers.
2957 (setq headers (mapconcat (lambda (header)
2959 (mail-fetch-field header) "\n"))
2960 (split-string (nth 1 items) ",") "")))
2961 (delete-region (point-min) (point-max))
2962 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2963 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2968 (if (looking-at "^-")
2971 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2972 (insert "Version: " (car items) "\n\n")
2973 (insert (mapconcat 'identity (cddr items) "\n"))
2974 (insert "\n-----END PGP SIGNATURE-----\n")
2975 (let ((mm-security-handle (list (format "multipart/signed"))))
2976 (mml2015-clean-buffer)
2977 (let ((coding-system-for-write (or gnus-newsgroup-charset
2979 (funcall (mml2015-clear-verify-function)))
2981 (or (mm-handle-multipart-ctl-parameter
2982 mm-security-handle 'gnus-details)
2983 (mm-handle-multipart-ctl-parameter
2984 mm-security-handle 'gnus-info)))))
2986 (let (buffer-read-only bface eface)
2988 (message-narrow-to-head)
2989 (goto-char (point-max))
2991 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2992 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2993 (message-remove-header "X-Gnus-PGP-Verify")
2994 (if (re-search-forward "^X-PGP-Sig:" nil t)
2996 (goto-char (point-max)))
2997 (narrow-to-region (point) (point))
2998 (insert "X-Gnus-PGP-Verify: " info "\n")
2999 (goto-char (point-min))
3002 (if (not (looking-at "^[ \t]"))
3006 (goto-char (point-min))
3007 (when (looking-at "\\([^:]+\\): *")
3008 (put-text-property (match-beginning 1) (1+ (match-end 1))
3010 (put-text-property (match-end 0) (point-max)
3011 'face eface)))))))))
3018 (setq afunc (car func)
3021 gfunc (intern (format "gnus-%s" func))))
3024 `(lambda (&optional interactive &rest args)
3025 ,(documentation afunc t)
3026 (interactive (list t))
3028 (set-buffer gnus-article-buffer)
3030 (call-interactively ',afunc)
3031 (apply ',afunc args))))))))
3032 '(article-hide-headers
3033 article-verify-x-pgp-sig
3034 article-hide-boring-headers
3035 article-toggle-headers
3036 article-treat-overstrike
3037 article-fill-long-lines
3038 article-capitalize-sentences
3040 article-display-x-face
3041 article-de-quoted-unreadable
3042 article-de-base64-unreadable
3045 article-hide-list-identifiers
3047 article-strip-banner
3050 article-hide-signature
3051 article-strip-headers-in-body
3052 article-remove-trailing-blank-lines
3053 article-strip-leading-blank-lines
3054 article-strip-multiple-blank-lines
3055 article-strip-leading-space
3056 article-strip-trailing-space
3057 article-strip-blank-lines
3058 article-strip-all-blank-lines
3060 article-date-english
3061 article-date-iso8601
3062 article-date-original
3064 article-decode-mime-words
3065 article-decode-charset
3066 article-decode-encoded-words
3070 article-treat-dumbquotes
3071 article-normalize-headers
3072 (article-show-all-headers . gnus-article-show-all-headers)
3073 (article-show-all . gnus-article-show-all))))
3076 ;;; Gnus article mode
3079 (put 'gnus-article-mode 'mode-class 'special)
3081 (gnus-define-keys gnus-article-mode-map
3082 " " gnus-article-goto-next-page
3083 "\177" gnus-article-goto-prev-page
3084 [delete] gnus-article-goto-prev-page
3085 [backspace] gnus-article-goto-prev-page
3086 "\C-c^" gnus-article-refer-article
3087 "h" gnus-article-show-summary
3088 "s" gnus-article-show-summary
3089 "\C-c\C-m" gnus-article-mail
3090 "?" gnus-article-describe-briefly
3091 "e" gnus-summary-edit-article
3092 "<" beginning-of-buffer
3094 "\C-c\C-i" gnus-info-find-node
3096 "\C-hk" gnus-article-describe-key
3097 "\C-hc" gnus-article-describe-key-briefly
3099 "\C-d" gnus-article-read-summary-keys
3100 "\M-*" gnus-article-read-summary-keys
3101 "\M-#" gnus-article-read-summary-keys
3102 "\M-^" gnus-article-read-summary-keys
3103 "\M-g" gnus-article-read-summary-keys)
3105 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3108 (unless (lookup-key gnus-article-mode-map key)
3109 (define-key gnus-article-mode-map key
3110 'gnus-article-read-summary-keys)))
3115 (let ((key (car elt)))
3116 (and (> (length key) 0)
3117 (not (eq 'menu-bar (aref key 0)))
3118 (symbolp (lookup-key gnus-summary-mode-map key))
3120 (accessible-keymaps gnus-summary-mode-map))
3124 (push (char-to-string c) keys)
3129 (defvar gnus-article-commands-menu))
3131 (defun gnus-article-make-menu-bar ()
3132 (gnus-turn-off-edit-menu 'article)
3133 (unless (boundp 'gnus-article-article-menu)
3135 gnus-article-article-menu gnus-article-mode-map ""
3137 ["Scroll forwards" gnus-article-goto-next-page t]
3138 ["Scroll backwards" gnus-article-goto-prev-page t]
3139 ["Show summary" gnus-article-show-summary t]
3140 ["Fetch Message-ID at point" gnus-article-refer-article t]
3141 ["Mail to address at point" gnus-article-mail t]
3142 ["Send a bug report" gnus-bug t]))
3145 gnus-article-treatment-menu gnus-article-mode-map ""
3146 ;; Fixme: this should use :active (and maybe :visible).
3148 ["Hide headers" gnus-article-toggle-headers t]
3149 ["Hide signature" gnus-article-hide-signature t]
3150 ["Hide citation" gnus-article-hide-citation t]
3151 ["Treat overstrike" gnus-article-treat-overstrike t]
3152 ["Remove carriage return" gnus-article-remove-cr t]
3153 ["Decode HZ" gnus-article-decode-HZ t]))
3155 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3157 (when (boundp 'gnus-summary-post-menu)
3158 (define-key gnus-article-mode-map [menu-bar post]
3159 (cons "Post" gnus-summary-post-menu)))
3161 (gnus-run-hooks 'gnus-article-menu-hook))
3163 (when (boundp 'gnus-article-commands-menu)
3164 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
3165 (when (boundp 'gnus-summary-post-menu)
3166 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
3168 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3171 (defun gnus-article-mode ()
3172 "Major mode for displaying an article.
3174 All normal editing commands are switched off.
3176 The following commands are available in addition to all summary mode
3178 \\<gnus-article-mode-map>
3179 \\[gnus-article-next-page]\t Scroll the article one page forwards
3180 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3181 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3182 \\[gnus-article-show-summary]\t Display the summary buffer
3183 \\[gnus-article-mail]\t Send a reply to the address near point
3184 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3185 \\[gnus-info-find-node]\t Go to the Gnus info node"
3187 (when (gnus-visual-p 'article-menu 'menu)
3188 (gnus-article-make-menu-bar))
3189 (gnus-simplify-mode-line)
3190 (setq mode-name "Article")
3191 (setq major-mode 'gnus-article-mode)
3192 (make-local-variable 'minor-mode-alist)
3193 (unless (assq 'gnus-show-mime minor-mode-alist)
3194 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3195 (use-local-map gnus-article-mode-map)
3196 (gnus-update-format-specifications nil 'article-mode)
3197 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3198 (make-local-variable 'gnus-page-broken)
3199 (make-local-variable 'gnus-button-marker-list)
3200 (make-local-variable 'gnus-article-current-summary)
3201 (make-local-variable 'gnus-article-mime-handles)
3202 (make-local-variable 'gnus-article-decoded-p)
3203 (make-local-variable 'gnus-article-mime-handle-alist)
3204 (make-local-variable 'gnus-article-wash-types)
3205 (make-local-variable 'gnus-article-charset)
3206 (make-local-variable 'gnus-article-ignored-charsets)
3207 (gnus-set-default-directory)
3208 (buffer-disable-undo)
3209 (setq buffer-read-only t)
3210 (set-syntax-table gnus-article-mode-syntax-table)
3211 (gnus-run-hooks 'gnus-article-mode-hook))
3213 (defun gnus-article-setup-buffer ()
3214 "Initialize the article buffer."
3215 (let* ((name (if gnus-single-article-buffer "*Article*"
3216 (concat "*Article " gnus-newsgroup-name "*")))
3218 (progn (string-match "\\*Article" name)
3219 (concat " *Original Article"
3220 (substring name (match-end 0))))))
3221 (setq gnus-article-buffer name)
3222 (setq gnus-original-article-buffer original)
3223 (setq gnus-article-mime-handle-alist nil)
3224 ;; This might be a variable local to the summary buffer.
3225 (unless gnus-single-article-buffer
3227 (set-buffer gnus-summary-buffer)
3228 (setq gnus-article-buffer name)
3229 (setq gnus-original-article-buffer original)
3230 (gnus-set-global-variables)))
3231 (gnus-article-setup-highlight-words)
3232 ;; Init original article buffer.
3234 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3235 (set-buffer-multibyte nil)
3236 (setq major-mode 'gnus-original-article-mode)
3237 (make-local-variable 'gnus-original-article))
3238 (if (get-buffer name)
3241 (buffer-disable-undo)
3242 (setq buffer-read-only t)
3243 (unless (eq major-mode 'gnus-article-mode)
3244 (gnus-article-mode))
3247 (set-buffer (gnus-get-buffer-create name))
3249 (make-local-variable 'gnus-summary-buffer)
3250 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3251 (current-buffer)))))
3253 ;; Set article window start at LINE, where LINE is the number of lines
3254 ;; from the head of the article.
3255 (defun gnus-article-set-window-start (&optional line)
3257 (get-buffer-window gnus-article-buffer t)
3259 (set-buffer gnus-article-buffer)
3260 (goto-char (point-min))
3263 (gnus-message 6 "Moved to bookmark")
3264 (search-forward "\n\n" nil t)
3268 ;;; @@ article filters
3271 (defun gnus-article-display-mime-message ()
3272 "Article display method for MIME message."
3273 ;; called from `gnus-original-article-buffer'.
3274 (let (charset all-headers)
3275 (with-current-buffer gnus-summary-buffer
3276 (setq charset default-mime-charset
3277 all-headers gnus-have-all-headers))
3278 (make-local-variable 'default-mime-charset)
3279 (setq default-mime-charset charset)
3280 (with-current-buffer (get-buffer-create gnus-article-buffer)
3281 (make-local-variable 'default-mime-charset)
3282 (setq default-mime-charset charset))
3283 (mime-display-message mime-message-structure
3284 gnus-article-buffer nil gnus-article-mode-map)
3286 (gnus-article-hide-headers nil -1)))
3287 (run-hooks 'gnus-mime-article-prepare-hook))
3289 (defun gnus-article-display-traditional-message ()
3290 "Article display method for traditional message."
3291 (set-buffer gnus-article-buffer)
3292 (let (buffer-read-only)
3294 (insert-buffer-substring gnus-original-article-buffer)))
3296 (defun gnus-article-make-full-mail-header (&optional number charset)
3297 "Create a new mail header structure in a raw article buffer."
3298 (unless (and number charset)
3299 (save-current-buffer
3300 (set-buffer gnus-summary-buffer)
3302 (setq number (or (cdr gnus-article-current) 0)))
3304 (setq charset (or default-mime-charset 'x-ctext)))))
3305 (goto-char (point-min))
3306 (let ((header-end (if (search-forward "\n\n" nil t)
3308 (goto-char (point-max))))
3309 (chars (- (point-max) (point)))
3310 (lines (count-lines (point) (point-max)))
3311 (default-mime-charset charset)
3313 (narrow-to-region (point-min) header-end)
3314 (setq xref (std11-fetch-field "xref"))
3316 (make-full-mail-header
3318 (std11-fetch-field "subject")
3319 (std11-fetch-field "from")
3320 (std11-fetch-field "date")
3321 (std11-fetch-field "message-id")
3322 (std11-fetch-field "references")
3325 (when xref (concat "Xref: " xref)))
3328 (defun gnus-article-prepare (article &optional all-headers header)
3329 "Prepare ARTICLE in article mode buffer.
3330 ARTICLE should either be an article number or a Message-ID.
3331 If ARTICLE is an id, HEADER should be the article headers.
3332 If ALL-HEADERS is non-nil, no headers are hidden."
3334 ;; Make sure we start in a summary buffer.
3335 (unless (eq major-mode 'gnus-summary-mode)
3336 (set-buffer gnus-summary-buffer))
3337 (setq gnus-summary-buffer (current-buffer))
3338 (let* ((gnus-article (if header (mail-header-number header) article))
3339 (summary-buffer (current-buffer))
3340 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3341 (group gnus-newsgroup-name)
3344 (gnus-article-setup-buffer)
3345 (set-buffer gnus-original-article-buffer)
3346 ;; Deactivate active regions.
3347 (when (and (boundp 'transient-mark-mode)
3348 transient-mark-mode)
3349 (setq mark-active nil))
3350 (if (not (setq result (let ((buffer-read-only nil))
3351 (gnus-request-article-this-buffer
3353 ;; There is no such article.
3355 (when (and (numberp article)
3356 (not (memq article gnus-newsgroup-sparse)))
3357 (setq gnus-article-current
3358 (cons gnus-newsgroup-name article))
3359 (set-buffer gnus-summary-buffer)
3360 (setq gnus-current-article article)
3361 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3363 (gnus-summary-set-agent-mark article)
3364 (message "Message marked for downloading"))
3365 (gnus-summary-mark-article article gnus-canceled-mark)
3366 (unless (memq article gnus-newsgroup-sparse)
3367 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3368 (if (or (eq result 'pseudo)
3369 (eq result 'nneething))
3372 (set-buffer summary-buffer)
3373 (push article gnus-newsgroup-history)
3374 (setq gnus-last-article gnus-current-article
3375 gnus-current-article 0
3376 gnus-current-headers nil
3377 gnus-article-current nil)
3378 (if (eq result 'nneething)
3379 (gnus-configure-windows 'summary)
3380 (gnus-configure-windows 'article))
3381 (gnus-set-global-variables))
3382 (let ((gnus-article-mime-handle-alist-1
3383 gnus-article-mime-handle-alist))
3384 (gnus-set-mode-line 'article)))
3385 ;; The result from the `request' was an actual article -
3386 ;; or at least some text that is now displayed in the
3388 (when (and (numberp article)
3389 (not (eq article gnus-current-article)))
3390 ;; Seems like a new article has been selected.
3391 ;; `gnus-current-article' must be an article number.
3393 (set-buffer summary-buffer)
3394 (push article gnus-newsgroup-history)
3395 (setq gnus-last-article gnus-current-article
3396 gnus-current-article article
3397 gnus-current-headers
3398 (gnus-summary-article-header gnus-current-article)
3399 gnus-article-current
3400 (cons gnus-newsgroup-name gnus-current-article))
3401 (unless (vectorp gnus-current-headers)
3402 (setq gnus-current-headers nil))
3403 (gnus-summary-goto-subject gnus-current-article)
3404 (when (gnus-summary-show-thread)
3405 ;; If the summary buffer really was folded, the
3406 ;; previous goto may not actually have gone to
3407 ;; the right article, but the thread root instead.
3409 (gnus-summary-goto-subject gnus-current-article))
3410 (gnus-run-hooks 'gnus-mark-article-hook)
3411 (gnus-set-mode-line 'summary)
3412 (when (gnus-visual-p 'article-highlight 'highlight)
3413 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3414 ;; Set the global newsgroup variables here.
3415 (gnus-set-global-variables)
3416 (setq gnus-have-all-headers
3417 (or all-headers gnus-show-all-headers))))
3419 (gnus-configure-windows 'article))
3420 (when (or (numberp article)
3422 (gnus-article-prepare-display)
3424 (goto-char (point-min))
3425 (setq gnus-page-broken
3426 (when gnus-break-pages
3427 (gnus-narrow-to-page)
3429 (let ((gnus-article-mime-handle-alist-1
3430 gnus-article-mime-handle-alist))
3431 (gnus-set-mode-line 'article))
3433 (set-window-point (get-buffer-window (current-buffer)) (point))
3434 (gnus-configure-windows 'article)
3437 (defun gnus-article-prepare-mime-display (&optional number)
3438 (goto-char (point-min))
3439 (when (re-search-forward "^[^\t ]+:" nil t)
3440 (goto-char (match-beginning 0)))
3441 (let ((entity (if (eq 1 (point-min))
3442 (get-text-property 1 'mime-view-entity)
3443 (get-text-property (point) 'mime-view-entity)))
3444 last-entity child-entity next type)
3445 (setq child-entity (mime-entity-children entity))
3447 (setq last-entity (nth (1- (length child-entity))
3449 (setq last-entity entity))
3451 (narrow-to-region (point)
3452 (if (search-forward "\n\n" nil t)
3455 (gnus-treat-article 'head)
3456 (put-text-property (point-min) (point-max) 'article-treated-header t)
3457 (goto-char (point-max)))
3458 (while (and (not (eobp)) entity)
3459 (setq next (set-marker
3461 (next-single-property-change (point) 'mime-view-entity
3463 (let ((types (mime-entity-content-type entity)))
3464 (while (eq 'multipart (mime-content-type-primary-type types))
3465 (setq entity (car (mime-entity-children entity))
3466 types (mime-entity-content-type entity)))
3468 (setq type (format "%s/%s"
3469 (mime-content-type-primary-type types)
3470 (mime-content-type-subtype types)))))
3471 (if (string-equal type "message/rfc822")
3474 (let ((children (mime-entity-children entity))
3477 (setq last-children (nth (1- (length children)) children))
3480 (not (eq last-children
3481 (get-text-property next 'mime-view-entity)))
3483 (next-single-property-change next
3485 nil (point-max)))))))
3486 (setq next (next-single-property-change next 'mime-view-entity
3489 (narrow-to-region (point) next)
3490 (gnus-article-prepare-mime-display)
3491 (goto-char (point-max)))
3492 (setq entity (get-text-property (point) 'mime-view-entity)))
3494 (narrow-to-region (point) next)
3495 ;; Kludge. We have to count true number, but for now,
3496 ;; part number is here only to achieve `last'.
3497 (gnus-treat-article nil 1
3498 (if (eq entity last-entity)
3501 (goto-char (point-max)))
3502 (setq entity (get-text-property next 'mime-view-entity))))))
3505 (defun gnus-article-prepare-display ()
3506 "Make the current buffer look like a nice article."
3507 (setq gnus-article-wash-types nil)
3508 (gnus-run-hooks 'gnus-tmp-internal-hook)
3509 (gnus-run-hooks 'gnus-article-prepare-hook)
3511 (let (mime-display-header-hook mime-display-text/plain-hook)
3512 (funcall (if gnus-show-mime
3514 (setq mime-message-structure gnus-current-headers)
3515 (mime-buffer-entity-set-buffer-internal
3516 mime-message-structure
3517 gnus-original-article-buffer)
3518 (mime-entity-set-representation-type-internal
3519 mime-message-structure 'mime-buffer-entity)
3520 (luna-send mime-message-structure
3521 'initialize-instance
3522 mime-message-structure)
3523 gnus-article-display-method-for-mime)
3524 gnus-article-display-method-for-traditional)))
3525 ;; Associate this article with the current summary buffer.
3526 (setq gnus-article-current-summary gnus-summary-buffer)
3527 ;; Call the treatment functions.
3528 (let ((inhibit-read-only t)
3533 (gnus-article-prepare-mime-display)
3534 (narrow-to-region (goto-char (point-min))
3535 (if (search-forward "\n\n" nil t)
3538 (gnus-treat-article 'head)
3539 (put-text-property (point-min) (point-max) 'article-treated-header t)
3540 (goto-char (point-max))
3542 (narrow-to-region (point) (point-max))
3543 (gnus-treat-article nil))
3544 (put-text-property (point-min) (point-max) 'read-only nil)))
3545 ;; Perform the article display hooks. Incidentally, this hook is
3546 ;; an obsolete variable by now.
3547 (gnus-run-hooks 'gnus-article-display-hook))
3549 (defun gnus-article-decode-article-as-default-mime-charset ()
3550 "Decode an article as `default-mime-charset'. It won't work if the
3551 value of the variable `gnus-show-mime' is non-nil."
3552 (unless gnus-show-mime
3553 (decode-mime-charset-region (point-min) (point-max)
3554 (with-current-buffer gnus-summary-buffer
3555 default-mime-charset))))
3558 ;;; Gnus MIME viewing functions
3561 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3562 "The following specs can be used:
3564 %T MIME type, along with additional info
3565 %n The `name' parameter
3566 %d The description, if any
3567 %l The length of the encoded part
3568 %p The part identifier number
3569 %e Dots if the part isn't displayed")
3571 (defvar gnus-mime-button-line-format-alist
3572 '((?t gnus-tmp-type ?s)
3573 (?T gnus-tmp-type-long ?s)
3574 (?n gnus-tmp-name ?s)
3575 (?d gnus-tmp-description ?s)
3577 (?l gnus-tmp-length ?d)
3578 (?e gnus-tmp-dots ?s)))
3580 (defvar gnus-mime-button-commands
3581 '((gnus-article-press-button "\r" "Toggle Display")
3582 (gnus-mime-view-part "v" "View Interactively...")
3583 (gnus-mime-view-part-as-type "t" "View As Type...")
3584 (gnus-mime-view-part-as-charset "C" "View As charset...")
3585 (gnus-mime-save-part "o" "Save...")
3586 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3587 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3588 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3589 (gnus-mime-internalize-part "E" "View Internally")
3590 (gnus-mime-externalize-part "e" "View Externally")
3591 (gnus-mime-pipe-part "|" "Pipe To Command...")
3592 (gnus-mime-action-on-part "." "Take action on the part")))
3594 (defun gnus-article-mime-part-status ()
3595 (with-current-buffer gnus-article-buffer
3596 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3597 (if (and entity (mime-entity-children entity))
3598 (format " (%d parts)" (length (mime-entity-children entity)))
3601 (defvar gnus-mime-button-map
3602 (let ((map (make-sparse-keymap)))
3603 (unless (>= (string-to-number emacs-version) 21)
3604 ;; XEmacs doesn't care.
3605 (set-keymap-parent map gnus-article-mode-map))
3606 (define-key map gnus-mouse-2 'gnus-article-push-button)
3607 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3608 (dolist (c gnus-mime-button-commands)
3609 (define-key map (cadr c) (car c)))
3612 (defun gnus-mime-button-menu (event)
3613 "Construct a context-sensitive menu of MIME commands."
3615 (save-window-excursion
3616 (let ((pos (event-start event)))
3617 (select-window (posn-window pos))
3618 (goto-char (posn-point pos))
3619 (gnus-article-check-buffer)
3620 (let ((response (x-popup-menu
3622 ("" ,@(mapcar (lambda (c)
3623 (cons (caddr c) (car c)))
3624 gnus-mime-button-commands))))))
3626 (call-interactively response))))))
3628 (defun gnus-mime-view-all-parts (&optional handles)
3629 "View all the MIME parts."
3631 (save-current-buffer
3632 (set-buffer gnus-article-buffer)
3633 (let ((handles (or handles gnus-article-mime-handles))
3634 (mail-parse-charset gnus-newsgroup-charset)
3635 (mail-parse-ignored-charsets
3636 (with-current-buffer gnus-summary-buffer
3637 gnus-newsgroup-ignored-charsets)))
3639 (mm-remove-parts handles)
3640 (goto-char (point-min))
3641 (or (search-forward "\n\n") (goto-char (point-max)))
3642 (let (buffer-read-only)
3643 (delete-region (point) (point-max)))
3644 (mm-display-parts handles)))))
3646 (defun gnus-mime-save-part-and-strip ()
3647 "Save the MIME part under point then replace it with an external body."
3649 (gnus-article-check-buffer)
3650 (let* ((data (get-text-property (point) 'gnus-data))
3651 (file (and data (mm-save-part data)))
3654 (with-current-buffer (mm-handle-buffer data)
3656 (insert "Content-Type: " (mm-handle-media-type data))
3657 (mml-insert-parameter-string (cdr (mm-handle-type data))
3660 (insert "Content-ID: " (message-make-message-id) "\n")
3661 (insert "Content-Transfer-Encoding: binary\n")
3664 (cdr (mm-make-handle nil
3665 `("message/external-body"
3666 (access-type . "LOCAL-FILE")
3668 (set-buffer gnus-summary-buffer)
3669 (gnus-article-edit-article
3672 (let ((mail-parse-charset (or gnus-article-charset
3673 ',gnus-newsgroup-charset))
3674 (mail-parse-ignored-charsets
3675 (or gnus-article-ignored-charsets
3676 ',gnus-newsgroup-ignored-charsets))
3677 (mbl mml-buffer-list))
3678 (setq mml-buffer-list nil)
3679 (insert-buffer gnus-original-article-buffer)
3680 (mime-to-mml gnus-article-mime-handles)
3681 (setq gnus-article-mime-handles nil)
3682 (make-local-hook 'kill-buffer-hook)
3683 (let ((mbl1 mml-buffer-list))
3684 (setq mml-buffer-list mbl)
3685 (set (make-local-variable 'mml-buffer-list) mbl1))
3686 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3687 `(lambda (no-highlight)
3688 (let ((mail-parse-charset (or gnus-article-charset
3689 ',gnus-newsgroup-charset))
3690 (message-options message-options)
3691 (message-options-set-recipient)
3692 (mail-parse-ignored-charsets
3693 (or gnus-article-ignored-charsets
3694 ',gnus-newsgroup-ignored-charsets)))
3696 (mml-destroy-buffers)
3697 (remove-hook 'kill-buffer-hook
3698 'mml-destroy-buffers t)
3699 (kill-local-variable 'mml-buffer-list))
3700 (gnus-summary-edit-article-done
3701 ,(or (mail-header-references gnus-current-headers) "")
3702 ,(gnus-group-read-only-p)
3703 ,gnus-summary-buffer no-highlight))))))
3705 (defun gnus-mime-save-part ()
3706 "Save the MIME part under point."
3708 (gnus-article-check-buffer)
3709 (let ((data (get-text-property (point) 'gnus-data)))
3711 (mm-save-part data))))
3713 (defun gnus-mime-pipe-part ()
3714 "Pipe the MIME part under point to a process."
3716 (gnus-article-check-buffer)
3717 (let ((data (get-text-property (point) 'gnus-data)))
3719 (mm-pipe-part data))))
3721 (defun gnus-mime-view-part ()
3722 "Interactively choose a viewing method for the MIME part under point."
3724 (gnus-article-check-buffer)
3725 (let ((data (get-text-property (point) 'gnus-data)))
3727 (push (setq data (copy-sequence data)) gnus-article-mime-handles)
3728 (mm-interactively-view-part data))))
3730 (defun gnus-mime-view-part-as-type-internal ()
3731 (gnus-article-check-buffer)
3732 (let* ((name (mail-content-type-get
3733 (mm-handle-type (get-text-property (point) 'gnus-data))
3735 (def-type (and name (mm-default-file-encoding name))))
3736 (and def-type (cons def-type 0))))
3738 (defun gnus-mime-view-part-as-type (&optional mime-type)
3739 "Choose a MIME media type, and view the part as such."
3742 (setq mime-type (completing-read
3743 "View as MIME type: "
3744 (mapcar #'list (mailcap-mime-types))
3746 (gnus-mime-view-part-as-type-internal))))
3747 (gnus-article-check-buffer)
3748 (let ((handle (get-text-property (point) 'gnus-data)))
3751 (mm-make-handle (mm-handle-buffer handle)
3752 (cons mime-type (cdr (mm-handle-type handle)))
3753 (mm-handle-encoding handle)
3754 (mm-handle-undisplayer handle)
3755 (mm-handle-disposition handle)
3756 (mm-handle-description handle)
3757 (mm-handle-cache handle)
3758 (mm-handle-id handle)))
3759 (push handle gnus-article-mime-handles)
3760 (gnus-mm-display-part handle))))
3762 (defun gnus-mime-copy-part (&optional handle)
3763 "Put the the MIME part under point into a new buffer."
3765 (gnus-article-check-buffer)
3766 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3767 (contents (and handle (mm-get-part handle)))
3769 (file-name-nondirectory
3771 (mail-content-type-get (mm-handle-type handle) 'name)
3772 (mail-content-type-get (mm-handle-type handle)
3775 (buffer (and base (generate-new-buffer base))))
3777 (switch-to-buffer buffer)
3779 ;; We do it this way to make `normal-mode' set the appropriate mode.
3782 (setq buffer-file-name (expand-file-name base))
3784 (setq buffer-file-name nil))
3785 (goto-char (point-min)))))
3787 (defun gnus-mime-inline-part (&optional handle arg)
3788 "Insert the MIME part under point into the current buffer."
3789 (interactive (list nil current-prefix-arg))
3790 (gnus-article-check-buffer)
3791 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3796 (if (and (not arg) (mm-handle-undisplayer handle))
3797 (mm-remove-part handle)
3798 (setq contents (mm-get-part handle))
3801 (setq charset (or (mail-content-type-get
3802 (mm-handle-type handle) 'charset)
3803 gnus-newsgroup-charset)))
3805 (if (mm-handle-undisplayer handle)
3806 (mm-remove-part handle))
3809 gnus-summary-show-article-charset-alist))
3810 (read-coding-system "Charset: ")))))
3812 (mm-insert-inline handle
3814 (setq charset (mm-charset-to-coding-system
3816 (not (eq charset 'ascii)))
3817 (mm-decode-coding-string contents charset)
3821 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3822 "Insert the MIME part under point into the current buffer."
3823 (interactive (list nil current-prefix-arg))
3824 (gnus-article-check-buffer)
3825 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3830 (if (mm-handle-undisplayer handle)
3831 (mm-remove-part handle))
3832 (let ((gnus-newsgroup-charset
3834 gnus-summary-show-article-charset-alist))
3835 (read-coding-system "Charset: ")))
3836 (gnus-newsgroup-ignored-charsets 'gnus-all))
3837 (gnus-article-press-button)))))
3839 (defun gnus-mime-externalize-part (&optional handle)
3840 "View the MIME part under point with an external viewer."
3842 (gnus-article-check-buffer)
3843 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3844 (mm-user-display-methods nil)
3845 (mm-inlined-types nil)
3846 (mail-parse-charset gnus-newsgroup-charset)
3847 (mail-parse-ignored-charsets
3848 (save-excursion (set-buffer gnus-summary-buffer)
3849 gnus-newsgroup-ignored-charsets)))
3851 (if (mm-handle-undisplayer handle)
3852 (mm-remove-part handle)
3853 (mm-display-part handle)))))
3855 (defun gnus-mime-internalize-part (&optional handle)
3856 "View the MIME part under point with an internal viewer.
3857 In no internal viewer is available, use an external viewer."
3859 (gnus-article-check-buffer)
3860 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3861 (mm-inlined-types '(".*"))
3862 (mm-inline-large-images t)
3863 (mail-parse-charset gnus-newsgroup-charset)
3864 (mail-parse-ignored-charsets
3865 (save-excursion (set-buffer gnus-summary-buffer)
3866 gnus-newsgroup-ignored-charsets)))
3868 (if (mm-handle-undisplayer handle)
3869 (mm-remove-part handle)
3870 (mm-display-part handle)))))
3872 (defun gnus-mime-action-on-part (&optional action)
3873 "Do something with the MIME attachment at \(point\)."
3875 (list (completing-read "Action: " gnus-mime-action-alist)))
3876 (gnus-article-check-buffer)
3877 (let ((action-pair (assoc action gnus-mime-action-alist)))
3879 (funcall (cdr action-pair)))))
3881 (defun gnus-article-part-wrapper (n function)
3882 (save-current-buffer
3883 (set-buffer gnus-article-buffer)
3884 (when (> n (length gnus-article-mime-handle-alist))
3885 (error "No such part"))
3886 (gnus-article-goto-part n)
3887 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3888 (funcall function handle))))
3890 (defun gnus-article-pipe-part (n)
3891 "Pipe MIME part N, which is the numerical prefix."
3893 (gnus-article-part-wrapper n 'mm-pipe-part))
3895 (defun gnus-article-save-part (n)
3896 "Save MIME part N, which is the numerical prefix."
3898 (gnus-article-part-wrapper n 'mm-save-part))
3900 (defun gnus-article-interactively-view-part (n)
3901 "View MIME part N interactively, which is the numerical prefix."
3903 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3905 (defun gnus-article-copy-part (n)
3906 "Copy MIME part N, which is the numerical prefix."
3908 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3910 (defun gnus-article-view-part-as-charset (n)
3911 "Copy MIME part N, which is the numerical prefix."
3913 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3915 (defun gnus-article-externalize-part (n)
3916 "View MIME part N externally, which is the numerical prefix."
3918 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3920 (defun gnus-article-inline-part (n)
3921 "Inline MIME part N, which is the numerical prefix."
3923 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3925 (defun gnus-article-mime-match-handle-first (condition)
3927 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3928 (while (setq ihandle (pop alist))
3930 ((functionp condition)
3931 (funcall condition (cdr ihandle)))
3932 ((eq condition 'undisplayed)
3933 (not (or (mm-handle-undisplayer (cdr ihandle))
3934 (equal (mm-handle-media-type (cdr ihandle))
3935 "multipart/alternative"))))
3936 ((eq condition 'undisplayed-alternative)
3937 (not (mm-handle-undisplayer (cdr ihandle))))
3939 (gnus-article-goto-part (car ihandle))
3940 (or (not n) (< (car ihandle) n)))
3941 (setq n (car ihandle))))
3945 (defun gnus-article-view-part (&optional n)
3946 "View MIME part N, which is the numerical prefix."
3948 (save-current-buffer
3949 (set-buffer gnus-article-buffer)
3950 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3951 gnus-article-mime-match-handle-function)))
3952 (when (> n (length gnus-article-mime-handle-alist))
3953 (error "No such part"))
3954 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3955 (when (gnus-article-goto-part n)
3956 (if (equal (car handle) "multipart/alternative")
3957 (gnus-article-press-button)
3958 (when (eq (gnus-mm-display-part handle) 'internal)
3959 (gnus-set-window-start)))))))
3961 (defsubst gnus-article-mime-total-parts ()
3962 (if (bufferp (car gnus-article-mime-handles))
3964 (1- (length gnus-article-mime-handles))))
3966 (defun gnus-mm-display-part (handle)
3967 "Display HANDLE and fix MIME button."
3968 (let ((id (get-text-property (point) 'gnus-part))
3973 (let ((window (selected-window))
3974 (mail-parse-charset gnus-newsgroup-charset)
3975 (mail-parse-ignored-charsets
3976 (save-excursion (set-buffer gnus-summary-buffer)
3977 gnus-newsgroup-ignored-charsets)))
3980 (let ((win (get-buffer-window (current-buffer) t))
3983 (select-window win))
3986 (if (mm-handle-displayed-p handle)
3987 ;; This will remove the part.
3988 (mm-display-part handle)
3990 (narrow-to-region (point) (1+ (point)))
3991 (mm-display-part handle)
3992 ;; We narrow to the part itself and
3993 ;; then call the treatment functions.
3994 (goto-char (point-min))
3996 (narrow-to-region (point) (point-max))
3999 (gnus-article-mime-total-parts)
4000 (mm-handle-media-type handle)))))
4001 (select-window window))))
4003 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4004 (gnus-insert-mime-button
4005 handle id (list (mm-handle-displayed-p handle)))
4006 (goto-char point))))
4008 (defun gnus-article-goto-part (n)
4009 "Go to MIME part N."
4010 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4012 (goto-char point))))
4014 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4015 (let ((gnus-tmp-name
4016 (or (mail-content-type-get (mm-handle-type handle)
4018 (mail-content-type-get (mm-handle-disposition handle)
4020 (mail-content-type-get (mm-handle-type handle)
4023 (gnus-tmp-type (mm-handle-media-type handle))
4024 (gnus-tmp-description
4025 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4028 (if (if displayed (car displayed)
4029 (mm-handle-displayed-p handle))
4031 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4033 gnus-tmp-type-long b e)
4034 (when (string-match ".*/" gnus-tmp-name)
4035 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4036 (setq gnus-tmp-type-long (concat gnus-tmp-type
4037 (and (not (equal gnus-tmp-name ""))
4038 (concat "; " gnus-tmp-name))))
4039 (or (equal gnus-tmp-description "")
4040 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4045 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4046 `(keymap ,gnus-mime-button-map
4047 ,@(if (>= (string-to-number emacs-version) 21)
4049 (list 'local-map gnus-mime-button-map))
4050 gnus-callback gnus-mm-display-part
4051 gnus-part ,gnus-tmp-id
4052 article-type annotation
4055 (widget-convert-button
4058 :action 'gnus-widget-press-button
4059 :button-keymap gnus-mime-button-map
4061 (lambda (widget/window &optional overlay pos)
4062 ;; Needed to properly clear the message due to a bug in
4063 ;; wid-edit (XEmacs only).
4064 (if (boundp 'help-echo-owns-message)
4065 (setq help-echo-owns-message t))
4067 "%S: %s the MIME part; %S: more options"
4068 (aref gnus-mouse-2 0)
4069 ;; XEmacs will get a single widget arg; Emacs 21 will get
4070 ;; window, overlay, position.
4071 (if (mm-handle-displayed-p
4073 (with-current-buffer (gnus-overlay-buffer overlay)
4074 (widget-get (widget-at (gnus-overlay-start overlay))
4076 (widget-get widget/window :mime-handle)))
4078 (aref gnus-down-mouse-3 0))))))
4080 (defun gnus-widget-press-button (elems el)
4081 (goto-char (widget-get elems :from))
4082 (gnus-article-press-button))
4084 (defvar gnus-displaying-mime nil)
4086 (defun gnus-display-mime (&optional ihandles)
4087 "Display the MIME parts."
4089 (save-selected-window
4090 (let ((window (get-buffer-window gnus-article-buffer))
4093 (select-window window)
4094 ;; We have to do this since selecting the window
4095 ;; may change the point. So we set the window point.
4096 (set-window-point window point)))
4097 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
4098 buffer-read-only handle name type b e display)
4099 (when (and (not ihandles)
4100 (not gnus-displaying-mime))
4101 ;; Top-level call; we clean up.
4102 (when gnus-article-mime-handles
4103 (mm-destroy-parts gnus-article-mime-handles)
4104 (setq gnus-article-mime-handle-alist nil));; A trick.
4105 (setq gnus-article-mime-handles handles)
4106 ;; We allow users to glean info from the handles.
4107 (when gnus-article-mime-part-function
4108 (gnus-mime-part-function handles)))
4110 (or (not (stringp (car handles)))
4113 (when (and (not ihandles)
4114 (not gnus-displaying-mime))
4115 ;; Clean up for mime parts.
4117 (delete-region (point) (point-max)))
4118 (let ((gnus-displaying-mime t))
4119 (gnus-mime-display-part handles)))
4122 (narrow-to-region (point) (point-max))
4123 (gnus-treat-article nil 1 1)
4126 ;; Highlight the headers.
4130 (narrow-to-region (point-min) (point))
4131 (gnus-treat-article 'head))))))))
4133 (defvar gnus-mime-display-multipart-as-mixed nil)
4135 (defun gnus-mime-display-part (handle)
4138 ((not (stringp (car handle)))
4139 (gnus-mime-display-single handle))
4140 ;; User-defined multipart
4141 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4142 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4144 ;; multipart/alternative
4145 ((and (equal (car handle) "multipart/alternative")
4146 (not gnus-mime-display-multipart-as-mixed))
4147 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4148 (push (cons id handle) gnus-article-mime-handle-alist)
4149 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4150 ;; multipart/related
4151 ((and (equal (car handle) "multipart/related")
4152 (not gnus-mime-display-multipart-as-mixed))
4153 ;;;!!!We should find the start part, but we just default
4154 ;;;!!!to the first part.
4155 ;;(gnus-mime-display-part (cadr handle))
4156 ;;;!!! Most multipart/related is an HTML message plus images.
4157 ;;;!!! Unfortunately we are unable to let W3 display those
4158 ;;;!!! included images, so we just display it as a mixed multipart.
4159 ;;(gnus-mime-display-mixed (cdr handle))
4160 ;;;!!! No, w3 can display everything just fine.
4161 (gnus-mime-display-part (cadr handle)))
4162 ((equal (car handle) "multipart/signed")
4163 (or (memq 'signed gnus-article-wash-types)
4164 (push 'signed gnus-article-wash-types))
4165 (gnus-mime-display-security handle))
4166 ((equal (car handle) "multipart/encrypted")
4167 (or (memq 'encrypted gnus-article-wash-types)
4168 (push 'encrypted gnus-article-wash-types))
4169 (gnus-mime-display-security handle))
4170 ;; Other multiparts are handled like multipart/mixed.
4172 (gnus-mime-display-mixed (cdr handle)))))
4174 (defun gnus-mime-part-function (handles)
4175 (if (stringp (car handles))
4176 (mapcar 'gnus-mime-part-function (cdr handles))
4177 (funcall gnus-article-mime-part-function handles)))
4179 (defun gnus-mime-display-mixed (handles)
4180 (mapcar 'gnus-mime-display-part handles))
4182 (defun gnus-mime-display-single (handle)
4183 (let ((type (mm-handle-media-type handle))
4184 (ignored gnus-ignored-mime-types)
4191 (when (string-match (pop ignored) type)
4192 (throw 'ignored nil)))
4193 (if (and (setq not-attachment
4194 (and (not (mm-inline-override-p handle))
4195 (or (not (mm-handle-disposition handle))
4196 (equal (car (mm-handle-disposition handle))
4198 (mm-attachment-override-p handle))))
4199 (mm-automatic-display-p handle)
4200 (or (mm-inlined-p handle)
4201 (mm-automatic-external-display-p type)))
4203 (when (equal (mm-handle-media-supertype handle) "text")
4205 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4207 (push (cons id handle) gnus-article-mime-handle-alist)
4208 (when (or (not display)
4209 (not (gnus-unbuttonized-mime-type-p type)))
4210 ;(gnus-article-insert-newline)
4211 (gnus-insert-mime-button
4212 handle id (list (or display (and not-attachment text))))
4213 (gnus-article-insert-newline)
4214 ;(gnus-article-insert-newline)
4215 ;; Remember modify the number of forward lines.
4223 (let ((mail-parse-charset gnus-newsgroup-charset)
4224 (mail-parse-ignored-charsets
4225 (save-excursion (condition-case ()
4226 (set-buffer gnus-summary-buffer)
4228 gnus-newsgroup-ignored-charsets)))
4229 (mm-display-part handle t))
4230 (goto-char (point-max)))
4231 ((and text not-attachment)
4235 (gnus-article-insert-newline)
4236 (mm-insert-inline handle (mm-get-part handle))
4237 (goto-char (point-max))))
4241 (narrow-to-region beg (point))
4244 (gnus-article-mime-total-parts)
4245 (mm-handle-media-type handle)))))))))
4247 (defun gnus-unbuttonized-mime-type-p (type)
4248 "Say whether TYPE is to be unbuttonized."
4249 (unless gnus-inhibit-mime-unbuttonizing
4251 (let ((types gnus-unbuttonized-mime-types))
4253 (when (string-match (pop types) type)
4254 (throw 'found t)))))))
4256 (defun gnus-article-insert-newline ()
4257 "Insert a newline, but mark it as undeletable."
4258 (gnus-put-text-property
4259 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4261 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4262 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4265 handle buffer-read-only from props begend not-pref)
4266 (save-window-excursion
4269 (narrow-to-region (car ibegend)
4272 (goto-char (car ibegend))
4275 (delete-region (point-min) (point-max))
4276 (mm-remove-parts handles))
4277 (setq begend (list (point-marker)))
4279 (unless (setq not-pref (cadr (member preferred ihandles)))
4280 (setq not-pref (car ihandles)))
4283 (not (gnus-unbuttonized-mime-type-p
4284 "multipart/alternative")))
4285 (gnus-add-text-properties
4288 (insert (format "%d. " id))
4292 (unless ,(not ibegend)
4293 (setq gnus-article-mime-handle-alist
4294 ',gnus-article-mime-handle-alist))
4295 (gnus-mime-display-alternative
4296 ',ihandles ',not-pref ',begend ,id))
4297 ,@(if (>= (string-to-number emacs-version) 21)
4298 nil ;; XEmacs doesn't care
4299 (list 'local-map gnus-mime-button-map))
4300 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4301 face ,gnus-article-button-face
4302 keymap ,gnus-mime-button-map
4305 (widget-convert-button 'link from (point)
4306 :action 'gnus-widget-press-button
4307 :button-keymap gnus-widget-button-keymap)
4309 (while (setq handle (pop handles))
4310 (gnus-add-text-properties
4313 (insert (format "(%c) %-18s"
4314 (if (equal handle preferred) ?* ? )
4315 (mm-handle-media-type handle)))
4319 (unless ,(not ibegend)
4320 (setq gnus-article-mime-handle-alist
4321 ',gnus-article-mime-handle-alist))
4322 (gnus-mime-display-alternative
4323 ',ihandles ',handle ',begend ,id))
4324 ,@(if (>= (string-to-number emacs-version) 21)
4325 nil ;; XEmacs doesn't care
4326 (list 'local-map gnus-mime-button-map))
4327 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4328 face ,gnus-article-button-face
4329 keymap ,gnus-mime-button-map
4332 (widget-convert-button 'link from (point)
4333 :action 'gnus-widget-press-button
4334 :button-keymap gnus-widget-button-keymap)
4338 (if (stringp (car preferred))
4339 (gnus-display-mime preferred)
4340 (let ((mail-parse-charset gnus-newsgroup-charset)
4341 (mail-parse-ignored-charsets
4342 (save-excursion (set-buffer gnus-summary-buffer)
4343 gnus-newsgroup-ignored-charsets)))
4344 (mm-display-part preferred)
4348 (narrow-to-region (car begend) (point-max))
4350 nil (length gnus-article-mime-handle-alist)
4351 (gnus-article-mime-total-parts)
4352 (mm-handle-media-type handle))))))
4353 (goto-char (point-max))
4354 (setcdr begend (point-marker)))))
4356 (goto-char point))))
4358 (defun gnus-article-wash-status ()
4359 "Return a string which display status of article washing."
4361 (set-buffer gnus-article-buffer)
4362 (let ((cite (memq 'cite gnus-article-wash-types))
4363 (headers (memq 'headers gnus-article-wash-types))
4364 (boring (memq 'boring-headers gnus-article-wash-types))
4365 (pgp (memq 'pgp gnus-article-wash-types))
4366 (pem (memq 'pem gnus-article-wash-types))
4367 (signed (memq 'signed gnus-article-wash-types))
4368 (encrypted (memq 'encrypted gnus-article-wash-types))
4369 (signature (memq 'signature gnus-article-wash-types))
4370 (overstrike (memq 'overstrike gnus-article-wash-types))
4371 (emphasis (memq 'emphasis gnus-article-wash-types)))
4372 (format "%c%c%c%c%c%c%c"
4374 (if (or headers boring) ?h ? )
4375 (if (or pgp pem signed encrypted) ?p ? )
4376 (if signature ?s ? )
4377 (if overstrike ?o ? )
4378 (if gnus-show-mime ?m ? )
4379 (if emphasis ?e ? )))))
4381 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4383 (defun gnus-article-maybe-hide-headers ()
4384 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4385 Provided for backwards compatibility."
4386 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4387 (not (save-excursion (set-buffer gnus-summary-buffer)
4388 gnus-have-all-headers)))
4389 (not gnus-inhibit-hiding))
4390 (gnus-article-hide-headers)))
4394 (defun gnus-output-to-file (file-name)
4395 "Append the current article to a file named FILE-NAME."
4396 (let ((artbuf (current-buffer)))
4398 (insert-buffer-substring artbuf)
4399 ;; Append newline at end of the buffer as separator, and then
4401 (goto-char (point-max))
4403 (write-region-as-binary (point-min) (point-max) file-name 'append)
4406 (defun gnus-narrow-to-page (&optional arg)
4407 "Narrow the article buffer to a page.
4408 If given a numerical ARG, move forward ARG pages."
4410 (setq arg (if arg (prefix-numeric-value arg) 0))
4412 (set-buffer gnus-article-buffer)
4413 (goto-char (point-min))
4415 ;; Remove any old next/prev buttons.
4416 (when (gnus-visual-p 'page-marker)
4417 (let ((buffer-read-only nil))
4418 (gnus-remove-text-with-property 'gnus-prev)
4419 (gnus-remove-text-with-property 'gnus-next)))
4422 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4424 (re-search-forward page-delimiter nil 'move arg)))
4425 (goto-char (match-end 0)))
4428 (if (re-search-forward page-delimiter nil 'move)
4431 (when (and (gnus-visual-p 'page-marker)
4432 (not (= (point-min) 1)))
4434 (goto-char (point-min))
4435 (gnus-insert-prev-page-button)))
4436 (when (and (gnus-visual-p 'page-marker)
4437 (< (+ (point-max) 2) (buffer-size)))
4439 (goto-char (point-max))
4440 (gnus-insert-next-page-button)))))
4442 ;; Article mode commands
4444 (defun gnus-article-goto-next-page ()
4445 "Show the next page of the article."
4447 (when (gnus-article-next-page)
4448 (goto-char (point-min))
4449 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4451 (defun gnus-article-goto-prev-page ()
4452 "Show the next page of the article."
4454 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4455 (gnus-article-prev-page nil)))
4457 (defun gnus-article-next-page (&optional lines)
4458 "Show the next page of the current article.
4459 If end of article, return non-nil. Otherwise return nil.
4460 Argument LINES specifies lines to be scrolled up."
4462 (let ((start (window-start))
4463 end-of-buffer end-of-page)
4465 (move-to-window-line -1)
4466 (if (<= (point) start)
4469 (setq start (point)))
4472 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4473 (and (pos-visible-in-window-p)
4474 (setq end-of-buffer t)))
4476 (setq end-of-page t)))
4478 (move-to-window-line lines)
4479 (unless (search-backward "\n\n" nil t)
4480 (setq start (point)))))
4481 (cond (end-of-buffer t)
4483 (gnus-narrow-to-page 1)
4487 (set-window-start (selected-window) start)
4488 (let (window-pixel-scroll-increment)
4492 (defun gnus-article-prev-page (&optional lines)
4493 "Show previous page of current article.
4494 Argument LINES specifies lines to be scrolled down."
4496 (let (beginning-of-buffer beginning-of-page)
4498 (move-to-window-line 0)
4499 (cond ((eq 1 (point))
4500 (setq beginning-of-buffer t))
4502 (setq beginning-of-page t))))
4503 (cond (beginning-of-buffer)
4505 (gnus-narrow-to-page -1))
4508 (let (window-pixel-scroll-increment)
4509 (scroll-down lines))
4510 (beginning-of-buffer
4511 (goto-char (point-min))))))))
4513 (defun gnus-article-refer-article ()
4514 "Read article specified by message-id around point."
4516 (let ((point (point)))
4517 (search-forward ">" nil t) ;Move point to end of "<....>".
4518 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4519 (let ((message-id (match-string 1)))
4521 (set-buffer gnus-summary-buffer)
4522 (gnus-summary-refer-article message-id))
4524 (error "No references around point"))))
4526 (defun gnus-article-show-summary ()
4527 "Reconfigure windows to show summary buffer."
4529 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4530 (error "There is no summary buffer for this article buffer")
4531 (gnus-article-set-globals)
4532 (gnus-configure-windows 'article)
4533 (gnus-summary-goto-subject gnus-current-article)
4534 (gnus-summary-position-point)))
4536 (defun gnus-article-describe-briefly ()
4537 "Describe article mode commands briefly."
4539 (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")))
4541 (defun gnus-article-summary-command ()
4542 "Execute the last keystroke in the summary buffer."
4544 (let ((obuf (current-buffer))
4545 (owin (current-window-configuration))
4547 (switch-to-buffer gnus-article-current-summary 'norecord)
4548 (setq func (lookup-key (current-local-map) (this-command-keys)))
4549 (call-interactively func)
4551 (set-window-configuration owin)
4552 (set-window-point (get-buffer-window (current-buffer)) (point))))
4554 (defun gnus-article-summary-command-nosave ()
4555 "Execute the last keystroke in the summary buffer."
4558 (pop-to-buffer gnus-article-current-summary 'norecord)
4559 (setq func (lookup-key (current-local-map) (this-command-keys)))
4560 (call-interactively func)))
4562 (defun gnus-article-check-buffer ()
4563 "Beep if not in an article buffer."
4564 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4565 (error "Command invoked outside of a Gnus article buffer")))
4567 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4568 "Read a summary buffer key sequence and execute it from the article buffer."
4570 (gnus-article-check-buffer)
4572 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4573 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4574 "=" "^" "\M-^" "|"))
4580 '("n" "Gn" "p" "Gp"))
4583 (set-buffer gnus-article-current-summary)
4584 (let (gnus-pick-mode)
4585 (push (or key last-command-event) unread-command-events)
4586 (setq keys (static-if (featurep 'xemacs)
4587 (events-to-keys (read-key-sequence nil))
4588 (read-key-sequence nil)))))
4591 (if (or (member keys nosaves)
4592 (member keys nosave-but-article)
4593 (member keys nosave-in-article))
4595 (save-window-excursion
4596 (pop-to-buffer gnus-article-current-summary 'norecord)
4597 ;; We disable the pick minor mode commands.
4598 (let (gnus-pick-mode)
4599 (setq func (lookup-key (current-local-map) keys))))
4603 (unless (member keys nosave-in-article)
4604 (set-buffer gnus-article-current-summary))
4605 (call-interactively func)
4606 (setq new-sum-point (point)))
4607 (when (member keys nosave-but-article)
4608 (pop-to-buffer gnus-article-buffer 'norecord)))
4609 ;; These commands should restore window configuration.
4610 (let ((obuf (current-buffer))
4611 (owin (current-window-configuration))
4613 (summary gnus-article-current-summary)
4614 func in-buffer selected)
4615 (if not-restore-window
4616 (pop-to-buffer summary 'norecord)
4617 (switch-to-buffer summary 'norecord))
4618 (setq in-buffer (current-buffer))
4619 ;; We disable the pick minor mode commands.
4620 (if (and (setq func (let (gnus-pick-mode)
4621 (lookup-key (current-local-map) keys)))
4624 (call-interactively func)
4625 (setq new-sum-point (point))
4626 (when (eq in-buffer (current-buffer))
4627 (setq selected (gnus-summary-select-article))
4629 (unless not-restore-window
4630 (set-window-configuration owin))
4631 (when (eq selected 'old)
4633 (set-window-start (get-buffer-window (current-buffer))
4635 (set-window-point (get-buffer-window (current-buffer))
4637 (let ((win (get-buffer-window gnus-article-current-summary)))
4639 (set-window-point win new-sum-point)))) )
4640 (switch-to-buffer gnus-article-buffer)
4643 (defun gnus-article-describe-key (key)
4644 "Display documentation of the function invoked by KEY. KEY is a string."
4645 (interactive "kDescribe key: ")
4646 (gnus-article-check-buffer)
4647 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4649 (set-buffer gnus-article-current-summary)
4650 (let (gnus-pick-mode)
4651 (push (elt key 0) unread-command-events)
4652 (setq key (if (featurep 'xemacs)
4653 (events-to-keys (read-key-sequence "Describe key: "))
4654 (read-key-sequence "Describe key: "))))
4656 (describe-key key)))
4658 (defun gnus-article-describe-key-briefly (key &optional insert)
4659 "Display documentation of the function invoked by KEY. KEY is a string."
4660 (interactive "kDescribe key: \nP")
4661 (gnus-article-check-buffer)
4662 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4664 (set-buffer gnus-article-current-summary)
4665 (let (gnus-pick-mode)
4666 (push (elt key 0) unread-command-events)
4667 (setq key (if (featurep 'xemacs)
4668 (events-to-keys (read-key-sequence "Describe key: "))
4669 (read-key-sequence "Describe key: "))))
4670 (describe-key-briefly key insert))
4671 (describe-key-briefly key insert)))
4673 (defun gnus-article-hide (&optional arg force)
4674 "Hide all the gruft in the current article.
4675 This means that PGP stuff, signatures, cited text and (some)
4676 headers will be hidden.
4677 If given a prefix, show the hidden text instead."
4678 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4679 (gnus-article-hide-headers arg)
4680 (gnus-article-hide-list-identifiers arg)
4681 (gnus-article-hide-pgp arg)
4682 (gnus-article-hide-citation-maybe arg force)
4683 (gnus-article-hide-signature arg))
4685 (defun gnus-article-maybe-highlight ()
4686 "Do some article highlighting if article highlighting is requested."
4687 (when (gnus-visual-p 'article-highlight 'highlight)
4688 (gnus-article-highlight-some)))
4690 (defun gnus-check-group-server ()
4691 ;; Make sure the connection to the server is alive.
4692 (unless (gnus-server-opened
4693 (gnus-find-method-for-group gnus-newsgroup-name))
4694 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4695 (gnus-request-group gnus-newsgroup-name t)))
4697 (defun gnus-request-article-this-buffer (article group)
4698 "Get an article and insert it into this buffer."
4699 (let (do-update-line sparse-header)
4703 (gnus-kill-all-overlays)
4704 (setq group (or group gnus-newsgroup-name))
4706 ;; Using `gnus-request-article' directly will insert the article into
4707 ;; `nntp-server-buffer' - so we'll save some time by not having to
4708 ;; copy it from the server buffer into the article buffer.
4710 ;; We only request an article by message-id when we do not have the
4711 ;; headers for it, so we'll have to get those.
4712 (when (stringp article)
4713 (gnus-read-header article))
4715 ;; If the article number is negative, that means that this article
4716 ;; doesn't belong in this newsgroup (possibly), so we find its
4717 ;; message-id and request it by id instead of number.
4718 (when (and (numberp article)
4720 (get-buffer gnus-summary-buffer)
4721 (gnus-buffer-exists-p gnus-summary-buffer))
4723 (set-buffer gnus-summary-buffer)
4724 (let ((header (gnus-summary-article-header article)))
4727 ((memq article gnus-newsgroup-sparse)
4728 ;; This is a sparse gap article.
4729 (setq do-update-line article)
4730 (setq article (mail-header-id header))
4731 (setq sparse-header (gnus-read-header article))
4732 (setq gnus-newsgroup-sparse
4733 (delq article gnus-newsgroup-sparse)))
4735 ;; It's a real article.
4736 (setq article (mail-header-id header)))
4738 ;; It is an extracted pseudo-article.
4739 (setq article 'pseudo)
4740 (gnus-request-pseudo-article header))))
4742 (let ((method (gnus-find-method-for-group
4743 gnus-newsgroup-name)))
4744 (when (and (eq (car method) 'nneething)
4746 (let ((dir (expand-file-name
4747 (mail-header-subject header)
4748 (file-name-as-directory
4749 (or (cadr (assq 'nneething-address method))
4751 (when (file-directory-p dir)
4752 (setq article 'nneething)
4753 (gnus-group-enter-directory dir))))))))
4756 ;; Refuse to select canceled articles.
4757 ((and (numberp article)
4759 (get-buffer gnus-summary-buffer)
4760 (gnus-buffer-exists-p gnus-summary-buffer)
4761 (eq (cdr (save-excursion
4762 (set-buffer gnus-summary-buffer)
4763 (assq article gnus-newsgroup-reads)))
4764 gnus-canceled-mark))
4766 ;; Check the backlog.
4767 ((and gnus-keep-backlog
4768 (gnus-backlog-request-article group article (current-buffer)))
4770 ;; Check asynchronous pre-fetch.
4771 ((gnus-async-request-fetched-article group article (current-buffer))
4772 (gnus-async-prefetch-next group article gnus-summary-buffer)
4773 (when (and (numberp article) gnus-keep-backlog)
4774 (gnus-backlog-enter-article group article (current-buffer)))
4777 ((and gnus-use-cache
4779 (gnus-cache-request-article article group))
4781 ;; Get the article and put into the article buffer.
4782 ((or (stringp article)
4784 (let ((gnus-override-method gnus-override-method)
4785 (methods (and (stringp article)
4786 gnus-refer-article-method))
4788 (buffer-read-only nil))
4789 (if (or (not (listp methods))
4790 (and (symbolp (car methods))
4791 (assq (car methods) nnoo-definition-alist)))
4792 (setq methods (list methods)))
4793 (when (and (null gnus-override-method)
4795 (setq gnus-override-method (pop methods)))
4797 (when (eq gnus-override-method 'current)
4798 (setq gnus-override-method gnus-current-select-method))
4800 (gnus-kill-all-overlays)
4801 (let ((gnus-newsgroup-name group))
4802 (gnus-check-group-server))
4803 (when (gnus-request-article article group (current-buffer))
4804 (when (numberp article)
4805 (gnus-async-prefetch-next group article
4806 gnus-summary-buffer)
4807 (when gnus-keep-backlog
4808 (gnus-backlog-enter-article
4809 group article (current-buffer))))
4810 (setq result 'article))
4813 (setq gnus-override-method (pop methods))
4814 (setq result 'done))))
4815 (and (eq result 'article) 'article)))
4819 ;; Associate this article with the current summary buffer.
4820 (setq gnus-article-current-summary gnus-summary-buffer)
4822 ;; Take the article from the original article buffer
4823 ;; and place it in the buffer it's supposed to be in.
4824 (when (and (get-buffer gnus-article-buffer)
4825 (equal (buffer-name (current-buffer))
4826 (buffer-name (get-buffer gnus-article-buffer))))
4828 (if (get-buffer gnus-original-article-buffer)
4829 (set-buffer gnus-original-article-buffer)
4830 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4831 (set-buffer-multibyte nil)
4832 (buffer-disable-undo)
4833 (setq major-mode 'gnus-original-article-mode)
4834 (setq buffer-read-only t))
4835 (let (buffer-read-only)
4837 (insert-buffer-substring gnus-article-buffer))
4838 (setq gnus-original-article (cons group article)))
4841 (run-hooks 'gnus-article-decode-hook)
4842 ;; Mark article as decoded or not.
4843 (setq gnus-article-decoded-p gnus-article-decode-hook))
4845 ;; Update sparse articles.
4846 (when (and do-update-line
4847 (or (numberp article)
4849 (let ((buf (current-buffer)))
4850 (set-buffer gnus-summary-buffer)
4851 (gnus-summary-update-article do-update-line sparse-header)
4852 (gnus-summary-goto-subject do-update-line nil t)
4853 (set-window-point (get-buffer-window (current-buffer) t)
4855 (set-buffer buf))))))
4861 (defcustom gnus-article-edit-mode-hook nil
4862 "Hook run in article edit mode buffers."
4863 :group 'gnus-article-various
4866 (defcustom gnus-article-edit-article-setup-function
4867 'gnus-article-mime-edit-article-setup
4868 "Function called to setup an editing article buffer."
4869 :group 'gnus-article-various
4872 (defvar gnus-article-edit-done-function nil)
4874 (defvar gnus-article-edit-mode-map nil)
4876 ;; Should we be using derived.el for this?
4877 (unless gnus-article-edit-mode-map
4878 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4879 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4881 (gnus-define-keys gnus-article-edit-mode-map
4882 "\C-c\C-c" gnus-article-edit-done
4883 "\C-c\C-k" gnus-article-edit-exit)
4885 (gnus-define-keys (gnus-article-edit-wash-map
4886 "\C-c\C-w" gnus-article-edit-mode-map)
4887 "f" gnus-article-edit-full-stops))
4889 (defun gnus-article-edit-mode ()
4890 "Major mode for editing articles.
4891 This is an extended text-mode.
4893 \\{gnus-article-edit-mode-map}"
4895 (setq major-mode 'gnus-article-edit-mode)
4896 (setq mode-name "Article Edit")
4897 (use-local-map gnus-article-edit-mode-map)
4898 (make-local-variable 'gnus-article-edit-done-function)
4899 (make-local-variable 'gnus-prev-winconf)
4900 (setq buffer-read-only nil)
4901 (buffer-enable-undo)
4903 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4905 (defun gnus-article-edit (&optional force)
4906 "Edit the current article.
4907 This will have permanent effect only in mail groups.
4908 If FORCE is non-nil, allow editing of articles even in read-only
4911 (when (and (not force)
4912 (gnus-group-read-only-p))
4913 (error "The current newsgroup does not support article editing"))
4914 (gnus-article-date-original)
4915 (gnus-article-edit-article
4917 `(lambda (no-highlight)
4919 (gnus-summary-edit-article-done
4920 ,(or (mail-header-references gnus-current-headers) "")
4921 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4923 (defun gnus-article-edit-article (start-func exit-func)
4924 "Start editing the contents of the current article buffer."
4925 (let ((winconf (current-window-configuration)))
4926 (set-buffer gnus-article-buffer)
4927 (gnus-article-edit-mode)
4928 (funcall start-func)
4929 (gnus-configure-windows 'edit-article)
4930 (setq gnus-article-edit-done-function exit-func)
4931 (setq gnus-prev-winconf winconf)
4932 (when gnus-article-edit-article-setup-function
4933 (funcall gnus-article-edit-article-setup-function))
4934 (gnus-message 6 "C-c C-c to end edits")))
4936 (defun gnus-article-edit-done (&optional arg)
4937 "Update the article edits and exit."
4939 (let ((func gnus-article-edit-done-function)
4940 (buf (current-buffer))
4941 (start (window-start)))
4942 (remove-hook 'gnus-article-mode-hook
4943 'gnus-article-mime-edit-article-unwind)
4944 (gnus-article-edit-exit)
4947 (let ((buffer-read-only nil))
4949 ;; The cache and backlog have to be flushed somewhat.
4950 (when gnus-keep-backlog
4951 (gnus-backlog-remove-article
4952 (car gnus-article-current) (cdr gnus-article-current)))
4953 ;; Flush original article as well.
4955 (when (get-buffer gnus-original-article-buffer)
4956 (set-buffer gnus-original-article-buffer)
4957 (setq gnus-original-article nil)))
4958 (when gnus-use-cache
4959 (gnus-cache-update-article
4960 (car gnus-article-current) (cdr gnus-article-current))))
4962 (set-window-start (get-buffer-window buf) start)
4963 (set-window-point (get-buffer-window buf) (point))))
4965 (defun gnus-article-edit-exit ()
4966 "Exit the article editing without updating."
4968 ;; We remove all text props from the article buffer.
4969 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4970 (curbuf (current-buffer))
4972 (window-start (window-start)))
4975 (let ((winconf gnus-prev-winconf))
4977 (set-window-configuration winconf)
4978 ;; Tippy-toe some to make sure that point remains where it was.
4979 (save-current-buffer
4981 (set-window-start (get-buffer-window (current-buffer)) window-start)
4984 (defun gnus-article-edit-full-stops ()
4985 "Interactively repair spacing at end of sentences."
4988 (goto-char (point-min))
4989 (search-forward-regexp "^$" nil t)
4990 (let ((case-fold-search nil))
4991 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4994 ;;; Article editing with MIME-Edit
4997 (defcustom gnus-article-mime-edit-article-setup-hook nil
4998 "Hook run after setting up a MIME editing article buffer."
4999 :group 'gnus-article-various
5002 (defun gnus-article-mime-edit-article-unwind ()
5003 "Unwind `gnus-article-buffer' if article editing was given up."
5004 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5005 (when mime-edit-mode-flag
5006 (mime-edit-exit 'nomime 'no-error)
5008 (when (featurep 'font-lock)
5009 (setq font-lock-defaults nil)
5010 (font-lock-mode 0)))
5012 (defun gnus-article-mime-edit-article-setup ()
5013 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5014 after replacing with the original article."
5015 (setq gnus-show-mime t)
5016 (setq gnus-article-edit-done-function
5017 `(lambda (&rest args)
5018 (when mime-edit-mode-flag
5021 (goto-char (point-min))
5022 (let (case-fold-search)
5023 (when (re-search-forward
5024 (format "^%s$" (regexp-quote mail-header-separator))
5026 (replace-match "")))
5027 (when (featurep 'font-lock)
5028 (setq font-lock-defaults nil)
5030 (apply ,gnus-article-edit-done-function args)
5031 (set-buffer gnus-original-article-buffer)
5033 (insert-buffer gnus-article-buffer)
5034 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5035 (gnus-article-prepare-display)))
5036 (substitute-key-definition
5037 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
5038 gnus-article-edit-mode-map)
5040 (insert-buffer gnus-original-article-buffer)
5042 (when (featurep 'font-lock)
5043 (set (make-local-variable 'font-lock-defaults)
5044 '(message-font-lock-keywords t))
5045 (font-lock-set-defaults)
5046 (turn-on-font-lock))
5047 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5048 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5050 (defun gnus-article-mime-edit-exit ()
5051 "Exit the article MIME editing without updating."
5053 (let ((winconf gnus-prev-winconf)
5055 (when mime-edit-mode-flag
5058 (goto-char (point-min))
5059 (let (case-fold-search)
5060 (when (re-search-forward
5061 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5062 (replace-match "")))
5063 (when (featurep 'font-lock)
5064 (setq font-lock-defaults nil)
5066 ;; We remove all text props from the article buffer.
5067 (setq buf (buffer-substring-no-properties (point-min) (point-max)))
5068 (set-buffer (get-buffer-create gnus-original-article-buffer))
5071 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5072 (gnus-article-prepare-display)
5073 (set-window-configuration winconf)))
5076 ;;; Article highlights
5079 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5081 ;;; Internal Variables:
5083 (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\\)\\)"
5084 "Regular expression that matches URLs."
5085 :group 'gnus-article-buttons
5088 (defcustom gnus-button-alist
5089 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5090 0 t gnus-button-message-id 2)
5091 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
5092 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5094 gnus-button-fetch-group 4)
5095 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5096 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5097 t gnus-button-message-id 3)
5098 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5099 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5100 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5101 ;; This is how URLs _should_ be embedded in text...
5102 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
5104 (,gnus-button-url-regexp 0 t browse-url 0))
5105 "*Alist of regexps matching buttons in article bodies.
5107 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5108 REGEXP: is the string matching text around the button,
5109 BUTTON: is the number of the regexp grouping actually matching the button,
5110 FORM: is a lisp expression which must eval to true for the button to
5112 CALLBACK: is the function to call when the user push this button, and each
5113 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5115 CALLBACK can also be a variable, in that case the value of that
5116 variable it the real callback function."
5117 :group 'gnus-article-buttons
5118 :type '(repeat (list regexp
5119 (integer :tag "Button")
5121 (function :tag "Callback")
5124 (integer :tag "Regexp group")))))
5126 (defcustom gnus-header-button-alist
5127 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
5128 0 t gnus-button-message-id 0)
5129 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5130 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5131 0 t gnus-button-mailto 0)
5132 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5133 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5134 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5135 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5136 gnus-button-message-id 3))
5137 "*Alist of headers and regexps to match buttons in article heads.
5139 This alist is very similar to `gnus-button-alist', except that each
5140 alist has an additional HEADER element first in each entry:
5142 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5144 HEADER is a regexp to match a header. For a fuller explanation, see
5145 `gnus-button-alist'."
5146 :group 'gnus-article-buttons
5147 :group 'gnus-article-headers
5148 :type '(repeat (list (regexp :tag "Header")
5150 (integer :tag "Button")
5152 (function :tag "Callback")
5155 (integer :tag "Regexp group")))))
5157 (defvar gnus-button-regexp nil)
5158 (defvar gnus-button-marker-list nil)
5159 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5161 (defvar gnus-button-last nil)
5162 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5166 (defun gnus-article-push-button (event)
5167 "Check text under the mouse pointer for a callback function.
5168 If the text under the mouse pointer has a `gnus-callback' property,
5169 call it with the value of the `gnus-data' text property."
5171 (set-buffer (window-buffer (posn-window (event-start event))))
5172 (let* ((pos (posn-point (event-start event)))
5173 (data (get-text-property pos 'gnus-data))
5174 (fun (get-text-property pos 'gnus-callback)))
5177 (funcall fun data))))
5179 (defun gnus-article-press-button ()
5180 "Check text at point for a callback function.
5181 If the text at point has a `gnus-callback' property,
5182 call it with the value of the `gnus-data' text property."
5184 (let* ((data (get-text-property (point) 'gnus-data))
5185 (fun (get-text-property (point) 'gnus-callback)))
5187 (funcall fun data))))
5189 (defun gnus-article-prev-button (n)
5190 "Move point to N buttons backward.
5191 If N is negative, move forward instead."
5193 (gnus-article-next-button (- n)))
5195 (defun gnus-article-next-button (n)
5196 "Move point to N buttons forward.
5197 If N is negative, move backward instead."
5199 (let ((function (if (< n 0) 'previous-single-property-change
5200 'next-single-property-change))
5201 (inhibit-point-motion-hooks t)
5203 (limit (if (< n 0) (point-min) (point-max))))
5205 (while (and (not (= limit (point)))
5207 ;; Skip past the current button.
5208 (when (get-text-property (point) 'gnus-callback)
5209 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5210 ;; Go to the next (or previous) button.
5211 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5212 ;; Put point at the start of the button.
5213 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5214 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5215 ;; Skip past intangible buttons.
5216 (when (get-text-property (point) 'intangible)
5220 (gnus-message 5 "No more buttons"))
5223 (defun gnus-article-highlight (&optional force)
5224 "Highlight current article.
5225 This function calls `gnus-article-highlight-headers',
5226 `gnus-article-highlight-citation',
5227 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5228 do the highlighting. See the documentation for those functions."
5229 (interactive (list 'force))
5230 (gnus-article-highlight-headers)
5231 (gnus-article-highlight-citation force)
5232 (gnus-article-highlight-signature)
5233 (gnus-article-add-buttons force)
5234 (gnus-article-add-buttons-to-head))
5236 (defun gnus-article-highlight-some (&optional force)
5237 "Highlight current article.
5238 This function calls `gnus-article-highlight-headers',
5239 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5240 do the highlighting. See the documentation for those functions."
5241 (interactive (list 'force))
5242 (gnus-article-highlight-headers)
5243 (gnus-article-highlight-signature)
5244 (gnus-article-add-buttons))
5246 (defun gnus-article-highlight-headers ()
5247 "Highlight article headers as specified by `gnus-header-face-alist'."
5250 (set-buffer gnus-article-buffer)
5252 (let ((alist gnus-header-face-alist)
5253 (buffer-read-only nil)
5254 (case-fold-search t)
5255 (inhibit-point-motion-hooks t)
5256 entry regexp header-face field-face from hpoints fpoints)
5257 (article-narrow-to-head)
5258 (while (setq entry (pop alist))
5259 (goto-char (point-min))
5260 (setq regexp (concat "^\\("
5261 (if (string-equal "" (nth 0 entry))
5265 header-face (nth 1 entry)
5266 field-face (nth 2 entry))
5267 (while (and (re-search-forward regexp nil t)
5271 (unless (search-forward ":" nil t)
5273 (when (and header-face
5274 (not (memq (point) hpoints)))
5275 (push (point) hpoints)
5276 (gnus-put-text-property from (point) 'face header-face))
5277 (when (and field-face
5278 (not (memq (setq from (point)) fpoints)))
5280 (if (re-search-forward "^[^ \t]" nil t)
5282 (goto-char (point-max)))
5283 (gnus-put-text-property from (point) 'face field-face))))))))
5285 (defun gnus-article-highlight-signature ()
5286 "Highlight the signature in an article.
5287 It does this by highlighting everything after
5288 `gnus-signature-separator' using `gnus-signature-face'."
5290 (when gnus-signature-face
5292 (set-buffer gnus-article-buffer)
5293 (let ((buffer-read-only nil)
5294 (inhibit-point-motion-hooks t))
5296 (when (gnus-article-narrow-to-signature)
5297 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5298 'face gnus-signature-face)))))))
5300 (defun gnus-article-buttonize-signature ()
5301 "Add button to the signature."
5304 (set-buffer gnus-article-buffer)
5305 (let ((buffer-read-only nil)
5306 (inhibit-point-motion-hooks t))
5307 (when (gnus-article-search-signature)
5308 (gnus-article-add-button (match-beginning 0) (match-end 0)
5309 'gnus-signature-toggle
5310 (set-marker (make-marker)
5311 (1+ (match-end 0))))))))
5313 (defun gnus-button-in-region-p (b e prop)
5314 "Say whether PROP exists in the region."
5315 (text-property-not-all b e prop nil))
5317 (defun gnus-article-add-buttons (&optional force)
5318 "Find external references in the article and make buttons of them.
5319 \"External references\" are things like Message-IDs and URLs, as
5320 specified by `gnus-button-alist'."
5321 (interactive (list 'force))
5323 (set-buffer gnus-article-buffer)
5324 (let ((buffer-read-only nil)
5325 (inhibit-point-motion-hooks t)
5326 (case-fold-search t)
5327 (alist gnus-button-alist)
5329 ;; Remove all old markers.
5330 (let (marker entry new-list)
5331 (while (setq marker (pop gnus-button-marker-list))
5332 (if (or (< marker (point-min)) (>= marker (point-max)))
5333 (push marker new-list)
5335 (when (setq entry (gnus-button-entry))
5336 (put-text-property (match-beginning (nth 1 entry))
5337 (match-end (nth 1 entry))
5338 'gnus-callback nil))
5339 (set-marker marker nil)))
5340 (setq gnus-button-marker-list new-list))
5341 ;; We skip the headers.
5344 (while (setq entry (pop alist))
5345 (setq regexp (car entry))
5347 (while (re-search-forward regexp nil t)
5348 (let* ((start (and entry (match-beginning (nth 1 entry))))
5349 (end (and entry (match-end (nth 1 entry))))
5350 (from (match-beginning 0)))
5351 (when (and (or (eq t (nth 2 entry))
5352 (eval (nth 2 entry)))
5353 (not (gnus-button-in-region-p
5354 start end 'gnus-callback)))
5355 ;; That optional form returned non-nil, so we add the
5357 (gnus-article-add-button
5358 start end 'gnus-button-push
5359 (car (push (set-marker (make-marker) from)
5360 gnus-button-marker-list))))))))))
5362 ;; Add buttons to the head of an article.
5363 (defun gnus-article-add-buttons-to-head ()
5364 "Add buttons to the head of the article."
5367 (set-buffer gnus-article-buffer)
5369 (let ((buffer-read-only nil)
5370 (inhibit-point-motion-hooks t)
5371 (case-fold-search t)
5372 (alist gnus-header-button-alist)
5374 (article-narrow-to-head)
5376 ;; Each alist entry.
5377 (setq entry (car alist)
5379 (goto-char (point-min))
5380 (while (re-search-forward (car entry) nil t)
5381 ;; Each header matching the entry.
5382 (setq beg (match-beginning 0))
5383 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5384 (match-beginning 0))
5387 (while (re-search-forward (nth 1 entry) end t)
5388 ;; Each match within a header.
5389 (let* ((entry (cdr entry))
5390 (start (match-beginning (nth 1 entry)))
5391 (end (match-end (nth 1 entry)))
5392 (form (nth 2 entry)))
5393 (goto-char (match-end 0))
5395 (gnus-article-add-button
5396 start end (nth 3 entry)
5397 (buffer-substring (match-beginning (nth 4 entry))
5398 (match-end (nth 4 entry)))))))
5399 (goto-char end)))))))
5401 ;;; External functions:
5403 (defun gnus-article-add-button (from to fun &optional data)
5404 "Create a button between FROM and TO with callback FUN and data DATA."
5405 (when gnus-article-button-face
5406 (gnus-overlay-put (gnus-make-overlay from to)
5407 'face gnus-article-button-face))
5408 (gnus-add-text-properties
5410 (nconc (and gnus-article-mouse-face
5411 (list gnus-mouse-face-prop gnus-article-mouse-face))
5412 (list 'gnus-callback fun)
5413 (and data (list 'gnus-data data))))
5414 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5415 ;; Quote `:button-keymap' for Mule 2.3
5416 ;; but it won't work.
5417 ':button-keymap gnus-widget-button-keymap))
5419 ;;; Internal functions:
5421 (defun gnus-article-set-globals ()
5423 (set-buffer gnus-summary-buffer)
5424 (gnus-set-global-variables)))
5426 (defun gnus-signature-toggle (end)
5428 (set-buffer gnus-article-buffer)
5429 (let ((buffer-read-only nil)
5430 (inhibit-point-motion-hooks t)
5431 (limit (next-single-property-change end 'mime-view-entity
5433 (if (text-property-any end limit 'article-type 'signature)
5434 (gnus-remove-text-properties-when
5435 'article-type 'signature end limit
5436 (cons 'article-type (cons 'signature
5437 gnus-hidden-properties)))
5438 (gnus-add-text-properties-when
5439 'article-type nil end limit
5440 (cons 'article-type (cons 'signature
5441 gnus-hidden-properties)))))))
5443 (defun gnus-button-entry ()
5444 ;; Return the first entry in `gnus-button-alist' matching this place.
5445 (let ((alist gnus-button-alist)
5448 (setq entry (pop alist))
5449 (if (looking-at (car entry))
5454 (defun gnus-button-push (marker)
5455 ;; Push button starting at MARKER.
5458 (let* ((entry (gnus-button-entry))
5459 (inhibit-point-motion-hooks t)
5461 (args (mapcar (lambda (group)
5462 (let ((string (match-string group)))
5463 (gnus-set-text-properties
5464 0 (length string) nil string)
5471 (fboundp (symbol-value fun)))
5472 (apply (symbol-value fun) args))
5474 (gnus-message 1 "You must define `%S' to use this button"
5475 (cons fun args)))))))
5477 (defun gnus-button-message-id (message-id)
5480 (set-buffer gnus-summary-buffer)
5481 (gnus-summary-refer-article message-id)))
5483 (defun gnus-button-fetch-group (address)
5484 "Fetch GROUP specified by ADDRESS."
5485 (if (not (string-match "[:/]" address))
5486 ;; This is just a simple group url.
5487 (gnus-group-read-ephemeral-group address gnus-select-method)
5488 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5490 (error "Can't parse %s" address)
5491 (gnus-group-read-ephemeral-group
5492 (match-string 4 address)
5493 `(nntp ,(match-string 1 address)
5494 (nntp-address ,(match-string 1 address))
5495 (nntp-port-number ,(if (match-end 3)
5496 (match-string 3 address)
5499 (defun gnus-url-parse-query-string (query &optional downcase)
5500 (let (retval pairs cur key val)
5501 (setq pairs (split-string query "&"))
5503 (setq cur (car pairs)
5505 (if (not (string-match "=" cur))
5507 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5508 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5510 (setq key (downcase key)))
5511 (setq cur (assoc key retval))
5513 (setcdr cur (cons val (cdr cur)))
5514 (setq retval (cons (list key val) retval)))))
5517 (defun gnus-url-unhex (x)
5524 (defun gnus-url-unhex-string (str &optional allow-newlines)
5525 "Remove %XXX embedded spaces, etc in a url.
5526 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5527 decoding of carriage returns and line feeds in the string, which is normally
5528 forbidden in URL encoding."
5529 (setq str (or str ""))
5531 (case-fold-search t))
5532 (while (string-match "%[0-9a-f][0-9a-f]" str)
5533 (let* ((start (match-beginning 0))
5534 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5536 (gnus-url-unhex (elt str (+ start 2))))))
5538 tmp (substring str 0 start)
5541 (char-to-string code))
5542 ((or (= code ?\n) (= code ?\r))
5544 (t (char-to-string code))))
5545 str (substring str (match-end 0)))))
5546 (setq tmp (concat tmp str))
5549 (defun gnus-url-mailto (url)
5550 ;; Send mail to someone
5551 (when (string-match "mailto:/*\\(.*\\)" url)
5552 (setq url (substring url (match-beginning 1) nil)))
5553 (let (to args subject func)
5554 (if (string-match (regexp-quote "?") url)
5555 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5556 args (gnus-url-parse-query-string
5557 (substring url (match-end 0) nil) t))
5558 (setq to (gnus-url-unhex-string url)))
5559 (setq args (cons (list "to" to) args)
5560 subject (cdr-safe (assoc "subject" args)))
5563 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5566 (message-position-on-field (caar args)))
5567 (insert (mapconcat 'identity (cdar args) ", "))
5568 (setq args (cdr args)))
5571 (message-goto-subject))))
5573 (defun gnus-button-embedded-url (address)
5574 "Activate ADDRESS with `browse-url'."
5575 (browse-url (gnus-strip-whitespace address)))
5578 ;; Silence the byte-compiler.
5579 (autoload 'smiley-toggle-buffer "gnus-bitmap"))
5580 (defun gnus-article-smiley-display ()
5581 "Display \"smileys\" as small graphical icons."
5582 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5584 ;;; Next/prev buttons in the article buffer.
5586 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5587 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5589 (defvar gnus-prev-page-map nil)
5590 (unless gnus-prev-page-map
5591 (setq gnus-prev-page-map (make-sparse-keymap))
5592 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5593 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5595 (static-if (featurep 'xemacs)
5596 (defun gnus-insert-prev-page-button ()
5597 (let ((buffer-read-only nil))
5599 gnus-prev-page-line-format nil
5600 `(gnus-prev t local-map ,gnus-prev-page-map
5601 gnus-callback gnus-article-button-prev-page
5602 article-type annotation))))
5603 (defun gnus-insert-prev-page-button ()
5604 (let ((buffer-read-only nil)
5605 (situation (get-text-property (point-min) 'mime-view-situation)))
5606 (set-keymap-parent gnus-prev-page-map (current-local-map))
5608 gnus-prev-page-line-format nil
5609 `(gnus-prev t local-map ,gnus-prev-page-map
5610 gnus-callback gnus-article-button-prev-page
5611 article-type annotation
5612 mime-view-situation ,situation))))
5615 (defvar gnus-next-page-map nil)
5616 (unless gnus-next-page-map
5617 (setq gnus-next-page-map (make-sparse-keymap))
5618 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5619 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5621 (defun gnus-button-next-page ()
5622 "Go to the next page."
5624 (let ((win (selected-window)))
5625 (select-window (get-buffer-window gnus-article-buffer t))
5626 (gnus-article-next-page)
5627 (select-window win)))
5629 (defun gnus-button-prev-page ()
5630 "Go to the prev page."
5632 (let ((win (selected-window)))
5633 (select-window (get-buffer-window gnus-article-buffer t))
5634 (gnus-article-prev-page)
5635 (select-window win)))
5637 (static-if (featurep 'xemacs)
5638 (defun gnus-insert-next-page-button ()
5639 (let ((buffer-read-only nil))
5640 (gnus-eval-format gnus-next-page-line-format nil
5642 t local-map ,gnus-next-page-map
5643 gnus-callback gnus-article-button-next-page
5644 article-type annotation))))
5645 (defun gnus-insert-next-page-button ()
5646 (let ((buffer-read-only nil)
5647 (situation (get-text-property (point-min) 'mime-view-situation)))
5648 (set-keymap-parent gnus-next-page-map (current-local-map))
5649 (gnus-eval-format gnus-next-page-line-format nil
5651 t local-map ,gnus-next-page-map
5652 gnus-callback gnus-article-button-next-page
5653 article-type annotation
5654 mime-view-situation ,situation))))
5657 (defun gnus-article-button-next-page (arg)
5658 "Go to the next page."
5660 (let ((win (selected-window)))
5661 (select-window (get-buffer-window gnus-article-buffer t))
5662 (gnus-article-next-page)
5663 (select-window win)))
5665 (defun gnus-article-button-prev-page (arg)
5666 "Go to the prev page."
5668 (let ((win (selected-window)))
5669 (select-window (get-buffer-window gnus-article-buffer t))
5670 (gnus-article-prev-page)
5671 (select-window win)))
5673 (defvar gnus-decode-header-methods
5674 '(mail-decode-encoded-word-region)
5675 "List of methods used to decode headers.
5677 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5678 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5679 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5680 whose names match REGEXP.
5683 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5684 mail-decode-encoded-word-region
5685 (\"chinese\" . rfc1843-decode-region))
5688 (defvar gnus-decode-header-methods-cache nil)
5690 (defun gnus-multi-decode-header (start end)
5691 "Apply the functions from `gnus-encoded-word-methods' that match."
5692 (unless (and gnus-decode-header-methods-cache
5693 (eq gnus-newsgroup-name
5694 (car gnus-decode-header-methods-cache)))
5695 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5698 (nconc gnus-decode-header-methods-cache (list x))
5699 (if (and gnus-newsgroup-name
5700 (string-match (car x) gnus-newsgroup-name))
5701 (nconc gnus-decode-header-methods-cache
5703 gnus-decode-header-methods))
5704 (let ((xlist gnus-decode-header-methods-cache))
5707 (narrow-to-region start end)
5709 (funcall (pop xlist) (point-min) (point-max))))))
5712 ;;; Treatment top-level handling.
5715 (defun gnus-treat-article (condition &optional part-number total-parts type)
5716 (let ((length (- (point-max) (point-min)))
5717 (alist gnus-treatment-function-alist)
5718 (article-goto-body-goes-to-point-min-p t)
5722 (let ((list gnus-article-treat-types))
5724 (when (string-match (pop list) type)
5725 (throw 'found t)))))))
5726 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5727 (entity (static-unless (featurep 'xemacs)
5728 (when (eq 'head condition)
5729 (get-text-property (point-min) 'mime-view-entity))))
5730 val elem buttonized)
5731 (gnus-run-hooks 'gnus-part-display-hook)
5732 (unless gnus-inhibit-treatment
5733 (while (setq elem (pop alist))
5736 (if (gnus-buffer-live-p gnus-summary-buffer)
5737 (set-buffer gnus-summary-buffer))
5738 (symbol-value (car elem))))
5739 (when (and (or (consp val)
5741 (gnus-treat-predicate val)
5742 (or (not (get (car elem) 'highlight))
5744 (when (and (not buttonized)
5746 '(gnus-treat-hide-signature
5747 gnus-treat-highlight-signature)))
5748 (gnus-article-buttonize-signature)
5749 (setq buttonized t))
5751 (funcall (cadr elem)))))
5752 ;; FSF Emacsen does not inherit the existing text properties
5753 ;; in the new text, so we should do it for `mime-view-entity'.
5754 (static-unless (featurep 'xemacs)
5756 (put-text-property (point-min) (point-max)
5757 'mime-view-entity entity))))))
5759 ;; Dynamic variables.
5761 (defvar part-number)
5762 (defvar total-parts)
5767 (defun gnus-treat-predicate (val)
5772 (stringp (car val)))
5773 (apply 'gnus-or (mapcar `(lambda (s)
5774 (string-match s ,(or gnus-newsgroup-name "")))
5777 (let ((pred (pop val)))
5780 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5782 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5784 (not (gnus-treat-predicate (car val))))
5786 (equal (car val) type))
5788 (error "%S is not a valid predicate" pred)))))
5798 (eq part-number total-parts))
5802 (error "%S is not a valid value" val))))
5804 (defun gnus-article-encrypt-body (protocol &optional n)
5805 "Encrypt the article body."
5808 (or gnus-article-encrypt-protocol
5809 (completing-read "Encrypt protocol: "
5810 gnus-article-encrypt-protocol-alist
5812 current-prefix-arg))
5813 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5815 (error (format "Can't find the encrypt protocol %s" protocol)))
5816 (if (equal gnus-newsgroup-name "nndraft:drafts")
5817 (error "Can't encrypt the article in group nndraft:drafts."))
5818 (if (equal gnus-newsgroup-name "nndraft:queue")
5819 (error "Don't encrypt the article in group nndraft:queue."))
5820 (gnus-summary-iterate n
5822 (set-buffer gnus-summary-buffer)
5823 (let ((mail-parse-charset gnus-newsgroup-charset)
5824 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5825 (summary-buffer gnus-summary-buffer)
5827 (gnus-set-global-variables)
5828 (when (gnus-group-read-only-p)
5829 (error "The current newsgroup does not support article encrypt"))
5830 (gnus-summary-show-article t)
5832 (or (mail-header-references gnus-current-headers) ""))
5833 (set-buffer gnus-article-buffer)
5834 (let* ((buffer-read-only nil)
5836 (mapcar (lambda (field)
5837 (and (save-restriction
5838 (message-narrow-to-head)
5839 (goto-char (point-min))
5840 (search-forward field nil t))
5842 (message-narrow-to-field)
5843 (buffer-substring (point-min) (point-max))
5844 (delete-region (point-min) (point-max))
5846 '("Content-Type:" "Content-Transfer-Encoding:"
5847 "Content-Disposition:"))))
5848 (message-narrow-to-head)
5849 (message-remove-header "MIME-Version")
5850 (goto-char (point-max))
5851 (setq point (point))
5852 (insert (apply 'concat headers))
5854 (narrow-to-region point (point-max))
5855 (let ((message-options message-options))
5856 (message-options-set 'message-sender user-mail-address)
5857 (message-options-set 'message-recipients user-mail-address)
5858 (message-options-set 'message-sign-encrypt 'not)
5860 (goto-char (point-min))
5861 (insert "MIME-Version: 1.0\n")
5863 (gnus-summary-edit-article-done
5864 references nil summary-buffer t))
5865 (when gnus-keep-backlog
5866 (gnus-backlog-remove-article
5867 (car gnus-article-current) (cdr gnus-article-current)))
5869 (when (get-buffer gnus-original-article-buffer)
5870 (set-buffer gnus-original-article-buffer)
5871 (setq gnus-original-article nil)))
5872 (when gnus-use-cache
5873 (gnus-cache-update-article
5874 (car gnus-article-current) (cdr gnus-article-current))))))))
5876 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5877 "The following specs can be used:
5878 %t The security MIME type
5881 %D Details if button is pressed")
5883 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5884 "The following specs can be used:
5885 %t The security MIME type
5888 %D Details if button is pressed")
5890 (defvar gnus-mime-security-button-line-format-alist
5891 '((?t gnus-tmp-type ?s)
5892 (?i gnus-tmp-info ?s)
5893 (?d gnus-tmp-details ?s)
5894 (?D gnus-tmp-pressed-details ?s)))
5896 (defvar gnus-mime-security-button-map
5897 (let ((map (make-sparse-keymap)))
5898 (unless (>= (string-to-number emacs-version) 21)
5899 (set-keymap-parent map gnus-article-mode-map))
5900 (define-key map gnus-mouse-2 'gnus-article-push-button)
5901 (define-key map "\r" 'gnus-article-press-button)
5904 (defvar gnus-mime-security-details-buffer nil)
5906 (defvar gnus-mime-security-button-pressed nil)
5908 (defvar gnus-mime-security-show-details-inline t
5909 "If non-nil, show details in the article buffer.")
5911 (defun gnus-mime-security-verify-or-decrypt (handle)
5912 (mm-remove-parts (cdr handle))
5913 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5916 (delete-region (car region) (cdr region))
5917 (set-marker (car region) nil)
5918 (set-marker (cdr region) nil)))
5919 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5920 (let* ((mm-verify-option 'known)
5921 (mm-decrypt-option 'known)
5922 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5923 (unless (eq nparts (cdr handle))
5924 (mm-destroy-parts (cdr handle))
5925 (setcdr handle nparts))))
5926 (let ((point (point))
5928 (gnus-mime-display-security handle)
5931 (defun gnus-mime-security-show-details (handle)
5932 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5934 (if gnus-mime-security-show-details-inline
5935 (let ((gnus-mime-security-button-pressed t)
5936 (gnus-mime-security-button-line-format
5937 (get-text-property (point) 'gnus-line-format))
5940 (while (eq (get-text-property (point) 'gnus-line-format)
5941 gnus-mime-security-button-line-format)
5944 (delete-region (point)
5945 (or (text-property-not-all
5948 gnus-mime-security-button-line-format)
5950 (gnus-insert-mime-security-button handle))
5951 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5952 (with-current-buffer gnus-mime-security-details-buffer
5955 (setq gnus-mime-security-details-buffer
5956 (gnus-get-buffer-create "*MIME Security Details*")))
5957 (with-current-buffer gnus-mime-security-details-buffer
5959 (goto-char (point-min)))
5960 (pop-to-buffer gnus-mime-security-details-buffer))
5961 (gnus-message 5 "No details."))))
5963 (defun gnus-mime-security-press-button (handle)
5964 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5965 (gnus-mime-security-show-details handle)
5966 (gnus-mime-security-verify-or-decrypt handle)))
5968 (defun gnus-insert-mime-security-button (handle &optional displayed)
5969 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5972 (or (nth 2 (assoc protocol mm-verify-function-alist))
5973 (nth 2 (assoc protocol mm-decrypt-function-alist))
5975 (if (equal (car handle) "multipart/signed")
5976 " Signed" " Encrypted")
5979 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5982 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5983 gnus-tmp-pressed-details
5985 (setq gnus-tmp-details
5986 (if gnus-tmp-details
5987 (concat "\n" gnus-tmp-details) ""))
5988 (setq gnus-tmp-pressed-details
5989 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5994 gnus-mime-security-button-line-format
5995 gnus-mime-security-button-line-format-alist
5996 `(keymap ,gnus-mime-security-button-map
5997 ,@(if (>= (string-to-number emacs-version) 21)
5998 nil ;; XEmacs doesn't care
5999 (list 'local-map gnus-mime-security-button-map))
6000 gnus-callback gnus-mime-security-press-button
6001 gnus-line-format ,gnus-mime-security-button-line-format
6002 article-type annotation
6005 (widget-convert-button
6008 :action 'gnus-widget-press-button
6009 :button-keymap gnus-mime-security-button-map
6011 (lambda (widget/window &optional overlay pos)
6012 ;; Needed to properly clear the message due to a bug in
6013 ;; wid-edit (XEmacs only).
6014 (if (boundp 'help-echo-owns-message)
6015 (setq help-echo-owns-message t))
6018 (aref gnus-mouse-2 0))))))
6020 (defun gnus-mime-display-security (handle)
6022 (narrow-to-region (point) (point))
6023 (gnus-insert-mime-security-button handle)
6024 (gnus-mime-display-mixed (cdr handle))
6027 (let ((gnus-mime-security-button-line-format
6028 gnus-mime-security-button-end-line-format))
6029 (gnus-insert-mime-security-button handle))
6030 (mm-set-handle-multipart-parameter
6032 (cons (set-marker (make-marker) (point-min))
6033 (set-marker (make-marker) (point-max))))))
6039 (defun gnus-article-header-presentation-method (entity situation)
6040 (mime-insert-header entity)
6043 (set-alist 'mime-header-presentation-method-alist
6044 'gnus-original-article-mode
6045 #'gnus-article-header-presentation-method)
6047 (defun gnus-mime-preview-quitting-method ()
6048 (mime-preview-kill-buffer)
6049 (delete-other-windows)
6050 (gnus-article-show-summary)
6051 (gnus-summary-select-article gnus-show-all-headers t))
6053 (set-alist 'mime-preview-quitting-method-alist
6054 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6056 (set-alist 'mime-preview-following-method-alist
6057 'gnus-original-article-mode #'gnus-following-method)
6059 (set-alist 'mime-preview-over-to-previous-method-alist
6060 'gnus-original-article-mode
6062 (if (> (point-min) 1)
6063 (gnus-article-prev-page)
6064 (gnus-article-read-summary-keys
6065 nil (gnus-character-to-event ?P)))))
6067 (set-alist 'mime-preview-over-to-next-method-alist
6068 'gnus-original-article-mode'
6070 (if (< (point-max) (buffer-size))
6071 (gnus-article-next-page)
6072 (gnus-article-read-summary-keys
6073 nil (gnus-character-to-event ?N)))))
6083 (run-hooks 'gnus-art-load-hook)
6085 ;;; gnus-art.el ends here