]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / gnus / gnus-art.el
1 ;;; gnus-art.el --- article mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 ;; For Emacs < 22.2.
31 (eval-and-compile
32 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (eval-when-compile
34 (require 'cl))
35 (defvar tool-bar-map)
36 (defvar w3m-minor-mode-map)
37
38 (require 'gnus)
39 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
40 (eval-and-compile
41 (let ((recursive-load-depth-limit 100))
42 (require 'gnus-sum)))
43 (require 'gnus-spec)
44 (require 'gnus-int)
45 (require 'gnus-win)
46 (require 'mm-bodies)
47 (require 'mail-parse)
48 (require 'mm-decode)
49 (require 'mm-view)
50 (require 'wid-edit)
51 (require 'mm-uu)
52 (require 'message)
53
54 (autoload 'gnus-msg-mail "gnus-msg" nil t)
55 (autoload 'gnus-button-mailto "gnus-msg")
56 (autoload 'gnus-button-reply "gnus-msg" nil t)
57 (autoload 'parse-time-string "parse-time" nil nil)
58 (autoload 'ansi-color-apply-on-region "ansi-color")
59 (autoload 'mm-url-insert-file-contents-external "mm-url")
60 (autoload 'mm-extern-cache-contents "mm-extern")
61
62 (defgroup gnus-article nil
63 "Article display."
64 :link '(custom-manual "(gnus)Article Buffer")
65 :group 'gnus)
66
67 (defgroup gnus-article-treat nil
68 "Treating article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
70 :group 'gnus-article)
71
72 (defgroup gnus-article-hiding nil
73 "Hiding article parts."
74 :link '(custom-manual "(gnus)Article Hiding")
75 :group 'gnus-article)
76
77 (defgroup gnus-article-highlight nil
78 "Article highlighting."
79 :link '(custom-manual "(gnus)Article Highlighting")
80 :group 'gnus-article
81 :group 'gnus-visual)
82
83 (defgroup gnus-article-signature nil
84 "Article signatures."
85 :link '(custom-manual "(gnus)Article Signature")
86 :group 'gnus-article)
87
88 (defgroup gnus-article-headers nil
89 "Article headers."
90 :link '(custom-manual "(gnus)Hiding Headers")
91 :group 'gnus-article)
92
93 (defgroup gnus-article-washing nil
94 "Special commands on articles."
95 :link '(custom-manual "(gnus)Article Washing")
96 :group 'gnus-article)
97
98 (defgroup gnus-article-emphasis nil
99 "Fontisizing articles."
100 :link '(custom-manual "(gnus)Article Fontisizing")
101 :group 'gnus-article)
102
103 (defgroup gnus-article-saving nil
104 "Saving articles."
105 :link '(custom-manual "(gnus)Saving Articles")
106 :group 'gnus-article)
107
108 (defgroup gnus-article-mime nil
109 "Worshiping the MIME wonder."
110 :link '(custom-manual "(gnus)Using MIME")
111 :group 'gnus-article)
112
113 (defgroup gnus-article-buttons nil
114 "Pushable buttons in the article buffer."
115 :link '(custom-manual "(gnus)Article Buttons")
116 :group 'gnus-article)
117
118 (defgroup gnus-article-various nil
119 "Other article options."
120 :link '(custom-manual "(gnus)Misc Article")
121 :group 'gnus-article)
122
123 (defcustom gnus-ignored-headers
124 (mapcar
125 (lambda (header)
126 (concat "^" header ":"))
127 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
128 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
129 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
130 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
131 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
132 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
133 "X-Attribution" "X-Originating-IP" "Delivered-To"
134 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
135 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
136 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
137 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
138 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
139 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
140 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
141 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
142 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
143 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
144 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
145 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
146 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
147 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
148 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
149 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
150 "List-[A-Za-z]+" "X-Listprocessor-Version"
151 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
152 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
153 "X-Received" "Content-length" "X-precedence"
154 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
155 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
156 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
157 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
158 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
159 "X-Content-length" "X-Posting-Agent" "Original-Received"
160 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
161 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
162 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
163 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
164 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
165 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
166 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
167 "Envelope-Sender" "Envelope-Recipients"))
168 "*All headers that start with this regexp will be hidden.
169 This variable can also be a list of regexps of headers to be ignored.
170 If `gnus-visible-headers' is non-nil, this variable will be ignored."
171 :type '(choice :custom-show nil
172 regexp
173 (repeat regexp))
174 :group 'gnus-article-hiding)
175
176 (defcustom gnus-visible-headers
177 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
178 "*All headers that do not match this regexp will be hidden.
179 This variable can also be a list of regexp of headers to remain visible.
180 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181 :type '(repeat :value-to-internal (lambda (widget value)
182 (custom-split-regexp-maybe value))
183 :match (lambda (widget value)
184 (or (stringp value)
185 (widget-editable-list-match widget value)))
186 regexp)
187 :group 'gnus-article-hiding)
188
189 (defcustom gnus-sorted-header-list
190 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
192 "*This variable is a list of regular expressions.
193 If it is non-nil, headers that match the regular expressions will
194 be placed first in the article buffer in the sequence specified by
195 this list."
196 :type '(repeat regexp)
197 :group 'gnus-article-hiding)
198
199 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200 "Headers that are only to be displayed if they have interesting data.
201 Possible values in this list are:
202
203 'empty Headers with no content.
204 'newsgroups Newsgroup identical to Gnus group.
205 'to-address To identical to To-address.
206 'to-list To identical to To-list.
207 'cc-list CC identical to To-list.
208 'followup-to Followup-to identical to Newsgroups.
209 'reply-to Reply-to identical to From.
210 'date Date less than four days old.
211 'long-to To and/or Cc longer than 1024 characters.
212 'many-to Multiple To and/or Cc."
213 :type '(set (const :tag "Headers with no content." empty)
214 (const :tag "Newsgroups identical to Gnus group." newsgroups)
215 (const :tag "To identical to To-address." to-address)
216 (const :tag "To identical to To-list." to-list)
217 (const :tag "CC identical to To-list." cc-list)
218 (const :tag "Followup-to identical to Newsgroups." followup-to)
219 (const :tag "Reply-to identical to From." reply-to)
220 (const :tag "Date less than four days old." date)
221 (const :tag "To and/or Cc longer than 1024 characters." long-to)
222 (const :tag "Multiple To and/or Cc headers." many-to))
223 :group 'gnus-article-hiding)
224
225 (defcustom gnus-article-skip-boring nil
226 "Skip over text that is not worth reading.
227 By default, if you set this t, then Gnus will display citations and
228 signatures, but will never scroll down to show you a page consisting
229 only of boring text. Boring text is controlled by
230 `gnus-article-boring-faces'."
231 :version "22.1"
232 :type 'boolean
233 :group 'gnus-article-hiding)
234
235 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
236 "Regexp matching signature separator.
237 This can also be a list of regexps. In that case, it will be checked
238 from head to tail looking for a separator. Searches will be done from
239 the end of the buffer."
240 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
241 (regexp)
242 (repeat :tag "List of regexp" regexp))
243 :group 'gnus-article-signature)
244
245 (defcustom gnus-signature-limit nil
246 "Provide a limit to what is considered a signature.
247 If it is a number, no signature may not be longer (in characters) than
248 that number. If it is a floating point number, no signature may be
249 longer (in lines) than that number. If it is a function, the function
250 will be called without any parameters, and if it returns nil, there is
251 no signature in the buffer. If it is a string, it will be used as a
252 regexp. If it matches, the text in question is not a signature.
253
254 This can also be a list of the above values."
255 :type '(choice (const nil)
256 (integer :value 200)
257 (number :value 4.0)
258 function
259 (regexp :value ".*"))
260 :group 'gnus-article-signature)
261
262 (defcustom gnus-hidden-properties '(invisible t intangible t)
263 "Property list to use for hiding text."
264 :type 'sexp
265 :group 'gnus-article-hiding)
266
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
275 (if (gnus-image-type-available-p 'pbm)
276 'gnus-display-x-face-in-from
277 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
278 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)
288
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)
293
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)
301
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.
316
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.")
322
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:
330
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
332 "
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)
343
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))
349
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)))
354 2
355 (if (nth 1 value) 2 3)
356 (nth 2 value))
357 value)))
358
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))))
371
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:
399
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
401
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)
445
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)
454
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
458
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
462
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
466
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)
470
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)
474
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)
478
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)
484
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)
490
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
495
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.
499
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)
506
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)
514
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)))
527
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)
538
539 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
540 "A function to save articles in your favourite format.
541 The function will be called by way of the `gnus-summary-save-article'
542 command, and friends such as `gnus-summary-save-article-rmail'.
543
544 Gnus provides the following functions:
545
546 * gnus-summary-save-in-rmail (Rmail format)
547 * gnus-summary-save-in-mail (Unix mail format)
548 * gnus-summary-save-in-folder (MH folder)
549 * gnus-summary-save-in-file (article format)
550 * gnus-summary-save-body-in-file (article body)
551 * gnus-summary-save-in-vm (use VM's folder format)
552 * gnus-summary-write-to-file (article format -- overwrite)
553 * gnus-summary-write-body-to-file (article body -- overwrite)
554
555 The symbol of each function may have the following properties:
556
557 * :decode
558 The value non-nil means save decoded articles. This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
561
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
568
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function)))
584
585 (defcustom gnus-article-save-coding-system
586 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
587 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
588 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
589 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
590 "Coding system used to save decoded articles to a file.
591
592 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
593 which can safely encode any characters in text. This is used by the
594 commands including:
595
596 * gnus-summary-save-article-file
597 * gnus-summary-save-article-body-file
598 * gnus-summary-write-article-file
599 * gnus-summary-write-article-body-file
600
601 and the functions to which you may set `gnus-default-article-saver':
602
603 * gnus-summary-save-in-file
604 * gnus-summary-save-body-in-file
605 * gnus-summary-write-to-file
606 * gnus-summary-write-body-to-file
607
608 Those commands and functions save just text displayed in the article
609 buffer to a file if the value of this variable is non-nil. Note that
610 buttonized MIME parts will be lost in a saved file in that case.
611 Otherwise, raw articles will be saved."
612 :group 'gnus-article-saving
613 :type `(choice
614 :format "%{%t%}:\n %[Value Menu%] %v"
615 (const :tag "Save raw articles" nil)
616 ,@(delq nil
617 (mapcar
618 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
619 '((const :tag "UTF-8" utf-8)
620 (const :tag "iso-2022-7bit" iso-2022-7bit)
621 (const :tag "Emacs internal" emacs-mule)
622 (const :tag "escape-quoted" escape-quoted))))
623 (symbol :tag "Coding system")))
624
625 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
626 "A function generating a file name to save articles in Rmail format.
627 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
628 :group 'gnus-article-saving
629 :type 'function)
630
631 (defcustom gnus-mail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Unix mail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
635 :type 'function)
636
637 (defcustom gnus-folder-save-name 'gnus-folder-save-name
638 "A function generating a file name to save articles in MH folder.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
640 :group 'gnus-article-saving
641 :type 'function)
642
643 (defcustom gnus-file-save-name 'gnus-numeric-save-name
644 "A function generating a file name to save articles in article format.
645 The function is called with NEWSGROUP, HEADERS, and optional
646 LAST-FILE."
647 :group 'gnus-article-saving
648 :type 'function)
649
650 (defcustom gnus-split-methods
651 '((gnus-article-archive-name)
652 (gnus-article-nndoc-name))
653 "*Variable used to suggest where articles are to be saved.
654 For instance, if you would like to save articles related to Gnus in
655 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
656 you could set this variable to something like:
657
658 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
659 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
660
661 This variable is an alist where the key is the match and the
662 value is a list of possible files to save in if the match is
663 non-nil.
664
665 If the match is a string, it is used as a regexp match on the
666 article. If the match is a symbol, that symbol will be funcalled
667 from the buffer of the article to be saved with the newsgroup as the
668 parameter. If it is a list, it will be evaled in the same buffer.
669
670 If this form or function returns a string, this string will be used as a
671 possible file name; and if it returns a non-nil list, that list will be
672 used as possible file names."
673 :group 'gnus-article-saving
674 :type '(repeat (choice (list :value (fun) function)
675 (cons :value ("" "") regexp (repeat string))
676 (sexp :value nil))))
677
678 (defcustom gnus-page-delimiter "^\^L"
679 "*Regexp describing what to use as article page delimiters.
680 The default value is \"^\^L\", which is a form linefeed at the
681 beginning of a line."
682 :type 'regexp
683 :group 'gnus-article-various)
684
685 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
686 "*The format specification for the article mode line.
687 See `gnus-summary-mode-line-format' for a closer description.
688
689 The following additional specs are available:
690
691 %w The article washing status.
692 %m The number of MIME parts in the article."
693 :type 'string
694 :group 'gnus-article-various)
695
696 (defcustom gnus-article-mode-hook nil
697 "*A hook for Gnus article mode."
698 :type 'hook
699 :group 'gnus-article-various)
700
701 (when (featurep 'xemacs)
702 ;; Extracted from gnus-xmas-define in order to preserve user settings
703 (when (fboundp 'turn-off-scroll-in-place)
704 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
705 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
706 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
707
708 (defcustom gnus-article-menu-hook nil
709 "*Hook run after the creation of the article mode menu."
710 :type 'hook
711 :group 'gnus-article-various)
712
713 (defcustom gnus-article-prepare-hook nil
714 "*A hook called after an article has been prepared in the article buffer."
715 :type 'hook
716 :group 'gnus-article-various)
717
718 (defcustom gnus-copy-article-ignored-headers nil
719 "List of headers to be removed when copying an article.
720 Each element is a regular expression."
721 :version "23.1" ;; No Gnus
722 :type '(repeat regexp)
723 :group 'gnus-article-various)
724
725 (make-obsolete-variable 'gnus-article-hide-pgp-hook
726 "This variable is obsolete in Gnus 5.10.")
727
728 (defface gnus-button
729 '((t (:weight bold)))
730 "Face used for highlighting a button in the article buffer."
731 :group 'gnus-article-buttons)
732
733 (defcustom gnus-article-button-face 'gnus-button
734 "Face used for highlighting buttons in the article buffer.
735
736 An article button is a piece of text that you can activate by pressing
737 `RET' or `mouse-2' above it."
738 :type 'face
739 :group 'gnus-article-buttons)
740
741 (defcustom gnus-article-mouse-face 'highlight
742 "Face used for mouse highlighting in the article buffer.
743
744 Article buttons will be displayed in this face when the cursor is
745 above them."
746 :type 'face
747 :group 'gnus-article-buttons)
748
749 (defcustom gnus-signature-face 'gnus-signature
750 "Face used for highlighting a signature in the article buffer.
751 Obsolete; use the face `gnus-signature' for customizations instead."
752 :type 'face
753 :group 'gnus-article-highlight
754 :group 'gnus-article-signature)
755
756 (defface gnus-signature
757 '((t
758 (:italic t)))
759 "Face used for highlighting a signature in the article buffer."
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
762 ;; backward-compatibility alias
763 (put 'gnus-signature-face 'face-alias 'gnus-signature)
764
765 (defface gnus-header-from
766 '((((class color)
767 (background dark))
768 (:foreground "PaleGreen1"))
769 (((class color)
770 (background light))
771 (:foreground "red3"))
772 (t
773 (:italic t)))
774 "Face used for displaying from headers."
775 :group 'gnus-article-headers
776 :group 'gnus-article-highlight)
777 ;; backward-compatibility alias
778 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
779
780 (defface gnus-header-subject
781 '((((class color)
782 (background dark))
783 (:foreground "SeaGreen1"))
784 (((class color)
785 (background light))
786 (:foreground "red4"))
787 (t
788 (:bold t :italic t)))
789 "Face used for displaying subject headers."
790 :group 'gnus-article-headers
791 :group 'gnus-article-highlight)
792 ;; backward-compatibility alias
793 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
794
795 (defface gnus-header-newsgroups
796 '((((class color)
797 (background dark))
798 (:foreground "yellow" :italic t))
799 (((class color)
800 (background light))
801 (:foreground "MidnightBlue" :italic t))
802 (t
803 (:italic t)))
804 "Face used for displaying newsgroups headers.
805 In the default setup this face is only used for crossposted
806 articles."
807 :group 'gnus-article-headers
808 :group 'gnus-article-highlight)
809 ;; backward-compatibility alias
810 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
811
812 (defface gnus-header-name
813 '((((class color)
814 (background dark))
815 (:foreground "SpringGreen2"))
816 (((class color)
817 (background light))
818 (:foreground "maroon"))
819 (t
820 (:bold t)))
821 "Face used for displaying header names."
822 :group 'gnus-article-headers
823 :group 'gnus-article-highlight)
824 ;; backward-compatibility alias
825 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
826
827 (defface gnus-header-content
828 '((((class color)
829 (background dark))
830 (:foreground "SpringGreen1" :italic t))
831 (((class color)
832 (background light))
833 (:foreground "indianred4" :italic t))
834 (t
835 (:italic t))) "Face used for displaying header content."
836 :group 'gnus-article-headers
837 :group 'gnus-article-highlight)
838 ;; backward-compatibility alias
839 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
840
841 (defcustom gnus-header-face-alist
842 '(("From" nil gnus-header-from)
843 ("Subject" nil gnus-header-subject)
844 ("Newsgroups:.*," nil gnus-header-newsgroups)
845 ("" gnus-header-name gnus-header-content))
846 "*Controls highlighting of article headers.
847
848 An alist of the form (HEADER NAME CONTENT).
849
850 HEADER is a regular expression which should match the name of a
851 header and NAME and CONTENT are either face names or nil.
852
853 The name of each header field will be displayed using the face
854 specified by the first element in the list where HEADER matches
855 the header name and NAME is non-nil. Similarly, the content will
856 be displayed by the first non-nil matching CONTENT face."
857 :group 'gnus-article-headers
858 :group 'gnus-article-highlight
859 :type '(repeat (list (regexp :tag "Header")
860 (choice :tag "Name"
861 (item :tag "skip" nil)
862 (face :value default))
863 (choice :tag "Content"
864 (item :tag "skip" nil)
865 (face :value default)))))
866
867 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
868 '((xface . (:face gnus-x-face)))
869 '((pbm . (:face gnus-x-face))
870 (png . nil)))
871 "Alist of image types and properties applied to Face and X-Face images.
872 Here are examples:
873
874 ;; Specify the altitude of Face images in the From header.
875 \(setq gnus-face-properties-alist
876 '((pbm . (:face gnus-x-face :ascent 80))
877 (png . (:ascent 80))))
878
879 ;; Show Face images as pressed buttons.
880 \(setq gnus-face-properties-alist
881 '((pbm . (:face gnus-x-face :relief -2))
882 (png . (:relief -2))))
883
884 See the manual for the valid properties for various image types.
885 Currently, `pbm' is used for X-Face images and `png' is used for Face
886 images in Emacs. Only the `:face' property is effective on the `xface'
887 image type in XEmacs if it is built with the libcompface library."
888 :version "23.1" ;; No Gnus
889 :group 'gnus-article-headers
890 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
891
892 (defcustom gnus-article-decode-hook
893 '(article-decode-charset article-decode-encoded-words
894 article-decode-group-name article-decode-idna-rhs)
895 "*Hook run to decode charsets in articles."
896 :group 'gnus-article-headers
897 :type 'hook)
898
899 (defcustom gnus-display-mime-function 'gnus-display-mime
900 "Function to display MIME articles."
901 :group 'gnus-article-mime
902 :type 'function)
903
904 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
905 "Function used to decode headers.")
906
907 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
908 "Function used to decode addresses.")
909
910 (defvar gnus-article-dumbquotes-map
911 '(("\200" "EUR")
912 ("\202" ",")
913 ("\203" "f")
914 ("\204" ",,")
915 ("\205" "...")
916 ("\213" "<")
917 ("\214" "OE")
918 ("\221" "`")
919 ("\222" "'")
920 ("\223" "``")
921 ("\224" "\"")
922 ("\225" "*")
923 ("\226" "-")
924 ("\227" "--")
925 ("\230" "~")
926 ("\231" "(TM)")
927 ("\233" ">")
928 ("\234" "oe")
929 ("\264" "'"))
930 "Table for MS-to-Latin1 translation.")
931
932 (defcustom gnus-ignored-mime-types nil
933 "List of MIME types that should be ignored by Gnus."
934 :version "21.1"
935 :group 'gnus-article-mime
936 :type '(repeat regexp))
937
938 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
939 "List of MIME types that should not be given buttons when rendered inline.
940 See also `gnus-buttonized-mime-types' which may override this variable.
941 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
945
946 (defcustom gnus-buttonized-mime-types nil
947 "List of MIME types that should be given buttons when rendered inline.
948 If set, this variable overrides `gnus-unbuttonized-mime-types'.
949 To see e.g. security buttons you could set this to
950 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
951 this list to display radio buttons that allow you to choose one of two
952 media types those mails include. See also `mm-discouraged-alternatives'.
953 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
954 :version "22.1"
955 :group 'gnus-article-mime
956 :type '(repeat regexp))
957
958 (defcustom gnus-inhibit-mime-unbuttonizing nil
959 "If non-nil, all MIME parts get buttons.
960 When nil (the default value), then some MIME parts do not get buttons,
961 as described by the variables `gnus-buttonized-mime-types' and
962 `gnus-unbuttonized-mime-types'."
963 :version "22.1"
964 :group 'gnus-article-mime
965 :type 'boolean)
966
967 (defcustom gnus-body-boundary-delimiter "_"
968 "String used to delimit header and body.
969 This variable is used by `gnus-article-treat-body-boundary' which can
970 be controlled by `gnus-treat-body-boundary'."
971 :version "22.1"
972 :group 'gnus-article-various
973 :type '(choice (item :tag "None" :value nil)
974 string))
975
976 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
977 "/usr/share/picons")
978 "Defines the location of the faces database.
979 For information on obtaining this database of pretty pictures, please
980 see http://www.cs.indiana.edu/picons/ftp/index.html"
981 :version "22.1"
982 :type '(repeat directory)
983 :link '(url-link :tag "download"
984 "http://www.cs.indiana.edu/picons/ftp/index.html")
985 :link '(custom-manual "(gnus)Picons")
986 :group 'gnus-picon)
987
988 (defun gnus-picons-installed-p ()
989 "Say whether picons are installed on your machine."
990 (let ((installed nil))
991 (dolist (database gnus-picon-databases)
992 (when (file-exists-p database)
993 (setq installed t)))
994 installed))
995
996 (defcustom gnus-article-mime-part-function nil
997 "Function called with a MIME handle as the argument.
998 This is meant for people who want to do something automatic based
999 on parts -- for instance, adding Vcard info to a database."
1000 :group 'gnus-article-mime
1001 :type '(choice (const nil)
1002 function))
1003
1004 (defcustom gnus-mime-multipart-functions nil
1005 "An alist of MIME types to functions to display them."
1006 :version "21.1"
1007 :group 'gnus-article-mime
1008 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1009
1010 (defcustom gnus-article-date-lapsed-new-header nil
1011 "Whether the X-Sent and Date headers can coexist.
1012 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1013 either replace the old \"Date:\" header (if this variable is nil), or
1014 be added below it (otherwise)."
1015 :version "21.1"
1016 :group 'gnus-article-headers
1017 :type 'boolean)
1018
1019 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1020 "Function called with a MIME handle as the argument.
1021 This is meant for people who want to view first matched part.
1022 For `undisplayed-alternative' (default), the first undisplayed
1023 part or alternative part is used. For `undisplayed', the first
1024 undisplayed part is used. For a function, the first part which
1025 the function return t is used. For nil, the first part is
1026 used."
1027 :version "21.1"
1028 :group 'gnus-article-mime
1029 :type '(choice
1030 (item :tag "first" :value nil)
1031 (item :tag "undisplayed" :value undisplayed)
1032 (item :tag "undisplayed or alternative"
1033 :value undisplayed-alternative)
1034 (function)))
1035
1036 (defcustom gnus-mime-action-alist
1037 '(("save to file" . gnus-mime-save-part)
1038 ("save and strip" . gnus-mime-save-part-and-strip)
1039 ("replace with file" . gnus-mime-replace-part)
1040 ("delete part" . gnus-mime-delete-part)
1041 ("display as text" . gnus-mime-inline-part)
1042 ("view the part" . gnus-mime-view-part)
1043 ("pipe to command" . gnus-mime-pipe-part)
1044 ("toggle display" . gnus-article-press-button)
1045 ("toggle display" . gnus-article-view-part-as-charset)
1046 ("view as type" . gnus-mime-view-part-as-type)
1047 ("view internally" . gnus-mime-view-part-internally)
1048 ("view externally" . gnus-mime-view-part-externally))
1049 "An alist of actions that run on the MIME attachment."
1050 :group 'gnus-article-mime
1051 :type '(repeat (cons (string :tag "name")
1052 (function))))
1053
1054 (defcustom gnus-auto-select-part 1
1055 "Advance to next MIME part when deleting or stripping parts.
1056
1057 When 0, point will be placed on the same part as before. When
1058 positive (negative), move point forward (backwards) this many
1059 parts. When nil, redisplay article."
1060 :version "23.1" ;; No Gnus
1061 :group 'gnus-article-mime
1062 :type '(choice (const nil :tag "Redisplay article.")
1063 (const 1 :tag "Next part.")
1064 (const 0 :tag "Current part.")
1065 integer))
1066
1067 ;;;
1068 ;;; The treatment variables
1069 ;;;
1070
1071 (defvar gnus-part-display-hook nil
1072 "Hook called on parts that are to receive treatment.")
1073
1074 (defvar gnus-article-treat-custom
1075 '(choice (const :tag "Off" nil)
1076 (const :tag "On" t)
1077 (const :tag "Header" head)
1078 (const :tag "First" first)
1079 (const :tag "Last" last)
1080 (integer :tag "Less")
1081 (repeat :tag "Groups" regexp)
1082 (sexp :tag "Predicate")))
1083
1084 (defvar gnus-article-treat-head-custom
1085 '(choice (const :tag "Off" nil)
1086 (const :tag "Header" head)))
1087
1088 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1089 "text/x-patch")
1090 "Parts to treat.")
1091
1092 (defvar gnus-inhibit-treatment nil
1093 "Whether to inhibit treatment.")
1094
1095 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1096 "Highlight the signature.
1097 Valid values are nil, t, `head', `first', `last', an integer or a
1098 predicate. See Info node `(gnus)Customizing Articles'."
1099 :group 'gnus-article-treat
1100 :link '(custom-manual "(gnus)Customizing Articles")
1101 :type gnus-article-treat-custom)
1102 (put 'gnus-treat-highlight-signature 'highlight t)
1103
1104 (defcustom gnus-treat-buttonize 100000
1105 "Add buttons.
1106 Valid values are nil, t, `head', `first', `last', an integer or a
1107 predicate. See Info node `(gnus)Customizing Articles'."
1108 :group 'gnus-article-treat
1109 :link '(custom-manual "(gnus)Customizing Articles")
1110 :type gnus-article-treat-custom)
1111 (put 'gnus-treat-buttonize 'highlight t)
1112
1113 (defcustom gnus-treat-buttonize-head 'head
1114 "Add buttons to the head.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate. See Info node `(gnus)Customizing Articles'."
1117 :group 'gnus-article-treat
1118 :link '(custom-manual "(gnus)Customizing Articles")
1119 :type gnus-article-treat-head-custom)
1120 (put 'gnus-treat-buttonize-head 'highlight t)
1121
1122 (defcustom gnus-treat-emphasize 50000
1123 "Emphasize text.
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate. See Info node `(gnus)Customizing Articles'."
1126 :group 'gnus-article-treat
1127 :link '(custom-manual "(gnus)Customizing Articles")
1128 :type gnus-article-treat-custom)
1129 (put 'gnus-treat-emphasize 'highlight t)
1130
1131 (defcustom gnus-treat-strip-cr nil
1132 "Remove carriage returns.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1135 :version "22.1"
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1139
1140 (defcustom gnus-treat-unsplit-urls nil
1141 "Remove newlines from within URLs.
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate. See Info node `(gnus)Customizing Articles'."
1144 :version "22.1"
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1148
1149 (defcustom gnus-treat-leading-whitespace nil
1150 "Remove leading whitespace in headers.
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate. See Info node `(gnus)Customizing Articles'."
1153 :version "22.1"
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-custom)
1157
1158 (defcustom gnus-treat-hide-headers 'head
1159 "Hide headers.
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1165
1166 (defcustom gnus-treat-hide-boring-headers nil
1167 "Hide boring headers.
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-head-custom)
1173
1174 (defcustom gnus-treat-hide-signature nil
1175 "Hide the signature.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1181
1182 (defcustom gnus-treat-fill-article nil
1183 "Fill the article.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1189
1190 (defcustom gnus-treat-hide-citation nil
1191 "Hide cited text.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-custom)
1197
1198 (defcustom gnus-treat-hide-citation-maybe nil
1199 "Hide cited text.
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1205
1206 (defcustom gnus-treat-strip-list-identifiers 'head
1207 "Strip list identifiers from `gnus-list-identifiers`.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1210 :version "21.1"
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-custom)
1214
1215 (make-obsolete-variable 'gnus-treat-strip-pgp
1216 "This option is obsolete in Gnus 5.10.")
1217
1218 (defcustom gnus-treat-strip-pem nil
1219 "Strip PEM signatures.
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)
1225
1226 (defcustom gnus-treat-strip-banner t
1227 "Strip banners from articles.
1228 The banner to be stripped is specified in the `banner' group parameter.
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate. See Info node `(gnus)Customizing Articles'."
1231 :group 'gnus-article-treat
1232 :link '(custom-manual "(gnus)Customizing Articles")
1233 :type gnus-article-treat-custom)
1234
1235 (defcustom gnus-treat-highlight-headers 'head
1236 "Highlight the headers.
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate. See Info node `(gnus)Customizing Articles'."
1239 :group 'gnus-article-treat
1240 :link '(custom-manual "(gnus)Customizing Articles")
1241 :type gnus-article-treat-head-custom)
1242 (put 'gnus-treat-highlight-headers 'highlight t)
1243
1244 (defcustom gnus-treat-highlight-citation t
1245 "Highlight cited text.
1246 Valid values are nil, t, `head', `first', `last', an integer or a
1247 predicate. See Info node `(gnus)Customizing Articles'."
1248 :group 'gnus-article-treat
1249 :link '(custom-manual "(gnus)Customizing Articles")
1250 :type gnus-article-treat-custom)
1251 (put 'gnus-treat-highlight-citation 'highlight t)
1252
1253 (defcustom gnus-treat-date-ut nil
1254 "Display the Date in UT (GMT).
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :group 'gnus-article-treat
1258 :link '(custom-manual "(gnus)Customizing Articles")
1259 :type gnus-article-treat-head-custom)
1260
1261 (defcustom gnus-treat-date-local nil
1262 "Display the Date in the local timezone.
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-head-custom)
1268
1269 (defcustom gnus-treat-date-english nil
1270 "Display the Date in a format that can be read aloud in English.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1273 :version "22.1"
1274 :group 'gnus-article-treat
1275 :link '(custom-manual "(gnus)Customizing Articles")
1276 :type gnus-article-treat-head-custom)
1277
1278 (defcustom gnus-treat-date-lapsed nil
1279 "Display the Date header in a way that says how much time has elapsed.
1280 Valid values are nil, t, `head', `first', `last', an integer or a
1281 predicate. See Info node `(gnus)Customizing Articles'."
1282 :group 'gnus-article-treat
1283 :link '(custom-manual "(gnus)Customizing Articles")
1284 :type gnus-article-treat-head-custom)
1285
1286 (defcustom gnus-treat-date-original nil
1287 "Display the date in the original timezone.
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-head-custom)
1293
1294 (defcustom gnus-treat-date-iso8601 nil
1295 "Display the date in the ISO8601 format.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1298 :version "21.1"
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-head-custom)
1302
1303 (defcustom gnus-treat-date-user-defined nil
1304 "Display the date in a user-defined format.
1305 The format is defined by the `gnus-article-time-format' variable.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate. See Info node `(gnus)Customizing Articles'."
1308 :group 'gnus-article-treat
1309 :link '(custom-manual "(gnus)Customizing Articles")
1310 :type gnus-article-treat-head-custom)
1311
1312 (defcustom gnus-treat-strip-headers-in-body t
1313 "Strip the X-No-Archive header line from the beginning of the body.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1316 :version "21.1"
1317 :group 'gnus-article-treat
1318 :link '(custom-manual "(gnus)Customizing Articles")
1319 :type gnus-article-treat-custom)
1320
1321 (defcustom gnus-treat-strip-trailing-blank-lines nil
1322 "Strip trailing blank lines.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'.
1325
1326 When set to t, it also strips trailing blanks in all MIME parts.
1327 Consider to use `last' instead."
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1331
1332 (defcustom gnus-treat-strip-leading-blank-lines nil
1333 "Strip leading blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1336
1337 When set to t, it also strips trailing blanks in all MIME parts."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1341
1342 (defcustom gnus-treat-strip-multiple-blank-lines nil
1343 "Strip multiple blank lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'."
1346 :group 'gnus-article-treat
1347 :link '(custom-manual "(gnus)Customizing Articles")
1348 :type gnus-article-treat-custom)
1349
1350 (defcustom gnus-treat-unfold-headers 'head
1351 "Unfold folded header lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 predicate. See Info node `(gnus)Customizing Articles'."
1354 :version "22.1"
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1358
1359 (defcustom gnus-article-unfold-long-headers nil
1360 "If non-nil, allow unfolding headers even if the header is long.
1361 If it is a regexp, only long headers matching this regexp are unfolded.
1362 If it is t, all long headers are unfolded.
1363
1364 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1365 :version "23.1" ;; No Gnus
1366 :group 'gnus-article-treat
1367 :type '(choice (const nil)
1368 (const :tag "all" t)
1369 (regexp)))
1370
1371 (defcustom gnus-treat-fold-headers nil
1372 "Fold headers.
1373 Valid values are nil, t, `head', `first', `last', an integer or a
1374 predicate. See Info node `(gnus)Customizing Articles'."
1375 :version "22.1"
1376 :group 'gnus-article-treat
1377 :link '(custom-manual "(gnus)Customizing Articles")
1378 :type gnus-article-treat-custom)
1379
1380 (defcustom gnus-treat-fold-newsgroups 'head
1381 "Fold the Newsgroups and Followup-To 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)
1388
1389 (defcustom gnus-treat-overstrike t
1390 "Treat overstrike highlighting.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
1395 :type gnus-article-treat-custom)
1396 (put 'gnus-treat-overstrike 'highlight t)
1397
1398 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1399 "Treat ANSI SGR control sequences.
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
1406 (make-obsolete-variable 'gnus-treat-display-xface
1407 'gnus-treat-display-x-face)
1408
1409 (defcustom gnus-treat-display-x-face
1410 (and (not noninteractive)
1411 (gnus-image-type-available-p 'xbm)
1412 (if (featurep 'xemacs)
1413 (featurep 'xface)
1414 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1415 (executable-find "icontopbm")))
1416 'head)
1417 "Display X-Face headers.
1418 Valid values are nil and `head'.
1419 See Info node `(gnus)Customizing Articles' and Info node
1420 `(gnus)X-Face' for details."
1421 :group 'gnus-article-treat
1422 :version "21.1"
1423 :link '(custom-manual "(gnus)Customizing Articles")
1424 :link '(custom-manual "(gnus)X-Face")
1425 :type gnus-article-treat-head-custom
1426 :set (lambda (symbol value)
1427 (set-default
1428 symbol
1429 (cond ((or (boundp symbol) (get symbol 'saved-value))
1430 value)
1431 ((boundp 'gnus-treat-display-xface)
1432 (message "\
1433 ** gnus-treat-display-xface is an obsolete variable;\
1434 use gnus-treat-display-x-face instead")
1435 (default-value 'gnus-treat-display-xface))
1436 ((get 'gnus-treat-display-xface 'saved-value)
1437 (message "\
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1441 (t
1442 value)))))
1443 (put 'gnus-treat-display-x-face 'highlight t)
1444
1445 (defcustom gnus-treat-display-face
1446 (and (not noninteractive)
1447 (gnus-image-type-available-p 'png)
1448 'head)
1449 "Display Face headers.
1450 Valid values are nil, t, `head', `first', `last', an integer or a
1451 predicate. See Info node `(gnus)Customizing Articles' and Info
1452 node `(gnus)X-Face' for details."
1453 :group 'gnus-article-treat
1454 :version "22.1"
1455 :link '(custom-manual "(gnus)Customizing Articles")
1456 :link '(custom-manual "(gnus)X-Face")
1457 :type gnus-article-treat-head-custom)
1458 (put 'gnus-treat-display-face 'highlight t)
1459
1460 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1461 "Display smileys.
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate. See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Smileys' for details."
1465 :group 'gnus-article-treat
1466 :version "21.1"
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)Smileys")
1469 :type gnus-article-treat-custom)
1470 (put 'gnus-treat-display-smileys 'highlight t)
1471
1472 (defcustom gnus-treat-from-picon
1473 (if (and (gnus-image-type-available-p 'xpm)
1474 (gnus-picons-installed-p))
1475 'head nil)
1476 "Display picons in the From header.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Picons' for details."
1480 :version "22.1"
1481 :group 'gnus-article-treat
1482 :group 'gnus-picon
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Picons")
1485 :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-from-picon 'highlight t)
1487
1488 (defcustom gnus-treat-mail-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1491 'head nil)
1492 "Display picons in To and Cc headers.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1496 :version "22.1"
1497 :group 'gnus-article-treat
1498 :group 'gnus-picon
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-mail-picon 'highlight t)
1503
1504 (defcustom gnus-treat-newsgroups-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1507 'head nil)
1508 "Display picons in the Newsgroups and Followup-To headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1512 :version "22.1"
1513 :group 'gnus-article-treat
1514 :group 'gnus-picon
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-newsgroups-picon 'highlight t)
1519
1520 (defcustom gnus-treat-body-boundary
1521 (if (or gnus-treat-newsgroups-picon
1522 gnus-treat-mail-picon
1523 gnus-treat-from-picon)
1524 ;; If there's much decoration, the user might prefer a boundery.
1525 'head
1526 nil)
1527 "Draw a boundary at the end of the headers.
1528 Valid values are nil and `head'.
1529 See Info node `(gnus)Customizing Articles' for details."
1530 :version "22.1"
1531 :group 'gnus-article-treat
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :type gnus-article-treat-head-custom)
1534
1535 (defcustom gnus-treat-capitalize-sentences nil
1536 "Capitalize sentence-starting words.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles'."
1539 :version "21.1"
1540 :group 'gnus-article-treat
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :type gnus-article-treat-custom)
1543
1544 (defcustom gnus-treat-wash-html nil
1545 "Format as HTML.
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate. See Info node `(gnus)Customizing Articles'."
1548 :version "22.1"
1549 :group 'gnus-article-treat
1550 :link '(custom-manual "(gnus)Customizing Articles")
1551 :type gnus-article-treat-custom)
1552
1553 (defcustom gnus-treat-fill-long-lines nil
1554 "Fill long lines.
1555 Valid values are nil, t, `head', `first', `last', an integer or a
1556 predicate. See Info node `(gnus)Customizing Articles'."
1557 :group 'gnus-article-treat
1558 :link '(custom-manual "(gnus)Customizing Articles")
1559 :type gnus-article-treat-custom)
1560
1561 (defcustom gnus-treat-play-sounds nil
1562 "Play sounds.
1563 Valid values are nil, t, `head', `first', `last', an integer or a
1564 predicate. See Info node `(gnus)Customizing Articles'."
1565 :version "21.1"
1566 :group 'gnus-article-treat
1567 :link '(custom-manual "(gnus)Customizing Articles")
1568 :type gnus-article-treat-custom)
1569
1570 (defcustom gnus-treat-translate nil
1571 "Translate articles from one language to another.
1572 Valid values are nil, t, `head', `first', `last', an integer or a
1573 predicate. See Info node `(gnus)Customizing Articles'."
1574 :version "21.1"
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-custom)
1578
1579 (defcustom gnus-treat-x-pgp-sig nil
1580 "Verify X-PGP-Sig.
1581 To automatically treat X-PGP-Sig, set it to head.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate. See Info node `(gnus)Customizing Articles'."
1584 :version "22.1"
1585 :group 'gnus-article-treat
1586 :group 'mime-security
1587 :link '(custom-manual "(gnus)Customizing Articles")
1588 :type gnus-article-treat-custom)
1589
1590 (defvar gnus-article-encrypt-protocol-alist
1591 '(("PGP" . mml2015-self-encrypt)))
1592
1593 ;; Set to nil if more than one protocol added to
1594 ;; gnus-article-encrypt-protocol-alist.
1595 (defcustom gnus-article-encrypt-protocol "PGP"
1596 "The protocol used for encrypt articles.
1597 It is a string, such as \"PGP\". If nil, ask user."
1598 :version "22.1"
1599 :type 'string
1600 :group 'mime-security)
1601
1602 (defvar gnus-article-wash-function nil
1603 "Function used for converting HTML into text.")
1604
1605 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1606 (mm-coding-system-p 'utf-8)
1607 (executable-find idna-program))
1608 "Whether IDNA decoding of headers is used when viewing messages.
1609 This requires GNU Libidn, and by default only enabled if it is found."
1610 :version "22.1"
1611 :group 'gnus-article-headers
1612 :type 'boolean)
1613
1614 (defcustom gnus-article-over-scroll nil
1615 "If non-nil, allow scrolling the article buffer even when there no more text."
1616 :version "22.1"
1617 :group 'gnus-article
1618 :type 'boolean)
1619
1620 ;;; Internal variables
1621
1622 (defvar gnus-english-month-names
1623 '("January" "February" "March" "April" "May" "June" "July" "August"
1624 "September" "October" "November" "December"))
1625
1626 (defvar article-goto-body-goes-to-point-min-p nil)
1627 (defvar gnus-article-wash-types nil)
1628 (defvar gnus-article-emphasis-alist nil)
1629 (defvar gnus-article-image-alist nil)
1630
1631 (defvar gnus-article-mime-handle-alist-1 nil)
1632 (defvar gnus-treatment-function-alist
1633 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1634 (gnus-treat-strip-banner gnus-article-strip-banner)
1635 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1636 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1637 (gnus-treat-buttonize gnus-article-add-buttons)
1638 (gnus-treat-fill-article gnus-article-fill-cited-article)
1639 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1640 (gnus-treat-strip-cr gnus-article-remove-cr)
1641 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1642 (gnus-treat-date-ut gnus-article-date-ut)
1643 (gnus-treat-date-local gnus-article-date-local)
1644 (gnus-treat-date-english gnus-article-date-english)
1645 (gnus-treat-date-original gnus-article-date-original)
1646 (gnus-treat-date-user-defined gnus-article-date-user)
1647 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1648 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1649 (gnus-treat-display-x-face gnus-article-display-x-face)
1650 (gnus-treat-display-face gnus-article-display-face)
1651 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1652 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1653 (gnus-treat-hide-signature gnus-article-hide-signature)
1654 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1655 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1656 (gnus-treat-strip-pem gnus-article-hide-pem)
1657 (gnus-treat-from-picon gnus-treat-from-picon)
1658 (gnus-treat-mail-picon gnus-treat-mail-picon)
1659 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1660 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1661 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1662 (gnus-treat-strip-trailing-blank-lines
1663 gnus-article-remove-trailing-blank-lines)
1664 (gnus-treat-strip-leading-blank-lines
1665 gnus-article-strip-leading-blank-lines)
1666 (gnus-treat-strip-multiple-blank-lines
1667 gnus-article-strip-multiple-blank-lines)
1668 (gnus-treat-overstrike gnus-article-treat-overstrike)
1669 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1670 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1671 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1672 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1673 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1674 (gnus-treat-display-smileys gnus-treat-smiley)
1675 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1676 (gnus-treat-wash-html gnus-article-wash-html)
1677 (gnus-treat-emphasize gnus-article-emphasize)
1678 (gnus-treat-hide-citation gnus-article-hide-citation)
1679 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1680 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1681 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1682 (gnus-treat-play-sounds gnus-earcon-display)))
1683
1684 (defvar gnus-article-mime-handle-alist nil)
1685 (defvar article-lapsed-timer nil)
1686 (defvar gnus-article-current-summary nil)
1687
1688 (defvar gnus-article-mode-syntax-table
1689 (let ((table (copy-syntax-table text-mode-syntax-table)))
1690 ;; This causes the citation match run O(2^n).
1691 ;; (modify-syntax-entry ?- "w" table)
1692 (modify-syntax-entry ?> ")<" table)
1693 (modify-syntax-entry ?< "(>" table)
1694 ;; make M-. in article buffers work for `foo' strings
1695 (modify-syntax-entry ?' " " table)
1696 (modify-syntax-entry ?` " " table)
1697 table)
1698 "Syntax table used in article mode buffers.
1699 Initialized from `text-mode-syntax-table.")
1700
1701 (defvar gnus-save-article-buffer nil)
1702
1703 (defvar gnus-number-of-articles-to-be-saved nil)
1704
1705 (defvar gnus-inhibit-hiding nil)
1706
1707 (defvar gnus-article-edit-mode nil)
1708
1709 ;;; Macros for dealing with the article buffer.
1710
1711 (defmacro gnus-with-article-headers (&rest forms)
1712 `(with-current-buffer gnus-article-buffer
1713 (save-restriction
1714 (let ((inhibit-read-only t)
1715 (inhibit-point-motion-hooks t)
1716 (case-fold-search t))
1717 (article-narrow-to-head)
1718 ,@forms))))
1719
1720 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1721 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1722
1723 (defmacro gnus-with-article-buffer (&rest forms)
1724 `(with-current-buffer gnus-article-buffer
1725 (let ((inhibit-read-only t))
1726 ,@forms)))
1727
1728 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1729 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1730
1731 (defun gnus-article-goto-header (header)
1732 "Go to HEADER, which is a regular expression."
1733 (re-search-forward (concat "^\\(" header "\\):") nil t))
1734
1735 (defsubst gnus-article-hide-text (b e props)
1736 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1737 (gnus-add-text-properties-when 'article-type nil b e props)
1738 (when (memq 'intangible props)
1739 (put-text-property
1740 (max (1- b) (point-min))
1741 b 'intangible (cddr (memq 'intangible props)))))
1742
1743 (defsubst gnus-article-unhide-text (b e)
1744 "Remove hidden text properties from region between B and E."
1745 (remove-text-properties b e gnus-hidden-properties)
1746 (when (memq 'intangible gnus-hidden-properties)
1747 (put-text-property (max (1- b) (point-min))
1748 b 'intangible nil)))
1749
1750 (defun gnus-article-hide-text-type (b e type)
1751 "Hide text of TYPE between B and E."
1752 (gnus-add-wash-type type)
1753 (gnus-article-hide-text
1754 b e (cons 'article-type (cons type gnus-hidden-properties))))
1755
1756 (defun gnus-article-unhide-text-type (b e type)
1757 "Unhide text of TYPE between B and E."
1758 (gnus-delete-wash-type type)
1759 (remove-text-properties
1760 b e (cons 'article-type (cons type gnus-hidden-properties)))
1761 (when (memq 'intangible gnus-hidden-properties)
1762 (put-text-property (max (1- b) (point-min))
1763 b 'intangible nil)))
1764
1765 (defun gnus-article-hide-text-of-type (type)
1766 "Hide text of TYPE in the current buffer."
1767 (save-excursion
1768 (let ((b (point-min))
1769 (e (point-max)))
1770 (while (setq b (text-property-any b e 'article-type type))
1771 (add-text-properties b (incf b) gnus-hidden-properties)))))
1772
1773 (defun gnus-article-delete-text-of-type (type)
1774 "Delete text of TYPE in the current buffer."
1775 (save-excursion
1776 (let ((b (point-min)))
1777 (if (eq type 'multipart)
1778 ;; Remove MIME buttons associated with multipart/alternative parts.
1779 (progn
1780 (goto-char b)
1781 (while (if (get-text-property (point) 'gnus-part)
1782 (setq b (point))
1783 (when (setq b (next-single-property-change (point)
1784 'gnus-part))
1785 (goto-char b)
1786 t))
1787 (end-of-line)
1788 (skip-chars-forward "\n")
1789 (when (eq (get-text-property b 'article-type) 'multipart)
1790 (delete-region b (point)))))
1791 (while (setq b (text-property-any b (point-max) 'article-type type))
1792 (delete-region
1793 b (or (text-property-not-all b (point-max) 'article-type type)
1794 (point-max))))))))
1795
1796 (defun gnus-article-delete-invisible-text ()
1797 "Delete all invisible text in the current buffer."
1798 (save-excursion
1799 (let ((b (point-min)))
1800 (while (setq b (text-property-any b (point-max) 'invisible t))
1801 (delete-region
1802 b (or (text-property-not-all b (point-max) 'invisible t)
1803 (point-max)))))))
1804
1805 (defun gnus-article-text-type-exists-p (type)
1806 "Say whether any text of type TYPE exists in the buffer."
1807 (text-property-any (point-min) (point-max) 'article-type type))
1808
1809 (defsubst gnus-article-header-rank ()
1810 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1811 (let ((list gnus-sorted-header-list)
1812 (i 1))
1813 (while list
1814 (if (looking-at (car list))
1815 (setq list nil)
1816 (setq list (cdr list))
1817 (incf i)))
1818 i))
1819
1820 (defun article-hide-headers (&optional arg delete)
1821 "Hide unwanted headers and possibly sort them as well."
1822 (interactive)
1823 ;; This function might be inhibited.
1824 (unless gnus-inhibit-hiding
1825 (let ((inhibit-read-only t)
1826 (case-fold-search t)
1827 (max (1+ (length gnus-sorted-header-list)))
1828 (inhibit-point-motion-hooks t)
1829 (cur (current-buffer))
1830 ignored visible beg)
1831 (save-excursion
1832 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1833 ;; group parameters, so we should go to the summary buffer.
1834 (when (prog1
1835 (condition-case nil
1836 (progn (set-buffer gnus-summary-buffer) t)
1837 (error nil))
1838 (setq ignored (when (not gnus-visible-headers)
1839 (cond ((stringp gnus-ignored-headers)
1840 gnus-ignored-headers)
1841 ((listp gnus-ignored-headers)
1842 (mapconcat 'identity
1843 gnus-ignored-headers
1844 "\\|"))))
1845 visible (cond ((stringp gnus-visible-headers)
1846 gnus-visible-headers)
1847 ((and gnus-visible-headers
1848 (listp gnus-visible-headers))
1849 (mapconcat 'identity
1850 gnus-visible-headers
1851 "\\|")))))
1852 (set-buffer cur))
1853 (save-restriction
1854 ;; First we narrow to just the headers.
1855 (article-narrow-to-head)
1856 ;; Hide any "From " lines at the beginning of (mail) articles.
1857 (while (looking-at "From ")
1858 (forward-line 1))
1859 (unless (bobp)
1860 (delete-region (point-min) (point)))
1861 ;; Then treat the rest of the header lines.
1862 ;; Then we use the two regular expressions
1863 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1864 ;; select which header lines is to remain visible in the
1865 ;; article buffer.
1866 (while (re-search-forward "^[^ \t:]*:" nil t)
1867 (beginning-of-line)
1868 ;; Mark the rank of the header.
1869 (put-text-property
1870 (point) (1+ (point)) 'message-rank
1871 (if (or (and visible (looking-at visible))
1872 (and ignored
1873 (not (looking-at ignored))))
1874 (gnus-article-header-rank)
1875 (+ 2 max)))
1876 (forward-line 1))
1877 (message-sort-headers-1)
1878 (when (setq beg (text-property-any
1879 (point-min) (point-max) 'message-rank (+ 2 max)))
1880 ;; We delete the unwanted headers.
1881 (gnus-add-wash-type 'headers)
1882 (add-text-properties (point-min) (+ 5 (point-min))
1883 '(article-type headers dummy-invisible t))
1884 (delete-region beg (point-max))))))))
1885
1886 (defun article-hide-boring-headers (&optional arg)
1887 "Toggle hiding of headers that aren't very interesting.
1888 If given a negative prefix, always show; if given a positive prefix,
1889 always hide."
1890 (interactive (gnus-article-hidden-arg))
1891 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1892 (not gnus-show-all-headers))
1893 (save-excursion
1894 (save-restriction
1895 (let ((inhibit-read-only t)
1896 (inhibit-point-motion-hooks t))
1897 (article-narrow-to-head)
1898 (dolist (elem gnus-boring-article-headers)
1899 (goto-char (point-min))
1900 (cond
1901 ;; Hide empty headers.
1902 ((eq elem 'empty)
1903 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1904 (forward-line -1)
1905 (gnus-article-hide-text-type
1906 (point-at-bol)
1907 (progn
1908 (end-of-line)
1909 (if (re-search-forward "^[^ \t]" nil t)
1910 (match-beginning 0)
1911 (point-max)))
1912 'boring-headers)))
1913 ;; Hide boring Newsgroups header.
1914 ((eq elem 'newsgroups)
1915 (when (gnus-string-equal
1916 (gnus-fetch-field "newsgroups")
1917 (gnus-group-real-name
1918 (if (boundp 'gnus-newsgroup-name)
1919 gnus-newsgroup-name
1920 "")))
1921 (gnus-article-hide-header "newsgroups")))
1922 ((eq elem 'to-address)
1923 (let ((to (message-fetch-field "to"))
1924 (to-address
1925 (gnus-parameter-to-address
1926 (if (boundp 'gnus-newsgroup-name)
1927 gnus-newsgroup-name ""))))
1928 (when (and to to-address
1929 (ignore-errors
1930 (gnus-string-equal
1931 ;; only one address in To
1932 (nth 1 (mail-extract-address-components to))
1933 to-address)))
1934 (gnus-article-hide-header "to"))))
1935 ((eq elem 'to-list)
1936 (let ((to (message-fetch-field "to"))
1937 (to-list
1938 (gnus-parameter-to-list
1939 (if (boundp 'gnus-newsgroup-name)
1940 gnus-newsgroup-name ""))))
1941 (when (and to to-list
1942 (ignore-errors
1943 (gnus-string-equal
1944 ;; only one address in To
1945 (nth 1 (mail-extract-address-components to))
1946 to-list)))
1947 (gnus-article-hide-header "to"))))
1948 ((eq elem 'cc-list)
1949 (let ((cc (message-fetch-field "cc"))
1950 (to-list
1951 (gnus-parameter-to-list
1952 (if (boundp 'gnus-newsgroup-name)
1953 gnus-newsgroup-name ""))))
1954 (when (and cc to-list
1955 (ignore-errors
1956 (gnus-string-equal
1957 ;; only one address in CC
1958 (nth 1 (mail-extract-address-components cc))
1959 to-list)))
1960 (gnus-article-hide-header "cc"))))
1961 ((eq elem 'followup-to)
1962 (when (gnus-string-equal
1963 (message-fetch-field "followup-to")
1964 (message-fetch-field "newsgroups"))
1965 (gnus-article-hide-header "followup-to")))
1966 ((eq elem 'reply-to)
1967 (if (gnus-group-find-parameter
1968 gnus-newsgroup-name 'broken-reply-to)
1969 (gnus-article-hide-header "reply-to")
1970 (let ((from (message-fetch-field "from"))
1971 (reply-to (message-fetch-field "reply-to")))
1972 (when
1973 (and
1974 from reply-to
1975 (ignore-errors
1976 (equal
1977 (sort (mapcar
1978 (lambda (x) (downcase (cadr x)))
1979 (mail-extract-address-components from t))
1980 'string<)
1981 (sort (mapcar
1982 (lambda (x) (downcase (cadr x)))
1983 (mail-extract-address-components reply-to t))
1984 'string<))))
1985 (gnus-article-hide-header "reply-to")))))
1986 ((eq elem 'date)
1987 (let ((date (with-current-buffer gnus-original-article-buffer
1988 ;; If date in `gnus-article-buffer' is localized
1989 ;; (`gnus-treat-date-user-defined'),
1990 ;; `days-between' might fail.
1991 (message-fetch-field "date"))))
1992 (when (and date
1993 (< (days-between (current-time-string) date)
1994 4))
1995 (gnus-article-hide-header "date"))))
1996 ((eq elem 'long-to)
1997 (let ((to (message-fetch-field "to"))
1998 (cc (message-fetch-field "cc")))
1999 (when (> (length to) 1024)
2000 (gnus-article-hide-header "to"))
2001 (when (> (length cc) 1024)
2002 (gnus-article-hide-header "cc"))))
2003 ((eq elem 'many-to)
2004 (let ((to-count 0)
2005 (cc-count 0))
2006 (goto-char (point-min))
2007 (while (re-search-forward "^to:" nil t)
2008 (setq to-count (1+ to-count)))
2009 (when (> to-count 1)
2010 (while (> to-count 0)
2011 (goto-char (point-min))
2012 (save-restriction
2013 (re-search-forward "^to:" nil nil to-count)
2014 (forward-line -1)
2015 (narrow-to-region (point) (point-max))
2016 (gnus-article-hide-header "to"))
2017 (setq to-count (1- to-count))))
2018 (goto-char (point-min))
2019 (while (re-search-forward "^cc:" nil t)
2020 (setq cc-count (1+ cc-count)))
2021 (when (> cc-count 1)
2022 (while (> cc-count 0)
2023 (goto-char (point-min))
2024 (save-restriction
2025 (re-search-forward "^cc:" nil nil cc-count)
2026 (forward-line -1)
2027 (narrow-to-region (point) (point-max))
2028 (gnus-article-hide-header "cc"))
2029 (setq cc-count (1- cc-count)))))))))))))
2030
2031 (defun gnus-article-hide-header (header)
2032 (save-excursion
2033 (goto-char (point-min))
2034 (when (re-search-forward (concat "^" header ":") nil t)
2035 (gnus-article-hide-text-type
2036 (point-at-bol)
2037 (progn
2038 (end-of-line)
2039 (if (re-search-forward "^[^ \t]" nil t)
2040 (match-beginning 0)
2041 (point-max)))
2042 'boring-headers))))
2043
2044 (defvar gnus-article-normalized-header-length 40
2045 "Length of normalized headers.")
2046
2047 (defun article-normalize-headers ()
2048 "Make all header lines 40 characters long."
2049 (interactive)
2050 (let ((inhibit-read-only t)
2051 column)
2052 (save-excursion
2053 (save-restriction
2054 (article-narrow-to-head)
2055 (while (not (eobp))
2056 (cond
2057 ((< (setq column (- (point-at-eol) (point)))
2058 gnus-article-normalized-header-length)
2059 (end-of-line)
2060 (insert (make-string
2061 (- gnus-article-normalized-header-length column)
2062 ? )))
2063 ((> column gnus-article-normalized-header-length)
2064 (gnus-put-text-property
2065 (progn
2066 (forward-char gnus-article-normalized-header-length)
2067 (point))
2068 (point-at-eol)
2069 'invisible t))
2070 (t
2071 ;; Do nothing.
2072 ))
2073 (forward-line 1))))))
2074
2075 (defun article-treat-dumbquotes ()
2076 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2077 Note that this function guesses whether a character is a sm*rtq**t* or
2078 not, so it should only be used interactively.
2079
2080 Sm*rtq**t*s are M****s***'s unilateral extension to the
2081 iso-8859-1 character map in an attempt to provide more quoting
2082 characters. If you see something like \\222 or \\264 where
2083 you're expecting some kind of apostrophe or quotation mark, then
2084 try this wash."
2085 (interactive)
2086 (article-translate-strings gnus-article-dumbquotes-map))
2087
2088 (defun article-translate-characters (from to)
2089 "Translate all characters in the body of the article according to FROM and TO.
2090 FROM is a string of characters to translate from; to is a string of
2091 characters to translate to."
2092 (save-excursion
2093 (when (article-goto-body)
2094 (let ((inhibit-read-only t)
2095 (x (make-string 225 ?x))
2096 (i -1))
2097 (while (< (incf i) (length x))
2098 (aset x i i))
2099 (setq i 0)
2100 (while (< i (length from))
2101 (aset x (aref from i) (aref to i))
2102 (incf i))
2103 (translate-region (point) (point-max) x)))))
2104
2105 (defun article-translate-strings (map)
2106 "Translate all string in the body of the article according to MAP.
2107 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2108 (save-excursion
2109 (when (article-goto-body)
2110 (let ((inhibit-read-only t))
2111 (dolist (elem map)
2112 (save-excursion
2113 (while (search-forward (car elem) nil t)
2114 (replace-match (cadr elem)))))))))
2115
2116 (defun article-treat-overstrike ()
2117 "Translate overstrikes into bold text."
2118 (interactive)
2119 (save-excursion
2120 (when (article-goto-body)
2121 (let ((inhibit-read-only t))
2122 (while (search-forward "\b" nil t)
2123 (let ((next (char-after))
2124 (previous (char-after (- (point) 2))))
2125 ;; We do the boldification/underlining by hiding the
2126 ;; overstrikes and putting the proper text property
2127 ;; on the letters.
2128 (cond
2129 ((eq next previous)
2130 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2131 (put-text-property (point) (1+ (point)) 'face 'bold))
2132 ((eq next ?_)
2133 (gnus-article-hide-text-type
2134 (1- (point)) (1+ (point)) 'overstrike)
2135 (put-text-property
2136 (- (point) 2) (1- (point)) 'face 'underline))
2137 ((eq previous ?_)
2138 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2139 (put-text-property
2140 (point) (1+ (point)) 'face 'underline)))))))))
2141
2142 (defun article-treat-ansi-sequences ()
2143 "Translate ANSI SGR control sequences into overlays or extents."
2144 (interactive)
2145 (save-excursion
2146 (when (article-goto-body)
2147 (let ((inhibit-read-only t))
2148 (ansi-color-apply-on-region (point) (point-max))))))
2149
2150 (defun gnus-article-treat-unfold-headers ()
2151 "Unfold folded message headers.
2152 Only the headers that fit into the current window width will be
2153 unfolded."
2154 (interactive)
2155 (gnus-with-article-headers
2156 (let (length)
2157 (while (not (eobp))
2158 (save-restriction
2159 (mail-header-narrow-to-field)
2160 (let* ((header (buffer-string))
2161 (unfoldable
2162 (or (equal gnus-article-unfold-long-headers t)
2163 (and (stringp gnus-article-unfold-long-headers)
2164 (string-match gnus-article-unfold-long-headers header)))))
2165 (with-temp-buffer
2166 (insert header)
2167 (goto-char (point-min))
2168 (while (re-search-forward "\n[\t ]" nil t)
2169 (replace-match " " t t)))
2170 (setq length (- (point-max) (point-min) 1))
2171 (when (or unfoldable
2172 (< length (window-width)))
2173 (while (re-search-forward "\n[\t ]" nil t)
2174 (replace-match " " t t))))
2175 (goto-char (point-max)))))))
2176
2177 (defun gnus-article-treat-fold-headers ()
2178 "Fold message headers."
2179 (interactive)
2180 (gnus-with-article-headers
2181 (while (not (eobp))
2182 (save-restriction
2183 (mail-header-narrow-to-field)
2184 (mail-header-fold-field)
2185 (goto-char (point-max))))))
2186
2187 (defun gnus-treat-smiley ()
2188 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2189 (interactive)
2190 (gnus-with-article-buffer
2191 (if (memq 'smiley gnus-article-wash-types)
2192 (gnus-delete-images 'smiley)
2193 (article-goto-body)
2194 (let ((images (smiley-region (point) (point-max))))
2195 (when images
2196 (gnus-add-wash-type 'smiley)
2197 (dolist (image images)
2198 (gnus-add-image 'smiley image)))))))
2199
2200 (defun gnus-article-remove-images ()
2201 "Remove all images from the article buffer."
2202 (interactive)
2203 (gnus-with-article-buffer
2204 (dolist (elem gnus-article-image-alist)
2205 (gnus-delete-images (car elem)))))
2206
2207 (defun gnus-article-treat-fold-newsgroups ()
2208 "Unfold folded message headers.
2209 Only the headers that fit into the current window width will be
2210 unfolded."
2211 (interactive)
2212 (gnus-with-article-headers
2213 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2214 (save-restriction
2215 (mail-header-narrow-to-field)
2216 (while (re-search-forward ", *" nil t)
2217 (replace-match ", " t t))
2218 (mail-header-fold-field)
2219 (goto-char (point-max))))))
2220
2221 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2222 "Value of `truncate-lines' in Gnus Article buffer.
2223 Valid values are nil, t, `head', `first', `last', an integer or a
2224 predicate. See Info node `(gnus)Customizing Articles'."
2225 :version "23.1" ;; No Gnus
2226 :group 'gnus-article
2227 ;; :link '(custom-manual "(gnus)Customizing Articles")
2228 :type 'boolean)
2229
2230 (defun gnus-article-toggle-truncate-lines (&optional arg)
2231 "Toggle whether to fold or truncate long lines in article the buffer.
2232 If ARG is non-nil and not a number, toggle
2233 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2234 long lines iff arg is positive."
2235 (interactive "P")
2236 (cond
2237 ((and (numberp arg) (> arg 0))
2238 (setq gnus-article-truncate-lines t))
2239 ((numberp arg)
2240 (setq gnus-article-truncate-lines nil))
2241 (arg
2242 (setq gnus-article-truncate-lines
2243 (not gnus-article-truncate-lines))))
2244 (gnus-with-article-buffer
2245 (cond
2246 ((and (numberp arg) (> arg 0))
2247 (setq truncate-lines nil))
2248 ((numberp arg)
2249 (setq truncate-lines t)))
2250 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2251 ;; `toggle-truncate-lines' needs an argument.
2252 (toggle-truncate-lines)))
2253
2254 (defun gnus-article-treat-body-boundary ()
2255 "Place a boundary line at the end of the headers."
2256 (interactive)
2257 (when (and gnus-body-boundary-delimiter
2258 (> (length gnus-body-boundary-delimiter) 0))
2259 (gnus-with-article-headers
2260 (goto-char (point-max))
2261 (let ((start (point)))
2262 (insert "X-Boundary: ")
2263 (gnus-add-text-properties start (point) '(invisible t intangible t))
2264 (insert (let (str)
2265 (while (>= (1- (window-width)) (length str))
2266 (setq str (concat str gnus-body-boundary-delimiter)))
2267 (substring str 0 (1- (window-width))))
2268 "\n")
2269 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2270
2271 (defun article-fill-long-lines ()
2272 "Fill lines that are wider than the window width."
2273 (interactive)
2274 (save-excursion
2275 (let ((inhibit-read-only t)
2276 (width (window-width (get-buffer-window (current-buffer)))))
2277 (save-restriction
2278 (article-goto-body)
2279 (let ((adaptive-fill-mode nil)) ;Why? -sm
2280 (while (not (eobp))
2281 (end-of-line)
2282 (when (>= (current-column) (min fill-column width))
2283 (narrow-to-region (min (1+ (point)) (point-max))
2284 (point-at-bol))
2285 (let ((goback (point-marker)))
2286 (fill-paragraph nil)
2287 (goto-char (marker-position goback)))
2288 (widen))
2289 (forward-line 1)))))))
2290
2291 (defun article-capitalize-sentences ()
2292 "Capitalize the first word in each sentence."
2293 (interactive)
2294 (save-excursion
2295 (let ((inhibit-read-only t)
2296 (paragraph-start "^[\n\^L]"))
2297 (article-goto-body)
2298 (while (not (eobp))
2299 (capitalize-word 1)
2300 (forward-sentence)))))
2301
2302 (defun article-remove-cr ()
2303 "Remove trailing CRs and then translate remaining CRs into LFs."
2304 (interactive)
2305 (save-excursion
2306 (let ((inhibit-read-only t))
2307 (goto-char (point-min))
2308 (while (re-search-forward "\r+$" nil t)
2309 (replace-match "" t t))
2310 (goto-char (point-min))
2311 (while (search-forward "\r" nil t)
2312 (replace-match "\n" t t)))))
2313
2314 (defun article-remove-trailing-blank-lines ()
2315 "Remove all trailing blank lines from the article."
2316 (interactive)
2317 (save-excursion
2318 (let ((inhibit-read-only t))
2319 (goto-char (point-max))
2320 (delete-region
2321 (point)
2322 (progn
2323 (while (and (not (bobp))
2324 (looking-at "^[ \t]*$")
2325 (not (gnus-annotation-in-region-p
2326 (point) (point-at-eol))))
2327 (forward-line -1))
2328 (forward-line 1)
2329 (point))))))
2330
2331 (defvar gnus-face-properties-alist)
2332
2333 (defun article-display-face (&optional force)
2334 "Display any Face headers in the header."
2335 (interactive (list 'force))
2336 (let ((wash-face-p buffer-read-only))
2337 (gnus-with-article-headers
2338 ;; When displaying parts, this function can be called several times on
2339 ;; the same article, without any intended toggle semantic (as typing `W
2340 ;; D d' would have). So face deletion must occur only when we come from
2341 ;; an interactive command, that is when the *Article* buffer is
2342 ;; read-only.
2343 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2344 (gnus-delete-images 'face)
2345 (let ((from (message-fetch-field "from"))
2346 face faces)
2347 (save-current-buffer
2348 (when (and wash-face-p
2349 (gnus-buffer-live-p gnus-original-article-buffer)
2350 (not (re-search-forward "^Face:[\t ]*" nil t)))
2351 (set-buffer gnus-original-article-buffer))
2352 (save-restriction
2353 (mail-narrow-to-head)
2354 (when (or force
2355 ;; Check whether this face is censored.
2356 (not (and gnus-article-x-face-too-ugly
2357 (or from
2358 (setq from (message-fetch-field "from")))
2359 (string-match gnus-article-x-face-too-ugly
2360 from))))
2361 (while (gnus-article-goto-header "Face")
2362 (push (mail-header-field-value) faces)))))
2363 (when faces
2364 (goto-char (point-min))
2365 (let (png image)
2366 (unless (setq from (gnus-article-goto-header "from"))
2367 (insert "From:")
2368 (setq from (point))
2369 (insert " [no `from' set]\n"))
2370 (while faces
2371 (when (setq png (gnus-convert-face-to-png (pop faces)))
2372 (setq image
2373 (apply 'gnus-create-image png 'png t
2374 (cdr (assq 'png gnus-face-properties-alist))))
2375 (goto-char from)
2376 (gnus-add-wash-type 'face)
2377 (gnus-add-image 'face image)
2378 (gnus-put-image image nil 'face))))))))))
2379
2380 (defun article-display-x-face (&optional force)
2381 "Look for an X-Face header and display it if present."
2382 (interactive (list 'force))
2383 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2384 (gnus-with-article-headers
2385 ;; Delete the old process, if any.
2386 (when (process-status "article-x-face")
2387 (delete-process "article-x-face"))
2388 ;; See the comment in `article-display-face'.
2389 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2390 ;; We have already displayed X-Faces, so we remove them
2391 ;; instead.
2392 (gnus-delete-images 'xface)
2393 ;; Display X-Faces.
2394 (let ((from (message-fetch-field "from"))
2395 x-faces face)
2396 (save-current-buffer
2397 (when (and wash-face-p
2398 (gnus-buffer-live-p gnus-original-article-buffer)
2399 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2400 ;; If type `W f', use gnus-original-article-buffer,
2401 ;; otherwise use the current buffer because displaying
2402 ;; RFC822 parts calls this function too.
2403 (set-buffer gnus-original-article-buffer))
2404 (save-restriction
2405 (mail-narrow-to-head)
2406 (and gnus-article-x-face-command
2407 (or force
2408 ;; Check whether this face is censored.
2409 (not (and gnus-article-x-face-too-ugly
2410 (or from
2411 (setq from (message-fetch-field "from")))
2412 (string-match gnus-article-x-face-too-ugly
2413 from))))
2414 (while (gnus-article-goto-header "X-Face")
2415 (push (mail-header-field-value) x-faces)))))
2416 (when x-faces
2417 ;; We display the face.
2418 (cond ((functionp gnus-article-x-face-command)
2419 ;; The command is a lisp function, so we call it.
2420 (mapc gnus-article-x-face-command x-faces))
2421 ((stringp gnus-article-x-face-command)
2422 ;; The command is a string, so we interpret the command
2423 ;; as a, well, command, and fork it off.
2424 (let ((process-connection-type nil))
2425 (gnus-set-process-query-on-exit-flag
2426 (start-process
2427 "article-x-face" nil shell-file-name
2428 shell-command-switch gnus-article-x-face-command)
2429 nil)
2430 ;; Sending multiple EOFs to xv doesn't work,
2431 ;; so we only do a single external face.
2432 (with-temp-buffer
2433 (insert (car x-faces))
2434 (process-send-region "article-x-face"
2435 (point-min) (point-max)))
2436 (process-send-eof "article-x-face")))
2437 (t
2438 (error "`%s' set to `%s' is not a function"
2439 gnus-article-x-face-command
2440 'gnus-article-x-face-command)))))))))
2441
2442 (defun article-decode-mime-words ()
2443 "Decode all MIME-encoded words in the article."
2444 (interactive)
2445 (gnus-with-article-buffer
2446 (let ((inhibit-point-motion-hooks t)
2447 (mail-parse-charset gnus-newsgroup-charset)
2448 (mail-parse-ignored-charsets
2449 (with-current-buffer gnus-summary-buffer
2450 gnus-newsgroup-ignored-charsets)))
2451 (mail-decode-encoded-word-region (point-min) (point-max)))))
2452
2453 (defun article-decode-charset (&optional prompt)
2454 "Decode charset-encoded text in the article.
2455 If PROMPT (the prefix), prompt for a coding system to use."
2456 (interactive "P")
2457 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2458 (inhibit-read-only t)
2459 (mail-parse-charset gnus-newsgroup-charset)
2460 (mail-parse-ignored-charsets
2461 (save-excursion (condition-case nil
2462 (set-buffer gnus-summary-buffer)
2463 (error))
2464 gnus-newsgroup-ignored-charsets))
2465 ct cte ctl charset format)
2466 (save-excursion
2467 (save-restriction
2468 (article-narrow-to-head)
2469 (setq ct (message-fetch-field "Content-Type" t)
2470 cte (message-fetch-field "Content-Transfer-Encoding" t)
2471 ctl (and ct (mail-header-parse-content-type ct))
2472 charset (cond
2473 (prompt
2474 (mm-read-coding-system "Charset to decode: "))
2475 (ctl
2476 (mail-content-type-get ctl 'charset)))
2477 format (and ctl (mail-content-type-get ctl 'format)))
2478 (when cte
2479 (setq cte (mail-header-strip cte)))
2480 (if (and ctl (not (string-match "/" (car ctl))))
2481 (setq ctl nil))
2482 (goto-char (point-max)))
2483 (forward-line 1)
2484 (save-restriction
2485 (narrow-to-region (point) (point-max))
2486 (when (and (eq mail-parse-charset 'gnus-decoded)
2487 (eq (mm-body-7-or-8) '8bit))
2488 ;; The text code could have been decoded.
2489 (setq charset mail-parse-charset))
2490 (when (and (or (not ctl)
2491 (equal (car ctl) "text/plain"))
2492 (not format)) ;; article with format will decode later.
2493 (mm-decode-body
2494 charset (and cte (intern (downcase
2495 (gnus-strip-whitespace cte))))
2496 (car ctl)))))))
2497
2498 (defun article-decode-encoded-words ()
2499 "Remove encoded-word encoding from headers."
2500 (let ((inhibit-point-motion-hooks t)
2501 (mail-parse-charset gnus-newsgroup-charset)
2502 (mail-parse-ignored-charsets
2503 (save-excursion (condition-case nil
2504 (set-buffer gnus-summary-buffer)
2505 (error))
2506 gnus-newsgroup-ignored-charsets))
2507 (inhibit-read-only t)
2508 end start)
2509 (goto-char (point-min))
2510 (when (search-forward "\n\n" nil 'move)
2511 (forward-line -1))
2512 (setq end (point))
2513 (while (not (bobp))
2514 (while (progn
2515 (forward-line -1)
2516 (and (not (bobp))
2517 (memq (char-after) '(?\t ? )))))
2518 (setq start (point))
2519 (if (looking-at "\
2520 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2521 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2522 (funcall gnus-decode-address-function start end)
2523 (funcall gnus-decode-header-function start end))
2524 (goto-char (setq end start)))))
2525
2526 (defun article-decode-group-name ()
2527 "Decode group names in Newsgroups, Followup-To and Xref headers."
2528 (let ((inhibit-point-motion-hooks t)
2529 (inhibit-read-only t)
2530 (method (gnus-find-method-for-group gnus-newsgroup-name))
2531 regexp)
2532 (when (and (or gnus-group-name-charset-method-alist
2533 gnus-group-name-charset-group-alist)
2534 (gnus-buffer-live-p gnus-original-article-buffer))
2535 (save-restriction
2536 (article-narrow-to-head)
2537 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2538 (with-current-buffer gnus-original-article-buffer
2539 (goto-char (point-min)))
2540 (setq regexp (concat "^" header
2541 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2542 (while (re-search-forward regexp nil t)
2543 (replace-match (save-match-data
2544 (gnus-decode-newsgroups
2545 ;; XXX how to use data in article buffer?
2546 (with-current-buffer gnus-original-article-buffer
2547 (re-search-forward regexp nil t)
2548 (match-string 1))
2549 gnus-newsgroup-name method))
2550 t t nil 1))
2551 (goto-char (point-min)))))))
2552
2553 (autoload 'idna-to-unicode "idna")
2554
2555 (defun article-decode-idna-rhs ()
2556 "Decode IDNA strings in RHS in various headers in current buffer.
2557 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2558 Mail-Reply-To: and Mail-Followup-To:."
2559 (when gnus-use-idna
2560 (save-restriction
2561 (let ((inhibit-point-motion-hooks t)
2562 (inhibit-read-only t))
2563 (article-narrow-to-head)
2564 (goto-char (point-min))
2565 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2566 (let (ace unicode)
2567 (when (save-match-data
2568 (and (setq ace (match-string 1))
2569 (save-excursion
2570 (and (re-search-backward "^[^ \t]" nil t)
2571 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2572 (setq unicode (idna-to-unicode ace))))
2573 (unless (string= ace unicode)
2574 (replace-match unicode nil nil nil 1)))))))))
2575
2576 (defun article-de-quoted-unreadable (&optional force read-charset)
2577 "Translate a quoted-printable-encoded article.
2578 If FORCE, decode the article whether it is marked as quoted-printable
2579 or not.
2580 If READ-CHARSET, ask for a coding system."
2581 (interactive (list 'force current-prefix-arg))
2582 (save-excursion
2583 (let ((inhibit-read-only t) type charset)
2584 (if (gnus-buffer-live-p gnus-original-article-buffer)
2585 (with-current-buffer gnus-original-article-buffer
2586 (setq type
2587 (gnus-fetch-field "content-transfer-encoding"))
2588 (let* ((ct (gnus-fetch-field "content-type"))
2589 (ctl (and ct (mail-header-parse-content-type ct))))
2590 (setq charset (and ctl
2591 (mail-content-type-get ctl 'charset)))
2592 (if (stringp charset)
2593 (setq charset (intern (downcase charset)))))))
2594 (if read-charset
2595 (setq charset (mm-read-coding-system "Charset: " charset)))
2596 (unless charset
2597 (setq charset gnus-newsgroup-charset))
2598 (when (or force
2599 (and type (let ((case-fold-search t))
2600 (string-match "quoted-printable" type))))
2601 (article-goto-body)
2602 (quoted-printable-decode-region
2603 (point) (point-max) (mm-charset-to-coding-system charset))))))
2604
2605 (defun article-de-base64-unreadable (&optional force read-charset)
2606 "Translate a base64 article.
2607 If FORCE, decode the article whether it is marked as base64 not.
2608 If READ-CHARSET, ask for a coding system."
2609 (interactive (list 'force current-prefix-arg))
2610 (save-excursion
2611 (let ((inhibit-read-only t) type charset)
2612 (if (gnus-buffer-live-p gnus-original-article-buffer)
2613 (with-current-buffer gnus-original-article-buffer
2614 (setq type
2615 (gnus-fetch-field "content-transfer-encoding"))
2616 (let* ((ct (gnus-fetch-field "content-type"))
2617 (ctl (and ct (mail-header-parse-content-type ct))))
2618 (setq charset (and ctl
2619 (mail-content-type-get ctl 'charset)))
2620 (if (stringp charset)
2621 (setq charset (intern (downcase charset)))))))
2622 (if read-charset
2623 (setq charset (mm-read-coding-system "Charset: " charset)))
2624 (unless charset
2625 (setq charset gnus-newsgroup-charset))
2626 (when (or force
2627 (and type (let ((case-fold-search t))
2628 (string-match "base64" type))))
2629 (article-goto-body)
2630 (save-restriction
2631 (narrow-to-region (point) (point-max))
2632 (base64-decode-region (point-min) (point-max))
2633 (mm-decode-coding-region
2634 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2635
2636 (eval-when-compile
2637 (require 'rfc1843))
2638
2639 (defun article-decode-HZ ()
2640 "Translate a HZ-encoded article."
2641 (interactive)
2642 (require 'rfc1843)
2643 (save-excursion
2644 (let ((inhibit-read-only t))
2645 (rfc1843-decode-region (point-min) (point-max)))))
2646
2647 (defun article-unsplit-urls ()
2648 "Remove the newlines that some other mailers insert into URLs."
2649 (interactive)
2650 (save-excursion
2651 (let ((inhibit-read-only t))
2652 (goto-char (point-min))
2653 (while (re-search-forward
2654 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2655 (replace-match "\\1\\3" t)))
2656 (when (interactive-p)
2657 (gnus-treat-article nil))))
2658
2659
2660 (defun article-wash-html (&optional read-charset)
2661 "Format an HTML article.
2662 If READ-CHARSET, ask for a coding system. If it is a number, the
2663 charset defined in `gnus-summary-show-article-charset-alist' is used."
2664 (interactive "P")
2665 (save-excursion
2666 (let ((inhibit-read-only t)
2667 charset)
2668 (if read-charset
2669 (if (or (and (numberp read-charset)
2670 (setq charset
2671 (cdr
2672 (assq read-charset
2673 gnus-summary-show-article-charset-alist))))
2674 (setq charset (mm-read-coding-system "Charset: ")))
2675 (let ((gnus-summary-show-article-charset-alist
2676 (list (cons 1 charset))))
2677 (with-current-buffer gnus-summary-buffer
2678 (gnus-summary-show-article 1)))
2679 (error "No charset is given"))
2680 (when (gnus-buffer-live-p gnus-original-article-buffer)
2681 (with-current-buffer gnus-original-article-buffer
2682 (let* ((ct (gnus-fetch-field "content-type"))
2683 (ctl (and ct (mail-header-parse-content-type ct))))
2684 (setq charset (and ctl
2685 (mail-content-type-get ctl 'charset)))
2686 (when (stringp charset)
2687 (setq charset (intern (downcase charset)))))))
2688 (unless charset
2689 (setq charset gnus-newsgroup-charset)))
2690 (article-goto-body)
2691 (save-window-excursion
2692 (save-restriction
2693 (narrow-to-region (point) (point-max))
2694 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2695 (entry (assq func mm-text-html-washer-alist)))
2696 (when entry
2697 (setq func (cdr entry)))
2698 (cond
2699 ((functionp func)
2700 (funcall func))
2701 (t
2702 (apply (car func) (cdr func))))))))))
2703
2704 ;; External.
2705 (declare-function w3-region "ext:w3-display" (st nd))
2706
2707 (defun gnus-article-wash-html-with-w3 ()
2708 "Wash the current buffer with w3."
2709 (mm-setup-w3)
2710 (let ((w3-strict-width (window-width))
2711 (url-standalone-mode t)
2712 (url-gateway-unplugged t)
2713 (w3-honor-stylesheets nil))
2714 (condition-case ()
2715 (w3-region (point-min) (point-max))
2716 (error))))
2717
2718 ;; External.
2719 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2720
2721 (defun gnus-article-wash-html-with-w3m ()
2722 "Wash the current buffer with emacs-w3m."
2723 (mm-setup-w3m)
2724 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2725 w3m-force-redisplay)
2726 (w3m-region (point-min) (point-max)))
2727 (when (and mm-inline-text-html-with-w3m-keymap
2728 (boundp 'w3m-minor-mode-map)
2729 w3m-minor-mode-map)
2730 (add-text-properties
2731 (point-min) (point-max)
2732 (list 'keymap w3m-minor-mode-map
2733 ;; Put the mark meaning this part was rendered by emacs-w3m.
2734 'mm-inline-text-html-with-w3m t))))
2735
2736 (defvar charset) ;; Bound by `article-wash-html'.
2737
2738 (defun gnus-article-wash-html-with-w3m-standalone ()
2739 "Wash the current buffer with w3m."
2740 (if (mm-w3m-standalone-supports-m17n-p)
2741 (progn
2742 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2743 ;; The default.
2744 (setq charset 'iso-8859-1))
2745 (let ((coding-system-for-write charset)
2746 (coding-system-for-read charset))
2747 (call-process-region
2748 (point-min) (point-max)
2749 "w3m" t t nil "-dump" "-T" "text/html"
2750 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2751 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2752
2753 (defvar gnus-article-browse-html-temp-list nil
2754 "List of temporary files created by `gnus-article-browse-html-parts'.
2755 Internal variable.")
2756
2757 (defcustom gnus-article-browse-delete-temp 'ask
2758 "What to do with temporary files from `gnus-article-browse-html-parts'.
2759 If nil, don't delete temporary files. If it is t, delete them on
2760 exit from the summary buffer. If it is the symbol `file', query
2761 on each file, if it is `ask' ask once when exiting from the
2762 summary buffer."
2763 :group 'gnus-article
2764 :version "23.1" ;; No Gnus
2765 :type '(choice (const :tag "Don't delete" nil)
2766 (const :tag "Don't ask" t)
2767 (const :tag "Ask" ask)
2768 (const :tag "Ask for each file" file)))
2769
2770 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2771
2772 (defun gnus-article-browse-delete-temp-files (&optional how)
2773 "Delete temp-files created by `gnus-article-browse-html-parts'."
2774 (when (and gnus-article-browse-html-temp-list
2775 (or how
2776 (setq how gnus-article-browse-delete-temp)))
2777 (when (and (eq how 'ask)
2778 (gnus-y-or-n-p (format
2779 "Delete all %s temporary HTML file(s)? "
2780 (length gnus-article-browse-html-temp-list)))
2781 (setq how t)))
2782 (dolist (file gnus-article-browse-html-temp-list)
2783 (when (and (file-exists-p file)
2784 (or (eq how t)
2785 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2786 (gnus-y-or-n-p
2787 (format "Delete temporary HTML file `%s'? " file))))
2788 (delete-file file)))
2789 ;; Also remove file from the list when not deleted or if file doesn't
2790 ;; exist anymore.
2791 (setq gnus-article-browse-html-temp-list nil))
2792 gnus-article-browse-html-temp-list)
2793
2794 (defun gnus-article-browse-html-parts (list &optional header)
2795 "View all \"text/html\" parts from LIST.
2796 Recurse into multiparts. The optional HEADER that should be a decoded
2797 message header will be added to the bodies of the \"text/html\" parts."
2798 ;; Internal function used by `gnus-article-browse-html-article'.
2799 (let (type file charset tmp-file showed)
2800 ;; Find and show the html-parts.
2801 (dolist (handle list)
2802 ;; If HTML, show it:
2803 (cond ((not (listp handle)))
2804 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2805 (and (equal (car type) "message/external-body")
2806 (or header
2807 (setq file (or (mail-content-type-get type 'name)
2808 (mail-content-type-get
2809 (mm-handle-disposition handle)
2810 'filename))))
2811 (or (mm-handle-cache handle)
2812 (condition-case code
2813 (progn (mm-extern-cache-contents handle) t)
2814 (error
2815 (gnus-message 3 "%s" (error-message-string code))
2816 (when (>= gnus-verbose 3) (sit-for 2))
2817 nil)))
2818 (progn
2819 (setq handle (mm-handle-cache handle)
2820 type (mm-handle-type handle))
2821 (equal (car type) "text/html"))))
2822 (when (or (setq charset (mail-content-type-get type 'charset))
2823 header
2824 (not file))
2825 (setq tmp-file (mm-make-temp-file
2826 ;; Do we need to care for 8.3 filenames?
2827 "mm-" nil ".html")))
2828 ;; Add a meta html tag to specify charset and a header.
2829 (cond
2830 (header
2831 (let (title eheader body hcharset coding)
2832 (with-temp-buffer
2833 (mm-enable-multibyte)
2834 (setq case-fold-search t)
2835 (insert header "\n")
2836 (setq title (message-fetch-field "subject"))
2837 (goto-char (point-min))
2838 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2839 (replace-match (cond ((match-beginning 1) "&lt;")
2840 ((match-beginning 2) "&gt;")
2841 (t "&amp;"))))
2842 (goto-char (point-min))
2843 (insert "<pre>\n")
2844 (goto-char (point-max))
2845 (insert "</pre>\n<hr>\n")
2846 ;; We have to examine charset one by one since
2847 ;; charset specified in parts might be different.
2848 (if (eq charset 'gnus-decoded)
2849 (setq charset 'utf-8
2850 eheader (mm-encode-coding-string (buffer-string)
2851 charset)
2852 title (when title
2853 (mm-encode-coding-string title charset))
2854 body (mm-encode-coding-string (mm-get-part handle)
2855 charset))
2856 (setq hcharset (mm-find-mime-charset-region (point-min)
2857 (point-max)))
2858 (cond ((= (length hcharset) 1)
2859 (setq hcharset (car hcharset)
2860 coding (mm-charset-to-coding-system
2861 hcharset)))
2862 ((> (length hcharset) 1)
2863 (setq hcharset 'utf-8
2864 coding hcharset)))
2865 (if coding
2866 (if charset
2867 (progn
2868 (setq body
2869 (mm-charset-to-coding-system charset))
2870 (if (eq coding body)
2871 (setq eheader (mm-encode-coding-string
2872 (buffer-string) coding)
2873 title (when title
2874 (mm-encode-coding-string
2875 title coding))
2876 body (mm-get-part handle))
2877 (setq charset 'utf-8
2878 eheader (mm-encode-coding-string
2879 (buffer-string) charset)
2880 title (when title
2881 (mm-encode-coding-string
2882 title charset))
2883 body (mm-encode-coding-string
2884 (mm-decode-coding-string
2885 (mm-get-part handle) body)
2886 charset))))
2887 (setq charset hcharset
2888 eheader (mm-encode-coding-string
2889 (buffer-string) coding)
2890 title (when title
2891 (mm-encode-coding-string
2892 title coding))
2893 body (mm-get-part handle)))
2894 (setq eheader (mm-string-as-unibyte (buffer-string))
2895 body (mm-get-part handle))))
2896 (erase-buffer)
2897 (mm-disable-multibyte)
2898 (insert body)
2899 (when charset
2900 (mm-add-meta-html-tag handle charset))
2901 (when title
2902 (goto-char (point-min))
2903 (unless (search-forward "<title>" nil t)
2904 (re-search-forward "<head>\\s-*" nil t)
2905 (insert "<title>" title "</title>\n")))
2906 (goto-char (point-min))
2907 (or (re-search-forward
2908 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2909 (re-search-forward
2910 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2911 (insert eheader)
2912 (mm-write-region (point-min) (point-max)
2913 tmp-file nil nil nil 'binary t))))
2914 (charset
2915 (mm-with-unibyte-buffer
2916 (insert (if (eq charset 'gnus-decoded)
2917 (mm-encode-coding-string
2918 (mm-get-part handle)
2919 (setq charset 'utf-8))
2920 (mm-get-part handle)))
2921 (if (or (mm-add-meta-html-tag handle charset)
2922 (not file))
2923 (mm-write-region (point-min) (point-max)
2924 tmp-file nil nil nil 'binary t)
2925 (setq tmp-file nil))))
2926 (tmp-file
2927 (mm-save-part-to-file handle tmp-file)))
2928 (when tmp-file
2929 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2930 (add-hook 'gnus-summary-prepare-exit-hook
2931 'gnus-article-browse-delete-temp-files)
2932 (add-hook 'gnus-exit-gnus-hook
2933 (lambda ()
2934 (gnus-article-browse-delete-temp-files t)))
2935 ;; FIXME: Warn if there's an <img> tag?
2936 (browse-url-of-file (or tmp-file (expand-file-name file)))
2937 (setq showed t))
2938 ;; If multipart, recurse
2939 ((equal (mm-handle-media-supertype handle) "multipart")
2940 (when (gnus-article-browse-html-parts handle header)
2941 (setq showed t)))
2942 ((equal (mm-handle-media-type handle) "message/rfc822")
2943 (mm-with-multibyte-buffer
2944 (mm-insert-part handle)
2945 (setq handle (mm-dissect-buffer t t))
2946 (when (and (bufferp (car handle))
2947 (stringp (car (mm-handle-type handle))))
2948 (setq handle (list handle)))
2949 (when header
2950 (article-decode-encoded-words)
2951 (let ((gnus-visible-headers
2952 (or (get 'gnus-visible-headers 'standard-value)
2953 gnus-visible-headers)))
2954 (article-hide-headers))
2955 (goto-char (point-min))
2956 (search-forward "\n\n" nil 'move)
2957 (skip-chars-backward "\t\n ")
2958 (setq header (buffer-substring (point-min) (point)))))
2959 (when (prog1
2960 (gnus-article-browse-html-parts handle header)
2961 (mm-destroy-parts handle))
2962 (setq showed t)))))
2963 showed))
2964
2965 ;; FIXME: Documentation in texi/gnus.texi missing.
2966 (defun gnus-article-browse-html-article (&optional arg)
2967 "View \"text/html\" parts of the current article with a WWW browser.
2968 The message header is added to the beginning of every html part unless
2969 the prefix argument ARG is given.
2970
2971 Warning: Spammers use links to images in HTML articles to verify
2972 whether you have read the message. As
2973 `gnus-article-browse-html-article' passes the unmodified HTML
2974 content to the browser without eliminating these \"web bugs\" you
2975 should only use it for mails from trusted senders.
2976
2977 If you alwasy want to display HTML part in the browser, set
2978 `mm-text-html-renderer' to nil."
2979 ;; Cf. `mm-w3m-safe-url-regexp'
2980 (interactive "P")
2981 (if arg
2982 (gnus-summary-show-article)
2983 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
2984 gnus-visible-headers)))
2985 (gnus-summary-show-article)))
2986 (with-current-buffer gnus-article-buffer
2987 (let ((header (unless arg
2988 (save-restriction
2989 (widen)
2990 (buffer-substring-no-properties
2991 (goto-char (point-min))
2992 (if (search-forward "\n\n" nil t)
2993 (match-beginning 0)
2994 (goto-char (point-max))
2995 (skip-chars-backward "\t\n ")
2996 (point))))))
2997 parts)
2998 (set-buffer gnus-original-article-buffer)
2999 (setq parts (mm-dissect-buffer t t))
3000 ;; If singlepart, enforce a list.
3001 (when (and (bufferp (car parts))
3002 (stringp (car (mm-handle-type parts))))
3003 (setq parts (list parts)))
3004 ;; Process the list
3005 (unless (gnus-article-browse-html-parts parts header)
3006 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3007 (mm-destroy-parts parts)
3008 (unless arg
3009 (gnus-summary-show-article)))))
3010
3011 (defun article-hide-list-identifiers ()
3012 "Remove list identifies from the Subject header.
3013 The `gnus-list-identifiers' variable specifies what to do."
3014 (interactive)
3015 (let ((inhibit-point-motion-hooks t)
3016 (regexp (if (consp gnus-list-identifiers)
3017 (mapconcat 'identity gnus-list-identifiers " *\\|")
3018 gnus-list-identifiers))
3019 (inhibit-read-only t))
3020 (when regexp
3021 (save-excursion
3022 (save-restriction
3023 (article-narrow-to-head)
3024 (goto-char (point-min))
3025 (while (re-search-forward
3026 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3027 nil t)
3028 (delete-region (match-beginning 2) (match-end 0))
3029 (beginning-of-line))
3030 (when (re-search-forward
3031 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3032 (delete-region (match-beginning 1) (match-end 1))))))))
3033
3034 (defun article-hide-pem (&optional arg)
3035 "Toggle hiding of any PEM headers and signatures in the current article.
3036 If given a negative prefix, always show; if given a positive prefix,
3037 always hide."
3038 (interactive (gnus-article-hidden-arg))
3039 (unless (gnus-article-check-hidden-text 'pem arg)
3040 (save-excursion
3041 (let ((inhibit-read-only t) end)
3042 (goto-char (point-min))
3043 ;; Hide the horrendously ugly "header".
3044 (when (and (search-forward
3045 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3046 nil t)
3047 (setq end (1+ (match-beginning 0))))
3048 (gnus-add-wash-type 'pem)
3049 (gnus-article-hide-text-type
3050 end
3051 (if (search-forward "\n\n" nil t)
3052 (match-end 0)
3053 (point-max))
3054 'pem)
3055 ;; Hide the trailer as well
3056 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3057 nil t)
3058 (gnus-article-hide-text-type
3059 (match-beginning 0) (match-end 0) 'pem)))))))
3060
3061 (defun article-strip-banner ()
3062 "Strip the banners specified by the `banner' group parameter and by
3063 `gnus-article-address-banner-alist'."
3064 (interactive)
3065 (save-excursion
3066 (save-restriction
3067 (let ((inhibit-point-motion-hooks t))
3068 (when (gnus-parameter-banner gnus-newsgroup-name)
3069 (article-really-strip-banner
3070 (gnus-parameter-banner gnus-newsgroup-name)))
3071 (when gnus-article-address-banner-alist
3072 ;; Note that the From header is decoded here, so it is
3073 ;; required that the *-extract-address-components function
3074 ;; supports non-ASCII text.
3075 (let ((from (save-restriction
3076 (widen)
3077 (article-narrow-to-head)
3078 (mail-fetch-field "from"))))
3079 (when (and from
3080 (setq from
3081 (cadr (funcall gnus-extract-address-components
3082 from))))
3083 (catch 'found
3084 (dolist (pair gnus-article-address-banner-alist)
3085 (when (string-match (car pair) from)
3086 (throw 'found
3087 (article-really-strip-banner (cdr pair)))))))))))))
3088
3089 (defun article-really-strip-banner (banner)
3090 "Strip the banner specified by the argument."
3091 (save-excursion
3092 (save-restriction
3093 (let ((inhibit-point-motion-hooks t)
3094 (gnus-signature-limit nil)
3095 (inhibit-read-only t))
3096 (article-goto-body)
3097 (cond
3098 ((eq banner 'signature)
3099 (when (gnus-article-narrow-to-signature)
3100 (widen)
3101 (forward-line -1)
3102 (delete-region (point) (point-max))))
3103 ((symbolp banner)
3104 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3105 (while (re-search-forward banner nil t)
3106 (delete-region (match-beginning 0) (match-end 0)))))
3107 ((stringp banner)
3108 (while (re-search-forward banner nil t)
3109 (delete-region (match-beginning 0) (match-end 0)))))))))
3110
3111 (defun article-babel ()
3112 "Translate article using an online translation service."
3113 (interactive)
3114 (require 'babel)
3115 (gnus-with-article-buffer
3116 (when (article-goto-body)
3117 (let* ((start (point))
3118 (end (point-max))
3119 (orig (buffer-substring start end))
3120 (trans (babel-as-string orig)))
3121 (save-restriction
3122 (narrow-to-region start end)
3123 (delete-region start end)
3124 (insert trans))))))
3125
3126 (defun article-hide-signature (&optional arg)
3127 "Hide the signature in the current article.
3128 If given a negative prefix, always show; if given a positive prefix,
3129 always hide."
3130 (interactive (gnus-article-hidden-arg))
3131 (unless (gnus-article-check-hidden-text 'signature arg)
3132 (save-excursion
3133 (save-restriction
3134 (let ((inhibit-read-only t))
3135 (when (gnus-article-narrow-to-signature)
3136 (gnus-article-hide-text-type
3137 (point-min) (point-max) 'signature))))))
3138 (gnus-set-mode-line 'article))
3139
3140 (defun article-strip-headers-in-body ()
3141 "Strip offensive headers from bodies."
3142 (interactive)
3143 (save-excursion
3144 (article-goto-body)
3145 (let ((case-fold-search t))
3146 (when (looking-at "x-no-archive:")
3147 (gnus-delete-line)))))
3148
3149 (defun article-strip-leading-blank-lines ()
3150 "Remove all blank lines from the beginning of the article."
3151 (interactive)
3152 (save-excursion
3153 (let ((inhibit-point-motion-hooks t)
3154 (inhibit-read-only t))
3155 (when (article-goto-body)
3156 (while (and (not (eobp))
3157 (looking-at "[ \t]*$"))
3158 (gnus-delete-line))))))
3159
3160 (defun article-narrow-to-head ()
3161 "Narrow the buffer to the head of the message.
3162 Point is left at the beginning of the narrowed-to region."
3163 (narrow-to-region
3164 (goto-char (point-min))
3165 (if (search-forward "\n\n" nil 1)
3166 (1- (point))
3167 (point-max)))
3168 (goto-char (point-min)))
3169
3170 (defun article-goto-body ()
3171 "Place point at the start of the body."
3172 (goto-char (point-min))
3173 (cond
3174 ;; This variable is only bound when dealing with separate
3175 ;; MIME body parts.
3176 (article-goto-body-goes-to-point-min-p
3177 t)
3178 ((search-forward "\n\n" nil t)
3179 t)
3180 (t
3181 (goto-char (point-max))
3182 nil)))
3183
3184 (defun article-strip-multiple-blank-lines ()
3185 "Replace consecutive blank lines with one empty line."
3186 (interactive)
3187 (save-excursion
3188 (let ((inhibit-point-motion-hooks t)
3189 (inhibit-read-only t))
3190 ;; First make all blank lines empty.
3191 (article-goto-body)
3192 (while (re-search-forward "^[ \t]+$" nil t)
3193 (unless (gnus-annotation-in-region-p
3194 (match-beginning 0) (match-end 0))
3195 (replace-match "" nil t)))
3196 ;; Then replace multiple empty lines with a single empty line.
3197 (article-goto-body)
3198 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3199 (unless (gnus-annotation-in-region-p
3200 (match-beginning 0) (match-end 0))
3201 (delete-region (match-beginning 1) (match-end 1)))))))
3202
3203 (defun article-strip-leading-space ()
3204 "Remove all white space from the beginning of the lines in the article."
3205 (interactive)
3206 (save-excursion
3207 (let ((inhibit-point-motion-hooks t)
3208 (inhibit-read-only t))
3209 (article-goto-body)
3210 (while (re-search-forward "^[ \t]+" nil t)
3211 (replace-match "" t t)))))
3212
3213 (defun article-strip-trailing-space ()
3214 "Remove all white space from the end of the lines in the article."
3215 (interactive)
3216 (save-excursion
3217 (let ((inhibit-point-motion-hooks t)
3218 (inhibit-read-only t))
3219 (article-goto-body)
3220 (while (re-search-forward "[ \t]+$" nil t)
3221 (replace-match "" t t)))))
3222
3223 (defun article-strip-blank-lines ()
3224 "Strip leading, trailing and multiple blank lines."
3225 (interactive)
3226 (article-strip-leading-blank-lines)
3227 (article-remove-trailing-blank-lines)
3228 (article-strip-multiple-blank-lines))
3229
3230 (defun article-strip-all-blank-lines ()
3231 "Strip all blank lines."
3232 (interactive)
3233 (save-excursion
3234 (let ((inhibit-point-motion-hooks t)
3235 (inhibit-read-only t))
3236 (article-goto-body)
3237 (while (re-search-forward "^[ \t]*\n" nil t)
3238 (replace-match "" t t)))))
3239
3240 (defun gnus-article-narrow-to-signature ()
3241 "Narrow to the signature; return t if a signature is found, else nil."
3242 (let ((inhibit-point-motion-hooks t))
3243 (when (gnus-article-search-signature)
3244 (forward-line 1)
3245 ;; Check whether we have some limits to what we consider
3246 ;; to be a signature.
3247 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3248 (list gnus-signature-limit)))
3249 limit limited)
3250 (while (setq limit (pop limits))
3251 (if (or (and (integerp limit)
3252 (< (- (point-max) (point)) limit))
3253 (and (floatp limit)
3254 (< (count-lines (point) (point-max)) limit))
3255 (and (functionp limit)
3256 (funcall limit))
3257 (and (stringp limit)
3258 (not (re-search-forward limit nil t))))
3259 () ; This limit did not succeed.
3260 (setq limited t
3261 limits nil)))
3262 (unless limited
3263 (narrow-to-region (point) (point-max))
3264 t)))))
3265
3266 (defun gnus-article-search-signature ()
3267 "Search the current buffer for the signature separator.
3268 Put point at the beginning of the signature separator."
3269 (let ((cur (point)))
3270 (goto-char (point-max))
3271 (if (if (stringp gnus-signature-separator)
3272 (re-search-backward gnus-signature-separator nil t)
3273 (let ((seps gnus-signature-separator))
3274 (while (and seps
3275 (not (re-search-backward (car seps) nil t)))
3276 (pop seps))
3277 seps))
3278 t
3279 (goto-char cur)
3280 nil)))
3281
3282 (defun gnus-article-hidden-arg ()
3283 "Return the current prefix arg as a number, or 0 if no prefix."
3284 (list (if current-prefix-arg
3285 (prefix-numeric-value current-prefix-arg)
3286 0)))
3287
3288 (defun gnus-article-check-hidden-text (type arg)
3289 "Return nil if hiding is necessary.
3290 Arg can be nil or a number. nil and positive means hide, negative
3291 means show, 0 means toggle."
3292 (save-excursion
3293 (save-restriction
3294 (let ((hide (gnus-article-hidden-text-p type)))
3295 (cond
3296 ((or (null arg)
3297 (> arg 0))
3298 nil)
3299 ((< arg 0)
3300 (gnus-article-show-hidden-text type)
3301 t)
3302 (t
3303 (if (eq hide 'hidden)
3304 (progn
3305 (gnus-article-show-hidden-text type)
3306 t)
3307 nil)))))))
3308
3309 (defun gnus-article-hidden-text-p (type)
3310 "Say whether the current buffer contains hidden text of type TYPE."
3311 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3312 (while (and pos
3313 (not (get-text-property pos 'invisible))
3314 (not (get-text-property pos 'dummy-invisible)))
3315 (setq pos
3316 (text-property-any (1+ pos) (point-max) 'article-type type)))
3317 (if pos
3318 'hidden
3319 nil)))
3320
3321 (defun gnus-article-show-hidden-text (type &optional dummy)
3322 "Show all hidden text of type TYPE.
3323 Originally it is hide instead of DUMMY."
3324 (let ((inhibit-read-only t)
3325 (inhibit-point-motion-hooks t))
3326 (gnus-remove-text-properties-when
3327 'article-type type
3328 (point-min) (point-max)
3329 (cons 'article-type (cons type
3330 gnus-hidden-properties)))
3331 (gnus-delete-wash-type type)))
3332
3333 (defconst article-time-units
3334 `((year . ,(* 365.25 24 60 60))
3335 (week . ,(* 7 24 60 60))
3336 (day . ,(* 24 60 60))
3337 (hour . ,(* 60 60))
3338 (minute . 60)
3339 (second . 1))
3340 "Mapping from time units to seconds.")
3341
3342 (defun gnus-article-forward-header ()
3343 "Move point to the start of the next header.
3344 If the current header is a continuation header, this can be several
3345 lines forward."
3346 (let ((ended nil))
3347 (while (not ended)
3348 (forward-line 1)
3349 (if (looking-at "[ \t]+[^ \t]")
3350 (forward-line 1)
3351 (setq ended t)))))
3352
3353 (defun article-date-ut (&optional type highlight)
3354 "Convert DATE date to universal time in the current article.
3355 If TYPE is `local', convert to local time; if it is `lapsed', output
3356 how much time has lapsed since DATE. For `lapsed', the value of
3357 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3358 should replace the \"Date:\" one, or should be added below it."
3359 (interactive (list 'ut t))
3360 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3361 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3362 tdate-regexp)
3363 ((eq type 'lapsed)
3364 "^X-Sent:[ \t]")
3365 (article-lapsed-timer
3366 "^Date:[ \t]")
3367 (t
3368 tdate-regexp)))
3369 (case-fold-search t)
3370 (inhibit-read-only t)
3371 (inhibit-point-motion-hooks t)
3372 pos date bface eface)
3373 (save-excursion
3374 (save-restriction
3375 (widen)
3376 (goto-char (point-min))
3377 (while (or (setq date (get-text-property (setq pos (point))
3378 'original-date))
3379 (when (setq pos (next-single-property-change
3380 (point) 'original-date))
3381 (setq date (get-text-property pos 'original-date))
3382 t))
3383 (narrow-to-region pos (or (text-property-any pos (point-max)
3384 'original-date nil)
3385 (point-max)))
3386 (goto-char (point-min))
3387 (when (re-search-forward tdate-regexp nil t)
3388 (setq bface (get-text-property (point-at-bol) 'face)
3389 eface (get-text-property (1- (point-at-eol)) 'face)))
3390 (goto-char (point-min))
3391 (setq pos nil)
3392 ;; Delete any old Date headers.
3393 (while (re-search-forward date-regexp nil t)
3394 (if pos
3395 (delete-region (point-at-bol) (progn
3396 (gnus-article-forward-header)
3397 (point)))
3398 (delete-region (point-at-bol) (progn
3399 (gnus-article-forward-header)
3400 (forward-char -1)
3401 (point)))
3402 (setq pos (point))))
3403 (when (and (not pos)
3404 (re-search-forward tdate-regexp nil t))
3405 (forward-line 1))
3406 (gnus-goto-char pos)
3407 (insert (article-make-date-line date (or type 'ut)))
3408 (unless pos
3409 (insert "\n")
3410 (forward-line -1))
3411 ;; Do highlighting.
3412 (beginning-of-line)
3413 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3414 (put-text-property (match-beginning 1) (1+ (match-end 1))
3415 'face bface)
3416 (put-text-property (match-beginning 2) (match-end 2)
3417 'face eface))
3418 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3419 (goto-char (point-max))
3420 (widen))))))
3421
3422 (defun article-make-date-line (date type)
3423 "Return a DATE line of TYPE."
3424 (unless (memq type '(local ut original user iso8601 lapsed english))
3425 (error "Unknown conversion type: %s" type))
3426 (condition-case ()
3427 (let ((time (date-to-time date)))
3428 (cond
3429 ;; Convert to the local timezone.
3430 ((eq type 'local)
3431 (concat "Date: " (message-make-date time)))
3432 ;; Convert to Universal Time.
3433 ((eq type 'ut)
3434 (concat "Date: "
3435 (substring
3436 (message-make-date
3437 (let* ((e (parse-time-string date))
3438 (tm (apply 'encode-time e))
3439 (ms (car tm))
3440 (ls (- (cadr tm) (car (current-time-zone time)))))
3441 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3442 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3443 (t (list ms ls)))))
3444 0 -5)
3445 "UT"))
3446 ;; Get the original date from the article.
3447 ((eq type 'original)
3448 (concat "Date: " (if (string-match "\n+$" date)
3449 (substring date 0 (match-beginning 0))
3450 date)))
3451 ;; Let the user define the format.
3452 ((eq type 'user)
3453 (let ((format (or (condition-case nil
3454 (with-current-buffer gnus-summary-buffer
3455 gnus-article-time-format)
3456 (error nil))
3457 gnus-article-time-format)))
3458 (if (functionp format)
3459 (funcall format time)
3460 (concat "Date: " (format-time-string format time)))))
3461 ;; ISO 8601.
3462 ((eq type 'iso8601)
3463 (let ((tz (car (current-time-zone time))))
3464 (concat
3465 "Date: "
3466 (format-time-string "%Y%m%dT%H%M%S" time)
3467 (format "%s%02d%02d"
3468 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3469 (/ (% (abs tz) 3600) 60)))))
3470 ;; Do an X-Sent lapsed format.
3471 ((eq type 'lapsed)
3472 ;; If the date is seriously mangled, the timezone functions are
3473 ;; liable to bug out, so we ignore all errors.
3474 (let* ((now (current-time))
3475 (real-time (subtract-time now time))
3476 (real-sec (and real-time
3477 (+ (* (float (car real-time)) 65536)
3478 (cadr real-time))))
3479 (sec (and real-time (abs real-sec)))
3480 num prev)
3481 (cond
3482 ((null real-time)
3483 "X-Sent: Unknown")
3484 ((zerop sec)
3485 "X-Sent: Now")
3486 (t
3487 (concat
3488 "X-Sent: "
3489 ;; This is a bit convoluted, but basically we go
3490 ;; through the time units for years, weeks, etc,
3491 ;; and divide things to see whether that results
3492 ;; in positive answers.
3493 (mapconcat
3494 (lambda (unit)
3495 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3496 ;; The (remaining) seconds are too few to
3497 ;; be divided into this time unit.
3498 ""
3499 ;; It's big enough, so we output it.
3500 (setq sec (- sec (* num (cdr unit))))
3501 (prog1
3502 (concat (if prev ", " "") (int-to-string
3503 (floor num))
3504 " " (symbol-name (car unit))
3505 (if (> num 1) "s" ""))
3506 (setq prev t))))
3507 article-time-units "")
3508 ;; If dates are odd, then it might appear like the
3509 ;; article was sent in the future.
3510 (if (> real-sec 0)
3511 " ago"
3512 " in the future"))))))
3513 ;; Display the date in proper English
3514 ((eq type 'english)
3515 (let ((dtime (decode-time time)))
3516 (concat
3517 "Date: the "
3518 (number-to-string (nth 3 dtime))
3519 (let ((digit (% (nth 3 dtime) 10)))
3520 (cond
3521 ((memq (nth 3 dtime) '(11 12 13)) "th")
3522 ((= digit 1) "st")
3523 ((= digit 2) "nd")
3524 ((= digit 3) "rd")
3525 (t "th")))
3526 " of "
3527 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3528 " "
3529 (number-to-string (nth 5 dtime))
3530 " at "
3531 (format "%02d" (nth 2 dtime))
3532 ":"
3533 (format "%02d" (nth 1 dtime)))))))
3534 (error
3535 (format "Date: %s (from Gnus)" date))))
3536
3537 (defun article-date-local (&optional highlight)
3538 "Convert the current article date to the local timezone."
3539 (interactive (list t))
3540 (article-date-ut 'local highlight))
3541
3542 (defun article-date-english (&optional highlight)
3543 "Convert the current article date to something that is proper English."
3544 (interactive (list t))
3545 (article-date-ut 'english highlight))
3546
3547 (defun article-date-original (&optional highlight)
3548 "Convert the current article date to what it was originally.
3549 This is only useful if you have used some other date conversion
3550 function and want to see what the date was before converting."
3551 (interactive (list t))
3552 (article-date-ut 'original highlight))
3553
3554 (defun article-date-lapsed (&optional highlight)
3555 "Convert the current article date to time lapsed since it was sent."
3556 (interactive (list t))
3557 (article-date-ut 'lapsed highlight))
3558
3559 (defun article-update-date-lapsed ()
3560 "Function to be run from a timer to update the lapsed time line."
3561 (save-match-data
3562 (let (deactivate-mark)
3563 (save-excursion
3564 (ignore-errors
3565 (walk-windows
3566 (lambda (w)
3567 (set-buffer (window-buffer w))
3568 (when (eq major-mode 'gnus-article-mode)
3569 (let ((mark (point-marker)))
3570 (goto-char (point-min))
3571 (when (re-search-forward "^X-Sent:" nil t)
3572 (article-date-lapsed t))
3573 (goto-char (marker-position mark))
3574 (move-marker mark nil))))
3575 nil 'visible))))))
3576
3577 (defun gnus-start-date-timer (&optional n)
3578 "Start a timer to update the X-Sent header in the article buffers.
3579 The numerical prefix says how frequently (in seconds) the function
3580 is to run."
3581 (interactive "p")
3582 (unless n
3583 (setq n 1))
3584 (gnus-stop-date-timer)
3585 (setq article-lapsed-timer
3586 (run-at-time 1 n 'article-update-date-lapsed)))
3587
3588 (defun gnus-stop-date-timer ()
3589 "Stop the X-Sent timer."
3590 (interactive)
3591 (when article-lapsed-timer
3592 (nnheader-cancel-timer article-lapsed-timer)
3593 (setq article-lapsed-timer nil)))
3594
3595 (defun article-date-user (&optional highlight)
3596 "Convert the current article date to the user-defined format.
3597 This format is defined by the `gnus-article-time-format' variable."
3598 (interactive (list t))
3599 (article-date-ut 'user highlight))
3600
3601 (defun article-date-iso8601 (&optional highlight)
3602 "Convert the current article date to ISO8601."
3603 (interactive (list t))
3604 (article-date-ut 'iso8601 highlight))
3605
3606 (defmacro gnus-article-save-original-date (&rest forms)
3607 "Save the original date as a text property and evaluate FORMS."
3608 `(let* ((case-fold-search t)
3609 (start (progn
3610 (goto-char (point-min))
3611 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3612 (not (bolp)))
3613 (match-end 0))))
3614 (date (when (and start
3615 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3616 nil t))
3617 (buffer-substring-no-properties start
3618 (match-beginning 0)))))
3619 (goto-char (point-max))
3620 (skip-chars-backward "\n")
3621 (put-text-property (point-min) (point) 'original-date date)
3622 ,@forms
3623 (goto-char (point-max))
3624 (skip-chars-backward "\n")
3625 (put-text-property (point-min) (point) 'original-date date)))
3626
3627 ;; (defun article-show-all ()
3628 ;; "Show all hidden text in the article buffer."
3629 ;; (interactive)
3630 ;; (save-excursion
3631 ;; (let ((inhibit-read-only t))
3632 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3633
3634 (defun article-remove-leading-whitespace ()
3635 "Remove excessive whitespace from all headers."
3636 (interactive)
3637 (save-excursion
3638 (save-restriction
3639 (let ((inhibit-read-only t))
3640 (article-narrow-to-head)
3641 (goto-char (point-min))
3642 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3643 (delete-region (match-beginning 1) (match-end 1)))))))
3644
3645 (defun article-emphasize (&optional arg)
3646 "Emphasize text according to `gnus-emphasis-alist'."
3647 (interactive (gnus-article-hidden-arg))
3648 (unless (gnus-article-check-hidden-text 'emphasis arg)
3649 (save-excursion
3650 (let ((alist (or
3651 (condition-case nil
3652 (with-current-buffer gnus-summary-buffer
3653 gnus-article-emphasis-alist)
3654 (error))
3655 gnus-emphasis-alist))
3656 (inhibit-read-only t)
3657 (props (append '(article-type emphasis)
3658 gnus-hidden-properties))
3659 regexp elem beg invisible visible face)
3660 (article-goto-body)
3661 (setq beg (point))
3662 (while (setq elem (pop alist))
3663 (goto-char beg)
3664 (setq regexp (car elem)
3665 invisible (nth 1 elem)
3666 visible (nth 2 elem)
3667 face (nth 3 elem))
3668 (while (re-search-forward regexp nil t)
3669 (when (and (match-beginning visible) (match-beginning invisible))
3670 (gnus-article-hide-text
3671 (match-beginning invisible) (match-end invisible) props)
3672 (gnus-article-unhide-text-type
3673 (match-beginning visible) (match-end visible) 'emphasis)
3674 (gnus-put-overlay-excluding-newlines
3675 (match-beginning visible) (match-end visible) 'face face)
3676 (gnus-add-wash-type 'emphasis)
3677 (goto-char (match-end invisible)))))))))
3678
3679 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3680 "Setup newsgroup emphasis alist."
3681 (unless gnus-article-emphasis-alist
3682 (let ((name (and gnus-newsgroup-name
3683 (gnus-group-real-name gnus-newsgroup-name))))
3684 (make-local-variable 'gnus-article-emphasis-alist)
3685 (setq gnus-article-emphasis-alist
3686 (nconc
3687 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3688 (while (setq elem (pop alist))
3689 (when (and name (string-match (car elem) name))
3690 (setq alist nil
3691 highlight (copy-sequence (cdr elem)))))
3692 highlight)
3693 (copy-sequence highlight-words)
3694 (if gnus-newsgroup-name
3695 (copy-sequence (gnus-group-find-parameter
3696 gnus-newsgroup-name 'highlight-words t)))
3697 gnus-emphasis-alist)))))
3698
3699 (defvar gnus-summary-article-menu)
3700 (defvar gnus-summary-post-menu)
3701
3702 ;;; Saving functions.
3703
3704 (defun gnus-article-save (save-buffer file &optional num)
3705 "Save the currently selected article."
3706 (when (or (get gnus-default-article-saver :headers)
3707 (not gnus-save-all-headers))
3708 ;; Remove headers according to `gnus-saved-headers' or the value
3709 ;; of the `:headers' property that the saver function might have.
3710 (let ((gnus-visible-headers
3711 (or (symbol-value (get gnus-default-article-saver :headers))
3712 gnus-saved-headers gnus-visible-headers))
3713 (gnus-article-buffer save-buffer))
3714 (with-current-buffer save-buffer
3715 (article-hide-headers 1 t))))
3716 (save-window-excursion
3717 (if (not gnus-default-article-saver)
3718 (error "No default saver is defined")
3719 ;; !!! Magic! The saving functions all save
3720 ;; `gnus-save-article-buffer' (or so they think), but we
3721 ;; bind that variable to our save-buffer.
3722 (set-buffer gnus-article-buffer)
3723 (let* ((gnus-save-article-buffer save-buffer)
3724 (filename
3725 (cond
3726 ((not gnus-prompt-before-saving) 'default)
3727 ((eq gnus-prompt-before-saving 'always) nil)
3728 (t file)))
3729 (gnus-number-of-articles-to-be-saved
3730 (when (eq gnus-prompt-before-saving t)
3731 num))) ; Magic
3732 (set-buffer gnus-article-current-summary)
3733 (funcall gnus-default-article-saver filename)))))
3734
3735 (defun gnus-read-save-file-name (prompt &optional filename
3736 function group headers variable
3737 dir-var)
3738 (let ((default-name
3739 (funcall function group headers (symbol-value variable)))
3740 result)
3741 (setq result
3742 (expand-file-name
3743 (cond
3744 ((eq filename 'default)
3745 default-name)
3746 ((eq filename t)
3747 default-name)
3748 (filename filename)
3749 (t
3750 (when (symbol-value dir-var)
3751 (setq default-name (expand-file-name
3752 (file-name-nondirectory default-name)
3753 (symbol-value dir-var))))
3754 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3755 (prompt
3756 (format prompt
3757 (if (and gnus-number-of-articles-to-be-saved
3758 (> gnus-number-of-articles-to-be-saved 1))
3759 (format "these %d articles"
3760 gnus-number-of-articles-to-be-saved)
3761 "this article")))
3762 (file
3763 ;; Let the split methods have their say.
3764 (cond
3765 ;; No split name was found.
3766 ((null split-name)
3767 (read-file-name
3768 (concat prompt " (default "
3769 (file-name-nondirectory default-name) "): ")
3770 (file-name-directory default-name)
3771 default-name))
3772 ;; A single group name is returned.
3773 ((stringp split-name)
3774 (setq default-name
3775 (funcall function split-name headers
3776 (symbol-value variable)))
3777 (read-file-name
3778 (concat prompt " (default "
3779 (file-name-nondirectory default-name) "): ")
3780 (file-name-directory default-name)
3781 default-name))
3782 ;; A single split name was found
3783 ((= 1 (length split-name))
3784 (let* ((name (expand-file-name
3785 (car split-name)
3786 gnus-article-save-directory))
3787 (dir (cond ((file-directory-p name)
3788 (file-name-as-directory name))
3789 ((file-exists-p name) name)
3790 (t gnus-article-save-directory))))
3791 (read-file-name
3792 (concat prompt " (default " name "): ")
3793 dir name)))
3794 ;; A list of splits was found.
3795 (t
3796 (setq split-name (nreverse split-name))
3797 (let (result)
3798 (let ((file-name-history
3799 (nconc split-name file-name-history)))
3800 (setq result
3801 (expand-file-name
3802 (read-file-name
3803 (concat prompt " (`M-p' for defaults): ")
3804 gnus-article-save-directory
3805 (car split-name))
3806 gnus-article-save-directory)))
3807 (car (push result file-name-history)))))))
3808 ;; Create the directory.
3809 (gnus-make-directory (file-name-directory file))
3810 ;; If we have read a directory, we append the default file name.
3811 (when (file-directory-p file)
3812 (setq file (expand-file-name (file-name-nondirectory
3813 default-name)
3814 (file-name-as-directory file))))
3815 ;; Possibly translate some characters.
3816 (nnheader-translate-file-chars file))))))
3817 (gnus-make-directory (file-name-directory result))
3818 (when variable
3819 (set variable result))
3820 (when dir-var
3821 (set dir-var (file-name-directory result)))
3822 result))
3823
3824 (defun gnus-article-archive-name (group)
3825 "Return the first instance of an \"Archive-name\" in the current buffer."
3826 (let ((case-fold-search t))
3827 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3828 (nnheader-concat gnus-article-save-directory
3829 (match-string 1)))))
3830
3831 (defun gnus-article-nndoc-name (group)
3832 "If GROUP is an nndoc group, return the name of the parent group."
3833 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3834 (gnus-group-get-parameter group 'save-article-group)))
3835
3836 (defun gnus-summary-save-in-rmail (&optional filename)
3837 "Append this article to Rmail file.
3838 Optional argument FILENAME specifies file name.
3839 Directory to save to is default to `gnus-article-save-directory'."
3840 (setq filename (gnus-read-save-file-name
3841 "Save %s in rmail file" filename
3842 gnus-rmail-save-name gnus-newsgroup-name
3843 gnus-current-headers 'gnus-newsgroup-last-rmail))
3844 (gnus-eval-in-buffer-window gnus-save-article-buffer
3845 (save-excursion
3846 (save-restriction
3847 (widen)
3848 (gnus-output-to-rmail filename))))
3849 filename)
3850
3851 (defun gnus-summary-save-in-mail (&optional filename)
3852 "Append this article to Unix mail file.
3853 Optional argument FILENAME specifies file name.
3854 Directory to save to is default to `gnus-article-save-directory'."
3855 (setq filename (gnus-read-save-file-name
3856 "Save %s in Unix mail file" filename
3857 gnus-mail-save-name gnus-newsgroup-name
3858 gnus-current-headers 'gnus-newsgroup-last-mail))
3859 (gnus-eval-in-buffer-window gnus-save-article-buffer
3860 (save-excursion
3861 (save-restriction
3862 (widen)
3863 (if (and (file-readable-p filename)
3864 (file-regular-p filename)
3865 (mail-file-babyl-p filename))
3866 (rmail-output-to-rmail-file filename t)
3867 (gnus-output-to-mail filename)))))
3868 filename)
3869
3870 (put 'gnus-summary-save-in-file :decode t)
3871 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3872 (defun gnus-summary-save-in-file (&optional filename overwrite)
3873 "Append this article to file.
3874 Optional argument FILENAME specifies file name.
3875 Directory to save to is default to `gnus-article-save-directory'."
3876 (setq filename (gnus-read-save-file-name
3877 "Save %s in file" filename
3878 gnus-file-save-name gnus-newsgroup-name
3879 gnus-current-headers 'gnus-newsgroup-last-file))
3880 (gnus-eval-in-buffer-window gnus-save-article-buffer
3881 (save-excursion
3882 (save-restriction
3883 (widen)
3884 (when (and overwrite
3885 (file-exists-p filename))
3886 (delete-file filename))
3887 (gnus-output-to-file filename))))
3888 filename)
3889
3890 (put 'gnus-summary-write-to-file :decode t)
3891 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3892 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3893 (defun gnus-summary-write-to-file (&optional filename)
3894 "Write this article to a file, overwriting it if the file exists.
3895 Optional argument FILENAME specifies file name.
3896 The directory to save in defaults to `gnus-article-save-directory'."
3897 (setq filename (gnus-read-save-file-name
3898 "Save %s in file" filename
3899 gnus-file-save-name gnus-newsgroup-name
3900 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3901 (gnus-summary-save-in-file filename t))
3902
3903 (put 'gnus-summary-save-body-in-file :decode t)
3904 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3905 "Append this article body to a file.
3906 Optional argument FILENAME specifies file name.
3907 The directory to save in defaults to `gnus-article-save-directory'."
3908 (setq filename (gnus-read-save-file-name
3909 "Save %s body in file" filename
3910 gnus-file-save-name gnus-newsgroup-name
3911 gnus-current-headers 'gnus-newsgroup-last-file))
3912 (gnus-eval-in-buffer-window gnus-save-article-buffer
3913 (save-excursion
3914 (save-restriction
3915 (widen)
3916 (when (article-goto-body)
3917 (narrow-to-region (point) (point-max)))
3918 (when (and overwrite
3919 (file-exists-p filename))
3920 (delete-file filename))
3921 (gnus-output-to-file filename))))
3922 filename)
3923
3924 (put 'gnus-summary-write-body-to-file :decode t)
3925 (put 'gnus-summary-write-body-to-file
3926 :function 'gnus-summary-save-body-in-file)
3927 (defun gnus-summary-write-body-to-file (&optional filename)
3928 "Write this article body to a file, overwriting it if the file exists.
3929 Optional argument FILENAME specifies file name.
3930 The directory to save in defaults to `gnus-article-save-directory'."
3931 (setq filename (gnus-read-save-file-name
3932 "Save %s body in file" filename
3933 gnus-file-save-name gnus-newsgroup-name
3934 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3935 (gnus-summary-save-body-in-file filename t))
3936
3937 (defun gnus-summary-save-in-pipe (&optional command)
3938 "Pipe this article to subprocess."
3939 (setq command
3940 (cond ((and (eq command 'default)
3941 gnus-last-shell-command)
3942 gnus-last-shell-command)
3943 ((stringp command)
3944 command)
3945 (t (read-string
3946 (format
3947 "Shell command on %s: "
3948 (if (and gnus-number-of-articles-to-be-saved
3949 (> gnus-number-of-articles-to-be-saved 1))
3950 (format "these %d articles"
3951 gnus-number-of-articles-to-be-saved)
3952 "this article"))
3953 gnus-last-shell-command))))
3954 (when (string-equal command "")
3955 (if gnus-last-shell-command
3956 (setq command gnus-last-shell-command)
3957 (error "A command is required")))
3958 (gnus-eval-in-buffer-window gnus-article-buffer
3959 (save-restriction
3960 (widen)
3961 (shell-command-on-region (point-min) (point-max) command nil)))
3962 (setq gnus-last-shell-command command))
3963
3964 (defun gnus-summary-pipe-to-muttprint (&optional command)
3965 "Pipe this article to muttprint."
3966 (setq command (read-string
3967 "Print using command: " gnus-summary-muttprint-program
3968 nil gnus-summary-muttprint-program))
3969 (gnus-summary-save-in-pipe command))
3970
3971 ;;; Article file names when saving.
3972
3973 (defun gnus-capitalize-newsgroup (newsgroup)
3974 "Capitalize NEWSGROUP name."
3975 (when (not (zerop (length newsgroup)))
3976 (concat (char-to-string (upcase (aref newsgroup 0)))
3977 (substring newsgroup 1))))
3978
3979 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3980 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3981 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3982 Otherwise, it is like ~/News/news/group/num."
3983 (let ((default
3984 (expand-file-name
3985 (concat (if (gnus-use-long-file-name 'not-save)
3986 (gnus-capitalize-newsgroup newsgroup)
3987 (gnus-newsgroup-directory-form newsgroup))
3988 "/" (int-to-string (mail-header-number headers)))
3989 gnus-article-save-directory)))
3990 (if (and last-file
3991 (string-equal (file-name-directory default)
3992 (file-name-directory last-file))
3993 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3994 default
3995 (or last-file default))))
3996
3997 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3998 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3999 If variable `gnus-use-long-file-name' is non-nil, it is
4000 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4001 (let ((default
4002 (expand-file-name
4003 (concat (if (gnus-use-long-file-name 'not-save)
4004 newsgroup
4005 (gnus-newsgroup-directory-form newsgroup))
4006 "/" (int-to-string (mail-header-number headers)))
4007 gnus-article-save-directory)))
4008 (if (and last-file
4009 (string-equal (file-name-directory default)
4010 (file-name-directory last-file))
4011 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4012 default
4013 (or last-file default))))
4014
4015 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4016 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4017 If variable `gnus-use-long-file-name' is non-nil, it is
4018 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4019 (or last-file
4020 (expand-file-name
4021 (if (gnus-use-long-file-name 'not-save)
4022 newsgroup
4023 (file-relative-name
4024 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4025 default-directory))
4026 gnus-article-save-directory)))
4027
4028 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4029 "Generate file name from sender."
4030 (let ((from (mail-header-from headers)))
4031 (expand-file-name
4032 (if (and from (string-match "\\([^ <]+\\)@" from))
4033 (match-string 1 from)
4034 "nobody")
4035 gnus-article-save-directory)))
4036
4037 (defun article-verify-x-pgp-sig ()
4038 "Verify X-PGP-Sig."
4039 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4040 (interactive)
4041 (if (gnus-buffer-live-p gnus-original-article-buffer)
4042 (let ((sig (with-current-buffer gnus-original-article-buffer
4043 (gnus-fetch-field "X-PGP-Sig")))
4044 items info headers)
4045 (when (and sig
4046 mml2015-use
4047 (mml2015-clear-verify-function))
4048 (with-temp-buffer
4049 (insert-buffer-substring gnus-original-article-buffer)
4050 (setq items (split-string sig))
4051 (message-narrow-to-head)
4052 (let ((inhibit-point-motion-hooks t)
4053 (case-fold-search t))
4054 ;; Don't verify multiple headers.
4055 (setq headers (mapconcat (lambda (header)
4056 (concat header ": "
4057 (mail-fetch-field header)
4058 "\n"))
4059 (split-string (nth 1 items) ",") "")))
4060 (delete-region (point-min) (point-max))
4061 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4062 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4063 (insert headers)
4064 (widen)
4065 (forward-line)
4066 (while (not (eobp))
4067 (if (looking-at "^-")
4068 (insert "- "))
4069 (forward-line))
4070 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4071 (insert "Version: " (car items) "\n\n")
4072 (insert (mapconcat 'identity (cddr items) "\n"))
4073 (insert "\n-----END PGP SIGNATURE-----\n")
4074 (let ((mm-security-handle (list (format "multipart/signed"))))
4075 (mml2015-clean-buffer)
4076 (let ((coding-system-for-write (or gnus-newsgroup-charset
4077 'iso-8859-1)))
4078 (funcall (mml2015-clear-verify-function)))
4079 (setq info
4080 (or (mm-handle-multipart-ctl-parameter
4081 mm-security-handle 'gnus-details)
4082 (mm-handle-multipart-ctl-parameter
4083 mm-security-handle 'gnus-info)))))
4084 (when info
4085 (let ((inhibit-read-only t) bface eface)
4086 (save-restriction
4087 (message-narrow-to-head)
4088 (goto-char (point-max))
4089 (forward-line -1)
4090 (setq bface (get-text-property (point-at-bol) 'face)
4091 eface (get-text-property (1- (point-at-eol)) 'face))
4092 (message-remove-header "X-Gnus-PGP-Verify")
4093 (if (re-search-forward "^X-PGP-Sig:" nil t)
4094 (forward-line)
4095 (goto-char (point-max)))
4096 (narrow-to-region (point) (point))
4097 (insert "X-Gnus-PGP-Verify: " info "\n")
4098 (goto-char (point-min))
4099 (forward-line)
4100 (while (not (eobp))
4101 (if (not (looking-at "^[ \t]"))
4102 (insert " "))
4103 (forward-line))
4104 ;; Do highlighting.
4105 (goto-char (point-min))
4106 (when (looking-at "\\([^:]+\\): *")
4107 (put-text-property (match-beginning 1) (1+ (match-end 1))
4108 'face bface)
4109 (put-text-property (match-end 0) (point-max)
4110 'face eface)))))))))
4111
4112 (defun article-verify-cancel-lock ()
4113 "Verify Cancel-Lock header."
4114 (interactive)
4115 (if (gnus-buffer-live-p gnus-original-article-buffer)
4116 (canlock-verify gnus-original-article-buffer)))
4117
4118 (eval-and-compile
4119 (mapc
4120 (lambda (func)
4121 (let (afunc gfunc)
4122 (if (consp func)
4123 (setq afunc (car func)
4124 gfunc (cdr func))
4125 (setq afunc func
4126 gfunc (intern (format "gnus-%s" func))))
4127 (defalias gfunc
4128 (when (fboundp afunc)
4129 `(lambda (&optional interactive &rest args)
4130 ,(documentation afunc t)
4131 (interactive (list t))
4132 (with-current-buffer gnus-article-buffer
4133 (if interactive
4134 (call-interactively ',afunc)
4135 (apply ',afunc args))))))))
4136 '(article-hide-headers
4137 article-verify-x-pgp-sig
4138 article-verify-cancel-lock
4139 article-hide-boring-headers
4140 article-treat-overstrike
4141 article-treat-ansi-sequences
4142 article-fill-long-lines
4143 article-capitalize-sentences
4144 article-remove-cr
4145 article-remove-leading-whitespace
4146 article-display-x-face
4147 article-display-face
4148 article-de-quoted-unreadable
4149 article-de-base64-unreadable
4150 article-decode-HZ
4151 article-wash-html
4152 article-unsplit-urls
4153 article-hide-list-identifiers
4154 article-strip-banner
4155 article-babel
4156 article-hide-pem
4157 article-hide-signature
4158 article-strip-headers-in-body
4159 article-remove-trailing-blank-lines
4160 article-strip-leading-blank-lines
4161 article-strip-multiple-blank-lines
4162 article-strip-leading-space
4163 article-strip-trailing-space
4164 article-strip-blank-lines
4165 article-strip-all-blank-lines
4166 article-date-local
4167 article-date-english
4168 article-date-iso8601
4169 article-date-original
4170 article-date-ut
4171 article-decode-mime-words
4172 article-decode-charset
4173 article-decode-encoded-words
4174 article-date-user
4175 article-date-lapsed
4176 article-emphasize
4177 article-treat-dumbquotes
4178 article-normalize-headers
4179 ;;(article-show-all . gnus-article-show-all-headers)
4180 )))
4181 \f
4182 ;;;
4183 ;;; Gnus article mode
4184 ;;;
4185
4186 (put 'gnus-article-mode 'mode-class 'special)
4187
4188 (set-keymap-parent gnus-article-mode-map widget-keymap)
4189
4190 (gnus-define-keys gnus-article-mode-map
4191 " " gnus-article-goto-next-page
4192 "\177" gnus-article-goto-prev-page
4193 [delete] gnus-article-goto-prev-page
4194 [backspace] gnus-article-goto-prev-page
4195 "\C-c^" gnus-article-refer-article
4196 "h" gnus-article-show-summary
4197 "s" gnus-article-show-summary
4198 "\C-c\C-m" gnus-article-mail
4199 "?" gnus-article-describe-briefly
4200 "e" gnus-summary-edit-article
4201 "<" beginning-of-buffer
4202 ">" end-of-buffer
4203 "\C-c\C-i" gnus-info-find-node
4204 "\C-c\C-b" gnus-bug
4205 "R" gnus-article-reply-with-original
4206 "F" gnus-article-followup-with-original
4207 "\C-hk" gnus-article-describe-key
4208 "\C-hc" gnus-article-describe-key-briefly
4209 "\C-hb" gnus-article-describe-bindings
4210
4211 "\C-d" gnus-article-read-summary-keys
4212 "\M-*" gnus-article-read-summary-keys
4213 "\M-#" gnus-article-read-summary-keys
4214 "\M-^" gnus-article-read-summary-keys
4215 "\M-g" gnus-article-read-summary-keys)
4216
4217 (substitute-key-definition
4218 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4219
4220 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4221 "W" gnus-article-wide-reply-with-original)
4222 (if (featurep 'xemacs)
4223 (set-keymap-default-binding gnus-article-send-map
4224 'gnus-article-read-summary-send-keys)
4225 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4226
4227 (defun gnus-article-make-menu-bar ()
4228 (unless (boundp 'gnus-article-commands-menu)
4229 (gnus-summary-make-menu-bar))
4230 (gnus-turn-off-edit-menu 'article)
4231 (unless (boundp 'gnus-article-article-menu)
4232 (easy-menu-define
4233 gnus-article-article-menu gnus-article-mode-map ""
4234 '("Article"
4235 ["Scroll forwards" gnus-article-goto-next-page t]
4236 ["Scroll backwards" gnus-article-goto-prev-page t]
4237 ["Show summary" gnus-article-show-summary t]
4238 ["Fetch Message-ID at point" gnus-article-refer-article t]
4239 ["Mail to address at point" gnus-article-mail t]
4240 ["Send a bug report" gnus-bug t]))
4241
4242 (easy-menu-define
4243 gnus-article-treatment-menu gnus-article-mode-map ""
4244 ;; Fixme: this should use :active (and maybe :visible).
4245 '("Treatment"
4246 ["Hide headers" gnus-article-hide-headers t]
4247 ["Hide signature" gnus-article-hide-signature t]
4248 ["Hide citation" gnus-article-hide-citation t]
4249 ["Treat overstrike" gnus-article-treat-overstrike t]
4250 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4251 ["Remove carriage return" gnus-article-remove-cr t]
4252 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4253 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4254 ["Remove base64" gnus-article-de-base64-unreadable t]
4255 ["Treat html" gnus-article-wash-html t]
4256 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4257 ["Decode HZ" gnus-article-decode-HZ t]))
4258
4259 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4260
4261 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4262
4263 (gnus-run-hooks 'gnus-article-menu-hook)))
4264
4265 (defun gnus-article-mode ()
4266 "Major mode for displaying an article.
4267
4268 All normal editing commands are switched off.
4269
4270 The following commands are available in addition to all summary mode
4271 commands:
4272 \\<gnus-article-mode-map>
4273 \\[gnus-article-next-page]\t Scroll the article one page forwards
4274 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4275 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4276 \\[gnus-article-show-summary]\t Display the summary buffer
4277 \\[gnus-article-mail]\t Send a reply to the address near point
4278 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4279 \\[gnus-info-find-node]\t Go to the Gnus info node"
4280 (interactive)
4281 (kill-all-local-variables)
4282 (gnus-simplify-mode-line)
4283 (setq mode-name "Article")
4284 (setq major-mode 'gnus-article-mode)
4285 (make-local-variable 'minor-mode-alist)
4286 (use-local-map gnus-article-mode-map)
4287 (when (gnus-visual-p 'article-menu 'menu)
4288 (gnus-article-make-menu-bar)
4289 (when gnus-summary-tool-bar-map
4290 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4291 (gnus-update-format-specifications nil 'article-mode)
4292 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4293 (set (make-local-variable 'gnus-page-broken) nil)
4294 (make-local-variable 'gnus-button-marker-list)
4295 (make-local-variable 'gnus-article-current-summary)
4296 (make-local-variable 'gnus-article-mime-handles)
4297 (make-local-variable 'gnus-article-decoded-p)
4298 (make-local-variable 'gnus-article-mime-handle-alist)
4299 (make-local-variable 'gnus-article-wash-types)
4300 (make-local-variable 'gnus-article-image-alist)
4301 (make-local-variable 'gnus-article-charset)
4302 (make-local-variable 'gnus-article-ignored-charsets)
4303 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4304 ;; face.
4305 (set (make-local-variable 'nobreak-char-display) nil)
4306 (setq cursor-in-non-selected-windows nil)
4307 (setq truncate-lines gnus-article-truncate-lines)
4308 (gnus-set-default-directory)
4309 (buffer-disable-undo)
4310 (setq buffer-read-only t
4311 show-trailing-whitespace nil)
4312 (set-syntax-table gnus-article-mode-syntax-table)
4313 (mm-enable-multibyte)
4314 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4315
4316 (defvar gnus-button-marker-list nil
4317 "Regexp matching any of the regexps from `gnus-button-alist'.
4318 Internal variable.")
4319
4320 (defun gnus-article-setup-buffer ()
4321 "Initialize the article buffer."
4322 (let* ((name (if gnus-single-article-buffer "*Article*"
4323 (concat "*Article " gnus-newsgroup-name "*")))
4324 (original
4325 (progn (string-match "\\*Article" name)
4326 (concat " *Original Article"
4327 (substring name (match-end 0))))))
4328 (setq gnus-article-buffer name)
4329 (setq gnus-original-article-buffer original)
4330 (setq gnus-article-mime-handle-alist nil)
4331 (with-current-buffer gnus-summary-buffer
4332 ;; This might be a variable local to the summary buffer.
4333 (unless gnus-single-article-buffer
4334 (setq gnus-article-buffer name)
4335 (setq gnus-original-article-buffer original)
4336 (gnus-set-global-variables)))
4337 (gnus-article-setup-highlight-words)
4338 ;; Init original article buffer.
4339 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4340 (mm-enable-multibyte)
4341 (setq major-mode 'gnus-original-article-mode)
4342 (make-local-variable 'gnus-original-article))
4343 (if (and (get-buffer name)
4344 (with-current-buffer name
4345 (if gnus-article-edit-mode
4346 (if (y-or-n-p "Article mode edit in progress; discard? ")
4347 (progn
4348 (set-buffer-modified-p nil)
4349 (gnus-kill-buffer name)
4350 (message "")
4351 nil)
4352 (error "Action aborted"))
4353 t)))
4354 (with-current-buffer name
4355 (set (make-local-variable 'gnus-article-edit-mode) nil)
4356 (when gnus-article-mime-handles
4357 (mm-destroy-parts gnus-article-mime-handles)
4358 (setq gnus-article-mime-handles nil))
4359 ;; Set it to nil in article-buffer!
4360 (setq gnus-article-mime-handle-alist nil)
4361 (buffer-disable-undo)
4362 (setq buffer-read-only t)
4363 ;; This list just keeps growing if we don't reset it.
4364 (setq gnus-button-marker-list nil)
4365 (unless (eq major-mode 'gnus-article-mode)
4366 (gnus-article-mode))
4367 (current-buffer))
4368 (with-current-buffer (gnus-get-buffer-create name)
4369 (gnus-article-mode)
4370 (make-local-variable 'gnus-summary-buffer)
4371 (setq gnus-summary-buffer
4372 (gnus-summary-buffer-name gnus-newsgroup-name))
4373 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4374 (current-buffer)))))
4375
4376 ;; Set article window start at LINE, where LINE is the number of lines
4377 ;; from the head of the article.
4378 (defun gnus-article-set-window-start (&optional line)
4379 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4380 (when article-window
4381 (set-window-start
4382 article-window
4383 (with-current-buffer gnus-article-buffer
4384 (goto-char (point-min))
4385 (if (not line)
4386 (point-min)
4387 (gnus-message 6 "Moved to bookmark")
4388 (search-forward "\n\n" nil t)
4389 (forward-line line)
4390 (point)))))))
4391
4392 (defun gnus-article-prepare (article &optional all-headers header)
4393 "Prepare ARTICLE in article mode buffer.
4394 ARTICLE should either be an article number or a Message-ID.
4395 If ARTICLE is an id, HEADER should be the article headers.
4396 If ALL-HEADERS is non-nil, no headers are hidden."
4397 (save-excursion
4398 ;; Make sure we start in a summary buffer.
4399 (unless (eq major-mode 'gnus-summary-mode)
4400 (set-buffer gnus-summary-buffer))
4401 (setq gnus-summary-buffer (current-buffer))
4402 (let* ((gnus-article (if header (mail-header-number header) article))
4403 (summary-buffer (current-buffer))
4404 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4405 (group gnus-newsgroup-name)
4406 result)
4407 (save-excursion
4408 (gnus-article-setup-buffer)
4409 (set-buffer gnus-article-buffer)
4410 ;; Deactivate active regions.
4411 (when (and (boundp 'transient-mark-mode)
4412 transient-mark-mode)
4413 (setq mark-active nil))
4414 (if (not (setq result (let ((inhibit-read-only t))
4415 (gnus-request-article-this-buffer
4416 article group))))
4417 ;; There is no such article.
4418 (save-excursion
4419 (when (and (numberp article)
4420 (not (memq article gnus-newsgroup-sparse)))
4421 (setq gnus-article-current
4422 (cons gnus-newsgroup-name article))
4423 (set-buffer gnus-summary-buffer)
4424 (setq gnus-current-article article)
4425 (if (and (memq article gnus-newsgroup-undownloaded)
4426 (not (gnus-online (gnus-find-method-for-group
4427 gnus-newsgroup-name))))
4428 (progn
4429 (gnus-summary-set-agent-mark article)
4430 (message "Message marked for downloading"))
4431 (gnus-summary-mark-article article gnus-canceled-mark)
4432 (unless (memq article gnus-newsgroup-sparse)
4433 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4434 (if (or (eq result 'pseudo)
4435 (eq result 'nneething))
4436 (progn
4437 (with-current-buffer summary-buffer
4438 (push article gnus-newsgroup-history)
4439 (setq gnus-last-article gnus-current-article
4440 gnus-current-article 0
4441 gnus-current-headers nil
4442 gnus-article-current nil)
4443 (if (eq result 'nneething)
4444 (gnus-configure-windows 'summary)
4445 (gnus-configure-windows 'article))
4446 (gnus-set-global-variables))
4447 (let ((gnus-article-mime-handle-alist-1
4448 gnus-article-mime-handle-alist))
4449 (gnus-set-mode-line 'article)))
4450 ;; The result from the `request' was an actual article -
4451 ;; or at least some text that is now displayed in the
4452 ;; article buffer.
4453 (when (and (numberp article)
4454 (not (eq article gnus-current-article)))
4455 ;; Seems like a new article has been selected.
4456 ;; `gnus-current-article' must be an article number.
4457 (with-current-buffer summary-buffer
4458 (push article gnus-newsgroup-history)
4459 (setq gnus-last-article gnus-current-article
4460 gnus-current-article article
4461 gnus-current-headers
4462 (gnus-summary-article-header gnus-current-article)
4463 gnus-article-current
4464 (cons gnus-newsgroup-name gnus-current-article))
4465 (unless (vectorp gnus-current-headers)
4466 (setq gnus-current-headers nil))
4467 (gnus-summary-goto-subject gnus-current-article)
4468 (when (gnus-summary-show-thread)
4469 ;; If the summary buffer really was folded, the
4470 ;; previous goto may not actually have gone to
4471 ;; the right article, but the thread root instead.
4472 ;; So we go again.
4473 (gnus-summary-goto-subject gnus-current-article))
4474 (gnus-run-hooks 'gnus-mark-article-hook)
4475 (gnus-set-mode-line 'summary)
4476 (when (gnus-visual-p 'article-highlight 'highlight)
4477 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4478 ;; Set the global newsgroup variables here.
4479 (gnus-set-global-variables)
4480 (setq gnus-have-all-headers
4481 (or all-headers gnus-show-all-headers))))
4482 (save-excursion
4483 (gnus-configure-windows 'article))
4484 (when (or (numberp article)
4485 (stringp article))
4486 (gnus-article-prepare-display)
4487 ;; Do page break.
4488 (goto-char (point-min))
4489 (when gnus-break-pages
4490 (gnus-narrow-to-page)))
4491 (let ((gnus-article-mime-handle-alist-1
4492 gnus-article-mime-handle-alist))
4493 (gnus-set-mode-line 'article))
4494 (article-goto-body)
4495 (unless (bobp)
4496 (forward-line -1))
4497 (set-window-point (get-buffer-window (current-buffer)) (point))
4498 (gnus-configure-windows 'article)
4499 t))))))
4500
4501 ;;;###autoload
4502 (defun gnus-article-prepare-display ()
4503 "Make the current buffer look like a nice article."
4504 ;; Hooks for getting information from the article.
4505 ;; This hook must be called before being narrowed.
4506 (let ((gnus-article-buffer (current-buffer))
4507 buffer-read-only
4508 (inhibit-read-only t))
4509 (unless (eq major-mode 'gnus-article-mode)
4510 (gnus-article-mode))
4511 (setq buffer-read-only nil
4512 gnus-article-wash-types nil
4513 gnus-article-image-alist nil)
4514 (gnus-run-hooks 'gnus-tmp-internal-hook)
4515 (when gnus-display-mime-function
4516 (funcall gnus-display-mime-function))
4517 (gnus-run-hooks 'gnus-article-prepare-hook)))
4518
4519 ;;;
4520 ;;; Gnus Sticky Article Mode
4521 ;;;
4522
4523 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4524 "Mode for sticky articles."
4525 ;; Release bindings that won't work.
4526 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4527 gnus-sticky-article-mode-map)
4528 (substitute-key-definition 'gnus-article-refer-article 'undefined
4529 gnus-sticky-article-mode-map)
4530 (dolist (k '("e" "h" "s" "F" "R"))
4531 (define-key gnus-sticky-article-mode-map k nil))
4532 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4533 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4534 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4535 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4536
4537 (defun gnus-sticky-article (arg)
4538 "Make the current article sticky.
4539 If a prefix ARG is given, ask for a name for this sticky article buffer."
4540 (interactive "P")
4541 (gnus-summary-show-thread)
4542 (gnus-summary-select-article nil nil 'pseudo)
4543 (let (new-art-buf-name)
4544 (gnus-eval-in-buffer-window gnus-article-buffer
4545 (setq new-art-buf-name
4546 (concat
4547 "*Sticky Article: "
4548 (if arg
4549 (read-from-minibuffer "Sticky article buffer name: ")
4550 (gnus-with-article-headers
4551 (gnus-article-goto-header "subject")
4552 (setq new-art-buf-name
4553 (buffer-substring-no-properties
4554 (line-beginning-position) (line-end-position)))
4555 (goto-char (point-min))
4556 (gnus-article-goto-header "from")
4557 (setq new-art-buf-name
4558 (concat
4559 new-art-buf-name ", "
4560 (buffer-substring-no-properties
4561 (line-beginning-position) (line-end-position))))
4562 (goto-char (point-min))
4563 (gnus-article-goto-header "date")
4564 (setq new-art-buf-name
4565 (concat
4566 new-art-buf-name ", "
4567 (buffer-substring-no-properties
4568 (line-beginning-position) (line-end-position))))))
4569 "*"))
4570 (if (and (gnus-buffer-live-p new-art-buf-name)
4571 (with-current-buffer new-art-buf-name
4572 (eq major-mode 'gnus-sticky-article-mode)))
4573 (switch-to-buffer new-art-buf-name)
4574 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4575 (gnus-sticky-article-mode))
4576 (setq gnus-article-buffer new-art-buf-name))
4577 (gnus-summary-recenter)
4578 (gnus-summary-position-point))
4579
4580 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4581 "Kill the given sticky article BUFFER.
4582 If none is given, assume the current buffer and kill it if it has
4583 `gnus-sticky-article-mode'."
4584 (interactive)
4585 (unless buffer
4586 (setq buffer (current-buffer)))
4587 (with-current-buffer buffer
4588 (when (eq major-mode 'gnus-sticky-article-mode)
4589 (gnus-kill-buffer buffer))))
4590
4591 (defun gnus-kill-sticky-article-buffers (arg)
4592 "Kill all sticky article buffers.
4593 If a prefix ARG is given, ask for confirmation."
4594 (interactive "P")
4595 (dolist (buf (gnus-buffers))
4596 (with-current-buffer buf
4597 (when (eq major-mode 'gnus-sticky-article-mode)
4598 (if (not arg)
4599 (gnus-kill-buffer buf)
4600 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4601 (gnus-kill-buffer buf)))))))
4602
4603 ;;;
4604 ;;; Gnus MIME viewing functions
4605 ;;;
4606
4607 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4608 "Format of the MIME buttons.
4609
4610 Valid specifiers include:
4611 %t The MIME type
4612 %T MIME type, along with additional info
4613 %n The `name' parameter
4614 %d The description, if any
4615 %l The length of the encoded part
4616 %p The part identifier number
4617 %e Dots if the part isn't displayed
4618
4619 General format specifiers can also be used. See Info node
4620 `(gnus)Formatting Variables'.")
4621
4622 (defvar gnus-mime-button-line-format-alist
4623 '((?t gnus-tmp-type ?s)
4624 (?T gnus-tmp-type-long ?s)
4625 (?n gnus-tmp-name ?s)
4626 (?d gnus-tmp-description ?s)
4627 (?p gnus-tmp-id ?s)
4628 (?l gnus-tmp-length ?d)
4629 (?e gnus-tmp-dots ?s)))
4630
4631 (defvar gnus-mime-button-commands
4632 '((gnus-article-press-button "\r" "Toggle Display")
4633 (gnus-mime-view-part "v" "View Interactively...")
4634 (gnus-mime-view-part-as-type "t" "View As Type...")
4635 (gnus-mime-view-part-as-charset "C" "View As charset...")
4636 (gnus-mime-save-part "o" "Save...")
4637 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4638 (gnus-mime-replace-part "r" "Replace part")
4639 (gnus-mime-delete-part "d" "Delete part")
4640 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4641 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4642 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4643 (gnus-mime-view-part-externally "e" "View Externally")
4644 (gnus-mime-print-part "p" "Print")
4645 (gnus-mime-pipe-part "|" "Pipe To Command...")
4646 (gnus-mime-action-on-part "." "Take action on the part...")))
4647
4648 (defun gnus-article-mime-part-status ()
4649 (if gnus-article-mime-handle-alist-1
4650 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4651 " (1 part)"
4652 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4653 ""))
4654
4655 (defvar gnus-mime-button-map
4656 (let ((map (make-sparse-keymap)))
4657 (define-key map gnus-mouse-2 'gnus-article-push-button)
4658 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4659 (dolist (c gnus-mime-button-commands)
4660 (define-key map (cadr c) (car c)))
4661 map))
4662
4663 (easy-menu-define
4664 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4665 `("MIME Part"
4666 ,@(mapcar (lambda (c)
4667 (vector (caddr c) (car c) :active t))
4668 gnus-mime-button-commands)))
4669
4670 (defun gnus-mime-button-menu (event prefix)
4671 "Construct a context-sensitive menu of MIME commands."
4672 (interactive "e\nP")
4673 (save-window-excursion
4674 (let ((pos (event-start event)))
4675 (select-window (posn-window pos))
4676 (goto-char (posn-point pos))
4677 (gnus-article-check-buffer)
4678 (popup-menu gnus-mime-button-menu nil prefix))))
4679
4680 (defun gnus-mime-view-all-parts (&optional handles)
4681 "View all the MIME parts."
4682 (interactive)
4683 (with-current-buffer gnus-article-buffer
4684 (let ((handles (or handles gnus-article-mime-handles))
4685 (mail-parse-charset gnus-newsgroup-charset)
4686 (mail-parse-ignored-charsets
4687 (with-current-buffer gnus-summary-buffer
4688 gnus-newsgroup-ignored-charsets)))
4689 (when handles
4690 (mm-remove-parts handles)
4691 (goto-char (point-min))
4692 (or (search-forward "\n\n") (goto-char (point-max)))
4693 (let ((inhibit-read-only t))
4694 (delete-region (point) (point-max))
4695 (mm-display-parts handles))))))
4696
4697 (defun gnus-article-jump-to-part (n)
4698 "Jump to MIME part N."
4699 (interactive "P")
4700 (pop-to-buffer gnus-article-buffer)
4701 ;; FIXME: why is it necessary?
4702 (sit-for 0)
4703 (let ((parts (length gnus-article-mime-handle-alist)))
4704 (or n (setq n
4705 (string-to-number
4706 (read-string ;; Emacs 21 doesn't have `read-number'.
4707 (format "Jump to part (2..%s): " parts)))))
4708 (unless (and (integerp n) (<= n parts) (>= n 1))
4709 (setq n
4710 (progn
4711 (gnus-message 7 "Invalid part `%s', using %s instead."
4712 n parts)
4713 parts)))
4714 (gnus-message 9 "Jumping to part %s." n)
4715 (cond ((>= gnus-auto-select-part 1)
4716 (while (and (<= n parts)
4717 (not (gnus-article-goto-part n)))
4718 (setq n (1+ n))))
4719 ((< gnus-auto-select-part 0)
4720 (while (and (>= n 1)
4721 (not (gnus-article-goto-part n)))
4722 (setq n (1- n))))
4723 (t
4724 (gnus-article-goto-part n)))))
4725
4726 (eval-when-compile
4727 (defsubst gnus-article-edit-part (handles &optional current-id)
4728 "Edit an article in order to delete a mime part.
4729 This function is exclusively used by `gnus-mime-save-part-and-strip'
4730 and `gnus-mime-delete-part', and not provided at run-time normally."
4731 (gnus-article-edit-article
4732 `(lambda ()
4733 (buffer-disable-undo)
4734 (erase-buffer)
4735 (let ((mail-parse-charset (or gnus-article-charset
4736 ',gnus-newsgroup-charset))
4737 (mail-parse-ignored-charsets
4738 (or gnus-article-ignored-charsets
4739 ',gnus-newsgroup-ignored-charsets))
4740 (mbl mml-buffer-list))
4741 (setq mml-buffer-list nil)
4742 (insert-buffer-substring gnus-original-article-buffer)
4743 (mime-to-mml ',handles)
4744 (setq gnus-article-mime-handles nil)
4745 (let ((mbl1 mml-buffer-list))
4746 (setq mml-buffer-list mbl)
4747 (set (make-local-variable 'mml-buffer-list) mbl1))
4748 (gnus-make-local-hook 'kill-buffer-hook)
4749 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4750 `(lambda (no-highlight)
4751 (let ((mail-parse-charset (or gnus-article-charset
4752 ',gnus-newsgroup-charset))
4753 (message-options message-options)
4754 (message-options-set-recipient)
4755 (mail-parse-ignored-charsets
4756 (or gnus-article-ignored-charsets
4757 ',gnus-newsgroup-ignored-charsets)))
4758 (mml-to-mime)
4759 (mml-destroy-buffers)
4760 (remove-hook 'kill-buffer-hook
4761 'mml-destroy-buffers t)
4762 (kill-local-variable 'mml-buffer-list))
4763 (gnus-summary-edit-article-done
4764 ,(or (mail-header-references gnus-current-headers) "")
4765 ,(gnus-group-read-only-p)
4766 ,gnus-summary-buffer no-highlight))
4767 t)
4768 (gnus-article-edit-done)
4769 (gnus-summary-expand-window)
4770 (gnus-summary-show-article)
4771 (when (and current-id (integerp gnus-auto-select-part))
4772 (gnus-article-jump-to-part
4773 (if (text-property-any (point-min) (point-max)
4774 'gnus-part (+ current-id gnus-auto-select-part))
4775 (+ current-id gnus-auto-select-part)
4776 (with-current-buffer gnus-article-buffer
4777 (length gnus-article-mime-handle-alist)))))))
4778
4779 (defun gnus-mime-replace-part (file)
4780 "Replace MIME part under point with an external body."
4781 ;; Useful if file has already been saved to disk
4782 (interactive
4783 (list
4784 (mm-with-multibyte
4785 (read-file-name "Replace MIME part with file: "
4786 (or mm-default-directory default-directory)
4787 nil nil))))
4788 (gnus-mime-save-part-and-strip file))
4789
4790 (defun gnus-mime-save-part-and-strip (&optional file)
4791 "Save the MIME part under point then replace it with an external body.
4792 If FILE is given, use it for the external part."
4793 (interactive)
4794 (gnus-article-check-buffer)
4795 (when (gnus-group-read-only-p)
4796 (error "The current group does not support deleting of parts"))
4797 (when (mm-complicated-handles gnus-article-mime-handles)
4798 (error "\
4799 The current article has a complicated MIME structure, giving up..."))
4800 (let* ((data (get-text-property (point) 'gnus-data))
4801 (id (get-text-property (point) 'gnus-part))
4802 param
4803 (handles gnus-article-mime-handles))
4804 (unless file
4805 (setq file
4806 (and data (mm-save-part data "Delete MIME part and save to: "))))
4807 (when file
4808 (with-current-buffer (mm-handle-buffer data)
4809 (erase-buffer)
4810 (insert "Content-Type: " (mm-handle-media-type data))
4811 (mml-insert-parameter-string (cdr (mm-handle-type data))
4812 '(charset))
4813 ;; Add a filename for the sake of saving the part again.
4814 (mml-insert-parameter
4815 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4816 (insert "\n")
4817 (insert "Content-ID: " (message-make-message-id) "\n")
4818 (insert "Content-Transfer-Encoding: binary\n")
4819 (insert "\n"))
4820 (setcdr data
4821 (cdr (mm-make-handle nil
4822 `("message/external-body"
4823 (access-type . "LOCAL-FILE")
4824 (name . ,file)))))
4825 ;; (set-buffer gnus-summary-buffer)
4826 (gnus-article-edit-part handles id))))
4827
4828 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4829 ;; parts...>') but with stripping would be nice.
4830
4831 (defun gnus-mime-delete-part ()
4832 "Delete the MIME part under point.
4833 Replace it with some information about the removed part."
4834 (interactive)
4835 (gnus-article-check-buffer)
4836 (when (gnus-group-read-only-p)
4837 (error "The current group does not support deleting of parts"))
4838 (when (mm-complicated-handles gnus-article-mime-handles)
4839 (error "\
4840 The current article has a complicated MIME structure, giving up..."))
4841 (when (or gnus-expert-user
4842 (gnus-yes-or-no-p "\
4843 Deleting parts may malfunction or destroy the article; continue? "))
4844 (let* ((data (get-text-property (point) 'gnus-data))
4845 (id (get-text-property (point) 'gnus-part))
4846 (handles gnus-article-mime-handles)
4847 (none "(none)")
4848 (description
4849 (let ((desc (mm-handle-description data)))
4850 (when desc
4851 (mail-decode-encoded-word-string desc))))
4852 (filename
4853 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4854 none))
4855 (type (mm-handle-media-type data)))
4856 (unless data
4857 (error "No MIME part under point"))
4858 (with-current-buffer (mm-handle-buffer data)
4859 (let ((bsize (format "%s" (buffer-size))))
4860 (erase-buffer)
4861 (insert
4862 (concat
4863 ",----\n"
4864 "| The following attachment has been deleted:\n"
4865 "|\n"
4866 "| Type: " type "\n"
4867 "| Filename: " filename "\n"
4868 "| Size (encoded): " bsize " Byte\n"
4869 (when description
4870 (concat "| Description: " description "\n"))
4871 "`----\n"))
4872 (setcdr data
4873 (cdr (mm-make-handle
4874 nil `("text/plain") nil nil
4875 (list "attachment")
4876 (format "Deleted attachment (%s bytes)" bsize))))))
4877 ;; (set-buffer gnus-summary-buffer)
4878 (gnus-article-edit-part handles id))))
4879
4880 (defun gnus-mime-save-part ()
4881 "Save the MIME part under point."
4882 (interactive)
4883 (gnus-article-check-buffer)
4884 (let ((data (get-text-property (point) 'gnus-data)))
4885 (when data
4886 (mm-save-part data))))
4887
4888 (defun gnus-mime-pipe-part ()
4889 "Pipe the MIME part under point to a process."
4890 (interactive)
4891 (gnus-article-check-buffer)
4892 (let ((data (get-text-property (point) 'gnus-data)))
4893 (when data
4894 (mm-pipe-part data))))
4895
4896 (defun gnus-mime-view-part ()
4897 "Interactively choose a viewing method for the MIME part under point."
4898 (interactive)
4899 (gnus-article-check-buffer)
4900 (let ((data (get-text-property (point) 'gnus-data)))
4901 (when data
4902 (setq gnus-article-mime-handles
4903 (mm-merge-handles
4904 gnus-article-mime-handles (setq data (copy-sequence data))))
4905 (mm-interactively-view-part data))))
4906
4907 (defun gnus-mime-view-part-as-type-internal ()
4908 (gnus-article-check-buffer)
4909 (let* ((handle (get-text-property (point) 'gnus-data))
4910 (name (or
4911 ;; Content-Type: foo/bar; name=...
4912 (mail-content-type-get (mm-handle-type handle) 'name)
4913 ;; Content-Disposition: attachment; filename=...
4914 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4915 (def-type (and name (mm-default-file-encoding name))))
4916 (or (and def-type (cons def-type 0))
4917 (and handle
4918 (equal (mm-handle-media-supertype handle) "text")
4919 '("text/plain" . 0))
4920 '("application/octet-stream" . 0))))
4921
4922 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4923 "Choose a MIME media type, and view the part as such.
4924 If non-nil, PRED is a predicate to use during completion to limit the
4925 available media-types."
4926 (interactive)
4927 (unless mime-type
4928 (setq mime-type
4929 (let ((default (gnus-mime-view-part-as-type-internal)))
4930 (completing-read
4931 (format "View as MIME type (default %s): "
4932 (car default))
4933 (mapcar #'list (mailcap-mime-types))
4934 pred nil nil nil
4935 (car default)))))
4936 (gnus-article-check-buffer)
4937 (let ((handle (get-text-property (point) 'gnus-data)))
4938 (when handle
4939 (when (equal (mm-handle-media-type handle) "message/external-body")
4940 (unless (mm-handle-cache handle)
4941 (mm-extern-cache-contents handle))
4942 (setq handle (mm-handle-cache handle)))
4943 (setq handle
4944 (mm-make-handle (mm-handle-buffer handle)
4945 (cons mime-type (cdr (mm-handle-type handle)))
4946 (mm-handle-encoding handle)
4947 (mm-handle-undisplayer handle)
4948 (mm-handle-disposition handle)
4949 (mm-handle-description handle)
4950 nil
4951 (mm-handle-id handle)))
4952 (setq gnus-article-mime-handles
4953 (mm-merge-handles gnus-article-mime-handles handle))
4954 (when (mm-handle-displayed-p handle)
4955 (mm-remove-part handle))
4956 (gnus-mm-display-part handle))))
4957
4958 (defun gnus-mime-copy-part (&optional handle arg)
4959 "Put the MIME part under point into a new buffer.
4960 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4961 are decompressed."
4962 (interactive (list nil current-prefix-arg))
4963 (gnus-article-check-buffer)
4964 (unless handle
4965 (setq handle (get-text-property (point) 'gnus-data)))
4966 (when handle
4967 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4968 'name)
4969 (mail-content-type-get (mm-handle-disposition handle)
4970 'filename)))
4971 contents dont-decode charset coding-system)
4972 (mm-with-unibyte-buffer
4973 (mm-insert-part handle)
4974 (setq contents (or (condition-case nil
4975 (mm-decompress-buffer filename nil 'sig)
4976 (error
4977 (setq dont-decode t)
4978 nil))
4979 (buffer-string))))
4980 (setq filename (cond (filename (file-name-nondirectory filename))
4981 (dont-decode "*raw data*")
4982 (t "*decoded*")))
4983 (cond
4984 (dont-decode)
4985 ((not arg)
4986 (unless (setq charset (mail-content-type-get
4987 (mm-handle-type handle) 'charset))
4988 (unless (setq coding-system (mm-with-unibyte-buffer
4989 (insert contents)
4990 (mm-find-buffer-file-coding-system)))
4991 (setq charset gnus-newsgroup-charset))))
4992 ((numberp arg)
4993 (setq charset (or (cdr (assq arg
4994 gnus-summary-show-article-charset-alist))
4995 (mm-read-coding-system "Charset: ")))))
4996 (switch-to-buffer (generate-new-buffer filename))
4997 (if (or coding-system
4998 (and charset
4999 (setq coding-system (mm-charset-to-coding-system charset))
5000 (not (eq charset 'ascii))))
5001 (progn
5002 (mm-enable-multibyte)
5003 (insert (mm-decode-coding-string contents coding-system))
5004 (setq buffer-file-coding-system
5005 (if (boundp 'last-coding-system-used)
5006 (symbol-value 'last-coding-system-used)
5007 coding-system)))
5008 (mm-disable-multibyte)
5009 (insert contents)
5010 (setq buffer-file-coding-system mm-binary-coding-system))
5011 ;; We do it this way to make `normal-mode' set the appropriate mode.
5012 (unwind-protect
5013 (progn
5014 (setq buffer-file-name (expand-file-name filename))
5015 (normal-mode))
5016 (setq buffer-file-name nil))
5017 (goto-char (point-min)))))
5018
5019 (defun gnus-mime-print-part (&optional handle filename)
5020 "Print the MIME part under point."
5021 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5022 (gnus-article-check-buffer)
5023 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5024 (contents (and handle (mm-get-part handle)))
5025 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5026 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5027 (when contents
5028 (if printer
5029 (unwind-protect
5030 (progn
5031 (mm-save-part-to-file handle file)
5032 (call-process shell-file-name nil
5033 (generate-new-buffer " *mm*")
5034 nil
5035 shell-command-switch
5036 (mm-mailcap-command
5037 printer file (mm-handle-type handle))))
5038 (delete-file file))
5039 (with-temp-buffer
5040 (insert contents)
5041 (gnus-print-buffer))
5042 (ps-despool filename)))))
5043
5044 (defun gnus-mime-inline-part (&optional handle arg)
5045 "Insert the MIME part under point into the current buffer.
5046 Compressed files like .gz and .bz2 are decompressed."
5047 (interactive (list nil current-prefix-arg))
5048 (gnus-article-check-buffer)
5049 (unless handle
5050 (setq handle (get-text-property (point) 'gnus-data)))
5051 (when handle
5052 (let ((b (point))
5053 (inhibit-read-only t)
5054 contents charset coding-system)
5055 (if (and (not arg) (mm-handle-undisplayer handle))
5056 (mm-remove-part handle)
5057 (mm-with-unibyte-buffer
5058 (mm-insert-part handle)
5059 (setq contents
5060 (or (mm-decompress-buffer
5061 (or (mail-content-type-get (mm-handle-type handle)
5062 'name)
5063 (mail-content-type-get (mm-handle-disposition handle)
5064 'filename))
5065 nil t)
5066 (buffer-string))))
5067 (cond
5068 ((not arg)
5069 (unless (setq charset (mail-content-type-get
5070 (mm-handle-type handle) 'charset))
5071 (unless (setq coding-system
5072 (mm-with-unibyte-buffer
5073 (insert contents)
5074 (mm-find-buffer-file-coding-system)))
5075 (setq charset gnus-newsgroup-charset))))
5076 ((numberp arg)
5077 (if (mm-handle-undisplayer handle)
5078 (mm-remove-part handle))
5079 (setq charset
5080 (or (cdr (assq arg
5081 gnus-summary-show-article-charset-alist))
5082 (mm-read-coding-system "Charset: "))))
5083 (t
5084 (if (mm-handle-undisplayer handle)
5085 (mm-remove-part handle))))
5086 (forward-line 2)
5087 (mm-insert-inline
5088 handle
5089 (if (or coding-system
5090 (and charset
5091 (setq coding-system
5092 (mm-charset-to-coding-system charset))
5093 (not (eq coding-system 'ascii))))
5094 (mm-decode-coding-string contents coding-system)
5095 (mm-string-to-multibyte contents)))
5096 (goto-char b)))))
5097
5098 (defun gnus-mime-strip-charset-parameters (handle)
5099 "Strip charset parameters from HANDLE."
5100 (if (stringp (car handle))
5101 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
5102 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5103 "message/external-body")
5104 (progn
5105 (unless (mm-handle-cache handle)
5106 (mm-extern-cache-contents handle))
5107 (mm-handle-cache handle))
5108 handle)))
5109 (charset (assq 'charset (cdr type))))
5110 (when charset
5111 (delq charset type)))))
5112
5113 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5114 "Insert the MIME part under point into the current buffer using the
5115 specified charset."
5116 (interactive (list nil current-prefix-arg))
5117 (gnus-article-check-buffer)
5118 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5119 (fun (get-text-property (point) 'gnus-callback))
5120 (gnus-newsgroup-ignored-charsets 'gnus-all)
5121 gnus-newsgroup-charset form preferred parts)
5122 (when handle
5123 (when (prog1
5124 (and fun
5125 (setq gnus-newsgroup-charset
5126 (or (cdr (assq
5127 arg
5128 gnus-summary-show-article-charset-alist))
5129 (mm-read-coding-system "Charset: "))))
5130 (if (mm-handle-undisplayer handle)
5131 (mm-remove-part handle)))
5132 (gnus-mime-strip-charset-parameters handle)
5133 (when (and (consp (setq form (cdr-safe fun)))
5134 (setq form (ignore-errors
5135 (assq 'gnus-mime-display-alternative form)))
5136 (setq preferred (caddr form))
5137 (progn
5138 (when (eq (car preferred) 'quote)
5139 (setq preferred (cadr preferred)))
5140 (not (equal preferred
5141 (get-text-property (point) 'gnus-data))))
5142 (setq parts (get-text-property (point) 'gnus-part))
5143 (setq parts (cdr (assq parts
5144 gnus-article-mime-handle-alist)))
5145 (equal (mm-handle-media-type parts) "multipart/alternative")
5146 (setq parts (reverse (cdr parts))))
5147 (setcar (cddr form)
5148 (list 'quote (or (cadr (member preferred parts))
5149 (car parts)))))
5150 (funcall fun handle)))))
5151
5152 (defun gnus-mime-view-part-externally (&optional handle)
5153 "View the MIME part under point with an external viewer."
5154 (interactive)
5155 (gnus-article-check-buffer)
5156 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5157 (mm-user-display-methods nil)
5158 (mm-inlined-types nil)
5159 (mail-parse-charset gnus-newsgroup-charset)
5160 (mail-parse-ignored-charsets
5161 (with-current-buffer gnus-summary-buffer
5162 gnus-newsgroup-ignored-charsets))
5163 (type (mm-handle-media-type handle))
5164 (method (mailcap-mime-info type))
5165 (mm-enable-external t))
5166 (if (not (stringp method))
5167 (gnus-mime-view-part-as-type
5168 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5169 (when handle
5170 (if (mm-handle-undisplayer handle)
5171 (mm-remove-part handle)
5172 (mm-display-part handle))))))
5173
5174 (defun gnus-mime-view-part-internally (&optional handle)
5175 "View the MIME part under point with an internal viewer.
5176 If no internal viewer is available, use an external viewer."
5177 (interactive)
5178 (gnus-article-check-buffer)
5179 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5180 (mm-inlined-types '(".*"))
5181 (mm-inline-large-images t)
5182 (mail-parse-charset gnus-newsgroup-charset)
5183 (mail-parse-ignored-charsets
5184 (with-current-buffer gnus-summary-buffer
5185 gnus-newsgroup-ignored-charsets))
5186 (inhibit-read-only t))
5187 (if (not (mm-inlinable-p handle))
5188 (gnus-mime-view-part-as-type
5189 nil (lambda (types) (mm-inlinable-p handle (car types))))
5190 (when handle
5191 (if (mm-handle-undisplayer handle)
5192 (mm-remove-part handle)
5193 (mm-display-part handle))))))
5194
5195 (defun gnus-mime-action-on-part (&optional action)
5196 "Do something with the MIME attachment at \(point\)."
5197 (interactive
5198 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5199 (gnus-article-check-buffer)
5200 (let ((action-pair (assoc action gnus-mime-action-alist)))
5201 (if action-pair
5202 (funcall (cdr action-pair)))))
5203
5204 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5205 "Call FUNCTION on MIME part N.
5206 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5207 If INTERACTIVE, call FUNCTION interactivly."
5208 (let (window frame)
5209 ;; Check whether the article is displayed.
5210 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5211 (setq window (get-buffer-window gnus-article-buffer t))
5212 (frame-visible-p (setq frame (window-frame window))))
5213 (error "No article is displayed"))
5214 (with-current-buffer gnus-article-buffer
5215 ;; Check whether the article displays the right contents.
5216 (unless (with-current-buffer gnus-summary-buffer
5217 (eq gnus-current-article (gnus-summary-article-number)))
5218 (error "You should select the right article first"))
5219 (if n
5220 (setq n (prefix-numeric-value n))
5221 (let ((pt (point)))
5222 (setq n (or (get-text-property pt 'gnus-part)
5223 (and (not (bobp))
5224 (get-text-property (1- pt) 'gnus-part))
5225 (get-text-property (prog2
5226 (forward-line 1)
5227 (point)
5228 (goto-char pt))
5229 'gnus-part)
5230 (get-text-property
5231 (or (and (setq pt (previous-single-property-change
5232 pt 'gnus-part))
5233 (1- pt))
5234 (next-single-property-change (point) 'gnus-part)
5235 (point))
5236 'gnus-part)
5237 1))))
5238 ;; Check whether the specified part exists.
5239 (when (> n (length gnus-article-mime-handle-alist))
5240 (error "No such part")))
5241 (unless
5242 (progn
5243 ;; To select the window is needed so that the cursor
5244 ;; might be visible on the MIME button.
5245 (select-window (prog1
5246 window
5247 (setq window (selected-window))
5248 ;; Article may be displayed in the other frame.
5249 (gnus-select-frame-set-input-focus
5250 (prog1
5251 frame
5252 (setq frame (selected-frame))))))
5253 (when (gnus-article-goto-part n)
5254 ;; We point the cursor and the arrow at the MIME button
5255 ;; when the `function' prompt the user for something.
5256 (let ((cursor-in-non-selected-windows t)
5257 (overlay-arrow-string "=>")
5258 (overlay-arrow-position (point-marker)))
5259 (unwind-protect
5260 (cond
5261 ((and no-handle interactive)
5262 (call-interactively function))
5263 (no-handle
5264 (funcall function))
5265 (interactive
5266 (call-interactively
5267 function
5268 (cdr (assq n gnus-article-mime-handle-alist))))
5269 (t
5270 (funcall function
5271 (cdr (assq n gnus-article-mime-handle-alist)))))
5272 (set-marker overlay-arrow-position nil)
5273 (unless gnus-auto-select-part
5274 (gnus-select-frame-set-input-focus frame)
5275 (select-window window))))
5276 t))
5277 (if gnus-inhibit-mime-unbuttonizing
5278 ;; This is the default though the program shouldn't reach here.
5279 (error "No such part")
5280 ;; The part which doesn't have the MIME button is selected.
5281 ;; So, we display all the buttons and redo it.
5282 (let ((gnus-inhibit-mime-unbuttonizing t))
5283 (gnus-summary-show-article)
5284 (gnus-article-part-wrapper n function no-handle))))))
5285
5286 (defun gnus-article-pipe-part (n)
5287 "Pipe MIME part N, which is the numerical prefix."
5288 (interactive "P")
5289 (gnus-article-part-wrapper n 'mm-pipe-part))
5290
5291 (defun gnus-article-save-part (n)
5292 "Save MIME part N, which is the numerical prefix."
5293 (interactive "P")
5294 (gnus-article-part-wrapper n 'mm-save-part))
5295
5296 (defun gnus-article-interactively-view-part (n)
5297 "View MIME part N interactively, which is the numerical prefix."
5298 (interactive "P")
5299 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5300
5301 (defun gnus-article-copy-part (n)
5302 "Copy MIME part N, which is the numerical prefix."
5303 (interactive "P")
5304 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5305
5306 (defun gnus-article-view-part-as-charset (n)
5307 "View MIME part N using a specified charset.
5308 N is the numerical prefix."
5309 (interactive "P")
5310 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5311
5312 (defun gnus-article-view-part-externally (n)
5313 "View MIME part N externally, which is the numerical prefix."
5314 (interactive "P")
5315 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5316
5317 (defun gnus-article-inline-part (n)
5318 "Inline MIME part N, which is the numerical prefix."
5319 (interactive "P")
5320 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5321
5322 (defun gnus-article-save-part-and-strip (n)
5323 "Save MIME part N and replace it with an external body.
5324 N is the numerical prefix."
5325 (interactive "P")
5326 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5327
5328 (defun gnus-article-replace-part (n)
5329 "Replace MIME part N with an external body.
5330 N is the numerical prefix."
5331 (interactive "P")
5332 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5333
5334 (defun gnus-article-delete-part (n)
5335 "Delete MIME part N and add some information about the removed part.
5336 N is the numerical prefix."
5337 (interactive "P")
5338 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5339
5340 (defun gnus-article-view-part-as-type (n)
5341 "Choose a MIME media type, and view part N as such.
5342 N is the numerical prefix."
5343 (interactive "P")
5344 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5345
5346 (defun gnus-article-mime-match-handle-first (condition)
5347 (if condition
5348 (let (n)
5349 (dolist (ihandle gnus-article-mime-handle-alist)
5350 (if (and (cond
5351 ((functionp condition)
5352 (funcall condition (cdr ihandle)))
5353 ((eq condition 'undisplayed)
5354 (not (or (mm-handle-undisplayer (cdr ihandle))
5355 (equal (mm-handle-media-type (cdr ihandle))
5356 "multipart/alternative"))))
5357 ((eq condition 'undisplayed-alternative)
5358 (not (mm-handle-undisplayer (cdr ihandle))))
5359 (t t))
5360 (gnus-article-goto-part (car ihandle))
5361 (or (not n) (< (car ihandle) n)))
5362 (setq n (car ihandle))))
5363 (or n 1))
5364 1))
5365
5366 (defun gnus-article-view-part (&optional n)
5367 "View MIME part N, which is the numerical prefix."
5368 (interactive "P")
5369 (with-current-buffer gnus-article-buffer
5370 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5371 gnus-article-mime-match-handle-function)))
5372 (when (> n (length gnus-article-mime-handle-alist))
5373 (error "No such part"))
5374 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5375 (when (gnus-article-goto-part n)
5376 (if (equal (car handle) "multipart/alternative")
5377 (gnus-article-press-button)
5378 (when (eq (gnus-mm-display-part handle) 'internal)
5379 (gnus-set-window-start)))))))
5380
5381 (defsubst gnus-article-mime-total-parts ()
5382 (if (bufferp (car gnus-article-mime-handles))
5383 1 ;; single part
5384 (1- (length gnus-article-mime-handles))))
5385
5386 (defun gnus-mm-display-part (handle)
5387 "Display HANDLE and fix MIME button."
5388 (let ((id (get-text-property (point) 'gnus-part))
5389 (point (point))
5390 (inhibit-read-only t))
5391 (forward-line 1)
5392 (prog1
5393 (let ((window (selected-window))
5394 (mail-parse-charset gnus-newsgroup-charset)
5395 (mail-parse-ignored-charsets
5396 (if (gnus-buffer-live-p gnus-summary-buffer)
5397 (with-current-buffer gnus-summary-buffer
5398 gnus-newsgroup-ignored-charsets)
5399 nil)))
5400 (save-excursion
5401 (unwind-protect
5402 (let ((win (gnus-get-buffer-window (current-buffer) t))
5403 (beg (point)))
5404 (when win
5405 (select-window win))
5406 (goto-char point)
5407 (forward-line)
5408 (if (mm-handle-displayed-p handle)
5409 ;; This will remove the part.
5410 (mm-display-part handle)
5411 (save-restriction
5412 (narrow-to-region (point)
5413 (if (eobp) (point) (1+ (point))))
5414 (mm-display-part handle)
5415 ;; We narrow to the part itself and
5416 ;; then call the treatment functions.
5417 (goto-char (point-min))
5418 (forward-line 1)
5419 (narrow-to-region (point) (point-max))
5420 (gnus-treat-article
5421 nil id
5422 (gnus-article-mime-total-parts)
5423 (mm-handle-media-type handle)))))
5424 (if (window-live-p window)
5425 (select-window window)))))
5426 (goto-char point)
5427 (gnus-delete-line)
5428 (gnus-insert-mime-button
5429 handle id (list (mm-handle-displayed-p handle)))
5430 (goto-char point))))
5431
5432 (defun gnus-article-goto-part (n)
5433 "Go to MIME part N."
5434 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5435
5436 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5437 (let ((gnus-tmp-name
5438 (or (mail-content-type-get (mm-handle-type handle) 'name)
5439 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5440 (mail-content-type-get (mm-handle-type handle) 'url)
5441 ""))
5442 (gnus-tmp-type (mm-handle-media-type handle))
5443 (gnus-tmp-description (or (mm-handle-description handle) ""))
5444 (gnus-tmp-dots
5445 (if (if displayed (car displayed)
5446 (mm-handle-displayed-p handle))
5447 "" "..."))
5448 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5449 (buffer-size)))
5450 gnus-tmp-type-long b e)
5451 (when (string-match ".*/" gnus-tmp-name)
5452 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5453 (setq gnus-tmp-type-long (concat gnus-tmp-type
5454 (and (not (equal gnus-tmp-name ""))
5455 (concat "; " gnus-tmp-name))))
5456 (unless (equal gnus-tmp-description "")
5457 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5458 (unless (bolp)
5459 (insert "\n"))
5460 (setq b (point))
5461 (gnus-eval-format
5462 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5463 `(keymap ,gnus-mime-button-map
5464 gnus-callback gnus-mm-display-part
5465 gnus-part ,gnus-tmp-id
5466 article-type annotation
5467 gnus-data ,handle))
5468 (setq e (if (bolp)
5469 ;; Exclude a newline.
5470 (1- (point))
5471 (point)))
5472 (when gnus-article-button-face
5473 (gnus-overlay-put (gnus-make-overlay b e nil t)
5474 'face gnus-article-button-face))
5475 (widget-convert-button
5476 'link b e
5477 :mime-handle handle
5478 :action 'gnus-widget-press-button
5479 :button-keymap gnus-mime-button-map
5480 :help-echo
5481 (lambda (widget/window &optional overlay pos)
5482 ;; Needed to properly clear the message due to a bug in
5483 ;; wid-edit (XEmacs only).
5484 (if (boundp 'help-echo-owns-message)
5485 (setq help-echo-owns-message t))
5486 (format
5487 "%S: %s the MIME part; %S: more options"
5488 (aref gnus-mouse-2 0)
5489 ;; XEmacs will get a single widget arg; Emacs 21 will get
5490 ;; window, overlay, position.
5491 (if (mm-handle-displayed-p
5492 (if overlay
5493 (with-current-buffer (gnus-overlay-buffer overlay)
5494 (widget-get (widget-at (gnus-overlay-start overlay))
5495 :mime-handle))
5496 (widget-get widget/window :mime-handle)))
5497 "hide" "show")
5498 (aref gnus-down-mouse-3 0))))))
5499
5500 (defun gnus-widget-press-button (elems el)
5501 (goto-char (widget-get elems :from))
5502 (gnus-article-press-button))
5503
5504 (defvar gnus-displaying-mime nil)
5505
5506 (defun gnus-display-mime (&optional ihandles)
5507 "Display the MIME parts."
5508 (save-excursion
5509 (save-selected-window
5510 (let ((window (get-buffer-window gnus-article-buffer))
5511 (point (point)))
5512 (when window
5513 (select-window window)
5514 ;; We have to do this since selecting the window
5515 ;; may change the point. So we set the window point.
5516 (set-window-point window point)))
5517 (let ((handles ihandles)
5518 (inhibit-read-only t)
5519 handle)
5520 (cond (handles)
5521 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5522 (when gnus-article-emulate-mime
5523 (mm-uu-dissect-text-parts handles)))
5524 (gnus-article-emulate-mime
5525 (setq handles (mm-uu-dissect))))
5526 (when (and (not ihandles)
5527 (not gnus-displaying-mime))
5528 ;; Top-level call; we clean up.
5529 (when gnus-article-mime-handles
5530 (mm-destroy-parts gnus-article-mime-handles)
5531 (setq gnus-article-mime-handle-alist nil));; A trick.
5532 (setq gnus-article-mime-handles handles)
5533 ;; We allow users to glean info from the handles.
5534 (when gnus-article-mime-part-function
5535 (gnus-mime-part-function handles)))
5536 (if (and handles
5537 (or (not (stringp (car handles)))
5538 (cdr handles)))
5539 (progn
5540 (when (and (not ihandles)
5541 (not gnus-displaying-mime))
5542 ;; Clean up for mime parts.
5543 (article-goto-body)
5544 (delete-region (point) (point-max)))
5545 (let ((gnus-displaying-mime t))
5546 (gnus-mime-display-part handles)))
5547 (save-restriction
5548 (article-goto-body)
5549 (narrow-to-region (point) (point-max))
5550 (gnus-treat-article nil 1 1)
5551 (widen)))
5552 (unless ihandles
5553 ;; Highlight the headers.
5554 (save-excursion
5555 (save-restriction
5556 (article-goto-body)
5557 (narrow-to-region (point-min) (point))
5558 (gnus-article-save-original-date
5559 (gnus-treat-article 'head)))))))
5560 ;; Cope with broken MIME messages.
5561 (goto-char (point-max))
5562 (unless (bolp)
5563 (insert "\n"))))
5564
5565 (defcustom gnus-mime-display-multipart-as-mixed nil
5566 "Display \"multipart\" parts as \"multipart/mixed\".
5567
5568 If t, it overrides nil values of
5569 `gnus-mime-display-multipart-alternative-as-mixed' and
5570 `gnus-mime-display-multipart-related-as-mixed'."
5571 :group 'gnus-article-mime
5572 :type 'boolean)
5573
5574 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5575 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5576 :version "22.1"
5577 :group 'gnus-article-mime
5578 :type 'boolean)
5579
5580 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5581 "Display \"multipart/related\" parts as \"multipart/mixed\".
5582
5583 If displaying \"text/html\" is discouraged \(see
5584 `mm-discouraged-alternatives'\) images or other material inside a
5585 \"multipart/related\" part might be overlooked when this variable is nil."
5586 :version "22.1"
5587 :group 'gnus-article-mime
5588 :type 'boolean)
5589
5590 (defun gnus-mime-display-part (handle)
5591 (cond
5592 ;; Maybe a broken MIME message.
5593 ((null handle))
5594 ;; Single part.
5595 ((not (stringp (car handle)))
5596 (gnus-mime-display-single handle))
5597 ;; User-defined multipart
5598 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5599 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5600 handle))
5601 ;; multipart/alternative
5602 ((and (equal (car handle) "multipart/alternative")
5603 (not (or gnus-mime-display-multipart-as-mixed
5604 gnus-mime-display-multipart-alternative-as-mixed)))
5605 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5606 (push (cons id handle) gnus-article-mime-handle-alist)
5607 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5608 ;; multipart/related
5609 ((and (equal (car handle) "multipart/related")
5610 (not (or gnus-mime-display-multipart-as-mixed
5611 gnus-mime-display-multipart-related-as-mixed)))
5612 ;;;!!!We should find the start part, but we just default
5613 ;;;!!!to the first part.
5614 ;;(gnus-mime-display-part (cadr handle))
5615 ;;;!!! Most multipart/related is an HTML message plus images.
5616 ;;;!!! Unfortunately we are unable to let W3 display those
5617 ;;;!!! included images, so we just display it as a mixed multipart.
5618 ;;(gnus-mime-display-mixed (cdr handle))
5619 ;;;!!! No, w3 can display everything just fine.
5620 (gnus-mime-display-part (cadr handle)))
5621 ((equal (car handle) "multipart/signed")
5622 (gnus-add-wash-type 'signed)
5623 (gnus-mime-display-security handle))
5624 ((equal (car handle) "multipart/encrypted")
5625 (gnus-add-wash-type 'encrypted)
5626 (gnus-mime-display-security handle))
5627 ;; Other multiparts are handled like multipart/mixed.
5628 (t
5629 (gnus-mime-display-mixed (cdr handle)))))
5630
5631 (defun gnus-mime-part-function (handles)
5632 (if (stringp (car handles))
5633 (mapcar 'gnus-mime-part-function (cdr handles))
5634 (funcall gnus-article-mime-part-function handles)))
5635
5636 (defun gnus-mime-display-mixed (handles)
5637 (mapcar 'gnus-mime-display-part handles))
5638
5639 (defun gnus-mime-display-single (handle)
5640 (let ((type (mm-handle-media-type handle))
5641 (ignored gnus-ignored-mime-types)
5642 (not-attachment t)
5643 (move nil)
5644 display text)
5645 (catch 'ignored
5646 (progn
5647 (while ignored
5648 (when (string-match (pop ignored) type)
5649 (throw 'ignored nil)))
5650 (if (and (setq not-attachment
5651 (and (not (mm-inline-override-p handle))
5652 (or (not (mm-handle-disposition handle))
5653 (equal (car (mm-handle-disposition handle))
5654 "inline")
5655 (mm-attachment-override-p handle))))
5656 (mm-automatic-display-p handle)
5657 (or (and
5658 (mm-inlinable-p handle)
5659 (mm-inlined-p handle))
5660 (mm-automatic-external-display-p type)))
5661 (setq display t)
5662 (when (equal (mm-handle-media-supertype handle) "text")
5663 (setq text t)))
5664 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5665 beg)
5666 (push (cons id handle) gnus-article-mime-handle-alist)
5667 (when (and display
5668 (equal (mm-handle-media-supertype handle) "message"))
5669 (insert-char
5670 ?\n
5671 (cond ((not (bolp)) 2)
5672 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5673 (t 1))))
5674 (when (or (not display)
5675 (not (gnus-unbuttonized-mime-type-p type)))
5676 (gnus-insert-mime-button
5677 handle id (list (or display (and not-attachment text))))
5678 (gnus-article-insert-newline)
5679 ;; Remember modify the number of forward lines.
5680 (setq move t))
5681 (setq beg (point))
5682 (cond
5683 (display
5684 (when move
5685 (forward-line -1)
5686 (setq beg (point)))
5687 (let ((mail-parse-charset gnus-newsgroup-charset)
5688 (mail-parse-ignored-charsets
5689 (save-excursion (condition-case ()
5690 (set-buffer gnus-summary-buffer)
5691 (error))
5692 gnus-newsgroup-ignored-charsets)))
5693 (mm-display-part handle t))
5694 (goto-char (point-max)))
5695 ((and text not-attachment)
5696 (when move
5697 (forward-line -1)
5698 (setq beg (point)))
5699 (gnus-article-insert-newline)
5700 (mm-insert-inline
5701 handle
5702 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5703 'charset)
5704 (and (equal type "text/calendar") 'utf-8))))
5705 (cond ((not charset)
5706 (mm-string-as-multibyte (mm-get-part handle)))
5707 ((eq charset 'gnus-decoded)
5708 (with-current-buffer (mm-handle-buffer handle)
5709 (buffer-string)))
5710 (t
5711 (mm-decode-string (mm-get-part handle) charset)))))
5712 (goto-char (point-max))))
5713 ;; Do highlighting.
5714 (save-excursion
5715 (save-restriction
5716 (narrow-to-region beg (point))
5717 (if (eq handle gnus-article-mime-handles)
5718 ;; The format=flowed case.
5719 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5720 ;; Don't count signature parts that are never displayed.
5721 ;; The part number should be re-calculated supposing this
5722 ;; might be a message/rfc822 part.
5723 (let (handles)
5724 (dolist (part gnus-article-mime-handles)
5725 (unless (or (stringp part)
5726 (equal (car (mm-handle-type part))
5727 "application/pgp-signature"))
5728 (push part handles)))
5729 (gnus-treat-article
5730 nil (length (memq handle handles)) (length handles)
5731 (mm-handle-media-type handle)))))))))))
5732
5733 (defun gnus-unbuttonized-mime-type-p (type)
5734 "Say whether TYPE is to be unbuttonized."
5735 (unless gnus-inhibit-mime-unbuttonizing
5736 (when (catch 'found
5737 (let ((types gnus-unbuttonized-mime-types))
5738 (while types
5739 (when (string-match (pop types) type)
5740 (throw 'found t)))))
5741 (not (catch 'found
5742 (let ((types gnus-buttonized-mime-types))
5743 (while types
5744 (when (string-match (pop types) type)
5745 (throw 'found t)))))))))
5746
5747 (defun gnus-article-insert-newline ()
5748 "Insert a newline, but mark it as undeletable."
5749 (gnus-put-text-property
5750 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5751
5752 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5753 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5754 (ihandles handles)
5755 (point (point))
5756 handle (inhibit-read-only t) from props begend not-pref)
5757 (save-window-excursion
5758 (save-restriction
5759 (when ibegend
5760 (narrow-to-region (car ibegend)
5761 (or (cdr ibegend)
5762 (progn
5763 (goto-char (car ibegend))
5764 (forward-line 2)
5765 (point))))
5766 (delete-region (point-min) (point-max))
5767 (mm-remove-parts handles))
5768 (setq begend (list (point-marker)))
5769 ;; Do the toggle.
5770 (unless (setq not-pref (cadr (member preferred ihandles)))
5771 (setq not-pref (car ihandles)))
5772 (when (or ibegend
5773 (not preferred)
5774 (not (gnus-unbuttonized-mime-type-p
5775 "multipart/alternative")))
5776 (gnus-add-text-properties
5777 (setq from (point))
5778 (progn
5779 (insert (format "%d. " id))
5780 (point))
5781 `(gnus-callback
5782 (lambda (handles)
5783 (unless ,(not ibegend)
5784 (setq gnus-article-mime-handle-alist
5785 ',gnus-article-mime-handle-alist))
5786 (gnus-mime-display-alternative
5787 ',ihandles ',not-pref ',begend ,id))
5788 keymap ,gnus-mime-button-map
5789 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5790 face ,gnus-article-button-face
5791 gnus-part ,id
5792 article-type multipart))
5793 (widget-convert-button 'link from (point)
5794 :action 'gnus-widget-press-button
5795 :button-keymap gnus-widget-button-keymap)
5796 ;; Do the handles
5797 (while (setq handle (pop handles))
5798 (gnus-add-text-properties
5799 (setq from (point))
5800 (progn
5801 (insert (format "(%c) %-18s"
5802 (if (equal handle preferred) ?* ? )
5803 (mm-handle-media-type handle)))
5804 (point))
5805 `(gnus-callback
5806 (lambda (handles)
5807 (unless ,(not ibegend)
5808 (setq gnus-article-mime-handle-alist
5809 ',gnus-article-mime-handle-alist))
5810 (gnus-mime-display-alternative
5811 ',ihandles ',handle ',begend ,id))
5812 keymap ,gnus-mime-button-map
5813 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5814 face ,gnus-article-button-face
5815 gnus-part ,id
5816 gnus-data ,handle))
5817 (widget-convert-button 'link from (point)
5818 :action 'gnus-widget-press-button
5819 :button-keymap gnus-widget-button-keymap)
5820 (insert " "))
5821 (insert "\n\n"))
5822 (when preferred
5823 (if (stringp (car preferred))
5824 (gnus-display-mime preferred)
5825 (let ((mail-parse-charset gnus-newsgroup-charset)
5826 (mail-parse-ignored-charsets
5827 (with-current-buffer gnus-summary-buffer
5828 gnus-newsgroup-ignored-charsets)))
5829 (mm-display-part preferred)
5830 ;; Do highlighting.
5831 (save-excursion
5832 (save-restriction
5833 (narrow-to-region (car begend) (point-max))
5834 (gnus-treat-article
5835 nil (length gnus-article-mime-handle-alist)
5836 (gnus-article-mime-total-parts)
5837 (mm-handle-media-type handle))))))
5838 (goto-char (point-max))
5839 (setcdr begend (point-marker)))))
5840 (when ibegend
5841 (goto-char point))))
5842
5843 (defconst gnus-article-wash-status-strings
5844 (let ((alist '((cite "c" "Possible hidden citation text"
5845 " " "All citation text visible")
5846 (headers "h" "Hidden headers"
5847 " " "All headers visible.")
5848 (pgp "p" "Encrypted or signed message status hidden"
5849 " " "No hidden encryption nor digital signature status")
5850 (signature "s" "Signature has been hidden"
5851 " " "Signature is visible")
5852 (overstrike "o" "Overstrike (^H) characters applied"
5853 " " "No overstrike characters applied")
5854 (emphasis "e" "/*_Emphasis_*/ characters applied"
5855 " " "No /*_emphasis_*/ characters applied")))
5856 result)
5857 (dolist (entry alist result)
5858 (let ((key (nth 0 entry))
5859 (on (copy-sequence (nth 1 entry)))
5860 (on-help (nth 2 entry))
5861 (off (copy-sequence (nth 3 entry)))
5862 (off-help (nth 4 entry)))
5863 (put-text-property 0 1 'help-echo on-help on)
5864 (put-text-property 0 1 'help-echo off-help off)
5865 (push (list key on off) result))))
5866 "Alist of strings describing wash status in the mode line.
5867 Each entry has the form (KEY ON OF), where the KEY is a symbol
5868 representing the particular washing function, ON is the string to use
5869 in the article mode line when the washing function is active, and OFF
5870 is the string to use when it is inactive.")
5871
5872 (defun gnus-article-wash-status-entry (key value)
5873 (let ((entry (assoc key gnus-article-wash-status-strings)))
5874 (if value (nth 1 entry) (nth 2 entry))))
5875
5876 (defun gnus-article-wash-status ()
5877 "Return a string which display status of article washing."
5878 (with-current-buffer gnus-article-buffer
5879 (let ((cite (memq 'cite gnus-article-wash-types))
5880 (headers (memq 'headers gnus-article-wash-types))
5881 (boring (memq 'boring-headers gnus-article-wash-types))
5882 (pgp (memq 'pgp gnus-article-wash-types))
5883 (pem (memq 'pem gnus-article-wash-types))
5884 (signed (memq 'signed gnus-article-wash-types))
5885 (encrypted (memq 'encrypted gnus-article-wash-types))
5886 (signature (memq 'signature gnus-article-wash-types))
5887 (overstrike (memq 'overstrike gnus-article-wash-types))
5888 (emphasis (memq 'emphasis gnus-article-wash-types)))
5889 (concat
5890 (gnus-article-wash-status-entry 'cite cite)
5891 (gnus-article-wash-status-entry 'headers (or headers boring))
5892 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5893 (gnus-article-wash-status-entry 'signature signature)
5894 (gnus-article-wash-status-entry 'overstrike overstrike)
5895 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5896
5897 (defun gnus-add-wash-type (type)
5898 "Add a washing of TYPE to the current status."
5899 (add-to-list 'gnus-article-wash-types type))
5900
5901 (defun gnus-delete-wash-type (type)
5902 "Add a washing of TYPE to the current status."
5903 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5904
5905 (defun gnus-add-image (category image)
5906 "Add IMAGE of CATEGORY to the list of displayed images."
5907 (let ((entry (assq category gnus-article-image-alist)))
5908 (unless entry
5909 (setq entry (list category))
5910 (push entry gnus-article-image-alist))
5911 (nconc entry (list image))))
5912
5913 (defun gnus-delete-images (category)
5914 "Delete all images in CATEGORY."
5915 (let ((entry (assq category gnus-article-image-alist)))
5916 (dolist (image (cdr entry))
5917 (gnus-remove-image image category))
5918 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5919 (gnus-delete-wash-type category)))
5920
5921 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5922
5923 (defun gnus-article-maybe-hide-headers ()
5924 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5925 Provided for backwards compatibility."
5926 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5927 (not (with-current-buffer gnus-summary-buffer
5928 gnus-have-all-headers)))
5929 (not gnus-inhibit-hiding))
5930 (gnus-article-hide-headers)))
5931
5932 ;;; Article savers.
5933
5934 (defun gnus-output-to-file (file-name)
5935 "Append the current article to a file named FILE-NAME.
5936 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5937 text and used as the value of the coding cookie which is added to the
5938 top of a file. Otherwise, this function saves a raw article without
5939 the coding cookie."
5940 (let* ((artbuf (current-buffer))
5941 (file-name-coding-system nnmail-pathname-coding-system)
5942 (coding gnus-article-save-coding-system)
5943 (coding-system-for-read (if coding
5944 nil ;; Rely on the coding cookie.
5945 mm-text-coding-system))
5946 (coding-system-for-write (or coding
5947 mm-text-coding-system-for-write
5948 mm-text-coding-system))
5949 (exists (file-exists-p file-name)))
5950 (with-temp-buffer
5951 (when exists
5952 (insert-file-contents file-name)
5953 (goto-char (point-min))
5954 ;; Remove the existing coding cookie.
5955 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5956 (delete-region (match-beginning 0) (match-end 0))))
5957 (goto-char (point-max))
5958 (insert-buffer-substring artbuf)
5959 ;; Append newline at end of the buffer as separator, and then
5960 ;; save it to file.
5961 (goto-char (point-max))
5962 (insert "\n")
5963 (when coding
5964 ;; If the coding system is not suitable to encode the text,
5965 ;; ask a user for a proper one.
5966 (when (fboundp 'select-safe-coding-system)
5967 (setq coding (coding-system-base
5968 (save-window-excursion
5969 (select-safe-coding-system (point-min) (point-max)
5970 coding))))
5971 (setq coding-system-for-write
5972 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5973 coding)))
5974 (goto-char (point-min))
5975 ;; Add the coding cookie.
5976 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5977 coding-system-for-write)))
5978 (if exists
5979 (progn
5980 (write-region (point-min) (point-max) file-name nil 'no-message)
5981 (message "Appended to %s" file-name))
5982 (write-region (point-min) (point-max) file-name))))
5983 t)
5984
5985 (defun gnus-narrow-to-page (&optional arg)
5986 "Narrow the article buffer to a page.
5987 If given a numerical ARG, move forward ARG pages."
5988 (interactive "P")
5989 (setq arg (if arg (prefix-numeric-value arg) 0))
5990 (with-current-buffer gnus-article-buffer
5991 (goto-char (point-min))
5992 (widen)
5993 ;; Remove any old next/prev buttons.
5994 (when (gnus-visual-p 'page-marker)
5995 (let ((inhibit-read-only t))
5996 (gnus-remove-text-with-property 'gnus-prev)
5997 (gnus-remove-text-with-property 'gnus-next)))
5998 (if
5999 (cond ((< arg 0)
6000 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
6001 ((> arg 0)
6002 (re-search-forward page-delimiter nil 'move arg)))
6003 (goto-char (match-end 0))
6004 (save-excursion
6005 (goto-char (point-min))
6006 (setq gnus-page-broken
6007 (and (re-search-forward page-delimiter nil t) t))))
6008 (when gnus-page-broken
6009 (narrow-to-region
6010 (point)
6011 (if (re-search-forward page-delimiter nil 'move)
6012 (match-beginning 0)
6013 (point)))
6014 (when (and (gnus-visual-p 'page-marker)
6015 (> (point-min) (save-restriction (widen) (point-min))))
6016 (save-excursion
6017 (goto-char (point-min))
6018 (gnus-insert-prev-page-button)))
6019 (when (and (gnus-visual-p 'page-marker)
6020 (< (point-max) (save-restriction (widen) (point-max))))
6021 (save-excursion
6022 (goto-char (point-max))
6023 (gnus-insert-next-page-button))))))
6024
6025 ;; Article mode commands
6026
6027 (defun gnus-article-goto-next-page ()
6028 "Show the next page of the article."
6029 (interactive)
6030 (when (gnus-article-next-page)
6031 (goto-char (point-min))
6032 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6033
6034
6035 (defun gnus-article-goto-prev-page ()
6036 "Show the previous page of the article."
6037 (interactive)
6038 (if (bobp)
6039 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6040 (gnus-article-prev-page nil)))
6041
6042 ;; This is cleaner but currently breaks `gnus-pick-mode':
6043 ;;
6044 ;; (defun gnus-article-goto-next-page ()
6045 ;; "Show the next page of the article."
6046 ;; (interactive)
6047 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6048 ;; (gnus-summary-next-page)))
6049 ;;
6050 ;; (defun gnus-article-goto-prev-page ()
6051 ;; "Show the next page of the article."
6052 ;; (interactive)
6053 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6054 ;; (gnus-summary-prev-page)))
6055
6056 (defun gnus-article-next-page (&optional lines)
6057 "Show the next page of the current article.
6058 If end of article, return non-nil. Otherwise return nil.
6059 Argument LINES specifies lines to be scrolled up."
6060 (interactive "p")
6061 (move-to-window-line -1)
6062 (if (and (not (and gnus-article-over-scroll
6063 (> (count-lines (window-start) (point-max))
6064 (+ (or lines (1- (window-height)))
6065 (or (and (boundp 'scroll-margin)
6066 (symbol-value 'scroll-margin))
6067 0)))))
6068 (save-excursion
6069 (end-of-line)
6070 (and (pos-visible-in-window-p) ;Not continuation line.
6071 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
6072 ;; Nothing in this page.
6073 (if (or (not gnus-page-broken)
6074 (save-excursion
6075 (save-restriction
6076 (widen)
6077 (forward-line)
6078 (eobp)))) ;Real end-of-buffer?
6079 (progn
6080 (when gnus-article-over-scroll
6081 (gnus-article-next-page-1 lines))
6082 t) ;Nothing more.
6083 (gnus-narrow-to-page 1) ;Go to next page.
6084 nil)
6085 ;; More in this page.
6086 (gnus-article-next-page-1 lines)
6087 nil))
6088
6089 (defmacro gnus-article-beginning-of-window ()
6090 "Move point to the beginning of the window.
6091 In Emacs, the point is placed at the line number which `scroll-margin'
6092 specifies."
6093 (if (featurep 'xemacs)
6094 '(move-to-window-line 0)
6095 '(move-to-window-line
6096 (min (max 0 scroll-margin)
6097 (max 1 (- (window-height)
6098 (if mode-line-format 1 0)
6099 (if header-line-format 1 0)))))))
6100
6101 (defun gnus-article-next-page-1 (lines)
6102 (when (and (not (featurep 'xemacs))
6103 (numberp lines)
6104 (> lines 0)
6105 (numberp (symbol-value 'scroll-margin))
6106 (> (symbol-value 'scroll-margin) 0))
6107 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6108 ;; too many number of lines if `scroll-margin' is set as two or greater.
6109 (setq lines (min lines
6110 (max 0 (- (count-lines (window-start) (point-max))
6111 (symbol-value 'scroll-margin))))))
6112 (condition-case ()
6113 (let ((scroll-in-place nil))
6114 (scroll-up lines))
6115 (end-of-buffer
6116 ;; Long lines may cause an end-of-buffer error.
6117 (goto-char (point-max))))
6118 (gnus-article-beginning-of-window))
6119
6120 (defun gnus-article-prev-page (&optional lines)
6121 "Show previous page of current article.
6122 Argument LINES specifies lines to be scrolled down."
6123 (interactive "p")
6124 (move-to-window-line 0)
6125 (if (and gnus-page-broken
6126 (bobp)
6127 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6128 (progn
6129 (gnus-narrow-to-page -1) ;Go to previous page.
6130 (goto-char (point-max))
6131 (recenter (if gnus-article-over-scroll
6132 (if lines
6133 (max (+ lines (or (and (boundp 'scroll-margin)
6134 (symbol-value 'scroll-margin))
6135 0))
6136 3)
6137 (- (window-height) 2))
6138 -1)))
6139 (prog1
6140 (condition-case ()
6141 (let ((scroll-in-place nil))
6142 (scroll-down lines))
6143 (beginning-of-buffer
6144 (goto-char (point-min))))
6145 (gnus-article-beginning-of-window))))
6146
6147 (defun gnus-article-only-boring-p ()
6148 "Decide whether there is only boring text remaining in the article.
6149 Something \"interesting\" is a word of at least two letters that does
6150 not have a face in `gnus-article-boring-faces'."
6151 (when (and gnus-article-skip-boring
6152 (boundp 'gnus-article-boring-faces)
6153 (symbol-value 'gnus-article-boring-faces))
6154 (save-excursion
6155 (let ((inhibit-point-motion-hooks t))
6156 (catch 'only-boring
6157 (while (re-search-forward "\\b\\w\\w" nil t)
6158 (forward-char -1)
6159 (when (not (gnus-intersection
6160 (gnus-faces-at (point))
6161 (symbol-value 'gnus-article-boring-faces)))
6162 (throw 'only-boring nil)))
6163 (throw 'only-boring t))))))
6164
6165 (defun gnus-article-refer-article ()
6166 "Read article specified by message-id around point."
6167 (interactive)
6168 (save-excursion
6169 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6170 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6171 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6172 (let ((msg-id (concat "<" (match-string 0) ">")))
6173 (set-buffer gnus-summary-buffer)
6174 (gnus-summary-refer-article msg-id))
6175 (error "No references around point"))))
6176
6177 (defun gnus-article-show-summary ()
6178 "Reconfigure windows to show summary buffer."
6179 (interactive)
6180 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6181 (error "There is no summary buffer for this article buffer")
6182 (gnus-article-set-globals)
6183 (gnus-configure-windows 'article)
6184 (gnus-summary-goto-subject gnus-current-article)
6185 (gnus-summary-position-point)))
6186
6187 (defun gnus-article-describe-briefly ()
6188 "Describe article mode commands briefly."
6189 (interactive)
6190 (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
6191
6192 (defun gnus-article-summary-command ()
6193 "Execute the last keystroke in the summary buffer."
6194 (interactive)
6195 (let ((obuf (current-buffer))
6196 (owin (current-window-configuration))
6197 func)
6198 (switch-to-buffer gnus-article-current-summary 'norecord)
6199 (setq func (lookup-key (current-local-map) (this-command-keys)))
6200 (call-interactively func)
6201 (set-buffer obuf)
6202 (set-window-configuration owin)
6203 (set-window-point (get-buffer-window (current-buffer)) (point))))
6204
6205 (defun gnus-article-summary-command-nosave ()
6206 "Execute the last keystroke in the summary buffer."
6207 (interactive)
6208 (let (func)
6209 (pop-to-buffer gnus-article-current-summary)
6210 (setq func (lookup-key (current-local-map) (this-command-keys)))
6211 (call-interactively func)))
6212
6213 (defun gnus-article-check-buffer ()
6214 "Beep if not in an article buffer."
6215 (unless (equal major-mode 'gnus-article-mode)
6216 (error "Command invoked outside of a Gnus article buffer")))
6217
6218 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6219 "Read a summary buffer key sequence and execute it from the article buffer."
6220 (interactive "P")
6221 (gnus-article-check-buffer)
6222 (let ((nosaves
6223 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6224 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6225 "=" "^" "\M-^" "|"))
6226 (nosave-but-article
6227 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6228 "An" "Ap" [?A (meta return)] [?A delete]))
6229 (nosave-in-article
6230 '("AS" "\C-d"))
6231 (up-to-top
6232 '("n" "Gn" "p" "Gp"))
6233 keys new-sum-point)
6234 (with-current-buffer gnus-article-current-summary
6235 (let (gnus-pick-mode)
6236 (setq unread-command-events (nconc unread-command-events
6237 (list (or key last-command-event)))
6238 keys (if (featurep 'xemacs)
6239 (events-to-keys (read-key-sequence nil t))
6240 (read-key-sequence nil t)))))
6241
6242 (message "")
6243
6244 (cond
6245 ((eq (aref keys (1- (length keys))) ?\C-h)
6246 (gnus-article-describe-bindings (substring keys 0 -1)))
6247 ((or (member keys nosaves)
6248 (member keys nosave-but-article)
6249 (member keys nosave-in-article))
6250 (let (func)
6251 (save-window-excursion
6252 (pop-to-buffer gnus-article-current-summary)
6253 ;; We disable the pick minor mode commands.
6254 (let (gnus-pick-mode)
6255 (setq func (lookup-key (current-local-map) keys))))
6256 (if (or (not func)
6257 (numberp func))
6258 (ding)
6259 (unless (member keys nosave-in-article)
6260 (set-buffer gnus-article-current-summary))
6261 (call-interactively func)
6262 (setq new-sum-point (point)))
6263 (when (member keys nosave-but-article)
6264 (pop-to-buffer gnus-article-buffer))))
6265 (t
6266 ;; These commands should restore window configuration.
6267 (let ((obuf (current-buffer))
6268 (owin (current-window-configuration))
6269 win func in-buffer selected new-sum-start new-sum-hscroll err)
6270 (cond (not-restore-window
6271 (pop-to-buffer gnus-article-current-summary)
6272 (setq win (selected-window)))
6273 ((setq win (get-buffer-window gnus-article-current-summary))
6274 (select-window win))
6275 (t
6276 (let ((summary-buffer gnus-article-current-summary))
6277 (gnus-configure-windows 'article)
6278 (unless (setq win (get-buffer-window summary-buffer 'visible))
6279 (let ((gnus-buffer-configuration
6280 '(article ((vertical 1.0
6281 (summary 0.25 point)
6282 (article 1.0))))))
6283 (gnus-configure-windows 'article))
6284 (setq win (get-buffer-window summary-buffer 'visible)))
6285 (gnus-select-frame-set-input-focus (window-frame win))
6286 (select-window win))))
6287 (setq in-buffer (current-buffer))
6288 ;; We disable the pick minor mode commands.
6289 (if (and (setq func (let (gnus-pick-mode)
6290 (lookup-key (current-local-map) keys)))
6291 (functionp func)
6292 (condition-case code
6293 (progn
6294 (call-interactively func)
6295 t)
6296 (error
6297 (setq err code)
6298 nil)))
6299 (progn
6300 (when (eq win (selected-window))
6301 (setq new-sum-point (point)
6302 new-sum-start (window-start win)
6303 new-sum-hscroll (window-hscroll win)))
6304 (when (or (eq in-buffer (current-buffer))
6305 (when (eq obuf (current-buffer))
6306 (set-buffer in-buffer)
6307 t))
6308 (setq selected (gnus-summary-select-article))
6309 (set-buffer obuf)
6310 (unless not-restore-window
6311 (set-window-configuration owin))
6312 (when (and (eq selected 'old)
6313 new-sum-point)
6314 (set-window-start (get-buffer-window (current-buffer))
6315 1)
6316 (set-window-point (get-buffer-window (current-buffer))
6317 (if (article-goto-body)
6318 (1- (point))
6319 (point))))
6320 (when (and (not not-restore-window)
6321 new-sum-point
6322 (with-current-buffer (window-buffer win)
6323 (eq major-mode 'gnus-summary-mode)))
6324 (set-window-point win new-sum-point)
6325 (set-window-start win new-sum-start)
6326 (set-window-hscroll win new-sum-hscroll))))
6327 (set-window-configuration owin)
6328 (if err
6329 (signal (car err) (cdr err))
6330 (ding))))))))
6331
6332 (defun gnus-article-read-summary-send-keys ()
6333 (interactive)
6334 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6335 (gnus-article-read-summary-keys)))
6336
6337 (defun gnus-article-describe-key (key)
6338 "Display documentation of the function invoked by KEY.
6339 KEY is a string or a vector."
6340 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6341 (read-key-sequence "Describe key: "))))
6342 (gnus-article-check-buffer)
6343 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6344 gnus-article-read-summary-send-keys))
6345 (with-current-buffer gnus-article-current-summary
6346 (setq unread-command-events
6347 (if (featurep 'xemacs)
6348 (append key nil)
6349 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6350 (list 'meta (- x 128))
6351 x))
6352 key)))
6353 (let ((cursor-in-echo-area t)
6354 gnus-pick-mode)
6355 (describe-key (read-key-sequence nil t))))
6356 (describe-key key)))
6357
6358 (defun gnus-article-describe-key-briefly (key &optional insert)
6359 "Display documentation of the function invoked by KEY.
6360 KEY is a string or a vector."
6361 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6362 (read-key-sequence "Describe key: "))
6363 current-prefix-arg))
6364 (gnus-article-check-buffer)
6365 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6366 gnus-article-read-summary-send-keys))
6367 (with-current-buffer gnus-article-current-summary
6368 (setq unread-command-events
6369 (if (featurep 'xemacs)
6370 (append key nil)
6371 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6372 (list 'meta (- x 128))
6373 x))
6374 key)))
6375 (let ((cursor-in-echo-area t)
6376 gnus-pick-mode)
6377 (describe-key-briefly (read-key-sequence nil t) insert)))
6378 (describe-key-briefly key insert)))
6379
6380 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6381 (defvar gnus-agent-summary-mode)
6382 (defvar gnus-draft-mode)
6383
6384 (defun gnus-article-describe-bindings (&optional prefix)
6385 "Show a list of all defined keys, and their definitions.
6386 The optional argument PREFIX, if non-nil, should be a key sequence;
6387 then we display only bindings that start with that prefix."
6388 (interactive)
6389 (gnus-article-check-buffer)
6390 (let ((keymap (copy-keymap gnus-article-mode-map))
6391 (map (copy-keymap gnus-article-send-map))
6392 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6393 agent draft)
6394 (define-key keymap "S" map)
6395 (define-key map [t] nil)
6396 (with-current-buffer gnus-article-current-summary
6397 (set-keymap-parent map (key-binding "S"))
6398 (let (def gnus-pick-mode)
6399 (dolist (key sumkeys)
6400 (when (setq def (key-binding key))
6401 (define-key keymap key def))))
6402 (when (boundp 'gnus-agent-summary-mode)
6403 (setq agent gnus-agent-summary-mode))
6404 (when (boundp 'gnus-draft-mode)
6405 (setq draft gnus-draft-mode)))
6406 (with-temp-buffer
6407 (use-local-map keymap)
6408 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6409 (set (make-local-variable 'gnus-draft-mode) draft)
6410 (describe-bindings prefix))
6411 (let ((item `((lambda (prefix)
6412 (with-current-buffer ,(current-buffer)
6413 (gnus-article-describe-bindings prefix)))
6414 ,prefix)))
6415 (with-current-buffer (if (fboundp 'help-buffer)
6416 (let (help-xref-following) (help-buffer))
6417 "*Help*") ;; Emacs 21
6418 (setq help-xref-stack-item item)))))
6419
6420 (defun gnus-article-reply-with-original (&optional wide)
6421 "Start composing a reply mail to the current message.
6422 The text in the region will be yanked. If the region isn't active,
6423 the entire article will be yanked."
6424 (interactive)
6425 (let ((article (cdr gnus-article-current))
6426 contents)
6427 (if (not (gnus-region-active-p))
6428 (with-current-buffer gnus-summary-buffer
6429 (gnus-summary-reply (list (list article)) wide))
6430 (setq contents (buffer-substring (point) (mark t)))
6431 ;; Deactivate active regions.
6432 (when (and (boundp 'transient-mark-mode)
6433 transient-mark-mode)
6434 (setq mark-active nil))
6435 (with-current-buffer gnus-summary-buffer
6436 (gnus-summary-reply
6437 (list (list article contents)) wide)))))
6438
6439 (defun gnus-article-wide-reply-with-original ()
6440 "Start composing a wide reply mail to the current message.
6441 The text in the region will be yanked. If the region isn't active,
6442 the entire article will be yanked."
6443 (interactive)
6444 (gnus-article-reply-with-original t))
6445
6446 (defun gnus-article-followup-with-original ()
6447 "Compose a followup to the current article.
6448 The text in the region will be yanked. If the region isn't active,
6449 the entire article will be yanked."
6450 (interactive)
6451 (let ((article (cdr gnus-article-current))
6452 contents)
6453 (if (not (gnus-region-active-p))
6454 (with-current-buffer gnus-summary-buffer
6455 (gnus-summary-followup (list (list article))))
6456 (setq contents (buffer-substring (point) (mark t)))
6457 ;; Deactivate active regions.
6458 (when (and (boundp 'transient-mark-mode)
6459 transient-mark-mode)
6460 (setq mark-active nil))
6461 (with-current-buffer gnus-summary-buffer
6462 (gnus-summary-followup
6463 (list (list article contents)))))))
6464
6465 (defun gnus-article-hide (&optional arg force)
6466 "Hide all the gruft in the current article.
6467 This means that signatures, cited text and (some) headers will be
6468 hidden.
6469 If given a prefix, show the hidden text instead."
6470 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6471 (gnus-article-hide-headers arg)
6472 (gnus-article-hide-list-identifiers arg)
6473 (gnus-article-hide-citation-maybe arg force)
6474 (gnus-article-hide-signature arg))
6475
6476 (defun gnus-article-maybe-highlight ()
6477 "Do some article highlighting if article highlighting is requested."
6478 (when (gnus-visual-p 'article-highlight 'highlight)
6479 (gnus-article-highlight-some)))
6480
6481 (defun gnus-check-group-server ()
6482 ;; Make sure the connection to the server is alive.
6483 (unless (gnus-server-opened
6484 (gnus-find-method-for-group gnus-newsgroup-name))
6485 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6486 (gnus-request-group gnus-newsgroup-name t)))
6487
6488 (eval-when-compile
6489 (autoload 'nneething-get-file-name "nneething"))
6490
6491 (defun gnus-request-article-this-buffer (article group)
6492 "Get an article and insert it into this buffer."
6493 (let (do-update-line sparse-header)
6494 (prog1
6495 (save-excursion
6496 (erase-buffer)
6497 (gnus-kill-all-overlays)
6498 (setq group (or group gnus-newsgroup-name))
6499
6500 ;; Using `gnus-request-article' directly will insert the article into
6501 ;; `nntp-server-buffer' - so we'll save some time by not having to
6502 ;; copy it from the server buffer into the article buffer.
6503
6504 ;; We only request an article by message-id when we do not have the
6505 ;; headers for it, so we'll have to get those.
6506 (when (stringp article)
6507 (gnus-read-header article))
6508
6509 ;; If the article number is negative, that means that this article
6510 ;; doesn't belong in this newsgroup (possibly), so we find its
6511 ;; message-id and request it by id instead of number.
6512 (when (and (numberp article)
6513 gnus-summary-buffer
6514 (get-buffer gnus-summary-buffer)
6515 (gnus-buffer-exists-p gnus-summary-buffer))
6516 (with-current-buffer gnus-summary-buffer
6517 (let ((header (gnus-summary-article-header article)))
6518 (when (< article 0)
6519 (cond
6520 ((memq article gnus-newsgroup-sparse)
6521 ;; This is a sparse gap article.
6522 (setq do-update-line article)
6523 (setq article (mail-header-id header))
6524 (setq sparse-header (gnus-read-header article))
6525 (setq gnus-newsgroup-sparse
6526 (delq article gnus-newsgroup-sparse)))
6527 ((vectorp header)
6528 ;; It's a real article.
6529 (setq article (mail-header-id header)))
6530 (t
6531 ;; It is an extracted pseudo-article.
6532 (setq article 'pseudo)
6533 (gnus-request-pseudo-article header))))
6534
6535 (let ((method (gnus-find-method-for-group
6536 gnus-newsgroup-name)))
6537 (when (and (eq (car method) 'nneething)
6538 (vectorp header))
6539 (let ((dir (nneething-get-file-name
6540 (mail-header-id header))))
6541 (when (and (stringp dir)
6542 (file-directory-p dir))
6543 (setq article 'nneething)
6544 (gnus-group-enter-directory dir))))))))
6545
6546 (cond
6547 ;; Refuse to select canceled articles.
6548 ((and (numberp article)
6549 gnus-summary-buffer
6550 (get-buffer gnus-summary-buffer)
6551 (gnus-buffer-exists-p gnus-summary-buffer)
6552 (eq (cdr (with-current-buffer gnus-summary-buffer
6553 (assq article gnus-newsgroup-reads)))
6554 gnus-canceled-mark))
6555 nil)
6556 ;; We first check `gnus-original-article-buffer'.
6557 ((and (get-buffer gnus-original-article-buffer)
6558 (numberp article)
6559 (with-current-buffer gnus-original-article-buffer
6560 (and (equal (car gnus-original-article) group)
6561 (eq (cdr gnus-original-article) article))))
6562 (insert-buffer-substring gnus-original-article-buffer)
6563 'article)
6564 ;; Check the backlog.
6565 ((and gnus-keep-backlog
6566 (gnus-backlog-request-article group article (current-buffer)))
6567 'article)
6568 ;; Check asynchronous pre-fetch.
6569 ((gnus-async-request-fetched-article group article (current-buffer))
6570 (gnus-async-prefetch-next group article gnus-summary-buffer)
6571 (when (and (numberp article) gnus-keep-backlog)
6572 (gnus-backlog-enter-article group article (current-buffer)))
6573 'article)
6574 ;; Check the cache.
6575 ((and gnus-use-cache
6576 (numberp article)
6577 (gnus-cache-request-article article group))
6578 'article)
6579 ;; Check the agent cache.
6580 ((gnus-agent-request-article article group)
6581 'article)
6582 ;; Get the article and put into the article buffer.
6583 ((or (stringp article)
6584 (numberp article))
6585 (let ((gnus-override-method gnus-override-method)
6586 (methods (and (stringp article)
6587 gnus-refer-article-method))
6588 (backend (car (gnus-find-method-for-group
6589 gnus-newsgroup-name)))
6590 result
6591 (inhibit-read-only t))
6592 (if (or (not (listp methods))
6593 (and (symbolp (car methods))
6594 (assq (car methods) nnoo-definition-alist)))
6595 (setq methods (list methods)))
6596 (when (and (null gnus-override-method)
6597 methods)
6598 (setq gnus-override-method (pop methods)))
6599 (while (not result)
6600 (when (eq gnus-override-method 'current)
6601 (setq gnus-override-method
6602 (with-current-buffer gnus-summary-buffer
6603 gnus-current-select-method)))
6604 (erase-buffer)
6605 (gnus-kill-all-overlays)
6606 (let ((gnus-newsgroup-name group))
6607 (gnus-check-group-server))
6608 (cond
6609 ((gnus-request-article article group (current-buffer))
6610 (when (numberp article)
6611 (gnus-async-prefetch-next group article
6612 gnus-summary-buffer)
6613 (when gnus-keep-backlog
6614 (gnus-backlog-enter-article
6615 group article (current-buffer))))
6616 (setq result 'article))
6617 (methods
6618 (setq gnus-override-method (pop methods)))
6619 ((not (string-match "^400 "
6620 (nnheader-get-report backend)))
6621 ;; If we get 400 server disconnect, reconnect and
6622 ;; retry; otherwise, assume the article has expired.
6623 (setq result 'done))))
6624 (and (eq result 'article) 'article)))
6625 ;; It was a pseudo.
6626 (t article)))
6627
6628 ;; Associate this article with the current summary buffer.
6629 (setq gnus-article-current-summary gnus-summary-buffer)
6630
6631 ;; Take the article from the original article buffer
6632 ;; and place it in the buffer it's supposed to be in.
6633 (when (and (get-buffer gnus-article-buffer)
6634 (equal (buffer-name (current-buffer))
6635 (buffer-name (get-buffer gnus-article-buffer))))
6636 (save-excursion
6637 (if (get-buffer gnus-original-article-buffer)
6638 (set-buffer gnus-original-article-buffer)
6639 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6640 (buffer-disable-undo)
6641 (setq major-mode 'gnus-original-article-mode)
6642 (setq buffer-read-only t))
6643 (let ((inhibit-read-only t))
6644 (erase-buffer)
6645 (insert-buffer-substring gnus-article-buffer))
6646 (setq gnus-original-article (cons group article)))
6647
6648 ;; Decode charsets.
6649 (run-hooks 'gnus-article-decode-hook)
6650 ;; Mark article as decoded or not.
6651 (setq gnus-article-decoded-p gnus-article-decode-hook))
6652
6653 ;; Update sparse articles.
6654 (when (and do-update-line
6655 (or (numberp article)
6656 (stringp article)))
6657 (let ((buf (current-buffer)))
6658 (set-buffer gnus-summary-buffer)
6659 (gnus-summary-update-article do-update-line sparse-header)
6660 (gnus-summary-goto-subject do-update-line nil t)
6661 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6662 (point))
6663 (set-buffer buf))))))
6664
6665 ;;;
6666 ;;; Article editing
6667 ;;;
6668
6669 (defcustom gnus-article-edit-mode-hook nil
6670 "Hook run in article edit mode buffers."
6671 :group 'gnus-article-various
6672 :type 'hook)
6673
6674 (defvar gnus-article-edit-done-function nil)
6675
6676 (defvar gnus-article-edit-mode-map nil)
6677
6678 ;; Should we be using derived.el for this?
6679 (unless gnus-article-edit-mode-map
6680 (setq gnus-article-edit-mode-map (make-keymap))
6681 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6682
6683 (gnus-define-keys gnus-article-edit-mode-map
6684 "\C-c?" describe-mode
6685 "\C-c\C-c" gnus-article-edit-done
6686 "\C-c\C-k" gnus-article-edit-exit
6687 "\C-c\C-f\C-t" message-goto-to
6688 "\C-c\C-f\C-o" message-goto-from
6689 "\C-c\C-f\C-b" message-goto-bcc
6690 ;;"\C-c\C-f\C-w" message-goto-fcc
6691 "\C-c\C-f\C-c" message-goto-cc
6692 "\C-c\C-f\C-s" message-goto-subject
6693 "\C-c\C-f\C-r" message-goto-reply-to
6694 "\C-c\C-f\C-n" message-goto-newsgroups
6695 "\C-c\C-f\C-d" message-goto-distribution
6696 "\C-c\C-f\C-f" message-goto-followup-to
6697 "\C-c\C-f\C-m" message-goto-mail-followup-to
6698 "\C-c\C-f\C-k" message-goto-keywords
6699 "\C-c\C-f\C-u" message-goto-summary
6700 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6701 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6702 "\C-c\C-b" message-goto-body
6703 "\C-c\C-i" message-goto-signature
6704
6705 "\C-c\C-t" message-insert-to
6706 "\C-c\C-n" message-insert-newsgroups
6707 "\C-c\C-o" message-sort-headers
6708 "\C-c\C-e" message-elide-region
6709 "\C-c\C-v" message-delete-not-region
6710 "\C-c\C-z" message-kill-to-signature
6711 "\M-\r" message-newline-and-reformat
6712 "\C-c\C-a" mml-attach-file
6713 "\C-a" message-beginning-of-line
6714 "\t" message-tab
6715 "\M-;" comment-region)
6716
6717 (gnus-define-keys (gnus-article-edit-wash-map
6718 "\C-c\C-w" gnus-article-edit-mode-map)
6719 "f" gnus-article-edit-full-stops))
6720
6721 (easy-menu-define
6722 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6723 '("Field"
6724 ["Fetch To" message-insert-to t]
6725 ["Fetch Newsgroups" message-insert-newsgroups t]
6726 "----"
6727 ["To" message-goto-to t]
6728 ["From" message-goto-from t]
6729 ["Subject" message-goto-subject t]
6730 ["Cc" message-goto-cc t]
6731 ["Reply-To" message-goto-reply-to t]
6732 ["Summary" message-goto-summary t]
6733 ["Keywords" message-goto-keywords t]
6734 ["Newsgroups" message-goto-newsgroups t]
6735 ["Followup-To" message-goto-followup-to t]
6736 ["Mail-Followup-To" message-goto-mail-followup-to t]
6737 ["Distribution" message-goto-distribution t]
6738 ["Body" message-goto-body t]
6739 ["Signature" message-goto-signature t]))
6740
6741 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6742 "Major mode for editing articles.
6743 This is an extended text-mode.
6744
6745 \\{gnus-article-edit-mode-map}"
6746 (make-local-variable 'gnus-article-edit-done-function)
6747 (make-local-variable 'gnus-prev-winconf)
6748 (set (make-local-variable 'font-lock-defaults)
6749 '(message-font-lock-keywords t))
6750 (set (make-local-variable 'mail-header-separator) "")
6751 (set (make-local-variable 'gnus-article-edit-mode) t)
6752 (easy-menu-add message-mode-field-menu message-mode-map)
6753 (mml-mode)
6754 (setq buffer-read-only nil)
6755 (buffer-enable-undo)
6756 (widen))
6757
6758 (defun gnus-article-edit (&optional force)
6759 "Edit the current article.
6760 This will have permanent effect only in mail groups.
6761 If FORCE is non-nil, allow editing of articles even in read-only
6762 groups."
6763 (interactive "P")
6764 (when (and (not force)
6765 (gnus-group-read-only-p))
6766 (error "The current newsgroup does not support article editing"))
6767 (gnus-article-date-original)
6768 (gnus-article-edit-article
6769 'ignore
6770 `(lambda (no-highlight)
6771 'ignore
6772 (gnus-summary-edit-article-done
6773 ,(or (mail-header-references gnus-current-headers) "")
6774 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6775
6776 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6777 "Start editing the contents of the current article buffer."
6778 (let ((winconf (current-window-configuration)))
6779 (set-buffer gnus-article-buffer)
6780 (let ((message-auto-save-directory
6781 ;; Don't associate the article buffer with a draft file.
6782 nil))
6783 (gnus-article-edit-mode))
6784 (funcall start-func)
6785 (set-buffer-modified-p nil)
6786 (gnus-configure-windows 'edit-article)
6787 (setq gnus-article-edit-done-function exit-func)
6788 (setq gnus-prev-winconf winconf)
6789 (unless quiet
6790 (gnus-message 6 "C-c C-c to end edits"))))
6791
6792 (defun gnus-article-edit-done (&optional arg)
6793 "Update the article edits and exit."
6794 (interactive "P")
6795 (let ((func gnus-article-edit-done-function)
6796 (buf (current-buffer))
6797 (start (window-start))
6798 (p (point))
6799 (winconf gnus-prev-winconf))
6800 (widen) ;; Widen it in case that users narrowed the buffer.
6801 (funcall func arg)
6802 (set-buffer buf)
6803 ;; The cache and backlog have to be flushed somewhat.
6804 (when gnus-keep-backlog
6805 (gnus-backlog-remove-article
6806 (car gnus-article-current) (cdr gnus-article-current)))
6807 ;; Flush original article as well.
6808 (when (get-buffer gnus-original-article-buffer)
6809 (with-current-buffer gnus-original-article-buffer
6810 (setq gnus-original-article nil)))
6811 (when gnus-use-cache
6812 (gnus-cache-update-article
6813 (car gnus-article-current) (cdr gnus-article-current)))
6814 ;; We remove all text props from the article buffer.
6815 (kill-all-local-variables)
6816 (set-text-properties (point-min) (point-max) nil)
6817 (gnus-article-mode)
6818 (set-window-configuration winconf)
6819 (set-buffer buf)
6820 (set-window-start (get-buffer-window buf) start)
6821 (set-window-point (get-buffer-window buf) (point)))
6822 (gnus-summary-show-article))
6823
6824 (defun gnus-article-edit-exit ()
6825 "Exit the article editing without updating."
6826 (interactive)
6827 (when (or (not (buffer-modified-p))
6828 (yes-or-no-p "Article modified; kill anyway? "))
6829 (let ((curbuf (current-buffer))
6830 (p (point))
6831 (window-start (window-start)))
6832 (erase-buffer)
6833 (if (gnus-buffer-live-p gnus-original-article-buffer)
6834 (insert-buffer-substring gnus-original-article-buffer))
6835 (let ((winconf gnus-prev-winconf))
6836 (kill-all-local-variables)
6837 (gnus-article-mode)
6838 (set-window-configuration winconf)
6839 ;; Tippy-toe some to make sure that point remains where it was.
6840 (save-current-buffer
6841 (set-buffer curbuf)
6842 (set-window-start (get-buffer-window (current-buffer)) window-start)
6843 (goto-char p))))
6844 (gnus-summary-show-article)))
6845
6846 (defun gnus-article-edit-full-stops ()
6847 "Interactively repair spacing at end of sentences."
6848 (interactive)
6849 (save-excursion
6850 (goto-char (point-min))
6851 (search-forward-regexp "^$" nil t)
6852 (let ((case-fold-search nil))
6853 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6854
6855 ;;;
6856 ;;; Article highlights
6857 ;;;
6858
6859 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6860
6861 ;;; Internal Variables:
6862
6863 (defcustom gnus-button-url-regexp
6864 (concat
6865 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6866 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6867 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6868 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6869 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6870 (punct "!?:;.,"))
6871 (concat
6872 "\\(?:"
6873 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6874 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6875 "\\|"
6876 "[" chars punct "]+" "[" chars "]"
6877 "\\)"))
6878 (concat ;; XEmacs 21.4 doesn't support POSIX.
6879 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6880 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6881 "\\)")
6882 "Regular expression that matches URLs."
6883 :group 'gnus-article-buttons
6884 :type 'regexp)
6885
6886 (defcustom gnus-button-valid-fqdn-regexp
6887 message-valid-fqdn-regexp
6888 "Regular expression that matches a valid FQDN."
6889 :version "22.1"
6890 :group 'gnus-article-buttons
6891 :type 'regexp)
6892
6893 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6894 (defcustom gnus-button-valid-localpart-regexp
6895 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6896 "Regular expression that matches a localpart of mail addresses or MIDs."
6897 :version "22.1"
6898 :group 'gnus-article-buttons
6899 :type 'regexp)
6900
6901 (defcustom gnus-button-man-handler 'manual-entry
6902 "Function to use for displaying man pages.
6903 The function must take at least one argument with a string naming the
6904 man page."
6905 :version "22.1"
6906 :type '(choice (function-item :tag "Man" manual-entry)
6907 (function-item :tag "Woman" woman)
6908 (function :tag "Other"))
6909 :group 'gnus-article-buttons)
6910
6911 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6912 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6913 If the default site is too slow, try to find a CTAN mirror, see
6914 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6915 the variable `gnus-button-handle-ctan'."
6916 :version "22.1"
6917 :group 'gnus-article-buttons
6918 :link '(custom-manual "(gnus)Group Parameters")
6919 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6920 (const "http://tug.ctan.org/tex-archive/")
6921 (const "http://www.dante.de/CTAN/")
6922 (string :tag "Other")))
6923
6924 (defcustom gnus-button-ctan-handler 'browse-url
6925 "Function to use for displaying CTAN links.
6926 The function must take one argument, the string naming the URL."
6927 :version "22.1"
6928 :type '(choice (function-item :tag "Browse Url" browse-url)
6929 (function :tag "Other"))
6930 :group 'gnus-article-buttons)
6931
6932 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6933 "Bogus strings removed from CTAN URLs."
6934 :version "22.1"
6935 :group 'gnus-article-buttons
6936 :type '(choice (const "^/?tex-archive/\\|/")
6937 (regexp :tag "Other")))
6938
6939 (defcustom gnus-button-ctan-directory-regexp
6940 (regexp-opt
6941 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6942 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6943 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6944 "tds" "tools" "usergrps" "web") t)
6945 "Regular expression for ctan directories.
6946 It should match all directories in the top level of `gnus-ctan-url'."
6947 :version "22.1"
6948 :group 'gnus-article-buttons
6949 :type 'regexp)
6950
6951 (defcustom gnus-button-mid-or-mail-regexp
6952 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6953 gnus-button-valid-fqdn-regexp
6954 ">?\\)\\b")
6955 "Regular expression that matches a message ID or a mail address."
6956 :version "22.1"
6957 :group 'gnus-article-buttons
6958 :type 'regexp)
6959
6960 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6961 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6962 Strings like this can be either a message ID or a mail address. If it is one
6963 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6964 message ID or a mail address, respectively. If this variable is set to the
6965 symbol `ask', always query the user what do do. If it is a function, this
6966 function will be called with the string as its only argument. The function
6967 must return `mid', `mail', `invalid' or `ask'."
6968 :version "22.1"
6969 :group 'gnus-article-buttons
6970 :type '(choice (function-item :tag "Heuristic function"
6971 gnus-button-mid-or-mail-heuristic)
6972 (const ask)
6973 (const mid)
6974 (const mail)))
6975
6976 (defcustom gnus-button-mid-or-mail-heuristic-alist
6977 '((-10.0 . ".+\\$.+@")
6978 (-10.0 . "#")
6979 (-10.0 . "\\*")
6980 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6981 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6982 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6983 (-1.0 . "^[^a-z]+@")
6984 ;;
6985 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6986 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6987 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6988 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6989 ;;
6990 (-2.0 . "^[0-9]")
6991 (-1.0 . "^[0-9][0-9]")
6992 ;;
6993 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6994 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6995 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6996 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6997 ;;
6998 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6999 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7000 ;; "[0-9]{8,}.*\@"
7001 (-3.0
7002 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7003 ;; "[0-9]{12,}.*\@"
7004 ;; compensation for TDMA dated mail addresses:
7005 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7006 ;;
7007 (-20.0 . "\\.fsf@") ;; Gnus
7008 (-20.0 . "^slrn")
7009 (-20.0 . "^Pine")
7010 (-20.0 . "^alpine\\.")
7011 (-20.0 . "_-_") ;; Subject change in thread
7012 ;;
7013 (-20.0 . "\\.ln@") ;; leafnode
7014 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7015 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7016 ;;
7017 ;; (5.0 . "") ;; $local_part_len <= 7
7018 (10.0 . "^[^0-9]+@")
7019 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7020 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7021 (3.0 . "\@stud")
7022 ;;
7023 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7024 ;;
7025 (0.5 . "^[A-Z][a-z]")
7026 (0.5 . "^[A-Z][a-z][a-z]")
7027 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7028 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7029 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7030
7031 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7032 address. The REGEXP is processed with `case-fold-search' set to nil."
7033 :version "22.1"
7034 :group 'gnus-article-buttons
7035 :type '(repeat (cons (number :tag "Rate")
7036 (regexp :tag "Regexp"))))
7037
7038 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7039 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7040 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7041 address, `ask' if unsure and `invalid' if the string is invalid."
7042 (let ((case-fold-search nil)
7043 (list gnus-button-mid-or-mail-heuristic-alist)
7044 (result 0) rate regexp lpartlen elem)
7045 (setq lpartlen
7046 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7047 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7048 ;; Certain special cases...
7049 (when (string-match
7050 (concat
7051 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7052 "^[0-9]+\\.[0-9]+@compuserve\\|"
7053 "@public\\.gmane\\.org")
7054 mid-or-mail)
7055 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7056 (setq result 'mail))
7057 (when (string-match "@.*@\\| " mid-or-mail)
7058 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7059 (setq result 'invalid))
7060 ;; Nothing more to do, if result is not a number here...
7061 (when (numberp result)
7062 (while list
7063 (setq elem (car list)
7064 rate (car elem)
7065 regexp (cdr elem)
7066 list (cdr list))
7067 (when (string-match regexp mid-or-mail)
7068 (setq result (+ result rate))
7069 (gnus-message
7070 9 "`%s' matched `%s', rate `%s', result `%s'."
7071 mid-or-mail regexp rate result)))
7072 (when (<= lpartlen 7)
7073 (setq result (+ result 5.0))
7074 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7075 mid-or-mail result))
7076 (when (>= lpartlen 12)
7077 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7078 (cond
7079 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7080 ;; Long local part should contain realname if e-mail address,
7081 ;; too many digits: message-id.
7082 ;; $score -= 5.0 + 0.1 * $local_part_len;
7083 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7084 (setq result (+ result rate))
7085 (gnus-message
7086 9 "Many digits in `%s', rate `%s', result `%s'."
7087 mid-or-mail rate result))
7088 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7089 mid-or-mail)
7090 ;; Too few vowels [^aeiouy]{4,}.*\@
7091 (setq result (+ result -5.0))
7092 (gnus-message
7093 9 "Few vowels in `%s', rate `%s', result `%s'."
7094 mid-or-mail -5.0 result))
7095 (t
7096 (setq result (+ result 5.0))
7097 (gnus-message
7098 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7099 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7100 ;; Maybe we should make this a customizable alist: (condition . 'result)
7101 (cond
7102 ((symbolp result) result)
7103 ;; Now convert number into proper results:
7104 ((< result -10.0) 'mid)
7105 ((> result 10.0) 'mail)
7106 (t 'ask))))
7107
7108 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7109 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7110 (url-mid (concat "news" ":" mid-or-mail))
7111 (url-mailto (concat "mailto" ":" mid-or-mail)))
7112 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7113 (when (fboundp pref)
7114 (setq guessed
7115 ;; get rid of surrounding angles...
7116 (funcall pref
7117 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7118 (if (or (eq 'mid guessed) (eq 'mail guessed))
7119 (setq pref guessed)
7120 (setq pref 'ask)))
7121 (if (eq pref 'ask)
7122 (save-window-excursion
7123 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7124 (setq pref 'mail)
7125 (setq pref 'mid))))
7126 (cond ((eq pref 'mid)
7127 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7128 (gnus-button-handle-news url-mid))
7129 ((eq pref 'mail)
7130 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7131 (gnus-url-mailto url-mailto))
7132 (t (gnus-message 3 "Invalid string.")))))
7133
7134 (defun gnus-button-handle-custom (fun arg)
7135 "Call function FUN on argument ARG.
7136 Both FUN and ARG are supposed to be strings. ARG will be passed
7137 as a symbol to FUN."
7138 (funcall (intern fun)
7139 (if (string-match "^customize-apropos" fun)
7140 arg
7141 (intern arg))))
7142
7143 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7144
7145 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7146 ;; stuff?
7147
7148 (defun gnus-button-handle-describe-function (url)
7149 "Call `describe-function' when pushing the corresponding URL button."
7150 (describe-function
7151 (intern
7152 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7153
7154 (defun gnus-button-handle-describe-variable (url)
7155 "Call `describe-variable' when pushing the corresponding URL button."
7156 (describe-variable
7157 (intern
7158 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7159
7160 (defun gnus-button-handle-symbol (url)
7161 "Display help on variable or function.
7162 Calls `describe-variable' or `describe-function'."
7163 (let ((sym (intern url)))
7164 (cond
7165 ((fboundp sym) (describe-function sym))
7166 ((boundp sym) (describe-variable sym))
7167 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7168
7169 (defun gnus-button-handle-describe-key (url)
7170 "Call `describe-key' when pushing the corresponding URL button."
7171 (let* ((key-string
7172 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7173 (keys (ignore-errors (eval `(kbd ,key-string)))))
7174 (if keys
7175 (describe-key keys)
7176 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7177
7178 (defun gnus-button-handle-apropos (url)
7179 "Call `apropos' when pushing the corresponding URL button."
7180 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7181
7182 (defun gnus-button-handle-apropos-command (url)
7183 "Call `apropos' when pushing the corresponding URL button."
7184 (apropos-command
7185 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7186
7187 (defun gnus-button-handle-apropos-variable (url)
7188 "Call `apropos' when pushing the corresponding URL button."
7189 (funcall
7190 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7191 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7192
7193 (defun gnus-button-handle-apropos-documentation (url)
7194 "Call `apropos' when pushing the corresponding URL button."
7195 (funcall
7196 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7197 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7198
7199 (defun gnus-button-handle-library (url)
7200 "Call `locate-library' when pushing the corresponding URL button."
7201 (gnus-message 9 "url=`%s'" url)
7202 (let* ((lib (locate-library url))
7203 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7204 (if (not lib)
7205 (gnus-message 1 "Cannot locale library `%s'." url)
7206 (find-file-read-only file))))
7207
7208 (defun gnus-button-handle-ctan (url)
7209 "Call `browse-url' when pushing a CTAN URL button."
7210 (funcall
7211 gnus-button-ctan-handler
7212 (concat
7213 gnus-ctan-url
7214 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7215
7216 (defcustom gnus-button-tex-level 5
7217 "*Integer that says how many TeX-related buttons Gnus will show.
7218 The higher the number, the more buttons will appear and the more false
7219 positives are possible. Note that you can set this variable local to
7220 specific groups. Setting it higher in TeX groups is probably a good idea.
7221 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7222 how to set variables in specific groups."
7223 :version "22.1"
7224 :group 'gnus-article-buttons
7225 :link '(custom-manual "(gnus)Group Parameters")
7226 :type 'integer)
7227
7228 (defcustom gnus-button-man-level 5
7229 "*Integer that says how many man-related buttons Gnus will show.
7230 The higher the number, the more buttons will appear and the more false
7231 positives are possible. Note that you can set this variable local to
7232 specific groups. Setting it higher in Unix groups is probably a good idea.
7233 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7234 how to set variables in specific groups."
7235 :version "22.1"
7236 :group 'gnus-article-buttons
7237 :link '(custom-manual "(gnus)Group Parameters")
7238 :type 'integer)
7239
7240 (defcustom gnus-button-emacs-level 5
7241 "*Integer that says how many emacs-related buttons Gnus will show.
7242 The higher the number, the more buttons will appear and the more false
7243 positives are possible. Note that you can set this variable local to
7244 specific groups. Setting it higher in Emacs or Gnus related groups is
7245 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7246 `gnus-parameters' on how to set variables in specific groups."
7247 :version "22.1"
7248 :group 'gnus-article-buttons
7249 :link '(custom-manual "(gnus)Group Parameters")
7250 :type 'integer)
7251
7252 (defcustom gnus-button-message-level 5
7253 "*Integer that says how many buttons for news or mail messages will appear.
7254 The higher the number, the more buttons will appear and the more false
7255 positives are possible."
7256 ;; mail addresses, MIDs, URLs for news, ...
7257 :version "22.1"
7258 :group 'gnus-article-buttons
7259 :type 'integer)
7260
7261 (defcustom gnus-button-browse-level 5
7262 "*Integer that says how many buttons for browsing will appear.
7263 The higher the number, the more buttons will appear and the more false
7264 positives are possible."
7265 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7266 :version "22.1"
7267 :group 'gnus-article-buttons
7268 :type 'integer)
7269
7270 (defcustom gnus-button-alist
7271 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7272 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7273 ((concat "\\b\\(nntp\\|news\\):\\("
7274 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7275 0 t gnus-button-handle-news 2)
7276 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7277 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7278 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7279 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7280 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7281 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7282 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7283 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7284 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7285 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7286 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7287 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7288 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7289 ;; RFC 2368 (The mailto URL scheme)
7290 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7291 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7292 ("\\bmailto:\\([^ \n\t]+\\)"
7293 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7294 ;; CTAN
7295 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7296 gnus-button-ctan-directory-regexp
7297 "[^][>)!;:,'\n\t ]+\\)")
7298 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7299 ((concat "\\btex-archive/\\("
7300 gnus-button-ctan-directory-regexp
7301 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7302 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7303 ((concat
7304 "\\b\\("
7305 gnus-button-ctan-directory-regexp
7306 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7307 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7308 ;; This is info (home-grown style) <info://foo/bar+baz>
7309 ("\\binfo://\\([^'\">\n\t ]+\\)"
7310 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7311 ;; Info GNOME style <info:foo#bar_baz>
7312 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7313 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7314 ;; Info KDE style <info:(foo)bar baz>
7315 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7316 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7317 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7318 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7319 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7320 ;; Info links like `C-h i d m CC Mode RET'
7321 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7322 ;; This is custom
7323 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7324 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7325 ;; Emacs help commands
7326 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7327 ;; regexp doesn't match arguments containing ` '.
7328 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7329 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7330 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7331 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7332 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7333 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7334 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7335 ;; The following entries may lead to many false positives so don't enable
7336 ;; them by default (use a high button level).
7337 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7338 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7339 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7340 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7341 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7342 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7343 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7344 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7345 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7346 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7347 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7348 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7349 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7350 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7351 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7352 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7353 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7354 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7355 ;; Unlike the other regexps we really have to require quoting
7356 ;; here to determine where it ends.
7357 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7358 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7359 ("<URL: *\\([^\n<>]*\\)>"
7360 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7361 ;; RFC 2396 (2.4.3., delims) ...
7362 ("\"URL: *\\([^\n\"]*\\)\""
7363 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7364 ;; Raw URLs.
7365 (gnus-button-url-regexp
7366 0 (>= gnus-button-browse-level 0) browse-url 0)
7367 ;; man pages
7368 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7369 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7370 gnus-button-handle-man 1)
7371 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7372 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7373 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7374 gnus-button-handle-man 1)
7375 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7376 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7377 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7378 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7379 ;; Recognizing patches to .el files. This is somewhat obscure,
7380 ;; but considering the percentage of Gnus users who hack Emacs
7381 ;; Lisp files...
7382 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7383 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7384 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7385 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7386 ;; MID or mail: To avoid too many false positives we don't try to catch
7387 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7388 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7389 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7390 ;; so that non-ambiguous entries (see above) match first.
7391 (gnus-button-mid-or-mail-regexp
7392 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7393 "*Alist of regexps matching buttons in article bodies.
7394
7395 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7396 REGEXP: is the string (case insensitive) matching text around the button (can
7397 also be Lisp expression evaluating to a string),
7398 BUTTON: is the number of the regexp grouping actually matching the button,
7399 FORM: is a Lisp expression which must eval to true for the button to
7400 be added,
7401 CALLBACK: is the function to call when the user push this button, and each
7402 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7403
7404 CALLBACK can also be a variable, in that case the value of that
7405 variable it the real callback function."
7406 :group 'gnus-article-buttons
7407 :type '(repeat (list (choice regexp variable sexp)
7408 (integer :tag "Button")
7409 (sexp :tag "Form")
7410 (function :tag "Callback")
7411 (repeat :tag "Par"
7412 :inline t
7413 (integer :tag "Regexp group")))))
7414 (put 'gnus-button-alist 'risky-local-variable t)
7415
7416 (defcustom gnus-header-button-alist
7417 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7418 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7419 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7420 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7421 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7422 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7423 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7424 0 (>= gnus-button-browse-level 0) browse-url 0)
7425 ("^Subject:" gnus-button-url-regexp
7426 0 (>= gnus-button-browse-level 0) browse-url 0)
7427 ("^[^:]+:" gnus-button-url-regexp
7428 0 (>= gnus-button-browse-level 0) browse-url 0)
7429 ("^OpenPGP:.*url=" gnus-button-url-regexp
7430 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7431 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7432 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7433 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7434 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7435 "*Alist of headers and regexps to match buttons in article heads.
7436
7437 This alist is very similar to `gnus-button-alist', except that each
7438 alist has an additional HEADER element first in each entry:
7439
7440 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7441
7442 HEADER is a regexp to match a header. For a fuller explanation, see
7443 `gnus-button-alist'."
7444 :group 'gnus-article-buttons
7445 :group 'gnus-article-headers
7446 :type '(repeat (list (regexp :tag "Header")
7447 (choice regexp variable)
7448 (integer :tag "Button")
7449 (sexp :tag "Form")
7450 (function :tag "Callback")
7451 (repeat :tag "Par"
7452 :inline t
7453 (integer :tag "Regexp group")))))
7454 (put 'gnus-header-button-alist 'risky-local-variable t)
7455
7456 ;;; Commands:
7457
7458 (defun gnus-article-push-button (event)
7459 "Check text under the mouse pointer for a callback function.
7460 If the text under the mouse pointer has a `gnus-callback' property,
7461 call it with the value of the `gnus-data' text property."
7462 (interactive "e")
7463 (set-buffer (window-buffer (posn-window (event-start event))))
7464 (let* ((pos (posn-point (event-start event)))
7465 (data (get-text-property pos 'gnus-data))
7466 (fun (get-text-property pos 'gnus-callback)))
7467 (goto-char pos)
7468 (when fun
7469 (funcall fun data))))
7470
7471 (defun gnus-article-press-button ()
7472 "Check text at point for a callback function.
7473 If the text at point has a `gnus-callback' property,
7474 call it with the value of the `gnus-data' text property."
7475 (interactive)
7476 (let ((data (get-text-property (point) 'gnus-data))
7477 (fun (get-text-property (point) 'gnus-callback)))
7478 (when fun
7479 (funcall fun data))))
7480
7481 (defun gnus-article-highlight (&optional force)
7482 "Highlight current article.
7483 This function calls `gnus-article-highlight-headers',
7484 `gnus-article-highlight-citation',
7485 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7486 do the highlighting. See the documentation for those functions."
7487 (interactive (list 'force))
7488 (gnus-article-highlight-headers)
7489 (gnus-article-highlight-citation force)
7490 (gnus-article-highlight-signature)
7491 (gnus-article-add-buttons force)
7492 (gnus-article-add-buttons-to-head))
7493
7494 (defun gnus-article-highlight-some (&optional force)
7495 "Highlight current article.
7496 This function calls `gnus-article-highlight-headers',
7497 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7498 do the highlighting. See the documentation for those functions."
7499 (interactive (list 'force))
7500 (gnus-article-highlight-headers)
7501 (gnus-article-highlight-signature)
7502 (gnus-article-add-buttons))
7503
7504 (defun gnus-article-highlight-headers ()
7505 "Highlight article headers as specified by `gnus-header-face-alist'."
7506 (interactive)
7507 (gnus-with-article-headers
7508 (let (regexp header-face field-face from hpoints fpoints)
7509 (dolist (entry gnus-header-face-alist)
7510 (goto-char (point-min))
7511 (setq regexp (concat "^\\("
7512 (if (string-equal "" (nth 0 entry))
7513 "[^\t ]"
7514 (nth 0 entry))
7515 "\\)")
7516 header-face (nth 1 entry)
7517 field-face (nth 2 entry))
7518 (while (and (re-search-forward regexp nil t)
7519 (not (eobp)))
7520 (beginning-of-line)
7521 (setq from (point))
7522 (unless (search-forward ":" nil t)
7523 (forward-char 1))
7524 (when (and header-face
7525 (not (memq (point) hpoints)))
7526 (push (point) hpoints)
7527 (gnus-put-text-property from (point) 'face header-face))
7528 (when (and field-face
7529 (not (memq (setq from (point)) fpoints)))
7530 (push from fpoints)
7531 (if (re-search-forward "^[^ \t]" nil t)
7532 (forward-char -2)
7533 (goto-char (point-max)))
7534 (gnus-put-text-property from (point) 'face field-face)))))))
7535
7536 (defun gnus-article-highlight-signature ()
7537 "Highlight the signature in an article.
7538 It does this by highlighting everything after
7539 `gnus-signature-separator' using the face `gnus-signature'."
7540 (interactive)
7541 (gnus-with-article-buffer
7542 (let ((inhibit-point-motion-hooks t))
7543 (save-restriction
7544 (when (and gnus-signature-face
7545 (gnus-article-narrow-to-signature))
7546 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7547 'face gnus-signature-face)
7548 (widen)
7549 (gnus-article-search-signature)
7550 (let ((start (match-beginning 0))
7551 (end (set-marker (make-marker) (1+ (match-end 0)))))
7552 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7553 end)))))))
7554
7555 (defun gnus-button-in-region-p (b e prop)
7556 "Say whether PROP exists in the region."
7557 (text-property-not-all b e prop nil))
7558
7559 (defun gnus-article-add-buttons (&optional force)
7560 "Find external references in the article and make buttons of them.
7561 \"External references\" are things like Message-IDs and URLs, as
7562 specified by `gnus-button-alist'."
7563 (interactive (list 'force))
7564 (gnus-with-article-buffer
7565 (let ((inhibit-point-motion-hooks t)
7566 (case-fold-search t)
7567 (alist gnus-button-alist)
7568 beg entry regexp)
7569 ;; Remove all old markers.
7570 (let (marker entry new-list)
7571 (while (setq marker (pop gnus-button-marker-list))
7572 (if (or (< marker (point-min)) (>= marker (point-max)))
7573 (push marker new-list)
7574 (goto-char marker)
7575 (when (setq entry (gnus-button-entry))
7576 (put-text-property (match-beginning (nth 1 entry))
7577 (match-end (nth 1 entry))
7578 'gnus-callback nil))
7579 (set-marker marker nil)))
7580 (setq gnus-button-marker-list new-list))
7581 ;; We skip the headers.
7582 (article-goto-body)
7583 (setq beg (point))
7584 (while (setq entry (pop alist))
7585 (setq regexp (eval (car entry)))
7586 (goto-char beg)
7587 (while (re-search-forward regexp nil t)
7588 (let ((start (match-beginning (nth 1 entry)))
7589 (end (match-end (nth 1 entry)))
7590 (from (match-beginning 0)))
7591 (when (and (or (eq t (nth 2 entry))
7592 (eval (nth 2 entry)))
7593 (not (gnus-button-in-region-p
7594 start end 'gnus-callback)))
7595 ;; That optional form returned non-nil, so we add the
7596 ;; button.
7597 (setq from (set-marker (make-marker) from))
7598 (push from gnus-button-marker-list)
7599 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7600 (gnus-article-extend-url-button from start end))
7601 (gnus-article-add-button start end
7602 'gnus-button-push from)))))))))
7603
7604 (defun gnus-article-extend-url-button (beg start end)
7605 "Extend url button if url is folded into two or more lines.
7606 Return non-nil if button is extended. BEG is a marker that points to
7607 the beginning position of a text containing url. START and END are
7608 the endpoints of a url button before it is extended. The concatenated
7609 url is put as the `gnus-button-url' overlay property on the button."
7610 (let ((opoint (point))
7611 (points (list start end))
7612 url delim regexp)
7613 (prog1
7614 (when (and (progn
7615 (goto-char end)
7616 (not (looking-at "[\t ]*[\">]")))
7617 (progn
7618 (goto-char start)
7619 (string-match
7620 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7621 (buffer-substring (point-at-bol) start)))
7622 (progn
7623 (setq url (list (buffer-substring start end))
7624 delim (if (match-beginning 1) ">" "\""))
7625 (beginning-of-line)
7626 (setq regexp (concat
7627 (when (and (looking-at
7628 message-cite-prefix-regexp)
7629 (< (match-end 0) start))
7630 (regexp-quote (match-string 0)))
7631 "\
7632 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7633 delim "\\)"))
7634 (while (progn
7635 (forward-line 1)
7636 (and (looking-at regexp)
7637 (prog1
7638 (match-beginning 1)
7639 (push (or (match-string 2)
7640 (match-string 1))
7641 url)
7642 (push (setq end (or (match-end 2)
7643 (match-end 1)))
7644 points)
7645 (push (or (match-beginning 2)
7646 (match-beginning 1))
7647 points)))))
7648 (match-beginning 2)))
7649 (let (gnus-article-mouse-face widget-mouse-face)
7650 (while points
7651 (gnus-article-add-button (pop points) (pop points)
7652 'gnus-button-push beg)))
7653 (let ((overlay (gnus-make-overlay start end)))
7654 (gnus-overlay-put overlay 'evaporate t)
7655 (gnus-overlay-put overlay 'gnus-button-url
7656 (list (mapconcat 'identity (nreverse url) "")))
7657 (when gnus-article-mouse-face
7658 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7659 t)
7660 (goto-char opoint))))
7661
7662 ;; Add buttons to the head of an article.
7663 (defun gnus-article-add-buttons-to-head ()
7664 "Add buttons to the head of the article."
7665 (interactive)
7666 (gnus-with-article-headers
7667 (let (beg end)
7668 (dolist (entry gnus-header-button-alist)
7669 ;; Each alist entry.
7670 (goto-char (point-min))
7671 (while (re-search-forward (car entry) nil t)
7672 ;; Each header matching the entry.
7673 (setq beg (match-beginning 0))
7674 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7675 (match-beginning 0))
7676 (point-max)))
7677 (goto-char beg)
7678 (while (re-search-forward (eval (nth 1 entry)) end t)
7679 ;; Each match within a header.
7680 (let* ((entry (cdr entry))
7681 (start (match-beginning (nth 1 entry)))
7682 (end (match-end (nth 1 entry)))
7683 (form (nth 2 entry)))
7684 (goto-char (match-end 0))
7685 (when (eval form)
7686 (gnus-article-add-button
7687 start end (nth 3 entry)
7688 (buffer-substring (match-beginning (nth 4 entry))
7689 (match-end (nth 4 entry)))))))
7690 (goto-char end))))))
7691
7692 ;;; External functions:
7693
7694 (defun gnus-article-add-button (from to fun &optional data)
7695 "Create a button between FROM and TO with callback FUN and data DATA."
7696 (when gnus-article-button-face
7697 (gnus-overlay-put (gnus-make-overlay from to nil t)
7698 'face gnus-article-button-face))
7699 (gnus-add-text-properties
7700 from to
7701 (nconc (and gnus-article-mouse-face
7702 (list gnus-mouse-face-prop gnus-article-mouse-face))
7703 (list 'gnus-callback fun)
7704 (and data (list 'gnus-data data))))
7705 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7706 :button-keymap gnus-widget-button-keymap))
7707
7708 ;;; Internal functions:
7709
7710 (defun gnus-article-set-globals ()
7711 (with-current-buffer gnus-summary-buffer
7712 (gnus-set-global-variables)))
7713
7714 (defun gnus-signature-toggle (end)
7715 (gnus-with-article-buffer
7716 (let ((inhibit-point-motion-hooks t))
7717 (if (text-property-any end (point-max) 'article-type 'signature)
7718 (progn
7719 (gnus-delete-wash-type 'signature)
7720 (gnus-remove-text-properties-when
7721 'article-type 'signature end (point-max)
7722 (cons 'article-type (cons 'signature
7723 gnus-hidden-properties))))
7724 (gnus-add-wash-type 'signature)
7725 (gnus-add-text-properties-when
7726 'article-type nil end (point-max)
7727 (cons 'article-type (cons 'signature
7728 gnus-hidden-properties)))))
7729 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7730 (gnus-set-mode-line 'article))))
7731
7732 (defun gnus-button-entry ()
7733 ;; Return the first entry in `gnus-button-alist' matching this place.
7734 (let ((alist gnus-button-alist)
7735 (entry nil))
7736 (while alist
7737 (setq entry (pop alist))
7738 (if (looking-at (eval (car entry)))
7739 (setq alist nil)
7740 (setq entry nil)))
7741 entry))
7742
7743 (defun gnus-button-push (marker)
7744 ;; Push button starting at MARKER.
7745 (save-excursion
7746 (goto-char marker)
7747 (let* ((entry (gnus-button-entry))
7748 (inhibit-point-motion-hooks t)
7749 (fun (nth 3 entry))
7750 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7751 (get-char-property marker 'gnus-button-url))
7752 (mapcar (lambda (group)
7753 (let ((string (match-string group)))
7754 (set-text-properties
7755 0 (length string) nil string)
7756 string))
7757 (nthcdr 4 entry)))))
7758 (cond
7759 ((fboundp fun)
7760 (apply fun args))
7761 ((and (boundp fun)
7762 (fboundp (symbol-value fun)))
7763 (apply (symbol-value fun) args))
7764 (t
7765 (gnus-message 1 "You must define `%S' to use this button"
7766 (cons fun args)))))))
7767
7768 (defun gnus-parse-news-url (url)
7769 (let (scheme server port group message-id articles)
7770 (with-temp-buffer
7771 (insert url)
7772 (goto-char (point-min))
7773 (when (looking-at "\\([A-Za-z]+\\):")
7774 (setq scheme (match-string 1))
7775 (goto-char (match-end 0)))
7776 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7777 (setq server (match-string 1))
7778 (setq port (if (stringp (match-string 3))
7779 (string-to-number (match-string 3))
7780 (match-string 3)))
7781 (goto-char (match-end 0)))
7782
7783 (cond
7784 ((looking-at "\\(.*@.*\\)")
7785 (setq message-id (match-string 1)))
7786 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7787 (setq group (match-string 1)
7788 articles (split-string (match-string 2) "-")))
7789 ((looking-at "\\([^/]+\\)/?")
7790 (setq group (match-string 1)))
7791 (t
7792 (error "Unknown news URL syntax"))))
7793 (list scheme server port group message-id articles)))
7794
7795 (defun gnus-button-handle-news (url)
7796 "Fetch a news URL."
7797 (destructuring-bind (scheme server port group message-id articles)
7798 (gnus-parse-news-url url)
7799 (cond
7800 (message-id
7801 (with-current-buffer gnus-summary-buffer
7802 (if server
7803 (let ((gnus-refer-article-method
7804 (nconc (list (list 'nntp server))
7805 gnus-refer-article-method))
7806 (nntp-port-number (or port "nntp")))
7807 (gnus-message 7 "Fetching %s with %s"
7808 message-id gnus-refer-article-method)
7809 (gnus-summary-refer-article message-id))
7810 (gnus-summary-refer-article message-id))))
7811 (group
7812 (gnus-button-fetch-group url)))))
7813
7814 (defun gnus-button-patch (library line)
7815 "Visit an Emacs Lisp library LIBRARY on line LINE."
7816 (interactive)
7817 (let ((file (locate-library (file-name-nondirectory library))))
7818 (unless file
7819 (error "Couldn't find library %s" library))
7820 (find-file file)
7821 (goto-line (string-to-number line))))
7822
7823 (defun gnus-button-handle-man (url)
7824 "Fetch a man page."
7825 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7826 (when (eq gnus-button-man-handler 'woman)
7827 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7828 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7829 (funcall gnus-button-man-handler url))
7830
7831 (defun gnus-button-handle-info-url (url)
7832 "Fetch an info URL."
7833 (setq url (mm-subst-char-in-string ?+ ?\ url))
7834 (cond
7835 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7836 (gnus-info-find-node
7837 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7838 "Gnus")
7839 ")" (gnus-url-unhex-string (match-string 2 url)))))
7840 ((string-match "([^)\"]+)[^\"]+" url)
7841 (setq url
7842 (gnus-replace-in-string
7843 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7844 (gnus-info-find-node url))
7845 (t (error "Can't parse %s" url))))
7846
7847 (defun gnus-button-handle-info-url-gnome (url)
7848 "Fetch GNOME style info URL."
7849 (setq url (mm-subst-char-in-string ?_ ?\ url))
7850 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7851 (gnus-info-find-node
7852 (concat "("
7853 (gnus-url-unhex-string
7854 (match-string 1 url))
7855 ")"
7856 (or (gnus-url-unhex-string
7857 (match-string 2 url))
7858 "Top")))
7859 (error "Can't parse %s" url)))
7860
7861 (defun gnus-button-handle-info-url-kde (url)
7862 "Fetch KDE style info URL."
7863 (gnus-info-find-node (gnus-url-unhex-string url)))
7864
7865 ;; (info) will autoload info.el
7866 (declare-function Info-menu "info" (menu-item &optional fork))
7867
7868 (defun gnus-button-handle-info-keystrokes (url)
7869 "Call `info' when pushing the corresponding URL button."
7870 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7871 (info)
7872 (Info-directory)
7873 (Info-menu url))
7874
7875 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
7876 (declare-function pgg-display-output-buffer "pgg" (start end status))
7877
7878 (defun gnus-button-openpgp (url)
7879 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7880 (with-temp-buffer
7881 (mm-url-insert-file-contents-external url)
7882 (pgg-snarf-keys-region (point-min) (point-max))
7883 (pgg-display-output-buffer nil nil nil)))
7884
7885 (defun gnus-button-message-id (message-id)
7886 "Fetch MESSAGE-ID."
7887 (with-current-buffer gnus-summary-buffer
7888 (gnus-summary-refer-article message-id)))
7889
7890 (defun gnus-button-fetch-group (address &rest ignore)
7891 "Fetch GROUP specified by ADDRESS."
7892 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7893 address)
7894 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7895 ;; for nntp:// and news://
7896 (setq address (match-string 3 address)))
7897 (if (not (string-match "[:/]" address))
7898 ;; This is just a simple group url.
7899 (gnus-group-read-ephemeral-group address gnus-select-method)
7900 (if (not
7901 (string-match
7902 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7903 address))
7904 (error "Can't parse %s" address)
7905 (gnus-group-read-ephemeral-group
7906 (match-string 4 address)
7907 `(nntp ,(match-string 1 address)
7908 (nntp-address ,(match-string 1 address))
7909 (nntp-port-number ,(if (match-end 3)
7910 (match-string 3 address)
7911 "nntp")))
7912 nil nil nil
7913 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7914
7915 (defun gnus-url-parse-query-string (query &optional downcase)
7916 (let (retval pairs cur key val)
7917 (setq pairs (split-string query "&"))
7918 (while pairs
7919 (setq cur (car pairs)
7920 pairs (cdr pairs))
7921 (if (not (string-match "=" cur))
7922 nil ; Grace
7923 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7924 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7925 (if downcase
7926 (setq key (downcase key)))
7927 (setq cur (assoc key retval))
7928 (if cur
7929 (setcdr cur (cons val (cdr cur)))
7930 (setq retval (cons (list key val) retval)))))
7931 retval))
7932
7933 (defun gnus-url-mailto (url)
7934 ;; Send mail to someone
7935 (when (string-match "mailto:/*\\(.*\\)" url)
7936 (setq url (substring url (match-beginning 1) nil)))
7937 (let (to args subject func)
7938 (setq args (gnus-url-parse-query-string
7939 (if (string-match "^\\?" url)
7940 (substring url 1)
7941 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7942 (concat "to=" (match-string 1 url) "&"
7943 (match-string 2 url))
7944 (concat "to=" url)))
7945 t)
7946 subject (cdr-safe (assoc "subject" args)))
7947 (gnus-msg-mail)
7948 (while args
7949 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7950 (if (fboundp func)
7951 (funcall func)
7952 (message-position-on-field (caar args)))
7953 (insert (gnus-replace-in-string
7954 (mapconcat 'identity (reverse (cdar args)) ", ")
7955 "\r\n" "\n" t))
7956 (setq args (cdr args)))
7957 (if subject
7958 (message-goto-body)
7959 (message-goto-subject))))
7960
7961 (defun gnus-button-embedded-url (address)
7962 "Activate ADDRESS with `browse-url'."
7963 (browse-url (gnus-strip-whitespace address)))
7964
7965 ;;; Next/prev buttons in the article buffer.
7966
7967 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7968 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7969
7970 (defvar gnus-prev-page-map
7971 (let ((map (make-sparse-keymap)))
7972 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7973 (define-key map "\r" 'gnus-button-prev-page)
7974 map))
7975
7976 (defvar gnus-next-page-map
7977 (let ((map (make-sparse-keymap)))
7978 (unless (>= emacs-major-version 21)
7979 ;; XEmacs doesn't care.
7980 (set-keymap-parent map gnus-article-mode-map))
7981 (define-key map gnus-mouse-2 'gnus-button-next-page)
7982 (define-key map "\r" 'gnus-button-next-page)
7983 map))
7984
7985 (defun gnus-insert-prev-page-button ()
7986 (let ((b (point)) e
7987 (inhibit-read-only t))
7988 (gnus-eval-format
7989 gnus-prev-page-line-format nil
7990 `(keymap ,gnus-prev-page-map
7991 gnus-prev t
7992 gnus-callback gnus-article-button-prev-page
7993 article-type annotation))
7994 (setq e (if (bolp)
7995 ;; Exclude a newline.
7996 (1- (point))
7997 (point)))
7998 (when gnus-article-button-face
7999 (gnus-overlay-put (gnus-make-overlay b e nil t)
8000 'face gnus-article-button-face))
8001 (widget-convert-button
8002 'link b e
8003 :action 'gnus-button-prev-page
8004 :button-keymap gnus-prev-page-map)))
8005
8006 (defun gnus-button-next-page (&optional args more-args)
8007 "Go to the next page."
8008 (interactive)
8009 (let ((win (selected-window)))
8010 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8011 (gnus-article-next-page)
8012 (select-window win)))
8013
8014 (defun gnus-button-prev-page (&optional args more-args)
8015 "Go to the prev page."
8016 (interactive)
8017 (let ((win (selected-window)))
8018 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8019 (gnus-article-prev-page)
8020 (select-window win)))
8021
8022 (defun gnus-insert-next-page-button ()
8023 (let ((b (point)) e
8024 (inhibit-read-only t))
8025 (gnus-eval-format gnus-next-page-line-format nil
8026 `(keymap ,gnus-next-page-map
8027 gnus-next t
8028 gnus-callback gnus-article-button-next-page
8029 article-type annotation))
8030 (setq e (if (bolp)
8031 ;; Exclude a newline.
8032 (1- (point))
8033 (point)))
8034 (when gnus-article-button-face
8035 (gnus-overlay-put (gnus-make-overlay b e nil t)
8036 'face gnus-article-button-face))
8037 (widget-convert-button
8038 'link b e
8039 :action 'gnus-button-next-page
8040 :button-keymap gnus-next-page-map)))
8041
8042 (defun gnus-article-button-next-page (arg)
8043 "Go to the next page."
8044 (interactive "P")
8045 (let ((win (selected-window)))
8046 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8047 (gnus-article-next-page)
8048 (select-window win)))
8049
8050 (defun gnus-article-button-prev-page (arg)
8051 "Go to the prev page."
8052 (interactive "P")
8053 (let ((win (selected-window)))
8054 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8055 (gnus-article-prev-page)
8056 (select-window win)))
8057
8058 (defvar gnus-decode-header-methods
8059 '(mail-decode-encoded-word-region)
8060 "List of methods used to decode headers.
8061
8062 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8063 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8064 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8065 whose names match REGEXP.
8066
8067 For example:
8068 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8069 mail-decode-encoded-word-region
8070 (\"chinese\" . rfc1843-decode-region))
8071 ")
8072
8073 (defvar gnus-decode-header-methods-cache nil)
8074
8075 (defun gnus-multi-decode-header (start end)
8076 "Apply the functions from `gnus-encoded-word-methods' that match."
8077 (unless (and gnus-decode-header-methods-cache
8078 (eq gnus-newsgroup-name
8079 (car gnus-decode-header-methods-cache)))
8080 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8081 (dolist (x gnus-decode-header-methods)
8082 (if (symbolp x)
8083 (nconc gnus-decode-header-methods-cache (list x))
8084 (if (and gnus-newsgroup-name
8085 (string-match (car x) gnus-newsgroup-name))
8086 (nconc gnus-decode-header-methods-cache
8087 (list (cdr x)))))))
8088 (let ((xlist gnus-decode-header-methods-cache))
8089 (pop xlist)
8090 (save-restriction
8091 (narrow-to-region start end)
8092 (while xlist
8093 (funcall (pop xlist) (point-min) (point-max))))))
8094
8095 ;;;
8096 ;;; Treatment top-level handling.
8097 ;;;
8098
8099 (defun gnus-treat-article (condition &optional part-number total-parts type)
8100 (let ((length (- (point-max) (point-min)))
8101 (alist gnus-treatment-function-alist)
8102 (article-goto-body-goes-to-point-min-p t)
8103 (treated-type
8104 (or (not type)
8105 (catch 'found
8106 (let ((list gnus-article-treat-types))
8107 (while list
8108 (when (string-match (pop list) type)
8109 (throw 'found t)))))))
8110 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8111 val elem)
8112 (gnus-run-hooks 'gnus-part-display-hook)
8113 (dolist (elem alist)
8114 (setq val
8115 (save-excursion
8116 (when (gnus-buffer-live-p gnus-summary-buffer)
8117 (set-buffer gnus-summary-buffer))
8118 (symbol-value (car elem))))
8119 (when (and (or (consp val)
8120 treated-type)
8121 (gnus-treat-predicate val)
8122 (or (not (get (car elem) 'highlight))
8123 highlightp))
8124 (save-restriction
8125 (funcall (cadr elem)))))))
8126
8127 ;; Dynamic variables.
8128 (defvar part-number)
8129 (defvar total-parts)
8130 (defvar type)
8131 (defvar condition)
8132 (defvar length)
8133
8134 (defun gnus-treat-predicate (val)
8135 (cond
8136 ((null val)
8137 nil)
8138 (condition
8139 (eq condition val))
8140 ((and (listp val)
8141 (stringp (car val)))
8142 (apply 'gnus-or (mapcar `(lambda (s)
8143 (string-match s ,(or gnus-newsgroup-name "")))
8144 val)))
8145 ((listp val)
8146 (let ((pred (pop val)))
8147 (cond
8148 ((eq pred 'or)
8149 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8150 ((eq pred 'and)
8151 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8152 ((eq pred 'not)
8153 (not (gnus-treat-predicate (car val))))
8154 ((eq pred 'typep)
8155 (equal (car val) type))
8156 (t
8157 (error "%S is not a valid predicate" pred)))))
8158 ((eq val t)
8159 t)
8160 ((eq val 'head)
8161 nil)
8162 ((eq val 'first)
8163 (eq part-number 1))
8164 ((eq val 'last)
8165 (eq part-number total-parts))
8166 ((numberp val)
8167 (< length val))
8168 (t
8169 (error "%S is not a valid value" val))))
8170
8171 (defun gnus-article-encrypt-body (protocol &optional n)
8172 "Encrypt the article body."
8173 (interactive
8174 (list
8175 (or gnus-article-encrypt-protocol
8176 (completing-read "Encrypt protocol: "
8177 gnus-article-encrypt-protocol-alist
8178 nil t))
8179 current-prefix-arg))
8180 ;; User might hit `K E' instead of `K e', so prompt once.
8181 (when (and gnus-article-encrypt-protocol
8182 gnus-novice-user)
8183 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8184 (error "Encrypt aborted.")))
8185 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8186 (unless func
8187 (error "Can't find the encrypt protocol %s" protocol))
8188 (if (member gnus-newsgroup-name '("nndraft:delayed"
8189 "nndraft:drafts"
8190 "nndraft:queue"))
8191 (error "Can't encrypt the article in group %s"
8192 gnus-newsgroup-name))
8193 (gnus-summary-iterate n
8194 (with-current-buffer gnus-summary-buffer
8195 (let ((mail-parse-charset gnus-newsgroup-charset)
8196 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8197 (summary-buffer gnus-summary-buffer)
8198 references point)
8199 (gnus-set-global-variables)
8200 (when (gnus-group-read-only-p)
8201 (error "The current newsgroup does not support article encrypt"))
8202 (gnus-summary-show-article t)
8203 (setq references
8204 (or (mail-header-references gnus-current-headers) ""))
8205 (set-buffer gnus-article-buffer)
8206 (let* ((inhibit-read-only t)
8207 (headers
8208 (mapcar (lambda (field)
8209 (and (save-restriction
8210 (message-narrow-to-head)
8211 (goto-char (point-min))
8212 (search-forward field nil t))
8213 (prog2
8214 (message-narrow-to-field)
8215 (buffer-string)
8216 (delete-region (point-min) (point-max))
8217 (widen))))
8218 '("Content-Type:" "Content-Transfer-Encoding:"
8219 "Content-Disposition:"))))
8220 (message-narrow-to-head)
8221 (message-remove-header "MIME-Version")
8222 (goto-char (point-max))
8223 (setq point (point))
8224 (insert (apply 'concat headers))
8225 (widen)
8226 (narrow-to-region point (point-max))
8227 (let ((message-options message-options))
8228 (message-options-set 'message-sender user-mail-address)
8229 (message-options-set 'message-recipients user-mail-address)
8230 (message-options-set 'message-sign-encrypt 'not)
8231 (funcall func))
8232 (goto-char (point-min))
8233 (insert "MIME-Version: 1.0\n")
8234 (widen)
8235 (gnus-summary-edit-article-done
8236 references nil summary-buffer t))
8237 (when gnus-keep-backlog
8238 (gnus-backlog-remove-article
8239 (car gnus-article-current) (cdr gnus-article-current)))
8240 (when (get-buffer gnus-original-article-buffer)
8241 (with-current-buffer gnus-original-article-buffer
8242 (setq gnus-original-article nil)))
8243 (when gnus-use-cache
8244 (gnus-cache-update-article
8245 (car gnus-article-current) (cdr gnus-article-current))))))))
8246
8247 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8248 "The following specs can be used:
8249 %t The security MIME type
8250 %i Additional info
8251 %d Details
8252 %D Details if button is pressed")
8253
8254 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8255 "The following specs can be used:
8256 %t The security MIME type
8257 %i Additional info
8258 %d Details
8259 %D Details if button is pressed")
8260
8261 (defvar gnus-mime-security-button-line-format-alist
8262 '((?t gnus-tmp-type ?s)
8263 (?i gnus-tmp-info ?s)
8264 (?d gnus-tmp-details ?s)
8265 (?D gnus-tmp-pressed-details ?s)))
8266
8267 (defvar gnus-mime-security-button-commands
8268 '((gnus-article-press-button "\r" "Show Detail")
8269 (undefined "v")
8270 (undefined "t")
8271 (undefined "C")
8272 (gnus-mime-security-save-part "o" "Save...")
8273 (undefined "\C-o")
8274 (undefined "r")
8275 (undefined "d")
8276 (undefined "c")
8277 (undefined "i")
8278 (undefined "E")
8279 (undefined "e")
8280 (undefined "p")
8281 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8282 (undefined ".")))
8283
8284 (defvar gnus-mime-security-button-map
8285 (let ((map (make-sparse-keymap)))
8286 (define-key map gnus-mouse-2 'gnus-article-push-button)
8287 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8288 (dolist (c gnus-mime-security-button-commands)
8289 (define-key map (cadr c) (car c)))
8290 map))
8291
8292 (easy-menu-define
8293 gnus-mime-security-button-menu gnus-mime-security-button-map
8294 "Security button menu."
8295 `("Security Part"
8296 ,@(delq nil
8297 (mapcar (lambda (c)
8298 (unless (eq (car c) 'undefined)
8299 (vector (caddr c) (car c) :active t)))
8300 gnus-mime-security-button-commands))))
8301
8302 (defun gnus-mime-security-button-menu (event prefix)
8303 "Construct a context-sensitive menu of security commands."
8304 (interactive "e\nP")
8305 (save-window-excursion
8306 (let ((pos (event-start event)))
8307 (select-window (posn-window pos))
8308 (goto-char (posn-point pos))
8309 (gnus-article-check-buffer)
8310 (popup-menu gnus-mime-security-button-menu nil prefix))))
8311
8312 (defvar gnus-mime-security-details-buffer nil)
8313
8314 (defvar gnus-mime-security-button-pressed nil)
8315
8316 (defvar gnus-mime-security-show-details-inline t
8317 "If non-nil, show details in the article buffer.")
8318
8319 (defun gnus-mime-security-verify-or-decrypt (handle)
8320 (mm-remove-parts (cdr handle))
8321 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8322 point (inhibit-read-only t))
8323 (if region
8324 (goto-char (car region)))
8325 (setq point (point))
8326 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8327 (let* ((mm-verify-option 'known)
8328 (mm-decrypt-option 'known)
8329 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8330 (unless (eq nparts (cdr handle))
8331 (mm-destroy-parts (cdr handle))
8332 (setcdr handle nparts))))
8333 (gnus-mime-display-security handle)
8334 (when region
8335 (delete-region (point) (cdr region))
8336 (set-marker (car region) nil)
8337 (set-marker (cdr region) nil))
8338 (goto-char point)))
8339
8340 (defun gnus-mime-security-show-details (handle)
8341 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8342 (if (not details)
8343 (gnus-message 5 "No details.")
8344 (if gnus-mime-security-show-details-inline
8345 (let ((gnus-mime-security-button-pressed
8346 (not (get-text-property (point) 'gnus-mime-details)))
8347 (gnus-mime-security-button-line-format
8348 (get-text-property (point) 'gnus-line-format))
8349 (inhibit-read-only t))
8350 (forward-char -1)
8351 (while (eq (get-text-property (point) 'gnus-line-format)
8352 gnus-mime-security-button-line-format)
8353 (forward-char -1))
8354 (forward-char)
8355 (save-restriction
8356 (narrow-to-region (point) (point))
8357 (gnus-insert-mime-security-button handle))
8358 (delete-region (point)
8359 (or (text-property-not-all
8360 (point) (point-max)
8361 'gnus-line-format
8362 gnus-mime-security-button-line-format)
8363 (point-max))))
8364 ;; Not inlined.
8365 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8366 (with-current-buffer gnus-mime-security-details-buffer
8367 (erase-buffer)
8368 t)
8369 (setq gnus-mime-security-details-buffer
8370 (gnus-get-buffer-create "*MIME Security Details*")))
8371 (with-current-buffer gnus-mime-security-details-buffer
8372 (insert details)
8373 (goto-char (point-min)))
8374 (pop-to-buffer gnus-mime-security-details-buffer)))))
8375
8376 (defun gnus-mime-security-press-button (handle)
8377 (save-excursion
8378 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8379 (gnus-mime-security-show-details handle)
8380 (gnus-mime-security-verify-or-decrypt handle))))
8381
8382 (defun gnus-insert-mime-security-button (handle &optional displayed)
8383 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8384 (gnus-tmp-type
8385 (concat
8386 (or (nth 2 (assoc protocol mm-verify-function-alist))
8387 (nth 2 (assoc protocol mm-decrypt-function-alist))
8388 "Unknown")
8389 (if (equal (car handle) "multipart/signed")
8390 " Signed" " Encrypted")
8391 " Part"))
8392 (gnus-tmp-info
8393 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8394 "Undecided"))
8395 (gnus-tmp-details
8396 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8397 gnus-tmp-pressed-details
8398 b e)
8399 (setq gnus-tmp-details
8400 (if gnus-tmp-details
8401 (concat "\n" gnus-tmp-details)
8402 ""))
8403 (setq gnus-tmp-pressed-details
8404 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8405 (unless (bolp)
8406 (insert "\n"))
8407 (setq b (point))
8408 (gnus-eval-format
8409 gnus-mime-security-button-line-format
8410 gnus-mime-security-button-line-format-alist
8411 `(keymap ,gnus-mime-security-button-map
8412 gnus-callback gnus-mime-security-press-button
8413 gnus-line-format ,gnus-mime-security-button-line-format
8414 gnus-mime-details ,gnus-mime-security-button-pressed
8415 article-type annotation
8416 gnus-data ,handle))
8417 (setq e (if (bolp)
8418 ;; Exclude a newline.
8419 (1- (point))
8420 (point)))
8421 (when gnus-article-button-face
8422 (gnus-overlay-put (gnus-make-overlay b e nil t)
8423 'face gnus-article-button-face))
8424 (widget-convert-button
8425 'link b e
8426 :mime-handle handle
8427 :action 'gnus-widget-press-button
8428 :button-keymap gnus-mime-security-button-map
8429 :help-echo
8430 (lambda (widget/window &optional overlay pos)
8431 ;; Needed to properly clear the message due to a bug in
8432 ;; wid-edit (XEmacs only).
8433 (when (boundp 'help-echo-owns-message)
8434 (setq help-echo-owns-message t))
8435 (format
8436 "%S: show detail; %S: more options"
8437 (aref gnus-mouse-2 0)
8438 (aref gnus-down-mouse-3 0))))))
8439
8440 (defun gnus-mime-display-security (handle)
8441 (save-restriction
8442 (narrow-to-region (point) (point))
8443 (unless (gnus-unbuttonized-mime-type-p (car handle))
8444 (gnus-insert-mime-security-button handle))
8445 (gnus-mime-display-part (cadr handle))
8446 (unless (bolp)
8447 (insert "\n"))
8448 (unless (gnus-unbuttonized-mime-type-p (car handle))
8449 (let ((gnus-mime-security-button-line-format
8450 gnus-mime-security-button-end-line-format))
8451 (gnus-insert-mime-security-button handle)))
8452 (mm-set-handle-multipart-parameter
8453 handle 'gnus-region
8454 (cons (set-marker (make-marker) (point-min))
8455 (set-marker (make-marker) (point-max))))
8456 (goto-char (point-max))))
8457
8458 (defun gnus-mime-security-run-function (function)
8459 "Run FUNCTION with the security part under point."
8460 (gnus-article-check-buffer)
8461 (let ((data (get-text-property (point) 'gnus-data))
8462 buffer handle)
8463 (when (and (stringp (car-safe data))
8464 (setq buffer (mm-handle-multipart-original-buffer data))
8465 (setq handle (cadr data)))
8466 (if (bufferp (mm-handle-buffer handle))
8467 (progn
8468 (setq handle (cons buffer (copy-sequence (cdr handle))))
8469 (mm-handle-set-undisplayer handle nil))
8470 (setq handle (mm-make-handle
8471 buffer
8472 (mm-handle-multipart-ctl-parameter handle 'protocol)
8473 nil nil nil nil nil nil)))
8474 (funcall function handle))))
8475
8476 (defun gnus-mime-security-save-part ()
8477 "Save the security part under point."
8478 (interactive)
8479 (gnus-mime-security-run-function 'mm-save-part))
8480
8481 (defun gnus-mime-security-pipe-part ()
8482 "Pipe the security part under point to a process."
8483 (interactive)
8484 (gnus-mime-security-run-function 'mm-pipe-part))
8485
8486 (gnus-ems-redefine)
8487
8488 (provide 'gnus-art)
8489
8490 (run-hooks 'gnus-art-load-hook)
8491
8492 ;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8493 ;;; gnus-art.el ends here