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