* lisp/emacs-lisp/cl-lib.el (cl-pushnew): Use macroexp-let2.
[emacs/old-mirror.git] / lisp / gnus / gnus-art.el
blobb92c3b6435f390a2017144aa81a7f6d0281ce8c5
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; For Emacs <22.2 and XEmacs.
28 (eval-and-compile
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30 (eval-when-compile
31 (require 'cl))
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map)
35 (require 'gnus)
36 (require 'gnus-sum)
37 (require 'gnus-spec)
38 (require 'gnus-int)
39 (require 'gnus-win)
40 (require 'mm-bodies)
41 (require 'mail-parse)
42 (require 'mm-decode)
43 (require 'mm-view)
44 (require 'wid-edit)
45 (require 'mm-uu)
46 (require 'message)
47 (require 'mouse)
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
57 (defgroup gnus-article nil
58 "Article display."
59 :link '(custom-manual "(gnus)Article Buffer")
60 :group 'gnus)
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
65 :group 'gnus-article)
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
70 :group 'gnus-article)
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
75 :group 'gnus-article
76 :group 'gnus-visual)
78 (defgroup gnus-article-signature nil
79 "Article signatures."
80 :link '(custom-manual "(gnus)Article Signature")
81 :group 'gnus-article)
83 (defgroup gnus-article-headers nil
84 "Article headers."
85 :link '(custom-manual "(gnus)Hiding Headers")
86 :group 'gnus-article)
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
91 :group 'gnus-article)
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
96 :group 'gnus-article)
98 (defgroup gnus-article-saving nil
99 "Saving articles."
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
119 (mapcar
120 (lambda (header)
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice regexp
167 (repeat regexp))
168 :group 'gnus-article-hiding)
170 (defcustom gnus-visible-headers
171 "^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:"
172 "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
175 :type '(choice
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
179 (or (stringp value)
180 (widget-editable-list-match widget value)))
181 regexp)
182 (const :tag "Use gnus-ignored-headers" nil)
183 regexp)
184 :group 'gnus-article-hiding)
186 (defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189 "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
192 this list."
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
210 :type '(set (const :tag "Headers with no content." empty)
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
217 (const :tag "Date less than four days old." date)
218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
219 (const :tag "Multiple To and/or Cc headers." many-to))
220 :group 'gnus-article-hiding)
222 (defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text. Boring text is controlled by
227 `gnus-article-boring-faces'."
228 :version "22.1"
229 :type 'boolean
230 :group 'gnus-article-hiding)
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234 This can also be a list of regexps. In that case, it will be checked
235 from head to tail looking for a separator. Searches will be done from
236 the end of the buffer."
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238 (regexp)
239 (repeat :tag "List of regexp" regexp))
240 :group 'gnus-article-signature)
242 (defcustom gnus-signature-limit nil
243 "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number. If it is a floating point number, no signature may be
246 longer (in lines) than that number. If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer. If it is a string, it will be used as a
249 regexp. If it matches, the text in question is not a signature.
251 This can also be a list of the above values."
252 :type '(choice (const nil)
253 (integer :value 200)
254 (number :value 4.0)
255 function
256 (regexp :value ".*"))
257 :group 'gnus-article-signature)
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
261 :type 'sexp
262 :group 'gnus-article-hiding)
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
271 "{ echo \
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | ee -")
274 (if (gnus-image-type-available-p 'pbm)
275 'gnus-display-x-face-in-from
276 "{ echo \
277 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
278 ; uncompface; } | icontopbm | display -"))
279 "*String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
284 function)
285 :version "21.1"
286 :group 'gnus-picon
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
296 For example,
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
298 :version "21.1"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
303 banner
304 :variable-document
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
307 :parameter-type
308 '(choice :tag "Banner"
309 :value nil
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
312 regexp
313 (const :tag "None" nil))
314 :parameter-document
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
321 directly.")
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 :type '(repeat
334 (cons
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
339 regexp
340 (const :tag "None" nil))))
341 :version "22.1"
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
345 `(let ((format "\
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 ,@body))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
356 (nth 2 value))
357 value)))
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
364 "\\'"))
365 pattern)
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
368 (= (nth 2 value) 2)
369 (nth 3 value))
370 value))))
372 (defcustom gnus-emphasis-alist
373 (let ((types
374 '(("\\*" "\\*" bold nil 2)
375 ("_" "_" underline)
376 ("/" "/" italic)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
381 (nconc
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
385 (or (nth 3 spec) 2)
386 (or (nth 4 spec) 3)
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
388 types))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "*Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
407 :type
408 '(repeat
409 (menu-choice
410 :format "%[Customizing Style%]\n%v"
411 :indent 2
412 (group :tag "Default"
413 :value ("" 0 0 default)
414 :value-create
415 (lambda (widget)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
418 :args))
419 :value)))
420 (if (not (eq (nth 2 value) 'default))
421 (widget-put
422 widget
423 :value
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
426 regexp
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
429 face)
430 (group :tag "Simple"
431 :value (("_" . "_") nil default)
432 (cons :format "%v"
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
437 face)))
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
443 value)))
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
451 :version "21.1"
452 :group 'gnus-article-emphasis
453 :type 'regexp)
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
496 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
497 "Format for display of Date headers in article bodies.
498 See `format-time-string' for the possible values.
500 The variable can also be function, which should return a complete Date
501 header. The function is called with one argument, the time, which can
502 be fed to `format-time-string'."
503 :type '(choice string function)
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
507 (defcustom gnus-save-all-headers t
508 "*If non-nil, don't remove any headers before saving.
509 This will be overridden by the `:headers' property that the symbol of
510 the saver function, which is specified by `gnus-default-article-saver',
511 might have."
512 :group 'gnus-article-saving
513 :type 'boolean)
515 (defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517 If it is nil, no prompting will be done, and the articles will be
518 saved to the default files. If this variable is `always', each and
519 every article that is saved will be preceded by a prompt, even when
520 saving large batches of articles. If this variable is neither nil not
521 `always', there the user will be prompted once for a file name for
522 each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
526 (sexp :tag "once" :format "%t\n" :value t)))
528 (defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531 If that variable is nil, however, all headers that match this regexp
532 will be kept while the rest will be deleted before saving. This and
533 `gnus-save-all-headers' will be overridden by the `:headers' property
534 that the symbol of the saver function, which is specified by
535 `gnus-default-article-saver', might have."
536 :group 'gnus-article-saving
537 :type 'regexp)
539 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
540 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
541 "A function to save articles in your favorite format.
542 The function will be called by way of the `gnus-summary-save-article'
543 command, and friends such as `gnus-summary-save-article-rmail'.
545 Gnus provides the following functions:
547 * gnus-summary-save-in-rmail (Rmail format)
548 * gnus-summary-save-in-mail (Unix mail format)
549 * gnus-summary-save-in-folder (MH folder)
550 * gnus-summary-save-in-file (article format)
551 * gnus-summary-save-body-in-file (article body)
552 * gnus-summary-save-in-vm (use VM's folder format)
553 * gnus-summary-write-to-file (article format -- overwrite)
554 * gnus-summary-write-body-to-file (article body -- overwrite)
555 * gnus-summary-save-in-pipe (article format)
557 The symbol of each function may have the following properties:
559 * :decode
560 The value non-nil means save decoded articles. This is meaningful
561 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
562 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
563 `gnus-summary-save-in-pipe'.
565 * :function
566 The value specifies an alternative function which appends, not
567 overwrites, articles to a file. This implies that when saving many
568 articles at a time, `gnus-prompt-before-saving' is bound to t and all
569 articles are saved in a single file. This is meaningful only with
570 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
572 * :headers
573 The value specifies the symbol of a variable of which the value
574 specifies headers to be saved. If it is omitted,
575 `gnus-save-all-headers' and `gnus-saved-headers' control what
576 headers should be saved."
577 :group 'gnus-article-saving
578 :type '(radio (function-item gnus-summary-save-in-rmail)
579 (function-item gnus-summary-save-in-mail)
580 (function-item gnus-summary-save-in-folder)
581 (function-item gnus-summary-save-in-file)
582 (function-item gnus-summary-save-body-in-file)
583 (function-item gnus-summary-save-in-vm)
584 (function-item gnus-summary-write-to-file)
585 (function-item gnus-summary-write-body-to-file)
586 (function-item gnus-summary-save-in-pipe)
587 (function)))
589 (defcustom gnus-article-save-coding-system
590 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
591 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
592 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
593 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
594 "Coding system used to save decoded articles to a file.
596 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
597 which can safely encode any characters in text. This is used by the
598 commands including:
600 * gnus-summary-save-article-file
601 * gnus-summary-save-article-body-file
602 * gnus-summary-write-article-file
603 * gnus-summary-write-article-body-file
605 and the functions to which you may set `gnus-default-article-saver':
607 * gnus-summary-save-in-file
608 * gnus-summary-save-body-in-file
609 * gnus-summary-write-to-file
610 * gnus-summary-write-body-to-file
612 Those commands and functions save just text displayed in the article
613 buffer to a file if the value of this variable is non-nil. Note that
614 buttonized MIME parts will be lost in a saved file in that case.
615 Otherwise, raw articles will be saved."
616 :group 'gnus-article-saving
617 :type `(choice
618 :format "%{%t%}:\n %[Value Menu%] %v"
619 (const :tag "Save raw articles" nil)
620 ,@(delq nil
621 (mapcar
622 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
623 '((const :tag "UTF-8" utf-8)
624 (const :tag "iso-2022-7bit" iso-2022-7bit)
625 (const :tag "Emacs internal" emacs-mule)
626 (const :tag "escape-quoted" escape-quoted))))
627 (symbol :tag "Coding system")))
629 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
630 "A function generating a file name to save articles in Rmail format.
631 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
632 :group 'gnus-article-saving
633 :type 'function)
635 (defcustom gnus-mail-save-name 'gnus-plain-save-name
636 "A function generating a file name to save articles in Unix mail format.
637 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
638 :group 'gnus-article-saving
639 :type 'function)
641 (defcustom gnus-folder-save-name 'gnus-folder-save-name
642 "A function generating a file name to save articles in MH folder.
643 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
644 :group 'gnus-article-saving
645 :type 'function)
647 (defcustom gnus-file-save-name 'gnus-numeric-save-name
648 "A function generating a file name to save articles in article format.
649 The function is called with NEWSGROUP, HEADERS, and optional
650 LAST-FILE."
651 :group 'gnus-article-saving
652 :type 'function)
654 (defcustom gnus-split-methods
655 '((gnus-article-archive-name)
656 (gnus-article-nndoc-name))
657 "*Variable used to suggest where articles are to be saved.
658 For instance, if you would like to save articles related to Gnus in
659 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
660 you could set this variable to something like:
662 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
663 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
665 This variable is an alist where the key is the match and the
666 value is a list of possible files to save in if the match is
667 non-nil.
669 If the match is a string, it is used as a regexp match on the
670 article. If the match is a symbol, that symbol will be funcalled
671 from the buffer of the article to be saved with the newsgroup as the
672 parameter. If it is a list, it will be evalled in the same buffer.
674 If this form or function returns a string, this string will be used as a
675 possible file name; and if it returns a non-nil list, that list will be
676 used as possible file names."
677 :group 'gnus-article-saving
678 :type '(repeat (choice (list :value (fun) function)
679 (cons :value ("" "") regexp (repeat string))
680 (sexp :value nil))))
682 (defcustom gnus-page-delimiter "^\^L"
683 "*Regexp describing what to use as article page delimiters.
684 The default value is \"^\^L\", which is a form linefeed at the
685 beginning of a line."
686 :type 'regexp
687 :group 'gnus-article-various)
689 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
690 "*The format specification for the article mode line.
691 See `gnus-summary-mode-line-format' for a closer description.
693 The following additional specs are available:
695 %w The article washing status.
696 %m The number of MIME parts in the article."
697 :version "24.1"
698 :type 'string
699 :group 'gnus-article-various)
701 (defcustom gnus-article-mode-hook nil
702 "*A hook for Gnus article mode."
703 :type 'hook
704 :group 'gnus-article-various)
706 (when (featurep 'xemacs)
707 ;; Extracted from gnus-xmas-define in order to preserve user settings
708 (when (fboundp 'turn-off-scroll-in-place)
709 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
710 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
711 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
713 (defcustom gnus-article-menu-hook nil
714 "*Hook run after the creation of the article mode menu."
715 :type 'hook
716 :group 'gnus-article-various)
718 (defcustom gnus-article-prepare-hook nil
719 "*A hook called after an article has been prepared in the article buffer."
720 :type 'hook
721 :group 'gnus-article-various)
723 (defcustom gnus-copy-article-ignored-headers nil
724 "List of headers to be removed when copying an article.
725 Each element is a regular expression."
726 :version "23.1" ;; No Gnus
727 :type '(repeat regexp)
728 :group 'gnus-article-various)
730 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
731 "Gnus 5.10 (Emacs 22.1)")
733 (defface gnus-button
734 '((t (:weight bold)))
735 "Face used for highlighting a button in the article buffer."
736 :group 'gnus-article-buttons)
738 (defcustom gnus-article-button-face 'gnus-button
739 "Face used for highlighting buttons in the article buffer.
741 An article button is a piece of text that you can activate by pressing
742 `RET' or `mouse-2' above it."
743 :type 'face
744 :group 'gnus-article-buttons)
746 (defcustom gnus-article-mouse-face 'highlight
747 "Face used for mouse highlighting in the article buffer.
749 Article buttons will be displayed in this face when the cursor is
750 above them."
751 :type 'face
752 :group 'gnus-article-buttons)
754 (defcustom gnus-signature-face 'gnus-signature
755 "Face used for highlighting a signature in the article buffer.
756 Obsolete; use the face `gnus-signature' for customizations instead."
757 :type 'face
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
761 (defface gnus-signature
762 '((t
763 (:italic t)))
764 "Face used for highlighting a signature in the article buffer."
765 :group 'gnus-article-highlight
766 :group 'gnus-article-signature)
767 ;; backward-compatibility alias
768 (put 'gnus-signature-face 'face-alias 'gnus-signature)
769 (put 'gnus-signature-face 'obsolete-face "22.1")
771 (defface gnus-header-from
772 '((((class color)
773 (background dark))
774 (:foreground "PaleGreen1"))
775 (((class color)
776 (background light))
777 (:foreground "red3"))
779 (:italic t)))
780 "Face used for displaying from headers."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
783 ;; backward-compatibility alias
784 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
785 (put 'gnus-header-from-face 'obsolete-face "22.1")
787 (defface gnus-header-subject
788 '((((class color)
789 (background dark))
790 (:foreground "SeaGreen1"))
791 (((class color)
792 (background light))
793 (:foreground "red4"))
795 (:bold t :italic t)))
796 "Face used for displaying subject headers."
797 :group 'gnus-article-headers
798 :group 'gnus-article-highlight)
799 ;; backward-compatibility alias
800 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
801 (put 'gnus-header-subject-face 'obsolete-face "22.1")
803 (defface gnus-header-newsgroups
804 '((((class color)
805 (background dark))
806 (:foreground "yellow" :italic t))
807 (((class color)
808 (background light))
809 (:foreground "MidnightBlue" :italic t))
811 (:italic t)))
812 "Face used for displaying newsgroups headers.
813 In the default setup this face is only used for crossposted
814 articles."
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
817 ;; backward-compatibility alias
818 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
819 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
821 (defface gnus-header-name
822 '((((class color)
823 (background dark))
824 (:foreground "SpringGreen2"))
825 (((class color)
826 (background light))
827 (:foreground "maroon"))
829 (:bold t)))
830 "Face used for displaying header names."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight)
833 ;; backward-compatibility alias
834 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
835 (put 'gnus-header-name-face 'obsolete-face "22.1")
837 (defface gnus-header-content
838 '((((class color)
839 (background dark))
840 (:foreground "SpringGreen1" :italic t))
841 (((class color)
842 (background light))
843 (:foreground "indianred4" :italic t))
845 (:italic t))) "Face used for displaying header content."
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight)
848 ;; backward-compatibility alias
849 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
850 (put 'gnus-header-content-face 'obsolete-face "22.1")
852 (defcustom gnus-header-face-alist
853 '(("From" nil gnus-header-from)
854 ("Subject" nil gnus-header-subject)
855 ("Newsgroups:.*," nil gnus-header-newsgroups)
856 ("" gnus-header-name gnus-header-content))
857 "*Controls highlighting of article headers.
859 An alist of the form (HEADER NAME CONTENT).
861 HEADER is a regular expression which should match the name of a
862 header and NAME and CONTENT are either face names or nil.
864 The name of each header field will be displayed using the face
865 specified by the first element in the list where HEADER matches
866 the header name and NAME is non-nil. Similarly, the content will
867 be displayed by the first non-nil matching CONTENT face."
868 :group 'gnus-article-headers
869 :group 'gnus-article-highlight
870 :type '(repeat (list (regexp :tag "Header")
871 (choice :tag "Name"
872 (item :tag "skip" nil)
873 (face :value default))
874 (choice :tag "Content"
875 (item :tag "skip" nil)
876 (face :value default)))))
878 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
879 '((xface . (:face gnus-x-face)))
880 '((pbm . (:face gnus-x-face))
881 (png . nil)))
882 "Alist of image types and properties applied to Face and X-Face images.
883 Here are examples:
885 ;; Specify the altitude of Face images in the From header.
886 \(setq gnus-face-properties-alist
887 '((pbm . (:face gnus-x-face :ascent 80))
888 (png . (:ascent 80))))
890 ;; Show Face images as pressed buttons.
891 \(setq gnus-face-properties-alist
892 '((pbm . (:face gnus-x-face :relief -2))
893 (png . (:relief -2))))
895 See the manual for the valid properties for various image types.
896 Currently, `pbm' is used for X-Face images and `png' is used for Face
897 images in Emacs. Only the `:face' property is effective on the `xface'
898 image type in XEmacs if it is built with the libcompface library."
899 :version "23.1" ;; No Gnus
900 :group 'gnus-article-headers
901 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
903 (defcustom gnus-article-decode-hook
904 '(article-decode-charset article-decode-encoded-words
905 article-decode-group-name article-decode-idna-rhs)
906 "*Hook run to decode charsets in articles."
907 :group 'gnus-article-headers
908 :type 'hook)
910 (defcustom gnus-display-mime-function 'gnus-display-mime
911 "Function to display MIME articles."
912 :group 'gnus-article-mime
913 :type 'function)
915 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
916 "Function used to decode headers.")
918 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
919 "Function used to decode addresses.")
921 (defvar gnus-article-dumbquotes-map
922 '((?\200 "EUR")
923 (?\202 ",")
924 (?\203 "f")
925 (?\204 ",,")
926 (?\205 "...")
927 (?\213 "<")
928 (?\214 "OE")
929 (?\221 "`")
930 (?\222 "'")
931 (?\223 "``")
932 (?\224 "\"")
933 (?\225 "*")
934 (?\226 "-")
935 (?\227 "--")
936 (?\230 "~")
937 (?\231 "(TM)")
938 (?\233 ">")
939 (?\234 "oe")
940 (?\264 "'"))
941 "Table for MS-to-Latin1 translation.")
943 (defcustom gnus-ignored-mime-types nil
944 "List of MIME types that should be ignored by Gnus."
945 :version "21.1"
946 :group 'gnus-article-mime
947 :type '(repeat regexp))
949 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
950 "List of MIME types that should not be given buttons when rendered inline.
951 See also `gnus-buttonized-mime-types' which may override this variable.
952 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
953 :version "21.1"
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
957 (defcustom gnus-buttonized-mime-types nil
958 "List of MIME types that should be given buttons when rendered inline.
959 If set, this variable overrides `gnus-unbuttonized-mime-types'.
960 To see e.g. security buttons you could set this to
961 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
962 this list to display radio buttons that allow you to choose one of two
963 media types those mails include. See also `mm-discouraged-alternatives'.
964 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
965 :version "22.1"
966 :group 'gnus-article-mime
967 :type '(repeat regexp))
969 (defcustom gnus-inhibit-mime-unbuttonizing nil
970 "If non-nil, all MIME parts get buttons.
971 When nil (the default value), then some MIME parts do not get buttons,
972 as described by the variables `gnus-buttonized-mime-types' and
973 `gnus-unbuttonized-mime-types'."
974 :version "22.1"
975 :group 'gnus-article-mime
976 :type 'boolean)
978 (defcustom gnus-body-boundary-delimiter "_"
979 "String used to delimit header and body.
980 This variable is used by `gnus-article-treat-body-boundary' which can
981 be controlled by `gnus-treat-body-boundary'."
982 :version "22.1"
983 :group 'gnus-article-various
984 :type '(choice (item :tag "None" :value nil)
985 string))
987 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
988 "/usr/share/picons")
989 "Defines the location of the faces database.
990 For information on obtaining this database of pretty pictures, please
991 see http://www.cs.indiana.edu/picons/ftp/index.html"
992 :version "22.1"
993 :type '(repeat directory)
994 :link '(url-link :tag "download"
995 "http://www.cs.indiana.edu/picons/ftp/index.html")
996 :link '(custom-manual "(gnus)Picons")
997 :group 'gnus-picon)
999 (defun gnus-picons-installed-p ()
1000 "Say whether picons are installed on your machine."
1001 (let ((installed nil))
1002 (dolist (database gnus-picon-databases)
1003 (when (file-exists-p database)
1004 (setq installed t)))
1005 installed))
1007 (defcustom gnus-article-mime-part-function nil
1008 "Function called with a MIME handle as the argument.
1009 This is meant for people who want to do something automatic based
1010 on parts -- for instance, adding Vcard info to a database."
1011 :group 'gnus-article-mime
1012 :type '(choice (const nil)
1013 function))
1015 (defcustom gnus-mime-multipart-functions nil
1016 "An alist of MIME types to functions to display them."
1017 :version "21.1"
1018 :group 'gnus-article-mime
1019 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1021 (defcustom gnus-article-date-headers '(combined-lapsed)
1022 "A list of Date header formats to display.
1023 Valid formats are `ut' (universal time), `local' (local time
1024 zone), `english' (readable English), `lapsed' (elapsed time),
1025 `combined-lapsed' (both the original date and the elapsed time),
1026 `original' (the original date header), `iso8601' (ISO8601
1027 format), and `user-defined' (a user-defined format defined by the
1028 `gnus-article-time-format' variable).
1030 You have as many date headers as you want in the article buffer.
1031 Some of these headers are updated automatically. See
1032 `gnus-article-update-date-headers' for details."
1033 :version "24.1"
1034 :group 'gnus-article-headers
1035 :type '(repeat
1036 (item :tag "Universal time (UT)" :value 'ut)
1037 (item :tag "Local time zone" :value 'local)
1038 (item :tag "Readable English" :value 'english)
1039 (item :tag "Elapsed time" :value 'lapsed)
1040 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1041 (item :tag "Original date header" :value 'original)
1042 (item :tag "ISO8601 format" :value 'iso8601)
1043 (item :tag "User-defined" :value 'user-defined)))
1045 (defcustom gnus-article-update-date-headers nil
1046 "A number that says how often to update the date header (in seconds).
1047 If nil, don't update it at all."
1048 :version "24.1"
1049 :group 'gnus-article-headers
1050 :type '(choice
1051 (item :tag "Don't update" :value nil)
1052 integer))
1054 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1055 "Function called with a MIME handle as the argument.
1056 This is meant for people who want to view first matched part.
1057 For `undisplayed-alternative' (default), the first undisplayed
1058 part or alternative part is used. For `undisplayed', the first
1059 undisplayed part is used. For a function, the first part which
1060 the function return t is used. For nil, the first part is
1061 used."
1062 :version "21.1"
1063 :group 'gnus-article-mime
1064 :type '(choice
1065 (item :tag "first" :value nil)
1066 (item :tag "undisplayed" :value undisplayed)
1067 (item :tag "undisplayed or alternative"
1068 :value undisplayed-alternative)
1069 (function)))
1071 (defcustom gnus-mime-action-alist
1072 '(("save to file" . gnus-mime-save-part)
1073 ("save and strip" . gnus-mime-save-part-and-strip)
1074 ("replace with file" . gnus-mime-replace-part)
1075 ("delete part" . gnus-mime-delete-part)
1076 ("display as text" . gnus-mime-inline-part)
1077 ("view the part" . gnus-mime-view-part)
1078 ("pipe to command" . gnus-mime-pipe-part)
1079 ("toggle display" . gnus-article-press-button)
1080 ("toggle display" . gnus-article-view-part-as-charset)
1081 ("view as type" . gnus-mime-view-part-as-type)
1082 ("view internally" . gnus-mime-view-part-internally)
1083 ("view externally" . gnus-mime-view-part-externally))
1084 "An alist of actions that run on the MIME attachment."
1085 :group 'gnus-article-mime
1086 :type '(repeat (cons (string :tag "name")
1087 (function))))
1089 (defcustom gnus-auto-select-part 1
1090 "Advance to next MIME part when deleting or stripping parts.
1092 When 0, point will be placed on the same part as before. When
1093 positive (negative), move point forward (backwards) this many
1094 parts. When nil, redisplay article."
1095 :version "23.1" ;; No Gnus
1096 :group 'gnus-article-mime
1097 :type '(choice (const nil :tag "Redisplay article.")
1098 (const 1 :tag "Next part.")
1099 (const 0 :tag "Current part.")
1100 integer))
1103 ;;; The treatment variables
1106 (defvar gnus-part-display-hook nil
1107 "Hook called on parts that are to receive treatment.")
1109 (defvar gnus-article-treat-custom
1110 '(choice (const :tag "Off" nil)
1111 (const :tag "On" t)
1112 (const :tag "Header" head)
1113 (const :tag "First" first)
1114 (const :tag "Last" last)
1115 (integer :tag "Less")
1116 (repeat :tag "Groups" regexp)
1117 (sexp :tag "Predicate")))
1119 (defvar gnus-article-treat-head-custom
1120 '(choice (const :tag "Off" nil)
1121 (const :tag "Header" head)))
1123 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1124 "text/x-patch")
1125 "Parts to treat.")
1127 (defvar gnus-inhibit-treatment nil
1128 "Whether to inhibit treatment.")
1130 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1131 "Highlight the signature.
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate. See Info node `(gnus)Customizing Articles'."
1134 :group 'gnus-article-treat
1135 :link '(custom-manual "(gnus)Customizing Articles")
1136 :type gnus-article-treat-custom)
1137 (put 'gnus-treat-highlight-signature 'highlight t)
1139 (defcustom gnus-treat-buttonize 100000
1140 "Add buttons.
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1143 :group 'gnus-article-treat
1144 :link '(custom-manual "(gnus)Customizing Articles")
1145 :type gnus-article-treat-custom)
1146 (put 'gnus-treat-buttonize 'highlight t)
1148 (defcustom gnus-treat-buttonize-head 'head
1149 "Add buttons to the head.
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate. See Info node `(gnus)Customizing Articles'."
1152 :group 'gnus-article-treat
1153 :link '(custom-manual "(gnus)Customizing Articles")
1154 :type gnus-article-treat-head-custom)
1155 (put 'gnus-treat-buttonize-head 'highlight t)
1157 (defcustom gnus-treat-date 'head
1158 "Display dates according to the `gnus-article-date-headers' variable.
1159 Valid values are nil, t, `head', `first', `last', an integer or a
1160 predicate. See Info node `(gnus)Customizing Articles'."
1161 :version "24.1"
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-emphasize 50000
1167 "Emphasize text.
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-custom)
1173 (put 'gnus-treat-emphasize 'highlight t)
1175 (defcustom gnus-treat-strip-cr nil
1176 "Remove carriage returns.
1177 Valid values are nil, t, `head', `first', `last', an integer or a
1178 predicate. See Info node `(gnus)Customizing Articles'."
1179 :version "22.1"
1180 :group 'gnus-article-treat
1181 :link '(custom-manual "(gnus)Customizing Articles")
1182 :type gnus-article-treat-custom)
1184 (defcustom gnus-treat-unsplit-urls nil
1185 "Remove newlines from within URLs.
1186 Valid values are nil, t, `head', `first', `last', an integer or a
1187 predicate. See Info node `(gnus)Customizing Articles'."
1188 :version "22.1"
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-custom)
1193 (defcustom gnus-treat-leading-whitespace nil
1194 "Remove leading whitespace in headers.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1197 :version "22.1"
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-custom)
1202 (defcustom gnus-treat-hide-headers 'head
1203 "Hide headers.
1204 Valid values are nil, t, `head', `first', `last', an integer or a
1205 predicate. See Info node `(gnus)Customizing Articles'."
1206 :group 'gnus-article-treat
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-head-custom)
1210 (defcustom gnus-treat-hide-boring-headers nil
1211 "Hide boring headers.
1212 Valid values are nil, t, `head', `first', `last', an integer or a
1213 predicate. See Info node `(gnus)Customizing Articles'."
1214 :group 'gnus-article-treat
1215 :link '(custom-manual "(gnus)Customizing Articles")
1216 :type gnus-article-treat-head-custom)
1218 (defcustom gnus-treat-hide-signature nil
1219 "Hide the signature.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-fill-article nil
1227 "Fill the article.
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate. See Info node `(gnus)Customizing Articles'."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1234 (defcustom gnus-treat-hide-citation nil
1235 "Hide cited text.
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'.
1239 See `gnus-article-highlight-citation' for variables used to
1240 control what it hides."
1241 :group 'gnus-article-treat
1242 :link '(custom-manual "(gnus)Customizing Articles")
1243 :type gnus-article-treat-custom)
1245 (defcustom gnus-treat-hide-citation-maybe nil
1246 "Hide cited text according to certain conditions.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'.
1250 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1251 how to control what it hides."
1252 :group 'gnus-article-treat
1253 :link '(custom-manual "(gnus)Customizing Articles")
1254 :type gnus-article-treat-custom)
1256 (defcustom gnus-treat-strip-list-identifiers 'head
1257 "Strip list identifiers from `gnus-list-identifiers`.
1258 Valid values are nil, t, `head', `first', `last', an integer or a
1259 predicate. See Info node `(gnus)Customizing Articles'."
1260 :version "21.1"
1261 :group 'gnus-article-treat
1262 :link '(custom-manual "(gnus)Customizing Articles")
1263 :type gnus-article-treat-custom)
1265 (gnus-define-group-parameter
1266 list-identifier
1267 :variable-document
1268 "Alist of regexps and correspondent identifiers."
1269 :variable-group gnus-article-washing
1270 :parameter-type
1271 '(choice :tag "Identifier"
1272 :value nil
1273 (symbol :tag "Item in `gnus-list-identifiers'" none)
1274 regexp
1275 (const :tag "None" nil))
1276 :parameter-document
1277 "If non-nil, specify how to remove `identifiers' from articles' subject.
1279 Any symbol is used to look up a regular expression to match the
1280 banner in `gnus-list-identifiers'. A string is used as a regular
1281 expression to match the identifier directly.")
1283 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1284 "Gnus 5.10 (Emacs 22.1)")
1286 (defcustom gnus-treat-strip-pem nil
1287 "Strip PEM signatures.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-custom)
1294 (defcustom gnus-treat-strip-banner t
1295 "Strip banners from articles.
1296 The banner to be stripped is specified in the `banner' group parameter.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-custom)
1303 (defcustom gnus-treat-highlight-headers 'head
1304 "Highlight the headers.
1305 Valid values are nil, t, `head', `first', `last', an integer or a
1306 predicate. See Info node `(gnus)Customizing Articles'."
1307 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :type gnus-article-treat-head-custom)
1310 (put 'gnus-treat-highlight-headers 'highlight t)
1312 (defcustom gnus-treat-highlight-citation t
1313 "Highlight cited text.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1316 :group 'gnus-article-treat
1317 :link '(custom-manual "(gnus)Customizing Articles")
1318 :type gnus-article-treat-custom)
1319 (put 'gnus-treat-highlight-citation 'highlight t)
1321 (defcustom gnus-treat-strip-headers-in-body t
1322 "Strip the X-No-Archive header line from the beginning of the body.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'."
1325 :version "21.1"
1326 :group 'gnus-article-treat
1327 :link '(custom-manual "(gnus)Customizing Articles")
1328 :type gnus-article-treat-custom)
1330 (defcustom gnus-treat-strip-trailing-blank-lines nil
1331 "Strip trailing blank lines.
1332 Valid values are nil, t, `head', `first', `last', an integer or a
1333 predicate. See Info node `(gnus)Customizing Articles'.
1335 When set to t, it also strips trailing blanks in all MIME parts.
1336 Consider to use `last' instead."
1337 :group 'gnus-article-treat
1338 :link '(custom-manual "(gnus)Customizing Articles")
1339 :type gnus-article-treat-custom)
1341 (defcustom gnus-treat-strip-leading-blank-lines nil
1342 "Strip leading blank lines.
1343 Valid values are nil, t, `head', `first', `last', an integer or a
1344 predicate. See Info node `(gnus)Customizing Articles'.
1346 When set to t, it also strips trailing blanks in all MIME parts."
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1351 (defcustom gnus-treat-strip-multiple-blank-lines nil
1352 "Strip multiple blank lines.
1353 Valid values are nil, t, `head', `first', `last', an integer or a
1354 predicate. See Info node `(gnus)Customizing Articles'."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1359 (defcustom gnus-treat-unfold-headers 'head
1360 "Unfold folded header lines.
1361 Valid values are nil, t, `head', `first', `last', an integer or a
1362 predicate. See Info node `(gnus)Customizing Articles'."
1363 :version "22.1"
1364 :group 'gnus-article-treat
1365 :link '(custom-manual "(gnus)Customizing Articles")
1366 :type gnus-article-treat-custom)
1368 (defcustom gnus-article-unfold-long-headers nil
1369 "If non-nil, allow unfolding headers even if the header is long.
1370 If it is a regexp, only long headers matching this regexp are unfolded.
1371 If it is t, all long headers are unfolded.
1373 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1374 :version "23.1" ;; No Gnus
1375 :group 'gnus-article-treat
1376 :type '(choice (const nil)
1377 (const :tag "all" t)
1378 (regexp)))
1380 (defcustom gnus-treat-fold-headers nil
1381 "Fold headers.
1382 Valid values are nil, t, `head', `first', `last', an integer or a
1383 predicate. See Info node `(gnus)Customizing Articles'."
1384 :version "22.1"
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-fold-newsgroups 'head
1390 "Fold the Newsgroups and Followup-To headers.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1393 :version "22.1"
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1398 (defcustom gnus-treat-overstrike t
1399 "Treat overstrike highlighting.
1400 Valid values are nil, t, `head', `first', `last', an integer or a
1401 predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1405 (put 'gnus-treat-overstrike 'highlight t)
1407 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1408 "Treat ANSI SGR control sequences.
1409 Valid values are nil, t, `head', `first', `last', an integer or a
1410 predicate. See Info node `(gnus)Customizing Articles'."
1411 :group 'gnus-article-treat
1412 :link '(custom-manual "(gnus)Customizing Articles")
1413 :type gnus-article-treat-custom)
1415 (make-obsolete-variable 'gnus-treat-display-xface
1416 'gnus-treat-display-x-face "Emacs 22.1")
1418 (defcustom gnus-treat-display-x-face
1419 (and (not noninteractive)
1420 (gnus-image-type-available-p 'xbm)
1421 (if (featurep 'xemacs)
1422 (featurep 'xface)
1423 (condition-case nil
1424 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1425 (executable-find "icontopbm"))
1426 ;; shell-command-to-string may signal an error, e.g. if
1427 ;; shell-file-name is not found.
1428 (error nil)))
1429 'head)
1430 "Display X-Face headers.
1431 Valid values are nil and `head'.
1432 See Info node `(gnus)Customizing Articles' and Info node
1433 `(gnus)X-Face' for details."
1434 :group 'gnus-article-treat
1435 :version "21.1"
1436 :link '(custom-manual "(gnus)Customizing Articles")
1437 :link '(custom-manual "(gnus)X-Face")
1438 :type gnus-article-treat-head-custom
1439 :set (lambda (symbol value)
1440 (set-default
1441 symbol
1442 (cond ((or (boundp symbol) (get symbol 'saved-value))
1443 value)
1444 ((boundp 'gnus-treat-display-xface)
1445 (message "\
1446 ** gnus-treat-display-xface is an obsolete variable;\
1447 use gnus-treat-display-x-face instead")
1448 (default-value 'gnus-treat-display-xface))
1449 ((get 'gnus-treat-display-xface 'saved-value)
1450 (message "\
1451 ** gnus-treat-display-xface is an obsolete variable;\
1452 use gnus-treat-display-x-face instead")
1453 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1455 value)))))
1456 (put 'gnus-treat-display-x-face 'highlight t)
1458 (defcustom gnus-treat-display-face
1459 (and (not noninteractive)
1460 (gnus-image-type-available-p 'png)
1461 'head)
1462 "Display Face headers.
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles' and Info
1465 node `(gnus)Face' for details."
1466 :group 'gnus-article-treat
1467 :version "22.1"
1468 :link '(custom-manual "(gnus)Customizing Articles")
1469 :link '(custom-manual "(gnus)X-Face")
1470 :type gnus-article-treat-head-custom)
1471 (put 'gnus-treat-display-face 'highlight t)
1473 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1474 "Display smileys.
1475 Valid values are nil, t, `head', `first', `last', an integer or a
1476 predicate. See Info node `(gnus)Customizing Articles' and Info
1477 node `(gnus)Smileys' for details."
1478 :group 'gnus-article-treat
1479 :version "21.1"
1480 :link '(custom-manual "(gnus)Customizing Articles")
1481 :link '(custom-manual "(gnus)Smileys")
1482 :type gnus-article-treat-custom)
1483 (put 'gnus-treat-display-smileys 'highlight t)
1485 (defcustom gnus-treat-from-picon
1486 (if (and (gnus-image-type-available-p 'xpm)
1487 (gnus-picons-installed-p))
1488 'head nil)
1489 "Display picons in the From header.
1490 Valid values are nil, t, `head', `first', `last', an integer or a
1491 predicate. See Info node `(gnus)Customizing Articles' and Info
1492 node `(gnus)Picons' for details."
1493 :version "22.1"
1494 :group 'gnus-article-treat
1495 :group 'gnus-picon
1496 :link '(custom-manual "(gnus)Customizing Articles")
1497 :link '(custom-manual "(gnus)Picons")
1498 :type gnus-article-treat-head-custom)
1499 (put 'gnus-treat-from-picon 'highlight t)
1501 (defcustom gnus-treat-mail-picon
1502 (if (and (gnus-image-type-available-p 'xpm)
1503 (gnus-picons-installed-p))
1504 'head nil)
1505 "Display picons in To and Cc headers.
1506 Valid values are nil, t, `head', `first', `last', an integer or a
1507 predicate. See Info node `(gnus)Customizing Articles' and Info
1508 node `(gnus)Picons' for details."
1509 :version "22.1"
1510 :group 'gnus-article-treat
1511 :group 'gnus-picon
1512 :link '(custom-manual "(gnus)Customizing Articles")
1513 :link '(custom-manual "(gnus)Picons")
1514 :type gnus-article-treat-head-custom)
1515 (put 'gnus-treat-mail-picon 'highlight t)
1517 (defcustom gnus-treat-newsgroups-picon
1518 (if (and (gnus-image-type-available-p 'xpm)
1519 (gnus-picons-installed-p))
1520 'head nil)
1521 "Display picons in the Newsgroups and Followup-To headers.
1522 Valid values are nil, t, `head', `first', `last', an integer or a
1523 predicate. See Info node `(gnus)Customizing Articles' and Info
1524 node `(gnus)Picons' for details."
1525 :version "22.1"
1526 :group 'gnus-article-treat
1527 :group 'gnus-picon
1528 :link '(custom-manual "(gnus)Customizing Articles")
1529 :link '(custom-manual "(gnus)Picons")
1530 :type gnus-article-treat-head-custom)
1531 (put 'gnus-treat-newsgroups-picon 'highlight t)
1533 (defcustom gnus-treat-from-gravatar nil
1534 "Display gravatars in the From header.
1535 Valid values are nil, t, `head', `first', `last', an integer or a
1536 predicate. See Info node `(gnus)Customizing Articles' and Info
1537 node `(gnus)Gravatars' for details."
1538 :version "24.1"
1539 :group 'gnus-article-treat
1540 :group 'gnus-gravatar
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :link '(custom-manual "(gnus)Gravatars")
1543 :type gnus-article-treat-head-custom)
1544 (put 'gnus-treat-from-gravatar 'highlight t)
1546 (defcustom gnus-treat-mail-gravatar nil
1547 "Display gravatars in To and Cc headers.
1548 Valid values are nil, t, `head', `first', `last', an integer or a
1549 predicate. See Info node `(gnus)Customizing Articles' and Info
1550 node `(gnus)Gravatars' for details."
1551 :version "24.1"
1552 :group 'gnus-article-treat
1553 :group 'gnus-gravatar
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :link '(custom-manual "(gnus)Gravatars")
1556 :type gnus-article-treat-head-custom)
1557 (put 'gnus-treat-mail-gravatar 'highlight t)
1559 (defcustom gnus-treat-body-boundary
1560 (if (or gnus-treat-newsgroups-picon
1561 gnus-treat-mail-picon
1562 gnus-treat-from-picon
1563 gnus-treat-from-gravatar
1564 gnus-treat-mail-gravatar)
1565 ;; If there's much decoration, the user might prefer a boundary.
1566 'head
1567 nil)
1568 "Draw a boundary at the end of the headers.
1569 Valid values are nil and `head'.
1570 See Info node `(gnus)Customizing Articles' for details."
1571 :version "22.1"
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-head-custom)
1576 (defcustom gnus-treat-capitalize-sentences nil
1577 "Capitalize sentence-starting words.
1578 Valid values are nil, t, `head', `first', `last', an integer or a
1579 predicate. See Info node `(gnus)Customizing Articles'."
1580 :version "21.1"
1581 :group 'gnus-article-treat
1582 :link '(custom-manual "(gnus)Customizing Articles")
1583 :type gnus-article-treat-custom)
1585 (defcustom gnus-treat-wash-html nil
1586 "Format as HTML.
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1589 :version "22.1"
1590 :group 'gnus-article-treat
1591 :link '(custom-manual "(gnus)Customizing Articles")
1592 :type gnus-article-treat-custom)
1594 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1595 "Fill long lines.
1596 Valid values are nil, t, `head', `first', `last', an integer or a
1597 predicate. See Info node `(gnus)Customizing Articles'."
1598 :version "24.1"
1599 :group 'gnus-article-treat
1600 :link '(custom-manual "(gnus)Customizing Articles")
1601 :type gnus-article-treat-custom)
1603 (defcustom gnus-treat-x-pgp-sig nil
1604 "Verify X-PGP-Sig.
1605 To automatically treat X-PGP-Sig, set it to head.
1606 Valid values are nil, t, `head', `first', `last', an integer or a
1607 predicate. See Info node `(gnus)Customizing Articles'."
1608 :version "22.1"
1609 :group 'gnus-article-treat
1610 :group 'mime-security
1611 :link '(custom-manual "(gnus)Customizing Articles")
1612 :type gnus-article-treat-custom)
1614 (defvar gnus-article-encrypt-protocol-alist
1615 '(("PGP" . mml2015-self-encrypt)))
1617 ;; Set to nil if more than one protocol added to
1618 ;; gnus-article-encrypt-protocol-alist.
1619 (defcustom gnus-article-encrypt-protocol "PGP"
1620 "The protocol used for encrypt articles.
1621 It is a string, such as \"PGP\". If nil, ask user."
1622 :version "22.1"
1623 :type 'string
1624 :group 'mime-security)
1626 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1627 (mm-coding-system-p 'utf-8)
1628 (executable-find idna-program))
1629 "Whether IDNA decoding of headers is used when viewing messages.
1630 This requires GNU Libidn, and by default only enabled if it is found."
1631 :version "22.1"
1632 :group 'gnus-article-headers
1633 :type 'boolean)
1635 (defcustom gnus-article-over-scroll nil
1636 "If non-nil, allow scrolling the article buffer even when there no more text."
1637 :version "22.1"
1638 :group 'gnus-article
1639 :type 'boolean)
1641 (defcustom gnus-inhibit-images nil
1642 "Non-nil means inhibit displaying of images inline in the article body."
1643 :version "24.1"
1644 :group 'gnus-article
1645 :type 'boolean)
1647 (defcustom gnus-blocked-images 'gnus-block-private-groups
1648 "Images that have URLs matching this regexp will be blocked.
1649 This can also be a function to be evaluated. If so, it will be
1650 called with the group name as the parameter, and should return a
1651 regexp."
1652 :version "24.1"
1653 :group 'gnus-art
1654 :type 'regexp)
1656 ;;; Internal variables
1658 (defvar gnus-english-month-names
1659 '("January" "February" "March" "April" "May" "June" "July" "August"
1660 "September" "October" "November" "December"))
1662 (defvar article-goto-body-goes-to-point-min-p nil)
1663 (defvar gnus-article-wash-types nil)
1664 (defvar gnus-article-emphasis-alist nil)
1665 (defvar gnus-article-image-alist nil)
1667 (defvar gnus-article-mime-handle-alist-1 nil)
1668 (defvar gnus-treatment-function-alist
1669 '((gnus-treat-strip-cr gnus-article-remove-cr)
1670 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1671 (gnus-treat-strip-banner gnus-article-strip-banner)
1672 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1673 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1674 (gnus-treat-buttonize gnus-article-add-buttons)
1675 (gnus-treat-fill-article gnus-article-fill-cited-article)
1676 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1677 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1678 (gnus-treat-display-x-face gnus-article-display-x-face)
1679 (gnus-treat-display-face gnus-article-display-face)
1680 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1681 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1682 (gnus-treat-hide-signature gnus-article-hide-signature)
1683 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1684 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1685 (gnus-treat-from-picon gnus-treat-from-picon)
1686 (gnus-treat-mail-picon gnus-treat-mail-picon)
1687 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1688 (gnus-treat-strip-pem gnus-article-hide-pem)
1689 (gnus-treat-date gnus-article-treat-date)
1690 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1691 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1692 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1693 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1694 (gnus-treat-strip-trailing-blank-lines
1695 gnus-article-remove-trailing-blank-lines)
1696 (gnus-treat-strip-leading-blank-lines
1697 gnus-article-strip-leading-blank-lines)
1698 (gnus-treat-strip-multiple-blank-lines
1699 gnus-article-strip-multiple-blank-lines)
1700 (gnus-treat-overstrike gnus-article-treat-overstrike)
1701 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1702 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1703 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1704 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1705 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1706 (gnus-treat-display-smileys gnus-treat-smiley)
1707 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1708 (gnus-treat-wash-html gnus-article-wash-html)
1709 (gnus-treat-emphasize gnus-article-emphasize)
1710 (gnus-treat-hide-citation gnus-article-hide-citation)
1711 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1712 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1713 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1715 (defvar gnus-article-mime-handle-alist nil)
1716 (defvar article-lapsed-timer nil)
1717 (defvar gnus-article-current-summary nil)
1719 (defvar gnus-article-mode-syntax-table
1720 (let ((table (copy-syntax-table text-mode-syntax-table)))
1721 ;; This causes the citation match run O(2^n).
1722 ;; (modify-syntax-entry ?- "w" table)
1723 (modify-syntax-entry ?> ")<" table)
1724 (modify-syntax-entry ?< "(>" table)
1725 ;; make M-. in article buffers work for `foo' strings
1726 (modify-syntax-entry ?' " " table)
1727 (modify-syntax-entry ?` " " table)
1728 table)
1729 "Syntax table used in article mode buffers.
1730 Initialized from `text-mode-syntax-table.")
1732 (defvar gnus-save-article-buffer nil)
1734 (defvar gnus-number-of-articles-to-be-saved nil)
1736 (defvar gnus-inhibit-hiding nil)
1738 (defvar gnus-article-edit-mode nil)
1740 ;;; Macros for dealing with the article buffer.
1742 (defmacro gnus-with-article-headers (&rest forms)
1743 `(with-current-buffer gnus-article-buffer
1744 (save-restriction
1745 (let ((inhibit-read-only t)
1746 (inhibit-point-motion-hooks t)
1747 (case-fold-search t))
1748 (article-narrow-to-head)
1749 ,@forms))))
1751 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1752 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1754 (defmacro gnus-with-article-buffer (&rest forms)
1755 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1756 (with-current-buffer gnus-article-buffer
1757 (let ((inhibit-read-only t))
1758 ,@forms))))
1760 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1761 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1763 (defun gnus-article-goto-header (header)
1764 "Go to HEADER, which is a regular expression."
1765 (re-search-forward (concat "^\\(" header "\\):") nil t))
1767 (defsubst gnus-article-hide-text (b e props)
1768 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1769 (gnus-add-text-properties-when 'article-type nil b e props)
1770 (when (memq 'intangible props)
1771 (put-text-property
1772 (max (1- b) (point-min))
1773 b 'intangible (cddr (memq 'intangible props)))))
1775 (defsubst gnus-article-unhide-text (b e)
1776 "Remove hidden text properties from region between B and E."
1777 (remove-text-properties b e gnus-hidden-properties)
1778 (when (memq 'intangible gnus-hidden-properties)
1779 (put-text-property (max (1- b) (point-min))
1780 b 'intangible nil)))
1782 (defun gnus-article-hide-text-type (b e type)
1783 "Hide text of TYPE between B and E."
1784 (gnus-add-wash-type type)
1785 (gnus-article-hide-text
1786 b e (cons 'article-type (cons type gnus-hidden-properties))))
1788 (defun gnus-article-unhide-text-type (b e type)
1789 "Unhide text of TYPE between B and E."
1790 (gnus-delete-wash-type type)
1791 (remove-text-properties
1792 b e (cons 'article-type (cons type gnus-hidden-properties)))
1793 (when (memq 'intangible gnus-hidden-properties)
1794 (put-text-property (max (1- b) (point-min))
1795 b 'intangible nil)))
1797 (defun gnus-article-hide-text-of-type (type)
1798 "Hide text of TYPE in the current buffer."
1799 (save-excursion
1800 (let ((b (point-min))
1801 (e (point-max)))
1802 (while (setq b (text-property-any b e 'article-type type))
1803 (add-text-properties b (incf b) gnus-hidden-properties)))))
1805 (defun gnus-article-delete-text-of-type (type)
1806 "Delete text of TYPE in the current buffer."
1807 (save-excursion
1808 (let ((b (point-min)))
1809 (if (eq type 'multipart)
1810 ;; Remove MIME buttons associated with multipart/alternative parts.
1811 (progn
1812 (goto-char b)
1813 (while (if (get-text-property (point) 'gnus-part)
1814 (setq b (point))
1815 (when (setq b (next-single-property-change (point)
1816 'gnus-part))
1817 (goto-char b)
1819 (end-of-line)
1820 (skip-chars-forward "\n")
1821 (when (eq (get-text-property b 'article-type) 'multipart)
1822 (delete-region b (point)))))
1823 (while (setq b (text-property-any b (point-max) 'article-type type))
1824 (delete-region
1825 b (or (text-property-not-all b (point-max) 'article-type type)
1826 (point-max))))))))
1828 (defun gnus-article-delete-invisible-text ()
1829 "Delete all invisible text in the current buffer."
1830 (save-excursion
1831 (let ((b (point-min)))
1832 (while (setq b (text-property-any b (point-max) 'invisible t))
1833 (delete-region
1834 b (or (text-property-not-all b (point-max) 'invisible t)
1835 (point-max)))))))
1837 (defun gnus-article-text-type-exists-p (type)
1838 "Say whether any text of type TYPE exists in the buffer."
1839 (text-property-any (point-min) (point-max) 'article-type type))
1841 (defsubst gnus-article-header-rank ()
1842 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1843 (let ((list gnus-sorted-header-list)
1844 (i 1))
1845 (while list
1846 (if (looking-at (car list))
1847 (setq list nil)
1848 (setq list (cdr list))
1849 (incf i)))
1852 (defun article-hide-headers (&optional arg delete)
1853 "Hide unwanted headers and possibly sort them as well."
1854 (interactive)
1855 ;; This function might be inhibited.
1856 (unless gnus-inhibit-hiding
1857 (let ((inhibit-read-only t)
1858 (case-fold-search t)
1859 (max (1+ (length gnus-sorted-header-list)))
1860 (inhibit-point-motion-hooks t)
1861 (cur (current-buffer))
1862 ignored visible beg)
1863 (save-excursion
1864 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1865 ;; group parameters, so we should go to the summary buffer.
1866 (when (prog1
1867 (condition-case nil
1868 (progn (set-buffer gnus-summary-buffer) t)
1869 (error nil))
1870 (setq ignored (when (not gnus-visible-headers)
1871 (cond ((stringp gnus-ignored-headers)
1872 gnus-ignored-headers)
1873 ((listp gnus-ignored-headers)
1874 (mapconcat 'identity
1875 gnus-ignored-headers
1876 "\\|"))))
1877 visible (cond ((stringp gnus-visible-headers)
1878 gnus-visible-headers)
1879 ((and gnus-visible-headers
1880 (listp gnus-visible-headers))
1881 (mapconcat 'identity
1882 gnus-visible-headers
1883 "\\|")))))
1884 (set-buffer cur))
1885 (save-restriction
1886 ;; First we narrow to just the headers.
1887 (article-narrow-to-head)
1888 ;; Hide any "From " lines at the beginning of (mail) articles.
1889 (while (looking-at "From ")
1890 (forward-line 1))
1891 (unless (bobp)
1892 (delete-region (point-min) (point)))
1893 ;; Then treat the rest of the header lines.
1894 ;; Then we use the two regular expressions
1895 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1896 ;; select which header lines is to remain visible in the
1897 ;; article buffer.
1898 (while (re-search-forward "^[^ \t:]*:" nil t)
1899 (beginning-of-line)
1900 ;; Mark the rank of the header.
1901 (put-text-property
1902 (point) (1+ (point)) 'message-rank
1903 (if (or (and visible (looking-at visible))
1904 (and ignored
1905 (not (looking-at ignored))))
1906 (gnus-article-header-rank)
1907 (+ 2 max)))
1908 (forward-line 1))
1909 (message-sort-headers-1)
1910 (when (setq beg (text-property-any
1911 (point-min) (point-max) 'message-rank (+ 2 max)))
1912 ;; We delete the unwanted headers.
1913 (gnus-add-wash-type 'headers)
1914 (add-text-properties (point-min) (+ 5 (point-min))
1915 '(article-type headers dummy-invisible t))
1916 (delete-region beg (point-max))))))))
1918 (defun article-hide-boring-headers (&optional arg)
1919 "Toggle hiding of headers that aren't very interesting.
1920 If given a negative prefix, always show; if given a positive prefix,
1921 always hide."
1922 (interactive (gnus-article-hidden-arg))
1923 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1924 (not gnus-show-all-headers))
1925 (save-excursion
1926 (save-restriction
1927 (let ((inhibit-read-only t)
1928 (inhibit-point-motion-hooks t))
1929 (article-narrow-to-head)
1930 (dolist (elem gnus-boring-article-headers)
1931 (goto-char (point-min))
1932 (cond
1933 ;; Hide empty headers.
1934 ((eq elem 'empty)
1935 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1936 (forward-line -1)
1937 (gnus-article-hide-text-type
1938 (point-at-bol)
1939 (progn
1940 (end-of-line)
1941 (if (re-search-forward "^[^ \t]" nil t)
1942 (match-beginning 0)
1943 (point-max)))
1944 'boring-headers)))
1945 ;; Hide boring Newsgroups header.
1946 ((eq elem 'newsgroups)
1947 (when (gnus-string-equal
1948 (gnus-fetch-field "newsgroups")
1949 (gnus-group-real-name
1950 (if (boundp 'gnus-newsgroup-name)
1951 gnus-newsgroup-name
1952 "")))
1953 (gnus-article-hide-header "newsgroups")))
1954 ((eq elem 'to-address)
1955 (let ((to (message-fetch-field "to"))
1956 (to-address
1957 (gnus-parameter-to-address
1958 (if (boundp 'gnus-newsgroup-name)
1959 gnus-newsgroup-name ""))))
1960 (when (and to to-address
1961 (ignore-errors
1962 (gnus-string-equal
1963 ;; only one address in To
1964 (nth 1 (mail-extract-address-components to))
1965 to-address)))
1966 (gnus-article-hide-header "to"))))
1967 ((eq elem 'to-list)
1968 (let ((to (message-fetch-field "to"))
1969 (to-list
1970 (gnus-parameter-to-list
1971 (if (boundp 'gnus-newsgroup-name)
1972 gnus-newsgroup-name ""))))
1973 (when (and to to-list
1974 (ignore-errors
1975 (gnus-string-equal
1976 ;; only one address in To
1977 (nth 1 (mail-extract-address-components to))
1978 to-list)))
1979 (gnus-article-hide-header "to"))))
1980 ((eq elem 'cc-list)
1981 (let ((cc (message-fetch-field "cc"))
1982 (to-list
1983 (gnus-parameter-to-list
1984 (if (boundp 'gnus-newsgroup-name)
1985 gnus-newsgroup-name ""))))
1986 (when (and cc to-list
1987 (ignore-errors
1988 (gnus-string-equal
1989 ;; only one address in CC
1990 (nth 1 (mail-extract-address-components cc))
1991 to-list)))
1992 (gnus-article-hide-header "cc"))))
1993 ((eq elem 'followup-to)
1994 (when (gnus-string-equal
1995 (message-fetch-field "followup-to")
1996 (message-fetch-field "newsgroups"))
1997 (gnus-article-hide-header "followup-to")))
1998 ((eq elem 'reply-to)
1999 (if (gnus-group-find-parameter
2000 gnus-newsgroup-name 'broken-reply-to)
2001 (gnus-article-hide-header "reply-to")
2002 (let ((from (message-fetch-field "from"))
2003 (reply-to (message-fetch-field "reply-to")))
2004 (when
2005 (and
2006 from reply-to
2007 (ignore-errors
2008 (equal
2009 (sort (mapcar
2010 (lambda (x) (downcase (cadr x)))
2011 (mail-extract-address-components from t))
2012 'string<)
2013 (sort (mapcar
2014 (lambda (x) (downcase (cadr x)))
2015 (mail-extract-address-components reply-to t))
2016 'string<))))
2017 (gnus-article-hide-header "reply-to")))))
2018 ((eq elem 'date)
2019 (let ((date (with-current-buffer gnus-original-article-buffer
2020 ;; If date in `gnus-article-buffer' is localized
2021 ;; (`gnus-treat-date-user-defined'),
2022 ;; `days-between' might fail.
2023 (message-fetch-field "date"))))
2024 (when (and date
2025 (< (days-between (current-time-string) date)
2027 (gnus-article-hide-header "date"))))
2028 ((eq elem 'long-to)
2029 (let ((to (message-fetch-field "to"))
2030 (cc (message-fetch-field "cc")))
2031 (when (> (length to) 1024)
2032 (gnus-article-hide-header "to"))
2033 (when (> (length cc) 1024)
2034 (gnus-article-hide-header "cc"))))
2035 ((eq elem 'many-to)
2036 (let ((to-count 0)
2037 (cc-count 0))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^to:" nil t)
2040 (setq to-count (1+ to-count)))
2041 (when (> to-count 1)
2042 (while (> to-count 0)
2043 (goto-char (point-min))
2044 (save-restriction
2045 (re-search-forward "^to:" nil nil to-count)
2046 (forward-line -1)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "to"))
2049 (setq to-count (1- to-count))))
2050 (goto-char (point-min))
2051 (while (re-search-forward "^cc:" nil t)
2052 (setq cc-count (1+ cc-count)))
2053 (when (> cc-count 1)
2054 (while (> cc-count 0)
2055 (goto-char (point-min))
2056 (save-restriction
2057 (re-search-forward "^cc:" nil nil cc-count)
2058 (forward-line -1)
2059 (narrow-to-region (point) (point-max))
2060 (gnus-article-hide-header "cc"))
2061 (setq cc-count (1- cc-count)))))))))))))
2063 (defun gnus-article-hide-header (header)
2064 (save-excursion
2065 (goto-char (point-min))
2066 (when (re-search-forward (concat "^" header ":") nil t)
2067 (gnus-article-hide-text-type
2068 (point-at-bol)
2069 (progn
2070 (end-of-line)
2071 (if (re-search-forward "^[^ \t]" nil t)
2072 (match-beginning 0)
2073 (point-max)))
2074 'boring-headers))))
2076 (defvar gnus-article-normalized-header-length 40
2077 "Length of normalized headers.")
2079 (defun article-normalize-headers ()
2080 "Make all header lines 40 characters long."
2081 (interactive)
2082 (let ((inhibit-read-only t)
2083 column)
2084 (save-excursion
2085 (save-restriction
2086 (article-narrow-to-head)
2087 (while (not (eobp))
2088 (cond
2089 ((< (setq column (- (point-at-eol) (point)))
2090 gnus-article-normalized-header-length)
2091 (end-of-line)
2092 (insert (make-string
2093 (- gnus-article-normalized-header-length column)
2094 ? )))
2095 ((> column gnus-article-normalized-header-length)
2096 (gnus-put-text-property
2097 (progn
2098 (forward-char gnus-article-normalized-header-length)
2099 (point))
2100 (point-at-eol)
2101 'invisible t))
2103 ;; Do nothing.
2105 (forward-line 1))))))
2107 (defun article-treat-dumbquotes ()
2108 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2109 Note that this function guesses whether a character is a sm*rtq**t* or
2110 not, so it should only be used interactively.
2112 Sm*rtq**t*s are M****s***'s unilateral extension to the
2113 iso-8859-1 character map in an attempt to provide more quoting
2114 characters. If you see something like \\222 or \\264 where
2115 you're expecting some kind of apostrophe or quotation mark, then
2116 try this wash."
2117 (interactive)
2118 (article-translate-strings gnus-article-dumbquotes-map))
2120 (defvar org-entities)
2122 (defun article-treat-non-ascii ()
2123 "Translate many Unicode characters into their ASCII equivalents."
2124 (interactive)
2125 (require 'org-entities)
2126 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2127 (dolist (elem org-entities)
2128 (when (and (listp elem)
2129 (= (length (nth 6 elem)) 1))
2130 (if (featurep 'xemacs)
2131 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2132 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2133 (save-excursion
2134 (when (article-goto-body)
2135 (let ((inhibit-read-only t)
2136 replace props)
2137 (while (not (eobp))
2138 (if (not (setq replace (if (featurep 'xemacs)
2139 (get-char-table (following-char) table)
2140 (aref table (following-char)))))
2141 (forward-char 1)
2142 (if (prog1
2143 (setq props (text-properties-at (point)))
2144 (delete-char 1))
2145 (add-text-properties (point) (progn (insert replace) (point))
2146 props)
2147 (insert replace)))))))))
2149 (defun article-translate-characters (from to)
2150 "Translate all characters in the body of the article according to FROM and TO.
2151 FROM is a string of characters to translate from; to is a string of
2152 characters to translate to."
2153 (save-excursion
2154 (when (article-goto-body)
2155 (let ((inhibit-read-only t)
2156 (x (make-string 225 ?x))
2157 (i -1))
2158 (while (< (incf i) (length x))
2159 (aset x i i))
2160 (setq i 0)
2161 (while (< i (length from))
2162 (aset x (aref from i) (aref to i))
2163 (incf i))
2164 (translate-region (point) (point-max) x)))))
2166 (defun article-translate-strings (map)
2167 "Translate all string in the body of the article according to MAP.
2168 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2169 (save-excursion
2170 (when (article-goto-body)
2171 (let ((inhibit-read-only t))
2172 (dolist (elem map)
2173 (let ((from (car elem))
2174 (to (cadr elem)))
2175 (save-excursion
2176 (if (stringp from)
2177 (while (search-forward from nil t)
2178 (replace-match to))
2179 (while (not (eobp))
2180 (if (eq (following-char) from)
2181 (progn
2182 (delete-char 1)
2183 (insert to))
2184 (forward-char 1)))))))))))
2186 (defun article-treat-overstrike ()
2187 "Translate overstrikes into bold text."
2188 (interactive)
2189 (save-excursion
2190 (when (article-goto-body)
2191 (let ((inhibit-read-only t))
2192 (while (search-forward "\b" nil t)
2193 (let ((next (char-after))
2194 (previous (char-after (- (point) 2))))
2195 ;; We do the boldification/underlining by hiding the
2196 ;; overstrikes and putting the proper text property
2197 ;; on the letters.
2198 (cond
2199 ((eq next previous)
2200 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2201 (put-text-property (point) (1+ (point)) 'face 'bold))
2202 ((eq next ?_)
2203 (gnus-article-hide-text-type
2204 (1- (point)) (1+ (point)) 'overstrike)
2205 (put-text-property
2206 (- (point) 2) (1- (point)) 'face 'underline))
2207 ((eq previous ?_)
2208 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2209 (put-text-property
2210 (point) (1+ (point)) 'face 'underline)))))))))
2212 (defun article-treat-ansi-sequences ()
2213 "Translate ANSI SGR control sequences into overlays or extents."
2214 (interactive)
2215 (save-excursion
2216 (when (article-goto-body)
2217 (let ((inhibit-read-only t))
2218 (ansi-color-apply-on-region (point) (point-max))))))
2220 (defun gnus-article-treat-unfold-headers ()
2221 "Unfold folded message headers.
2222 Only the headers that fit into the current window width will be
2223 unfolded."
2224 (interactive)
2225 (gnus-with-article-headers
2226 (let (length)
2227 (while (not (eobp))
2228 (save-restriction
2229 (mail-header-narrow-to-field)
2230 (let* ((header (buffer-string))
2231 (unfoldable
2232 (or (equal gnus-article-unfold-long-headers t)
2233 (and (stringp gnus-article-unfold-long-headers)
2234 (string-match gnus-article-unfold-long-headers
2235 header)))))
2236 (with-temp-buffer
2237 (insert header)
2238 (goto-char (point-min))
2239 (while (re-search-forward "\n[\t ]" nil t)
2240 (replace-match " " t t)))
2241 (setq length (- (point-max) (point-min) 1))
2242 (when (or unfoldable
2243 (< length (window-width)))
2244 (while (re-search-forward "\n[\t ]" nil t)
2245 (replace-match " " t t))))
2246 (goto-char (point-max)))))))
2248 (defun gnus-article-treat-fold-headers ()
2249 "Fold message headers."
2250 (interactive)
2251 (gnus-with-article-headers
2252 (while (not (eobp))
2253 (save-restriction
2254 (mail-header-narrow-to-field)
2255 (mail-header-fold-field)
2256 (goto-char (point-max))))))
2258 (defun gnus-treat-smiley ()
2259 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2260 (interactive)
2261 (gnus-with-article-buffer
2262 (if (memq 'smiley gnus-article-wash-types)
2263 (gnus-delete-images 'smiley)
2264 (article-goto-body)
2265 (let ((images (smiley-region (point) (point-max))))
2266 (when images
2267 (gnus-add-wash-type 'smiley)
2268 (dolist (image images)
2269 (gnus-add-image 'smiley image)))))))
2271 (defun gnus-article-remove-images ()
2272 "Remove all images from the article buffer."
2273 (interactive)
2274 (gnus-with-article-buffer
2275 (save-restriction
2276 (widen)
2277 (dolist (elem gnus-article-image-alist)
2278 (gnus-delete-images (car elem))))))
2280 (autoload 'w3m-toggle-inline-images "w3m")
2282 (defun gnus-article-show-images ()
2283 "Show any images that are in the HTML-rendered article buffer.
2284 This only works if the article in question is HTML."
2285 (interactive)
2286 (gnus-with-article-buffer
2287 (save-restriction
2288 (widen)
2289 (if (eq mm-text-html-renderer 'w3m)
2290 (let ((mm-inline-text-html-with-images nil))
2291 (w3m-toggle-inline-images))
2292 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2293 'image-displayer))
2294 (destructuring-bind (start end function) region
2295 (funcall function (get-text-property start 'image-url)
2296 start end)))))))
2298 (defun gnus-article-treat-fold-newsgroups ()
2299 "Unfold folded message headers.
2300 Only the headers that fit into the current window width will be
2301 unfolded."
2302 (interactive)
2303 (gnus-with-article-headers
2304 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2305 (save-restriction
2306 (mail-header-narrow-to-field)
2307 (while (re-search-forward ", *" nil t)
2308 (replace-match ", " t t))
2309 (mail-header-fold-field)
2310 (goto-char (point-max))))))
2312 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2313 "Value of `truncate-lines' in Gnus Article buffer.
2314 Valid values are nil, t, `head', `first', `last', an integer or a
2315 predicate. See Info node `(gnus)Customizing Articles'."
2316 :version "23.1" ;; No Gnus
2317 :group 'gnus-article
2318 ;; :link '(custom-manual "(gnus)Customizing Articles")
2319 :type 'boolean)
2321 (defun gnus-article-toggle-truncate-lines (&optional arg)
2322 "Toggle whether to fold or truncate long lines in article the buffer.
2323 If ARG is non-nil and not a number, toggle
2324 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2325 long lines if and only if arg is positive."
2326 (interactive "P")
2327 (cond
2328 ((and (numberp arg) (> arg 0))
2329 (setq gnus-article-truncate-lines t))
2330 ((numberp arg)
2331 (setq gnus-article-truncate-lines nil))
2332 (arg
2333 (setq gnus-article-truncate-lines
2334 (not gnus-article-truncate-lines))))
2335 (gnus-with-article-buffer
2336 (cond
2337 ((and (numberp arg) (> arg 0))
2338 (setq truncate-lines nil))
2339 ((numberp arg)
2340 (setq truncate-lines t)))
2341 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2342 ;; `toggle-truncate-lines' needs an argument.
2343 (toggle-truncate-lines)))
2345 (defun gnus-article-treat-body-boundary ()
2346 "Place a boundary line at the end of the headers."
2347 (interactive)
2348 (when (and gnus-body-boundary-delimiter
2349 (> (length gnus-body-boundary-delimiter) 0))
2350 (gnus-with-article-headers
2351 (goto-char (point-max))
2352 (let ((start (point)))
2353 (insert "X-Boundary: ")
2354 (gnus-add-text-properties start (point) '(invisible t intangible t))
2355 (insert (let (str (max (window-width)))
2356 (if (featurep 'xemacs)
2357 (setq max (1- max)))
2358 (while (>= max (length str))
2359 (setq str (concat str gnus-body-boundary-delimiter)))
2360 (substring str 0 max))
2361 "\n")
2362 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2364 (defun article-fill-long-lines ()
2365 "Fill lines that are wider than the window width."
2366 (interactive)
2367 (save-excursion
2368 (let ((inhibit-read-only t)
2369 (width (window-width (get-buffer-window (current-buffer)))))
2370 (save-restriction
2371 (article-goto-body)
2372 (let ((adaptive-fill-mode nil)) ;Why? -sm
2373 (while (not (eobp))
2374 (end-of-line)
2375 (when (>= (current-column) (min fill-column width))
2376 (narrow-to-region (min (1+ (point)) (point-max))
2377 (point-at-bol))
2378 (let ((goback (point-marker)))
2379 (fill-paragraph nil)
2380 (goto-char (marker-position goback)))
2381 (widen))
2382 (forward-line 1)))))))
2384 (defun article-capitalize-sentences ()
2385 "Capitalize the first word in each sentence."
2386 (interactive)
2387 (save-excursion
2388 (let ((inhibit-read-only t)
2389 (paragraph-start "^[\n\^L]"))
2390 (article-goto-body)
2391 (while (not (eobp))
2392 (capitalize-word 1)
2393 (forward-sentence)))))
2395 (defun article-remove-cr ()
2396 "Remove trailing CRs and then translate remaining CRs into LFs."
2397 (interactive)
2398 (save-excursion
2399 (let ((inhibit-read-only t))
2400 (goto-char (point-min))
2401 (while (re-search-forward "\r+$" nil t)
2402 (replace-match "" t t))
2403 (goto-char (point-min))
2404 (while (search-forward "\r" nil t)
2405 (replace-match "\n" t t)))))
2407 (defun article-remove-trailing-blank-lines ()
2408 "Remove all trailing blank lines from the article."
2409 (interactive)
2410 (save-excursion
2411 (let ((inhibit-read-only t))
2412 (goto-char (point-max))
2413 (delete-region
2414 (point)
2415 (progn
2416 (while (and (not (bobp))
2417 (looking-at "^[ \t]*$")
2418 (not (gnus-annotation-in-region-p
2419 (point) (point-at-eol))))
2420 (forward-line -1))
2421 (forward-line 1)
2422 (point))))))
2424 (defvar gnus-face-properties-alist)
2426 (defun article-display-face (&optional force)
2427 "Display any Face headers in the header."
2428 (interactive (list 'force))
2429 (let ((wash-face-p buffer-read-only))
2430 (gnus-with-article-headers
2431 ;; When displaying parts, this function can be called several times on
2432 ;; the same article, without any intended toggle semantic (as typing `W
2433 ;; D d' would have). So face deletion must occur only when we come from
2434 ;; an interactive command, that is when the *Article* buffer is
2435 ;; read-only.
2436 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2437 (gnus-delete-images 'face)
2438 (let ((from (message-fetch-field "from"))
2439 face faces)
2440 (save-current-buffer
2441 (when (and wash-face-p
2442 (gnus-buffer-live-p gnus-original-article-buffer)
2443 (not (re-search-forward "^Face:[\t ]*" nil t)))
2444 (set-buffer gnus-original-article-buffer))
2445 (save-restriction
2446 (mail-narrow-to-head)
2447 (when (or force
2448 ;; Check whether this face is censored.
2449 (not (and gnus-article-x-face-too-ugly
2450 (or from
2451 (setq from (message-fetch-field "from")))
2452 (string-match gnus-article-x-face-too-ugly
2453 from))))
2454 (while (gnus-article-goto-header "Face")
2455 (push (mail-header-field-value) faces)))))
2456 (when faces
2457 (goto-char (point-min))
2458 (let (png image)
2459 (unless (setq from (gnus-article-goto-header "from"))
2460 (insert "From:")
2461 (setq from (point))
2462 (insert " [no `from' set]\n"))
2463 (while faces
2464 (when (setq png (gnus-convert-face-to-png (pop faces)))
2465 (setq image
2466 (apply 'gnus-create-image png 'png t
2467 (cdr (assq 'png gnus-face-properties-alist))))
2468 (goto-char from)
2469 (gnus-add-wash-type 'face)
2470 (gnus-add-image 'face image)
2471 (gnus-put-image image nil 'face))))))))))
2473 (defun article-display-x-face (&optional force)
2474 "Look for an X-Face header and display it if present."
2475 (interactive (list 'force))
2476 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2477 (gnus-with-article-headers
2478 ;; Delete the old process, if any.
2479 (when (process-status "article-x-face")
2480 (delete-process "article-x-face"))
2481 ;; See the comment in `article-display-face'.
2482 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2483 ;; We have already displayed X-Faces, so we remove them
2484 ;; instead.
2485 (gnus-delete-images 'xface)
2486 ;; Display X-Faces.
2487 (let ((from (message-fetch-field "from"))
2488 x-faces face)
2489 (save-current-buffer
2490 (when (and wash-face-p
2491 (gnus-buffer-live-p gnus-original-article-buffer)
2492 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2493 ;; If type `W f', use gnus-original-article-buffer,
2494 ;; otherwise use the current buffer because displaying
2495 ;; RFC822 parts calls this function too.
2496 (set-buffer gnus-original-article-buffer))
2497 (save-restriction
2498 (mail-narrow-to-head)
2499 (and gnus-article-x-face-command
2500 (or force
2501 ;; Check whether this face is censored.
2502 (not (and gnus-article-x-face-too-ugly
2503 (or from
2504 (setq from (message-fetch-field "from")))
2505 (string-match gnus-article-x-face-too-ugly
2506 from))))
2507 (while (gnus-article-goto-header "X-Face")
2508 (push (mail-header-field-value) x-faces)))))
2509 (when x-faces
2510 ;; We display the face.
2511 (cond ((functionp gnus-article-x-face-command)
2512 ;; The command is a lisp function, so we call it.
2513 (mapc gnus-article-x-face-command x-faces))
2514 ((stringp gnus-article-x-face-command)
2515 ;; The command is a string, so we interpret the command
2516 ;; as a, well, command, and fork it off.
2517 (let ((process-connection-type nil))
2518 (gnus-set-process-query-on-exit-flag
2519 (start-process
2520 "article-x-face" nil shell-file-name
2521 shell-command-switch gnus-article-x-face-command)
2522 nil)
2523 ;; Sending multiple EOFs to xv doesn't work,
2524 ;; so we only do a single external face.
2525 (with-temp-buffer
2526 (insert (car x-faces))
2527 (process-send-region "article-x-face"
2528 (point-min) (point-max)))
2529 (process-send-eof "article-x-face")))
2531 (error "`%s' set to `%s' is not a function"
2532 gnus-article-x-face-command
2533 'gnus-article-x-face-command)))))))))
2535 (defun article-decode-mime-words ()
2536 "Decode all MIME-encoded words in the article."
2537 (interactive)
2538 (gnus-with-article-buffer
2539 (let ((inhibit-point-motion-hooks t)
2540 (mail-parse-charset gnus-newsgroup-charset)
2541 (mail-parse-ignored-charsets
2542 (with-current-buffer gnus-summary-buffer
2543 gnus-newsgroup-ignored-charsets)))
2544 (mail-decode-encoded-word-region (point-min) (point-max)))))
2546 (defun article-decode-charset (&optional prompt)
2547 "Decode charset-encoded text in the article.
2548 If PROMPT (the prefix), prompt for a coding system to use."
2549 (interactive "P")
2550 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2551 (inhibit-read-only t)
2552 (mail-parse-charset gnus-newsgroup-charset)
2553 (mail-parse-ignored-charsets
2554 (save-excursion (condition-case nil
2555 (set-buffer gnus-summary-buffer)
2556 (error))
2557 gnus-newsgroup-ignored-charsets))
2558 ct cte ctl charset format)
2559 (save-excursion
2560 (save-restriction
2561 (article-narrow-to-head)
2562 (setq ct (message-fetch-field "Content-Type" t)
2563 cte (message-fetch-field "Content-Transfer-Encoding" t)
2564 ctl (and ct (mail-header-parse-content-type ct))
2565 charset (cond
2566 (prompt
2567 (mm-read-coding-system "Charset to decode: "))
2568 (ctl
2569 (mail-content-type-get ctl 'charset)))
2570 format (and ctl (mail-content-type-get ctl 'format)))
2571 (when cte
2572 (setq cte (mail-header-strip cte)))
2573 (if (and ctl (not (string-match "/" (car ctl))))
2574 (setq ctl nil))
2575 (goto-char (point-max)))
2576 (forward-line 1)
2577 (save-restriction
2578 (narrow-to-region (point) (point-max))
2579 (when (and (eq mail-parse-charset 'gnus-decoded)
2580 (eq (mm-body-7-or-8) '8bit))
2581 ;; The text code could have been decoded.
2582 (setq charset mail-parse-charset))
2583 (when (and (or (not ctl)
2584 (equal (car ctl) "text/plain"))
2585 (not format)) ;; article with format will decode later.
2586 (mm-decode-body
2587 charset (and cte (intern (downcase
2588 (gnus-strip-whitespace cte))))
2589 (car ctl)))))))
2591 (defun article-decode-encoded-words ()
2592 "Remove encoded-word encoding from headers."
2593 (let ((inhibit-point-motion-hooks t)
2594 (mail-parse-charset gnus-newsgroup-charset)
2595 (mail-parse-ignored-charsets
2596 (save-excursion (condition-case nil
2597 (set-buffer gnus-summary-buffer)
2598 (error))
2599 gnus-newsgroup-ignored-charsets))
2600 (inhibit-read-only t)
2601 end start)
2602 (goto-char (point-min))
2603 (when (search-forward "\n\n" nil 'move)
2604 (forward-line -1))
2605 (setq end (point))
2606 (while (not (bobp))
2607 (while (progn
2608 (forward-line -1)
2609 (and (not (bobp))
2610 (memq (char-after) '(?\t ? )))))
2611 (setq start (point))
2612 (if (looking-at "\
2613 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2614 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2615 (funcall gnus-decode-address-function start end)
2616 (funcall gnus-decode-header-function start end))
2617 (goto-char (setq end start)))))
2619 (defun article-decode-group-name ()
2620 "Decode group names in Newsgroups, Followup-To and Xref headers."
2621 (let ((inhibit-point-motion-hooks t)
2622 (inhibit-read-only t)
2623 (method (gnus-find-method-for-group gnus-newsgroup-name))
2624 regexp)
2625 (when (and (or gnus-group-name-charset-method-alist
2626 gnus-group-name-charset-group-alist)
2627 (gnus-buffer-live-p gnus-original-article-buffer))
2628 (save-restriction
2629 (article-narrow-to-head)
2630 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2631 (with-current-buffer gnus-original-article-buffer
2632 (goto-char (point-min)))
2633 (setq regexp (concat "^" header
2634 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2635 (while (re-search-forward regexp nil t)
2636 (replace-match (save-match-data
2637 (gnus-decode-newsgroups
2638 ;; XXX how to use data in article buffer?
2639 (with-current-buffer gnus-original-article-buffer
2640 (re-search-forward regexp nil t)
2641 (match-string 1))
2642 gnus-newsgroup-name method))
2643 t t nil 1))
2644 (goto-char (point-min)))))))
2646 (autoload 'idna-to-unicode "idna")
2648 (defun article-decode-idna-rhs ()
2649 "Decode IDNA strings in RHS in various headers in current buffer.
2650 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2651 Mail-Reply-To: and Mail-Followup-To:."
2652 (when gnus-use-idna
2653 (save-restriction
2654 (let ((inhibit-point-motion-hooks t)
2655 (inhibit-read-only t))
2656 (article-narrow-to-head)
2657 (goto-char (point-min))
2658 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2659 (let (ace unicode)
2660 (when (save-match-data
2661 (and (setq ace (match-string 1))
2662 (save-excursion
2663 (and (re-search-backward "^[^ \t]" nil t)
2664 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2665 (setq unicode (idna-to-unicode ace))))
2666 (unless (string= ace unicode)
2667 (replace-match unicode nil nil nil 1)))))))))
2669 (defun article-de-quoted-unreadable (&optional force read-charset)
2670 "Translate a quoted-printable-encoded article.
2671 If FORCE, decode the article whether it is marked as quoted-printable
2672 or not.
2673 If READ-CHARSET, ask for a coding system."
2674 (interactive (list 'force current-prefix-arg))
2675 (save-excursion
2676 (let ((inhibit-read-only t) type charset)
2677 (if (gnus-buffer-live-p gnus-original-article-buffer)
2678 (with-current-buffer gnus-original-article-buffer
2679 (setq type
2680 (gnus-fetch-field "content-transfer-encoding"))
2681 (let* ((ct (gnus-fetch-field "content-type"))
2682 (ctl (and ct (mail-header-parse-content-type ct))))
2683 (setq charset (and ctl
2684 (mail-content-type-get ctl 'charset)))
2685 (if (stringp charset)
2686 (setq charset (intern (downcase charset)))))))
2687 (if read-charset
2688 (setq charset (mm-read-coding-system "Charset: " charset)))
2689 (unless charset
2690 (setq charset gnus-newsgroup-charset))
2691 (when (or force
2692 (and type (let ((case-fold-search t))
2693 (string-match "quoted-printable" type))))
2694 (article-goto-body)
2695 (quoted-printable-decode-region
2696 (point) (point-max) (mm-charset-to-coding-system charset))))))
2698 (defun article-de-base64-unreadable (&optional force read-charset)
2699 "Translate a base64 article.
2700 If FORCE, decode the article whether it is marked as base64 not.
2701 If READ-CHARSET, ask for a coding system."
2702 (interactive (list 'force current-prefix-arg))
2703 (save-excursion
2704 (let ((inhibit-read-only t) type charset)
2705 (if (gnus-buffer-live-p gnus-original-article-buffer)
2706 (with-current-buffer gnus-original-article-buffer
2707 (setq type
2708 (gnus-fetch-field "content-transfer-encoding"))
2709 (let* ((ct (gnus-fetch-field "content-type"))
2710 (ctl (and ct (mail-header-parse-content-type ct))))
2711 (setq charset (and ctl
2712 (mail-content-type-get ctl 'charset)))
2713 (if (stringp charset)
2714 (setq charset (intern (downcase charset)))))))
2715 (if read-charset
2716 (setq charset (mm-read-coding-system "Charset: " charset)))
2717 (unless charset
2718 (setq charset gnus-newsgroup-charset))
2719 (when (or force
2720 (and type (let ((case-fold-search t))
2721 (string-match "base64" type))))
2722 (article-goto-body)
2723 (save-restriction
2724 (narrow-to-region (point) (point-max))
2725 (base64-decode-region (point-min) (point-max))
2726 (mm-decode-coding-region
2727 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2729 (eval-when-compile
2730 (require 'rfc1843))
2732 (defun article-decode-HZ ()
2733 "Translate a HZ-encoded article."
2734 (interactive)
2735 (require 'rfc1843)
2736 (save-excursion
2737 (let ((inhibit-read-only t))
2738 (rfc1843-decode-region (point-min) (point-max)))))
2740 (defun article-unsplit-urls ()
2741 "Remove the newlines that some other mailers insert into URLs."
2742 (interactive)
2743 (save-excursion
2744 (let ((inhibit-read-only t))
2745 (goto-char (point-min))
2746 (while (re-search-forward
2747 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2748 (replace-match "\\1\\3" t)))
2749 (when (interactive-p)
2750 (gnus-treat-article nil))))
2752 (defun article-wash-html ()
2753 "Format an HTML article."
2754 (interactive)
2755 (let ((handles nil)
2756 (buffer-read-only nil))
2757 (when (gnus-buffer-live-p gnus-original-article-buffer)
2758 (with-current-buffer gnus-original-article-buffer
2759 (setq handles (mm-dissect-buffer t t))))
2760 (article-goto-body)
2761 (delete-region (point) (point-max))
2762 (mm-enable-multibyte)
2763 (mm-inline-text-html handles)))
2765 (defvar gnus-article-browse-html-temp-list nil
2766 "List of temporary files created by `gnus-article-browse-html-parts'.
2767 Internal variable.")
2769 (defcustom gnus-article-browse-delete-temp 'ask
2770 "What to do with temporary files from `gnus-article-browse-html-parts'.
2771 If nil, don't delete temporary files. If it is t, delete them on
2772 exit from the summary buffer. If it is the symbol `file', query
2773 on each file, if it is `ask' ask once when exiting from the
2774 summary buffer."
2775 :group 'gnus-article
2776 :version "23.1" ;; No Gnus
2777 :type '(choice (const :tag "Don't delete" nil)
2778 (const :tag "Don't ask" t)
2779 (const :tag "Ask" ask)
2780 (const :tag "Ask for each file" file)))
2782 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2784 (defun gnus-article-browse-delete-temp-files (&optional how)
2785 "Delete temp-files created by `gnus-article-browse-html-parts'."
2786 (when (and gnus-article-browse-html-temp-list
2787 (progn
2788 (or how (setq how gnus-article-browse-delete-temp))
2789 (if (eq how 'ask)
2790 (let ((files (length gnus-article-browse-html-temp-list)))
2791 (gnus-y-or-n-p
2792 (if (= files 1)
2793 "Delete the temporary HTML file? "
2794 (format "Delete all %s temporary HTML files? "
2795 files))))
2796 how)))
2797 (dolist (file gnus-article-browse-html-temp-list)
2798 (cond ((file-directory-p file)
2799 (when (or (not (eq how 'file))
2800 (gnus-y-or-n-p
2801 (format
2802 "Delete temporary HTML file(s) in directory `%s'? "
2803 (file-name-as-directory file))))
2804 (gnus-delete-directory file)))
2805 ((file-exists-p file)
2806 (when (or (not (eq how 'file))
2807 (gnus-y-or-n-p
2808 (format "Delete temporary HTML file `%s'? " file)))
2809 (delete-file file)))))
2810 ;; Also remove file from the list when not deleted or if file doesn't
2811 ;; exist anymore.
2812 (setq gnus-article-browse-html-temp-list nil))
2813 gnus-article-browse-html-temp-list)
2815 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2816 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2817 Return file name."
2818 (save-match-data
2819 (let (file type)
2820 (catch 'found
2821 (dolist (handle handles)
2822 (cond
2823 ((not (listp handle)))
2824 ((equal (mm-handle-media-supertype handle) "multipart")
2825 (when (setq file (gnus-article-browse-html-save-cid-content
2826 cid handle directory))
2827 (throw 'found file)))
2828 ((equal (concat "<" cid ">") (mm-handle-id handle))
2829 (setq file
2830 (expand-file-name
2831 (or (mm-handle-filename handle)
2832 (concat
2833 (make-temp-name "cid")
2834 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2835 directory))
2836 (mm-save-part-to-file handle file)
2837 (throw 'found file))))))))
2839 (defun gnus-article-browse-html-parts (list &optional header)
2840 "View all \"text/html\" parts from LIST.
2841 Recurse into multiparts. The optional HEADER that should be a decoded
2842 message header will be added to the bodies of the \"text/html\" parts."
2843 ;; Internal function used by `gnus-article-browse-html-article'.
2844 (let (type file charset content cid-dir tmp-file showed)
2845 ;; Find and show the html-parts.
2846 (dolist (handle list)
2847 ;; If HTML, show it:
2848 (cond ((not (listp handle)))
2849 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2850 (and (equal (car type) "message/external-body")
2851 (or header
2852 (setq file (mm-handle-filename handle)))
2853 (or (mm-handle-cache handle)
2854 (condition-case code
2855 (progn (mm-extern-cache-contents handle) t)
2856 (error
2857 (gnus-message 3 "%s" (error-message-string code))
2858 (when (>= gnus-verbose 3) (sit-for 2))
2859 nil)))
2860 (progn
2861 (setq handle (mm-handle-cache handle)
2862 type (mm-handle-type handle))
2863 (equal (car type) "text/html"))))
2864 (setq charset (mail-content-type-get type 'charset)
2865 content (mm-get-part handle))
2866 (with-temp-buffer
2867 (if (eq charset 'gnus-decoded)
2868 (mm-enable-multibyte)
2869 (mm-disable-multibyte))
2870 (insert content)
2871 ;; resolve cid contents
2872 (let ((case-fold-search t)
2873 cid-file)
2874 (goto-char (point-min))
2875 (while (re-search-forward "\
2876 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2877 nil t)
2878 (unless cid-dir
2879 (setq cid-dir (mm-make-temp-file "cid" t))
2880 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2881 (setq file nil
2882 content nil)
2883 (when (setq cid-file
2884 (gnus-article-browse-html-save-cid-content
2885 (match-string 2)
2886 (with-current-buffer gnus-article-buffer
2887 gnus-article-mime-handles)
2888 cid-dir))
2889 (when (eq system-type 'cygwin)
2890 (setq cid-file
2891 (concat "/" (substring
2892 (with-output-to-string
2893 (call-process "cygpath" nil
2894 standard-output
2895 nil "-m" cid-file))
2896 0 -1))))
2897 (replace-match (concat "file://" cid-file)
2898 nil nil nil 1))))
2899 (unless content (setq content (buffer-string))))
2900 (when (or charset header (not file))
2901 (setq tmp-file (mm-make-temp-file
2902 ;; Do we need to care for 8.3 filenames?
2903 "mm-" nil ".html")))
2904 ;; Add a meta html tag to specify charset and a header.
2905 (cond
2906 (header
2907 (let (title eheader body hcharset coding force-charset)
2908 (with-temp-buffer
2909 (mm-enable-multibyte)
2910 (setq case-fold-search t)
2911 (insert header "\n")
2912 (setq title (message-fetch-field "subject"))
2913 (goto-char (point-min))
2914 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2915 (replace-match (cond ((match-beginning 1) "&lt;")
2916 ((match-beginning 2) "&gt;")
2917 (t "&amp;"))))
2918 (goto-char (point-min))
2919 (insert "<pre>\n")
2920 (goto-char (point-max))
2921 (insert "</pre>\n<hr>\n")
2922 ;; We have to examine charset one by one since
2923 ;; charset specified in parts might be different.
2924 (if (eq charset 'gnus-decoded)
2925 (setq charset 'utf-8
2926 eheader (mm-encode-coding-string (buffer-string)
2927 charset)
2928 title (when title
2929 (mm-encode-coding-string title charset))
2930 body (mm-encode-coding-string content charset)
2931 force-charset t)
2932 (setq hcharset (mm-find-mime-charset-region (point-min)
2933 (point-max)))
2934 (cond ((= (length hcharset) 1)
2935 (setq hcharset (car hcharset)
2936 coding (mm-charset-to-coding-system
2937 hcharset)))
2938 ((> (length hcharset) 1)
2939 (setq hcharset 'utf-8
2940 coding hcharset)))
2941 (if coding
2942 (if charset
2943 (progn
2944 (setq body
2945 (mm-charset-to-coding-system charset))
2946 (if (eq coding body)
2947 (setq eheader (mm-encode-coding-string
2948 (buffer-string) coding)
2949 title (when title
2950 (mm-encode-coding-string
2951 title coding))
2952 body content)
2953 (setq charset 'utf-8
2954 eheader (mm-encode-coding-string
2955 (buffer-string) charset)
2956 title (when title
2957 (mm-encode-coding-string
2958 title charset))
2959 body (mm-encode-coding-string
2960 (mm-decode-coding-string
2961 content body)
2962 charset)
2963 force-charset t)))
2964 (setq charset hcharset
2965 eheader (mm-encode-coding-string
2966 (buffer-string) coding)
2967 title (when title
2968 (mm-encode-coding-string
2969 title coding))
2970 body content))
2971 (setq eheader (mm-string-as-unibyte (buffer-string))
2972 body content)))
2973 (erase-buffer)
2974 (mm-disable-multibyte)
2975 (insert body)
2976 (when charset
2977 (mm-add-meta-html-tag handle charset force-charset))
2978 (when title
2979 (goto-char (point-min))
2980 (unless (search-forward "<title>" nil t)
2981 (re-search-forward "<head>\\s-*" nil t)
2982 (insert "<title>" title "</title>\n")))
2983 (goto-char (point-min))
2984 (or (re-search-forward
2985 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2986 (re-search-forward
2987 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2988 (insert eheader)
2989 (mm-write-region (point-min) (point-max)
2990 tmp-file nil nil nil 'binary t))))
2991 (charset
2992 (mm-with-unibyte-buffer
2993 (insert (if (eq charset 'gnus-decoded)
2994 (mm-encode-coding-string content
2995 (setq charset 'utf-8))
2996 content))
2997 (if (or (mm-add-meta-html-tag handle charset)
2998 (not file))
2999 (mm-write-region (point-min) (point-max)
3000 tmp-file nil nil nil 'binary t)
3001 (setq tmp-file nil))))
3002 (tmp-file
3003 (mm-save-part-to-file handle tmp-file)))
3004 (when tmp-file
3005 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3006 (add-hook 'gnus-summary-prepare-exit-hook
3007 'gnus-article-browse-delete-temp-files)
3008 (add-hook 'gnus-exit-gnus-hook
3009 (lambda ()
3010 (gnus-article-browse-delete-temp-files t)))
3011 ;; FIXME: Warn if there's an <img> tag?
3012 (browse-url-of-file (or tmp-file (expand-file-name file)))
3013 (setq showed t))
3014 ;; If multipart, recurse
3015 ((equal (mm-handle-media-supertype handle) "multipart")
3016 (when (gnus-article-browse-html-parts handle header)
3017 (setq showed t)))
3018 ((equal (mm-handle-media-type handle) "message/rfc822")
3019 (mm-with-multibyte-buffer
3020 (mm-insert-part handle)
3021 (setq handle (mm-dissect-buffer t t))
3022 (when (and (bufferp (car handle))
3023 (stringp (car (mm-handle-type handle))))
3024 (setq handle (list handle)))
3025 (when header
3026 (article-decode-encoded-words)
3027 (let ((gnus-visible-headers
3028 (or (get 'gnus-visible-headers 'standard-value)
3029 gnus-visible-headers)))
3030 (article-hide-headers))
3031 (goto-char (point-min))
3032 (search-forward "\n\n" nil 'move)
3033 (skip-chars-backward "\t\n ")
3034 (setq header (buffer-substring (point-min) (point)))))
3035 (when (prog1
3036 (gnus-article-browse-html-parts handle header)
3037 (mm-destroy-parts handle))
3038 (setq showed t)))))
3039 showed))
3041 (defun gnus-article-browse-html-article (&optional arg)
3042 "View \"text/html\" parts of the current article with a WWW browser.
3043 Inline images embedded in a message using the cid scheme, as they are
3044 generally considered to be safe, will be processed properly.
3045 The message header is added to the beginning of every html part unless
3046 the prefix argument ARG is given.
3048 Warning: Spammers use links to images (using the http scheme) in HTML
3049 articles to verify whether you have read the message. As
3050 `gnus-article-browse-html-article' passes the HTML content to the
3051 browser without eliminating these \"web bugs\" you should only
3052 use it for mails from trusted senders.
3054 If you always want to display HTML parts in the browser, set
3055 `mm-text-html-renderer' to nil.
3057 This command creates temporary files to pass HTML contents including
3058 images if any to the browser, and deletes them when exiting the group
3059 \(if you want)."
3060 ;; Cf. `mm-w3m-safe-url-regexp'
3061 (interactive "P")
3062 (if arg
3063 (gnus-summary-show-article)
3064 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3065 gnus-visible-headers))
3066 ;; As we insert a <hr>, there's no need for the body boundary.
3067 (gnus-treat-body-boundary nil))
3068 (gnus-summary-show-article)))
3069 (with-current-buffer gnus-article-buffer
3070 (let ((header (unless arg
3071 (save-restriction
3072 (widen)
3073 (buffer-substring-no-properties
3074 (goto-char (point-min))
3075 (if (search-forward "\n\n" nil t)
3076 (match-beginning 0)
3077 (goto-char (point-max))
3078 (skip-chars-backward "\t\n ")
3079 (point))))))
3080 parts)
3081 (set-buffer gnus-original-article-buffer)
3082 (setq parts (mm-dissect-buffer t t))
3083 ;; If singlepart, enforce a list.
3084 (when (and (bufferp (car parts))
3085 (stringp (car (mm-handle-type parts))))
3086 (setq parts (list parts)))
3087 ;; Process the list
3088 (unless (gnus-article-browse-html-parts parts header)
3089 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3090 (mm-destroy-parts parts)
3091 (unless arg
3092 (gnus-summary-show-article)))))
3094 (defun article-hide-list-identifiers ()
3095 "Remove list identifies from the Subject header.
3096 The `gnus-list-identifiers' variable specifies what to do."
3097 (interactive)
3098 (let ((inhibit-point-motion-hooks t)
3099 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3100 (inhibit-read-only t))
3101 (when regexp
3102 (save-excursion
3103 (save-restriction
3104 (article-narrow-to-head)
3105 (goto-char (point-min))
3106 (while (re-search-forward
3107 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3108 nil t)
3109 (delete-region (match-beginning 2) (match-end 0))
3110 (beginning-of-line))
3111 (when (re-search-forward
3112 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3113 (delete-region (match-beginning 1) (match-end 1))))))))
3115 (defun article-hide-pem (&optional arg)
3116 "Toggle hiding of any PEM headers and signatures in the current article.
3117 If given a negative prefix, always show; if given a positive prefix,
3118 always hide."
3119 (interactive (gnus-article-hidden-arg))
3120 (unless (gnus-article-check-hidden-text 'pem arg)
3121 (save-excursion
3122 (let ((inhibit-read-only t) end)
3123 (goto-char (point-min))
3124 ;; Hide the horrendously ugly "header".
3125 (when (and (search-forward
3126 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3127 nil t)
3128 (setq end (1+ (match-beginning 0))))
3129 (gnus-add-wash-type 'pem)
3130 (gnus-article-hide-text-type
3132 (if (search-forward "\n\n" nil t)
3133 (match-end 0)
3134 (point-max))
3135 'pem)
3136 ;; Hide the trailer as well
3137 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3138 nil t)
3139 (gnus-article-hide-text-type
3140 (match-beginning 0) (match-end 0) 'pem)))))))
3142 (defun article-strip-banner ()
3143 "Strip the banners specified by the `banner' group parameter and by
3144 `gnus-article-address-banner-alist'."
3145 (interactive)
3146 (save-excursion
3147 (save-restriction
3148 (let ((inhibit-point-motion-hooks t))
3149 (when (gnus-parameter-banner gnus-newsgroup-name)
3150 (article-really-strip-banner
3151 (gnus-parameter-banner gnus-newsgroup-name)))
3152 (when gnus-article-address-banner-alist
3153 ;; Note that the From header is decoded here, so it is
3154 ;; required that the *-extract-address-components function
3155 ;; supports non-ASCII text.
3156 (let ((from (save-restriction
3157 (widen)
3158 (article-narrow-to-head)
3159 (mail-fetch-field "from"))))
3160 (when (and from
3161 (setq from
3162 (cadr (funcall gnus-extract-address-components
3163 from))))
3164 (catch 'found
3165 (dolist (pair gnus-article-address-banner-alist)
3166 (when (string-match (car pair) from)
3167 (throw 'found
3168 (article-really-strip-banner (cdr pair)))))))))))))
3170 (defun article-really-strip-banner (banner)
3171 "Strip the banner specified by the argument."
3172 (save-excursion
3173 (save-restriction
3174 (let ((inhibit-point-motion-hooks t)
3175 (gnus-signature-limit nil)
3176 (inhibit-read-only t))
3177 (article-goto-body)
3178 (cond
3179 ((eq banner 'signature)
3180 (when (gnus-article-narrow-to-signature)
3181 (widen)
3182 (forward-line -1)
3183 (delete-region (point) (point-max))))
3184 ((symbolp banner)
3185 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3186 (while (re-search-forward banner nil t)
3187 (delete-region (match-beginning 0) (match-end 0)))))
3188 ((stringp banner)
3189 (while (re-search-forward banner nil t)
3190 (delete-region (match-beginning 0) (match-end 0)))))))))
3192 (defun article-babel ()
3193 "Translate article using an online translation service."
3194 (interactive)
3195 (require 'babel)
3196 (gnus-with-article-buffer
3197 (when (article-goto-body)
3198 (let* ((start (point))
3199 (end (point-max))
3200 (orig (buffer-substring start end))
3201 (trans (babel-as-string orig)))
3202 (save-restriction
3203 (narrow-to-region start end)
3204 (delete-region start end)
3205 (insert trans))))))
3207 (defun article-hide-signature (&optional arg)
3208 "Hide the signature in the current article.
3209 If given a negative prefix, always show; if given a positive prefix,
3210 always hide."
3211 (interactive (gnus-article-hidden-arg))
3212 (unless (gnus-article-check-hidden-text 'signature arg)
3213 (save-excursion
3214 (save-restriction
3215 (let ((inhibit-read-only t))
3216 (when (gnus-article-narrow-to-signature)
3217 (gnus-article-hide-text-type
3218 (point-min) (point-max) 'signature))))))
3219 (gnus-set-mode-line 'article))
3221 (defun article-strip-headers-in-body ()
3222 "Strip offensive headers from bodies."
3223 (interactive)
3224 (save-excursion
3225 (article-goto-body)
3226 (let ((case-fold-search t))
3227 (when (looking-at "x-no-archive:")
3228 (gnus-delete-line)))))
3230 (defun article-strip-leading-blank-lines ()
3231 "Remove all blank lines from the beginning of the article."
3232 (interactive)
3233 (save-excursion
3234 (let ((inhibit-point-motion-hooks t)
3235 (inhibit-read-only t))
3236 (when (article-goto-body)
3237 (while (and (not (eobp))
3238 (looking-at "[ \t]*$"))
3239 (gnus-delete-line))))))
3241 (defun article-narrow-to-head ()
3242 "Narrow the buffer to the head of the message.
3243 Point is left at the beginning of the narrowed-to region."
3244 (narrow-to-region
3245 (goto-char (point-min))
3246 (cond
3247 ;; Absolutely no headers displayed.
3248 ((looking-at "\n")
3249 (point))
3250 ;; Normal headers.
3251 ((search-forward "\n\n" nil 1)
3252 (1- (point)))
3253 ;; Nothing but headers.
3255 (point-max))))
3256 (goto-char (point-min)))
3258 (defun article-goto-body ()
3259 "Place point at the start of the body."
3260 (goto-char (point-min))
3261 (cond
3262 ;; This variable is only bound when dealing with separate
3263 ;; MIME body parts.
3264 (article-goto-body-goes-to-point-min-p
3266 ((search-forward "\n\n" nil t)
3269 (goto-char (point-max))
3270 nil)))
3272 (defun article-strip-multiple-blank-lines ()
3273 "Replace consecutive blank lines with one empty line."
3274 (interactive)
3275 (save-excursion
3276 (let ((inhibit-point-motion-hooks t)
3277 (inhibit-read-only t))
3278 ;; First make all blank lines empty.
3279 (article-goto-body)
3280 (while (re-search-forward "^[ \t]+$" nil t)
3281 (unless (gnus-annotation-in-region-p
3282 (match-beginning 0) (match-end 0))
3283 (replace-match "" nil t)))
3284 ;; Then replace multiple empty lines with a single empty line.
3285 (article-goto-body)
3286 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3287 (unless (gnus-annotation-in-region-p
3288 (match-beginning 0) (match-end 0))
3289 (delete-region (match-beginning 1) (match-end 1)))))))
3291 (defun article-strip-leading-space ()
3292 "Remove all white space from the beginning of the lines in the article."
3293 (interactive)
3294 (save-excursion
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3297 (article-goto-body)
3298 (while (re-search-forward "^[ \t]+" nil t)
3299 (replace-match "" t t)))))
3301 (defun article-strip-trailing-space ()
3302 "Remove all white space from the end of the lines in the article."
3303 (interactive)
3304 (save-excursion
3305 (let ((inhibit-point-motion-hooks t)
3306 (inhibit-read-only t))
3307 (article-goto-body)
3308 (while (re-search-forward "[ \t]+$" nil t)
3309 (replace-match "" t t)))))
3311 (defun article-strip-blank-lines ()
3312 "Strip leading, trailing and multiple blank lines."
3313 (interactive)
3314 (article-strip-leading-blank-lines)
3315 (article-remove-trailing-blank-lines)
3316 (article-strip-multiple-blank-lines))
3318 (defun article-strip-all-blank-lines ()
3319 "Strip all blank lines."
3320 (interactive)
3321 (save-excursion
3322 (let ((inhibit-point-motion-hooks t)
3323 (inhibit-read-only t))
3324 (article-goto-body)
3325 (while (re-search-forward "^[ \t]*\n" nil t)
3326 (replace-match "" t t)))))
3328 (defun gnus-article-narrow-to-signature ()
3329 "Narrow to the signature; return t if a signature is found, else nil."
3330 (let ((inhibit-point-motion-hooks t))
3331 (when (gnus-article-search-signature)
3332 (forward-line 1)
3333 ;; Check whether we have some limits to what we consider
3334 ;; to be a signature.
3335 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3336 (list gnus-signature-limit)))
3337 limit limited)
3338 (while (setq limit (pop limits))
3339 (if (or (and (integerp limit)
3340 (< (- (point-max) (point)) limit))
3341 (and (floatp limit)
3342 (< (count-lines (point) (point-max)) limit))
3343 (and (functionp limit)
3344 (funcall limit))
3345 (and (stringp limit)
3346 (not (re-search-forward limit nil t))))
3347 () ; This limit did not succeed.
3348 (setq limited t
3349 limits nil)))
3350 (unless limited
3351 (narrow-to-region (point) (point-max))
3352 t)))))
3354 (defun gnus-article-search-signature ()
3355 "Search the current buffer for the signature separator.
3356 Put point at the beginning of the signature separator."
3357 (let ((cur (point)))
3358 (goto-char (point-max))
3359 (if (if (stringp gnus-signature-separator)
3360 (re-search-backward gnus-signature-separator nil t)
3361 (let ((seps gnus-signature-separator))
3362 (while (and seps
3363 (not (re-search-backward (car seps) nil t)))
3364 (pop seps))
3365 seps))
3367 (goto-char cur)
3368 nil)))
3370 (defun gnus-article-hidden-arg ()
3371 "Return the current prefix arg as a number, or 0 if no prefix."
3372 (list (if current-prefix-arg
3373 (prefix-numeric-value current-prefix-arg)
3374 0)))
3376 (defun gnus-article-check-hidden-text (type arg)
3377 "Return nil if hiding is necessary.
3378 Arg can be nil or a number. nil and positive means hide, negative
3379 means show, 0 means toggle."
3380 (save-excursion
3381 (save-restriction
3382 (let ((hide (gnus-article-hidden-text-p type)))
3383 (cond
3384 ((or (null arg)
3385 (> arg 0))
3386 nil)
3387 ((< arg 0)
3388 (gnus-article-show-hidden-text type)
3391 (if (eq hide 'hidden)
3392 (progn
3393 (gnus-article-show-hidden-text type)
3395 nil)))))))
3397 (defun gnus-article-hidden-text-p (type)
3398 "Say whether the current buffer contains hidden text of type TYPE."
3399 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3400 (while (and pos
3401 (not (get-text-property pos 'invisible))
3402 (not (get-text-property pos 'dummy-invisible)))
3403 (setq pos
3404 (text-property-any (1+ pos) (point-max) 'article-type type)))
3405 (if pos
3406 'hidden
3407 nil)))
3409 (defun gnus-article-show-hidden-text (type &optional dummy)
3410 "Show all hidden text of type TYPE.
3411 Originally it is hide instead of DUMMY."
3412 (let ((inhibit-read-only t)
3413 (inhibit-point-motion-hooks t))
3414 (gnus-remove-text-properties-when
3415 'article-type type
3416 (point-min) (point-max)
3417 (cons 'article-type (cons type
3418 gnus-hidden-properties)))
3419 (gnus-delete-wash-type type)))
3421 (defconst article-time-units
3422 `((year . ,(* 365.25 24 60 60))
3423 (week . ,(* 7 24 60 60))
3424 (day . ,(* 24 60 60))
3425 (hour . ,(* 60 60))
3426 (minute . 60)
3427 (second . 1))
3428 "Mapping from time units to seconds.")
3430 (defun gnus-article-forward-header ()
3431 "Move point to the start of the next header.
3432 If the current header is a continuation header, this can be several
3433 lines forward."
3434 (let ((ended nil))
3435 (while (not ended)
3436 (forward-line 1)
3437 (if (looking-at "[ \t]+[^ \t]")
3438 (forward-line 1)
3439 (setq ended t)))))
3441 (defun article-treat-date ()
3442 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3443 (with-current-buffer gnus-summary-buffer
3444 gnus-article-date-headers)
3445 gnus-article-date-headers)
3448 (defun article-date-ut (&optional type highlight date-position)
3449 "Convert DATE date to TYPE in the current article.
3450 The default type is `ut'. See `gnus-article-date-headers' for
3451 possible values."
3452 (interactive (list 'ut t))
3453 (let* ((case-fold-search t)
3454 (inhibit-read-only t)
3455 (inhibit-point-motion-hooks t)
3456 (first t)
3457 (visible-date (mail-fetch-field "Date"))
3458 pos date bface eface)
3459 (save-excursion
3460 (goto-char (point-min))
3461 (when (re-search-forward "^Date:" nil t)
3462 (setq bface (get-text-property (point-at-bol) 'face)
3463 eface (get-text-property (1- (point-at-eol)) 'face)))
3464 ;; Delete any old Date headers.
3465 (if date-position
3466 (progn
3467 (goto-char date-position)
3468 (setq date (get-text-property (point) 'original-date))
3469 (delete-region (point)
3470 (progn
3471 (gnus-article-forward-header)
3472 (point)))
3473 (article-transform-date date type bface eface))
3474 (save-restriction
3475 (widen)
3476 (goto-char (point-min))
3477 (while (or (get-text-property (setq pos (point)) 'original-date)
3478 (and (setq pos (next-single-property-change
3479 (point) 'original-date))
3480 (goto-char pos)))
3481 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3482 (1+ (match-beginning 0))
3483 (point-max)))
3484 (goto-char (point-min))
3485 (while (re-search-forward "^Date:" nil t)
3486 (setq date (get-text-property (match-beginning 0) 'original-date))
3487 (delete-region (point-at-bol) (progn
3488 (gnus-article-forward-header)
3489 (point))))
3490 (when (and (not date)
3491 visible-date)
3492 (setq date visible-date))
3493 (when date
3494 (article-transform-date date type bface eface))
3495 (goto-char (point-max))
3496 (widen)))))))
3498 (defun article-transform-date (date type bface eface)
3499 (dolist (this-type (cond
3500 ((null type)
3501 (list 'ut))
3502 ((atom type)
3503 (list type))
3505 type)))
3506 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3507 (forward-line -1)
3508 (beginning-of-line)
3509 (put-text-property (point) (1+ (point))
3510 'original-date date)
3511 (put-text-property (point) (1+ (point))
3512 'gnus-date-type this-type)
3513 ;; Do highlighting.
3514 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3515 (put-text-property (match-beginning 1) (1+ (match-end 1))
3516 'face bface)
3517 (put-text-property (match-beginning 2) (match-end 2)
3518 'face eface))
3519 (forward-line 1)))
3521 (defun article-make-date-line (date type)
3522 "Return a DATE line of TYPE."
3523 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3524 combined-lapsed))
3525 (error "Unknown conversion type: %s" type))
3526 (condition-case ()
3527 (let ((time (ignore-errors (date-to-time date))))
3528 (cond
3529 ;; Convert to the local timezone.
3530 ((eq type 'local)
3531 (concat "Date: " (message-make-date time)))
3532 ;; Convert to Universal Time.
3533 ((eq type 'ut)
3534 (concat "Date: "
3535 (substring
3536 (message-make-date
3537 (let* ((e (parse-time-string date))
3538 (tm (apply 'encode-time e))
3539 (ms (car tm))
3540 (ls (- (cadr tm) (car (current-time-zone time)))))
3541 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3542 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3543 (t (list ms ls)))))
3544 0 -5)
3545 "UT"))
3546 ;; Get the original date from the article.
3547 ((eq type 'original)
3548 (concat "Date: " (if (string-match "\n+$" date)
3549 (substring date 0 (match-beginning 0))
3550 date)))
3551 ;; Let the user define the format.
3552 ((eq type 'user-defined)
3553 (let ((format (or (condition-case nil
3554 (with-current-buffer gnus-summary-buffer
3555 gnus-article-time-format)
3556 (error nil))
3557 gnus-article-time-format)))
3558 (if (functionp format)
3559 (funcall format time)
3560 (concat "Date: " (format-time-string format time)))))
3561 ;; ISO 8601.
3562 ((eq type 'iso8601)
3563 (let ((tz (car (current-time-zone time))))
3564 (concat
3565 "Date: "
3566 (format-time-string "%Y%m%dT%H%M%S" time)
3567 (format "%s%02d%02d"
3568 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3569 (/ (% (abs tz) 3600) 60)))))
3570 ;; Do a lapsed format.
3571 ((eq type 'lapsed)
3572 (concat "Date: " (article-lapsed-string time)))
3573 ;; A combined date/lapsed format.
3574 ((eq type 'combined-lapsed)
3575 (let ((date-string (article-make-date-line date 'original))
3576 (segments 3)
3577 lapsed-string)
3578 (while (and
3579 time
3580 (setq lapsed-string
3581 (concat " (" (article-lapsed-string time segments) ")"))
3582 (> (+ (length date-string)
3583 (length lapsed-string))
3584 (+ fill-column 6))
3585 (> segments 0))
3586 (setq segments (1- segments)))
3587 (if (> segments 0)
3588 (concat date-string lapsed-string)
3589 date-string)))
3590 ;; Display the date in proper English
3591 ((eq type 'english)
3592 (let ((dtime (decode-time time)))
3593 (concat
3594 "Date: the "
3595 (number-to-string (nth 3 dtime))
3596 (let ((digit (% (nth 3 dtime) 10)))
3597 (cond
3598 ((memq (nth 3 dtime) '(11 12 13)) "th")
3599 ((= digit 1) "st")
3600 ((= digit 2) "nd")
3601 ((= digit 3) "rd")
3602 (t "th")))
3603 " of "
3604 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3606 (number-to-string (nth 5 dtime))
3607 " at "
3608 (format "%02d" (nth 2 dtime))
3610 (format "%02d" (nth 1 dtime)))))))
3611 (foo
3612 (format "Date: %s (from Gnus)" date))))
3614 (defun article-lapsed-string (time &optional max-segments)
3615 ;; If the date is seriously mangled, the timezone functions are
3616 ;; liable to bug out, so we ignore all errors.
3617 (let* ((now (current-time))
3618 (real-time (subtract-time now time))
3619 (real-sec (and real-time
3620 (+ (* (float (car real-time)) 65536)
3621 (cadr real-time))))
3622 (sec (and real-time (abs real-sec)))
3623 (segments 0)
3624 num prev)
3625 (unless max-segments
3626 (setq max-segments (length article-time-units)))
3627 (cond
3628 ((null real-time)
3629 "Unknown")
3630 ((zerop sec)
3631 "Now")
3633 (concat
3634 ;; This is a bit convoluted, but basically we go
3635 ;; through the time units for years, weeks, etc,
3636 ;; and divide things to see whether that results
3637 ;; in positive answers.
3638 (mapconcat
3639 (lambda (unit)
3640 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3641 (>= segments max-segments))
3642 ;; The (remaining) seconds are too few to
3643 ;; be divided into this time unit.
3645 ;; It's big enough, so we output it.
3646 (setq sec (- sec (* num (cdr unit))))
3647 (prog1
3648 (concat (if prev ", " "") (int-to-string
3649 (floor num))
3650 " " (symbol-name (car unit))
3651 (if (> num 1) "s" ""))
3652 (setq prev t
3653 segments (1+ segments)))))
3654 article-time-units "")
3655 ;; If dates are odd, then it might appear like the
3656 ;; article was sent in the future.
3657 (if (> real-sec 0)
3658 " ago"
3659 " in the future"))))))
3661 (defun article-date-local (&optional highlight)
3662 "Convert the current article date to the local timezone."
3663 (interactive (list t))
3664 (article-date-ut 'local highlight))
3666 (defun article-date-english (&optional highlight)
3667 "Convert the current article date to something that is proper English."
3668 (interactive (list t))
3669 (article-date-ut 'english highlight))
3671 (defun article-date-original (&optional highlight)
3672 "Convert the current article date to what it was originally.
3673 This is only useful if you have used some other date conversion
3674 function and want to see what the date was before converting."
3675 (interactive (list t))
3676 (article-date-ut 'original highlight))
3678 (defun article-date-lapsed (&optional highlight)
3679 "Convert the current article date to time lapsed since it was sent."
3680 (interactive (list t))
3681 (article-date-ut 'lapsed highlight))
3683 (defun article-date-combined-lapsed (&optional highlight)
3684 "Convert the current article date to time lapsed since it was sent."
3685 (interactive (list t))
3686 (article-date-ut 'combined-lapsed highlight))
3688 (defun article-update-date-lapsed ()
3689 "Function to be run from a timer to update the lapsed time line."
3690 (save-match-data
3691 (let ((buffer (current-buffer)))
3692 (ignore-errors
3693 (walk-windows
3694 (lambda (w)
3695 (set-buffer (window-buffer w))
3696 (when (eq major-mode 'gnus-article-mode)
3697 (let ((old-line (count-lines (point-min) (point)))
3698 (old-column (- (point) (line-beginning-position)))
3699 (window-start
3700 (window-start (get-buffer-window (current-buffer)))))
3701 (goto-char (point-min))
3702 (while (re-search-forward "^Date:" nil t)
3703 (let ((type (get-text-property (match-beginning 0)
3704 'gnus-date-type)))
3705 (when (memq type '(lapsed combined-lapsed user-format))
3706 (when (and window-start
3707 (not (= window-start
3708 (save-excursion
3709 (forward-line 1)
3710 (point)))))
3711 (setq window-start nil))
3712 (save-excursion
3713 (article-date-ut type t (match-beginning 0)))
3714 (forward-line 1)
3715 (when window-start
3716 (set-window-start (get-buffer-window (current-buffer))
3717 (point))))))
3718 (goto-char (point-min))
3719 (when (> old-column 0)
3720 (setq old-line (1- old-line)))
3721 (forward-line old-line)
3722 (end-of-line)
3723 (when (> (current-column) old-column)
3724 (beginning-of-line)
3725 (forward-char old-column)))))
3726 nil 'visible))
3727 (set-buffer buffer))))
3729 (defun gnus-start-date-timer (&optional n)
3730 "Start a timer to update the Date headers in the article buffers.
3731 The numerical prefix says how frequently (in seconds) the function
3732 is to run."
3733 (interactive "p")
3734 (unless n
3735 (setq n 1))
3736 (gnus-stop-date-timer)
3737 (setq article-lapsed-timer
3738 (run-at-time 1 n 'article-update-date-lapsed)))
3740 (defun gnus-stop-date-timer ()
3741 "Stop the Date timer."
3742 (interactive)
3743 (when article-lapsed-timer
3744 (nnheader-cancel-timer article-lapsed-timer)
3745 (setq article-lapsed-timer nil)))
3747 (defun article-date-user (&optional highlight)
3748 "Convert the current article date to the user-defined format.
3749 This format is defined by the `gnus-article-time-format' variable."
3750 (interactive (list t))
3751 (article-date-ut 'user highlight))
3753 (defun article-date-iso8601 (&optional highlight)
3754 "Convert the current article date to ISO8601."
3755 (interactive (list t))
3756 (article-date-ut 'iso8601 highlight))
3758 (defmacro gnus-article-save-original-date (&rest forms)
3759 "Save the original date as a text property and evaluate FORMS."
3760 `(let* ((case-fold-search t)
3761 (start (progn
3762 (goto-char (point-min))
3763 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3764 (not (bolp)))
3765 (match-end 0))))
3766 (date (when (and start
3767 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3768 nil t))
3769 (buffer-substring-no-properties start
3770 (match-beginning 0)))))
3771 (goto-char (point-max))
3772 (skip-chars-backward "\n")
3773 (put-text-property (point-min) (point) 'original-date date)
3774 ,@forms
3775 (goto-char (point-max))
3776 (skip-chars-backward "\n")
3777 (put-text-property (point-min) (point) 'original-date date)))
3779 ;; (defun article-show-all ()
3780 ;; "Show all hidden text in the article buffer."
3781 ;; (interactive)
3782 ;; (save-excursion
3783 ;; (let ((inhibit-read-only t))
3784 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3786 (defun article-remove-leading-whitespace ()
3787 "Remove excessive whitespace from all headers."
3788 (interactive)
3789 (save-excursion
3790 (save-restriction
3791 (let ((inhibit-read-only t))
3792 (article-narrow-to-head)
3793 (goto-char (point-min))
3794 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3795 (delete-region (match-beginning 1) (match-end 1)))))))
3797 (defun article-emphasize (&optional arg)
3798 "Emphasize text according to `gnus-emphasis-alist'."
3799 (interactive (gnus-article-hidden-arg))
3800 (unless (gnus-article-check-hidden-text 'emphasis arg)
3801 (save-excursion
3802 (let ((alist (or
3803 (condition-case nil
3804 (with-current-buffer gnus-summary-buffer
3805 gnus-article-emphasis-alist)
3806 (error))
3807 gnus-emphasis-alist))
3808 (inhibit-read-only t)
3809 (props (append '(article-type emphasis)
3810 gnus-hidden-properties))
3811 regexp elem beg invisible visible face)
3812 (article-goto-body)
3813 (setq beg (point))
3814 (while (setq elem (pop alist))
3815 (goto-char beg)
3816 (setq regexp (car elem)
3817 invisible (nth 1 elem)
3818 visible (nth 2 elem)
3819 face (nth 3 elem))
3820 (while (re-search-forward regexp nil t)
3821 (when (and (match-beginning visible) (match-beginning invisible))
3822 (gnus-article-hide-text
3823 (match-beginning invisible) (match-end invisible) props)
3824 (gnus-article-unhide-text-type
3825 (match-beginning visible) (match-end visible) 'emphasis)
3826 (gnus-put-overlay-excluding-newlines
3827 (match-beginning visible) (match-end visible) 'face face)
3828 (gnus-add-wash-type 'emphasis)
3829 (goto-char (match-end invisible)))))))))
3831 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3832 "Setup newsgroup emphasis alist."
3833 (unless gnus-article-emphasis-alist
3834 (let ((name (and gnus-newsgroup-name
3835 (gnus-group-real-name gnus-newsgroup-name))))
3836 (make-local-variable 'gnus-article-emphasis-alist)
3837 (setq gnus-article-emphasis-alist
3838 (nconc
3839 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3840 (while (setq elem (pop alist))
3841 (when (and name (string-match (car elem) name))
3842 (setq alist nil
3843 highlight (copy-sequence (cdr elem)))))
3844 highlight)
3845 (copy-sequence highlight-words)
3846 (if gnus-newsgroup-name
3847 (copy-sequence (gnus-group-find-parameter
3848 gnus-newsgroup-name 'highlight-words t)))
3849 gnus-emphasis-alist)))))
3851 (defvar gnus-summary-article-menu)
3852 (defvar gnus-summary-post-menu)
3854 ;;; Saving functions.
3856 (defun gnus-article-save (save-buffer file &optional num)
3857 "Save the currently selected article."
3858 (when (or (get gnus-default-article-saver :headers)
3859 (not gnus-save-all-headers))
3860 ;; Remove headers according to `gnus-saved-headers' or the value
3861 ;; of the `:headers' property that the saver function might have.
3862 (let ((gnus-visible-headers
3863 (or (symbol-value (get gnus-default-article-saver :headers))
3864 gnus-saved-headers gnus-visible-headers))
3865 ;; Ignore group parameter. See `article-hide-headers'.
3866 (gnus-summary-buffer nil))
3867 (with-current-buffer save-buffer
3868 (article-hide-headers 1 t))))
3869 (save-window-excursion
3870 (if (not gnus-default-article-saver)
3871 (error "No default saver is defined")
3872 ;; !!! Magic! The saving functions all save
3873 ;; `gnus-save-article-buffer' (or so they think), but we
3874 ;; bind that variable to our save-buffer.
3875 (set-buffer gnus-article-buffer)
3876 (let* ((gnus-save-article-buffer save-buffer)
3877 (filename
3878 (cond
3879 ((not gnus-prompt-before-saving) 'default)
3880 ((eq gnus-prompt-before-saving 'always) nil)
3881 (t file)))
3882 (gnus-number-of-articles-to-be-saved
3883 (when (eq gnus-prompt-before-saving t)
3884 num))) ; Magic
3885 (set-buffer gnus-article-current-summary)
3886 (funcall gnus-default-article-saver filename)))))
3888 (defun gnus-read-save-file-name (prompt &optional filename
3889 function group headers variable
3890 dir-var)
3891 (let ((default-name
3892 (funcall function group headers (symbol-value variable)))
3893 result)
3894 (setq result
3895 (expand-file-name
3896 (cond
3897 ((eq filename 'default)
3898 default-name)
3899 ((eq filename t)
3900 default-name)
3901 (filename filename)
3903 (when (symbol-value dir-var)
3904 (setq default-name (expand-file-name
3905 (file-name-nondirectory default-name)
3906 (symbol-value dir-var))))
3907 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3908 (prompt
3909 (format prompt
3910 (if (and gnus-number-of-articles-to-be-saved
3911 (> gnus-number-of-articles-to-be-saved 1))
3912 (format "these %d articles"
3913 gnus-number-of-articles-to-be-saved)
3914 "this article")))
3915 (file
3916 ;; Let the split methods have their say.
3917 (cond
3918 ;; No split name was found.
3919 ((null split-name)
3920 (read-file-name
3921 (concat prompt " (default "
3922 (file-name-nondirectory default-name) "): ")
3923 (file-name-directory default-name)
3924 default-name))
3925 ;; A single group name is returned.
3926 ((stringp split-name)
3927 (setq default-name
3928 (funcall function split-name headers
3929 (symbol-value variable)))
3930 (read-file-name
3931 (concat prompt " (default "
3932 (file-name-nondirectory default-name) "): ")
3933 (file-name-directory default-name)
3934 default-name))
3935 ;; A single split name was found
3936 ((= 1 (length split-name))
3937 (let* ((name (expand-file-name
3938 (car split-name)
3939 gnus-article-save-directory))
3940 (dir (cond ((file-directory-p name)
3941 (file-name-as-directory name))
3942 ((file-exists-p name) name)
3943 (t gnus-article-save-directory))))
3944 (read-file-name
3945 (concat prompt " (default " name "): ")
3946 dir name)))
3947 ;; A list of splits was found.
3949 (setq split-name (nreverse split-name))
3950 (let (result)
3951 (let ((file-name-history
3952 (nconc split-name file-name-history)))
3953 (setq result
3954 (expand-file-name
3955 (read-file-name
3956 (concat prompt " (`M-p' for defaults): ")
3957 gnus-article-save-directory
3958 (car split-name))
3959 gnus-article-save-directory)))
3960 (car (push result file-name-history)))))))
3961 ;; Create the directory.
3962 (gnus-make-directory (file-name-directory file))
3963 ;; If we have read a directory, we append the default file name.
3964 (when (file-directory-p file)
3965 (setq file (expand-file-name (file-name-nondirectory
3966 default-name)
3967 (file-name-as-directory file))))
3968 ;; Possibly translate some characters.
3969 (nnheader-translate-file-chars file))))))
3970 (gnus-make-directory (file-name-directory result))
3971 (when variable
3972 (set variable result))
3973 (when dir-var
3974 (set dir-var (file-name-directory result)))
3975 result))
3977 (defun gnus-article-archive-name (group)
3978 "Return the first instance of an \"Archive-name\" in the current buffer."
3979 (let ((case-fold-search t))
3980 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3981 (nnheader-concat gnus-article-save-directory
3982 (match-string 1)))))
3984 (defun gnus-article-nndoc-name (group)
3985 "If GROUP is an nndoc group, return the name of the parent group."
3986 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3987 (gnus-group-get-parameter group 'save-article-group)))
3989 (defun gnus-summary-save-in-rmail (&optional filename)
3990 "Append this article to Rmail file.
3991 Optional argument FILENAME specifies file name.
3992 Directory to save to is default to `gnus-article-save-directory'."
3993 (setq filename (gnus-read-save-file-name
3994 "Save %s in rmail file" filename
3995 gnus-rmail-save-name gnus-newsgroup-name
3996 gnus-current-headers 'gnus-newsgroup-last-rmail))
3997 (with-current-buffer gnus-save-article-buffer
3998 (save-excursion
3999 (save-restriction
4000 (widen)
4001 ;; Note that unlike gnus-summary-save-in-mail, there is no
4002 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4003 ;; not use Babyl.
4004 (gnus-output-to-rmail filename))))
4005 filename)
4007 (defun gnus-summary-save-in-mail (&optional filename)
4008 "Append this article to Unix mail file.
4009 Optional argument FILENAME specifies file name.
4010 Directory to save to is default to `gnus-article-save-directory'."
4011 (setq filename (gnus-read-save-file-name
4012 "Save %s in Unix mail file" filename
4013 gnus-mail-save-name gnus-newsgroup-name
4014 gnus-current-headers 'gnus-newsgroup-last-mail))
4015 (with-current-buffer gnus-save-article-buffer
4016 (save-excursion
4017 (save-restriction
4018 (widen)
4019 (if (and (file-readable-p filename)
4020 (file-regular-p filename)
4021 (mail-file-babyl-p filename))
4022 (gnus-output-to-rmail filename)
4023 (gnus-output-to-mail filename)))))
4024 filename)
4026 (put 'gnus-summary-save-in-file :decode t)
4027 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4028 (defun gnus-summary-save-in-file (&optional filename overwrite)
4029 "Append this article to file.
4030 Optional argument FILENAME specifies file name.
4031 Directory to save to is default to `gnus-article-save-directory'."
4032 (setq filename (gnus-read-save-file-name
4033 "Save %s in file" filename
4034 gnus-file-save-name gnus-newsgroup-name
4035 gnus-current-headers 'gnus-newsgroup-last-file))
4036 (with-current-buffer gnus-save-article-buffer
4037 (save-excursion
4038 (save-restriction
4039 (widen)
4040 (when (and overwrite
4041 (file-exists-p filename))
4042 (delete-file filename))
4043 (gnus-output-to-file filename))))
4044 filename)
4046 (put 'gnus-summary-write-to-file :decode t)
4047 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4048 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4049 (defun gnus-summary-write-to-file (&optional filename)
4050 "Write this article to a file, overwriting it if the file exists.
4051 Optional argument FILENAME specifies file name.
4052 The directory to save in defaults to `gnus-article-save-directory'."
4053 (setq filename (gnus-read-save-file-name
4054 "Save %s in file" filename
4055 gnus-file-save-name gnus-newsgroup-name
4056 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4057 (gnus-summary-save-in-file filename t))
4059 (put 'gnus-summary-save-body-in-file :decode t)
4060 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4061 "Append this article body to a file.
4062 Optional argument FILENAME specifies file name.
4063 The directory to save in defaults to `gnus-article-save-directory'."
4064 (setq filename (gnus-read-save-file-name
4065 "Save %s body in file" filename
4066 gnus-file-save-name gnus-newsgroup-name
4067 gnus-current-headers 'gnus-newsgroup-last-file))
4068 (with-current-buffer gnus-save-article-buffer
4069 (save-excursion
4070 (save-restriction
4071 (widen)
4072 (when (article-goto-body)
4073 (narrow-to-region (point) (point-max)))
4074 (when (and overwrite
4075 (file-exists-p filename))
4076 (delete-file filename))
4077 (gnus-output-to-file filename))))
4078 filename)
4080 (put 'gnus-summary-write-body-to-file :decode t)
4081 (put 'gnus-summary-write-body-to-file
4082 :function 'gnus-summary-save-body-in-file)
4083 (defun gnus-summary-write-body-to-file (&optional filename)
4084 "Write this article body to a file, overwriting it if the file exists.
4085 Optional argument FILENAME specifies file name.
4086 The directory to save in defaults to `gnus-article-save-directory'."
4087 (setq filename (gnus-read-save-file-name
4088 "Save %s body in file" filename
4089 gnus-file-save-name gnus-newsgroup-name
4090 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4091 (gnus-summary-save-body-in-file filename t))
4093 (put 'gnus-summary-save-in-pipe :decode t)
4094 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4095 (defun gnus-summary-save-in-pipe (&optional command raw)
4096 "Pipe this article to subprocess COMMAND.
4097 Valid values for COMMAND include:
4098 a string
4099 The executable command name and possibly arguments.
4101 You will be prompted for the command in the minibuffer.
4102 the symbol `default'
4103 It will be replaced with the command which the variable
4104 `gnus-summary-pipe-output-default-command' holds or the command
4105 last used for saving.
4106 Non-nil value for RAW overrides `:decode' and `:headers' properties
4107 and the raw article including all headers will be piped."
4108 (let ((article (gnus-summary-article-number))
4109 (decode (unless raw
4110 (get 'gnus-summary-save-in-pipe :decode)))
4111 save-buffer default)
4112 (if article
4113 (if (vectorp (gnus-summary-article-header article))
4114 (save-current-buffer
4115 (gnus-summary-select-article decode decode nil article)
4116 (insert-buffer-substring
4117 (prog1
4118 (if decode
4119 gnus-article-buffer
4120 gnus-original-article-buffer)
4121 (setq save-buffer
4122 (nnheader-set-temp-buffer " *Gnus Save*"))))
4123 ;; Remove unwanted headers.
4124 (when (and (not raw)
4125 (or (get 'gnus-summary-save-in-pipe :headers)
4126 (not gnus-save-all-headers)))
4127 (let ((gnus-visible-headers
4128 (or (symbol-value (get 'gnus-summary-save-in-pipe
4129 :headers))
4130 gnus-saved-headers gnus-visible-headers))
4131 (gnus-summary-buffer nil))
4132 (article-hide-headers 1 t))))
4133 (error "%d is not a real article" article))
4134 (error "No article to pipe"))
4135 (setq default (or gnus-summary-pipe-output-default-command
4136 gnus-last-shell-command))
4137 (unless (stringp command)
4138 (setq command
4139 (if (and (eq command 'default) default)
4140 default
4141 (gnus-read-shell-command "Shell command on this article: "
4142 default))))
4143 (when (string-equal command "")
4144 (if default
4145 (setq command default)
4146 (error "A command is required")))
4147 (with-current-buffer save-buffer
4148 (save-restriction
4149 (widen)
4150 (shell-command-on-region (point-min) (point-max) command nil)))
4151 (gnus-kill-buffer save-buffer))
4152 (setq gnus-summary-pipe-output-default-command command))
4154 (defun gnus-summary-pipe-to-muttprint (&optional command)
4155 "Pipe this article to muttprint."
4156 (unless (stringp command)
4157 (setq command (read-string
4158 "Print using command: " gnus-summary-muttprint-program
4159 nil gnus-summary-muttprint-program)))
4160 (let ((gnus-summary-pipe-output-default-command
4161 gnus-summary-pipe-output-default-command))
4162 (gnus-summary-save-in-pipe command))
4163 (setq gnus-summary-muttprint-program command))
4165 ;;; Article file names when saving.
4167 (defun gnus-capitalize-newsgroup (newsgroup)
4168 "Capitalize NEWSGROUP name."
4169 (when (not (zerop (length newsgroup)))
4170 (concat (char-to-string (upcase (aref newsgroup 0)))
4171 (substring newsgroup 1))))
4173 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4174 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4175 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4176 Otherwise, it is like ~/News/news/group/num."
4177 (let ((default
4178 (expand-file-name
4179 (concat (if (gnus-use-long-file-name 'not-save)
4180 (gnus-capitalize-newsgroup newsgroup)
4181 (gnus-newsgroup-directory-form newsgroup))
4182 "/" (int-to-string (mail-header-number headers)))
4183 gnus-article-save-directory)))
4184 (if (and last-file
4185 (string-equal (file-name-directory default)
4186 (file-name-directory last-file))
4187 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4188 default
4189 (or last-file default))))
4191 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4192 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4193 If variable `gnus-use-long-file-name' is non-nil, it is
4194 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4195 (let ((default
4196 (expand-file-name
4197 (concat (if (gnus-use-long-file-name 'not-save)
4198 newsgroup
4199 (gnus-newsgroup-directory-form newsgroup))
4200 "/" (int-to-string (mail-header-number headers)))
4201 gnus-article-save-directory)))
4202 (if (and last-file
4203 (string-equal (file-name-directory default)
4204 (file-name-directory last-file))
4205 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4206 default
4207 (or last-file default))))
4209 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4210 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4211 If variable `gnus-use-long-file-name' is non-nil, it is
4212 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4213 (or last-file
4214 (expand-file-name
4215 (if (gnus-use-long-file-name 'not-save)
4216 newsgroup
4217 (file-relative-name
4218 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4219 default-directory))
4220 gnus-article-save-directory)))
4222 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4223 "Generate file name from sender."
4224 (let ((from (mail-header-from headers)))
4225 (expand-file-name
4226 (if (and from (string-match "\\([^ <]+\\)@" from))
4227 (match-string 1 from)
4228 "nobody")
4229 gnus-article-save-directory)))
4231 (defun article-verify-x-pgp-sig ()
4232 "Verify X-PGP-Sig."
4233 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4234 (interactive)
4235 (if (gnus-buffer-live-p gnus-original-article-buffer)
4236 (let ((sig (with-current-buffer gnus-original-article-buffer
4237 (gnus-fetch-field "X-PGP-Sig")))
4238 items info headers)
4239 (when (and sig
4240 mml2015-use
4241 (mml2015-clear-verify-function))
4242 (with-temp-buffer
4243 (insert-buffer-substring gnus-original-article-buffer)
4244 (setq items (split-string sig))
4245 (message-narrow-to-head)
4246 (let ((inhibit-point-motion-hooks t)
4247 (case-fold-search t))
4248 ;; Don't verify multiple headers.
4249 (setq headers (mapconcat (lambda (header)
4250 (concat header ": "
4251 (mail-fetch-field header)
4252 "\n"))
4253 (split-string (nth 1 items) ",") "")))
4254 (delete-region (point-min) (point-max))
4255 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4256 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4257 (insert headers)
4258 (widen)
4259 (forward-line)
4260 (while (not (eobp))
4261 (if (looking-at "^-")
4262 (insert "- "))
4263 (forward-line))
4264 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4265 (insert "Version: " (car items) "\n\n")
4266 (insert (mapconcat 'identity (cddr items) "\n"))
4267 (insert "\n-----END PGP SIGNATURE-----\n")
4268 (let ((mm-security-handle (list (format "multipart/signed"))))
4269 (mml2015-clean-buffer)
4270 (let ((coding-system-for-write (or gnus-newsgroup-charset
4271 'iso-8859-1)))
4272 (funcall (mml2015-clear-verify-function)))
4273 (setq info
4274 (or (mm-handle-multipart-ctl-parameter
4275 mm-security-handle 'gnus-details)
4276 (mm-handle-multipart-ctl-parameter
4277 mm-security-handle 'gnus-info)))))
4278 (when info
4279 (let ((inhibit-read-only t) bface eface)
4280 (save-restriction
4281 (message-narrow-to-head)
4282 (goto-char (point-max))
4283 (forward-line -1)
4284 (setq bface (get-text-property (point-at-bol) 'face)
4285 eface (get-text-property (1- (point-at-eol)) 'face))
4286 (message-remove-header "X-Gnus-PGP-Verify")
4287 (if (re-search-forward "^X-PGP-Sig:" nil t)
4288 (forward-line)
4289 (goto-char (point-max)))
4290 (narrow-to-region (point) (point))
4291 (insert "X-Gnus-PGP-Verify: " info "\n")
4292 (goto-char (point-min))
4293 (forward-line)
4294 (while (not (eobp))
4295 (if (not (looking-at "^[ \t]"))
4296 (insert " "))
4297 (forward-line))
4298 ;; Do highlighting.
4299 (goto-char (point-min))
4300 (when (looking-at "\\([^:]+\\): *")
4301 (put-text-property (match-beginning 1) (1+ (match-end 1))
4302 'face bface)
4303 (put-text-property (match-end 0) (point-max)
4304 'face eface)))))))))
4306 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4308 (defun article-verify-cancel-lock ()
4309 "Verify Cancel-Lock header."
4310 (interactive)
4311 (if (gnus-buffer-live-p gnus-original-article-buffer)
4312 (canlock-verify gnus-original-article-buffer)))
4314 (eval-and-compile
4315 (mapc
4316 (lambda (func)
4317 (let (afunc gfunc)
4318 (if (consp func)
4319 (setq afunc (car func)
4320 gfunc (cdr func))
4321 (setq afunc func
4322 gfunc (intern (format "gnus-%s" func))))
4323 (defalias gfunc
4324 (when (fboundp afunc)
4325 `(lambda (&optional interactive &rest args)
4326 ,(documentation afunc t)
4327 (interactive (list t))
4328 (with-current-buffer gnus-article-buffer
4329 (if interactive
4330 (call-interactively ',afunc)
4331 (apply ',afunc args))))))))
4332 '(article-hide-headers
4333 article-verify-x-pgp-sig
4334 article-verify-cancel-lock
4335 article-hide-boring-headers
4336 article-treat-overstrike
4337 article-treat-ansi-sequences
4338 article-fill-long-lines
4339 article-capitalize-sentences
4340 article-remove-cr
4341 article-remove-leading-whitespace
4342 article-display-x-face
4343 article-display-face
4344 article-de-quoted-unreadable
4345 article-de-base64-unreadable
4346 article-decode-HZ
4347 article-wash-html
4348 article-unsplit-urls
4349 article-hide-list-identifiers
4350 article-strip-banner
4351 article-babel
4352 article-hide-pem
4353 article-hide-signature
4354 article-strip-headers-in-body
4355 article-remove-trailing-blank-lines
4356 article-strip-leading-blank-lines
4357 article-strip-multiple-blank-lines
4358 article-strip-leading-space
4359 article-strip-trailing-space
4360 article-strip-blank-lines
4361 article-strip-all-blank-lines
4362 article-date-local
4363 article-date-english
4364 article-date-iso8601
4365 article-date-original
4366 article-treat-date
4367 article-date-ut
4368 article-decode-mime-words
4369 article-decode-charset
4370 article-decode-encoded-words
4371 article-date-user
4372 article-date-lapsed
4373 article-date-combined-lapsed
4374 article-emphasize
4375 article-treat-dumbquotes
4376 article-treat-non-ascii
4377 article-normalize-headers
4378 ;;(article-show-all . gnus-article-show-all-headers)
4382 ;;; Gnus article mode
4385 (put 'gnus-article-mode 'mode-class 'special)
4387 (set-keymap-parent gnus-article-mode-map widget-keymap)
4389 (gnus-define-keys gnus-article-mode-map
4390 " " gnus-article-goto-next-page
4391 "\177" gnus-article-goto-prev-page
4392 [delete] gnus-article-goto-prev-page
4393 [backspace] gnus-article-goto-prev-page
4394 "\C-c^" gnus-article-refer-article
4395 "h" gnus-article-show-summary
4396 "s" gnus-article-show-summary
4397 "\C-c\C-m" gnus-article-mail
4398 "?" gnus-article-describe-briefly
4399 "<" beginning-of-buffer
4400 ">" end-of-buffer
4401 "\C-c\C-i" gnus-info-find-node
4402 "\C-c\C-b" gnus-bug
4403 "R" gnus-article-reply-with-original
4404 "F" gnus-article-followup-with-original
4405 "\C-hk" gnus-article-describe-key
4406 "\C-hc" gnus-article-describe-key-briefly
4407 "\C-hb" gnus-article-describe-bindings
4409 "e" gnus-article-read-summary-keys
4410 "\C-d" gnus-article-read-summary-keys
4411 "\M-*" gnus-article-read-summary-keys
4412 "\M-#" gnus-article-read-summary-keys
4413 "\M-^" gnus-article-read-summary-keys
4414 "\M-g" gnus-article-read-summary-keys)
4416 (substitute-key-definition
4417 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4419 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4420 "W" gnus-article-wide-reply-with-original)
4421 (if (featurep 'xemacs)
4422 (set-keymap-default-binding gnus-article-send-map
4423 'gnus-article-read-summary-send-keys)
4424 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4426 (defun gnus-article-make-menu-bar ()
4427 (unless (boundp 'gnus-article-commands-menu)
4428 (gnus-summary-make-menu-bar))
4429 (unless (boundp 'gnus-article-article-menu)
4430 (easy-menu-define
4431 gnus-article-article-menu gnus-article-mode-map ""
4432 '("Article"
4433 ["Scroll forwards" gnus-article-goto-next-page t]
4434 ["Scroll backwards" gnus-article-goto-prev-page t]
4435 ["Show summary" gnus-article-show-summary t]
4436 ["Fetch Message-ID at point" gnus-article-refer-article t]
4437 ["Mail to address at point" gnus-article-mail t]
4438 ["Send a bug report" gnus-bug t]))
4440 (easy-menu-define
4441 gnus-article-treatment-menu gnus-article-mode-map ""
4442 ;; Fixme: this should use :active (and maybe :visible).
4443 '("Treatment"
4444 ["Hide headers" gnus-article-hide-headers t]
4445 ["Hide signature" gnus-article-hide-signature t]
4446 ["Hide citation" gnus-article-hide-citation t]
4447 ["Treat overstrike" gnus-article-treat-overstrike t]
4448 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4449 ["Remove carriage return" gnus-article-remove-cr t]
4450 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4451 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4452 ["Remove base64" gnus-article-de-base64-unreadable t]
4453 ["Treat html" gnus-article-wash-html t]
4454 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4455 ["Decode HZ" gnus-article-decode-HZ t]))
4457 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4459 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4461 (gnus-run-hooks 'gnus-article-menu-hook)))
4463 (defvar bookmark-make-record-function)
4464 (defvar shr-put-image-function)
4466 (defun gnus-article-mode ()
4467 "Major mode for displaying an article.
4469 All normal editing commands are switched off.
4471 The following commands are available in addition to all summary mode
4472 commands:
4473 \\<gnus-article-mode-map>
4474 \\[gnus-article-next-page]\t Scroll the article one page forwards
4475 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4476 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4477 \\[gnus-article-show-summary]\t Display the summary buffer
4478 \\[gnus-article-mail]\t Send a reply to the address near point
4479 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4480 \\[gnus-info-find-node]\t Go to the Gnus info node"
4481 (interactive)
4482 (kill-all-local-variables)
4483 (gnus-simplify-mode-line)
4484 (setq mode-name "Article")
4485 (setq major-mode 'gnus-article-mode)
4486 (make-local-variable 'minor-mode-alist)
4487 (use-local-map gnus-article-mode-map)
4488 (when (gnus-visual-p 'article-menu 'menu)
4489 (gnus-article-make-menu-bar)
4490 (when gnus-summary-tool-bar-map
4491 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4492 (gnus-update-format-specifications nil 'article-mode)
4493 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4494 (set (make-local-variable 'gnus-page-broken) nil)
4495 (make-local-variable 'gnus-article-current-summary)
4496 (make-local-variable 'gnus-article-mime-handles)
4497 (make-local-variable 'gnus-article-decoded-p)
4498 (make-local-variable 'gnus-article-mime-handle-alist)
4499 (make-local-variable 'gnus-article-wash-types)
4500 (make-local-variable 'gnus-article-image-alist)
4501 (make-local-variable 'gnus-article-charset)
4502 (make-local-variable 'gnus-article-ignored-charsets)
4503 (set (make-local-variable 'bookmark-make-record-function)
4504 'gnus-summary-bookmark-make-record)
4505 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4506 ;; face.
4507 (set (make-local-variable 'nobreak-char-display) nil)
4508 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4509 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4510 (setq cursor-in-non-selected-windows nil)
4511 (gnus-set-default-directory)
4512 (buffer-disable-undo)
4513 (setq buffer-read-only t
4514 show-trailing-whitespace nil)
4515 (set-syntax-table gnus-article-mode-syntax-table)
4516 (mm-enable-multibyte)
4517 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4519 (defun gnus-article-setup-buffer ()
4520 "Initialize the article buffer."
4521 (let* ((name (if gnus-single-article-buffer "*Article*"
4522 (concat "*Article "
4523 (gnus-group-decoded-name gnus-newsgroup-name)
4524 "*")))
4525 (original
4526 (progn (string-match "\\*Article" name)
4527 (concat " *Original Article"
4528 (substring name (match-end 0))))))
4529 (setq gnus-article-buffer name)
4530 (setq gnus-original-article-buffer original)
4531 (setq gnus-article-mime-handle-alist nil)
4532 (with-current-buffer gnus-summary-buffer
4533 ;; This might be a variable local to the summary buffer.
4534 (unless gnus-single-article-buffer
4535 (setq gnus-article-buffer name)
4536 (setq gnus-original-article-buffer original)
4537 (gnus-set-global-variables)))
4538 (gnus-article-setup-highlight-words)
4539 ;; Init original article buffer.
4540 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4541 (mm-enable-multibyte)
4542 (setq major-mode 'gnus-original-article-mode)
4543 (make-local-variable 'gnus-original-article))
4544 (if (and (get-buffer name)
4545 (with-current-buffer name
4546 (if gnus-article-edit-mode
4547 (if (y-or-n-p "Article mode edit in progress; discard? ")
4548 (progn
4549 (set-buffer-modified-p nil)
4550 (gnus-kill-buffer name)
4551 (message "")
4552 nil)
4553 (error "Action aborted"))
4554 t)))
4555 (with-current-buffer name
4556 (set (make-local-variable 'gnus-article-edit-mode) nil)
4557 (gnus-article-stop-animations)
4558 (when gnus-article-mime-handles
4559 (mm-destroy-parts gnus-article-mime-handles)
4560 (setq gnus-article-mime-handles nil))
4561 ;; Set it to nil in article-buffer!
4562 (setq gnus-article-mime-handle-alist nil)
4563 (buffer-disable-undo)
4564 (setq buffer-read-only t)
4565 (unless (eq major-mode 'gnus-article-mode)
4566 (gnus-article-mode))
4567 (setq truncate-lines gnus-article-truncate-lines)
4568 (current-buffer))
4569 (with-current-buffer (gnus-get-buffer-create name)
4570 (gnus-article-mode)
4571 (setq truncate-lines gnus-article-truncate-lines)
4572 (make-local-variable 'gnus-summary-buffer)
4573 (setq gnus-summary-buffer
4574 (gnus-summary-buffer-name gnus-newsgroup-name))
4575 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4576 (when article-lapsed-timer
4577 (gnus-stop-date-timer))
4578 (when gnus-article-update-date-headers
4579 (gnus-start-date-timer gnus-article-update-date-headers))
4580 (current-buffer)))))
4582 (defun gnus-article-stop-animations ()
4583 (dolist (timer (and (boundp 'timer-list)
4584 timer-list))
4585 (when (eq (elt timer 5) 'image-animate-timeout)
4586 (cancel-timer timer))))
4588 (defun gnus-stop-downloads ()
4589 (when (boundp 'url-queue)
4590 (set (intern "url-queue" obarray) nil)))
4592 ;; Set article window start at LINE, where LINE is the number of lines
4593 ;; from the head of the article.
4594 (defun gnus-article-set-window-start (&optional line)
4595 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4596 (when article-window
4597 (set-window-start
4598 article-window
4599 (with-current-buffer gnus-article-buffer
4600 (goto-char (point-min))
4601 (if (not line)
4602 (point-min)
4603 (gnus-message 6 "Moved to bookmark")
4604 (search-forward "\n\n" nil t)
4605 (forward-line line)
4606 (point)))))))
4608 (defun gnus-article-prepare (article &optional all-headers header)
4609 "Prepare ARTICLE in article mode buffer.
4610 ARTICLE should either be an article number or a Message-ID.
4611 If ARTICLE is an id, HEADER should be the article headers.
4612 If ALL-HEADERS is non-nil, no headers are hidden."
4613 (save-excursion
4614 ;; Make sure we start in a summary buffer.
4615 (unless (eq major-mode 'gnus-summary-mode)
4616 (set-buffer gnus-summary-buffer))
4617 (setq gnus-summary-buffer (current-buffer))
4618 (let* ((gnus-article (if header (mail-header-number header) article))
4619 (summary-buffer (current-buffer))
4620 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4621 (group gnus-newsgroup-name)
4622 result)
4623 (save-excursion
4624 (gnus-article-setup-buffer)
4625 (set-buffer gnus-article-buffer)
4626 ;; Deactivate active regions.
4627 (when (and (boundp 'transient-mark-mode)
4628 transient-mark-mode)
4629 (setq mark-active nil))
4630 (if (not (setq result (let ((inhibit-read-only t))
4631 (gnus-request-article-this-buffer
4632 article group))))
4633 ;; There is no such article.
4634 (save-excursion
4635 (when (and (numberp article)
4636 (not (memq article gnus-newsgroup-sparse)))
4637 (setq gnus-article-current
4638 (cons gnus-newsgroup-name article))
4639 (set-buffer gnus-summary-buffer)
4640 (setq gnus-current-article article)
4641 (if (and (memq article gnus-newsgroup-undownloaded)
4642 (not (gnus-online (gnus-find-method-for-group
4643 gnus-newsgroup-name))))
4644 (progn
4645 (gnus-summary-set-agent-mark article)
4646 (message "Message marked for downloading"))
4647 (gnus-summary-mark-article article gnus-canceled-mark)
4648 (unless (memq article gnus-newsgroup-sparse)
4649 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4650 (if (or (eq result 'pseudo)
4651 (eq result 'nneething))
4652 (progn
4653 (with-current-buffer summary-buffer
4654 (push article gnus-newsgroup-history)
4655 (setq gnus-last-article gnus-current-article
4656 gnus-current-article 0
4657 gnus-current-headers nil
4658 gnus-article-current nil)
4659 (if (eq result 'nneething)
4660 (gnus-configure-windows 'summary)
4661 (gnus-configure-windows 'article))
4662 (gnus-set-global-variables))
4663 (let ((gnus-article-mime-handle-alist-1
4664 gnus-article-mime-handle-alist))
4665 (gnus-set-mode-line 'article)))
4666 ;; The result from the `request' was an actual article -
4667 ;; or at least some text that is now displayed in the
4668 ;; article buffer.
4669 (when (and (numberp article)
4670 (not (eq article gnus-current-article)))
4671 ;; Seems like a new article has been selected.
4672 ;; `gnus-current-article' must be an article number.
4673 (with-current-buffer summary-buffer
4674 (push article gnus-newsgroup-history)
4675 (setq gnus-last-article gnus-current-article
4676 gnus-current-article article
4677 gnus-current-headers
4678 (gnus-summary-article-header gnus-current-article)
4679 gnus-article-current
4680 (cons gnus-newsgroup-name gnus-current-article))
4681 (unless (vectorp gnus-current-headers)
4682 (setq gnus-current-headers nil))
4683 (gnus-summary-goto-subject gnus-current-article)
4684 (when (gnus-summary-show-thread)
4685 ;; If the summary buffer really was folded, the
4686 ;; previous goto may not actually have gone to
4687 ;; the right article, but the thread root instead.
4688 ;; So we go again.
4689 (gnus-summary-goto-subject gnus-current-article))
4690 (gnus-run-hooks 'gnus-mark-article-hook)
4691 (gnus-set-mode-line 'summary)
4692 (when (gnus-visual-p 'article-highlight 'highlight)
4693 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4694 ;; Set the global newsgroup variables here.
4695 (gnus-set-global-variables)
4696 (setq gnus-have-all-headers
4697 (or all-headers gnus-show-all-headers))))
4698 (save-excursion
4699 (gnus-configure-windows 'article))
4700 (when (or (numberp article)
4701 (stringp article))
4702 (gnus-article-prepare-display)
4703 ;; Do page break.
4704 (goto-char (point-min))
4705 (when gnus-break-pages
4706 (gnus-narrow-to-page)))
4707 (let ((gnus-article-mime-handle-alist-1
4708 gnus-article-mime-handle-alist))
4709 (gnus-set-mode-line 'article))
4710 (article-goto-body)
4711 (unless (bobp)
4712 (forward-line -1))
4713 (set-window-point (get-buffer-window (current-buffer)) (point))
4714 (gnus-configure-windows 'article)
4715 (gnus-run-hooks 'gnus-article-prepare-hook)
4716 t))))))
4718 ;;;###autoload
4719 (defun gnus-article-prepare-display ()
4720 "Make the current buffer look like a nice article."
4721 ;; Hooks for getting information from the article.
4722 ;; This hook must be called before being narrowed.
4723 (let ((gnus-article-buffer (current-buffer))
4724 buffer-read-only
4725 (inhibit-read-only t))
4726 (unless (eq major-mode 'gnus-article-mode)
4727 (gnus-article-mode))
4728 (setq buffer-read-only nil
4729 gnus-article-wash-types nil
4730 gnus-article-image-alist nil)
4731 (gnus-run-hooks 'gnus-tmp-internal-hook)
4732 (when gnus-display-mime-function
4733 (funcall gnus-display-mime-function))))
4736 ;;; Gnus Sticky Article Mode
4739 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4740 "Mode for sticky articles."
4741 ;; Release bindings that won't work.
4742 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4743 gnus-sticky-article-mode-map)
4744 (substitute-key-definition 'gnus-article-refer-article 'undefined
4745 gnus-sticky-article-mode-map)
4746 (dolist (k '("e" "h" "s" "F" "R"))
4747 (define-key gnus-sticky-article-mode-map k nil))
4748 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4749 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4750 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4751 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4753 (defun gnus-sticky-article (arg)
4754 "Make the current article sticky.
4755 If a prefix ARG is given, ask for a name for this sticky article buffer."
4756 (interactive "P")
4757 (gnus-summary-show-thread)
4758 (gnus-summary-select-article nil nil 'pseudo)
4759 (let (new-art-buf-name)
4760 (gnus-eval-in-buffer-window gnus-article-buffer
4761 (setq new-art-buf-name
4762 (concat
4763 "*Sticky Article: "
4764 (if arg
4765 (read-from-minibuffer "Sticky article buffer name: ")
4766 (gnus-with-article-headers
4767 (gnus-article-goto-header "subject")
4768 (setq new-art-buf-name
4769 (buffer-substring-no-properties
4770 (line-beginning-position) (line-end-position)))
4771 (goto-char (point-min))
4772 (gnus-article-goto-header "from")
4773 (setq new-art-buf-name
4774 (concat
4775 new-art-buf-name ", "
4776 (buffer-substring-no-properties
4777 (line-beginning-position) (line-end-position))))
4778 (goto-char (point-min))
4779 (gnus-article-goto-header "date")
4780 (setq new-art-buf-name
4781 (concat
4782 new-art-buf-name ", "
4783 (buffer-substring-no-properties
4784 (line-beginning-position) (line-end-position))))))
4785 "*"))
4786 (if (and (gnus-buffer-live-p new-art-buf-name)
4787 (with-current-buffer new-art-buf-name
4788 (eq major-mode 'gnus-sticky-article-mode)))
4789 (switch-to-buffer new-art-buf-name)
4790 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4791 (gnus-sticky-article-mode))
4792 (setq gnus-article-buffer new-art-buf-name))
4793 (gnus-summary-recenter)
4794 (gnus-summary-position-point))
4796 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4797 "Kill the given sticky article BUFFER.
4798 If none is given, assume the current buffer and kill it if it has
4799 `gnus-sticky-article-mode'."
4800 (interactive)
4801 (unless buffer
4802 (setq buffer (current-buffer)))
4803 (with-current-buffer buffer
4804 (when (eq major-mode 'gnus-sticky-article-mode)
4805 (gnus-kill-buffer buffer))))
4807 (defun gnus-kill-sticky-article-buffers (arg)
4808 "Kill all sticky article buffers.
4809 If a prefix ARG is given, ask for confirmation."
4810 (interactive "P")
4811 (dolist (buf (gnus-buffers))
4812 (with-current-buffer buf
4813 (when (eq major-mode 'gnus-sticky-article-mode)
4814 (if (not arg)
4815 (gnus-kill-buffer buf)
4816 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4817 (gnus-kill-buffer buf)))))))
4820 ;;; Gnus MIME viewing functions
4823 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4824 "Format of the MIME buttons.
4826 Valid specifiers include:
4827 %t The MIME type
4828 %T MIME type, along with additional info
4829 %n The `name' parameter
4830 %d The description, if any
4831 %l The length of the encoded part
4832 %p The part identifier number
4833 %e Dots if the part isn't displayed
4835 General format specifiers can also be used. See Info node
4836 `(gnus)Formatting Variables'.")
4838 (defvar gnus-mime-button-line-format-alist
4839 '((?t gnus-tmp-type ?s)
4840 (?T gnus-tmp-type-long ?s)
4841 (?n gnus-tmp-name ?s)
4842 (?d gnus-tmp-description ?s)
4843 (?p gnus-tmp-id ?s)
4844 (?l gnus-tmp-length ?d)
4845 (?e gnus-tmp-dots ?s)))
4847 (defvar gnus-mime-button-commands
4848 '((gnus-article-press-button "\r" "Toggle Display")
4849 (gnus-mime-view-part "v" "View Interactively...")
4850 (gnus-mime-view-part-as-type "t" "View As Type...")
4851 (gnus-mime-view-part-as-charset "C" "View As charset...")
4852 (gnus-mime-save-part "o" "Save...")
4853 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4854 (gnus-mime-replace-part "r" "Replace part")
4855 (gnus-mime-delete-part "d" "Delete part")
4856 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4857 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4858 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4859 (gnus-mime-view-part-externally "e" "View Externally")
4860 (gnus-mime-print-part "p" "Print")
4861 (gnus-mime-pipe-part "|" "Pipe To Command...")
4862 (gnus-mime-action-on-part "." "Take action on the part...")))
4864 (defun gnus-article-mime-part-status ()
4865 (if gnus-article-mime-handle-alist-1
4866 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4867 " (1 part)"
4868 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4869 ""))
4871 (defvar gnus-mime-button-map
4872 (let ((map (make-sparse-keymap)))
4873 (define-key map gnus-mouse-2 'gnus-article-push-button)
4874 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4875 (dolist (c gnus-mime-button-commands)
4876 (define-key map (cadr c) (car c)))
4877 map))
4879 (easy-menu-define
4880 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4881 `("MIME Part"
4882 ,@(mapcar (lambda (c)
4883 (vector (caddr c) (car c) :active t))
4884 gnus-mime-button-commands)))
4886 (defvar gnus-url-button-commands
4887 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4889 (defvar gnus-url-button-map
4890 (let ((map (make-sparse-keymap)))
4891 (dolist (c gnus-url-button-commands)
4892 (define-key map (cadr c) (car c)))
4893 map))
4895 (easy-menu-define
4896 gnus-url-button-menu gnus-url-button-map "URL button menu."
4897 `("Url Button"
4898 ,@(mapcar (lambda (c)
4899 (vector (caddr c) (car c) :active t))
4900 gnus-url-button-commands)))
4902 (defmacro gnus-bind-safe-url-regexp (&rest body)
4903 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4904 `(let ((mm-w3m-safe-url-regexp
4905 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4906 (gnus-buffer-live-p
4907 gnus-article-current-summary))
4908 (with-current-buffer gnus-article-current-summary
4909 gnus-newsgroup-name)
4910 gnus-newsgroup-name)))
4911 (if (cond ((not group)
4912 ;; Maybe we're in a mml-preview buffer
4913 ;; and no group is selected.
4915 ((stringp gnus-safe-html-newsgroups)
4916 (string-match gnus-safe-html-newsgroups group))
4917 ((consp gnus-safe-html-newsgroups)
4918 (member group gnus-safe-html-newsgroups)))
4920 mm-w3m-safe-url-regexp))))
4921 ,@body))
4923 (defun gnus-mime-button-menu (event prefix)
4924 "Construct a context-sensitive menu of MIME commands."
4925 (interactive "e\nP")
4926 (save-window-excursion
4927 (let ((pos (event-start event)))
4928 (select-window (posn-window pos))
4929 (goto-char (posn-point pos))
4930 (gnus-article-check-buffer)
4931 (popup-menu gnus-mime-button-menu nil prefix))))
4933 (defun gnus-mime-view-all-parts (&optional handles)
4934 "View all the MIME parts."
4935 (interactive)
4936 (with-current-buffer gnus-article-buffer
4937 (let ((handles (or handles gnus-article-mime-handles))
4938 (mail-parse-charset gnus-newsgroup-charset)
4939 (mail-parse-ignored-charsets
4940 (with-current-buffer gnus-summary-buffer
4941 gnus-newsgroup-ignored-charsets)))
4942 (when handles
4943 (mm-remove-parts handles)
4944 (goto-char (point-min))
4945 (or (search-forward "\n\n") (goto-char (point-max)))
4946 (let ((inhibit-read-only t))
4947 (delete-region (point) (point-max))
4948 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4950 (defun gnus-article-jump-to-part (n)
4951 "Jump to MIME part N."
4952 (interactive "P")
4953 (let ((parts (with-current-buffer gnus-article-buffer
4954 (length gnus-article-mime-handle-alist))))
4955 (when (zerop parts)
4956 (error "No such part"))
4957 (pop-to-buffer gnus-article-buffer)
4958 (or n
4959 (setq n (if (= parts 1)
4961 (read-number (format "Jump to part (1..%s): " parts)))))
4962 (unless (and (integerp n) (<= n parts) (>= n 1))
4963 (setq n
4964 (progn
4965 (gnus-message 7 "Invalid part `%s', using %s instead."
4966 n parts)
4967 parts)))
4968 (gnus-message 9 "Jumping to part %s." n)
4969 (cond ((>= gnus-auto-select-part 1)
4970 (while (and (<= n parts)
4971 (not (gnus-article-goto-part n)))
4972 (setq n (1+ n))))
4973 ((< gnus-auto-select-part 0)
4974 (while (and (>= n 1)
4975 (not (gnus-article-goto-part n)))
4976 (setq n (1- n))))
4978 (gnus-article-goto-part n)))))
4980 (defvar gnus-mime-buttonized-part-id nil
4981 "ID of a mime part that should be buttonized.
4982 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4984 (eval-when-compile
4985 (defsubst gnus-article-edit-part (handles &optional current-id)
4986 "Edit an article in order to delete a mime part.
4987 This function is exclusively used by `gnus-mime-save-part-and-strip'
4988 and `gnus-mime-delete-part', and not provided at run-time normally."
4989 (gnus-article-edit-article
4990 `(lambda ()
4991 (buffer-disable-undo)
4992 (erase-buffer)
4993 (let ((mail-parse-charset (or gnus-article-charset
4994 ',gnus-newsgroup-charset))
4995 (mail-parse-ignored-charsets
4996 (or gnus-article-ignored-charsets
4997 ',gnus-newsgroup-ignored-charsets))
4998 (mbl mml-buffer-list))
4999 (setq mml-buffer-list nil)
5000 (insert-buffer-substring gnus-original-article-buffer)
5001 (mime-to-mml ',handles)
5002 (setq gnus-article-mime-handles nil)
5003 (let ((mbl1 mml-buffer-list))
5004 (setq mml-buffer-list mbl)
5005 (set (make-local-variable 'mml-buffer-list) mbl1))
5006 (gnus-make-local-hook 'kill-buffer-hook)
5007 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5008 `(lambda (no-highlight)
5009 (let ((mail-parse-charset (or gnus-article-charset
5010 ',gnus-newsgroup-charset))
5011 (message-options message-options)
5012 (message-options-set-recipient)
5013 (mail-parse-ignored-charsets
5014 (or gnus-article-ignored-charsets
5015 ',gnus-newsgroup-ignored-charsets)))
5016 (mml-to-mime)
5017 (mml-destroy-buffers)
5018 (remove-hook 'kill-buffer-hook
5019 'mml-destroy-buffers t)
5020 (kill-local-variable 'mml-buffer-list))
5021 (gnus-summary-edit-article-done
5022 ,(or (mail-header-references gnus-current-headers) "")
5023 ,(gnus-group-read-only-p)
5024 ,gnus-summary-buffer no-highlight))
5026 ;; Force buttonizing this part.
5027 (let ((gnus-mime-buttonized-part-id current-id))
5028 (gnus-article-edit-done))
5029 (gnus-configure-windows 'article)
5030 (when (and current-id (integerp gnus-auto-select-part))
5031 (gnus-article-jump-to-part
5032 (min (max (+ current-id gnus-auto-select-part) 1)
5033 (with-current-buffer gnus-article-buffer
5034 (length gnus-article-mime-handle-alist)))))))
5036 (defun gnus-mime-replace-part (file)
5037 "Replace MIME part under point with an external body."
5038 ;; Useful if file has already been saved to disk
5039 (interactive
5040 (list
5041 (read-file-name "Replace MIME part with file: "
5042 (or mm-default-directory default-directory)
5043 nil nil)))
5044 (gnus-mime-save-part-and-strip file))
5046 (defun gnus-mime-save-part-and-strip (&optional file)
5047 "Save the MIME part under point then replace it with an external body.
5048 If FILE is given, use it for the external part."
5049 (interactive)
5050 (gnus-article-check-buffer)
5051 (when (gnus-group-read-only-p)
5052 (error "The current group does not support deleting of parts"))
5053 (when (mm-complicated-handles gnus-article-mime-handles)
5054 (error "\
5055 The current article has a complicated MIME structure, giving up..."))
5056 (let* ((data (get-text-property (point) 'gnus-data))
5057 (id (get-text-property (point) 'gnus-part))
5058 param
5059 (handles gnus-article-mime-handles))
5060 (unless file
5061 (setq file
5062 (and data (mm-save-part data "Delete MIME part and save to: "))))
5063 (when file
5064 (with-current-buffer (mm-handle-buffer data)
5065 (erase-buffer)
5066 (insert "Content-Type: " (mm-handle-media-type data))
5067 (mml-insert-parameter-string (cdr (mm-handle-type data))
5068 '(charset))
5069 ;; Add a filename for the sake of saving the part again.
5070 (mml-insert-parameter
5071 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5072 (insert "\n")
5073 (insert "Content-ID: " (message-make-message-id) "\n")
5074 (insert "Content-Transfer-Encoding: binary\n")
5075 (insert "\n"))
5076 (setcdr data
5077 (cdr (mm-make-handle nil
5078 `("message/external-body"
5079 (access-type . "LOCAL-FILE")
5080 (name . ,file)))))
5081 ;; (set-buffer gnus-summary-buffer)
5082 (gnus-article-edit-part handles id))))
5084 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5085 ;; parts...>') but with stripping would be nice.
5087 (defun gnus-mime-delete-part ()
5088 "Delete the MIME part under point.
5089 Replace it with some information about the removed part."
5090 (interactive)
5091 (gnus-article-check-buffer)
5092 (when (gnus-group-read-only-p)
5093 (error "The current group does not support deleting of parts"))
5094 (when (mm-complicated-handles gnus-article-mime-handles)
5095 (error "\
5096 The current article has a complicated MIME structure, giving up..."))
5097 (when (or gnus-expert-user
5098 (gnus-yes-or-no-p "\
5099 Deleting parts may malfunction or destroy the article; continue? "))
5100 (let* ((data (get-text-property (point) 'gnus-data))
5101 (id (get-text-property (point) 'gnus-part))
5102 (handles gnus-article-mime-handles)
5103 (description
5104 (let ((desc (mm-handle-description data)))
5105 (when desc
5106 (mail-decode-encoded-word-string desc))))
5107 (filename (or (mm-handle-filename data) "(none)"))
5108 (type (mm-handle-media-type data)))
5109 (unless data
5110 (error "No MIME part under point"))
5111 (with-current-buffer (mm-handle-buffer data)
5112 (let ((bsize (buffer-size)))
5113 (erase-buffer)
5114 (insert
5115 (concat
5116 ",----\n"
5117 "| The following attachment has been deleted:\n"
5118 "|\n"
5119 "| Type: " type "\n"
5120 "| Filename: " filename "\n"
5121 "| Size (encoded): " (format "%s byte%s\n"
5122 bsize (if (= bsize 1)
5124 "s"))
5125 (when description
5126 (concat "| Description: " description "\n"))
5127 "`----\n"))
5128 (setcdr data
5129 (cdr (mm-make-handle
5130 nil `("text/plain" (charset . gnus-decoded)) nil nil
5131 (list "attachment")
5132 (format "Deleted attachment (%s bytes)" bsize))))))
5133 ;; (set-buffer gnus-summary-buffer)
5134 (gnus-article-edit-part handles id))))
5136 (defun gnus-mime-save-part ()
5137 "Save the MIME part under point."
5138 (interactive)
5139 (gnus-article-check-buffer)
5140 (let ((data (get-text-property (point) 'gnus-data)))
5141 (when data
5142 (mm-save-part data))))
5144 (defun gnus-mime-pipe-part (&optional cmd)
5145 "Pipe the MIME part under point to a process.
5146 Use CMD as the process."
5147 (interactive)
5148 (gnus-article-check-buffer)
5149 (let ((data (get-text-property (point) 'gnus-data)))
5150 (when data
5151 (mm-pipe-part data cmd))))
5153 (defun gnus-mime-view-part ()
5154 "Interactively choose a viewing method for the MIME part under point."
5155 (interactive)
5156 (gnus-article-check-buffer)
5157 (let ((data (get-text-property (point) 'gnus-data)))
5158 (when data
5159 (setq gnus-article-mime-handles
5160 (mm-merge-handles
5161 gnus-article-mime-handles (setq data (copy-sequence data))))
5162 (mm-interactively-view-part data))))
5164 (defun gnus-mime-view-part-as-type-internal ()
5165 (gnus-article-check-buffer)
5166 (let* ((handle (get-text-property (point) 'gnus-data))
5167 (name (or
5168 ;; Content-Type: foo/bar; name=...
5169 (mail-content-type-get (mm-handle-type handle) 'name)
5170 ;; Content-Disposition: attachment; filename=...
5171 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5172 (def-type (and name (mm-default-file-encoding name))))
5173 (or (and def-type (cons def-type 0))
5174 (and handle
5175 (equal (mm-handle-media-supertype handle) "text")
5176 '("text/plain" . 0))
5177 '("application/octet-stream" . 0))))
5179 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5180 "Choose a MIME media type, and view the part as such.
5181 If non-nil, PRED is a predicate to use during completion to limit the
5182 available media-types."
5183 (interactive)
5184 (unless mime-type
5185 (setq mime-type
5186 (let ((default (gnus-mime-view-part-as-type-internal)))
5187 (gnus-completing-read
5188 "View as MIME type"
5189 (if pred
5190 (gnus-remove-if-not pred (mailcap-mime-types))
5191 (mailcap-mime-types))
5192 nil nil nil
5193 (car default)))))
5194 (gnus-article-check-buffer)
5195 (let ((handle (get-text-property (point) 'gnus-data)))
5196 (when handle
5197 (when (equal (mm-handle-media-type handle) "message/external-body")
5198 (unless (mm-handle-cache handle)
5199 (mm-extern-cache-contents handle))
5200 (setq handle (mm-handle-cache handle)))
5201 (setq handle
5202 (mm-make-handle (mm-handle-buffer handle)
5203 (cons mime-type (cdr (mm-handle-type handle)))
5204 (mm-handle-encoding handle)
5205 (mm-handle-undisplayer handle)
5206 (mm-handle-disposition handle)
5207 (mm-handle-description handle)
5209 (mm-handle-id handle)))
5210 (setq gnus-article-mime-handles
5211 (mm-merge-handles gnus-article-mime-handles handle))
5212 (when (mm-handle-displayed-p handle)
5213 (mm-remove-part handle))
5214 (gnus-mm-display-part handle))))
5216 (defun gnus-mime-copy-part (&optional handle arg)
5217 "Put the MIME part under point into a new buffer.
5218 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5219 are decompressed."
5220 (interactive (list nil current-prefix-arg))
5221 (gnus-article-check-buffer)
5222 (unless handle
5223 (setq handle (get-text-property (point) 'gnus-data)))
5224 (when handle
5225 (let ((filename (mm-handle-filename handle))
5226 contents dont-decode charset coding-system)
5227 (mm-with-unibyte-buffer
5228 (mm-insert-part handle)
5229 (setq contents (or (condition-case nil
5230 (mm-decompress-buffer filename nil 'sig)
5231 (error
5232 (setq dont-decode t)
5233 nil))
5234 (buffer-string))))
5235 (setq filename (cond (filename (file-name-nondirectory filename))
5236 (dont-decode "*raw data*")
5237 (t "*decoded*")))
5238 (cond
5239 (dont-decode)
5240 ((not arg)
5241 (unless (setq charset (mail-content-type-get
5242 (mm-handle-type handle) 'charset))
5243 (unless (setq coding-system (mm-with-unibyte-buffer
5244 (insert contents)
5245 (mm-find-buffer-file-coding-system)))
5246 (setq charset gnus-newsgroup-charset))))
5247 ((numberp arg)
5248 (setq charset (or (cdr (assq arg
5249 gnus-summary-show-article-charset-alist))
5250 (mm-read-coding-system "Charset: ")))))
5251 (switch-to-buffer (generate-new-buffer filename))
5252 (if (or coding-system
5253 (and charset
5254 (setq coding-system (mm-charset-to-coding-system charset))
5255 (not (eq coding-system 'ascii))))
5256 (progn
5257 (mm-enable-multibyte)
5258 (insert (mm-decode-coding-string contents coding-system))
5259 (setq buffer-file-coding-system
5260 (if (boundp 'last-coding-system-used)
5261 (symbol-value 'last-coding-system-used)
5262 coding-system)))
5263 (mm-disable-multibyte)
5264 (insert contents)
5265 (setq buffer-file-coding-system mm-binary-coding-system))
5266 ;; We do it this way to make `normal-mode' set the appropriate mode.
5267 (unwind-protect
5268 (progn
5269 (setq buffer-file-name (expand-file-name filename))
5270 (normal-mode))
5271 (setq buffer-file-name nil))
5272 (goto-char (point-min)))))
5274 (defun gnus-mime-print-part (&optional handle filename)
5275 "Print the MIME part under point."
5276 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5277 (gnus-article-check-buffer)
5278 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5279 (contents (and handle (mm-get-part handle)))
5280 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5281 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5282 (when contents
5283 (if printer
5284 (unwind-protect
5285 (progn
5286 (mm-save-part-to-file handle file)
5287 (call-process shell-file-name nil
5288 (generate-new-buffer " *mm*")
5290 shell-command-switch
5291 (mm-mailcap-command
5292 printer file (mm-handle-type handle))))
5293 (delete-file file))
5294 (with-temp-buffer
5295 (insert contents)
5296 (gnus-print-buffer))
5297 (ps-despool filename)))))
5299 (defun gnus-mime-inline-part (&optional handle arg)
5300 "Insert the MIME part under point into the current buffer.
5301 Compressed files like .gz and .bz2 are decompressed."
5302 (interactive (list nil current-prefix-arg))
5303 (gnus-article-check-buffer)
5304 (unless handle
5305 (setq handle (get-text-property (point) 'gnus-data)))
5306 (when handle
5307 (let ((b (point))
5308 (inhibit-read-only t)
5309 contents charset coding-system)
5310 (if (and (not arg) (mm-handle-undisplayer handle))
5311 (mm-remove-part handle)
5312 (mm-with-unibyte-buffer
5313 (mm-insert-part handle)
5314 (setq contents
5315 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5316 (buffer-string))))
5317 (cond
5318 ((not arg)
5319 (unless (setq charset (mail-content-type-get
5320 (mm-handle-type handle) 'charset))
5321 (unless (setq coding-system
5322 (mm-with-unibyte-buffer
5323 (insert contents)
5324 (mm-find-buffer-file-coding-system)))
5325 (setq charset gnus-newsgroup-charset))))
5326 ((numberp arg)
5327 (if (mm-handle-undisplayer handle)
5328 (mm-remove-part handle))
5329 (setq charset
5330 (or (cdr (assq arg
5331 gnus-summary-show-article-charset-alist))
5332 (mm-read-coding-system "Charset: "))))
5333 ((mm-handle-undisplayer handle)
5334 (mm-remove-part handle)))
5335 (forward-line 2)
5336 (mm-display-inline handle)
5337 (goto-char b)))))
5339 (defun gnus-mime-set-charset-parameters (handle charset)
5340 "Set CHARSET to parameters in HANDLE.
5341 CHARSET may either be a string or a symbol."
5342 (unless (stringp charset)
5343 (setq charset (symbol-name charset)))
5344 (if (stringp (car handle))
5345 (dolist (h (cdr handle))
5346 (gnus-mime-set-charset-parameters h charset))
5347 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5348 "message/external-body")
5349 (progn
5350 (unless (mm-handle-cache handle)
5351 (mm-extern-cache-contents handle))
5352 (mm-handle-cache handle))
5353 handle)))
5354 (param (assq 'charset (cdr type))))
5355 (if param
5356 (setcdr param charset)
5357 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5359 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5360 "Insert the MIME part under point into the current buffer using the
5361 specified charset."
5362 (interactive (list nil current-prefix-arg))
5363 (gnus-article-check-buffer)
5364 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5365 (fun (get-text-property (point) 'gnus-callback))
5366 (gnus-newsgroup-ignored-charsets 'gnus-all)
5367 charset form preferred parts)
5368 (when handle
5369 (when (prog1
5370 (and fun
5371 (setq charset
5372 (or (cdr (assq
5374 gnus-summary-show-article-charset-alist))
5375 (mm-read-coding-system "Charset: "))))
5376 (if (mm-handle-undisplayer handle)
5377 (mm-remove-part handle)))
5378 (gnus-mime-set-charset-parameters handle charset)
5379 (when (and (consp (setq form (cdr-safe fun)))
5380 (setq form (ignore-errors
5381 (assq 'gnus-mime-display-alternative form)))
5382 (setq preferred (caddr form))
5383 (progn
5384 (when (eq (car preferred) 'quote)
5385 (setq preferred (cadr preferred)))
5386 (not (equal preferred
5387 (get-text-property (point) 'gnus-data))))
5388 (setq parts (get-text-property (point) 'gnus-part))
5389 (setq parts (cdr (assq parts
5390 gnus-article-mime-handle-alist)))
5391 (equal (mm-handle-media-type parts) "multipart/alternative")
5392 (setq parts (reverse (cdr parts))))
5393 (setcar (cddr form)
5394 (list 'quote (or (cadr (member preferred parts))
5395 (car parts)))))
5396 (funcall fun handle)))))
5398 (defun gnus-mime-view-part-externally (&optional handle)
5399 "View the MIME part under point with an external viewer."
5400 (interactive)
5401 (gnus-article-check-buffer)
5402 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5403 (mm-user-display-methods nil)
5404 (mm-inlined-types nil)
5405 (mail-parse-charset gnus-newsgroup-charset)
5406 (mail-parse-ignored-charsets
5407 (with-current-buffer gnus-summary-buffer
5408 gnus-newsgroup-ignored-charsets))
5409 (type (mm-handle-media-type handle))
5410 (method (mailcap-mime-info type))
5411 (mm-enable-external t))
5412 (if (not (stringp method))
5413 (gnus-mime-view-part-as-type
5414 nil (lambda (type) (stringp (mailcap-mime-info type))))
5415 (when handle
5416 (mm-display-part handle nil t)))))
5418 (defun gnus-mime-view-part-internally (&optional handle)
5419 "View the MIME part under point with an internal viewer.
5420 If no internal viewer is available, use an external viewer."
5421 (interactive)
5422 (gnus-article-check-buffer)
5423 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5424 (mm-inlined-types '(".*"))
5425 (mm-inline-large-images t)
5426 (mail-parse-charset gnus-newsgroup-charset)
5427 (mail-parse-ignored-charsets
5428 (with-current-buffer gnus-summary-buffer
5429 gnus-newsgroup-ignored-charsets))
5430 (inhibit-read-only t))
5431 (if (not (mm-inlinable-p handle))
5432 (gnus-mime-view-part-as-type
5433 nil (lambda (type) (mm-inlinable-p handle type)))
5434 (when handle
5435 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5437 (defun gnus-mime-action-on-part (&optional action)
5438 "Do something with the MIME attachment at \(point\)."
5439 (interactive
5440 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5441 (gnus-article-check-buffer)
5442 (let ((action-pair (assoc action gnus-mime-action-alist)))
5443 (if action-pair
5444 (funcall (cdr action-pair)))))
5446 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5447 "Call FUNCTION on MIME part N.
5448 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5449 If INTERACTIVE, call FUNCTION interactively."
5450 (let (window frame)
5451 ;; Check whether the article is displayed.
5452 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5453 (setq window (get-buffer-window gnus-article-buffer t))
5454 (frame-visible-p (setq frame (window-frame window))))
5455 (error "No article is displayed"))
5456 (with-current-buffer gnus-article-buffer
5457 ;; Check whether the article displays the right contents.
5458 (unless (with-current-buffer gnus-summary-buffer
5459 (eq gnus-current-article (gnus-summary-article-number)))
5460 (error "You should select the right article first"))
5461 (if n
5462 (setq n (prefix-numeric-value n))
5463 (let ((pt (point)))
5464 (setq n (or (get-text-property pt 'gnus-part)
5465 (and (not (bobp))
5466 (get-text-property (1- pt) 'gnus-part))
5467 (get-text-property (prog2
5468 (forward-line 1)
5469 (point)
5470 (goto-char pt))
5471 'gnus-part)
5472 (get-text-property
5473 (or (and (setq pt (previous-single-property-change
5474 pt 'gnus-part))
5475 (1- pt))
5476 (next-single-property-change (point) 'gnus-part)
5477 (point))
5478 'gnus-part)
5479 1))))
5480 ;; Check whether the specified part exists.
5481 (when (> n (length gnus-article-mime-handle-alist))
5482 (error "No such part")))
5483 (unless
5484 (progn
5485 ;; To select the window is needed so that the cursor
5486 ;; might be visible on the MIME button.
5487 (select-window (prog1
5488 window
5489 (setq window (selected-window))
5490 ;; Article may be displayed in the other frame.
5491 (gnus-select-frame-set-input-focus
5492 (prog1
5493 frame
5494 (setq frame (selected-frame))))))
5495 (when (gnus-article-goto-part n)
5496 ;; We point the cursor and the arrow at the MIME button
5497 ;; when the `function' prompt the user for something.
5498 (unless (and (pos-visible-in-window-p)
5499 (> (count-lines (point) (window-end))
5500 (/ (1- (window-height)) 3)))
5501 (recenter (/ (1- (window-height)) 3)))
5502 (let ((cursor-in-non-selected-windows t)
5503 (overlay-arrow-string "=>")
5504 (overlay-arrow-position (point-marker)))
5505 (unwind-protect
5506 (cond
5507 ((and no-handle interactive)
5508 (call-interactively function))
5509 (no-handle
5510 (funcall function))
5511 (interactive
5512 (call-interactively
5513 function (get-text-property (point) 'gnus-data)))
5515 (funcall function
5516 (get-text-property (point) 'gnus-data))))
5517 (set-marker overlay-arrow-position nil)
5518 (unless gnus-auto-select-part
5519 (gnus-select-frame-set-input-focus frame)
5520 (select-window window))))
5522 (if gnus-inhibit-mime-unbuttonizing
5523 ;; This is the default though the program shouldn't reach here.
5524 (error "No such part")
5525 ;; The part which doesn't have the MIME button is selected.
5526 ;; So, we display all the buttons and redo it.
5527 (let ((gnus-inhibit-mime-unbuttonizing t))
5528 (gnus-summary-show-article)
5529 (gnus-article-part-wrapper n function no-handle))))))
5531 (defun gnus-article-pipe-part (n)
5532 "Pipe MIME part N, which is the numerical prefix."
5533 (interactive "P")
5534 (gnus-article-part-wrapper n 'mm-pipe-part))
5536 (defun gnus-article-save-part (n)
5537 "Save MIME part N, which is the numerical prefix."
5538 (interactive "P")
5539 (gnus-article-part-wrapper n 'mm-save-part))
5541 (defun gnus-article-interactively-view-part (n)
5542 "View MIME part N interactively, which is the numerical prefix."
5543 (interactive "P")
5544 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5546 (defun gnus-article-copy-part (n)
5547 "Copy MIME part N, which is the numerical prefix."
5548 (interactive "P")
5549 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5551 (defun gnus-article-view-part-as-charset (n)
5552 "View MIME part N using a specified charset.
5553 N is the numerical prefix."
5554 (interactive "P")
5555 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5557 (defun gnus-article-view-part-externally (n)
5558 "View MIME part N externally, which is the numerical prefix."
5559 (interactive "P")
5560 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5562 (defun gnus-article-inline-part (n)
5563 "Inline MIME part N, which is the numerical prefix."
5564 (interactive "P")
5565 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5567 (defun gnus-article-save-part-and-strip (n)
5568 "Save MIME part N and replace it with an external body.
5569 N is the numerical prefix."
5570 (interactive "P")
5571 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5573 (defun gnus-article-replace-part (n)
5574 "Replace MIME part N with an external body.
5575 N is the numerical prefix."
5576 (interactive "P")
5577 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5579 (defun gnus-article-delete-part (n)
5580 "Delete MIME part N and add some information about the removed part.
5581 N is the numerical prefix."
5582 (interactive "P")
5583 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5585 (defun gnus-article-view-part-as-type (n)
5586 "Choose a MIME media type, and view part N as such.
5587 N is the numerical prefix."
5588 (interactive "P")
5589 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5591 (defun gnus-article-mime-match-handle-first (condition)
5592 (if condition
5593 (let (n)
5594 (dolist (ihandle gnus-article-mime-handle-alist)
5595 (if (and (cond
5596 ((functionp condition)
5597 (funcall condition (cdr ihandle)))
5598 ((eq condition 'undisplayed)
5599 (not (or (mm-handle-undisplayer (cdr ihandle))
5600 (equal (mm-handle-media-type (cdr ihandle))
5601 "multipart/alternative"))))
5602 ((eq condition 'undisplayed-alternative)
5603 (not (mm-handle-undisplayer (cdr ihandle))))
5604 (t t))
5605 (gnus-article-goto-part (car ihandle))
5606 (or (not n) (< (car ihandle) n)))
5607 (setq n (car ihandle))))
5608 (or n 1))
5611 (defun gnus-article-view-part (&optional n)
5612 "View MIME part N, which is the numerical prefix.
5613 If the part is already shown, hide the part. If N is nil, view
5614 all parts."
5615 (interactive "P")
5616 (with-current-buffer gnus-article-buffer
5617 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5618 gnus-article-mime-match-handle-function)))
5619 (when (> n (length gnus-article-mime-handle-alist))
5620 (error "No such part"))
5621 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5622 (when (gnus-article-goto-part n)
5623 (if (equal (car handle) "multipart/alternative")
5624 (gnus-article-press-button)
5625 (when (eq (gnus-mm-display-part handle) 'internal)
5626 (gnus-set-window-start)))))))
5628 (defsubst gnus-article-mime-total-parts ()
5629 (if (bufferp (car gnus-article-mime-handles))
5630 1 ;; single part
5631 (1- (length gnus-article-mime-handles))))
5633 (defun gnus-mm-display-part (handle)
5634 "Display HANDLE and fix MIME button."
5635 (let ((id (get-text-property (point) 'gnus-part))
5636 (point (point))
5637 (inhibit-read-only t))
5638 (forward-line 1)
5639 (prog1
5640 (let ((window (selected-window))
5641 (mail-parse-charset gnus-newsgroup-charset)
5642 (mail-parse-ignored-charsets
5643 (if (gnus-buffer-live-p gnus-summary-buffer)
5644 (with-current-buffer gnus-summary-buffer
5645 gnus-newsgroup-ignored-charsets)
5646 nil)))
5647 (save-excursion
5648 (unwind-protect
5649 (let ((win (gnus-get-buffer-window (current-buffer) t))
5650 (beg (point)))
5651 (when win
5652 (select-window win))
5653 (goto-char point)
5654 (forward-line)
5655 (if (mm-handle-displayed-p handle)
5656 ;; This will remove the part.
5657 (mm-display-part handle)
5658 (save-restriction
5659 (narrow-to-region (point)
5660 (if (eobp) (point) (1+ (point))))
5661 (gnus-bind-safe-url-regexp (mm-display-part handle))
5662 ;; We narrow to the part itself and
5663 ;; then call the treatment functions.
5664 (goto-char (point-min))
5665 (forward-line 1)
5666 (narrow-to-region (point) (point-max))
5667 (gnus-treat-article
5668 nil id
5669 (gnus-article-mime-total-parts)
5670 (mm-handle-media-type handle)))))
5671 (if (window-live-p window)
5672 (select-window window)))))
5673 (goto-char point)
5674 (gnus-delete-line)
5675 (gnus-insert-mime-button
5676 handle id (list (mm-handle-displayed-p handle)))
5677 (goto-char point))))
5679 (defun gnus-article-goto-part (n)
5680 "Go to MIME part N."
5681 (when gnus-break-pages
5682 (widen))
5683 (prog1
5684 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5685 part handle end next handles)
5686 (when start
5687 (goto-char start)
5688 (if (setq handle (get-text-property start 'gnus-data))
5689 start
5690 ;; Go to the displayed subpart, assuming this is
5691 ;; multipart/alternative.
5692 (setq part start
5693 end (point-at-eol))
5694 (while (and (not handle)
5695 part
5696 (< part end)
5697 (setq next (text-property-not-all part end
5698 'gnus-data nil)))
5699 (setq part next
5700 handle (get-text-property part 'gnus-data))
5701 (push (cons handle part) handles)
5702 (unless (mm-handle-displayed-p handle)
5703 (setq handle nil
5704 part (text-property-any part end 'gnus-data nil))))
5705 (unless handle
5706 ;; No subpart is displayed, so we find preferred one.
5707 (setq part
5708 (cdr (assq (mm-preferred-alternative
5709 (nreverse (mapcar 'car handles)))
5710 handles))))
5711 (if part
5712 (goto-char (1+ part))
5713 start))))
5714 (when gnus-break-pages
5715 (gnus-narrow-to-page))))
5717 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5718 (let ((gnus-tmp-name
5719 (or (mm-handle-filename handle)
5720 (mail-content-type-get (mm-handle-type handle) 'url)
5721 ""))
5722 (gnus-tmp-type (mm-handle-media-type handle))
5723 (gnus-tmp-description (or (mm-handle-description handle) ""))
5724 (gnus-tmp-dots
5725 (if (if displayed (car displayed)
5726 (mm-handle-displayed-p handle))
5727 "" "..."))
5728 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5729 (buffer-size)))
5730 gnus-tmp-type-long b e)
5731 (when (string-match ".*/" gnus-tmp-name)
5732 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5733 (setq gnus-tmp-type-long (concat gnus-tmp-type
5734 (and (not (equal gnus-tmp-name ""))
5735 (concat "; " gnus-tmp-name))))
5736 (unless (equal gnus-tmp-description "")
5737 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5738 (unless (bolp)
5739 (insert "\n"))
5740 (setq b (point))
5741 (gnus-eval-format
5742 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5743 `(keymap ,gnus-mime-button-map
5744 gnus-callback gnus-mm-display-part
5745 gnus-part ,gnus-tmp-id
5746 article-type annotation
5747 gnus-data ,handle
5748 rear-nonsticky t))
5749 (setq e (if (bolp)
5750 ;; Exclude a newline.
5751 (1- (point))
5752 (point)))
5753 (when gnus-article-button-face
5754 (gnus-overlay-put (gnus-make-overlay b e nil t)
5755 'face gnus-article-button-face))
5756 (widget-convert-button
5757 'link b e
5758 :mime-handle handle
5759 :action 'gnus-widget-press-button
5760 :button-keymap gnus-mime-button-map
5761 :help-echo
5762 (lambda (widget)
5763 ;; Needed to properly clear the message due to a bug in
5764 ;; wid-edit (XEmacs only).
5765 (if (boundp 'help-echo-owns-message)
5766 (setq help-echo-owns-message t))
5767 (format
5768 "%S: %s the MIME part; %S: more options"
5769 (aref gnus-mouse-2 0)
5770 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5771 "hide" "show")
5772 (aref gnus-down-mouse-3 0))))))
5774 (defun gnus-widget-press-button (elems el)
5775 (goto-char (widget-get elems :from))
5776 (gnus-article-press-button))
5778 (defvar gnus-displaying-mime nil)
5780 (defun gnus-display-mime (&optional ihandles)
5781 "Display the MIME parts."
5782 (save-excursion
5783 (save-selected-window
5784 (let ((window (get-buffer-window gnus-article-buffer))
5785 (point (point)))
5786 (when window
5787 (select-window window)
5788 ;; We have to do this since selecting the window
5789 ;; may change the point. So we set the window point.
5790 (set-window-point window point)))
5791 (let ((handles ihandles)
5792 (inhibit-read-only t)
5793 handle)
5794 (cond (handles)
5795 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5796 (when gnus-article-emulate-mime
5797 (mm-uu-dissect-text-parts handles)))
5798 (gnus-article-emulate-mime
5799 (setq handles (mm-uu-dissect))))
5800 (when (and (not ihandles)
5801 (not gnus-displaying-mime))
5802 ;; Top-level call; we clean up.
5803 (when gnus-article-mime-handles
5804 (mm-destroy-parts gnus-article-mime-handles)
5805 (setq gnus-article-mime-handle-alist nil));; A trick.
5806 (setq gnus-article-mime-handles handles)
5807 ;; We allow users to glean info from the handles.
5808 (when gnus-article-mime-part-function
5809 (gnus-mime-part-function handles)))
5810 (if (and handles
5811 (or (not (stringp (car handles)))
5812 (cdr handles)))
5813 (progn
5814 (when (and (not ihandles)
5815 (not gnus-displaying-mime))
5816 ;; Clean up for mime parts.
5817 (article-goto-body)
5818 (delete-region (point) (point-max)))
5819 (let ((gnus-displaying-mime t))
5820 (gnus-mime-display-part handles)))
5821 (save-restriction
5822 (article-goto-body)
5823 (narrow-to-region (point) (point-max))
5824 (gnus-treat-article nil 1 1 "text/plain")
5825 (widen)))
5826 (unless ihandles
5827 ;; Highlight the headers.
5828 (save-excursion
5829 (save-restriction
5830 (article-goto-body)
5831 (narrow-to-region (point-min) (point))
5832 (gnus-article-save-original-date
5833 (gnus-treat-article 'head)))))))
5834 ;; Cope with broken MIME messages.
5835 (goto-char (point-max))
5836 (unless (bolp)
5837 (insert "\n"))))
5839 (defcustom gnus-mime-display-multipart-as-mixed nil
5840 "Display \"multipart\" parts as \"multipart/mixed\".
5842 If t, it overrides nil values of
5843 `gnus-mime-display-multipart-alternative-as-mixed' and
5844 `gnus-mime-display-multipart-related-as-mixed'."
5845 :group 'gnus-article-mime
5846 :type 'boolean)
5848 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5849 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5850 :version "22.1"
5851 :group 'gnus-article-mime
5852 :type 'boolean)
5854 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5855 "Display \"multipart/related\" parts as \"multipart/mixed\".
5857 If displaying \"text/html\" is discouraged \(see
5858 `mm-discouraged-alternatives'\) images or other material inside a
5859 \"multipart/related\" part might be overlooked when this variable is nil."
5860 :version "22.1"
5861 :group 'gnus-article-mime
5862 :type 'boolean)
5864 (defun gnus-mime-display-part (handle)
5865 (cond
5866 ;; Maybe a broken MIME message.
5867 ((null handle))
5868 ;; Single part.
5869 ((not (stringp (car handle)))
5870 (gnus-mime-display-single handle))
5871 ;; User-defined multipart
5872 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5873 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5874 handle))
5875 ;; multipart/alternative
5876 ((and (equal (car handle) "multipart/alternative")
5877 (not (or gnus-mime-display-multipart-as-mixed
5878 gnus-mime-display-multipart-alternative-as-mixed)))
5879 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5880 (push (cons id handle) gnus-article-mime-handle-alist)
5881 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5882 ;; multipart/related
5883 ((and (equal (car handle) "multipart/related")
5884 (not (or gnus-mime-display-multipart-as-mixed
5885 gnus-mime-display-multipart-related-as-mixed)))
5886 ;;;!!!We should find the start part, but we just default
5887 ;;;!!!to the first part.
5888 ;;(gnus-mime-display-part (cadr handle))
5889 ;;;!!! Most multipart/related is an HTML message plus images.
5890 ;;;!!! Unfortunately we are unable to let W3 display those
5891 ;;;!!! included images, so we just display it as a mixed multipart.
5892 ;;(gnus-mime-display-mixed (cdr handle))
5893 ;;;!!! No, w3 can display everything just fine.
5894 (gnus-mime-display-part (cadr handle)))
5895 ((equal (car handle) "multipart/signed")
5896 (gnus-add-wash-type 'signed)
5897 (gnus-mime-display-security handle))
5898 ((equal (car handle) "multipart/encrypted")
5899 (gnus-add-wash-type 'encrypted)
5900 (gnus-mime-display-security handle))
5901 ;; Other multiparts are handled like multipart/mixed.
5903 (gnus-mime-display-mixed (cdr handle)))))
5905 (defun gnus-mime-part-function (handles)
5906 (if (stringp (car handles))
5907 (mapcar 'gnus-mime-part-function (cdr handles))
5908 (funcall gnus-article-mime-part-function handles)))
5910 (defun gnus-mime-display-mixed (handles)
5911 (mapcar 'gnus-mime-display-part handles))
5913 (defun gnus-mime-display-single (handle)
5914 (let ((type (mm-handle-media-type handle))
5915 (ignored gnus-ignored-mime-types)
5916 (not-attachment t)
5917 (move nil)
5918 display text)
5919 (catch 'ignored
5920 (progn
5921 (while ignored
5922 (when (string-match (pop ignored) type)
5923 (throw 'ignored nil)))
5924 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5925 (with-current-buffer gnus-summary-buffer
5926 gnus-inhibit-images)
5927 gnus-inhibit-images)
5928 (string-match "\\`image/" type)))
5929 (setq not-attachment
5930 (and (not (mm-inline-override-p handle))
5931 (or (not (mm-handle-disposition handle))
5932 (equal (car (mm-handle-disposition handle))
5933 "inline")
5934 (mm-attachment-override-p handle))))
5935 (mm-automatic-display-p handle)
5936 (or (and
5937 (mm-inlinable-p handle)
5938 (mm-inlined-p handle))
5939 (mm-automatic-external-display-p type)))
5940 (setq display t)
5941 (when (equal (mm-handle-media-supertype handle) "text")
5942 (setq text t)))
5943 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5944 beg)
5945 (push (cons id handle) gnus-article-mime-handle-alist)
5946 (when (and display
5947 (equal (mm-handle-media-supertype handle) "message"))
5948 (insert-char
5950 (cond ((not (bolp)) 2)
5951 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5952 (t 1))))
5953 (when (or (not display)
5954 (not (gnus-unbuttonized-mime-type-p type))
5955 (eq id gnus-mime-buttonized-part-id))
5956 (gnus-insert-mime-button
5957 handle id (list (or display (and not-attachment text))))
5958 (gnus-article-insert-newline)
5959 ;; Remember modify the number of forward lines.
5960 (setq move t))
5961 (setq beg (point))
5962 (cond
5963 (display
5964 (when move
5965 (forward-line -1)
5966 (setq beg (point)))
5967 (let ((mail-parse-charset gnus-newsgroup-charset)
5968 (mail-parse-ignored-charsets
5969 (save-excursion (condition-case ()
5970 (set-buffer gnus-summary-buffer)
5971 (error))
5972 gnus-newsgroup-ignored-charsets)))
5973 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5974 (goto-char (point-max)))
5975 ((and text not-attachment)
5976 (when move
5977 (forward-line -1)
5978 (setq beg (point)))
5979 (gnus-article-insert-newline)
5980 (mm-display-inline handle)
5981 (goto-char (point-max))))
5982 ;; Do highlighting.
5983 (save-excursion
5984 (save-restriction
5985 (narrow-to-region beg (point))
5986 (if (eq handle gnus-article-mime-handles)
5987 ;; The format=flowed case.
5988 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5989 ;; Don't count signature parts that are never displayed.
5990 ;; The part number should be re-calculated supposing this
5991 ;; might be a message/rfc822 part.
5992 (let (handles)
5993 (dolist (part gnus-article-mime-handles)
5994 (unless (or (stringp part)
5995 (equal (car (mm-handle-type part))
5996 "application/pgp-signature"))
5997 (push part handles)))
5998 (gnus-treat-article
5999 nil (length (memq handle handles)) (length handles)
6000 (mm-handle-media-type handle)))))))))))
6002 (defun gnus-unbuttonized-mime-type-p (type)
6003 "Say whether TYPE is to be unbuttonized."
6004 (unless gnus-inhibit-mime-unbuttonizing
6005 (when (catch 'found
6006 (let ((types gnus-unbuttonized-mime-types))
6007 (while types
6008 (when (string-match (pop types) type)
6009 (throw 'found t)))))
6010 (not (catch 'found
6011 (let ((types gnus-buttonized-mime-types))
6012 (while types
6013 (when (string-match (pop types) type)
6014 (throw 'found t)))))))))
6016 (defun gnus-article-insert-newline ()
6017 "Insert a newline, but mark it as undeletable."
6018 (gnus-put-text-property
6019 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6021 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6022 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6023 (ihandles handles)
6024 (point (point))
6025 handle (inhibit-read-only t) from props begend not-pref)
6026 (save-window-excursion
6027 (save-restriction
6028 (when ibegend
6029 (narrow-to-region (car ibegend)
6030 (or (cdr ibegend)
6031 (progn
6032 (goto-char (car ibegend))
6033 (forward-line 2)
6034 (point))))
6035 (delete-region (point-min) (point-max))
6036 (mm-remove-parts handles))
6037 (setq begend (list (point-marker)))
6038 ;; Do the toggle.
6039 (unless (setq not-pref (cadr (member preferred ihandles)))
6040 (setq not-pref (car ihandles)))
6041 (when (or ibegend
6042 (not preferred)
6043 (not (gnus-unbuttonized-mime-type-p
6044 "multipart/alternative")))
6045 (gnus-add-text-properties
6046 (setq from (point))
6047 (progn
6048 (insert (format "%d. " id))
6049 (point))
6050 `(gnus-callback
6051 (lambda (handles)
6052 (unless ,(not ibegend)
6053 (setq gnus-article-mime-handle-alist
6054 ',gnus-article-mime-handle-alist))
6055 (gnus-mime-display-alternative
6056 ',ihandles ',not-pref ',begend ,id))
6057 keymap ,gnus-mime-button-map
6058 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6059 face ,gnus-article-button-face
6060 gnus-part ,id
6061 article-type multipart
6062 rear-nonsticky t))
6063 (widget-convert-button 'link from (point)
6064 :action 'gnus-widget-press-button
6065 :button-keymap gnus-widget-button-keymap)
6066 ;; Do the handles
6067 (while (setq handle (pop handles))
6068 (gnus-add-text-properties
6069 (setq from (point))
6070 (progn
6071 (insert (format "(%c) %-18s"
6072 (if (equal handle preferred) ?* ? )
6073 (mm-handle-media-type handle)))
6074 (point))
6075 `(gnus-callback
6076 (lambda (handles)
6077 (unless ,(not ibegend)
6078 (setq gnus-article-mime-handle-alist
6079 ',gnus-article-mime-handle-alist))
6080 (gnus-mime-display-alternative
6081 ',ihandles ',handle ',begend ,id))
6082 keymap ,gnus-mime-button-map
6083 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6084 face ,gnus-article-button-face
6085 gnus-part ,id
6086 gnus-data ,handle
6087 rear-nonsticky t))
6088 (widget-convert-button 'link from (point)
6089 :action 'gnus-widget-press-button
6090 :button-keymap gnus-widget-button-keymap)
6091 (insert " "))
6092 (insert "\n\n"))
6093 (when preferred
6094 (if (stringp (car preferred))
6095 (gnus-display-mime preferred)
6096 (let ((mail-parse-charset gnus-newsgroup-charset)
6097 (mail-parse-ignored-charsets
6098 (with-current-buffer gnus-summary-buffer
6099 gnus-newsgroup-ignored-charsets)))
6100 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6101 ;; Do highlighting.
6102 (save-excursion
6103 (save-restriction
6104 (narrow-to-region (car begend) (point-max))
6105 (gnus-treat-article
6106 nil (length gnus-article-mime-handle-alist)
6107 (gnus-article-mime-total-parts)
6108 (mm-handle-media-type preferred))))))
6109 (goto-char (point-max))
6110 (setcdr begend (point-marker)))))
6111 (when ibegend
6112 (goto-char point))))
6114 (defconst gnus-article-wash-status-strings
6115 (let ((alist '((cite "c" "Possible hidden citation text"
6116 " " "All citation text visible")
6117 (headers "h" "Hidden headers"
6118 " " "All headers visible.")
6119 (pgp "p" "Encrypted or signed message status hidden"
6120 " " "No hidden encryption nor digital signature status")
6121 (signature "s" "Signature has been hidden"
6122 " " "Signature is visible")
6123 (overstrike "o" "Overstrike (^H) characters applied"
6124 " " "No overstrike characters applied")
6125 (emphasis "e" "/*_Emphasis_*/ characters applied"
6126 " " "No /*_emphasis_*/ characters applied")))
6127 result)
6128 (dolist (entry alist result)
6129 (let ((key (nth 0 entry))
6130 (on (copy-sequence (nth 1 entry)))
6131 (on-help (nth 2 entry))
6132 (off (copy-sequence (nth 3 entry)))
6133 (off-help (nth 4 entry)))
6134 (put-text-property 0 1 'help-echo on-help on)
6135 (put-text-property 0 1 'help-echo off-help off)
6136 (push (list key on off) result))))
6137 "Alist of strings describing wash status in the mode line.
6138 Each entry has the form (KEY ON OF), where the KEY is a symbol
6139 representing the particular washing function, ON is the string to use
6140 in the article mode line when the washing function is active, and OFF
6141 is the string to use when it is inactive.")
6143 (defun gnus-article-wash-status-entry (key value)
6144 (let ((entry (assoc key gnus-article-wash-status-strings)))
6145 (if value (nth 1 entry) (nth 2 entry))))
6147 (defun gnus-article-wash-status ()
6148 "Return a string which display status of article washing."
6149 (with-current-buffer gnus-article-buffer
6150 (let ((cite (memq 'cite gnus-article-wash-types))
6151 (headers (memq 'headers gnus-article-wash-types))
6152 (boring (memq 'boring-headers gnus-article-wash-types))
6153 (pgp (memq 'pgp gnus-article-wash-types))
6154 (pem (memq 'pem gnus-article-wash-types))
6155 (signed (memq 'signed gnus-article-wash-types))
6156 (encrypted (memq 'encrypted gnus-article-wash-types))
6157 (signature (memq 'signature gnus-article-wash-types))
6158 (overstrike (memq 'overstrike gnus-article-wash-types))
6159 (emphasis (memq 'emphasis gnus-article-wash-types)))
6160 (concat
6161 (gnus-article-wash-status-entry 'cite cite)
6162 (gnus-article-wash-status-entry 'headers (or headers boring))
6163 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6164 (gnus-article-wash-status-entry 'signature signature)
6165 (gnus-article-wash-status-entry 'overstrike overstrike)
6166 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6168 (defun gnus-add-wash-type (type)
6169 "Add a washing of TYPE to the current status."
6170 (add-to-list 'gnus-article-wash-types type))
6172 (defun gnus-delete-wash-type (type)
6173 "Add a washing of TYPE to the current status."
6174 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6176 (defun gnus-add-image (category image)
6177 "Add IMAGE of CATEGORY to the list of displayed images."
6178 (let ((entry (assq category gnus-article-image-alist)))
6179 (unless entry
6180 (setq entry (list category))
6181 (push entry gnus-article-image-alist))
6182 (nconc entry (list image))))
6184 (defun gnus-delete-images (category)
6185 "Delete all images in CATEGORY."
6186 (let ((entry (assq category gnus-article-image-alist)))
6187 (dolist (image (cdr entry))
6188 (gnus-remove-image image category))
6189 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6190 (gnus-delete-wash-type category)))
6192 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6194 (defun gnus-article-maybe-hide-headers ()
6195 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6196 Provided for backwards compatibility."
6197 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6198 (not (with-current-buffer gnus-summary-buffer
6199 gnus-have-all-headers)))
6200 (not gnus-inhibit-hiding))
6201 (gnus-article-hide-headers)))
6203 (declare-function shr-put-image "shr" (data alt &optional flags))
6205 (defun gnus-shr-put-image (data alt &optional flags)
6206 "Put image DATA with a string ALT. Enable image to be deleted."
6207 (let ((image (shr-put-image data (propertize (or alt "*")
6208 'gnus-image-category 'shr)
6209 flags)))
6210 (when image
6211 (gnus-add-image 'shr image))))
6213 ;;; Article savers.
6215 (defun gnus-output-to-file (file-name)
6216 "Append the current article to a file named FILE-NAME.
6217 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6218 text and used as the value of the coding cookie which is added to the
6219 top of a file. Otherwise, this function saves a raw article without
6220 the coding cookie."
6221 (let* ((artbuf (current-buffer))
6222 (file-name-coding-system nnmail-pathname-coding-system)
6223 (coding gnus-article-save-coding-system)
6224 (coding-system-for-read (if coding
6225 nil ;; Rely on the coding cookie.
6226 mm-text-coding-system))
6227 (coding-system-for-write (or coding
6228 mm-text-coding-system-for-write
6229 mm-text-coding-system))
6230 (exists (file-exists-p file-name)))
6231 (with-temp-buffer
6232 (when exists
6233 (insert-file-contents file-name)
6234 (goto-char (point-min))
6235 ;; Remove the existing coding cookie.
6236 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6237 (delete-region (match-beginning 0) (match-end 0))))
6238 (goto-char (point-max))
6239 (insert-buffer-substring artbuf)
6240 ;; Append newline at end of the buffer as separator, and then
6241 ;; save it to file.
6242 (goto-char (point-max))
6243 (insert "\n")
6244 (when coding
6245 ;; If the coding system is not suitable to encode the text,
6246 ;; ask a user for a proper one.
6247 (when (fboundp 'select-safe-coding-system)
6248 (setq coding (coding-system-base
6249 (save-window-excursion
6250 (select-safe-coding-system (point-min) (point-max)
6251 coding))))
6252 (setq coding-system-for-write
6253 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6254 coding)))
6255 (goto-char (point-min))
6256 ;; Add the coding cookie.
6257 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6258 coding-system-for-write)))
6259 (if exists
6260 (progn
6261 (write-region (point-min) (point-max) file-name nil 'no-message)
6262 (message "Appended to %s" file-name))
6263 (write-region (point-min) (point-max) file-name))))
6266 (defun gnus-narrow-to-page (&optional arg)
6267 "Narrow the article buffer to a page.
6268 If given a numerical ARG, move forward ARG pages."
6269 (interactive "P")
6270 (setq arg (if arg (prefix-numeric-value arg) 0))
6271 (with-current-buffer gnus-article-buffer
6272 (widen)
6273 ;; Remove any old next/prev buttons.
6274 (when (gnus-visual-p 'page-marker)
6275 (let ((inhibit-read-only t))
6276 (gnus-remove-text-with-property 'gnus-prev)
6277 (gnus-remove-text-with-property 'gnus-next)))
6278 (let (st nd pt)
6279 (when (save-excursion
6280 (cond ((< arg 0)
6281 (if (re-search-backward page-delimiter nil 'move (abs arg))
6282 (prog1
6283 (setq nd (match-beginning 0)
6284 pt nd)
6285 (when (re-search-backward page-delimiter nil t)
6286 (setq st (match-end 0))))
6287 (when (re-search-forward page-delimiter nil t)
6288 (setq nd (match-beginning 0)
6289 pt (point-min)))))
6290 ((> arg 0)
6291 (if (re-search-forward page-delimiter nil 'move arg)
6292 (prog1
6293 (setq st (match-end 0)
6294 pt st)
6295 (when (re-search-forward page-delimiter nil t)
6296 (setq nd (match-beginning 0))))
6297 (when (re-search-backward page-delimiter nil t)
6298 (setq st (match-end 0)
6299 pt (point-max)))))
6301 (when (re-search-backward page-delimiter nil t)
6302 (goto-char (setq st (match-end 0))))
6303 (when (re-search-forward page-delimiter nil t)
6304 (setq nd (match-beginning 0)))
6305 (or st nd))))
6306 (setq gnus-page-broken t)
6307 (when pt (goto-char pt))
6308 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6309 (when (gnus-visual-p 'page-marker)
6310 (save-excursion
6311 (when nd
6312 (goto-char nd)
6313 (gnus-insert-next-page-button))
6314 (when st
6315 (goto-char st)
6316 (gnus-insert-prev-page-button))))))))
6318 ;; Article mode commands
6320 (defun gnus-article-goto-next-page ()
6321 "Show the next page of the article."
6322 (interactive)
6323 (when (gnus-article-next-page)
6324 (goto-char (point-min))
6325 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6328 (defun gnus-article-goto-prev-page ()
6329 "Show the previous page of the article."
6330 (interactive)
6331 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6332 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6333 (gnus-article-prev-page nil)))
6335 ;; This is cleaner but currently breaks `gnus-pick-mode':
6337 ;; (defun gnus-article-goto-next-page ()
6338 ;; "Show the next page of the article."
6339 ;; (interactive)
6340 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6341 ;; (gnus-summary-next-page)))
6343 ;; (defun gnus-article-goto-prev-page ()
6344 ;; "Show the next page of the article."
6345 ;; (interactive)
6346 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6347 ;; (gnus-summary-prev-page)))
6349 (defun gnus-article-next-page (&optional lines)
6350 "Show the next page of the current article.
6351 If end of article, return non-nil. Otherwise return nil.
6352 Argument LINES specifies lines to be scrolled up."
6353 (interactive "p")
6354 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6355 (if (and (not (and gnus-article-over-scroll
6356 (> (count-lines (window-start) (point-max))
6357 (if (featurep 'xemacs)
6358 (or lines (1- (window-height)))
6359 (+ (or lines (1- (window-height))) scroll-margin)))))
6360 (save-excursion
6361 (end-of-line)
6362 (and (pos-visible-in-window-p) ;Not continuation line.
6363 (>= (point) (point-max)))))
6364 ;; Nothing in this page.
6365 (if (or (not gnus-page-broken)
6366 (save-excursion
6367 (save-restriction
6368 (widen)
6369 (forward-line)
6370 (eobp)))) ;Real end-of-buffer?
6371 (progn
6372 (when gnus-article-over-scroll
6373 (gnus-article-next-page-1 lines))
6374 t) ;Nothing more.
6375 (gnus-narrow-to-page 1) ;Go to next page.
6376 nil)
6377 ;; More in this page.
6378 (gnus-article-next-page-1 lines)
6379 nil))
6381 (defun gnus-article-beginning-of-window ()
6382 "Move point to the beginning of the window.
6383 In Emacs, the point is placed at the line number which `scroll-margin'
6384 specifies."
6385 (if (featurep 'xemacs)
6386 (move-to-window-line 0)
6387 ;; There is an obscure bug in Emacs that makes it impossible to
6388 ;; scroll past big pictures in the article buffer. Try to fix
6389 ;; this by adding a sanity check by counting the lines visible.
6390 (when (> (count-lines (window-start) (window-end)) 30)
6391 (move-to-window-line
6392 (min (max 0 scroll-margin)
6393 (max 1 (- (window-height)
6394 (if mode-line-format 1 0)
6395 (if header-line-format 1 0)
6396 2)))))))
6398 (defun gnus-article-next-page-1 (lines)
6399 (condition-case ()
6400 (let ((scroll-in-place nil)
6401 (auto-window-vscroll nil))
6402 (scroll-up lines))
6403 (end-of-buffer
6404 ;; Long lines may cause an end-of-buffer error.
6405 (goto-char (point-max))))
6406 (gnus-article-beginning-of-window))
6408 (defun gnus-article-prev-page (&optional lines)
6409 "Show previous page of current article.
6410 Argument LINES specifies lines to be scrolled down."
6411 (interactive "p")
6412 (move-to-window-line 0)
6413 (if (and gnus-page-broken
6414 (bobp)
6415 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6416 (progn
6417 (gnus-narrow-to-page -1) ;Go to previous page.
6418 (goto-char (point-max))
6419 (recenter (if gnus-article-over-scroll
6420 (if lines
6421 (max (if (featurep 'xemacs)
6422 lines
6423 (+ lines scroll-margin))
6425 (- (window-height) 2))
6426 -1)))
6427 (prog1
6428 (condition-case ()
6429 (let ((scroll-in-place nil))
6430 (scroll-down lines))
6431 (beginning-of-buffer
6432 (goto-char (point-min))))
6433 (gnus-article-beginning-of-window))))
6435 (defun gnus-article-only-boring-p ()
6436 "Decide whether there is only boring text remaining in the article.
6437 Something \"interesting\" is a word of at least two letters that does
6438 not have a face in `gnus-article-boring-faces'."
6439 (when (and gnus-article-skip-boring
6440 (boundp 'gnus-article-boring-faces)
6441 (symbol-value 'gnus-article-boring-faces))
6442 (save-excursion
6443 (let ((inhibit-point-motion-hooks t))
6444 (catch 'only-boring
6445 (while (re-search-forward "\\b\\w\\w" nil t)
6446 (forward-char -1)
6447 (when (not (gnus-intersection
6448 (gnus-faces-at (point))
6449 (symbol-value 'gnus-article-boring-faces)))
6450 (throw 'only-boring nil)))
6451 (throw 'only-boring t))))))
6453 (defun gnus-article-refer-article ()
6454 "Read article specified by message-id around point."
6455 (interactive)
6456 (save-excursion
6457 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6458 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6459 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6460 (let ((msg-id (concat "<" (match-string 0) ">")))
6461 (set-buffer gnus-summary-buffer)
6462 (gnus-summary-refer-article msg-id))
6463 (error "No references around point"))))
6465 (defun gnus-article-show-summary ()
6466 "Reconfigure windows to show summary buffer."
6467 (interactive)
6468 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6469 (error "There is no summary buffer for this article buffer")
6470 (gnus-article-set-globals)
6471 (gnus-configure-windows 'article)
6472 (gnus-summary-goto-subject gnus-current-article)
6473 (gnus-summary-position-point)))
6475 (defun gnus-article-describe-briefly ()
6476 "Describe article mode commands briefly."
6477 (interactive)
6478 (gnus-message 6 "%s" (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")))
6480 (defun gnus-article-check-buffer ()
6481 "Beep if not in an article buffer."
6482 (unless (equal major-mode 'gnus-article-mode)
6483 (error "Command invoked outside of a Gnus article buffer")))
6485 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6486 "Read a summary buffer key sequence and execute it from the article buffer."
6487 (interactive "P")
6488 (gnus-article-check-buffer)
6489 (let ((nosaves
6490 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6491 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6492 "=" "^" "\M-^" "|"))
6493 (nosave-but-article
6494 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6495 "An" "Ap" [?A (meta return)] [?A delete]))
6496 (nosave-in-article
6497 '("AS" "\C-d"))
6498 (up-to-top
6499 '("n" "Gn" "p" "Gp"))
6500 keys new-sum-point)
6501 (with-current-buffer gnus-article-current-summary
6502 (let (gnus-pick-mode)
6503 (setq unread-command-events (nconc unread-command-events
6504 (list (or key last-command-event)))
6505 keys (if (featurep 'xemacs)
6506 (events-to-keys (read-key-sequence nil t))
6507 (read-key-sequence nil t)))))
6509 (message "")
6511 (cond
6512 ((eq (aref keys (1- (length keys))) ?\C-h)
6513 (gnus-article-describe-bindings (substring keys 0 -1)))
6514 ((or (member keys nosaves)
6515 (member keys nosave-but-article)
6516 (member keys nosave-in-article))
6517 (let (func)
6518 (save-window-excursion
6519 (pop-to-buffer gnus-article-current-summary)
6520 ;; We disable the pick minor mode commands.
6521 (let (gnus-pick-mode)
6522 (setq func (key-binding keys t))))
6523 (if (or (not func)
6524 (numberp func))
6525 (ding)
6526 (unless (member keys nosave-in-article)
6527 (set-buffer gnus-article-current-summary))
6528 (when (and (symbolp func)
6529 (get func 'disabled))
6530 (error "Function %s disabled" func))
6531 (call-interactively func)
6532 (setq new-sum-point (point)))
6533 (when (member keys nosave-but-article)
6534 (pop-to-buffer gnus-article-buffer))))
6536 ;; These commands should restore window configuration.
6537 (let ((obuf (current-buffer))
6538 (owin (current-window-configuration))
6539 win func in-buffer selected new-sum-start new-sum-hscroll err)
6540 (cond (not-restore-window
6541 (pop-to-buffer gnus-article-current-summary)
6542 (setq win (selected-window)))
6543 ((setq win (get-buffer-window gnus-article-current-summary))
6544 (select-window win))
6546 (let ((summary-buffer gnus-article-current-summary))
6547 (gnus-configure-windows 'article)
6548 (unless (setq win (get-buffer-window summary-buffer 'visible))
6549 (let ((gnus-buffer-configuration
6550 '((article ((vertical 1.0
6551 (summary 0.25 point)
6552 (article 1.0)))))))
6553 (gnus-configure-windows 'article))
6554 (setq win (get-buffer-window summary-buffer 'visible)))
6555 (gnus-select-frame-set-input-focus (window-frame win))
6556 (select-window win))))
6557 (setq in-buffer (current-buffer))
6558 ;; We disable the pick minor mode commands.
6559 (setq func (let (gnus-pick-mode)
6560 (key-binding keys t)))
6561 (when (get func 'disabled)
6562 (error "Function %s disabled" func))
6563 (if (and func
6564 (functionp func)
6565 (condition-case code
6566 (progn
6567 (call-interactively func)
6569 (error
6570 (setq err code)
6571 nil)))
6572 (progn
6573 (when (eq win (selected-window))
6574 (setq new-sum-point (point)
6575 new-sum-start (window-start win)
6576 new-sum-hscroll (window-hscroll win)))
6577 (when (or (eq in-buffer (current-buffer))
6578 (when (eq obuf (current-buffer))
6579 (set-buffer in-buffer)
6581 (setq selected (gnus-summary-select-article))
6582 (set-buffer obuf)
6583 (unless not-restore-window
6584 (set-window-configuration owin))
6585 (when (and (eq selected 'old)
6586 new-sum-point)
6587 (set-window-start (get-buffer-window (current-buffer))
6589 (set-window-point (get-buffer-window (current-buffer))
6590 (if (article-goto-body)
6591 (1- (point))
6592 (point))))
6593 (when (and (not not-restore-window)
6594 new-sum-point
6595 (window-live-p win)
6596 (with-current-buffer (window-buffer win)
6597 (eq major-mode 'gnus-summary-mode)))
6598 (set-window-point win new-sum-point)
6599 (set-window-start win new-sum-start)
6600 (set-window-hscroll win new-sum-hscroll))))
6601 (set-window-configuration owin)
6602 (if err
6603 (signal (car err) (cdr err))
6604 (ding))))))))
6606 (defun gnus-article-read-summary-send-keys ()
6607 (interactive)
6608 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6609 (gnus-article-read-summary-keys)))
6611 (defun gnus-article-describe-key (key)
6612 "Display documentation of the function invoked by KEY.
6613 KEY is a string or a vector."
6614 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6615 (read-key-sequence "Describe key: "))))
6616 (gnus-article-check-buffer)
6617 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6618 gnus-article-read-summary-send-keys))
6619 (with-current-buffer gnus-article-current-summary
6620 (setq unread-command-events
6621 (if (featurep 'xemacs)
6622 (append key nil)
6623 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6624 (list 'meta (- x 128))
6626 key)))
6627 (let ((cursor-in-echo-area t)
6628 gnus-pick-mode)
6629 (describe-key (read-key-sequence nil t))))
6630 (describe-key key)))
6632 (defun gnus-article-describe-key-briefly (key &optional insert)
6633 "Display documentation of the function invoked by KEY.
6634 KEY is a string or a vector."
6635 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6636 (read-key-sequence "Describe key: "))
6637 current-prefix-arg))
6638 (gnus-article-check-buffer)
6639 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6640 gnus-article-read-summary-send-keys))
6641 (with-current-buffer gnus-article-current-summary
6642 (setq unread-command-events
6643 (if (featurep 'xemacs)
6644 (append key nil)
6645 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6646 (list 'meta (- x 128))
6648 key)))
6649 (let ((cursor-in-echo-area t)
6650 gnus-pick-mode)
6651 (describe-key-briefly (read-key-sequence nil t) insert)))
6652 (describe-key-briefly key insert)))
6654 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6655 (defvar gnus-agent-summary-mode)
6656 (defvar gnus-draft-mode)
6657 ;; Calling help-buffer will autoload help-mode.
6658 (defvar help-xref-stack-item)
6659 ;; Emacs 22 doesn't load it in the batch mode.
6660 (eval-when-compile
6661 (autoload 'help-buffer "help-mode"))
6663 (defun gnus-article-describe-bindings (&optional prefix)
6664 "Show a list of all defined keys, and their definitions.
6665 The optional argument PREFIX, if non-nil, should be a key sequence;
6666 then we display only bindings that start with that prefix."
6667 (interactive)
6668 (gnus-article-check-buffer)
6669 (let ((keymap (copy-keymap gnus-article-mode-map))
6670 (map (copy-keymap gnus-article-send-map))
6671 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6672 parent agent draft)
6673 (define-key keymap "S" map)
6674 (define-key map [t] nil)
6675 (with-current-buffer gnus-article-current-summary
6676 (set-keymap-parent
6677 keymap
6678 (if (setq parent (keymap-parent gnus-article-mode-map))
6679 (prog1
6680 (setq parent (copy-keymap parent))
6681 (set-keymap-parent parent (current-local-map)))
6682 (current-local-map)))
6683 (set-keymap-parent map (key-binding "S"))
6684 (let (key def gnus-pick-mode)
6685 (while sumkeys
6686 (setq key (pop sumkeys))
6687 (cond ((and (vectorp key) (= (length key) 1)
6688 (consp (setq def (aref key 0)))
6689 (numberp (car def)) (numberp (cdr def)))
6690 (when (< (max (car def) (cdr def)) 128)
6691 (setq sumkeys
6692 (append (mapcar
6693 #'vector
6694 (nreverse (gnus-uncompress-range def)))
6695 sumkeys))))
6696 ((setq def (key-binding key))
6697 (unless (eq def 'undefined)
6698 (define-key keymap key def))))))
6699 (when (boundp 'gnus-agent-summary-mode)
6700 (setq agent gnus-agent-summary-mode))
6701 (when (boundp 'gnus-draft-mode)
6702 (setq draft gnus-draft-mode)))
6703 (with-temp-buffer
6704 (use-local-map keymap)
6705 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6706 (set (make-local-variable 'gnus-draft-mode) draft)
6707 (describe-bindings prefix))
6708 (let ((item `((lambda (prefix)
6709 (with-current-buffer ,(current-buffer)
6710 (gnus-article-describe-bindings prefix)))
6711 ,prefix)))
6712 (with-current-buffer (let (help-xref-following) (help-buffer))
6713 (setq help-xref-stack-item item)))))
6715 (defun gnus-article-reply-with-original (&optional wide)
6716 "Start composing a reply mail to the current message.
6717 The text in the region will be yanked. If the region isn't active,
6718 the entire article will be yanked."
6719 (interactive)
6720 (let ((article (cdr gnus-article-current))
6721 contents)
6722 (if (not (gnus-region-active-p))
6723 (with-current-buffer gnus-summary-buffer
6724 (gnus-summary-reply (list (list article)) wide))
6725 (setq contents (buffer-substring (point) (mark t)))
6726 ;; Deactivate active regions.
6727 (when (and (boundp 'transient-mark-mode)
6728 transient-mark-mode)
6729 (setq mark-active nil))
6730 (with-current-buffer gnus-summary-buffer
6731 (gnus-summary-reply
6732 (list (list article contents)) wide)))))
6734 (defun gnus-article-wide-reply-with-original ()
6735 "Start composing a wide reply mail to the current message.
6736 The text in the region will be yanked. If the region isn't active,
6737 the entire article will be yanked."
6738 (interactive)
6739 (gnus-article-reply-with-original t))
6741 (defun gnus-article-followup-with-original ()
6742 "Compose a followup to the current article.
6743 The text in the region will be yanked. If the region isn't active,
6744 the entire article will be yanked."
6745 (interactive)
6746 (let ((article (cdr gnus-article-current))
6747 contents)
6748 (if (not (gnus-region-active-p))
6749 (with-current-buffer gnus-summary-buffer
6750 (gnus-summary-followup (list (list article))))
6751 (setq contents (buffer-substring (point) (mark t)))
6752 ;; Deactivate active regions.
6753 (when (and (boundp 'transient-mark-mode)
6754 transient-mark-mode)
6755 (setq mark-active nil))
6756 (with-current-buffer gnus-summary-buffer
6757 (gnus-summary-followup
6758 (list (list article contents)))))))
6760 (defun gnus-article-hide (&optional arg force)
6761 "Hide all the gruft in the current article.
6762 This means that signatures, cited text and (some) headers will be
6763 hidden.
6764 If given a prefix, show the hidden text instead."
6765 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6766 (gnus-article-hide-headers arg)
6767 (gnus-article-hide-list-identifiers arg)
6768 (gnus-article-hide-citation-maybe arg force)
6769 (gnus-article-hide-signature arg))
6771 (defun gnus-article-maybe-highlight ()
6772 "Do some article highlighting if article highlighting is requested."
6773 (when (gnus-visual-p 'article-highlight 'highlight)
6774 (gnus-article-highlight-some)))
6776 (defun gnus-check-group-server ()
6777 ;; Make sure the connection to the server is alive.
6778 (unless (gnus-server-opened
6779 (gnus-find-method-for-group gnus-newsgroup-name))
6780 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6781 (gnus-request-group gnus-newsgroup-name t)))
6783 (eval-when-compile
6784 (autoload 'nneething-get-file-name "nneething"))
6786 (defun gnus-request-article-this-buffer (article group)
6787 "Get an article and insert it into this buffer."
6788 (let (do-update-line sparse-header)
6789 (prog1
6790 (save-excursion
6791 (erase-buffer)
6792 (gnus-kill-all-overlays)
6793 (setq group (or group gnus-newsgroup-name))
6795 ;; Using `gnus-request-article' directly will insert the article into
6796 ;; `nntp-server-buffer' - so we'll save some time by not having to
6797 ;; copy it from the server buffer into the article buffer.
6799 ;; We only request an article by message-id when we do not have the
6800 ;; headers for it, so we'll have to get those.
6801 (when (stringp article)
6802 (gnus-read-header article))
6804 ;; If the article number is negative, that means that this article
6805 ;; doesn't belong in this newsgroup (possibly), so we find its
6806 ;; message-id and request it by id instead of number.
6807 (when (and (numberp article)
6808 gnus-summary-buffer
6809 (get-buffer gnus-summary-buffer)
6810 (gnus-buffer-exists-p gnus-summary-buffer))
6811 (with-current-buffer gnus-summary-buffer
6812 (let ((header (gnus-summary-article-header article)))
6813 (when (< article 0)
6814 (cond
6815 ((memq article gnus-newsgroup-sparse)
6816 ;; This is a sparse gap article.
6817 (setq do-update-line article)
6818 (setq article (mail-header-id header))
6819 (setq sparse-header (gnus-read-header article))
6820 (setq gnus-newsgroup-sparse
6821 (delq article gnus-newsgroup-sparse)))
6822 ((vectorp header)
6823 ;; It's a real article.
6824 (setq article (mail-header-id header)))
6826 ;; It is an extracted pseudo-article.
6827 (setq article 'pseudo)
6828 (gnus-request-pseudo-article header))))
6830 (let ((method (gnus-find-method-for-group
6831 gnus-newsgroup-name)))
6832 (when (and (eq (car method) 'nneething)
6833 (vectorp header))
6834 (let ((dir (nneething-get-file-name
6835 (mail-header-id header))))
6836 (when (and (stringp dir)
6837 (file-directory-p dir))
6838 (setq article 'nneething)
6839 (gnus-group-enter-directory dir))))))))
6841 (cond
6842 ;; Refuse to select canceled articles.
6843 ((and (numberp article)
6844 gnus-summary-buffer
6845 (get-buffer gnus-summary-buffer)
6846 (gnus-buffer-exists-p gnus-summary-buffer)
6847 (eq (cdr (with-current-buffer gnus-summary-buffer
6848 (assq article gnus-newsgroup-reads)))
6849 gnus-canceled-mark))
6850 nil)
6851 ;; We first check `gnus-original-article-buffer'.
6852 ((and (get-buffer gnus-original-article-buffer)
6853 (numberp article)
6854 (with-current-buffer gnus-original-article-buffer
6855 (and (equal (car gnus-original-article) group)
6856 (eq (cdr gnus-original-article) article))))
6857 ;; `insert-buffer-substring' would incorrectly use the
6858 ;; equivalent of string-make-multibyte which amount to decoding
6859 ;; with locale-coding-system, causing failure of
6860 ;; subsequent decoding.
6861 (insert (mm-string-to-multibyte
6862 (with-current-buffer gnus-original-article-buffer
6863 (buffer-substring (point-min) (point-max)))))
6864 'article)
6865 ;; Check the backlog.
6866 ((and gnus-keep-backlog
6867 (gnus-backlog-request-article group article (current-buffer)))
6868 'article)
6869 ;; Check asynchronous pre-fetch.
6870 ((gnus-async-request-fetched-article group article (current-buffer))
6871 (gnus-async-prefetch-next group article gnus-summary-buffer)
6872 (when (and (numberp article) gnus-keep-backlog)
6873 (gnus-backlog-enter-article group article (current-buffer)))
6874 'article)
6875 ;; Check the cache.
6876 ((and gnus-use-cache
6877 (numberp article)
6878 (gnus-cache-request-article article group))
6879 'article)
6880 ;; Check the agent cache.
6881 ((gnus-agent-request-article article group)
6882 'article)
6883 ;; Get the article and put into the article buffer.
6884 ((or (stringp article)
6885 (numberp article))
6886 (let ((gnus-override-method gnus-override-method)
6887 (methods (and (stringp article)
6888 (with-current-buffer gnus-summary-buffer
6889 (gnus-refer-article-methods))))
6890 (backend (car (gnus-find-method-for-group
6891 gnus-newsgroup-name)))
6892 result
6893 (inhibit-read-only t))
6894 (when (and (null gnus-override-method)
6895 methods)
6896 (setq gnus-override-method (pop methods)))
6897 (while (not result)
6898 (erase-buffer)
6899 (gnus-kill-all-overlays)
6900 (let ((gnus-newsgroup-name group))
6901 (gnus-check-group-server))
6902 (cond
6903 ((gnus-request-article article group (current-buffer))
6904 (when (numberp article)
6905 (gnus-async-prefetch-next group article
6906 gnus-summary-buffer)
6907 (when gnus-keep-backlog
6908 (gnus-backlog-enter-article
6909 group article (current-buffer)))
6910 (when (and gnus-agent
6911 (gnus-agent-group-covered-p group))
6912 (gnus-agent-store-article article group)))
6913 (setq result 'article))
6914 (methods
6915 (setq gnus-override-method (pop methods)))
6916 ((not (string-match "^400 "
6917 (nnheader-get-report backend)))
6918 ;; If we get 400 server disconnect, reconnect and
6919 ;; retry; otherwise, assume the article has expired.
6920 (setq result 'done))))
6921 (and (eq result 'article) 'article)))
6922 ;; It was a pseudo.
6923 (t article)))
6925 ;; Associate this article with the current summary buffer.
6926 (setq gnus-article-current-summary gnus-summary-buffer)
6928 ;; Take the article from the original article buffer
6929 ;; and place it in the buffer it's supposed to be in.
6930 (when (and (get-buffer gnus-article-buffer)
6931 (equal (buffer-name (current-buffer))
6932 (buffer-name (get-buffer gnus-article-buffer))))
6933 (save-excursion
6934 (if (get-buffer gnus-original-article-buffer)
6935 (set-buffer gnus-original-article-buffer)
6936 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6937 (buffer-disable-undo)
6938 (setq major-mode 'gnus-original-article-mode)
6939 (setq buffer-read-only t))
6940 (let ((inhibit-read-only t))
6941 (erase-buffer)
6942 (insert-buffer-substring gnus-article-buffer))
6943 (setq gnus-original-article (cons group article)))
6945 ;; Decode charsets.
6946 (run-hooks 'gnus-article-decode-hook)
6947 ;; Mark article as decoded or not.
6948 (setq gnus-article-decoded-p gnus-article-decode-hook))
6950 ;; Update sparse articles.
6951 (when (and do-update-line
6952 (or (numberp article)
6953 (stringp article)))
6954 (let ((buf (current-buffer)))
6955 (set-buffer gnus-summary-buffer)
6956 (gnus-summary-update-article do-update-line sparse-header)
6957 (gnus-summary-goto-subject do-update-line nil t)
6958 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6959 (point))
6960 (set-buffer buf))))))
6962 (defun gnus-block-private-groups (group)
6963 (if (gnus-news-group-p group)
6964 ;; Block nothing in news groups.
6966 ;; Block everything anywhere else.
6967 "."))
6969 (defun gnus-blocked-images ()
6970 (if (functionp gnus-blocked-images)
6971 (funcall gnus-blocked-images gnus-newsgroup-name)
6972 gnus-blocked-images))
6975 ;;; Article editing
6978 (defcustom gnus-article-edit-mode-hook nil
6979 "Hook run in article edit mode buffers."
6980 :group 'gnus-article-various
6981 :type 'hook)
6983 (defvar gnus-article-edit-done-function nil)
6985 (defvar gnus-article-edit-mode-map nil)
6987 ;; Should we be using derived.el for this?
6988 (unless gnus-article-edit-mode-map
6989 (setq gnus-article-edit-mode-map (make-keymap))
6990 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6992 (gnus-define-keys gnus-article-edit-mode-map
6993 "\C-c?" describe-mode
6994 "\C-c\C-c" gnus-article-edit-done
6995 "\C-c\C-k" gnus-article-edit-exit
6996 "\C-c\C-f\C-t" message-goto-to
6997 "\C-c\C-f\C-o" message-goto-from
6998 "\C-c\C-f\C-b" message-goto-bcc
6999 ;;"\C-c\C-f\C-w" message-goto-fcc
7000 "\C-c\C-f\C-c" message-goto-cc
7001 "\C-c\C-f\C-s" message-goto-subject
7002 "\C-c\C-f\C-r" message-goto-reply-to
7003 "\C-c\C-f\C-n" message-goto-newsgroups
7004 "\C-c\C-f\C-d" message-goto-distribution
7005 "\C-c\C-f\C-f" message-goto-followup-to
7006 "\C-c\C-f\C-m" message-goto-mail-followup-to
7007 "\C-c\C-f\C-k" message-goto-keywords
7008 "\C-c\C-f\C-u" message-goto-summary
7009 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7010 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7011 "\C-c\C-b" message-goto-body
7012 "\C-c\C-i" message-goto-signature
7014 "\C-c\C-t" message-insert-to
7015 "\C-c\C-n" message-insert-newsgroups
7016 "\C-c\C-o" message-sort-headers
7017 "\C-c\C-e" message-elide-region
7018 "\C-c\C-v" message-delete-not-region
7019 "\C-c\C-z" message-kill-to-signature
7020 "\M-\r" message-newline-and-reformat
7021 "\C-c\C-a" mml-attach-file
7022 "\C-a" message-beginning-of-line
7023 "\t" message-tab
7024 "\M-;" comment-region)
7026 (gnus-define-keys (gnus-article-edit-wash-map
7027 "\C-c\C-w" gnus-article-edit-mode-map)
7028 "f" gnus-article-edit-full-stops))
7030 (easy-menu-define
7031 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7032 '("Field"
7033 ["Fetch To" message-insert-to t]
7034 ["Fetch Newsgroups" message-insert-newsgroups t]
7035 "----"
7036 ["To" message-goto-to t]
7037 ["From" message-goto-from t]
7038 ["Subject" message-goto-subject t]
7039 ["Cc" message-goto-cc t]
7040 ["Reply-To" message-goto-reply-to t]
7041 ["Summary" message-goto-summary t]
7042 ["Keywords" message-goto-keywords t]
7043 ["Newsgroups" message-goto-newsgroups t]
7044 ["Followup-To" message-goto-followup-to t]
7045 ["Mail-Followup-To" message-goto-mail-followup-to t]
7046 ["Distribution" message-goto-distribution t]
7047 ["Body" message-goto-body t]
7048 ["Signature" message-goto-signature t]))
7050 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7051 "Major mode for editing articles.
7052 This is an extended text-mode.
7054 \\{gnus-article-edit-mode-map}"
7055 (make-local-variable 'gnus-article-edit-done-function)
7056 (make-local-variable 'gnus-prev-winconf)
7057 (set (make-local-variable 'font-lock-defaults)
7058 '(message-font-lock-keywords t))
7059 (set (make-local-variable 'mail-header-separator) "")
7060 (set (make-local-variable 'gnus-article-edit-mode) t)
7061 (easy-menu-add message-mode-field-menu message-mode-map)
7062 (mml-mode)
7063 (setq buffer-read-only nil)
7064 (buffer-enable-undo)
7065 (widen))
7067 (defun gnus-article-edit (&optional force)
7068 "Edit the current article.
7069 This will have permanent effect only in mail groups.
7070 If FORCE is non-nil, allow editing of articles even in read-only
7071 groups."
7072 (interactive "P")
7073 (when (and (not force)
7074 (gnus-group-read-only-p))
7075 (error "The current newsgroup does not support article editing"))
7076 (gnus-article-date-original)
7077 (gnus-article-edit-article
7078 'ignore
7079 `(lambda (no-highlight)
7080 'ignore
7081 (gnus-summary-edit-article-done
7082 ,(or (mail-header-references gnus-current-headers) "")
7083 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7085 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7086 "Start editing the contents of the current article buffer."
7087 (let ((winconf (current-window-configuration)))
7088 (set-buffer gnus-article-buffer)
7089 (let ((message-auto-save-directory
7090 ;; Don't associate the article buffer with a draft file.
7091 nil))
7092 (gnus-article-edit-mode))
7093 (funcall start-func)
7094 (set-buffer-modified-p nil)
7095 (gnus-configure-windows 'edit-article)
7096 (setq gnus-article-edit-done-function exit-func)
7097 (setq gnus-prev-winconf winconf)
7098 (unless quiet
7099 (gnus-message 6 "C-c C-c to end edits"))))
7101 (defun gnus-article-edit-done (&optional arg)
7102 "Update the article edits and exit."
7103 (interactive "P")
7104 (let ((func gnus-article-edit-done-function)
7105 (buf (current-buffer))
7106 (start (window-start))
7107 (p (point))
7108 (winconf gnus-prev-winconf))
7109 (widen) ;; Widen it in case that users narrowed the buffer.
7110 (funcall func arg)
7111 (set-buffer buf)
7112 ;; The cache and backlog have to be flushed somewhat.
7113 (when gnus-keep-backlog
7114 (gnus-backlog-remove-article
7115 (car gnus-article-current) (cdr gnus-article-current)))
7116 ;; Flush original article as well.
7117 (gnus-flush-original-article-buffer)
7118 (when gnus-use-cache
7119 (gnus-cache-update-article
7120 (car gnus-article-current) (cdr gnus-article-current)))
7121 ;; We remove all text props from the article buffer.
7122 (kill-all-local-variables)
7123 (set-text-properties (point-min) (point-max) nil)
7124 (gnus-article-mode)
7125 (set-window-configuration winconf)
7126 (set-buffer buf)
7127 (set-window-start (get-buffer-window buf) start)
7128 (set-window-point (get-buffer-window buf) (point)))
7129 (gnus-summary-show-article))
7131 (defun gnus-flush-original-article-buffer ()
7132 (when (get-buffer gnus-original-article-buffer)
7133 (with-current-buffer gnus-original-article-buffer
7134 (setq gnus-original-article nil))))
7136 (defun gnus-article-edit-exit ()
7137 "Exit the article editing without updating."
7138 (interactive)
7139 (when (or (not (buffer-modified-p))
7140 (yes-or-no-p "Article modified; kill anyway? "))
7141 (let ((curbuf (current-buffer))
7142 (p (point))
7143 (window-start (window-start)))
7144 (erase-buffer)
7145 (if (gnus-buffer-live-p gnus-original-article-buffer)
7146 (insert-buffer-substring gnus-original-article-buffer))
7147 (let ((winconf gnus-prev-winconf))
7148 (kill-all-local-variables)
7149 (gnus-article-mode)
7150 (set-window-configuration winconf)
7151 ;; Tippy-toe some to make sure that point remains where it was.
7152 (save-current-buffer
7153 (set-buffer curbuf)
7154 (set-window-start (get-buffer-window (current-buffer)) window-start)
7155 (goto-char p))))
7156 (gnus-summary-show-article)))
7158 (defun gnus-article-edit-full-stops ()
7159 "Interactively repair spacing at end of sentences."
7160 (interactive)
7161 (save-excursion
7162 (goto-char (point-min))
7163 (search-forward-regexp "^$" nil t)
7164 (let ((case-fold-search nil))
7165 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7168 ;;; Article highlights
7171 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7173 ;;; Internal Variables:
7175 (defcustom gnus-button-url-regexp
7176 (concat
7177 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7178 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7179 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7180 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7181 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7182 (punct "!?:;.,"))
7183 (concat
7184 "\\(?:"
7185 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7186 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7187 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7188 "\\|"
7189 "[" chars punct "]+" "[" chars "]"
7190 "\\)"))
7191 (concat ;; XEmacs 21.4 doesn't support POSIX.
7192 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7193 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7194 "\\)")
7195 "Regular expression that matches URLs."
7196 :group 'gnus-article-buttons
7197 :type 'regexp)
7199 (defcustom gnus-button-valid-fqdn-regexp
7200 message-valid-fqdn-regexp
7201 "Regular expression that matches a valid FQDN."
7202 :version "22.1"
7203 :group 'gnus-article-buttons
7204 :type 'regexp)
7206 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7207 (defcustom gnus-button-valid-localpart-regexp
7208 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7209 "Regular expression that matches a localpart of mail addresses or MIDs."
7210 :version "22.1"
7211 :group 'gnus-article-buttons
7212 :type 'regexp)
7214 (defcustom gnus-button-man-handler 'manual-entry
7215 "Function to use for displaying man pages.
7216 The function must take at least one argument with a string naming the
7217 man page."
7218 :version "22.1"
7219 :type '(choice (function-item :tag "Man" manual-entry)
7220 (function-item :tag "Woman" woman)
7221 (function :tag "Other"))
7222 :group 'gnus-article-buttons)
7224 (defcustom gnus-button-mid-or-mail-regexp
7225 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7226 gnus-button-valid-fqdn-regexp
7227 ">?\\)\\b")
7228 "Regular expression that matches a message ID or a mail address."
7229 :version "22.1"
7230 :group 'gnus-article-buttons
7231 :type 'regexp)
7233 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7234 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7235 Strings like this can be either a message ID or a mail address. If it is one
7236 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7237 message ID or a mail address, respectively. If this variable is set to the
7238 symbol `ask', always query the user what do do. If it is a function, this
7239 function will be called with the string as its only argument. The function
7240 must return `mid', `mail', `invalid' or `ask'."
7241 :version "22.1"
7242 :group 'gnus-article-buttons
7243 :type '(choice (function-item :tag "Heuristic function"
7244 gnus-button-mid-or-mail-heuristic)
7245 (const ask)
7246 (const mid)
7247 (const mail)))
7249 (defcustom gnus-button-mid-or-mail-heuristic-alist
7250 '((-10.0 . ".+\\$.+@")
7251 (-10.0 . "#")
7252 (-10.0 . "\\*")
7253 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7254 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7255 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7256 (-1.0 . "^[^a-z]+@")
7258 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7259 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7260 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7261 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7263 (-2.0 . "^[0-9]")
7264 (-1.0 . "^[0-9][0-9]")
7266 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7267 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7268 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7269 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7271 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7272 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7273 ;; "[0-9]{8,}.*\@"
7274 (-3.0
7275 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7276 ;; "[0-9]{12,}.*\@"
7277 ;; compensation for TDMA dated mail addresses:
7278 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7280 (-20.0 . "\\.fsf@") ;; Gnus
7281 (-20.0 . "^slrn")
7282 (-20.0 . "^Pine")
7283 (-20.0 . "^alpine\\.")
7284 (-20.0 . "_-_") ;; Subject change in thread
7286 (-20.0 . "\\.ln@") ;; leafnode
7287 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7288 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7290 ;; (5.0 . "") ;; $local_part_len <= 7
7291 (10.0 . "^[^0-9]+@")
7292 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7293 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7294 (3.0 . "\@stud")
7296 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7298 (0.5 . "^[A-Z][a-z]")
7299 (0.5 . "^[A-Z][a-z][a-z]")
7300 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7301 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7302 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7304 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7305 address. The REGEXP is processed with `case-fold-search' set to nil."
7306 :version "22.1"
7307 :group 'gnus-article-buttons
7308 :type '(repeat (cons (number :tag "Rate")
7309 (regexp :tag "Regexp"))))
7311 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7312 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7313 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7314 address, `ask' if unsure and `invalid' if the string is invalid."
7315 (let ((case-fold-search nil)
7316 (list gnus-button-mid-or-mail-heuristic-alist)
7317 (result 0) rate regexp lpartlen elem)
7318 (setq lpartlen
7319 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7320 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7321 ;; Certain special cases...
7322 (when (string-match
7323 (concat
7324 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7325 "^[0-9]+\\.[0-9]+@compuserve\\|"
7326 "@public\\.gmane\\.org")
7327 mid-or-mail)
7328 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7329 (setq result 'mail))
7330 (when (string-match "@.*@\\| " mid-or-mail)
7331 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7332 (setq result 'invalid))
7333 ;; Nothing more to do, if result is not a number here...
7334 (when (numberp result)
7335 (while list
7336 (setq elem (car list)
7337 rate (car elem)
7338 regexp (cdr elem)
7339 list (cdr list))
7340 (when (string-match regexp mid-or-mail)
7341 (setq result (+ result rate))
7342 (gnus-message
7343 9 "`%s' matched `%s', rate `%s', result `%s'."
7344 mid-or-mail regexp rate result)))
7345 (when (<= lpartlen 7)
7346 (setq result (+ result 5.0))
7347 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7348 mid-or-mail result))
7349 (when (>= lpartlen 12)
7350 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7351 (cond
7352 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7353 ;; Long local part should contain realname if e-mail address,
7354 ;; too many digits: message-id.
7355 ;; $score -= 5.0 + 0.1 * $local_part_len;
7356 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7357 (setq result (+ result rate))
7358 (gnus-message
7359 9 "Many digits in `%s', rate `%s', result `%s'."
7360 mid-or-mail rate result))
7361 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7362 mid-or-mail)
7363 ;; Too few vowels [^aeiouy]{4,}.*\@
7364 (setq result (+ result -5.0))
7365 (gnus-message
7366 9 "Few vowels in `%s', rate `%s', result `%s'."
7367 mid-or-mail -5.0 result))
7369 (setq result (+ result 5.0))
7370 (gnus-message
7371 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7372 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7373 ;; Maybe we should make this a customizable alist: (condition . 'result)
7374 (cond
7375 ((symbolp result) result)
7376 ;; Now convert number into proper results:
7377 ((< result -10.0) 'mid)
7378 ((> result 10.0) 'mail)
7379 (t 'ask))))
7381 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7382 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7383 (url-mid (concat "news" ":" mid-or-mail))
7384 (url-mailto (concat "mailto" ":" mid-or-mail)))
7385 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7386 (when (fboundp pref)
7387 (setq guessed
7388 ;; get rid of surrounding angles...
7389 (funcall pref
7390 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7391 (if (or (eq 'mid guessed) (eq 'mail guessed))
7392 (setq pref guessed)
7393 (setq pref 'ask)))
7394 (if (eq pref 'ask)
7395 (save-window-excursion
7396 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7397 (setq pref 'mail)
7398 (setq pref 'mid))))
7399 (cond ((eq pref 'mid)
7400 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7401 (gnus-button-handle-news url-mid))
7402 ((eq pref 'mail)
7403 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7404 (gnus-url-mailto url-mailto))
7405 (t (gnus-message 3 "Invalid string.")))))
7407 (defun gnus-button-handle-custom (fun arg)
7408 "Call function FUN on argument ARG.
7409 Both FUN and ARG are supposed to be strings. ARG will be passed
7410 as a symbol to FUN."
7411 (funcall (intern fun)
7412 (if (string-match "^customize-apropos" fun)
7414 (intern arg))))
7416 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7418 (defun gnus-button-handle-describe-function (url)
7419 "Call `describe-function' when pushing the corresponding URL button."
7420 (describe-function
7421 (intern
7422 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7424 (defun gnus-button-handle-describe-variable (url)
7425 "Call `describe-variable' when pushing the corresponding URL button."
7426 (describe-variable
7427 (intern
7428 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7430 (defun gnus-button-handle-symbol (url)
7431 "Display help on variable or function.
7432 Calls `describe-variable' or `describe-function'."
7433 (let ((sym (intern url)))
7434 (cond
7435 ((fboundp sym) (describe-function sym))
7436 ((boundp sym) (describe-variable sym))
7437 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7439 (defun gnus-button-handle-describe-key (url)
7440 "Call `describe-key' when pushing the corresponding URL button."
7441 (let* ((key-string
7442 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7443 (keys (ignore-errors (eval `(kbd ,key-string)))))
7444 (if keys
7445 (describe-key keys)
7446 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7448 (defun gnus-button-handle-apropos (url)
7449 "Call `apropos' when pushing the corresponding URL button."
7450 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7452 (defun gnus-button-handle-apropos-command (url)
7453 "Call `apropos' when pushing the corresponding URL button."
7454 (apropos-command
7455 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7457 (defun gnus-button-handle-apropos-variable (url)
7458 "Call `apropos' when pushing the corresponding URL button."
7459 (funcall
7460 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7461 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7463 (defun gnus-button-handle-apropos-documentation (url)
7464 "Call `apropos' when pushing the corresponding URL button."
7465 (funcall
7466 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7467 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7469 (defun gnus-button-handle-library (url)
7470 "Call `locate-library' when pushing the corresponding URL button."
7471 (gnus-message 9 "url=`%s'" url)
7472 (let* ((lib (locate-library url))
7473 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7474 (if (not lib)
7475 (gnus-message 1 "Cannot locale library `%s'." url)
7476 (find-file-read-only file))))
7478 (defcustom gnus-button-man-level 5
7479 "*Integer that says how many man-related buttons Gnus will show.
7480 The higher the number, the more buttons will appear and the more false
7481 positives are possible. Note that you can set this variable local to
7482 specific groups. Setting it higher in Unix groups is probably a good idea.
7483 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7484 how to set variables in specific groups."
7485 :version "22.1"
7486 :group 'gnus-article-buttons
7487 :link '(custom-manual "(gnus)Group Parameters")
7488 :type 'integer)
7490 (defcustom gnus-button-emacs-level 5
7491 "*Integer that says how many emacs-related buttons Gnus will show.
7492 The higher the number, the more buttons will appear and the more false
7493 positives are possible. Note that you can set this variable local to
7494 specific groups. Setting it higher in Emacs or Gnus related groups is
7495 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7496 `gnus-parameters' on how to set variables in specific groups."
7497 :version "22.1"
7498 :group 'gnus-article-buttons
7499 :link '(custom-manual "(gnus)Group Parameters")
7500 :type 'integer)
7502 (defcustom gnus-button-message-level 5
7503 "*Integer that says how many buttons for news or mail messages will appear.
7504 The higher the number, the more buttons will appear and the more false
7505 positives are possible."
7506 ;; mail addresses, MIDs, URLs for news, ...
7507 :version "22.1"
7508 :group 'gnus-article-buttons
7509 :type 'integer)
7511 (defcustom gnus-button-browse-level 5
7512 "*Integer that says how many buttons for browsing will appear.
7513 The higher the number, the more buttons will appear and the more false
7514 positives are possible."
7515 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7516 :version "22.1"
7517 :group 'gnus-article-buttons
7518 :type 'integer)
7520 (defcustom gnus-button-alist
7521 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7522 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7523 ((concat "\\b\\(nntp\\|news\\):\\("
7524 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7525 0 t gnus-button-handle-news 2)
7526 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7527 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7528 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7529 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7530 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7531 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7532 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7533 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7534 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7535 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7536 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7537 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7538 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7539 ;; RFC 2368 (The mailto URL scheme)
7540 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7541 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7542 ("\\bmailto:\\([^ \n\t]+\\)"
7543 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7544 ;; Info Konqueror style <info:/foo/bar baz>.
7545 ;; Must come before " Gnus home-grown style".
7546 ("\\binfo://?\\([^'\">\n\t]+\\)"
7547 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7548 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7549 ("\\binfo://\\([^'\">\n\t ]+\\)"
7550 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7551 ;; Info GNOME style <info:foo#bar_baz>
7552 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7553 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7554 ;; Info KDE style <info:(foo)bar baz>
7555 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7556 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7557 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7558 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7559 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7560 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7561 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7562 ;; This is custom
7563 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7564 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7565 ;; Emacs help commands
7566 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7567 ;; regexp doesn't match arguments containing ` '.
7568 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7569 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7570 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7571 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7572 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7573 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7574 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7575 ;; The following entries may lead to many false positives so don't enable
7576 ;; them by default (use a high button level).
7577 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7578 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7579 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7580 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7581 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7582 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7583 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7584 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7585 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7586 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7587 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7588 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7589 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7590 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7591 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7592 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7593 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7594 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7595 ;; Unlike the other regexps we really have to require quoting
7596 ;; here to determine where it ends.
7597 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7598 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7599 ("<URL: *\\([^\n<>]*\\)>"
7600 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7601 ;; RFC 2396 (2.4.3., delims) ...
7602 ("\"URL: *\\([^\n\"]*\\)\""
7603 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7604 ;; Raw URLs.
7605 (gnus-button-url-regexp
7606 0 (>= gnus-button-browse-level 0) browse-url 0)
7607 ;; man pages
7608 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7609 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7610 gnus-button-handle-man 1)
7611 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7612 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7613 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7614 gnus-button-handle-man 1)
7615 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7616 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7617 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7618 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7619 ;; Recognizing patches to .el files. This is somewhat obscure,
7620 ;; but considering the percentage of Gnus users who hack Emacs
7621 ;; Lisp files...
7622 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7623 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7624 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7625 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7626 ;; MID or mail: To avoid too many false positives we don't try to catch
7627 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7628 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7629 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7630 ;; so that non-ambiguous entries (see above) match first.
7631 (gnus-button-mid-or-mail-regexp
7632 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7633 "*Alist of regexps matching buttons in article bodies.
7635 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7636 REGEXP: is the string (case insensitive) matching text around the button (can
7637 also be Lisp expression evaluating to a string),
7638 BUTTON: is the number of the regexp grouping actually matching the button,
7639 FORM: is a Lisp expression which must eval to true for the button to
7640 be added,
7641 CALLBACK: is the function to call when the user push this button, and each
7642 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7644 CALLBACK can also be a variable, in that case the value of that
7645 variable it the real callback function."
7646 :group 'gnus-article-buttons
7647 :type '(repeat (list (choice regexp variable sexp)
7648 (integer :tag "Button")
7649 (sexp :tag "Form")
7650 (function :tag "Callback")
7651 (repeat :tag "Par"
7652 :inline t
7653 (integer :tag "Regexp group")))))
7654 (put 'gnus-button-alist 'risky-local-variable t)
7656 (defcustom gnus-header-button-alist
7657 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7658 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7659 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7660 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7661 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7662 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7663 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7664 0 (>= gnus-button-browse-level 0) browse-url 0)
7665 ("^Subject:" gnus-button-url-regexp
7666 0 (>= gnus-button-browse-level 0) browse-url 0)
7667 ("^[^:]+:" gnus-button-url-regexp
7668 0 (>= gnus-button-browse-level 0) browse-url 0)
7669 ("^OpenPGP:.*url=" gnus-button-url-regexp
7670 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7671 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7672 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7673 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7674 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7675 "*Alist of headers and regexps to match buttons in article heads.
7677 This alist is very similar to `gnus-button-alist', except that each
7678 alist has an additional HEADER element first in each entry:
7680 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7682 HEADER is a regexp to match a header. For a fuller explanation, see
7683 `gnus-button-alist'."
7684 :group 'gnus-article-buttons
7685 :group 'gnus-article-headers
7686 :type '(repeat (list (regexp :tag "Header")
7687 (choice regexp variable)
7688 (integer :tag "Button")
7689 (sexp :tag "Form")
7690 (function :tag "Callback")
7691 (repeat :tag "Par"
7692 :inline t
7693 (integer :tag "Regexp group")))))
7694 (put 'gnus-header-button-alist 'risky-local-variable t)
7696 ;;; Commands:
7698 (defun gnus-article-push-button (event)
7699 "Check text under the mouse pointer for a callback function.
7700 If the text under the mouse pointer has a `gnus-callback' property,
7701 call it with the value of the `gnus-data' text property."
7702 (interactive "e")
7703 (set-buffer (window-buffer (posn-window (event-start event))))
7704 (let* ((pos (posn-point (event-start event)))
7705 (data (get-text-property pos 'gnus-data))
7706 (fun (get-text-property pos 'gnus-callback)))
7707 (goto-char pos)
7708 (when fun
7709 (funcall fun data))))
7711 (defun gnus-article-press-button ()
7712 "Check text at point for a callback function.
7713 If the text at point has a `gnus-callback' property,
7714 call it with the value of the `gnus-data' text property."
7715 (interactive)
7716 (let ((data (get-text-property (point) 'gnus-data))
7717 (fun (get-text-property (point) 'gnus-callback)))
7718 (when fun
7719 (funcall fun data))))
7721 (defun gnus-article-highlight (&optional force)
7722 "Highlight current article.
7723 This function calls `gnus-article-highlight-headers',
7724 `gnus-article-highlight-citation',
7725 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7726 do the highlighting. See the documentation for those functions."
7727 (interactive (list 'force))
7728 (gnus-article-highlight-headers)
7729 (gnus-article-highlight-citation force)
7730 (gnus-article-highlight-signature)
7731 (gnus-article-add-buttons)
7732 (gnus-article-add-buttons-to-head))
7734 (defun gnus-article-highlight-some (&optional force)
7735 "Highlight current article.
7736 This function calls `gnus-article-highlight-headers',
7737 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7738 do the highlighting. See the documentation for those functions."
7739 (interactive (list 'force))
7740 (gnus-article-highlight-headers)
7741 (gnus-article-highlight-signature)
7742 (gnus-article-add-buttons))
7744 (defun gnus-article-highlight-headers ()
7745 "Highlight article headers as specified by `gnus-header-face-alist'."
7746 (interactive)
7747 (gnus-with-article-headers
7748 (let (regexp header-face field-face from hpoints fpoints)
7749 (dolist (entry gnus-header-face-alist)
7750 (goto-char (point-min))
7751 (setq regexp (concat "^\\("
7752 (if (string-equal "" (nth 0 entry))
7753 "[^\t ]"
7754 (nth 0 entry))
7755 "\\)")
7756 header-face (nth 1 entry)
7757 field-face (nth 2 entry))
7758 (while (and (re-search-forward regexp nil t)
7759 (not (eobp)))
7760 (beginning-of-line)
7761 (setq from (point))
7762 (unless (search-forward ":" nil t)
7763 (forward-char 1))
7764 (when (and header-face
7765 (not (memq (point) hpoints)))
7766 (push (point) hpoints)
7767 (gnus-put-text-property from (point) 'face header-face))
7768 (when (and field-face
7769 (not (memq (setq from (point)) fpoints)))
7770 (push from fpoints)
7771 (if (re-search-forward "^[^ \t]" nil t)
7772 (forward-char -2)
7773 (goto-char (point-max)))
7774 (gnus-put-text-property from (point) 'face field-face)))))))
7776 (defun gnus-article-highlight-signature ()
7777 "Highlight the signature in an article.
7778 It does this by highlighting everything after
7779 `gnus-signature-separator' using the face `gnus-signature'."
7780 (interactive)
7781 (gnus-with-article-buffer
7782 (let ((inhibit-point-motion-hooks t))
7783 (save-restriction
7784 (when (and gnus-signature-face
7785 (gnus-article-narrow-to-signature))
7786 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7787 'face gnus-signature-face)
7788 (widen)
7789 (gnus-article-search-signature)
7790 (let ((start (match-beginning 0))
7791 (end (set-marker (make-marker) (1+ (match-end 0)))))
7792 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7793 end)))))))
7795 (defun gnus-button-in-region-p (b e prop)
7796 "Say whether PROP exists in the region."
7797 (text-property-not-all b e prop nil))
7799 (defun gnus-article-add-buttons ()
7800 "Find external references in the article and make buttons of them.
7801 \"External references\" are things like Message-IDs and URLs, as
7802 specified by `gnus-button-alist'."
7803 (interactive)
7804 (gnus-with-article-buffer
7805 (let ((inhibit-point-motion-hooks t)
7806 (case-fold-search t)
7807 (alist gnus-button-alist)
7808 beg entry regexp)
7809 ;; We skip the headers.
7810 (article-goto-body)
7811 (setq beg (point))
7812 (while (setq entry (pop alist))
7813 (setq regexp (eval (car entry)))
7814 (goto-char beg)
7815 (while (re-search-forward regexp nil t)
7816 (let ((start (match-beginning (nth 1 entry)))
7817 (end (match-end (nth 1 entry)))
7818 (from (match-beginning 0)))
7819 (when (and (eval (nth 2 entry))
7820 (not (gnus-button-in-region-p
7821 start end 'gnus-callback)))
7822 ;; That optional form returned non-nil, so we add the
7823 ;; button.
7824 (setq from (set-marker (make-marker) from))
7825 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7826 (gnus-article-extend-url-button from start end))
7827 (gnus-article-add-button start end
7828 'gnus-button-push (list from entry))
7829 (gnus-put-text-property
7830 start end
7831 'gnus-string (buffer-substring-no-properties
7832 start end))))))))))
7834 (defun gnus-article-extend-url-button (beg start end)
7835 "Extend url button if url is folded into two or more lines.
7836 Return non-nil if button is extended. BEG is a marker that points to
7837 the beginning position of a text containing url. START and END are
7838 the endpoints of a url button before it is extended. The concatenated
7839 url is put as the `gnus-button-url' overlay property on the button."
7840 (let ((opoint (point))
7841 (points (list start end))
7842 url delim regexp)
7843 (prog1
7844 (when (and (progn
7845 (goto-char end)
7846 (not (looking-at "[\t ]*[\">]")))
7847 (progn
7848 (goto-char start)
7849 (string-match
7850 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7851 (buffer-substring (point-at-bol) start)))
7852 (progn
7853 (setq url (list (buffer-substring start end))
7854 delim (if (match-beginning 1) ">" "\""))
7855 (beginning-of-line)
7856 (setq regexp (concat
7857 (when (and (looking-at
7858 message-cite-prefix-regexp)
7859 (< (match-end 0) start))
7860 (regexp-quote (match-string 0)))
7862 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7863 delim "\\)"))
7864 (while (progn
7865 (forward-line 1)
7866 (and (looking-at regexp)
7867 (prog1
7868 (match-beginning 1)
7869 (push (or (match-string 2)
7870 (match-string 1))
7871 url)
7872 (push (setq end (or (match-end 2)
7873 (match-end 1)))
7874 points)
7875 (push (or (match-beginning 2)
7876 (match-beginning 1))
7877 points)))))
7878 (match-beginning 2)))
7879 (let (gnus-article-mouse-face widget-mouse-face)
7880 (while points
7881 (gnus-article-add-button (pop points) (pop points)
7882 'gnus-button-push beg)))
7883 (let ((overlay (gnus-make-overlay start end)))
7884 (gnus-overlay-put overlay 'evaporate t)
7885 (gnus-overlay-put overlay 'gnus-button-url
7886 (list (mapconcat 'identity (nreverse url) "")))
7887 (when gnus-article-mouse-face
7888 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7890 (goto-char opoint))))
7892 ;; Add buttons to the head of an article.
7893 (defun gnus-article-add-buttons-to-head ()
7894 "Add buttons to the head of the article."
7895 (interactive)
7896 (gnus-with-article-headers
7897 (let (beg end)
7898 (dolist (entry gnus-header-button-alist)
7899 ;; Each alist entry.
7900 (goto-char (point-min))
7901 (while (re-search-forward (car entry) nil t)
7902 ;; Each header matching the entry.
7903 (setq beg (match-beginning 0))
7904 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7905 (match-beginning 0))
7906 (point-max)))
7907 (goto-char beg)
7908 (while (re-search-forward (eval (nth 1 entry)) end t)
7909 ;; Each match within a header.
7910 (let* ((entry (cdr entry))
7911 (start (match-beginning (nth 1 entry)))
7912 (end (match-end (nth 1 entry)))
7913 (form (nth 2 entry)))
7914 (goto-char (match-end 0))
7915 (when (eval form)
7916 (gnus-article-add-button
7917 start end (nth 3 entry)
7918 (buffer-substring (match-beginning (nth 4 entry))
7919 (match-end (nth 4 entry)))))))
7920 (goto-char end))))))
7922 ;;; External functions:
7924 (defun gnus-article-add-button (from to fun &optional data text)
7925 "Create a button between FROM and TO with callback FUN and data DATA."
7926 (when gnus-article-button-face
7927 (gnus-overlay-put (gnus-make-overlay from to nil t)
7928 'face gnus-article-button-face))
7929 (gnus-add-text-properties
7930 from to
7931 (nconc (and gnus-article-mouse-face
7932 (list gnus-mouse-face-prop gnus-article-mouse-face))
7933 (list 'gnus-callback fun)
7934 (and data (list 'gnus-data data))))
7935 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7936 :help-echo (or text "Follow the link")
7937 :keymap gnus-url-button-map
7938 :button-keymap gnus-widget-button-keymap))
7940 (defun gnus-article-copy-string ()
7941 "Copy the string in the button to the kill ring."
7942 (interactive)
7943 (gnus-article-check-buffer)
7944 (let ((data (get-text-property (point) 'gnus-string)))
7945 (when data
7946 (with-temp-buffer
7947 (insert data)
7948 (copy-region-as-kill (point-min) (point-max))
7949 (message "Copied %s" data)))))
7951 ;;; Internal functions:
7953 (defun gnus-article-set-globals ()
7954 (with-current-buffer gnus-summary-buffer
7955 (gnus-set-global-variables)))
7957 (defun gnus-signature-toggle (end)
7958 (gnus-with-article-buffer
7959 (let ((inhibit-point-motion-hooks t))
7960 (if (text-property-any end (point-max) 'article-type 'signature)
7961 (progn
7962 (gnus-delete-wash-type 'signature)
7963 (gnus-remove-text-properties-when
7964 'article-type 'signature end (point-max)
7965 (cons 'article-type (cons 'signature
7966 gnus-hidden-properties))))
7967 (gnus-add-wash-type 'signature)
7968 (gnus-add-text-properties-when
7969 'article-type nil end (point-max)
7970 (cons 'article-type (cons 'signature
7971 gnus-hidden-properties)))))
7972 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7973 (gnus-set-mode-line 'article))))
7975 (defun gnus-button-push (marker-and-entry)
7976 ;; Push button starting at MARKER.
7977 (save-excursion
7978 (let* ((marker (car marker-and-entry))
7979 (entry (cadr marker-and-entry))
7980 (regexp (car entry))
7981 (inhibit-point-motion-hooks t))
7982 (goto-char marker)
7983 ;; This is obviously true, or something bad is happening :)
7984 ;; But we need it to have the match-data
7985 (when (looking-at (or (if (symbolp regexp)
7986 (symbol-value regexp)
7987 regexp)))
7988 (let ((fun (nth 3 entry))
7989 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7990 (get-char-property marker 'gnus-button-url))
7991 (mapcar (lambda (group)
7992 (let ((string (match-string group)))
7993 (set-text-properties
7994 0 (length string) nil string)
7995 string))
7996 (nthcdr 4 entry)))))
7998 (cond
7999 ((fboundp fun)
8000 (apply fun args))
8001 ((and (boundp fun)
8002 (fboundp (symbol-value fun)))
8003 (apply (symbol-value fun) args))
8005 (gnus-message 1 "You must define `%S' to use this button"
8006 (cons fun args)))))))))
8008 (defun gnus-parse-news-url (url)
8009 (let (scheme server port group message-id articles)
8010 (with-temp-buffer
8011 (insert url)
8012 (goto-char (point-min))
8013 (when (looking-at "\\([A-Za-z]+\\):")
8014 (setq scheme (match-string 1))
8015 (goto-char (match-end 0)))
8016 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8017 (setq server (match-string 1))
8018 (setq port (if (stringp (match-string 3))
8019 (string-to-number (match-string 3))
8020 (match-string 3)))
8021 (goto-char (match-end 0)))
8023 (cond
8024 ((looking-at "\\(.*@.*\\)")
8025 (setq message-id (match-string 1)))
8026 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8027 (setq group (match-string 1)
8028 articles (split-string (match-string 2) "-")))
8029 ((looking-at "\\([^/]+\\)/?")
8030 (setq group (match-string 1)))
8032 (error "Unknown news URL syntax"))))
8033 (list scheme server port group message-id articles)))
8035 (defun gnus-button-handle-news (url)
8036 "Fetch a news URL."
8037 (destructuring-bind (scheme server port group message-id articles)
8038 (gnus-parse-news-url url)
8039 (cond
8040 (message-id
8041 (with-current-buffer gnus-summary-buffer
8042 (if server
8043 (let ((gnus-refer-article-method
8044 (nconc (list (list 'nntp server))
8045 gnus-refer-article-method))
8046 (nntp-port-number (or port "nntp")))
8047 (gnus-message 7 "Fetching %s with %s"
8048 message-id gnus-refer-article-method)
8049 (gnus-summary-refer-article message-id))
8050 (gnus-summary-refer-article message-id))))
8051 (group
8052 (gnus-button-fetch-group url)))))
8054 (defun gnus-button-patch (library line)
8055 "Visit an Emacs Lisp library LIBRARY on line LINE."
8056 (interactive)
8057 (let ((file (locate-library (file-name-nondirectory library))))
8058 (unless file
8059 (error "Couldn't find library %s" library))
8060 (find-file file)
8061 (goto-char (point-min))
8062 (forward-line (1- (string-to-number line)))))
8064 (defun gnus-button-handle-man (url)
8065 "Fetch a man page."
8066 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8067 (when (eq gnus-button-man-handler 'woman)
8068 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8069 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8070 (funcall gnus-button-man-handler url))
8072 (defun gnus-button-handle-info-url (url)
8073 "Fetch an info URL."
8074 (setq url (mm-subst-char-in-string ?+ ?\ url))
8075 (cond
8076 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8077 (gnus-info-find-node
8078 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8079 "Gnus")
8080 ")" (gnus-url-unhex-string (match-string 2 url)))))
8081 ((string-match "([^)\"]+)[^\"]+" url)
8082 (setq url
8083 (gnus-replace-in-string
8084 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8085 (gnus-info-find-node url))
8086 (t (error "Can't parse %s" url))))
8088 (defun gnus-button-handle-info-url-gnome (url)
8089 "Fetch GNOME style info URL."
8090 (setq url (mm-subst-char-in-string ?_ ?\ url))
8091 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8092 (gnus-info-find-node
8093 (concat "("
8094 (gnus-url-unhex-string
8095 (match-string 1 url))
8097 (or (gnus-url-unhex-string
8098 (match-string 2 url))
8099 "Top")))
8100 (error "Can't parse %s" url)))
8102 (defun gnus-button-handle-info-url-kde (url)
8103 "Fetch KDE style info URL."
8104 (gnus-info-find-node (gnus-url-unhex-string url)))
8106 ;; (info) will autoload info.el
8107 (declare-function Info-menu "info" (menu-item &optional fork))
8108 (declare-function Info-index-next "info" (num))
8110 (defun gnus-button-handle-info-keystrokes (url)
8111 "Call `info' when pushing the corresponding URL button."
8112 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8113 (let (node indx comma)
8114 (if (string-match
8115 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8116 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8117 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8118 "\\(?:[ \t\n,]*\\)\\)?")
8119 url)
8120 (setq node (match-string 2 url)
8121 indx (match-string 3 url))
8122 (error "Can't parse %s" url))
8123 (info)
8124 (Info-directory)
8125 (Info-menu node)
8126 (when (> (length indx) 0)
8127 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8128 "\\([ \t\n,]*\\)")
8129 indx)
8130 (setq comma (match-string 2 indx))
8131 (setq indx (match-string 1 indx))
8132 (Info-index indx)
8133 (when comma
8134 (dotimes (i (with-temp-buffer
8135 (insert comma)
8136 ;; Note: the XEmacs version of `how-many' takes
8137 ;; no optional argument.
8138 (goto-char (point-min))
8139 (how-many ",")))
8140 (Info-index-next 1)))
8141 nil)))
8143 (autoload 'pgg-snarf-keys-region "pgg")
8144 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8145 (declare-function pgg-display-output-buffer "pgg" (start end status))
8147 (defun gnus-button-openpgp (url)
8148 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8149 (with-temp-buffer
8150 (mm-url-insert-file-contents-external url)
8151 (pgg-snarf-keys-region (point-min) (point-max))
8152 (pgg-display-output-buffer nil nil nil)))
8154 (defun gnus-button-message-id (message-id)
8155 "Fetch MESSAGE-ID."
8156 (with-current-buffer gnus-summary-buffer
8157 (gnus-summary-refer-article message-id)))
8159 (defun gnus-button-fetch-group (address &rest ignore)
8160 "Fetch GROUP specified by ADDRESS."
8161 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8162 address)
8163 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8164 ;; for nntp:// and news://
8165 (setq address (match-string 3 address)))
8166 (if (not (string-match "[:/]" address))
8167 ;; This is just a simple group url.
8168 (gnus-group-read-ephemeral-group address gnus-select-method)
8169 (if (not
8170 (string-match
8171 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8172 address))
8173 (error "Can't parse %s" address)
8174 (gnus-group-read-ephemeral-group
8175 (match-string 4 address)
8176 `(nntp ,(match-string 1 address)
8177 (nntp-address ,(match-string 1 address))
8178 (nntp-port-number ,(if (match-end 3)
8179 (match-string 3 address)
8180 "nntp")))
8181 nil nil nil
8182 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8184 (defun gnus-url-parse-query-string (query &optional downcase)
8185 (let (retval pairs cur key val)
8186 (setq pairs (split-string query "&"))
8187 (while pairs
8188 (setq cur (car pairs)
8189 pairs (cdr pairs))
8190 (if (not (string-match "=" cur))
8191 nil ; Grace
8192 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8193 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8194 (if downcase
8195 (setq key (downcase key)))
8196 (setq cur (assoc key retval))
8197 (if cur
8198 (setcdr cur (cons val (cdr cur)))
8199 (setq retval (cons (list key val) retval)))))
8200 retval))
8202 (defun gnus-url-mailto (url)
8203 ;; Send mail to someone
8204 (setq url (replace-regexp-in-string "\n" " " url))
8205 (when (string-match "mailto:/*\\(.*\\)" url)
8206 (setq url (substring url (match-beginning 1) nil)))
8207 (let (to args subject func)
8208 (setq args (gnus-url-parse-query-string
8209 (if (string-match "^\\?" url)
8210 (substring url 1)
8211 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8212 (concat "to=" (match-string 1 url) "&"
8213 (match-string 2 url))
8214 (concat "to=" url))))
8215 subject (cdr-safe (assoc "subject" args)))
8216 (gnus-msg-mail)
8217 (while args
8218 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8219 (if (fboundp func)
8220 (funcall func)
8221 (message-position-on-field (caar args)))
8222 (insert (gnus-replace-in-string
8223 (mapconcat 'identity (reverse (cdar args)) ", ")
8224 "\r\n" "\n" t))
8225 (setq args (cdr args)))
8226 (if subject
8227 (message-goto-body)
8228 (message-goto-subject))))
8230 (defun gnus-button-embedded-url (address)
8231 "Activate ADDRESS with `browse-url'."
8232 (browse-url (gnus-strip-whitespace address)))
8234 ;;; Next/prev buttons in the article buffer.
8236 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8237 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8239 (defvar gnus-prev-page-map
8240 (let ((map (make-sparse-keymap)))
8241 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8242 (define-key map "\r" 'gnus-button-prev-page)
8243 map))
8245 (defvar gnus-next-page-map
8246 (let ((map (make-sparse-keymap)))
8247 (define-key map gnus-mouse-2 'gnus-button-next-page)
8248 (define-key map "\r" 'gnus-button-next-page)
8249 map))
8251 (defun gnus-insert-prev-page-button ()
8252 (let ((b (point)) e
8253 (inhibit-read-only t))
8254 (gnus-eval-format
8255 gnus-prev-page-line-format nil
8256 `(keymap ,gnus-prev-page-map
8257 gnus-prev t
8258 gnus-callback gnus-article-button-prev-page
8259 article-type annotation))
8260 (setq e (if (bolp)
8261 ;; Exclude a newline.
8262 (1- (point))
8263 (point)))
8264 (when gnus-article-button-face
8265 (gnus-overlay-put (gnus-make-overlay b e nil t)
8266 'face gnus-article-button-face))
8267 (widget-convert-button
8268 'link b e
8269 :action 'gnus-button-prev-page
8270 :button-keymap gnus-prev-page-map)))
8272 (defun gnus-button-next-page (&optional args more-args)
8273 "Go to the next page."
8274 (interactive)
8275 (let ((win (selected-window)))
8276 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8277 (gnus-article-next-page)
8278 (select-window win)))
8280 (defun gnus-button-prev-page (&optional args more-args)
8281 "Go to the prev page."
8282 (interactive)
8283 (let ((win (selected-window)))
8284 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8285 (gnus-article-prev-page)
8286 (select-window win)))
8288 (defun gnus-insert-next-page-button ()
8289 (let ((b (point)) e
8290 (inhibit-read-only t))
8291 (gnus-eval-format gnus-next-page-line-format nil
8292 `(keymap ,gnus-next-page-map
8293 gnus-next t
8294 gnus-callback gnus-article-button-next-page
8295 article-type annotation))
8296 (setq e (if (bolp)
8297 ;; Exclude a newline.
8298 (1- (point))
8299 (point)))
8300 (when gnus-article-button-face
8301 (gnus-overlay-put (gnus-make-overlay b e nil t)
8302 'face gnus-article-button-face))
8303 (widget-convert-button
8304 'link b e
8305 :action 'gnus-button-next-page
8306 :button-keymap gnus-next-page-map)))
8308 (defun gnus-article-button-next-page (arg)
8309 "Go to the next page."
8310 (interactive "P")
8311 (let ((win (selected-window)))
8312 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8313 (gnus-article-next-page)
8314 (select-window win)))
8316 (defun gnus-article-button-prev-page (arg)
8317 "Go to the prev page."
8318 (interactive "P")
8319 (let ((win (selected-window)))
8320 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8321 (gnus-article-prev-page)
8322 (select-window win)))
8324 (defvar gnus-decode-header-methods
8325 '(mail-decode-encoded-word-region)
8326 "List of methods used to decode headers.
8328 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8329 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8330 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8331 whose names match REGEXP.
8333 For example:
8334 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8335 mail-decode-encoded-word-region
8336 (\"chinese\" . rfc1843-decode-region))
8339 (defvar gnus-decode-header-methods-cache nil)
8341 (defun gnus-multi-decode-header (start end)
8342 "Apply the functions from `gnus-encoded-word-methods' that match."
8343 (unless (and gnus-decode-header-methods-cache
8344 (eq gnus-newsgroup-name
8345 (car gnus-decode-header-methods-cache)))
8346 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8347 (dolist (x gnus-decode-header-methods)
8348 (if (symbolp x)
8349 (nconc gnus-decode-header-methods-cache (list x))
8350 (if (and gnus-newsgroup-name
8351 (string-match (car x) gnus-newsgroup-name))
8352 (nconc gnus-decode-header-methods-cache
8353 (list (cdr x)))))))
8354 (let ((xlist gnus-decode-header-methods-cache))
8355 (pop xlist)
8356 (save-restriction
8357 (narrow-to-region start end)
8358 (while xlist
8359 (funcall (pop xlist) (point-min) (point-max))))))
8362 ;;; Treatment top-level handling.
8365 (defvar gnus-inhibit-article-treatments nil)
8367 (defun gnus-treat-article (gnus-treat-condition
8368 &optional part-number total-parts gnus-treat-type)
8369 (let ((gnus-treat-length (- (point-max) (point-min)))
8370 (alist gnus-treatment-function-alist)
8371 (article-goto-body-goes-to-point-min-p t)
8372 (treated-type
8373 (or (not gnus-treat-type)
8374 (catch 'found
8375 (let ((list gnus-article-treat-types))
8376 (while list
8377 (when (string-match (pop list) gnus-treat-type)
8378 (throw 'found t)))))))
8379 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8380 val elem)
8381 (gnus-run-hooks 'gnus-part-display-hook)
8382 (dolist (elem alist)
8383 (setq val
8384 (save-excursion
8385 (when (gnus-buffer-live-p gnus-summary-buffer)
8386 (set-buffer gnus-summary-buffer))
8387 (symbol-value (car elem))))
8388 (when (and (or (consp val)
8389 treated-type)
8390 (or (not gnus-inhibit-article-treatments)
8391 (eq gnus-treat-condition 'head))
8392 (gnus-treat-predicate val)
8393 (or (not (get (car elem) 'highlight))
8394 highlightp))
8395 (save-restriction
8396 (funcall (cadr elem)))))))
8398 ;; Dynamic variables.
8399 (defvar part-number)
8400 (defvar total-parts)
8401 (defvar gnus-treat-type)
8402 (defvar gnus-treat-condition)
8403 (defvar gnus-treat-length)
8405 (defun gnus-treat-predicate (val)
8406 (cond
8407 ((null val)
8408 nil)
8409 (gnus-treat-condition
8410 (eq gnus-treat-condition val))
8411 ((and (listp val)
8412 (stringp (car val)))
8413 (apply 'gnus-or (mapcar `(lambda (s)
8414 (string-match s ,(or gnus-newsgroup-name "")))
8415 val)))
8416 ((listp val)
8417 (let ((pred (pop val)))
8418 (cond
8419 ((eq pred 'or)
8420 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8421 ((eq pred 'and)
8422 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8423 ((eq pred 'not)
8424 (not (gnus-treat-predicate (car val))))
8425 ((eq pred 'typep)
8426 (equal (car val) gnus-treat-type))
8428 (error "%S is not a valid predicate" pred)))))
8429 ((eq val t)
8431 ((eq val 'head)
8432 nil)
8433 ((eq val 'first)
8434 (eq part-number 1))
8435 ((eq val 'last)
8436 (eq part-number total-parts))
8437 ((numberp val)
8438 (< gnus-treat-length val))
8440 (error "%S is not a valid value" val))))
8442 (defun gnus-article-encrypt-body (protocol &optional n)
8443 "Encrypt the article body."
8444 (interactive
8445 (list
8446 (or gnus-article-encrypt-protocol
8447 (gnus-completing-read "Encrypt protocol"
8448 (mapcar 'car gnus-article-encrypt-protocol-alist)
8450 current-prefix-arg))
8451 ;; User might hit `K E' instead of `K e', so prompt once.
8452 (when (and gnus-article-encrypt-protocol
8453 gnus-novice-user)
8454 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8455 (error "Encrypt aborted")))
8456 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8457 (unless func
8458 (error "Can't find the encrypt protocol %s" protocol))
8459 (if (member gnus-newsgroup-name '("nndraft:delayed"
8460 "nndraft:drafts"
8461 "nndraft:queue"))
8462 (error "Can't encrypt the article in group %s"
8463 gnus-newsgroup-name))
8464 (gnus-summary-iterate n
8465 (with-current-buffer gnus-summary-buffer
8466 (let ((mail-parse-charset gnus-newsgroup-charset)
8467 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8468 (summary-buffer gnus-summary-buffer)
8469 references point)
8470 (gnus-set-global-variables)
8471 (when (gnus-group-read-only-p)
8472 (error "The current newsgroup does not support article encrypt"))
8473 (gnus-summary-show-article t)
8474 (setq references
8475 (or (mail-header-references gnus-current-headers) ""))
8476 (set-buffer gnus-article-buffer)
8477 (let* ((inhibit-read-only t)
8478 (headers
8479 (mapcar (lambda (field)
8480 (and (save-restriction
8481 (message-narrow-to-head)
8482 (goto-char (point-min))
8483 (search-forward field nil t))
8484 (prog2
8485 (message-narrow-to-field)
8486 (buffer-string)
8487 (delete-region (point-min) (point-max))
8488 (widen))))
8489 '("Content-Type:" "Content-Transfer-Encoding:"
8490 "Content-Disposition:"))))
8491 (message-narrow-to-head)
8492 (message-remove-header "MIME-Version")
8493 (goto-char (point-max))
8494 (setq point (point))
8495 (insert (apply 'concat headers))
8496 (widen)
8497 (narrow-to-region point (point-max))
8498 (let ((message-options message-options))
8499 (message-options-set 'message-sender user-mail-address)
8500 (message-options-set 'message-recipients user-mail-address)
8501 (message-options-set 'message-sign-encrypt 'not)
8502 (funcall func))
8503 (goto-char (point-min))
8504 (insert "MIME-Version: 1.0\n")
8505 (widen)
8506 (gnus-summary-edit-article-done
8507 references nil summary-buffer t))
8508 (when gnus-keep-backlog
8509 (gnus-backlog-remove-article
8510 (car gnus-article-current) (cdr gnus-article-current)))
8511 (gnus-flush-original-article-buffer)
8512 (when gnus-use-cache
8513 (gnus-cache-update-article
8514 (car gnus-article-current) (cdr gnus-article-current))))))))
8516 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8517 "The following specs can be used:
8518 %t The security MIME type
8519 %i Additional info
8520 %d Details
8521 %D Details if button is pressed")
8523 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8524 "The following specs can be used:
8525 %t The security MIME type
8526 %i Additional info
8527 %d Details
8528 %D Details if button is pressed")
8530 (defvar gnus-mime-security-button-line-format-alist
8531 '((?t gnus-tmp-type ?s)
8532 (?i gnus-tmp-info ?s)
8533 (?d gnus-tmp-details ?s)
8534 (?D gnus-tmp-pressed-details ?s)))
8536 (defvar gnus-mime-security-button-commands
8537 '((gnus-article-press-button "\r" "Show Detail")
8538 (undefined "v")
8539 (undefined "t")
8540 (undefined "C")
8541 (gnus-mime-security-save-part "o" "Save...")
8542 (undefined "\C-o")
8543 (undefined "r")
8544 (undefined "d")
8545 (undefined "c")
8546 (undefined "i")
8547 (undefined "E")
8548 (undefined "e")
8549 (undefined "p")
8550 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8551 (undefined ".")))
8553 (defvar gnus-mime-security-button-map
8554 (let ((map (make-sparse-keymap)))
8555 (define-key map gnus-mouse-2 'gnus-article-push-button)
8556 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8557 (dolist (c gnus-mime-security-button-commands)
8558 (define-key map (cadr c) (car c)))
8559 map))
8561 (easy-menu-define
8562 gnus-mime-security-button-menu gnus-mime-security-button-map
8563 "Security button menu."
8564 `("Security Part"
8565 ,@(delq nil
8566 (mapcar (lambda (c)
8567 (unless (eq (car c) 'undefined)
8568 (vector (caddr c) (car c) :active t)))
8569 gnus-mime-security-button-commands))))
8571 (defun gnus-mime-security-button-menu (event prefix)
8572 "Construct a context-sensitive menu of security commands."
8573 (interactive "e\nP")
8574 (save-window-excursion
8575 (let ((pos (event-start event)))
8576 (select-window (posn-window pos))
8577 (goto-char (posn-point pos))
8578 (gnus-article-check-buffer)
8579 (popup-menu gnus-mime-security-button-menu nil prefix))))
8581 (defvar gnus-mime-security-details-buffer nil)
8583 (defvar gnus-mime-security-button-pressed nil)
8585 (defvar gnus-mime-security-show-details-inline t
8586 "If non-nil, show details in the article buffer.")
8588 (defun gnus-mime-security-verify-or-decrypt (handle)
8589 (mm-remove-parts (cdr handle))
8590 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8591 point (inhibit-read-only t))
8592 (if region
8593 (goto-char (car region)))
8594 (setq point (point))
8595 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8596 (let* ((mm-verify-option 'known)
8597 (mm-decrypt-option 'known)
8598 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8599 (unless (eq nparts (cdr handle))
8600 (mm-destroy-parts (cdr handle))
8601 (setcdr handle nparts))))
8602 (gnus-mime-display-security handle)
8603 (when region
8604 (delete-region (point) (cdr region))
8605 (set-marker (car region) nil)
8606 (set-marker (cdr region) nil))
8607 (goto-char point)))
8609 (defun gnus-mime-security-show-details (handle)
8610 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8611 (if (not details)
8612 (gnus-message 5 "No details.")
8613 (if gnus-mime-security-show-details-inline
8614 (let ((gnus-mime-security-button-pressed
8615 (not (get-text-property (point) 'gnus-mime-details)))
8616 (gnus-mime-security-button-line-format
8617 (get-text-property (point) 'gnus-line-format))
8618 (inhibit-read-only t))
8619 (forward-char -1)
8620 (while (eq (get-text-property (point) 'gnus-line-format)
8621 gnus-mime-security-button-line-format)
8622 (forward-char -1))
8623 (forward-char)
8624 (save-restriction
8625 (narrow-to-region (point) (point))
8626 (gnus-insert-mime-security-button handle))
8627 (delete-region (point)
8628 (or (text-property-not-all
8629 (point) (point-max)
8630 'gnus-line-format
8631 gnus-mime-security-button-line-format)
8632 (point-max))))
8633 ;; Not inlined.
8634 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8635 (with-current-buffer gnus-mime-security-details-buffer
8636 (erase-buffer)
8638 (setq gnus-mime-security-details-buffer
8639 (gnus-get-buffer-create "*MIME Security Details*")))
8640 (with-current-buffer gnus-mime-security-details-buffer
8641 (insert details)
8642 (goto-char (point-min)))
8643 (pop-to-buffer gnus-mime-security-details-buffer)))))
8645 (defun gnus-mime-security-press-button (handle)
8646 (save-excursion
8647 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8648 (gnus-mime-security-show-details handle)
8649 (gnus-mime-security-verify-or-decrypt handle))))
8651 (defun gnus-insert-mime-security-button (handle &optional displayed)
8652 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8653 (gnus-tmp-type
8654 (concat
8655 (or (nth 2 (assoc protocol mm-verify-function-alist))
8656 (nth 2 (assoc protocol mm-decrypt-function-alist))
8657 "Unknown")
8658 (if (equal (car handle) "multipart/signed")
8659 " Signed" " Encrypted")
8660 " Part"))
8661 (gnus-tmp-info
8662 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8663 "Undecided"))
8664 (gnus-tmp-details
8665 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8666 gnus-tmp-pressed-details
8667 b e)
8668 (setq gnus-tmp-details
8669 (if gnus-tmp-details
8670 (concat "\n" gnus-tmp-details)
8671 ""))
8672 (setq gnus-tmp-pressed-details
8673 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8674 (unless (bolp)
8675 (insert "\n"))
8676 (setq b (point))
8677 (gnus-eval-format
8678 gnus-mime-security-button-line-format
8679 gnus-mime-security-button-line-format-alist
8680 `(keymap ,gnus-mime-security-button-map
8681 gnus-callback gnus-mime-security-press-button
8682 gnus-line-format ,gnus-mime-security-button-line-format
8683 gnus-mime-details ,gnus-mime-security-button-pressed
8684 article-type annotation
8685 gnus-data ,handle))
8686 (setq e (if (bolp)
8687 ;; Exclude a newline.
8688 (1- (point))
8689 (point)))
8690 (when gnus-article-button-face
8691 (gnus-overlay-put (gnus-make-overlay b e nil t)
8692 'face gnus-article-button-face))
8693 (widget-convert-button
8694 'link b e
8695 :mime-handle handle
8696 :action 'gnus-widget-press-button
8697 :button-keymap gnus-mime-security-button-map
8698 :help-echo
8699 (lambda (widget)
8700 ;; Needed to properly clear the message due to a bug in
8701 ;; wid-edit (XEmacs only).
8702 (when (boundp 'help-echo-owns-message)
8703 (setq help-echo-owns-message t))
8704 (format
8705 "%S: show detail; %S: more options"
8706 (aref gnus-mouse-2 0)
8707 (aref gnus-down-mouse-3 0))))))
8709 (defun gnus-mime-display-security (handle)
8710 (save-restriction
8711 (narrow-to-region (point) (point))
8712 (unless (gnus-unbuttonized-mime-type-p (car handle))
8713 (gnus-insert-mime-security-button handle))
8714 (gnus-mime-display-part (cadr handle))
8715 (unless (bolp)
8716 (insert "\n"))
8717 (unless (gnus-unbuttonized-mime-type-p (car handle))
8718 (let ((gnus-mime-security-button-line-format
8719 gnus-mime-security-button-end-line-format))
8720 (gnus-insert-mime-security-button handle)))
8721 (mm-set-handle-multipart-parameter
8722 handle 'gnus-region
8723 (cons (set-marker (make-marker) (point-min))
8724 (set-marker (make-marker) (point-max))))
8725 (goto-char (point-max))))
8727 (defun gnus-mime-security-run-function (function)
8728 "Run FUNCTION with the security part under point."
8729 (gnus-article-check-buffer)
8730 (let ((data (get-text-property (point) 'gnus-data))
8731 buffer handle)
8732 (when (and (stringp (car-safe data))
8733 (setq buffer (mm-handle-multipart-original-buffer data))
8734 (setq handle (cadr data)))
8735 (if (bufferp (mm-handle-buffer handle))
8736 (progn
8737 (setq handle (cons buffer (copy-sequence (cdr handle))))
8738 (mm-handle-set-undisplayer handle nil))
8739 (setq handle (mm-make-handle
8740 buffer
8741 (mm-handle-multipart-ctl-parameter handle 'protocol)
8742 nil nil nil nil nil nil)))
8743 (funcall function handle))))
8745 (defun gnus-mime-security-save-part ()
8746 "Save the security part under point."
8747 (interactive)
8748 (gnus-mime-security-run-function 'mm-save-part))
8750 (defun gnus-mime-security-pipe-part ()
8751 "Pipe the security part under point to a process."
8752 (interactive)
8753 (gnus-mime-security-run-function 'mm-pipe-part))
8755 (gnus-ems-redefine)
8757 (provide 'gnus-art)
8759 (run-hooks 'gnus-art-load-hook)
8761 ;;; gnus-art.el ends here