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 (gnus-string-equal
1387 (gnus-fetch-field "newsgroups")
1388 (gnus-group-real-name
1389 (if (boundp 'gnus-newsgroup-name)
1392 (gnus-article-hide-header "newsgroups")))
1393 ((eq elem 'to-address)
1394 (let ((to (message-fetch-field "to"))
1396 (gnus-group-find-parameter
1397 (if (boundp 'gnus-newsgroup-name)
1398 gnus-newsgroup-name "") 'to-address)))
1399 (when (and to to-address
1402 ;; only one address in To
1403 (nth 1 (mail-extract-address-components to))
1405 (gnus-article-hide-header "to"))))
1406 ((eq elem 'followup-to)
1407 (when (gnus-string-equal
1408 (message-fetch-field "followup-to")
1409 (message-fetch-field "newsgroups"))
1410 (gnus-article-hide-header "followup-to")))
1411 ((eq elem 'reply-to)
1412 (let ((from (message-fetch-field "from"))
1413 (reply-to (message-fetch-field "reply-to")))
1418 (nth 1 (mail-extract-address-components from))
1419 (nth 1 (mail-extract-address-components reply-to)))))
1420 (gnus-article-hide-header "reply-to"))))
1422 (let ((date (message-fetch-field "date")))
1424 (< (days-between (current-time-string) date)
1426 (gnus-article-hide-header "date"))))
1428 (let ((to (message-fetch-field "to"))
1429 (cc (message-fetch-field "cc")))
1430 (when (> (length to) 1024)
1431 (gnus-article-hide-header "to"))
1432 (when (> (length cc) 1024)
1433 (gnus-article-hide-header "cc"))))
1437 (goto-char (point-min))
1438 (while (re-search-forward "^to:" nil t)
1439 (setq to-count (1+ to-count)))
1440 (when (> to-count 1)
1441 (while (> to-count 0)
1442 (goto-char (point-min))
1444 (re-search-forward "^to:" nil nil to-count)
1446 (narrow-to-region (point) (point-max))
1447 (gnus-article-hide-header "to"))
1448 (setq to-count (1- to-count))))
1449 (goto-char (point-min))
1450 (while (re-search-forward "^cc:" nil t)
1451 (setq cc-count (1+ cc-count)))
1452 (when (> cc-count 1)
1453 (while (> cc-count 0)
1454 (goto-char (point-min))
1456 (re-search-forward "^cc:" nil nil cc-count)
1458 (narrow-to-region (point) (point-max))
1459 (gnus-article-hide-header "cc"))
1460 (setq cc-count (1- cc-count)))))))))))))
1462 (defun gnus-article-hide-header (header)
1464 (goto-char (point-min))
1465 (when (re-search-forward (concat "^" header ":") nil t)
1466 (gnus-article-hide-text-type
1467 (progn (beginning-of-line) (point))
1470 (if (re-search-forward "^[^ \t]" nil t)
1475 (defun article-toggle-headers (&optional arg)
1476 "Toggle hiding of headers. If given a negative prefix, always show;
1477 if given a positive prefix, always hide."
1478 (interactive (gnus-article-hidden-arg))
1479 (let ((force (when (numberp arg)
1480 (cond ((> arg 0) 'always-hide)
1481 ((< arg 0) 'always-show))))
1482 (window (get-buffer-window gnus-article-buffer))
1483 (header-end (point-min))
1484 header-start field-end field-start
1485 (inhibit-point-motion-hooks t)
1486 (inhibit-read-only t)
1490 (while (and (setq header-start
1491 (text-property-any header-end (point-max)
1492 'article-treated-header t))
1494 (text-property-not-all header-start (point-max)
1495 'article-treated-header t)))
1496 (setq field-end header-start)
1498 (;; Hide exposed invisible fields.
1499 (and (not (eq 'always-show force))
1501 (text-property-any field-end header-end
1502 'exposed-invisible-field t)))
1503 (while (and field-start
1504 (setq field-end (text-property-not-all
1505 field-start header-end
1506 'exposed-invisible-field t)))
1507 (add-text-properties field-start field-end gnus-hidden-properties)
1508 (setq field-start (text-property-any field-end header-end
1509 'exposed-invisible-field t)))
1510 (put-text-property header-start header-end
1511 'exposed-invisible-field nil))
1512 (;; Expose invisible fields.
1513 (and (not (eq 'always-hide force))
1515 (text-property-any field-end header-end 'invisible t)))
1516 (while (and field-start
1517 (setq field-end (text-property-not-all
1518 field-start header-end
1520 ;; If the invisible text is not terminated with newline, we
1521 ;; won't expose it. Because it may be created by x-face-mule.
1522 ;; BTW, XEmacs sometimes fail in putting a invisible text
1523 ;; property with `gnus-article-hide-text' (really?). In that
1524 ;; case, the invisible text might be started from the middle of
1525 ;; a line so we will expose the sort of thing.
1526 (when (or (not (or (eq header-start field-start)
1527 (eq ?\n (char-before field-start))))
1528 (eq ?\n (char-before field-end)))
1529 (remove-text-properties field-start field-end
1530 gnus-hidden-properties)
1531 (put-text-property field-start field-end
1532 'exposed-invisible-field t))
1533 (setq field-start (text-property-any field-end header-end
1536 (not (eq 'always-show force))
1537 (narrow-to-region header-start header-end)
1538 (article-hide-headers)
1539 ;; Re-display X-Face image under XEmacs.
1540 (when (and (featurep 'xemacs)
1541 (gnus-functionp gnus-article-x-face-command))
1542 (let ((func (cadr (assq 'gnus-treat-display-xface
1543 gnus-treatment-function-alist)))
1545 (when (and (not gnus-inhibit-treatment)
1547 (gnus-treat-predicate gnus-treat-display-xface))
1549 (put-text-property header-start header-end 'read-only nil))))
1552 (goto-char (point-min))
1554 (set-window-start window (point-min))))))
1556 (defvar gnus-article-normalized-header-length 40
1557 "Length of normalized headers.")
1559 (defun article-normalize-headers ()
1560 "Make all header lines 40 characters long."
1562 (let ((buffer-read-only nil)
1566 (article-narrow-to-head)
1569 ((< (setq column (- (gnus-point-at-eol) (point)))
1570 gnus-article-normalized-header-length)
1572 (insert (make-string
1573 (- gnus-article-normalized-header-length column)
1575 ((> column gnus-article-normalized-header-length)
1576 (gnus-put-text-property
1578 (forward-char gnus-article-normalized-header-length)
1585 (forward-line 1))))))
1587 (defun article-treat-dumbquotes ()
1588 "Translate M****s*** sm*rtq**t*s into proper text.
1589 Note that this function guesses whether a character is a sm*rtq**t* or
1590 not, so it should only be used interactively.
1592 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1593 in an attempt to provide more quoting characters. If you see
1594 something like \\222 or \\264 where you're expecting some kind of
1595 apostrophe or quotation mark, then try this wash."
1597 (article-translate-strings gnus-article-dumbquotes-map))
1599 (defun article-translate-characters (from to)
1600 "Translate all characters in the body of the article according to FROM and TO.
1601 FROM is a string of characters to translate from; to is a string of
1602 characters to translate to."
1604 (when (article-goto-body)
1605 (let ((buffer-read-only nil)
1606 (x (make-string 225 ?x))
1608 (while (< (incf i) (length x))
1611 (while (< i (length from))
1612 (aset x (aref from i) (aref to i))
1614 (translate-region (point) (point-max) x)))))
1616 (defun article-translate-strings (map)
1617 "Translate all string in the body of the article according to MAP.
1618 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1620 (when (article-goto-body)
1621 (let ((buffer-read-only nil)
1623 (while (setq elem (pop map))
1625 (while (search-forward (car elem) nil t)
1626 (replace-match (cadr elem)))))))))
1628 (defun article-treat-overstrike ()
1629 "Translate overstrikes into bold text."
1632 (when (article-goto-body)
1633 (let ((buffer-read-only nil))
1634 (while (search-forward "\b" nil t)
1635 (let ((next (char-after))
1639 previous (char-after))
1643 ;; We do the boldification/underlining by hiding the
1644 ;; overstrikes and putting the proper text property
1648 (gnus-article-hide-text-type start (point) 'overstrike)
1649 (put-text-property (point) end 'face 'bold))
1651 (gnus-article-hide-text-type
1652 (1- (point)) (1+ (point)) 'overstrike)
1654 start (1- (point)) 'face 'underline))
1656 (gnus-article-hide-text-type start (point) 'overstrike)
1658 (point) end 'face 'underline)))))))))
1660 (defun article-fill-long-lines ()
1661 "Fill lines that are wider than the window width."
1664 (let ((buffer-read-only nil)
1665 (width (window-width (get-buffer-window (current-buffer)))))
1668 (let ((adaptive-fill-mode nil))
1671 (when (>= (current-column) (min fill-column width))
1672 (narrow-to-region (point) (gnus-point-at-bol))
1673 (fill-paragraph nil)
1674 (goto-char (point-max))
1676 (forward-line 1)))))))
1678 (defun article-capitalize-sentences ()
1679 "Capitalize the first word in each sentence."
1682 (let ((buffer-read-only nil)
1683 (paragraph-start "^[\n\^L]"))
1687 (forward-sentence)))))
1689 (defun article-remove-cr ()
1690 "Remove trailing CRs and then translate remaining CRs into LFs."
1693 (let ((buffer-read-only nil))
1694 (goto-char (point-min))
1695 (while (re-search-forward "\r+$" nil t)
1696 (replace-match "" t t))
1697 (goto-char (point-min))
1698 (while (search-forward "\r" nil t)
1699 (replace-match "\n" t t)))))
1701 (defun article-remove-trailing-blank-lines ()
1702 "Remove all trailing blank lines from the article."
1705 (let ((buffer-read-only nil))
1706 (goto-char (point-max))
1710 (while (and (not (bobp))
1711 (looking-at "^[ \t]*$")
1712 (not (gnus-annotation-in-region-p
1713 (point) (gnus-point-at-eol))))
1718 (defun article-display-x-face (&optional force)
1719 "Look for an X-Face header and display it if present."
1720 (interactive (list 'force))
1722 ;; Delete the old process, if any.
1723 (when (process-status "article-x-face")
1724 (delete-process "article-x-face"))
1725 (let ((inhibit-point-motion-hooks t)
1727 (case-fold-search t)
1730 (article-narrow-to-head)
1731 (when (and buffer-read-only ;; When type `W f'
1733 (goto-char (point-min))
1734 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1735 (gnus-buffer-live-p gnus-original-article-buffer))
1736 (with-current-buffer gnus-original-article-buffer
1738 (article-narrow-to-head)
1739 (while (re-search-forward "^X-Face:" nil t)
1745 (1- (re-search-forward
1746 "^\\($\\|[^ \t]\\)" nil t))))))))
1748 (let (point start bface eface buffer-read-only)
1749 (goto-char (point-max))
1751 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1752 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1753 (goto-char (point-max))
1754 (setq point (point))
1757 (while (looking-at "\\([^:]+\\): *")
1758 (put-text-property (match-beginning 1) (1+ (match-end 1))
1760 (setq start (match-end 0))
1762 (while (looking-at "[\t ]")
1764 (put-text-property start (point)
1766 (goto-char (point-min))
1767 (setq from (message-fetch-field "from"))
1768 (goto-char (point-min))
1769 (while (and gnus-article-x-face-command
1772 ;; Check whether this face is censored.
1773 (not gnus-article-x-face-too-ugly)
1774 (and gnus-article-x-face-too-ugly from
1775 (not (string-match gnus-article-x-face-too-ugly
1777 ;; Has to be present.
1778 (re-search-forward "^X-Face:[\t ]*" nil t))
1779 ;; This used to try to do multiple faces (`while' instead of
1780 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1781 ;; work (b) it can crash some versions of Emacs (c) are
1782 ;; multiple faces really something to encourage?
1783 (when (stringp gnus-article-x-face-command)
1785 ;; We now have the area of the buffer where the X-Face is stored.
1788 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1789 ;; We display the face.
1790 (if (symbolp gnus-article-x-face-command)
1791 ;; The command is a lisp function, so we call it.
1792 (if (gnus-functionp gnus-article-x-face-command)
1793 (funcall gnus-article-x-face-command beg end)
1794 (error "%s is not a function" gnus-article-x-face-command))
1795 ;; The command is a string, so we interpret the command
1796 ;; as a, well, command, and fork it off.
1797 (let ((process-connection-type nil))
1798 (process-kill-without-query
1800 "article-x-face" nil shell-file-name shell-command-switch
1801 gnus-article-x-face-command))
1802 (process-send-region "article-x-face" beg end)
1803 (process-send-eof "article-x-face"))))))))))
1805 (defun article-decode-mime-words ()
1806 "Decode all MIME-encoded words in the article."
1809 (set-buffer gnus-article-buffer)
1810 (let ((inhibit-point-motion-hooks t)
1812 (mail-parse-charset gnus-newsgroup-charset)
1813 (mail-parse-ignored-charsets
1814 (save-excursion (set-buffer gnus-summary-buffer)
1815 gnus-newsgroup-ignored-charsets)))
1816 (mail-decode-encoded-word-region (point-min) (point-max)))))
1818 (defun article-decode-charset (&optional prompt)
1819 "Decode charset-encoded text in the article.
1820 If PROMPT (the prefix), prompt for a coding system to use."
1822 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1824 (mail-parse-charset gnus-newsgroup-charset)
1825 (mail-parse-ignored-charsets
1826 (save-excursion (condition-case nil
1827 (set-buffer gnus-summary-buffer)
1829 gnus-newsgroup-ignored-charsets))
1830 ct cte ctl charset format)
1833 (article-narrow-to-head)
1834 (setq ct (message-fetch-field "Content-Type" t)
1835 cte (message-fetch-field "Content-Transfer-Encoding" t)
1836 ctl (and ct (ignore-errors
1837 (mail-header-parse-content-type ct)))
1840 (mm-read-coding-system "Charset to decode: "))
1842 (mail-content-type-get ctl 'charset)))
1843 format (and ctl (mail-content-type-get ctl 'format)))
1845 (setq cte (mail-header-strip cte)))
1846 (if (and ctl (not (string-match "/" (car ctl))))
1848 (goto-char (point-max)))
1851 (narrow-to-region (point) (point-max))
1852 (when (and (eq mail-parse-charset 'gnus-decoded)
1853 (eq (mm-body-7-or-8) '8bit))
1854 ;; The text code could have been decoded.
1855 (setq charset mail-parse-charset))
1856 (when (and (or (not ctl)
1857 (equal (car ctl) "text/plain"))
1858 (not format)) ;; article with format will decode later.
1860 charset (and cte (intern (downcase
1861 (gnus-strip-whitespace cte))))
1864 (defun article-decode-encoded-words ()
1865 "Remove encoded-word encoding from headers."
1866 (let (buffer-read-only)
1867 (let ((charset (save-excursion
1868 (set-buffer gnus-summary-buffer)
1869 default-mime-charset)))
1870 (mime-decode-header-in-buffer charset)
1873 (defun article-de-quoted-unreadable (&optional force)
1874 "Translate a quoted-printable-encoded article.
1875 If FORCE, decode the article whether it is marked as quoted-printable
1877 (interactive (list 'force))
1879 (let ((buffer-read-only nil) type charset)
1880 (if (gnus-buffer-live-p gnus-original-article-buffer)
1881 (with-current-buffer gnus-original-article-buffer
1883 (gnus-fetch-field "content-transfer-encoding"))
1884 (let* ((ct (gnus-fetch-field "content-type"))
1887 (mail-header-parse-content-type ct)))))
1888 (setq charset (and ctl
1889 (mail-content-type-get ctl 'charset)))
1890 (if (stringp charset)
1891 (setq charset (intern (downcase charset)))))))
1893 (setq charset gnus-newsgroup-charset))
1895 (and type (let ((case-fold-search t))
1896 (string-match "quoted-printable" type))))
1898 (quoted-printable-decode-region
1899 (point) (point-max) (mm-charset-to-coding-system charset))))))
1901 (defun article-de-base64-unreadable (&optional force)
1902 "Translate a base64 article.
1903 If FORCE, decode the article whether it is marked as base64 not."
1904 (interactive (list 'force))
1906 (let ((buffer-read-only nil) type charset)
1907 (if (gnus-buffer-live-p gnus-original-article-buffer)
1908 (with-current-buffer gnus-original-article-buffer
1910 (gnus-fetch-field "content-transfer-encoding"))
1911 (let* ((ct (gnus-fetch-field "content-type"))
1914 (mail-header-parse-content-type ct)))))
1915 (setq charset (and ctl
1916 (mail-content-type-get ctl 'charset)))
1917 (if (stringp charset)
1918 (setq charset (intern (downcase charset)))))))
1920 (setq charset gnus-newsgroup-charset))
1922 (and type (let ((case-fold-search t))
1923 (string-match "base64" type))))
1926 (narrow-to-region (point) (point-max))
1927 (base64-decode-region (point-min) (point-max))
1928 (mm-decode-coding-region
1929 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1934 (defun article-decode-HZ ()
1935 "Translate a HZ-encoded article."
1939 (let ((buffer-read-only nil))
1940 (rfc1843-decode-region (point-min) (point-max)))))
1942 (defun article-wash-html ()
1943 "Format an html article."
1946 (let ((buffer-read-only nil)
1948 (if (gnus-buffer-live-p gnus-original-article-buffer)
1949 (with-current-buffer gnus-original-article-buffer
1950 (let* ((ct (gnus-fetch-field "content-type"))
1953 (mail-header-parse-content-type ct)))))
1954 (setq charset (and ctl
1955 (mail-content-type-get ctl 'charset)))
1956 (if (stringp charset)
1957 (setq charset (intern (downcase charset)))))))
1959 (setq charset gnus-newsgroup-charset))
1961 (save-window-excursion
1963 (narrow-to-region (point) (point-max))
1965 (let ((w3-strict-width (window-width))
1966 (url-standalone-mode t))
1968 (w3-region (point-min) (point-max))
1971 (defun article-hide-list-identifiers ()
1972 "Remove list identifies from the Subject header.
1973 The `gnus-list-identifiers' variable specifies what to do."
1975 (let ((inhibit-point-motion-hooks t)
1976 (regexp (if (consp gnus-list-identifiers)
1977 (mapconcat 'identity gnus-list-identifiers " *\\|")
1978 gnus-list-identifiers))
1983 (article-narrow-to-head)
1984 (goto-char (point-min))
1985 (while (re-search-forward
1986 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1988 (delete-region (match-beginning 2) (match-end 0))
1989 (beginning-of-line))
1990 (when (re-search-forward
1991 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
1992 (delete-region (match-beginning 1) (match-end 1))))))))
1994 (defun article-hide-pgp ()
1995 "Remove any PGP headers and signatures in the current article."
1999 (let ((inhibit-point-motion-hooks t)
2000 buffer-read-only beg end)
2002 ;; Hide the "header".
2003 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2004 (push 'pgp gnus-article-wash-types)
2005 (delete-region (match-beginning 0) (match-end 0))
2006 ;; Remove armor headers (rfc2440 6.2)
2007 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2010 ;; Hide the actual signature.
2011 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2012 (setq end (1+ (match-beginning 0)))
2015 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2017 ;; Perhaps we shouldn't hide to the end of the buffer
2018 ;; if there is no end to the signature?
2020 ;; Hide "- " PGP quotation markers.
2022 (narrow-to-region beg end)
2023 (goto-char (point-min))
2024 (while (re-search-forward "^- " nil t)
2026 (match-beginning 0) (match-end 0)))
2028 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2030 (defun article-hide-pem (&optional arg)
2031 "Toggle hiding of any PEM headers and signatures in the current article.
2032 If given a negative prefix, always show; if given a positive prefix,
2034 (interactive (gnus-article-hidden-arg))
2035 (unless (gnus-article-check-hidden-text 'pem arg)
2037 (let (buffer-read-only end)
2038 (goto-char (point-min))
2039 ;; Hide the horrendously ugly "header".
2040 (when (and (search-forward
2041 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2043 (setq end (1+ (match-beginning 0))))
2044 (push 'pem gnus-article-wash-types)
2045 (gnus-article-hide-text-type
2047 (if (search-forward "\n\n" nil t)
2051 ;; Hide the trailer as well
2052 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2054 (gnus-article-hide-text-type
2055 (match-beginning 0) (match-end 0) 'pem)))))))
2057 (defun article-strip-banner ()
2058 "Strip the banner specified by the `banner' group parameter."
2062 (let ((inhibit-point-motion-hooks t)
2063 (banner (gnus-parameter-banner gnus-newsgroup-name))
2064 (gnus-signature-limit nil)
2065 buffer-read-only beg end)
2069 ((eq banner 'signature)
2070 (when (gnus-article-narrow-to-signature)
2073 (delete-region (point) (point-max))))
2075 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2076 (while (re-search-forward banner nil t)
2077 (delete-region (match-beginning 0) (match-end 0)))))
2079 (while (re-search-forward banner nil t)
2080 (delete-region (match-beginning 0) (match-end 0))))))))))
2082 (defun article-babel ()
2083 "Translate article using an online translation service."
2087 (set-buffer gnus-article-buffer)
2088 (when (article-goto-body)
2089 (let* ((buffer-read-only nil)
2092 (orig (buffer-substring start end))
2093 (trans (babel-as-string orig)))
2095 (narrow-to-region start end)
2096 (delete-region start end)
2099 (defun article-hide-signature (&optional arg)
2100 "Hide the signature in the current article.
2101 If given a negative prefix, always show; if given a positive prefix,
2103 (interactive (gnus-article-hidden-arg))
2109 (article-goto-body))
2110 (goto-char (point-min)))
2111 (unless (gnus-article-check-hidden-text 'signature arg)
2112 (let ((buffer-read-only nil)
2114 (while (setq button (text-property-any button (point-max)
2116 'gnus-signature-toggle))
2117 (setq button (text-property-not-all button (point-max)
2119 'gnus-signature-toggle))
2120 (when (and button (not (eobp)))
2121 (gnus-article-hide-text-type
2123 (next-single-property-change (1+ button) 'mime-view-entity
2127 (defun article-strip-headers-in-body ()
2128 "Strip offensive headers from bodies."
2132 (let ((case-fold-search t))
2133 (when (looking-at "x-no-archive:")
2134 (gnus-delete-line)))))
2136 (defun article-strip-leading-blank-lines ()
2137 "Remove all blank lines from the beginning of the article."
2140 (let ((inhibit-point-motion-hooks t)
2142 (when (article-goto-body)
2143 (while (and (not (eobp))
2144 (looking-at "[ \t]*$"))
2145 (gnus-delete-line))))))
2147 (defun article-narrow-to-head ()
2148 "Narrow the buffer to the head of the message.
2149 Point is left at the beginning of the narrowed-to region."
2151 (goto-char (point-min))
2152 (if (search-forward "\n\n" nil 1)
2155 (goto-char (point-min)))
2157 (defun article-goto-body ()
2158 "Place point at the start of the body."
2159 (goto-char (point-min))
2161 ;; This variable is only bound when dealing with separate
2163 (article-goto-body-goes-to-point-min-p
2165 ((search-forward "\n\n" nil t)
2168 (goto-char (point-max))
2171 (defun article-strip-multiple-blank-lines ()
2172 "Replace consecutive blank lines with one empty line."
2175 (let ((inhibit-point-motion-hooks t)
2177 ;; First make all blank lines empty.
2179 (while (re-search-forward "^[ \t]+$" nil t)
2180 (unless (gnus-annotation-in-region-p
2181 (match-beginning 0) (match-end 0))
2182 (replace-match "" nil t)))
2183 ;; Then replace multiple empty lines with a single empty line.
2185 (while (re-search-forward "\n\n\n+" nil t)
2186 (unless (gnus-annotation-in-region-p
2187 (match-beginning 0) (match-end 0))
2188 (replace-match "\n\n" t t))))))
2190 (defun article-strip-leading-space ()
2191 "Remove all white space from the beginning of the lines in the article."
2194 (let ((inhibit-point-motion-hooks t)
2197 (while (re-search-forward "^[ \t]+" nil t)
2198 (replace-match "" t t)))))
2200 (defun article-strip-trailing-space ()
2201 "Remove all white space from the end of the lines in the article."
2204 (let ((inhibit-point-motion-hooks t)
2207 (while (re-search-forward "[ \t]+$" nil t)
2208 (replace-match "" t t)))))
2210 (defun article-strip-blank-lines ()
2211 "Strip leading, trailing and multiple blank lines."
2213 (article-strip-leading-blank-lines)
2214 (article-remove-trailing-blank-lines)
2215 (article-strip-multiple-blank-lines))
2217 (defun article-strip-all-blank-lines ()
2218 "Strip all blank lines."
2221 (let ((inhibit-point-motion-hooks t)
2224 (while (re-search-forward "^[ \t]*\n" nil t)
2225 (replace-match "" t t)))))
2227 (defun gnus-article-narrow-to-signature ()
2228 "Narrow to the signature; return t if a signature is found, else nil."
2229 (let ((inhibit-point-motion-hooks t))
2230 (when (gnus-article-search-signature)
2232 ;; Check whether we have some limits to what we consider
2233 ;; to be a signature.
2234 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2235 (list gnus-signature-limit)))
2237 (while (setq limit (pop limits))
2238 (if (or (and (integerp limit)
2239 (< (- (point-max) (point)) limit))
2241 (< (count-lines (point) (point-max)) limit))
2242 (and (gnus-functionp limit)
2244 (and (stringp limit)
2245 (not (re-search-forward limit nil t))))
2246 () ; This limit did not succeed.
2250 (narrow-to-region (point) (point-max))
2253 (defun gnus-article-search-signature ()
2254 "Search the current buffer for the signature separator.
2255 Put point at the beginning of the signature separator."
2256 (let ((cur (point)))
2257 (goto-char (point-max))
2258 (if (if (stringp gnus-signature-separator)
2259 (re-search-backward gnus-signature-separator nil t)
2260 (let ((seps gnus-signature-separator))
2262 (not (re-search-backward (car seps) nil t)))
2269 (defun gnus-article-hidden-arg ()
2270 "Return the current prefix arg as a number, or 0 if no prefix."
2271 (list (if current-prefix-arg
2272 (prefix-numeric-value current-prefix-arg)
2275 (defun gnus-article-check-hidden-text (type arg)
2276 "Return nil if hiding is necessary.
2277 Arg can be nil or a number. Nil and positive means hide, negative
2278 means show, 0 means toggle."
2281 (let ((hide (gnus-article-hidden-text-p type)))
2287 (gnus-article-show-hidden-text type)
2290 (if (eq hide 'hidden)
2292 (gnus-article-show-hidden-text type)
2296 (defun gnus-article-hidden-text-p (type)
2297 "Say whether the current buffer contains hidden text of type TYPE."
2298 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2300 (not (get-text-property pos 'invisible))
2301 (not (get-text-property pos 'dummy-invisible)))
2303 (text-property-any (1+ pos) (point-max) 'article-type type)))
2308 (defun gnus-article-show-hidden-text (type &optional dummy)
2309 "Show all hidden text of type TYPE.
2310 Originally it is hide instead of DUMMY."
2311 (let ((buffer-read-only nil)
2312 (inhibit-point-motion-hooks t))
2313 (gnus-remove-text-properties-when
2315 (point-min) (point-max)
2316 (cons 'article-type (cons type
2317 gnus-hidden-properties)))))
2319 (defconst article-time-units
2320 `((year . ,(* 365.25 24 60 60))
2321 (week . ,(* 7 24 60 60))
2322 (day . ,(* 24 60 60))
2326 "Mapping from time units to seconds.")
2328 (defun article-date-ut (&optional type highlight header)
2329 "Convert DATE date to universal time in the current article.
2330 If TYPE is `local', convert to local time; if it is `lapsed', output
2331 how much time has lapsed since DATE. For `lapsed', the value of
2332 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2333 should replace the \"Date:\" one, or should be added below it."
2334 (interactive (list 'ut t))
2335 (let* ((header (or header
2336 (and (eq 1 (point-min))
2337 (mail-header-date (save-excursion
2338 (set-buffer gnus-summary-buffer)
2339 gnus-current-headers)))
2340 (message-fetch-field "date")
2342 (date (if (vectorp header) (mail-header-date header)
2344 (inhibit-point-motion-hooks t)
2345 bface eface date-pos)
2346 (when (and date (not (string= date "")))
2349 (article-narrow-to-head)
2350 (when (or (and (eq type 'lapsed)
2351 gnus-article-date-lapsed-new-header
2352 ;; Attempt to get the face of X-Sent first.
2353 (re-search-forward "^X-Sent:[ \t]" nil t))
2354 (re-search-forward "^Date:[ \t]" nil t)
2355 ;; If Date is missing, try again for X-Sent.
2356 (re-search-forward "^X-Sent:[ \t]" nil t))
2357 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2358 date (or (get-text-property (gnus-point-at-bol)
2361 eface (get-text-property (1- (gnus-point-at-eol))
2363 (let ((buffer-read-only nil))
2364 ;; Delete any old X-Sent headers.
2365 (when (setq date-pos
2366 (text-property-any (point-min) (point-max)
2367 'article-date-lapsed t))
2368 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2369 (delete-region (match-beginning 0)
2370 (progn (forward-line 1) (point))))
2371 (goto-char (point-min))
2372 ;; Delete any old Date headers.
2373 (while (re-search-forward "^Date:[ \t]" nil t)
2375 (setq date-pos (match-beginning 0)))
2376 (unless (and (eq type 'lapsed)
2377 gnus-article-date-lapsed-new-header)
2378 (delete-region (match-beginning 0)
2379 (progn (message-next-header) (point)))))
2382 (goto-char date-pos)
2384 ;; Possibly, Date has been deleted.
2386 (when (and (eq type 'lapsed)
2387 gnus-article-date-lapsed-new-header
2388 (looking-at "Date:"))
2390 (goto-char (point-min)))
2391 (insert (article-make-date-line date type))
2392 (when (eq type 'lapsed)
2393 (put-text-property (gnus-point-at-bol) (point)
2394 'article-date-lapsed t))
2398 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2399 (put-text-property (match-beginning 1) (1+ (match-end 1))
2400 'original-date date)
2401 (put-text-property (match-beginning 1) (1+ (match-end 1))
2403 (put-text-property (match-beginning 2) (match-end 2)
2406 (defun article-make-date-line (date type)
2407 "Return a DATE line of TYPE."
2408 (let ((time (condition-case ()
2412 ;; Convert to the local timezone. We have to slap a
2413 ;; `condition-case' round the calls to the timezone
2414 ;; functions since they aren't particularly resistant to
2417 (let ((tz (car (current-time-zone time))))
2418 (format "Date: %s %s%02d%02d" (current-time-string time)
2419 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2420 (/ (% (abs tz) 3600) 60))))
2421 ;; Convert to Universal Time.
2424 (current-time-string
2425 (let* ((e (parse-time-string date))
2426 (tm (apply 'encode-time e))
2428 (ls (- (cadr tm) (car (current-time-zone time)))))
2429 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2430 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2433 ;; Get the original date from the article.
2434 ((eq type 'original)
2435 (concat "Date: " (if (string-match "\n+$" date)
2436 (substring date 0 (match-beginning 0))
2438 ;; Let the user define the format.
2440 (if (gnus-functionp gnus-article-time-format)
2441 (funcall gnus-article-time-format time)
2444 (format-time-string gnus-article-time-format time))))
2447 (let ((tz (car (current-time-zone time))))
2450 (format-time-string "%Y%m%dT%H%M%S" time)
2451 (format "%s%02d%02d"
2452 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2453 (/ (% (abs tz) 3600) 60)))))
2454 ;; Do an X-Sent lapsed format.
2456 ;; If the date is seriously mangled, the timezone functions are
2457 ;; liable to bug out, so we ignore all errors.
2458 (let* ((now (current-time))
2459 (real-time (subtract-time now time))
2460 (real-sec (and real-time
2461 (+ (* (float (car real-time)) 65536)
2463 (sec (and real-time (abs real-sec)))
2473 ;; This is a bit convoluted, but basically we go
2474 ;; through the time units for years, weeks, etc,
2475 ;; and divide things to see whether that results
2476 ;; in positive answers.
2479 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2480 ;; The (remaining) seconds are too few to
2481 ;; be divided into this time unit.
2483 ;; It's big enough, so we output it.
2484 (setq sec (- sec (* num (cdr unit))))
2486 (concat (if prev ", " "") (int-to-string
2488 " " (symbol-name (car unit))
2489 (if (> num 1) "s" ""))
2491 article-time-units "")
2492 ;; If dates are odd, then it might appear like the
2493 ;; article was sent in the future.
2496 " in the future"))))))
2497 ;; Display the date in proper English
2499 (let ((dtime (decode-time time)))
2502 (number-to-string (nth 3 dtime))
2503 (let ((digit (% (nth 3 dtime) 10)))
2505 ((memq (nth 3 dtime) '(11 12 13)) "th")
2511 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2513 (number-to-string (nth 5 dtime))
2515 (format "%02d" (nth 2 dtime))
2517 (format "%02d" (nth 1 dtime)))))
2519 (error "Unknown conversion type: %s" type)))))
2521 (defun article-date-local (&optional highlight)
2522 "Convert the current article date to the local timezone."
2523 (interactive (list t))
2524 (article-date-ut 'local highlight))
2526 (defun article-date-english (&optional highlight)
2527 "Convert the current article date to something that is proper English."
2528 (interactive (list t))
2529 (article-date-ut 'english highlight))
2531 (defun article-date-original (&optional highlight)
2532 "Convert the current article date to what it was originally.
2533 This is only useful if you have used some other date conversion
2534 function and want to see what the date was before converting."
2535 (interactive (list t))
2536 (article-date-ut 'original highlight))
2538 (defun article-date-lapsed (&optional highlight)
2539 "Convert the current article date to time lapsed since it was sent."
2540 (interactive (list t))
2541 (article-date-ut 'lapsed highlight))
2543 (defun article-update-date-lapsed ()
2544 "Function to be run from a timer to update the lapsed time line."
2545 (let (deactivate-mark)
2550 (set-buffer (window-buffer w))
2551 (when (eq major-mode 'gnus-article-mode)
2552 (goto-char (point-min))
2553 (when (re-search-forward "^X-Sent:" nil t)
2554 (article-date-lapsed t))))
2557 (defun gnus-start-date-timer (&optional n)
2558 "Start a timer to update the X-Sent header in the article buffers.
2559 The numerical prefix says how frequently (in seconds) the function
2564 (gnus-stop-date-timer)
2565 (setq article-lapsed-timer
2566 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2568 (defun gnus-stop-date-timer ()
2569 "Stop the X-Sent timer."
2571 (when article-lapsed-timer
2572 (nnheader-cancel-timer article-lapsed-timer)
2573 (setq article-lapsed-timer nil)))
2575 (defun article-date-user (&optional highlight)
2576 "Convert the current article date to the user-defined format.
2577 This format is defined by the `gnus-article-time-format' variable."
2578 (interactive (list t))
2579 (article-date-ut 'user highlight))
2581 (defun article-date-iso8601 (&optional highlight)
2582 "Convert the current article date to ISO8601."
2583 (interactive (list t))
2584 (article-date-ut 'iso8601 highlight))
2586 (defun article-show-all ()
2587 "Show all hidden text in the article buffer."
2591 (let ((buffer-read-only nil))
2592 (gnus-article-unhide-text (point-min) (point-max))
2593 (gnus-remove-text-with-property 'gnus-prev)
2594 (gnus-remove-text-with-property 'gnus-next))))
2596 (defun article-show-all-headers ()
2597 "Show all hidden headers in the article buffer."
2602 (article-narrow-to-head)
2603 (let ((buffer-read-only nil))
2604 (gnus-article-unhide-text (point-min) (point-max))))))
2606 (defun article-emphasize (&optional arg)
2607 "Emphasize text according to `gnus-emphasis-alist'."
2608 (interactive (gnus-article-hidden-arg))
2609 (unless (gnus-article-check-hidden-text 'emphasis arg)
2613 (with-current-buffer gnus-summary-buffer
2614 gnus-article-emphasis-alist)
2616 gnus-emphasis-alist))
2617 (buffer-read-only nil)
2618 (props (append '(article-type emphasis)
2619 gnus-hidden-properties))
2620 regexp elem beg invisible visible face)
2623 (while (setq elem (pop alist))
2625 (setq regexp (car elem)
2626 invisible (nth 1 elem)
2627 visible (nth 2 elem)
2629 (while (re-search-forward regexp nil t)
2630 (when (and (match-beginning visible) (match-beginning invisible))
2631 (push 'emphasis gnus-article-wash-types)
2632 (gnus-article-hide-text
2633 (match-beginning invisible) (match-end invisible) props)
2634 (gnus-article-unhide-text-type
2635 (match-beginning visible) (match-end visible) 'emphasis)
2636 (gnus-put-text-property-excluding-newlines
2637 (match-beginning visible) (match-end visible) 'face face)
2638 (goto-char (match-end invisible)))))))))
2640 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2641 "Setup newsgroup emphasis alist."
2642 (unless gnus-article-emphasis-alist
2643 (let ((name (and gnus-newsgroup-name
2644 (gnus-group-real-name gnus-newsgroup-name))))
2645 (make-local-variable 'gnus-article-emphasis-alist)
2646 (setq gnus-article-emphasis-alist
2648 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2649 (while (setq elem (pop alist))
2650 (when (and name (string-match (car elem) name))
2652 highlight (copy-sequence (cdr elem)))))
2654 (copy-sequence highlight-words)
2655 (if gnus-newsgroup-name
2656 (copy-sequence (gnus-group-find-parameter
2657 gnus-newsgroup-name 'highlight-words t)))
2658 gnus-emphasis-alist)))))
2660 (defvar gnus-summary-article-menu)
2661 (defvar gnus-summary-post-menu)
2663 ;;; Saving functions.
2665 (defun gnus-article-save (save-buffer file &optional num)
2666 "Save the currently selected article."
2667 (unless gnus-save-all-headers
2668 ;; Remove headers according to `gnus-saved-headers'.
2669 (let ((gnus-visible-headers
2670 (or gnus-saved-headers gnus-visible-headers))
2671 (gnus-article-buffer save-buffer))
2673 (set-buffer save-buffer)
2674 (article-hide-headers 1 t))))
2675 (save-window-excursion
2676 (if (not gnus-default-article-saver)
2677 (error "No default saver is defined")
2678 ;; !!! Magic! The saving functions all save
2679 ;; `gnus-save-article-buffer' (or so they think), but we
2680 ;; bind that variable to our save-buffer.
2681 (set-buffer gnus-article-buffer)
2682 (let* ((gnus-save-article-buffer save-buffer)
2685 ((not gnus-prompt-before-saving) 'default)
2686 ((eq gnus-prompt-before-saving 'always) nil)
2688 (gnus-number-of-articles-to-be-saved
2689 (when (eq gnus-prompt-before-saving t)
2691 (set-buffer gnus-article-current-summary)
2692 (funcall gnus-default-article-saver filename)))))
2694 (defun gnus-read-save-file-name (prompt &optional filename
2695 function group headers variable)
2697 (funcall function group headers (symbol-value variable)))
2702 ((eq filename 'default)
2708 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2711 (if (and gnus-number-of-articles-to-be-saved
2712 (> gnus-number-of-articles-to-be-saved 1))
2713 (format "these %d articles"
2714 gnus-number-of-articles-to-be-saved)
2717 ;; Let the split methods have their say.
2719 ;; No split name was found.
2722 (concat prompt " (default "
2723 (file-name-nondirectory default-name) ") ")
2724 (file-name-directory default-name)
2726 ;; A single group name is returned.
2727 ((stringp split-name)
2729 (funcall function split-name headers
2730 (symbol-value variable)))
2732 (concat prompt " (default "
2733 (file-name-nondirectory default-name) ") ")
2734 (file-name-directory default-name)
2736 ;; A single split name was found
2737 ((= 1 (length split-name))
2738 (let* ((name (expand-file-name
2740 gnus-article-save-directory))
2741 (dir (cond ((file-directory-p name)
2742 (file-name-as-directory name))
2743 ((file-exists-p name) name)
2744 (t gnus-article-save-directory))))
2746 (concat prompt " (default " name ") ")
2748 ;; A list of splits was found.
2750 (setq split-name (nreverse split-name))
2752 (let ((file-name-history
2753 (nconc split-name file-name-history)))
2757 (concat prompt " (`M-p' for defaults) ")
2758 gnus-article-save-directory
2760 gnus-article-save-directory)))
2761 (car (push result file-name-history)))))))
2762 ;; Create the directory.
2763 (gnus-make-directory (file-name-directory file))
2764 ;; If we have read a directory, we append the default file name.
2765 (when (file-directory-p file)
2766 (setq file (expand-file-name (file-name-nondirectory
2768 (file-name-as-directory file))))
2769 ;; Possibly translate some characters.
2770 (nnheader-translate-file-chars file))))))
2771 (gnus-make-directory (file-name-directory result))
2772 (set variable result)))
2774 (defun gnus-article-archive-name (group)
2775 "Return the first instance of an \"Archive-name\" in the current buffer."
2776 (let ((case-fold-search t))
2777 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2778 (nnheader-concat gnus-article-save-directory
2779 (match-string 1)))))
2781 (defun gnus-article-nndoc-name (group)
2782 "If GROUP is an nndoc group, return the name of the parent group."
2783 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2784 (gnus-group-get-parameter group 'save-article-group)))
2786 (defun gnus-summary-save-in-rmail (&optional filename)
2787 "Append this article to Rmail file.
2788 Optional argument FILENAME specifies file name.
2789 Directory to save to is default to `gnus-article-save-directory'."
2790 (setq filename (gnus-read-save-file-name
2791 "Save %s in rmail file:" filename
2792 gnus-rmail-save-name gnus-newsgroup-name
2793 gnus-current-headers 'gnus-newsgroup-last-rmail))
2794 (gnus-eval-in-buffer-window gnus-save-article-buffer
2798 (gnus-output-to-rmail filename))))
2801 (defun gnus-summary-save-in-mail (&optional filename)
2802 "Append this article to Unix mail file.
2803 Optional argument FILENAME specifies file name.
2804 Directory to save to is default to `gnus-article-save-directory'."
2805 (setq filename (gnus-read-save-file-name
2806 "Save %s in Unix mail file:" filename
2807 gnus-mail-save-name gnus-newsgroup-name
2808 gnus-current-headers 'gnus-newsgroup-last-mail))
2809 (gnus-eval-in-buffer-window gnus-save-article-buffer
2813 (if (and (file-readable-p filename)
2814 (mail-file-babyl-p filename))
2815 (rmail-output-to-rmail-file filename t)
2816 (gnus-output-to-mail filename)))))
2819 (defun gnus-summary-save-in-file (&optional filename overwrite)
2820 "Append this article to file.
2821 Optional argument FILENAME specifies file name.
2822 Directory to save to is default to `gnus-article-save-directory'."
2823 (setq filename (gnus-read-save-file-name
2824 "Save %s in file:" filename
2825 gnus-file-save-name gnus-newsgroup-name
2826 gnus-current-headers 'gnus-newsgroup-last-file))
2827 (gnus-eval-in-buffer-window gnus-save-article-buffer
2831 (when (and overwrite
2832 (file-exists-p filename))
2833 (delete-file filename))
2834 (gnus-output-to-file filename))))
2837 (defun gnus-summary-write-to-file (&optional filename)
2838 "Write this article to a file.
2839 Optional argument FILENAME specifies file name.
2840 The directory to save in defaults to `gnus-article-save-directory'."
2841 (gnus-summary-save-in-file nil t))
2843 (defun gnus-summary-save-body-in-file (&optional filename)
2844 "Append this article body to a file.
2845 Optional argument FILENAME specifies file name.
2846 The directory to save in defaults to `gnus-article-save-directory'."
2847 (setq filename (gnus-read-save-file-name
2848 "Save %s body in file:" filename
2849 gnus-file-save-name gnus-newsgroup-name
2850 gnus-current-headers 'gnus-newsgroup-last-file))
2851 (gnus-eval-in-buffer-window gnus-save-article-buffer
2855 (when (article-goto-body)
2856 (narrow-to-region (point) (point-max)))
2857 (gnus-output-to-file filename))))
2860 (defun gnus-summary-save-in-pipe (&optional command)
2861 "Pipe this article to subprocess."
2863 (cond ((and (eq command 'default)
2864 gnus-last-shell-command)
2865 gnus-last-shell-command)
2870 "Shell command on %s: "
2871 (if (and gnus-number-of-articles-to-be-saved
2872 (> gnus-number-of-articles-to-be-saved 1))
2873 (format "these %d articles"
2874 gnus-number-of-articles-to-be-saved)
2876 gnus-last-shell-command))))
2877 (when (string-equal command "")
2878 (if gnus-last-shell-command
2879 (setq command gnus-last-shell-command)
2880 (error "A command is required.")))
2881 (gnus-eval-in-buffer-window gnus-article-buffer
2884 (shell-command-on-region (point-min) (point-max) command nil)))
2885 (setq gnus-last-shell-command command))
2887 ;;; Article file names when saving.
2889 (defun gnus-capitalize-newsgroup (newsgroup)
2890 "Capitalize NEWSGROUP name."
2891 (when (not (zerop (length newsgroup)))
2892 (concat (char-to-string (upcase (aref newsgroup 0)))
2893 (substring newsgroup 1))))
2895 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2896 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2897 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2898 Otherwise, it is like ~/News/news/group/num."
2901 (concat (if (gnus-use-long-file-name 'not-save)
2902 (gnus-capitalize-newsgroup newsgroup)
2903 (gnus-newsgroup-directory-form newsgroup))
2904 "/" (int-to-string (mail-header-number headers)))
2905 gnus-article-save-directory)))
2907 (string-equal (file-name-directory default)
2908 (file-name-directory last-file))
2909 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2911 (or last-file default))))
2913 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2914 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2915 If variable `gnus-use-long-file-name' is non-nil, it is
2916 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2919 (concat (if (gnus-use-long-file-name 'not-save)
2921 (gnus-newsgroup-directory-form newsgroup))
2922 "/" (int-to-string (mail-header-number headers)))
2923 gnus-article-save-directory)))
2925 (string-equal (file-name-directory default)
2926 (file-name-directory last-file))
2927 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2929 (or last-file default))))
2931 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2932 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2933 If variable `gnus-use-long-file-name' is non-nil, it is
2934 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2937 (if (gnus-use-long-file-name 'not-save)
2939 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2940 gnus-article-save-directory)))
2942 (defun article-verify-x-pgp-sig ()
2945 (if (gnus-buffer-live-p gnus-original-article-buffer)
2946 (let ((sig (with-current-buffer gnus-original-article-buffer
2947 (gnus-fetch-field "X-PGP-Sig")))
2951 (mml2015-clear-verify-function))
2953 (insert-buffer gnus-original-article-buffer)
2954 (setq items (split-string sig))
2955 (message-narrow-to-head)
2956 (let ((inhibit-point-motion-hooks t)
2957 (case-fold-search t))
2958 ;; Don't verify multiple headers.
2959 (setq headers (mapconcat (lambda (header)
2961 (mail-fetch-field header) "\n"))
2962 (split-string (nth 1 items) ",") "")))
2963 (delete-region (point-min) (point-max))
2964 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2965 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2970 (if (looking-at "^-")
2973 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2974 (insert "Version: " (car items) "\n\n")
2975 (insert (mapconcat 'identity (cddr items) "\n"))
2976 (insert "\n-----END PGP SIGNATURE-----\n")
2977 (let ((mm-security-handle (list (format "multipart/signed"))))
2978 (mml2015-clean-buffer)
2979 (let ((coding-system-for-write (or gnus-newsgroup-charset
2981 (funcall (mml2015-clear-verify-function)))
2983 (or (mm-handle-multipart-ctl-parameter
2984 mm-security-handle 'gnus-details)
2985 (mm-handle-multipart-ctl-parameter
2986 mm-security-handle 'gnus-info)))))
2988 (let (buffer-read-only bface eface)
2990 (message-narrow-to-head)
2991 (goto-char (point-max))
2993 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2994 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2995 (message-remove-header "X-Gnus-PGP-Verify")
2996 (if (re-search-forward "^X-PGP-Sig:" nil t)
2998 (goto-char (point-max)))
2999 (narrow-to-region (point) (point))
3000 (insert "X-Gnus-PGP-Verify: " info "\n")
3001 (goto-char (point-min))
3004 (if (not (looking-at "^[ \t]"))
3008 (goto-char (point-min))
3009 (when (looking-at "\\([^:]+\\): *")
3010 (put-text-property (match-beginning 1) (1+ (match-end 1))
3012 (put-text-property (match-end 0) (point-max)
3013 'face eface)))))))))
3020 (setq afunc (car func)
3023 gfunc (intern (format "gnus-%s" func))))
3026 `(lambda (&optional interactive &rest args)
3027 ,(documentation afunc t)
3028 (interactive (list t))
3030 (set-buffer gnus-article-buffer)
3032 (call-interactively ',afunc)
3033 (apply ',afunc args))))))))
3034 '(article-hide-headers
3035 article-verify-x-pgp-sig
3036 article-hide-boring-headers
3037 article-toggle-headers
3038 article-treat-overstrike
3039 article-fill-long-lines
3040 article-capitalize-sentences
3042 article-display-x-face
3043 article-de-quoted-unreadable
3044 article-de-base64-unreadable
3047 article-hide-list-identifiers
3049 article-strip-banner
3052 article-hide-signature
3053 article-strip-headers-in-body
3054 article-remove-trailing-blank-lines
3055 article-strip-leading-blank-lines
3056 article-strip-multiple-blank-lines
3057 article-strip-leading-space
3058 article-strip-trailing-space
3059 article-strip-blank-lines
3060 article-strip-all-blank-lines
3062 article-date-english
3063 article-date-iso8601
3064 article-date-original
3066 article-decode-mime-words
3067 article-decode-charset
3068 article-decode-encoded-words
3072 article-treat-dumbquotes
3073 article-normalize-headers
3074 (article-show-all-headers . gnus-article-show-all-headers)
3075 (article-show-all . gnus-article-show-all))))
3078 ;;; Gnus article mode
3081 (put 'gnus-article-mode 'mode-class 'special)
3083 (gnus-define-keys gnus-article-mode-map
3084 " " gnus-article-goto-next-page
3085 "\177" gnus-article-goto-prev-page
3086 [delete] gnus-article-goto-prev-page
3087 [backspace] gnus-article-goto-prev-page
3088 "\C-c^" gnus-article-refer-article
3089 "h" gnus-article-show-summary
3090 "s" gnus-article-show-summary
3091 "\C-c\C-m" gnus-article-mail
3092 "?" gnus-article-describe-briefly
3093 "e" gnus-summary-edit-article
3094 "<" beginning-of-buffer
3096 "\C-c\C-i" gnus-info-find-node
3098 "\C-hk" gnus-article-describe-key
3099 "\C-hc" gnus-article-describe-key-briefly
3101 "\C-d" gnus-article-read-summary-keys
3102 "\M-*" gnus-article-read-summary-keys
3103 "\M-#" gnus-article-read-summary-keys
3104 "\M-^" gnus-article-read-summary-keys
3105 "\M-g" gnus-article-read-summary-keys)
3107 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3110 (unless (lookup-key gnus-article-mode-map key)
3111 (define-key gnus-article-mode-map key
3112 'gnus-article-read-summary-keys)))
3117 (let ((key (car elt)))
3118 (and (> (length key) 0)
3119 (not (eq 'menu-bar (aref key 0)))
3120 (symbolp (lookup-key gnus-summary-mode-map key))
3122 (accessible-keymaps gnus-summary-mode-map))
3126 (push (char-to-string c) keys)
3131 (defvar gnus-article-commands-menu))
3133 (defun gnus-article-make-menu-bar ()
3134 (gnus-turn-off-edit-menu 'article)
3135 (unless (boundp 'gnus-article-article-menu)
3137 gnus-article-article-menu gnus-article-mode-map ""
3139 ["Scroll forwards" gnus-article-goto-next-page t]
3140 ["Scroll backwards" gnus-article-goto-prev-page t]
3141 ["Show summary" gnus-article-show-summary t]
3142 ["Fetch Message-ID at point" gnus-article-refer-article t]
3143 ["Mail to address at point" gnus-article-mail t]
3144 ["Send a bug report" gnus-bug t]))
3147 gnus-article-treatment-menu gnus-article-mode-map ""
3148 ;; Fixme: this should use :active (and maybe :visible).
3150 ["Hide headers" gnus-article-toggle-headers t]
3151 ["Hide signature" gnus-article-hide-signature t]
3152 ["Hide citation" gnus-article-hide-citation t]
3153 ["Treat overstrike" gnus-article-treat-overstrike t]
3154 ["Remove carriage return" gnus-article-remove-cr t]
3155 ["Decode HZ" gnus-article-decode-HZ t]))
3157 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3159 (when (boundp 'gnus-summary-post-menu)
3160 (define-key gnus-article-mode-map [menu-bar post]
3161 (cons "Post" gnus-summary-post-menu)))
3163 (gnus-run-hooks 'gnus-article-menu-hook))
3165 (when (boundp 'gnus-article-commands-menu)
3166 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
3167 (when (boundp 'gnus-summary-post-menu)
3168 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
3170 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3173 (defun gnus-article-mode ()
3174 "Major mode for displaying an article.
3176 All normal editing commands are switched off.
3178 The following commands are available in addition to all summary mode
3180 \\<gnus-article-mode-map>
3181 \\[gnus-article-next-page]\t Scroll the article one page forwards
3182 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3183 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3184 \\[gnus-article-show-summary]\t Display the summary buffer
3185 \\[gnus-article-mail]\t Send a reply to the address near point
3186 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3187 \\[gnus-info-find-node]\t Go to the Gnus info node"
3189 (when (gnus-visual-p 'article-menu 'menu)
3190 (gnus-article-make-menu-bar))
3191 (gnus-simplify-mode-line)
3192 (setq mode-name "Article")
3193 (setq major-mode 'gnus-article-mode)
3194 (make-local-variable 'minor-mode-alist)
3195 (unless (assq 'gnus-show-mime minor-mode-alist)
3196 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3197 (use-local-map gnus-article-mode-map)
3198 (gnus-update-format-specifications nil 'article-mode)
3199 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3200 (make-local-variable 'gnus-page-broken)
3201 (make-local-variable 'gnus-button-marker-list)
3202 (make-local-variable 'gnus-article-current-summary)
3203 (make-local-variable 'gnus-article-mime-handles)
3204 (make-local-variable 'gnus-article-decoded-p)
3205 (make-local-variable 'gnus-article-mime-handle-alist)
3206 (make-local-variable 'gnus-article-wash-types)
3207 (make-local-variable 'gnus-article-charset)
3208 (make-local-variable 'gnus-article-ignored-charsets)
3209 (gnus-set-default-directory)
3210 (buffer-disable-undo)
3211 (setq buffer-read-only t)
3212 (set-syntax-table gnus-article-mode-syntax-table)
3213 (gnus-run-hooks 'gnus-article-mode-hook))
3215 (defun gnus-article-setup-buffer ()
3216 "Initialize the article buffer."
3217 (let* ((name (if gnus-single-article-buffer "*Article*"
3218 (concat "*Article " gnus-newsgroup-name "*")))
3220 (progn (string-match "\\*Article" name)
3221 (concat " *Original Article"
3222 (substring name (match-end 0))))))
3223 (setq gnus-article-buffer name)
3224 (setq gnus-original-article-buffer original)
3225 (setq gnus-article-mime-handle-alist nil)
3226 ;; This might be a variable local to the summary buffer.
3227 (unless gnus-single-article-buffer
3229 (set-buffer gnus-summary-buffer)
3230 (setq gnus-article-buffer name)
3231 (setq gnus-original-article-buffer original)
3232 (gnus-set-global-variables)))
3233 (gnus-article-setup-highlight-words)
3234 ;; Init original article buffer.
3236 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3237 (set-buffer-multibyte nil)
3238 (setq major-mode 'gnus-original-article-mode)
3239 (make-local-variable 'gnus-original-article))
3240 (if (get-buffer name)
3243 (buffer-disable-undo)
3244 (setq buffer-read-only t)
3245 (unless (eq major-mode 'gnus-article-mode)
3246 (gnus-article-mode))
3249 (set-buffer (gnus-get-buffer-create name))
3251 (make-local-variable 'gnus-summary-buffer)
3252 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3253 (current-buffer)))))
3255 ;; Set article window start at LINE, where LINE is the number of lines
3256 ;; from the head of the article.
3257 (defun gnus-article-set-window-start (&optional line)
3259 (get-buffer-window gnus-article-buffer t)
3261 (set-buffer gnus-article-buffer)
3262 (goto-char (point-min))
3265 (gnus-message 6 "Moved to bookmark")
3266 (search-forward "\n\n" nil t)
3270 ;;; @@ article filters
3273 (defun gnus-article-display-mime-message ()
3274 "Article display method for MIME message."
3275 ;; called from `gnus-original-article-buffer'.
3276 (let (charset all-headers)
3277 (with-current-buffer gnus-summary-buffer
3278 (setq charset default-mime-charset
3279 all-headers gnus-have-all-headers))
3280 (make-local-variable 'default-mime-charset)
3281 (setq default-mime-charset charset)
3282 (with-current-buffer (get-buffer-create gnus-article-buffer)
3283 (make-local-variable 'default-mime-charset)
3284 (setq default-mime-charset charset))
3285 (mime-display-message mime-message-structure
3286 gnus-article-buffer nil gnus-article-mode-map)
3288 (gnus-article-hide-headers nil -1)))
3289 (run-hooks 'gnus-mime-article-prepare-hook))
3291 (defun gnus-article-display-traditional-message ()
3292 "Article display method for traditional message."
3293 (set-buffer gnus-article-buffer)
3294 (let (buffer-read-only)
3296 (insert-buffer-substring gnus-original-article-buffer)))
3298 (defun gnus-article-make-full-mail-header (&optional number charset)
3299 "Create a new mail header structure in a raw article buffer."
3300 (unless (and number charset)
3301 (save-current-buffer
3302 (set-buffer gnus-summary-buffer)
3304 (setq number (or (cdr gnus-article-current) 0)))
3306 (setq charset (or default-mime-charset 'x-ctext)))))
3307 (goto-char (point-min))
3308 (let ((header-end (if (search-forward "\n\n" nil t)
3310 (goto-char (point-max))))
3311 (chars (- (point-max) (point)))
3312 (lines (count-lines (point) (point-max)))
3313 (default-mime-charset charset)
3315 (narrow-to-region (point-min) header-end)
3316 (setq xref (std11-fetch-field "xref"))
3318 (make-full-mail-header
3320 (std11-fetch-field "subject")
3321 (std11-fetch-field "from")
3322 (std11-fetch-field "date")
3323 (std11-fetch-field "message-id")
3324 (std11-fetch-field "references")
3327 (when xref (concat "Xref: " xref)))
3330 (defun gnus-article-prepare (article &optional all-headers header)
3331 "Prepare ARTICLE in article mode buffer.
3332 ARTICLE should either be an article number or a Message-ID.
3333 If ARTICLE is an id, HEADER should be the article headers.
3334 If ALL-HEADERS is non-nil, no headers are hidden."
3336 ;; Make sure we start in a summary buffer.
3337 (unless (eq major-mode 'gnus-summary-mode)
3338 (set-buffer gnus-summary-buffer))
3339 (setq gnus-summary-buffer (current-buffer))
3340 (let* ((gnus-article (if header (mail-header-number header) article))
3341 (summary-buffer (current-buffer))
3342 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3343 (group gnus-newsgroup-name)
3346 (gnus-article-setup-buffer)
3347 (set-buffer gnus-original-article-buffer)
3348 ;; Deactivate active regions.
3349 (when (and (boundp 'transient-mark-mode)
3350 transient-mark-mode)
3351 (setq mark-active nil))
3352 (if (not (setq result (let ((buffer-read-only nil))
3353 (gnus-request-article-this-buffer
3355 ;; There is no such article.
3357 (when (and (numberp article)
3358 (not (memq article gnus-newsgroup-sparse)))
3359 (setq gnus-article-current
3360 (cons gnus-newsgroup-name article))
3361 (set-buffer gnus-summary-buffer)
3362 (setq gnus-current-article article)
3363 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3365 (gnus-summary-set-agent-mark article)
3366 (message "Message marked for downloading"))
3367 (gnus-summary-mark-article article gnus-canceled-mark)
3368 (unless (memq article gnus-newsgroup-sparse)
3369 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3370 (if (or (eq result 'pseudo)
3371 (eq result 'nneething))
3374 (set-buffer summary-buffer)
3375 (push article gnus-newsgroup-history)
3376 (setq gnus-last-article gnus-current-article
3377 gnus-current-article 0
3378 gnus-current-headers nil
3379 gnus-article-current nil)
3380 (if (eq result 'nneething)
3381 (gnus-configure-windows 'summary)
3382 (gnus-configure-windows 'article))
3383 (gnus-set-global-variables))
3384 (let ((gnus-article-mime-handle-alist-1
3385 gnus-article-mime-handle-alist))
3386 (gnus-set-mode-line 'article)))
3387 ;; The result from the `request' was an actual article -
3388 ;; or at least some text that is now displayed in the
3390 (when (and (numberp article)
3391 (not (eq article gnus-current-article)))
3392 ;; Seems like a new article has been selected.
3393 ;; `gnus-current-article' must be an article number.
3395 (set-buffer summary-buffer)
3396 (push article gnus-newsgroup-history)
3397 (setq gnus-last-article gnus-current-article
3398 gnus-current-article article
3399 gnus-current-headers
3400 (gnus-summary-article-header gnus-current-article)
3401 gnus-article-current
3402 (cons gnus-newsgroup-name gnus-current-article))
3403 (unless (vectorp gnus-current-headers)
3404 (setq gnus-current-headers nil))
3405 (gnus-summary-goto-subject gnus-current-article)
3406 (when (gnus-summary-show-thread)
3407 ;; If the summary buffer really was folded, the
3408 ;; previous goto may not actually have gone to
3409 ;; the right article, but the thread root instead.
3411 (gnus-summary-goto-subject gnus-current-article))
3412 (gnus-run-hooks 'gnus-mark-article-hook)
3413 (gnus-set-mode-line 'summary)
3414 (when (gnus-visual-p 'article-highlight 'highlight)
3415 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3416 ;; Set the global newsgroup variables here.
3417 (gnus-set-global-variables)
3418 (setq gnus-have-all-headers
3419 (or all-headers gnus-show-all-headers))))
3421 (gnus-configure-windows 'article))
3422 (when (or (numberp article)
3424 (gnus-article-prepare-display)
3426 (goto-char (point-min))
3427 (setq gnus-page-broken
3428 (when gnus-break-pages
3429 (gnus-narrow-to-page)
3431 (let ((gnus-article-mime-handle-alist-1
3432 gnus-article-mime-handle-alist))
3433 (gnus-set-mode-line 'article))
3435 (set-window-point (get-buffer-window (current-buffer)) (point))
3436 (gnus-configure-windows 'article)
3439 (defun gnus-article-prepare-mime-display (&optional number)
3440 (goto-char (point-min))
3441 (when (re-search-forward "^[^\t ]+:" nil t)
3442 (goto-char (match-beginning 0)))
3443 (let ((entity (if (eq 1 (point-min))
3444 (get-text-property 1 'mime-view-entity)
3445 (get-text-property (point) 'mime-view-entity)))
3446 last-entity child-entity next type)
3447 (setq child-entity (mime-entity-children entity))
3449 (setq last-entity (nth (1- (length child-entity))
3451 (setq last-entity entity))
3453 (narrow-to-region (point)
3454 (if (search-forward "\n\n" nil t)
3457 (gnus-treat-article 'head)
3458 (put-text-property (point-min) (point-max) 'article-treated-header t)
3459 (goto-char (point-max)))
3460 (while (and (not (eobp)) entity)
3461 (setq next (set-marker
3463 (next-single-property-change (point) 'mime-view-entity
3465 (let ((types (mime-entity-content-type entity)))
3466 (while (eq 'multipart (mime-content-type-primary-type types))
3467 (setq entity (car (mime-entity-children entity))
3468 types (mime-entity-content-type entity)))
3470 (setq type (format "%s/%s"
3471 (mime-content-type-primary-type types)
3472 (mime-content-type-subtype types)))))
3473 (if (string-equal type "message/rfc822")
3476 (let ((children (mime-entity-children entity))
3479 (setq last-children (nth (1- (length children)) children))
3482 (not (eq last-children
3483 (get-text-property next 'mime-view-entity)))
3485 (next-single-property-change next
3487 nil (point-max)))))))
3488 (setq next (next-single-property-change next 'mime-view-entity
3491 (narrow-to-region (point) next)
3492 (gnus-article-prepare-mime-display)
3493 (goto-char (point-max)))
3494 (setq entity (get-text-property (point) 'mime-view-entity)))
3496 (narrow-to-region (point) next)
3497 ;; Kludge. We have to count true number, but for now,
3498 ;; part number is here only to achieve `last'.
3499 (gnus-treat-article nil 1
3500 (if (eq entity last-entity)
3503 (goto-char (point-max)))
3504 (setq entity (get-text-property next 'mime-view-entity))))))
3507 (defun gnus-article-prepare-display ()
3508 "Make the current buffer look like a nice article."
3509 (setq gnus-article-wash-types nil)
3510 (gnus-run-hooks 'gnus-tmp-internal-hook)
3511 (gnus-run-hooks 'gnus-article-prepare-hook)
3513 (let (mime-display-header-hook mime-display-text/plain-hook)
3514 (funcall (if gnus-show-mime
3516 (setq mime-message-structure gnus-current-headers)
3517 (mime-buffer-entity-set-buffer-internal
3518 mime-message-structure
3519 gnus-original-article-buffer)
3520 (mime-entity-set-representation-type-internal
3521 mime-message-structure 'mime-buffer-entity)
3522 (luna-send mime-message-structure
3523 'initialize-instance
3524 mime-message-structure)
3525 gnus-article-display-method-for-mime)
3526 gnus-article-display-method-for-traditional)))
3527 ;; Associate this article with the current summary buffer.
3528 (setq gnus-article-current-summary gnus-summary-buffer)
3529 ;; Call the treatment functions.
3530 (let ((inhibit-read-only t)
3535 (gnus-article-prepare-mime-display)
3536 (narrow-to-region (goto-char (point-min))
3537 (if (search-forward "\n\n" nil t)
3540 (gnus-treat-article 'head)
3541 (put-text-property (point-min) (point-max) 'article-treated-header t)
3542 (goto-char (point-max))
3544 (narrow-to-region (point) (point-max))
3545 (gnus-treat-article nil))
3546 (put-text-property (point-min) (point-max) 'read-only nil)))
3547 ;; Perform the article display hooks. Incidentally, this hook is
3548 ;; an obsolete variable by now.
3549 (gnus-run-hooks 'gnus-article-display-hook))
3551 (defun gnus-article-decode-article-as-default-mime-charset ()
3552 "Decode an article as `default-mime-charset'. It won't work if the
3553 value of the variable `gnus-show-mime' is non-nil."
3554 (unless gnus-show-mime
3555 (decode-mime-charset-region (point-min) (point-max)
3556 (with-current-buffer gnus-summary-buffer
3557 default-mime-charset))))
3560 ;;; Gnus MIME viewing functions
3563 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3564 "The following specs can be used:
3566 %T MIME type, along with additional info
3567 %n The `name' parameter
3568 %d The description, if any
3569 %l The length of the encoded part
3570 %p The part identifier number
3571 %e Dots if the part isn't displayed")
3573 (defvar gnus-mime-button-line-format-alist
3574 '((?t gnus-tmp-type ?s)
3575 (?T gnus-tmp-type-long ?s)
3576 (?n gnus-tmp-name ?s)
3577 (?d gnus-tmp-description ?s)
3579 (?l gnus-tmp-length ?d)
3580 (?e gnus-tmp-dots ?s)))
3582 (defvar gnus-mime-button-commands
3583 '((gnus-article-press-button "\r" "Toggle Display")
3584 (gnus-mime-view-part "v" "View Interactively...")
3585 (gnus-mime-view-part-as-type "t" "View As Type...")
3586 (gnus-mime-view-part-as-charset "C" "View As charset...")
3587 (gnus-mime-save-part "o" "Save...")
3588 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3589 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3590 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3591 (gnus-mime-internalize-part "E" "View Internally")
3592 (gnus-mime-externalize-part "e" "View Externally")
3593 (gnus-mime-pipe-part "|" "Pipe To Command...")
3594 (gnus-mime-action-on-part "." "Take action on the part")))
3596 (defun gnus-article-mime-part-status ()
3597 (with-current-buffer gnus-article-buffer
3598 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3599 (if (and entity (mime-entity-children entity))
3600 (format " (%d parts)" (length (mime-entity-children entity)))
3603 (defvar gnus-mime-button-map
3604 (let ((map (make-sparse-keymap)))
3605 (unless (>= (string-to-number emacs-version) 21)
3606 ;; XEmacs doesn't care.
3607 (set-keymap-parent map gnus-article-mode-map))
3608 (define-key map gnus-mouse-2 'gnus-article-push-button)
3609 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3610 (dolist (c gnus-mime-button-commands)
3611 (define-key map (cadr c) (car c)))
3614 (defun gnus-mime-button-menu (event)
3615 "Construct a context-sensitive menu of MIME commands."
3617 (save-window-excursion
3618 (let ((pos (event-start event)))
3619 (select-window (posn-window pos))
3620 (goto-char (posn-point pos))
3621 (gnus-article-check-buffer)
3622 (let ((response (x-popup-menu
3624 ("" ,@(mapcar (lambda (c)
3625 (cons (caddr c) (car c)))
3626 gnus-mime-button-commands))))))
3628 (call-interactively response))))))
3630 (defun gnus-mime-view-all-parts (&optional handles)
3631 "View all the MIME parts."
3633 (save-current-buffer
3634 (set-buffer gnus-article-buffer)
3635 (let ((handles (or handles gnus-article-mime-handles))
3636 (mail-parse-charset gnus-newsgroup-charset)
3637 (mail-parse-ignored-charsets
3638 (with-current-buffer gnus-summary-buffer
3639 gnus-newsgroup-ignored-charsets)))
3641 (mm-remove-parts handles)
3642 (goto-char (point-min))
3643 (or (search-forward "\n\n") (goto-char (point-max)))
3644 (let (buffer-read-only)
3645 (delete-region (point) (point-max)))
3646 (mm-display-parts handles)))))
3648 (defun gnus-mime-save-part-and-strip ()
3649 "Save the MIME part under point then replace it with an external body."
3651 (gnus-article-check-buffer)
3652 (let* ((data (get-text-property (point) 'gnus-data))
3653 (file (and data (mm-save-part data)))
3656 (with-current-buffer (mm-handle-buffer data)
3658 (insert "Content-Type: " (mm-handle-media-type data))
3659 (mml-insert-parameter-string (cdr (mm-handle-type data))
3662 (insert "Content-ID: " (message-make-message-id) "\n")
3663 (insert "Content-Transfer-Encoding: binary\n")
3666 (cdr (mm-make-handle nil
3667 `("message/external-body"
3668 (access-type . "LOCAL-FILE")
3670 (set-buffer gnus-summary-buffer)
3671 (gnus-article-edit-article
3674 (let ((mail-parse-charset (or gnus-article-charset
3675 ',gnus-newsgroup-charset))
3676 (mail-parse-ignored-charsets
3677 (or gnus-article-ignored-charsets
3678 ',gnus-newsgroup-ignored-charsets))
3679 (mbl mml-buffer-list))
3680 (setq mml-buffer-list nil)
3681 (insert-buffer gnus-original-article-buffer)
3682 (mime-to-mml gnus-article-mime-handles)
3683 (setq gnus-article-mime-handles nil)
3684 (make-local-hook 'kill-buffer-hook)
3685 (let ((mbl1 mml-buffer-list))
3686 (setq mml-buffer-list mbl)
3687 (set (make-local-variable 'mml-buffer-list) mbl1))
3688 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3689 `(lambda (no-highlight)
3690 (let ((mail-parse-charset (or gnus-article-charset
3691 ',gnus-newsgroup-charset))
3692 (message-options message-options)
3693 (message-options-set-recipient)
3694 (mail-parse-ignored-charsets
3695 (or gnus-article-ignored-charsets
3696 ',gnus-newsgroup-ignored-charsets)))
3698 (mml-destroy-buffers)
3699 (remove-hook 'kill-buffer-hook
3700 'mml-destroy-buffers t)
3701 (kill-local-variable 'mml-buffer-list))
3702 (gnus-summary-edit-article-done
3703 ,(or (mail-header-references gnus-current-headers) "")
3704 ,(gnus-group-read-only-p)
3705 ,gnus-summary-buffer no-highlight))))))
3707 (defun gnus-mime-save-part ()
3708 "Save the MIME part under point."
3710 (gnus-article-check-buffer)
3711 (let ((data (get-text-property (point) 'gnus-data)))
3713 (mm-save-part data))))
3715 (defun gnus-mime-pipe-part ()
3716 "Pipe the MIME part under point to a process."
3718 (gnus-article-check-buffer)
3719 (let ((data (get-text-property (point) 'gnus-data)))
3721 (mm-pipe-part data))))
3723 (defun gnus-mime-view-part ()
3724 "Interactively choose a viewing method for the MIME part under point."
3726 (gnus-article-check-buffer)
3727 (let ((data (get-text-property (point) 'gnus-data)))
3729 (push (setq data (copy-sequence data)) gnus-article-mime-handles)
3730 (mm-interactively-view-part data))))
3732 (defun gnus-mime-view-part-as-type-internal ()
3733 (gnus-article-check-buffer)
3734 (let* ((name (mail-content-type-get
3735 (mm-handle-type (get-text-property (point) 'gnus-data))
3737 (def-type (and name (mm-default-file-encoding name))))
3738 (and def-type (cons def-type 0))))
3740 (defun gnus-mime-view-part-as-type (&optional mime-type)
3741 "Choose a MIME media type, and view the part as such."
3744 (setq mime-type (completing-read
3745 "View as MIME type: "
3746 (mapcar #'list (mailcap-mime-types))
3748 (gnus-mime-view-part-as-type-internal))))
3749 (gnus-article-check-buffer)
3750 (let ((handle (get-text-property (point) 'gnus-data)))
3753 (mm-make-handle (mm-handle-buffer handle)
3754 (cons mime-type (cdr (mm-handle-type handle)))
3755 (mm-handle-encoding handle)
3756 (mm-handle-undisplayer handle)
3757 (mm-handle-disposition handle)
3758 (mm-handle-description handle)
3759 (mm-handle-cache handle)
3760 (mm-handle-id handle)))
3761 (push handle gnus-article-mime-handles)
3762 (gnus-mm-display-part handle))))
3764 (defun gnus-mime-copy-part (&optional handle)
3765 "Put the the MIME part under point into a new buffer."
3767 (gnus-article-check-buffer)
3768 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3769 (contents (and handle (mm-get-part handle)))
3771 (file-name-nondirectory
3773 (mail-content-type-get (mm-handle-type handle) 'name)
3774 (mail-content-type-get (mm-handle-type handle)
3777 (buffer (and base (generate-new-buffer base))))
3779 (switch-to-buffer buffer)
3781 ;; We do it this way to make `normal-mode' set the appropriate mode.
3784 (setq buffer-file-name (expand-file-name base))
3786 (setq buffer-file-name nil))
3787 (goto-char (point-min)))))
3789 (defun gnus-mime-inline-part (&optional handle arg)
3790 "Insert the MIME part under point into the current buffer."
3791 (interactive (list nil current-prefix-arg))
3792 (gnus-article-check-buffer)
3793 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3798 (if (and (not arg) (mm-handle-undisplayer handle))
3799 (mm-remove-part handle)
3800 (setq contents (mm-get-part handle))
3803 (setq charset (or (mail-content-type-get
3804 (mm-handle-type handle) 'charset)
3805 gnus-newsgroup-charset)))
3807 (if (mm-handle-undisplayer handle)
3808 (mm-remove-part handle))
3811 gnus-summary-show-article-charset-alist))
3812 (read-coding-system "Charset: ")))))
3814 (mm-insert-inline handle
3816 (setq charset (mm-charset-to-coding-system
3818 (not (eq charset 'ascii)))
3819 (mm-decode-coding-string contents charset)
3823 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3824 "Insert the MIME part under point into the current buffer."
3825 (interactive (list nil current-prefix-arg))
3826 (gnus-article-check-buffer)
3827 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3832 (if (mm-handle-undisplayer handle)
3833 (mm-remove-part handle))
3834 (let ((gnus-newsgroup-charset
3836 gnus-summary-show-article-charset-alist))
3837 (read-coding-system "Charset: ")))
3838 (gnus-newsgroup-ignored-charsets 'gnus-all))
3839 (gnus-article-press-button)))))
3841 (defun gnus-mime-externalize-part (&optional handle)
3842 "View the MIME part under point with an external viewer."
3844 (gnus-article-check-buffer)
3845 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3846 (mm-user-display-methods nil)
3847 (mm-inlined-types nil)
3848 (mail-parse-charset gnus-newsgroup-charset)
3849 (mail-parse-ignored-charsets
3850 (save-excursion (set-buffer gnus-summary-buffer)
3851 gnus-newsgroup-ignored-charsets)))
3853 (if (mm-handle-undisplayer handle)
3854 (mm-remove-part handle)
3855 (mm-display-part handle)))))
3857 (defun gnus-mime-internalize-part (&optional handle)
3858 "View the MIME part under point with an internal viewer.
3859 In no internal viewer is available, use an external viewer."
3861 (gnus-article-check-buffer)
3862 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3863 (mm-inlined-types '(".*"))
3864 (mm-inline-large-images t)
3865 (mail-parse-charset gnus-newsgroup-charset)
3866 (mail-parse-ignored-charsets
3867 (save-excursion (set-buffer gnus-summary-buffer)
3868 gnus-newsgroup-ignored-charsets)))
3870 (if (mm-handle-undisplayer handle)
3871 (mm-remove-part handle)
3872 (mm-display-part handle)))))
3874 (defun gnus-mime-action-on-part (&optional action)
3875 "Do something with the MIME attachment at \(point\)."
3877 (list (completing-read "Action: " gnus-mime-action-alist)))
3878 (gnus-article-check-buffer)
3879 (let ((action-pair (assoc action gnus-mime-action-alist)))
3881 (funcall (cdr action-pair)))))
3883 (defun gnus-article-part-wrapper (n function)
3884 (save-current-buffer
3885 (set-buffer gnus-article-buffer)
3886 (when (> n (length gnus-article-mime-handle-alist))
3887 (error "No such part"))
3888 (gnus-article-goto-part n)
3889 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3890 (funcall function handle))))
3892 (defun gnus-article-pipe-part (n)
3893 "Pipe MIME part N, which is the numerical prefix."
3895 (gnus-article-part-wrapper n 'mm-pipe-part))
3897 (defun gnus-article-save-part (n)
3898 "Save MIME part N, which is the numerical prefix."
3900 (gnus-article-part-wrapper n 'mm-save-part))
3902 (defun gnus-article-interactively-view-part (n)
3903 "View MIME part N interactively, which is the numerical prefix."
3905 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3907 (defun gnus-article-copy-part (n)
3908 "Copy MIME part N, which is the numerical prefix."
3910 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3912 (defun gnus-article-view-part-as-charset (n)
3913 "Copy MIME part N, which is the numerical prefix."
3915 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3917 (defun gnus-article-externalize-part (n)
3918 "View MIME part N externally, which is the numerical prefix."
3920 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3922 (defun gnus-article-inline-part (n)
3923 "Inline MIME part N, which is the numerical prefix."
3925 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3927 (defun gnus-article-mime-match-handle-first (condition)
3929 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3930 (while (setq ihandle (pop alist))
3932 ((functionp condition)
3933 (funcall condition (cdr ihandle)))
3934 ((eq condition 'undisplayed)
3935 (not (or (mm-handle-undisplayer (cdr ihandle))
3936 (equal (mm-handle-media-type (cdr ihandle))
3937 "multipart/alternative"))))
3938 ((eq condition 'undisplayed-alternative)
3939 (not (mm-handle-undisplayer (cdr ihandle))))
3941 (gnus-article-goto-part (car ihandle))
3942 (or (not n) (< (car ihandle) n)))
3943 (setq n (car ihandle))))
3947 (defun gnus-article-view-part (&optional n)
3948 "View MIME part N, which is the numerical prefix."
3950 (save-current-buffer
3951 (set-buffer gnus-article-buffer)
3952 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3953 gnus-article-mime-match-handle-function)))
3954 (when (> n (length gnus-article-mime-handle-alist))
3955 (error "No such part"))
3956 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3957 (when (gnus-article-goto-part n)
3958 (if (equal (car handle) "multipart/alternative")
3959 (gnus-article-press-button)
3960 (when (eq (gnus-mm-display-part handle) 'internal)
3961 (gnus-set-window-start)))))))
3963 (defsubst gnus-article-mime-total-parts ()
3964 (if (bufferp (car gnus-article-mime-handles))
3966 (1- (length gnus-article-mime-handles))))
3968 (defun gnus-mm-display-part (handle)
3969 "Display HANDLE and fix MIME button."
3970 (let ((id (get-text-property (point) 'gnus-part))
3975 (let ((window (selected-window))
3976 (mail-parse-charset gnus-newsgroup-charset)
3977 (mail-parse-ignored-charsets
3978 (save-excursion (set-buffer gnus-summary-buffer)
3979 gnus-newsgroup-ignored-charsets)))
3982 (let ((win (get-buffer-window (current-buffer) t))
3985 (select-window win))
3988 (if (mm-handle-displayed-p handle)
3989 ;; This will remove the part.
3990 (mm-display-part handle)
3992 (narrow-to-region (point) (1+ (point)))
3993 (mm-display-part handle)
3994 ;; We narrow to the part itself and
3995 ;; then call the treatment functions.
3996 (goto-char (point-min))
3998 (narrow-to-region (point) (point-max))
4001 (gnus-article-mime-total-parts)
4002 (mm-handle-media-type handle)))))
4003 (select-window window))))
4005 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
4006 (gnus-insert-mime-button
4007 handle id (list (mm-handle-displayed-p handle)))
4008 (goto-char point))))
4010 (defun gnus-article-goto-part (n)
4011 "Go to MIME part N."
4012 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
4014 (goto-char point))))
4016 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4017 (let ((gnus-tmp-name
4018 (or (mail-content-type-get (mm-handle-type handle)
4020 (mail-content-type-get (mm-handle-disposition handle)
4022 (mail-content-type-get (mm-handle-type handle)
4025 (gnus-tmp-type (mm-handle-media-type handle))
4026 (gnus-tmp-description
4027 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4030 (if (if displayed (car displayed)
4031 (mm-handle-displayed-p handle))
4033 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4035 gnus-tmp-type-long b e)
4036 (when (string-match ".*/" gnus-tmp-name)
4037 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4038 (setq gnus-tmp-type-long (concat gnus-tmp-type
4039 (and (not (equal gnus-tmp-name ""))
4040 (concat "; " gnus-tmp-name))))
4041 (or (equal gnus-tmp-description "")
4042 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4047 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4048 `(keymap ,gnus-mime-button-map
4049 ,@(if (>= (string-to-number emacs-version) 21)
4051 (list 'local-map gnus-mime-button-map))
4052 gnus-callback gnus-mm-display-part
4053 gnus-part ,gnus-tmp-id
4054 article-type annotation
4057 (widget-convert-button
4060 :action 'gnus-widget-press-button
4061 :button-keymap gnus-mime-button-map
4063 (lambda (widget/window &optional overlay pos)
4064 ;; Needed to properly clear the message due to a bug in
4065 ;; wid-edit (XEmacs only).
4066 (if (boundp 'help-echo-owns-message)
4067 (setq help-echo-owns-message t))
4069 "%S: %s the MIME part; %S: more options"
4070 (aref gnus-mouse-2 0)
4071 ;; XEmacs will get a single widget arg; Emacs 21 will get
4072 ;; window, overlay, position.
4073 (if (mm-handle-displayed-p
4075 (with-current-buffer (gnus-overlay-buffer overlay)
4076 (widget-get (widget-at (gnus-overlay-start overlay))
4078 (widget-get widget/window :mime-handle)))
4080 (aref gnus-down-mouse-3 0))))))
4082 (defun gnus-widget-press-button (elems el)
4083 (goto-char (widget-get elems :from))
4084 (gnus-article-press-button))
4086 (defvar gnus-displaying-mime nil)
4088 (defun gnus-display-mime (&optional ihandles)
4089 "Display the MIME parts."
4091 (save-selected-window
4092 (let ((window (get-buffer-window gnus-article-buffer))
4095 (select-window window)
4096 ;; We have to do this since selecting the window
4097 ;; may change the point. So we set the window point.
4098 (set-window-point window point)))
4099 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
4100 buffer-read-only handle name type b e display)
4101 (when (and (not ihandles)
4102 (not gnus-displaying-mime))
4103 ;; Top-level call; we clean up.
4104 (when gnus-article-mime-handles
4105 (mm-destroy-parts gnus-article-mime-handles)
4106 (setq gnus-article-mime-handle-alist nil));; A trick.
4107 (setq gnus-article-mime-handles handles)
4108 ;; We allow users to glean info from the handles.
4109 (when gnus-article-mime-part-function
4110 (gnus-mime-part-function handles)))
4112 (or (not (stringp (car handles)))
4115 (when (and (not ihandles)
4116 (not gnus-displaying-mime))
4117 ;; Clean up for mime parts.
4119 (delete-region (point) (point-max)))
4120 (let ((gnus-displaying-mime t))
4121 (gnus-mime-display-part handles)))
4124 (narrow-to-region (point) (point-max))
4125 (gnus-treat-article nil 1 1)
4128 ;; Highlight the headers.
4132 (narrow-to-region (point-min) (point))
4133 (gnus-treat-article 'head))))))))
4135 (defvar gnus-mime-display-multipart-as-mixed nil)
4137 (defun gnus-mime-display-part (handle)
4140 ((not (stringp (car handle)))
4141 (gnus-mime-display-single handle))
4142 ;; User-defined multipart
4143 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4144 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4146 ;; multipart/alternative
4147 ((and (equal (car handle) "multipart/alternative")
4148 (not gnus-mime-display-multipart-as-mixed))
4149 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4150 (push (cons id handle) gnus-article-mime-handle-alist)
4151 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4152 ;; multipart/related
4153 ((and (equal (car handle) "multipart/related")
4154 (not gnus-mime-display-multipart-as-mixed))
4155 ;;;!!!We should find the start part, but we just default
4156 ;;;!!!to the first part.
4157 ;;(gnus-mime-display-part (cadr handle))
4158 ;;;!!! Most multipart/related is an HTML message plus images.
4159 ;;;!!! Unfortunately we are unable to let W3 display those
4160 ;;;!!! included images, so we just display it as a mixed multipart.
4161 ;;(gnus-mime-display-mixed (cdr handle))
4162 ;;;!!! No, w3 can display everything just fine.
4163 (gnus-mime-display-part (cadr handle)))
4164 ((equal (car handle) "multipart/signed")
4165 (or (memq 'signed gnus-article-wash-types)
4166 (push 'signed gnus-article-wash-types))
4167 (gnus-mime-display-security handle))
4168 ((equal (car handle) "multipart/encrypted")
4169 (or (memq 'encrypted gnus-article-wash-types)
4170 (push 'encrypted gnus-article-wash-types))
4171 (gnus-mime-display-security handle))
4172 ;; Other multiparts are handled like multipart/mixed.
4174 (gnus-mime-display-mixed (cdr handle)))))
4176 (defun gnus-mime-part-function (handles)
4177 (if (stringp (car handles))
4178 (mapcar 'gnus-mime-part-function (cdr handles))
4179 (funcall gnus-article-mime-part-function handles)))
4181 (defun gnus-mime-display-mixed (handles)
4182 (mapcar 'gnus-mime-display-part handles))
4184 (defun gnus-mime-display-single (handle)
4185 (let ((type (mm-handle-media-type handle))
4186 (ignored gnus-ignored-mime-types)
4193 (when (string-match (pop ignored) type)
4194 (throw 'ignored nil)))
4195 (if (and (setq not-attachment
4196 (and (not (mm-inline-override-p handle))
4197 (or (not (mm-handle-disposition handle))
4198 (equal (car (mm-handle-disposition handle))
4200 (mm-attachment-override-p handle))))
4201 (mm-automatic-display-p handle)
4202 (or (mm-inlined-p handle)
4203 (mm-automatic-external-display-p type)))
4205 (when (equal (mm-handle-media-supertype handle) "text")
4207 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4209 (push (cons id handle) gnus-article-mime-handle-alist)
4210 (when (or (not display)
4211 (not (gnus-unbuttonized-mime-type-p type)))
4212 ;(gnus-article-insert-newline)
4213 (gnus-insert-mime-button
4214 handle id (list (or display (and not-attachment text))))
4215 (gnus-article-insert-newline)
4216 ;(gnus-article-insert-newline)
4217 ;; Remember modify the number of forward lines.
4225 (let ((mail-parse-charset gnus-newsgroup-charset)
4226 (mail-parse-ignored-charsets
4227 (save-excursion (condition-case ()
4228 (set-buffer gnus-summary-buffer)
4230 gnus-newsgroup-ignored-charsets)))
4231 (mm-display-part handle t))
4232 (goto-char (point-max)))
4233 ((and text not-attachment)
4237 (gnus-article-insert-newline)
4238 (mm-insert-inline handle (mm-get-part handle))
4239 (goto-char (point-max))))
4243 (narrow-to-region beg (point))
4246 (gnus-article-mime-total-parts)
4247 (mm-handle-media-type handle)))))))))
4249 (defun gnus-unbuttonized-mime-type-p (type)
4250 "Say whether TYPE is to be unbuttonized."
4251 (unless gnus-inhibit-mime-unbuttonizing
4253 (let ((types gnus-unbuttonized-mime-types))
4255 (when (string-match (pop types) type)
4256 (throw 'found t)))))))
4258 (defun gnus-article-insert-newline ()
4259 "Insert a newline, but mark it as undeletable."
4260 (gnus-put-text-property
4261 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4263 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4264 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4267 handle buffer-read-only from props begend not-pref)
4268 (save-window-excursion
4271 (narrow-to-region (car ibegend)
4274 (goto-char (car ibegend))
4277 (delete-region (point-min) (point-max))
4278 (mm-remove-parts handles))
4279 (setq begend (list (point-marker)))
4281 (unless (setq not-pref (cadr (member preferred ihandles)))
4282 (setq not-pref (car ihandles)))
4285 (not (gnus-unbuttonized-mime-type-p
4286 "multipart/alternative")))
4287 (gnus-add-text-properties
4290 (insert (format "%d. " id))
4294 (unless ,(not ibegend)
4295 (setq gnus-article-mime-handle-alist
4296 ',gnus-article-mime-handle-alist))
4297 (gnus-mime-display-alternative
4298 ',ihandles ',not-pref ',begend ,id))
4299 ,@(if (>= (string-to-number emacs-version) 21)
4300 nil ;; XEmacs doesn't care
4301 (list 'local-map gnus-mime-button-map))
4302 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4303 face ,gnus-article-button-face
4304 keymap ,gnus-mime-button-map
4307 (widget-convert-button 'link from (point)
4308 :action 'gnus-widget-press-button
4309 :button-keymap gnus-widget-button-keymap)
4311 (while (setq handle (pop handles))
4312 (gnus-add-text-properties
4315 (insert (format "(%c) %-18s"
4316 (if (equal handle preferred) ?* ? )
4317 (mm-handle-media-type handle)))
4321 (unless ,(not ibegend)
4322 (setq gnus-article-mime-handle-alist
4323 ',gnus-article-mime-handle-alist))
4324 (gnus-mime-display-alternative
4325 ',ihandles ',handle ',begend ,id))
4326 ,@(if (>= (string-to-number emacs-version) 21)
4327 nil ;; XEmacs doesn't care
4328 (list 'local-map gnus-mime-button-map))
4329 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4330 face ,gnus-article-button-face
4331 keymap ,gnus-mime-button-map
4334 (widget-convert-button 'link from (point)
4335 :action 'gnus-widget-press-button
4336 :button-keymap gnus-widget-button-keymap)
4340 (if (stringp (car preferred))
4341 (gnus-display-mime preferred)
4342 (let ((mail-parse-charset gnus-newsgroup-charset)
4343 (mail-parse-ignored-charsets
4344 (save-excursion (set-buffer gnus-summary-buffer)
4345 gnus-newsgroup-ignored-charsets)))
4346 (mm-display-part preferred)
4350 (narrow-to-region (car begend) (point-max))
4352 nil (length gnus-article-mime-handle-alist)
4353 (gnus-article-mime-total-parts)
4354 (mm-handle-media-type handle))))))
4355 (goto-char (point-max))
4356 (setcdr begend (point-marker)))))
4358 (goto-char point))))
4360 (defun gnus-article-wash-status ()
4361 "Return a string which display status of article washing."
4363 (set-buffer gnus-article-buffer)
4364 (let ((cite (memq 'cite gnus-article-wash-types))
4365 (headers (memq 'headers gnus-article-wash-types))
4366 (boring (memq 'boring-headers gnus-article-wash-types))
4367 (pgp (memq 'pgp gnus-article-wash-types))
4368 (pem (memq 'pem gnus-article-wash-types))
4369 (signed (memq 'signed gnus-article-wash-types))
4370 (encrypted (memq 'encrypted gnus-article-wash-types))
4371 (signature (memq 'signature gnus-article-wash-types))
4372 (overstrike (memq 'overstrike gnus-article-wash-types))
4373 (emphasis (memq 'emphasis gnus-article-wash-types)))
4374 (format "%c%c%c%c%c%c%c"
4376 (if (or headers boring) ?h ? )
4377 (if (or pgp pem signed encrypted) ?p ? )
4378 (if signature ?s ? )
4379 (if overstrike ?o ? )
4380 (if gnus-show-mime ?m ? )
4381 (if emphasis ?e ? )))))
4383 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4385 (defun gnus-article-maybe-hide-headers ()
4386 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4387 Provided for backwards compatibility."
4388 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4389 (not (save-excursion (set-buffer gnus-summary-buffer)
4390 gnus-have-all-headers)))
4391 (not gnus-inhibit-hiding))
4392 (gnus-article-hide-headers)))
4396 (defun gnus-output-to-file (file-name)
4397 "Append the current article to a file named FILE-NAME."
4398 (let ((artbuf (current-buffer)))
4400 (insert-buffer-substring artbuf)
4401 ;; Append newline at end of the buffer as separator, and then
4403 (goto-char (point-max))
4405 (write-region-as-binary (point-min) (point-max) file-name 'append)
4408 (defun gnus-narrow-to-page (&optional arg)
4409 "Narrow the article buffer to a page.
4410 If given a numerical ARG, move forward ARG pages."
4412 (setq arg (if arg (prefix-numeric-value arg) 0))
4414 (set-buffer gnus-article-buffer)
4415 (goto-char (point-min))
4417 ;; Remove any old next/prev buttons.
4418 (when (gnus-visual-p 'page-marker)
4419 (let ((buffer-read-only nil))
4420 (gnus-remove-text-with-property 'gnus-prev)
4421 (gnus-remove-text-with-property 'gnus-next)))
4424 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4426 (re-search-forward page-delimiter nil 'move arg)))
4427 (goto-char (match-end 0)))
4430 (if (re-search-forward page-delimiter nil 'move)
4433 (when (and (gnus-visual-p 'page-marker)
4434 (not (= (point-min) 1)))
4436 (goto-char (point-min))
4437 (gnus-insert-prev-page-button)))
4438 (when (and (gnus-visual-p 'page-marker)
4439 (< (+ (point-max) 2) (buffer-size)))
4441 (goto-char (point-max))
4442 (gnus-insert-next-page-button)))))
4444 ;; Article mode commands
4446 (defun gnus-article-goto-next-page ()
4447 "Show the next page of the article."
4449 (when (gnus-article-next-page)
4450 (goto-char (point-min))
4451 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4453 (defun gnus-article-goto-prev-page ()
4454 "Show the next page of the article."
4456 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4457 (gnus-article-prev-page nil)))
4459 (defun gnus-article-next-page (&optional lines)
4460 "Show the next page of the current article.
4461 If end of article, return non-nil. Otherwise return nil.
4462 Argument LINES specifies lines to be scrolled up."
4464 (let ((start (window-start))
4465 end-of-buffer end-of-page)
4467 (move-to-window-line -1)
4468 (if (<= (point) start)
4471 (setq start (point)))
4474 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4475 (and (pos-visible-in-window-p)
4476 (setq end-of-buffer t)))
4478 (setq end-of-page t)))
4480 (move-to-window-line lines)
4481 (unless (search-backward "\n\n" nil t)
4482 (setq start (point)))))
4483 (cond (end-of-buffer t)
4485 (gnus-narrow-to-page 1)
4489 (set-window-start (selected-window) start)
4490 (let (window-pixel-scroll-increment)
4494 (defun gnus-article-prev-page (&optional lines)
4495 "Show previous page of current article.
4496 Argument LINES specifies lines to be scrolled down."
4498 (let (beginning-of-buffer beginning-of-page)
4500 (move-to-window-line 0)
4501 (cond ((eq 1 (point))
4502 (setq beginning-of-buffer t))
4504 (setq beginning-of-page t))))
4505 (cond (beginning-of-buffer)
4507 (gnus-narrow-to-page -1))
4510 (let (window-pixel-scroll-increment)
4511 (scroll-down lines))
4512 (beginning-of-buffer
4513 (goto-char (point-min))))))))
4515 (defun gnus-article-refer-article ()
4516 "Read article specified by message-id around point."
4518 (let ((point (point)))
4519 (search-forward ">" nil t) ;Move point to end of "<....>".
4520 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4521 (let ((message-id (match-string 1)))
4523 (set-buffer gnus-summary-buffer)
4524 (gnus-summary-refer-article message-id))
4526 (error "No references around point"))))
4528 (defun gnus-article-show-summary ()
4529 "Reconfigure windows to show summary buffer."
4531 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4532 (error "There is no summary buffer for this article buffer")
4533 (gnus-article-set-globals)
4534 (gnus-configure-windows 'article)
4535 (gnus-summary-goto-subject gnus-current-article)
4536 (gnus-summary-position-point)))
4538 (defun gnus-article-describe-briefly ()
4539 "Describe article mode commands briefly."
4541 (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")))
4543 (defun gnus-article-summary-command ()
4544 "Execute the last keystroke in the summary buffer."
4546 (let ((obuf (current-buffer))
4547 (owin (current-window-configuration))
4549 (switch-to-buffer gnus-article-current-summary 'norecord)
4550 (setq func (lookup-key (current-local-map) (this-command-keys)))
4551 (call-interactively func)
4553 (set-window-configuration owin)
4554 (set-window-point (get-buffer-window (current-buffer)) (point))))
4556 (defun gnus-article-summary-command-nosave ()
4557 "Execute the last keystroke in the summary buffer."
4560 (pop-to-buffer gnus-article-current-summary 'norecord)
4561 (setq func (lookup-key (current-local-map) (this-command-keys)))
4562 (call-interactively func)))
4564 (defun gnus-article-check-buffer ()
4565 "Beep if not in an article buffer."
4566 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4567 (error "Command invoked outside of a Gnus article buffer")))
4569 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4570 "Read a summary buffer key sequence and execute it from the article buffer."
4572 (gnus-article-check-buffer)
4574 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4575 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4576 "=" "^" "\M-^" "|"))
4582 '("n" "Gn" "p" "Gp"))
4585 (set-buffer gnus-article-current-summary)
4586 (let (gnus-pick-mode)
4587 (push (or key last-command-event) unread-command-events)
4588 (setq keys (static-if (featurep 'xemacs)
4589 (events-to-keys (read-key-sequence nil))
4590 (read-key-sequence nil)))))
4593 (if (or (member keys nosaves)
4594 (member keys nosave-but-article)
4595 (member keys nosave-in-article))
4597 (save-window-excursion
4598 (pop-to-buffer gnus-article-current-summary 'norecord)
4599 ;; We disable the pick minor mode commands.
4600 (let (gnus-pick-mode)
4601 (setq func (lookup-key (current-local-map) keys))))
4605 (unless (member keys nosave-in-article)
4606 (set-buffer gnus-article-current-summary))
4607 (call-interactively func)
4608 (setq new-sum-point (point)))
4609 (when (member keys nosave-but-article)
4610 (pop-to-buffer gnus-article-buffer 'norecord)))
4611 ;; These commands should restore window configuration.
4612 (let ((obuf (current-buffer))
4613 (owin (current-window-configuration))
4615 (summary gnus-article-current-summary)
4616 func in-buffer selected)
4617 (if not-restore-window
4618 (pop-to-buffer summary 'norecord)
4619 (switch-to-buffer summary 'norecord))
4620 (setq in-buffer (current-buffer))
4621 ;; We disable the pick minor mode commands.
4622 (if (and (setq func (let (gnus-pick-mode)
4623 (lookup-key (current-local-map) keys)))
4626 (call-interactively func)
4627 (setq new-sum-point (point))
4628 (when (eq in-buffer (current-buffer))
4629 (setq selected (gnus-summary-select-article))
4631 (unless not-restore-window
4632 (set-window-configuration owin))
4633 (when (eq selected 'old)
4635 (set-window-start (get-buffer-window (current-buffer))
4637 (set-window-point (get-buffer-window (current-buffer))
4639 (let ((win (get-buffer-window gnus-article-current-summary)))
4641 (set-window-point win new-sum-point)))) )
4642 (switch-to-buffer gnus-article-buffer)
4645 (defun gnus-article-describe-key (key)
4646 "Display documentation of the function invoked by KEY. KEY is a string."
4647 (interactive "kDescribe key: ")
4648 (gnus-article-check-buffer)
4649 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4651 (set-buffer gnus-article-current-summary)
4652 (let (gnus-pick-mode)
4653 (push (elt key 0) unread-command-events)
4654 (setq key (if (featurep 'xemacs)
4655 (events-to-keys (read-key-sequence "Describe key: "))
4656 (read-key-sequence "Describe key: "))))
4658 (describe-key key)))
4660 (defun gnus-article-describe-key-briefly (key &optional insert)
4661 "Display documentation of the function invoked by KEY. KEY is a string."
4662 (interactive "kDescribe key: \nP")
4663 (gnus-article-check-buffer)
4664 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4666 (set-buffer gnus-article-current-summary)
4667 (let (gnus-pick-mode)
4668 (push (elt key 0) unread-command-events)
4669 (setq key (if (featurep 'xemacs)
4670 (events-to-keys (read-key-sequence "Describe key: "))
4671 (read-key-sequence "Describe key: "))))
4672 (describe-key-briefly key insert))
4673 (describe-key-briefly key insert)))
4675 (defun gnus-article-hide (&optional arg force)
4676 "Hide all the gruft in the current article.
4677 This means that PGP stuff, signatures, cited text and (some)
4678 headers will be hidden.
4679 If given a prefix, show the hidden text instead."
4680 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4681 (gnus-article-hide-headers arg)
4682 (gnus-article-hide-list-identifiers arg)
4683 (gnus-article-hide-pgp arg)
4684 (gnus-article-hide-citation-maybe arg force)
4685 (gnus-article-hide-signature arg))
4687 (defun gnus-article-maybe-highlight ()
4688 "Do some article highlighting if article highlighting is requested."
4689 (when (gnus-visual-p 'article-highlight 'highlight)
4690 (gnus-article-highlight-some)))
4692 (defun gnus-check-group-server ()
4693 ;; Make sure the connection to the server is alive.
4694 (unless (gnus-server-opened
4695 (gnus-find-method-for-group gnus-newsgroup-name))
4696 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4697 (gnus-request-group gnus-newsgroup-name t)))
4699 (defun gnus-request-article-this-buffer (article group)
4700 "Get an article and insert it into this buffer."
4701 (let (do-update-line sparse-header)
4705 (gnus-kill-all-overlays)
4706 (setq group (or group gnus-newsgroup-name))
4708 ;; Using `gnus-request-article' directly will insert the article into
4709 ;; `nntp-server-buffer' - so we'll save some time by not having to
4710 ;; copy it from the server buffer into the article buffer.
4712 ;; We only request an article by message-id when we do not have the
4713 ;; headers for it, so we'll have to get those.
4714 (when (stringp article)
4715 (gnus-read-header article))
4717 ;; If the article number is negative, that means that this article
4718 ;; doesn't belong in this newsgroup (possibly), so we find its
4719 ;; message-id and request it by id instead of number.
4720 (when (and (numberp article)
4722 (get-buffer gnus-summary-buffer)
4723 (gnus-buffer-exists-p gnus-summary-buffer))
4725 (set-buffer gnus-summary-buffer)
4726 (let ((header (gnus-summary-article-header article)))
4729 ((memq article gnus-newsgroup-sparse)
4730 ;; This is a sparse gap article.
4731 (setq do-update-line article)
4732 (setq article (mail-header-id header))
4733 (setq sparse-header (gnus-read-header article))
4734 (setq gnus-newsgroup-sparse
4735 (delq article gnus-newsgroup-sparse)))
4737 ;; It's a real article.
4738 (setq article (mail-header-id header)))
4740 ;; It is an extracted pseudo-article.
4741 (setq article 'pseudo)
4742 (gnus-request-pseudo-article header))))
4744 (let ((method (gnus-find-method-for-group
4745 gnus-newsgroup-name)))
4746 (when (and (eq (car method) 'nneething)
4748 (let ((dir (expand-file-name
4749 (mail-header-subject header)
4750 (file-name-as-directory
4751 (or (cadr (assq 'nneething-address method))
4753 (when (file-directory-p dir)
4754 (setq article 'nneething)
4755 (gnus-group-enter-directory dir))))))))
4758 ;; Refuse to select canceled articles.
4759 ((and (numberp article)
4761 (get-buffer gnus-summary-buffer)
4762 (gnus-buffer-exists-p gnus-summary-buffer)
4763 (eq (cdr (save-excursion
4764 (set-buffer gnus-summary-buffer)
4765 (assq article gnus-newsgroup-reads)))
4766 gnus-canceled-mark))
4768 ;; Check the backlog.
4769 ((and gnus-keep-backlog
4770 (gnus-backlog-request-article group article (current-buffer)))
4772 ;; Check asynchronous pre-fetch.
4773 ((gnus-async-request-fetched-article group article (current-buffer))
4774 (gnus-async-prefetch-next group article gnus-summary-buffer)
4775 (when (and (numberp article) gnus-keep-backlog)
4776 (gnus-backlog-enter-article group article (current-buffer)))
4779 ((and gnus-use-cache
4781 (gnus-cache-request-article article group))
4783 ;; Get the article and put into the article buffer.
4784 ((or (stringp article)
4786 (let ((gnus-override-method gnus-override-method)
4787 (methods (and (stringp article)
4788 gnus-refer-article-method))
4790 (buffer-read-only nil))
4791 (if (or (not (listp methods))
4792 (and (symbolp (car methods))
4793 (assq (car methods) nnoo-definition-alist)))
4794 (setq methods (list methods)))
4795 (when (and (null gnus-override-method)
4797 (setq gnus-override-method (pop methods)))
4799 (when (eq gnus-override-method 'current)
4800 (setq gnus-override-method gnus-current-select-method))
4802 (gnus-kill-all-overlays)
4803 (let ((gnus-newsgroup-name group))
4804 (gnus-check-group-server))
4805 (when (gnus-request-article article group (current-buffer))
4806 (when (numberp article)
4807 (gnus-async-prefetch-next group article
4808 gnus-summary-buffer)
4809 (when gnus-keep-backlog
4810 (gnus-backlog-enter-article
4811 group article (current-buffer))))
4812 (setq result 'article))
4815 (setq gnus-override-method (pop methods))
4816 (setq result 'done))))
4817 (and (eq result 'article) 'article)))
4821 ;; Associate this article with the current summary buffer.
4822 (setq gnus-article-current-summary gnus-summary-buffer)
4824 ;; Take the article from the original article buffer
4825 ;; and place it in the buffer it's supposed to be in.
4826 (when (and (get-buffer gnus-article-buffer)
4827 (equal (buffer-name (current-buffer))
4828 (buffer-name (get-buffer gnus-article-buffer))))
4830 (if (get-buffer gnus-original-article-buffer)
4831 (set-buffer gnus-original-article-buffer)
4832 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4833 (set-buffer-multibyte nil)
4834 (buffer-disable-undo)
4835 (setq major-mode 'gnus-original-article-mode)
4836 (setq buffer-read-only t))
4837 (let (buffer-read-only)
4839 (insert-buffer-substring gnus-article-buffer))
4840 (setq gnus-original-article (cons group article)))
4843 (run-hooks 'gnus-article-decode-hook)
4844 ;; Mark article as decoded or not.
4845 (setq gnus-article-decoded-p gnus-article-decode-hook))
4847 ;; Update sparse articles.
4848 (when (and do-update-line
4849 (or (numberp article)
4851 (let ((buf (current-buffer)))
4852 (set-buffer gnus-summary-buffer)
4853 (gnus-summary-update-article do-update-line sparse-header)
4854 (gnus-summary-goto-subject do-update-line nil t)
4855 (set-window-point (get-buffer-window (current-buffer) t)
4857 (set-buffer buf))))))
4863 (defcustom gnus-article-edit-mode-hook nil
4864 "Hook run in article edit mode buffers."
4865 :group 'gnus-article-various
4868 (defcustom gnus-article-edit-article-setup-function
4869 'gnus-article-mime-edit-article-setup
4870 "Function called to setup an editing article buffer."
4871 :group 'gnus-article-various
4874 (defvar gnus-article-edit-done-function nil)
4876 (defvar gnus-article-edit-mode-map nil)
4878 ;; Should we be using derived.el for this?
4879 (unless gnus-article-edit-mode-map
4880 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4881 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4883 (gnus-define-keys gnus-article-edit-mode-map
4884 "\C-c\C-c" gnus-article-edit-done
4885 "\C-c\C-k" gnus-article-edit-exit)
4887 (gnus-define-keys (gnus-article-edit-wash-map
4888 "\C-c\C-w" gnus-article-edit-mode-map)
4889 "f" gnus-article-edit-full-stops))
4891 (defun gnus-article-edit-mode ()
4892 "Major mode for editing articles.
4893 This is an extended text-mode.
4895 \\{gnus-article-edit-mode-map}"
4897 (setq major-mode 'gnus-article-edit-mode)
4898 (setq mode-name "Article Edit")
4899 (use-local-map gnus-article-edit-mode-map)
4900 (make-local-variable 'gnus-article-edit-done-function)
4901 (make-local-variable 'gnus-prev-winconf)
4902 (setq buffer-read-only nil)
4903 (buffer-enable-undo)
4905 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4907 (defun gnus-article-edit (&optional force)
4908 "Edit the current article.
4909 This will have permanent effect only in mail groups.
4910 If FORCE is non-nil, allow editing of articles even in read-only
4913 (when (and (not force)
4914 (gnus-group-read-only-p))
4915 (error "The current newsgroup does not support article editing"))
4916 (gnus-article-date-original)
4917 (gnus-article-edit-article
4919 `(lambda (no-highlight)
4921 (gnus-summary-edit-article-done
4922 ,(or (mail-header-references gnus-current-headers) "")
4923 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4925 (defun gnus-article-edit-article (start-func exit-func)
4926 "Start editing the contents of the current article buffer."
4927 (let ((winconf (current-window-configuration)))
4928 (set-buffer gnus-article-buffer)
4929 (gnus-article-edit-mode)
4930 (funcall start-func)
4931 (gnus-configure-windows 'edit-article)
4932 (setq gnus-article-edit-done-function exit-func)
4933 (setq gnus-prev-winconf winconf)
4934 (when gnus-article-edit-article-setup-function
4935 (funcall gnus-article-edit-article-setup-function))
4936 (gnus-message 6 "C-c C-c to end edits")))
4938 (defun gnus-article-edit-done (&optional arg)
4939 "Update the article edits and exit."
4941 (let ((func gnus-article-edit-done-function)
4942 (buf (current-buffer))
4943 (start (window-start)))
4944 (remove-hook 'gnus-article-mode-hook
4945 'gnus-article-mime-edit-article-unwind)
4946 (gnus-article-edit-exit)
4949 (let ((buffer-read-only nil))
4951 ;; The cache and backlog have to be flushed somewhat.
4952 (when gnus-keep-backlog
4953 (gnus-backlog-remove-article
4954 (car gnus-article-current) (cdr gnus-article-current)))
4955 ;; Flush original article as well.
4957 (when (get-buffer gnus-original-article-buffer)
4958 (set-buffer gnus-original-article-buffer)
4959 (setq gnus-original-article nil)))
4960 (when gnus-use-cache
4961 (gnus-cache-update-article
4962 (car gnus-article-current) (cdr gnus-article-current))))
4964 (set-window-start (get-buffer-window buf) start)
4965 (set-window-point (get-buffer-window buf) (point))))
4967 (defun gnus-article-edit-exit ()
4968 "Exit the article editing without updating."
4970 ;; We remove all text props from the article buffer.
4971 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4972 (curbuf (current-buffer))
4974 (window-start (window-start)))
4977 (let ((winconf gnus-prev-winconf))
4979 (set-window-configuration winconf)
4980 ;; Tippy-toe some to make sure that point remains where it was.
4981 (save-current-buffer
4983 (set-window-start (get-buffer-window (current-buffer)) window-start)
4986 (defun gnus-article-edit-full-stops ()
4987 "Interactively repair spacing at end of sentences."
4990 (goto-char (point-min))
4991 (search-forward-regexp "^$" nil t)
4992 (let ((case-fold-search nil))
4993 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4996 ;;; Article editing with MIME-Edit
4999 (defcustom gnus-article-mime-edit-article-setup-hook nil
5000 "Hook run after setting up a MIME editing article buffer."
5001 :group 'gnus-article-various
5004 (defun gnus-article-mime-edit-article-unwind ()
5005 "Unwind `gnus-article-buffer' if article editing was given up."
5006 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5007 (when mime-edit-mode-flag
5008 (mime-edit-exit 'nomime 'no-error)
5010 (when (featurep 'font-lock)
5011 (setq font-lock-defaults nil)
5012 (font-lock-mode 0)))
5014 (defun gnus-article-mime-edit-article-setup ()
5015 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
5016 after replacing with the original article."
5017 (setq gnus-show-mime t)
5018 (setq gnus-article-edit-done-function
5019 `(lambda (&rest args)
5020 (when mime-edit-mode-flag
5023 (goto-char (point-min))
5024 (let (case-fold-search)
5025 (when (re-search-forward
5026 (format "^%s$" (regexp-quote mail-header-separator))
5028 (replace-match "")))
5029 (when (featurep 'font-lock)
5030 (setq font-lock-defaults nil)
5032 (apply ,gnus-article-edit-done-function args)
5033 (set-buffer gnus-original-article-buffer)
5035 (insert-buffer gnus-article-buffer)
5036 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5037 (gnus-article-prepare-display)))
5038 (substitute-key-definition
5039 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
5040 gnus-article-edit-mode-map)
5042 (insert-buffer gnus-original-article-buffer)
5044 (when (featurep 'font-lock)
5045 (set (make-local-variable 'font-lock-defaults)
5046 '(message-font-lock-keywords t))
5047 (font-lock-set-defaults)
5048 (turn-on-font-lock))
5049 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
5050 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
5052 (defun gnus-article-mime-edit-exit ()
5053 "Exit the article MIME editing without updating."
5055 (let ((winconf gnus-prev-winconf)
5057 (when mime-edit-mode-flag
5060 (goto-char (point-min))
5061 (let (case-fold-search)
5062 (when (re-search-forward
5063 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
5064 (replace-match "")))
5065 (when (featurep 'font-lock)
5066 (setq font-lock-defaults nil)
5068 ;; We remove all text props from the article buffer.
5069 (setq buf (buffer-substring-no-properties (point-min) (point-max)))
5070 (set-buffer (get-buffer-create gnus-original-article-buffer))
5073 (setq gnus-current-headers (gnus-article-make-full-mail-header))
5074 (gnus-article-prepare-display)
5075 (set-window-configuration winconf)))
5078 ;;; Article highlights
5081 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5083 ;;; Internal Variables:
5085 (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\\)\\)"
5086 "Regular expression that matches URLs."
5087 :group 'gnus-article-buttons
5090 (defcustom gnus-button-alist
5091 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
5092 0 t gnus-button-message-id 2)
5093 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
5094 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
5096 gnus-button-fetch-group 4)
5097 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
5098 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
5099 t gnus-button-message-id 3)
5100 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
5101 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
5102 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
5103 ;; This is how URLs _should_ be embedded in text...
5104 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
5106 (,gnus-button-url-regexp 0 t browse-url 0))
5107 "*Alist of regexps matching buttons in article bodies.
5109 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
5110 REGEXP: is the string matching text around the button,
5111 BUTTON: is the number of the regexp grouping actually matching the button,
5112 FORM: is a lisp expression which must eval to true for the button to
5114 CALLBACK: is the function to call when the user push this button, and each
5115 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
5117 CALLBACK can also be a variable, in that case the value of that
5118 variable it the real callback function."
5119 :group 'gnus-article-buttons
5120 :type '(repeat (list regexp
5121 (integer :tag "Button")
5123 (function :tag "Callback")
5126 (integer :tag "Regexp group")))))
5128 (defcustom gnus-header-button-alist
5129 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
5130 0 t gnus-button-message-id 0)
5131 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
5132 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
5133 0 t gnus-button-mailto 0)
5134 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
5135 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
5136 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
5137 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
5138 gnus-button-message-id 3))
5139 "*Alist of headers and regexps to match buttons in article heads.
5141 This alist is very similar to `gnus-button-alist', except that each
5142 alist has an additional HEADER element first in each entry:
5144 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
5146 HEADER is a regexp to match a header. For a fuller explanation, see
5147 `gnus-button-alist'."
5148 :group 'gnus-article-buttons
5149 :group 'gnus-article-headers
5150 :type '(repeat (list (regexp :tag "Header")
5152 (integer :tag "Button")
5154 (function :tag "Callback")
5157 (integer :tag "Regexp group")))))
5159 (defvar gnus-button-regexp nil)
5160 (defvar gnus-button-marker-list nil)
5161 ;; Regexp matching any of the regexps from `gnus-button-alist'.
5163 (defvar gnus-button-last nil)
5164 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
5168 (defun gnus-article-push-button (event)
5169 "Check text under the mouse pointer for a callback function.
5170 If the text under the mouse pointer has a `gnus-callback' property,
5171 call it with the value of the `gnus-data' text property."
5173 (set-buffer (window-buffer (posn-window (event-start event))))
5174 (let* ((pos (posn-point (event-start event)))
5175 (data (get-text-property pos 'gnus-data))
5176 (fun (get-text-property pos 'gnus-callback)))
5179 (funcall fun data))))
5181 (defun gnus-article-press-button ()
5182 "Check text at point for a callback function.
5183 If the text at point has a `gnus-callback' property,
5184 call it with the value of the `gnus-data' text property."
5186 (let* ((data (get-text-property (point) 'gnus-data))
5187 (fun (get-text-property (point) 'gnus-callback)))
5189 (funcall fun data))))
5191 (defun gnus-article-prev-button (n)
5192 "Move point to N buttons backward.
5193 If N is negative, move forward instead."
5195 (gnus-article-next-button (- n)))
5197 (defun gnus-article-next-button (n)
5198 "Move point to N buttons forward.
5199 If N is negative, move backward instead."
5201 (let ((function (if (< n 0) 'previous-single-property-change
5202 'next-single-property-change))
5203 (inhibit-point-motion-hooks t)
5205 (limit (if (< n 0) (point-min) (point-max))))
5207 (while (and (not (= limit (point)))
5209 ;; Skip past the current button.
5210 (when (get-text-property (point) 'gnus-callback)
5211 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5212 ;; Go to the next (or previous) button.
5213 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5214 ;; Put point at the start of the button.
5215 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5216 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5217 ;; Skip past intangible buttons.
5218 (when (get-text-property (point) 'intangible)
5222 (gnus-message 5 "No more buttons"))
5225 (defun gnus-article-highlight (&optional force)
5226 "Highlight current article.
5227 This function calls `gnus-article-highlight-headers',
5228 `gnus-article-highlight-citation',
5229 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5230 do the highlighting. See the documentation for those functions."
5231 (interactive (list 'force))
5232 (gnus-article-highlight-headers)
5233 (gnus-article-highlight-citation force)
5234 (gnus-article-highlight-signature)
5235 (gnus-article-add-buttons force)
5236 (gnus-article-add-buttons-to-head))
5238 (defun gnus-article-highlight-some (&optional force)
5239 "Highlight current article.
5240 This function calls `gnus-article-highlight-headers',
5241 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5242 do the highlighting. See the documentation for those functions."
5243 (interactive (list 'force))
5244 (gnus-article-highlight-headers)
5245 (gnus-article-highlight-signature)
5246 (gnus-article-add-buttons))
5248 (defun gnus-article-highlight-headers ()
5249 "Highlight article headers as specified by `gnus-header-face-alist'."
5252 (set-buffer gnus-article-buffer)
5254 (let ((alist gnus-header-face-alist)
5255 (buffer-read-only nil)
5256 (case-fold-search t)
5257 (inhibit-point-motion-hooks t)
5258 entry regexp header-face field-face from hpoints fpoints)
5259 (article-narrow-to-head)
5260 (while (setq entry (pop alist))
5261 (goto-char (point-min))
5262 (setq regexp (concat "^\\("
5263 (if (string-equal "" (nth 0 entry))
5267 header-face (nth 1 entry)
5268 field-face (nth 2 entry))
5269 (while (and (re-search-forward regexp nil t)
5273 (unless (search-forward ":" nil t)
5275 (when (and header-face
5276 (not (memq (point) hpoints)))
5277 (push (point) hpoints)
5278 (gnus-put-text-property from (point) 'face header-face))
5279 (when (and field-face
5280 (not (memq (setq from (point)) fpoints)))
5282 (if (re-search-forward "^[^ \t]" nil t)
5284 (goto-char (point-max)))
5285 (gnus-put-text-property from (point) 'face field-face))))))))
5287 (defun gnus-article-highlight-signature ()
5288 "Highlight the signature in an article.
5289 It does this by highlighting everything after
5290 `gnus-signature-separator' using `gnus-signature-face'."
5292 (when gnus-signature-face
5294 (set-buffer gnus-article-buffer)
5295 (let ((buffer-read-only nil)
5296 (inhibit-point-motion-hooks t))
5298 (when (gnus-article-narrow-to-signature)
5299 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5300 'face gnus-signature-face)))))))
5302 (defun gnus-article-buttonize-signature ()
5303 "Add button to the signature."
5306 (set-buffer gnus-article-buffer)
5307 (let ((buffer-read-only nil)
5308 (inhibit-point-motion-hooks t))
5309 (when (gnus-article-search-signature)
5310 (gnus-article-add-button (match-beginning 0) (match-end 0)
5311 'gnus-signature-toggle
5312 (set-marker (make-marker)
5313 (1+ (match-end 0))))))))
5315 (defun gnus-button-in-region-p (b e prop)
5316 "Say whether PROP exists in the region."
5317 (text-property-not-all b e prop nil))
5319 (defun gnus-article-add-buttons (&optional force)
5320 "Find external references in the article and make buttons of them.
5321 \"External references\" are things like Message-IDs and URLs, as
5322 specified by `gnus-button-alist'."
5323 (interactive (list 'force))
5325 (set-buffer gnus-article-buffer)
5326 (let ((buffer-read-only nil)
5327 (inhibit-point-motion-hooks t)
5328 (case-fold-search t)
5329 (alist gnus-button-alist)
5331 ;; Remove all old markers.
5332 (let (marker entry new-list)
5333 (while (setq marker (pop gnus-button-marker-list))
5334 (if (or (< marker (point-min)) (>= marker (point-max)))
5335 (push marker new-list)
5337 (when (setq entry (gnus-button-entry))
5338 (put-text-property (match-beginning (nth 1 entry))
5339 (match-end (nth 1 entry))
5340 'gnus-callback nil))
5341 (set-marker marker nil)))
5342 (setq gnus-button-marker-list new-list))
5343 ;; We skip the headers.
5346 (while (setq entry (pop alist))
5347 (setq regexp (car entry))
5349 (while (re-search-forward regexp nil t)
5350 (let* ((start (and entry (match-beginning (nth 1 entry))))
5351 (end (and entry (match-end (nth 1 entry))))
5352 (from (match-beginning 0)))
5353 (when (and (or (eq t (nth 2 entry))
5354 (eval (nth 2 entry)))
5355 (not (gnus-button-in-region-p
5356 start end 'gnus-callback)))
5357 ;; That optional form returned non-nil, so we add the
5359 (gnus-article-add-button
5360 start end 'gnus-button-push
5361 (car (push (set-marker (make-marker) from)
5362 gnus-button-marker-list))))))))))
5364 ;; Add buttons to the head of an article.
5365 (defun gnus-article-add-buttons-to-head ()
5366 "Add buttons to the head of the article."
5369 (set-buffer gnus-article-buffer)
5371 (let ((buffer-read-only nil)
5372 (inhibit-point-motion-hooks t)
5373 (case-fold-search t)
5374 (alist gnus-header-button-alist)
5376 (article-narrow-to-head)
5378 ;; Each alist entry.
5379 (setq entry (car alist)
5381 (goto-char (point-min))
5382 (while (re-search-forward (car entry) nil t)
5383 ;; Each header matching the entry.
5384 (setq beg (match-beginning 0))
5385 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5386 (match-beginning 0))
5389 (while (re-search-forward (nth 1 entry) end t)
5390 ;; Each match within a header.
5391 (let* ((entry (cdr entry))
5392 (start (match-beginning (nth 1 entry)))
5393 (end (match-end (nth 1 entry)))
5394 (form (nth 2 entry)))
5395 (goto-char (match-end 0))
5397 (gnus-article-add-button
5398 start end (nth 3 entry)
5399 (buffer-substring (match-beginning (nth 4 entry))
5400 (match-end (nth 4 entry)))))))
5401 (goto-char end)))))))
5403 ;;; External functions:
5405 (defun gnus-article-add-button (from to fun &optional data)
5406 "Create a button between FROM and TO with callback FUN and data DATA."
5407 (when gnus-article-button-face
5408 (gnus-overlay-put (gnus-make-overlay from to)
5409 'face gnus-article-button-face))
5410 (gnus-add-text-properties
5412 (nconc (and gnus-article-mouse-face
5413 (list gnus-mouse-face-prop gnus-article-mouse-face))
5414 (list 'gnus-callback fun)
5415 (and data (list 'gnus-data data))))
5416 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5417 ;; Quote `:button-keymap' for Mule 2.3
5418 ;; but it won't work.
5419 ':button-keymap gnus-widget-button-keymap))
5421 ;;; Internal functions:
5423 (defun gnus-article-set-globals ()
5425 (set-buffer gnus-summary-buffer)
5426 (gnus-set-global-variables)))
5428 (defun gnus-signature-toggle (end)
5430 (set-buffer gnus-article-buffer)
5431 (let ((buffer-read-only nil)
5432 (inhibit-point-motion-hooks t)
5433 (limit (next-single-property-change end 'mime-view-entity
5435 (if (text-property-any end limit 'article-type 'signature)
5436 (gnus-remove-text-properties-when
5437 'article-type 'signature end limit
5438 (cons 'article-type (cons 'signature
5439 gnus-hidden-properties)))
5440 (gnus-add-text-properties-when
5441 'article-type nil end limit
5442 (cons 'article-type (cons 'signature
5443 gnus-hidden-properties)))))))
5445 (defun gnus-button-entry ()
5446 ;; Return the first entry in `gnus-button-alist' matching this place.
5447 (let ((alist gnus-button-alist)
5450 (setq entry (pop alist))
5451 (if (looking-at (car entry))
5456 (defun gnus-button-push (marker)
5457 ;; Push button starting at MARKER.
5460 (let* ((entry (gnus-button-entry))
5461 (inhibit-point-motion-hooks t)
5463 (args (mapcar (lambda (group)
5464 (let ((string (match-string group)))
5465 (gnus-set-text-properties
5466 0 (length string) nil string)
5473 (fboundp (symbol-value fun)))
5474 (apply (symbol-value fun) args))
5476 (gnus-message 1 "You must define `%S' to use this button"
5477 (cons fun args)))))))
5479 (defun gnus-button-message-id (message-id)
5482 (set-buffer gnus-summary-buffer)
5483 (gnus-summary-refer-article message-id)))
5485 (defun gnus-button-fetch-group (address)
5486 "Fetch GROUP specified by ADDRESS."
5487 (if (not (string-match "[:/]" address))
5488 ;; This is just a simple group url.
5489 (gnus-group-read-ephemeral-group address gnus-select-method)
5490 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5492 (error "Can't parse %s" address)
5493 (gnus-group-read-ephemeral-group
5494 (match-string 4 address)
5495 `(nntp ,(match-string 1 address)
5496 (nntp-address ,(match-string 1 address))
5497 (nntp-port-number ,(if (match-end 3)
5498 (match-string 3 address)
5501 (defun gnus-url-parse-query-string (query &optional downcase)
5502 (let (retval pairs cur key val)
5503 (setq pairs (split-string query "&"))
5505 (setq cur (car pairs)
5507 (if (not (string-match "=" cur))
5509 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5510 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5512 (setq key (downcase key)))
5513 (setq cur (assoc key retval))
5515 (setcdr cur (cons val (cdr cur)))
5516 (setq retval (cons (list key val) retval)))))
5519 (defun gnus-url-unhex (x)
5526 (defun gnus-url-unhex-string (str &optional allow-newlines)
5527 "Remove %XXX embedded spaces, etc in a url.
5528 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5529 decoding of carriage returns and line feeds in the string, which is normally
5530 forbidden in URL encoding."
5531 (setq str (or str ""))
5533 (case-fold-search t))
5534 (while (string-match "%[0-9a-f][0-9a-f]" str)
5535 (let* ((start (match-beginning 0))
5536 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5538 (gnus-url-unhex (elt str (+ start 2))))))
5540 tmp (substring str 0 start)
5543 (char-to-string code))
5544 ((or (= code ?\n) (= code ?\r))
5546 (t (char-to-string code))))
5547 str (substring str (match-end 0)))))
5548 (setq tmp (concat tmp str))
5551 (defun gnus-url-mailto (url)
5552 ;; Send mail to someone
5553 (when (string-match "mailto:/*\\(.*\\)" url)
5554 (setq url (substring url (match-beginning 1) nil)))
5555 (let (to args subject func)
5556 (if (string-match (regexp-quote "?") url)
5557 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5558 args (gnus-url-parse-query-string
5559 (substring url (match-end 0) nil) t))
5560 (setq to (gnus-url-unhex-string url)))
5561 (setq args (cons (list "to" to) args)
5562 subject (cdr-safe (assoc "subject" args)))
5565 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5568 (message-position-on-field (caar args)))
5569 (insert (mapconcat 'identity (cdar args) ", "))
5570 (setq args (cdr args)))
5573 (message-goto-subject))))
5575 (defun gnus-button-embedded-url (address)
5576 "Activate ADDRESS with `browse-url'."
5577 (browse-url (gnus-strip-whitespace address)))
5580 ;; Silence the byte-compiler.
5581 (autoload 'smiley-toggle-buffer "gnus-bitmap"))
5582 (defun gnus-article-smiley-display ()
5583 "Display \"smileys\" as small graphical icons."
5584 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5586 ;;; Next/prev buttons in the article buffer.
5588 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5589 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5591 (defvar gnus-prev-page-map nil)
5592 (unless gnus-prev-page-map
5593 (setq gnus-prev-page-map (make-sparse-keymap))
5594 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5595 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5597 (static-if (featurep 'xemacs)
5598 (defun gnus-insert-prev-page-button ()
5599 (let ((buffer-read-only nil))
5601 gnus-prev-page-line-format nil
5602 `(gnus-prev t local-map ,gnus-prev-page-map
5603 gnus-callback gnus-article-button-prev-page
5604 article-type annotation))))
5605 (defun gnus-insert-prev-page-button ()
5606 (let ((buffer-read-only nil)
5607 (situation (get-text-property (point-min) 'mime-view-situation)))
5608 (set-keymap-parent gnus-prev-page-map (current-local-map))
5610 gnus-prev-page-line-format nil
5611 `(gnus-prev t local-map ,gnus-prev-page-map
5612 gnus-callback gnus-article-button-prev-page
5613 article-type annotation
5614 mime-view-situation ,situation))))
5617 (defvar gnus-next-page-map nil)
5618 (unless gnus-next-page-map
5619 (setq gnus-next-page-map (make-sparse-keymap))
5620 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5621 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5623 (defun gnus-button-next-page ()
5624 "Go to the next page."
5626 (let ((win (selected-window)))
5627 (select-window (get-buffer-window gnus-article-buffer t))
5628 (gnus-article-next-page)
5629 (select-window win)))
5631 (defun gnus-button-prev-page ()
5632 "Go to the prev page."
5634 (let ((win (selected-window)))
5635 (select-window (get-buffer-window gnus-article-buffer t))
5636 (gnus-article-prev-page)
5637 (select-window win)))
5639 (static-if (featurep 'xemacs)
5640 (defun gnus-insert-next-page-button ()
5641 (let ((buffer-read-only nil))
5642 (gnus-eval-format gnus-next-page-line-format nil
5644 t local-map ,gnus-next-page-map
5645 gnus-callback gnus-article-button-next-page
5646 article-type annotation))))
5647 (defun gnus-insert-next-page-button ()
5648 (let ((buffer-read-only nil)
5649 (situation (get-text-property (point-min) 'mime-view-situation)))
5650 (set-keymap-parent gnus-next-page-map (current-local-map))
5651 (gnus-eval-format gnus-next-page-line-format nil
5653 t local-map ,gnus-next-page-map
5654 gnus-callback gnus-article-button-next-page
5655 article-type annotation
5656 mime-view-situation ,situation))))
5659 (defun gnus-article-button-next-page (arg)
5660 "Go to the next page."
5662 (let ((win (selected-window)))
5663 (select-window (get-buffer-window gnus-article-buffer t))
5664 (gnus-article-next-page)
5665 (select-window win)))
5667 (defun gnus-article-button-prev-page (arg)
5668 "Go to the prev page."
5670 (let ((win (selected-window)))
5671 (select-window (get-buffer-window gnus-article-buffer t))
5672 (gnus-article-prev-page)
5673 (select-window win)))
5675 (defvar gnus-decode-header-methods
5676 '(mail-decode-encoded-word-region)
5677 "List of methods used to decode headers.
5679 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5680 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5681 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5682 whose names match REGEXP.
5685 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5686 mail-decode-encoded-word-region
5687 (\"chinese\" . rfc1843-decode-region))
5690 (defvar gnus-decode-header-methods-cache nil)
5692 (defun gnus-multi-decode-header (start end)
5693 "Apply the functions from `gnus-encoded-word-methods' that match."
5694 (unless (and gnus-decode-header-methods-cache
5695 (eq gnus-newsgroup-name
5696 (car gnus-decode-header-methods-cache)))
5697 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5700 (nconc gnus-decode-header-methods-cache (list x))
5701 (if (and gnus-newsgroup-name
5702 (string-match (car x) gnus-newsgroup-name))
5703 (nconc gnus-decode-header-methods-cache
5705 gnus-decode-header-methods))
5706 (let ((xlist gnus-decode-header-methods-cache))
5709 (narrow-to-region start end)
5711 (funcall (pop xlist) (point-min) (point-max))))))
5714 ;;; Treatment top-level handling.
5717 (defun gnus-treat-article (condition &optional part-number total-parts type)
5718 (let ((length (- (point-max) (point-min)))
5719 (alist gnus-treatment-function-alist)
5720 (article-goto-body-goes-to-point-min-p t)
5724 (let ((list gnus-article-treat-types))
5726 (when (string-match (pop list) type)
5727 (throw 'found t)))))))
5728 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5729 (entity (static-unless (featurep 'xemacs)
5730 (when (eq 'head condition)
5731 (get-text-property (point-min) 'mime-view-entity))))
5732 val elem buttonized)
5733 (gnus-run-hooks 'gnus-part-display-hook)
5734 (unless gnus-inhibit-treatment
5735 (while (setq elem (pop alist))
5738 (if (gnus-buffer-live-p gnus-summary-buffer)
5739 (set-buffer gnus-summary-buffer))
5740 (symbol-value (car elem))))
5741 (when (and (or (consp val)
5743 (gnus-treat-predicate val)
5744 (or (not (get (car elem) 'highlight))
5746 (when (and (not buttonized)
5748 '(gnus-treat-hide-signature
5749 gnus-treat-highlight-signature)))
5750 (gnus-article-buttonize-signature)
5751 (setq buttonized t))
5753 (funcall (cadr elem)))))
5754 ;; FSF Emacsen does not inherit the existing text properties
5755 ;; in the new text, so we should do it for `mime-view-entity'.
5756 (static-unless (featurep 'xemacs)
5758 (put-text-property (point-min) (point-max)
5759 'mime-view-entity entity))))))
5761 ;; Dynamic variables.
5763 (defvar part-number)
5764 (defvar total-parts)
5769 (defun gnus-treat-predicate (val)
5774 (stringp (car val)))
5775 (apply 'gnus-or (mapcar `(lambda (s)
5776 (string-match s ,(or gnus-newsgroup-name "")))
5779 (let ((pred (pop val)))
5782 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5784 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5786 (not (gnus-treat-predicate (car val))))
5788 (equal (car val) type))
5790 (error "%S is not a valid predicate" pred)))))
5800 (eq part-number total-parts))
5804 (error "%S is not a valid value" val))))
5806 (defun gnus-article-encrypt-body (protocol &optional n)
5807 "Encrypt the article body."
5810 (or gnus-article-encrypt-protocol
5811 (completing-read "Encrypt protocol: "
5812 gnus-article-encrypt-protocol-alist
5814 current-prefix-arg))
5815 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5817 (error (format "Can't find the encrypt protocol %s" protocol)))
5818 (if (equal gnus-newsgroup-name "nndraft:drafts")
5819 (error "Can't encrypt the article in group nndraft:drafts."))
5820 (if (equal gnus-newsgroup-name "nndraft:queue")
5821 (error "Don't encrypt the article in group nndraft:queue."))
5822 (gnus-summary-iterate n
5824 (set-buffer gnus-summary-buffer)
5825 (let ((mail-parse-charset gnus-newsgroup-charset)
5826 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5827 (summary-buffer gnus-summary-buffer)
5829 (gnus-set-global-variables)
5830 (when (gnus-group-read-only-p)
5831 (error "The current newsgroup does not support article encrypt"))
5832 (gnus-summary-show-article t)
5834 (or (mail-header-references gnus-current-headers) ""))
5835 (set-buffer gnus-article-buffer)
5836 (let* ((buffer-read-only nil)
5838 (mapcar (lambda (field)
5839 (and (save-restriction
5840 (message-narrow-to-head)
5841 (goto-char (point-min))
5842 (search-forward field nil t))
5844 (message-narrow-to-field)
5845 (buffer-substring (point-min) (point-max))
5846 (delete-region (point-min) (point-max))
5848 '("Content-Type:" "Content-Transfer-Encoding:"
5849 "Content-Disposition:"))))
5850 (message-narrow-to-head)
5851 (message-remove-header "MIME-Version")
5852 (goto-char (point-max))
5853 (setq point (point))
5854 (insert (apply 'concat headers))
5856 (narrow-to-region point (point-max))
5857 (let ((message-options message-options))
5858 (message-options-set 'message-sender user-mail-address)
5859 (message-options-set 'message-recipients user-mail-address)
5860 (message-options-set 'message-sign-encrypt 'not)
5862 (goto-char (point-min))
5863 (insert "MIME-Version: 1.0\n")
5865 (gnus-summary-edit-article-done
5866 references nil summary-buffer t))
5867 (when gnus-keep-backlog
5868 (gnus-backlog-remove-article
5869 (car gnus-article-current) (cdr gnus-article-current)))
5871 (when (get-buffer gnus-original-article-buffer)
5872 (set-buffer gnus-original-article-buffer)
5873 (setq gnus-original-article nil)))
5874 (when gnus-use-cache
5875 (gnus-cache-update-article
5876 (car gnus-article-current) (cdr gnus-article-current))))))))
5878 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5879 "The following specs can be used:
5880 %t The security MIME type
5883 %D Details if button is pressed")
5885 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5886 "The following specs can be used:
5887 %t The security MIME type
5890 %D Details if button is pressed")
5892 (defvar gnus-mime-security-button-line-format-alist
5893 '((?t gnus-tmp-type ?s)
5894 (?i gnus-tmp-info ?s)
5895 (?d gnus-tmp-details ?s)
5896 (?D gnus-tmp-pressed-details ?s)))
5898 (defvar gnus-mime-security-button-map
5899 (let ((map (make-sparse-keymap)))
5900 (unless (>= (string-to-number emacs-version) 21)
5901 (set-keymap-parent map gnus-article-mode-map))
5902 (define-key map gnus-mouse-2 'gnus-article-push-button)
5903 (define-key map "\r" 'gnus-article-press-button)
5906 (defvar gnus-mime-security-details-buffer nil)
5908 (defvar gnus-mime-security-button-pressed nil)
5910 (defvar gnus-mime-security-show-details-inline t
5911 "If non-nil, show details in the article buffer.")
5913 (defun gnus-mime-security-verify-or-decrypt (handle)
5914 (mm-remove-parts (cdr handle))
5915 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5918 (delete-region (car region) (cdr region))
5919 (set-marker (car region) nil)
5920 (set-marker (cdr region) nil)))
5921 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5922 (let* ((mm-verify-option 'known)
5923 (mm-decrypt-option 'known)
5924 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5925 (unless (eq nparts (cdr handle))
5926 (mm-destroy-parts (cdr handle))
5927 (setcdr handle nparts))))
5928 (let ((point (point))
5930 (gnus-mime-display-security handle)
5933 (defun gnus-mime-security-show-details (handle)
5934 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5936 (if gnus-mime-security-show-details-inline
5937 (let ((gnus-mime-security-button-pressed t)
5938 (gnus-mime-security-button-line-format
5939 (get-text-property (point) 'gnus-line-format))
5942 (while (eq (get-text-property (point) 'gnus-line-format)
5943 gnus-mime-security-button-line-format)
5946 (delete-region (point)
5947 (or (text-property-not-all
5950 gnus-mime-security-button-line-format)
5952 (gnus-insert-mime-security-button handle))
5953 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5954 (with-current-buffer gnus-mime-security-details-buffer
5957 (setq gnus-mime-security-details-buffer
5958 (gnus-get-buffer-create "*MIME Security Details*")))
5959 (with-current-buffer gnus-mime-security-details-buffer
5961 (goto-char (point-min)))
5962 (pop-to-buffer gnus-mime-security-details-buffer))
5963 (gnus-message 5 "No details."))))
5965 (defun gnus-mime-security-press-button (handle)
5966 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5967 (gnus-mime-security-show-details handle)
5968 (gnus-mime-security-verify-or-decrypt handle)))
5970 (defun gnus-insert-mime-security-button (handle &optional displayed)
5971 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5974 (or (nth 2 (assoc protocol mm-verify-function-alist))
5975 (nth 2 (assoc protocol mm-decrypt-function-alist))
5977 (if (equal (car handle) "multipart/signed")
5978 " Signed" " Encrypted")
5981 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5984 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5985 gnus-tmp-pressed-details
5987 (setq gnus-tmp-details
5988 (if gnus-tmp-details
5989 (concat "\n" gnus-tmp-details) ""))
5990 (setq gnus-tmp-pressed-details
5991 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5996 gnus-mime-security-button-line-format
5997 gnus-mime-security-button-line-format-alist
5998 `(keymap ,gnus-mime-security-button-map
5999 ,@(if (>= (string-to-number emacs-version) 21)
6000 nil ;; XEmacs doesn't care
6001 (list 'local-map gnus-mime-security-button-map))
6002 gnus-callback gnus-mime-security-press-button
6003 gnus-line-format ,gnus-mime-security-button-line-format
6004 article-type annotation
6007 (widget-convert-button
6010 :action 'gnus-widget-press-button
6011 :button-keymap gnus-mime-security-button-map
6013 (lambda (widget/window &optional overlay pos)
6014 ;; Needed to properly clear the message due to a bug in
6015 ;; wid-edit (XEmacs only).
6016 (if (boundp 'help-echo-owns-message)
6017 (setq help-echo-owns-message t))
6020 (aref gnus-mouse-2 0))))))
6022 (defun gnus-mime-display-security (handle)
6024 (narrow-to-region (point) (point))
6025 (gnus-insert-mime-security-button handle)
6026 (gnus-mime-display-mixed (cdr handle))
6029 (let ((gnus-mime-security-button-line-format
6030 gnus-mime-security-button-end-line-format))
6031 (gnus-insert-mime-security-button handle))
6032 (mm-set-handle-multipart-parameter
6034 (cons (set-marker (make-marker) (point-min))
6035 (set-marker (make-marker) (point-max))))))
6041 (defun gnus-article-header-presentation-method (entity situation)
6042 (mime-insert-header entity)
6045 (set-alist 'mime-header-presentation-method-alist
6046 'gnus-original-article-mode
6047 #'gnus-article-header-presentation-method)
6049 (defun gnus-mime-preview-quitting-method ()
6050 (mime-preview-kill-buffer)
6051 (delete-other-windows)
6052 (gnus-article-show-summary)
6053 (gnus-summary-select-article gnus-show-all-headers t))
6055 (set-alist 'mime-preview-quitting-method-alist
6056 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
6058 (set-alist 'mime-preview-following-method-alist
6059 'gnus-original-article-mode #'gnus-following-method)
6061 (set-alist 'mime-preview-over-to-previous-method-alist
6062 'gnus-original-article-mode
6064 (if (> (point-min) 1)
6065 (gnus-article-prev-page)
6066 (gnus-article-read-summary-keys
6067 nil (gnus-character-to-event ?P)))))
6069 (set-alist 'mime-preview-over-to-next-method-alist
6070 'gnus-original-article-mode'
6072 (if (< (point-max) (buffer-size))
6073 (gnus-article-next-page)
6074 (gnus-article-read-summary-keys
6075 nil (gnus-character-to-event ?N)))))
6085 (run-hooks 'gnus-art-load-hook)
6087 ;;; gnus-art.el ends here