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-from-picon gnus-treat-from-picon)
1204 (gnus-treat-mail-picon gnus-treat-mail-picon)
1205 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1206 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1207 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1208 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1209 (gnus-treat-strip-trailing-blank-lines
1210 gnus-article-remove-trailing-blank-lines)
1211 (gnus-treat-strip-leading-blank-lines
1212 gnus-article-strip-leading-blank-lines)
1213 (gnus-treat-strip-multiple-blank-lines
1214 gnus-article-strip-multiple-blank-lines)
1215 (gnus-treat-overstrike gnus-article-treat-overstrike)
1216 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1217 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1218 (gnus-treat-display-smileys gnus-smiley-display)
1219 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1220 (gnus-treat-emphasize gnus-article-emphasize)
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 ;;; Macros for dealing with the article buffer.
1251 (defmacro gnus-with-article-headers (&rest forms)
1253 (set-buffer gnus-article-buffer)
1255 (let ((buffer-read-only nil)
1256 (inhibit-point-motion-hooks t)
1257 (case-fold-search t))
1258 (article-narrow-to-head)
1261 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1262 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1264 (defsubst gnus-article-hide-text (b e props)
1265 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1266 (gnus-add-text-properties-when 'article-type nil b e props)
1267 (when (memq 'intangible props)
1269 (max (1- b) (point-min))
1270 b 'intangible (cddr (memq 'intangible props)))))
1272 (defsubst gnus-article-unhide-text (b e)
1273 "Remove hidden text properties from region between B and E."
1274 (remove-text-properties b e gnus-hidden-properties)
1275 (when (memq 'intangible gnus-hidden-properties)
1276 (put-text-property (max (1- b) (point-min))
1277 b 'intangible nil)))
1279 (defun gnus-article-hide-text-type (b e type)
1280 "Hide text of TYPE between B and E."
1281 (push type gnus-article-wash-types)
1282 (gnus-article-hide-text
1283 b e (cons 'article-type (cons type gnus-hidden-properties))))
1285 (defun gnus-article-unhide-text-type (b e type)
1286 "Unhide text of TYPE between B and E."
1287 (setq gnus-article-wash-types
1288 (delq type gnus-article-wash-types))
1289 (remove-text-properties
1290 b e (cons 'article-type (cons type gnus-hidden-properties)))
1291 (when (memq 'intangible gnus-hidden-properties)
1292 (put-text-property (max (1- b) (point-min))
1293 b 'intangible nil)))
1295 (defun gnus-article-hide-text-of-type (type)
1296 "Hide text of TYPE in the current buffer."
1298 (let ((b (point-min))
1300 (while (setq b (text-property-any b e 'article-type type))
1301 (add-text-properties b (incf b) gnus-hidden-properties)))))
1303 (defun gnus-article-delete-text-of-type (type)
1304 "Delete text of TYPE in the current buffer."
1306 (let ((b (point-min)))
1307 (while (setq b (text-property-any b (point-max) 'article-type type))
1309 b (or (text-property-not-all b (point-max) 'article-type type)
1312 (defun gnus-article-delete-invisible-text ()
1313 "Delete all invisible text in the current buffer."
1315 (let ((b (point-min)))
1316 (while (setq b (text-property-any b (point-max) 'invisible t))
1318 b (or (text-property-not-all b (point-max) 'invisible t)
1321 (defun gnus-article-text-type-exists-p (type)
1322 "Say whether any text of type TYPE exists in the buffer."
1323 (text-property-any (point-min) (point-max) 'article-type type))
1325 (defsubst gnus-article-header-rank ()
1326 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1327 (let ((list gnus-sorted-header-list)
1330 (when (looking-at (car list))
1332 (setq list (cdr list))
1336 (defun article-hide-headers (&optional arg delete)
1337 "Hide unwanted headers and possibly sort them as well."
1339 ;; This function might be inhibited.
1340 (unless gnus-inhibit-hiding
1343 (let ((buffer-read-only nil)
1344 (case-fold-search t)
1345 (max (1+ (length gnus-sorted-header-list)))
1346 (ignored (when (not gnus-visible-headers)
1347 (cond ((stringp gnus-ignored-headers)
1348 gnus-ignored-headers)
1349 ((listp gnus-ignored-headers)
1350 (mapconcat 'identity gnus-ignored-headers
1353 (cond ((stringp gnus-visible-headers)
1354 gnus-visible-headers)
1355 ((and gnus-visible-headers
1356 (listp gnus-visible-headers))
1357 (mapconcat 'identity gnus-visible-headers "\\|"))))
1358 (inhibit-point-motion-hooks t)
1360 ;; First we narrow to just the headers.
1361 (article-narrow-to-head)
1362 ;; Hide any "From " lines at the beginning of (mail) articles.
1363 (while (looking-at "From ")
1366 (delete-region (point-min) (point)))
1367 ;; Then treat the rest of the header lines.
1368 ;; Then we use the two regular expressions
1369 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1370 ;; select which header lines is to remain visible in the
1372 (while (re-search-forward "^[^ \t:]*:" nil t)
1374 ;; Mark the rank of the header.
1376 (point) (1+ (point)) 'message-rank
1377 (if (or (and visible (looking-at visible))
1379 (not (looking-at ignored))))
1380 (gnus-article-header-rank)
1383 (message-sort-headers-1)
1384 (when (setq beg (text-property-any
1385 (point-min) (point-max) 'message-rank (+ 2 max)))
1386 ;; We delete the unwanted headers.
1387 (push 'headers gnus-article-wash-types)
1388 (add-text-properties (point-min) (+ 5 (point-min))
1389 '(article-type headers dummy-invisible t))
1390 (delete-region beg (point-max))))))))
1392 (defun article-hide-boring-headers (&optional arg)
1393 "Toggle hiding of headers that aren't very interesting.
1394 If given a negative prefix, always show; if given a positive prefix,
1396 (interactive (gnus-article-hidden-arg))
1397 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1398 (not gnus-show-all-headers))
1401 (let ((buffer-read-only nil)
1402 (list gnus-boring-article-headers)
1403 (inhibit-point-motion-hooks t)
1405 (article-narrow-to-head)
1407 (setq elem (pop list))
1408 (goto-char (point-min))
1410 ;; Hide empty headers.
1412 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1414 (gnus-article-hide-text-type
1415 (progn (beginning-of-line) (point))
1418 (if (re-search-forward "^[^ \t]" nil t)
1422 ;; Hide boring Newsgroups header.
1423 ((eq elem 'newsgroups)
1424 (when (gnus-string-equal
1425 (gnus-fetch-field "newsgroups")
1426 (gnus-group-real-name
1427 (if (boundp 'gnus-newsgroup-name)
1430 (gnus-article-hide-header "newsgroups")))
1431 ((eq elem 'to-address)
1432 (let ((to (message-fetch-field "to"))
1434 (gnus-parameter-to-address
1435 (if (boundp 'gnus-newsgroup-name)
1436 gnus-newsgroup-name ""))))
1437 (when (and to to-address
1440 ;; only one address in To
1441 (nth 1 (mail-extract-address-components to))
1443 (gnus-article-hide-header "to"))))
1444 ((eq elem 'followup-to)
1445 (when (gnus-string-equal
1446 (message-fetch-field "followup-to")
1447 (message-fetch-field "newsgroups"))
1448 (gnus-article-hide-header "followup-to")))
1449 ((eq elem 'reply-to)
1450 (let ((from (message-fetch-field "from"))
1451 (reply-to (message-fetch-field "reply-to")))
1456 (nth 1 (mail-extract-address-components from))
1457 (nth 1 (mail-extract-address-components reply-to)))))
1458 (gnus-article-hide-header "reply-to"))))
1460 (let ((date (message-fetch-field "date")))
1462 (< (days-between (current-time-string) date)
1464 (gnus-article-hide-header "date"))))
1466 (let ((to (message-fetch-field "to"))
1467 (cc (message-fetch-field "cc")))
1468 (when (> (length to) 1024)
1469 (gnus-article-hide-header "to"))
1470 (when (> (length cc) 1024)
1471 (gnus-article-hide-header "cc"))))
1475 (goto-char (point-min))
1476 (while (re-search-forward "^to:" nil t)
1477 (setq to-count (1+ to-count)))
1478 (when (> to-count 1)
1479 (while (> to-count 0)
1480 (goto-char (point-min))
1482 (re-search-forward "^to:" nil nil to-count)
1484 (narrow-to-region (point) (point-max))
1485 (gnus-article-hide-header "to"))
1486 (setq to-count (1- to-count))))
1487 (goto-char (point-min))
1488 (while (re-search-forward "^cc:" nil t)
1489 (setq cc-count (1+ cc-count)))
1490 (when (> cc-count 1)
1491 (while (> cc-count 0)
1492 (goto-char (point-min))
1494 (re-search-forward "^cc:" nil nil cc-count)
1496 (narrow-to-region (point) (point-max))
1497 (gnus-article-hide-header "cc"))
1498 (setq cc-count (1- cc-count)))))))))))))
1500 (defun gnus-article-hide-header (header)
1502 (goto-char (point-min))
1503 (when (re-search-forward (concat "^" header ":") nil t)
1504 (gnus-article-hide-text-type
1505 (progn (beginning-of-line) (point))
1508 (if (re-search-forward "^[^ \t]" nil t)
1513 (defvar gnus-article-normalized-header-length 40
1514 "Length of normalized headers.")
1516 (defun article-normalize-headers ()
1517 "Make all header lines 40 characters long."
1519 (let ((buffer-read-only nil)
1523 (article-narrow-to-head)
1526 ((< (setq column (- (gnus-point-at-eol) (point)))
1527 gnus-article-normalized-header-length)
1529 (insert (make-string
1530 (- gnus-article-normalized-header-length column)
1532 ((> column gnus-article-normalized-header-length)
1533 (gnus-put-text-property
1535 (forward-char gnus-article-normalized-header-length)
1542 (forward-line 1))))))
1544 (defun article-treat-dumbquotes ()
1545 "Translate M****s*** sm*rtq**t*s into proper text.
1546 Note that this function guesses whether a character is a sm*rtq**t* or
1547 not, so it should only be used interactively.
1549 Sm*rtq**t*s are M****s***'s unilateral extension to the character map
1550 in an attempt to provide more quoting characters. If you see
1551 something like \\222 or \\264 where you're expecting some kind of
1552 apostrophe or quotation mark, then try this wash."
1554 (article-translate-strings gnus-article-dumbquotes-map))
1556 (defun article-translate-characters (from to)
1557 "Translate all characters in the body of the article according to FROM and TO.
1558 FROM is a string of characters to translate from; to is a string of
1559 characters to translate to."
1561 (when (article-goto-body)
1562 (let ((buffer-read-only nil)
1563 (x (make-string 225 ?x))
1565 (while (< (incf i) (length x))
1568 (while (< i (length from))
1569 (aset x (aref from i) (aref to i))
1571 (translate-region (point) (point-max) x)))))
1573 (defun article-translate-strings (map)
1574 "Translate all string in the body of the article according to MAP.
1575 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1577 (when (article-goto-body)
1578 (let ((buffer-read-only nil)
1580 (while (setq elem (pop map))
1582 (while (search-forward (car elem) nil t)
1583 (replace-match (cadr elem)))))))))
1585 (defun article-treat-overstrike ()
1586 "Translate overstrikes into bold text."
1589 (when (article-goto-body)
1590 (let ((buffer-read-only nil))
1591 (while (search-forward "\b" nil t)
1592 (let ((next (char-after))
1593 (previous (char-after (- (point) 2))))
1594 ;; We do the boldification/underlining by hiding the
1595 ;; overstrikes and putting the proper text property
1599 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1600 (put-text-property (point) (1+ (point)) 'face 'bold))
1602 (gnus-article-hide-text-type
1603 (1- (point)) (1+ (point)) 'overstrike)
1605 (- (point) 2) (1- (point)) 'face 'underline))
1607 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1609 (point) (1+ (point)) 'face 'underline)))))))))
1611 (defun gnus-article-treat-unfold-headers ()
1612 "Unfold folded message headers.
1613 Only the headers that fit into the current window width will be
1616 (gnus-with-article-headers
1620 (mail-header-narrow-to-field)
1621 (let ((header (buffer-substring (point-min) (point-max))))
1624 (goto-char (point-min))
1625 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1626 (replace-match " " t t)))
1627 (setq length (- (point-max) (point-min) 1)))
1628 (when (< length (window-width))
1629 (while (re-search-forward "[\t ]*\n[\t ]+" nil t)
1630 (replace-match " " t t)))
1631 (goto-char (point-max)))))))
1633 (defun gnus-article-treat-body-boundary ()
1634 "Place a boundary line at the end of the headers."
1636 (gnus-with-article-headers
1637 (goto-char (point-max))
1638 (insert (make-string (1- (window-width)) ? )
1640 (put-text-property (point) (progn (forward-line -1) (point))
1641 'face 'gnus-body-separator-face)))
1643 (defun article-fill-long-lines ()
1644 "Fill lines that are wider than the window width."
1647 (let ((buffer-read-only nil)
1648 (width (window-width (get-buffer-window (current-buffer)))))
1651 (let ((adaptive-fill-mode nil)) ;Why? -sm
1654 (when (>= (current-column) (min fill-column width))
1655 (narrow-to-region (point) (gnus-point-at-bol))
1656 (fill-paragraph nil)
1657 (goto-char (point-max))
1659 (forward-line 1)))))))
1661 (defun article-capitalize-sentences ()
1662 "Capitalize the first word in each sentence."
1665 (let ((buffer-read-only nil)
1666 (paragraph-start "^[\n\^L]"))
1670 (forward-sentence)))))
1672 (defun article-remove-cr ()
1673 "Remove trailing CRs and then translate remaining CRs into LFs."
1676 (let ((buffer-read-only nil))
1677 (goto-char (point-min))
1678 (while (re-search-forward "\r+$" nil t)
1679 (replace-match "" t t))
1680 (goto-char (point-min))
1681 (while (search-forward "\r" nil t)
1682 (replace-match "\n" t t)))))
1684 (defun article-remove-trailing-blank-lines ()
1685 "Remove all trailing blank lines from the article."
1688 (let ((buffer-read-only nil))
1689 (goto-char (point-max))
1693 (while (and (not (bobp))
1694 (looking-at "^[ \t]*$")
1695 (not (gnus-annotation-in-region-p
1696 (point) (gnus-point-at-eol))))
1701 (defun article-display-x-face (&optional force)
1702 "Look for an X-Face header and display it if present."
1703 (interactive (list 'force))
1705 ;; Delete the old process, if any.
1706 (when (process-status "article-x-face")
1707 (delete-process "article-x-face"))
1708 (let ((inhibit-point-motion-hooks t)
1710 (case-fold-search t)
1713 (article-narrow-to-head)
1714 (when (and buffer-read-only ;; When type `W f'
1716 (goto-char (point-min))
1717 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
1718 (gnus-buffer-live-p gnus-original-article-buffer))
1719 (with-current-buffer gnus-original-article-buffer
1721 (article-narrow-to-head)
1722 (while (re-search-forward "^X-Face:" nil t)
1728 (1- (re-search-forward
1729 "^\\($\\|[^ \t]\\)" nil t))))))))
1731 (let (point start bface eface buffer-read-only)
1732 (goto-char (point-max))
1734 (setq bface (get-text-property (gnus-point-at-bol) 'face)
1735 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
1736 (goto-char (point-max))
1737 (setq point (point))
1740 (while (looking-at "\\([^:]+\\): *")
1741 (put-text-property (match-beginning 1) (1+ (match-end 1))
1743 (setq start (match-end 0))
1745 (while (looking-at "[\t ]")
1747 (put-text-property start (point)
1749 (goto-char (point-min))
1750 (setq from (message-fetch-field "from"))
1751 (goto-char (point-min))
1752 (while (and gnus-article-x-face-command
1755 ;; Check whether this face is censored.
1756 (not gnus-article-x-face-too-ugly)
1757 (and gnus-article-x-face-too-ugly from
1758 (not (string-match gnus-article-x-face-too-ugly
1760 ;; Has to be present.
1761 (re-search-forward "^X-Face:[\t ]*" nil t))
1762 ;; This used to try to do multiple faces (`while' instead of
1763 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1764 ;; work (b) it can crash some versions of Emacs (c) are
1765 ;; multiple faces really something to encourage?
1766 (when (stringp gnus-article-x-face-command)
1768 ;; We now have the area of the buffer where the X-Face is stored.
1771 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t)))
1773 ;; We display the face.
1774 (if (symbolp gnus-article-x-face-command)
1775 ;; The command is a lisp function, so we call it.
1776 (if (gnus-functionp gnus-article-x-face-command)
1777 (funcall gnus-article-x-face-command beg end)
1778 (error "%s is not a function" gnus-article-x-face-command))
1779 ;; The command is a string, so we interpret the command
1780 ;; as a, well, command, and fork it off.
1781 (let ((process-connection-type nil))
1782 (process-kill-without-query
1784 "article-x-face" nil shell-file-name shell-command-switch
1785 gnus-article-x-face-command))
1786 (process-send-region "article-x-face" beg end)
1787 (process-send-eof "article-x-face"))))))))))
1789 (defun article-decode-mime-words ()
1790 "Decode all MIME-encoded words in the article."
1793 (set-buffer gnus-article-buffer)
1794 (let ((inhibit-point-motion-hooks t)
1796 (mail-parse-charset gnus-newsgroup-charset)
1797 (mail-parse-ignored-charsets
1798 (save-excursion (set-buffer gnus-summary-buffer)
1799 gnus-newsgroup-ignored-charsets)))
1800 (mail-decode-encoded-word-region (point-min) (point-max)))))
1802 (defun article-decode-charset (&optional prompt)
1803 "Decode charset-encoded text in the article.
1804 If PROMPT (the prefix), prompt for a coding system to use."
1806 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1808 (mail-parse-charset gnus-newsgroup-charset)
1809 (mail-parse-ignored-charsets
1810 (save-excursion (condition-case nil
1811 (set-buffer gnus-summary-buffer)
1813 gnus-newsgroup-ignored-charsets))
1814 ct cte ctl charset format)
1817 (article-narrow-to-head)
1818 (setq ct (message-fetch-field "Content-Type" t)
1819 cte (message-fetch-field "Content-Transfer-Encoding" t)
1820 ctl (and ct (ignore-errors
1821 (mail-header-parse-content-type ct)))
1824 (mm-read-coding-system "Charset to decode: "))
1826 (mail-content-type-get ctl 'charset)))
1827 format (and ctl (mail-content-type-get ctl 'format)))
1829 (setq cte (mail-header-strip cte)))
1830 (if (and ctl (not (string-match "/" (car ctl))))
1832 (goto-char (point-max)))
1835 (narrow-to-region (point) (point-max))
1836 (when (and (eq mail-parse-charset 'gnus-decoded)
1837 (eq (mm-body-7-or-8) '8bit))
1838 ;; The text code could have been decoded.
1839 (setq charset mail-parse-charset))
1840 (when (and (or (not ctl)
1841 (equal (car ctl) "text/plain"))
1842 (not format)) ;; article with format will decode later.
1844 charset (and cte (intern (downcase
1845 (gnus-strip-whitespace cte))))
1848 (defun article-decode-encoded-words ()
1849 "Remove encoded-word encoding from headers."
1850 (let ((inhibit-point-motion-hooks t)
1851 (mail-parse-charset gnus-newsgroup-charset)
1852 (mail-parse-ignored-charsets
1853 (save-excursion (condition-case nil
1854 (set-buffer gnus-summary-buffer)
1856 gnus-newsgroup-ignored-charsets))
1859 (article-narrow-to-head)
1860 (funcall gnus-decode-header-function (point-min) (point-max)))))
1862 (defun article-decode-group-name ()
1863 "Decode group names in `Newsgroups:'."
1864 (let ((inhibit-point-motion-hooks t)
1866 (method (gnus-find-method-for-group gnus-newsgroup-name)))
1867 (when (and (or gnus-group-name-charset-method-alist
1868 gnus-group-name-charset-group-alist)
1869 (gnus-buffer-live-p gnus-original-article-buffer))
1870 (when (nnmail-fetch-field "Newsgroups")
1871 (nnheader-replace-header "Newsgroups"
1872 (gnus-decode-newsgroups
1873 (with-current-buffer
1874 gnus-original-article-buffer
1875 (nnmail-fetch-field "Newsgroups"))
1876 gnus-newsgroup-name method)))
1877 (when (nnmail-fetch-field "Followup-To")
1878 (nnheader-replace-header "Followup-To"
1879 (gnus-decode-newsgroups
1880 (with-current-buffer
1881 gnus-original-article-buffer
1882 (nnmail-fetch-field "Followup-To"))
1883 gnus-newsgroup-name method))))))
1885 (defun article-de-quoted-unreadable (&optional force read-charset)
1886 "Translate a quoted-printable-encoded article.
1887 If FORCE, decode the article whether it is marked as quoted-printable
1889 If READ-CHARSET, ask for a coding system."
1890 (interactive (list 'force current-prefix-arg))
1892 (let ((buffer-read-only nil) type charset)
1893 (if (gnus-buffer-live-p gnus-original-article-buffer)
1894 (with-current-buffer gnus-original-article-buffer
1896 (gnus-fetch-field "content-transfer-encoding"))
1897 (let* ((ct (gnus-fetch-field "content-type"))
1900 (mail-header-parse-content-type ct)))))
1901 (setq charset (and ctl
1902 (mail-content-type-get ctl 'charset)))
1903 (if (stringp charset)
1904 (setq charset (intern (downcase charset)))))))
1906 (setq charset (mm-read-coding-system "Charset: " charset)))
1908 (setq charset gnus-newsgroup-charset))
1910 (and type (let ((case-fold-search t))
1911 (string-match "quoted-printable" type))))
1913 (quoted-printable-decode-region
1914 (point) (point-max) (mm-charset-to-coding-system charset))))))
1916 (defun article-de-base64-unreadable (&optional force read-charset)
1917 "Translate a base64 article.
1918 If FORCE, decode the article whether it is marked as base64 not.
1919 If READ-CHARSET, ask for a coding system."
1920 (interactive (list 'force current-prefix-arg))
1922 (let ((buffer-read-only nil) type charset)
1923 (if (gnus-buffer-live-p gnus-original-article-buffer)
1924 (with-current-buffer gnus-original-article-buffer
1926 (gnus-fetch-field "content-transfer-encoding"))
1927 (let* ((ct (gnus-fetch-field "content-type"))
1930 (mail-header-parse-content-type ct)))))
1931 (setq charset (and ctl
1932 (mail-content-type-get ctl 'charset)))
1933 (if (stringp charset)
1934 (setq charset (intern (downcase charset)))))))
1936 (setq charset (mm-read-coding-system "Charset: " charset)))
1938 (setq charset gnus-newsgroup-charset))
1940 (and type (let ((case-fold-search t))
1941 (string-match "base64" type))))
1944 (narrow-to-region (point) (point-max))
1945 (base64-decode-region (point-min) (point-max))
1946 (mm-decode-coding-region
1947 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1952 (defun article-decode-HZ ()
1953 "Translate a HZ-encoded article."
1957 (let ((buffer-read-only nil))
1958 (rfc1843-decode-region (point-min) (point-max)))))
1960 (defun article-wash-html (&optional read-charset)
1961 "Format an html article.
1962 If READ-CHARSET, ask for a coding system."
1965 (let ((buffer-read-only nil)
1967 (if (gnus-buffer-live-p gnus-original-article-buffer)
1968 (with-current-buffer gnus-original-article-buffer
1969 (let* ((ct (gnus-fetch-field "content-type"))
1972 (mail-header-parse-content-type ct)))))
1973 (setq charset (and ctl
1974 (mail-content-type-get ctl 'charset)))
1975 (if (stringp charset)
1976 (setq charset (intern (downcase charset)))))))
1978 (setq charset (mm-read-coding-system "Charset: " charset)))
1980 (setq charset gnus-newsgroup-charset))
1982 (save-window-excursion
1984 (narrow-to-region (point) (point-max))
1986 (let ((w3-strict-width (window-width))
1987 (url-standalone-mode t)
1988 (w3-honor-stylesheets nil)
1989 (w3-delay-image-loads t))
1991 (w3-region (point-min) (point-max))
1994 (defun article-hide-list-identifiers ()
1995 "Remove list identifies from the Subject header.
1996 The `gnus-list-identifiers' variable specifies what to do."
1998 (let ((inhibit-point-motion-hooks t)
1999 (regexp (if (consp gnus-list-identifiers)
2000 (mapconcat 'identity gnus-list-identifiers " *\\|")
2001 gnus-list-identifiers))
2006 (article-narrow-to-head)
2007 (goto-char (point-min))
2008 (while (re-search-forward
2009 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2011 (delete-region (match-beginning 2) (match-end 0))
2012 (beginning-of-line))
2013 (when (re-search-forward
2014 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2015 (delete-region (match-beginning 1) (match-end 1))))))))
2017 (defun article-hide-pgp ()
2018 "Remove any PGP headers and signatures in the current article."
2022 (let ((inhibit-point-motion-hooks t)
2023 buffer-read-only beg end)
2025 ;; Hide the "header".
2026 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
2027 (push 'pgp gnus-article-wash-types)
2028 (delete-region (match-beginning 0) (match-end 0))
2029 ;; Remove armor headers (rfc2440 6.2)
2030 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
2033 ;; Hide the actual signature.
2034 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
2035 (setq end (1+ (match-beginning 0)))
2038 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
2040 ;; Perhaps we shouldn't hide to the end of the buffer
2041 ;; if there is no end to the signature?
2043 ;; Hide "- " PGP quotation markers.
2045 (narrow-to-region beg end)
2046 (goto-char (point-min))
2047 (while (re-search-forward "^- " nil t)
2049 (match-beginning 0) (match-end 0)))
2051 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
2053 (defun article-hide-pem (&optional arg)
2054 "Toggle hiding of any PEM headers and signatures in the current article.
2055 If given a negative prefix, always show; if given a positive prefix,
2057 (interactive (gnus-article-hidden-arg))
2058 (unless (gnus-article-check-hidden-text 'pem arg)
2060 (let (buffer-read-only end)
2061 (goto-char (point-min))
2062 ;; Hide the horrendously ugly "header".
2063 (when (and (search-forward
2064 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2066 (setq end (1+ (match-beginning 0))))
2067 (push 'pem gnus-article-wash-types)
2068 (gnus-article-hide-text-type
2070 (if (search-forward "\n\n" nil t)
2074 ;; Hide the trailer as well
2075 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2077 (gnus-article-hide-text-type
2078 (match-beginning 0) (match-end 0) 'pem)))))))
2080 (defun article-strip-banner ()
2081 "Strip the banner specified by the `banner' group parameter."
2085 (let ((inhibit-point-motion-hooks t)
2086 (banner (gnus-parameter-banner gnus-newsgroup-name))
2087 (gnus-signature-limit nil)
2088 buffer-read-only beg end)
2092 ((eq banner 'signature)
2093 (when (gnus-article-narrow-to-signature)
2096 (delete-region (point) (point-max))))
2098 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2099 (while (re-search-forward banner nil t)
2100 (delete-region (match-beginning 0) (match-end 0)))))
2102 (while (re-search-forward banner nil t)
2103 (delete-region (match-beginning 0) (match-end 0))))))))))
2105 (defun article-babel ()
2106 "Translate article using an online translation service."
2110 (set-buffer gnus-article-buffer)
2111 (when (article-goto-body)
2112 (let* ((buffer-read-only nil)
2115 (orig (buffer-substring start end))
2116 (trans (babel-as-string orig)))
2118 (narrow-to-region start end)
2119 (delete-region start end)
2122 (defun article-hide-signature (&optional arg)
2123 "Hide the signature in the current article.
2124 If given a negative prefix, always show; if given a positive prefix,
2126 (interactive (gnus-article-hidden-arg))
2127 (unless (gnus-article-check-hidden-text 'signature arg)
2130 (let ((buffer-read-only nil))
2131 (when (gnus-article-narrow-to-signature)
2132 (gnus-article-hide-text-type
2133 (point-min) (point-max) 'signature))))))
2134 (gnus-set-mode-line 'article))
2136 (defun article-strip-headers-in-body ()
2137 "Strip offensive headers from bodies."
2141 (let ((case-fold-search t))
2142 (when (looking-at "x-no-archive:")
2143 (gnus-delete-line)))))
2145 (defun article-strip-leading-blank-lines ()
2146 "Remove all blank lines from the beginning of the article."
2149 (let ((inhibit-point-motion-hooks t)
2151 (when (article-goto-body)
2152 (while (and (not (eobp))
2153 (looking-at "[ \t]*$"))
2154 (gnus-delete-line))))))
2156 (defun article-narrow-to-head ()
2157 "Narrow the buffer to the head of the message.
2158 Point is left at the beginning of the narrowed-to region."
2160 (goto-char (point-min))
2161 (if (search-forward "\n\n" nil 1)
2164 (goto-char (point-min)))
2166 (defun article-goto-body ()
2167 "Place point at the start of the body."
2168 (goto-char (point-min))
2170 ;; This variable is only bound when dealing with separate
2172 (article-goto-body-goes-to-point-min-p
2174 ((search-forward "\n\n" nil t)
2177 (goto-char (point-max))
2180 (defun article-strip-multiple-blank-lines ()
2181 "Replace consecutive blank lines with one empty line."
2184 (let ((inhibit-point-motion-hooks t)
2186 ;; First make all blank lines empty.
2188 (while (re-search-forward "^[ \t]+$" nil t)
2189 (unless (gnus-annotation-in-region-p
2190 (match-beginning 0) (match-end 0))
2191 (replace-match "" nil t)))
2192 ;; Then replace multiple empty lines with a single empty line.
2194 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2195 (unless (gnus-annotation-in-region-p
2196 (match-beginning 0) (match-end 0))
2197 (delete-region (match-beginning 1) (match-end 1)))))))
2199 (defun article-strip-leading-space ()
2200 "Remove all white space from the beginning of the lines in the article."
2203 (let ((inhibit-point-motion-hooks t)
2206 (while (re-search-forward "^[ \t]+" nil t)
2207 (replace-match "" t t)))))
2209 (defun article-strip-trailing-space ()
2210 "Remove all white space from the end of the lines in the article."
2213 (let ((inhibit-point-motion-hooks t)
2216 (while (re-search-forward "[ \t]+$" nil t)
2217 (replace-match "" t t)))))
2219 (defun article-strip-blank-lines ()
2220 "Strip leading, trailing and multiple blank lines."
2222 (article-strip-leading-blank-lines)
2223 (article-remove-trailing-blank-lines)
2224 (article-strip-multiple-blank-lines))
2226 (defun article-strip-all-blank-lines ()
2227 "Strip all blank lines."
2230 (let ((inhibit-point-motion-hooks t)
2233 (while (re-search-forward "^[ \t]*\n" nil t)
2234 (replace-match "" t t)))))
2236 (defun gnus-article-narrow-to-signature ()
2237 "Narrow to the signature; return t if a signature is found, else nil."
2238 (let ((inhibit-point-motion-hooks t))
2239 (when (gnus-article-search-signature)
2241 ;; Check whether we have some limits to what we consider
2242 ;; to be a signature.
2243 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2244 (list gnus-signature-limit)))
2246 (while (setq limit (pop limits))
2247 (if (or (and (integerp limit)
2248 (< (- (point-max) (point)) limit))
2250 (< (count-lines (point) (point-max)) limit))
2251 (and (gnus-functionp limit)
2253 (and (stringp limit)
2254 (not (re-search-forward limit nil t))))
2255 () ; This limit did not succeed.
2259 (narrow-to-region (point) (point-max))
2262 (defun gnus-article-search-signature ()
2263 "Search the current buffer for the signature separator.
2264 Put point at the beginning of the signature separator."
2265 (let ((cur (point)))
2266 (goto-char (point-max))
2267 (if (if (stringp gnus-signature-separator)
2268 (re-search-backward gnus-signature-separator nil t)
2269 (let ((seps gnus-signature-separator))
2271 (not (re-search-backward (car seps) nil t)))
2278 (defun gnus-article-hidden-arg ()
2279 "Return the current prefix arg as a number, or 0 if no prefix."
2280 (list (if current-prefix-arg
2281 (prefix-numeric-value current-prefix-arg)
2284 (defun gnus-article-check-hidden-text (type arg)
2285 "Return nil if hiding is necessary.
2286 Arg can be nil or a number. nil and positive means hide, negative
2287 means show, 0 means toggle."
2290 (let ((hide (gnus-article-hidden-text-p type)))
2296 (gnus-article-show-hidden-text type)
2299 (if (eq hide 'hidden)
2301 (gnus-article-show-hidden-text type)
2305 (defun gnus-article-hidden-text-p (type)
2306 "Say whether the current buffer contains hidden text of type TYPE."
2307 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2309 (not (get-text-property pos 'invisible))
2310 (not (get-text-property pos 'dummy-invisible)))
2312 (text-property-any (1+ pos) (point-max) 'article-type type)))
2317 (defun gnus-article-show-hidden-text (type &optional dummy)
2318 "Show all hidden text of type TYPE.
2319 Originally it is hide instead of DUMMY."
2320 (let ((buffer-read-only nil)
2321 (inhibit-point-motion-hooks t))
2322 (gnus-remove-text-properties-when
2324 (point-min) (point-max)
2325 (cons 'article-type (cons type
2326 gnus-hidden-properties)))
2327 (setq gnus-article-wash-types (delq type gnus-article-wash-types))))
2329 (defconst article-time-units
2330 `((year . ,(* 365.25 24 60 60))
2331 (week . ,(* 7 24 60 60))
2332 (day . ,(* 24 60 60))
2336 "Mapping from time units to seconds.")
2338 (defun article-date-ut (&optional type highlight header)
2339 "Convert DATE date to universal time in the current article.
2340 If TYPE is `local', convert to local time; if it is `lapsed', output
2341 how much time has lapsed since DATE. For `lapsed', the value of
2342 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2343 should replace the \"Date:\" one, or should be added below it."
2344 (interactive (list 'ut t))
2345 (let* ((header (or header
2346 (message-fetch-field "date")
2348 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2351 ((not gnus-article-date-lapsed-new-header)
2357 (date (if (vectorp header) (mail-header-date header)
2359 (inhibit-point-motion-hooks t)
2364 (article-narrow-to-head)
2365 (when (re-search-forward tdate-regexp nil t)
2366 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2367 date (or (get-text-property (gnus-point-at-bol)
2370 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2372 (when (and date (not (string= date "")))
2373 (goto-char (point-min))
2374 (let ((buffer-read-only nil))
2375 ;; Delete any old Date headers.
2376 (while (re-search-forward date-regexp nil t)
2378 (delete-region (progn (beginning-of-line) (point))
2379 (progn (forward-line 1) (point)))
2380 (delete-region (progn (beginning-of-line) (point))
2381 (progn (end-of-line) (point)))
2382 (setq pos (point))))
2383 (when (and (not pos) (re-search-forward tdate-regexp nil t))
2385 (if pos (goto-char pos))
2386 (insert (article-make-date-line date (or type 'ut)))
2392 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2393 (put-text-property (match-beginning 1) (1+ (match-end 1))
2394 'original-date date)
2395 (put-text-property (match-beginning 1) (1+ (match-end 1))
2397 (put-text-property (match-beginning 2) (match-end 2)
2400 (defun article-make-date-line (date type)
2401 "Return a DATE line of TYPE."
2402 (unless (memq type '(local ut original user iso8601 lapsed english))
2403 (error "Unknown conversion type: %s" type))
2405 (let ((time (date-to-time date)))
2407 ;; Convert to the local timezone.
2409 (let ((tz (car (current-time-zone time))))
2410 (format "Date: %s %s%02d%02d" (current-time-string time)
2411 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2412 (/ (% (abs tz) 3600) 60))))
2413 ;; Convert to Universal Time.
2416 (current-time-string
2417 (let* ((e (parse-time-string date))
2418 (tm (apply 'encode-time e))
2420 (ls (- (cadr tm) (car (current-time-zone time)))))
2421 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2422 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2425 ;; Get the original date from the article.
2426 ((eq type 'original)
2427 (concat "Date: " (if (string-match "\n+$" date)
2428 (substring date 0 (match-beginning 0))
2430 ;; Let the user define the format.
2432 (if (gnus-functionp gnus-article-time-format)
2433 (funcall gnus-article-time-format time)
2436 (format-time-string gnus-article-time-format time))))
2439 (let ((tz (car (current-time-zone time))))
2442 (format-time-string "%Y%m%dT%H%M%S" time)
2443 (format "%s%02d%02d"
2444 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2445 (/ (% (abs tz) 3600) 60)))))
2446 ;; Do an X-Sent lapsed format.
2448 ;; If the date is seriously mangled, the timezone functions are
2449 ;; liable to bug out, so we ignore all errors.
2450 (let* ((now (current-time))
2451 (real-time (subtract-time now time))
2452 (real-sec (and real-time
2453 (+ (* (float (car real-time)) 65536)
2455 (sec (and real-time (abs real-sec)))
2465 ;; This is a bit convoluted, but basically we go
2466 ;; through the time units for years, weeks, etc,
2467 ;; and divide things to see whether that results
2468 ;; in positive answers.
2471 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2472 ;; The (remaining) seconds are too few to
2473 ;; be divided into this time unit.
2475 ;; It's big enough, so we output it.
2476 (setq sec (- sec (* num (cdr unit))))
2478 (concat (if prev ", " "") (int-to-string
2480 " " (symbol-name (car unit))
2481 (if (> num 1) "s" ""))
2483 article-time-units "")
2484 ;; If dates are odd, then it might appear like the
2485 ;; article was sent in the future.
2488 " in the future"))))))
2489 ;; Display the date in proper English
2491 (let ((dtime (decode-time time)))
2494 (number-to-string (nth 3 dtime))
2495 (let ((digit (% (nth 3 dtime) 10)))
2497 ((memq (nth 3 dtime) '(11 12 13)) "th")
2503 (nth (1- (nth 4 dtime)) gnus-english-month-names)
2505 (number-to-string (nth 5 dtime))
2507 (format "%02d" (nth 2 dtime))
2509 (format "%02d" (nth 1 dtime)))))))
2511 (format "Date: %s (from Oort)" date))))
2513 (defun article-date-local (&optional highlight)
2514 "Convert the current article date to the local timezone."
2515 (interactive (list t))
2516 (article-date-ut 'local highlight))
2518 (defun article-date-english (&optional highlight)
2519 "Convert the current article date to something that is proper English."
2520 (interactive (list t))
2521 (article-date-ut 'english highlight))
2523 (defun article-date-original (&optional highlight)
2524 "Convert the current article date to what it was originally.
2525 This is only useful if you have used some other date conversion
2526 function and want to see what the date was before converting."
2527 (interactive (list t))
2528 (article-date-ut 'original highlight))
2530 (defun article-date-lapsed (&optional highlight)
2531 "Convert the current article date to time lapsed since it was sent."
2532 (interactive (list t))
2533 (article-date-ut 'lapsed highlight))
2535 (defun article-update-date-lapsed ()
2536 "Function to be run from a timer to update the lapsed time line."
2537 (let (deactivate-mark)
2542 (set-buffer (window-buffer w))
2543 (when (eq major-mode 'gnus-article-mode)
2544 (goto-char (point-min))
2545 (when (re-search-forward "^X-Sent:" nil t)
2546 (article-date-lapsed t))))
2549 (defun gnus-start-date-timer (&optional n)
2550 "Start a timer to update the X-Sent header in the article buffers.
2551 The numerical prefix says how frequently (in seconds) the function
2556 (gnus-stop-date-timer)
2557 (setq article-lapsed-timer
2558 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2560 (defun gnus-stop-date-timer ()
2561 "Stop the X-Sent timer."
2563 (when article-lapsed-timer
2564 (nnheader-cancel-timer article-lapsed-timer)
2565 (setq article-lapsed-timer nil)))
2567 (defun article-date-user (&optional highlight)
2568 "Convert the current article date to the user-defined format.
2569 This format is defined by the `gnus-article-time-format' variable."
2570 (interactive (list t))
2571 (article-date-ut 'user highlight))
2573 (defun article-date-iso8601 (&optional highlight)
2574 "Convert the current article date to ISO8601."
2575 (interactive (list t))
2576 (article-date-ut 'iso8601 highlight))
2578 (defun article-show-all ()
2579 "Show all hidden text in the article buffer."
2582 (let ((buffer-read-only nil))
2583 (gnus-article-unhide-text (point-min) (point-max)))))
2585 (defun article-remove-leading-whitespace ()
2586 "Remove excessive whitespace from all headers."
2590 (let ((buffer-read-only nil))
2591 (article-narrow-to-head)
2592 (goto-char (point-min))
2593 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
2594 (delete-region (match-beginning 1) (match-end 1)))))))
2596 (defun article-emphasize (&optional arg)
2597 "Emphasize text according to `gnus-emphasis-alist'."
2598 (interactive (gnus-article-hidden-arg))
2599 (unless (gnus-article-check-hidden-text 'emphasis arg)
2603 (with-current-buffer gnus-summary-buffer
2604 gnus-article-emphasis-alist)
2606 gnus-emphasis-alist))
2607 (buffer-read-only nil)
2608 (props (append '(article-type emphasis)
2609 gnus-hidden-properties))
2610 regexp elem beg invisible visible face)
2613 (while (setq elem (pop alist))
2615 (setq regexp (car elem)
2616 invisible (nth 1 elem)
2617 visible (nth 2 elem)
2619 (while (re-search-forward regexp nil t)
2620 (when (and (match-beginning visible) (match-beginning invisible))
2621 (gnus-article-hide-text
2622 (match-beginning invisible) (match-end invisible) props)
2623 (gnus-article-unhide-text-type
2624 (match-beginning visible) (match-end visible) 'emphasis)
2625 (gnus-put-overlay-excluding-newlines
2626 (match-beginning visible) (match-end visible) 'face face)
2627 (push 'emphasis gnus-article-wash-types)
2628 (goto-char (match-end invisible)))))))))
2630 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2631 "Setup newsgroup emphasis alist."
2632 (unless gnus-article-emphasis-alist
2633 (let ((name (and gnus-newsgroup-name
2634 (gnus-group-real-name gnus-newsgroup-name))))
2635 (make-local-variable 'gnus-article-emphasis-alist)
2636 (setq gnus-article-emphasis-alist
2638 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2639 (while (setq elem (pop alist))
2640 (when (and name (string-match (car elem) name))
2642 highlight (copy-sequence (cdr elem)))))
2644 (copy-sequence highlight-words)
2645 (if gnus-newsgroup-name
2646 (copy-sequence (gnus-group-find-parameter
2647 gnus-newsgroup-name 'highlight-words t)))
2648 gnus-emphasis-alist)))))
2651 (defvar gnus-summary-article-menu)
2652 (defvar gnus-summary-post-menu))
2654 ;;; Saving functions.
2656 (defun gnus-article-save (save-buffer file &optional num)
2657 "Save the currently selected article."
2658 (unless gnus-save-all-headers
2659 ;; Remove headers according to `gnus-saved-headers'.
2660 (let ((gnus-visible-headers
2661 (or gnus-saved-headers gnus-visible-headers))
2662 (gnus-article-buffer save-buffer))
2664 (set-buffer save-buffer)
2665 (article-hide-headers 1 t))))
2666 (save-window-excursion
2667 (if (not gnus-default-article-saver)
2668 (error "No default saver is defined")
2669 ;; !!! Magic! The saving functions all save
2670 ;; `gnus-save-article-buffer' (or so they think), but we
2671 ;; bind that variable to our save-buffer.
2672 (set-buffer gnus-article-buffer)
2673 (let* ((gnus-save-article-buffer save-buffer)
2676 ((not gnus-prompt-before-saving) 'default)
2677 ((eq gnus-prompt-before-saving 'always) nil)
2679 (gnus-number-of-articles-to-be-saved
2680 (when (eq gnus-prompt-before-saving t)
2682 (set-buffer gnus-article-current-summary)
2683 (funcall gnus-default-article-saver filename)))))
2685 (defun gnus-read-save-file-name (prompt &optional filename
2686 function group headers variable)
2688 (funcall function group headers (symbol-value variable)))
2693 ((eq filename 'default)
2699 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2702 (if (and gnus-number-of-articles-to-be-saved
2703 (> gnus-number-of-articles-to-be-saved 1))
2704 (format "these %d articles"
2705 gnus-number-of-articles-to-be-saved)
2708 ;; Let the split methods have their say.
2710 ;; No split name was found.
2713 (concat prompt " (default "
2714 (file-name-nondirectory default-name) ") ")
2715 (file-name-directory default-name)
2717 ;; A single group name is returned.
2718 ((stringp split-name)
2720 (funcall function split-name headers
2721 (symbol-value variable)))
2723 (concat prompt " (default "
2724 (file-name-nondirectory default-name) ") ")
2725 (file-name-directory default-name)
2727 ;; A single split name was found
2728 ((= 1 (length split-name))
2729 (let* ((name (expand-file-name
2731 gnus-article-save-directory))
2732 (dir (cond ((file-directory-p name)
2733 (file-name-as-directory name))
2734 ((file-exists-p name) name)
2735 (t gnus-article-save-directory))))
2737 (concat prompt " (default " name ") ")
2739 ;; A list of splits was found.
2741 (setq split-name (nreverse split-name))
2743 (let ((file-name-history
2744 (nconc split-name file-name-history)))
2748 (concat prompt " (`M-p' for defaults) ")
2749 gnus-article-save-directory
2751 gnus-article-save-directory)))
2752 (car (push result file-name-history)))))))
2753 ;; Create the directory.
2754 (gnus-make-directory (file-name-directory file))
2755 ;; If we have read a directory, we append the default file name.
2756 (when (file-directory-p file)
2757 (setq file (expand-file-name (file-name-nondirectory
2759 (file-name-as-directory file))))
2760 ;; Possibly translate some characters.
2761 (nnheader-translate-file-chars file))))))
2762 (gnus-make-directory (file-name-directory result))
2763 (set variable result)))
2765 (defun gnus-article-archive-name (group)
2766 "Return the first instance of an \"Archive-name\" in the current buffer."
2767 (let ((case-fold-search t))
2768 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2769 (nnheader-concat gnus-article-save-directory
2770 (match-string 1)))))
2772 (defun gnus-article-nndoc-name (group)
2773 "If GROUP is an nndoc group, return the name of the parent group."
2774 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2775 (gnus-group-get-parameter group 'save-article-group)))
2777 (defun gnus-summary-save-in-rmail (&optional filename)
2778 "Append this article to Rmail 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 rmail file:" filename
2783 gnus-rmail-save-name gnus-newsgroup-name
2784 gnus-current-headers 'gnus-newsgroup-last-rmail))
2785 (gnus-eval-in-buffer-window gnus-save-article-buffer
2789 (gnus-output-to-rmail filename))))
2792 (defun gnus-summary-save-in-mail (&optional filename)
2793 "Append this article to Unix mail file.
2794 Optional argument FILENAME specifies file name.
2795 Directory to save to is default to `gnus-article-save-directory'."
2796 (setq filename (gnus-read-save-file-name
2797 "Save %s in Unix mail file:" filename
2798 gnus-mail-save-name gnus-newsgroup-name
2799 gnus-current-headers 'gnus-newsgroup-last-mail))
2800 (gnus-eval-in-buffer-window gnus-save-article-buffer
2804 (if (and (file-readable-p filename)
2805 (mail-file-babyl-p filename))
2806 (rmail-output-to-rmail-file filename t)
2807 (gnus-output-to-mail filename)))))
2810 (defun gnus-summary-save-in-file (&optional filename overwrite)
2811 "Append this article to file.
2812 Optional argument FILENAME specifies file name.
2813 Directory to save to is default to `gnus-article-save-directory'."
2814 (setq filename (gnus-read-save-file-name
2815 "Save %s in file:" filename
2816 gnus-file-save-name gnus-newsgroup-name
2817 gnus-current-headers 'gnus-newsgroup-last-file))
2818 (gnus-eval-in-buffer-window gnus-save-article-buffer
2822 (when (and overwrite
2823 (file-exists-p filename))
2824 (delete-file filename))
2825 (gnus-output-to-file filename))))
2828 (defun gnus-summary-write-to-file (&optional filename)
2829 "Write this article to a file, overwriting it if the file exists.
2830 Optional argument FILENAME specifies file name.
2831 The directory to save in defaults to `gnus-article-save-directory'."
2832 (gnus-summary-save-in-file nil t))
2834 (defun gnus-summary-save-body-in-file (&optional filename)
2835 "Append this article body to a file.
2836 Optional argument FILENAME specifies file name.
2837 The directory to save in defaults to `gnus-article-save-directory'."
2838 (setq filename (gnus-read-save-file-name
2839 "Save %s body in file:" filename
2840 gnus-file-save-name gnus-newsgroup-name
2841 gnus-current-headers 'gnus-newsgroup-last-file))
2842 (gnus-eval-in-buffer-window gnus-save-article-buffer
2846 (when (article-goto-body)
2847 (narrow-to-region (point) (point-max)))
2848 (gnus-output-to-file filename))))
2851 (defun gnus-summary-save-in-pipe (&optional command)
2852 "Pipe this article to subprocess."
2854 (cond ((and (eq command 'default)
2855 gnus-last-shell-command)
2856 gnus-last-shell-command)
2861 "Shell command on %s: "
2862 (if (and gnus-number-of-articles-to-be-saved
2863 (> gnus-number-of-articles-to-be-saved 1))
2864 (format "these %d articles"
2865 gnus-number-of-articles-to-be-saved)
2867 gnus-last-shell-command))))
2868 (when (string-equal command "")
2869 (if gnus-last-shell-command
2870 (setq command gnus-last-shell-command)
2871 (error "A command is required")))
2872 (gnus-eval-in-buffer-window gnus-article-buffer
2875 (shell-command-on-region (point-min) (point-max) command nil)))
2876 (setq gnus-last-shell-command command))
2878 (defun gnus-summary-pipe-to-muttprint (&optional command)
2879 "Pipe this article to muttprint."
2880 (setq command (read-string
2881 "Print using command: " gnus-summary-muttprint-program
2882 nil gnus-summary-muttprint-program))
2883 (gnus-summary-save-in-pipe command))
2885 ;;; Article file names when saving.
2887 (defun gnus-capitalize-newsgroup (newsgroup)
2888 "Capitalize NEWSGROUP name."
2889 (when (not (zerop (length newsgroup)))
2890 (concat (char-to-string (upcase (aref newsgroup 0)))
2891 (substring newsgroup 1))))
2893 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2894 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2895 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2896 Otherwise, it is like ~/News/news/group/num."
2899 (concat (if (gnus-use-long-file-name 'not-save)
2900 (gnus-capitalize-newsgroup newsgroup)
2901 (gnus-newsgroup-directory-form newsgroup))
2902 "/" (int-to-string (mail-header-number headers)))
2903 gnus-article-save-directory)))
2905 (string-equal (file-name-directory default)
2906 (file-name-directory last-file))
2907 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2909 (or last-file default))))
2911 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2912 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2913 If variable `gnus-use-long-file-name' is non-nil, it is
2914 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2917 (concat (if (gnus-use-long-file-name 'not-save)
2919 (gnus-newsgroup-directory-form newsgroup))
2920 "/" (int-to-string (mail-header-number headers)))
2921 gnus-article-save-directory)))
2923 (string-equal (file-name-directory default)
2924 (file-name-directory last-file))
2925 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2927 (or last-file default))))
2929 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2930 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2931 If variable `gnus-use-long-file-name' is non-nil, it is
2932 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2935 (if (gnus-use-long-file-name 'not-save)
2938 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
2940 gnus-article-save-directory)))
2942 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
2943 "Generate file name from sender."
2944 (let ((from (mail-header-from headers)))
2946 (if (and from (string-match "\\([^ <]+\\)@" from))
2947 (match-string 1 from)
2949 gnus-article-save-directory)))
2951 (defun article-verify-x-pgp-sig ()
2954 (if (gnus-buffer-live-p gnus-original-article-buffer)
2955 (let ((sig (with-current-buffer gnus-original-article-buffer
2956 (gnus-fetch-field "X-PGP-Sig")))
2960 (mml2015-clear-verify-function))
2962 (insert-buffer gnus-original-article-buffer)
2963 (setq items (split-string sig))
2964 (message-narrow-to-head)
2965 (let ((inhibit-point-motion-hooks t)
2966 (case-fold-search t))
2967 ;; Don't verify multiple headers.
2968 (setq headers (mapconcat (lambda (header)
2970 (mail-fetch-field header) "\n"))
2971 (split-string (nth 1 items) ",") "")))
2972 (delete-region (point-min) (point-max))
2973 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2974 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2979 (if (looking-at "^-")
2982 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2983 (insert "Version: " (car items) "\n\n")
2984 (insert (mapconcat 'identity (cddr items) "\n"))
2985 (insert "\n-----END PGP SIGNATURE-----\n")
2986 (let ((mm-security-handle (list (format "multipart/signed"))))
2987 (mml2015-clean-buffer)
2988 (let ((coding-system-for-write (or gnus-newsgroup-charset
2990 (funcall (mml2015-clear-verify-function)))
2992 (or (mm-handle-multipart-ctl-parameter
2993 mm-security-handle 'gnus-details)
2994 (mm-handle-multipart-ctl-parameter
2995 mm-security-handle 'gnus-info)))))
2997 (let (buffer-read-only bface eface)
2999 (message-narrow-to-head)
3000 (goto-char (point-max))
3002 (setq bface (get-text-property (gnus-point-at-bol) 'face)
3003 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
3004 (message-remove-header "X-Gnus-PGP-Verify")
3005 (if (re-search-forward "^X-PGP-Sig:" nil t)
3007 (goto-char (point-max)))
3008 (narrow-to-region (point) (point))
3009 (insert "X-Gnus-PGP-Verify: " info "\n")
3010 (goto-char (point-min))
3013 (if (not (looking-at "^[ \t]"))
3017 (goto-char (point-min))
3018 (when (looking-at "\\([^:]+\\): *")
3019 (put-text-property (match-beginning 1) (1+ (match-end 1))
3021 (put-text-property (match-end 0) (point-max)
3022 'face eface)))))))))
3024 (defun article-verify-cancel-lock ()
3025 "Verify Cancel-Lock header."
3027 (if (gnus-buffer-live-p gnus-original-article-buffer)
3028 (canlock-verify gnus-original-article-buffer)))
3035 (setq afunc (car func)
3038 gfunc (intern (format "gnus-%s" func))))
3041 `(lambda (&optional interactive &rest args)
3042 ,(documentation afunc t)
3043 (interactive (list t))
3045 (set-buffer gnus-article-buffer)
3047 (call-interactively ',afunc)
3048 (apply ',afunc args))))))))
3049 '(article-hide-headers
3050 article-verify-x-pgp-sig
3051 article-verify-cancel-lock
3052 article-hide-boring-headers
3053 article-treat-overstrike
3054 article-fill-long-lines
3055 article-capitalize-sentences
3057 article-remove-leading-whitespace
3058 article-display-x-face
3059 article-de-quoted-unreadable
3060 article-de-base64-unreadable
3063 article-hide-list-identifiers
3065 article-strip-banner
3068 article-hide-signature
3069 article-strip-headers-in-body
3070 article-remove-trailing-blank-lines
3071 article-strip-leading-blank-lines
3072 article-strip-multiple-blank-lines
3073 article-strip-leading-space
3074 article-strip-trailing-space
3075 article-strip-blank-lines
3076 article-strip-all-blank-lines
3077 article-replace-with-quoted-text
3079 article-date-english
3080 article-date-iso8601
3081 article-date-original
3083 article-decode-mime-words
3084 article-decode-charset
3085 article-decode-encoded-words
3089 article-treat-dumbquotes
3090 article-normalize-headers
3091 (article-show-all . gnus-article-show-all-headers))))
3094 ;;; Gnus article mode
3097 (put 'gnus-article-mode 'mode-class 'special)
3099 (set-keymap-parent gnus-article-mode-map widget-keymap)
3101 (gnus-define-keys gnus-article-mode-map
3102 " " gnus-article-goto-next-page
3103 "\177" gnus-article-goto-prev-page
3104 [delete] gnus-article-goto-prev-page
3105 [backspace] gnus-article-goto-prev-page
3106 "\C-c^" gnus-article-refer-article
3107 "h" gnus-article-show-summary
3108 "s" gnus-article-show-summary
3109 "\C-c\C-m" gnus-article-mail
3110 "?" gnus-article-describe-briefly
3111 "e" gnus-summary-edit-article
3112 "<" beginning-of-buffer
3114 "\C-c\C-i" gnus-info-find-node
3116 "\C-hk" gnus-article-describe-key
3117 "\C-hc" gnus-article-describe-key-briefly
3119 "\C-d" gnus-article-read-summary-keys
3120 "\M-*" gnus-article-read-summary-keys
3121 "\M-#" gnus-article-read-summary-keys
3122 "\M-^" gnus-article-read-summary-keys
3123 "\M-g" gnus-article-read-summary-keys)
3125 (substitute-key-definition
3126 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3128 (defun gnus-article-make-menu-bar ()
3129 (unless (boundp 'gnus-article-commands-menu)
3130 (gnus-summary-make-menu-bar))
3131 (gnus-turn-off-edit-menu 'article)
3132 (unless (boundp 'gnus-article-article-menu)
3134 gnus-article-article-menu gnus-article-mode-map ""
3136 ["Scroll forwards" gnus-article-goto-next-page t]
3137 ["Scroll backwards" gnus-article-goto-prev-page t]
3138 ["Show summary" gnus-article-show-summary t]
3139 ["Fetch Message-ID at point" gnus-article-refer-article t]
3140 ["Mail to address at point" gnus-article-mail t]
3141 ["Send a bug report" gnus-bug t]))
3144 gnus-article-treatment-menu gnus-article-mode-map ""
3145 ;; Fixme: this should use :active (and maybe :visible).
3147 ["Hide headers" gnus-article-hide-headers t]
3148 ["Hide signature" gnus-article-hide-signature t]
3149 ["Hide citation" gnus-article-hide-citation t]
3150 ["Treat overstrike" gnus-article-treat-overstrike t]
3151 ["Remove carriage return" gnus-article-remove-cr t]
3152 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3153 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3154 ["Remove base64" gnus-article-de-base64-unreadable t]
3155 ["Treat html" gnus-article-wash-html t]
3156 ["Decode HZ" gnus-article-decode-HZ t]))
3158 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3160 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3162 (gnus-run-hooks 'gnus-article-menu-hook)))
3164 ;; Fixme: do something for the Emacs tool bar in Article mode a la
3167 (defun gnus-article-mode ()
3168 "Major mode for displaying an article.
3170 All normal editing commands are switched off.
3172 The following commands are available in addition to all summary mode
3174 \\<gnus-article-mode-map>
3175 \\[gnus-article-next-page]\t Scroll the article one page forwards
3176 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3177 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3178 \\[gnus-article-show-summary]\t Display the summary buffer
3179 \\[gnus-article-mail]\t Send a reply to the address near point
3180 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3181 \\[gnus-info-find-node]\t Go to the Gnus info node"
3183 (gnus-simplify-mode-line)
3184 (setq mode-name "Article")
3185 (setq major-mode 'gnus-article-mode)
3186 (make-local-variable 'minor-mode-alist)
3187 (use-local-map gnus-article-mode-map)
3188 (when (gnus-visual-p 'article-menu 'menu)
3189 (gnus-article-make-menu-bar))
3190 (gnus-update-format-specifications nil 'article-mode)
3191 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3192 (make-local-variable 'gnus-page-broken)
3193 (make-local-variable 'gnus-button-marker-list)
3194 (make-local-variable 'gnus-article-current-summary)
3195 (make-local-variable 'gnus-article-mime-handles)
3196 (make-local-variable 'gnus-article-decoded-p)
3197 (make-local-variable 'gnus-article-mime-handle-alist)
3198 (make-local-variable 'gnus-article-wash-types)
3199 (make-local-variable 'gnus-article-charset)
3200 (make-local-variable 'gnus-article-ignored-charsets)
3201 (gnus-set-default-directory)
3202 (buffer-disable-undo)
3203 (setq buffer-read-only t)
3204 (set-syntax-table gnus-article-mode-syntax-table)
3205 (mm-enable-multibyte)
3206 (gnus-run-hooks 'gnus-article-mode-hook))
3208 (defun gnus-article-setup-buffer ()
3209 "Initialize the article buffer."
3210 (let* ((name (if gnus-single-article-buffer "*Article*"
3211 (concat "*Article " gnus-newsgroup-name "*")))
3213 (progn (string-match "\\*Article" name)
3214 (concat " *Original Article"
3215 (substring name (match-end 0))))))
3216 (setq gnus-article-buffer name)
3217 (setq gnus-original-article-buffer original)
3218 (setq gnus-article-mime-handle-alist nil)
3219 ;; This might be a variable local to the summary buffer.
3220 (unless gnus-single-article-buffer
3222 (set-buffer gnus-summary-buffer)
3223 (setq gnus-article-buffer name)
3224 (setq gnus-original-article-buffer original)
3225 (gnus-set-global-variables)))
3226 (gnus-article-setup-highlight-words)
3227 ;; Init original article buffer.
3229 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3230 (mm-enable-multibyte)
3231 (setq major-mode 'gnus-original-article-mode)
3232 (make-local-variable 'gnus-original-article))
3233 (if (get-buffer name)
3236 (when gnus-article-mime-handles
3237 (mm-destroy-parts gnus-article-mime-handles)
3238 (setq gnus-article-mime-handles nil))
3239 ;; Set it to nil in article-buffer!
3240 (setq gnus-article-mime-handle-alist nil)
3241 (buffer-disable-undo)
3242 (setq buffer-read-only t)
3243 (unless (eq major-mode 'gnus-article-mode)
3244 (gnus-article-mode))
3247 (set-buffer (gnus-get-buffer-create name))
3249 (make-local-variable 'gnus-summary-buffer)
3250 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3251 (current-buffer)))))
3253 ;; Set article window start at LINE, where LINE is the number of lines
3254 ;; from the head of the article.
3255 (defun gnus-article-set-window-start (&optional line)
3257 (gnus-get-buffer-window gnus-article-buffer t)
3259 (set-buffer gnus-article-buffer)
3260 (goto-char (point-min))
3263 (gnus-message 6 "Moved to bookmark")
3264 (search-forward "\n\n" nil t)
3268 (defun gnus-article-prepare (article &optional all-headers header)
3269 "Prepare ARTICLE in article mode buffer.
3270 ARTICLE should either be an article number or a Message-ID.
3271 If ARTICLE is an id, HEADER should be the article headers.
3272 If ALL-HEADERS is non-nil, no headers are hidden."
3274 ;; Make sure we start in a summary buffer.
3275 (unless (eq major-mode 'gnus-summary-mode)
3276 (set-buffer gnus-summary-buffer))
3277 (setq gnus-summary-buffer (current-buffer))
3278 (let* ((gnus-article (if header (mail-header-number header) article))
3279 (summary-buffer (current-buffer))
3280 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3281 (group gnus-newsgroup-name)
3284 (gnus-article-setup-buffer)
3285 (set-buffer gnus-article-buffer)
3286 ;; Deactivate active regions.
3287 (when (and (boundp 'transient-mark-mode)
3288 transient-mark-mode)
3289 (setq mark-active nil))
3290 (if (not (setq result (let ((buffer-read-only nil))
3291 (gnus-request-article-this-buffer
3293 ;; There is no such article.
3295 (when (and (numberp article)
3296 (not (memq article gnus-newsgroup-sparse)))
3297 (setq gnus-article-current
3298 (cons gnus-newsgroup-name article))
3299 (set-buffer gnus-summary-buffer)
3300 (setq gnus-current-article article)
3301 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3303 (gnus-summary-set-agent-mark article)
3304 (message "Message marked for downloading"))
3305 (gnus-summary-mark-article article gnus-canceled-mark)
3306 (unless (memq article gnus-newsgroup-sparse)
3307 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3308 (if (or (eq result 'pseudo)
3309 (eq result 'nneething))
3312 (set-buffer summary-buffer)
3313 (push article gnus-newsgroup-history)
3314 (setq gnus-last-article gnus-current-article
3315 gnus-current-article 0
3316 gnus-current-headers nil
3317 gnus-article-current nil)
3318 (if (eq result 'nneething)
3319 (gnus-configure-windows 'summary)
3320 (gnus-configure-windows 'article))
3321 (gnus-set-global-variables))
3322 (let ((gnus-article-mime-handle-alist-1
3323 gnus-article-mime-handle-alist))
3324 (gnus-set-mode-line 'article)))
3325 ;; The result from the `request' was an actual article -
3326 ;; or at least some text that is now displayed in the
3328 (when (and (numberp article)
3329 (not (eq article gnus-current-article)))
3330 ;; Seems like a new article has been selected.
3331 ;; `gnus-current-article' must be an article number.
3333 (set-buffer summary-buffer)
3334 (push article gnus-newsgroup-history)
3335 (setq gnus-last-article gnus-current-article
3336 gnus-current-article article
3337 gnus-current-headers
3338 (gnus-summary-article-header gnus-current-article)
3339 gnus-article-current
3340 (cons gnus-newsgroup-name gnus-current-article))
3341 (unless (vectorp gnus-current-headers)
3342 (setq gnus-current-headers nil))
3343 (gnus-summary-goto-subject gnus-current-article)
3344 (when (gnus-summary-show-thread)
3345 ;; If the summary buffer really was folded, the
3346 ;; previous goto may not actually have gone to
3347 ;; the right article, but the thread root instead.
3349 (gnus-summary-goto-subject gnus-current-article))
3350 (gnus-run-hooks 'gnus-mark-article-hook)
3351 (gnus-set-mode-line 'summary)
3352 (when (gnus-visual-p 'article-highlight 'highlight)
3353 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3354 ;; Set the global newsgroup variables here.
3355 (gnus-set-global-variables)
3356 (setq gnus-have-all-headers
3357 (or all-headers gnus-show-all-headers))))
3359 (gnus-configure-windows 'article))
3360 (when (or (numberp article)
3362 (gnus-article-prepare-display)
3364 (goto-char (point-min))
3365 (setq gnus-page-broken
3366 (when gnus-break-pages
3367 (gnus-narrow-to-page)
3369 (let ((gnus-article-mime-handle-alist-1
3370 gnus-article-mime-handle-alist))
3371 (gnus-set-mode-line 'article))
3373 (set-window-point (get-buffer-window (current-buffer)) (point))
3374 (gnus-configure-windows 'article)
3378 (defun gnus-article-prepare-display ()
3379 "Make the current buffer look like a nice article."
3380 ;; Hooks for getting information from the article.
3381 ;; This hook must be called before being narrowed.
3382 (let ((gnus-article-buffer (current-buffer))
3384 (unless (eq major-mode 'gnus-article-mode)
3385 (gnus-article-mode))
3386 (setq buffer-read-only nil
3387 gnus-article-wash-types nil)
3388 (gnus-run-hooks 'gnus-tmp-internal-hook)
3389 (when gnus-display-mime-function
3390 (funcall gnus-display-mime-function))
3391 (gnus-run-hooks 'gnus-article-prepare-hook)))
3394 ;;; Gnus MIME viewing functions
3397 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3398 "The following specs can be used:
3400 %T MIME type, along with additional info
3401 %n The `name' parameter
3402 %d The description, if any
3403 %l The length of the encoded part
3404 %p The part identifier number
3405 %e Dots if the part isn't displayed")
3407 (defvar gnus-mime-button-line-format-alist
3408 '((?t gnus-tmp-type ?s)
3409 (?T gnus-tmp-type-long ?s)
3410 (?n gnus-tmp-name ?s)
3411 (?d gnus-tmp-description ?s)
3413 (?l gnus-tmp-length ?d)
3414 (?e gnus-tmp-dots ?s)))
3416 (defvar gnus-mime-button-commands
3417 '((gnus-article-press-button "\r" "Toggle Display")
3418 (gnus-mime-view-part "v" "View Interactively...")
3419 (gnus-mime-view-part-as-type "t" "View As Type...")
3420 (gnus-mime-view-part-as-charset "C" "View As charset...")
3421 (gnus-mime-save-part "o" "Save...")
3422 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3423 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3424 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3425 (gnus-mime-internalize-part "E" "View Internally")
3426 (gnus-mime-externalize-part "e" "View Externally")
3427 (gnus-mime-pipe-part "|" "Pipe To Command...")
3428 (gnus-mime-action-on-part "." "Take action on the part")))
3430 (defun gnus-article-mime-part-status ()
3431 (if gnus-article-mime-handle-alist-1
3432 (if (eq 1 (length gnus-article-mime-handle-alist-1))
3434 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3437 (defvar gnus-mime-button-map
3438 (let ((map (make-sparse-keymap)))
3439 (unless (>= (string-to-number emacs-version) 21)
3440 ;; XEmacs doesn't care.
3441 (set-keymap-parent map gnus-article-mode-map))
3442 (define-key map gnus-mouse-2 'gnus-article-push-button)
3443 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3444 (dolist (c gnus-mime-button-commands)
3445 (define-key map (cadr c) (car c)))
3448 (defun gnus-mime-button-menu (event)
3449 "Construct a context-sensitive menu of MIME commands."
3451 (save-window-excursion
3452 (let ((pos (event-start event)))
3453 (select-window (posn-window pos))
3454 (goto-char (posn-point pos))
3455 (gnus-article-check-buffer)
3456 (let ((response (x-popup-menu
3458 ("" ,@(mapcar (lambda (c)
3459 (cons (caddr c) (car c)))
3460 gnus-mime-button-commands))))))
3462 (call-interactively response))))))
3464 (defun gnus-mime-view-all-parts (&optional handles)
3465 "View all the MIME parts."
3467 (save-current-buffer
3468 (set-buffer gnus-article-buffer)
3469 (let ((handles (or handles gnus-article-mime-handles))
3470 (mail-parse-charset gnus-newsgroup-charset)
3471 (mail-parse-ignored-charsets
3472 (with-current-buffer gnus-summary-buffer
3473 gnus-newsgroup-ignored-charsets)))
3475 (mm-remove-parts handles)
3476 (goto-char (point-min))
3477 (or (search-forward "\n\n") (goto-char (point-max)))
3478 (let (buffer-read-only)
3479 (delete-region (point) (point-max))
3480 (mm-display-parts handles))))))
3482 (defun gnus-mime-save-part-and-strip ()
3483 "Save the MIME part under point then replace it with an external body."
3485 (gnus-article-check-buffer)
3486 (let* ((data (get-text-property (point) 'gnus-data))
3488 (handles gnus-article-mime-handles))
3489 (if (mm-multiple-handles gnus-article-mime-handles)
3490 (error "This function is not implemented"))
3491 (setq file (and data (mm-save-part data)))
3493 (with-current-buffer (mm-handle-buffer data)
3495 (insert "Content-Type: " (mm-handle-media-type data))
3496 (mml-insert-parameter-string (cdr (mm-handle-type data))
3499 (insert "Content-ID: " (message-make-message-id) "\n")
3500 (insert "Content-Transfer-Encoding: binary\n")
3503 (cdr (mm-make-handle nil
3504 `("message/external-body"
3505 (access-type . "LOCAL-FILE")
3507 (set-buffer gnus-summary-buffer)
3508 (gnus-article-edit-article
3511 (let ((mail-parse-charset (or gnus-article-charset
3512 ',gnus-newsgroup-charset))
3513 (mail-parse-ignored-charsets
3514 (or gnus-article-ignored-charsets
3515 ',gnus-newsgroup-ignored-charsets))
3516 (mbl mml-buffer-list))
3517 (setq mml-buffer-list nil)
3518 (insert-buffer gnus-original-article-buffer)
3519 (mime-to-mml ',handles)
3520 (setq gnus-article-mime-handles nil)
3521 (let ((mbl1 mml-buffer-list))
3522 (setq mml-buffer-list mbl)
3523 (set (make-local-variable 'mml-buffer-list) mbl1))
3524 ;; LOCAL argument of add-hook differs between GNU Emacs
3525 ;; and XEmacs. make-local-hook makes sure they are local.
3526 (make-local-hook 'kill-buffer-hook)
3527 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3528 `(lambda (no-highlight)
3529 (let ((mail-parse-charset (or gnus-article-charset
3530 ',gnus-newsgroup-charset))
3531 (message-options message-options)
3532 (message-options-set-recipient)
3533 (mail-parse-ignored-charsets
3534 (or gnus-article-ignored-charsets
3535 ',gnus-newsgroup-ignored-charsets)))
3537 (mml-destroy-buffers)
3538 (remove-hook 'kill-buffer-hook
3539 'mml-destroy-buffers t)
3540 (kill-local-variable 'mml-buffer-list))
3541 (gnus-summary-edit-article-done
3542 ,(or (mail-header-references gnus-current-headers) "")
3543 ,(gnus-group-read-only-p)
3544 ,gnus-summary-buffer no-highlight))))))
3546 (defun gnus-mime-save-part ()
3547 "Save the MIME part under point."
3549 (gnus-article-check-buffer)
3550 (let ((data (get-text-property (point) 'gnus-data)))
3552 (mm-save-part data))))
3554 (defun gnus-mime-pipe-part ()
3555 "Pipe the MIME part under point to a process."
3557 (gnus-article-check-buffer)
3558 (let ((data (get-text-property (point) 'gnus-data)))
3560 (mm-pipe-part data))))
3562 (defun gnus-mime-view-part ()
3563 "Interactively choose a viewing method for the MIME part under point."
3565 (gnus-article-check-buffer)
3566 (let ((data (get-text-property (point) 'gnus-data)))
3568 (setq gnus-article-mime-handles
3570 gnus-article-mime-handles (setq data (copy-sequence data))))
3571 (mm-interactively-view-part data))))
3573 (defun gnus-mime-view-part-as-type-internal ()
3574 (gnus-article-check-buffer)
3575 (let* ((name (mail-content-type-get
3576 (mm-handle-type (get-text-property (point) 'gnus-data))
3578 (def-type (and name (mm-default-file-encoding name))))
3579 (and def-type (cons def-type 0))))
3581 (defun gnus-mime-view-part-as-type (&optional mime-type)
3582 "Choose a MIME media type, and view the part as such."
3585 (setq mime-type (completing-read
3586 "View as MIME type: "
3587 (mapcar #'list (mailcap-mime-types))
3589 (gnus-mime-view-part-as-type-internal))))
3590 (gnus-article-check-buffer)
3591 (let ((handle (get-text-property (point) 'gnus-data)))
3594 (mm-make-handle (mm-handle-buffer handle)
3595 (cons mime-type (cdr (mm-handle-type handle)))
3596 (mm-handle-encoding handle)
3597 (mm-handle-undisplayer handle)
3598 (mm-handle-disposition handle)
3599 (mm-handle-description handle)
3601 (mm-handle-id handle)))
3602 (setq gnus-article-mime-handles
3603 (mm-merge-handles gnus-article-mime-handles handle))
3604 (gnus-mm-display-part handle))))
3606 (defun gnus-mime-copy-part (&optional handle)
3607 "Put the the MIME part under point into a new buffer."
3609 (gnus-article-check-buffer)
3610 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3611 (contents (and handle (mm-get-part handle)))
3613 (file-name-nondirectory
3615 (mail-content-type-get (mm-handle-type handle) 'name)
3616 (mail-content-type-get (mm-handle-type handle)
3619 (buffer (and base (generate-new-buffer base))))
3621 (switch-to-buffer buffer)
3623 ;; We do it this way to make `normal-mode' set the appropriate mode.
3626 (setq buffer-file-name (expand-file-name base))
3628 (setq buffer-file-name nil))
3629 (goto-char (point-min)))))
3631 (defun gnus-mime-inline-part (&optional handle arg)
3632 "Insert the MIME part under point into the current buffer."
3633 (interactive (list nil current-prefix-arg))
3634 (gnus-article-check-buffer)
3635 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3640 (if (and (not arg) (mm-handle-undisplayer handle))
3641 (mm-remove-part handle)
3642 (setq contents (mm-get-part handle))
3645 (setq charset (or (mail-content-type-get
3646 (mm-handle-type handle) 'charset)
3647 gnus-newsgroup-charset)))
3649 (if (mm-handle-undisplayer handle)
3650 (mm-remove-part handle))
3653 gnus-summary-show-article-charset-alist))
3654 (mm-read-coding-system "Charset: ")))))
3656 (mm-insert-inline handle
3658 (setq charset (mm-charset-to-coding-system
3660 (not (eq charset 'ascii)))
3661 (mm-decode-coding-string contents charset)
3665 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3666 "Insert the MIME part under point into the current buffer using the
3668 (interactive (list nil current-prefix-arg))
3669 (gnus-article-check-buffer)
3670 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3675 (if (mm-handle-undisplayer handle)
3676 (mm-remove-part handle))
3677 (let ((gnus-newsgroup-charset
3679 gnus-summary-show-article-charset-alist))
3680 (mm-read-coding-system "Charset: ")))
3681 (gnus-newsgroup-ignored-charsets 'gnus-all))
3682 (gnus-article-press-button)))))
3684 (defun gnus-mime-externalize-part (&optional handle)
3685 "View the MIME part under point with an external viewer."
3687 (gnus-article-check-buffer)
3688 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3689 (mm-user-display-methods nil)
3690 (mm-inlined-types nil)
3691 (mail-parse-charset gnus-newsgroup-charset)
3692 (mail-parse-ignored-charsets
3693 (save-excursion (set-buffer gnus-summary-buffer)
3694 gnus-newsgroup-ignored-charsets)))
3696 (if (mm-handle-undisplayer handle)
3697 (mm-remove-part handle)
3698 (mm-display-part handle)))))
3700 (defun gnus-mime-internalize-part (&optional handle)
3701 "View the MIME part under point with an internal viewer.
3702 If no internal viewer is available, use an external viewer."
3704 (gnus-article-check-buffer)
3705 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3706 (mm-inlined-types '(".*"))
3707 (mm-inline-large-images t)
3708 (mail-parse-charset gnus-newsgroup-charset)
3709 (mail-parse-ignored-charsets
3710 (save-excursion (set-buffer gnus-summary-buffer)
3711 gnus-newsgroup-ignored-charsets)))
3713 (if (mm-handle-undisplayer handle)
3714 (mm-remove-part handle)
3715 (mm-display-part handle)))))
3717 (defun gnus-mime-action-on-part (&optional action)
3718 "Do something with the MIME attachment at \(point\)."
3720 (list (completing-read "Action: " gnus-mime-action-alist)))
3721 (gnus-article-check-buffer)
3722 (let ((action-pair (assoc action gnus-mime-action-alist)))
3724 (funcall (cdr action-pair)))))
3726 (defun gnus-article-part-wrapper (n function)
3727 (save-current-buffer
3728 (set-buffer gnus-article-buffer)
3729 (when (> n (length gnus-article-mime-handle-alist))
3730 (error "No such part"))
3731 (gnus-article-goto-part n)
3732 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3733 (funcall function handle))))
3735 (defun gnus-article-pipe-part (n)
3736 "Pipe MIME part N, which is the numerical prefix."
3738 (gnus-article-part-wrapper n 'mm-pipe-part))
3740 (defun gnus-article-save-part (n)
3741 "Save MIME part N, which is the numerical prefix."
3743 (gnus-article-part-wrapper n 'mm-save-part))
3745 (defun gnus-article-interactively-view-part (n)
3746 "View MIME part N interactively, which is the numerical prefix."
3748 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3750 (defun gnus-article-copy-part (n)
3751 "Copy MIME part N, which is the numerical prefix."
3753 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3755 (defun gnus-article-view-part-as-charset (n)
3756 "Copy MIME part N, which is the numerical prefix."
3758 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3760 (defun gnus-article-externalize-part (n)
3761 "View MIME part N externally, which is the numerical prefix."
3763 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3765 (defun gnus-article-inline-part (n)
3766 "Inline MIME part N, which is the numerical prefix."
3768 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3770 (defun gnus-article-mime-match-handle-first (condition)
3772 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3773 (while (setq ihandle (pop alist))
3775 ((functionp condition)
3776 (funcall condition (cdr ihandle)))
3777 ((eq condition 'undisplayed)
3778 (not (or (mm-handle-undisplayer (cdr ihandle))
3779 (equal (mm-handle-media-type (cdr ihandle))
3780 "multipart/alternative"))))
3781 ((eq condition 'undisplayed-alternative)
3782 (not (mm-handle-undisplayer (cdr ihandle))))
3784 (gnus-article-goto-part (car ihandle))
3785 (or (not n) (< (car ihandle) n)))
3786 (setq n (car ihandle))))
3790 (defun gnus-article-view-part (&optional n)
3791 "View MIME part N, which is the numerical prefix."
3793 (save-current-buffer
3794 (set-buffer gnus-article-buffer)
3795 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3796 gnus-article-mime-match-handle-function)))
3797 (when (> n (length gnus-article-mime-handle-alist))
3798 (error "No such part"))
3799 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3800 (when (gnus-article-goto-part n)
3801 (if (equal (car handle) "multipart/alternative")
3802 (gnus-article-press-button)
3803 (when (eq (gnus-mm-display-part handle) 'internal)
3804 (gnus-set-window-start)))))))
3806 (defsubst gnus-article-mime-total-parts ()
3807 (if (bufferp (car gnus-article-mime-handles))
3809 (1- (length gnus-article-mime-handles))))
3811 (defun gnus-mm-display-part (handle)
3812 "Display HANDLE and fix MIME button."
3813 (let ((id (get-text-property (point) 'gnus-part))
3818 (let ((window (selected-window))
3819 (mail-parse-charset gnus-newsgroup-charset)
3820 (mail-parse-ignored-charsets
3821 (save-excursion (set-buffer gnus-summary-buffer)
3822 gnus-newsgroup-ignored-charsets)))
3825 (let ((win (gnus-get-buffer-window (current-buffer) t))
3828 (select-window win))
3831 (if (mm-handle-displayed-p handle)
3832 ;; This will remove the part.
3833 (mm-display-part handle)
3835 (narrow-to-region (point)
3836 (if (eobp) (point) (1+ (point))))
3837 (mm-display-part handle)
3838 ;; We narrow to the part itself and
3839 ;; then call the treatment functions.
3840 (goto-char (point-min))
3842 (narrow-to-region (point) (point-max))
3845 (gnus-article-mime-total-parts)
3846 (mm-handle-media-type handle)))))
3847 (if (window-live-p window)
3848 (select-window window)))))
3850 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3851 (gnus-insert-mime-button
3852 handle id (list (mm-handle-displayed-p handle)))
3853 (goto-char point))))
3855 (defun gnus-article-goto-part (n)
3856 "Go to MIME part N."
3857 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3859 (goto-char point))))
3861 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3862 (let ((gnus-tmp-name
3863 (or (mail-content-type-get (mm-handle-type handle) 'name)
3864 (mail-content-type-get (mm-handle-disposition handle) 'filename)
3865 (mail-content-type-get (mm-handle-type handle) 'url)
3867 (gnus-tmp-type (mm-handle-media-type handle))
3868 (gnus-tmp-description
3869 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3872 (if (if displayed (car displayed)
3873 (mm-handle-displayed-p handle))
3875 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3877 gnus-tmp-type-long b e)
3878 (when (string-match ".*/" gnus-tmp-name)
3879 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3880 (setq gnus-tmp-type-long (concat gnus-tmp-type
3881 (and (not (equal gnus-tmp-name ""))
3882 (concat "; " gnus-tmp-name))))
3883 (unless (equal gnus-tmp-description "")
3884 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3889 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3890 `(keymap ,gnus-mime-button-map
3891 ,@(if (>= (string-to-number emacs-version) 21)
3893 (list 'local-map gnus-mime-button-map))
3894 gnus-callback gnus-mm-display-part
3895 gnus-part ,gnus-tmp-id
3896 article-type annotation
3899 (widget-convert-button
3902 :action 'gnus-widget-press-button
3903 :button-keymap gnus-mime-button-map
3905 (lambda (widget/window &optional overlay pos)
3906 ;; Needed to properly clear the message due to a bug in
3907 ;; wid-edit (XEmacs only).
3908 (if (boundp 'help-echo-owns-message)
3909 (setq help-echo-owns-message t))
3911 "%S: %s the MIME part; %S: more options"
3912 (aref gnus-mouse-2 0)
3913 ;; XEmacs will get a single widget arg; Emacs 21 will get
3914 ;; window, overlay, position.
3915 (if (mm-handle-displayed-p
3917 (with-current-buffer (gnus-overlay-buffer overlay)
3918 (widget-get (widget-at (gnus-overlay-start overlay))
3920 (widget-get widget/window :mime-handle)))
3922 (aref gnus-down-mouse-3 0))))))
3924 (defun gnus-widget-press-button (elems el)
3925 (goto-char (widget-get elems :from))
3926 (gnus-article-press-button))
3928 (defvar gnus-displaying-mime nil)
3930 (defun gnus-display-mime (&optional ihandles)
3931 "Display the MIME parts."
3933 (save-selected-window
3934 (let ((window (get-buffer-window gnus-article-buffer))
3937 (select-window window)
3938 ;; We have to do this since selecting the window
3939 ;; may change the point. So we set the window point.
3940 (set-window-point window point)))
3941 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3942 buffer-read-only handle name type b e display)
3943 (when (and (not ihandles)
3944 (not gnus-displaying-mime))
3945 ;; Top-level call; we clean up.
3946 (when gnus-article-mime-handles
3947 (mm-destroy-parts gnus-article-mime-handles)
3948 (setq gnus-article-mime-handle-alist nil));; A trick.
3949 (setq gnus-article-mime-handles handles)
3950 ;; We allow users to glean info from the handles.
3951 (when gnus-article-mime-part-function
3952 (gnus-mime-part-function handles)))
3954 (or (not (stringp (car handles)))
3957 (when (and (not ihandles)
3958 (not gnus-displaying-mime))
3959 ;; Clean up for mime parts.
3961 (delete-region (point) (point-max)))
3962 (let ((gnus-displaying-mime t))
3963 (gnus-mime-display-part handles)))
3966 (narrow-to-region (point) (point-max))
3967 (gnus-treat-article nil 1 1)
3970 ;; Highlight the headers.
3974 (narrow-to-region (point-min) (point))
3975 (gnus-treat-article 'head))))))))
3977 (defvar gnus-mime-display-multipart-as-mixed nil)
3978 (defvar gnus-mime-display-multipart-alternative-as-mixed nil)
3979 (defvar gnus-mime-display-multipart-related-as-mixed nil)
3981 (defun gnus-mime-display-part (handle)
3984 ((not (stringp (car handle)))
3985 (gnus-mime-display-single handle))
3986 ;; User-defined multipart
3987 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3988 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3990 ;; multipart/alternative
3991 ((and (equal (car handle) "multipart/alternative")
3992 (not (or gnus-mime-display-multipart-as-mixed
3993 gnus-mime-display-multipart-alternative-as-mixed)))
3994 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3995 (push (cons id handle) gnus-article-mime-handle-alist)
3996 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3997 ;; multipart/related
3998 ((and (equal (car handle) "multipart/related")
3999 (not (or gnus-mime-display-multipart-as-mixed
4000 gnus-mime-display-multipart-related-as-mixed)))
4001 ;;;!!!We should find the start part, but we just default
4002 ;;;!!!to the first part.
4003 ;;(gnus-mime-display-part (cadr handle))
4004 ;;;!!! Most multipart/related is an HTML message plus images.
4005 ;;;!!! Unfortunately we are unable to let W3 display those
4006 ;;;!!! included images, so we just display it as a mixed multipart.
4007 ;;(gnus-mime-display-mixed (cdr handle))
4008 ;;;!!! No, w3 can display everything just fine.
4009 (gnus-mime-display-part (cadr handle)))
4010 ((equal (car handle) "multipart/signed")
4011 (or (memq 'signed gnus-article-wash-types)
4012 (push 'signed gnus-article-wash-types))
4013 (gnus-mime-display-security handle))
4014 ((equal (car handle) "multipart/encrypted")
4015 (or (memq 'encrypted gnus-article-wash-types)
4016 (push 'encrypted gnus-article-wash-types))
4017 (gnus-mime-display-security handle))
4018 ;; Other multiparts are handled like multipart/mixed.
4020 (gnus-mime-display-mixed (cdr handle)))))
4022 (defun gnus-mime-part-function (handles)
4023 (if (stringp (car handles))
4024 (mapcar 'gnus-mime-part-function (cdr handles))
4025 (funcall gnus-article-mime-part-function handles)))
4027 (defun gnus-mime-display-mixed (handles)
4028 (mapcar 'gnus-mime-display-part handles))
4030 (defun gnus-mime-display-single (handle)
4031 (let ((type (mm-handle-media-type handle))
4032 (ignored gnus-ignored-mime-types)
4039 (when (string-match (pop ignored) type)
4040 (throw 'ignored nil)))
4041 (if (and (setq not-attachment
4042 (and (not (mm-inline-override-p handle))
4043 (or (not (mm-handle-disposition handle))
4044 (equal (car (mm-handle-disposition handle))
4046 (mm-attachment-override-p handle))))
4047 (mm-automatic-display-p handle)
4049 (mm-inlinable-p handle)
4050 (mm-inlined-p handle))
4051 (mm-automatic-external-display-p type)))
4053 (when (equal (mm-handle-media-supertype handle) "text")
4055 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4057 (push (cons id handle) gnus-article-mime-handle-alist)
4058 (when (or (not display)
4059 (not (gnus-unbuttonized-mime-type-p type)))
4060 ;(gnus-article-insert-newline)
4061 (gnus-insert-mime-button
4062 handle id (list (or display (and not-attachment text))))
4063 (gnus-article-insert-newline)
4064 ;(gnus-article-insert-newline)
4065 ;; Remember modify the number of forward lines.
4073 (let ((mail-parse-charset gnus-newsgroup-charset)
4074 (mail-parse-ignored-charsets
4075 (save-excursion (condition-case ()
4076 (set-buffer gnus-summary-buffer)
4078 gnus-newsgroup-ignored-charsets)))
4079 (mm-display-part handle t))
4080 (goto-char (point-max)))
4081 ((and text not-attachment)
4085 (gnus-article-insert-newline)
4086 (mm-insert-inline handle (mm-get-part handle))
4087 (goto-char (point-max))))
4091 (narrow-to-region beg (point))
4094 (gnus-article-mime-total-parts)
4095 (mm-handle-media-type handle)))))))))
4097 (defun gnus-unbuttonized-mime-type-p (type)
4098 "Say whether TYPE is to be unbuttonized."
4099 (unless gnus-inhibit-mime-unbuttonizing
4101 (let ((types gnus-unbuttonized-mime-types))
4103 (when (string-match (pop types) type)
4104 (throw 'found t)))))
4106 (let ((types gnus-buttonized-mime-types))
4108 (when (string-match (pop types) type)
4109 (throw 'found t)))))))))
4111 (defun gnus-article-insert-newline ()
4112 "Insert a newline, but mark it as undeletable."
4113 (gnus-put-text-property
4114 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4116 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4117 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4120 handle buffer-read-only from props begend not-pref)
4121 (save-window-excursion
4124 (narrow-to-region (car ibegend)
4127 (goto-char (car ibegend))
4130 (delete-region (point-min) (point-max))
4131 (mm-remove-parts handles))
4132 (setq begend (list (point-marker)))
4134 (unless (setq not-pref (cadr (member preferred ihandles)))
4135 (setq not-pref (car ihandles)))
4138 (not (gnus-unbuttonized-mime-type-p
4139 "multipart/alternative")))
4140 (gnus-add-text-properties
4143 (insert (format "%d. " id))
4147 (unless ,(not ibegend)
4148 (setq gnus-article-mime-handle-alist
4149 ',gnus-article-mime-handle-alist))
4150 (gnus-mime-display-alternative
4151 ',ihandles ',not-pref ',begend ,id))
4152 ,@(if (>= (string-to-number emacs-version) 21)
4153 nil ;; XEmacs doesn't care
4154 (list 'local-map gnus-mime-button-map))
4155 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4156 face ,gnus-article-button-face
4157 keymap ,gnus-mime-button-map
4160 (widget-convert-button 'link from (point)
4161 :action 'gnus-widget-press-button
4162 :button-keymap gnus-widget-button-keymap)
4164 (while (setq handle (pop handles))
4165 (gnus-add-text-properties
4168 (insert (format "(%c) %-18s"
4169 (if (equal handle preferred) ?* ? )
4170 (mm-handle-media-type handle)))
4174 (unless ,(not ibegend)
4175 (setq gnus-article-mime-handle-alist
4176 ',gnus-article-mime-handle-alist))
4177 (gnus-mime-display-alternative
4178 ',ihandles ',handle ',begend ,id))
4179 ,@(if (>= (string-to-number emacs-version) 21)
4180 nil ;; XEmacs doesn't care
4181 (list 'local-map gnus-mime-button-map))
4182 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4183 face ,gnus-article-button-face
4184 keymap ,gnus-mime-button-map
4187 (widget-convert-button 'link from (point)
4188 :action 'gnus-widget-press-button
4189 :button-keymap gnus-widget-button-keymap)
4193 (if (stringp (car preferred))
4194 (gnus-display-mime preferred)
4195 (let ((mail-parse-charset gnus-newsgroup-charset)
4196 (mail-parse-ignored-charsets
4197 (save-excursion (set-buffer gnus-summary-buffer)
4198 gnus-newsgroup-ignored-charsets)))
4199 (mm-display-part preferred)
4203 (narrow-to-region (car begend) (point-max))
4205 nil (length gnus-article-mime-handle-alist)
4206 (gnus-article-mime-total-parts)
4207 (mm-handle-media-type handle))))))
4208 (goto-char (point-max))
4209 (setcdr begend (point-marker)))))
4211 (goto-char point))))
4213 (defconst gnus-article-wash-status-strings
4214 (let ((alist '((cite "c" "Possible hidden citation text"
4215 " " "All citation text visible")
4216 (headers "h" "Hidden headers"
4217 " " "All headers visible.")
4218 (pgp "p" "Encrypted or signed message status hidden"
4219 " " "No hidden encryption nor digital signature status")
4220 (signature "s" "Signature has been hidden"
4221 " " "Signature is visible")
4222 (overstrike "o" "Overstrike (^H) characters applied"
4223 " " "No overstrike characters applied")
4224 (emphasis "e" "/*_Emphasis_*/ characters applied"
4225 " " "No /*_emphasis_*/ characters applied")))
4227 (dolist (entry alist result)
4228 (let ((key (nth 0 entry))
4229 (on (copy-sequence (nth 1 entry)))
4230 (on-help (nth 2 entry))
4231 (off (copy-sequence (nth 3 entry)))
4232 (off-help (nth 4 entry)))
4233 (put-text-property 0 1 'help-echo on-help on)
4234 (put-text-property 0 1 'help-echo off-help off)
4235 (push (list key on off) result))))
4236 "Alist of strings describing wash status in the mode line.
4237 Each entry has the form (KEY ON OF), where the KEY is a symbol
4238 representing the particular washing function, ON is the string to use
4239 in the article mode line when the washing function is active, and OFF
4240 is the string to use when it is inactive.")
4242 (defun gnus-gnus-article-wash-status-entry (key value)
4243 (let ((entry (assoc key gnus-article-wash-status-strings)))
4244 (if value (nth 1 entry) (nth 2 entry))))
4246 (defun gnus-article-wash-status ()
4247 "Return a string which display status of article washing."
4249 (set-buffer gnus-article-buffer)
4250 (let ((cite (memq 'cite gnus-article-wash-types))
4251 (headers (memq 'headers gnus-article-wash-types))
4252 (boring (memq 'boring-headers gnus-article-wash-types))
4253 (pgp (memq 'pgp gnus-article-wash-types))
4254 (pem (memq 'pem gnus-article-wash-types))
4255 (signed (memq 'signed gnus-article-wash-types))
4256 (encrypted (memq 'encrypted gnus-article-wash-types))
4257 (signature (memq 'signature gnus-article-wash-types))
4258 (overstrike (memq 'overstrike gnus-article-wash-types))
4259 (emphasis (memq 'emphasis gnus-article-wash-types)))
4260 (concat (gnus-gnus-article-wash-status-entry 'cite cite)
4261 (gnus-gnus-article-wash-status-entry 'headers
4262 (or headers boring))
4263 (gnus-gnus-article-wash-status-entry
4264 'pgp (or pgp pem signed encrypted))
4265 (gnus-gnus-article-wash-status-entry 'signature signature)
4266 (gnus-gnus-article-wash-status-entry 'overstrike overstrike)
4267 (gnus-gnus-article-wash-status-entry 'emphasis emphasis)))))
4269 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4271 (defun gnus-article-maybe-hide-headers ()
4272 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4273 Provided for backwards compatibility."
4274 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4275 (not (save-excursion (set-buffer gnus-summary-buffer)
4276 gnus-have-all-headers)))
4277 (not gnus-inhibit-hiding))
4278 (gnus-article-hide-headers)))
4282 (defun gnus-output-to-file (file-name)
4283 "Append the current article to a file named FILE-NAME."
4284 (let ((artbuf (current-buffer)))
4286 (insert-buffer-substring artbuf)
4287 ;; Append newline at end of the buffer as separator, and then
4289 (goto-char (point-max))
4291 (let ((file-name-coding-system nnmail-pathname-coding-system))
4292 (mm-append-to-file (point-min) (point-max) file-name))
4295 (defun gnus-narrow-to-page (&optional arg)
4296 "Narrow the article buffer to a page.
4297 If given a numerical ARG, move forward ARG pages."
4299 (setq arg (if arg (prefix-numeric-value arg) 0))
4301 (set-buffer gnus-article-buffer)
4302 (goto-char (point-min))
4304 ;; Remove any old next/prev buttons.
4305 (when (gnus-visual-p 'page-marker)
4306 (let ((buffer-read-only nil))
4307 (gnus-remove-text-with-property 'gnus-prev)
4308 (gnus-remove-text-with-property 'gnus-next)))
4311 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4313 (re-search-forward page-delimiter nil 'move arg)))
4314 (goto-char (match-end 0)))
4317 (if (re-search-forward page-delimiter nil 'move)
4320 (when (and (gnus-visual-p 'page-marker)
4321 (not (= (point-min) 1)))
4323 (goto-char (point-min))
4324 (gnus-insert-prev-page-button)))
4325 (when (and (gnus-visual-p 'page-marker)
4326 (< (+ (point-max) 2) (buffer-size)))
4328 (goto-char (point-max))
4329 (gnus-insert-next-page-button)))))
4331 ;; Article mode commands
4333 (defun gnus-article-goto-next-page ()
4334 "Show the next page of the article."
4336 (when (gnus-article-next-page)
4337 (goto-char (point-min))
4338 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4340 (defun gnus-article-goto-prev-page ()
4341 "Show the next page of the article."
4343 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4344 (gnus-article-prev-page nil)))
4346 (defun gnus-article-next-page (&optional lines)
4347 "Show the next page of the current article.
4348 If end of article, return non-nil. Otherwise return nil.
4349 Argument LINES specifies lines to be scrolled up."
4351 (move-to-window-line -1)
4354 (and (pos-visible-in-window-p) ;Not continuation line.
4356 ;; Nothing in this page.
4357 (if (or (not gnus-page-broken)
4360 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
4362 (gnus-narrow-to-page 1) ;Go to next page.
4364 ;; More in this page.
4365 (let ((scroll-in-place nil))
4369 ;; Long lines may cause an end-of-buffer error.
4370 (goto-char (point-max)))))
4371 (move-to-window-line 0)
4374 (defun gnus-article-prev-page (&optional lines)
4375 "Show previous page of current article.
4376 Argument LINES specifies lines to be scrolled down."
4378 (move-to-window-line 0)
4379 (if (and gnus-page-broken
4381 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
4383 (gnus-narrow-to-page -1) ;Go to previous page.
4384 (goto-char (point-max))
4386 (let ((scroll-in-place nil))
4390 (beginning-of-buffer
4391 (goto-char (point-min))))
4392 (move-to-window-line 0)))))
4394 (defun gnus-article-refer-article ()
4395 "Read article specified by message-id around point."
4397 (let ((point (point)))
4398 (search-forward ">" nil t) ;Move point to end of "<....>".
4399 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4400 (let ((message-id (match-string 1)))
4402 (set-buffer gnus-summary-buffer)
4403 (gnus-summary-refer-article message-id))
4405 (error "No references around point"))))
4407 (defun gnus-article-show-summary ()
4408 "Reconfigure windows to show summary buffer."
4410 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4411 (error "There is no summary buffer for this article buffer")
4412 (gnus-article-set-globals)
4413 (gnus-configure-windows 'article)
4414 (gnus-summary-goto-subject gnus-current-article)
4415 (gnus-summary-position-point)))
4417 (defun gnus-article-describe-briefly ()
4418 "Describe article mode commands briefly."
4420 (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")))
4422 (defun gnus-article-summary-command ()
4423 "Execute the last keystroke in the summary buffer."
4425 (let ((obuf (current-buffer))
4426 (owin (current-window-configuration))
4428 (switch-to-buffer gnus-article-current-summary 'norecord)
4429 (setq func (lookup-key (current-local-map) (this-command-keys)))
4430 (call-interactively func)
4432 (set-window-configuration owin)
4433 (set-window-point (get-buffer-window (current-buffer)) (point))))
4435 (defun gnus-article-summary-command-nosave ()
4436 "Execute the last keystroke in the summary buffer."
4439 (pop-to-buffer gnus-article-current-summary 'norecord)
4440 (setq func (lookup-key (current-local-map) (this-command-keys)))
4441 (call-interactively func)))
4443 (defun gnus-article-check-buffer ()
4444 "Beep if not in an article buffer."
4445 (unless (equal major-mode 'gnus-article-mode)
4446 (error "Command invoked outside of a Gnus article buffer")))
4448 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4449 "Read a summary buffer key sequence and execute it from the article buffer."
4451 (gnus-article-check-buffer)
4453 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4454 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4455 "=" "^" "\M-^" "|"))
4461 '("n" "Gn" "p" "Gp"))
4464 (set-buffer gnus-article-current-summary)
4465 (let (gnus-pick-mode)
4466 (push (or key last-command-event) unread-command-events)
4467 (setq keys (if (featurep 'xemacs)
4468 (events-to-keys (read-key-sequence nil))
4469 (read-key-sequence nil)))))
4473 (if (or (member keys nosaves)
4474 (member keys nosave-but-article)
4475 (member keys nosave-in-article))
4477 (save-window-excursion
4478 (pop-to-buffer gnus-article-current-summary 'norecord)
4479 ;; We disable the pick minor mode commands.
4480 (let (gnus-pick-mode)
4481 (setq func (lookup-key (current-local-map) keys))))
4485 (unless (member keys nosave-in-article)
4486 (set-buffer gnus-article-current-summary))
4487 (call-interactively func)
4488 (setq new-sum-point (point)))
4489 (when (member keys nosave-but-article)
4490 (pop-to-buffer gnus-article-buffer 'norecord)))
4491 ;; These commands should restore window configuration.
4492 (let ((obuf (current-buffer))
4493 (owin (current-window-configuration))
4495 (summary gnus-article-current-summary)
4496 func in-buffer selected)
4497 (if not-restore-window
4498 (pop-to-buffer summary 'norecord)
4499 (switch-to-buffer summary 'norecord))
4500 (setq in-buffer (current-buffer))
4501 ;; We disable the pick minor mode commands.
4502 (if (and (setq func (let (gnus-pick-mode)
4503 (lookup-key (current-local-map) keys)))
4506 (call-interactively func)
4507 (setq new-sum-point (point))
4508 (when (eq in-buffer (current-buffer))
4509 (setq selected (gnus-summary-select-article))
4511 (unless not-restore-window
4512 (set-window-configuration owin))
4513 (when (eq selected 'old)
4515 (set-window-start (get-buffer-window (current-buffer))
4517 (set-window-point (get-buffer-window (current-buffer))
4519 (let ((win (get-buffer-window gnus-article-current-summary)))
4521 (set-window-point win new-sum-point)))) )
4522 (switch-to-buffer gnus-article-buffer)
4525 (defun gnus-article-describe-key (key)
4526 "Display documentation of the function invoked by KEY. KEY is a string."
4527 (interactive "kDescribe key: ")
4528 (gnus-article-check-buffer)
4529 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4531 (set-buffer gnus-article-current-summary)
4532 (let (gnus-pick-mode)
4533 (if (featurep 'xemacs)
4535 (push (elt key 0) unread-command-events)
4536 (setq key (events-to-keys
4537 (read-key-sequence "Describe key: "))))
4538 (setq unread-command-events
4540 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4541 (string-to-list key)))
4542 (setq key (read-key-sequence "Describe key: "))))
4544 (describe-key key)))
4546 (defun gnus-article-describe-key-briefly (key &optional insert)
4547 "Display documentation of the function invoked by KEY. KEY is a string."
4548 (interactive "kDescribe key: \nP")
4549 (gnus-article-check-buffer)
4550 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4552 (set-buffer gnus-article-current-summary)
4553 (let (gnus-pick-mode)
4554 (if (featurep 'xemacs)
4556 (push (elt key 0) unread-command-events)
4557 (setq key (events-to-keys
4558 (read-key-sequence "Describe key: "))))
4559 (setq unread-command-events
4561 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
4562 (string-to-list key)))
4563 (setq key (read-key-sequence "Describe key: "))))
4564 (describe-key-briefly key insert))
4565 (describe-key-briefly key insert)))
4567 (defun gnus-article-hide (&optional arg force)
4568 "Hide all the gruft in the current article.
4569 This means that PGP stuff, signatures, cited text and (some)
4570 headers will be hidden.
4571 If given a prefix, show the hidden text instead."
4572 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4573 (gnus-article-hide-headers arg)
4574 (gnus-article-hide-list-identifiers arg)
4575 (gnus-article-hide-pgp arg)
4576 (gnus-article-hide-citation-maybe arg force)
4577 (gnus-article-hide-signature arg))
4579 (defun gnus-article-maybe-highlight ()
4580 "Do some article highlighting if article highlighting is requested."
4581 (when (gnus-visual-p 'article-highlight 'highlight)
4582 (gnus-article-highlight-some)))
4584 (defun gnus-check-group-server ()
4585 ;; Make sure the connection to the server is alive.
4586 (unless (gnus-server-opened
4587 (gnus-find-method-for-group gnus-newsgroup-name))
4588 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4589 (gnus-request-group gnus-newsgroup-name t)))
4591 (defun gnus-request-article-this-buffer (article group)
4592 "Get an article and insert it into this buffer."
4593 (let (do-update-line sparse-header)
4597 (gnus-kill-all-overlays)
4598 (setq group (or group gnus-newsgroup-name))
4600 ;; Using `gnus-request-article' directly will insert the article into
4601 ;; `nntp-server-buffer' - so we'll save some time by not having to
4602 ;; copy it from the server buffer into the article buffer.
4604 ;; We only request an article by message-id when we do not have the
4605 ;; headers for it, so we'll have to get those.
4606 (when (stringp article)
4607 (gnus-read-header article))
4609 ;; If the article number is negative, that means that this article
4610 ;; doesn't belong in this newsgroup (possibly), so we find its
4611 ;; message-id and request it by id instead of number.
4612 (when (and (numberp article)
4614 (get-buffer gnus-summary-buffer)
4615 (gnus-buffer-exists-p gnus-summary-buffer))
4617 (set-buffer gnus-summary-buffer)
4618 (let ((header (gnus-summary-article-header article)))
4621 ((memq article gnus-newsgroup-sparse)
4622 ;; This is a sparse gap article.
4623 (setq do-update-line article)
4624 (setq article (mail-header-id header))
4625 (setq sparse-header (gnus-read-header article))
4626 (setq gnus-newsgroup-sparse
4627 (delq article gnus-newsgroup-sparse)))
4629 ;; It's a real article.
4630 (setq article (mail-header-id header)))
4632 ;; It is an extracted pseudo-article.
4633 (setq article 'pseudo)
4634 (gnus-request-pseudo-article header))))
4636 (let ((method (gnus-find-method-for-group
4637 gnus-newsgroup-name)))
4638 (when (and (eq (car method) 'nneething)
4640 (let ((dir (expand-file-name
4641 (mail-header-subject header)
4642 (file-name-as-directory
4643 (or (cadr (assq 'nneething-address method))
4645 (when (file-directory-p dir)
4646 (setq article 'nneething)
4647 (gnus-group-enter-directory dir))))))))
4650 ;; Refuse to select canceled articles.
4651 ((and (numberp article)
4653 (get-buffer gnus-summary-buffer)
4654 (gnus-buffer-exists-p gnus-summary-buffer)
4655 (eq (cdr (save-excursion
4656 (set-buffer gnus-summary-buffer)
4657 (assq article gnus-newsgroup-reads)))
4658 gnus-canceled-mark))
4660 ;; We first check `gnus-original-article-buffer'.
4661 ((and (get-buffer gnus-original-article-buffer)
4664 (set-buffer gnus-original-article-buffer)
4665 (and (equal (car gnus-original-article) group)
4666 (eq (cdr gnus-original-article) article))))
4667 (insert-buffer-substring gnus-original-article-buffer)
4669 ;; Check the backlog.
4670 ((and gnus-keep-backlog
4671 (gnus-backlog-request-article group article (current-buffer)))
4673 ;; Check asynchronous pre-fetch.
4674 ((gnus-async-request-fetched-article group article (current-buffer))
4675 (gnus-async-prefetch-next group article gnus-summary-buffer)
4676 (when (and (numberp article) gnus-keep-backlog)
4677 (gnus-backlog-enter-article group article (current-buffer)))
4680 ((and gnus-use-cache
4682 (gnus-cache-request-article article group))
4684 ;; Get the article and put into the article buffer.
4685 ((or (stringp article)
4687 (let ((gnus-override-method gnus-override-method)
4688 (methods (and (stringp article)
4689 gnus-refer-article-method))
4691 (buffer-read-only nil))
4692 (if (or (not (listp methods))
4693 (and (symbolp (car methods))
4694 (assq (car methods) nnoo-definition-alist)))
4695 (setq methods (list methods)))
4696 (when (and (null gnus-override-method)
4698 (setq gnus-override-method (pop methods)))
4700 (when (eq gnus-override-method 'current)
4701 (setq gnus-override-method
4702 (with-current-buffer gnus-summary-buffer
4703 gnus-current-select-method)))
4705 (gnus-kill-all-overlays)
4706 (let ((gnus-newsgroup-name group))
4707 (gnus-check-group-server))
4708 (when (gnus-request-article article group (current-buffer))
4709 (when (numberp article)
4710 (gnus-async-prefetch-next group article
4711 gnus-summary-buffer)
4712 (when gnus-keep-backlog
4713 (gnus-backlog-enter-article
4714 group article (current-buffer))))
4715 (setq result 'article))
4718 (setq gnus-override-method (pop methods))
4719 (setq result 'done))))
4720 (and (eq result 'article) 'article)))
4724 ;; Associate this article with the current summary buffer.
4725 (setq gnus-article-current-summary gnus-summary-buffer)
4727 ;; Take the article from the original article buffer
4728 ;; and place it in the buffer it's supposed to be in.
4729 (when (and (get-buffer gnus-article-buffer)
4730 (equal (buffer-name (current-buffer))
4731 (buffer-name (get-buffer gnus-article-buffer))))
4733 (if (get-buffer gnus-original-article-buffer)
4734 (set-buffer gnus-original-article-buffer)
4735 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4736 (buffer-disable-undo)
4737 (setq major-mode 'gnus-original-article-mode)
4738 (setq buffer-read-only t))
4739 (let (buffer-read-only)
4741 (insert-buffer-substring gnus-article-buffer))
4742 (setq gnus-original-article (cons group article)))
4745 (run-hooks 'gnus-article-decode-hook)
4746 ;; Mark article as decoded or not.
4747 (setq gnus-article-decoded-p gnus-article-decode-hook))
4749 ;; Update sparse articles.
4750 (when (and do-update-line
4751 (or (numberp article)
4753 (let ((buf (current-buffer)))
4754 (set-buffer gnus-summary-buffer)
4755 (gnus-summary-update-article do-update-line sparse-header)
4756 (gnus-summary-goto-subject do-update-line nil t)
4757 (set-window-point (gnus-get-buffer-window (current-buffer) t)
4759 (set-buffer buf))))))
4765 (defcustom gnus-article-edit-mode-hook nil
4766 "Hook run in article edit mode buffers."
4767 :group 'gnus-article-various
4770 (defvar gnus-article-edit-done-function nil)
4772 (defvar gnus-article-edit-mode-map nil)
4774 ;; Should we be using derived.el for this?
4775 (unless gnus-article-edit-mode-map
4776 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4777 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4779 (gnus-define-keys gnus-article-edit-mode-map
4780 "\C-c\C-c" gnus-article-edit-done
4781 "\C-c\C-k" gnus-article-edit-exit)
4783 (gnus-define-keys (gnus-article-edit-wash-map
4784 "\C-c\C-w" gnus-article-edit-mode-map)
4785 "f" gnus-article-edit-full-stops))
4787 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
4788 "Major mode for editing articles.
4789 This is an extended text-mode.
4791 \\{gnus-article-edit-mode-map}"
4792 (make-local-variable 'gnus-article-edit-done-function)
4793 (make-local-variable 'gnus-prev-winconf)
4794 (set (make-local-variable 'font-lock-defaults)
4795 '(message-font-lock-keywords t))
4796 (setq buffer-read-only nil)
4797 (buffer-enable-undo)
4800 (defun gnus-article-edit (&optional force)
4801 "Edit the current article.
4802 This will have permanent effect only in mail groups.
4803 If FORCE is non-nil, allow editing of articles even in read-only
4806 (when (and (not force)
4807 (gnus-group-read-only-p))
4808 (error "The current newsgroup does not support article editing"))
4809 (gnus-article-date-original)
4810 (gnus-article-edit-article
4812 `(lambda (no-highlight)
4814 (gnus-summary-edit-article-done
4815 ,(or (mail-header-references gnus-current-headers) "")
4816 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4818 (defun gnus-article-edit-article (start-func exit-func)
4819 "Start editing the contents of the current article buffer."
4820 (let ((winconf (current-window-configuration)))
4821 (set-buffer gnus-article-buffer)
4822 (gnus-article-edit-mode)
4823 (funcall start-func)
4824 (set-buffer-modified-p nil)
4825 (gnus-configure-windows 'edit-article)
4826 (setq gnus-article-edit-done-function exit-func)
4827 (setq gnus-prev-winconf winconf)
4828 (gnus-message 6 "C-c C-c to end edits")))
4830 (defun gnus-article-edit-done (&optional arg)
4831 "Update the article edits and exit."
4833 (let ((func gnus-article-edit-done-function)
4834 (buf (current-buffer))
4835 (start (window-start)))
4836 ;; We remove all text props from the article buffer.
4838 (buffer-substring-no-properties (point-min) (point-max)))
4842 (let ((winconf gnus-prev-winconf))
4844 (set-window-configuration winconf)
4845 ;; Tippy-toe some to make sure that point remains where it was.
4846 (save-current-buffer
4848 (set-window-start (get-buffer-window (current-buffer)) start)
4852 (let ((buffer-read-only nil))
4854 ;; The cache and backlog have to be flushed somewhat.
4855 (when gnus-keep-backlog
4856 (gnus-backlog-remove-article
4857 (car gnus-article-current) (cdr gnus-article-current)))
4858 ;; Flush original article as well.
4860 (when (get-buffer gnus-original-article-buffer)
4861 (set-buffer gnus-original-article-buffer)
4862 (setq gnus-original-article nil)))
4863 (when gnus-use-cache
4864 (gnus-cache-update-article
4865 (car gnus-article-current) (cdr gnus-article-current))))
4867 (set-window-start (get-buffer-window buf) start)
4868 (set-window-point (get-buffer-window buf) (point))))
4870 (defun gnus-article-edit-exit ()
4871 "Exit the article editing without updating."
4873 (when (or (not (buffer-modified-p))
4874 (yes-or-no-p "Article modified; kill anyway? "))
4875 (let ((curbuf (current-buffer))
4877 (window-start (window-start)))
4879 (if (gnus-buffer-live-p gnus-original-article-buffer)
4880 (insert-buffer gnus-original-article-buffer))
4881 (let ((winconf gnus-prev-winconf))
4883 (set-window-configuration winconf)
4884 ;; Tippy-toe some to make sure that point remains where it was.
4885 (save-current-buffer
4887 (set-window-start (get-buffer-window (current-buffer)) window-start)
4890 (defun gnus-article-edit-full-stops ()
4891 "Interactively repair spacing at end of sentences."
4894 (goto-char (point-min))
4895 (search-forward-regexp "^$" nil t)
4896 (let ((case-fold-search nil))
4897 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4900 ;;; Article highlights
4903 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4905 ;;; Internal Variables:
4907 (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\\)\\)"
4908 "Regular expression that matches URLs."
4909 :group 'gnus-article-buttons
4912 (defcustom gnus-button-alist
4913 `(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4914 0 t gnus-button-handle-news 3)
4915 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
4916 gnus-button-handle-news 2)
4917 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4919 gnus-button-fetch-group 4)
4920 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4921 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4922 t gnus-button-message-id 3)
4923 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4924 ("mailto:\\([-a-zA-Z.@_+0-9%=?]+\\)" 0 t gnus-url-mailto 1)
4925 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4927 ("\\binfo:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t
4928 gnus-button-handle-info 2)
4929 ;; This is how URLs _should_ be embedded in text...
4930 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4932 (,gnus-button-url-regexp 0 t browse-url 0))
4933 "*Alist of regexps matching buttons in article bodies.
4935 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4936 REGEXP: is the string matching text around the button,
4937 BUTTON: is the number of the regexp grouping actually matching the button,
4938 FORM: is a lisp expression which must eval to true for the button to
4940 CALLBACK: is the function to call when the user push this button, and each
4941 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4943 CALLBACK can also be a variable, in that case the value of that
4944 variable it the real callback function."
4945 :group 'gnus-article-buttons
4946 :type '(repeat (list regexp
4947 (integer :tag "Button")
4949 (function :tag "Callback")
4952 (integer :tag "Regexp group")))))
4954 (defcustom gnus-header-button-alist
4955 `(("^\\(References\\|Message-I[Dd]\\):" "<[^<>]+>"
4956 0 t gnus-button-message-id 0)
4957 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4958 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4959 0 t gnus-button-mailto 0)
4960 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4961 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4962 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4963 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4964 gnus-button-message-id 3))
4965 "*Alist of headers and regexps to match buttons in article heads.
4967 This alist is very similar to `gnus-button-alist', except that each
4968 alist has an additional HEADER element first in each entry:
4970 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4972 HEADER is a regexp to match a header. For a fuller explanation, see
4973 `gnus-button-alist'."
4974 :group 'gnus-article-buttons
4975 :group 'gnus-article-headers
4976 :type '(repeat (list (regexp :tag "Header")
4978 (integer :tag "Button")
4980 (function :tag "Callback")
4983 (integer :tag "Regexp group")))))
4985 (defvar gnus-button-regexp nil)
4986 (defvar gnus-button-marker-list nil)
4987 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4989 (defvar gnus-button-last nil)
4990 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4994 (defun gnus-article-push-button (event)
4995 "Check text under the mouse pointer for a callback function.
4996 If the text under the mouse pointer has a `gnus-callback' property,
4997 call it with the value of the `gnus-data' text property."
4999 (set-buffer (window-buffer (posn-window (event-start event))))
5000 (let* ((pos (posn-point (event-start event)))
5001 (data (get-text-property pos 'gnus-data))
5002 (fun (get-text-property pos 'gnus-callback)))
5005 (funcall fun data))))
5007 (defun gnus-article-press-button ()
5008 "Check text at point for a callback function.
5009 If the text at point has a `gnus-callback' property,
5010 call it with the value of the `gnus-data' text property."
5012 (let* ((data (get-text-property (point) 'gnus-data))
5013 (fun (get-text-property (point) 'gnus-callback)))
5015 (funcall fun data))))
5017 (defun gnus-article-highlight (&optional force)
5018 "Highlight current article.
5019 This function calls `gnus-article-highlight-headers',
5020 `gnus-article-highlight-citation',
5021 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5022 do the highlighting. See the documentation for those functions."
5023 (interactive (list 'force))
5024 (gnus-article-highlight-headers)
5025 (gnus-article-highlight-citation force)
5026 (gnus-article-highlight-signature)
5027 (gnus-article-add-buttons force)
5028 (gnus-article-add-buttons-to-head))
5030 (defun gnus-article-highlight-some (&optional force)
5031 "Highlight current article.
5032 This function calls `gnus-article-highlight-headers',
5033 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5034 do the highlighting. See the documentation for those functions."
5035 (interactive (list 'force))
5036 (gnus-article-highlight-headers)
5037 (gnus-article-highlight-signature)
5038 (gnus-article-add-buttons))
5040 (defun gnus-article-highlight-headers ()
5041 "Highlight article headers as specified by `gnus-header-face-alist'."
5044 (set-buffer gnus-article-buffer)
5046 (let ((alist gnus-header-face-alist)
5047 (buffer-read-only nil)
5048 (case-fold-search t)
5049 (inhibit-point-motion-hooks t)
5050 entry regexp header-face field-face from hpoints fpoints)
5051 (article-narrow-to-head)
5052 (while (setq entry (pop alist))
5053 (goto-char (point-min))
5054 (setq regexp (concat "^\\("
5055 (if (string-equal "" (nth 0 entry))
5059 header-face (nth 1 entry)
5060 field-face (nth 2 entry))
5061 (while (and (re-search-forward regexp nil t)
5065 (unless (search-forward ":" nil t)
5067 (when (and header-face
5068 (not (memq (point) hpoints)))
5069 (push (point) hpoints)
5070 (gnus-put-text-property from (point) 'face header-face))
5071 (when (and field-face
5072 (not (memq (setq from (point)) fpoints)))
5074 (if (re-search-forward "^[^ \t]" nil t)
5076 (goto-char (point-max)))
5077 (gnus-put-text-property from (point) 'face field-face))))))))
5079 (defun gnus-article-highlight-signature ()
5080 "Highlight the signature in an article.
5081 It does this by highlighting everything after
5082 `gnus-signature-separator' using `gnus-signature-face'."
5085 (set-buffer gnus-article-buffer)
5086 (let ((buffer-read-only nil)
5087 (inhibit-point-motion-hooks t))
5089 (when (and gnus-signature-face
5090 (gnus-article-narrow-to-signature))
5091 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5092 'face gnus-signature-face)
5094 (gnus-article-search-signature)
5095 (let ((start (match-beginning 0))
5096 (end (set-marker (make-marker) (1+ (match-end 0)))))
5097 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
5100 (defun gnus-button-in-region-p (b e prop)
5101 "Say whether PROP exists in the region."
5102 (text-property-not-all b e prop nil))
5104 (defun gnus-article-add-buttons (&optional force)
5105 "Find external references in the article and make buttons of them.
5106 \"External references\" are things like Message-IDs and URLs, as
5107 specified by `gnus-button-alist'."
5108 (interactive (list 'force))
5110 (set-buffer gnus-article-buffer)
5111 (let ((buffer-read-only nil)
5112 (inhibit-point-motion-hooks t)
5113 (case-fold-search t)
5114 (alist gnus-button-alist)
5116 ;; Remove all old markers.
5117 (let (marker entry new-list)
5118 (while (setq marker (pop gnus-button-marker-list))
5119 (if (or (< marker (point-min)) (>= marker (point-max)))
5120 (push marker new-list)
5122 (when (setq entry (gnus-button-entry))
5123 (put-text-property (match-beginning (nth 1 entry))
5124 (match-end (nth 1 entry))
5125 'gnus-callback nil))
5126 (set-marker marker nil)))
5127 (setq gnus-button-marker-list new-list))
5128 ;; We skip the headers.
5131 (while (setq entry (pop alist))
5132 (setq regexp (car entry))
5134 (while (re-search-forward regexp nil t)
5135 (let* ((start (and entry (match-beginning (nth 1 entry))))
5136 (end (and entry (match-end (nth 1 entry))))
5137 (from (match-beginning 0)))
5138 (when (and (or (eq t (nth 2 entry))
5139 (eval (nth 2 entry)))
5140 (not (gnus-button-in-region-p
5141 start end 'gnus-callback)))
5142 ;; That optional form returned non-nil, so we add the
5144 (gnus-article-add-button
5145 start end 'gnus-button-push
5146 (car (push (set-marker (make-marker) from)
5147 gnus-button-marker-list))))))))))
5149 ;; Add buttons to the head of an article.
5150 (defun gnus-article-add-buttons-to-head ()
5151 "Add buttons to the head of the article."
5154 (set-buffer gnus-article-buffer)
5156 (let ((buffer-read-only nil)
5157 (inhibit-point-motion-hooks t)
5158 (case-fold-search t)
5159 (alist gnus-header-button-alist)
5161 (article-narrow-to-head)
5163 ;; Each alist entry.
5164 (setq entry (car alist)
5166 (goto-char (point-min))
5167 (while (re-search-forward (car entry) nil t)
5168 ;; Each header matching the entry.
5169 (setq beg (match-beginning 0))
5170 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5171 (match-beginning 0))
5174 (while (re-search-forward (nth 1 entry) end t)
5175 ;; Each match within a header.
5176 (let* ((entry (cdr entry))
5177 (start (match-beginning (nth 1 entry)))
5178 (end (match-end (nth 1 entry)))
5179 (form (nth 2 entry)))
5180 (goto-char (match-end 0))
5182 (gnus-article-add-button
5183 start end (nth 3 entry)
5184 (buffer-substring (match-beginning (nth 4 entry))
5185 (match-end (nth 4 entry)))))))
5186 (goto-char end)))))))
5188 ;;; External functions:
5190 (defun gnus-article-add-button (from to fun &optional data)
5191 "Create a button between FROM and TO with callback FUN and data DATA."
5192 (when gnus-article-button-face
5193 (gnus-overlay-put (gnus-make-overlay from to)
5194 'face gnus-article-button-face))
5195 (gnus-add-text-properties
5197 (nconc (and gnus-article-mouse-face
5198 (list gnus-mouse-face-prop gnus-article-mouse-face))
5199 (list 'gnus-callback fun)
5200 (and data (list 'gnus-data data))))
5201 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5202 :button-keymap gnus-widget-button-keymap))
5204 ;;; Internal functions:
5206 (defun gnus-article-set-globals ()
5208 (set-buffer gnus-summary-buffer)
5209 (gnus-set-global-variables)))
5211 (defun gnus-signature-toggle (end)
5213 (set-buffer gnus-article-buffer)
5214 (let ((buffer-read-only nil)
5215 (inhibit-point-motion-hooks t))
5216 (if (text-property-any end (point-max) 'article-type 'signature)
5218 (setq gnus-article-wash-types
5219 (delq 'signature gnus-article-wash-types))
5220 (gnus-remove-text-properties-when
5221 'article-type 'signature end (point-max)
5222 (cons 'article-type (cons 'signature
5223 gnus-hidden-properties))))
5224 (or (memq 'signature gnus-article-wash-types)
5225 (push 'signature gnus-article-wash-types))
5226 (gnus-add-text-properties-when
5227 'article-type nil end (point-max)
5228 (cons 'article-type (cons 'signature
5229 gnus-hidden-properties)))))
5230 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
5231 (gnus-set-mode-line 'article))))
5233 (defun gnus-button-entry ()
5234 ;; Return the first entry in `gnus-button-alist' matching this place.
5235 (let ((alist gnus-button-alist)
5238 (setq entry (pop alist))
5239 (if (looking-at (car entry))
5244 (defun gnus-button-push (marker)
5245 ;; Push button starting at MARKER.
5248 (let* ((entry (gnus-button-entry))
5249 (inhibit-point-motion-hooks t)
5251 (args (mapcar (lambda (group)
5252 (let ((string (match-string group)))
5253 (gnus-set-text-properties
5254 0 (length string) nil string)
5261 (fboundp (symbol-value fun)))
5262 (apply (symbol-value fun) args))
5264 (gnus-message 1 "You must define `%S' to use this button"
5265 (cons fun args)))))))
5267 (defun gnus-parse-news-url (url)
5268 (let (scheme server group message-id articles)
5271 (goto-char (point-min))
5272 (when (looking-at "\\([A-Za-z]+\\):")
5273 (setq scheme (match-string 1))
5274 (goto-char (match-end 0)))
5275 (when (looking-at "//\\([^/]+\\)/")
5276 (setq server (match-string 1))
5277 (goto-char (match-end 0)))
5280 ((looking-at "\\(.*@.*\\)")
5281 (setq message-id (match-string 1)))
5282 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
5283 (setq group (match-string 1)
5284 articles (split-string (match-string 2) "-")))
5285 ((looking-at "\\([^/]+\\)/?")
5286 (setq group (match-string 1)))
5288 (error "Unknown news URL syntax"))))
5289 (list scheme server group message-id articles)))
5291 (defun gnus-button-handle-news (url)
5293 (destructuring-bind (scheme server group message-id articles)
5294 (gnus-parse-news-url url)
5298 (set-buffer gnus-summary-buffer)
5300 (let ((gnus-refer-article-method (list (list 'nntp server))))
5301 (gnus-summary-refer-article message-id))
5302 (gnus-summary-refer-article message-id))))
5304 (gnus-button-fetch-group url)))))
5306 (defun gnus-button-handle-info (url)
5307 "Fetch an info URL."
5309 "^\\([^:/]+\\)?/\\(.*\\)"
5311 (gnus-info-find-node
5312 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
5315 (gnus-url-unhex-string (match-string 2 url))))
5316 (error "Can't parse %s" url)))
5318 (defun gnus-button-message-id (message-id)
5321 (set-buffer gnus-summary-buffer)
5322 (gnus-summary-refer-article message-id)))
5324 (defun gnus-button-fetch-group (address)
5325 "Fetch GROUP specified by ADDRESS."
5326 (if (not (string-match "[:/]" address))
5327 ;; This is just a simple group url.
5328 (gnus-group-read-ephemeral-group address gnus-select-method)
5331 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
5333 (error "Can't parse %s" address)
5334 (gnus-group-read-ephemeral-group
5335 (match-string 4 address)
5336 `(nntp ,(match-string 1 address)
5337 (nntp-address ,(match-string 1 address))
5338 (nntp-port-number ,(if (match-end 3)
5339 (match-string 3 address)
5342 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
5344 (defun gnus-url-parse-query-string (query &optional downcase)
5345 (let (retval pairs cur key val)
5346 (setq pairs (split-string query "&"))
5348 (setq cur (car pairs)
5350 (if (not (string-match "=" cur))
5352 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5353 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5355 (setq key (downcase key)))
5356 (setq cur (assoc key retval))
5358 (setcdr cur (cons val (cdr cur)))
5359 (setq retval (cons (list key val) retval)))))
5362 (defun gnus-url-mailto (url)
5363 ;; Send mail to someone
5364 (when (string-match "mailto:/*\\(.*\\)" url)
5365 (setq url (substring url (match-beginning 1) nil)))
5366 (let (to args subject func)
5367 (if (string-match (regexp-quote "?") url)
5368 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5369 args (gnus-url-parse-query-string
5370 (substring url (match-end 0) nil) t))
5371 (setq to (gnus-url-unhex-string url)))
5372 (setq args (cons (list "to" to) args)
5373 subject (cdr-safe (assoc "subject" args)))
5376 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5379 (message-position-on-field (caar args)))
5380 (insert (mapconcat 'identity (cdar args) ", "))
5381 (setq args (cdr args)))
5384 (message-goto-subject))))
5386 (defun gnus-button-embedded-url (address)
5387 "Activate ADDRESS with `browse-url'."
5388 (browse-url (gnus-strip-whitespace address)))
5390 ;;; Next/prev buttons in the article buffer.
5392 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5393 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5395 (defvar gnus-prev-page-map nil)
5396 (unless gnus-prev-page-map
5397 (setq gnus-prev-page-map (make-sparse-keymap))
5398 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5399 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5401 (defun gnus-insert-prev-page-button ()
5402 (let ((buffer-read-only nil))
5404 gnus-prev-page-line-format nil
5405 `(gnus-prev t local-map ,gnus-prev-page-map
5406 gnus-callback gnus-article-button-prev-page
5407 article-type annotation))))
5409 (defvar gnus-next-page-map nil)
5410 (unless gnus-next-page-map
5411 (setq gnus-next-page-map (make-keymap))
5412 (suppress-keymap gnus-prev-page-map)
5413 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5414 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5416 (defun gnus-button-next-page ()
5417 "Go to the next page."
5419 (let ((win (selected-window)))
5420 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5421 (gnus-article-next-page)
5422 (select-window win)))
5424 (defun gnus-button-prev-page ()
5425 "Go to the prev page."
5427 (let ((win (selected-window)))
5428 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5429 (gnus-article-prev-page)
5430 (select-window win)))
5432 (defun gnus-insert-next-page-button ()
5433 (let ((buffer-read-only nil))
5434 (gnus-eval-format gnus-next-page-line-format nil
5436 t local-map ,gnus-next-page-map
5437 gnus-callback gnus-article-button-next-page
5438 article-type annotation))))
5440 (defun gnus-article-button-next-page (arg)
5441 "Go to the next page."
5443 (let ((win (selected-window)))
5444 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5445 (gnus-article-next-page)
5446 (select-window win)))
5448 (defun gnus-article-button-prev-page (arg)
5449 "Go to the prev page."
5451 (let ((win (selected-window)))
5452 (select-window (gnus-get-buffer-window gnus-article-buffer t))
5453 (gnus-article-prev-page)
5454 (select-window win)))
5456 (defvar gnus-decode-header-methods
5457 '(mail-decode-encoded-word-region)
5458 "List of methods used to decode headers.
5460 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5461 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5462 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5463 whose names match REGEXP.
5466 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5467 mail-decode-encoded-word-region
5468 (\"chinese\" . rfc1843-decode-region))
5471 (defvar gnus-decode-header-methods-cache nil)
5473 (defun gnus-multi-decode-header (start end)
5474 "Apply the functions from `gnus-encoded-word-methods' that match."
5475 (unless (and gnus-decode-header-methods-cache
5476 (eq gnus-newsgroup-name
5477 (car gnus-decode-header-methods-cache)))
5478 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5481 (nconc gnus-decode-header-methods-cache (list x))
5482 (if (and gnus-newsgroup-name
5483 (string-match (car x) gnus-newsgroup-name))
5484 (nconc gnus-decode-header-methods-cache
5486 gnus-decode-header-methods))
5487 (let ((xlist gnus-decode-header-methods-cache))
5490 (narrow-to-region start end)
5492 (funcall (pop xlist) (point-min) (point-max))))))
5495 ;;; Treatment top-level handling.
5498 (defun gnus-treat-article (condition &optional part-number total-parts type)
5499 (let ((length (- (point-max) (point-min)))
5500 (alist gnus-treatment-function-alist)
5501 (article-goto-body-goes-to-point-min-p t)
5505 (let ((list gnus-article-treat-types))
5507 (when (string-match (pop list) type)
5508 (throw 'found t)))))))
5509 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5511 (gnus-run-hooks 'gnus-part-display-hook)
5512 (while (setq elem (pop alist))
5515 (if (gnus-buffer-live-p gnus-summary-buffer)
5516 (set-buffer gnus-summary-buffer))
5517 (symbol-value (car elem))))
5518 (when (and (or (consp val)
5520 (gnus-treat-predicate val)
5521 (or (not (get (car elem) 'highlight))
5524 (funcall (cadr elem)))))))
5526 ;; Dynamic variables.
5528 (defvar part-number)
5529 (defvar total-parts)
5534 (defun gnus-treat-predicate (val)
5539 (stringp (car val)))
5540 (apply 'gnus-or (mapcar `(lambda (s)
5541 (string-match s ,(or gnus-newsgroup-name "")))
5544 (let ((pred (pop val)))
5547 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5549 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5551 (not (gnus-treat-predicate (car val))))
5553 (equal (car val) type))
5555 (error "%S is not a valid predicate" pred)))))
5563 (eq part-number total-parts))
5567 (error "%S is not a valid value" val))))
5569 (defun gnus-article-encrypt-body (protocol &optional n)
5570 "Encrypt the article body."
5573 (or gnus-article-encrypt-protocol
5574 (completing-read "Encrypt protocol: "
5575 gnus-article-encrypt-protocol-alist
5577 current-prefix-arg))
5578 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5580 (error (format "Can't find the encrypt protocol %s" protocol)))
5581 (if (equal gnus-newsgroup-name "nndraft:drafts")
5582 (error "Can't encrypt the article in group nndraft:drafts"))
5583 (if (equal gnus-newsgroup-name "nndraft:queue")
5584 (error "Don't encrypt the article in group nndraft:queue"))
5585 (gnus-summary-iterate n
5587 (set-buffer gnus-summary-buffer)
5588 (let ((mail-parse-charset gnus-newsgroup-charset)
5589 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5590 (summary-buffer gnus-summary-buffer)
5592 (gnus-set-global-variables)
5593 (when (gnus-group-read-only-p)
5594 (error "The current newsgroup does not support article encrypt"))
5595 (gnus-summary-show-article t)
5597 (or (mail-header-references gnus-current-headers) ""))
5598 (set-buffer gnus-article-buffer)
5599 (let* ((buffer-read-only nil)
5601 (mapcar (lambda (field)
5602 (and (save-restriction
5603 (message-narrow-to-head)
5604 (goto-char (point-min))
5605 (search-forward field nil t))
5607 (message-narrow-to-field)
5608 (buffer-substring (point-min) (point-max))
5609 (delete-region (point-min) (point-max))
5611 '("Content-Type:" "Content-Transfer-Encoding:"
5612 "Content-Disposition:"))))
5613 (message-narrow-to-head)
5614 (message-remove-header "MIME-Version")
5615 (goto-char (point-max))
5616 (setq point (point))
5617 (insert (apply 'concat headers))
5619 (narrow-to-region point (point-max))
5620 (let ((message-options message-options))
5621 (message-options-set 'message-sender user-mail-address)
5622 (message-options-set 'message-recipients user-mail-address)
5623 (message-options-set 'message-sign-encrypt 'not)
5625 (goto-char (point-min))
5626 (insert "MIME-Version: 1.0\n")
5628 (gnus-summary-edit-article-done
5629 references nil summary-buffer t))
5630 (when gnus-keep-backlog
5631 (gnus-backlog-remove-article
5632 (car gnus-article-current) (cdr gnus-article-current)))
5634 (when (get-buffer gnus-original-article-buffer)
5635 (set-buffer gnus-original-article-buffer)
5636 (setq gnus-original-article nil)))
5637 (when gnus-use-cache
5638 (gnus-cache-update-article
5639 (car gnus-article-current) (cdr gnus-article-current))))))))
5641 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5642 "The following specs can be used:
5643 %t The security MIME type
5646 %D Details if button is pressed")
5648 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5649 "The following specs can be used:
5650 %t The security MIME type
5653 %D Details if button is pressed")
5655 (defvar gnus-mime-security-button-line-format-alist
5656 '((?t gnus-tmp-type ?s)
5657 (?i gnus-tmp-info ?s)
5658 (?d gnus-tmp-details ?s)
5659 (?D gnus-tmp-pressed-details ?s)))
5661 (defvar gnus-mime-security-button-map
5662 (let ((map (make-sparse-keymap)))
5663 (unless (>= (string-to-number emacs-version) 21)
5664 (set-keymap-parent map gnus-article-mode-map))
5665 (define-key map gnus-mouse-2 'gnus-article-push-button)
5666 (define-key map "\r" 'gnus-article-press-button)
5669 (defvar gnus-mime-security-details-buffer nil)
5671 (defvar gnus-mime-security-button-pressed nil)
5673 (defvar gnus-mime-security-show-details-inline t
5674 "If non-nil, show details in the article buffer.")
5676 (defun gnus-mime-security-verify-or-decrypt (handle)
5677 (mm-remove-parts (cdr handle))
5678 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5679 point buffer-read-only)
5681 (goto-char (car region)))
5683 (narrow-to-region (point) (point))
5684 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5685 (let* ((mm-verify-option 'known)
5686 (mm-decrypt-option 'known)
5687 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5688 (unless (eq nparts (cdr handle))
5689 (mm-destroy-parts (cdr handle))
5690 (setcdr handle nparts))))
5691 (setq point (point))
5692 (gnus-mime-display-security handle)
5693 (goto-char (point-max)))
5695 (delete-region (point) (cdr region))
5696 (set-marker (car region) nil)
5697 (set-marker (cdr region) nil))
5700 (defun gnus-mime-security-show-details (handle)
5701 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5703 (if gnus-mime-security-show-details-inline
5704 (let ((gnus-mime-security-button-pressed t)
5705 (gnus-mime-security-button-line-format
5706 (get-text-property (point) 'gnus-line-format))
5709 (while (eq (get-text-property (point) 'gnus-line-format)
5710 gnus-mime-security-button-line-format)
5714 (narrow-to-region (point) (point))
5715 (gnus-insert-mime-security-button handle))
5716 (delete-region (point)
5717 (or (text-property-not-all
5720 gnus-mime-security-button-line-format)
5722 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5723 (with-current-buffer gnus-mime-security-details-buffer
5726 (setq gnus-mime-security-details-buffer
5727 (gnus-get-buffer-create "*MIME Security Details*")))
5728 (with-current-buffer gnus-mime-security-details-buffer
5730 (goto-char (point-min)))
5731 (pop-to-buffer gnus-mime-security-details-buffer))
5732 (gnus-message 5 "No details."))))
5734 (defun gnus-mime-security-press-button (handle)
5735 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5736 (gnus-mime-security-show-details handle)
5737 (gnus-mime-security-verify-or-decrypt handle)))
5739 (defun gnus-insert-mime-security-button (handle &optional displayed)
5740 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5743 (or (nth 2 (assoc protocol mm-verify-function-alist))
5744 (nth 2 (assoc protocol mm-decrypt-function-alist))
5746 (if (equal (car handle) "multipart/signed")
5747 " Signed" " Encrypted")
5750 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5753 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5754 gnus-tmp-pressed-details
5756 (setq gnus-tmp-details
5757 (if gnus-tmp-details
5758 (concat "\n" gnus-tmp-details) ""))
5759 (setq gnus-tmp-pressed-details
5760 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5765 gnus-mime-security-button-line-format
5766 gnus-mime-security-button-line-format-alist
5767 `(keymap ,gnus-mime-security-button-map
5768 ,@(if (>= (string-to-number emacs-version) 21)
5769 nil ;; XEmacs doesn't care
5770 (list 'local-map gnus-mime-security-button-map))
5771 gnus-callback gnus-mime-security-press-button
5772 gnus-line-format ,gnus-mime-security-button-line-format
5773 article-type annotation
5776 (widget-convert-button
5779 :action 'gnus-widget-press-button
5780 :button-keymap gnus-mime-security-button-map
5782 (lambda (widget/window &optional overlay pos)
5783 ;; Needed to properly clear the message due to a bug in
5784 ;; wid-edit (XEmacs only).
5785 (if (boundp 'help-echo-owns-message)
5786 (setq help-echo-owns-message t))
5789 (aref gnus-mouse-2 0))))))
5791 (defun gnus-mime-display-security (handle)
5793 (narrow-to-region (point) (point))
5794 (unless (gnus-unbuttonized-mime-type-p (car handle))
5795 (gnus-insert-mime-security-button handle))
5796 (gnus-mime-display-mixed (cdr handle))
5799 (unless (gnus-unbuttonized-mime-type-p (car handle))
5800 (let ((gnus-mime-security-button-line-format
5801 gnus-mime-security-button-end-line-format))
5802 (gnus-insert-mime-security-button handle)))
5803 (mm-set-handle-multipart-parameter
5805 (cons (set-marker (make-marker) (point-min))
5806 (set-marker (make-marker) (point-max))))))
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