1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
31 (eval-when-compile (require 'static))
42 ;; Avoid byte-compile warnings.
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)The Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
113 '("^Path:" "^Expires:" "^Date-Received:" "^References:" "^Xref:" "^Lines:"
114 "^Relay-Version:" "^Message-ID:" "^Approved:" "^Sender:" "^Received:"
115 "^X-UIDL:" "^MIME-Version:" "^Return-Path:" "^In-Reply-To:"
116 "^Content-Type:" "^Content-Transfer-Encoding:" "^X-WebTV-Signature:"
117 "^X-MimeOLE:" "^X-MSMail-Priority:" "^X-Priority:" "^X-Loop:"
118 "^X-Authentication-Warning:" "^X-MIME-Autoconverted:" "^X-Face:"
119 "^X-Attribution:" "^X-Originating-IP:" "^Delivered-To:"
120 "^NNTP-[-A-Za-z]+:" "^Distribution:" "^X-no-archive:" "^X-Trace:"
121 "^X-Complaints-To:" "^X-NNTP-Posting-Host:" "^X-Orig.*:"
122 "^Abuse-Reports-To:" "^Cache-Post-Path:" "^X-Article-Creation-Date:"
123 "^X-Poster:" "^X-Mail2News-Path:" "^X-Server-Date:" "^X-Cache:"
124 "^Originator:" "^X-Problems-To:" "^X-Auth-User:" "^X-Post-Time:"
125 "^X-Admin:" "^X-UID:" "^Resent-[-A-Za-z]+:" "^X-Mailing-List:"
126 "^Precedence:" "^Original-[-A-Za-z]+:" "^X-filename:" "^X-Orcpt:"
127 "^Old-Received:" "^X-Pgp" "^X-Auth:" "^X-From-Line:"
128 "^X-Gnus-Article-Number:" "^X-Majordomo:" "^X-Url:" "^X-Sender:"
129 "^MBOX-Line" "^Priority:" "^X400-[-A-Za-z]+:"
130 "^Status:" "^X-Gnus-Mail-Source:" "^Cancel-Lock:"
131 "^X-FTN" "^X-EXP32-SerialNo:" "^Encoding:" "^Importance:"
132 "^Autoforwarded:" "^Original-Encoded-Information-Types:" "^X-Ya-Pop3:"
133 "^X-Face-Version:" "^X-Vms-To:" "^X-ML-NAME:" "^X-ML-COUNT:"
134 "^Mailing-List:" "^X-finfo:" "^X-md5sum:" "^X-md5sum-Origin:"
135 "^X-Sun-Charset:" "^X-Accept-Language:" "^X-Envelope-Sender:"
136 "^List-[A-Za-z]+:" "^X-Listprocessor-Version:"
137 "^X-Received:" "^X-Distribute:" "^X-Sequence:" "^X-Juno-Line-Breaks:"
138 "^X-Notes-Item:" "^X-MS-TNEF-Correlator:" "^x-uunet-gateway:"
139 "^X-Received:" "^Content-length:" "X-precedence:")
140 "*All headers that start with this regexp will be hidden.
141 This variable can also be a list of regexps of headers to be ignored.
142 If `gnus-visible-headers' is non-nil, this variable will be ignored."
143 :type '(choice :custom-show nil
146 :group 'gnus-article-hiding)
148 (defcustom gnus-visible-headers
149 "^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:"
150 "*All headers that do not match this regexp will be hidden.
151 This variable can also be a list of regexp of headers to remain visible.
152 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
153 :type '(repeat :value-to-internal (lambda (widget value)
154 (custom-split-regexp-maybe value))
155 :match (lambda (widget value)
157 (widget-editable-list-match widget value)))
159 :group 'gnus-article-hiding)
161 (defcustom gnus-sorted-header-list
162 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
163 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
164 "*This variable is a list of regular expressions.
165 If it is non-nil, headers that match the regular expressions will
166 be placed first in the article buffer in the sequence specified by
168 :type '(repeat regexp)
169 :group 'gnus-article-hiding)
171 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
172 "Headers that are only to be displayed if they have interesting data.
173 Possible values in this list are `empty', `newsgroups', `followup-to',
174 `reply-to', `date', `long-to', and `many-to'."
175 :type '(set (const :tag "Headers with no content." empty)
176 (const :tag "Newsgroups with only one group." newsgroups)
177 (const :tag "Followup-to identical to newsgroups." followup-to)
178 (const :tag "Reply-to identical to from." reply-to)
179 (const :tag "Date less than four days old." date)
180 (const :tag "Very long To and/or Cc header." long-to)
181 (const :tag "Multiple To and/or Cc headers." many-to))
182 :group 'gnus-article-hiding)
184 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
185 "Regexp matching signature separator.
186 This can also be a list of regexps. In that case, it will be checked
187 from head to tail looking for a separator. Searches will be done from
188 the end of the buffer."
189 :type '(repeat string)
190 :group 'gnus-article-signature)
192 (defcustom gnus-signature-limit nil
193 "Provide a limit to what is considered a signature.
194 If it is a number, no signature may not be longer (in characters) than
195 that number. If it is a floating point number, no signature may be
196 longer (in lines) than that number. If it is a function, the function
197 will be called without any parameters, and if it returns nil, there is
198 no signature in the buffer. If it is a string, it will be used as a
199 regexp. If it matches, the text in question is not a signature."
200 :type '(choice (integer :value 200)
202 (function :value fun)
203 (regexp :value ".*"))
204 :group 'gnus-article-signature)
206 (defcustom gnus-hidden-properties '(invisible t intangible t)
207 "Property list to use for hiding text."
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-x-face-command
213 ;; Fixme: This isn't the right thing for mixed graphical and and
214 ;; non-graphical frames in a session.
215 ;; gnus-xmas.el overrides this for XEmacs.
216 ((and (fboundp 'image-type-available-p)
217 (image-type-available-p 'xbm))
218 (if (module-installed-p 'x-face-e21)
219 'x-face-decode-message-header
220 'gnus-article-display-xface))
221 ((and (not (featurep 'xemacs))
223 (module-installed-p 'x-face-mule))
224 'x-face-mule-gnus-article-display-x-face)
225 (gnus-article-compface-xbm
226 "{ echo '/* Width=48, Height=48 */'; uncompface; } | display -")
228 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
230 "*String or function to be executed to display an X-Face header.
231 If it is a string, the command will be executed in a sub-shell
232 asynchronously. The compressed face will be piped to this command."
233 :type '(choice string
235 :tag "x-face-decode-message-header (x-face-e21)"
236 x-face-decode-message-header)
237 (function-item gnus-article-display-xface)
238 (function-item x-face-mule-gnus-article-display-x-face)
240 :group 'gnus-article-washing)
242 (defcustom gnus-article-x-face-too-ugly nil
243 "Regexp matching posters whose face shouldn't be shown automatically."
244 :type '(choice regexp (const nil))
245 :group 'gnus-article-washing)
247 (defcustom gnus-article-banner-alist nil
248 "Banner alist for stripping.
250 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( eGroups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
251 :type '(repeat (cons symbol regexp))
252 :group 'gnus-article-washing)
254 (defcustom gnus-emphasis-alist
256 "\\(\\s-\\|^\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-,;:\"]\\s-\\|[?!.]+\\s-\\|\\s)\\)")
258 '(("_" "_" underline)
261 ("_/" "/_" underline-italic)
262 ("_\\*" "\\*_" underline-bold)
263 ("\\*/" "/\\*" bold-italic)
264 ("_\\*/" "/\\*_" underline-bold-italic))))
265 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
266 2 3 gnus-emphasis-underline)
270 (format format (car spec) (car (cdr spec)))
271 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
273 "*Alist that says how to fontify certain phrases.
274 Each item looks like this:
276 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
278 The first element is a regular expression to be matched. The second
279 is a number that says what regular expression grouping used to find
280 the entire emphasized word. The third is a number that says what
281 regexp grouping should be displayed and highlighted. The fourth
282 is the face used for highlighting."
283 :type '(repeat (list :value ("" 0 0 default)
285 (integer :tag "Match group")
286 (integer :tag "Emphasize group")
288 :group 'gnus-article-emphasis)
290 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
291 "A regexp to describe whitespace which should not be emphasized.
292 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
293 The former avoids underlining of leading and trailing whitespace,
294 and the latter avoids underlining any whitespace at all."
295 :group 'gnus-article-emphasis
298 (defface gnus-emphasis-bold '((t (:bold t)))
299 "Face used for displaying strong emphasized text (*word*)."
300 :group 'gnus-article-emphasis)
302 (defface gnus-emphasis-italic '((t (:italic t)))
303 "Face used for displaying italic emphasized text (/word/)."
304 :group 'gnus-article-emphasis)
306 (defface gnus-emphasis-underline '((t (:underline t)))
307 "Face used for displaying underlined emphasized text (_word_)."
308 :group 'gnus-article-emphasis)
310 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
311 "Face used for displaying underlined bold emphasized text (_*word*_)."
312 :group 'gnus-article-emphasis)
314 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
315 "Face used for displaying underlined italic emphasized text (_/word/_)."
316 :group 'gnus-article-emphasis)
318 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
319 "Face used for displaying bold italic emphasized text (/*word*/)."
320 :group 'gnus-article-emphasis)
322 (defface gnus-emphasis-underline-bold-italic
323 '((t (:bold t :italic t :underline t)))
324 "Face used for displaying underlined bold italic emphasized text.
325 Esample: (_/*word*/_)."
326 :group 'gnus-article-emphasis)
328 (defface gnus-emphasis-highlight-words
329 '((t (:background "black" :foreground "yellow")))
330 "Face used for displaying highlighted words."
331 :group 'gnus-article-emphasis)
333 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
334 "Format for display of Date headers in article bodies.
335 See `format-time-string' for the possible values.
337 The variable can also be function, which should return a complete Date
338 header. The function is called with one argument, the time, which can
339 be fed to `format-time-string'."
340 :type '(choice string symbol)
341 :link '(custom-manual "(gnus)Article Date")
342 :group 'gnus-article-washing)
345 (autoload 'mail-extract-address-components "mail-extr"))
347 (defcustom gnus-save-all-headers t
348 "*If non-nil, don't remove any headers before saving."
349 :group 'gnus-article-saving
352 (defcustom gnus-prompt-before-saving 'always
353 "*This variable says how much prompting is to be done when saving articles.
354 If it is nil, no prompting will be done, and the articles will be
355 saved to the default files. If this variable is `always', each and
356 every article that is saved will be preceded by a prompt, even when
357 saving large batches of articles. If this variable is neither nil not
358 `always', there the user will be prompted once for a file name for
359 each invocation of the saving commands."
360 :group 'gnus-article-saving
361 :type '(choice (item always)
362 (item :tag "never" nil)
363 (sexp :tag "once" :format "%t\n" :value t)))
365 (defcustom gnus-saved-headers gnus-visible-headers
366 "Headers to keep if `gnus-save-all-headers' is nil.
367 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
368 If that variable is nil, however, all headers that match this regexp
369 will be kept while the rest will be deleted before saving."
370 :group 'gnus-article-saving
373 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
374 "A function to save articles in your favourite format.
375 The function must be interactively callable (in other words, it must
376 be an Emacs command).
378 Gnus provides the following functions:
380 * gnus-summary-save-in-rmail (Rmail format)
381 * gnus-summary-save-in-mail (Unix mail format)
382 * gnus-summary-save-in-folder (MH folder)
383 * gnus-summary-save-in-file (article format)
384 * gnus-summary-save-in-vm (use VM's folder format)
385 * gnus-summary-write-to-file (article format -- overwrite)."
386 :group 'gnus-article-saving
387 :type '(radio (function-item gnus-summary-save-in-rmail)
388 (function-item gnus-summary-save-in-mail)
389 (function-item gnus-summary-save-in-folder)
390 (function-item gnus-summary-save-in-file)
391 (function-item gnus-summary-save-in-vm)
392 (function-item gnus-summary-write-to-file)))
394 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
395 "A function generating a file name to save articles in Rmail format.
396 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
397 :group 'gnus-article-saving
400 (defcustom gnus-mail-save-name 'gnus-plain-save-name
401 "A function generating a file name to save articles in Unix mail format.
402 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
403 :group 'gnus-article-saving
406 (defcustom gnus-folder-save-name 'gnus-folder-save-name
407 "A function generating a file name to save articles in MH folder.
408 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
409 :group 'gnus-article-saving
412 (defcustom gnus-file-save-name 'gnus-numeric-save-name
413 "A function generating a file name to save articles in article format.
414 The function is called with NEWSGROUP, HEADERS, and optional
416 :group 'gnus-article-saving
419 (defcustom gnus-split-methods
420 '((gnus-article-archive-name)
421 (gnus-article-nndoc-name))
422 "*Variable used to suggest where articles are to be saved.
423 For instance, if you would like to save articles related to Gnus in
424 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
425 you could set this variable to something like:
427 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
428 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
430 This variable is an alist where the where the key is the match and the
431 value is a list of possible files to save in if the match is non-nil.
433 If the match is a string, it is used as a regexp match on the
434 article. If the match is a symbol, that symbol will be funcalled
435 from the buffer of the article to be saved with the newsgroup as the
436 parameter. If it is a list, it will be evaled in the same buffer.
438 If this form or function returns a string, this string will be used as
439 a possible file name; and if it returns a non-nil list, that list will
440 be used as possible file names."
441 :group 'gnus-article-saving
442 :type '(repeat (choice (list :value (fun) function)
443 (cons :value ("" "") regexp (repeat string))
446 (defcustom gnus-article-display-method-for-mime
447 'gnus-article-display-mime-message
448 "Function to display a MIME message.
449 The function is called from the article buffer."
450 :group 'gnus-article-mime
453 (defcustom gnus-article-display-method-for-traditional
454 'gnus-article-display-traditional-message
455 "*Function to display a traditional message.
456 The function is called from the article buffer."
457 :group 'gnus-article-mime
460 (defcustom gnus-page-delimiter "^\^L"
461 "*Regexp describing what to use as article page delimiters.
462 The default value is \"^\^L\", which is a form linefeed at the
463 beginning of a line."
465 :group 'gnus-article-various)
467 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
468 "*The format specification for the article mode line.
469 See `gnus-summary-mode-line-format' for a closer description.
471 The following additional specs are available:
473 %w The article washing status.
474 %m The number of MIME parts in the article."
476 :group 'gnus-article-various)
478 (defcustom gnus-article-mode-hook nil
479 "*A hook for Gnus article mode."
481 :group 'gnus-article-various)
483 (defcustom gnus-article-menu-hook nil
484 "*Hook run after the creation of the article mode menu."
486 :group 'gnus-article-various)
488 (defcustom gnus-article-prepare-hook nil
489 "*A hook called after an article has been prepared in the article buffer."
491 :group 'gnus-article-various)
493 (defcustom gnus-article-hide-pgp-hook nil
494 "*A hook called after successfully hiding a PGP signature."
496 :group 'gnus-article-various)
498 (defcustom gnus-article-button-face 'bold
499 "Face used for highlighting buttons in the article buffer.
501 An article button is a piece of text that you can activate by pressing
502 `RET' or `mouse-2' above it."
504 :group 'gnus-article-buttons)
506 (defcustom gnus-article-mouse-face 'highlight
507 "Face used for mouse highlighting in the article buffer.
509 Article buttons will be displayed in this face when the cursor is
512 :group 'gnus-article-buttons)
514 (defcustom gnus-signature-face 'gnus-signature-face
515 "Face used for highlighting a signature in the article buffer.
516 Obsolete; use the face `gnus-signature-face' for customizations instead."
518 :group 'gnus-article-highlight
519 :group 'gnus-article-signature)
521 (defface gnus-signature-face
524 "Face used for highlighting a signature in the article buffer."
525 :group 'gnus-article-highlight
526 :group 'gnus-article-signature)
528 (defface gnus-header-from-face
531 (:foreground "spring green"))
534 (:foreground "red3"))
537 "Face used for displaying from headers."
538 :group 'gnus-article-headers
539 :group 'gnus-article-highlight)
541 (defface gnus-header-subject-face
544 (:foreground "SeaGreen3"))
547 (:foreground "red4"))
549 (:bold t :italic t)))
550 "Face used for displaying subject headers."
551 :group 'gnus-article-headers
552 :group 'gnus-article-highlight)
554 (defface gnus-header-newsgroups-face
557 (:foreground "yellow" :italic t))
560 (:foreground "MidnightBlue" :italic t))
563 "Face used for displaying newsgroups headers."
564 :group 'gnus-article-headers
565 :group 'gnus-article-highlight)
567 (defface gnus-header-name-face
570 (:foreground "SeaGreen"))
573 (:foreground "maroon"))
576 "Face used for displaying header names."
577 :group 'gnus-article-headers
578 :group 'gnus-article-highlight)
580 (defface gnus-header-content-face
583 (:foreground "forest green" :italic t))
586 (:foreground "indianred4" :italic t))
588 (:italic t))) "Face used for displaying header content."
589 :group 'gnus-article-headers
590 :group 'gnus-article-highlight)
592 (defcustom gnus-header-face-alist
593 '(("From" nil gnus-header-from-face)
594 ("Subject" nil gnus-header-subject-face)
595 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
596 ("" gnus-header-name-face gnus-header-content-face))
597 "*Controls highlighting of article header.
599 An alist of the form (HEADER NAME CONTENT).
601 HEADER is a regular expression which should match the name of an
602 header header and NAME and CONTENT are either face names or nil.
604 The name of each header field will be displayed using the face
605 specified by the first element in the list where HEADER match the
606 header name and NAME is non-nil. Similarly, the content will be
607 displayed by the first non-nil matching CONTENT face."
608 :group 'gnus-article-headers
609 :group 'gnus-article-highlight
610 :type '(repeat (list (regexp :tag "Header")
612 (item :tag "skip" nil)
613 (face :value default))
614 (choice :tag "Content"
615 (item :tag "skip" nil)
616 (face :value default)))))
618 (defcustom gnus-article-decode-hook nil
619 "*Hook run to decode charsets in articles."
620 :group 'gnus-article-headers
623 (defcustom gnus-display-mime-function 'gnus-display-mime
624 "Function to display MIME articles."
625 :group 'gnus-article-mime
628 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
629 "Function used to decode headers.")
631 (defvar gnus-article-dumbquotes-map
650 "Table for MS-to-Latin1 translation.")
652 (defcustom gnus-ignored-mime-types nil
653 "List of MIME types that should be ignored by Gnus."
654 :group 'gnus-article-mime
655 :type '(repeat regexp))
657 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
658 "List of MIME types that should not be given buttons when rendered inline."
659 :group 'gnus-article-mime
660 :type '(repeat regexp))
662 (defcustom gnus-article-mime-part-function nil
663 "Function called with a MIME handle as the argument.
664 This is meant for people who want to do something automatic based
665 on parts -- for instance, adding Vcard info to a database."
666 :group 'gnus-article-mime
669 (defcustom gnus-mime-multipart-functions nil
670 "An alist of MIME types to functions to display them.")
672 (defcustom gnus-article-date-lapsed-new-header nil
673 "Whether the X-Sent and Date headers can coexist.
674 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
675 either replace the old \"Date:\" header (if this variable is nil), or
676 be added below it (otherwise)."
677 :group 'gnus-article-headers
680 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
681 "Function called with a MIME handle as the argument.
682 This is meant for people who want to view first matched part.
683 For `undisplayed-alternative' (default), the first undisplayed
684 part or alternative part is used. For `undisplayed', the first
685 undisplayed part is used. For a function, the first part which
686 the function return `t' is used. For `nil', the first part is
688 :group 'gnus-article-mime
690 (item :tag "first" :value nil)
691 (item :tag "undisplayed" :value undisplayed)
692 (item :tag "undisplayed or alternative"
693 :value undisplayed-alternative)
696 (defcustom gnus-mime-action-alist
697 '(("save to file" . gnus-mime-save-part)
698 ("save and strip" . gnus-mime-save-part-and-strip)
699 ("display as text" . gnus-mime-inline-part)
700 ("view the part" . gnus-mime-view-part)
701 ("pipe to command" . gnus-mime-pipe-part)
702 ("toggle display" . gnus-article-press-button)
703 ("toggle display" . gnus-article-view-part-as-charset)
704 ("view as type" . gnus-mime-view-part-as-type)
705 ("internalize type" . gnus-mime-internalize-part)
706 ("externalize type" . gnus-mime-externalize-part))
707 "An alist of actions that run on the MIME attachment."
708 :group 'gnus-article-mime
709 :type '(repeat (cons (string :tag "name")
713 ;;; The treatment variables
716 (defvar gnus-part-display-hook nil
717 "Hook called on parts that are to receive treatment.")
719 (defvar gnus-article-treat-custom
720 '(choice (const :tag "Off" nil)
722 (const :tag "Header" head)
723 (const :tag "Last" last)
724 (const :tag "Mime" mime)
725 (integer :tag "Less")
726 (repeat :tag "Groups" regexp)
727 (sexp :tag "Predicate")))
729 (defvar gnus-article-treat-head-custom
730 '(choice (const :tag "Off" nil)
731 (const :tag "Header" head)))
733 (defvar gnus-article-treat-types '("text/plain")
736 (defvar gnus-inhibit-treatment nil
737 "Whether to inhibit treatment.")
739 (defcustom gnus-treat-highlight-signature '(or last (typep "text/x-vcard"))
740 "Highlight the signature.
741 Valid values are nil, t, `head', `last', an integer or a predicate.
742 See the manual for details."
743 :group 'gnus-article-treat
744 :type gnus-article-treat-custom)
745 (put 'gnus-treat-highlight-signature 'highlight t)
747 (defcustom gnus-treat-buttonize 100000
749 Valid values are nil, t, `head', `last', an integer or a predicate.
750 See the manual for details."
751 :group 'gnus-article-treat
752 :type gnus-article-treat-custom)
753 (put 'gnus-treat-buttonize 'highlight t)
755 (defcustom gnus-treat-buttonize-head 'head
756 "Add buttons to the head.
757 Valid values are nil, t, `head', `last', an integer or a predicate.
758 See the manual for details."
759 :group 'gnus-article-treat
760 :type gnus-article-treat-head-custom)
761 (put 'gnus-treat-buttonize-head 'highlight t)
763 (defcustom gnus-treat-emphasize nil
765 Valid values are nil, t, `head', `last', an integer or a predicate.
766 See the manual for details."
767 :group 'gnus-article-treat
768 :type gnus-article-treat-custom)
769 (put 'gnus-treat-emphasize 'highlight t)
771 (defcustom gnus-treat-strip-cr nil
772 "Remove carriage returns.
773 Valid values are nil, t, `head', `last', an integer or a predicate.
774 See the manual for details."
775 :group 'gnus-article-treat
776 :type gnus-article-treat-custom)
778 (defcustom gnus-treat-hide-headers 'head
780 Valid values are nil, t, `head', `last', an integer or a predicate.
781 See the manual for details."
782 :group 'gnus-article-treat
783 :type gnus-article-treat-head-custom)
785 (defcustom gnus-treat-hide-boring-headers nil
786 "Hide boring headers.
787 Valid values are nil, t, `head', `last', an integer or a predicate.
788 See the manual for details."
789 :group 'gnus-article-treat
790 :type gnus-article-treat-head-custom)
792 (defcustom gnus-treat-hide-signature nil
794 Valid values are nil, t, `head', `last', an integer or a predicate.
795 See the manual for details."
796 :group 'gnus-article-treat
797 :type gnus-article-treat-custom)
799 (defcustom gnus-treat-fill-article nil
801 Valid values are nil, t, `head', `last', an integer or a predicate.
802 See the manual for details."
803 :group 'gnus-article-treat
804 :type gnus-article-treat-custom)
806 (defcustom gnus-treat-hide-citation nil
808 Valid values are nil, t, `head', `last', an integer or a predicate.
809 See the manual for details."
810 :group 'gnus-article-treat
811 :type gnus-article-treat-custom)
813 (defcustom gnus-treat-hide-citation-maybe nil
815 Valid values are nil, t, `head', `last', an integer or a predicate.
816 See the manual for details."
817 :group 'gnus-article-treat
818 :type gnus-article-treat-custom)
820 (defcustom gnus-treat-strip-list-identifiers 'head
821 "Strip list identifiers from `gnus-list-identifiers`.
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)
827 (defcustom gnus-treat-strip-pgp t
828 "Strip PGP signatures.
829 Valid values are nil, t, `head', `last', an integer or a predicate.
830 See the manual for details."
831 :group 'gnus-article-treat
832 :type gnus-article-treat-custom)
834 (defcustom gnus-treat-strip-pem nil
835 "Strip PEM signatures.
836 Valid values are nil, t, `head', `last', an integer or a predicate.
837 See the manual for details."
838 :group 'gnus-article-treat
839 :type gnus-article-treat-custom)
841 (defcustom gnus-treat-strip-banner t
842 "Strip banners from articles.
843 The banner to be stripped is specified in the `banner' group parameter.
844 Valid values are nil, t, `head', `last', an integer or a predicate.
845 See the manual for details."
846 :group 'gnus-article-treat
847 :type gnus-article-treat-custom)
849 (defcustom gnus-treat-highlight-headers 'head
850 "Highlight the headers.
851 Valid values are nil, t, `head', `last', an integer or a predicate.
852 See the manual for details."
853 :group 'gnus-article-treat
854 :type gnus-article-treat-head-custom)
855 (put 'gnus-treat-highlight-headers 'highlight t)
857 (defcustom gnus-treat-highlight-citation t
858 "Highlight cited text.
859 Valid values are nil, t, `head', `last', an integer or a predicate.
860 See the manual for details."
861 :group 'gnus-article-treat
862 :type gnus-article-treat-custom)
863 (put 'gnus-treat-highlight-citation 'highlight t)
865 (defcustom gnus-treat-date-ut nil
866 "Display the Date in UT (GMT).
867 Valid values are nil, t, `head', `last', an integer or a predicate.
868 See the manual for details."
869 :group 'gnus-article-treat
870 :type gnus-article-treat-head-custom)
872 (defcustom gnus-treat-date-local nil
873 "Display the Date in the local timezone.
874 Valid values are nil, t, `head', `last', an integer or a predicate.
875 See the manual for details."
876 :group 'gnus-article-treat
877 :type gnus-article-treat-head-custom)
879 (defcustom gnus-treat-date-lapsed nil
880 "Display the Date header in a way that says how much time has elapsed.
881 Valid values are nil, t, `head', `last', an integer or a predicate.
882 See the manual for details."
883 :group 'gnus-article-treat
884 :type gnus-article-treat-head-custom)
886 (defcustom gnus-treat-date-original nil
887 "Display the date in the original timezone.
888 Valid values are nil, t, `head', `last', an integer or a predicate.
889 See the manual for details."
890 :group 'gnus-article-treat
891 :type gnus-article-treat-head-custom)
893 (defcustom gnus-treat-date-iso8601 nil
894 "Display the date in the ISO8601 format.
895 Valid values are nil, t, `head', `last', an integer or a predicate.
896 See the manual for details."
897 :group 'gnus-article-treat
898 :type gnus-article-treat-head-custom)
900 (defcustom gnus-treat-date-user-defined nil
901 "Display the date in a user-defined format.
902 The format is defined by the `gnus-article-time-format' variable.
903 Valid values are nil, t, `head', `last', an integer or a predicate.
904 See the manual for details."
905 :group 'gnus-article-treat
906 :type gnus-article-treat-head-custom)
908 (defcustom gnus-treat-strip-headers-in-body t
909 "Strip the X-No-Archive header line from the beginning of the body.
910 Valid values are nil, t, `head', `last', an integer or a predicate.
911 See the manual for details."
912 :group 'gnus-article-treat
913 :type gnus-article-treat-custom)
915 (defcustom gnus-treat-strip-trailing-blank-lines nil
916 "Strip trailing blank lines.
917 Valid values are nil, t, `head', `last', an integer or a predicate.
918 See the manual for details."
919 :group 'gnus-article-treat
920 :type gnus-article-treat-custom)
922 (defcustom gnus-treat-strip-leading-blank-lines nil
923 "Strip leading blank lines.
924 Valid values are nil, t, `head', `last', an integer or a predicate.
925 See the manual for details."
926 :group 'gnus-article-treat
927 :type gnus-article-treat-custom)
929 (defcustom gnus-treat-strip-multiple-blank-lines nil
930 "Strip multiple blank lines.
931 Valid values are nil, t, `head', `last', an integer or a predicate.
932 See the manual for details."
933 :group 'gnus-article-treat
934 :type gnus-article-treat-custom)
936 (defcustom gnus-treat-overstrike t
937 "Treat overstrike highlighting.
938 Valid values are nil, t, `head', `last', an integer or a predicate.
939 See the manual for details."
940 :group 'gnus-article-treat
941 :type gnus-article-treat-custom)
942 (put 'gnus-treat-overstrike 'highlight t)
944 (defcustom gnus-treat-display-xface
945 (and (or (and (fboundp 'image-type-available-p)
946 (image-type-available-p 'xbm)
947 (string-match "^0x" (shell-command-to-string "uncompface")))
948 (and (featurep 'xemacs) (featurep 'xface))
949 (eq 'x-face-mule-gnus-article-display-x-face
950 gnus-article-x-face-command))
952 "Display X-Face headers.
953 Valid values are nil, t, `head', `last', an integer or a predicate.
954 See the manual for details."
955 :group 'gnus-article-treat
956 :type gnus-article-treat-head-custom)
957 (put 'gnus-treat-display-xface 'highlight t)
959 (defcustom gnus-treat-display-smileys
960 (if (or (and (featurep 'xemacs)
962 (and (fboundp 'image-type-available-p)
963 (image-type-available-p 'pbm))
964 (and (not (featurep 'xemacs))
966 (module-installed-p 'gnus-bitmap)))
970 Valid values are nil, t, `head', `last', an integer or a predicate.
971 See the manual for details."
972 :group 'gnus-article-treat
973 :type gnus-article-treat-custom)
974 (put 'gnus-treat-display-smileys 'highlight t)
976 (defcustom gnus-treat-display-picons (if (featurep 'xemacs) 'head nil)
978 Valid values are nil, t, `head', `last', an integer or a predicate.
979 See the manual for details."
980 :group 'gnus-article-treat
981 :type gnus-article-treat-head-custom)
982 (put 'gnus-treat-display-picons 'highlight t)
984 (defcustom gnus-treat-capitalize-sentences nil
985 "Capitalize sentence-starting words.
986 Valid values are nil, t, `head', `last', an integer or a predicate.
987 See the manual for details."
988 :group 'gnus-article-treat
989 :type gnus-article-treat-custom)
991 (defcustom gnus-treat-fill-long-lines nil
993 Valid values are nil, t, `head', `last', an integer or a predicate.
994 See the manual for details."
995 :group 'gnus-article-treat
996 :type gnus-article-treat-custom)
998 (defcustom gnus-treat-play-sounds nil
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See the manual for details."
1002 :group 'gnus-article-treat
1003 :type gnus-article-treat-custom)
1005 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1006 "Decode an article as `default-mime-charset'. For instance, if you want to
1007 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1008 you could set this variable to something like: nil for don't decode, t for
1009 decode the body, '(or header t) for the whole article, etc."
1010 :group 'gnus-article-treat
1011 :type '(radio (const :tag "Off" nil)
1012 (const :tag "Decode body" t)
1013 (const :tag "Decode all" (or head t))))
1015 (defcustom gnus-treat-translate nil
1016 "Translate articles from one language to another.
1017 Valid values are nil, t, `head', `last', an integer or a predicate.
1018 See the manual for details."
1019 :group 'gnus-article-treat
1020 :type gnus-article-treat-custom)
1022 (defcustom gnus-treat-x-pgp-sig nil
1024 To automatically treat X-PGP-Sig, set it to head.
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 :group 'mime-security
1029 :type gnus-article-treat-custom)
1031 (defvar gnus-article-encrypt-protocol-alist
1032 '(("PGP" . mml2015-self-encrypt)))
1034 ;; Set to nil if more than one protocol added to
1035 ;; gnus-article-encrypt-protocol-alist.
1036 (defcustom gnus-article-encrypt-protocol "PGP"
1037 "The protocol used for encrypt articles.
1038 It is a string, such as \"PGP\". If nil, ask user."
1040 :group 'mime-security)
1042 ;;; Internal variables
1044 (defvar article-goto-body-goes-to-point-min-p nil)
1045 (defvar gnus-article-wash-types nil)
1046 (defvar gnus-article-emphasis-alist nil)
1048 (defvar gnus-article-mime-handle-alist-1 nil)
1049 (defvar gnus-treatment-function-alist
1050 '((gnus-treat-decode-article-as-default-mime-charset
1051 gnus-article-decode-article-as-default-mime-charset)
1052 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1053 (gnus-treat-strip-banner gnus-article-strip-banner)
1054 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1055 (gnus-treat-buttonize gnus-article-add-buttons)
1056 (gnus-treat-fill-article gnus-article-fill-cited-article)
1057 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1058 (gnus-treat-strip-cr gnus-article-remove-cr)
1059 (gnus-treat-display-xface gnus-article-display-x-face)
1060 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1061 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1062 (gnus-treat-hide-signature gnus-article-hide-signature)
1063 (gnus-treat-hide-citation gnus-article-hide-citation)
1064 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1065 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1066 (gnus-treat-strip-pgp gnus-article-hide-pgp)
1067 (gnus-treat-strip-pem gnus-article-hide-pem)
1068 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1069 (gnus-treat-emphasize gnus-article-emphasize)
1070 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1071 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1072 (gnus-treat-date-ut gnus-article-date-ut)
1073 (gnus-treat-date-local gnus-article-date-local)
1074 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1075 (gnus-treat-date-original gnus-article-date-original)
1076 (gnus-treat-date-user-defined gnus-article-date-user)
1077 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1078 (gnus-treat-strip-trailing-blank-lines
1079 gnus-article-remove-trailing-blank-lines)
1080 (gnus-treat-strip-leading-blank-lines
1081 gnus-article-strip-leading-blank-lines)
1082 (gnus-treat-strip-multiple-blank-lines
1083 gnus-article-strip-multiple-blank-lines)
1084 (gnus-treat-overstrike gnus-article-treat-overstrike)
1085 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1086 (gnus-treat-display-smileys gnus-article-smiley-display)
1087 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1088 (gnus-treat-display-picons gnus-article-display-picons)
1089 (gnus-treat-play-sounds gnus-earcon-display)))
1091 (defvar gnus-article-mime-handle-alist nil)
1092 (defvar article-lapsed-timer nil)
1093 (defvar gnus-article-current-summary nil)
1095 (defvar gnus-article-mode-syntax-table
1096 (let ((table (copy-syntax-table text-mode-syntax-table)))
1097 ;; This causes the citation match run O(2^n).
1098 ;; (modify-syntax-entry ?- "w" table)
1099 (modify-syntax-entry ?> ")" table)
1100 (modify-syntax-entry ?< "(" table)
1102 "Syntax table used in article mode buffers.
1103 Initialized from `text-mode-syntax-table.")
1105 (defvar gnus-save-article-buffer nil)
1107 (defvar gnus-article-mode-line-format-alist
1108 (nconc '((?w (gnus-article-wash-status) ?s)
1109 (?m (gnus-article-mime-part-status) ?s))
1110 gnus-summary-mode-line-format-alist))
1112 (defvar gnus-number-of-articles-to-be-saved nil)
1114 (defvar gnus-inhibit-hiding nil)
1116 (defsubst gnus-article-hide-text (b e props)
1117 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1118 (gnus-add-text-properties-when 'article-type nil b e props)
1119 (when (memq 'intangible props)
1121 (max (1- b) (point-min))
1122 b 'intangible (cddr (memq 'intangible props)))))
1124 (defsubst gnus-article-unhide-text (b e)
1125 "Remove hidden text properties from region between B and E."
1126 (remove-text-properties b e gnus-hidden-properties)
1127 (when (memq 'intangible gnus-hidden-properties)
1128 (put-text-property (max (1- b) (point-min))
1129 b 'intangible nil)))
1131 (defun gnus-article-hide-text-type (b e type)
1132 "Hide text of TYPE between B and E."
1133 (push type gnus-article-wash-types)
1134 (gnus-article-hide-text
1135 b e (cons 'article-type (cons type gnus-hidden-properties))))
1137 (defun gnus-article-unhide-text-type (b e type)
1138 "Unhide text of TYPE between B and E."
1139 (setq gnus-article-wash-types
1140 (delq type gnus-article-wash-types))
1141 (remove-text-properties
1142 b e (cons 'article-type (cons type gnus-hidden-properties)))
1143 (when (memq 'intangible gnus-hidden-properties)
1144 (put-text-property (max (1- b) (point-min))
1145 b 'intangible nil)))
1147 (defun gnus-article-hide-text-of-type (type)
1148 "Hide text of TYPE in the current buffer."
1150 (let ((b (point-min))
1152 (while (setq b (text-property-any b e 'article-type type))
1153 (add-text-properties b (incf b) gnus-hidden-properties)))))
1155 (defun gnus-article-delete-text-of-type (type)
1156 "Delete text of TYPE in the current buffer."
1158 (let ((b (point-min)))
1159 (while (setq b (text-property-any b (point-max) 'article-type type))
1161 b (or (text-property-not-all b (point-max) 'article-type type)
1164 (defun gnus-article-delete-invisible-text ()
1165 "Delete all invisible text in the current buffer."
1167 (let ((b (point-min)))
1168 (while (setq b (text-property-any b (point-max) 'invisible t))
1170 b (or (text-property-not-all b (point-max) 'invisible t)
1173 (defun gnus-article-text-type-exists-p (type)
1174 "Say whether any text of type TYPE exists in the buffer."
1175 (text-property-any (point-min) (point-max) 'article-type type))
1177 (defsubst gnus-article-header-rank ()
1178 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1179 (let ((list gnus-sorted-header-list)
1182 (when (looking-at (car list))
1184 (setq list (cdr list))
1188 (defun article-hide-headers (&optional arg delete)
1189 "Hide unwanted headers and possibly sort them as well."
1190 (interactive (gnus-article-hidden-arg))
1191 ;; Lars said that this function might be inhibited.
1192 (if (gnus-article-check-hidden-text 'headers arg)
1194 ;; Show boring headers as well.
1195 (gnus-article-show-hidden-text 'boring-headers)
1196 (when (eq 1 (point-min))
1197 (set-window-start (get-buffer-window (current-buffer)) 1)))
1198 (unless gnus-inhibit-hiding
1201 (let ((buffer-read-only nil)
1202 (inhibit-read-only t)
1203 (case-fold-search t)
1204 (max (1+ (length gnus-sorted-header-list)))
1205 (ignored (when (not gnus-visible-headers)
1206 (cond ((stringp gnus-ignored-headers)
1207 gnus-ignored-headers)
1208 ((listp gnus-ignored-headers)
1209 (mapconcat 'identity gnus-ignored-headers
1212 (cond ((stringp gnus-visible-headers)
1213 gnus-visible-headers)
1214 ((and gnus-visible-headers
1215 (listp gnus-visible-headers))
1216 (mapconcat 'identity gnus-visible-headers "\\|"))))
1217 (inhibit-point-motion-hooks t)
1219 ;; First we narrow to just the headers.
1220 (article-narrow-to-head)
1221 ;; Hide any "From " lines at the beginning of (mail) articles.
1222 (while (looking-at "From ")
1226 (delete-region (point-min) (point))
1227 (gnus-article-hide-text (point-min) (point)
1228 (nconc (list 'article-type 'headers)
1229 gnus-hidden-properties))))
1230 ;; Then treat the rest of the header lines.
1231 ;; Then we use the two regular expressions
1232 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1233 ;; select which header lines is to remain visible in the
1235 (while (re-search-forward "^[^ \t]*:" nil t)
1237 ;; Mark the rank of the header.
1239 (point) (1+ (point)) 'message-rank
1240 (if (or (and visible (looking-at visible))
1242 (not (looking-at ignored))))
1243 (gnus-article-header-rank)
1246 (message-sort-headers-1)
1247 (when (setq beg (text-property-any
1248 (point-min) (point-max) 'message-rank (+ 2 max)))
1249 ;; We delete or make invisible the unwanted headers.
1250 (push 'headers gnus-article-wash-types)
1253 (add-text-properties
1254 (point-min) (+ 5 (point-min))
1255 '(article-type headers dummy-invisible t))
1256 (delete-region beg (point-max)))
1257 (gnus-article-hide-text-type beg (point-max) 'headers))))))))
1260 (defun article-hide-boring-headers (&optional arg)
1261 "Toggle hiding of headers that aren't very interesting.
1262 If given a negative prefix, always show; if given a positive prefix,
1264 (interactive (gnus-article-hidden-arg))
1265 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1266 (not gnus-show-all-headers))
1269 (let ((buffer-read-only nil)
1270 (list gnus-boring-article-headers)
1271 (inhibit-point-motion-hooks t)
1273 (article-narrow-to-head)
1275 (setq elem (pop list))
1276 (goto-char (point-min))
1278 ;; Hide empty headers.
1280 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1282 (gnus-article-hide-text-type
1283 (progn (beginning-of-line) (point))
1286 (if (re-search-forward "^[^ \t]" nil t)
1290 ;; Hide boring Newsgroups header.
1291 ((eq elem 'newsgroups)
1292 (when (equal (gnus-fetch-field "newsgroups")
1293 (gnus-group-real-name
1294 (if (boundp 'gnus-newsgroup-name)
1297 (gnus-article-hide-header "newsgroups")))
1298 ((eq elem 'followup-to)
1299 (when (equal (message-fetch-field "followup-to")
1300 (message-fetch-field "newsgroups"))
1301 (gnus-article-hide-header "followup-to")))
1302 ((eq elem 'reply-to)
1303 (let ((from (message-fetch-field "from"))
1304 (reply-to (message-fetch-field "reply-to")))
1309 (nth 1 (funcall gnus-extract-address-components from))
1310 (nth 1 (funcall gnus-extract-address-components reply-to)))))
1311 (gnus-article-hide-header "reply-to"))))
1313 (let ((date (message-fetch-field "date")))
1315 (< (days-between (current-time-string) date)
1317 (gnus-article-hide-header "date"))))
1319 (let ((to (message-fetch-field "to"))
1320 (cc (message-fetch-field "cc")))
1321 (when (> (length to) 1024)
1322 (gnus-article-hide-header "to"))
1323 (when (> (length cc) 1024)
1324 (gnus-article-hide-header "cc"))))
1328 (goto-char (point-min))
1329 (while (re-search-forward "^to:" nil t)
1330 (setq to-count (1+ to-count)))
1331 (when (> to-count 1)
1332 (while (> to-count 0)
1333 (goto-char (point-min))
1335 (re-search-forward "^to:" nil nil to-count)
1337 (narrow-to-region (point) (point-max))
1338 (gnus-article-hide-header "to"))
1339 (setq to-count (1- to-count))))
1340 (goto-char (point-min))
1341 (while (re-search-forward "^cc:" nil t)
1342 (setq cc-count (1+ cc-count)))
1343 (when (> cc-count 1)
1344 (while (> cc-count 0)
1345 (goto-char (point-min))
1347 (re-search-forward "^cc:" nil nil cc-count)
1349 (narrow-to-region (point) (point-max))
1350 (gnus-article-hide-header "cc"))
1351 (setq cc-count (1- cc-count)))))))))))))
1353 (defun gnus-article-hide-header (header)
1355 (goto-char (point-min))
1356 (when (re-search-forward (concat "^" header ":") nil t)
1357 (gnus-article-hide-text-type
1358 (progn (beginning-of-line) (point))
1361 (if (re-search-forward "^[^ \t]" nil t)
1366 (defun article-toggle-headers (&optional arg)
1367 "Toggle hiding of headers. If given a negative prefix, always show;
1368 if given a positive prefix, always hide."
1369 (interactive (gnus-article-hidden-arg))
1370 (let ((force (when (numberp arg)
1371 (cond ((> arg 0) 'always-hide)
1372 ((< arg 0) 'always-show))))
1373 (window (get-buffer-window gnus-article-buffer))
1374 (header-end (point-min))
1375 header-start field-end field-start
1376 (inhibit-point-motion-hooks t)
1377 (inhibit-read-only t)
1381 (while (and (setq header-start
1382 (text-property-any header-end (point-max)
1383 'article-treated-header t))
1385 (text-property-not-all header-start (point-max)
1386 'article-treated-header t)))
1387 (setq field-end header-start)
1389 (;; Hide exposed invisible fields.
1390 (and (not (eq 'always-show force))
1392 (text-property-any field-end header-end
1393 'exposed-invisible-field t)))
1394 (while (and field-start
1395 (setq field-end (text-property-not-all
1396 field-start header-end
1397 'exposed-invisible-field t)))
1398 (add-text-properties field-start field-end gnus-hidden-properties)
1399 (setq field-start (text-property-any field-end header-end
1400 'exposed-invisible-field t)))
1401 (put-text-property header-start header-end
1402 'exposed-invisible-field nil))
1403 (;; Expose invisible fields.
1404 (and (not (eq 'always-hide force))
1406 (text-property-any field-end header-end 'invisible t)))
1407 (while (and field-start
1408 (setq field-end (text-property-not-all
1409 field-start header-end
1411 ;; If the invisible text is not terminated with newline, we
1412 ;; won't expose it. Because it may be created by x-face-mule.
1413 ;; BTW, XEmacs sometimes fail in putting a invisible text
1414 ;; property with `gnus-article-hide-text' (really?). In that
1415 ;; case, the invisible text might be started from the middle of
1416 ;; a line so we will expose the sort of thing.
1417 (when (or (not (or (eq header-start field-start)
1418 (eq ?\n (char-before field-start))))
1419 (eq ?\n (char-before field-end)))
1420 (remove-text-properties field-start field-end
1421 gnus-hidden-properties)
1422 (put-text-property field-start field-end
1423 'exposed-invisible-field t))
1424 (setq field-start (text-property-any field-end header-end
1427 (not (eq 'always-show force))
1428 (narrow-to-region header-start header-end)
1429 (article-hide-headers)
1430 ;; Re-display X-Face image under XEmacs.
1431 (when (and (featurep 'xemacs)
1432 (gnus-functionp gnus-article-x-face-command))
1433 (let ((func (cadr (assq 'gnus-treat-display-xface
1434 gnus-treatment-function-alist)))
1436 (when (and (not gnus-inhibit-treatment)
1438 (gnus-treat-predicate gnus-treat-display-xface))
1440 (put-text-property header-start header-end 'read-only nil))))
1443 (goto-char (point-min))
1445 (set-window-start window (point-min))))))
1447 (defvar gnus-article-normalized-header-length 40
1448 "Length of normalized headers.")
1450 (defun article-normalize-headers ()
1451 "Make all header lines 40 characters long."
1453 (let ((buffer-read-only nil)
1457 (article-narrow-to-head)
1460 ((< (setq column (- (gnus-point-at-eol) (point)))
1461 gnus-article-normalized-header-length)
1463 (insert (make-string
1464 (- gnus-article-normalized-header-length column)
1466 ((> column gnus-article-normalized-header-length)
1467 (gnus-put-text-property
1469 (forward-char gnus-article-normalized-header-length)
1476 (forward-line 1))))))
1478 (defun article-treat-dumbquotes ()
1479 "Translate M******** sm*rtq**t*s into proper text.
1480 Note that this function guesses whether a character is a sm*rtq**t* or
1481 not, so it should only be used interactively."
1483 (article-translate-strings gnus-article-dumbquotes-map))
1485 (defun article-translate-characters (from to)
1486 "Translate all characters in the body of the article according to FROM and TO.
1487 FROM is a string of characters to translate from; to is a string of
1488 characters to translate to."
1490 (when (article-goto-body)
1491 (let ((buffer-read-only nil)
1492 (x (make-string 225 ?x))
1494 (while (< (incf i) (length x))
1497 (while (< i (length from))
1498 (aset x (aref from i) (aref to i))
1500 (translate-region (point) (point-max) x)))))
1502 (defun article-translate-strings (map)
1503 "Translate all string in the body of the article according to MAP.
1504 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1506 (when (article-goto-body)
1507 (let ((buffer-read-only nil)
1509 (while (setq elem (pop map))
1511 (while (search-forward (car elem) nil t)
1512 (replace-match (cadr elem)))))))))
1514 (defun article-treat-overstrike ()
1515 "Translate overstrikes into bold text."
1518 (when (article-goto-body)
1519 (let ((buffer-read-only nil))
1520 (while (search-forward "\b" nil t)
1521 (let ((next (char-after))
1525 previous (char-after))
1529 ;; We do the boldification/underlining by hiding the
1530 ;; overstrikes and putting the proper text property
1534 (gnus-article-hide-text-type start (point) 'overstrike)
1535 (put-text-property (point) end 'face 'bold))
1537 (gnus-article-hide-text-type
1538 (1- (point)) (1+ (point)) 'overstrike)
1540 start (1- (point)) 'face 'underline))
1542 (gnus-article-hide-text-type start (point) 'overstrike)
1544 (point) end 'face 'underline)))))))))
1546 (defun article-fill-long-lines ()
1547 "Fill lines that are wider than the window width."
1550 (let ((buffer-read-only nil)
1551 (width (window-width (get-buffer-window (current-buffer)))))
1554 (let ((adaptive-fill-mode nil))
1557 (when (>= (current-column) (min fill-column width))
1558 (narrow-to-region (point) (gnus-point-at-bol))
1559 (fill-paragraph nil)
1560 (goto-char (point-max))
1562 (forward-line 1)))))))
1564 (defun article-capitalize-sentences ()
1565 "Capitalize the first word in each sentence."
1568 (let ((buffer-read-only nil)
1569 (paragraph-start "^[\n\^L]"))
1573 (forward-sentence)))))
1575 (defun article-remove-cr ()
1576 "Remove trailing CRs and then translate remaining CRs into LFs."
1579 (let ((buffer-read-only nil))
1580 (goto-char (point-min))
1581 (while (re-search-forward "\r+$" nil t)
1582 (replace-match "" t t))
1583 (goto-char (point-min))
1584 (while (search-forward "\r" nil t)
1585 (replace-match "\n" t t)))))
1587 (defun article-remove-trailing-blank-lines ()
1588 "Remove all trailing blank lines from the article."
1591 (let ((buffer-read-only nil))
1592 (goto-char (point-max))
1596 (while (and (not (bobp))
1597 (looking-at "^[ \t]*$")
1598 (not (gnus-annotation-in-region-p
1599 (point) (gnus-point-at-eol))))
1604 (defun article-display-x-face (&optional force)
1605 "Look for an X-Face header and display it if present."
1606 (interactive (list 'force))
1608 ;; Delete the old process, if any.
1609 (when (process-status "article-x-face")
1610 (delete-process "article-x-face"))
1611 (let ((inhibit-point-motion-hooks t)
1612 (case-fold-search t)
1615 (article-narrow-to-head)
1616 (goto-char (point-min))
1617 (setq from (message-fetch-field "from"))
1618 (goto-char (point-min))
1619 (while (and gnus-article-x-face-command
1622 ;; Check whether this face is censored.
1623 (not gnus-article-x-face-too-ugly)
1624 (and gnus-article-x-face-too-ugly from
1625 (not (string-match gnus-article-x-face-too-ugly
1627 ;; Has to be present.
1628 (re-search-forward "^X-Face:[ \t]*" nil t))
1629 ;; This used to try to do multiple faces (`while' instead of
1630 ;; `when' above), but (a) sending multiple EOFs to xv doesn't
1631 ;; work (b) it can crash some versions of Emacs (c) are
1632 ;; multiple faces really something to encourage?
1633 (when (stringp gnus-article-x-face-command)
1635 ;; We now have the area of the buffer where the X-Face is stored.
1638 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
1639 ;; We display the face.
1640 (if (symbolp gnus-article-x-face-command)
1641 ;; The command is a lisp function, so we call it.
1642 (if (gnus-functionp gnus-article-x-face-command)
1643 (funcall gnus-article-x-face-command beg end)
1644 (error "%s is not a function" gnus-article-x-face-command))
1645 ;; The command is a string, so we interpret the command
1646 ;; as a, well, command, and fork it off.
1647 (let ((process-connection-type nil))
1648 (process-kill-without-query
1650 "article-x-face" nil shell-file-name shell-command-switch
1651 gnus-article-x-face-command))
1652 (process-send-region "article-x-face" beg end)
1653 (process-send-eof "article-x-face"))))))))))
1655 (defun article-decode-mime-words ()
1656 "Decode all MIME-encoded words in the article."
1659 (set-buffer gnus-article-buffer)
1660 (let ((inhibit-point-motion-hooks t)
1662 (mail-parse-charset gnus-newsgroup-charset)
1663 (mail-parse-ignored-charsets
1664 (save-excursion (set-buffer gnus-summary-buffer)
1665 gnus-newsgroup-ignored-charsets)))
1666 (mail-decode-encoded-word-region (point-min) (point-max)))))
1668 (defun article-decode-charset (&optional prompt)
1669 "Decode charset-encoded text in the article.
1670 If PROMPT (the prefix), prompt for a coding system to use."
1672 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
1674 (mail-parse-charset gnus-newsgroup-charset)
1675 (mail-parse-ignored-charsets
1676 (save-excursion (condition-case nil
1677 (set-buffer gnus-summary-buffer)
1679 gnus-newsgroup-ignored-charsets))
1680 ct cte ctl charset format)
1683 (article-narrow-to-head)
1684 (setq ct (message-fetch-field "Content-Type" t)
1685 cte (message-fetch-field "Content-Transfer-Encoding" t)
1686 ctl (and ct (ignore-errors
1687 (mail-header-parse-content-type ct)))
1690 (mm-read-coding-system "Charset to decode: "))
1692 (mail-content-type-get ctl 'charset)))
1693 format (and ctl (mail-content-type-get ctl 'format)))
1695 (setq cte (mail-header-strip cte)))
1696 (if (and ctl (not (string-match "/" (car ctl))))
1698 (goto-char (point-max)))
1701 (narrow-to-region (point) (point-max))
1702 (when (and (eq mail-parse-charset 'gnus-decoded)
1703 (eq (mm-body-7-or-8) '8bit))
1704 ;; The text code could have been decoded.
1705 (setq charset mail-parse-charset))
1706 (when (and (or (not ctl)
1707 (equal (car ctl) "text/plain"))
1708 (not format)) ;; article with format will decode later.
1710 charset (and cte (intern (downcase
1711 (gnus-strip-whitespace cte))))
1714 (defun article-decode-encoded-words ()
1715 "Remove encoded-word encoding from headers."
1716 (let (buffer-read-only)
1717 (let ((charset (save-excursion
1718 (set-buffer gnus-summary-buffer)
1719 default-mime-charset)))
1720 (mime-decode-header-in-buffer charset)
1723 (defun article-de-quoted-unreadable (&optional force)
1724 "Translate a quoted-printable-encoded article.
1725 If FORCE, decode the article whether it is marked as quoted-printable
1727 (interactive (list 'force))
1729 (let ((buffer-read-only nil) type charset)
1730 (if (gnus-buffer-live-p gnus-original-article-buffer)
1731 (with-current-buffer gnus-original-article-buffer
1733 (gnus-fetch-field "content-transfer-encoding"))
1734 (let* ((ct (gnus-fetch-field "content-type"))
1737 (mail-header-parse-content-type ct)))))
1738 (setq charset (and ctl
1739 (mail-content-type-get ctl 'charset)))
1740 (if (stringp charset)
1741 (setq charset (intern (downcase charset)))))))
1743 (setq charset gnus-newsgroup-charset))
1745 (and type (let ((case-fold-search t))
1746 (string-match "quoted-printable" type))))
1748 (quoted-printable-decode-region
1749 (point) (point-max) (mm-charset-to-coding-system charset))))))
1751 (defun article-de-base64-unreadable (&optional force)
1752 "Translate a base64 article.
1753 If FORCE, decode the article whether it is marked as base64 not."
1754 (interactive (list 'force))
1756 (let ((buffer-read-only nil) type charset)
1757 (if (gnus-buffer-live-p gnus-original-article-buffer)
1758 (with-current-buffer gnus-original-article-buffer
1760 (gnus-fetch-field "content-transfer-encoding"))
1761 (let* ((ct (gnus-fetch-field "content-type"))
1764 (mail-header-parse-content-type ct)))))
1765 (setq charset (and ctl
1766 (mail-content-type-get ctl 'charset)))
1767 (if (stringp charset)
1768 (setq charset (intern (downcase charset)))))))
1770 (setq charset gnus-newsgroup-charset))
1772 (and type (let ((case-fold-search t))
1773 (string-match "base64" type))))
1776 (narrow-to-region (point) (point-max))
1777 (base64-decode-region (point-min) (point-max))
1778 (mm-decode-coding-region
1779 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
1784 (defun article-decode-HZ ()
1785 "Translate a HZ-encoded article."
1789 (let ((buffer-read-only nil))
1790 (rfc1843-decode-region (point-min) (point-max)))))
1792 (defun article-wash-html ()
1793 "Format an html article."
1796 (let ((buffer-read-only nil)
1798 (if (gnus-buffer-live-p gnus-original-article-buffer)
1799 (with-current-buffer gnus-original-article-buffer
1800 (let* ((ct (gnus-fetch-field "content-type"))
1803 (mail-header-parse-content-type ct)))))
1804 (setq charset (and ctl
1805 (mail-content-type-get ctl 'charset)))
1806 (if (stringp charset)
1807 (setq charset (intern (downcase charset)))))))
1809 (setq charset gnus-newsgroup-charset))
1811 (save-window-excursion
1813 (narrow-to-region (point) (point-max))
1815 (let ((w3-strict-width (window-width))
1816 (url-standalone-mode t))
1818 (w3-region (point-min) (point-max))
1821 (defun article-hide-list-identifiers ()
1822 "Remove list identifies from the Subject header.
1823 The `gnus-list-identifiers' variable specifies what to do."
1827 (let ((inhibit-point-motion-hooks t)
1829 (article-narrow-to-head)
1830 (let ((regexp (if (stringp gnus-list-identifiers) gnus-list-identifiers
1831 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1833 (goto-char (point-min))
1834 (when (re-search-forward
1835 (concat "^Subject: +\\(\\(\\(Re: +\\)?\\(" regexp
1836 " *\\)\\)+\\(Re: +\\)?\\)")
1838 (let ((s (or (match-string 3) (match-string 5))))
1839 (delete-region (match-beginning 1) (match-end 1))
1841 (goto-char (match-beginning 1))
1844 (defun article-hide-pgp ()
1845 "Remove any PGP headers and signatures in the current article."
1849 (let ((inhibit-point-motion-hooks t)
1850 buffer-read-only beg end)
1852 ;; Hide the "header".
1853 (when (re-search-forward "^-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
1854 (push 'pgp gnus-article-wash-types)
1855 (delete-region (match-beginning 0) (match-end 0))
1856 ;; Remove armor headers (rfc2440 6.2)
1857 (delete-region (point) (or (re-search-forward "^[ \t]*\n" nil t)
1860 ;; Hide the actual signature.
1861 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
1862 (setq end (1+ (match-beginning 0)))
1865 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
1867 ;; Perhaps we shouldn't hide to the end of the buffer
1868 ;; if there is no end to the signature?
1870 ;; Hide "- " PGP quotation markers.
1872 (narrow-to-region beg end)
1873 (goto-char (point-min))
1874 (while (re-search-forward "^- " nil t)
1876 (match-beginning 0) (match-end 0)))
1878 (gnus-run-hooks 'gnus-article-hide-pgp-hook))))))
1880 (defun article-hide-pem (&optional arg)
1881 "Toggle hiding of any PEM headers and signatures in the current article.
1882 If given a negative prefix, always show; if given a positive prefix,
1884 (interactive (gnus-article-hidden-arg))
1885 (unless (gnus-article-check-hidden-text 'pem arg)
1887 (let (buffer-read-only end)
1888 (goto-char (point-min))
1889 ;; Hide the horrendously ugly "header".
1890 (when (and (search-forward
1891 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
1893 (setq end (1+ (match-beginning 0))))
1894 (push 'pem gnus-article-wash-types)
1895 (gnus-article-hide-text-type
1897 (if (search-forward "\n\n" nil t)
1901 ;; Hide the trailer as well
1902 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
1904 (gnus-article-hide-text-type
1905 (match-beginning 0) (match-end 0) 'pem)))))))
1907 (defun article-strip-banner ()
1908 "Strip the banner specified by the `banner' group parameter."
1912 (let ((inhibit-point-motion-hooks t)
1913 (banner (gnus-group-find-parameter gnus-newsgroup-name 'banner))
1914 (gnus-signature-limit nil)
1915 buffer-read-only beg end)
1919 ((eq banner 'signature)
1920 (when (gnus-article-narrow-to-signature)
1923 (delete-region (point) (point-max))))
1925 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
1926 (while (re-search-forward banner nil t)
1927 (delete-region (match-beginning 0) (match-end 0)))))
1929 (while (re-search-forward banner nil t)
1930 (delete-region (match-beginning 0) (match-end 0))))))))))
1932 (defun article-babel ()
1933 "Translate article using an online translation service."
1937 (set-buffer gnus-article-buffer)
1938 (when (article-goto-body)
1939 (let* ((buffer-read-only nil)
1942 (orig (buffer-substring start end))
1943 (trans (babel-as-string orig)))
1945 (narrow-to-region start end)
1946 (delete-region start end)
1949 (defun article-hide-signature (&optional arg)
1950 "Hide the signature in the current article.
1951 If given a negative prefix, always show; if given a positive prefix,
1953 (interactive (gnus-article-hidden-arg))
1959 (article-goto-body))
1960 (goto-char (point-min)))
1961 (unless (gnus-article-check-hidden-text 'signature arg)
1962 (let ((buffer-read-only nil)
1964 (while (setq button (text-property-any button (point-max)
1966 'gnus-signature-toggle))
1967 (setq button (text-property-not-all button (point-max)
1969 'gnus-signature-toggle))
1970 (when (and button (not (eobp)))
1971 (gnus-article-hide-text-type
1973 (next-single-property-change (1+ button) 'mime-view-entity
1977 (defun article-strip-headers-in-body ()
1978 "Strip offensive headers from bodies."
1982 (let ((case-fold-search t))
1983 (when (looking-at "x-no-archive:")
1984 (gnus-delete-line)))))
1986 (defun article-strip-leading-blank-lines ()
1987 "Remove all blank lines from the beginning of the article."
1990 (let ((inhibit-point-motion-hooks t)
1992 (when (article-goto-body)
1993 (while (and (not (eobp))
1994 (looking-at "[ \t]*$"))
1995 (gnus-delete-line))))))
1997 (defun article-narrow-to-head ()
1998 "Narrow the buffer to the head of the message.
1999 Point is left at the beginning of the narrowed-to region."
2001 (goto-char (point-min))
2002 (if (search-forward "\n\n" nil 1)
2005 (goto-char (point-min)))
2007 (defun article-goto-body ()
2008 "Place point at the start of the body."
2009 (goto-char (point-min))
2011 ;; This variable is only bound when dealing with separate
2013 (article-goto-body-goes-to-point-min-p
2015 ((search-forward "\n\n" nil t)
2018 (goto-char (point-max))
2021 (defun article-strip-multiple-blank-lines ()
2022 "Replace consecutive blank lines with one empty line."
2025 (let ((inhibit-point-motion-hooks t)
2027 ;; First make all blank lines empty.
2029 (while (re-search-forward "^[ \t]+$" nil t)
2030 (unless (gnus-annotation-in-region-p
2031 (match-beginning 0) (match-end 0))
2032 (replace-match "" nil t)))
2033 ;; Then replace multiple empty lines with a single empty line.
2035 (while (re-search-forward "\n\n\n+" nil t)
2036 (unless (gnus-annotation-in-region-p
2037 (match-beginning 0) (match-end 0))
2038 (replace-match "\n\n" t t))))))
2040 (defun article-strip-leading-space ()
2041 "Remove all white space from the beginning of the lines in the article."
2044 (let ((inhibit-point-motion-hooks t)
2047 (while (re-search-forward "^[ \t]+" nil t)
2048 (replace-match "" t t)))))
2050 (defun article-strip-trailing-space ()
2051 "Remove all white space from the end of the lines in the article."
2054 (let ((inhibit-point-motion-hooks t)
2057 (while (re-search-forward "[ \t]+$" nil t)
2058 (replace-match "" t t)))))
2060 (defun article-strip-blank-lines ()
2061 "Strip leading, trailing and multiple blank lines."
2063 (article-strip-leading-blank-lines)
2064 (article-remove-trailing-blank-lines)
2065 (article-strip-multiple-blank-lines))
2067 (defun article-strip-all-blank-lines ()
2068 "Strip all blank lines."
2071 (let ((inhibit-point-motion-hooks t)
2074 (while (re-search-forward "^[ \t]*\n" nil t)
2075 (replace-match "" t t)))))
2077 (defun gnus-article-narrow-to-signature ()
2078 "Narrow to the signature; return t if a signature is found, else nil."
2079 (let ((inhibit-point-motion-hooks t))
2080 (when (gnus-article-search-signature)
2082 ;; Check whether we have some limits to what we consider
2083 ;; to be a signature.
2084 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2085 (list gnus-signature-limit)))
2087 (while (setq limit (pop limits))
2088 (if (or (and (integerp limit)
2089 (< (- (point-max) (point)) limit))
2091 (< (count-lines (point) (point-max)) limit))
2092 (and (gnus-functionp limit)
2094 (and (stringp limit)
2095 (not (re-search-forward limit nil t))))
2096 () ; This limit did not succeed.
2100 (narrow-to-region (point) (point-max))
2103 (defun gnus-article-search-signature ()
2104 "Search the current buffer for the signature separator.
2105 Put point at the beginning of the signature separator."
2106 (let ((cur (point)))
2107 (goto-char (point-max))
2108 (if (if (stringp gnus-signature-separator)
2109 (re-search-backward gnus-signature-separator nil t)
2110 (let ((seps gnus-signature-separator))
2112 (not (re-search-backward (car seps) nil t)))
2119 (defun gnus-article-hidden-arg ()
2120 "Return the current prefix arg as a number, or 0 if no prefix."
2121 (list (if current-prefix-arg
2122 (prefix-numeric-value current-prefix-arg)
2125 (defun gnus-article-check-hidden-text (type arg)
2126 "Return nil if hiding is necessary.
2127 Arg can be nil or a number. Nil and positive means hide, negative
2128 means show, 0 means toggle."
2131 (let ((hide (gnus-article-hidden-text-p type)))
2137 (gnus-article-show-hidden-text type))
2139 (if (eq hide 'hidden)
2140 (gnus-article-show-hidden-text type)
2143 (defun gnus-article-hidden-text-p (type)
2144 "Say whether the current buffer contains hidden text of type TYPE."
2145 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2147 (not (get-text-property pos 'invisible))
2148 (not (get-text-property pos 'dummy-invisible)))
2150 (text-property-any (1+ pos) (point-max) 'article-type type)))
2155 (defun gnus-article-show-hidden-text (type &optional dummy)
2156 "Show all hidden text of type TYPE.
2157 Originally it is hide instead of DUMMY."
2158 (let ((buffer-read-only nil)
2159 (inhibit-point-motion-hooks t))
2160 (gnus-remove-text-properties-when
2162 (point-min) (point-max)
2163 (cons 'article-type (cons type
2164 gnus-hidden-properties)))))
2166 (defconst article-time-units
2167 `((year . ,(* 365.25 24 60 60))
2168 (week . ,(* 7 24 60 60))
2169 (day . ,(* 24 60 60))
2173 "Mapping from time units to seconds.")
2175 (defun article-date-ut (&optional type highlight header)
2176 "Convert DATE date to universal time in the current article.
2177 If TYPE is `local', convert to local time; if it is `lapsed', output
2178 how much time has lapsed since DATE. For `lapsed', the value of
2179 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2180 should replace the \"Date:\" one, or should be added below it."
2181 (interactive (list 'ut t))
2182 (let* ((header (or header
2183 (and (eq 1 (point-min))
2184 (mail-header-date (save-excursion
2185 (set-buffer gnus-summary-buffer)
2186 gnus-current-headers)))
2187 (message-fetch-field "date")
2189 (date (if (vectorp header) (mail-header-date header)
2191 (inhibit-point-motion-hooks t)
2192 bface eface date-pos)
2193 (when (and date (not (string= date "")))
2196 (article-narrow-to-head)
2197 (when (or (and (eq type 'lapsed)
2198 gnus-article-date-lapsed-new-header
2199 ;; Attempt to get the face of X-Sent first.
2200 (re-search-forward "^X-Sent:[ \t]" nil t))
2201 (re-search-forward "^Date:[ \t]" nil t)
2202 ;; If Date is missing, try again for X-Sent.
2203 (re-search-forward "^X-Sent:[ \t]" nil t))
2204 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2205 date (or (get-text-property (gnus-point-at-bol)
2208 eface (get-text-property (1- (gnus-point-at-eol))
2210 (let ((buffer-read-only nil))
2211 ;; Delete any old X-Sent headers.
2212 (when (setq date-pos
2213 (text-property-any (point-min) (point-max)
2214 'article-date-lapsed t))
2215 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2216 (delete-region (match-beginning 0)
2217 (progn (forward-line 1) (point))))
2218 (goto-char (point-min))
2219 ;; Delete any old Date headers.
2220 (while (re-search-forward "^Date:[ \t]" nil t)
2222 (setq date-pos (match-beginning 0)))
2223 (unless (and (eq type 'lapsed)
2224 gnus-article-date-lapsed-new-header)
2225 (delete-region (match-beginning 0)
2226 (progn (message-next-header) (point)))))
2229 (goto-char date-pos)
2231 ;; Possibly, Date has been deleted.
2233 (when (and (eq type 'lapsed)
2234 gnus-article-date-lapsed-new-header
2235 (looking-at "Date:"))
2237 (goto-char (point-min)))
2238 (insert (article-make-date-line date type))
2239 (when (eq type 'lapsed)
2240 (put-text-property (gnus-point-at-bol) (point)
2241 'article-date-lapsed t))
2245 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2246 (put-text-property (match-beginning 1) (1+ (match-end 1))
2247 'original-date date)
2248 (put-text-property (match-beginning 1) (1+ (match-end 1))
2250 (put-text-property (match-beginning 2) (match-end 2)
2253 (defun article-make-date-line (date type)
2254 "Return a DATE line of TYPE."
2255 (let ((time (condition-case ()
2259 ;; Convert to the local timezone. We have to slap a
2260 ;; `condition-case' round the calls to the timezone
2261 ;; functions since they aren't particularly resistant to
2264 (let ((tz (car (current-time-zone time))))
2265 (format "Date: %s %s%02d%02d" (current-time-string time)
2266 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2267 (/ (% (abs tz) 3600) 60))))
2268 ;; Convert to Universal Time.
2271 (current-time-string
2272 (let* ((e (parse-time-string date))
2273 (tm (apply 'encode-time e))
2275 (ls (- (cadr tm) (car (current-time-zone time)))))
2276 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2277 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2280 ;; Get the original date from the article.
2281 ((eq type 'original)
2282 (concat "Date: " (if (string-match "\n+$" date)
2283 (substring date 0 (match-beginning 0))
2285 ;; Let the user define the format.
2287 (if (gnus-functionp gnus-article-time-format)
2288 (funcall gnus-article-time-format time)
2291 (format-time-string gnus-article-time-format time))))
2294 (let ((tz (car (current-time-zone time))))
2297 (format-time-string "%Y%m%dT%H%M%S" time)
2298 (format "%s%02d%02d"
2299 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2300 (/ (% (abs tz) 3600) 60)))))
2301 ;; Do an X-Sent lapsed format.
2303 ;; If the date is seriously mangled, the timezone functions are
2304 ;; liable to bug out, so we ignore all errors.
2305 (let* ((now (current-time))
2306 (real-time (subtract-time now time))
2307 (real-sec (and real-time
2308 (+ (* (float (car real-time)) 65536)
2310 (sec (and real-time (abs real-sec)))
2320 ;; This is a bit convoluted, but basically we go
2321 ;; through the time units for years, weeks, etc,
2322 ;; and divide things to see whether that results
2323 ;; in positive answers.
2326 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
2327 ;; The (remaining) seconds are too few to
2328 ;; be divided into this time unit.
2330 ;; It's big enough, so we output it.
2331 (setq sec (- sec (* num (cdr unit))))
2333 (concat (if prev ", " "") (int-to-string
2335 " " (symbol-name (car unit))
2336 (if (> num 1) "s" ""))
2338 article-time-units "")
2339 ;; If dates are odd, then it might appear like the
2340 ;; article was sent in the future.
2343 " in the future"))))))
2345 (error "Unknown conversion type: %s" type)))))
2347 (defun article-date-local (&optional highlight)
2348 "Convert the current article date to the local timezone."
2349 (interactive (list t))
2350 (article-date-ut 'local highlight))
2352 (defun article-date-original (&optional highlight)
2353 "Convert the current article date to what it was originally.
2354 This is only useful if you have used some other date conversion
2355 function and want to see what the date was before converting."
2356 (interactive (list t))
2357 (article-date-ut 'original highlight))
2359 (defun article-date-lapsed (&optional highlight)
2360 "Convert the current article date to time lapsed since it was sent."
2361 (interactive (list t))
2362 (article-date-ut 'lapsed highlight))
2364 (defun article-update-date-lapsed ()
2365 "Function to be run from a timer to update the lapsed time line."
2366 (let (deactivate-mark)
2371 (set-buffer (window-buffer w))
2372 (when (eq major-mode 'gnus-article-mode)
2373 (goto-char (point-min))
2374 (when (re-search-forward "^X-Sent:" nil t)
2375 (article-date-lapsed t))))
2378 (defun gnus-start-date-timer (&optional n)
2379 "Start a timer to update the X-Sent header in the article buffers.
2380 The numerical prefix says how frequently (in seconds) the function
2385 (gnus-stop-date-timer)
2386 (setq article-lapsed-timer
2387 (nnheader-run-at-time 1 n 'article-update-date-lapsed)))
2389 (defun gnus-stop-date-timer ()
2390 "Stop the X-Sent timer."
2392 (when article-lapsed-timer
2393 (nnheader-cancel-timer article-lapsed-timer)
2394 (setq article-lapsed-timer nil)))
2396 (defun article-date-user (&optional highlight)
2397 "Convert the current article date to the user-defined format.
2398 This format is defined by the `gnus-article-time-format' variable."
2399 (interactive (list t))
2400 (article-date-ut 'user highlight))
2402 (defun article-date-iso8601 (&optional highlight)
2403 "Convert the current article date to ISO8601."
2404 (interactive (list t))
2405 (article-date-ut 'iso8601 highlight))
2407 (defun article-show-all ()
2408 "Show all hidden text in the article buffer."
2412 (let ((buffer-read-only nil))
2413 (gnus-article-unhide-text (point-min) (point-max))
2414 (gnus-remove-text-with-property 'gnus-prev)
2415 (gnus-remove-text-with-property 'gnus-next))))
2417 (defun article-show-all-headers ()
2418 "Show all hidden headers in the article buffer."
2423 (article-narrow-to-head)
2424 (let ((buffer-read-only nil))
2425 (gnus-article-unhide-text (point-min) (point-max))))))
2427 (defun article-emphasize (&optional arg)
2428 "Emphasize text according to `gnus-emphasis-alist'."
2429 (interactive (gnus-article-hidden-arg))
2430 (unless (gnus-article-check-hidden-text 'emphasis arg)
2434 (with-current-buffer gnus-summary-buffer
2435 gnus-article-emphasis-alist)
2437 gnus-emphasis-alist))
2438 (buffer-read-only nil)
2439 (props (append '(article-type emphasis)
2440 gnus-hidden-properties))
2441 regexp elem beg invisible visible face)
2444 (while (setq elem (pop alist))
2446 (setq regexp (car elem)
2447 invisible (nth 1 elem)
2448 visible (nth 2 elem)
2450 (while (re-search-forward regexp nil t)
2451 (when (and (match-beginning visible) (match-beginning invisible))
2452 (push 'emphasis gnus-article-wash-types)
2453 (gnus-article-hide-text
2454 (match-beginning invisible) (match-end invisible) props)
2455 (gnus-article-unhide-text-type
2456 (match-beginning visible) (match-end visible) 'emphasis)
2457 (gnus-put-text-property-excluding-newlines
2458 (match-beginning visible) (match-end visible) 'face face)
2459 (goto-char (match-end invisible)))))))))
2461 (defun gnus-article-setup-highlight-words (&optional highlight-words)
2462 "Setup newsgroup emphasis alist."
2463 (unless gnus-article-emphasis-alist
2464 (let ((name (and gnus-newsgroup-name
2465 (gnus-group-real-name gnus-newsgroup-name))))
2466 (make-local-variable 'gnus-article-emphasis-alist)
2467 (setq gnus-article-emphasis-alist
2469 (let ((alist gnus-group-highlight-words-alist) elem highlight)
2470 (while (setq elem (pop alist))
2471 (when (and name (string-match (car elem) name))
2473 highlight (copy-sequence (cdr elem)))))
2475 (copy-sequence highlight-words)
2476 (if gnus-newsgroup-name
2477 (copy-sequence (gnus-group-find-parameter
2478 gnus-newsgroup-name 'highlight-words t)))
2479 gnus-emphasis-alist)))))
2481 (defvar gnus-summary-article-menu)
2482 (defvar gnus-summary-post-menu)
2484 ;;; Saving functions.
2486 (defun gnus-article-save (save-buffer file &optional num)
2487 "Save the currently selected article."
2488 (unless gnus-save-all-headers
2489 ;; Remove headers according to `gnus-saved-headers'.
2490 (let ((gnus-visible-headers
2491 (or gnus-saved-headers gnus-visible-headers))
2492 (gnus-article-buffer save-buffer))
2494 (set-buffer save-buffer)
2495 (article-hide-headers 1 t))))
2496 (save-window-excursion
2497 (if (not gnus-default-article-saver)
2498 (error "No default saver is defined")
2499 ;; !!! Magic! The saving functions all save
2500 ;; `gnus-save-article-buffer' (or so they think), but we
2501 ;; bind that variable to our save-buffer.
2502 (set-buffer gnus-article-buffer)
2503 (let* ((gnus-save-article-buffer save-buffer)
2506 ((not gnus-prompt-before-saving) 'default)
2507 ((eq gnus-prompt-before-saving 'always) nil)
2509 (gnus-number-of-articles-to-be-saved
2510 (when (eq gnus-prompt-before-saving t)
2512 (set-buffer gnus-article-current-summary)
2513 (funcall gnus-default-article-saver filename)))))
2515 (defun gnus-read-save-file-name (prompt &optional filename
2516 function group headers variable)
2518 (funcall function group headers (symbol-value variable)))
2523 ((eq filename 'default)
2529 (let* ((split-name (gnus-get-split-value gnus-split-methods))
2532 (if (and gnus-number-of-articles-to-be-saved
2533 (> gnus-number-of-articles-to-be-saved 1))
2534 (format "these %d articles"
2535 gnus-number-of-articles-to-be-saved)
2538 ;; Let the split methods have their say.
2540 ;; No split name was found.
2543 (concat prompt " (default "
2544 (file-name-nondirectory default-name) ") ")
2545 (file-name-directory default-name)
2547 ;; A single group name is returned.
2548 ((stringp split-name)
2550 (funcall function split-name headers
2551 (symbol-value variable)))
2553 (concat prompt " (default "
2554 (file-name-nondirectory default-name) ") ")
2555 (file-name-directory default-name)
2557 ;; A single split name was found
2558 ((= 1 (length split-name))
2559 (let* ((name (expand-file-name
2561 gnus-article-save-directory))
2562 (dir (cond ((file-directory-p name)
2563 (file-name-as-directory name))
2564 ((file-exists-p name) name)
2565 (t gnus-article-save-directory))))
2567 (concat prompt " (default " name ") ")
2569 ;; A list of splits was found.
2571 (setq split-name (nreverse split-name))
2573 (let ((file-name-history
2574 (nconc split-name file-name-history)))
2578 (concat prompt " (`M-p' for defaults) ")
2579 gnus-article-save-directory
2581 gnus-article-save-directory)))
2582 (car (push result file-name-history)))))))
2583 ;; Create the directory.
2584 (gnus-make-directory (file-name-directory file))
2585 ;; If we have read a directory, we append the default file name.
2586 (when (file-directory-p file)
2587 (setq file (expand-file-name (file-name-nondirectory
2589 (file-name-as-directory file))))
2590 ;; Possibly translate some characters.
2591 (nnheader-translate-file-chars file))))))
2592 (gnus-make-directory (file-name-directory result))
2593 (set variable result)))
2595 (defun gnus-article-archive-name (group)
2596 "Return the first instance of an \"Archive-name\" in the current buffer."
2597 (let ((case-fold-search t))
2598 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
2599 (nnheader-concat gnus-article-save-directory
2600 (match-string 1)))))
2602 (defun gnus-article-nndoc-name (group)
2603 "If GROUP is an nndoc group, return the name of the parent group."
2604 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
2605 (gnus-group-get-parameter group 'save-article-group)))
2607 (defun gnus-summary-save-in-rmail (&optional filename)
2608 "Append this article to Rmail file.
2609 Optional argument FILENAME specifies file name.
2610 Directory to save to is default to `gnus-article-save-directory'."
2611 (setq filename (gnus-read-save-file-name
2612 "Save %s in rmail file:" filename
2613 gnus-rmail-save-name gnus-newsgroup-name
2614 gnus-current-headers 'gnus-newsgroup-last-rmail))
2615 (gnus-eval-in-buffer-window gnus-save-article-buffer
2619 (gnus-output-to-rmail filename))))
2622 (defun gnus-summary-save-in-mail (&optional filename)
2623 "Append this article to Unix mail file.
2624 Optional argument FILENAME specifies file name.
2625 Directory to save to is default to `gnus-article-save-directory'."
2626 (setq filename (gnus-read-save-file-name
2627 "Save %s in Unix mail file:" filename
2628 gnus-mail-save-name gnus-newsgroup-name
2629 gnus-current-headers 'gnus-newsgroup-last-mail))
2630 (gnus-eval-in-buffer-window gnus-save-article-buffer
2634 (if (and (file-readable-p filename)
2635 (mail-file-babyl-p filename))
2636 (rmail-output-to-rmail-file filename t)
2637 (gnus-output-to-mail filename)))))
2640 (defun gnus-summary-save-in-file (&optional filename overwrite)
2641 "Append this article to file.
2642 Optional argument FILENAME specifies file name.
2643 Directory to save to is default to `gnus-article-save-directory'."
2644 (setq filename (gnus-read-save-file-name
2645 "Save %s in file:" filename
2646 gnus-file-save-name gnus-newsgroup-name
2647 gnus-current-headers 'gnus-newsgroup-last-file))
2648 (gnus-eval-in-buffer-window gnus-save-article-buffer
2652 (when (and overwrite
2653 (file-exists-p filename))
2654 (delete-file filename))
2655 (gnus-output-to-file filename))))
2658 (defun gnus-summary-write-to-file (&optional filename)
2659 "Write this article to a file.
2660 Optional argument FILENAME specifies file name.
2661 The directory to save in defaults to `gnus-article-save-directory'."
2662 (gnus-summary-save-in-file nil t))
2664 (defun gnus-summary-save-body-in-file (&optional filename)
2665 "Append this article body to a file.
2666 Optional argument FILENAME specifies file name.
2667 The directory to save in defaults to `gnus-article-save-directory'."
2668 (setq filename (gnus-read-save-file-name
2669 "Save %s body in file:" filename
2670 gnus-file-save-name gnus-newsgroup-name
2671 gnus-current-headers 'gnus-newsgroup-last-file))
2672 (gnus-eval-in-buffer-window gnus-save-article-buffer
2676 (when (article-goto-body)
2677 (narrow-to-region (point) (point-max)))
2678 (gnus-output-to-file filename))))
2681 (defun gnus-summary-save-in-pipe (&optional command)
2682 "Pipe this article to subprocess."
2684 (cond ((and (eq command 'default)
2685 gnus-last-shell-command)
2686 gnus-last-shell-command)
2690 "Shell command on %s: "
2691 (if (and gnus-number-of-articles-to-be-saved
2692 (> gnus-number-of-articles-to-be-saved 1))
2693 (format "these %d articles"
2694 gnus-number-of-articles-to-be-saved)
2696 gnus-last-shell-command))))
2697 (when (string-equal command "")
2698 (setq command gnus-last-shell-command))
2699 (gnus-eval-in-buffer-window gnus-article-buffer
2702 (shell-command-on-region (point-min) (point-max) command nil)))
2703 (setq gnus-last-shell-command command))
2705 ;;; Article file names when saving.
2707 (defun gnus-capitalize-newsgroup (newsgroup)
2708 "Capitalize NEWSGROUP name."
2709 (when (not (zerop (length newsgroup)))
2710 (concat (char-to-string (upcase (aref newsgroup 0)))
2711 (substring newsgroup 1))))
2713 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2714 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2715 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
2716 Otherwise, it is like ~/News/news/group/num."
2719 (concat (if (gnus-use-long-file-name 'not-save)
2720 (gnus-capitalize-newsgroup newsgroup)
2721 (gnus-newsgroup-directory-form newsgroup))
2722 "/" (int-to-string (mail-header-number headers)))
2723 gnus-article-save-directory)))
2725 (string-equal (file-name-directory default)
2726 (file-name-directory last-file))
2727 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2729 (or last-file default))))
2731 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2732 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2733 If variable `gnus-use-long-file-name' is non-nil, it is
2734 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
2737 (concat (if (gnus-use-long-file-name 'not-save)
2739 (gnus-newsgroup-directory-form newsgroup))
2740 "/" (int-to-string (mail-header-number headers)))
2741 gnus-article-save-directory)))
2743 (string-equal (file-name-directory default)
2744 (file-name-directory last-file))
2745 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2747 (or last-file default))))
2749 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2750 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2751 If variable `gnus-use-long-file-name' is non-nil, it is
2752 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
2755 (if (gnus-use-long-file-name 'not-save)
2757 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)))
2758 gnus-article-save-directory)))
2760 (defun article-verify-x-pgp-sig ()
2763 (if (gnus-buffer-live-p gnus-original-article-buffer)
2764 (let ((sig (with-current-buffer gnus-original-article-buffer
2765 (gnus-fetch-field "X-PGP-Sig")))
2769 (mml2015-clear-verify-function))
2771 (insert-buffer gnus-original-article-buffer)
2772 (setq items (split-string sig))
2773 (message-narrow-to-head)
2774 (let ((inhibit-point-motion-hooks t)
2775 (case-fold-search t))
2776 ;; Don't verify multiple headers.
2777 (setq headers (mapconcat (lambda (header)
2779 (mail-fetch-field header) "\n"))
2780 (split-string (nth 1 items) ",") "")))
2781 (delete-region (point-min) (point-max))
2782 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
2783 (insert "X-Signed-Headers: " (nth 1 items) "\n")
2788 (if (looking-at "^-")
2791 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
2792 (insert "Version: " (car items) "\n\n")
2793 (insert (mapconcat 'identity (cddr items) "\n"))
2794 (insert "\n-----END PGP SIGNATURE-----\n")
2795 (let ((mm-security-handle (list (format "multipart/signed"))))
2796 (mml2015-clean-buffer)
2797 (let ((coding-system-for-write (or gnus-newsgroup-charset
2799 (funcall (mml2015-clear-verify-function)))
2801 (or (mm-handle-multipart-ctl-parameter
2802 mm-security-handle 'gnus-details)
2803 (mm-handle-multipart-ctl-parameter
2804 mm-security-handle 'gnus-info)))))
2806 (let (buffer-read-only bface eface)
2808 (message-narrow-to-head)
2809 (goto-char (point-max))
2811 (setq bface (get-text-property (gnus-point-at-bol) 'face)
2812 eface (get-text-property (1- (gnus-point-at-eol)) 'face))
2813 (message-remove-header "X-Gnus-PGP-Verify")
2814 (if (re-search-forward "^X-PGP-Sig:" nil t)
2816 (goto-char (point-max)))
2817 (narrow-to-region (point) (point))
2818 (insert "X-Gnus-PGP-Verify: " info "\n")
2819 (goto-char (point-min))
2822 (if (not (looking-at "^[ \t]"))
2826 (goto-char (point-min))
2827 (when (looking-at "\\([^:]+\\): *")
2828 (put-text-property (match-beginning 1) (1+ (match-end 1))
2830 (put-text-property (match-end 0) (point-max)
2831 'face eface)))))))))
2838 (setq afunc (car func)
2841 gfunc (intern (format "gnus-%s" func))))
2844 `(lambda (&optional interactive &rest args)
2845 ,(documentation afunc t)
2846 (interactive (list t))
2848 (set-buffer gnus-article-buffer)
2850 (call-interactively ',afunc)
2851 (apply ',afunc args))))))))
2852 '(article-hide-headers
2853 article-verify-x-pgp-sig
2854 article-hide-boring-headers
2855 article-toggle-headers
2856 article-treat-overstrike
2857 article-fill-long-lines
2858 article-capitalize-sentences
2860 article-display-x-face
2861 article-de-quoted-unreadable
2862 article-de-base64-unreadable
2865 article-hide-list-identifiers
2867 article-strip-banner
2870 article-hide-signature
2871 article-strip-headers-in-body
2872 article-remove-trailing-blank-lines
2873 article-strip-leading-blank-lines
2874 article-strip-multiple-blank-lines
2875 article-strip-leading-space
2876 article-strip-trailing-space
2877 article-strip-blank-lines
2878 article-strip-all-blank-lines
2880 article-date-iso8601
2881 article-date-original
2883 article-decode-mime-words
2884 article-decode-charset
2885 article-decode-encoded-words
2889 article-treat-dumbquotes
2890 article-normalize-headers
2891 (article-show-all-headers . gnus-article-show-all-headers)
2892 (article-show-all . gnus-article-show-all))))
2895 ;;; Gnus article mode
2898 (put 'gnus-article-mode 'mode-class 'special)
2900 (gnus-define-keys gnus-article-mode-map
2901 " " gnus-article-goto-next-page
2902 "\177" gnus-article-goto-prev-page
2903 [delete] gnus-article-goto-prev-page
2904 [backspace] gnus-article-goto-prev-page
2905 "\C-c^" gnus-article-refer-article
2906 "h" gnus-article-show-summary
2907 "s" gnus-article-show-summary
2908 "\C-c\C-m" gnus-article-mail
2909 "?" gnus-article-describe-briefly
2910 "e" gnus-summary-edit-article
2911 "<" beginning-of-buffer
2913 "\C-c\C-i" gnus-info-find-node
2915 "\C-hk" gnus-article-describe-key
2916 "\C-hc" gnus-article-describe-key-briefly
2918 "\C-d" gnus-article-read-summary-keys
2919 "\M-*" gnus-article-read-summary-keys
2920 "\M-#" gnus-article-read-summary-keys
2921 "\M-^" gnus-article-read-summary-keys
2922 "\M-g" gnus-article-read-summary-keys)
2924 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
2927 (unless (lookup-key gnus-article-mode-map key)
2928 (define-key gnus-article-mode-map key
2929 'gnus-article-read-summary-keys)))
2934 (let ((key (car elt)))
2935 (and (> (length key) 0)
2936 (not (eq 'menu-bar (aref key 0)))
2937 (symbolp (lookup-key gnus-summary-mode-map key))
2939 (accessible-keymaps gnus-summary-mode-map))
2943 (push (char-to-string c) keys)
2948 (defvar gnus-article-commands-menu))
2950 (defun gnus-article-make-menu-bar ()
2951 (gnus-turn-off-edit-menu 'article)
2952 (unless (boundp 'gnus-article-article-menu)
2954 gnus-article-article-menu gnus-article-mode-map ""
2956 ["Scroll forwards" gnus-article-goto-next-page t]
2957 ["Scroll backwards" gnus-article-goto-prev-page t]
2958 ["Show summary" gnus-article-show-summary t]
2959 ["Fetch Message-ID at point" gnus-article-refer-article t]
2960 ["Mail to address at point" gnus-article-mail t]
2961 ["Send a bug report" gnus-bug t]))
2964 gnus-article-treatment-menu gnus-article-mode-map ""
2966 ["Hide headers" gnus-article-toggle-headers t]
2967 ["Hide signature" gnus-article-hide-signature t]
2968 ["Hide citation" gnus-article-hide-citation t]
2969 ["Treat overstrike" gnus-article-treat-overstrike t]
2970 ["Remove carriage return" gnus-article-remove-cr t]
2971 ["Decode HZ" gnus-article-decode-HZ t]))
2973 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
2975 (when (boundp 'gnus-summary-post-menu)
2976 (define-key gnus-article-mode-map [menu-bar post]
2977 (cons "Post" gnus-summary-post-menu)))
2979 (gnus-run-hooks 'gnus-article-menu-hook))
2981 (when (boundp 'gnus-article-commands-menu)
2982 (easy-menu-add gnus-article-commands-menu gnus-article-mode-map))
2983 (when (boundp 'gnus-summary-post-menu)
2984 (easy-menu-add gnus-summary-post-menu gnus-article-mode-map)))
2986 (defun gnus-article-mode ()
2987 "Major mode for displaying an article.
2989 All normal editing commands are switched off.
2991 The following commands are available in addition to all summary mode
2993 \\<gnus-article-mode-map>
2994 \\[gnus-article-next-page]\t Scroll the article one page forwards
2995 \\[gnus-article-prev-page]\t Scroll the article one page backwards
2996 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
2997 \\[gnus-article-show-summary]\t Display the summary buffer
2998 \\[gnus-article-mail]\t Send a reply to the address near point
2999 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3000 \\[gnus-info-find-node]\t Go to the Gnus info node"
3002 (when (gnus-visual-p 'article-menu 'menu)
3003 (gnus-article-make-menu-bar))
3004 (gnus-simplify-mode-line)
3005 (setq mode-name "Article")
3006 (setq major-mode 'gnus-article-mode)
3007 (make-local-variable 'minor-mode-alist)
3008 (unless (assq 'gnus-show-mime minor-mode-alist)
3009 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3010 (use-local-map gnus-article-mode-map)
3011 (gnus-update-format-specifications nil 'article-mode)
3012 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3013 (make-local-variable 'gnus-page-broken)
3014 (make-local-variable 'gnus-button-marker-list)
3015 (make-local-variable 'gnus-article-current-summary)
3016 (make-local-variable 'gnus-article-mime-handles)
3017 (make-local-variable 'gnus-article-decoded-p)
3018 (make-local-variable 'gnus-article-mime-handle-alist)
3019 (make-local-variable 'gnus-article-wash-types)
3020 (make-local-variable 'gnus-article-charset)
3021 (make-local-variable 'gnus-article-ignored-charsets)
3022 (gnus-set-default-directory)
3023 (buffer-disable-undo)
3024 (setq buffer-read-only t)
3025 (set-syntax-table gnus-article-mode-syntax-table)
3026 (gnus-run-hooks 'gnus-article-mode-hook))
3028 (defun gnus-article-setup-buffer ()
3029 "Initialize the article buffer."
3030 (let* ((name (if gnus-single-article-buffer "*Article*"
3031 (concat "*Article " gnus-newsgroup-name "*")))
3033 (progn (string-match "\\*Article" name)
3034 (concat " *Original Article"
3035 (substring name (match-end 0))))))
3036 (setq gnus-article-buffer name)
3037 (setq gnus-original-article-buffer original)
3038 (setq gnus-article-mime-handle-alist nil)
3039 ;; This might be a variable local to the summary buffer.
3040 (unless gnus-single-article-buffer
3042 (set-buffer gnus-summary-buffer)
3043 (setq gnus-article-buffer name)
3044 (setq gnus-original-article-buffer original)
3045 (gnus-set-global-variables)))
3046 (gnus-article-setup-highlight-words)
3047 ;; Init original article buffer.
3049 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3050 (set-buffer-multibyte nil)
3051 (setq major-mode 'gnus-original-article-mode)
3052 (make-local-variable 'gnus-original-article))
3053 (if (get-buffer name)
3056 (buffer-disable-undo)
3057 (setq buffer-read-only t)
3058 (unless (eq major-mode 'gnus-article-mode)
3059 (gnus-article-mode))
3062 (set-buffer (gnus-get-buffer-create name))
3064 (make-local-variable 'gnus-summary-buffer)
3065 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3066 (current-buffer)))))
3068 ;; Set article window start at LINE, where LINE is the number of lines
3069 ;; from the head of the article.
3070 (defun gnus-article-set-window-start (&optional line)
3072 (get-buffer-window gnus-article-buffer t)
3074 (set-buffer gnus-article-buffer)
3075 (goto-char (point-min))
3078 (gnus-message 6 "Moved to bookmark")
3079 (search-forward "\n\n" nil t)
3083 ;;; @@ article filters
3086 (defun gnus-article-display-mime-message ()
3087 "Article display method for MIME message."
3088 ;; called from `gnus-original-article-buffer'.
3089 (let (charset all-headers)
3090 (with-current-buffer gnus-summary-buffer
3091 (setq charset default-mime-charset
3092 all-headers gnus-have-all-headers))
3093 (make-local-variable 'default-mime-charset)
3094 (setq default-mime-charset charset)
3095 (with-current-buffer (get-buffer-create gnus-article-buffer)
3096 (make-local-variable 'default-mime-charset)
3097 (setq default-mime-charset charset))
3098 (mime-display-message mime-message-structure
3099 gnus-article-buffer nil gnus-article-mode-map)
3101 (gnus-article-hide-headers nil -1)))
3102 (run-hooks 'gnus-mime-article-prepare-hook))
3104 (defun gnus-article-display-traditional-message ()
3105 "Article display method for traditional message."
3106 (set-buffer gnus-article-buffer)
3107 (let (buffer-read-only)
3109 (insert-buffer-substring gnus-original-article-buffer)))
3111 (defun gnus-article-make-full-mail-header (&optional number charset)
3112 "Create a new mail header structure in a raw article buffer."
3113 (unless (and number charset)
3114 (save-current-buffer
3115 (set-buffer gnus-summary-buffer)
3117 (setq number (or (cdr gnus-article-current) 0)))
3119 (setq charset (or default-mime-charset 'x-ctext)))))
3120 (goto-char (point-min))
3121 (let ((header-end (if (search-forward "\n\n" nil t)
3123 (goto-char (point-max))))
3124 (chars (- (point-max) (point)))
3125 (lines (count-lines (point) (point-max)))
3126 (default-mime-charset charset)
3128 (narrow-to-region (point-min) header-end)
3129 (setq xref (std11-fetch-field "xref"))
3131 (make-full-mail-header
3133 (std11-fetch-field "subject")
3134 (std11-fetch-field "from")
3135 (std11-fetch-field "date")
3136 (std11-fetch-field "message-id")
3137 (std11-fetch-field "references")
3140 (when xref (concat "Xref: " xref)))
3143 (defun gnus-article-prepare (article &optional all-headers header)
3144 "Prepare ARTICLE in article mode buffer.
3145 ARTICLE should either be an article number or a Message-ID.
3146 If ARTICLE is an id, HEADER should be the article headers.
3147 If ALL-HEADERS is non-nil, no headers are hidden."
3149 ;; Make sure we start in a summary buffer.
3150 (unless (eq major-mode 'gnus-summary-mode)
3151 (set-buffer gnus-summary-buffer))
3152 (setq gnus-summary-buffer (current-buffer))
3153 (let* ((gnus-article (if header (mail-header-number header) article))
3154 (summary-buffer (current-buffer))
3155 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3156 (group gnus-newsgroup-name)
3159 (gnus-article-setup-buffer)
3160 (set-buffer gnus-original-article-buffer)
3161 ;; Deactivate active regions.
3162 (when (and (boundp 'transient-mark-mode)
3163 transient-mark-mode)
3164 (setq mark-active nil))
3165 (if (not (setq result (let ((buffer-read-only nil))
3166 (gnus-request-article-this-buffer
3168 ;; There is no such article.
3170 (when (and (numberp article)
3171 (not (memq article gnus-newsgroup-sparse)))
3172 (setq gnus-article-current
3173 (cons gnus-newsgroup-name article))
3174 (set-buffer gnus-summary-buffer)
3175 (setq gnus-current-article article)
3176 (if (eq (gnus-article-mark article) gnus-undownloaded-mark)
3178 (gnus-summary-set-agent-mark article)
3179 (message "Message marked for downloading"))
3180 (gnus-summary-mark-article article gnus-canceled-mark)
3181 (unless (memq article gnus-newsgroup-sparse)
3182 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3183 (if (or (eq result 'pseudo)
3184 (eq result 'nneething))
3187 (set-buffer summary-buffer)
3188 (push article gnus-newsgroup-history)
3189 (setq gnus-last-article gnus-current-article
3190 gnus-current-article 0
3191 gnus-current-headers nil
3192 gnus-article-current nil)
3193 (if (eq result 'nneething)
3194 (gnus-configure-windows 'summary)
3195 (gnus-configure-windows 'article))
3196 (gnus-set-global-variables))
3197 (let ((gnus-article-mime-handle-alist-1
3198 gnus-article-mime-handle-alist))
3199 (gnus-set-mode-line 'article)))
3200 ;; The result from the `request' was an actual article -
3201 ;; or at least some text that is now displayed in the
3203 (when (and (numberp article)
3204 (not (eq article gnus-current-article)))
3205 ;; Seems like a new article has been selected.
3206 ;; `gnus-current-article' must be an article number.
3208 (set-buffer summary-buffer)
3209 (push article gnus-newsgroup-history)
3210 (setq gnus-last-article gnus-current-article
3211 gnus-current-article article
3212 gnus-current-headers
3213 (gnus-summary-article-header gnus-current-article)
3214 gnus-article-current
3215 (cons gnus-newsgroup-name gnus-current-article))
3216 (unless (vectorp gnus-current-headers)
3217 (setq gnus-current-headers nil))
3218 (gnus-summary-goto-subject gnus-current-article)
3219 (when (gnus-summary-show-thread)
3220 ;; If the summary buffer really was folded, the
3221 ;; previous goto may not actually have gone to
3222 ;; the right article, but the thread root instead.
3224 (gnus-summary-goto-subject gnus-current-article))
3225 (gnus-run-hooks 'gnus-mark-article-hook)
3226 (gnus-set-mode-line 'summary)
3227 (when (gnus-visual-p 'article-highlight 'highlight)
3228 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3229 ;; Set the global newsgroup variables here.
3230 (gnus-set-global-variables)
3231 (setq gnus-have-all-headers
3232 (or all-headers gnus-show-all-headers))))
3234 (gnus-configure-windows 'article))
3235 (when (or (numberp article)
3237 (gnus-article-prepare-display)
3239 (goto-char (point-min))
3240 (setq gnus-page-broken
3241 (when gnus-break-pages
3242 (gnus-narrow-to-page)
3244 (let ((gnus-article-mime-handle-alist-1
3245 gnus-article-mime-handle-alist))
3246 (gnus-set-mode-line 'article))
3248 (set-window-point (get-buffer-window (current-buffer)) (point))
3249 (gnus-configure-windows 'article)
3252 (defun gnus-article-prepare-mime-display (&optional number)
3253 (goto-char (point-min))
3254 (when (re-search-forward "^[^\t ]+:" nil t)
3255 (goto-char (match-beginning 0)))
3256 (let ((entity (if (eq 1 (point-min))
3257 (get-text-property 1 'mime-view-entity)
3258 (get-text-property (point) 'mime-view-entity)))
3259 last-entity child-entity next type)
3260 (setq child-entity (mime-entity-children entity))
3262 (setq last-entity (nth (1- (length child-entity))
3264 (setq last-entity entity))
3266 (narrow-to-region (point)
3267 (if (search-forward "\n\n" nil t)
3270 (gnus-treat-article 'head)
3271 (put-text-property (point-min) (point-max) 'article-treated-header t)
3272 (goto-char (point-max)))
3273 (while (and (not (eobp)) entity)
3274 (setq next (set-marker
3276 (next-single-property-change (point) 'mime-view-entity
3278 (let ((types (mime-entity-content-type entity)))
3279 (while (eq 'multipart (mime-content-type-primary-type types))
3280 (setq entity (car (mime-entity-children entity))
3281 types (mime-entity-content-type entity)))
3283 (setq type (format "%s/%s"
3284 (mime-content-type-primary-type types)
3285 (mime-content-type-subtype types)))))
3286 (if (string-equal type "message/rfc822")
3289 (let ((children (mime-entity-children entity))
3292 (setq last-children (nth (1- (length children)) children))
3295 (not (eq last-children
3296 (get-text-property next 'mime-view-entity)))
3298 (next-single-property-change next
3300 nil (point-max)))))))
3301 (setq next (next-single-property-change next 'mime-view-entity
3304 (narrow-to-region (point) next)
3305 (gnus-article-prepare-mime-display)
3306 (goto-char (point-max)))
3307 (setq entity (get-text-property (point) 'mime-view-entity)))
3309 (narrow-to-region (point) next)
3310 ;; Kludge. We have to count true number, but for now,
3311 ;; part number is here only to achieve `last'.
3312 (gnus-treat-article nil 1
3313 (if (eq entity last-entity)
3316 (goto-char (point-max)))
3317 (setq entity (get-text-property next 'mime-view-entity))))))
3320 (defun gnus-article-prepare-display ()
3321 "Make the current buffer look like a nice article."
3322 (setq gnus-article-wash-types nil)
3323 (gnus-run-hooks 'gnus-tmp-internal-hook)
3324 (gnus-run-hooks 'gnus-article-prepare-hook)
3326 (let (mime-display-header-hook mime-display-text/plain-hook)
3327 (funcall (if gnus-show-mime
3329 (setq mime-message-structure gnus-current-headers)
3330 (mime-buffer-entity-set-buffer-internal
3331 mime-message-structure
3332 gnus-original-article-buffer)
3333 (mime-entity-set-representation-type-internal
3334 mime-message-structure 'mime-buffer-entity)
3335 (luna-send mime-message-structure
3336 'initialize-instance
3337 mime-message-structure)
3338 gnus-article-display-method-for-mime)
3339 gnus-article-display-method-for-traditional)))
3340 ;; Associate this article with the current summary buffer.
3341 (setq gnus-article-current-summary gnus-summary-buffer)
3342 ;; Call the treatment functions.
3343 (let ((inhibit-read-only t)
3348 (gnus-article-prepare-mime-display)
3349 (narrow-to-region (goto-char (point-min))
3350 (if (search-forward "\n\n" nil t)
3353 (gnus-treat-article 'head)
3354 (put-text-property (point-min) (point-max) 'article-treated-header t)
3355 (goto-char (point-max))
3357 (narrow-to-region (point) (point-max))
3358 (gnus-treat-article nil))
3359 (put-text-property (point-min) (point-max) 'read-only nil)))
3360 ;; Perform the article display hooks. Incidentally, this hook is
3361 ;; an obsolete variable by now.
3362 (gnus-run-hooks 'gnus-article-display-hook))
3364 (defun gnus-article-decode-article-as-default-mime-charset ()
3365 "Decode an article as `default-mime-charset'. It won't work if the
3366 value of the variable `gnus-show-mime' is non-nil."
3367 (unless gnus-show-mime
3368 (decode-mime-charset-region (point-min) (point-max)
3369 (with-current-buffer gnus-summary-buffer
3370 default-mime-charset))))
3373 ;;; Gnus MIME viewing functions
3376 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3377 "The following specs can be used:
3379 %T MIME type, along with additional info
3380 %n The `name' parameter
3381 %d The description, if any
3382 %l The length of the encoded part
3383 %p The part identifier number
3384 %e Dots if the part isn't displayed")
3386 (defvar gnus-mime-button-line-format-alist
3387 '((?t gnus-tmp-type ?s)
3388 (?T gnus-tmp-type-long ?s)
3389 (?n gnus-tmp-name ?s)
3390 (?d gnus-tmp-description ?s)
3392 (?l gnus-tmp-length ?d)
3393 (?e gnus-tmp-dots ?s)))
3395 (defvar gnus-mime-button-commands
3396 '((gnus-article-press-button "\r" "Toggle Display")
3397 (gnus-mime-view-part "v" "View Interactively...")
3398 (gnus-mime-view-part-as-type "t" "View As Type...")
3399 (gnus-mime-view-part-as-charset "C" "View As charset...")
3400 (gnus-mime-save-part "o" "Save...")
3401 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3402 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3403 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3404 (gnus-mime-internalize-part "E" "View Internally")
3405 (gnus-mime-externalize-part "e" "View Externally")
3406 (gnus-mime-pipe-part "|" "Pipe To Command...")
3407 (gnus-mime-action-on-part "." "Take action on the part")))
3409 (defun gnus-article-mime-part-status ()
3410 (with-current-buffer gnus-article-buffer
3411 (let ((entity (get-text-property (point-min) 'mime-view-entity)))
3412 (if (and entity (mime-entity-children entity))
3413 (format " (%d parts)" (length (mime-entity-children entity)))
3416 (defvar gnus-mime-button-map
3417 (let ((map (make-sparse-keymap)))
3418 (set-keymap-parent map gnus-article-mode-map)
3419 (define-key map gnus-mouse-2 'gnus-article-push-button)
3420 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
3421 (dolist (c gnus-mime-button-commands)
3422 (define-key map (cadr c) (car c)))
3425 (defun gnus-mime-button-menu (event)
3426 "Construct a context-sensitive menu of MIME commands."
3428 (save-window-excursion
3429 (let ((pos (event-start event)))
3430 (select-window (posn-window pos))
3431 (goto-char (posn-point pos))
3432 (gnus-article-check-buffer)
3433 (let ((response (x-popup-menu
3435 ("" ,@(mapcar (lambda (c)
3436 (cons (caddr c) (car c)))
3437 gnus-mime-button-commands))))))
3439 (call-interactively response))))))
3441 (defun gnus-mime-view-all-parts (&optional handles)
3442 "View all the MIME parts."
3444 (save-current-buffer
3445 (set-buffer gnus-article-buffer)
3446 (let ((handles (or handles gnus-article-mime-handles))
3447 (mail-parse-charset gnus-newsgroup-charset)
3448 (mail-parse-ignored-charsets
3449 (with-current-buffer gnus-summary-buffer
3450 gnus-newsgroup-ignored-charsets)))
3451 (mm-remove-parts handles)
3452 (goto-char (point-min))
3453 (or (search-forward "\n\n") (goto-char (point-max)))
3454 (let (buffer-read-only)
3455 (delete-region (point) (point-max)))
3456 (mm-display-parts handles))))
3458 (defun gnus-mime-save-part-and-strip ()
3459 "Save the MIME part under point then replace it with an external body."
3461 (gnus-article-check-buffer)
3462 (let* ((data (get-text-property (point) 'gnus-data))
3463 (file (mm-save-part data))
3466 (with-current-buffer (mm-handle-buffer data)
3468 (insert "Content-Type: " (mm-handle-media-type data))
3469 (mml-insert-parameter-string (cdr (mm-handle-type data))
3472 (insert "Content-ID: " (message-make-message-id) "\n")
3473 (insert "Content-Transfer-Encoding: binary\n")
3476 (cdr (mm-make-handle nil
3477 `("message/external-body"
3478 (access-type . "LOCAL-FILE")
3480 (set-buffer gnus-summary-buffer)
3481 (gnus-article-edit-article
3484 (let ((mail-parse-charset (or gnus-article-charset
3485 ',gnus-newsgroup-charset))
3486 (mail-parse-ignored-charsets
3487 (or gnus-article-ignored-charsets
3488 ',gnus-newsgroup-ignored-charsets))
3489 (mbl mml-buffer-list))
3490 (setq mml-buffer-list nil)
3491 (insert-buffer gnus-original-article-buffer)
3492 (mime-to-mml gnus-article-mime-handles)
3493 (setq gnus-article-mime-handles nil)
3494 (make-local-hook 'kill-buffer-hook)
3495 (let ((mbl1 mml-buffer-list))
3496 (setq mml-buffer-list mbl)
3497 (set (make-local-variable 'mml-buffer-list) mbl1))
3498 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
3499 `(lambda (no-highlight)
3500 (let ((mail-parse-charset (or gnus-article-charset
3501 ',gnus-newsgroup-charset))
3502 (message-options message-options)
3503 (message-options-set-recipient)
3504 (mail-parse-ignored-charsets
3505 (or gnus-article-ignored-charsets
3506 ',gnus-newsgroup-ignored-charsets)))
3508 (mml-destroy-buffers)
3509 (remove-hook 'kill-buffer-hook
3510 'mml-destroy-buffers t)
3511 (kill-local-variable 'mml-buffer-list))
3512 (gnus-summary-edit-article-done
3513 ,(or (mail-header-references gnus-current-headers) "")
3514 ,(gnus-group-read-only-p)
3515 ,gnus-summary-buffer no-highlight))))))
3517 (defun gnus-mime-save-part ()
3518 "Save the MIME part under point."
3520 (gnus-article-check-buffer)
3521 (let ((data (get-text-property (point) 'gnus-data)))
3522 (mm-save-part data)))
3524 (defun gnus-mime-pipe-part ()
3525 "Pipe the MIME part under point to a process."
3527 (gnus-article-check-buffer)
3528 (let ((data (get-text-property (point) 'gnus-data)))
3529 (mm-pipe-part data)))
3531 (defun gnus-mime-view-part ()
3532 "Interactively choose a viewing method for the MIME part under point."
3534 (gnus-article-check-buffer)
3535 (let ((data (get-text-property (point) 'gnus-data)))
3536 (mm-interactively-view-part data)))
3538 (defun gnus-mime-view-part-as-type-internal ()
3539 (gnus-article-check-buffer)
3540 (let* ((name (mail-content-type-get
3541 (mm-handle-type (get-text-property (point) 'gnus-data))
3543 (def-type (and name (mm-default-file-encoding name))))
3544 (and def-type (cons def-type 0))))
3546 (defun gnus-mime-view-part-as-type (mime-type)
3547 "Choose a MIME media type, and view the part as such."
3549 (list (completing-read
3550 "View as MIME type: "
3551 (mapcar #'list (mailcap-mime-types))
3553 (gnus-mime-view-part-as-type-internal))))
3554 (gnus-article-check-buffer)
3555 (let ((handle (get-text-property (point) 'gnus-data)))
3556 (gnus-mm-display-part
3557 (mm-make-handle (mm-handle-buffer handle)
3558 (cons mime-type (cdr (mm-handle-type handle)))
3559 (mm-handle-encoding handle)
3560 (mm-handle-undisplayer handle)
3561 (mm-handle-disposition handle)
3562 (mm-handle-description handle)
3563 (mm-handle-cache handle)
3564 (mm-handle-id handle)))))
3566 (defun gnus-mime-copy-part (&optional handle)
3567 "Put the the MIME part under point into a new buffer."
3569 (gnus-article-check-buffer)
3570 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3571 (contents (mm-get-part handle))|
3572 (base (file-name-nondirectory
3574 (mail-content-type-get (mm-handle-type handle) 'name)
3575 (mail-content-type-get (mm-handle-type handle)
3578 (buffer (generate-new-buffer base)))
3579 (switch-to-buffer buffer)
3581 ;; We do it this way to make `normal-mode' set the appropriate mode.
3584 (setq buffer-file-name (expand-file-name base))
3586 (setq buffer-file-name nil))
3587 (goto-char (point-min))))
3589 (defun gnus-mime-inline-part (&optional handle arg)
3590 "Insert the MIME part under point into the current buffer."
3591 (interactive (list nil current-prefix-arg))
3592 (gnus-article-check-buffer)
3593 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3597 (if (and (not arg) (mm-handle-undisplayer handle))
3598 (mm-remove-part handle)
3599 (setq contents (mm-get-part handle))
3602 (setq charset (or (mail-content-type-get
3603 (mm-handle-type handle) 'charset)
3604 gnus-newsgroup-charset)))
3606 (if (mm-handle-undisplayer handle)
3607 (mm-remove-part handle))
3610 gnus-summary-show-article-charset-alist))
3611 (read-coding-system "Charset: ")))))
3613 (mm-insert-inline handle
3615 (setq charset (mm-charset-to-coding-system
3617 (not (eq charset 'ascii)))
3618 (mm-decode-coding-string contents charset)
3622 (defun gnus-mime-view-part-as-charset (&optional handle arg)
3623 "Insert the MIME part under point into the current buffer."
3624 (interactive (list nil current-prefix-arg))
3625 (gnus-article-check-buffer)
3626 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3630 (if (mm-handle-undisplayer handle)
3631 (mm-remove-part handle))
3632 (let ((gnus-newsgroup-charset
3634 gnus-summary-show-article-charset-alist))
3635 (read-coding-system "Charset: ")))
3636 (gnus-newsgroup-ignored-charsets 'gnus-all))
3637 (gnus-article-press-button))))
3639 (defun gnus-mime-externalize-part (&optional handle)
3640 "View the MIME part under point with an external viewer."
3642 (gnus-article-check-buffer)
3643 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3644 (mm-user-display-methods nil)
3645 (mm-inlined-types nil)
3646 (mail-parse-charset gnus-newsgroup-charset)
3647 (mail-parse-ignored-charsets
3648 (save-excursion (set-buffer gnus-summary-buffer)
3649 gnus-newsgroup-ignored-charsets)))
3650 (if (mm-handle-undisplayer handle)
3651 (mm-remove-part handle)
3652 (mm-display-part handle))))
3654 (defun gnus-mime-internalize-part (&optional handle)
3655 "View the MIME part under point with an internal viewer.
3656 In no internal viewer is available, use an external viewer."
3658 (gnus-article-check-buffer)
3659 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
3660 (mm-inlined-types '(".*"))
3661 (mm-inline-large-images t)
3662 (mail-parse-charset gnus-newsgroup-charset)
3663 (mail-parse-ignored-charsets
3664 (save-excursion (set-buffer gnus-summary-buffer)
3665 gnus-newsgroup-ignored-charsets)))
3666 (if (mm-handle-undisplayer handle)
3667 (mm-remove-part handle)
3668 (mm-display-part handle))))
3670 (defun gnus-mime-action-on-part (&optional action)
3671 "Do something with the MIME attachment at \(point\)."
3673 (list (completing-read "Action: " gnus-mime-action-alist)))
3674 (gnus-article-check-buffer)
3675 (let ((action-pair (assoc action gnus-mime-action-alist)))
3677 (funcall (cdr action-pair)))))
3680 (defun gnus-article-part-wrapper (n function)
3681 (save-current-buffer
3682 (set-buffer gnus-article-buffer)
3683 (when (> n (length gnus-article-mime-handle-alist))
3684 (error "No such part"))
3685 (gnus-article-goto-part n)
3686 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3687 (funcall function handle))))
3689 (defun gnus-article-pipe-part (n)
3690 "Pipe MIME part N, which is the numerical prefix."
3692 (gnus-article-part-wrapper n 'mm-pipe-part))
3694 (defun gnus-article-save-part (n)
3695 "Save MIME part N, which is the numerical prefix."
3697 (gnus-article-part-wrapper n 'mm-save-part))
3699 (defun gnus-article-interactively-view-part (n)
3700 "View MIME part N interactively, which is the numerical prefix."
3702 (gnus-article-part-wrapper n 'mm-interactively-view-part))
3704 (defun gnus-article-copy-part (n)
3705 "Copy MIME part N, which is the numerical prefix."
3707 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
3709 (defun gnus-article-view-part-as-charset (n)
3710 "Copy MIME part N, which is the numerical prefix."
3712 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
3714 (defun gnus-article-externalize-part (n)
3715 "View MIME part N externally, which is the numerical prefix."
3717 (gnus-article-part-wrapper n 'gnus-mime-externalize-part))
3719 (defun gnus-article-inline-part (n)
3720 "Inline MIME part N, which is the numerical prefix."
3722 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
3724 (defun gnus-article-mime-match-handle-first (condition)
3726 (let ((alist gnus-article-mime-handle-alist) ihandle n)
3727 (while (setq ihandle (pop alist))
3729 ((functionp condition)
3730 (funcall condition (cdr ihandle)))
3731 ((eq condition 'undisplayed)
3732 (not (or (mm-handle-undisplayer (cdr ihandle))
3733 (equal (mm-handle-media-type (cdr ihandle))
3734 "multipart/alternative"))))
3735 ((eq condition 'undisplayed-alternative)
3736 (not (mm-handle-undisplayer (cdr ihandle))))
3738 (gnus-article-goto-part (car ihandle))
3739 (or (not n) (< (car ihandle) n)))
3740 (setq n (car ihandle))))
3744 (defun gnus-article-view-part (&optional n)
3745 "View MIME part N, which is the numerical prefix."
3747 (save-current-buffer
3748 (set-buffer gnus-article-buffer)
3749 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
3750 gnus-article-mime-match-handle-function)))
3751 (when (> n (length gnus-article-mime-handle-alist))
3752 (error "No such part"))
3753 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
3754 (when (gnus-article-goto-part n)
3755 (if (equal (car handle) "multipart/alternative")
3756 (gnus-article-press-button)
3757 (when (eq (gnus-mm-display-part handle) 'internal)
3758 (gnus-set-window-start)))))))
3760 (defsubst gnus-article-mime-total-parts ()
3761 (if (bufferp (car gnus-article-mime-handles))
3763 (1- (length gnus-article-mime-handles))))
3765 (defun gnus-mm-display-part (handle)
3766 "Display HANDLE and fix MIME button."
3767 (let ((id (get-text-property (point) 'gnus-part))
3772 (let ((window (selected-window))
3773 (mail-parse-charset gnus-newsgroup-charset)
3774 (mail-parse-ignored-charsets
3775 (save-excursion (set-buffer gnus-summary-buffer)
3776 gnus-newsgroup-ignored-charsets)))
3779 (let ((win (get-buffer-window (current-buffer) t))
3782 (select-window win))
3785 (if (mm-handle-displayed-p handle)
3786 ;; This will remove the part.
3787 (mm-display-part handle)
3789 (narrow-to-region (point) (1+ (point)))
3790 (mm-display-part handle)
3791 ;; We narrow to the part itself and
3792 ;; then call the treatment functions.
3793 (goto-char (point-min))
3795 (narrow-to-region (point) (point-max))
3798 (gnus-article-mime-total-parts)
3799 (mm-handle-media-type handle)))))
3800 (select-window window))))
3802 (delete-region (gnus-point-at-bol) (progn (forward-line 1) (point)))
3803 (gnus-insert-mime-button
3804 handle id (list (mm-handle-displayed-p handle)))
3805 (goto-char point))))
3807 (defun gnus-article-goto-part (n)
3808 "Go to MIME part N."
3809 (let ((point (text-property-any (point-min) (point-max) 'gnus-part n)))
3811 (goto-char point))))
3813 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
3814 (let ((gnus-tmp-name
3815 (or (mail-content-type-get (mm-handle-type handle)
3817 (mail-content-type-get (mm-handle-disposition handle)
3819 (mail-content-type-get (mm-handle-type handle)
3822 (gnus-tmp-type (mm-handle-media-type handle))
3823 (gnus-tmp-description
3824 (mail-decode-encoded-word-string (or (mm-handle-description handle)
3827 (if (if displayed (car displayed)
3828 (mm-handle-displayed-p handle))
3830 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
3832 gnus-tmp-type-long b e)
3833 (when (string-match ".*/" gnus-tmp-name)
3834 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
3835 (setq gnus-tmp-type-long (concat gnus-tmp-type
3836 (and (not (equal gnus-tmp-name ""))
3837 (concat "; " gnus-tmp-name))))
3838 (or (equal gnus-tmp-description "")
3839 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
3844 gnus-mime-button-line-format gnus-mime-button-line-format-alist
3845 `(local-map ,gnus-mime-button-map
3846 keymap ,gnus-mime-button-map
3847 gnus-callback gnus-mm-display-part
3848 gnus-part ,gnus-tmp-id
3849 article-type annotation
3852 (widget-convert-button
3855 :action 'gnus-widget-press-button
3856 :button-keymap gnus-mime-button-map
3858 (lambda (widget/window &optional overlay pos)
3859 ;; Needed to properly clear the message due to a bug in
3860 ;; wid-edit (XEmacs only).
3861 (if (boundp 'help-echo-owns-message)
3862 (setq help-echo-owns-message t))
3864 "%S: %s the MIME part; %S: more options"
3865 (aref gnus-mouse-2 0)
3866 ;; XEmacs will get a single widget arg; Emacs 21 will get
3867 ;; window, overlay, position.
3868 (if (mm-handle-displayed-p
3870 (with-current-buffer (gnus-overlay-buffer overlay)
3871 (widget-get (widget-at (gnus-overlay-start overlay))
3873 (widget-get widget/window :mime-handle)))
3875 (aref gnus-down-mouse-3 0))))))
3877 (defun gnus-widget-press-button (elems el)
3878 (goto-char (widget-get elems :from))
3879 (gnus-article-press-button))
3881 (defvar gnus-displaying-mime nil)
3883 (defun gnus-display-mime (&optional ihandles)
3884 "Display the MIME parts."
3886 (save-selected-window
3887 (let ((window (get-buffer-window gnus-article-buffer))
3890 (select-window window)
3891 ;; We have to do this since selecting the window
3892 ;; may change the point. So we set the window point.
3893 (set-window-point window point)))
3894 (let* ((handles (or ihandles (mm-dissect-buffer) (mm-uu-dissect)))
3895 buffer-read-only handle name type b e display)
3896 (when (and (not ihandles)
3897 (not gnus-displaying-mime))
3898 ;; Top-level call; we clean up.
3899 (when gnus-article-mime-handles
3900 (mm-destroy-parts gnus-article-mime-handles)
3901 (setq gnus-article-mime-handle-alist nil));; A trick.
3902 (setq gnus-article-mime-handles handles)
3903 ;; We allow users to glean info from the handles.
3904 (when gnus-article-mime-part-function
3905 (gnus-mime-part-function handles)))
3907 (or (not (stringp (car handles)))
3910 (when (and (not ihandles)
3911 (not gnus-displaying-mime))
3912 ;; Clean up for mime parts.
3914 (delete-region (point) (point-max)))
3915 (let ((gnus-displaying-mime t))
3916 (gnus-mime-display-part handles)))
3919 (narrow-to-region (point) (point-max))
3920 (gnus-treat-article nil 1 1)
3923 ;; Highlight the headers.
3927 (narrow-to-region (point-min) (point))
3928 (gnus-treat-article 'head))))))))
3930 (defvar gnus-mime-display-multipart-as-mixed nil)
3932 (defun gnus-mime-display-part (handle)
3935 ((not (stringp (car handle)))
3936 (gnus-mime-display-single handle))
3937 ;; User-defined multipart
3938 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
3939 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
3941 ;; multipart/alternative
3942 ((and (equal (car handle) "multipart/alternative")
3943 (not gnus-mime-display-multipart-as-mixed))
3944 (let ((id (1+ (length gnus-article-mime-handle-alist))))
3945 (push (cons id handle) gnus-article-mime-handle-alist)
3946 (gnus-mime-display-alternative (cdr handle) nil nil id)))
3947 ;; multipart/related
3948 ((and (equal (car handle) "multipart/related")
3949 (not gnus-mime-display-multipart-as-mixed))
3950 ;;;!!!We should find the start part, but we just default
3951 ;;;!!!to the first part.
3952 ;;(gnus-mime-display-part (cadr handle))
3953 ;;;!!! Most multipart/related is an HTML message plus images.
3954 ;;;!!! Unfortunately we are unable to let W3 display those
3955 ;;;!!! included images, so we just display it as a mixed multipart.
3956 (gnus-mime-display-mixed (cdr handle)))
3957 ((equal (car handle) "multipart/signed")
3958 (or (memq 'signed gnus-article-wash-types)
3959 (push 'signed gnus-article-wash-types))
3960 (gnus-mime-display-security handle))
3961 ((equal (car handle) "multipart/encrypted")
3962 (or (memq 'encrypted gnus-article-wash-types)
3963 (push 'encrypted gnus-article-wash-types))
3964 (gnus-mime-display-security handle))
3965 ;; Other multiparts are handled like multipart/mixed.
3967 (gnus-mime-display-mixed (cdr handle)))))
3969 (defun gnus-mime-part-function (handles)
3970 (if (stringp (car handles))
3971 (mapcar 'gnus-mime-part-function (cdr handles))
3972 (funcall gnus-article-mime-part-function handles)))
3974 (defun gnus-mime-display-mixed (handles)
3975 (mapcar 'gnus-mime-display-part handles))
3977 (defun gnus-mime-display-single (handle)
3978 (let ((type (mm-handle-media-type handle))
3979 (ignored gnus-ignored-mime-types)
3986 (when (string-match (pop ignored) type)
3987 (throw 'ignored nil)))
3988 (if (and (setq not-attachment
3989 (and (not (mm-inline-override-p handle))
3990 (or (not (mm-handle-disposition handle))
3991 (equal (car (mm-handle-disposition handle))
3993 (mm-attachment-override-p handle))))
3994 (mm-automatic-display-p handle)
3995 (or (mm-inlined-p handle)
3996 (mm-automatic-external-display-p type)))
3998 (when (equal (mm-handle-media-supertype handle) "text")
4000 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4002 (push (cons id handle) gnus-article-mime-handle-alist)
4003 (when (or (not display)
4004 (not (gnus-unbuttonized-mime-type-p type)))
4005 ;(gnus-article-insert-newline)
4006 (gnus-insert-mime-button
4007 handle id (list (or display (and not-attachment text))))
4008 (gnus-article-insert-newline)
4009 ;(gnus-article-insert-newline)
4010 ;; Remember modify the number of forward lines.
4018 (let ((mail-parse-charset gnus-newsgroup-charset)
4019 (mail-parse-ignored-charsets
4020 (save-excursion (condition-case ()
4021 (set-buffer gnus-summary-buffer)
4023 gnus-newsgroup-ignored-charsets)))
4024 (mm-display-part handle t))
4025 (goto-char (point-max)))
4026 ((and text not-attachment)
4030 (gnus-article-insert-newline)
4031 (mm-insert-inline handle (mm-get-part handle))
4032 (goto-char (point-max))))
4036 (narrow-to-region beg (point))
4039 (gnus-article-mime-total-parts)
4040 (mm-handle-media-type handle)))))))))
4042 (defun gnus-unbuttonized-mime-type-p (type)
4043 "Say whether TYPE is to be unbuttonized."
4044 (unless gnus-inhibit-mime-unbuttonizing
4046 (let ((types gnus-unbuttonized-mime-types))
4048 (when (string-match (pop types) type)
4049 (throw 'found t)))))))
4051 (defun gnus-article-insert-newline ()
4052 "Insert a newline, but mark it as undeletable."
4053 (gnus-put-text-property
4054 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4056 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4057 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4060 handle buffer-read-only from props begend not-pref)
4061 (save-window-excursion
4064 (narrow-to-region (car ibegend)
4067 (goto-char (car ibegend))
4070 (delete-region (point-min) (point-max))
4071 (mm-remove-parts handles))
4072 (setq begend (list (point-marker)))
4074 (unless (setq not-pref (cadr (member preferred ihandles)))
4075 (setq not-pref (car ihandles)))
4078 (not (gnus-unbuttonized-mime-type-p
4079 "multipart/alternative")))
4080 (gnus-add-text-properties
4083 (insert (format "%d. " id))
4087 (unless ,(not ibegend)
4088 (setq gnus-article-mime-handle-alist
4089 ',gnus-article-mime-handle-alist))
4090 (gnus-mime-display-alternative
4091 ',ihandles ',not-pref ',begend ,id))
4092 local-map ,gnus-mime-button-map
4093 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4094 face ,gnus-article-button-face
4095 keymap ,gnus-mime-button-map
4098 (widget-convert-button 'link from (point)
4099 :action 'gnus-widget-press-button
4100 :button-keymap gnus-widget-button-keymap)
4102 (while (setq handle (pop handles))
4103 (gnus-add-text-properties
4106 (insert (format "(%c) %-18s"
4107 (if (equal handle preferred) ?* ? )
4108 (mm-handle-media-type handle)))
4112 (unless ,(not ibegend)
4113 (setq gnus-article-mime-handle-alist
4114 ',gnus-article-mime-handle-alist))
4115 (gnus-mime-display-alternative
4116 ',ihandles ',handle ',begend ,id))
4117 local-map ,gnus-mime-button-map
4118 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4119 face ,gnus-article-button-face
4120 keymap ,gnus-mime-button-map
4123 (widget-convert-button 'link from (point)
4124 :action 'gnus-widget-press-button
4125 :button-keymap gnus-widget-button-keymap)
4129 (if (stringp (car preferred))
4130 (gnus-display-mime preferred)
4131 (let ((mail-parse-charset gnus-newsgroup-charset)
4132 (mail-parse-ignored-charsets
4133 (save-excursion (set-buffer gnus-summary-buffer)
4134 gnus-newsgroup-ignored-charsets)))
4135 (mm-display-part preferred)
4139 (narrow-to-region (car begend) (point-max))
4141 nil (length gnus-article-mime-handle-alist)
4142 (gnus-article-mime-total-parts)
4143 (mm-handle-media-type handle))))))
4144 (goto-char (point-max))
4145 (setcdr begend (point-marker)))))
4147 (goto-char point))))
4149 (defun gnus-article-wash-status ()
4150 "Return a string which display status of article washing."
4152 (set-buffer gnus-article-buffer)
4153 (let ((cite (memq 'cite gnus-article-wash-types))
4154 (headers (memq 'headers gnus-article-wash-types))
4155 (boring (memq 'boring-headers gnus-article-wash-types))
4156 (pgp (memq 'pgp gnus-article-wash-types))
4157 (pem (memq 'pem gnus-article-wash-types))
4158 (signed (memq 'signed gnus-article-wash-types))
4159 (encrypted (memq 'encrypted gnus-article-wash-types))
4160 (signature (memq 'signature gnus-article-wash-types))
4161 (overstrike (memq 'overstrike gnus-article-wash-types))
4162 (emphasis (memq 'emphasis gnus-article-wash-types)))
4163 (format "%c%c%c%c%c%c%c"
4165 (if (or headers boring) ?h ? )
4166 (if (or pgp pem signed encrypted) ?p ? )
4167 (if signature ?s ? )
4168 (if overstrike ?o ? )
4169 (if gnus-show-mime ?m ? )
4170 (if emphasis ?e ? )))))
4172 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4174 (defun gnus-article-maybe-hide-headers ()
4175 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4176 Provided for backwards compatibility."
4177 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4178 (not (save-excursion (set-buffer gnus-summary-buffer)
4179 gnus-have-all-headers)))
4180 (not gnus-inhibit-hiding))
4181 (gnus-article-hide-headers)))
4185 (defun gnus-output-to-file (file-name)
4186 "Append the current article to a file named FILE-NAME."
4187 (let ((artbuf (current-buffer)))
4189 (insert-buffer-substring artbuf)
4190 ;; Append newline at end of the buffer as separator, and then
4192 (goto-char (point-max))
4194 (write-region-as-binary (point-min) (point-max) file-name 'append)
4197 (defun gnus-narrow-to-page (&optional arg)
4198 "Narrow the article buffer to a page.
4199 If given a numerical ARG, move forward ARG pages."
4201 (setq arg (if arg (prefix-numeric-value arg) 0))
4203 (set-buffer gnus-article-buffer)
4204 (goto-char (point-min))
4206 ;; Remove any old next/prev buttons.
4207 (when (gnus-visual-p 'page-marker)
4208 (let ((buffer-read-only nil))
4209 (gnus-remove-text-with-property 'gnus-prev)
4210 (gnus-remove-text-with-property 'gnus-next)))
4213 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
4215 (re-search-forward page-delimiter nil 'move arg)))
4216 (goto-char (match-end 0)))
4219 (if (re-search-forward page-delimiter nil 'move)
4222 (when (and (gnus-visual-p 'page-marker)
4223 (not (= (point-min) 1)))
4225 (goto-char (point-min))
4226 (gnus-insert-prev-page-button)))
4227 (when (and (gnus-visual-p 'page-marker)
4228 (< (+ (point-max) 2) (buffer-size)))
4230 (goto-char (point-max))
4231 (gnus-insert-next-page-button)))))
4233 ;; Article mode commands
4235 (defun gnus-article-goto-next-page ()
4236 "Show the next page of the article."
4238 (when (gnus-article-next-page)
4239 (goto-char (point-min))
4240 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
4242 (defun gnus-article-goto-prev-page ()
4243 "Show the next page of the article."
4245 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
4246 (gnus-article-prev-page nil)))
4248 (defun gnus-article-next-page (&optional lines)
4249 "Show the next page of the current article.
4250 If end of article, return non-nil. Otherwise return nil.
4251 Argument LINES specifies lines to be scrolled up."
4253 (let ((start (window-start))
4254 end-of-buffer end-of-page)
4256 (move-to-window-line -1)
4257 (if (<= (point) start)
4260 (setq start (point)))
4263 (unless (or (cond ((eq (1+ (buffer-size)) (point))
4264 (and (pos-visible-in-window-p)
4265 (setq end-of-buffer t)))
4267 (setq end-of-page t)))
4269 (move-to-window-line lines)
4270 (unless (search-backward "\n\n" nil t)
4271 (setq start (point)))))
4272 (cond (end-of-buffer t)
4274 (gnus-narrow-to-page 1)
4278 (set-window-start (selected-window) start)
4279 (let (window-pixel-scroll-increment)
4283 (defun gnus-article-prev-page (&optional lines)
4284 "Show previous page of current article.
4285 Argument LINES specifies lines to be scrolled down."
4287 (let (beginning-of-buffer beginning-of-page)
4289 (move-to-window-line 0)
4290 (cond ((eq 1 (point))
4291 (setq beginning-of-buffer t))
4293 (setq beginning-of-page t))))
4294 (cond (beginning-of-buffer)
4296 (gnus-narrow-to-page -1))
4299 (let (window-pixel-scroll-increment)
4300 (scroll-down lines))
4301 (beginning-of-buffer
4302 (goto-char (point-min))))))))
4304 (defun gnus-article-refer-article ()
4305 "Read article specified by message-id around point."
4307 (let ((point (point)))
4308 (search-forward ">" nil t) ;Move point to end of "<....>".
4309 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
4310 (let ((message-id (match-string 1)))
4312 (set-buffer gnus-summary-buffer)
4313 (gnus-summary-refer-article message-id))
4315 (error "No references around point"))))
4317 (defun gnus-article-show-summary ()
4318 "Reconfigure windows to show summary buffer."
4320 (if (not (gnus-buffer-live-p gnus-summary-buffer))
4321 (error "There is no summary buffer for this article buffer")
4322 (gnus-article-set-globals)
4323 (gnus-configure-windows 'article)
4324 (gnus-summary-goto-subject gnus-current-article)
4325 (gnus-summary-position-point)))
4327 (defun gnus-article-describe-briefly ()
4328 "Describe article mode commands briefly."
4330 (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")))
4332 (defun gnus-article-summary-command ()
4333 "Execute the last keystroke in the summary buffer."
4335 (let ((obuf (current-buffer))
4336 (owin (current-window-configuration))
4338 (switch-to-buffer gnus-article-current-summary 'norecord)
4339 (setq func (lookup-key (current-local-map) (this-command-keys)))
4340 (call-interactively func)
4342 (set-window-configuration owin)
4343 (set-window-point (get-buffer-window (current-buffer)) (point))))
4345 (defun gnus-article-summary-command-nosave ()
4346 "Execute the last keystroke in the summary buffer."
4349 (pop-to-buffer gnus-article-current-summary 'norecord)
4350 (setq func (lookup-key (current-local-map) (this-command-keys)))
4351 (call-interactively func)))
4353 (defun gnus-article-check-buffer ()
4354 "Beep if not in an article buffer."
4355 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
4356 (error "Command invoked outside of a Gnus article buffer")))
4358 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
4359 "Read a summary buffer key sequence and execute it from the article buffer."
4361 (gnus-article-check-buffer)
4363 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F"
4364 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
4365 "=" "^" "\M-^" "|"))
4371 '("n" "Gn" "p" "Gp"))
4374 (set-buffer gnus-article-current-summary)
4375 (let (gnus-pick-mode)
4376 (push (or key last-command-event) unread-command-events)
4377 (setq keys (static-if (featurep 'xemacs)
4378 (events-to-keys (read-key-sequence nil))
4379 (read-key-sequence nil)))))
4382 (if (or (member keys nosaves)
4383 (member keys nosave-but-article)
4384 (member keys nosave-in-article))
4386 (save-window-excursion
4387 (pop-to-buffer gnus-article-current-summary 'norecord)
4388 ;; We disable the pick minor mode commands.
4389 (let (gnus-pick-mode)
4390 (setq func (lookup-key (current-local-map) keys))))
4394 (unless (member keys nosave-in-article)
4395 (set-buffer gnus-article-current-summary))
4396 (call-interactively func)
4397 (setq new-sum-point (point)))
4398 (when (member keys nosave-but-article)
4399 (pop-to-buffer gnus-article-buffer 'norecord)))
4400 ;; These commands should restore window configuration.
4401 (let ((obuf (current-buffer))
4402 (owin (current-window-configuration))
4404 (summary gnus-article-current-summary)
4405 func in-buffer selected)
4406 (if not-restore-window
4407 (pop-to-buffer summary 'norecord)
4408 (switch-to-buffer summary 'norecord))
4409 (setq in-buffer (current-buffer))
4410 ;; We disable the pick minor mode commands.
4411 (if (and (setq func (let (gnus-pick-mode)
4412 (lookup-key (current-local-map) keys)))
4415 (call-interactively func)
4416 (setq new-sum-point (point))
4417 (when (eq in-buffer (current-buffer))
4418 (setq selected (gnus-summary-select-article))
4420 (unless not-restore-window
4421 (set-window-configuration owin))
4422 (when (eq selected 'old)
4424 (set-window-start (get-buffer-window (current-buffer))
4426 (set-window-point (get-buffer-window (current-buffer))
4428 (let ((win (get-buffer-window gnus-article-current-summary)))
4430 (set-window-point win new-sum-point)))) )
4431 (switch-to-buffer gnus-article-buffer)
4434 (defun gnus-article-describe-key (key)
4435 "Display documentation of the function invoked by KEY. KEY is a string."
4436 (interactive "kDescribe key: ")
4437 (gnus-article-check-buffer)
4438 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4440 (set-buffer gnus-article-current-summary)
4441 (let (gnus-pick-mode)
4442 (push (elt key 0) unread-command-events)
4443 (setq key (if (featurep 'xemacs)
4444 (events-to-keys (read-key-sequence "Describe key: "))
4445 (read-key-sequence "Describe key: "))))
4447 (describe-key key)))
4449 (defun gnus-article-describe-key-briefly (key &optional insert)
4450 "Display documentation of the function invoked by KEY. KEY is a string."
4451 (interactive "kDescribe key: \nP")
4452 (gnus-article-check-buffer)
4453 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
4455 (set-buffer gnus-article-current-summary)
4456 (let (gnus-pick-mode)
4457 (push (elt key 0) unread-command-events)
4458 (setq key (if (featurep 'xemacs)
4459 (events-to-keys (read-key-sequence "Describe key: "))
4460 (read-key-sequence "Describe key: "))))
4461 (describe-key-briefly key insert))
4462 (describe-key-briefly key insert)))
4464 (defun gnus-article-hide (&optional arg force)
4465 "Hide all the gruft in the current article.
4466 This means that PGP stuff, signatures, cited text and (some)
4467 headers will be hidden.
4468 If given a prefix, show the hidden text instead."
4469 (interactive (append (gnus-article-hidden-arg) (list 'force)))
4470 (gnus-article-hide-headers arg)
4471 (gnus-article-hide-list-identifiers arg)
4472 (gnus-article-hide-pgp arg)
4473 (gnus-article-hide-citation-maybe arg force)
4474 (gnus-article-hide-signature arg))
4476 (defun gnus-article-maybe-highlight ()
4477 "Do some article highlighting if article highlighting is requested."
4478 (when (gnus-visual-p 'article-highlight 'highlight)
4479 (gnus-article-highlight-some)))
4481 (defun gnus-check-group-server ()
4482 ;; Make sure the connection to the server is alive.
4483 (unless (gnus-server-opened
4484 (gnus-find-method-for-group gnus-newsgroup-name))
4485 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
4486 (gnus-request-group gnus-newsgroup-name t)))
4488 (defun gnus-request-article-this-buffer (article group)
4489 "Get an article and insert it into this buffer."
4490 (let (do-update-line sparse-header)
4494 (gnus-kill-all-overlays)
4495 (setq group (or group gnus-newsgroup-name))
4497 ;; Using `gnus-request-article' directly will insert the article into
4498 ;; `nntp-server-buffer' - so we'll save some time by not having to
4499 ;; copy it from the server buffer into the article buffer.
4501 ;; We only request an article by message-id when we do not have the
4502 ;; headers for it, so we'll have to get those.
4503 (when (stringp article)
4504 (gnus-read-header article))
4506 ;; If the article number is negative, that means that this article
4507 ;; doesn't belong in this newsgroup (possibly), so we find its
4508 ;; message-id and request it by id instead of number.
4509 (when (and (numberp article)
4511 (get-buffer gnus-summary-buffer)
4512 (gnus-buffer-exists-p gnus-summary-buffer))
4514 (set-buffer gnus-summary-buffer)
4515 (let ((header (gnus-summary-article-header article)))
4518 ((memq article gnus-newsgroup-sparse)
4519 ;; This is a sparse gap article.
4520 (setq do-update-line article)
4521 (setq article (mail-header-id header))
4522 (setq sparse-header (gnus-read-header article))
4523 (setq gnus-newsgroup-sparse
4524 (delq article gnus-newsgroup-sparse)))
4526 ;; It's a real article.
4527 (setq article (mail-header-id header)))
4529 ;; It is an extracted pseudo-article.
4530 (setq article 'pseudo)
4531 (gnus-request-pseudo-article header))))
4533 (let ((method (gnus-find-method-for-group
4534 gnus-newsgroup-name)))
4535 (when (and (eq (car method) 'nneething)
4537 (let ((dir (expand-file-name
4538 (mail-header-subject header)
4539 (file-name-as-directory
4540 (or (cadr (assq 'nneething-address method))
4542 (when (file-directory-p dir)
4543 (setq article 'nneething)
4544 (gnus-group-enter-directory dir))))))))
4547 ;; Refuse to select canceled articles.
4548 ((and (numberp article)
4550 (get-buffer gnus-summary-buffer)
4551 (gnus-buffer-exists-p gnus-summary-buffer)
4552 (eq (cdr (save-excursion
4553 (set-buffer gnus-summary-buffer)
4554 (assq article gnus-newsgroup-reads)))
4555 gnus-canceled-mark))
4557 ;; Check the backlog.
4558 ((and gnus-keep-backlog
4559 (gnus-backlog-request-article group article (current-buffer)))
4561 ;; Check asynchronous pre-fetch.
4562 ((gnus-async-request-fetched-article group article (current-buffer))
4563 (gnus-async-prefetch-next group article gnus-summary-buffer)
4564 (when (and (numberp article) gnus-keep-backlog)
4565 (gnus-backlog-enter-article group article (current-buffer)))
4568 ((and gnus-use-cache
4570 (gnus-cache-request-article article group))
4572 ;; Get the article and put into the article buffer.
4573 ((or (stringp article)
4575 (let ((gnus-override-method gnus-override-method)
4576 (methods (and (stringp article)
4577 gnus-refer-article-method))
4579 (buffer-read-only nil))
4580 (if (or (not (listp methods))
4581 (and (symbolp (car methods))
4582 (assq (car methods) nnoo-definition-alist)))
4583 (setq methods (list methods)))
4584 (when (and (null gnus-override-method)
4586 (setq gnus-override-method (pop methods)))
4588 (when (eq gnus-override-method 'current)
4589 (setq gnus-override-method gnus-current-select-method))
4591 (gnus-kill-all-overlays)
4592 (let ((gnus-newsgroup-name group))
4593 (gnus-check-group-server))
4594 (when (gnus-request-article article group (current-buffer))
4595 (when (numberp article)
4596 (gnus-async-prefetch-next group article
4597 gnus-summary-buffer)
4598 (when gnus-keep-backlog
4599 (gnus-backlog-enter-article
4600 group article (current-buffer))))
4601 (setq result 'article))
4604 (setq gnus-override-method (pop methods))
4605 (setq result 'done))))
4606 (and (eq result 'article) 'article)))
4610 ;; Associate this article with the current summary buffer.
4611 (setq gnus-article-current-summary gnus-summary-buffer)
4613 ;; Take the article from the original article buffer
4614 ;; and place it in the buffer it's supposed to be in.
4615 (when (and (get-buffer gnus-article-buffer)
4616 (equal (buffer-name (current-buffer))
4617 (buffer-name (get-buffer gnus-article-buffer))))
4619 (if (get-buffer gnus-original-article-buffer)
4620 (set-buffer gnus-original-article-buffer)
4621 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4622 (set-buffer-multibyte nil)
4623 (buffer-disable-undo)
4624 (setq major-mode 'gnus-original-article-mode)
4625 (setq buffer-read-only t))
4626 (let (buffer-read-only)
4628 (insert-buffer-substring gnus-article-buffer))
4629 (setq gnus-original-article (cons group article)))
4632 (run-hooks 'gnus-article-decode-hook)
4633 ;; Mark article as decoded or not.
4634 (setq gnus-article-decoded-p gnus-article-decode-hook))
4636 ;; Update sparse articles.
4637 (when (and do-update-line
4638 (or (numberp article)
4640 (let ((buf (current-buffer)))
4641 (set-buffer gnus-summary-buffer)
4642 (gnus-summary-update-article do-update-line sparse-header)
4643 (gnus-summary-goto-subject do-update-line nil t)
4644 (set-window-point (get-buffer-window (current-buffer) t)
4646 (set-buffer buf))))))
4652 (defcustom gnus-article-edit-mode-hook nil
4653 "Hook run in article edit mode buffers."
4654 :group 'gnus-article-various
4657 (defcustom gnus-article-edit-article-setup-function
4658 'gnus-article-mime-edit-article-setup
4659 "Function called to setup an editing article buffer."
4660 :group 'gnus-article-various
4663 (defvar gnus-article-edit-done-function nil)
4665 (defvar gnus-article-edit-mode-map nil)
4667 ;; Should we be using derived.el for this?
4668 (unless gnus-article-edit-mode-map
4669 (setq gnus-article-edit-mode-map (make-sparse-keymap))
4670 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
4672 (gnus-define-keys gnus-article-edit-mode-map
4673 "\C-c\C-c" gnus-article-edit-done
4674 "\C-c\C-k" gnus-article-edit-exit)
4676 (gnus-define-keys (gnus-article-edit-wash-map
4677 "\C-c\C-w" gnus-article-edit-mode-map)
4678 "f" gnus-article-edit-full-stops))
4680 (defun gnus-article-edit-mode ()
4681 "Major mode for editing articles.
4682 This is an extended text-mode.
4684 \\{gnus-article-edit-mode-map}"
4686 (setq major-mode 'gnus-article-edit-mode)
4687 (setq mode-name "Article Edit")
4688 (use-local-map gnus-article-edit-mode-map)
4689 (make-local-variable 'gnus-article-edit-done-function)
4690 (make-local-variable 'gnus-prev-winconf)
4691 (setq buffer-read-only nil)
4692 (buffer-enable-undo)
4694 (gnus-run-hooks 'text-mode-hook 'gnus-article-edit-mode-hook))
4696 (defun gnus-article-edit (&optional force)
4697 "Edit the current article.
4698 This will have permanent effect only in mail groups.
4699 If FORCE is non-nil, allow editing of articles even in read-only
4702 (when (and (not force)
4703 (gnus-group-read-only-p))
4704 (error "The current newsgroup does not support article editing"))
4705 (gnus-article-date-original)
4706 (gnus-article-edit-article
4708 `(lambda (no-highlight)
4710 (gnus-summary-edit-article-done
4711 ,(or (mail-header-references gnus-current-headers) "")
4712 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
4714 (defun gnus-article-edit-article (start-func exit-func)
4715 "Start editing the contents of the current article buffer."
4716 (let ((winconf (current-window-configuration)))
4717 (set-buffer gnus-article-buffer)
4718 (gnus-article-edit-mode)
4719 (funcall start-func)
4720 (gnus-configure-windows 'edit-article)
4721 (setq gnus-article-edit-done-function exit-func)
4722 (setq gnus-prev-winconf winconf)
4723 (when gnus-article-edit-article-setup-function
4724 (funcall gnus-article-edit-article-setup-function))
4725 (gnus-message 6 "C-c C-c to end edits")))
4727 (defun gnus-article-edit-done (&optional arg)
4728 "Update the article edits and exit."
4730 (let ((func gnus-article-edit-done-function)
4731 (buf (current-buffer))
4732 (start (window-start)))
4733 (remove-hook 'gnus-article-mode-hook
4734 'gnus-article-mime-edit-article-unwind)
4735 (gnus-article-edit-exit)
4738 (let ((buffer-read-only nil))
4740 ;; The cache and backlog have to be flushed somewhat.
4741 (when gnus-keep-backlog
4742 (gnus-backlog-remove-article
4743 (car gnus-article-current) (cdr gnus-article-current)))
4744 ;; Flush original article as well.
4746 (when (get-buffer gnus-original-article-buffer)
4747 (set-buffer gnus-original-article-buffer)
4748 (setq gnus-original-article nil)))
4749 (when gnus-use-cache
4750 (gnus-cache-update-article
4751 (car gnus-article-current) (cdr gnus-article-current))))
4753 (set-window-start (get-buffer-window buf) start)
4754 (set-window-point (get-buffer-window buf) (point))))
4756 (defun gnus-article-edit-exit ()
4757 "Exit the article editing without updating."
4759 ;; We remove all text props from the article buffer.
4760 (let ((buf (buffer-substring-no-properties (point-min) (point-max)))
4761 (curbuf (current-buffer))
4763 (window-start (window-start)))
4766 (let ((winconf gnus-prev-winconf))
4768 (set-window-configuration winconf)
4769 ;; Tippy-toe some to make sure that point remains where it was.
4770 (save-current-buffer
4772 (set-window-start (get-buffer-window (current-buffer)) window-start)
4775 (defun gnus-article-edit-full-stops ()
4776 "Interactively repair spacing at end of sentences."
4779 (goto-char (point-min))
4780 (search-forward-regexp "^$" nil t)
4781 (let ((case-fold-search nil))
4782 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
4785 ;;; Article editing with MIME-Edit
4788 (defcustom gnus-article-mime-edit-article-setup-hook nil
4789 "Hook run after setting up a MIME editing article buffer."
4790 :group 'gnus-article-various
4793 (defun gnus-article-mime-edit-article-unwind ()
4794 "Unwind `gnus-article-buffer' if article editing was given up."
4795 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4796 (when mime-edit-mode-flag
4797 (mime-edit-exit 'nomime 'no-error)
4799 (when (featurep 'font-lock)
4800 (setq font-lock-defaults nil)
4801 (font-lock-mode 0)))
4803 (defun gnus-article-mime-edit-article-setup ()
4804 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
4805 after replacing with the original article."
4806 (setq gnus-show-mime t)
4807 (setq gnus-article-edit-done-function
4808 `(lambda (&rest args)
4809 (when mime-edit-mode-flag
4812 (goto-char (point-min))
4813 (let (case-fold-search)
4814 (when (re-search-forward
4815 (format "^%s$" (regexp-quote mail-header-separator))
4817 (replace-match "")))
4818 (when (featurep 'font-lock)
4819 (setq font-lock-defaults nil)
4821 (apply ,gnus-article-edit-done-function args)
4822 (set-buffer gnus-original-article-buffer)
4824 (insert-buffer gnus-article-buffer)
4825 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4826 (gnus-article-prepare-display)))
4827 (substitute-key-definition
4828 'gnus-article-edit-exit 'gnus-article-mime-edit-exit
4829 gnus-article-edit-mode-map)
4831 (insert-buffer gnus-original-article-buffer)
4833 (when (featurep 'font-lock)
4834 (set (make-local-variable 'font-lock-defaults)
4835 '(message-font-lock-keywords t))
4836 (font-lock-set-defaults)
4837 (turn-on-font-lock))
4838 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
4839 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
4841 (defun gnus-article-mime-edit-exit ()
4842 "Exit the article MIME editing without updating."
4844 (let ((winconf gnus-prev-winconf)
4846 (when mime-edit-mode-flag
4849 (goto-char (point-min))
4850 (let (case-fold-search)
4851 (when (re-search-forward
4852 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
4853 (replace-match "")))
4854 (when (featurep 'font-lock)
4855 (setq font-lock-defaults nil)
4857 ;; We remove all text props from the article buffer.
4858 (setq buf (format "%s" (buffer-string)))
4859 (set-buffer (get-buffer-create gnus-original-article-buffer))
4862 (setq gnus-current-headers (gnus-article-make-full-mail-header))
4863 (gnus-article-prepare-display)
4864 (set-window-configuration winconf)))
4867 ;;; Article highlights
4870 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
4872 ;;; Internal Variables:
4874 (defcustom gnus-button-url-regexp "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\)\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)\\)"
4875 "Regular expression that matches URLs."
4876 :group 'gnus-article-buttons
4879 (defcustom gnus-button-alist
4880 `(("<\\(url:[>\n\t ]*?\\)?news:[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
4881 0 t gnus-button-message-id 2)
4882 ("\\bnews:\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t gnus-button-message-id 1)
4883 ("\\(\\b<\\(url:[>\n\t ]*\\)?news:[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
4885 gnus-button-fetch-group 4)
4886 ("\\bnews:\\(//\\)?\\([^'\">\n\t ]+\\)" 0 t gnus-button-fetch-group 2)
4887 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2
4888 t gnus-button-message-id 3)
4889 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 2)
4890 ("mailto:\\([-a-zA-Z.@_+0-9%]+\\)" 0 t gnus-url-mailto 1)
4891 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 1)
4892 ;; This is how URLs _should_ be embedded in text...
4893 ("<URL: *\\([^<>]*\\)>" 0 t gnus-button-embedded-url 1)
4895 (,gnus-button-url-regexp 0 t browse-url 0))
4896 "*Alist of regexps matching buttons in article bodies.
4898 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
4899 REGEXP: is the string matching text around the button,
4900 BUTTON: is the number of the regexp grouping actually matching the button,
4901 FORM: is a lisp expression which must eval to true for the button to
4903 CALLBACK: is the function to call when the user push this button, and each
4904 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
4906 CALLBACK can also be a variable, in that case the value of that
4907 variable it the real callback function."
4908 :group 'gnus-article-buttons
4909 :type '(repeat (list regexp
4910 (integer :tag "Button")
4912 (function :tag "Callback")
4915 (integer :tag "Regexp group")))))
4917 (defcustom gnus-header-button-alist
4918 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>"
4919 0 t gnus-button-message-id 0)
4920 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1)
4921 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
4922 0 t gnus-button-mailto 0)
4923 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t browse-url 0)
4924 ("^Subject:" ,gnus-button-url-regexp 0 t browse-url 0)
4925 ("^[^:]+:" ,gnus-button-url-regexp 0 t browse-url 0)
4926 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t
4927 gnus-button-message-id 3))
4928 "*Alist of headers and regexps to match buttons in article heads.
4930 This alist is very similar to `gnus-button-alist', except that each
4931 alist has an additional HEADER element first in each entry:
4933 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
4935 HEADER is a regexp to match a header. For a fuller explanation, see
4936 `gnus-button-alist'."
4937 :group 'gnus-article-buttons
4938 :group 'gnus-article-headers
4939 :type '(repeat (list (regexp :tag "Header")
4941 (integer :tag "Button")
4943 (function :tag "Callback")
4946 (integer :tag "Regexp group")))))
4948 (defvar gnus-button-regexp nil)
4949 (defvar gnus-button-marker-list nil)
4950 ;; Regexp matching any of the regexps from `gnus-button-alist'.
4952 (defvar gnus-button-last nil)
4953 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
4957 (defun gnus-article-push-button (event)
4958 "Check text under the mouse pointer for a callback function.
4959 If the text under the mouse pointer has a `gnus-callback' property,
4960 call it with the value of the `gnus-data' text property."
4962 (set-buffer (window-buffer (posn-window (event-start event))))
4963 (let* ((pos (posn-point (event-start event)))
4964 (data (get-text-property pos 'gnus-data))
4965 (fun (get-text-property pos 'gnus-callback)))
4968 (funcall fun data))))
4970 (defun gnus-article-press-button ()
4971 "Check text at point for a callback function.
4972 If the text at point has a `gnus-callback' property,
4973 call it with the value of the `gnus-data' text property."
4975 (let* ((data (get-text-property (point) 'gnus-data))
4976 (fun (get-text-property (point) 'gnus-callback)))
4978 (funcall fun data))))
4980 (defun gnus-article-prev-button (n)
4981 "Move point to N buttons backward.
4982 If N is negative, move forward instead."
4984 (gnus-article-next-button (- n)))
4986 (defun gnus-article-next-button (n)
4987 "Move point to N buttons forward.
4988 If N is negative, move backward instead."
4990 (let ((function (if (< n 0) 'previous-single-property-change
4991 'next-single-property-change))
4992 (inhibit-point-motion-hooks t)
4994 (limit (if (< n 0) (point-min) (point-max))))
4996 (while (and (not (= limit (point)))
4998 ;; Skip past the current button.
4999 (when (get-text-property (point) 'gnus-callback)
5000 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5001 ;; Go to the next (or previous) button.
5002 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
5003 ;; Put point at the start of the button.
5004 (when (and backward (not (get-text-property (point) 'gnus-callback)))
5005 (goto-char (funcall function (point) 'gnus-callback nil limit)))
5006 ;; Skip past intangible buttons.
5007 (when (get-text-property (point) 'intangible)
5011 (gnus-message 5 "No more buttons"))
5014 (defun gnus-article-highlight (&optional force)
5015 "Highlight current article.
5016 This function calls `gnus-article-highlight-headers',
5017 `gnus-article-highlight-citation',
5018 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5019 do the highlighting. See the documentation for those functions."
5020 (interactive (list 'force))
5021 (gnus-article-highlight-headers)
5022 (gnus-article-highlight-citation force)
5023 (gnus-article-highlight-signature)
5024 (gnus-article-add-buttons force)
5025 (gnus-article-add-buttons-to-head))
5027 (defun gnus-article-highlight-some (&optional force)
5028 "Highlight current article.
5029 This function calls `gnus-article-highlight-headers',
5030 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
5031 do the highlighting. See the documentation for those functions."
5032 (interactive (list 'force))
5033 (gnus-article-highlight-headers)
5034 (gnus-article-highlight-signature)
5035 (gnus-article-add-buttons))
5037 (defun gnus-article-highlight-headers ()
5038 "Highlight article headers as specified by `gnus-header-face-alist'."
5041 (set-buffer gnus-article-buffer)
5043 (let ((alist gnus-header-face-alist)
5044 (buffer-read-only nil)
5045 (case-fold-search t)
5046 (inhibit-point-motion-hooks t)
5047 entry regexp header-face field-face from hpoints fpoints)
5048 (article-narrow-to-head)
5049 (while (setq entry (pop alist))
5050 (goto-char (point-min))
5051 (setq regexp (concat "^\\("
5052 (if (string-equal "" (nth 0 entry))
5056 header-face (nth 1 entry)
5057 field-face (nth 2 entry))
5058 (while (and (re-search-forward regexp nil t)
5062 (unless (search-forward ":" nil t)
5064 (when (and header-face
5065 (not (memq (point) hpoints)))
5066 (push (point) hpoints)
5067 (gnus-put-text-property from (point) 'face header-face))
5068 (when (and field-face
5069 (not (memq (setq from (point)) fpoints)))
5071 (if (re-search-forward "^[^ \t]" nil t)
5073 (goto-char (point-max)))
5074 (gnus-put-text-property from (point) 'face field-face))))))))
5076 (defun gnus-article-highlight-signature ()
5077 "Highlight the signature in an article.
5078 It does this by highlighting everything after
5079 `gnus-signature-separator' using `gnus-signature-face'."
5081 (when gnus-signature-face
5083 (set-buffer gnus-article-buffer)
5084 (let ((buffer-read-only nil)
5085 (inhibit-point-motion-hooks t))
5087 (when (gnus-article-narrow-to-signature)
5088 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
5089 'face gnus-signature-face)))))))
5091 (defun gnus-article-buttonize-signature ()
5092 "Add button to the signature."
5095 (set-buffer gnus-article-buffer)
5096 (let ((buffer-read-only nil)
5097 (inhibit-point-motion-hooks t))
5098 (when (gnus-article-search-signature)
5099 (gnus-article-add-button (match-beginning 0) (match-end 0)
5100 'gnus-signature-toggle
5101 (set-marker (make-marker)
5102 (1+ (match-end 0))))))))
5104 (defun gnus-button-in-region-p (b e prop)
5105 "Say whether PROP exists in the region."
5106 (text-property-not-all b e prop nil))
5108 (defun gnus-article-add-buttons (&optional force)
5109 "Find external references in the article and make buttons of them.
5110 \"External references\" are things like Message-IDs and URLs, as
5111 specified by `gnus-button-alist'."
5112 (interactive (list 'force))
5114 (set-buffer gnus-article-buffer)
5115 (let ((buffer-read-only nil)
5116 (inhibit-point-motion-hooks t)
5117 (case-fold-search t)
5118 (alist gnus-button-alist)
5120 ;; Remove all old markers.
5121 (let (marker entry new-list)
5122 (while (setq marker (pop gnus-button-marker-list))
5123 (if (or (< marker (point-min)) (>= marker (point-max)))
5124 (push marker new-list)
5126 (when (setq entry (gnus-button-entry))
5127 (put-text-property (match-beginning (nth 1 entry))
5128 (match-end (nth 1 entry))
5129 'gnus-callback nil))
5130 (set-marker marker nil)))
5131 (setq gnus-button-marker-list new-list))
5132 ;; We skip the headers.
5135 (while (setq entry (pop alist))
5136 (setq regexp (car entry))
5138 (while (re-search-forward regexp nil t)
5139 (let* ((start (and entry (match-beginning (nth 1 entry))))
5140 (end (and entry (match-end (nth 1 entry))))
5141 (from (match-beginning 0)))
5142 (when (and (or (eq t (nth 2 entry))
5143 (eval (nth 2 entry)))
5144 (not (gnus-button-in-region-p
5145 start end 'gnus-callback)))
5146 ;; That optional form returned non-nil, so we add the
5148 (gnus-article-add-button
5149 start end 'gnus-button-push
5150 (car (push (set-marker (make-marker) from)
5151 gnus-button-marker-list))))))))))
5153 ;; Add buttons to the head of an article.
5154 (defun gnus-article-add-buttons-to-head ()
5155 "Add buttons to the head of the article."
5158 (set-buffer gnus-article-buffer)
5160 (let ((buffer-read-only nil)
5161 (inhibit-point-motion-hooks t)
5162 (case-fold-search t)
5163 (alist gnus-header-button-alist)
5165 (article-narrow-to-head)
5167 ;; Each alist entry.
5168 (setq entry (car alist)
5170 (goto-char (point-min))
5171 (while (re-search-forward (car entry) nil t)
5172 ;; Each header matching the entry.
5173 (setq beg (match-beginning 0))
5174 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
5175 (match-beginning 0))
5178 (while (re-search-forward (nth 1 entry) end t)
5179 ;; Each match within a header.
5180 (let* ((entry (cdr entry))
5181 (start (match-beginning (nth 1 entry)))
5182 (end (match-end (nth 1 entry)))
5183 (form (nth 2 entry)))
5184 (goto-char (match-end 0))
5186 (gnus-article-add-button
5187 start end (nth 3 entry)
5188 (buffer-substring (match-beginning (nth 4 entry))
5189 (match-end (nth 4 entry)))))))
5190 (goto-char end)))))))
5192 ;;; External functions:
5194 (defun gnus-article-add-button (from to fun &optional data)
5195 "Create a button between FROM and TO with callback FUN and data DATA."
5196 (when gnus-article-button-face
5197 (gnus-overlay-put (gnus-make-overlay from to)
5198 'face gnus-article-button-face))
5199 (gnus-add-text-properties
5201 (nconc (and gnus-article-mouse-face
5202 (list gnus-mouse-face-prop gnus-article-mouse-face))
5203 (list 'gnus-callback fun)
5204 (and data (list 'gnus-data data))))
5205 (widget-convert-button 'link from to :action 'gnus-widget-press-button
5206 ;; Quote `:button-keymap' for Mule 2.3
5207 ;; but it won't work.
5208 ':button-keymap gnus-widget-button-keymap))
5210 ;;; Internal functions:
5212 (defun gnus-article-set-globals ()
5214 (set-buffer gnus-summary-buffer)
5215 (gnus-set-global-variables)))
5217 (defun gnus-signature-toggle (end)
5219 (set-buffer gnus-article-buffer)
5220 (let ((buffer-read-only nil)
5221 (inhibit-point-motion-hooks t)
5222 (limit (next-single-property-change end 'mime-view-entity
5224 (if (text-property-any end limit 'article-type 'signature)
5225 (gnus-remove-text-properties-when
5226 'article-type 'signature end limit
5227 (cons 'article-type (cons 'signature
5228 gnus-hidden-properties)))
5229 (gnus-add-text-properties-when
5230 'article-type nil end limit
5231 (cons 'article-type (cons 'signature
5232 gnus-hidden-properties)))))))
5234 (defun gnus-button-entry ()
5235 ;; Return the first entry in `gnus-button-alist' matching this place.
5236 (let ((alist gnus-button-alist)
5239 (setq entry (pop alist))
5240 (if (looking-at (car entry))
5245 (defun gnus-button-push (marker)
5246 ;; Push button starting at MARKER.
5249 (let* ((entry (gnus-button-entry))
5250 (inhibit-point-motion-hooks t)
5252 (args (mapcar (lambda (group)
5253 (let ((string (match-string group)))
5254 (gnus-set-text-properties
5255 0 (length string) nil string)
5262 (fboundp (symbol-value fun)))
5263 (apply (symbol-value fun) args))
5265 (gnus-message 1 "You must define `%S' to use this button"
5266 (cons fun args)))))))
5268 (defun gnus-button-message-id (message-id)
5271 (set-buffer gnus-summary-buffer)
5272 (gnus-summary-refer-article message-id)))
5274 (defun gnus-button-fetch-group (address)
5275 "Fetch GROUP specified by ADDRESS."
5276 (if (not (string-match "[:/]" address))
5277 ;; This is just a simple group url.
5278 (gnus-group-read-ephemeral-group address gnus-select-method)
5279 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)/\\)?\\(.*\\)$"
5281 (error "Can't parse %s" address)
5282 (gnus-group-read-ephemeral-group
5283 (match-string 4 address)
5284 `(nntp ,(match-string 1 address)
5285 (nntp-address ,(match-string 1 address))
5286 (nntp-port-number ,(if (match-end 3)
5287 (match-string 3 address)
5290 (defun gnus-url-parse-query-string (query &optional downcase)
5291 (let (retval pairs cur key val)
5292 (setq pairs (split-string query "&"))
5294 (setq cur (car pairs)
5296 (if (not (string-match "=" cur))
5298 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
5299 val (gnus-url-unhex-string (substring cur (match-end 0) nil)))
5301 (setq key (downcase key)))
5302 (setq cur (assoc key retval))
5304 (setcdr cur (cons val (cdr cur)))
5305 (setq retval (cons (list key val) retval)))))
5308 (defun gnus-url-unhex (x)
5315 (defun gnus-url-unhex-string (str &optional allow-newlines)
5316 "Remove %XXX embedded spaces, etc in a url.
5317 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
5318 decoding of carriage returns and line feeds in the string, which is normally
5319 forbidden in URL encoding."
5320 (setq str (or str ""))
5322 (case-fold-search t))
5323 (while (string-match "%[0-9a-f][0-9a-f]" str)
5324 (let* ((start (match-beginning 0))
5325 (ch1 (gnus-url-unhex (elt str (+ start 1))))
5327 (gnus-url-unhex (elt str (+ start 2))))))
5329 tmp (substring str 0 start)
5332 (char-to-string code))
5333 ((or (= code ?\n) (= code ?\r))
5335 (t (char-to-string code))))
5336 str (substring str (match-end 0)))))
5337 (setq tmp (concat tmp str))
5340 (defun gnus-url-mailto (url)
5341 ;; Send mail to someone
5342 (when (string-match "mailto:/*\\(.*\\)" url)
5343 (setq url (substring url (match-beginning 1) nil)))
5344 (let (to args subject func)
5345 (if (string-match (regexp-quote "?") url)
5346 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0)))
5347 args (gnus-url-parse-query-string
5348 (substring url (match-end 0) nil) t))
5349 (setq to (gnus-url-unhex-string url)))
5350 (setq args (cons (list "to" to) args)
5351 subject (cdr-safe (assoc "subject" args)))
5352 (gnus-setup-message 'reply
5355 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
5358 (message-position-on-field (caar args)))
5359 (insert (mapconcat 'identity (cdar args) ", "))
5360 (setq args (cdr args)))
5363 (message-goto-subject)))))
5365 (defun gnus-button-mailto (address)
5367 (set-buffer (gnus-copy-article-buffer))
5368 (message-reply address))
5370 (defalias 'gnus-button-reply 'message-reply)
5372 (defun gnus-button-embedded-url (address)
5373 "Activate ADDRESS with `browse-url'."
5374 (browse-url (gnus-strip-whitespace address)))
5376 (defun gnus-article-smiley-display ()
5377 "Display \"smileys\" as small graphical icons."
5378 (smiley-toggle-buffer 1 (current-buffer) (point-min) (point-max)))
5380 ;;; Next/prev buttons in the article buffer.
5382 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
5383 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
5385 (defvar gnus-prev-page-map nil)
5386 (unless gnus-prev-page-map
5387 (setq gnus-prev-page-map (make-sparse-keymap))
5388 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page)
5389 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page))
5391 (static-if (featurep 'xemacs)
5392 (defun gnus-insert-prev-page-button ()
5393 (let ((buffer-read-only nil))
5395 gnus-prev-page-line-format nil
5396 `(gnus-prev t local-map ,gnus-prev-page-map
5397 gnus-callback gnus-article-button-prev-page
5398 article-type annotation))))
5399 (defun gnus-insert-prev-page-button ()
5400 (let ((buffer-read-only nil)
5401 (situation (get-text-property (point-min) 'mime-view-situation)))
5402 (set-keymap-parent gnus-prev-page-map (current-local-map))
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
5408 mime-view-situation ,situation))))
5411 (defvar gnus-next-page-map nil)
5412 (unless gnus-next-page-map
5413 (setq gnus-next-page-map (make-sparse-keymap))
5414 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page)
5415 (define-key gnus-next-page-map "\r" 'gnus-button-next-page))
5417 (defun gnus-button-next-page ()
5418 "Go to the next page."
5420 (let ((win (selected-window)))
5421 (select-window (get-buffer-window gnus-article-buffer t))
5422 (gnus-article-next-page)
5423 (select-window win)))
5425 (defun gnus-button-prev-page ()
5426 "Go to the prev page."
5428 (let ((win (selected-window)))
5429 (select-window (get-buffer-window gnus-article-buffer t))
5430 (gnus-article-prev-page)
5431 (select-window win)))
5433 (static-if (featurep 'xemacs)
5434 (defun gnus-insert-next-page-button ()
5435 (let ((buffer-read-only nil))
5436 (gnus-eval-format gnus-next-page-line-format nil
5438 t local-map ,gnus-next-page-map
5439 gnus-callback gnus-article-button-next-page
5440 article-type annotation))))
5441 (defun gnus-insert-next-page-button ()
5442 (let ((buffer-read-only nil)
5443 (situation (get-text-property (point-min) 'mime-view-situation)))
5444 (set-keymap-parent gnus-next-page-map (current-local-map))
5445 (gnus-eval-format gnus-next-page-line-format nil
5447 t local-map ,gnus-next-page-map
5448 gnus-callback gnus-article-button-next-page
5449 article-type annotation
5450 mime-view-situation ,situation))))
5453 (defun gnus-article-button-next-page (arg)
5454 "Go to the next page."
5456 (let ((win (selected-window)))
5457 (select-window (get-buffer-window gnus-article-buffer t))
5458 (gnus-article-next-page)
5459 (select-window win)))
5461 (defun gnus-article-button-prev-page (arg)
5462 "Go to the prev page."
5464 (let ((win (selected-window)))
5465 (select-window (get-buffer-window gnus-article-buffer t))
5466 (gnus-article-prev-page)
5467 (select-window win)))
5469 (defvar gnus-decode-header-methods
5470 '(mail-decode-encoded-word-region)
5471 "List of methods used to decode headers.
5473 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
5474 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
5475 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
5476 whose names match REGEXP.
5479 ((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
5480 mail-decode-encoded-word-region
5481 (\"chinese\" . rfc1843-decode-region))
5484 (defvar gnus-decode-header-methods-cache nil)
5486 (defun gnus-multi-decode-header (start end)
5487 "Apply the functions from `gnus-encoded-word-methods' that match."
5488 (unless (and gnus-decode-header-methods-cache
5489 (eq gnus-newsgroup-name
5490 (car gnus-decode-header-methods-cache)))
5491 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
5494 (nconc gnus-decode-header-methods-cache (list x))
5495 (if (and gnus-newsgroup-name
5496 (string-match (car x) gnus-newsgroup-name))
5497 (nconc gnus-decode-header-methods-cache
5499 gnus-decode-header-methods))
5500 (let ((xlist gnus-decode-header-methods-cache))
5503 (narrow-to-region start end)
5505 (funcall (pop xlist) (point-min) (point-max))))))
5508 ;;; Treatment top-level handling.
5511 (defun gnus-treat-article (condition &optional part-number total-parts type)
5512 (let ((length (- (point-max) (point-min)))
5513 (alist gnus-treatment-function-alist)
5514 (article-goto-body-goes-to-point-min-p t)
5518 (let ((list gnus-article-treat-types))
5520 (when (string-match (pop list) type)
5521 (throw 'found t)))))))
5522 (highlightp (gnus-visual-p 'article-highlight 'highlight))
5523 (entity (static-unless (featurep 'xemacs)
5524 (when (eq 'head condition)
5525 (get-text-property (point-min) 'mime-view-entity))))
5526 val elem buttonized)
5527 (gnus-run-hooks 'gnus-part-display-hook)
5528 (unless gnus-inhibit-treatment
5529 (while (setq elem (pop alist))
5532 (if (gnus-buffer-live-p gnus-summary-buffer)
5533 (set-buffer gnus-summary-buffer))
5534 (symbol-value (car elem))))
5535 (when (and (or (consp val)
5537 (gnus-treat-predicate val)
5538 (or (not (get (car elem) 'highlight))
5540 (when (and (not buttonized)
5542 '(gnus-treat-hide-signature
5543 gnus-treat-highlight-signature)))
5544 (gnus-article-buttonize-signature)
5545 (setq buttonized t))
5547 (funcall (cadr elem)))))
5548 ;; FSF Emacsen does not inherit the existing text properties
5549 ;; in the new text, so we should do it for `mime-view-entity'.
5550 (static-unless (featurep 'xemacs)
5552 (put-text-property (point-min) (point-max)
5553 'mime-view-entity entity))))))
5555 ;; Dynamic variables.
5557 (defvar part-number)
5558 (defvar total-parts)
5563 (defun gnus-treat-predicate (val)
5568 (stringp (car val)))
5569 (apply 'gnus-or (mapcar `(lambda (s)
5570 (string-match s ,(or gnus-newsgroup-name "")))
5573 (let ((pred (pop val)))
5576 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
5578 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
5580 (not (gnus-treat-predicate (car val))))
5582 (equal (car val) type))
5584 (error "%S is not a valid predicate" pred)))))
5594 (eq part-number total-parts))
5598 (error "%S is not a valid value" val))))
5600 (defun gnus-article-encrypt-body (protocol &optional n)
5601 "Encrypt the article body."
5604 (or gnus-article-encrypt-protocol
5605 (completing-read "Encrypt protocol: "
5606 gnus-article-encrypt-protocol-alist
5608 current-prefix-arg))
5609 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
5611 (error (format "Can't find the encrypt protocol %s" protocol)))
5612 (if (equal gnus-newsgroup-name "nndraft:drafts")
5613 (error "Can't encrypt the article in group nndraft:drafts."))
5614 (if (equal gnus-newsgroup-name "nndraft:queue")
5615 (error "Don't encrypt the article in group nndraft:queue."))
5616 (gnus-summary-iterate n
5618 (set-buffer gnus-summary-buffer)
5619 (let ((mail-parse-charset gnus-newsgroup-charset)
5620 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5621 (summary-buffer gnus-summary-buffer)
5623 (gnus-set-global-variables)
5624 (when (gnus-group-read-only-p)
5625 (error "The current newsgroup does not support article encrypt"))
5626 (gnus-summary-show-article t)
5628 (or (mail-header-references gnus-current-headers) ""))
5629 (set-buffer gnus-article-buffer)
5630 (let* ((buffer-read-only nil)
5632 (mapcar (lambda (field)
5633 (and (save-restriction
5634 (message-narrow-to-head)
5635 (goto-char (point-min))
5636 (search-forward field nil t))
5638 (message-narrow-to-field)
5639 (buffer-substring (point-min) (point-max))
5640 (delete-region (point-min) (point-max))
5642 '("Content-Type:" "Content-Transfer-Encoding:"
5643 "Content-Disposition:"))))
5644 (message-narrow-to-head)
5645 (message-remove-header "MIME-Version")
5646 (goto-char (point-max))
5647 (setq point (point))
5648 (insert (apply 'concat headers))
5650 (narrow-to-region point (point-max))
5651 (let ((message-options message-options))
5652 (message-options-set 'message-sender user-mail-address)
5653 (message-options-set 'message-recipients user-mail-address)
5654 (message-options-set 'message-sign-encrypt 'not)
5656 (goto-char (point-min))
5657 (insert "MIME-Version: 1.0\n")
5659 (gnus-summary-edit-article-done
5660 references nil summary-buffer t))
5661 (when gnus-keep-backlog
5662 (gnus-backlog-remove-article
5663 (car gnus-article-current) (cdr gnus-article-current)))
5665 (when (get-buffer gnus-original-article-buffer)
5666 (set-buffer gnus-original-article-buffer)
5667 (setq gnus-original-article nil)))
5668 (when gnus-use-cache
5669 (gnus-cache-update-article
5670 (car gnus-article-current) (cdr gnus-article-current))))))))
5672 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
5673 "The following specs can be used:
5674 %t The security MIME type
5677 %D Details if button is pressed")
5679 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
5680 "The following specs can be used:
5681 %t The security MIME type
5684 %D Details if button is pressed")
5686 (defvar gnus-mime-security-button-line-format-alist
5687 '((?t gnus-tmp-type ?s)
5688 (?i gnus-tmp-info ?s)
5689 (?d gnus-tmp-details ?s)
5690 (?D gnus-tmp-pressed-details ?s)))
5692 (defvar gnus-mime-security-button-map
5693 (let ((map (make-sparse-keymap)))
5694 (set-keymap-parent map gnus-article-mode-map)
5695 (define-key map gnus-mouse-2 'gnus-article-push-button)
5696 (define-key map "\r" 'gnus-article-press-button)
5699 (defvar gnus-mime-security-details-buffer nil)
5701 (defvar gnus-mime-security-button-pressed nil)
5703 (defvar gnus-mime-security-show-details-inline t
5704 "If non-nil, show details in the article buffer.")
5706 (defun gnus-mime-security-verify-or-decrypt (handle)
5707 (mm-remove-parts (cdr handle))
5708 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
5711 (delete-region (car region) (cdr region))
5712 (set-marker (car region) nil)
5713 (set-marker (cdr region) nil)))
5714 (with-current-buffer (mm-handle-multipart-original-buffer handle)
5715 (let* ((mm-verify-option 'known)
5716 (mm-decrypt-option 'known)
5717 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
5718 (unless (eq nparts (cdr handle))
5719 (mm-destroy-parts (cdr handle))
5720 (setcdr handle nparts))))
5721 (let ((point (point))
5723 (gnus-mime-display-security handle)
5726 (defun gnus-mime-security-show-details (handle)
5727 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
5729 (if gnus-mime-security-show-details-inline
5730 (let ((gnus-mime-security-button-pressed t)
5731 (gnus-mime-security-button-line-format
5732 (get-text-property (point) 'gnus-line-format))
5735 (while (eq (get-text-property (point) 'gnus-line-format)
5736 gnus-mime-security-button-line-format)
5739 (delete-region (point)
5740 (or (text-property-not-all
5743 gnus-mime-security-button-line-format)
5745 (gnus-insert-mime-security-button handle))
5746 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
5747 (with-current-buffer gnus-mime-security-details-buffer
5750 (setq gnus-mime-security-details-buffer
5751 (gnus-get-buffer-create "*MIME Security Details*")))
5752 (with-current-buffer gnus-mime-security-details-buffer
5754 (goto-char (point-min)))
5755 (pop-to-buffer gnus-mime-security-details-buffer))
5756 (gnus-message 5 "No details."))))
5758 (defun gnus-mime-security-press-button (handle)
5759 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5760 (gnus-mime-security-show-details handle)
5761 (gnus-mime-security-verify-or-decrypt handle)))
5763 (defun gnus-insert-mime-security-button (handle &optional displayed)
5764 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
5767 (or (nth 2 (assoc protocol mm-verify-function-alist))
5768 (nth 2 (assoc protocol mm-decrypt-function-alist))
5770 (if (equal (car handle) "multipart/signed")
5771 " Signed" " Encrypted")
5774 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
5777 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
5778 gnus-tmp-pressed-details
5780 (setq gnus-tmp-details
5781 (if gnus-tmp-details
5782 (concat "\n" gnus-tmp-details) ""))
5783 (setq gnus-tmp-pressed-details
5784 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
5789 gnus-mime-security-button-line-format
5790 gnus-mime-security-button-line-format-alist
5791 `(local-map ,gnus-mime-security-button-map
5792 keymap ,gnus-mime-security-button-map
5793 gnus-callback gnus-mime-security-press-button
5794 gnus-line-format ,gnus-mime-security-button-line-format
5795 article-type annotation
5798 (widget-convert-button
5801 :action 'gnus-widget-press-button
5802 :button-keymap gnus-mime-security-button-map
5804 (lambda (widget/window &optional overlay pos)
5805 ;; Needed to properly clear the message due to a bug in
5806 ;; wid-edit (XEmacs only).
5807 (if (boundp 'help-echo-owns-message)
5808 (setq help-echo-owns-message t))
5811 (aref gnus-mouse-2 0))))))
5813 (defun gnus-mime-display-security (handle)
5815 (narrow-to-region (point) (point))
5816 (gnus-insert-mime-security-button handle)
5817 (gnus-mime-display-mixed (cdr handle))
5820 (let ((gnus-mime-security-button-line-format
5821 gnus-mime-security-button-end-line-format))
5822 (gnus-insert-mime-security-button handle))
5823 (mm-set-handle-multipart-parameter handle 'gnus-region
5824 (cons (set-marker (make-marker)
5826 (set-marker (make-marker)
5833 (defun gnus-article-header-presentation-method (entity situation)
5834 (mime-insert-header entity)
5837 (set-alist 'mime-header-presentation-method-alist
5838 'gnus-original-article-mode
5839 #'gnus-article-header-presentation-method)
5841 (defun gnus-mime-preview-quitting-method ()
5842 (mime-preview-kill-buffer)
5843 (delete-other-windows)
5844 (gnus-article-show-summary)
5845 (gnus-summary-select-article gnus-show-all-headers t))
5847 (set-alist 'mime-preview-quitting-method-alist
5848 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
5850 (set-alist 'mime-preview-following-method-alist
5851 'gnus-original-article-mode #'gnus-following-method)
5853 (set-alist 'mime-preview-over-to-previous-method-alist
5854 'gnus-original-article-mode
5856 (if (> (point-min) 1)
5857 (gnus-article-prev-page)
5858 (gnus-article-read-summary-keys
5859 nil (gnus-character-to-event ?P)))))
5861 (set-alist 'mime-preview-over-to-next-method-alist
5862 'gnus-original-article-mode'
5864 (if (< (point-max) (buffer-size))
5865 (gnus-article-next-page)
5866 (gnus-article-read-summary-keys
5867 nil (gnus-character-to-event ?N)))))
5877 (run-hooks 'gnus-art-load-hook)
5879 ;;; gnus-art.el ends here