1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
43 (autoload 'gnus-msg-mail "gnus-msg" nil t)
44 (autoload 'gnus-button-mailto "gnus-msg")
45 (autoload 'gnus-button-reply "gnus-msg" nil t)
47 (defgroup gnus-article nil
49 :link '(custom-manual "(gnus)The Article Buffer")
52 (defgroup gnus-article-treat nil
53 "Treating article parts."
54 :link '(custom-manual "(gnus)Article Hiding")
57 (defgroup gnus-article-hiding nil
58 "Hiding article parts."
59 :link '(custom-manual "(gnus)Article Hiding")
62 (defgroup gnus-article-highlight nil
63 "Article highlighting."
64 :link '(custom-manual "(gnus)Article Highlighting")
68 (defgroup gnus-article-signature nil
70 :link '(custom-manual "(gnus)Article Signature")
73 (defgroup gnus-article-headers nil
75 :link '(custom-manual "(gnus)Hiding Headers")
78 (defgroup gnus-article-washing nil
79 "Special commands on articles."
80 :link '(custom-manual "(gnus)Article Washing")
83 (defgroup gnus-article-emphasis nil
84 "Fontisizing articles."
85 :link '(custom-manual "(gnus)Article Fontisizing")
88 (defgroup gnus-article-saving nil
90 :link '(custom-manual "(gnus)Saving Articles")
93 (defgroup gnus-article-mime nil
94 "Worshiping the MIME wonder."
95 :link '(custom-manual "(gnus)Using MIME")
98 (defgroup gnus-article-buttons nil
99 "Pushable buttons in the article buffer."
100 :link '(custom-manual "(gnus)Article Buttons")
101 :group 'gnus-article)
103 (defgroup gnus-article-various nil
104 "Other article options."
105 :link '(custom-manual "(gnus)Misc Article")
106 :group 'gnus-article)
108 (defcustom gnus-ignored-headers
109 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
110 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
111 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
112 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
113 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
114 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
115 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
116 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
117 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
118 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
119 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
120 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
121 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
122 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
123 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
124 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
125 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
126 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
127 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
128 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
129 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
130 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
131 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
132 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
133 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
134 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
135 "^X-Received:" "^Content-length:" "X-precedence:"
136 "^X-Authenticated-User:" "^X-Comment" "^X-Report:" "^X-Abuse-Info:"
137 "^X-HTTP-Proxy:" "^X-Mydeja-Info:" "^X-Copyright" "^X-No-Markup:"
138 "^X-Abuse-Info:" "^X-From_:" "^X-Accept-Language:" "^Errors-To:"
139 "^X-BeenThere:" "^X-Mailman-Version:" "^List-Help:" "^List-Post:"
140 "^List-Subscribe:" "^List-Id:" "^List-Unsubscribe:" "^List-Archive:"
141 "^X-Content-length:" "^X-Posting-Agent:" "^Original-Received:"
142 "^X-Request-PGP:" "^X-Fingerprint:" "^X-WRIEnvto:" "^X-WRIEnvfrom:"
143 "^X-Virus-Scanned:" "^X-Delivery-Agent:" "^Posted-Date:" "^X-Gateway:"
144 "^X-Local-Origin:" "^X-Local-Destination:")
145 "*All headers that start with this regexp will be hidden.
146 This variable can also be a list of regexps of headers to be ignored.
147 If `gnus-visible-headers' is non-nil, this variable will be ignored."
148 :type '(choice :custom-show nil
151 :group 'gnus-article-hiding)
153 (defcustom gnus-visible-headers
154 "^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:"
155 "*All headers that do not match this regexp will be hidden.
156 This variable can also be a list of regexp of headers to remain visible.
157 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
158 :type '(repeat :value-to-internal (lambda (widget value)
159 (custom-split-regexp-maybe value))
160 :match (lambda (widget value)
162 (widget-editable-list-match widget value)))
164 :group 'gnus-article-hiding)
166 (defcustom gnus-sorted-header-list
167 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
168 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
169 "*This variable is a list of regular expressions.
170 If it is non-nil, headers that match the regular expressions will
171 be placed first in the article buffer in the sequence specified by
173 :type '(repeat regexp)
174 :group 'gnus-article-hiding)
176 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
177 "Headers that are only to be displayed if they have interesting data.
178 Possible values in this list are:
180 'empty Headers with no content.
181 'newsgroups Newsgroup identical to Gnus group.
182 'to-address To identical to To-address.
183 'followup-to Followup-to identical to Newsgroups.
184 'reply-to Reply-to identical to From.
185 'date Date less than four days old.
186 'long-to To and/or Cc longer than 1024 characters.
187 'many-to Multiple To and/or Cc."
188 :type '(set (const :tag "Headers with no content." empty)
189 (const :tag "Newsgroups identical to Gnus group." newsgroups)
190 (const :tag "To identical to To-address." to-address)
191 (const :tag "Followup-to identical to Newsgroups." followup-to)
192 (const :tag "Reply-to identical to From." reply-to)
193 (const :tag "Date less than four days old." date)
194 (const :tag "To and/or Cc longer than 1024 characters." long-to)
195 (const :tag "Multiple To and/or Cc headers." many-to))
196 :group 'gnus-article-hiding)
198 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
199 "Regexp matching signature separator.
200 This can also be a list of regexps. In that case, it will be checked
201 from head to tail looking for a separator. Searches will be done from
202 the end of the buffer."
203 :type '(repeat string)
204 :group 'gnus-article-signature)
206 (defcustom gnus-signature-limit nil
207 "Provide a limit to what is considered a signature.
208 If it is a number, no signature may not be longer (in characters) than
209 that number. If it is a floating point number, no signature may be
210 longer (in lines) than that number. If it is a function, the function
211 will be called without any parameters, and if it returns nil, there is
212 no signature in the buffer. If it is a string, it will be used as a
213 regexp. If it matches, the text in question is not a signature."
214 :type '(choice (integer :value 200)
216 (function :value fun)
217 (regexp :value ".*"))
218 :group 'gnus-article-signature)
220 (defcustom gnus-hidden-properties '(invisible t intangible t)
221 "Property list to use for hiding text."
223 :group 'gnus-article-hiding)
225 ;; Fixme: This isn't the right thing for mixed graphical and and
226 ;; non-graphical frames in a session.
227 (defcustom gnus-article-x-face-command
228 (if (featurep 'xemacs)
229 (if (or (gnus-image-type-available-p 'xface)
230 (gnus-image-type-available-p 'xpm))
231 'gnus-xmas-article-display-xface
232 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
233 (if (gnus-image-type-available-p 'xbm)
234 'gnus-article-display-xface
235 (if gnus-article-compface-xbm
236 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -"
237 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
239 "*String or function to be executed to display an X-Face header.
240 If it is a string, the command will be executed in a sub-shell
241 asynchronously. The compressed face will be piped to this command."
242 :type `(choice string
244 ,(if (featurep 'xemacs)
245 'gnus-xmas-article-display-xface
246 'gnus-article-display-xface))
249 :group 'gnus-article-washing)
251 (defcustom gnus-article-x-face-too-ugly nil
252 "Regexp matching posters whose face shouldn't be shown automatically."
253 :type '(choice regexp (const nil))
254 :group 'gnus-article-washing)
256 (defcustom gnus-article-banner-alist nil
257 "Banner alist for stripping.
259 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
261 :type '(repeat (cons symbol regexp))
262 :group 'gnus-article-washing)
264 (gnus-define-group-parameter
267 "Alist of regexps (to match group names) and banner."
268 :variable-group gnus-article-washing
270 '(choice :tag "Banner"
272 (const :tag "Remove signature" signature)
273 (symbol :tag "Item in `gnus-article-banner-alist'" none)
275 (const :tag "None" nil))
277 "If non-nil, specify how to remove `banners' from articles.
279 Symbol `signature' means to remove signatures delimited by
280 `gnus-signature-separator'. Any other symbol is used to look up a
281 regular expression to match the banner in `gnus-article-banner-alist'.
282 A string is used as a regular expression to match the banner
285 (defcustom gnus-emphasis-alist
287 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
289 '(("_" "_" underline)
292 ("_/" "/_" underline-italic)
293 ("_\\*" "\\*_" underline-bold)
294 ("\\*/" "/\\*" bold-italic)
295 ("_\\*/" "/\\*_" underline-bold-italic))))
296 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
297 2 3 gnus-emphasis-underline)
301 (format format (car spec) (cadr spec))
302 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
304 "*Alist that says how to fontify certain phrases.
305 Each item looks like this:
307 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
309 The first element is a regular expression to be matched. The second
310 is a number that says what regular expression grouping used to find
311 the entire emphasized word. The third is a number that says what
312 regexp grouping should be displayed and highlighted. The fourth
313 is the face used for highlighting."
314 :type '(repeat (list :value ("" 0 0 default)
316 (integer :tag "Match group")
317 (integer :tag "Emphasize group")
319 :group 'gnus-article-emphasis)
321 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
322 "A regexp to describe whitespace which should not be emphasized.
323 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
324 The former avoids underlining of leading and trailing whitespace,
325 and the latter avoids underlining any whitespace at all."
327 :group 'gnus-article-emphasis
330 (defface gnus-emphasis-bold '((t (:bold t)))
331 "Face used for displaying strong emphasized text (*word*)."
332 :group 'gnus-article-emphasis)
334 (defface gnus-emphasis-italic '((t (:italic t)))
335 "Face used for displaying italic emphasized text (/word/)."
336 :group 'gnus-article-emphasis)
338 (defface gnus-emphasis-underline '((t (:underline t)))
339 "Face used for displaying underlined emphasized text (_word_)."
340 :group 'gnus-article-emphasis)
342 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
343 "Face used for displaying underlined bold emphasized text (_*word*_)."
344 :group 'gnus-article-emphasis)
346 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
347 "Face used for displaying underlined italic emphasized text (_/word/_)."
348 :group 'gnus-article-emphasis)
350 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
351 "Face used for displaying bold italic emphasized text (/*word*/)."
352 :group 'gnus-article-emphasis)
354 (defface gnus-emphasis-underline-bold-italic
355 '((t (:bold t :italic t :underline t)))
356 "Face used for displaying underlined bold italic emphasized text.
357 Esample: (_/*word*/_)."
358 :group 'gnus-article-emphasis)
360 (defface gnus-emphasis-highlight-words
361 '((t (:background "black" :foreground "yellow")))
362 "Face used for displaying highlighted words."
363 :group 'gnus-article-emphasis)
365 (defface gnus-body-separator-face
368 (:background "white")
369 (:foreground "black"))
372 (:background "black")
373 (:foreground "white"))
376 "Face for the body separator.")
378 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
379 "Format for display of Date headers in article bodies.
380 See `format-time-string' for the possible values.
382 The variable can also be function, which should return a complete Date
383 header. The function is called with one argument, the time, which can
384 be fed to `format-time-string'."
385 :type '(choice string symbol)
386 :link '(custom-manual "(gnus)Article Date")
387 :group 'gnus-article-washing)
390 (autoload 'mail-extract-address-components "mail-extr"))
392 (defcustom gnus-save-all-headers t
393 "*If non-nil, don't remove any headers before saving."
394 :group 'gnus-article-saving
397 (defcustom gnus-prompt-before-saving 'always
398 "*This variable says how much prompting is to be done when saving articles.
399 If it is nil, no prompting will be done, and the articles will be
400 saved to the default files. If this variable is `always', each and
401 every article that is saved will be preceded by a prompt, even when
402 saving large batches of articles. If this variable is neither nil not
403 `always', there the user will be prompted once for a file name for
404 each invocation of the saving commands."
405 :group 'gnus-article-saving
406 :type '(choice (item always)
407 (item :tag "never" nil)
408 (sexp :tag "once" :format "%t\n" :value t)))
410 (defcustom gnus-saved-headers gnus-visible-headers
411 "Headers to keep if `gnus-save-all-headers' is nil.
412 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
413 If that variable is nil, however, all headers that match this regexp
414 will be kept while the rest will be deleted before saving."
415 :group 'gnus-article-saving
418 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
419 "A function to save articles in your favourite format.
420 The function must be interactively callable (in other words, it must
421 be an Emacs command).
423 Gnus provides the following functions:
425 * gnus-summary-save-in-rmail (Rmail format)
426 * gnus-summary-save-in-mail (Unix mail format)
427 * gnus-summary-save-in-folder (MH folder)
428 * gnus-summary-save-in-file (article format)
429 * gnus-summary-save-body-in-file (article body)
430 * gnus-summary-save-in-vm (use VM's folder format)
431 * gnus-summary-write-to-file (article format -- overwrite)."
432 :group 'gnus-article-saving
433 :type '(radio (function-item gnus-summary-save-in-rmail)
434 (function-item gnus-summary-save-in-mail)
435 (function-item gnus-summary-save-in-folder)
436 (function-item gnus-summary-save-in-file)
437 (function-item gnus-summary-save-body-in-file)
438 (function-item gnus-summary-save-in-vm)
439 (function-item gnus-summary-write-to-file)))
441 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
442 "A function generating a file name to save articles in Rmail format.
443 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
444 :group 'gnus-article-saving
447 (defcustom gnus-mail-save-name 'gnus-plain-save-name
448 "A function generating a file name to save articles in Unix mail format.
449 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
450 :group 'gnus-article-saving
453 (defcustom gnus-folder-save-name 'gnus-folder-save-name
454 "A function generating a file name to save articles in MH folder.
455 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
456 :group 'gnus-article-saving
459 (defcustom gnus-file-save-name 'gnus-numeric-save-name
460 "A function generating a file name to save articles in article format.
461 The function is called with NEWSGROUP, HEADERS, and optional
463 :group 'gnus-article-saving
466 (defcustom gnus-split-methods
467 '((gnus-article-archive-name)
468 (gnus-article-nndoc-name))
469 "*Variable used to suggest where articles are to be saved.
470 For instance, if you would like to save articles related to Gnus in
471 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
472 you could set this variable to something like:
474 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
475 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
477 This variable is an alist where the where the key is the match and the
478 value is a list of possible files to save in if the match is non-nil.
480 If the match is a string, it is used as a regexp match on the
481 article. If the match is a symbol, that symbol will be funcalled
482 from the buffer of the article to be saved with the newsgroup as the
483 parameter. If it is a list, it will be evaled in the same buffer.
485 If this form or function returns a string, this string will be used as
486 a possible file name; and if it returns a non-nil list, that list will
487 be used as possible file names."
488 :group 'gnus-article-saving
489 :type '(repeat (choice (list :value (fun) function)
490 (cons :value ("" "") regexp (repeat string))
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
659 '(article-decode-charset article-decode-encoded-words
660 article-decode-group-name)
661 "*Hook run to decode charsets in articles."
662 :group 'gnus-article-headers
665 (defcustom gnus-display-mime-function 'gnus-display-mime
666 "Function to display MIME articles."
667 :group 'gnus-article-mime
670 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
671 "Function used to decode headers.")
673 (defvar gnus-article-dumbquotes-map
692 "Table for MS-to-Latin1 translation.")
694 (defcustom gnus-ignored-mime-types nil
695 "List of MIME types that should be ignored by Gnus."
697 :group 'gnus-article-mime
698 :type '(repeat regexp))
700 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
701 "List of MIME types that should not be given buttons when rendered inline.
702 See also `gnus-buttonized-mime-types' which may override this variable."
704 :group 'gnus-article-mime
705 :type '(repeat regexp))
707 (defcustom gnus-buttonized-mime-types nil
708 "List of MIME types that should be given buttons when rendered inline.
709 If set, this variable overrides `gnus-unbuttonized-mime-types'.
710 To see e.g. security buttons you could set this to
711 `(\"multipart/signed\")'."
713 :group 'gnus-article-mime
714 :type '(repeat regexp))
716 (defcustom gnus-article-mime-part-function nil
717 "Function called with a MIME handle as the argument.
718 This is meant for people who want to do something automatic based
719 on parts -- for instance, adding Vcard info to a database."
720 :group 'gnus-article-mime
723 (defcustom gnus-mime-multipart-functions nil
724 "An alist of MIME types to functions to display them."
726 :group 'gnus-article-mime
729 (defcustom gnus-article-date-lapsed-new-header nil
730 "Whether the X-Sent and Date headers can coexist.
731 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
732 either replace the old \"Date:\" header (if this variable is nil), or
733 be added below it (otherwise)."
735 :group 'gnus-article-headers
738 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
739 "Function called with a MIME handle as the argument.
740 This is meant for people who want to view first matched part.
741 For `undisplayed-alternative' (default), the first undisplayed
742 part or alternative part is used. For `undisplayed', the first
743 undisplayed part is used. For a function, the first part which
744 the function return `t' is used. For `nil', the first part is
747 :group 'gnus-article-mime
749 (item :tag "first" :value nil)
750 (item :tag "undisplayed" :value undisplayed)
751 (item :tag "undisplayed or alternative"
752 :value undisplayed-alternative)
755 (defcustom gnus-mime-action-alist
756 '(("save to file" . gnus-mime-save-part)
757 ("save and strip" . gnus-mime-save-part-and-strip)
758 ("display as text" . gnus-mime-inline-part)
759 ("view the part" . gnus-mime-view-part)
760 ("pipe to command" . gnus-mime-pipe-part)
761 ("toggle display" . gnus-article-press-button)
762 ("toggle display" . gnus-article-view-part-as-charset)
763 ("view as type" . gnus-mime-view-part-as-type)
764 ("internalize type" . gnus-mime-internalize-part)
765 ("externalize type" . gnus-mime-externalize-part))
766 "An alist of actions that run on the MIME attachment."
767 :group 'gnus-article-mime
768 :type '(repeat (cons (string :tag "name")
771 (defcustom gnus-mime-action-alist
772 '(("save to file" . gnus-mime-save-part)
773 ("display as text" . gnus-mime-inline-part)
774 ("view the part" . gnus-mime-view-part)
775 ("pipe to command" . gnus-mime-pipe-part)
776 ("toggle display" . gnus-article-press-button)
777 ("view as type" . gnus-mime-view-part-as-type)
778 ("internalize type" . gnus-mime-internalize-part)
779 ("externalize type" . gnus-mime-externalize-part))
780 "An alist of actions that run on the MIME attachment."
782 :group 'gnus-article-mime
783 :type '(repeat (cons (string :tag "name")
787 ;;; The treatment variables
790 (defvar gnus-part-display-hook nil
791 "Hook called on parts that are to receive treatment.")
793 (defvar gnus-article-treat-custom
794 '(choice (const :tag "Off" nil)
796 (const :tag "Header" head)
797 (const :tag "Last" last)
798 (integer :tag "Less")
799 (repeat :tag "Groups" regexp)
800 (sexp :tag "Predicate")))
802 (defvar gnus-article-treat-head-custom
803 '(choice (const :tag "Off" nil)
804 (const :tag "Header" head)))
806 (defvar gnus-article-treat-types '("text/plain")
809 (defvar gnus-inhibit-treatment nil
810 "Whether to inhibit treatment.")
812 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
813 "Highlight the signature.
814 Valid values are nil, t, `head', `last', an integer or a predicate.
815 See Info node `(gnus)Customizing Articles'."
816 :group 'gnus-article-treat
817 :type gnus-article-treat-custom)
818 (put 'gnus-treat-highlight-signature 'highlight t)
820 (defcustom gnus-treat-buttonize 100000
822 Valid values are nil, t, `head', `last', an integer or a predicate.
823 See the manual for details."
824 :group 'gnus-article-treat
825 :type gnus-article-treat-custom)
826 (put 'gnus-treat-buttonize 'highlight t)
828 (defcustom gnus-treat-buttonize-head 'head
829 "Add buttons to the head.
830 Valid values are nil, t, `head', `last', an integer or a predicate.
831 See the manual for details."
832 :group 'gnus-article-treat
833 :type gnus-article-treat-head-custom)
834 (put 'gnus-treat-buttonize-head 'highlight t)
836 (defcustom gnus-treat-emphasize
837 (and (or window-system
839 (>= (string-to-number emacs-version) 21))
842 Valid values are nil, t, `head', `last', an integer or a predicate.
843 See the manual for details."
844 :group 'gnus-article-treat
845 :type gnus-article-treat-custom)
846 (put 'gnus-treat-emphasize 'highlight t)
848 (defcustom gnus-treat-strip-cr nil
849 "Remove carriage returns.
850 Valid values are nil, t, `head', `last', an integer or a predicate.
851 See the manual for details."
852 :group 'gnus-article-treat
853 :type gnus-article-treat-custom)
855 (defcustom gnus-treat-leading-whitespace nil
856 "Remove leading whitespace in headers.
857 Valid values are nil, t, `head', `last', an integer or a predicate.
858 See the manual for details."
859 :group 'gnus-article-treat
860 :type gnus-article-treat-custom)
862 (defcustom gnus-treat-hide-headers 'head
864 Valid values are nil, t, `head', `last', an integer or a predicate.
865 See the manual for details."
866 :group 'gnus-article-treat
867 :type gnus-article-treat-head-custom)
869 (defcustom gnus-treat-hide-boring-headers nil
870 "Hide boring headers.
871 Valid values are nil, t, `head', `last', an integer or a predicate.
872 See the manual for details."
873 :group 'gnus-article-treat
874 :type gnus-article-treat-head-custom)
876 (defcustom gnus-treat-hide-signature nil
878 Valid values are nil, t, `head', `last', an integer or a predicate.
879 See the manual for details."
880 :group 'gnus-article-treat
881 :type gnus-article-treat-custom)
883 (defcustom gnus-treat-fill-article nil
885 Valid values are nil, t, `head', `last', an integer or a predicate.
886 See the manual for details."
887 :group 'gnus-article-treat
888 :type gnus-article-treat-custom)
890 (defcustom gnus-treat-hide-citation nil
892 Valid values are nil, t, `head', `last', an integer or a predicate.
893 See the manual for details."
894 :group 'gnus-article-treat
895 :type gnus-article-treat-custom)
897 (defcustom gnus-treat-hide-citation-maybe nil
899 Valid values are nil, t, `head', `last', an integer or a predicate.
900 See the manual for details."
901 :group 'gnus-article-treat
902 :type gnus-article-treat-custom)
904 (defcustom gnus-treat-strip-list-identifiers 'head
905 "Strip list identifiers from `gnus-list-identifiers`.
906 Valid values are nil, t, `head', `last', an integer or a predicate.
907 See the manual for details."
909 :group 'gnus-article-treat
910 :type gnus-article-treat-custom)
912 (defcustom gnus-treat-strip-pgp t
913 "Strip PGP signatures.
914 Valid values are nil, t, `head', `last', an integer or a predicate.
915 See the manual for details."
916 :group 'gnus-article-treat
917 :type gnus-article-treat-custom)
919 (defcustom gnus-treat-strip-pem nil
920 "Strip PEM signatures.
921 Valid values are nil, t, `head', `last', an integer or a predicate.
922 See the manual for details."
923 :group 'gnus-article-treat
924 :type gnus-article-treat-custom)
926 (defcustom gnus-treat-strip-banner t
927 "Strip banners from articles.
928 The banner to be stripped is specified in the `banner' group parameter.
929 Valid values are nil, t, `head', `last', an integer or a predicate.
930 See the manual for details."
931 :group 'gnus-article-treat
932 :type gnus-article-treat-custom)
934 (defcustom gnus-treat-highlight-headers 'head
935 "Highlight the headers.
936 Valid values are nil, t, `head', `last', an integer or a predicate.
937 See the manual for details."
938 :group 'gnus-article-treat
939 :type gnus-article-treat-head-custom)
940 (put 'gnus-treat-highlight-headers 'highlight t)
942 (defcustom gnus-treat-highlight-citation t
943 "Highlight cited text.
944 Valid values are nil, t, `head', `last', an integer or a predicate.
945 See the manual for details."
946 :group 'gnus-article-treat
947 :type gnus-article-treat-custom)
948 (put 'gnus-treat-highlight-citation 'highlight t)
950 (defcustom gnus-treat-date-ut nil
951 "Display the Date in UT (GMT).
952 Valid values are nil, t, `head', `last', an integer or a predicate.
953 See the manual for details."
954 :group 'gnus-article-treat
955 :type gnus-article-treat-head-custom)
957 (defcustom gnus-treat-date-local nil
958 "Display the Date in the local timezone.
959 Valid values are nil, t, `head', `last', an integer or a predicate.
960 See the manual for details."
961 :group 'gnus-article-treat
962 :type gnus-article-treat-head-custom)
964 (defcustom gnus-treat-date-english nil
965 "Display the Date in a format that can be read aloud in English.
966 Valid values are nil, t, `head', `last', an integer or a predicate.
967 See the manual for details."
968 :group 'gnus-article-treat
969 :type gnus-article-treat-head-custom)
971 (defcustom gnus-treat-date-lapsed nil
972 "Display the Date header in a way that says how much time has elapsed.
973 Valid values are nil, t, `head', `last', an integer or a predicate.
974 See the manual for details."
975 :group 'gnus-article-treat
976 :type gnus-article-treat-head-custom)
978 (defcustom gnus-treat-date-original nil
979 "Display the date in the original timezone.
980 Valid values are nil, t, `head', `last', an integer or a predicate.
981 See the manual for details."
982 :group 'gnus-article-treat
983 :type gnus-article-treat-head-custom)
985 (defcustom gnus-treat-date-iso8601 nil
986 "Display the date in the ISO8601 format.
987 Valid values are nil, t, `head', `last', an integer or a predicate.
988 See the manual for details."
990 :group 'gnus-article-treat
991 :type gnus-article-treat-head-custom)
993 (defcustom gnus-treat-date-user-defined nil
994 "Display the date in a user-defined format.
995 The format is defined by the `gnus-article-time-format' variable.
996 Valid values are nil, t, `head', `last', an integer or a predicate.
997 See the manual for details."
998 :group 'gnus-article-treat
999 :type gnus-article-treat-head-custom)
1001 (defcustom gnus-treat-strip-headers-in-body t
1002 "Strip the X-No-Archive header line from the beginning of the body.
1003 Valid values are nil, t, `head', `last', an integer or a predicate.
1004 See the manual for details."
1006 :group 'gnus-article-treat
1007 :type gnus-article-treat-custom)
1009 (defcustom gnus-treat-strip-trailing-blank-lines nil
1010 "Strip trailing blank lines.
1011 Valid values are nil, t, `head', `last', an integer or a predicate.
1012 See the manual for details."
1013 :group 'gnus-article-treat
1014 :type gnus-article-treat-custom)
1016 (defcustom gnus-treat-strip-leading-blank-lines nil
1017 "Strip leading blank lines.
1018 Valid values are nil, t, `head', `last', an integer or a predicate.
1019 See the manual for details."
1020 :group 'gnus-article-treat
1021 :type gnus-article-treat-custom)
1023 (defcustom gnus-treat-strip-multiple-blank-lines nil
1024 "Strip multiple blank lines.
1025 Valid values are nil, t, `head', `last', an integer or a predicate.
1026 See the manual for details."
1027 :group 'gnus-article-treat
1028 :type gnus-article-treat-custom)
1030 (defcustom gnus-treat-unfold-headers 'head
1031 "Unfold folded header lines.
1032 Valid values are nil, t, `head', `last', an integer or a predicate.
1033 See the manual for details."
1034 :group 'gnus-article-treat
1035 :type gnus-article-treat-custom)
1037 (defcustom gnus-treat-overstrike t
1038 "Treat overstrike highlighting.
1039 Valid values are nil, t, `head', `last', an integer or a predicate.
1040 See the manual for details."
1041 :group 'gnus-article-treat
1042 :type gnus-article-treat-custom)
1043 (put 'gnus-treat-overstrike 'highlight t)
1045 (defcustom gnus-treat-display-xface
1046 (and (or (and (fboundp 'image-type-available-p)
1047 (image-type-available-p 'xbm)
1048 (string-match "^0x" (shell-command-to-string "uncompface")))
1049 (and (featurep 'xemacs) (featurep 'xface)))
1051 "Display X-Face headers.
1052 Valid values are nil, t, `head', `last', an integer or a predicate.
1053 See the manual for details."
1054 :group 'gnus-article-treat
1056 :type gnus-article-treat-head-custom)
1057 (put 'gnus-treat-display-xface 'highlight t)
1059 (defcustom gnus-treat-display-smileys
1060 (if (or (and (featurep 'xemacs)
1062 (and (fboundp 'image-type-available-p)
1063 (image-type-available-p 'pbm)))
1066 Valid values are nil, t, `head', `last', an integer or a predicate.
1067 See the manual for details."
1068 :group 'gnus-article-treat
1070 :type gnus-article-treat-custom)
1071 (put 'gnus-treat-display-smileys 'highlight t)
1073 (defcustom gnus-treat-from-picon
1074 (if (gnus-image-type-available-p 'xpm)
1076 "Display picons in the From header.
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-head-custom)
1081 (put 'gnus-treat-from-picon 'highlight t)
1083 (defcustom gnus-treat-mail-picon
1084 (if (gnus-image-type-available-p 'xpm)
1086 "Display picons in To and Cc headers.
1087 Valid values are nil, t, `head', `last', an integer or a predicate.
1088 See the manual for details."
1089 :group 'gnus-article-treat
1090 :type gnus-article-treat-head-custom)
1091 (put 'gnus-treat-mail-picon 'highlight t)
1093 (defcustom gnus-treat-newsgroups-picon
1094 (if (gnus-image-type-available-p 'xpm)
1096 "Display picons in the Newsgroups and Followup-To headers.
1097 Valid values are nil, t, `head', `last', an integer or a predicate.
1098 See the manual for details."
1099 :group 'gnus-article-treat
1100 :type gnus-article-treat-head-custom)
1101 (put 'gnus-treat-newsgroups-picon 'highlight t)
1103 (defcustom gnus-treat-body-boundary
1104 (if (or gnus-treat-newsgroups-picon
1105 gnus-treat-mail-picon
1106 gnus-treat-from-picon)
1108 "Draw a boundary at the end of the headers.
1109 Valid values are nil, t, `head', `last', an integer or a predicate.
1110 See the manual for details."
1112 :group 'gnus-article-treat
1113 :type gnus-article-treat-custom)
1115 (defcustom gnus-treat-capitalize-sentences nil
1116 "Capitalize sentence-starting words.
1117 Valid values are nil, t, `head', `last', an integer or a predicate.
1118 See the manual for details."
1120 :group 'gnus-article-treat
1121 :type gnus-article-treat-custom)
1123 (defcustom gnus-treat-fill-long-lines nil
1125 Valid values are nil, t, `head', `last', an integer or a predicate.
1126 See the manual for details."
1127 :group 'gnus-article-treat
1128 :type gnus-article-treat-custom)
1130 (defcustom gnus-treat-play-sounds nil
1132 Valid values are nil, t, `head', `last', an integer or a predicate.
1133 See the manual for details."
1135 :group 'gnus-article-treat
1136 :type gnus-article-treat-custom)
1138 (defcustom gnus-treat-translate nil
1139 "Translate articles from one language to another.
1140 Valid values are nil, t, `head', `last', an integer or a predicate.
1141 See the manual for details."
1143 :group 'gnus-article-treat
1144 :type gnus-article-treat-custom)
1146 (defcustom gnus-treat-x-pgp-sig nil
1148 To automatically treat X-PGP-Sig, set it to head.
1149 Valid values are nil, t, `head', `last', an integer or a predicate.
1150 See the manual for details."
1151 :group 'gnus-article-treat
1152 :group 'mime-security
1153 :type gnus-article-treat-custom)
1155 (defvar gnus-article-encrypt-protocol-alist
1156 '(("PGP" . mml2015-self-encrypt)))
1158 ;; Set to nil if more than one protocol added to
1159 ;; gnus-article-encrypt-protocol-alist.
1160 (defcustom gnus-article-encrypt-protocol "PGP"
1161 "The protocol used for encrypt articles.
1162 It is a string, such as \"PGP\". If nil, ask user."
1164 :group 'mime-security)
1166 ;;; Internal variables
1168 (defvar gnus-english-month-names
1169 '("January" "February" "March" "April" "May" "June" "July" "August"
1170 "September" "October" "November" "December"))
1172 (defvar article-goto-body-goes-to-point-min-p nil)
1173 (defvar gnus-article-wash-types nil)
1174 (defvar gnus-article-emphasis-alist nil)
1176 (defvar gnus-article-mime-handle-alist-1 nil)
1177 (defvar gnus-treatment-function-alist
1178 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1179 (gnus-treat-strip-banner gnus-article-strip-banner)
1180 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1181 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1182 (gnus-treat-buttonize gnus-article-add-buttons)
1183 (gnus-treat-fill-article gnus-article-fill-cited-article)
1184 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1185 (gnus-treat-strip-cr gnus-article-remove-cr)
1186 (gnus-treat-display-xface gnus-article-display-x-face)
1187 (gnus-treat-date-ut gnus-article-date-ut)
1188 (gnus-treat-date-local gnus-article-date-local)
1189 (gnus-treat-date-english gnus-article-date-english)
1190 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1191 (gnus-treat-date-original gnus-article-date-original)
1192 (gnus-treat-date-user-defined gnus-article-date-user)
1193 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1194 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1195 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1196 (gnus-treat-hide-signature gnus-article-hide-signature)
1197 (gnus-treat-hide-citation gnus-article-hide-citation)
1198 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1199 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1200 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1201 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1202 (gnus-treat-strip-pem gnus-article-hide-pem)
1203 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1204 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1205 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1206 (gnus-treat-strip-trailing-blank-lines
1207 gnus-article-remove-trailing-blank-lines)
1208 (gnus-treat-strip-leading-blank-lines
1209 gnus-article-strip-leading-blank-lines)
1210 (gnus-treat-strip-multiple-blank-lines
1211 gnus-article-strip-multiple-blank-lines)
1212 (gnus-treat-overstrike gnus-article-treat-overstrike)
1213 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1214 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1215 (gnus-treat-display-smileys gnus-smiley-display)
1216 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1217 (gnus-treat-emphasize gnus-article-emphasize)
1218 (gnus-treat-from-picon gnus-treat-from-picon)
1219 (gnus-treat-mail-picon gnus-treat-mail-picon)
1220 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1221 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1222 (gnus-treat-play-sounds gnus-earcon-display)))
1224 (defvar gnus-article-mime-handle-alist nil)
1225 (defvar article-lapsed-timer nil)
1226 (defvar gnus-article-current-summary nil)
1228 (defvar gnus-article-mode-syntax-table
1229 (let ((table (copy-syntax-table text-mode-syntax-table)))
1230 ;; This causes the citation match run O(2^n).
1231 ;; (modify-syntax-entry ?- "w" table)
1232 (modify-syntax-entry ?> ")" table)
1233 (modify-syntax-entry ?< "(" table)
1235 "Syntax table used in article mode buffers.
1236 Initialized from `text-mode-syntax-table.")
1238 (defvar gnus-save-article-buffer nil)
1240 (defvar gnus-article-mode-line-format-alist
1241 (nconc '((?w (gnus-article-wash-status) ?s)
1242 (?m (gnus-article-mime-part-status) ?s))
1243 gnus-summary-mode-line-format-alist))
1245 (defvar gnus-number-of-articles-to-be-saved nil)
1247 (defvar gnus-inhibit-hiding nil)
1249 (defsubst gnus-article-hide-text (b e props)
1250 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1251 (gnus-add-text-properties-when 'article-type nil b e props)
1252 (when (memq 'intangible props)
1254 (max (1- b) (point-min))
1255 b 'intangible (cddr (memq 'intangible props)))))
1257 (defsubst gnus-article-unhide-text (b e)
1258 "Remove hidden text properties from region between B and E."
1259 (remove-text-properties b e gnus-hidden-properties)
1260 (when (memq 'intangible gnus-hidden-properties)
1261 (put-text-property (max (1- b) (point-min))
1262 b 'intangible nil)))
1264 (defun gnus-article-hide-text-type (b e type)
1265 "Hide text of TYPE between B and E."
1266 (push type gnus-article-wash-types)
1267 (gnus-article-hide-text
1268 b e (cons 'article-type (cons type gnus-hidden-properties))))
1270 (defun gnus-article-unhide-text-type (b e type)
1271 "Unhide text of TYPE between B and E."
1272 (setq gnus-article-wash-types
1273 (delq type gnus-article-wash-types))
1274 (remove-text-properties
1275 b e (cons 'article-type (cons type gnus-hidden-properties)))
1276 (when (memq 'intangible gnus-hidden-properties)
1277 (put-text-property (max (1- b) (point-min))
1278 b 'intangible nil)))
1280 (defun gnus-article-hide-text-of-type (type)
1281 "Hide text of TYPE in the current buffer."
1283 (let ((b (point-min))
1285 (while (setq b (text-property-any b e 'article-type type))
1286 (add-text-properties b (incf b) gnus-hidden-properties)))))
1288 (defun gnus-article-delete-text-of-type (type)
1289 "Delete text of TYPE in the current buffer."
1291 (let ((b (point-min)))
1292 (while (setq b (text-property-any b (point-max) 'article-type type))
1294 b (or (text-property-not-all b (point-max) 'article-type type)
1297 (defun gnus-article-delete-invisible-text ()
1298 "Delete all invisible text in the current buffer."
1300 (let ((b (point-min)))
1301 (while (setq b (text-property-any b (point-max) 'invisible t))
1303 b (or (text-property-not-all b (point-max) 'invisible t)
1306 (defun gnus-article-text-type-exists-p (type)
1307 "Say whether any text of type TYPE exists in the buffer."
1308 (text-property-any (point-min) (point-max) 'article-type type))
1310 (defsubst gnus-article-header-rank ()
1311 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1312 (let ((list gnus-sorted-header-list)
1315 (when (looking-at (car list))
1317 (setq list (cdr list))
1321 (defun article-hide-headers (&optional arg delete)
1322 "Hide unwanted headers and possibly sort them as well."
1324 ;; This function might be inhibited.
1325 (unless gnus-inhibit-hiding
1328 (let ((buffer-read-only nil)
1329 (case-fold-search t)
1330 (max (1+ (length gnus-sorted-header-list)))
1331 (ignored (when (not gnus-visible-headers)
1332 (cond ((stringp gnus-ignored-headers)
1333 gnus-ignored-headers)
1334 ((listp gnus-ignored-headers)
1335 (mapconcat 'identity gnus-ignored-headers
1338 (cond ((stringp gnus-visible-headers)
1339 gnus-visible-headers)
1340 ((and gnus-visible-headers
1341 (listp gnus-visible-headers))
1342 (mapconcat 'identity gnus-visible-headers "\\|"))))
1343 (inhibit-point-motion-hooks t)
1345 ;; First we narrow to just the headers.
1346 (article-narrow-to-head)
1347 ;; Hide any "From " lines at the beginning of (mail) articles.
1348 (while (looking-at "From ")
1351 (delete-region (point-min) (point)))
1352 ;; Then treat the rest of the header lines.
1353 ;; Then we use the two regular expressions
1354 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1355 ;; select which header lines is to remain visible in the
1357 (while (re-search-forward "^[^ \t:]*:" nil t)
1359 ;; Mark the rank of the header.
1361 (point) (1+ (point)) 'message-rank
1362 (if (or (and visible (looking-at visible))
1364 (not (looking-at ignored))))
1365 (gnus-article-header-rank)
1368 (message-sort-headers-1)
1369 (when (setq beg (text-property-any
1370 (point-min) (point-max) 'message-rank (+ 2 max)))
1371 ;; We delete the unwanted headers.
1372 (push 'headers gnus-article-wash-types)
1373 (add-text-properties (point-min) (+ 5 (point-min))
1374 '(article-type headers dummy-invisible t))
1375 (delete-region beg (point-max))))))))
1377 (defun article-hide-boring-headers (&optional arg)
1378 "Toggle hiding of headers that aren't very interesting.
1379 If given a negative prefix, always show; if given a positive prefix,
1381 (interactive (gnus-article-hidden-arg))
1382 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1383 (not gnus-show-all-headers))
1386 (let ((buffer-read-only nil)
1387 (list gnus-boring-article-headers)
1388 (inhibit-point-motion-hooks t)
1390 (article-narrow-to-head)
1392 (setq elem (pop list))
1393 (goto-char (point-min))
1395 ;; Hide empty headers.
1397 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1399 (gnus-article-hide-text-type
1400 (progn (beginning-of-line) (point))
1403 (if (re-search-forward "^[^ \t]" nil t)
1407 ;; Hide boring Newsgroups header.
1408 ((eq elem 'newsgroups)
1409 (when (gnus-string-equal
1410 (gnus-fetch-field "newsgroups")
1411 (gnus-group-real-name
1412 (if (boundp 'gnus-newsgroup-name)
1415 (gnus-article-hide-header "newsgroups")))
1416 ((eq elem 'to-address)
1417 (let ((to (message-fetch-field "to"))
1419 (gnus-parameter-to-address
1420 (if (boundp 'gnus-newsgroup-name)
1421 gnus-newsgroup-name ""))))
1422 (when (and to to-address
1425 ;; only one address in To
1426 (nth 1 (mail-extract-address-components to))
1428 (gnus-article-hide-header "to"))))
1429 ((eq elem 'followup-to)
1430 (when (gnus-string-equal
1431 (message-fetch-field "followup-to")
1432 (message-fetch-field "newsgroups"))
1433 (gnus-article-hide-header "followup-to")))
1434 ((eq elem 'reply-to)
1435 (let ((from (message-fetch-field "from"))
1436 (reply-to (message-fetch-field "reply-to")))
1441 (nth 1 (mail-extract-address-components from))
1442 (nth 1 (mail-extract-address-components reply-to)))))
1443 (gnus-article-hide-header "reply-to"))))
1445 (let ((date (message-fetch-field "date")))
1447 (< (days-between (current-time-string) date)
1449 (gnus-article-hide-header "date"))))
1451 (let ((to (message-fetch-field "to"))
1452 (cc (message-fetch-field "cc")))
1453 (when (> (length to) 1024)
1454 (gnus-article-hide-header "to"))
1455 (when (> (length cc) 1024)
1456 (gnus-article-hide-header "cc"))))
1460 (goto-char (point-min))
1461 (while (re-search-forward "^to:" nil t)
1462 (setq to-count (1+ to-count)))
1463 (when (> to-count 1)
1464 (while (> to-count 0)
1465 (goto-char (point-min))
1467 (re-search-forward "^to:" nil nil to-count)
1469 (narrow-to-region (point) (point-max))
1470 (gnus-article-hide-header "to"))
1471 (setq to-count (1- to-count))))
1472 (goto-char (point-min))
1473 (while (re-search-forward "^cc:" nil t)
1474 (setq cc-count (1+ cc-count)))
1475 (when (> cc-count 1)
1476 (while (> cc-count 0)
1477 (goto-char (point-min))
1479 (re-search-forward "^cc:" nil nil cc-count)
1481 (narrow-to-region (point) (point-max))
1482 (gnus-article-hide-header "cc"))
1483 (setq cc-count (1- cc-count)))))))))))))
1485 (defun gnus-article-hide-header (header)
1487 (goto-char (point-min))
1488 (when (re-search-forward (concat "^" header ":") nil t)
1489 (gnus-article-hide-text-type
1490 (progn (beginning-of-line) (point))
1493 (if (re-search-forward "^[^ \t]" nil t)
1498 (defvar gnus-article-normalized-header-length 40
1499 "Length of normalized headers.")
1501 (defun article-normalize-headers ()
1502 "Make all header lines 40 characters long."
1504 (let ((buffer-read-only nil)
1508 (article-narrow-to-head)
1511 ((< (setq column (- (gnus-point-at-eol) (point)))
1512 gnus-article-normalized-header-length)
1514 (insert (make-string
1515 (- gnus-article-normalized-header-length column)
1517 ((> column gnus-article-normalized-header-length)
1518 (gnus-put-text-property
1520 (forward-char gnus-article-normalized-header-length)
1527 (forward-line 1))))))
1529 (defun article-treat-dumbquotes ()
1530 "Translate M****s*** sm*rtq**t*s into proper text.
1531 Note that this function guesses whether a character is a sm*rtq**t* or
1532 not, so it should only be used interactively.
1534 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1535 in an attempt to provide more quoting characters. If you see
1536 something like \\222 or \\264 where you're expecting some kind of
1537 apostrophe or quotation mark, then try this wash."
1539 (article-translate-strings gnus-article-dumbquotes-map))
1541 (defun article-translate-characters (from to)
1542 "Translate all characters in the body of the article according to FROM and TO.
1543 FROM is a string of characters to translate from; to is a string of
1544 characters to translate to."
1546 (when (article-goto-body)
1547 (let ((buffer-read-only nil)
1548 (x (make-string 225 ?x))
1550 (while (< (incf i) (length x))
1553 (while (< i (length from))
1554 (aset x (aref from i) (aref to i))
1556 (translate-region (point) (point-max) x)))))
1558 (defun article-translate-strings (map)
1559 "Translate all string in the body of the article according to MAP.
1560 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1562 (when (article-goto-body)
1563 (let ((buffer-read-only nil)
1565 (while (setq elem (pop map))
1567 (while (search-forward (car elem) nil t)
1568 (replace-match (cadr elem)))))))))
1570 (defun article-treat-overstrike ()
1571 "Translate overstrikes into bold text."
1574 (when (article-goto-body)
1575 (let ((buffer-read-only nil))
1576 (while (search-forward "\b" nil t)
1577 (let ((next (char-after))
1578 (previous (char-after (- (point) 2))))
1579 ;; We do the boldification/underlining by hiding the
1580 ;; overstrikes and putting the proper text property
1584 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1585 (put-text-property (point) (1+ (point)) 'face 'bold))
1587 (gnus-article-hide-text-type
1588 (1- (point)) (1+ (point)) 'overstrike)
1590 (- (point) 2) (1- (point)) 'face 'underline))
1592 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1594 (point) (1+ (point)) 'face 'underline)))))))))
1596 (defun gnus-article-treat-unfold-headers ()
1597 "Unfold folded message headers.
1598 Only the headers that fit into the current window width will be
1601 (gnus-with-article-headers
1605 (mail-header-narrow-to-field)
1606 (let ((header (buffer-substring (point-min) (point-max))))
1609 (goto-char (point-min))
1610 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1611 (replace-match " " t t)))
1612 (setq length (- (point-max) (point-min) 1)))
1613 (when (< length (window-width))
1614 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1615 (replace-match " " t t)))
1616 (goto-char (point-max)))))))
1618 (defun gnus-article-treat-body-boundary ()
1619 "Place a boundary line at the end of the headers."
1621 (gnus-with-article-headers
1622 (goto-char (point-max))
1623 (insert (make-string (1- (window-width)) ? )
1625 (put-text-property (point) (progn (forward-line -1) (point))
1626 'face 'gnus-body-separator-face)))
1628 (defun article-fill-long-lines ()
1629 "Fill lines that are wider than the window width."
1632 (let ((buffer-read-only nil)
1633 (width (window-width (get-buffer-window (current-buffer)))))
1636 (let ((adaptive-fill-mode nil)) ;Why? -sm
1639 (when (>= (current-column) (min fill-column width))
1640 (narrow-to-region (point) (gnus-point-at-bol))
1641 (fill-paragraph nil)
1642 (goto-char (point-max))
1644 (forward-line 1)))))))
1646 (defun article-capitalize-sentences ()
1647 "Capitalize the first word in each sentence."
1650 (let ((buffer-read-only nil)
1651 (paragraph-start "^[\n\^L]"))
1655 (forward-sentence)))))
1657 (defun article-remove-cr ()
1658 "Remove trailing CRs and then translate remaining CRs into LFs."
1661 (let ((buffer-read-only nil))
1662 (goto-char (point-min))
1663 (while (re-search-forward "\r+$" nil t)
1664 (replace-match "" t t))
1665 (goto-char (point-min))
1666 (while (search-forward "\r" nil t)
1667 (replace-match "\n" t t)))))
1669 (defun article-remove-trailing-blank-lines ()
1670 "Remove all trailing blank lines from the article."
1673 (let ((buffer-read-only nil))
1674 (goto-char (point-max))
1678 (while (and (not (bobp))
1679 (looking-at "^[ \t]*$")
1680 (not (gnus-annotation-in-region-p
1681 (point) (gnus-point-at-eol))))
1686 (defun article-display-x-face (&optional force)
1687 "Look for an X-Face header and display it if present."
1688 (interactive (list 'force))
1690 ;; Delete the old process, if any.
1691 (when (process-status "article-x-face")
1692 (delete-process "article-x-face"))
1693 (let ((inhibit-point-motion-hooks t)
1695 (case-fold-search t)
1698 (article-narrow-to-head)
1699 (when (and buffer-read-only ;; When type `W f'
1701 (goto-char (point-min))
1702 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1703 (gnus-buffer-live-p gnus-original-article-buffer))
1704 (with-current-buffer gnus-original-article-buffer
1706 (article-narrow-to-head)
1707 (while (re-search-forward "^X-Face:" nil t)
1713 (1- (re-search-forward
1714 "^\\($\\|[^ \t]\\)" nil t))))))))
1716 (let (point start bface eface buffer-read-only)
1717 (goto-char (point-max))
1719 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1720 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1721 (goto-char (point-max))
1722 (setq point (point))
1725 (while (looking-at "\\([^:]+\\): *")
1726 (put-text-property (match-beginning 1) (1+ (match-end 1))
1728 (setq start (match-end 0))
1730 (while (looking-at "[\t ]")
1732 (put-text-property start (point)
1734 (goto-char (point-min))
1735 (setq from (message-fetch-field "from"))
1736 (goto-char (point-min))
1737 (while (and gnus-article-x-face-command
1740 ;; Check whether this face is censored.
1741 (not gnus-article-x-face-too-ugly)
1742 (and gnus-article-x-face-too-ugly from
1743 (not (string-match gnus-article-x-face-too-ugly
1745 ;; Has to be present.
1746 (re-search-forward "^X-Face:[\t ]*" nil t))
1747 ;; This used to try to do multiple faces (`while' instead of
1748 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1749 ;; work (b) it can crash some versions of Emacs (c) are
1750 ;; multiple faces really something to encourage?
1751 (when (stringp gnus-article-x-face-command)
1753 ;; We now have the area of the buffer where the X-Face is stored.
1756 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t)))
1758 ;; We display the face.
1759 (if (symbolp gnus-article-x-face-command)
1760 ;; The command is a lisp function, so we call it.
1761 (if (gnus-functionp gnus-article-x-face-command)
1762 (funcall gnus-article-x-face-command beg end)
1763 (error "%s is not a function" gnus-article-x-face-command))
1764 ;; The command is a string, so we interpret the command
1765 ;; as a, well, command, and fork it off.
1766 (let ((process-connection-type nil))
1767 (process-kill-without-query
1769 "article-x-face" nil shell-file-name shell-command-switch
1770 gnus-article-x-face-command))
1771 (process-send-region "article-x-face" beg end)
1772 (process-send-eof "article-x-face"))))))))))
1774 (defun article-decode-mime-words ()
1775 "Decode all MIME-encoded words in the article."
1778 (set-buffer gnus-article-buffer)
1779 (let ((inhibit-point-motion-hooks t)
1781 (mail-parse-charset gnus-newsgroup-charset)
1782 (mail-parse-ignored-charsets
1783 (save-excursion (set-buffer gnus-summary-buffer)
1784 gnus-newsgroup-ignored-charsets)))
1785 (mail-decode-encoded-word-region (point-min) (point-max)))))
1787 (defun article-decode-charset (&optional prompt)
1788 "Decode charset-encoded text in the article.
1789 If PROMPT (the prefix), prompt for a coding system to use."
1791 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1793 (mail-parse-charset gnus-newsgroup-charset)
1794 (mail-parse-ignored-charsets
1795 (save-excursion (condition-case nil
1796 (set-buffer gnus-summary-buffer)
1798 gnus-newsgroup-ignored-charsets))
1799 ct cte ctl charset format)
1802 (article-narrow-to-head)
1803 (setq ct (message-fetch-field "Content-Type" t)
1804 cte (message-fetch-field "Content-Transfer-Encoding" t)
1805 ctl (and ct (ignore-errors
1806 (mail-header-parse-content-type ct)))
1809 (mm-read-coding-system "Charset to decode: "))
1811 (mail-content-type-get ctl 'charset)))
1812 format (and ctl (mail-content-type-get ctl 'format)))
1814 (setq cte (mail-header-strip cte)))
1815 (if (and ctl (not (string-match "/" (car ctl))))
1817 (goto-char (point-max)))
1820 (narrow-to-region (point) (point-max))
1821 (when (and (eq mail-parse-charset 'gnus-decoded)
1822 (eq (mm-body-7-or-8) '8bit))
1823 ;; The text code could have been decoded.
1824 (setq charset mail-parse-charset))
1825 (when (and (or (not ctl)
1826 (equal (car ctl) "text/plain"))
1827 (not format)) ;; article with format will decode later.
1829 charset (and cte (intern (downcase
1830 (gnus-strip-whitespace cte))))
1833 (defun article-decode-encoded-words ()
1834 "Remove encoded-word encoding from headers."
1835 (let ((inhibit-point-motion-hooks t)
1836 (mail-parse-charset gnus-newsgroup-charset)
1837 (mail-parse-ignored-charsets
1838 (save-excursion (condition-case nil
1839 (set-buffer gnus-summary-buffer)
1841 gnus-newsgroup-ignored-charsets))
1844 (article-narrow-to-head)
1845 (funcall gnus-decode-header-function (point-min) (point-max)))))
1847 (defun article-decode-group-name ()
1848 "Decode group names in `Newsgroups:'."
1849 (let ((inhibit-point-motion-hooks t)
1851 (method (gnus-find-method-for-group gnus-newsgroup-name)))
1852 (when (and (or gnus-group-name-charset-method-alist
1853 gnus-group-name-charset-group-alist)
1854 (gnus-buffer-live-p gnus-original-article-buffer))
1855 (when (nnmail-fetch-field "Newsgroups")
1856 (nnheader-replace-header "Newsgroups"
1857 (gnus-decode-newsgroups
1858 (with-current-buffer
1859 gnus-original-article-buffer
1860 (nnmail-fetch-field "Newsgroups"))
1861 gnus-newsgroup-name method)))
1862 (when (nnmail-fetch-field "Followup-To")
1863 (nnheader-replace-header "Followup-To"
1864 (gnus-decode-newsgroups
1865 (with-current-buffer
1866 gnus-original-article-buffer
1867 (nnmail-fetch-field "Followup-To"))
1868 gnus-newsgroup-name method))))))
1870 (defun article-de-quoted-unreadable (&optional force read-charset)
1871 "Translate a quoted-printable-encoded article.
1872 If FORCE, decode the article whether it is marked as quoted-printable
1874 If READ-CHARSET, ask for a coding system."
1875 (interactive (list 'force current-prefix-arg))
1877 (let ((buffer-read-only nil) type charset)
1878 (if (gnus-buffer-live-p gnus-original-article-buffer)
1879 (with-current-buffer gnus-original-article-buffer
1881 (gnus-fetch-field "content-transfer-encoding"))
1882 (let* ((ct (gnus-fetch-field "content-type"))
1885 (mail-header-parse-content-type ct)))))
1886 (setq charset (and ctl
1887 (mail-content-type-get ctl 'charset)))
1888 (if (stringp charset)
1889 (setq charset (intern (downcase charset)))))))
1891 (setq charset (mm-read-coding-system "Charset: " 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 read-charset)
1902 "Translate a base64 article.
1903 If FORCE, decode the article whether it is marked as base64 not.
1904 If READ-CHARSET, ask for a coding system."
1905 (interactive (list 'force current-prefix-arg))
1907 (let ((buffer-read-only nil) type charset)
1908 (if (gnus-buffer-live-p gnus-original-article-buffer)
1909 (with-current-buffer gnus-original-article-buffer
1911 (gnus-fetch-field "content-transfer-encoding"))
1912 (let* ((ct (gnus-fetch-field "content-type"))
1915 (mail-header-parse-content-type ct)))))
1916 (setq charset (and ctl
1917 (mail-content-type-get ctl 'charset)))
1918 (if (stringp charset)
1919 (setq charset (intern (downcase charset)))))))
1921 (setq charset (mm-read-coding-system "Charset: " charset)))
1923 (setq charset gnus-newsgroup-charset))
1925 (and type (let ((case-fold-search t))
1926 (string-match "base64" type))))
1929 (narrow-to-region (point) (point-max))
1930 (base64-decode-region (point-min) (point-max))
1931 (mm-decode-coding-region
1932 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1937 (defun article-decode-HZ ()
1938 "Translate a HZ-encoded article."
1942 (let ((buffer-read-only nil))
1943 (rfc1843-decode-region (point-min) (point-max)))))
1945 (defun article-wash-html (&optional read-charset)
1946 "Format an html article.
1947 If READ-CHARSET, ask for a coding system."
1950 (let ((buffer-read-only nil)
1952 (if (gnus-buffer-live-p gnus-original-article-buffer)
1953 (with-current-buffer gnus-original-article-buffer
1954 (let* ((ct (gnus-fetch-field "content-type"))
1957 (mail-header-parse-content-type ct)))))
1958 (setq charset (and ctl
1959 (mail-content-type-get ctl 'charset)))
1960 (if (stringp charset)
1961 (setq charset (intern (downcase charset)))))))
1963 (setq charset (mm-read-coding-system "Charset: " charset)))
1965 (setq charset gnus-newsgroup-charset))
1967 (save-window-excursion
1969 (narrow-to-region (point) (point-max))
1971 (let ((w3-strict-width (window-width))
1972 (url-standalone-mode t)
1973 (w3-honor-stylesheets nil)
1974 (w3-delay-image-loads t))
1976 (w3-region (point-min) (point-max))
1979 (defun article-hide-list-identifiers ()
1980 "Remove list identifies from the Subject header.
1981 The `gnus-list-identifiers' variable specifies what to do."
1983 (let ((inhibit-point-motion-hooks t)
1984 (regexp (if (consp gnus-list-identifiers)
1985 (mapconcat 'identity gnus-list-identifiers " *\\|")
1986 gnus-list-identifiers))
1991 (article-narrow-to-head)
1992 (goto-char (point-min))
1993 (while (re-search-forward
1994 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
1996 (delete-region (match-beginning 2) (match-end 0))
1997 (beginning-of-line))
1998 (when (re-search-forward
1999 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2000 (delete-region (match-beginning 1) (match-end 1))))))))
2002 (defun article-hide-pgp ()
2003 "Remove any PGP headers and signatures in the current article."
2007 (let ((inhibit-point-motion-hooks t)
2008 buffer-read-only beg end)
2010 ;; Hide the "header".
2011 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2012 (push 'pgp gnus-article-wash-types)
2013 (delete-region (match-beginning 0) (match-end 0))
2014 ;; Remove armor headers (rfc2440 6.2)
2015 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2018 ;; Hide the actual signature.
2019 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2020 (setq end (1+ (match-beginning 0)))
2023 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2025 ;; Perhaps we shouldn't hide to the end of the buffer
2026 ;; if there is no end to the signature?
2028 ;; Hide "- " PGP quotation markers.
2030 (narrow-to-region beg end)
2031 (goto-char (point-min))
2032 (while (re-search-forward "^- " nil t)
2034 (match-beginning 0) (match-end 0)))
2036 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2038 (defun article-hide-pem (&optional arg)
2039 "Toggle hiding of any PEM headers and signatures in the current article.
2040 If given a negative prefix, always show; if given a positive prefix,
2042 (interactive (gnus-article-hidden-arg))
2043 (unless (gnus-article-check-hidden-text 'pem arg)
2045 (let (buffer-read-only end)
2046 (goto-char (point-min))
2047 ;; Hide the horrendously ugly "header".
2048 (when (and (search-forward
2049 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2051 (setq end (1+ (match-beginning 0))))
2052 (push 'pem gnus-article-wash-types)
2053 (gnus-article-hide-text-type
2055 (if (search-forward "\n\n" nil t)
2059 ;; Hide the trailer as well
2060 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2062 (gnus-article-hide-text-type
2063 (match-beginning 0) (match-end 0) 'pem)))))))
2065 (defun article-strip-banner ()
2066 "Strip the banner specified by the `banner' group parameter."
2070 (let ((inhibit-point-motion-hooks t)
2071 (banner (gnus-parameter-banner gnus-newsgroup-name))
2072 (gnus-signature-limit nil)
2073 buffer-read-only beg end)
2077 ((eq banner 'signature)
2078 (when (gnus-article-narrow-to-signature)
2081 (delete-region (point) (point-max))))
2083 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2084 (while (re-search-forward banner nil t)
2085 (delete-region (match-beginning 0) (match-end 0)))))
2087 (while (re-search-forward banner nil t)
2088 (delete-region (match-beginning 0) (match-end 0))))))))))
2090 (defun article-babel ()
2091 "Translate article using an online translation service."
2095 (set-buffer gnus-article-buffer)
2096 (when (article-goto-body)
2097 (let* ((buffer-read-only nil)
2100 (orig (buffer-substring start end))
2101 (trans (babel-as-string orig)))
2103 (narrow-to-region start end)
2104 (delete-region start end)
2107 (defun article-hide-signature (&optional arg)
2108 "Hide the signature in the current article.
2109 If given a negative prefix, always show; if given a positive prefix,
2111 (interactive (gnus-article-hidden-arg))
2112 (unless (gnus-article-check-hidden-text 'signature arg)
2115 (let ((buffer-read-only nil))
2116 (when (gnus-article-narrow-to-signature)
2117 (gnus-article-hide-text-type
2118 (point-min) (point-max) 'signature))))))
2119 (gnus-set-mode-line 'article))
2121 (defun article-strip-headers-in-body ()
2122 "Strip offensive headers from bodies."
2126 (let ((case-fold-search t))
2127 (when (looking-at "x-no-archive:")
2128 (gnus-delete-line)))))
2130 (defun article-strip-leading-blank-lines ()
2131 "Remove all blank lines from the beginning of the article."
2134 (let ((inhibit-point-motion-hooks t)
2136 (when (article-goto-body)
2137 (while (and (not (eobp))
2138 (looking-at "[ \t]*$"))
2139 (gnus-delete-line))))))
2141 (defun article-narrow-to-head ()
2142 "Narrow the buffer to the head of the message.
2143 Point is left at the beginning of the narrowed-to region."
2145 (goto-char (point-min))
2146 (if (search-forward "\n\n" nil 1)
2149 (goto-char (point-min)))
2151 (defun article-goto-body ()
2152 "Place point at the start of the body."
2153 (goto-char (point-min))
2155 ;; This variable is only bound when dealing with separate
2157 (article-goto-body-goes-to-point-min-p
2159 ((search-forward "\n\n" nil t)
2162 (goto-char (point-max))
2165 (defun article-strip-multiple-blank-lines ()
2166 "Replace consecutive blank lines with one empty line."
2169 (let ((inhibit-point-motion-hooks t)
2171 ;; First make all blank lines empty.
2173 (while (re-search-forward "^[ \t]+$" nil t)
2174 (unless (gnus-annotation-in-region-p
2175 (match-beginning 0) (match-end 0))
2176 (replace-match "" nil t)))
2177 ;; Then replace multiple empty lines with a single empty line.
2179 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2180 (unless (gnus-annotation-in-region-p
2181 (match-beginning 0) (match-end 0))
2182 (delete-region (match-beginning 1) (match-end 1)))))))
2184 (defun article-strip-leading-space ()
2185 "Remove all white space from the beginning of the lines in the article."
2188 (let ((inhibit-point-motion-hooks t)
2191 (while (re-search-forward "^[ \t]+" nil t)
2192 (replace-match "" t t)))))
2194 (defun article-strip-trailing-space ()
2195 "Remove all white space from the end of the lines in the article."
2198 (let ((inhibit-point-motion-hooks t)
2201 (while (re-search-forward "[ \t]+$" nil t)
2202 (replace-match "" t t)))))
2204 (defun article-strip-blank-lines ()
2205 "Strip leading, trailing and multiple blank lines."
2207 (article-strip-leading-blank-lines)
2208 (article-remove-trailing-blank-lines)
2209 (article-strip-multiple-blank-lines))
2211 (defun article-strip-all-blank-lines ()
2212 "Strip all blank lines."
2215 (let ((inhibit-point-motion-hooks t)
2218 (while (re-search-forward "^[ \t]*\n" nil t)
2219 (replace-match "" t t)))))
2221 (defun gnus-article-narrow-to-signature ()
2222 "Narrow to the signature; return t if a signature is found, else nil."
2223 (let ((inhibit-point-motion-hooks t))
2224 (when (gnus-article-search-signature)
2226 ;; Check whether we have some limits to what we consider
2227 ;; to be a signature.
2228 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2229 (list gnus-signature-limit)))
2231 (while (setq limit (pop limits))
2232 (if (or (and (integerp limit)
2233 (< (- (point-max) (point)) limit))
2235 (< (count-lines (point) (point-max)) limit))
2236 (and (gnus-functionp limit)
2238 (and (stringp limit)
2239 (not (re-search-forward limit nil t))))
2240 () ; This limit did not succeed.
2244 (narrow-to-region (point) (point-max))
2247 (defun gnus-article-search-signature ()
2248 "Search the current buffer for the signature separator.
2249 Put point at the beginning of the signature separator."
2250 (let ((cur (point)))
2251 (goto-char (point-max))
2252 (if (if (stringp gnus-signature-separator)
2253 (re-search-backward gnus-signature-separator nil t)
2254 (let ((seps gnus-signature-separator))
2256 (not (re-search-backward (car seps) nil t)))
2263 (defun gnus-article-hidden-arg ()
2264 "Return the current prefix arg as a number, or 0 if no prefix."
2265 (list (if current-prefix-arg
2266 (prefix-numeric-value current-prefix-arg)
2269 (defun gnus-article-check-hidden-text (type arg)
2270 "Return nil if hiding is necessary.
2271 Arg can be nil or a number. nil and positive means hide, negative
2272 means show, 0 means toggle."
2275 (let ((hide (gnus-article-hidden-text-p type)))
2281 (gnus-article-show-hidden-text type)
2284 (if (eq hide 'hidden)
2286 (gnus-article-show-hidden-text type)
2290 (defun gnus-article-hidden-text-p (type)
2291 "Say whether the current buffer contains hidden text of type TYPE."
2292 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2294 (not (get-text-property pos 'invisible))
2295 (not (get-text-property pos 'dummy-invisible)))
2297 (text-property-any (1+ pos) (point-max) 'article-type type)))
2302 (defun gnus-article-show-hidden-text (type &optional dummy)
2303 "Show all hidden text of type TYPE.
2304 Originally it is hide instead of DUMMY."
2305 (let ((buffer-read-only nil)
2306 (inhibit-point-motion-hooks t))
2307 (gnus-remove-text-properties-when
2309 (point-min) (point-max)
2310 (cons 'article-type (cons type
2311 gnus-hidden-properties)))
2312 (setq gnus-article-wash-types (delq type gnus-article-wash-types))))
2314 (defconst article-time-units
2315 `((year . ,(* 365.25 24 60 60))
2316 (week . ,(* 7 24 60 60))
2317 (day . ,(* 24 60 60))
2321 "Mapping from time units to seconds.")
2323 (defun article-date-ut (&optional type highlight header)
2324 "Convert DATE date to universal time in the current article.
2325 If TYPE is `local', convert to local time; if it is `lapsed', output
2326 how much time has lapsed since DATE. For `lapsed', the value of
2327 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2328 should replace the \"Date:\" one, or should be added below it."
2329 (interactive (list 'ut t))
2330 (let* ((header (or header
2331 (message-fetch-field "date")
2333 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2336 ((not gnus-article-date-lapsed-new-header)
2342 (date (if (vectorp header) (mail-header-date header)
2344 (inhibit-point-motion-hooks t)
2349 (article-narrow-to-head)
2350 (when (re-search-forward tdate-regexp nil t)
2351 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2352 date (or (get-text-property (gnus-point-at-bol)
2355 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2357 (when (and date (not (string= date "")))
2358 (goto-char (point-min))
2359 (let ((buffer-read-only nil))
2360 ;; Delete any old Date headers.
2361 (while (re-search-forward date-regexp nil t)
2363 (delete-region (progn (beginning-of-line) (point))
2364 (progn (forward-line 1) (point)))
2365 (delete-region (progn (beginning-of-line) (point))
2366 (progn (end-of-line) (point)))
2367 (setq pos (point))))
2368 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2370 (if pos (goto-char pos))
2371 (insert (article-make-date-line date (or type 'ut)))
2377 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2378 (put-text-property (match-beginning 1) (1+ (match-end 1))
2379 'original-date date)
2380 (put-text-property (match-beginning 1) (1+ (match-end 1))
2382 (put-text-property (match-beginning 2) (match-end 2)
2385 (defun article-make-date-line (date type)
2386 "Return a DATE line of TYPE."
2387 (unless (memq type '(local ut original user iso8601 lapsed english))
2388 (error "Unknown conversion type: %s" type))
2390 (let ((time (date-to-time date)))
2392 ;; Convert to the local timezone.
2394 (let ((tz (car (current-time-zone time))))
2395 (format "Date: %s %s%02d%02d" (current-time-string time)
2396 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2397 (/ (% (abs tz) 3600) 60))))
2398 ;; Convert to Universal Time.
2401 (current-time-string
2402 (let* ((e (parse-time-string date))
2403 (tm (apply 'encode-time e))
2405 (ls (- (cadr tm) (car (current-time-zone time)))))
2406 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2407 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2410 ;; Get the original date from the article.
2411 ((eq type 'original)
2412 (concat "Date: " (if (string-match "\n+$" date)
2413 (substring date 0 (match-beginning 0))
2415 ;; Let the user define the format.
2417 (if (gnus-functionp gnus-article-time-format)
2418 (funcall gnus-article-time-format time)
2421 (format-time-string gnus-article-time-format time))))
2424 (let ((tz (car (current-time-zone time))))
2427 (format-time-string "%Y%m%dT%H%M%S" time)
2428 (format "%s%02d%02d"
2429 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2430 (/ (% (abs tz) 3600) 60)))))
2431 ;; Do an X-Sent lapsed format.
2433 ;; If the date is seriously mangled, the timezone functions are
2434 ;; liable to bug out, so we ignore all errors.
2435 (let* ((now (current-time))
2436 (real-time (subtract-time now time))
2437 (real-sec (and real-time
2438 (+ (* (float (car real-time)) 65536)
2440 (sec (and real-time (abs real-sec)))
2450 ;; This is a bit convoluted, but basically we go
2451 ;; through the time units for years, weeks, etc,
2452 ;; and divide things to see whether that results
2453 ;; in positive answers.
2456 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2457 ;; The (remaining) seconds are too few to
2458 ;; be divided into this time unit.
2460 ;; It's big enough, so we output it.
2461 (setq sec (- sec (* num (cdr unit))))
2463 (concat (if prev ", " "") (int-to-string
2465 " " (symbol-name (car unit))
2466 (if (> num 1) "s" ""))
2468 article-time-units "")
2469 ;; If dates are odd, then it might appear like the
2470 ;; article was sent in the future.
2473 " in the future"))))))
2474 ;; Display the date in proper English
2476 (let ((dtime (decode-time time)))
2479 (number-to-string (nth 3 dtime))
2480 (let ((digit (% (nth 3 dtime) 10)))
2482 ((memq (nth 3 dtime) '(11 12 13)) "th")
2488 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2490 (number-to-string (nth 5 dtime))
2492 (format "%02d" (nth 2 dtime))
2494 (format "%02d" (nth 1 dtime)))))))
2496 (format "Date: %s (from Oort)" date))))
2498 (defun article-date-local (&optional highlight)
2499 "Convert the current article date to the local timezone."
2500 (interactive (list t))
2501 (article-date-ut 'local highlight))
2503 (defun article-date-english (&optional highlight)
2504 "Convert the current article date to something that is proper English."
2505 (interactive (list t))
2506 (article-date-ut 'english highlight))
2508 (defun article-date-original (&optional highlight)
2509 "Convert the current article date to what it was originally.
2510 This is only useful if you have used some other date conversion
2511 function and want to see what the date was before converting."
2512 (interactive (list t))
2513 (article-date-ut 'original highlight))
2515 (defun article-date-lapsed (&optional highlight)
2516 "Convert the current article date to time lapsed since it was sent."
2517 (interactive (list t))
2518 (article-date-ut 'lapsed highlight))
2520 (defun article-update-date-lapsed ()
2521 "Function to be run from a timer to update the lapsed time line."
2522 (let (deactivate-mark)
2527 (set-buffer (window-buffer w))
2528 (when (eq major-mode 'gnus-article-mode)
2529 (goto-char (point-min))
2530 (when (re-search-forward "^X-Sent:" nil t)
2531 (article-date-lapsed t))))
2534 (defun gnus-start-date-timer (&optional n)
2535 "Start a timer to update the X-Sent header in the article buffers.
2536 The numerical prefix says how frequently (in seconds) the function
2541 (gnus-stop-date-timer)
2542 (setq article-lapsed-timer
2543 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2545 (defun gnus-stop-date-timer ()
2546 "Stop the X-Sent timer."
2548 (when article-lapsed-timer
2549 (nnheader-cancel-timer article-lapsed-timer)
2550 (setq article-lapsed-timer nil)))
2552 (defun article-date-user (&optional highlight)
2553 "Convert the current article date to the user-defined format.
2554 This format is defined by the `gnus-article-time-format' variable."
2555 (interactive (list t))
2556 (article-date-ut 'user highlight))
2558 (defun article-date-iso8601 (&optional highlight)
2559 "Convert the current article date to ISO8601."
2560 (interactive (list t))
2561 (article-date-ut 'iso8601 highlight))
2563 (defun article-show-all ()
2564 "Show all hidden text in the article buffer."
2567 (let ((buffer-read-only nil))
2568 (gnus-article-unhide-text (point-min) (point-max)))))
2570 (defun article-remove-leading-whitespace ()
2571 "Remove excessive whitespace from all headers."
2575 (let ((buffer-read-only nil))
2576 (article-narrow-to-head)
2577 (goto-char (point-min))
2578 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2579 (delete-region (match-beginning 1) (match-end 1)))))))
2581 (defun article-emphasize (&optional arg)
2582 "Emphasize text according to `gnus-emphasis-alist'."
2583 (interactive (gnus-article-hidden-arg))
2584 (unless (gnus-article-check-hidden-text 'emphasis arg)
2588 (with-current-buffer gnus-summary-buffer
2589 gnus-article-emphasis-alist)
2591 gnus-emphasis-alist))
2592 (buffer-read-only nil)
2593 (props (append '(article-type emphasis)
2594 gnus-hidden-properties))
2595 regexp elem beg invisible visible face)
2598 (while (setq elem (pop alist))
2600 (setq regexp (car elem)
2601 invisible (nth 1 elem)
2602 visible (nth 2 elem)
2604 (while (re-search-forward regexp nil t)
2605 (when (and (match-beginning visible) (match-beginning invisible))
2606 (gnus-article-hide-text
2607 (match-beginning invisible) (match-end invisible) props)
2608 (gnus-article-unhide-text-type
2609 (match-beginning visible) (match-end visible) 'emphasis)
2610 (gnus-put-overlay-excluding-newlines
2611 (match-beginning visible) (match-end visible) 'face face)
2612 (push 'emphasis gnus-article-wash-types)
2613 (goto-char (match-end invisible)))))))))
2615 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2616 "Setup newsgroup emphasis alist."
2617 (unless gnus-article-emphasis-alist
2618 (let ((name (and gnus-newsgroup-name
2619 (gnus-group-real-name gnus-newsgroup-name))))
2620 (make-local-variable 'gnus-article-emphasis-alist)
2621 (setq gnus-article-emphasis-alist
2623 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2624 (while (setq elem (pop alist))
2625 (when (and name (string-match (car elem) name))
2627 highlight (copy-sequence (cdr elem)))))
2629 (copy-sequence highlight-words)
2630 (if gnus-newsgroup-name
2631 (copy-sequence (gnus-group-find-parameter
2632 gnus-newsgroup-name 'highlight-words t)))
2633 gnus-emphasis-alist)))))
2636 (defvar gnus-summary-article-menu)
2637 (defvar gnus-summary-post-menu))
2639 ;;; Saving functions.
2641 (defun gnus-article-save (save-buffer file &optional num)
2642 "Save the currently selected article."
2643 (unless gnus-save-all-headers
2644 ;; Remove headers according to `gnus-saved-headers'.
2645 (let ((gnus-visible-headers
2646 (or gnus-saved-headers gnus-visible-headers))
2647 (gnus-article-buffer save-buffer))
2649 (set-buffer save-buffer)
2650 (article-hide-headers 1 t))))
2651 (save-window-excursion
2652 (if (not gnus-default-article-saver)
2653 (error "No default saver is defined")
2654 ;; !!! Magic! The saving functions all save
2655 ;; `gnus-save-article-buffer' (or so they think), but we
2656 ;; bind that variable to our save-buffer.
2657 (set-buffer gnus-article-buffer)
2658 (let* ((gnus-save-article-buffer save-buffer)
2661 ((not gnus-prompt-before-saving) 'default)
2662 ((eq gnus-prompt-before-saving 'always) nil)
2664 (gnus-number-of-articles-to-be-saved
2665 (when (eq gnus-prompt-before-saving t)
2667 (set-buffer gnus-article-current-summary)
2668 (funcall gnus-default-article-saver filename)))))
2670 (defun gnus-read-save-file-name (prompt &optional filename
2671 function group headers variable)
2673 (funcall function group headers (symbol-value variable)))
2678 ((eq filename 'default)
2684 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2687 (if (and gnus-number-of-articles-to-be-saved
2688 (> gnus-number-of-articles-to-be-saved 1))
2689 (format "these %d articles"
2690 gnus-number-of-articles-to-be-saved)
2693 ;; Let the split methods have their say.
2695 ;; No split name was found.
2698 (concat prompt " (default "
2699 (file-name-nondirectory default-name) ") ")
2700 (file-name-directory default-name)
2702 ;; A single group name is returned.
2703 ((stringp split-name)
2705 (funcall function split-name headers
2706 (symbol-value variable)))
2708 (concat prompt " (default "
2709 (file-name-nondirectory default-name) ") ")
2710 (file-name-directory default-name)
2712 ;; A single split name was found
2713 ((= 1 (length split-name))
2714 (let* ((name (expand-file-name
2716 gnus-article-save-directory))
2717 (dir (cond ((file-directory-p name)
2718 (file-name-as-directory name))
2719 ((file-exists-p name) name)
2720 (t gnus-article-save-directory))))
2722 (concat prompt " (default " name ") ")
2724 ;; A list of splits was found.
2726 (setq split-name (nreverse split-name))
2728 (let ((file-name-history
2729 (nconc split-name file-name-history)))
2733 (concat prompt " (`M-p' for defaults) ")
2734 gnus-article-save-directory
2736 gnus-article-save-directory)))
2737 (car (push result file-name-history)))))))
2738 ;; Create the directory.
2739 (gnus-make-directory (file-name-directory file))
2740 ;; If we have read a directory, we append the default file name.
2741 (when (file-directory-p file)
2742 (setq file (expand-file-name (file-name-nondirectory
2744 (file-name-as-directory file))))
2745 ;; Possibly translate some characters.
2746 (nnheader-translate-file-chars file))))))
2747 (gnus-make-directory (file-name-directory result))
2748 (set variable result)))
2750 (defun gnus-article-archive-name (group)
2751 "Return the first instance of an \"Archive-name\" in the current buffer."
2752 (let ((case-fold-search t))
2753 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2754 (nnheader-concat gnus-article-save-directory
2755 (match-string 1)))))
2757 (defun gnus-article-nndoc-name (group)
2758 "If GROUP is an nndoc group, return the name of the parent group."
2759 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2760 (gnus-group-get-parameter group 'save-article-group)))
2762 (defun gnus-summary-save-in-rmail (&optional filename)
2763 "Append this article to Rmail file.
2764 Optional argument FILENAME specifies file name.
2765 Directory to save to is default to `gnus-article-save-directory'."
2766 (setq filename (gnus-read-save-file-name
2767 "Save %s in rmail file:" filename
2768 gnus-rmail-save-name gnus-newsgroup-name
2769 gnus-current-headers 'gnus-newsgroup-last-rmail))
2770 (gnus-eval-in-buffer-window gnus-save-article-buffer
2774 (gnus-output-to-rmail filename))))
2777 (defun gnus-summary-save-in-mail (&optional filename)
2778 "Append this article to Unix mail file.
2779 Optional argument FILENAME specifies file name.
2780 Directory to save to is default to `gnus-article-save-directory'."
2781 (setq filename (gnus-read-save-file-name
2782 "Save %s in Unix mail file:" filename
2783 gnus-mail-save-name gnus-newsgroup-name
2784 gnus-current-headers 'gnus-newsgroup-last-mail))
2785 (gnus-eval-in-buffer-window gnus-save-article-buffer
2789 (if (and (file-readable-p filename)
2790 (mail-file-babyl-p filename))
2791 (rmail-output-to-rmail-file filename t)
2792 (gnus-output-to-mail filename)))))
2795 (defun gnus-summary-save-in-file (&optional filename overwrite)
2796 "Append this article to file.
2797 Optional argument FILENAME specifies file name.
2798 Directory to save to is default to `gnus-article-save-directory'."
2799 (setq filename (gnus-read-save-file-name
2800 "Save %s in file:" filename
2801 gnus-file-save-name gnus-newsgroup-name
2802 gnus-current-headers 'gnus-newsgroup-last-file))
2803 (gnus-eval-in-buffer-window gnus-save-article-buffer
2807 (when (and overwrite
2808 (file-exists-p filename))
2809 (delete-file filename))
2810 (gnus-output-to-file filename))))
2813 (defun gnus-summary-write-to-file (&optional filename)
2814 "Write this article to a file, overwriting it if the file exists.
2815 Optional argument FILENAME specifies file name.
2816 The directory to save in defaults to `gnus-article-save-directory'."
2817 (gnus-summary-save-in-file nil t))
2819 (defun gnus-summary-save-body-in-file (&optional filename)
2820 "Append this article body to a file.
2821 Optional argument FILENAME specifies file name.
2822 The directory to save in defaults to `gnus-article-save-directory'."
2823 (setq filename (gnus-read-save-file-name
2824 "Save %s body 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 (article-goto-body)
2832 (narrow-to-region (point) (point-max)))
2833 (gnus-output-to-file filename))))
2836 (defun gnus-summary-save-in-pipe (&optional command)
2837 "Pipe this article to subprocess."
2839 (cond ((and (eq command 'default)
2840 gnus-last-shell-command)
2841 gnus-last-shell-command)
2846 "Shell command on %s: "
2847 (if (and gnus-number-of-articles-to-be-saved
2848 (> gnus-number-of-articles-to-be-saved 1))
2849 (format "these %d articles"
2850 gnus-number-of-articles-to-be-saved)
2852 gnus-last-shell-command))))
2853 (when (string-equal command "")
2854 (if gnus-last-shell-command
2855 (setq command gnus-last-shell-command)
2856 (error "A command is required")))
2857 (gnus-eval-in-buffer-window gnus-article-buffer
2860 (shell-command-on-region (point-min) (point-max) command nil)))
2861 (setq gnus-last-shell-command command))
2863 (defun gnus-summary-pipe-to-muttprint (&optional command)
2864 "Pipe this article to muttprint."
2865 (setq command (read-string
2866 "Print using command: " gnus-summary-muttprint-program
2867 nil gnus-summary-muttprint-program))
2868 (gnus-summary-save-in-pipe command))
2870 ;;; Article file names when saving.
2872 (defun gnus-capitalize-newsgroup (newsgroup)
2873 "Capitalize NEWSGROUP name."
2874 (when (not (zerop (length newsgroup)))
2875 (concat (char-to-string (upcase (aref newsgroup 0)))
2876 (substring newsgroup 1))))
2878 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2879 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2880 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2881 Otherwise, it is like ~/News/news/group/num."
2884 (concat (if (gnus-use-long-file-name 'not-save)
2885 (gnus-capitalize-newsgroup newsgroup)
2886 (gnus-newsgroup-directory-form newsgroup))
2887 "/" (int-to-string (mail-header-number headers)))
2888 gnus-article-save-directory)))
2890 (string-equal (file-name-directory default)
2891 (file-name-directory last-file))
2892 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2894 (or last-file default))))
2896 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2897 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2898 If variable `gnus-use-long-file-name' is non-nil, it is
2899 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2902 (concat (if (gnus-use-long-file-name 'not-save)
2904 (gnus-newsgroup-directory-form newsgroup))
2905 "/" (int-to-string (mail-header-number headers)))
2906 gnus-article-save-directory)))
2908 (string-equal (file-name-directory default)
2909 (file-name-directory last-file))
2910 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2912 (or last-file default))))
2914 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2915 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2916 If variable `gnus-use-long-file-name' is non-nil, it is
2917 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2920 (if (gnus-use-long-file-name 'not-save)
2923 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2925 gnus-article-save-directory)))
2927 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2928 "Generate file name from sender."
2929 (let ((from (mail-header-from headers)))
2931 (if (and from (string-match "\\([^ <]+\\)@" from))
2932 (match-string 1 from)
2934 gnus-article-save-directory)))
2936 (defun article-verify-x-pgp-sig ()
2939 (if (gnus-buffer-live-p gnus-original-article-buffer)
2940 (let ((sig (with-current-buffer gnus-original-article-buffer
2941 (gnus-fetch-field "X-PGP-Sig")))
2945 (mml2015-clear-verify-function))
2947 (insert-buffer gnus-original-article-buffer)
2948 (setq items (split-string sig))
2949 (message-narrow-to-head)
2950 (let ((inhibit-point-motion-hooks t)
2951 (case-fold-search t))
2952 ;; Don't verify multiple headers.
2953 (setq headers (mapconcat (lambda (header)
2955 (mail-fetch-field header) "\n"))
2956 (split-string (nth 1 items) ",") "")))
2957 (delete-region (point-min) (point-max))
2958 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2959 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2964 (if (looking-at "^-")
2967 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2968 (insert "Version: " (car items) "\n\n")
2969 (insert (mapconcat 'identity (cddr items) "\n"))
2970 (insert "\n-----END PGP SIGNATURE-----\n")
2971 (let ((mm-security-handle (list (format "multipart/signed"))))
2972 (mml2015-clean-buffer)
2973 (let ((coding-system-for-write (or gnus-newsgroup-charset
2975 (funcall (mml2015-clear-verify-function)))
2977 (or (mm-handle-multipart-ctl-parameter
2978 mm-security-handle 'gnus-details)
2979 (mm-handle-multipart-ctl-parameter
2980 mm-security-handle 'gnus-info)))))
2982 (let (buffer-read-only bface eface)
2984 (message-narrow-to-head)
2985 (goto-char (point-max))
2987 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2988 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2989 (message-remove-header "X-Gnus-PGP-Verify")
2990 (if (re-search-forward "^X-PGP-Sig:" nil t)
2992 (goto-char (point-max)))
2993 (narrow-to-region (point) (point))
2994 (insert "X-Gnus-PGP-Verify: " info "\n")
2995 (goto-char (point-min))
2998 (if (not (looking-at "^[ \t]"))
3002 (goto-char (point-min))
3003 (when (looking-at "\\([^:]+\\): *")
3004 (put-text-property (match-beginning 1) (1+ (match-end 1))
3006 (put-text-property (match-end 0) (point-max)
3007 'face eface)))))))))
3009 (defun article-verify-cancel-lock ()
3010 "Verify Cancel-Lock header."
3012 (if (gnus-buffer-live-p gnus-original-article-buffer)
3013 (canlock-verify gnus-original-article-buffer)))
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-verify-cancel-lock
3037 article-hide-boring-headers
3038 article-treat-overstrike
3039 article-fill-long-lines
3040 article-capitalize-sentences
3042 article-remove-leading-whitespace
3043 article-display-x-face
3044 article-de-quoted-unreadable
3045 article-de-base64-unreadable
3048 article-hide-list-identifiers
3050 article-strip-banner
3053 article-hide-signature
3054 article-strip-headers-in-body
3055 article-remove-trailing-blank-lines
3056 article-strip-leading-blank-lines
3057 article-strip-multiple-blank-lines
3058 article-strip-leading-space
3059 article-strip-trailing-space
3060 article-strip-blank-lines
3061 article-strip-all-blank-lines
3062 article-replace-with-quoted-text
3064 article-date-english
3065 article-date-iso8601
3066 article-date-original
3068 article-decode-mime-words
3069 article-decode-charset
3070 article-decode-encoded-words
3074 article-treat-dumbquotes
3075 article-normalize-headers
3076 (article-show-all . gnus-article-show-all-headers))))
3079 ;;; Gnus article mode
3082 (put 'gnus-article-mode 'mode-class 'special)
3084 (set-keymap-parent gnus-article-mode-map widget-keymap)
3086 (gnus-define-keys gnus-article-mode-map
3087 " " gnus-article-goto-next-page
3088 "\177" gnus-article-goto-prev-page
3089 [delete] gnus-article-goto-prev-page
3090 [backspace] gnus-article-goto-prev-page
3091 "\C-c^" gnus-article-refer-article
3092 "h" gnus-article-show-summary
3093 "s" gnus-article-show-summary
3094 "\C-c\C-m" gnus-article-mail
3095 "?" gnus-article-describe-briefly
3096 "e" gnus-summary-edit-article
3097 "<" beginning-of-buffer
3099 "\C-c\C-i" gnus-info-find-node
3101 "\C-hk" gnus-article-describe-key
3102 "\C-hc" gnus-article-describe-key-briefly
3104 "\C-d" gnus-article-read-summary-keys
3105 "\M-*" gnus-article-read-summary-keys
3106 "\M-#" gnus-article-read-summary-keys
3107 "\M-^" gnus-article-read-summary-keys
3108 "\M-g" gnus-article-read-summary-keys)
3110 (substitute-key-definition
3111 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3113 (defun gnus-article-make-menu-bar ()
3114 (unless (boundp 'gnus-article-commands-menu)
3115 (gnus-summary-make-menu-bar))
3116 (gnus-turn-off-edit-menu 'article)
3117 (unless (boundp 'gnus-article-article-menu)
3119 gnus-article-article-menu gnus-article-mode-map ""
3121 ["Scroll forwards" gnus-article-goto-next-page t]
3122 ["Scroll backwards" gnus-article-goto-prev-page t]
3123 ["Show summary" gnus-article-show-summary t]
3124 ["Fetch Message-ID at point" gnus-article-refer-article t]
3125 ["Mail to address at point" gnus-article-mail t]
3126 ["Send a bug report" gnus-bug t]))
3129 gnus-article-treatment-menu gnus-article-mode-map ""
3130 ;; Fixme: this should use :active (and maybe :visible).
3132 ["Hide headers" gnus-article-hide-headers t]
3133 ["Hide signature" gnus-article-hide-signature t]
3134 ["Hide citation" gnus-article-hide-citation t]
3135 ["Treat overstrike" gnus-article-treat-overstrike t]
3136 ["Remove carriage return" gnus-article-remove-cr t]
3137 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3138 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3139 ["Remove base64" gnus-article-de-base64-unreadable t]
3140 ["Treat html" gnus-article-wash-html t]
3141 ["Decode HZ" gnus-article-decode-HZ t]))
3143 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3145 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3147 (gnus-run-hooks 'gnus-article-menu-hook)))
3149 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3152 (defun gnus-article-mode ()
3153 "Major mode for displaying an article.
3155 All normal editing commands are switched off.
3157 The following commands are available in addition to all summary mode
3159 \\<gnus-article-mode-map>
3160 \\[gnus-article-next-page]\t Scroll the article one page forwards
3161 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3162 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3163 \\[gnus-article-show-summary]\t Display the summary buffer
3164 \\[gnus-article-mail]\t Send a reply to the address near point
3165 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3166 \\[gnus-info-find-node]\t Go to the Gnus info node"
3168 (gnus-simplify-mode-line)
3169 (setq mode-name "Article")
3170 (setq major-mode 'gnus-article-mode)
3171 (make-local-variable 'minor-mode-alist)
3172 (use-local-map gnus-article-mode-map)
3173 (when (gnus-visual-p 'article-menu 'menu)
3174 (gnus-article-make-menu-bar))
3175 (gnus-update-format-specifications nil 'article-mode)
3176 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3177 (make-local-variable 'gnus-page-broken)
3178 (make-local-variable 'gnus-button-marker-list)
3179 (make-local-variable 'gnus-article-current-summary)
3180 (make-local-variable 'gnus-article-mime-handles)
3181 (make-local-variable 'gnus-article-decoded-p)
3182 (make-local-variable 'gnus-article-mime-handle-alist)
3183 (make-local-variable 'gnus-article-wash-types)
3184 (make-local-variable 'gnus-article-charset)
3185 (make-local-variable 'gnus-article-ignored-charsets)
3186 (gnus-set-default-directory)
3187 (buffer-disable-undo)
3188 (setq buffer-read-only t)
3189 (set-syntax-table gnus-article-mode-syntax-table)
3190 (mm-enable-multibyte)
3191 (gnus-run-hooks 'gnus-article-mode-hook))
3193 (defun gnus-article-setup-buffer ()
3194 "Initialize the article buffer."
3195 (let* ((name (if gnus-single-article-buffer "*Article*"
3196 (concat "*Article " gnus-newsgroup-name "*")))
3198 (progn (string-match "\\*Article" name)
3199 (concat " *Original Article"
3200 (substring name (match-end 0))))))
3201 (setq gnus-article-buffer name)
3202 (setq gnus-original-article-buffer original)
3203 (setq gnus-article-mime-handle-alist nil)
3204 ;; This might be a variable local to the summary buffer.
3205 (unless gnus-single-article-buffer
3207 (set-buffer gnus-summary-buffer)
3208 (setq gnus-article-buffer name)
3209 (setq gnus-original-article-buffer original)
3210 (gnus-set-global-variables)))
3211 (gnus-article-setup-highlight-words)
3212 ;; Init original article buffer.
3214 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3215 (mm-enable-multibyte)
3216 (setq major-mode 'gnus-original-article-mode)
3217 (make-local-variable 'gnus-original-article))
3218 (if (get-buffer name)
3221 (when gnus-article-mime-handles
3222 (mm-destroy-parts gnus-article-mime-handles)
3223 (setq gnus-article-mime-handles nil))
3224 ;; Set it to nil in article-buffer!
3225 (setq gnus-article-mime-handle-alist nil)
3226 (buffer-disable-undo)
3227 (setq buffer-read-only t)
3228 (unless (eq major-mode 'gnus-article-mode)
3229 (gnus-article-mode))
3232 (set-buffer (gnus-get-buffer-create name))
3234 (make-local-variable 'gnus-summary-buffer)
3235 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3236 (current-buffer)))))
3238 ;; Set article window start at LINE, where LINE is the number of lines
3239 ;; from the head of the article.
3240 (defun gnus-article-set-window-start (&optional line)
3242 (gnus-get-buffer-window gnus-article-buffer t)
3244 (set-buffer gnus-article-buffer)
3245 (goto-char (point-min))
3248 (gnus-message 6 "Moved to bookmark")
3249 (search-forward "\n\n" nil t)
3253 (defun gnus-article-prepare (article &optional all-headers header)
3254 "Prepare ARTICLE in article mode buffer.
3255 ARTICLE should either be an article number or a Message-ID.
3256 If ARTICLE is an id, HEADER should be the article headers.
3257 If ALL-HEADERS is non-nil, no headers are hidden."
3259 ;; Make sure we start in a summary buffer.
3260 (unless (eq major-mode 'gnus-summary-mode)
3261 (set-buffer gnus-summary-buffer))
3262 (setq gnus-summary-buffer (current-buffer))
3263 (let* ((gnus-article (if header (mail-header-number header) article))
3264 (summary-buffer (current-buffer))
3265 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3266 (group gnus-newsgroup-name)
3269 (gnus-article-setup-buffer)
3270 (set-buffer gnus-article-buffer)
3271 ;; Deactivate active regions.
3272 (when (and (boundp 'transient-mark-mode)
3273 transient-mark-mode)
3274 (setq mark-active nil))
3275 (if (not (setq result (let ((buffer-read-only nil))
3276 (gnus-request-article-this-buffer
3278 ;; There is no such article.
3280 (when (and (numberp article)
3281 (not (memq article gnus-newsgroup-sparse)))
3282 (setq gnus-article-current
3283 (cons gnus-newsgroup-name article))
3284 (set-buffer gnus-summary-buffer)
3285 (setq gnus-current-article article)
3286 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3288 (gnus-summary-set-agent-mark article)
3289 (message "Message marked for downloading"))
3290 (gnus-summary-mark-article article gnus-canceled-mark)
3291 (unless (memq article gnus-newsgroup-sparse)
3292 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3293 (if (or (eq result 'pseudo)
3294 (eq result 'nneething))
3297 (set-buffer summary-buffer)
3298 (push article gnus-newsgroup-history)
3299 (setq gnus-last-article gnus-current-article
3300 gnus-current-article 0
3301 gnus-current-headers nil
3302 gnus-article-current nil)
3303 (if (eq result 'nneething)
3304 (gnus-configure-windows 'summary)
3305 (gnus-configure-windows 'article))
3306 (gnus-set-global-variables))
3307 (let ((gnus-article-mime-handle-alist-1
3308 gnus-article-mime-handle-alist))
3309 (gnus-set-mode-line 'article)))
3310 ;; The result from the `request' was an actual article -
3311 ;; or at least some text that is now displayed in the
3313 (when (and (numberp article)
3314 (not (eq article gnus-current-article)))
3315 ;; Seems like a new article has been selected.
3316 ;; `gnus-current-article' must be an article number.
3318 (set-buffer summary-buffer)
3319 (push article gnus-newsgroup-history)
3320 (setq gnus-last-article gnus-current-article
3321 gnus-current-article article
3322 gnus-current-headers
3323 (gnus-summary-article-header gnus-current-article)
3324 gnus-article-current
3325 (cons gnus-newsgroup-name gnus-current-article))
3326 (unless (vectorp gnus-current-headers)
3327 (setq gnus-current-headers nil))
3328 (gnus-summary-goto-subject gnus-current-article)
3329 (when (gnus-summary-show-thread)
3330 ;; If the summary buffer really was folded, the
3331 ;; previous goto may not actually have gone to
3332 ;; the right article, but the thread root instead.
3334 (gnus-summary-goto-subject gnus-current-article))
3335 (gnus-run-hooks 'gnus-mark-article-hook)
3336 (gnus-set-mode-line 'summary)
3337 (when (gnus-visual-p 'article-highlight 'highlight)
3338 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3339 ;; Set the global newsgroup variables here.
3340 (gnus-set-global-variables)
3341 (setq gnus-have-all-headers
3342 (or all-headers gnus-show-all-headers))))
3344 (gnus-configure-windows 'article))
3345 (when (or (numberp article)
3347 (gnus-article-prepare-display)
3349 (goto-char (point-min))
3350 (setq gnus-page-broken
3351 (when gnus-break-pages
3352 (gnus-narrow-to-page)
3354 (let ((gnus-article-mime-handle-alist-1
3355 gnus-article-mime-handle-alist))
3356 (gnus-set-mode-line 'article))
3358 (set-window-point (get-buffer-window (current-buffer)) (point))
3359 (gnus-configure-windows 'article)
3363 (defun gnus-article-prepare-display ()
3364 "Make the current buffer look like a nice article."
3365 ;; Hooks for getting information from the article.
3366 ;; This hook must be called before being narrowed.
3367 (let ((gnus-article-buffer (current-buffer))
3369 (unless (eq major-mode 'gnus-article-mode)
3370 (gnus-article-mode))
3371 (setq buffer-read-only nil
3372 gnus-article-wash-types nil)
3373 (gnus-run-hooks 'gnus-tmp-internal-hook)
3374 (when gnus-display-mime-function
3375 (funcall gnus-display-mime-function))
3376 (gnus-run-hooks 'gnus-article-prepare-hook)))
3379 ;;; Gnus MIME viewing functions
3382 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3383 "The following specs can be used:
3385 %T MIME type, along with additional info
3386 %n The `name' parameter
3387 %d The description, if any
3388 %l The length of the encoded part
3389 %p The part identifier number
3390 %e Dots if the part isn't displayed")
3392 (defvar gnus-mime-button-line-format-alist
3393 '((?t gnus-tmp-type ?s)
3394 (?T gnus-tmp-type-long ?s)
3395 (?n gnus-tmp-name ?s)
3396 (?d gnus-tmp-description ?s)
3398 (?l gnus-tmp-length ?d)
3399 (?e gnus-tmp-dots ?s)))
3401 (defvar gnus-mime-button-commands
3402 '((gnus-article-press-button "\r" "Toggle Display")
3403 (gnus-mime-view-part "v" "View Interactively...")
3404 (gnus-mime-view-part-as-type "t" "View As Type...")
3405 (gnus-mime-view-part-as-charset "C" "View As charset...")
3406 (gnus-mime-save-part "o" "Save...")
3407 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3408 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3409 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3410 (gnus-mime-internalize-part "E" "View Internally")
3411 (gnus-mime-externalize-part "e" "View Externally")
3412 (gnus-mime-pipe-part "|" "Pipe To Command...")
3413 (gnus-mime-action-on-part "." "Take action on the part")))
3415 (defun gnus-article-mime-part-status ()
3416 (if gnus-article-mime-handle-alist-1
3417 (if (eq 1 (length gnus-article-mime-handle-alist-1))
3419 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3422 (defvar gnus-mime-button-map
3423 (let ((map (make-sparse-keymap)))
3424 (unless (>= (string-to-number emacs-version) 21)
3425 ;; XEmacs doesn't care.
3426 (set-keymap-parent map gnus-article-mode-map))
3427 (define-key map gnus-mouse-2 'gnus-article-push-button)
3428 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3429 (dolist (c gnus-mime-button-commands)
3430 (define-key map (cadr c) (car c)))
3433 (defun gnus-mime-button-menu (event)
3434 "Construct a context-sensitive menu of MIME commands."
3436 (save-window-excursion
3437 (let ((pos (event-start event)))
3438 (select-window (posn-window pos))
3439 (goto-char (posn-point pos))
3440 (gnus-article-check-buffer)
3441 (let ((response (x-popup-menu
3443 ("" ,@(mapcar (lambda (c)
3444 (cons (caddr c) (car c)))
3445 gnus-mime-button-commands))))))
3447 (call-interactively response))))))
3449 (defun gnus-mime-view-all-parts (&optional handles)
3450 "View all the MIME parts."
3452 (save-current-buffer
3453 (set-buffer gnus-article-buffer)
3454 (let ((handles (or handles gnus-article-mime-handles))
3455 (mail-parse-charset gnus-newsgroup-charset)
3456 (mail-parse-ignored-charsets
3457 (with-current-buffer gnus-summary-buffer
3458 gnus-newsgroup-ignored-charsets)))
3460 (mm-remove-parts handles)
3461 (goto-char (point-min))
3462 (or (search-forward "\n\n") (goto-char (point-max)))
3463 (let (buffer-read-only)
3464 (delete-region (point) (point-max))
3465 (mm-display-parts handles))))))
3467 (defun gnus-mime-save-part-and-strip ()
3468 "Save the MIME part under point then replace it with an external body."
3470 (gnus-article-check-buffer)
3471 (let* ((data (get-text-property (point) 'gnus-data))
3473 (handles gnus-article-mime-handles))
3474 (if (mm-multiple-handles gnus-article-mime-handles)
3475 (error "This function is not implemented"))
3476 (setq file (and data (mm-save-part data)))
3478 (with-current-buffer (mm-handle-buffer data)
3480 (insert "Content-Type: " (mm-handle-media-type data))
3481 (mml-insert-parameter-string (cdr (mm-handle-type data))
3484 (insert "Content-ID: " (message-make-message-id) "\n")
3485 (insert "Content-Transfer-Encoding: binary\n")
3488 (cdr (mm-make-handle nil
3489 `("message/external-body"
3490 (access-type . "LOCAL-FILE")
3492 (set-buffer gnus-summary-buffer)
3493 (gnus-article-edit-article
3496 (let ((mail-parse-charset (or gnus-article-charset
3497 ',gnus-newsgroup-charset))
3498 (mail-parse-ignored-charsets
3499 (or gnus-article-ignored-charsets
3500 ',gnus-newsgroup-ignored-charsets))
3501 (mbl mml-buffer-list))
3502 (setq mml-buffer-list nil)
3503 (insert-buffer gnus-original-article-buffer)
3504 (mime-to-mml ',handles)
3505 (setq gnus-article-mime-handles nil)
3506 (let ((mbl1 mml-buffer-list))
3507 (setq mml-buffer-list mbl)
3508 (set (make-local-variable 'mml-buffer-list) mbl1))
3509 ;; LOCAL argument of add-hook differs between GNU Emacs
3510 ;; and XEmacs. make-local-hook makes sure they are local.
3511 (make-local-hook 'kill-buffer-hook)
3512 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3513 `(lambda (no-highlight)
3514 (let ((mail-parse-charset (or gnus-article-charset
3515 ',gnus-newsgroup-charset))
3516 (message-options message-options)
3517 (message-options-set-recipient)
3518 (mail-parse-ignored-charsets
3519 (or gnus-article-ignored-charsets
3520 ',gnus-newsgroup-ignored-charsets)))
3522 (mml-destroy-buffers)
3523 (remove-hook 'kill-buffer-hook
3524 'mml-destroy-buffers t)
3525 (kill-local-variable 'mml-buffer-list))
3526 (gnus-summary-edit-article-done
3527 ,(or (mail-header-references gnus-current-headers) "")
3528 ,(gnus-group-read-only-p)
3529 ,gnus-summary-buffer no-highlight))))))
3531 (defun gnus-mime-save-part ()
3532 "Save the MIME part under point."
3534 (gnus-article-check-buffer)
3535 (let ((data (get-text-property (point) 'gnus-data)))
3537 (mm-save-part data))))
3539 (defun gnus-mime-pipe-part ()
3540 "Pipe the MIME part under point to a process."
3542 (gnus-article-check-buffer)
3543 (let ((data (get-text-property (point) 'gnus-data)))
3545 (mm-pipe-part data))))
3547 (defun gnus-mime-view-part ()
3548 "Interactively choose a viewing method for the MIME part under point."
3550 (gnus-article-check-buffer)
3551 (let ((data (get-text-property (point) 'gnus-data)))
3553 (setq gnus-article-mime-handles
3555 gnus-article-mime-handles (setq data (copy-sequence data))))
3556 (mm-interactively-view-part data))))
3558 (defun gnus-mime-view-part-as-type-internal ()
3559 (gnus-article-check-buffer)
3560 (let* ((name (mail-content-type-get
3561 (mm-handle-type (get-text-property (point) 'gnus-data))
3563 (def-type (and name (mm-default-file-encoding name))))
3564 (and def-type (cons def-type 0))))
3566 (defun gnus-mime-view-part-as-type (&optional mime-type)
3567 "Choose a MIME media type, and view the part as such."
3570 (setq mime-type (completing-read
3571 "View as MIME type: "
3572 (mapcar #'list (mailcap-mime-types))
3574 (gnus-mime-view-part-as-type-internal))))
3575 (gnus-article-check-buffer)
3576 (let ((handle (get-text-property (point) 'gnus-data)))
3579 (mm-make-handle (mm-handle-buffer handle)
3580 (cons mime-type (cdr (mm-handle-type handle)))
3581 (mm-handle-encoding handle)
3582 (mm-handle-undisplayer handle)
3583 (mm-handle-disposition handle)
3584 (mm-handle-description handle)
3586 (mm-handle-id handle)))
3587 (setq gnus-article-mime-handles
3588 (mm-merge-handles gnus-article-mime-handles handle))
3589 (gnus-mm-display-part handle))))
3591 (defun gnus-mime-copy-part (&optional handle)
3592 "Put the the MIME part under point into a new buffer."
3594 (gnus-article-check-buffer)
3595 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3596 (contents (and handle (mm-get-part handle)))
3598 (file-name-nondirectory
3600 (mail-content-type-get (mm-handle-type handle) 'name)
3601 (mail-content-type-get (mm-handle-type handle)
3604 (buffer (and base (generate-new-buffer base))))
3606 (switch-to-buffer buffer)
3608 ;; We do it this way to make `normal-mode' set the appropriate mode.
3611 (setq buffer-file-name (expand-file-name base))
3613 (setq buffer-file-name nil))
3614 (goto-char (point-min)))))
3616 (defun gnus-mime-inline-part (&optional handle arg)
3617 "Insert the MIME part under point into the current buffer."
3618 (interactive (list nil current-prefix-arg))
3619 (gnus-article-check-buffer)
3620 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3625 (if (and (not arg) (mm-handle-undisplayer handle))
3626 (mm-remove-part handle)
3627 (setq contents (mm-get-part handle))
3630 (setq charset (or (mail-content-type-get
3631 (mm-handle-type handle) 'charset)
3632 gnus-newsgroup-charset)))
3634 (if (mm-handle-undisplayer handle)
3635 (mm-remove-part handle))
3638 gnus-summary-show-article-charset-alist))
3639 (mm-read-coding-system "Charset: ")))))
3641 (mm-insert-inline handle
3643 (setq charset (mm-charset-to-coding-system
3645 (not (eq charset 'ascii)))
3646 (mm-decode-coding-string contents charset)
3650 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3651 "Insert the MIME part under point into the current buffer using the
3653 (interactive (list nil current-prefix-arg))
3654 (gnus-article-check-buffer)
3655 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3660 (if (mm-handle-undisplayer handle)
3661 (mm-remove-part handle))
3662 (let ((gnus-newsgroup-charset
3664 gnus-summary-show-article-charset-alist))
3665 (mm-read-coding-system "Charset: ")))
3666 (gnus-newsgroup-ignored-charsets 'gnus-all))
3667 (gnus-article-press-button)))))
3669 (defun gnus-mime-externalize-part (&optional handle)
3670 "View the MIME part under point with an external viewer."
3672 (gnus-article-check-buffer)
3673 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3674 (mm-user-display-methods nil)
3675 (mm-inlined-types nil)
3676 (mail-parse-charset gnus-newsgroup-charset)
3677 (mail-parse-ignored-charsets
3678 (save-excursion (set-buffer gnus-summary-buffer)
3679 gnus-newsgroup-ignored-charsets)))
3681 (if (mm-handle-undisplayer handle)
3682 (mm-remove-part handle)
3683 (mm-display-part handle)))))
3685 (defun gnus-mime-internalize-part (&optional handle)
3686 "View the MIME part under point with an internal viewer.
3687 If no internal viewer is available, use an external viewer."
3689 (gnus-article-check-buffer)
3690 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3691 (mm-inlined-types '(".*"))
3692 (mm-inline-large-images t)
3693 (mail-parse-charset gnus-newsgroup-charset)
3694 (mail-parse-ignored-charsets
3695 (save-excursion (set-buffer gnus-summary-buffer)
3696 gnus-newsgroup-ignored-charsets)))
3698 (if (mm-handle-undisplayer handle)
3699 (mm-remove-part handle)
3700 (mm-display-part handle)))))
3702 (defun gnus-mime-action-on-part (&optional action)
3703 "Do something with the MIME attachment at \(point\)."
3705 (list (completing-read "Action: " gnus-mime-action-alist)))
3706 (gnus-article-check-buffer)
3707 (let ((action-pair (assoc action gnus-mime-action-alist)))
3709 (funcall (cdr action-pair)))))
3711 (defun gnus-article-part-wrapper (n function)
3712 (save-current-buffer
3713 (set-buffer gnus-article-buffer)
3714 (when (> n (length gnus-article-mime-handle-alist))
3715 (error "No such part"))
3716 (gnus-article-goto-part n)
3717 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3718 (funcall function handle))))
3720 (defun gnus-article-pipe-part (n)
3721 "Pipe MIME part N, which is the numerical prefix."
3723 (gnus-article-part-wrapper n 'mm-pipe-part))
3725 (defun gnus-article-save-part (n)
3726 "Save MIME part N, which is the numerical prefix."
3728 (gnus-article-part-wrapper n 'mm-save-part))
3730 (defun gnus-article-interactively-view-part (n)
3731 "View MIME part N interactively, which is the numerical prefix."
3733 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3735 (defun gnus-article-copy-part (n)
3736 "Copy MIME part N, which is the numerical prefix."
3738 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3740 (defun gnus-article-view-part-as-charset (n)
3741 "Copy MIME part N, which is the numerical prefix."
3743 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3745 (defun gnus-article-externalize-part (n)
3746 "View MIME part N externally, which is the numerical prefix."
3748 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3750 (defun gnus-article-inline-part (n)
3751 "Inline MIME part N, which is the numerical prefix."
3753 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3755 (defun gnus-article-mime-match-handle-first (condition)
3757 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3758 (while (setq ihandle (pop alist))
3760 ((functionp condition)
3761 (funcall condition (cdr ihandle)))
3762 ((eq condition 'undisplayed)
3763 (not (or (mm-handle-undisplayer (cdr ihandle))
3764 (equal (mm-handle-media-type (cdr ihandle))
3765 "multipart/alternative"))))
3766 ((eq condition 'undisplayed-alternative)
3767 (not (mm-handle-undisplayer (cdr ihandle))))
3769 (gnus-article-goto-part (car ihandle))
3770 (or (not n) (< (car ihandle) n)))
3771 (setq n (car ihandle))))
3775 (defun gnus-article-view-part (&optional n)
3776 "View MIME part N, which is the numerical prefix."
3778 (save-current-buffer
3779 (set-buffer gnus-article-buffer)
3780 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3781 gnus-article-mime-match-handle-function)))
3782 (when (> n (length gnus-article-mime-handle-alist))
3783 (error "No such part"))
3784 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3785 (when (gnus-article-goto-part n)
3786 (if (equal (car handle) "multipart/alternative")
3787 (gnus-article-press-button)
3788 (when (eq (gnus-mm-display-part handle) 'internal)
3789 (gnus-set-window-start)))))))
3791 (defsubst gnus-article-mime-total-parts ()
3792 (if (bufferp (car gnus-article-mime-handles))
3794 (1- (length gnus-article-mime-handles))))
3796 (defun gnus-mm-display-part (handle)
3797 "Display HANDLE and fix MIME button."
3798 (let ((id (get-text-property (point) 'gnus-part))
3803 (let ((window (selected-window))
3804 (mail-parse-charset gnus-newsgroup-charset)
3805 (mail-parse-ignored-charsets
3806 (save-excursion (set-buffer gnus-summary-buffer)
3807 gnus-newsgroup-ignored-charsets)))
3810 (let ((win (gnus-get-buffer-window (current-buffer) t))
3813 (select-window win))
3816 (if (mm-handle-displayed-p handle)
3817 ;; This will remove the part.
3818 (mm-display-part handle)
3820 (narrow-to-region (point)
3821 (if (eobp) (point) (1+ (point))))
3822 (mm-display-part handle)
3823 ;; We narrow to the part itself and
3824 ;; then call the treatment functions.
3825 (goto-char (point-min))
3827 (narrow-to-region (point) (point-max))
3830 (gnus-article-mime-total-parts)
3831 (mm-handle-media-type handle)))))
3832 (if (window-live-p window)
3833 (select-window window)))))
3835 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3836 (gnus-insert-mime-button
3837 handle id (list (mm-handle-displayed-p handle)))
3838 (goto-char point))))
3840 (defun gnus-article-goto-part (n)
3841 "Go to MIME part N."
3842 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3844 (goto-char point))))
3846 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3847 (let ((gnus-tmp-name
3848 (or (mail-content-type-get (mm-handle-type handle) 'name)
3849 (mail-content-type-get (mm-handle-disposition handle) 'filename)
3850 (mail-content-type-get (mm-handle-type handle) 'url)
3852 (gnus-tmp-type (mm-handle-media-type handle))
3853 (gnus-tmp-description
3854 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3857 (if (if displayed (car displayed)
3858 (mm-handle-displayed-p handle))
3860 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3862 gnus-tmp-type-long b e)
3863 (when (string-match ".*/" gnus-tmp-name)
3864 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3865 (setq gnus-tmp-type-long (concat gnus-tmp-type
3866 (and (not (equal gnus-tmp-name ""))
3867 (concat "; " gnus-tmp-name))))
3868 (unless (equal gnus-tmp-description "")
3869 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3874 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3875 `(keymap ,gnus-mime-button-map
3876 ,@(if (>= (string-to-number emacs-version) 21)
3878 (list 'local-map gnus-mime-button-map))
3879 gnus-callback gnus-mm-display-part
3880 gnus-part ,gnus-tmp-id
3881 article-type annotation
3884 (widget-convert-button
3887 :action 'gnus-widget-press-button
3888 :button-keymap gnus-mime-button-map
3890 (lambda (widget/window &optional overlay pos)
3891 ;; Needed to properly clear the message due to a bug in
3892 ;; wid-edit (XEmacs only).
3893 (if (boundp 'help-echo-owns-message)
3894 (setq help-echo-owns-message t))
3896 "%S: %s the MIME part; %S: more options"
3897 (aref gnus-mouse-2 0)
3898 ;; XEmacs will get a single widget arg; Emacs 21 will get
3899 ;; window, overlay, position.
3900 (if (mm-handle-displayed-p
3902 (with-current-buffer (gnus-overlay-buffer overlay)
3903 (widget-get (widget-at (gnus-overlay-start overlay))
3905 (widget-get widget/window :mime-handle)))
3907 (aref gnus-down-mouse-3 0))))))
3909 (defun gnus-widget-press-button (elems el)
3910 (goto-char (widget-get elems :from))
3911 (gnus-article-press-button))
3913 (defvar gnus-displaying-mime nil)
3915 (defun gnus-display-mime (&optional ihandles)
3916 "Display the MIME parts."
3918 (save-selected-window
3919 (let ((window (get-buffer-window gnus-article-buffer))
3922 (select-window window)
3923 ;; We have to do this since selecting the window
3924 ;; may change the point. So we set the window point.
3925 (set-window-point window point)))
3926 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3927 buffer-read-only handle name type b e display)
3928 (when (and (not ihandles)
3929 (not gnus-displaying-mime))
3930 ;; Top-level call; we clean up.
3931 (when gnus-article-mime-handles
3932 (mm-destroy-parts gnus-article-mime-handles)
3933 (setq gnus-article-mime-handle-alist nil));; A trick.
3934 (setq gnus-article-mime-handles handles)
3935 ;; We allow users to glean info from the handles.
3936 (when gnus-article-mime-part-function
3937 (gnus-mime-part-function handles)))
3939 (or (not (stringp (car handles)))
3942 (when (and (not ihandles)
3943 (not gnus-displaying-mime))
3944 ;; Clean up for mime parts.
3946 (delete-region (point) (point-max)))
3947 (let ((gnus-displaying-mime t))
3948 (gnus-mime-display-part handles)))
3951 (narrow-to-region (point) (point-max))
3952 (gnus-treat-article nil 1 1)
3955 ;; Highlight the headers.
3959 (narrow-to-region (point-min) (point))
3960 (gnus-treat-article 'head))))))))
3962 (defvar gnus-mime-display-multipart-as-mixed nil)
3963 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
3964 (defvar gnus-mime-display-multipart-related-as-mixed nil)
3966 (defun gnus-mime-display-part (handle)
3969 ((not (stringp (car handle)))
3970 (gnus-mime-display-single handle))
3971 ;; User-defined multipart
3972 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3973 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3975 ;; multipart/alternative
3976 ((and (equal (car handle) "multipart/alternative")
3977 (not (or gnus-mime-display-multipart-as-mixed
3978 gnus-mime-display-multipart-alternative-as-mixed)))
3979 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3980 (push (cons id handle) gnus-article-mime-handle-alist)
3981 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3982 ;; multipart/related
3983 ((and (equal (car handle) "multipart/related")
3984 (not (or gnus-mime-display-multipart-as-mixed
3985 gnus-mime-display-multipart-related-as-mixed)))
3986 ;;;!!!We should find the start part, but we just default
3987 ;;;!!!to the first part.
3988 ;;(gnus-mime-display-part (cadr handle))
3989 ;;;!!! Most multipart/related is an HTML message plus images.
3990 ;;;!!! Unfortunately we are unable to let W3 display those
3991 ;;;!!! included images, so we just display it as a mixed multipart.
3992 ;;(gnus-mime-display-mixed (cdr handle))
3993 ;;;!!! No, w3 can display everything just fine.
3994 (gnus-mime-display-part (cadr handle)))
3995 ((equal (car handle) "multipart/signed")
3996 (or (memq 'signed gnus-article-wash-types)
3997 (push 'signed gnus-article-wash-types))
3998 (gnus-mime-display-security handle))
3999 ((equal (car handle) "multipart/encrypted")
4000 (or (memq 'encrypted gnus-article-wash-types)
4001 (push 'encrypted gnus-article-wash-types))
4002 (gnus-mime-display-security handle))
4003 ;; Other multiparts are handled like multipart/mixed.
4005 (gnus-mime-display-mixed (cdr handle)))))
4007 (defun gnus-mime-part-function (handles)
4008 (if (stringp (car handles))
4009 (mapcar 'gnus-mime-part-function (cdr handles))
4010 (funcall gnus-article-mime-part-function handles)))
4012 (defun gnus-mime-display-mixed (handles)
4013 (mapcar 'gnus-mime-display-part handles))
4015 (defun gnus-mime-display-single (handle)
4016 (let ((type (mm-handle-media-type handle))
4017 (ignored gnus-ignored-mime-types)
4024 (when (string-match (pop ignored) type)
4025 (throw 'ignored nil)))
4026 (if (and (setq not-attachment
4027 (and (not (mm-inline-override-p handle))
4028 (or (not (mm-handle-disposition handle))
4029 (equal (car (mm-handle-disposition handle))
4031 (mm-attachment-override-p handle))))
4032 (mm-automatic-display-p handle)
4034 (mm-inlinable-p handle)
4035 (mm-inlined-p handle))
4036 (mm-automatic-external-display-p type)))
4038 (when (equal (mm-handle-media-supertype handle) "text")
4040 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4042 (push (cons id handle) gnus-article-mime-handle-alist)
4043 (when (or (not display)
4044 (not (gnus-unbuttonized-mime-type-p type)))
4045 ;(gnus-article-insert-newline)
4046 (gnus-insert-mime-button
4047 handle id (list (or display (and not-attachment text))))
4048 (gnus-article-insert-newline)
4049 ;(gnus-article-insert-newline)
4050 ;; Remember modify the number of forward lines.
4058 (let ((mail-parse-charset gnus-newsgroup-charset)
4059 (mail-parse-ignored-charsets
4060 (save-excursion (condition-case ()
4061 (set-buffer gnus-summary-buffer)
4063 gnus-newsgroup-ignored-charsets)))
4064 (mm-display-part handle t))
4065 (goto-char (point-max)))
4066 ((and text not-attachment)
4070 (gnus-article-insert-newline)
4071 (mm-insert-inline handle (mm-get-part handle))
4072 (goto-char (point-max))))
4076 (narrow-to-region beg (point))
4079 (gnus-article-mime-total-parts)
4080 (mm-handle-media-type handle)))))))))
4082 (defun gnus-unbuttonized-mime-type-p (type)
4083 "Say whether TYPE is to be unbuttonized."
4084 (unless gnus-inhibit-mime-unbuttonizing
4086 (let ((types gnus-unbuttonized-mime-types))
4088 (when (string-match (pop types) type)
4089 (throw 'found t)))))
4091 (let ((types gnus-buttonized-mime-types))
4093 (when (string-match (pop types) type)
4094 (throw 'found t)))))))))
4096 (defun gnus-article-insert-newline ()
4097 "Insert a newline, but mark it as undeletable."
4098 (gnus-put-text-property
4099 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4101 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4102 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4105 handle buffer-read-only from props begend not-pref)
4106 (save-window-excursion
4109 (narrow-to-region (car ibegend)
4112 (goto-char (car ibegend))
4115 (delete-region (point-min) (point-max))
4116 (mm-remove-parts handles))
4117 (setq begend (list (point-marker)))
4119 (unless (setq not-pref (cadr (member preferred ihandles)))
4120 (setq not-pref (car ihandles)))
4123 (not (gnus-unbuttonized-mime-type-p
4124 "multipart/alternative")))
4125 (gnus-add-text-properties
4128 (insert (format "%d. " id))
4132 (unless ,(not ibegend)
4133 (setq gnus-article-mime-handle-alist
4134 ',gnus-article-mime-handle-alist))
4135 (gnus-mime-display-alternative
4136 ',ihandles ',not-pref ',begend ,id))
4137 ,@(if (>= (string-to-number emacs-version) 21)
4138 nil ;; XEmacs doesn't care
4139 (list 'local-map gnus-mime-button-map))
4140 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4141 face ,gnus-article-button-face
4142 keymap ,gnus-mime-button-map
4145 (widget-convert-button 'link from (point)
4146 :action 'gnus-widget-press-button
4147 :button-keymap gnus-widget-button-keymap)
4149 (while (setq handle (pop handles))
4150 (gnus-add-text-properties
4153 (insert (format "(%c) %-18s"
4154 (if (equal handle preferred) ?* ? )
4155 (mm-handle-media-type handle)))
4159 (unless ,(not ibegend)
4160 (setq gnus-article-mime-handle-alist
4161 ',gnus-article-mime-handle-alist))
4162 (gnus-mime-display-alternative
4163 ',ihandles ',handle ',begend ,id))
4164 ,@(if (>= (string-to-number emacs-version) 21)
4165 nil ;; XEmacs doesn't care
4166 (list 'local-map gnus-mime-button-map))
4167 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4168 face ,gnus-article-button-face
4169 keymap ,gnus-mime-button-map
4172 (widget-convert-button 'link from (point)
4173 :action 'gnus-widget-press-button
4174 :button-keymap gnus-widget-button-keymap)
4178 (if (stringp (car preferred))
4179 (gnus-display-mime preferred)
4180 (let ((mail-parse-charset gnus-newsgroup-charset)
4181 (mail-parse-ignored-charsets
4182 (save-excursion (set-buffer gnus-summary-buffer)
4183 gnus-newsgroup-ignored-charsets)))
4184 (mm-display-part preferred)
4188 (narrow-to-region (car begend) (point-max))
4190 nil (length gnus-article-mime-handle-alist)
4191 (gnus-article-mime-total-parts)
4192 (mm-handle-media-type handle))))))
4193 (goto-char (point-max))
4194 (setcdr begend (point-marker)))))
4196 (goto-char point))))
4198 (defconst gnus-article-wash-status-strings
4199 (let ((alist '((cite "c" "Possible hidden citation text"
4200 " " "All citation text visible")
4201 (headers "h" "Hidden headers"
4202 " " "All headers visible.")
4203 (pgp "p" "Encrypted or signed message status hidden"
4204 " " "No hidden encryption nor digital signature status")
4205 (signature "s" "Signature has been hidden"
4206 " " "Signature is visible")
4207 (overstrike "o" "Overstrike (^H) characters applied"
4208 " " "No overstrike characters applied")
4209 (emphasis "e" "/*_Emphasis_*/ characters applied"
4210 " " "No /*_emphasis_*/ characters applied")))
4212 (dolist (entry alist result)
4213 (let ((key (nth 0 entry))
4214 (on (copy-sequence (nth 1 entry)))
4215 (on-help (nth 2 entry))
4216 (off (copy-sequence (nth 3 entry)))
4217 (off-help (nth 4 entry)))
4218 (put-text-property 0 1 'help-echo on-help on)
4219 (put-text-property 0 1 'help-echo off-help off)
4220 (push (list key on off) result))))
4221 "Alist of strings describing wash status in the mode line.
4222 Each entry has the form (KEY ON OF), where the KEY is a symbol
4223 representing the particular washing function, ON is the string to use
4224 in the article mode line when the washing function is active, and OFF
4225 is the string to use when it is inactive.")
4227 (defun gnus-gnus-article-wash-status-entry (key value)
4228 (let ((entry (assoc key gnus-article-wash-status-strings)))
4229 (if value (nth 1 entry) (nth 2 entry))))
4231 (defun gnus-article-wash-status ()
4232 "Return a string which display status of article washing."
4234 (set-buffer gnus-article-buffer)
4235 (let ((cite (memq 'cite gnus-article-wash-types))
4236 (headers (memq 'headers gnus-article-wash-types))
4237 (boring (memq 'boring-headers gnus-article-wash-types))
4238 (pgp (memq 'pgp gnus-article-wash-types))
4239 (pem (memq 'pem gnus-article-wash-types))
4240 (signed (memq 'signed gnus-article-wash-types))
4241 (encrypted (memq 'encrypted gnus-article-wash-types))
4242 (signature (memq 'signature gnus-article-wash-types))
4243 (overstrike (memq 'overstrike gnus-article-wash-types))
4244 (emphasis (memq 'emphasis gnus-article-wash-types)))
4245 (concat (gnus-gnus-article-wash-status-entry 'cite cite)
4246 (gnus-gnus-article-wash-status-entry 'headers
4247 (or headers boring))
4248 (gnus-gnus-article-wash-status-entry
4249 'pgp (or pgp pem signed encrypted))
4250 (gnus-gnus-article-wash-status-entry 'signature signature)
4251 (gnus-gnus-article-wash-status-entry 'overstrike overstrike)
4252 (gnus-gnus-article-wash-status-entry 'emphasis emphasis)))))
4254 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4256 (defun gnus-article-maybe-hide-headers ()
4257 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4258 Provided for backwards compatibility."
4259 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4260 (not (save-excursion (set-buffer gnus-summary-buffer)
4261 gnus-have-all-headers)))
4262 (not gnus-inhibit-hiding))
4263 (gnus-article-hide-headers)))
4267 (defun gnus-output-to-file (file-name)
4268 "Append the current article to a file named FILE-NAME."
4269 (let ((artbuf (current-buffer)))
4271 (insert-buffer-substring artbuf)
4272 ;; Append newline at end of the buffer as separator, and then
4274 (goto-char (point-max))
4276 (let ((file-name-coding-system nnmail-pathname-coding-system))
4277 (mm-append-to-file (point-min) (point-max) file-name))
4280 (defun gnus-narrow-to-page (&optional arg)
4281 "Narrow the article buffer to a page.
4282 If given a numerical ARG, move forward ARG pages."
4284 (setq arg (if arg (prefix-numeric-value arg) 0))
4286 (set-buffer gnus-article-buffer)
4287 (goto-char (point-min))
4289 ;; Remove any old next/prev buttons.
4290 (when (gnus-visual-p 'page-marker)
4291 (let ((buffer-read-only nil))
4292 (gnus-remove-text-with-property 'gnus-prev)
4293 (gnus-remove-text-with-property 'gnus-next)))
4296 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4298 (re-search-forward page-delimiter nil 'move arg)))
4299 (goto-char (match-end 0)))
4302 (if (re-search-forward page-delimiter nil 'move)
4305 (when (and (gnus-visual-p 'page-marker)
4306 (not (= (point-min) 1)))
4308 (goto-char (point-min))
4309 (gnus-insert-prev-page-button)))
4310 (when (and (gnus-visual-p 'page-marker)
4311 (< (+ (point-max) 2) (buffer-size)))
4313 (goto-char (point-max))
4314 (gnus-insert-next-page-button)))))
4316 ;; Article mode commands
4318 (defun gnus-article-goto-next-page ()
4319 "Show the next page of the article."
4321 (when (gnus-article-next-page)
4322 (goto-char (point-min))
4323 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4325 (defun gnus-article-goto-prev-page ()
4326 "Show the next page of the article."
4328 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4329 (gnus-article-prev-page nil)))
4331 (defun gnus-article-next-page (&optional lines)
4332 "Show the next page of the current article.
4333 If end of article, return non-nil. Otherwise return nil.
4334 Argument LINES specifies lines to be scrolled up."
4336 (move-to-window-line -1)
4339 (and (pos-visible-in-window-p) ;Not continuation line.
4341 ;; Nothing in this page.
4342 (if (or (not gnus-page-broken)
4345 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4347 (gnus-narrow-to-page 1) ;Go to next page.
4349 ;; More in this page.
4350 (let ((scroll-in-place nil))
4354 ;; Long lines may cause an end-of-buffer error.
4355 (goto-char (point-max)))))
4356 (move-to-window-line 0)
4359 (defun gnus-article-prev-page (&optional lines)
4360 "Show previous page of current article.
4361 Argument LINES specifies lines to be scrolled down."
4363 (move-to-window-line 0)
4364 (if (and gnus-page-broken
4366 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4368 (gnus-narrow-to-page -1) ;Go to previous page.
4369 (goto-char (point-max))
4371 (let ((scroll-in-place nil))
4375 (beginning-of-buffer
4376 (goto-char (point-min))))
4377 (move-to-window-line 0)))))
4379 (defun gnus-article-refer-article ()
4380 "Read article specified by message-id around point."
4382 (let ((point (point)))
4383 (search-forward ">" nil t) ;Move point to end of "<....>".
4384 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4385 (let ((message-id (match-string 1)))
4387 (set-buffer gnus-summary-buffer)
4388 (gnus-summary-refer-article message-id))
4390 (error "No references around point"))))
4392 (defun gnus-article-show-summary ()
4393 "Reconfigure windows to show summary buffer."
4395 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4396 (error "There is no summary buffer for this article buffer")
4397 (gnus-article-set-globals)
4398 (gnus-configure-windows 'article)
4399 (gnus-summary-goto-subject gnus-current-article)
4400 (gnus-summary-position-point)))
4402 (defun gnus-article-describe-briefly ()
4403 "Describe article mode commands briefly."
4405 (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")))
4407 (defun gnus-article-summary-command ()
4408 "Execute the last keystroke in the summary buffer."
4410 (let ((obuf (current-buffer))
4411 (owin (current-window-configuration))
4413 (switch-to-buffer gnus-article-current-summary 'norecord)
4414 (setq func (lookup-key (current-local-map) (this-command-keys)))
4415 (call-interactively func)
4417 (set-window-configuration owin)
4418 (set-window-point (get-buffer-window (current-buffer)) (point))))
4420 (defun gnus-article-summary-command-nosave ()
4421 "Execute the last keystroke in the summary buffer."
4424 (pop-to-buffer gnus-article-current-summary 'norecord)
4425 (setq func (lookup-key (current-local-map) (this-command-keys)))
4426 (call-interactively func)))
4428 (defun gnus-article-check-buffer ()
4429 "Beep if not in an article buffer."
4430 (unless (equal major-mode 'gnus-article-mode)
4431 (error "Command invoked outside of a Gnus article buffer")))
4433 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4434 "Read a summary buffer key sequence and execute it from the article buffer."
4436 (gnus-article-check-buffer)
4438 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4439 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4440 "=" "^" "\M-^" "|"))
4446 '("n" "Gn" "p" "Gp"))
4449 (set-buffer gnus-article-current-summary)
4450 (let (gnus-pick-mode)
4451 (push (or key last-command-event) unread-command-events)
4452 (setq keys (if (featurep 'xemacs)
4453 (events-to-keys (read-key-sequence nil))
4454 (read-key-sequence nil)))))
4458 (if (or (member keys nosaves)
4459 (member keys nosave-but-article)
4460 (member keys nosave-in-article))
4462 (save-window-excursion
4463 (pop-to-buffer gnus-article-current-summary 'norecord)
4464 ;; We disable the pick minor mode commands.
4465 (let (gnus-pick-mode)
4466 (setq func (lookup-key (current-local-map) keys))))
4470 (unless (member keys nosave-in-article)
4471 (set-buffer gnus-article-current-summary))
4472 (call-interactively func)
4473 (setq new-sum-point (point)))
4474 (when (member keys nosave-but-article)
4475 (pop-to-buffer gnus-article-buffer 'norecord)))
4476 ;; These commands should restore window configuration.
4477 (let ((obuf (current-buffer))
4478 (owin (current-window-configuration))
4480 (summary gnus-article-current-summary)
4481 func in-buffer selected)
4482 (if not-restore-window
4483 (pop-to-buffer summary 'norecord)
4484 (switch-to-buffer summary 'norecord))
4485 (setq in-buffer (current-buffer))
4486 ;; We disable the pick minor mode commands.
4487 (if (and (setq func (let (gnus-pick-mode)
4488 (lookup-key (current-local-map) keys)))
4491 (call-interactively func)
4492 (setq new-sum-point (point))
4493 (when (eq in-buffer (current-buffer))
4494 (setq selected (gnus-summary-select-article))
4496 (unless not-restore-window
4497 (set-window-configuration owin))
4498 (when (eq selected 'old)
4500 (set-window-start (get-buffer-window (current-buffer))
4502 (set-window-point (get-buffer-window (current-buffer))
4504 (let ((win (get-buffer-window gnus-article-current-summary)))
4506 (set-window-point win new-sum-point)))) )
4507 (switch-to-buffer gnus-article-buffer)
4510 (defun gnus-article-describe-key (key)
4511 "Display documentation of the function invoked by KEY. KEY is a string."
4512 (interactive "kDescribe key: ")
4513 (gnus-article-check-buffer)
4514 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4516 (set-buffer gnus-article-current-summary)
4517 (let (gnus-pick-mode)
4518 (if (featurep 'xemacs)
4520 (push (elt key 0) unread-command-events)
4521 (setq key (events-to-keys
4522 (read-key-sequence "Describe key: "))))
4523 (setq unread-command-events
4525 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4526 (string-to-list key)))
4527 (setq key (read-key-sequence "Describe key: "))))
4529 (describe-key key)))
4531 (defun gnus-article-describe-key-briefly (key &optional insert)
4532 "Display documentation of the function invoked by KEY. KEY is a string."
4533 (interactive "kDescribe key: \nP")
4534 (gnus-article-check-buffer)
4535 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4537 (set-buffer gnus-article-current-summary)
4538 (let (gnus-pick-mode)
4539 (if (featurep 'xemacs)
4541 (push (elt key 0) unread-command-events)
4542 (setq key (events-to-keys
4543 (read-key-sequence "Describe key: "))))
4544 (setq unread-command-events
4546 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4547 (string-to-list key)))
4548 (setq key (read-key-sequence "Describe key: "))))
4549 (describe-key-briefly key insert))
4550 (describe-key-briefly key insert)))
4552 (defun gnus-article-hide (&optional arg force)
4553 "Hide all the gruft in the current article.
4554 This means that PGP stuff, signatures, cited text and (some)
4555 headers will be hidden.
4556 If given a prefix, show the hidden text instead."
4557 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4558 (gnus-article-hide-headers arg)
4559 (gnus-article-hide-list-identifiers arg)
4560 (gnus-article-hide-pgp arg)
4561 (gnus-article-hide-citation-maybe arg force)
4562 (gnus-article-hide-signature arg))
4564 (defun gnus-article-maybe-highlight ()
4565 "Do some article highlighting if article highlighting is requested."
4566 (when (gnus-visual-p 'article-highlight 'highlight)
4567 (gnus-article-highlight-some)))
4569 (defun gnus-check-group-server ()
4570 ;; Make sure the connection to the server is alive.
4571 (unless (gnus-server-opened
4572 (gnus-find-method-for-group gnus-newsgroup-name))
4573 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4574 (gnus-request-group gnus-newsgroup-name t)))
4576 (defun gnus-request-article-this-buffer (article group)
4577 "Get an article and insert it into this buffer."
4578 (let (do-update-line sparse-header)
4582 (gnus-kill-all-overlays)
4583 (setq group (or group gnus-newsgroup-name))
4585 ;; Using `gnus-request-article' directly will insert the article into
4586 ;; `nntp-server-buffer' - so we'll save some time by not having to
4587 ;; copy it from the server buffer into the article buffer.
4589 ;; We only request an article by message-id when we do not have the
4590 ;; headers for it, so we'll have to get those.
4591 (when (stringp article)
4592 (gnus-read-header article))
4594 ;; If the article number is negative, that means that this article
4595 ;; doesn't belong in this newsgroup (possibly), so we find its
4596 ;; message-id and request it by id instead of number.
4597 (when (and (numberp article)
4599 (get-buffer gnus-summary-buffer)
4600 (gnus-buffer-exists-p gnus-summary-buffer))
4602 (set-buffer gnus-summary-buffer)
4603 (let ((header (gnus-summary-article-header article)))
4606 ((memq article gnus-newsgroup-sparse)
4607 ;; This is a sparse gap article.
4608 (setq do-update-line article)
4609 (setq article (mail-header-id header))
4610 (setq sparse-header (gnus-read-header article))
4611 (setq gnus-newsgroup-sparse
4612 (delq article gnus-newsgroup-sparse)))
4614 ;; It's a real article.
4615 (setq article (mail-header-id header)))
4617 ;; It is an extracted pseudo-article.
4618 (setq article 'pseudo)
4619 (gnus-request-pseudo-article header))))
4621 (let ((method (gnus-find-method-for-group
4622 gnus-newsgroup-name)))
4623 (when (and (eq (car method) 'nneething)
4625 (let ((dir (expand-file-name
4626 (mail-header-subject header)
4627 (file-name-as-directory
4628 (or (cadr (assq 'nneething-address method))
4630 (when (file-directory-p dir)
4631 (setq article 'nneething)
4632 (gnus-group-enter-directory dir))))))))
4635 ;; Refuse to select canceled articles.
4636 ((and (numberp article)
4638 (get-buffer gnus-summary-buffer)
4639 (gnus-buffer-exists-p gnus-summary-buffer)
4640 (eq (cdr (save-excursion
4641 (set-buffer gnus-summary-buffer)
4642 (assq article gnus-newsgroup-reads)))
4643 gnus-canceled-mark))
4645 ;; We first check `gnus-original-article-buffer'.
4646 ((and (get-buffer gnus-original-article-buffer)
4649 (set-buffer gnus-original-article-buffer)
4650 (and (equal (car gnus-original-article) group)
4651 (eq (cdr gnus-original-article) article))))
4652 (insert-buffer-substring gnus-original-article-buffer)
4654 ;; Check the backlog.
4655 ((and gnus-keep-backlog
4656 (gnus-backlog-request-article group article (current-buffer)))
4658 ;; Check asynchronous pre-fetch.
4659 ((gnus-async-request-fetched-article group article (current-buffer))
4660 (gnus-async-prefetch-next group article gnus-summary-buffer)
4661 (when (and (numberp article) gnus-keep-backlog)
4662 (gnus-backlog-enter-article group article (current-buffer)))
4665 ((and gnus-use-cache
4667 (gnus-cache-request-article article group))
4669 ;; Get the article and put into the article buffer.
4670 ((or (stringp article)
4672 (let ((gnus-override-method gnus-override-method)
4673 (methods (and (stringp article)
4674 gnus-refer-article-method))
4676 (buffer-read-only nil))
4677 (if (or (not (listp methods))
4678 (and (symbolp (car methods))
4679 (assq (car methods) nnoo-definition-alist)))
4680 (setq methods (list methods)))
4681 (when (and (null gnus-override-method)
4683 (setq gnus-override-method (pop methods)))
4685 (when (eq gnus-override-method 'current)
4686 (setq gnus-override-method
4687 (with-current-buffer gnus-summary-buffer
4688 gnus-current-select-method)))
4690 (gnus-kill-all-overlays)
4691 (let ((gnus-newsgroup-name group))
4692 (gnus-check-group-server))
4693 (when (gnus-request-article article group (current-buffer))
4694 (when (numberp article)
4695 (gnus-async-prefetch-next group article
4696 gnus-summary-buffer)
4697 (when gnus-keep-backlog
4698 (gnus-backlog-enter-article
4699 group article (current-buffer))))
4700 (setq result 'article))
4703 (setq gnus-override-method (pop methods))
4704 (setq result 'done))))
4705 (and (eq result 'article) 'article)))
4709 ;; Associate this article with the current summary buffer.
4710 (setq gnus-article-current-summary gnus-summary-buffer)
4712 ;; Take the article from the original article buffer
4713 ;; and place it in the buffer it's supposed to be in.
4714 (when (and (get-buffer gnus-article-buffer)
4715 (equal (buffer-name (current-buffer))
4716 (buffer-name (get-buffer gnus-article-buffer))))
4718 (if (get-buffer gnus-original-article-buffer)
4719 (set-buffer gnus-original-article-buffer)
4720 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4721 (buffer-disable-undo)
4722 (setq major-mode 'gnus-original-article-mode)
4723 (setq buffer-read-only t))
4724 (let (buffer-read-only)
4726 (insert-buffer-substring gnus-article-buffer))
4727 (setq gnus-original-article (cons group article)))
4730 (run-hooks 'gnus-article-decode-hook)
4731 ;; Mark article as decoded or not.
4732 (setq gnus-article-decoded-p gnus-article-decode-hook))
4734 ;; Update sparse articles.
4735 (when (and do-update-line
4736 (or (numberp article)
4738 (let ((buf (current-buffer)))
4739 (set-buffer gnus-summary-buffer)
4740 (gnus-summary-update-article do-update-line sparse-header)
4741 (gnus-summary-goto-subject do-update-line nil t)
4742 (set-window-point (gnus-get-buffer-window (current-buffer) t)
4744 (set-buffer buf))))))
4750 (defcustom gnus-article-edit-mode-hook nil
4751 "Hook run in article edit mode buffers."
4752 :group 'gnus-article-various
4755 (defvar gnus-article-edit-done-function nil)
4757 (defvar gnus-article-edit-mode-map nil)
4759 ;; Should we be using derived.el for this?
4760 (unless gnus-article-edit-mode-map
4761 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4762 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4764 (gnus-define-keys gnus-article-edit-mode-map
4765 "\C-c\C-c" gnus-article-edit-done
4766 "\C-c\C-k" gnus-article-edit-exit)
4768 (gnus-define-keys (gnus-article-edit-wash-map
4769 "\C-c\C-w" gnus-article-edit-mode-map)
4770 "f" gnus-article-edit-full-stops))
4772 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4773 "Major mode for editing articles.
4774 This is an extended text-mode.
4776 \\{gnus-article-edit-mode-map}"
4777 (make-local-variable 'gnus-article-edit-done-function)
4778 (make-local-variable 'gnus-prev-winconf)
4779 (set (make-local-variable 'font-lock-defaults)
4780 '(message-font-lock-keywords t))
4781 (setq buffer-read-only nil)
4782 (buffer-enable-undo)
4785 (defun gnus-article-edit (&optional force)
4786 "Edit the current article.
4787 This will have permanent effect only in mail groups.
4788 If FORCE is non-nil, allow editing of articles even in read-only
4791 (when (and (not force)
4792 (gnus-group-read-only-p))
4793 (error "The current newsgroup does not support article editing"))
4794 (gnus-article-date-original)
4795 (gnus-article-edit-article
4797 `(lambda (no-highlight)
4799 (gnus-summary-edit-article-done
4800 ,(or (mail-header-references gnus-current-headers) "")
4801 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4803 (defun gnus-article-edit-article (start-func exit-func)
4804 "Start editing the contents of the current article buffer."
4805 (let ((winconf (current-window-configuration)))
4806 (set-buffer gnus-article-buffer)
4807 (gnus-article-edit-mode)
4808 (funcall start-func)
4809 (set-buffer-modified-p nil)
4810 (gnus-configure-windows 'edit-article)
4811 (setq gnus-article-edit-done-function exit-func)
4812 (setq gnus-prev-winconf winconf)
4813 (gnus-message 6 "C-c C-c to end edits")))
4815 (defun gnus-article-edit-done (&optional arg)
4816 "Update the article edits and exit."
4818 (let ((func gnus-article-edit-done-function)
4819 (buf (current-buffer))
4820 (start (window-start)))
4821 ;; We remove all text props from the article buffer.
4823 (buffer-substring-no-properties (point-min) (point-max)))
4827 (let ((winconf gnus-prev-winconf))
4829 (set-window-configuration winconf)
4830 ;; Tippy-toe some to make sure that point remains where it was.
4831 (save-current-buffer
4833 (set-window-start (get-buffer-window (current-buffer)) start)
4837 (let ((buffer-read-only nil))
4839 ;; The cache and backlog have to be flushed somewhat.
4840 (when gnus-keep-backlog
4841 (gnus-backlog-remove-article
4842 (car gnus-article-current) (cdr gnus-article-current)))
4843 ;; Flush original article as well.
4845 (when (get-buffer gnus-original-article-buffer)
4846 (set-buffer gnus-original-article-buffer)
4847 (setq gnus-original-article nil)))
4848 (when gnus-use-cache
4849 (gnus-cache-update-article
4850 (car gnus-article-current) (cdr gnus-article-current))))
4852 (set-window-start (get-buffer-window buf) start)
4853 (set-window-point (get-buffer-window buf) (point))))
4855 (defun gnus-article-edit-exit ()
4856 "Exit the article editing without updating."
4858 (when (or (not (buffer-modified-p))
4859 (yes-or-no-p "Article modified; kill anyway? "))
4860 (let ((curbuf (current-buffer))
4862 (window-start (window-start)))
4864 (if (gnus-buffer-live-p gnus-original-article-buffer)
4865 (insert-buffer gnus-original-article-buffer))
4866 (let ((winconf gnus-prev-winconf))
4868 (set-window-configuration winconf)
4869 ;; Tippy-toe some to make sure that point remains where it was.
4870 (save-current-buffer
4872 (set-window-start (get-buffer-window (current-buffer)) window-start)
4875 (defun gnus-article-edit-full-stops ()
4876 "Interactively repair spacing at end of sentences."
4879 (goto-char (point-min))
4880 (search-forward-regexp "^$" nil t)
4881 (let ((case-fold-search nil))
4882 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4885 ;;; Article highlights
4888 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4890 ;;; Internal Variables:
4892 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
4893 "Regular expression that matches URLs."
4894 :group 'gnus-article-buttons
4897 (defcustom gnus-button-alist
4898 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4899 0 t gnus-button-handle-news 3)
4900 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
4901 gnus-button-handle-news 2)
4902 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4904 gnus-button-fetch-group 4)
4905 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4906 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4907 t gnus-button-message-id 3)
4908 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4909 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4910 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4912 ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
4913 gnus-button-handle-info 2)
4914 ;; This is how URLs _should_ be embedded in text...
4915 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4917 (,gnus-button-url-regexp 0 t browse-url 0))
4918 "*Alist of regexps matching buttons in article bodies.
4920 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4921 REGEXP: is the string matching text around the button,
4922 BUTTON: is the number of the regexp grouping actually matching the button,
4923 FORM: is a lisp expression which must eval to true for the button to
4925 CALLBACK: is the function to call when the user push this button, and each
4926 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4928 CALLBACK can also be a variable, in that case the value of that
4929 variable it the real callback function."
4930 :group 'gnus-article-buttons
4931 :type '(repeat (list regexp
4932 (integer :tag "Button")
4934 (function :tag "Callback")
4937 (integer :tag "Regexp group")))))
4939 (defcustom gnus-header-button-alist
4940 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
4941 0 t gnus-button-message-id 0)
4942 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4943 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4944 0 t gnus-button-mailto 0)
4945 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4946 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4947 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4948 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4949 gnus-button-message-id 3))
4950 "*Alist of headers and regexps to match buttons in article heads.
4952 This alist is very similar to `gnus-button-alist', except that each
4953 alist has an additional HEADER element first in each entry:
4955 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4957 HEADER is a regexp to match a header. For a fuller explanation, see
4958 `gnus-button-alist'."
4959 :group 'gnus-article-buttons
4960 :group 'gnus-article-headers
4961 :type '(repeat (list (regexp :tag "Header")
4963 (integer :tag "Button")
4965 (function :tag "Callback")
4968 (integer :tag "Regexp group")))))
4970 (defvar gnus-button-regexp nil)
4971 (defvar gnus-button-marker-list nil)
4972 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4974 (defvar gnus-button-last nil)
4975 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4979 (defun gnus-article-push-button (event)
4980 "Check text under the mouse pointer for a callback function.
4981 If the text under the mouse pointer has a `gnus-callback' property,
4982 call it with the value of the `gnus-data' text property."
4984 (set-buffer (window-buffer (posn-window (event-start event))))
4985 (let* ((pos (posn-point (event-start event)))
4986 (data (get-text-property pos 'gnus-data))
4987 (fun (get-text-property pos 'gnus-callback)))
4990 (funcall fun data))))
4992 (defun gnus-article-press-button ()
4993 "Check text at point for a callback function.
4994 If the text at point has a `gnus-callback' property,
4995 call it with the value of the `gnus-data' text property."
4997 (let* ((data (get-text-property (point) 'gnus-data))
4998 (fun (get-text-property (point) 'gnus-callback)))
5000 (funcall fun data))))
5002 (defun gnus-article-highlight (&optional force)
5003 "Highlight current article.
5004 This function calls `gnus-article-highlight-headers',
5005 `gnus-article-highlight-citation',
5006 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5007 do the highlighting. See the documentation for those functions."
5008 (interactive (list 'force))
5009 (gnus-article-highlight-headers)
5010 (gnus-article-highlight-citation force)
5011 (gnus-article-highlight-signature)
5012 (gnus-article-add-buttons force)
5013 (gnus-article-add-buttons-to-head))
5015 (defun gnus-article-highlight-some (&optional force)
5016 "Highlight current article.
5017 This function calls `gnus-article-highlight-headers',
5018 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5019 do the highlighting. See the documentation for those functions."
5020 (interactive (list 'force))
5021 (gnus-article-highlight-headers)
5022 (gnus-article-highlight-signature)
5023 (gnus-article-add-buttons))
5025 (defun gnus-article-highlight-headers ()
5026 "Highlight article headers as specified by `gnus-header-face-alist'."
5029 (set-buffer gnus-article-buffer)
5031 (let ((alist gnus-header-face-alist)
5032 (buffer-read-only nil)
5033 (case-fold-search t)
5034 (inhibit-point-motion-hooks t)
5035 entry regexp header-face field-face from hpoints fpoints)
5036 (article-narrow-to-head)
5037 (while (setq entry (pop alist))
5038 (goto-char (point-min))
5039 (setq regexp (concat "^\\("
5040 (if (string-equal "" (nth 0 entry))
5044 header-face (nth 1 entry)
5045 field-face (nth 2 entry))
5046 (while (and (re-search-forward regexp nil t)
5050 (unless (search-forward ":" nil t)
5052 (when (and header-face
5053 (not (memq (point) hpoints)))
5054 (push (point) hpoints)
5055 (gnus-put-text-property from (point) 'face header-face))
5056 (when (and field-face
5057 (not (memq (setq from (point)) fpoints)))
5059 (if (re-search-forward "^[^ \t]" nil t)
5061 (goto-char (point-max)))
5062 (gnus-put-text-property from (point) 'face field-face))))))))
5064 (defun gnus-article-highlight-signature ()
5065 "Highlight the signature in an article.
5066 It does this by highlighting everything after
5067 `gnus-signature-separator' using `gnus-signature-face'."
5070 (set-buffer gnus-article-buffer)
5071 (let ((buffer-read-only nil)
5072 (inhibit-point-motion-hooks t))
5074 (when (and gnus-signature-face
5075 (gnus-article-narrow-to-signature))
5076 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5077 'face gnus-signature-face)
5079 (gnus-article-search-signature)
5080 (let ((start (match-beginning 0))
5081 (end (set-marker (make-marker) (1+ (match-end 0)))))
5082 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5085 (defun gnus-button-in-region-p (b e prop)
5086 "Say whether PROP exists in the region."
5087 (text-property-not-all b e prop nil))
5089 (defun gnus-article-add-buttons (&optional force)
5090 "Find external references in the article and make buttons of them.
5091 \"External references\" are things like Message-IDs and URLs, as
5092 specified by `gnus-button-alist'."
5093 (interactive (list 'force))
5095 (set-buffer gnus-article-buffer)
5096 (let ((buffer-read-only nil)
5097 (inhibit-point-motion-hooks t)
5098 (case-fold-search t)
5099 (alist gnus-button-alist)
5101 ;; Remove all old markers.
5102 (let (marker entry new-list)
5103 (while (setq marker (pop gnus-button-marker-list))
5104 (if (or (< marker (point-min)) (>= marker (point-max)))
5105 (push marker new-list)
5107 (when (setq entry (gnus-button-entry))
5108 (put-text-property (match-beginning (nth 1 entry))
5109 (match-end (nth 1 entry))
5110 'gnus-callback nil))
5111 (set-marker marker nil)))
5112 (setq gnus-button-marker-list new-list))
5113 ;; We skip the headers.
5116 (while (setq entry (pop alist))
5117 (setq regexp (car entry))
5119 (while (re-search-forward regexp nil t)
5120 (let* ((start (and entry (match-beginning (nth 1 entry))))
5121 (end (and entry (match-end (nth 1 entry))))
5122 (from (match-beginning 0)))
5123 (when (and (or (eq t (nth 2 entry))
5124 (eval (nth 2 entry)))
5125 (not (gnus-button-in-region-p
5126 start end 'gnus-callback)))
5127 ;; That optional form returned non-nil, so we add the
5129 (gnus-article-add-button
5130 start end 'gnus-button-push
5131 (car (push (set-marker (make-marker) from)
5132 gnus-button-marker-list))))))))))
5134 ;; Add buttons to the head of an article.
5135 (defun gnus-article-add-buttons-to-head ()
5136 "Add buttons to the head of the article."
5139 (set-buffer gnus-article-buffer)
5141 (let ((buffer-read-only nil)
5142 (inhibit-point-motion-hooks t)
5143 (case-fold-search t)
5144 (alist gnus-header-button-alist)
5146 (article-narrow-to-head)
5148 ;; Each alist entry.
5149 (setq entry (car alist)
5151 (goto-char (point-min))
5152 (while (re-search-forward (car entry) nil t)
5153 ;; Each header matching the entry.
5154 (setq beg (match-beginning 0))
5155 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5156 (match-beginning 0))
5159 (while (re-search-forward (nth 1 entry) end t)
5160 ;; Each match within a header.
5161 (let* ((entry (cdr entry))
5162 (start (match-beginning (nth 1 entry)))
5163 (end (match-end (nth 1 entry)))
5164 (form (nth 2 entry)))
5165 (goto-char (match-end 0))
5167 (gnus-article-add-button
5168 start end (nth 3 entry)
5169 (buffer-substring (match-beginning (nth 4 entry))
5170 (match-end (nth 4 entry)))))))
5171 (goto-char end)))))))
5173 ;;; External functions:
5175 (defun gnus-article-add-button (from to fun &optional data)
5176 "Create a button between FROM and TO with callback FUN and data DATA."
5177 (when gnus-article-button-face
5178 (gnus-overlay-put (gnus-make-overlay from to)
5179 'face gnus-article-button-face))
5180 (gnus-add-text-properties
5182 (nconc (and gnus-article-mouse-face
5183 (list gnus-mouse-face-prop gnus-article-mouse-face))
5184 (list 'gnus-callback fun)
5185 (and data (list 'gnus-data data))))
5186 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5187 :button-keymap gnus-widget-button-keymap))
5189 ;;; Internal functions:
5191 (defun gnus-article-set-globals ()
5193 (set-buffer gnus-summary-buffer)
5194 (gnus-set-global-variables)))
5196 (defun gnus-signature-toggle (end)
5198 (set-buffer gnus-article-buffer)
5199 (let ((buffer-read-only nil)
5200 (inhibit-point-motion-hooks t))
5201 (if (text-property-any end (point-max) 'article-type 'signature)
5203 (setq gnus-article-wash-types
5204 (delq 'signature gnus-article-wash-types))
5205 (gnus-remove-text-properties-when
5206 'article-type 'signature end (point-max)
5207 (cons 'article-type (cons 'signature
5208 gnus-hidden-properties))))
5209 (or (memq 'signature gnus-article-wash-types)
5210 (push 'signature gnus-article-wash-types))
5211 (gnus-add-text-properties-when
5212 'article-type nil end (point-max)
5213 (cons 'article-type (cons 'signature
5214 gnus-hidden-properties)))))
5215 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5216 (gnus-set-mode-line 'article))))
5218 (defun gnus-button-entry ()
5219 ;; Return the first entry in `gnus-button-alist' matching this place.
5220 (let ((alist gnus-button-alist)
5223 (setq entry (pop alist))
5224 (if (looking-at (car entry))
5229 (defun gnus-button-push (marker)
5230 ;; Push button starting at MARKER.
5233 (let* ((entry (gnus-button-entry))
5234 (inhibit-point-motion-hooks t)
5236 (args (mapcar (lambda (group)
5237 (let ((string (match-string group)))
5238 (gnus-set-text-properties
5239 0 (length string) nil string)
5246 (fboundp (symbol-value fun)))
5247 (apply (symbol-value fun) args))
5249 (gnus-message 1 "You must define `%S' to use this button"
5250 (cons fun args)))))))
5252 (defun gnus-parse-news-url (url)
5253 (let (scheme server group message-id articles)
5256 (goto-char (point-min))
5257 (when (looking-at "\\([A-Za-z]+\\):")
5258 (setq scheme (match-string 1))
5259 (goto-char (match-end 0)))
5260 (when (looking-at "//\\([^/]+\\)/")
5261 (setq server (match-string 1))
5262 (goto-char (match-end 0)))
5265 ((looking-at "\\(.*@.*\\)")
5266 (setq message-id (match-string 1)))
5267 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5268 (setq group (match-string 1)
5269 articles (split-string (match-string 2) "-")))
5270 ((looking-at "\\([^/]+\\)/?")
5271 (setq group (match-string 1)))
5273 (error "Unknown news URL syntax"))))
5274 (list scheme server group message-id articles)))
5276 (defun gnus-button-handle-news (url)
5278 (destructuring-bind (scheme server group message-id articles)
5279 (gnus-parse-news-url url)
5283 (set-buffer gnus-summary-buffer)
5285 (let ((gnus-refer-article-method (list (list 'nntp server))))
5286 (gnus-summary-refer-article message-id))
5287 (gnus-summary-refer-article message-id))))
5289 (gnus-button-fetch-group url)))))
5291 (defun gnus-button-handle-info (url)
5292 "Fetch an info URL."
5294 "^\\([^:/]+\\)?/\\(.*\\)"
5296 (gnus-info-find-node
5297 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
5300 (gnus-url-unhex-string (match-string 2 url))))
5301 (error "Can't parse %s" url)))
5303 (defun gnus-button-message-id (message-id)
5306 (set-buffer gnus-summary-buffer)
5307 (gnus-summary-refer-article message-id)))
5309 (defun gnus-button-fetch-group (address)
5310 "Fetch GROUP specified by ADDRESS."
5311 (if (not (string-match "[:/]" address))
5312 ;; This is just a simple group url.
5313 (gnus-group-read-ephemeral-group address gnus-select-method)
5316 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5318 (error "Can't parse %s" address)
5319 (gnus-group-read-ephemeral-group
5320 (match-string 4 address)
5321 `(nntp ,(match-string 1 address)
5322 (nntp-address ,(match-string 1 address))
5323 (nntp-port-number ,(if (match-end 3)
5324 (match-string 3 address)
5327 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5329 (defun gnus-url-parse-query-string (query &optional downcase)
5330 (let (retval pairs cur key val)
5331 (setq pairs (split-string query "&"))
5333 (setq cur (car pairs)
5335 (if (not (string-match "=" cur))
5337 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5338 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5340 (setq key (downcase key)))
5341 (setq cur (assoc key retval))
5343 (setcdr cur (cons val (cdr cur)))
5344 (setq retval (cons (list key val) retval)))))
5347 (defun gnus-url-mailto (url)
5348 ;; Send mail to someone
5349 (when (string-match "mailto:/*\\(.*\\)" url)
5350 (setq url (substring url (match-beginning 1) nil)))
5351 (let (to args subject func)
5352 (if (string-match (regexp-quote "?") url)
5353 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5354 args (gnus-url-parse-query-string
5355 (substring url (match-end 0) nil) t))
5356 (setq to (gnus-url-unhex-string url)))
5357 (setq args (cons (list "to" to) args)
5358 subject (cdr-safe (assoc "subject" args)))
5361 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5364 (message-position-on-field (caar args)))
5365 (insert (mapconcat 'identity (cdar args) ", "))
5366 (setq args (cdr args)))
5369 (message-goto-subject))))
5371 (defun gnus-button-embedded-url (address)
5372 "Activate ADDRESS with `browse-url'."
5373 (browse-url (gnus-strip-whitespace address)))
5375 ;;; Next/prev buttons in the article buffer.
5377 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5378 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5380 (defvar gnus-prev-page-map nil)
5381 (unless gnus-prev-page-map
5382 (setq gnus-prev-page-map (make-sparse-keymap))
5383 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5384 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5386 (defun gnus-insert-prev-page-button ()
5387 (let ((buffer-read-only nil))
5389 gnus-prev-page-line-format nil
5390 `(gnus-prev t local-map ,gnus-prev-page-map
5391 gnus-callback gnus-article-button-prev-page
5392 article-type annotation))))
5394 (defvar gnus-next-page-map nil)
5395 (unless gnus-next-page-map
5396 (setq gnus-next-page-map (make-keymap))
5397 (suppress-keymap gnus-prev-page-map)
5398 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5399 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5401 (defun gnus-button-next-page ()
5402 "Go to the next page."
5404 (let ((win (selected-window)))
5405 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5406 (gnus-article-next-page)
5407 (select-window win)))
5409 (defun gnus-button-prev-page ()
5410 "Go to the prev page."
5412 (let ((win (selected-window)))
5413 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5414 (gnus-article-prev-page)
5415 (select-window win)))
5417 (defun gnus-insert-next-page-button ()
5418 (let ((buffer-read-only nil))
5419 (gnus-eval-format gnus-next-page-line-format nil
5421 t local-map ,gnus-next-page-map
5422 gnus-callback gnus-article-button-next-page
5423 article-type annotation))))
5425 (defun gnus-article-button-next-page (arg)
5426 "Go to the next page."
5428 (let ((win (selected-window)))
5429 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5430 (gnus-article-next-page)
5431 (select-window win)))
5433 (defun gnus-article-button-prev-page (arg)
5434 "Go to the prev page."
5436 (let ((win (selected-window)))
5437 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5438 (gnus-article-prev-page)
5439 (select-window win)))
5441 (defvar gnus-decode-header-methods
5442 '(mail-decode-encoded-word-region)
5443 "List of methods used to decode headers.
5445 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5446 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5447 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5448 whose names match REGEXP.
5451 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5452 mail-decode-encoded-word-region
5453 (\"chinese\" . rfc1843-decode-region))
5456 (defvar gnus-decode-header-methods-cache nil)
5458 (defun gnus-multi-decode-header (start end)
5459 "Apply the functions from `gnus-encoded-word-methods' that match."
5460 (unless (and gnus-decode-header-methods-cache
5461 (eq gnus-newsgroup-name
5462 (car gnus-decode-header-methods-cache)))
5463 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5466 (nconc gnus-decode-header-methods-cache (list x))
5467 (if (and gnus-newsgroup-name
5468 (string-match (car x) gnus-newsgroup-name))
5469 (nconc gnus-decode-header-methods-cache
5471 gnus-decode-header-methods))
5472 (let ((xlist gnus-decode-header-methods-cache))
5475 (narrow-to-region start end)
5477 (funcall (pop xlist) (point-min) (point-max))))))
5480 ;;; Treatment top-level handling.
5483 (defun gnus-treat-article (condition &optional part-number total-parts type)
5484 (let ((length (- (point-max) (point-min)))
5485 (alist gnus-treatment-function-alist)
5486 (article-goto-body-goes-to-point-min-p t)
5490 (let ((list gnus-article-treat-types))
5492 (when (string-match (pop list) type)
5493 (throw 'found t)))))))
5494 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5496 (gnus-run-hooks 'gnus-part-display-hook)
5497 (while (setq elem (pop alist))
5500 (if (gnus-buffer-live-p gnus-summary-buffer)
5501 (set-buffer gnus-summary-buffer))
5502 (symbol-value (car elem))))
5503 (when (and (or (consp val)
5505 (gnus-treat-predicate val)
5506 (or (not (get (car elem) 'highlight))
5509 (funcall (cadr elem)))))))
5511 ;; Dynamic variables.
5513 (defvar part-number)
5514 (defvar total-parts)
5519 (defun gnus-treat-predicate (val)
5524 (stringp (car val)))
5525 (apply 'gnus-or (mapcar `(lambda (s)
5526 (string-match s ,(or gnus-newsgroup-name "")))
5529 (let ((pred (pop val)))
5532 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5534 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5536 (not (gnus-treat-predicate (car val))))
5538 (equal (car val) type))
5540 (error "%S is not a valid predicate" pred)))))
5548 (eq part-number total-parts))
5552 (error "%S is not a valid value" val))))
5554 (defun gnus-article-encrypt-body (protocol &optional n)
5555 "Encrypt the article body."
5558 (or gnus-article-encrypt-protocol
5559 (completing-read "Encrypt protocol: "
5560 gnus-article-encrypt-protocol-alist
5562 current-prefix-arg))
5563 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5565 (error (format "Can't find the encrypt protocol %s" protocol)))
5566 (if (equal gnus-newsgroup-name "nndraft:drafts")
5567 (error "Can't encrypt the article in group nndraft:drafts"))
5568 (if (equal gnus-newsgroup-name "nndraft:queue")
5569 (error "Don't encrypt the article in group nndraft:queue"))
5570 (gnus-summary-iterate n
5572 (set-buffer gnus-summary-buffer)
5573 (let ((mail-parse-charset gnus-newsgroup-charset)
5574 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5575 (summary-buffer gnus-summary-buffer)
5577 (gnus-set-global-variables)
5578 (when (gnus-group-read-only-p)
5579 (error "The current newsgroup does not support article encrypt"))
5580 (gnus-summary-show-article t)
5582 (or (mail-header-references gnus-current-headers) ""))
5583 (set-buffer gnus-article-buffer)
5584 (let* ((buffer-read-only nil)
5586 (mapcar (lambda (field)
5587 (and (save-restriction
5588 (message-narrow-to-head)
5589 (goto-char (point-min))
5590 (search-forward field nil t))
5592 (message-narrow-to-field)
5593 (buffer-substring (point-min) (point-max))
5594 (delete-region (point-min) (point-max))
5596 '("Content-Type:" "Content-Transfer-Encoding:"
5597 "Content-Disposition:"))))
5598 (message-narrow-to-head)
5599 (message-remove-header "MIME-Version")
5600 (goto-char (point-max))
5601 (setq point (point))
5602 (insert (apply 'concat headers))
5604 (narrow-to-region point (point-max))
5605 (let ((message-options message-options))
5606 (message-options-set 'message-sender user-mail-address)
5607 (message-options-set 'message-recipients user-mail-address)
5608 (message-options-set 'message-sign-encrypt 'not)
5610 (goto-char (point-min))
5611 (insert "MIME-Version: 1.0\n")
5613 (gnus-summary-edit-article-done
5614 references nil summary-buffer t))
5615 (when gnus-keep-backlog
5616 (gnus-backlog-remove-article
5617 (car gnus-article-current) (cdr gnus-article-current)))
5619 (when (get-buffer gnus-original-article-buffer)
5620 (set-buffer gnus-original-article-buffer)
5621 (setq gnus-original-article nil)))
5622 (when gnus-use-cache
5623 (gnus-cache-update-article
5624 (car gnus-article-current) (cdr gnus-article-current))))))))
5626 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5627 "The following specs can be used:
5628 %t The security MIME type
5631 %D Details if button is pressed")
5633 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5634 "The following specs can be used:
5635 %t The security MIME type
5638 %D Details if button is pressed")
5640 (defvar gnus-mime-security-button-line-format-alist
5641 '((?t gnus-tmp-type ?s)
5642 (?i gnus-tmp-info ?s)
5643 (?d gnus-tmp-details ?s)
5644 (?D gnus-tmp-pressed-details ?s)))
5646 (defvar gnus-mime-security-button-map
5647 (let ((map (make-sparse-keymap)))
5648 (unless (>= (string-to-number emacs-version) 21)
5649 (set-keymap-parent map gnus-article-mode-map))
5650 (define-key map gnus-mouse-2 'gnus-article-push-button)
5651 (define-key map "\r" 'gnus-article-press-button)
5654 (defvar gnus-mime-security-details-buffer nil)
5656 (defvar gnus-mime-security-button-pressed nil)
5658 (defvar gnus-mime-security-show-details-inline t
5659 "If non-nil, show details in the article buffer.")
5661 (defun gnus-mime-security-verify-or-decrypt (handle)
5662 (mm-remove-parts (cdr handle))
5663 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5664 point buffer-read-only)
5666 (goto-char (car region)))
5668 (narrow-to-region (point) (point))
5669 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5670 (let* ((mm-verify-option 'known)
5671 (mm-decrypt-option 'known)
5672 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5673 (unless (eq nparts (cdr handle))
5674 (mm-destroy-parts (cdr handle))
5675 (setcdr handle nparts))))
5676 (setq point (point))
5677 (gnus-mime-display-security handle)
5678 (goto-char (point-max)))
5680 (delete-region (point) (cdr region))
5681 (set-marker (car region) nil)
5682 (set-marker (cdr region) nil))
5685 (defun gnus-mime-security-show-details (handle)
5686 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5688 (if gnus-mime-security-show-details-inline
5689 (let ((gnus-mime-security-button-pressed t)
5690 (gnus-mime-security-button-line-format
5691 (get-text-property (point) 'gnus-line-format))
5694 (while (eq (get-text-property (point) 'gnus-line-format)
5695 gnus-mime-security-button-line-format)
5699 (narrow-to-region (point) (point))
5700 (gnus-insert-mime-security-button handle))
5701 (delete-region (point)
5702 (or (text-property-not-all
5705 gnus-mime-security-button-line-format)
5707 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5708 (with-current-buffer gnus-mime-security-details-buffer
5711 (setq gnus-mime-security-details-buffer
5712 (gnus-get-buffer-create "*MIME Security Details*")))
5713 (with-current-buffer gnus-mime-security-details-buffer
5715 (goto-char (point-min)))
5716 (pop-to-buffer gnus-mime-security-details-buffer))
5717 (gnus-message 5 "No details."))))
5719 (defun gnus-mime-security-press-button (handle)
5720 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5721 (gnus-mime-security-show-details handle)
5722 (gnus-mime-security-verify-or-decrypt handle)))
5724 (defun gnus-insert-mime-security-button (handle &optional displayed)
5725 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5728 (or (nth 2 (assoc protocol mm-verify-function-alist))
5729 (nth 2 (assoc protocol mm-decrypt-function-alist))
5731 (if (equal (car handle) "multipart/signed")
5732 " Signed" " Encrypted")
5735 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5738 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5739 gnus-tmp-pressed-details
5741 (setq gnus-tmp-details
5742 (if gnus-tmp-details
5743 (concat "\n" gnus-tmp-details) ""))
5744 (setq gnus-tmp-pressed-details
5745 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5750 gnus-mime-security-button-line-format
5751 gnus-mime-security-button-line-format-alist
5752 `(keymap ,gnus-mime-security-button-map
5753 ,@(if (>= (string-to-number emacs-version) 21)
5754 nil ;; XEmacs doesn't care
5755 (list 'local-map gnus-mime-security-button-map))
5756 gnus-callback gnus-mime-security-press-button
5757 gnus-line-format ,gnus-mime-security-button-line-format
5758 article-type annotation
5761 (widget-convert-button
5764 :action 'gnus-widget-press-button
5765 :button-keymap gnus-mime-security-button-map
5767 (lambda (widget/window &optional overlay pos)
5768 ;; Needed to properly clear the message due to a bug in
5769 ;; wid-edit (XEmacs only).
5770 (if (boundp 'help-echo-owns-message)
5771 (setq help-echo-owns-message t))
5774 (aref gnus-mouse-2 0))))))
5776 (defun gnus-mime-display-security (handle)
5778 (narrow-to-region (point) (point))
5779 (unless (gnus-unbuttonized-mime-type-p (car handle))
5780 (gnus-insert-mime-security-button handle))
5781 (gnus-mime-display-mixed (cdr handle))
5784 (unless (gnus-unbuttonized-mime-type-p (car handle))
5785 (let ((gnus-mime-security-button-line-format
5786 gnus-mime-security-button-end-line-format))
5787 (gnus-insert-mime-security-button handle)))
5788 (mm-set-handle-multipart-parameter
5790 (cons (set-marker (make-marker) (point-min))
5791 (set-marker (make-marker) (point-max))))))
5793 ;;; Macros for dealing with the article buffer.
5795 (defmacro gnus-with-article-headers (&rest forms)
5797 (set-buffer gnus-article-buffer)
5799 (let ((buffer-read-only nil)
5800 (inhibit-point-motion-hooks t)
5801 (case-fold-search t))
5802 (article-narrow-to-head)
5805 (put 'gnus-with-article-headers 'lisp-indent-function 0)
5806 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
5808 (defun gnus-article-goto-header (header)
5809 (re-search-forward (concat "^" header ":") nil t))
5815 (run-hooks 'gnus-art-load-hook)
5817 ;;; gnus-art.el ends here