]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-art.el
merge trunk
[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, 2009, 2010 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 of the License, or
14 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 ;; For Emacs < 22.2.
29 (eval-and-compile
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
31 (eval-when-compile
32 (require 'cl))
33 (defvar tool-bar-map)
34 (defvar w3m-minor-mode-map)
35
36 (require 'gnus)
37 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
38 (eval-and-compile
39 (let ((recursive-load-depth-limit 100))
40 (require 'gnus-sum)))
41 (require 'gnus-spec)
42 (require 'gnus-int)
43 (require 'gnus-win)
44 (require 'mm-bodies)
45 (require 'mail-parse)
46 (require 'mm-decode)
47 (require 'mm-view)
48 (require 'wid-edit)
49 (require 'mm-uu)
50 (require 'message)
51
52 (autoload 'gnus-msg-mail "gnus-msg" nil t)
53 (autoload 'gnus-button-mailto "gnus-msg")
54 (autoload 'gnus-button-reply "gnus-msg" nil t)
55 (autoload 'parse-time-string "parse-time" nil nil)
56 (autoload 'ansi-color-apply-on-region "ansi-color")
57 (autoload 'mm-url-insert-file-contents-external "mm-url")
58 (autoload 'mm-extern-cache-contents "mm-extern")
59
60 (defgroup gnus-article nil
61 "Article display."
62 :link '(custom-manual "(gnus)Article Buffer")
63 :group 'gnus)
64
65 (defgroup gnus-article-treat nil
66 "Treating article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
69
70 (defgroup gnus-article-hiding nil
71 "Hiding article parts."
72 :link '(custom-manual "(gnus)Article Hiding")
73 :group 'gnus-article)
74
75 (defgroup gnus-article-highlight nil
76 "Article highlighting."
77 :link '(custom-manual "(gnus)Article Highlighting")
78 :group 'gnus-article
79 :group 'gnus-visual)
80
81 (defgroup gnus-article-signature nil
82 "Article signatures."
83 :link '(custom-manual "(gnus)Article Signature")
84 :group 'gnus-article)
85
86 (defgroup gnus-article-headers nil
87 "Article headers."
88 :link '(custom-manual "(gnus)Hiding Headers")
89 :group 'gnus-article)
90
91 (defgroup gnus-article-washing nil
92 "Special commands on articles."
93 :link '(custom-manual "(gnus)Article Washing")
94 :group 'gnus-article)
95
96 (defgroup gnus-article-emphasis nil
97 "Fontisizing articles."
98 :link '(custom-manual "(gnus)Article Fontisizing")
99 :group 'gnus-article)
100
101 (defgroup gnus-article-saving nil
102 "Saving articles."
103 :link '(custom-manual "(gnus)Saving Articles")
104 :group 'gnus-article)
105
106 (defgroup gnus-article-mime nil
107 "Worshiping the MIME wonder."
108 :link '(custom-manual "(gnus)Using MIME")
109 :group 'gnus-article)
110
111 (defgroup gnus-article-buttons nil
112 "Pushable buttons in the article buffer."
113 :link '(custom-manual "(gnus)Article Buttons")
114 :group 'gnus-article)
115
116 (defgroup gnus-article-various nil
117 "Other article options."
118 :link '(custom-manual "(gnus)Misc Article")
119 :group 'gnus-article)
120
121 (defcustom gnus-ignored-headers
122 (mapcar
123 (lambda (header)
124 (concat "^" header ":"))
125 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
126 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
127 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
128 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
129 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
130 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
131 "X-Attribution" "X-Originating-IP" "Delivered-To"
132 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
133 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
134 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
135 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
136 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
137 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
138 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
139 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
140 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
141 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
142 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
143 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
144 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
145 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
146 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
147 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
148 "List-[A-Za-z]+" "X-Listprocessor-Version"
149 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
150 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
151 "X-Received" "Content-length" "X-precedence"
152 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
153 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
154 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
155 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
156 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
157 "X-Content-length" "X-Posting-Agent" "Original-Received"
158 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
159 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
160 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
161 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
162 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
163 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
164 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
165 "Envelope-Sender" "Envelope-Recipients"))
166 "*All headers that start with this regexp will be hidden.
167 This variable can also be a list of regexps of headers to be ignored.
168 If `gnus-visible-headers' is non-nil, this variable will be ignored."
169 :type '(choice :custom-show nil
170 regexp
171 (repeat regexp))
172 :group 'gnus-article-hiding)
173
174 (defcustom gnus-visible-headers
175 "^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:"
176 "*All headers that do not match this regexp will be hidden.
177 This variable can also be a list of regexp of headers to remain visible.
178 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
179 :type '(choice
180 (repeat :value-to-internal (lambda (widget value)
181 (custom-split-regexp-maybe value))
182 :match (lambda (widget value)
183 (or (stringp value)
184 (widget-editable-list-match widget value)))
185 regexp)
186 (const :tag "Use gnus-ignored-headers" nil)
187 regexp)
188 :group 'gnus-article-hiding)
189
190 (defcustom gnus-sorted-header-list
191 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
192 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
193 "*This variable is a list of regular expressions.
194 If it is non-nil, headers that match the regular expressions will
195 be placed first in the article buffer in the sequence specified by
196 this list."
197 :type '(repeat regexp)
198 :group 'gnus-article-hiding)
199
200 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
201 "Headers that are only to be displayed if they have interesting data.
202 Possible values in this list are:
203
204 'empty Headers with no content.
205 'newsgroups Newsgroup identical to Gnus group.
206 'to-address To identical to To-address.
207 'to-list To identical to To-list.
208 'cc-list CC identical to To-list.
209 'followup-to Followup-to identical to Newsgroups.
210 'reply-to Reply-to identical to From.
211 'date Date less than four days old.
212 'long-to To and/or Cc longer than 1024 characters.
213 'many-to Multiple To and/or Cc."
214 :type '(set (const :tag "Headers with no content." empty)
215 (const :tag "Newsgroups identical to Gnus group." newsgroups)
216 (const :tag "To identical to To-address." to-address)
217 (const :tag "To identical to To-list." to-list)
218 (const :tag "CC identical to To-list." cc-list)
219 (const :tag "Followup-to identical to Newsgroups." followup-to)
220 (const :tag "Reply-to identical to From." reply-to)
221 (const :tag "Date less than four days old." date)
222 (const :tag "To and/or Cc longer than 1024 characters." long-to)
223 (const :tag "Multiple To and/or Cc headers." many-to))
224 :group 'gnus-article-hiding)
225
226 (defcustom gnus-article-skip-boring nil
227 "Skip over text that is not worth reading.
228 By default, if you set this t, then Gnus will display citations and
229 signatures, but will never scroll down to show you a page consisting
230 only of boring text. Boring text is controlled by
231 `gnus-article-boring-faces'."
232 :version "22.1"
233 :type 'boolean
234 :group 'gnus-article-hiding)
235
236 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
237 "Regexp matching signature separator.
238 This can also be a list of regexps. In that case, it will be checked
239 from head to tail looking for a separator. Searches will be done from
240 the end of the buffer."
241 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
242 (regexp)
243 (repeat :tag "List of regexp" regexp))
244 :group 'gnus-article-signature)
245
246 (defcustom gnus-signature-limit nil
247 "Provide a limit to what is considered a signature.
248 If it is a number, no signature may not be longer (in characters) than
249 that number. If it is a floating point number, no signature may be
250 longer (in lines) than that number. If it is a function, the function
251 will be called without any parameters, and if it returns nil, there is
252 no signature in the buffer. If it is a string, it will be used as a
253 regexp. If it matches, the text in question is not a signature.
254
255 This can also be a list of the above values."
256 :type '(choice (const nil)
257 (integer :value 200)
258 (number :value 4.0)
259 function
260 (regexp :value ".*"))
261 :group 'gnus-article-signature)
262
263 (defcustom gnus-hidden-properties '(invisible t intangible t)
264 "Property list to use for hiding text."
265 :type 'sexp
266 :group 'gnus-article-hiding)
267
268 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
269 ;; frames in a session.
270 (defcustom gnus-article-x-face-command
271 (if (featurep 'xemacs)
272 (if (or (gnus-image-type-available-p 'xface)
273 (gnus-image-type-available-p 'pbm))
274 'gnus-display-x-face-in-from
275 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
276 (if (gnus-image-type-available-p 'pbm)
277 'gnus-display-x-face-in-from
278 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
279 display -"))
280 "*String or function to be executed to display an X-Face header.
281 If it is a string, the command will be executed in a sub-shell
282 asynchronously. The compressed face will be piped to this command."
283 :type `(choice string
284 (function-item gnus-display-x-face-in-from)
285 function)
286 :version "21.1"
287 :group 'gnus-picon
288 :group 'gnus-article-washing)
289
290 (defcustom gnus-article-x-face-too-ugly nil
291 "Regexp matching posters whose face shouldn't be shown automatically."
292 :type '(choice regexp (const nil))
293 :group 'gnus-article-washing)
294
295 (defcustom gnus-article-banner-alist nil
296 "Banner alist for stripping.
297 For example,
298 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
299 :version "21.1"
300 :type '(repeat (cons symbol regexp))
301 :group 'gnus-article-washing)
302
303 (gnus-define-group-parameter
304 banner
305 :variable-document
306 "Alist of regexps (to match group names) and banner."
307 :variable-group gnus-article-washing
308 :parameter-type
309 '(choice :tag "Banner"
310 :value nil
311 (const :tag "Remove signature" signature)
312 (symbol :tag "Item in `gnus-article-banner-alist'" none)
313 regexp
314 (const :tag "None" nil))
315 :parameter-document
316 "If non-nil, specify how to remove `banners' from articles.
317
318 Symbol `signature' means to remove signatures delimited by
319 `gnus-signature-separator'. Any other symbol is used to look up a
320 regular expression to match the banner in `gnus-article-banner-alist'.
321 A string is used as a regular expression to match the banner
322 directly.")
323
324 (defcustom gnus-article-address-banner-alist nil
325 "Alist of mail addresses and banners.
326 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
327 to match a mail address in the From: header, BANNER is one of a symbol
328 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
329 If ADDRESS matches author's mail address, it will remove things like
330 advertisements. For example:
331
332 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 "
334 :type '(repeat
335 (cons
336 (regexp :tag "Address")
337 (choice :tag "Banner" :value nil
338 (const :tag "Remove signature" signature)
339 (symbol :tag "Item in `gnus-article-banner-alist'" none)
340 regexp
341 (const :tag "None" nil))))
342 :version "22.1"
343 :group 'gnus-article-washing)
344
345 (defmacro gnus-emphasis-custom-with-format (&rest body)
346 `(let ((format "\
347 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
348 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
349 ,@body))
350
351 (defun gnus-emphasis-custom-value-to-external (value)
352 (gnus-emphasis-custom-with-format
353 (if (consp (car value))
354 (list (format format (car (car value)) (cdr (car value)))
355 2
356 (if (nth 1 value) 2 3)
357 (nth 2 value))
358 value)))
359
360 (defun gnus-emphasis-custom-value-to-internal (value)
361 (gnus-emphasis-custom-with-format
362 (let ((regexp (concat "\\`"
363 (format (regexp-quote format)
364 "\\([^()]+\\)" "\\([^()]+\\)")
365 "\\'"))
366 pattern)
367 (if (string-match regexp (setq pattern (car value)))
368 (list (cons (match-string 1 pattern) (match-string 2 pattern))
369 (= (nth 2 value) 2)
370 (nth 3 value))
371 value))))
372
373 (defcustom gnus-emphasis-alist
374 (let ((types
375 '(("\\*" "\\*" bold nil 2)
376 ("_" "_" underline)
377 ("/" "/" italic)
378 ("_/" "/_" underline-italic)
379 ("_\\*" "\\*_" underline-bold)
380 ("\\*/" "/\\*" bold-italic)
381 ("_\\*/" "/\\*_" underline-bold-italic))))
382 (nconc
383 (gnus-emphasis-custom-with-format
384 (mapcar (lambda (spec)
385 (list (format format (car spec) (cadr spec))
386 (or (nth 3 spec) 2)
387 (or (nth 4 spec) 3)
388 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
389 types))
390 '(;; I've never seen anyone use this strikethru convention whereas I've
391 ;; several times seen it triggered by normal text. --Stef
392 ;; Miles suggests that this form is sometimes used but for italics,
393 ;; so maybe we should map it to `italic'.
394 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
395 ;; 2 3 gnus-emphasis-strikethru)
396 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
397 2 3 gnus-emphasis-underline))))
398 "*Alist that says how to fontify certain phrases.
399 Each item looks like this:
400
401 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402
403 The first element is a regular expression to be matched. The second
404 is a number that says what regular expression grouping used to find
405 the entire emphasized word. The third is a number that says what
406 regexp grouping should be displayed and highlighted. The fourth
407 is the face used for highlighting."
408 :type
409 '(repeat
410 (menu-choice
411 :format "%[Customizing Style%]\n%v"
412 :indent 2
413 (group :tag "Default"
414 :value ("" 0 0 default)
415 :value-create
416 (lambda (widget)
417 (let ((value (widget-get
418 (cadr (widget-get (widget-get widget :parent)
419 :args))
420 :value)))
421 (if (not (eq (nth 2 value) 'default))
422 (widget-put
423 widget
424 :value
425 (gnus-emphasis-custom-value-to-external value))))
426 (widget-group-value-create widget))
427 regexp
428 (integer :format "Match group: %v")
429 (integer :format "Emphasize group: %v")
430 face)
431 (group :tag "Simple"
432 :value (("_" . "_") nil default)
433 (cons :format "%v"
434 (regexp :format "Start regexp: %v")
435 (regexp :format "End regexp: %v"))
436 (boolean :format "Show start and end patterns: %[%v%]\n"
437 :on " On " :off " Off ")
438 face)))
439 :get (lambda (symbol)
440 (mapcar 'gnus-emphasis-custom-value-to-internal
441 (default-value symbol)))
442 :set (lambda (symbol value)
443 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
444 value)))
445 :group 'gnus-article-emphasis)
446
447 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
448 "A regexp to describe whitespace which should not be emphasized.
449 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
450 The former avoids underlining of leading and trailing whitespace,
451 and the latter avoids underlining any whitespace at all."
452 :version "21.1"
453 :group 'gnus-article-emphasis
454 :type 'regexp)
455
456 (defface gnus-emphasis-bold '((t (:bold t)))
457 "Face used for displaying strong emphasized text (*word*)."
458 :group 'gnus-article-emphasis)
459
460 (defface gnus-emphasis-italic '((t (:italic t)))
461 "Face used for displaying italic emphasized text (/word/)."
462 :group 'gnus-article-emphasis)
463
464 (defface gnus-emphasis-underline '((t (:underline t)))
465 "Face used for displaying underlined emphasized text (_word_)."
466 :group 'gnus-article-emphasis)
467
468 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
469 "Face used for displaying underlined bold emphasized text (_*word*_)."
470 :group 'gnus-article-emphasis)
471
472 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
473 "Face used for displaying underlined italic emphasized text (_/word/_)."
474 :group 'gnus-article-emphasis)
475
476 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
477 "Face used for displaying bold italic emphasized text (/*word*/)."
478 :group 'gnus-article-emphasis)
479
480 (defface gnus-emphasis-underline-bold-italic
481 '((t (:bold t :italic t :underline t)))
482 "Face used for displaying underlined bold italic emphasized text.
483 Example: (_/*word*/_)."
484 :group 'gnus-article-emphasis)
485
486 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
487 '((t (:strikethru t)))
488 '((t (:strike-through t))))
489 "Face used for displaying strike-through text (-word-)."
490 :group 'gnus-article-emphasis)
491
492 (defface gnus-emphasis-highlight-words
493 '((t (:background "black" :foreground "yellow")))
494 "Face used for displaying highlighted words."
495 :group 'gnus-article-emphasis)
496
497 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
498 "Format for display of Date headers in article bodies.
499 See `format-time-string' for the possible values.
500
501 The variable can also be function, which should return a complete Date
502 header. The function is called with one argument, the time, which can
503 be fed to `format-time-string'."
504 :type '(choice string function)
505 :link '(custom-manual "(gnus)Article Date")
506 :group 'gnus-article-washing)
507
508 (defcustom gnus-save-all-headers t
509 "*If non-nil, don't remove any headers before saving.
510 This will be overridden by the `:headers' property that the symbol of
511 the saver function, which is specified by `gnus-default-article-saver',
512 might have."
513 :group 'gnus-article-saving
514 :type 'boolean)
515
516 (defcustom gnus-prompt-before-saving 'always
517 "*This variable says how much prompting is to be done when saving articles.
518 If it is nil, no prompting will be done, and the articles will be
519 saved to the default files. If this variable is `always', each and
520 every article that is saved will be preceded by a prompt, even when
521 saving large batches of articles. If this variable is neither nil not
522 `always', there the user will be prompted once for a file name for
523 each invocation of the saving commands."
524 :group 'gnus-article-saving
525 :type '(choice (item always)
526 (item :tag "never" nil)
527 (sexp :tag "once" :format "%t\n" :value t)))
528
529 (defcustom gnus-saved-headers gnus-visible-headers
530 "Headers to keep if `gnus-save-all-headers' is nil.
531 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
532 If that variable is nil, however, all headers that match this regexp
533 will be kept while the rest will be deleted before saving. This and
534 `gnus-save-all-headers' will be overridden by the `:headers' property
535 that the symbol of the saver function, which is specified by
536 `gnus-default-article-saver', might have."
537 :group 'gnus-article-saving
538 :type 'regexp)
539
540 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
541 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
542 "A function to save articles in your favourite format.
543 The function will be called by way of the `gnus-summary-save-article'
544 command, and friends such as `gnus-summary-save-article-rmail'.
545
546 Gnus provides the following functions:
547
548 * gnus-summary-save-in-rmail (Rmail format)
549 * gnus-summary-save-in-mail (Unix mail format)
550 * gnus-summary-save-in-folder (MH folder)
551 * gnus-summary-save-in-file (article format)
552 * gnus-summary-save-body-in-file (article body)
553 * gnus-summary-save-in-vm (use VM's folder format)
554 * gnus-summary-write-to-file (article format -- overwrite)
555 * gnus-summary-write-body-to-file (article body -- overwrite)
556 * gnus-summary-save-in-pipe (article format)
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', `gnus-summary-write-body-to-file', and
564 `gnus-summary-save-in-pipe'.
565
566 * :function
567 The value specifies an alternative function which appends, not
568 overwrites, articles to a file. This implies that when saving many
569 articles at a time, `gnus-prompt-before-saving' is bound to t and all
570 articles are saved in a single file. This is meaningful only with
571 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
572
573 * :headers
574 The value specifies the symbol of a variable of which the value
575 specifies headers to be saved. If it is omitted,
576 `gnus-save-all-headers' and `gnus-saved-headers' control what
577 headers should be saved."
578 :group 'gnus-article-saving
579 :type '(radio (function-item gnus-summary-save-in-rmail)
580 (function-item gnus-summary-save-in-mail)
581 (function-item gnus-summary-save-in-folder)
582 (function-item gnus-summary-save-in-file)
583 (function-item gnus-summary-save-body-in-file)
584 (function-item gnus-summary-save-in-vm)
585 (function-item gnus-summary-write-to-file)
586 (function-item gnus-summary-write-body-to-file)
587 (function-item gnus-summary-save-in-pipe)
588 (function)))
589
590 (defcustom gnus-article-save-coding-system
591 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
592 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
593 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
594 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
595 "Coding system used to save decoded articles to a file.
596
597 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
598 which can safely encode any characters in text. This is used by the
599 commands including:
600
601 * gnus-summary-save-article-file
602 * gnus-summary-save-article-body-file
603 * gnus-summary-write-article-file
604 * gnus-summary-write-article-body-file
605
606 and the functions to which you may set `gnus-default-article-saver':
607
608 * gnus-summary-save-in-file
609 * gnus-summary-save-body-in-file
610 * gnus-summary-write-to-file
611 * gnus-summary-write-body-to-file
612
613 Those commands and functions save just text displayed in the article
614 buffer to a file if the value of this variable is non-nil. Note that
615 buttonized MIME parts will be lost in a saved file in that case.
616 Otherwise, raw articles will be saved."
617 :group 'gnus-article-saving
618 :type `(choice
619 :format "%{%t%}:\n %[Value Menu%] %v"
620 (const :tag "Save raw articles" nil)
621 ,@(delq nil
622 (mapcar
623 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
624 '((const :tag "UTF-8" utf-8)
625 (const :tag "iso-2022-7bit" iso-2022-7bit)
626 (const :tag "Emacs internal" emacs-mule)
627 (const :tag "escape-quoted" escape-quoted))))
628 (symbol :tag "Coding system")))
629
630 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
631 "A function generating a file name to save articles in Rmail format.
632 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
633 :group 'gnus-article-saving
634 :type 'function)
635
636 (defcustom gnus-mail-save-name 'gnus-plain-save-name
637 "A function generating a file name to save articles in Unix mail format.
638 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
639 :group 'gnus-article-saving
640 :type 'function)
641
642 (defcustom gnus-folder-save-name 'gnus-folder-save-name
643 "A function generating a file name to save articles in MH folder.
644 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
645 :group 'gnus-article-saving
646 :type 'function)
647
648 (defcustom gnus-file-save-name 'gnus-numeric-save-name
649 "A function generating a file name to save articles in article format.
650 The function is called with NEWSGROUP, HEADERS, and optional
651 LAST-FILE."
652 :group 'gnus-article-saving
653 :type 'function)
654
655 (defcustom gnus-split-methods
656 '((gnus-article-archive-name)
657 (gnus-article-nndoc-name))
658 "*Variable used to suggest where articles are to be saved.
659 For instance, if you would like to save articles related to Gnus in
660 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
661 you could set this variable to something like:
662
663 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
664 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
665
666 This variable is an alist where the key is the match and the
667 value is a list of possible files to save in if the match is
668 non-nil.
669
670 If the match is a string, it is used as a regexp match on the
671 article. If the match is a symbol, that symbol will be funcalled
672 from the buffer of the article to be saved with the newsgroup as the
673 parameter. If it is a list, it will be evaled in the same buffer.
674
675 If this form or function returns a string, this string will be used as a
676 possible file name; and if it returns a non-nil list, that list will be
677 used as possible file names."
678 :group 'gnus-article-saving
679 :type '(repeat (choice (list :value (fun) function)
680 (cons :value ("" "") regexp (repeat string))
681 (sexp :value nil))))
682
683 (defcustom gnus-page-delimiter "^\^L"
684 "*Regexp describing what to use as article page delimiters.
685 The default value is \"^\^L\", which is a form linefeed at the
686 beginning of a line."
687 :type 'regexp
688 :group 'gnus-article-various)
689
690 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
691 "*The format specification for the article mode line.
692 See `gnus-summary-mode-line-format' for a closer description.
693
694 The following additional specs are available:
695
696 %w The article washing status.
697 %m The number of MIME parts in the article."
698 :type 'string
699 :group 'gnus-article-various)
700
701 (defcustom gnus-article-mode-hook nil
702 "*A hook for Gnus article mode."
703 :type 'hook
704 :group 'gnus-article-various)
705
706 (when (featurep 'xemacs)
707 ;; Extracted from gnus-xmas-define in order to preserve user settings
708 (when (fboundp 'turn-off-scroll-in-place)
709 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
710 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
711 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
712
713 (defcustom gnus-article-menu-hook nil
714 "*Hook run after the creation of the article mode menu."
715 :type 'hook
716 :group 'gnus-article-various)
717
718 (defcustom gnus-article-prepare-hook nil
719 "*A hook called after an article has been prepared in the article buffer."
720 :type 'hook
721 :group 'gnus-article-various)
722
723 (defcustom gnus-copy-article-ignored-headers nil
724 "List of headers to be removed when copying an article.
725 Each element is a regular expression."
726 :version "23.1" ;; No Gnus
727 :type '(repeat regexp)
728 :group 'gnus-article-various)
729
730 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
731 "Gnus 5.10 (Emacs-22.1)")
732
733 (defface gnus-button
734 '((t (:weight bold)))
735 "Face used for highlighting a button in the article buffer."
736 :group 'gnus-article-buttons)
737
738 (defcustom gnus-article-button-face 'gnus-button
739 "Face used for highlighting buttons in the article buffer.
740
741 An article button is a piece of text that you can activate by pressing
742 `RET' or `mouse-2' above it."
743 :type 'face
744 :group 'gnus-article-buttons)
745
746 (defcustom gnus-article-mouse-face 'highlight
747 "Face used for mouse highlighting in the article buffer.
748
749 Article buttons will be displayed in this face when the cursor is
750 above them."
751 :type 'face
752 :group 'gnus-article-buttons)
753
754 (defcustom gnus-signature-face 'gnus-signature
755 "Face used for highlighting a signature in the article buffer.
756 Obsolete; use the face `gnus-signature' for customizations instead."
757 :type 'face
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
760
761 (defface gnus-signature
762 '((t
763 (:italic t)))
764 "Face used for highlighting a signature in the article buffer."
765 :group 'gnus-article-highlight
766 :group 'gnus-article-signature)
767 ;; backward-compatibility alias
768 (put 'gnus-signature-face 'face-alias 'gnus-signature)
769 (put 'gnus-signature-face 'obsolete-face "22.1")
770
771 (defface gnus-header-from
772 '((((class color)
773 (background dark))
774 (:foreground "PaleGreen1"))
775 (((class color)
776 (background light))
777 (:foreground "red3"))
778 (t
779 (:italic t)))
780 "Face used for displaying from headers."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
783 ;; backward-compatibility alias
784 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
785 (put 'gnus-header-from-face 'obsolete-face "22.1")
786
787 (defface gnus-header-subject
788 '((((class color)
789 (background dark))
790 (:foreground "SeaGreen1"))
791 (((class color)
792 (background light))
793 (:foreground "red4"))
794 (t
795 (:bold t :italic t)))
796 "Face used for displaying subject headers."
797 :group 'gnus-article-headers
798 :group 'gnus-article-highlight)
799 ;; backward-compatibility alias
800 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
801 (put 'gnus-header-subject-face 'obsolete-face "22.1")
802
803 (defface gnus-header-newsgroups
804 '((((class color)
805 (background dark))
806 (:foreground "yellow" :italic t))
807 (((class color)
808 (background light))
809 (:foreground "MidnightBlue" :italic t))
810 (t
811 (:italic t)))
812 "Face used for displaying newsgroups headers.
813 In the default setup this face is only used for crossposted
814 articles."
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
817 ;; backward-compatibility alias
818 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
819 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
820
821 (defface gnus-header-name
822 '((((class color)
823 (background dark))
824 (:foreground "SpringGreen2"))
825 (((class color)
826 (background light))
827 (:foreground "maroon"))
828 (t
829 (:bold t)))
830 "Face used for displaying header names."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight)
833 ;; backward-compatibility alias
834 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
835 (put 'gnus-header-name-face 'obsolete-face "22.1")
836
837 (defface gnus-header-content
838 '((((class color)
839 (background dark))
840 (:foreground "SpringGreen1" :italic t))
841 (((class color)
842 (background light))
843 (:foreground "indianred4" :italic t))
844 (t
845 (:italic t))) "Face used for displaying header content."
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight)
848 ;; backward-compatibility alias
849 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
850 (put 'gnus-header-content-face 'obsolete-face "22.1")
851
852 (defcustom gnus-header-face-alist
853 '(("From" nil gnus-header-from)
854 ("Subject" nil gnus-header-subject)
855 ("Newsgroups:.*," nil gnus-header-newsgroups)
856 ("" gnus-header-name gnus-header-content))
857 "*Controls highlighting of article headers.
858
859 An alist of the form (HEADER NAME CONTENT).
860
861 HEADER is a regular expression which should match the name of a
862 header and NAME and CONTENT are either face names or nil.
863
864 The name of each header field will be displayed using the face
865 specified by the first element in the list where HEADER matches
866 the header name and NAME is non-nil. Similarly, the content will
867 be displayed by the first non-nil matching CONTENT face."
868 :group 'gnus-article-headers
869 :group 'gnus-article-highlight
870 :type '(repeat (list (regexp :tag "Header")
871 (choice :tag "Name"
872 (item :tag "skip" nil)
873 (face :value default))
874 (choice :tag "Content"
875 (item :tag "skip" nil)
876 (face :value default)))))
877
878 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
879 '((xface . (:face gnus-x-face)))
880 '((pbm . (:face gnus-x-face))
881 (png . nil)))
882 "Alist of image types and properties applied to Face and X-Face images.
883 Here are examples:
884
885 ;; Specify the altitude of Face images in the From header.
886 \(setq gnus-face-properties-alist
887 '((pbm . (:face gnus-x-face :ascent 80))
888 (png . (:ascent 80))))
889
890 ;; Show Face images as pressed buttons.
891 \(setq gnus-face-properties-alist
892 '((pbm . (:face gnus-x-face :relief -2))
893 (png . (:relief -2))))
894
895 See the manual for the valid properties for various image types.
896 Currently, `pbm' is used for X-Face images and `png' is used for Face
897 images in Emacs. Only the `:face' property is effective on the `xface'
898 image type in XEmacs if it is built with the libcompface library."
899 :version "23.1" ;; No Gnus
900 :group 'gnus-article-headers
901 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
902
903 (defcustom gnus-article-decode-hook
904 '(article-decode-charset article-decode-encoded-words
905 article-decode-group-name article-decode-idna-rhs)
906 "*Hook run to decode charsets in articles."
907 :group 'gnus-article-headers
908 :type 'hook)
909
910 (defcustom gnus-display-mime-function 'gnus-display-mime
911 "Function to display MIME articles."
912 :group 'gnus-article-mime
913 :type 'function)
914
915 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
916 "Function used to decode headers.")
917
918 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
919 "Function used to decode addresses.")
920
921 (defvar gnus-article-dumbquotes-map
922 '(("\200" "EUR")
923 ("\202" ",")
924 ("\203" "f")
925 ("\204" ",,")
926 ("\205" "...")
927 ("\213" "<")
928 ("\214" "OE")
929 ("\221" "`")
930 ("\222" "'")
931 ("\223" "``")
932 ("\224" "\"")
933 ("\225" "*")
934 ("\226" "-")
935 ("\227" "--")
936 ("\230" "~")
937 ("\231" "(TM)")
938 ("\233" ">")
939 ("\234" "oe")
940 ("\264" "'"))
941 "Table for MS-to-Latin1 translation.")
942
943 (defcustom gnus-ignored-mime-types nil
944 "List of MIME types that should be ignored by Gnus."
945 :version "21.1"
946 :group 'gnus-article-mime
947 :type '(repeat regexp))
948
949 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
950 "List of MIME types that should not be given buttons when rendered inline.
951 See also `gnus-buttonized-mime-types' which may override this variable.
952 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
953 :version "21.1"
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
956
957 (defcustom gnus-buttonized-mime-types nil
958 "List of MIME types that should be given buttons when rendered inline.
959 If set, this variable overrides `gnus-unbuttonized-mime-types'.
960 To see e.g. security buttons you could set this to
961 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
962 this list to display radio buttons that allow you to choose one of two
963 media types those mails include. See also `mm-discouraged-alternatives'.
964 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
965 :version "22.1"
966 :group 'gnus-article-mime
967 :type '(repeat regexp))
968
969 (defcustom gnus-inhibit-mime-unbuttonizing nil
970 "If non-nil, all MIME parts get buttons.
971 When nil (the default value), then some MIME parts do not get buttons,
972 as described by the variables `gnus-buttonized-mime-types' and
973 `gnus-unbuttonized-mime-types'."
974 :version "22.1"
975 :group 'gnus-article-mime
976 :type 'boolean)
977
978 (defcustom gnus-body-boundary-delimiter "_"
979 "String used to delimit header and body.
980 This variable is used by `gnus-article-treat-body-boundary' which can
981 be controlled by `gnus-treat-body-boundary'."
982 :version "22.1"
983 :group 'gnus-article-various
984 :type '(choice (item :tag "None" :value nil)
985 string))
986
987 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
988 "/usr/share/picons")
989 "Defines the location of the faces database.
990 For information on obtaining this database of pretty pictures, please
991 see http://www.cs.indiana.edu/picons/ftp/index.html"
992 :version "22.1"
993 :type '(repeat directory)
994 :link '(url-link :tag "download"
995 "http://www.cs.indiana.edu/picons/ftp/index.html")
996 :link '(custom-manual "(gnus)Picons")
997 :group 'gnus-picon)
998
999 (defun gnus-picons-installed-p ()
1000 "Say whether picons are installed on your machine."
1001 (let ((installed nil))
1002 (dolist (database gnus-picon-databases)
1003 (when (file-exists-p database)
1004 (setq installed t)))
1005 installed))
1006
1007 (defcustom gnus-article-mime-part-function nil
1008 "Function called with a MIME handle as the argument.
1009 This is meant for people who want to do something automatic based
1010 on parts -- for instance, adding Vcard info to a database."
1011 :group 'gnus-article-mime
1012 :type '(choice (const nil)
1013 function))
1014
1015 (defcustom gnus-mime-multipart-functions nil
1016 "An alist of MIME types to functions to display them."
1017 :version "21.1"
1018 :group 'gnus-article-mime
1019 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1020
1021 (defcustom gnus-article-date-lapsed-new-header nil
1022 "Whether the X-Sent and Date headers can coexist.
1023 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1024 either replace the old \"Date:\" header (if this variable is nil), or
1025 be added below it (otherwise)."
1026 :version "21.1"
1027 :group 'gnus-article-headers
1028 :type 'boolean)
1029
1030 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1031 "Function called with a MIME handle as the argument.
1032 This is meant for people who want to view first matched part.
1033 For `undisplayed-alternative' (default), the first undisplayed
1034 part or alternative part is used. For `undisplayed', the first
1035 undisplayed part is used. For a function, the first part which
1036 the function return t is used. For nil, the first part is
1037 used."
1038 :version "21.1"
1039 :group 'gnus-article-mime
1040 :type '(choice
1041 (item :tag "first" :value nil)
1042 (item :tag "undisplayed" :value undisplayed)
1043 (item :tag "undisplayed or alternative"
1044 :value undisplayed-alternative)
1045 (function)))
1046
1047 (defcustom gnus-mime-action-alist
1048 '(("save to file" . gnus-mime-save-part)
1049 ("save and strip" . gnus-mime-save-part-and-strip)
1050 ("replace with file" . gnus-mime-replace-part)
1051 ("delete part" . gnus-mime-delete-part)
1052 ("display as text" . gnus-mime-inline-part)
1053 ("view the part" . gnus-mime-view-part)
1054 ("pipe to command" . gnus-mime-pipe-part)
1055 ("toggle display" . gnus-article-press-button)
1056 ("toggle display" . gnus-article-view-part-as-charset)
1057 ("view as type" . gnus-mime-view-part-as-type)
1058 ("view internally" . gnus-mime-view-part-internally)
1059 ("view externally" . gnus-mime-view-part-externally))
1060 "An alist of actions that run on the MIME attachment."
1061 :group 'gnus-article-mime
1062 :type '(repeat (cons (string :tag "name")
1063 (function))))
1064
1065 (defcustom gnus-auto-select-part 1
1066 "Advance to next MIME part when deleting or stripping parts.
1067
1068 When 0, point will be placed on the same part as before. When
1069 positive (negative), move point forward (backwards) this many
1070 parts. When nil, redisplay article."
1071 :version "23.1" ;; No Gnus
1072 :group 'gnus-article-mime
1073 :type '(choice (const nil :tag "Redisplay article.")
1074 (const 1 :tag "Next part.")
1075 (const 0 :tag "Current part.")
1076 integer))
1077
1078 ;;;
1079 ;;; The treatment variables
1080 ;;;
1081
1082 (defvar gnus-part-display-hook nil
1083 "Hook called on parts that are to receive treatment.")
1084
1085 (defvar gnus-article-treat-custom
1086 '(choice (const :tag "Off" nil)
1087 (const :tag "On" t)
1088 (const :tag "Header" head)
1089 (const :tag "First" first)
1090 (const :tag "Last" last)
1091 (integer :tag "Less")
1092 (repeat :tag "Groups" regexp)
1093 (sexp :tag "Predicate")))
1094
1095 (defvar gnus-article-treat-head-custom
1096 '(choice (const :tag "Off" nil)
1097 (const :tag "Header" head)))
1098
1099 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1100 "text/x-patch")
1101 "Parts to treat.")
1102
1103 (defvar gnus-inhibit-treatment nil
1104 "Whether to inhibit treatment.")
1105
1106 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1107 "Highlight the signature.
1108 Valid values are nil, t, `head', `first', `last', an integer or a
1109 predicate. See Info node `(gnus)Customizing Articles'."
1110 :group 'gnus-article-treat
1111 :link '(custom-manual "(gnus)Customizing Articles")
1112 :type gnus-article-treat-custom)
1113 (put 'gnus-treat-highlight-signature 'highlight t)
1114
1115 (defcustom gnus-treat-buttonize 100000
1116 "Add buttons.
1117 Valid values are nil, t, `head', `first', `last', an integer or a
1118 predicate. See Info node `(gnus)Customizing Articles'."
1119 :group 'gnus-article-treat
1120 :link '(custom-manual "(gnus)Customizing Articles")
1121 :type gnus-article-treat-custom)
1122 (put 'gnus-treat-buttonize 'highlight t)
1123
1124 (defcustom gnus-treat-buttonize-head 'head
1125 "Add buttons to the head.
1126 Valid values are nil, t, `head', `first', `last', an integer or a
1127 predicate. See Info node `(gnus)Customizing Articles'."
1128 :group 'gnus-article-treat
1129 :link '(custom-manual "(gnus)Customizing Articles")
1130 :type gnus-article-treat-head-custom)
1131 (put 'gnus-treat-buttonize-head 'highlight t)
1132
1133 (defcustom gnus-treat-emphasize 50000
1134 "Emphasize text.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-emphasize 'highlight t)
1141
1142 (defcustom gnus-treat-strip-cr nil
1143 "Remove carriage returns.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :version "22.1"
1147 :group 'gnus-article-treat
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-custom)
1150
1151 (defcustom gnus-treat-unsplit-urls nil
1152 "Remove newlines from within URLs.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :version "22.1"
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-custom)
1159
1160 (defcustom gnus-treat-leading-whitespace nil
1161 "Remove leading whitespace in headers.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :version "22.1"
1165 :group 'gnus-article-treat
1166 :link '(custom-manual "(gnus)Customizing Articles")
1167 :type gnus-article-treat-custom)
1168
1169 (defcustom gnus-treat-hide-headers 'head
1170 "Hide 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-boring-headers nil
1178 "Hide boring headers.
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-head-custom)
1184
1185 (defcustom gnus-treat-hide-signature nil
1186 "Hide the signature.
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-fill-article nil
1194 "Fill the article.
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 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-hide-citation-maybe nil
1210 "Hide cited text.
1211 Valid values are nil, t, `head', `first', `last', an integer or a
1212 predicate. See Info node `(gnus)Customizing Articles'."
1213 :group 'gnus-article-treat
1214 :link '(custom-manual "(gnus)Customizing Articles")
1215 :type gnus-article-treat-custom)
1216
1217 (defcustom gnus-treat-strip-list-identifiers 'head
1218 "Strip list identifiers from `gnus-list-identifiers`.
1219 Valid values are nil, t, `head', `first', `last', an integer or a
1220 predicate. See Info node `(gnus)Customizing Articles'."
1221 :version "21.1"
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1225
1226 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1227 "Gnus 5.10 (Emacs 22.1)")
1228
1229 (defcustom gnus-treat-strip-pem nil
1230 "Strip PEM signatures.
1231 Valid values are nil, t, `head', `first', `last', an integer or a
1232 predicate. See Info node `(gnus)Customizing Articles'."
1233 :group 'gnus-article-treat
1234 :link '(custom-manual "(gnus)Customizing Articles")
1235 :type gnus-article-treat-custom)
1236
1237 (defcustom gnus-treat-strip-banner t
1238 "Strip banners from articles.
1239 The banner to be stripped is specified in the `banner' group parameter.
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-custom)
1245
1246 (defcustom gnus-treat-highlight-headers 'head
1247 "Highlight the headers.
1248 Valid values are nil, t, `head', `first', `last', an integer or a
1249 predicate. See Info node `(gnus)Customizing Articles'."
1250 :group 'gnus-article-treat
1251 :link '(custom-manual "(gnus)Customizing Articles")
1252 :type gnus-article-treat-head-custom)
1253 (put 'gnus-treat-highlight-headers 'highlight t)
1254
1255 (defcustom gnus-treat-highlight-citation t
1256 "Highlight cited text.
1257 Valid values are nil, t, `head', `first', `last', an integer or a
1258 predicate. See Info node `(gnus)Customizing Articles'."
1259 :group 'gnus-article-treat
1260 :link '(custom-manual "(gnus)Customizing Articles")
1261 :type gnus-article-treat-custom)
1262 (put 'gnus-treat-highlight-citation 'highlight t)
1263
1264 (defcustom gnus-treat-date-ut nil
1265 "Display the Date in UT (GMT).
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-local nil
1273 "Display the Date in the local timezone.
1274 Valid values are nil, t, `head', `first', `last', an integer or a
1275 predicate. See Info node `(gnus)Customizing Articles'."
1276 :group 'gnus-article-treat
1277 :link '(custom-manual "(gnus)Customizing Articles")
1278 :type gnus-article-treat-head-custom)
1279
1280 (defcustom gnus-treat-date-english nil
1281 "Display the Date in a format that can be read aloud in English.
1282 Valid values are nil, t, `head', `first', `last', an integer or a
1283 predicate. See Info node `(gnus)Customizing Articles'."
1284 :version "22.1"
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-lapsed nil
1290 "Display the Date header in a way that says how much time has elapsed.
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-original nil
1298 "Display the date in the original timezone.
1299 Valid values are nil, t, `head', `first', `last', an integer or a
1300 predicate. See Info node `(gnus)Customizing Articles'."
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-head-custom)
1304
1305 (defcustom gnus-treat-date-iso8601 nil
1306 "Display the date in the ISO8601 format.
1307 Valid values are nil, t, `head', `first', `last', an integer or a
1308 predicate. See Info node `(gnus)Customizing Articles'."
1309 :version "21.1"
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-head-custom)
1313
1314 (defcustom gnus-treat-date-user-defined nil
1315 "Display the date in a user-defined format.
1316 The format is defined by the `gnus-article-time-format' variable.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :group 'gnus-article-treat
1320 :link '(custom-manual "(gnus)Customizing Articles")
1321 :type gnus-article-treat-head-custom)
1322
1323 (defcustom gnus-treat-strip-headers-in-body t
1324 "Strip the X-No-Archive header line from the beginning of the body.
1325 Valid values are nil, t, `head', `first', `last', an integer or a
1326 predicate. See Info node `(gnus)Customizing Articles'."
1327 :version "21.1"
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1331
1332 (defcustom gnus-treat-strip-trailing-blank-lines nil
1333 "Strip trailing blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1336
1337 When set to t, it also strips trailing blanks in all MIME parts.
1338 Consider to use `last' instead."
1339 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :type gnus-article-treat-custom)
1342
1343 (defcustom gnus-treat-strip-leading-blank-lines nil
1344 "Strip leading blank lines.
1345 Valid values are nil, t, `head', `first', `last', an integer or a
1346 predicate. See Info node `(gnus)Customizing Articles'.
1347
1348 When set to t, it also strips trailing blanks in all MIME parts."
1349 :group 'gnus-article-treat
1350 :link '(custom-manual "(gnus)Customizing Articles")
1351 :type gnus-article-treat-custom)
1352
1353 (defcustom gnus-treat-strip-multiple-blank-lines nil
1354 "Strip multiple blank lines.
1355 Valid values are nil, t, `head', `first', `last', an integer or a
1356 predicate. See Info node `(gnus)Customizing Articles'."
1357 :group 'gnus-article-treat
1358 :link '(custom-manual "(gnus)Customizing Articles")
1359 :type gnus-article-treat-custom)
1360
1361 (defcustom gnus-treat-unfold-headers 'head
1362 "Unfold folded header lines.
1363 Valid values are nil, t, `head', `first', `last', an integer or a
1364 predicate. See Info node `(gnus)Customizing Articles'."
1365 :version "22.1"
1366 :group 'gnus-article-treat
1367 :link '(custom-manual "(gnus)Customizing Articles")
1368 :type gnus-article-treat-custom)
1369
1370 (defcustom gnus-article-unfold-long-headers nil
1371 "If non-nil, allow unfolding headers even if the header is long.
1372 If it is a regexp, only long headers matching this regexp are unfolded.
1373 If it is t, all long headers are unfolded.
1374
1375 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1376 :version "23.1" ;; No Gnus
1377 :group 'gnus-article-treat
1378 :type '(choice (const nil)
1379 (const :tag "all" t)
1380 (regexp)))
1381
1382 (defcustom gnus-treat-fold-headers nil
1383 "Fold headers.
1384 Valid values are nil, t, `head', `first', `last', an integer or a
1385 predicate. See Info node `(gnus)Customizing Articles'."
1386 :version "22.1"
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1390
1391 (defcustom gnus-treat-fold-newsgroups 'head
1392 "Fold the Newsgroups and Followup-To headers.
1393 Valid values are nil, t, `head', `first', `last', an integer or a
1394 predicate. See Info node `(gnus)Customizing Articles'."
1395 :version "22.1"
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1399
1400 (defcustom gnus-treat-overstrike t
1401 "Treat overstrike highlighting.
1402 Valid values are nil, t, `head', `first', `last', an integer or a
1403 predicate. See Info node `(gnus)Customizing Articles'."
1404 :group 'gnus-article-treat
1405 :link '(custom-manual "(gnus)Customizing Articles")
1406 :type gnus-article-treat-custom)
1407 (put 'gnus-treat-overstrike 'highlight t)
1408
1409 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1410 "Treat ANSI SGR control sequences.
1411 Valid values are nil, t, `head', `first', `last', an integer or a
1412 predicate. See Info node `(gnus)Customizing Articles'."
1413 :group 'gnus-article-treat
1414 :link '(custom-manual "(gnus)Customizing Articles")
1415 :type gnus-article-treat-custom)
1416
1417 (make-obsolete-variable 'gnus-treat-display-xface
1418 'gnus-treat-display-x-face "22.1")
1419
1420 (defcustom gnus-treat-display-x-face
1421 (and (not noninteractive)
1422 (gnus-image-type-available-p 'xbm)
1423 (if (featurep 'xemacs)
1424 (featurep 'xface)
1425 (condition-case nil
1426 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1427 (executable-find "icontopbm"))
1428 ;; shell-command-to-string may signal an error, e.g. if
1429 ;; shell-file-name is not found.
1430 (error nil)))
1431 'head)
1432 "Display X-Face headers.
1433 Valid values are nil and `head'.
1434 See Info node `(gnus)Customizing Articles' and Info node
1435 `(gnus)X-Face' for details."
1436 :group 'gnus-article-treat
1437 :version "21.1"
1438 :link '(custom-manual "(gnus)Customizing Articles")
1439 :link '(custom-manual "(gnus)X-Face")
1440 :type gnus-article-treat-head-custom
1441 :set (lambda (symbol value)
1442 (set-default
1443 symbol
1444 (cond ((or (boundp symbol) (get symbol 'saved-value))
1445 value)
1446 ((boundp 'gnus-treat-display-xface)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (default-value 'gnus-treat-display-xface))
1451 ((get 'gnus-treat-display-xface 'saved-value)
1452 (message "\
1453 ** gnus-treat-display-xface is an obsolete variable;\
1454 use gnus-treat-display-x-face instead")
1455 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1456 (t
1457 value)))))
1458 (put 'gnus-treat-display-x-face 'highlight t)
1459
1460 (defcustom gnus-treat-display-face
1461 (and (not noninteractive)
1462 (gnus-image-type-available-p 'png)
1463 'head)
1464 "Display Face headers.
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)Face' for details."
1468 :group 'gnus-article-treat
1469 :version "22.1"
1470 :link '(custom-manual "(gnus)Customizing Articles")
1471 :link '(custom-manual "(gnus)X-Face")
1472 :type gnus-article-treat-head-custom)
1473 (put 'gnus-treat-display-face 'highlight t)
1474
1475 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1476 "Display smileys.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Smileys' for details."
1480 :group 'gnus-article-treat
1481 :version "21.1"
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :link '(custom-manual "(gnus)Smileys")
1484 :type gnus-article-treat-custom)
1485 (put 'gnus-treat-display-smileys 'highlight t)
1486
1487 (defcustom gnus-treat-from-picon
1488 (if (and (gnus-image-type-available-p 'xpm)
1489 (gnus-picons-installed-p))
1490 'head nil)
1491 "Display picons in the From header.
1492 Valid values are nil, t, `head', `first', `last', an integer or a
1493 predicate. See Info node `(gnus)Customizing Articles' and Info
1494 node `(gnus)Picons' for details."
1495 :version "22.1"
1496 :group 'gnus-article-treat
1497 :group 'gnus-picon
1498 :link '(custom-manual "(gnus)Customizing Articles")
1499 :link '(custom-manual "(gnus)Picons")
1500 :type gnus-article-treat-head-custom)
1501 (put 'gnus-treat-from-picon 'highlight t)
1502
1503 (defcustom gnus-treat-mail-picon
1504 (if (and (gnus-image-type-available-p 'xpm)
1505 (gnus-picons-installed-p))
1506 'head nil)
1507 "Display picons in To and Cc headers.
1508 Valid values are nil, t, `head', `first', `last', an integer or a
1509 predicate. See Info node `(gnus)Customizing Articles' and Info
1510 node `(gnus)Picons' for details."
1511 :version "22.1"
1512 :group 'gnus-article-treat
1513 :group 'gnus-picon
1514 :link '(custom-manual "(gnus)Customizing Articles")
1515 :link '(custom-manual "(gnus)Picons")
1516 :type gnus-article-treat-head-custom)
1517 (put 'gnus-treat-mail-picon 'highlight t)
1518
1519 (defcustom gnus-treat-newsgroups-picon
1520 (if (and (gnus-image-type-available-p 'xpm)
1521 (gnus-picons-installed-p))
1522 'head nil)
1523 "Display picons in the Newsgroups and Followup-To headers.
1524 Valid values are nil, t, `head', `first', `last', an integer or a
1525 predicate. See Info node `(gnus)Customizing Articles' and Info
1526 node `(gnus)Picons' for details."
1527 :version "22.1"
1528 :group 'gnus-article-treat
1529 :group 'gnus-picon
1530 :link '(custom-manual "(gnus)Customizing Articles")
1531 :link '(custom-manual "(gnus)Picons")
1532 :type gnus-article-treat-head-custom)
1533 (put 'gnus-treat-newsgroups-picon 'highlight t)
1534
1535 (defcustom gnus-treat-body-boundary
1536 (if (or gnus-treat-newsgroups-picon
1537 gnus-treat-mail-picon
1538 gnus-treat-from-picon)
1539 ;; If there's much decoration, the user might prefer a boundery.
1540 'head
1541 nil)
1542 "Draw a boundary at the end of the headers.
1543 Valid values are nil and `head'.
1544 See Info node `(gnus)Customizing Articles' for details."
1545 :version "22.1"
1546 :group 'gnus-article-treat
1547 :link '(custom-manual "(gnus)Customizing Articles")
1548 :type gnus-article-treat-head-custom)
1549
1550 (defcustom gnus-treat-capitalize-sentences nil
1551 "Capitalize sentence-starting words.
1552 Valid values are nil, t, `head', `first', `last', an integer or a
1553 predicate. See Info node `(gnus)Customizing Articles'."
1554 :version "21.1"
1555 :group 'gnus-article-treat
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :type gnus-article-treat-custom)
1558
1559 (defcustom gnus-treat-wash-html nil
1560 "Format as HTML.
1561 Valid values are nil, t, `head', `first', `last', an integer or a
1562 predicate. See Info node `(gnus)Customizing Articles'."
1563 :version "22.1"
1564 :group 'gnus-article-treat
1565 :link '(custom-manual "(gnus)Customizing Articles")
1566 :type gnus-article-treat-custom)
1567
1568 (defcustom gnus-treat-fill-long-lines nil
1569 "Fill long lines.
1570 Valid values are nil, t, `head', `first', `last', an integer or a
1571 predicate. See Info node `(gnus)Customizing Articles'."
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-custom)
1575
1576 (defcustom gnus-treat-play-sounds nil
1577 "Play sounds.
1578 Valid values are nil, t, `head', `first', `last', an integer or a
1579 predicate. See Info node `(gnus)Customizing Articles'."
1580 :version "21.1"
1581 :group 'gnus-article-treat
1582 :link '(custom-manual "(gnus)Customizing Articles")
1583 :type gnus-article-treat-custom)
1584
1585 (defcustom gnus-treat-translate nil
1586 "Translate articles from one language to another.
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1589 :version "21.1"
1590 :group 'gnus-article-treat
1591 :link '(custom-manual "(gnus)Customizing Articles")
1592 :type gnus-article-treat-custom)
1593
1594 (defcustom gnus-treat-x-pgp-sig nil
1595 "Verify X-PGP-Sig.
1596 To automatically treat X-PGP-Sig, set it to head.
1597 Valid values are nil, t, `head', `first', `last', an integer or a
1598 predicate. See Info node `(gnus)Customizing Articles'."
1599 :version "22.1"
1600 :group 'gnus-article-treat
1601 :group 'mime-security
1602 :link '(custom-manual "(gnus)Customizing Articles")
1603 :type gnus-article-treat-custom)
1604
1605 (defvar gnus-article-encrypt-protocol-alist
1606 '(("PGP" . mml2015-self-encrypt)))
1607
1608 ;; Set to nil if more than one protocol added to
1609 ;; gnus-article-encrypt-protocol-alist.
1610 (defcustom gnus-article-encrypt-protocol "PGP"
1611 "The protocol used for encrypt articles.
1612 It is a string, such as \"PGP\". If nil, ask user."
1613 :version "22.1"
1614 :type 'string
1615 :group 'mime-security)
1616
1617 (defvar gnus-article-wash-function nil
1618 "Function used for converting HTML into text.")
1619
1620 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1621 (mm-coding-system-p 'utf-8)
1622 (executable-find idna-program))
1623 "Whether IDNA decoding of headers is used when viewing messages.
1624 This requires GNU Libidn, and by default only enabled if it is found."
1625 :version "22.1"
1626 :group 'gnus-article-headers
1627 :type 'boolean)
1628
1629 (defcustom gnus-article-over-scroll nil
1630 "If non-nil, allow scrolling the article buffer even when there no more text."
1631 :version "22.1"
1632 :group 'gnus-article
1633 :type 'boolean)
1634
1635 ;;; Internal variables
1636
1637 (defvar gnus-english-month-names
1638 '("January" "February" "March" "April" "May" "June" "July" "August"
1639 "September" "October" "November" "December"))
1640
1641 (defvar article-goto-body-goes-to-point-min-p nil)
1642 (defvar gnus-article-wash-types nil)
1643 (defvar gnus-article-emphasis-alist nil)
1644 (defvar gnus-article-image-alist nil)
1645
1646 (defvar gnus-article-mime-handle-alist-1 nil)
1647 (defvar gnus-treatment-function-alist
1648 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1649 (gnus-treat-strip-banner gnus-article-strip-banner)
1650 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1651 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1652 (gnus-treat-buttonize gnus-article-add-buttons)
1653 (gnus-treat-fill-article gnus-article-fill-cited-article)
1654 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1655 (gnus-treat-strip-cr gnus-article-remove-cr)
1656 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1657 (gnus-treat-date-ut gnus-article-date-ut)
1658 (gnus-treat-date-local gnus-article-date-local)
1659 (gnus-treat-date-english gnus-article-date-english)
1660 (gnus-treat-date-original gnus-article-date-original)
1661 (gnus-treat-date-user-defined gnus-article-date-user)
1662 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1663 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1664 (gnus-treat-display-x-face gnus-article-display-x-face)
1665 (gnus-treat-display-face gnus-article-display-face)
1666 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1667 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1668 (gnus-treat-hide-signature gnus-article-hide-signature)
1669 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1670 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1671 (gnus-treat-strip-pem gnus-article-hide-pem)
1672 (gnus-treat-from-picon gnus-treat-from-picon)
1673 (gnus-treat-mail-picon gnus-treat-mail-picon)
1674 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1675 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1676 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1677 (gnus-treat-strip-trailing-blank-lines
1678 gnus-article-remove-trailing-blank-lines)
1679 (gnus-treat-strip-leading-blank-lines
1680 gnus-article-strip-leading-blank-lines)
1681 (gnus-treat-strip-multiple-blank-lines
1682 gnus-article-strip-multiple-blank-lines)
1683 (gnus-treat-overstrike gnus-article-treat-overstrike)
1684 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1685 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1686 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1687 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1688 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1689 (gnus-treat-display-smileys gnus-treat-smiley)
1690 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1691 (gnus-treat-wash-html gnus-article-wash-html)
1692 (gnus-treat-emphasize gnus-article-emphasize)
1693 (gnus-treat-hide-citation gnus-article-hide-citation)
1694 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1695 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1696 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1697 (gnus-treat-play-sounds gnus-earcon-display)))
1698
1699 (defvar gnus-article-mime-handle-alist nil)
1700 (defvar article-lapsed-timer nil)
1701 (defvar gnus-article-current-summary nil)
1702
1703 (defvar gnus-article-mode-syntax-table
1704 (let ((table (copy-syntax-table text-mode-syntax-table)))
1705 ;; This causes the citation match run O(2^n).
1706 ;; (modify-syntax-entry ?- "w" table)
1707 (modify-syntax-entry ?> ")<" table)
1708 (modify-syntax-entry ?< "(>" table)
1709 ;; make M-. in article buffers work for `foo' strings
1710 (modify-syntax-entry ?' " " table)
1711 (modify-syntax-entry ?` " " table)
1712 table)
1713 "Syntax table used in article mode buffers.
1714 Initialized from `text-mode-syntax-table.")
1715
1716 (defvar gnus-save-article-buffer nil)
1717
1718 (defvar gnus-number-of-articles-to-be-saved nil)
1719
1720 (defvar gnus-inhibit-hiding nil)
1721
1722 (defvar gnus-article-edit-mode nil)
1723
1724 ;;; Macros for dealing with the article buffer.
1725
1726 (defmacro gnus-with-article-headers (&rest forms)
1727 `(with-current-buffer gnus-article-buffer
1728 (save-restriction
1729 (let ((inhibit-read-only t)
1730 (inhibit-point-motion-hooks t)
1731 (case-fold-search t))
1732 (article-narrow-to-head)
1733 ,@forms))))
1734
1735 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1736 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1737
1738 (defmacro gnus-with-article-buffer (&rest forms)
1739 `(with-current-buffer gnus-article-buffer
1740 (let ((inhibit-read-only t))
1741 ,@forms)))
1742
1743 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1744 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1745
1746 (defun gnus-article-goto-header (header)
1747 "Go to HEADER, which is a regular expression."
1748 (re-search-forward (concat "^\\(" header "\\):") nil t))
1749
1750 (defsubst gnus-article-hide-text (b e props)
1751 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1752 (gnus-add-text-properties-when 'article-type nil b e props)
1753 (when (memq 'intangible props)
1754 (put-text-property
1755 (max (1- b) (point-min))
1756 b 'intangible (cddr (memq 'intangible props)))))
1757
1758 (defsubst gnus-article-unhide-text (b e)
1759 "Remove hidden text properties from region between B and E."
1760 (remove-text-properties b e gnus-hidden-properties)
1761 (when (memq 'intangible gnus-hidden-properties)
1762 (put-text-property (max (1- b) (point-min))
1763 b 'intangible nil)))
1764
1765 (defun gnus-article-hide-text-type (b e type)
1766 "Hide text of TYPE between B and E."
1767 (gnus-add-wash-type type)
1768 (gnus-article-hide-text
1769 b e (cons 'article-type (cons type gnus-hidden-properties))))
1770
1771 (defun gnus-article-unhide-text-type (b e type)
1772 "Unhide text of TYPE between B and E."
1773 (gnus-delete-wash-type type)
1774 (remove-text-properties
1775 b e (cons 'article-type (cons type gnus-hidden-properties)))
1776 (when (memq 'intangible gnus-hidden-properties)
1777 (put-text-property (max (1- b) (point-min))
1778 b 'intangible nil)))
1779
1780 (defun gnus-article-hide-text-of-type (type)
1781 "Hide text of TYPE in the current buffer."
1782 (save-excursion
1783 (let ((b (point-min))
1784 (e (point-max)))
1785 (while (setq b (text-property-any b e 'article-type type))
1786 (add-text-properties b (incf b) gnus-hidden-properties)))))
1787
1788 (defun gnus-article-delete-text-of-type (type)
1789 "Delete text of TYPE in the current buffer."
1790 (save-excursion
1791 (let ((b (point-min)))
1792 (if (eq type 'multipart)
1793 ;; Remove MIME buttons associated with multipart/alternative parts.
1794 (progn
1795 (goto-char b)
1796 (while (if (get-text-property (point) 'gnus-part)
1797 (setq b (point))
1798 (when (setq b (next-single-property-change (point)
1799 'gnus-part))
1800 (goto-char b)
1801 t))
1802 (end-of-line)
1803 (skip-chars-forward "\n")
1804 (when (eq (get-text-property b 'article-type) 'multipart)
1805 (delete-region b (point)))))
1806 (while (setq b (text-property-any b (point-max) 'article-type type))
1807 (delete-region
1808 b (or (text-property-not-all b (point-max) 'article-type type)
1809 (point-max))))))))
1810
1811 (defun gnus-article-delete-invisible-text ()
1812 "Delete all invisible text in the current buffer."
1813 (save-excursion
1814 (let ((b (point-min)))
1815 (while (setq b (text-property-any b (point-max) 'invisible t))
1816 (delete-region
1817 b (or (text-property-not-all b (point-max) 'invisible t)
1818 (point-max)))))))
1819
1820 (defun gnus-article-text-type-exists-p (type)
1821 "Say whether any text of type TYPE exists in the buffer."
1822 (text-property-any (point-min) (point-max) 'article-type type))
1823
1824 (defsubst gnus-article-header-rank ()
1825 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1826 (let ((list gnus-sorted-header-list)
1827 (i 1))
1828 (while list
1829 (if (looking-at (car list))
1830 (setq list nil)
1831 (setq list (cdr list))
1832 (incf i)))
1833 i))
1834
1835 (defun article-hide-headers (&optional arg delete)
1836 "Hide unwanted headers and possibly sort them as well."
1837 (interactive)
1838 ;; This function might be inhibited.
1839 (unless gnus-inhibit-hiding
1840 (let ((inhibit-read-only t)
1841 (case-fold-search t)
1842 (max (1+ (length gnus-sorted-header-list)))
1843 (inhibit-point-motion-hooks t)
1844 (cur (current-buffer))
1845 ignored visible beg)
1846 (save-excursion
1847 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1848 ;; group parameters, so we should go to the summary buffer.
1849 (when (prog1
1850 (condition-case nil
1851 (progn (set-buffer gnus-summary-buffer) t)
1852 (error nil))
1853 (setq ignored (when (not gnus-visible-headers)
1854 (cond ((stringp gnus-ignored-headers)
1855 gnus-ignored-headers)
1856 ((listp gnus-ignored-headers)
1857 (mapconcat 'identity
1858 gnus-ignored-headers
1859 "\\|"))))
1860 visible (cond ((stringp gnus-visible-headers)
1861 gnus-visible-headers)
1862 ((and gnus-visible-headers
1863 (listp gnus-visible-headers))
1864 (mapconcat 'identity
1865 gnus-visible-headers
1866 "\\|")))))
1867 (set-buffer cur))
1868 (save-restriction
1869 ;; First we narrow to just the headers.
1870 (article-narrow-to-head)
1871 ;; Hide any "From " lines at the beginning of (mail) articles.
1872 (while (looking-at "From ")
1873 (forward-line 1))
1874 (unless (bobp)
1875 (delete-region (point-min) (point)))
1876 ;; Then treat the rest of the header lines.
1877 ;; Then we use the two regular expressions
1878 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1879 ;; select which header lines is to remain visible in the
1880 ;; article buffer.
1881 (while (re-search-forward "^[^ \t:]*:" nil t)
1882 (beginning-of-line)
1883 ;; Mark the rank of the header.
1884 (put-text-property
1885 (point) (1+ (point)) 'message-rank
1886 (if (or (and visible (looking-at visible))
1887 (and ignored
1888 (not (looking-at ignored))))
1889 (gnus-article-header-rank)
1890 (+ 2 max)))
1891 (forward-line 1))
1892 (message-sort-headers-1)
1893 (when (setq beg (text-property-any
1894 (point-min) (point-max) 'message-rank (+ 2 max)))
1895 ;; We delete the unwanted headers.
1896 (gnus-add-wash-type 'headers)
1897 (add-text-properties (point-min) (+ 5 (point-min))
1898 '(article-type headers dummy-invisible t))
1899 (delete-region beg (point-max))))))))
1900
1901 (defun article-hide-boring-headers (&optional arg)
1902 "Toggle hiding of headers that aren't very interesting.
1903 If given a negative prefix, always show; if given a positive prefix,
1904 always hide."
1905 (interactive (gnus-article-hidden-arg))
1906 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1907 (not gnus-show-all-headers))
1908 (save-excursion
1909 (save-restriction
1910 (let ((inhibit-read-only t)
1911 (inhibit-point-motion-hooks t))
1912 (article-narrow-to-head)
1913 (dolist (elem gnus-boring-article-headers)
1914 (goto-char (point-min))
1915 (cond
1916 ;; Hide empty headers.
1917 ((eq elem 'empty)
1918 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1919 (forward-line -1)
1920 (gnus-article-hide-text-type
1921 (point-at-bol)
1922 (progn
1923 (end-of-line)
1924 (if (re-search-forward "^[^ \t]" nil t)
1925 (match-beginning 0)
1926 (point-max)))
1927 'boring-headers)))
1928 ;; Hide boring Newsgroups header.
1929 ((eq elem 'newsgroups)
1930 (when (gnus-string-equal
1931 (gnus-fetch-field "newsgroups")
1932 (gnus-group-real-name
1933 (if (boundp 'gnus-newsgroup-name)
1934 gnus-newsgroup-name
1935 "")))
1936 (gnus-article-hide-header "newsgroups")))
1937 ((eq elem 'to-address)
1938 (let ((to (message-fetch-field "to"))
1939 (to-address
1940 (gnus-parameter-to-address
1941 (if (boundp 'gnus-newsgroup-name)
1942 gnus-newsgroup-name ""))))
1943 (when (and to to-address
1944 (ignore-errors
1945 (gnus-string-equal
1946 ;; only one address in To
1947 (nth 1 (mail-extract-address-components to))
1948 to-address)))
1949 (gnus-article-hide-header "to"))))
1950 ((eq elem 'to-list)
1951 (let ((to (message-fetch-field "to"))
1952 (to-list
1953 (gnus-parameter-to-list
1954 (if (boundp 'gnus-newsgroup-name)
1955 gnus-newsgroup-name ""))))
1956 (when (and to to-list
1957 (ignore-errors
1958 (gnus-string-equal
1959 ;; only one address in To
1960 (nth 1 (mail-extract-address-components to))
1961 to-list)))
1962 (gnus-article-hide-header "to"))))
1963 ((eq elem 'cc-list)
1964 (let ((cc (message-fetch-field "cc"))
1965 (to-list
1966 (gnus-parameter-to-list
1967 (if (boundp 'gnus-newsgroup-name)
1968 gnus-newsgroup-name ""))))
1969 (when (and cc to-list
1970 (ignore-errors
1971 (gnus-string-equal
1972 ;; only one address in CC
1973 (nth 1 (mail-extract-address-components cc))
1974 to-list)))
1975 (gnus-article-hide-header "cc"))))
1976 ((eq elem 'followup-to)
1977 (when (gnus-string-equal
1978 (message-fetch-field "followup-to")
1979 (message-fetch-field "newsgroups"))
1980 (gnus-article-hide-header "followup-to")))
1981 ((eq elem 'reply-to)
1982 (if (gnus-group-find-parameter
1983 gnus-newsgroup-name 'broken-reply-to)
1984 (gnus-article-hide-header "reply-to")
1985 (let ((from (message-fetch-field "from"))
1986 (reply-to (message-fetch-field "reply-to")))
1987 (when
1988 (and
1989 from reply-to
1990 (ignore-errors
1991 (equal
1992 (sort (mapcar
1993 (lambda (x) (downcase (cadr x)))
1994 (mail-extract-address-components from t))
1995 'string<)
1996 (sort (mapcar
1997 (lambda (x) (downcase (cadr x)))
1998 (mail-extract-address-components reply-to t))
1999 'string<))))
2000 (gnus-article-hide-header "reply-to")))))
2001 ((eq elem 'date)
2002 (let ((date (with-current-buffer gnus-original-article-buffer
2003 ;; If date in `gnus-article-buffer' is localized
2004 ;; (`gnus-treat-date-user-defined'),
2005 ;; `days-between' might fail.
2006 (message-fetch-field "date"))))
2007 (when (and date
2008 (< (days-between (current-time-string) date)
2009 4))
2010 (gnus-article-hide-header "date"))))
2011 ((eq elem 'long-to)
2012 (let ((to (message-fetch-field "to"))
2013 (cc (message-fetch-field "cc")))
2014 (when (> (length to) 1024)
2015 (gnus-article-hide-header "to"))
2016 (when (> (length cc) 1024)
2017 (gnus-article-hide-header "cc"))))
2018 ((eq elem 'many-to)
2019 (let ((to-count 0)
2020 (cc-count 0))
2021 (goto-char (point-min))
2022 (while (re-search-forward "^to:" nil t)
2023 (setq to-count (1+ to-count)))
2024 (when (> to-count 1)
2025 (while (> to-count 0)
2026 (goto-char (point-min))
2027 (save-restriction
2028 (re-search-forward "^to:" nil nil to-count)
2029 (forward-line -1)
2030 (narrow-to-region (point) (point-max))
2031 (gnus-article-hide-header "to"))
2032 (setq to-count (1- to-count))))
2033 (goto-char (point-min))
2034 (while (re-search-forward "^cc:" nil t)
2035 (setq cc-count (1+ cc-count)))
2036 (when (> cc-count 1)
2037 (while (> cc-count 0)
2038 (goto-char (point-min))
2039 (save-restriction
2040 (re-search-forward "^cc:" nil nil cc-count)
2041 (forward-line -1)
2042 (narrow-to-region (point) (point-max))
2043 (gnus-article-hide-header "cc"))
2044 (setq cc-count (1- cc-count)))))))))))))
2045
2046 (defun gnus-article-hide-header (header)
2047 (save-excursion
2048 (goto-char (point-min))
2049 (when (re-search-forward (concat "^" header ":") nil t)
2050 (gnus-article-hide-text-type
2051 (point-at-bol)
2052 (progn
2053 (end-of-line)
2054 (if (re-search-forward "^[^ \t]" nil t)
2055 (match-beginning 0)
2056 (point-max)))
2057 'boring-headers))))
2058
2059 (defvar gnus-article-normalized-header-length 40
2060 "Length of normalized headers.")
2061
2062 (defun article-normalize-headers ()
2063 "Make all header lines 40 characters long."
2064 (interactive)
2065 (let ((inhibit-read-only t)
2066 column)
2067 (save-excursion
2068 (save-restriction
2069 (article-narrow-to-head)
2070 (while (not (eobp))
2071 (cond
2072 ((< (setq column (- (point-at-eol) (point)))
2073 gnus-article-normalized-header-length)
2074 (end-of-line)
2075 (insert (make-string
2076 (- gnus-article-normalized-header-length column)
2077 ? )))
2078 ((> column gnus-article-normalized-header-length)
2079 (gnus-put-text-property
2080 (progn
2081 (forward-char gnus-article-normalized-header-length)
2082 (point))
2083 (point-at-eol)
2084 'invisible t))
2085 (t
2086 ;; Do nothing.
2087 ))
2088 (forward-line 1))))))
2089
2090 (defun article-treat-dumbquotes ()
2091 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2092 Note that this function guesses whether a character is a sm*rtq**t* or
2093 not, so it should only be used interactively.
2094
2095 Sm*rtq**t*s are M****s***'s unilateral extension to the
2096 iso-8859-1 character map in an attempt to provide more quoting
2097 characters. If you see something like \\222 or \\264 where
2098 you're expecting some kind of apostrophe or quotation mark, then
2099 try this wash."
2100 (interactive)
2101 (article-translate-strings gnus-article-dumbquotes-map))
2102
2103 (defun article-translate-characters (from to)
2104 "Translate all characters in the body of the article according to FROM and TO.
2105 FROM is a string of characters to translate from; to is a string of
2106 characters to translate to."
2107 (save-excursion
2108 (when (article-goto-body)
2109 (let ((inhibit-read-only t)
2110 (x (make-string 225 ?x))
2111 (i -1))
2112 (while (< (incf i) (length x))
2113 (aset x i i))
2114 (setq i 0)
2115 (while (< i (length from))
2116 (aset x (aref from i) (aref to i))
2117 (incf i))
2118 (translate-region (point) (point-max) x)))))
2119
2120 (defun article-translate-strings (map)
2121 "Translate all string in the body of the article according to MAP.
2122 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2123 (save-excursion
2124 (when (article-goto-body)
2125 (let ((inhibit-read-only t))
2126 (dolist (elem map)
2127 (save-excursion
2128 (while (search-forward (car elem) nil t)
2129 (replace-match (cadr elem)))))))))
2130
2131 (defun article-treat-overstrike ()
2132 "Translate overstrikes into bold text."
2133 (interactive)
2134 (save-excursion
2135 (when (article-goto-body)
2136 (let ((inhibit-read-only t))
2137 (while (search-forward "\b" nil t)
2138 (let ((next (char-after))
2139 (previous (char-after (- (point) 2))))
2140 ;; We do the boldification/underlining by hiding the
2141 ;; overstrikes and putting the proper text property
2142 ;; on the letters.
2143 (cond
2144 ((eq next previous)
2145 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2146 (put-text-property (point) (1+ (point)) 'face 'bold))
2147 ((eq next ?_)
2148 (gnus-article-hide-text-type
2149 (1- (point)) (1+ (point)) 'overstrike)
2150 (put-text-property
2151 (- (point) 2) (1- (point)) 'face 'underline))
2152 ((eq previous ?_)
2153 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2154 (put-text-property
2155 (point) (1+ (point)) 'face 'underline)))))))))
2156
2157 (defun article-treat-ansi-sequences ()
2158 "Translate ANSI SGR control sequences into overlays or extents."
2159 (interactive)
2160 (save-excursion
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (ansi-color-apply-on-region (point) (point-max))))))
2164
2165 (defun gnus-article-treat-unfold-headers ()
2166 "Unfold folded message headers.
2167 Only the headers that fit into the current window width will be
2168 unfolded."
2169 (interactive)
2170 (gnus-with-article-headers
2171 (let (length)
2172 (while (not (eobp))
2173 (save-restriction
2174 (mail-header-narrow-to-field)
2175 (let* ((header (buffer-string))
2176 (unfoldable
2177 (or (equal gnus-article-unfold-long-headers t)
2178 (and (stringp gnus-article-unfold-long-headers)
2179 (string-match gnus-article-unfold-long-headers header)))))
2180 (with-temp-buffer
2181 (insert header)
2182 (goto-char (point-min))
2183 (while (re-search-forward "\n[\t ]" nil t)
2184 (replace-match " " t t)))
2185 (setq length (- (point-max) (point-min) 1))
2186 (when (or unfoldable
2187 (< length (window-width)))
2188 (while (re-search-forward "\n[\t ]" nil t)
2189 (replace-match " " t t))))
2190 (goto-char (point-max)))))))
2191
2192 (defun gnus-article-treat-fold-headers ()
2193 "Fold message headers."
2194 (interactive)
2195 (gnus-with-article-headers
2196 (while (not (eobp))
2197 (save-restriction
2198 (mail-header-narrow-to-field)
2199 (mail-header-fold-field)
2200 (goto-char (point-max))))))
2201
2202 (defun gnus-treat-smiley ()
2203 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2204 (interactive)
2205 (gnus-with-article-buffer
2206 (if (memq 'smiley gnus-article-wash-types)
2207 (gnus-delete-images 'smiley)
2208 (article-goto-body)
2209 (let ((images (smiley-region (point) (point-max))))
2210 (when images
2211 (gnus-add-wash-type 'smiley)
2212 (dolist (image images)
2213 (gnus-add-image 'smiley image)))))))
2214
2215 (defun gnus-article-remove-images ()
2216 "Remove all images from the article buffer."
2217 (interactive)
2218 (gnus-with-article-buffer
2219 (dolist (elem gnus-article-image-alist)
2220 (gnus-delete-images (car elem)))))
2221
2222 (defun gnus-article-treat-fold-newsgroups ()
2223 "Unfold folded message headers.
2224 Only the headers that fit into the current window width will be
2225 unfolded."
2226 (interactive)
2227 (gnus-with-article-headers
2228 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2229 (save-restriction
2230 (mail-header-narrow-to-field)
2231 (while (re-search-forward ", *" nil t)
2232 (replace-match ", " t t))
2233 (mail-header-fold-field)
2234 (goto-char (point-max))))))
2235
2236 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2237 "Value of `truncate-lines' in Gnus Article buffer.
2238 Valid values are nil, t, `head', `first', `last', an integer or a
2239 predicate. See Info node `(gnus)Customizing Articles'."
2240 :version "23.1" ;; No Gnus
2241 :group 'gnus-article
2242 ;; :link '(custom-manual "(gnus)Customizing Articles")
2243 :type 'boolean)
2244
2245 (defun gnus-article-toggle-truncate-lines (&optional arg)
2246 "Toggle whether to fold or truncate long lines in article the buffer.
2247 If ARG is non-nil and not a number, toggle
2248 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2249 long lines if and only if arg is positive."
2250 (interactive "P")
2251 (cond
2252 ((and (numberp arg) (> arg 0))
2253 (setq gnus-article-truncate-lines t))
2254 ((numberp arg)
2255 (setq gnus-article-truncate-lines nil))
2256 (arg
2257 (setq gnus-article-truncate-lines
2258 (not gnus-article-truncate-lines))))
2259 (gnus-with-article-buffer
2260 (cond
2261 ((and (numberp arg) (> arg 0))
2262 (setq truncate-lines nil))
2263 ((numberp arg)
2264 (setq truncate-lines t)))
2265 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2266 ;; `toggle-truncate-lines' needs an argument.
2267 (toggle-truncate-lines)))
2268
2269 (defun gnus-article-treat-body-boundary ()
2270 "Place a boundary line at the end of the headers."
2271 (interactive)
2272 (when (and gnus-body-boundary-delimiter
2273 (> (length gnus-body-boundary-delimiter) 0))
2274 (gnus-with-article-headers
2275 (goto-char (point-max))
2276 (let ((start (point)))
2277 (insert "X-Boundary: ")
2278 (gnus-add-text-properties start (point) '(invisible t intangible t))
2279 (insert (let (str)
2280 (while (>= (1- (window-width)) (length str))
2281 (setq str (concat str gnus-body-boundary-delimiter)))
2282 (substring str 0 (1- (window-width))))
2283 "\n")
2284 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2285
2286 (defun article-fill-long-lines ()
2287 "Fill lines that are wider than the window width."
2288 (interactive)
2289 (save-excursion
2290 (let ((inhibit-read-only t)
2291 (width (window-width (get-buffer-window (current-buffer)))))
2292 (save-restriction
2293 (article-goto-body)
2294 (let ((adaptive-fill-mode nil)) ;Why? -sm
2295 (while (not (eobp))
2296 (end-of-line)
2297 (when (>= (current-column) (min fill-column width))
2298 (narrow-to-region (min (1+ (point)) (point-max))
2299 (point-at-bol))
2300 (let ((goback (point-marker)))
2301 (fill-paragraph nil)
2302 (goto-char (marker-position goback)))
2303 (widen))
2304 (forward-line 1)))))))
2305
2306 (defun article-capitalize-sentences ()
2307 "Capitalize the first word in each sentence."
2308 (interactive)
2309 (save-excursion
2310 (let ((inhibit-read-only t)
2311 (paragraph-start "^[\n\^L]"))
2312 (article-goto-body)
2313 (while (not (eobp))
2314 (capitalize-word 1)
2315 (forward-sentence)))))
2316
2317 (defun article-remove-cr ()
2318 "Remove trailing CRs and then translate remaining CRs into LFs."
2319 (interactive)
2320 (save-excursion
2321 (let ((inhibit-read-only t))
2322 (goto-char (point-min))
2323 (while (re-search-forward "\r+$" nil t)
2324 (replace-match "" t t))
2325 (goto-char (point-min))
2326 (while (search-forward "\r" nil t)
2327 (replace-match "\n" t t)))))
2328
2329 (defun article-remove-trailing-blank-lines ()
2330 "Remove all trailing blank lines from the article."
2331 (interactive)
2332 (save-excursion
2333 (let ((inhibit-read-only t))
2334 (goto-char (point-max))
2335 (delete-region
2336 (point)
2337 (progn
2338 (while (and (not (bobp))
2339 (looking-at "^[ \t]*$")
2340 (not (gnus-annotation-in-region-p
2341 (point) (point-at-eol))))
2342 (forward-line -1))
2343 (forward-line 1)
2344 (point))))))
2345
2346 (defvar gnus-face-properties-alist)
2347
2348 (defun article-display-face (&optional force)
2349 "Display any Face headers in the header."
2350 (interactive (list 'force))
2351 (let ((wash-face-p buffer-read-only))
2352 (gnus-with-article-headers
2353 ;; When displaying parts, this function can be called several times on
2354 ;; the same article, without any intended toggle semantic (as typing `W
2355 ;; D d' would have). So face deletion must occur only when we come from
2356 ;; an interactive command, that is when the *Article* buffer is
2357 ;; read-only.
2358 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2359 (gnus-delete-images 'face)
2360 (let ((from (message-fetch-field "from"))
2361 face faces)
2362 (save-current-buffer
2363 (when (and wash-face-p
2364 (gnus-buffer-live-p gnus-original-article-buffer)
2365 (not (re-search-forward "^Face:[\t ]*" nil t)))
2366 (set-buffer gnus-original-article-buffer))
2367 (save-restriction
2368 (mail-narrow-to-head)
2369 (when (or force
2370 ;; Check whether this face is censored.
2371 (not (and gnus-article-x-face-too-ugly
2372 (or from
2373 (setq from (message-fetch-field "from")))
2374 (string-match gnus-article-x-face-too-ugly
2375 from))))
2376 (while (gnus-article-goto-header "Face")
2377 (push (mail-header-field-value) faces)))))
2378 (when faces
2379 (goto-char (point-min))
2380 (let (png image)
2381 (unless (setq from (gnus-article-goto-header "from"))
2382 (insert "From:")
2383 (setq from (point))
2384 (insert " [no `from' set]\n"))
2385 (while faces
2386 (when (setq png (gnus-convert-face-to-png (pop faces)))
2387 (setq image
2388 (apply 'gnus-create-image png 'png t
2389 (cdr (assq 'png gnus-face-properties-alist))))
2390 (goto-char from)
2391 (gnus-add-wash-type 'face)
2392 (gnus-add-image 'face image)
2393 (gnus-put-image image nil 'face))))))))))
2394
2395 (defun article-display-x-face (&optional force)
2396 "Look for an X-Face header and display it if present."
2397 (interactive (list 'force))
2398 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2399 (gnus-with-article-headers
2400 ;; Delete the old process, if any.
2401 (when (process-status "article-x-face")
2402 (delete-process "article-x-face"))
2403 ;; See the comment in `article-display-face'.
2404 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2405 ;; We have already displayed X-Faces, so we remove them
2406 ;; instead.
2407 (gnus-delete-images 'xface)
2408 ;; Display X-Faces.
2409 (let ((from (message-fetch-field "from"))
2410 x-faces face)
2411 (save-current-buffer
2412 (when (and wash-face-p
2413 (gnus-buffer-live-p gnus-original-article-buffer)
2414 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2415 ;; If type `W f', use gnus-original-article-buffer,
2416 ;; otherwise use the current buffer because displaying
2417 ;; RFC822 parts calls this function too.
2418 (set-buffer gnus-original-article-buffer))
2419 (save-restriction
2420 (mail-narrow-to-head)
2421 (and gnus-article-x-face-command
2422 (or force
2423 ;; Check whether this face is censored.
2424 (not (and gnus-article-x-face-too-ugly
2425 (or from
2426 (setq from (message-fetch-field "from")))
2427 (string-match gnus-article-x-face-too-ugly
2428 from))))
2429 (while (gnus-article-goto-header "X-Face")
2430 (push (mail-header-field-value) x-faces)))))
2431 (when x-faces
2432 ;; We display the face.
2433 (cond ((functionp gnus-article-x-face-command)
2434 ;; The command is a lisp function, so we call it.
2435 (mapc gnus-article-x-face-command x-faces))
2436 ((stringp gnus-article-x-face-command)
2437 ;; The command is a string, so we interpret the command
2438 ;; as a, well, command, and fork it off.
2439 (let ((process-connection-type nil))
2440 (gnus-set-process-query-on-exit-flag
2441 (start-process
2442 "article-x-face" nil shell-file-name
2443 shell-command-switch gnus-article-x-face-command)
2444 nil)
2445 ;; Sending multiple EOFs to xv doesn't work,
2446 ;; so we only do a single external face.
2447 (with-temp-buffer
2448 (insert (car x-faces))
2449 (process-send-region "article-x-face"
2450 (point-min) (point-max)))
2451 (process-send-eof "article-x-face")))
2452 (t
2453 (error "`%s' set to `%s' is not a function"
2454 gnus-article-x-face-command
2455 'gnus-article-x-face-command)))))))))
2456
2457 (defun article-decode-mime-words ()
2458 "Decode all MIME-encoded words in the article."
2459 (interactive)
2460 (gnus-with-article-buffer
2461 (let ((inhibit-point-motion-hooks t)
2462 (mail-parse-charset gnus-newsgroup-charset)
2463 (mail-parse-ignored-charsets
2464 (with-current-buffer gnus-summary-buffer
2465 gnus-newsgroup-ignored-charsets)))
2466 (mail-decode-encoded-word-region (point-min) (point-max)))))
2467
2468 (defun article-decode-charset (&optional prompt)
2469 "Decode charset-encoded text in the article.
2470 If PROMPT (the prefix), prompt for a coding system to use."
2471 (interactive "P")
2472 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2473 (inhibit-read-only t)
2474 (mail-parse-charset gnus-newsgroup-charset)
2475 (mail-parse-ignored-charsets
2476 (save-excursion (condition-case nil
2477 (set-buffer gnus-summary-buffer)
2478 (error))
2479 gnus-newsgroup-ignored-charsets))
2480 ct cte ctl charset format)
2481 (save-excursion
2482 (save-restriction
2483 (article-narrow-to-head)
2484 (setq ct (message-fetch-field "Content-Type" t)
2485 cte (message-fetch-field "Content-Transfer-Encoding" t)
2486 ctl (and ct (mail-header-parse-content-type ct))
2487 charset (cond
2488 (prompt
2489 (mm-read-coding-system "Charset to decode: "))
2490 (ctl
2491 (mail-content-type-get ctl 'charset)))
2492 format (and ctl (mail-content-type-get ctl 'format)))
2493 (when cte
2494 (setq cte (mail-header-strip cte)))
2495 (if (and ctl (not (string-match "/" (car ctl))))
2496 (setq ctl nil))
2497 (goto-char (point-max)))
2498 (forward-line 1)
2499 (save-restriction
2500 (narrow-to-region (point) (point-max))
2501 (when (and (eq mail-parse-charset 'gnus-decoded)
2502 (eq (mm-body-7-or-8) '8bit))
2503 ;; The text code could have been decoded.
2504 (setq charset mail-parse-charset))
2505 (when (and (or (not ctl)
2506 (equal (car ctl) "text/plain"))
2507 (not format)) ;; article with format will decode later.
2508 (mm-decode-body
2509 charset (and cte (intern (downcase
2510 (gnus-strip-whitespace cte))))
2511 (car ctl)))))))
2512
2513 (defun article-decode-encoded-words ()
2514 "Remove encoded-word encoding from headers."
2515 (let ((inhibit-point-motion-hooks t)
2516 (mail-parse-charset gnus-newsgroup-charset)
2517 (mail-parse-ignored-charsets
2518 (save-excursion (condition-case nil
2519 (set-buffer gnus-summary-buffer)
2520 (error))
2521 gnus-newsgroup-ignored-charsets))
2522 (inhibit-read-only t)
2523 end start)
2524 (goto-char (point-min))
2525 (when (search-forward "\n\n" nil 'move)
2526 (forward-line -1))
2527 (setq end (point))
2528 (while (not (bobp))
2529 (while (progn
2530 (forward-line -1)
2531 (and (not (bobp))
2532 (memq (char-after) '(?\t ? )))))
2533 (setq start (point))
2534 (if (looking-at "\
2535 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2536 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2537 (funcall gnus-decode-address-function start end)
2538 (funcall gnus-decode-header-function start end))
2539 (goto-char (setq end start)))))
2540
2541 (defun article-decode-group-name ()
2542 "Decode group names in Newsgroups, Followup-To and Xref headers."
2543 (let ((inhibit-point-motion-hooks t)
2544 (inhibit-read-only t)
2545 (method (gnus-find-method-for-group gnus-newsgroup-name))
2546 regexp)
2547 (when (and (or gnus-group-name-charset-method-alist
2548 gnus-group-name-charset-group-alist)
2549 (gnus-buffer-live-p gnus-original-article-buffer))
2550 (save-restriction
2551 (article-narrow-to-head)
2552 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2553 (with-current-buffer gnus-original-article-buffer
2554 (goto-char (point-min)))
2555 (setq regexp (concat "^" header
2556 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2557 (while (re-search-forward regexp nil t)
2558 (replace-match (save-match-data
2559 (gnus-decode-newsgroups
2560 ;; XXX how to use data in article buffer?
2561 (with-current-buffer gnus-original-article-buffer
2562 (re-search-forward regexp nil t)
2563 (match-string 1))
2564 gnus-newsgroup-name method))
2565 t t nil 1))
2566 (goto-char (point-min)))))))
2567
2568 (autoload 'idna-to-unicode "idna")
2569
2570 (defun article-decode-idna-rhs ()
2571 "Decode IDNA strings in RHS in various headers in current buffer.
2572 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2573 Mail-Reply-To: and Mail-Followup-To:."
2574 (when gnus-use-idna
2575 (save-restriction
2576 (let ((inhibit-point-motion-hooks t)
2577 (inhibit-read-only t))
2578 (article-narrow-to-head)
2579 (goto-char (point-min))
2580 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2581 (let (ace unicode)
2582 (when (save-match-data
2583 (and (setq ace (match-string 1))
2584 (save-excursion
2585 (and (re-search-backward "^[^ \t]" nil t)
2586 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2587 (setq unicode (idna-to-unicode ace))))
2588 (unless (string= ace unicode)
2589 (replace-match unicode nil nil nil 1)))))))))
2590
2591 (defun article-de-quoted-unreadable (&optional force read-charset)
2592 "Translate a quoted-printable-encoded article.
2593 If FORCE, decode the article whether it is marked as quoted-printable
2594 or not.
2595 If READ-CHARSET, ask for a coding system."
2596 (interactive (list 'force current-prefix-arg))
2597 (save-excursion
2598 (let ((inhibit-read-only t) type charset)
2599 (if (gnus-buffer-live-p gnus-original-article-buffer)
2600 (with-current-buffer gnus-original-article-buffer
2601 (setq type
2602 (gnus-fetch-field "content-transfer-encoding"))
2603 (let* ((ct (gnus-fetch-field "content-type"))
2604 (ctl (and ct (mail-header-parse-content-type ct))))
2605 (setq charset (and ctl
2606 (mail-content-type-get ctl 'charset)))
2607 (if (stringp charset)
2608 (setq charset (intern (downcase charset)))))))
2609 (if read-charset
2610 (setq charset (mm-read-coding-system "Charset: " charset)))
2611 (unless charset
2612 (setq charset gnus-newsgroup-charset))
2613 (when (or force
2614 (and type (let ((case-fold-search t))
2615 (string-match "quoted-printable" type))))
2616 (article-goto-body)
2617 (quoted-printable-decode-region
2618 (point) (point-max) (mm-charset-to-coding-system charset))))))
2619
2620 (defun article-de-base64-unreadable (&optional force read-charset)
2621 "Translate a base64 article.
2622 If FORCE, decode the article whether it is marked as base64 not.
2623 If READ-CHARSET, ask for a coding system."
2624 (interactive (list 'force current-prefix-arg))
2625 (save-excursion
2626 (let ((inhibit-read-only t) type charset)
2627 (if (gnus-buffer-live-p gnus-original-article-buffer)
2628 (with-current-buffer gnus-original-article-buffer
2629 (setq type
2630 (gnus-fetch-field "content-transfer-encoding"))
2631 (let* ((ct (gnus-fetch-field "content-type"))
2632 (ctl (and ct (mail-header-parse-content-type ct))))
2633 (setq charset (and ctl
2634 (mail-content-type-get ctl 'charset)))
2635 (if (stringp charset)
2636 (setq charset (intern (downcase charset)))))))
2637 (if read-charset
2638 (setq charset (mm-read-coding-system "Charset: " charset)))
2639 (unless charset
2640 (setq charset gnus-newsgroup-charset))
2641 (when (or force
2642 (and type (let ((case-fold-search t))
2643 (string-match "base64" type))))
2644 (article-goto-body)
2645 (save-restriction
2646 (narrow-to-region (point) (point-max))
2647 (base64-decode-region (point-min) (point-max))
2648 (mm-decode-coding-region
2649 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2650
2651 (eval-when-compile
2652 (require 'rfc1843))
2653
2654 (defun article-decode-HZ ()
2655 "Translate a HZ-encoded article."
2656 (interactive)
2657 (require 'rfc1843)
2658 (save-excursion
2659 (let ((inhibit-read-only t))
2660 (rfc1843-decode-region (point-min) (point-max)))))
2661
2662 (defun article-unsplit-urls ()
2663 "Remove the newlines that some other mailers insert into URLs."
2664 (interactive)
2665 (save-excursion
2666 (let ((inhibit-read-only t))
2667 (goto-char (point-min))
2668 (while (re-search-forward
2669 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2670 (replace-match "\\1\\3" t)))
2671 (when (interactive-p)
2672 (gnus-treat-article nil))))
2673
2674
2675 (defun article-wash-html (&optional read-charset)
2676 "Format an HTML article.
2677 If READ-CHARSET, ask for a coding system. If it is a number, the
2678 charset defined in `gnus-summary-show-article-charset-alist' is used."
2679 (interactive "P")
2680 (save-excursion
2681 (let ((inhibit-read-only t)
2682 charset)
2683 (if read-charset
2684 (if (or (and (numberp read-charset)
2685 (setq charset
2686 (cdr
2687 (assq read-charset
2688 gnus-summary-show-article-charset-alist))))
2689 (setq charset (mm-read-coding-system "Charset: ")))
2690 (let ((gnus-summary-show-article-charset-alist
2691 (list (cons 1 charset))))
2692 (with-current-buffer gnus-summary-buffer
2693 (gnus-summary-show-article 1)))
2694 (error "No charset is given"))
2695 (when (gnus-buffer-live-p gnus-original-article-buffer)
2696 (with-current-buffer gnus-original-article-buffer
2697 (let* ((ct (gnus-fetch-field "content-type"))
2698 (ctl (and ct (mail-header-parse-content-type ct))))
2699 (setq charset (and ctl
2700 (mail-content-type-get ctl 'charset)))
2701 (when (stringp charset)
2702 (setq charset (intern (downcase charset)))))))
2703 (unless charset
2704 (setq charset gnus-newsgroup-charset)))
2705 (article-goto-body)
2706 (save-window-excursion
2707 (save-restriction
2708 (narrow-to-region (point) (point-max))
2709 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2710 (entry (assq func mm-text-html-washer-alist)))
2711 (when entry
2712 (setq func (cdr entry)))
2713 (cond
2714 ((functionp func)
2715 (funcall func))
2716 (t
2717 (apply (car func) (cdr func))))))))))
2718
2719 ;; External.
2720 (declare-function w3-region "ext:w3-display" (st nd))
2721
2722 (defun gnus-article-wash-html-with-w3 ()
2723 "Wash the current buffer with w3."
2724 (mm-setup-w3)
2725 (let ((w3-strict-width (window-width))
2726 (url-standalone-mode t)
2727 (url-gateway-unplugged t)
2728 (w3-honor-stylesheets nil))
2729 (condition-case ()
2730 (w3-region (point-min) (point-max))
2731 (error))))
2732
2733 ;; External.
2734 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2735
2736 (defun gnus-article-wash-html-with-w3m ()
2737 "Wash the current buffer with emacs-w3m."
2738 (mm-setup-w3m)
2739 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2740 w3m-force-redisplay)
2741 (w3m-region (point-min) (point-max)))
2742 ;; Put the mark meaning this part was rendered by emacs-w3m.
2743 (put-text-property (point-min) (point-max) 'mm-inline-text-html-with-w3m t)
2744 (when (and mm-inline-text-html-with-w3m-keymap
2745 (boundp 'w3m-minor-mode-map)
2746 w3m-minor-mode-map)
2747 (if (and (boundp 'w3m-link-map)
2748 w3m-link-map)
2749 (let* ((start (point-min))
2750 (end (point-max))
2751 (on (get-text-property start 'w3m-href-anchor))
2752 (map (copy-keymap w3m-link-map))
2753 next)
2754 (set-keymap-parent map w3m-minor-mode-map)
2755 (while (< start end)
2756 (if on
2757 (progn
2758 (setq next (or (text-property-any start end
2759 'w3m-href-anchor nil)
2760 end))
2761 (put-text-property start next 'keymap map))
2762 (setq next (or (text-property-not-all start end
2763 'w3m-href-anchor nil)
2764 end))
2765 (put-text-property start next 'keymap w3m-minor-mode-map))
2766 (setq start next
2767 on (not on))))
2768 (put-text-property (point-min) (point-max) 'keymap w3m-minor-mode-map))))
2769
2770 (defvar charset) ;; Bound by `article-wash-html'.
2771
2772 (defun gnus-article-wash-html-with-w3m-standalone ()
2773 "Wash the current buffer with w3m."
2774 (if (mm-w3m-standalone-supports-m17n-p)
2775 (progn
2776 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2777 ;; The default.
2778 (setq charset 'iso-8859-1))
2779 (let ((coding-system-for-write charset)
2780 (coding-system-for-read charset))
2781 (call-process-region
2782 (point-min) (point-max)
2783 "w3m" t t nil "-dump" "-T" "text/html"
2784 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2785 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2786
2787 (defvar gnus-article-browse-html-temp-list nil
2788 "List of temporary files created by `gnus-article-browse-html-parts'.
2789 Internal variable.")
2790
2791 (defcustom gnus-article-browse-delete-temp 'ask
2792 "What to do with temporary files from `gnus-article-browse-html-parts'.
2793 If nil, don't delete temporary files. If it is t, delete them on
2794 exit from the summary buffer. If it is the symbol `file', query
2795 on each file, if it is `ask' ask once when exiting from the
2796 summary buffer."
2797 :group 'gnus-article
2798 :version "23.1" ;; No Gnus
2799 :type '(choice (const :tag "Don't delete" nil)
2800 (const :tag "Don't ask" t)
2801 (const :tag "Ask" ask)
2802 (const :tag "Ask for each file" file)))
2803
2804 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2805
2806 (defun gnus-article-browse-delete-temp-files (&optional how)
2807 "Delete temp-files created by `gnus-article-browse-html-parts'."
2808 (when (and gnus-article-browse-html-temp-list
2809 (or how
2810 (setq how gnus-article-browse-delete-temp)))
2811 (when (and (eq how 'ask)
2812 (gnus-y-or-n-p (format
2813 "Delete all %s temporary HTML file(s)? "
2814 (length gnus-article-browse-html-temp-list)))
2815 (setq how t)))
2816 (dolist (file gnus-article-browse-html-temp-list)
2817 (when (and (file-exists-p file)
2818 (or (eq how t)
2819 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2820 (gnus-y-or-n-p
2821 (format "Delete temporary HTML file `%s'? " file))))
2822 (if (file-directory-p file)
2823 (gnus-delete-directory file)
2824 (delete-file file))))
2825 ;; Also remove file from the list when not deleted or if file doesn't
2826 ;; exist anymore.
2827 (setq gnus-article-browse-html-temp-list nil))
2828 gnus-article-browse-html-temp-list)
2829
2830 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2831 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2832 Return file name."
2833 (save-match-data
2834 (let (file type)
2835 (catch 'found
2836 (dolist (handle handles)
2837 (cond
2838 ((not (listp handle)))
2839 ((equal (mm-handle-media-supertype handle) "multipart")
2840 (when (setq file (gnus-article-browse-html-save-cid-content
2841 cid handle directory))
2842 (throw 'found file)))
2843 ((equal (concat "<" cid ">") (mm-handle-id handle))
2844 (setq file
2845 (expand-file-name
2846 (or (mail-content-type-get
2847 (mm-handle-disposition handle) 'filename)
2848 (mail-content-type-get
2849 (setq type (mm-handle-type handle)) 'name)
2850 (concat
2851 (make-temp-name "cid")
2852 (car (rassoc (car type) mailcap-mime-extensions))))
2853 directory))
2854 (mm-save-part-to-file handle file)
2855 (throw 'found file))))))))
2856
2857 (defun gnus-article-browse-html-parts (list &optional header)
2858 "View all \"text/html\" parts from LIST.
2859 Recurse into multiparts. The optional HEADER that should be a decoded
2860 message header will be added to the bodies of the \"text/html\" parts."
2861 ;; Internal function used by `gnus-article-browse-html-article'.
2862 (let (type file charset content cid-dir tmp-file showed)
2863 ;; Find and show the html-parts.
2864 (dolist (handle list)
2865 ;; If HTML, show it:
2866 (cond ((not (listp handle)))
2867 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2868 (and (equal (car type) "message/external-body")
2869 (or header
2870 (setq file (or (mail-content-type-get type 'name)
2871 (mail-content-type-get
2872 (mm-handle-disposition handle)
2873 'filename))))
2874 (or (mm-handle-cache handle)
2875 (condition-case code
2876 (progn (mm-extern-cache-contents handle) t)
2877 (error
2878 (gnus-message 3 "%s" (error-message-string code))
2879 (when (>= gnus-verbose 3) (sit-for 2))
2880 nil)))
2881 (progn
2882 (setq handle (mm-handle-cache handle)
2883 type (mm-handle-type handle))
2884 (equal (car type) "text/html"))))
2885 (setq charset (mail-content-type-get type 'charset)
2886 content (mm-get-part handle))
2887 (with-temp-buffer
2888 (if (eq charset 'gnus-decoded)
2889 (mm-enable-multibyte)
2890 (mm-disable-multibyte))
2891 (insert content)
2892 ;; resolve cid contents
2893 (let ((case-fold-search t)
2894 cid-file)
2895 (goto-char (point-min))
2896 (while (re-search-forward "\
2897 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2898 nil t)
2899 (unless cid-dir
2900 (setq cid-dir (mm-make-temp-file "cid" t))
2901 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2902 (setq file nil
2903 content nil)
2904 (when (setq cid-file
2905 (gnus-article-browse-html-save-cid-content
2906 (match-string 2)
2907 (with-current-buffer gnus-article-buffer
2908 gnus-article-mime-handles)
2909 cid-dir))
2910 (replace-match (concat "file://" cid-file)
2911 nil nil nil 1))))
2912 (unless content (setq content (buffer-string))))
2913 (when (or charset header (not file))
2914 (setq tmp-file (mm-make-temp-file
2915 ;; Do we need to care for 8.3 filenames?
2916 "mm-" nil ".html")))
2917 ;; Add a meta html tag to specify charset and a header.
2918 (cond
2919 (header
2920 (let (title eheader body hcharset coding force-charset)
2921 (with-temp-buffer
2922 (mm-enable-multibyte)
2923 (setq case-fold-search t)
2924 (insert header "\n")
2925 (setq title (message-fetch-field "subject"))
2926 (goto-char (point-min))
2927 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2928 (replace-match (cond ((match-beginning 1) "&lt;")
2929 ((match-beginning 2) "&gt;")
2930 (t "&amp;"))))
2931 (goto-char (point-min))
2932 (insert "<pre>\n")
2933 (goto-char (point-max))
2934 (insert "</pre>\n<hr>\n")
2935 ;; We have to examine charset one by one since
2936 ;; charset specified in parts might be different.
2937 (if (eq charset 'gnus-decoded)
2938 (setq charset 'utf-8
2939 eheader (mm-encode-coding-string (buffer-string)
2940 charset)
2941 title (when title
2942 (mm-encode-coding-string title charset))
2943 body (mm-encode-coding-string content charset)
2944 force-charset t)
2945 (setq hcharset (mm-find-mime-charset-region (point-min)
2946 (point-max)))
2947 (cond ((= (length hcharset) 1)
2948 (setq hcharset (car hcharset)
2949 coding (mm-charset-to-coding-system
2950 hcharset)))
2951 ((> (length hcharset) 1)
2952 (setq hcharset 'utf-8
2953 coding hcharset)))
2954 (if coding
2955 (if charset
2956 (progn
2957 (setq body
2958 (mm-charset-to-coding-system charset))
2959 (if (eq coding body)
2960 (setq eheader (mm-encode-coding-string
2961 (buffer-string) coding)
2962 title (when title
2963 (mm-encode-coding-string
2964 title coding))
2965 body content)
2966 (setq charset 'utf-8
2967 eheader (mm-encode-coding-string
2968 (buffer-string) charset)
2969 title (when title
2970 (mm-encode-coding-string
2971 title charset))
2972 body (mm-encode-coding-string
2973 (mm-decode-coding-string
2974 content body)
2975 charset)
2976 force-charset t)))
2977 (setq charset hcharset
2978 eheader (mm-encode-coding-string
2979 (buffer-string) coding)
2980 title (when title
2981 (mm-encode-coding-string
2982 title coding))
2983 body content))
2984 (setq eheader (mm-string-as-unibyte (buffer-string))
2985 body content)))
2986 (erase-buffer)
2987 (mm-disable-multibyte)
2988 (insert body)
2989 (when charset
2990 (mm-add-meta-html-tag handle charset force-charset))
2991 (when title
2992 (goto-char (point-min))
2993 (unless (search-forward "<title>" nil t)
2994 (re-search-forward "<head>\\s-*" nil t)
2995 (insert "<title>" title "</title>\n")))
2996 (goto-char (point-min))
2997 (or (re-search-forward
2998 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2999 (re-search-forward
3000 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
3001 (insert eheader)
3002 (mm-write-region (point-min) (point-max)
3003 tmp-file nil nil nil 'binary t))))
3004 (charset
3005 (mm-with-unibyte-buffer
3006 (insert (if (eq charset 'gnus-decoded)
3007 (mm-encode-coding-string content
3008 (setq charset 'utf-8))
3009 content))
3010 (if (or (mm-add-meta-html-tag handle charset)
3011 (not file))
3012 (mm-write-region (point-min) (point-max)
3013 tmp-file nil nil nil 'binary t)
3014 (setq tmp-file nil))))
3015 (tmp-file
3016 (mm-save-part-to-file handle tmp-file)))
3017 (when tmp-file
3018 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3019 (add-hook 'gnus-summary-prepare-exit-hook
3020 'gnus-article-browse-delete-temp-files)
3021 (add-hook 'gnus-exit-gnus-hook
3022 (lambda ()
3023 (gnus-article-browse-delete-temp-files t)))
3024 ;; FIXME: Warn if there's an <img> tag?
3025 (browse-url-of-file (or tmp-file (expand-file-name file)))
3026 (setq showed t))
3027 ;; If multipart, recurse
3028 ((equal (mm-handle-media-supertype handle) "multipart")
3029 (when (gnus-article-browse-html-parts handle header)
3030 (setq showed t)))
3031 ((equal (mm-handle-media-type handle) "message/rfc822")
3032 (mm-with-multibyte-buffer
3033 (mm-insert-part handle)
3034 (setq handle (mm-dissect-buffer t t))
3035 (when (and (bufferp (car handle))
3036 (stringp (car (mm-handle-type handle))))
3037 (setq handle (list handle)))
3038 (when header
3039 (article-decode-encoded-words)
3040 (let ((gnus-visible-headers
3041 (or (get 'gnus-visible-headers 'standard-value)
3042 gnus-visible-headers)))
3043 (article-hide-headers))
3044 (goto-char (point-min))
3045 (search-forward "\n\n" nil 'move)
3046 (skip-chars-backward "\t\n ")
3047 (setq header (buffer-substring (point-min) (point)))))
3048 (when (prog1
3049 (gnus-article-browse-html-parts handle header)
3050 (mm-destroy-parts handle))
3051 (setq showed t)))))
3052 showed))
3053
3054 (defun gnus-article-browse-html-article (&optional arg)
3055 "View \"text/html\" parts of the current article with a WWW browser.
3056 Inline images embedded in a message using the cid scheme, as they are
3057 generally considered to be safe, will be processed properly.
3058 The message header is added to the beginning of every html part unless
3059 the prefix argument ARG is given.
3060
3061 Warning: Spammers use links to images (using the http scheme) in HTML
3062 articles to verify whether you have read the message. As
3063 `gnus-article-browse-html-article' passes the HTML content to the
3064 browser without eliminating these \"web bugs\" you should only
3065 use it for mails from trusted senders.
3066
3067 If you always want to display HTML parts in the browser, set
3068 `mm-text-html-renderer' to nil.
3069
3070 This command creates temporary files to pass HTML contents including
3071 images if any to the browser, and deletes them when exiting the group
3072 \(if you want)."
3073 ;; Cf. `mm-w3m-safe-url-regexp'
3074 (interactive "P")
3075 (if arg
3076 (gnus-summary-show-article)
3077 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3078 gnus-visible-headers))
3079 ;; As we insert a <hr>, there's no need for the body boundary.
3080 (gnus-treat-body-boundary nil))
3081 (gnus-summary-show-article)))
3082 (with-current-buffer gnus-article-buffer
3083 (let ((header (unless arg
3084 (save-restriction
3085 (widen)
3086 (buffer-substring-no-properties
3087 (goto-char (point-min))
3088 (if (search-forward "\n\n" nil t)
3089 (match-beginning 0)
3090 (goto-char (point-max))
3091 (skip-chars-backward "\t\n ")
3092 (point))))))
3093 parts)
3094 (set-buffer gnus-original-article-buffer)
3095 (setq parts (mm-dissect-buffer t t))
3096 ;; If singlepart, enforce a list.
3097 (when (and (bufferp (car parts))
3098 (stringp (car (mm-handle-type parts))))
3099 (setq parts (list parts)))
3100 ;; Process the list
3101 (unless (gnus-article-browse-html-parts parts header)
3102 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3103 (mm-destroy-parts parts)
3104 (unless arg
3105 (gnus-summary-show-article)))))
3106
3107 (defun article-hide-list-identifiers ()
3108 "Remove list identifies from the Subject header.
3109 The `gnus-list-identifiers' variable specifies what to do."
3110 (interactive)
3111 (let ((inhibit-point-motion-hooks t)
3112 (regexp (if (consp gnus-list-identifiers)
3113 (mapconcat 'identity gnus-list-identifiers " *\\|")
3114 gnus-list-identifiers))
3115 (inhibit-read-only t))
3116 (when regexp
3117 (save-excursion
3118 (save-restriction
3119 (article-narrow-to-head)
3120 (goto-char (point-min))
3121 (while (re-search-forward
3122 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3123 nil t)
3124 (delete-region (match-beginning 2) (match-end 0))
3125 (beginning-of-line))
3126 (when (re-search-forward
3127 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3128 (delete-region (match-beginning 1) (match-end 1))))))))
3129
3130 (defun article-hide-pem (&optional arg)
3131 "Toggle hiding of any PEM headers and signatures 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 'pem arg)
3136 (save-excursion
3137 (let ((inhibit-read-only t) end)
3138 (goto-char (point-min))
3139 ;; Hide the horrendously ugly "header".
3140 (when (and (search-forward
3141 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3142 nil t)
3143 (setq end (1+ (match-beginning 0))))
3144 (gnus-add-wash-type 'pem)
3145 (gnus-article-hide-text-type
3146 end
3147 (if (search-forward "\n\n" nil t)
3148 (match-end 0)
3149 (point-max))
3150 'pem)
3151 ;; Hide the trailer as well
3152 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3153 nil t)
3154 (gnus-article-hide-text-type
3155 (match-beginning 0) (match-end 0) 'pem)))))))
3156
3157 (defun article-strip-banner ()
3158 "Strip the banners specified by the `banner' group parameter and by
3159 `gnus-article-address-banner-alist'."
3160 (interactive)
3161 (save-excursion
3162 (save-restriction
3163 (let ((inhibit-point-motion-hooks t))
3164 (when (gnus-parameter-banner gnus-newsgroup-name)
3165 (article-really-strip-banner
3166 (gnus-parameter-banner gnus-newsgroup-name)))
3167 (when gnus-article-address-banner-alist
3168 ;; Note that the From header is decoded here, so it is
3169 ;; required that the *-extract-address-components function
3170 ;; supports non-ASCII text.
3171 (let ((from (save-restriction
3172 (widen)
3173 (article-narrow-to-head)
3174 (mail-fetch-field "from"))))
3175 (when (and from
3176 (setq from
3177 (cadr (funcall gnus-extract-address-components
3178 from))))
3179 (catch 'found
3180 (dolist (pair gnus-article-address-banner-alist)
3181 (when (string-match (car pair) from)
3182 (throw 'found
3183 (article-really-strip-banner (cdr pair)))))))))))))
3184
3185 (defun article-really-strip-banner (banner)
3186 "Strip the banner specified by the argument."
3187 (save-excursion
3188 (save-restriction
3189 (let ((inhibit-point-motion-hooks t)
3190 (gnus-signature-limit nil)
3191 (inhibit-read-only t))
3192 (article-goto-body)
3193 (cond
3194 ((eq banner 'signature)
3195 (when (gnus-article-narrow-to-signature)
3196 (widen)
3197 (forward-line -1)
3198 (delete-region (point) (point-max))))
3199 ((symbolp banner)
3200 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3201 (while (re-search-forward banner nil t)
3202 (delete-region (match-beginning 0) (match-end 0)))))
3203 ((stringp banner)
3204 (while (re-search-forward banner nil t)
3205 (delete-region (match-beginning 0) (match-end 0)))))))))
3206
3207 (defun article-babel ()
3208 "Translate article using an online translation service."
3209 (interactive)
3210 (require 'babel)
3211 (gnus-with-article-buffer
3212 (when (article-goto-body)
3213 (let* ((start (point))
3214 (end (point-max))
3215 (orig (buffer-substring start end))
3216 (trans (babel-as-string orig)))
3217 (save-restriction
3218 (narrow-to-region start end)
3219 (delete-region start end)
3220 (insert trans))))))
3221
3222 (defun article-hide-signature (&optional arg)
3223 "Hide the signature in the current article.
3224 If given a negative prefix, always show; if given a positive prefix,
3225 always hide."
3226 (interactive (gnus-article-hidden-arg))
3227 (unless (gnus-article-check-hidden-text 'signature arg)
3228 (save-excursion
3229 (save-restriction
3230 (let ((inhibit-read-only t))
3231 (when (gnus-article-narrow-to-signature)
3232 (gnus-article-hide-text-type
3233 (point-min) (point-max) 'signature))))))
3234 (gnus-set-mode-line 'article))
3235
3236 (defun article-strip-headers-in-body ()
3237 "Strip offensive headers from bodies."
3238 (interactive)
3239 (save-excursion
3240 (article-goto-body)
3241 (let ((case-fold-search t))
3242 (when (looking-at "x-no-archive:")
3243 (gnus-delete-line)))))
3244
3245 (defun article-strip-leading-blank-lines ()
3246 "Remove all blank lines from the beginning of the article."
3247 (interactive)
3248 (save-excursion
3249 (let ((inhibit-point-motion-hooks t)
3250 (inhibit-read-only t))
3251 (when (article-goto-body)
3252 (while (and (not (eobp))
3253 (looking-at "[ \t]*$"))
3254 (gnus-delete-line))))))
3255
3256 (defun article-narrow-to-head ()
3257 "Narrow the buffer to the head of the message.
3258 Point is left at the beginning of the narrowed-to region."
3259 (narrow-to-region
3260 (goto-char (point-min))
3261 (if (search-forward "\n\n" nil 1)
3262 (1- (point))
3263 (point-max)))
3264 (goto-char (point-min)))
3265
3266 (defun article-goto-body ()
3267 "Place point at the start of the body."
3268 (goto-char (point-min))
3269 (cond
3270 ;; This variable is only bound when dealing with separate
3271 ;; MIME body parts.
3272 (article-goto-body-goes-to-point-min-p
3273 t)
3274 ((search-forward "\n\n" nil t)
3275 t)
3276 (t
3277 (goto-char (point-max))
3278 nil)))
3279
3280 (defun article-strip-multiple-blank-lines ()
3281 "Replace consecutive blank lines with one empty line."
3282 (interactive)
3283 (save-excursion
3284 (let ((inhibit-point-motion-hooks t)
3285 (inhibit-read-only t))
3286 ;; First make all blank lines empty.
3287 (article-goto-body)
3288 (while (re-search-forward "^[ \t]+$" nil t)
3289 (unless (gnus-annotation-in-region-p
3290 (match-beginning 0) (match-end 0))
3291 (replace-match "" nil t)))
3292 ;; Then replace multiple empty lines with a single empty line.
3293 (article-goto-body)
3294 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3295 (unless (gnus-annotation-in-region-p
3296 (match-beginning 0) (match-end 0))
3297 (delete-region (match-beginning 1) (match-end 1)))))))
3298
3299 (defun article-strip-leading-space ()
3300 "Remove all white space from the beginning of the lines in the article."
3301 (interactive)
3302 (save-excursion
3303 (let ((inhibit-point-motion-hooks t)
3304 (inhibit-read-only t))
3305 (article-goto-body)
3306 (while (re-search-forward "^[ \t]+" nil t)
3307 (replace-match "" t t)))))
3308
3309 (defun article-strip-trailing-space ()
3310 "Remove all white space from the end of the lines in the article."
3311 (interactive)
3312 (save-excursion
3313 (let ((inhibit-point-motion-hooks t)
3314 (inhibit-read-only t))
3315 (article-goto-body)
3316 (while (re-search-forward "[ \t]+$" nil t)
3317 (replace-match "" t t)))))
3318
3319 (defun article-strip-blank-lines ()
3320 "Strip leading, trailing and multiple blank lines."
3321 (interactive)
3322 (article-strip-leading-blank-lines)
3323 (article-remove-trailing-blank-lines)
3324 (article-strip-multiple-blank-lines))
3325
3326 (defun article-strip-all-blank-lines ()
3327 "Strip all blank lines."
3328 (interactive)
3329 (save-excursion
3330 (let ((inhibit-point-motion-hooks t)
3331 (inhibit-read-only t))
3332 (article-goto-body)
3333 (while (re-search-forward "^[ \t]*\n" nil t)
3334 (replace-match "" t t)))))
3335
3336 (defun gnus-article-narrow-to-signature ()
3337 "Narrow to the signature; return t if a signature is found, else nil."
3338 (let ((inhibit-point-motion-hooks t))
3339 (when (gnus-article-search-signature)
3340 (forward-line 1)
3341 ;; Check whether we have some limits to what we consider
3342 ;; to be a signature.
3343 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3344 (list gnus-signature-limit)))
3345 limit limited)
3346 (while (setq limit (pop limits))
3347 (if (or (and (integerp limit)
3348 (< (- (point-max) (point)) limit))
3349 (and (floatp limit)
3350 (< (count-lines (point) (point-max)) limit))
3351 (and (functionp limit)
3352 (funcall limit))
3353 (and (stringp limit)
3354 (not (re-search-forward limit nil t))))
3355 () ; This limit did not succeed.
3356 (setq limited t
3357 limits nil)))
3358 (unless limited
3359 (narrow-to-region (point) (point-max))
3360 t)))))
3361
3362 (defun gnus-article-search-signature ()
3363 "Search the current buffer for the signature separator.
3364 Put point at the beginning of the signature separator."
3365 (let ((cur (point)))
3366 (goto-char (point-max))
3367 (if (if (stringp gnus-signature-separator)
3368 (re-search-backward gnus-signature-separator nil t)
3369 (let ((seps gnus-signature-separator))
3370 (while (and seps
3371 (not (re-search-backward (car seps) nil t)))
3372 (pop seps))
3373 seps))
3374 t
3375 (goto-char cur)
3376 nil)))
3377
3378 (defun gnus-article-hidden-arg ()
3379 "Return the current prefix arg as a number, or 0 if no prefix."
3380 (list (if current-prefix-arg
3381 (prefix-numeric-value current-prefix-arg)
3382 0)))
3383
3384 (defun gnus-article-check-hidden-text (type arg)
3385 "Return nil if hiding is necessary.
3386 Arg can be nil or a number. nil and positive means hide, negative
3387 means show, 0 means toggle."
3388 (save-excursion
3389 (save-restriction
3390 (let ((hide (gnus-article-hidden-text-p type)))
3391 (cond
3392 ((or (null arg)
3393 (> arg 0))
3394 nil)
3395 ((< arg 0)
3396 (gnus-article-show-hidden-text type)
3397 t)
3398 (t
3399 (if (eq hide 'hidden)
3400 (progn
3401 (gnus-article-show-hidden-text type)
3402 t)
3403 nil)))))))
3404
3405 (defun gnus-article-hidden-text-p (type)
3406 "Say whether the current buffer contains hidden text of type TYPE."
3407 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3408 (while (and pos
3409 (not (get-text-property pos 'invisible))
3410 (not (get-text-property pos 'dummy-invisible)))
3411 (setq pos
3412 (text-property-any (1+ pos) (point-max) 'article-type type)))
3413 (if pos
3414 'hidden
3415 nil)))
3416
3417 (defun gnus-article-show-hidden-text (type &optional dummy)
3418 "Show all hidden text of type TYPE.
3419 Originally it is hide instead of DUMMY."
3420 (let ((inhibit-read-only t)
3421 (inhibit-point-motion-hooks t))
3422 (gnus-remove-text-properties-when
3423 'article-type type
3424 (point-min) (point-max)
3425 (cons 'article-type (cons type
3426 gnus-hidden-properties)))
3427 (gnus-delete-wash-type type)))
3428
3429 (defconst article-time-units
3430 `((year . ,(* 365.25 24 60 60))
3431 (week . ,(* 7 24 60 60))
3432 (day . ,(* 24 60 60))
3433 (hour . ,(* 60 60))
3434 (minute . 60)
3435 (second . 1))
3436 "Mapping from time units to seconds.")
3437
3438 (defun gnus-article-forward-header ()
3439 "Move point to the start of the next header.
3440 If the current header is a continuation header, this can be several
3441 lines forward."
3442 (let ((ended nil))
3443 (while (not ended)
3444 (forward-line 1)
3445 (if (looking-at "[ \t]+[^ \t]")
3446 (forward-line 1)
3447 (setq ended t)))))
3448
3449 (defun article-date-ut (&optional type highlight)
3450 "Convert DATE date to universal time in the current article.
3451 If TYPE is `local', convert to local time; if it is `lapsed', output
3452 how much time has lapsed since DATE. For `lapsed', the value of
3453 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3454 should replace the \"Date:\" one, or should be added below it."
3455 (interactive (list 'ut t))
3456 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3457 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3458 tdate-regexp)
3459 ((eq type 'lapsed)
3460 "^X-Sent:[ \t]")
3461 (article-lapsed-timer
3462 "^Date:[ \t]")
3463 (t
3464 tdate-regexp)))
3465 (case-fold-search t)
3466 (inhibit-read-only t)
3467 (inhibit-point-motion-hooks t)
3468 pos date bface eface)
3469 (save-excursion
3470 (save-restriction
3471 (widen)
3472 (goto-char (point-min))
3473 (while (or (setq date (get-text-property (setq pos (point))
3474 'original-date))
3475 (when (setq pos (next-single-property-change
3476 (point) 'original-date))
3477 (setq date (get-text-property pos 'original-date))
3478 t))
3479 (narrow-to-region
3480 pos (if (setq pos (text-property-any pos (point-max)
3481 'original-date nil))
3482 (progn
3483 (goto-char pos)
3484 (if (or (bolp) (eobp))
3485 (point)
3486 (1+ (point))))
3487 (point-max)))
3488 (goto-char (point-min))
3489 (when (re-search-forward tdate-regexp nil t)
3490 (setq bface (get-text-property (point-at-bol) 'face)
3491 eface (get-text-property (1- (point-at-eol)) 'face)))
3492 (goto-char (point-min))
3493 (setq pos nil)
3494 ;; Delete any old Date headers.
3495 (while (re-search-forward date-regexp nil t)
3496 (if pos
3497 (delete-region (point-at-bol) (progn
3498 (gnus-article-forward-header)
3499 (point)))
3500 (delete-region (point-at-bol) (progn
3501 (gnus-article-forward-header)
3502 (forward-char -1)
3503 (point)))
3504 (setq pos (point))))
3505 (when (and (not pos)
3506 (re-search-forward tdate-regexp nil t))
3507 (forward-line 1))
3508 (gnus-goto-char pos)
3509 (insert (article-make-date-line date (or type 'ut)))
3510 (unless pos
3511 (insert "\n")
3512 (forward-line -1))
3513 ;; Do highlighting.
3514 (beginning-of-line)
3515 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3516 (put-text-property (match-beginning 1) (1+ (match-end 1))
3517 'face bface)
3518 (put-text-property (match-beginning 2) (match-end 2)
3519 'face eface))
3520 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3521 (goto-char (point-max))
3522 (widen))))))
3523
3524 (defun article-make-date-line (date type)
3525 "Return a DATE line of TYPE."
3526 (unless (memq type '(local ut original user iso8601 lapsed english))
3527 (error "Unknown conversion type: %s" type))
3528 (condition-case ()
3529 (let ((time (date-to-time date)))
3530 (cond
3531 ;; Convert to the local timezone.
3532 ((eq type 'local)
3533 (concat "Date: " (message-make-date time)))
3534 ;; Convert to Universal Time.
3535 ((eq type 'ut)
3536 (concat "Date: "
3537 (substring
3538 (message-make-date
3539 (let* ((e (parse-time-string date))
3540 (tm (apply 'encode-time e))
3541 (ms (car tm))
3542 (ls (- (cadr tm) (car (current-time-zone time)))))
3543 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3544 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3545 (t (list ms ls)))))
3546 0 -5)
3547 "UT"))
3548 ;; Get the original date from the article.
3549 ((eq type 'original)
3550 (concat "Date: " (if (string-match "\n+$" date)
3551 (substring date 0 (match-beginning 0))
3552 date)))
3553 ;; Let the user define the format.
3554 ((eq type 'user)
3555 (let ((format (or (condition-case nil
3556 (with-current-buffer gnus-summary-buffer
3557 gnus-article-time-format)
3558 (error nil))
3559 gnus-article-time-format)))
3560 (if (functionp format)
3561 (funcall format time)
3562 (concat "Date: " (format-time-string format time)))))
3563 ;; ISO 8601.
3564 ((eq type 'iso8601)
3565 (let ((tz (car (current-time-zone time))))
3566 (concat
3567 "Date: "
3568 (format-time-string "%Y%m%dT%H%M%S" time)
3569 (format "%s%02d%02d"
3570 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3571 (/ (% (abs tz) 3600) 60)))))
3572 ;; Do an X-Sent lapsed format.
3573 ((eq type 'lapsed)
3574 ;; If the date is seriously mangled, the timezone functions are
3575 ;; liable to bug out, so we ignore all errors.
3576 (let* ((now (current-time))
3577 (real-time (subtract-time now time))
3578 (real-sec (and real-time
3579 (+ (* (float (car real-time)) 65536)
3580 (cadr real-time))))
3581 (sec (and real-time (abs real-sec)))
3582 num prev)
3583 (cond
3584 ((null real-time)
3585 "X-Sent: Unknown")
3586 ((zerop sec)
3587 "X-Sent: Now")
3588 (t
3589 (concat
3590 "X-Sent: "
3591 ;; This is a bit convoluted, but basically we go
3592 ;; through the time units for years, weeks, etc,
3593 ;; and divide things to see whether that results
3594 ;; in positive answers.
3595 (mapconcat
3596 (lambda (unit)
3597 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3598 ;; The (remaining) seconds are too few to
3599 ;; be divided into this time unit.
3600 ""
3601 ;; It's big enough, so we output it.
3602 (setq sec (- sec (* num (cdr unit))))
3603 (prog1
3604 (concat (if prev ", " "") (int-to-string
3605 (floor num))
3606 " " (symbol-name (car unit))
3607 (if (> num 1) "s" ""))
3608 (setq prev t))))
3609 article-time-units "")
3610 ;; If dates are odd, then it might appear like the
3611 ;; article was sent in the future.
3612 (if (> real-sec 0)
3613 " ago"
3614 " in the future"))))))
3615 ;; Display the date in proper English
3616 ((eq type 'english)
3617 (let ((dtime (decode-time time)))
3618 (concat
3619 "Date: the "
3620 (number-to-string (nth 3 dtime))
3621 (let ((digit (% (nth 3 dtime) 10)))
3622 (cond
3623 ((memq (nth 3 dtime) '(11 12 13)) "th")
3624 ((= digit 1) "st")
3625 ((= digit 2) "nd")
3626 ((= digit 3) "rd")
3627 (t "th")))
3628 " of "
3629 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3630 " "
3631 (number-to-string (nth 5 dtime))
3632 " at "
3633 (format "%02d" (nth 2 dtime))
3634 ":"
3635 (format "%02d" (nth 1 dtime)))))))
3636 (error
3637 (format "Date: %s (from Gnus)" date))))
3638
3639 (defun article-date-local (&optional highlight)
3640 "Convert the current article date to the local timezone."
3641 (interactive (list t))
3642 (article-date-ut 'local highlight))
3643
3644 (defun article-date-english (&optional highlight)
3645 "Convert the current article date to something that is proper English."
3646 (interactive (list t))
3647 (article-date-ut 'english highlight))
3648
3649 (defun article-date-original (&optional highlight)
3650 "Convert the current article date to what it was originally.
3651 This is only useful if you have used some other date conversion
3652 function and want to see what the date was before converting."
3653 (interactive (list t))
3654 (article-date-ut 'original highlight))
3655
3656 (defun article-date-lapsed (&optional highlight)
3657 "Convert the current article date to time lapsed since it was sent."
3658 (interactive (list t))
3659 (article-date-ut 'lapsed highlight))
3660
3661 (defun article-update-date-lapsed ()
3662 "Function to be run from a timer to update the lapsed time line."
3663 (save-match-data
3664 (let (deactivate-mark)
3665 (save-excursion
3666 (ignore-errors
3667 (walk-windows
3668 (lambda (w)
3669 (set-buffer (window-buffer w))
3670 (when (eq major-mode 'gnus-article-mode)
3671 (let ((mark (point-marker)))
3672 (goto-char (point-min))
3673 (when (re-search-forward "^X-Sent:" nil t)
3674 (article-date-lapsed t))
3675 (goto-char (marker-position mark))
3676 (move-marker mark nil))))
3677 nil 'visible))))))
3678
3679 (defun gnus-start-date-timer (&optional n)
3680 "Start a timer to update the X-Sent header in the article buffers.
3681 The numerical prefix says how frequently (in seconds) the function
3682 is to run."
3683 (interactive "p")
3684 (unless n
3685 (setq n 1))
3686 (gnus-stop-date-timer)
3687 (setq article-lapsed-timer
3688 (run-at-time 1 n 'article-update-date-lapsed)))
3689
3690 (defun gnus-stop-date-timer ()
3691 "Stop the X-Sent timer."
3692 (interactive)
3693 (when article-lapsed-timer
3694 (nnheader-cancel-timer article-lapsed-timer)
3695 (setq article-lapsed-timer nil)))
3696
3697 (defun article-date-user (&optional highlight)
3698 "Convert the current article date to the user-defined format.
3699 This format is defined by the `gnus-article-time-format' variable."
3700 (interactive (list t))
3701 (article-date-ut 'user highlight))
3702
3703 (defun article-date-iso8601 (&optional highlight)
3704 "Convert the current article date to ISO8601."
3705 (interactive (list t))
3706 (article-date-ut 'iso8601 highlight))
3707
3708 (defmacro gnus-article-save-original-date (&rest forms)
3709 "Save the original date as a text property and evaluate FORMS."
3710 `(let* ((case-fold-search t)
3711 (start (progn
3712 (goto-char (point-min))
3713 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3714 (not (bolp)))
3715 (match-end 0))))
3716 (date (when (and start
3717 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3718 nil t))
3719 (buffer-substring-no-properties start
3720 (match-beginning 0)))))
3721 (goto-char (point-max))
3722 (skip-chars-backward "\n")
3723 (put-text-property (point-min) (point) 'original-date date)
3724 ,@forms
3725 (goto-char (point-max))
3726 (skip-chars-backward "\n")
3727 (put-text-property (point-min) (point) 'original-date date)))
3728
3729 ;; (defun article-show-all ()
3730 ;; "Show all hidden text in the article buffer."
3731 ;; (interactive)
3732 ;; (save-excursion
3733 ;; (let ((inhibit-read-only t))
3734 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3735
3736 (defun article-remove-leading-whitespace ()
3737 "Remove excessive whitespace from all headers."
3738 (interactive)
3739 (save-excursion
3740 (save-restriction
3741 (let ((inhibit-read-only t))
3742 (article-narrow-to-head)
3743 (goto-char (point-min))
3744 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3745 (delete-region (match-beginning 1) (match-end 1)))))))
3746
3747 (defun article-emphasize (&optional arg)
3748 "Emphasize text according to `gnus-emphasis-alist'."
3749 (interactive (gnus-article-hidden-arg))
3750 (unless (gnus-article-check-hidden-text 'emphasis arg)
3751 (save-excursion
3752 (let ((alist (or
3753 (condition-case nil
3754 (with-current-buffer gnus-summary-buffer
3755 gnus-article-emphasis-alist)
3756 (error))
3757 gnus-emphasis-alist))
3758 (inhibit-read-only t)
3759 (props (append '(article-type emphasis)
3760 gnus-hidden-properties))
3761 regexp elem beg invisible visible face)
3762 (article-goto-body)
3763 (setq beg (point))
3764 (while (setq elem (pop alist))
3765 (goto-char beg)
3766 (setq regexp (car elem)
3767 invisible (nth 1 elem)
3768 visible (nth 2 elem)
3769 face (nth 3 elem))
3770 (while (re-search-forward regexp nil t)
3771 (when (and (match-beginning visible) (match-beginning invisible))
3772 (gnus-article-hide-text
3773 (match-beginning invisible) (match-end invisible) props)
3774 (gnus-article-unhide-text-type
3775 (match-beginning visible) (match-end visible) 'emphasis)
3776 (gnus-put-overlay-excluding-newlines
3777 (match-beginning visible) (match-end visible) 'face face)
3778 (gnus-add-wash-type 'emphasis)
3779 (goto-char (match-end invisible)))))))))
3780
3781 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3782 "Setup newsgroup emphasis alist."
3783 (unless gnus-article-emphasis-alist
3784 (let ((name (and gnus-newsgroup-name
3785 (gnus-group-real-name gnus-newsgroup-name))))
3786 (make-local-variable 'gnus-article-emphasis-alist)
3787 (setq gnus-article-emphasis-alist
3788 (nconc
3789 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3790 (while (setq elem (pop alist))
3791 (when (and name (string-match (car elem) name))
3792 (setq alist nil
3793 highlight (copy-sequence (cdr elem)))))
3794 highlight)
3795 (copy-sequence highlight-words)
3796 (if gnus-newsgroup-name
3797 (copy-sequence (gnus-group-find-parameter
3798 gnus-newsgroup-name 'highlight-words t)))
3799 gnus-emphasis-alist)))))
3800
3801 (defvar gnus-summary-article-menu)
3802 (defvar gnus-summary-post-menu)
3803
3804 ;;; Saving functions.
3805
3806 (defun gnus-article-save (save-buffer file &optional num)
3807 "Save the currently selected article."
3808 (when (or (get gnus-default-article-saver :headers)
3809 (not gnus-save-all-headers))
3810 ;; Remove headers according to `gnus-saved-headers' or the value
3811 ;; of the `:headers' property that the saver function might have.
3812 (let ((gnus-visible-headers
3813 (or (symbol-value (get gnus-default-article-saver :headers))
3814 gnus-saved-headers gnus-visible-headers))
3815 ;; Ignore group parameter. See `article-hide-headers'.
3816 (gnus-summary-buffer nil))
3817 (with-current-buffer save-buffer
3818 (article-hide-headers 1 t))))
3819 (save-window-excursion
3820 (if (not gnus-default-article-saver)
3821 (error "No default saver is defined")
3822 ;; !!! Magic! The saving functions all save
3823 ;; `gnus-save-article-buffer' (or so they think), but we
3824 ;; bind that variable to our save-buffer.
3825 (set-buffer gnus-article-buffer)
3826 (let* ((gnus-save-article-buffer save-buffer)
3827 (filename
3828 (cond
3829 ((not gnus-prompt-before-saving) 'default)
3830 ((eq gnus-prompt-before-saving 'always) nil)
3831 (t file)))
3832 (gnus-number-of-articles-to-be-saved
3833 (when (eq gnus-prompt-before-saving t)
3834 num))) ; Magic
3835 (set-buffer gnus-article-current-summary)
3836 (funcall gnus-default-article-saver filename)))))
3837
3838 (defun gnus-read-save-file-name (prompt &optional filename
3839 function group headers variable
3840 dir-var)
3841 (let ((default-name
3842 (funcall function group headers (symbol-value variable)))
3843 result)
3844 (setq result
3845 (expand-file-name
3846 (cond
3847 ((eq filename 'default)
3848 default-name)
3849 ((eq filename t)
3850 default-name)
3851 (filename filename)
3852 (t
3853 (when (symbol-value dir-var)
3854 (setq default-name (expand-file-name
3855 (file-name-nondirectory default-name)
3856 (symbol-value dir-var))))
3857 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3858 (prompt
3859 (format prompt
3860 (if (and gnus-number-of-articles-to-be-saved
3861 (> gnus-number-of-articles-to-be-saved 1))
3862 (format "these %d articles"
3863 gnus-number-of-articles-to-be-saved)
3864 "this article")))
3865 (file
3866 ;; Let the split methods have their say.
3867 (cond
3868 ;; No split name was found.
3869 ((null split-name)
3870 (read-file-name
3871 (concat prompt " (default "
3872 (file-name-nondirectory default-name) "): ")
3873 (file-name-directory default-name)
3874 default-name))
3875 ;; A single group name is returned.
3876 ((stringp split-name)
3877 (setq default-name
3878 (funcall function split-name headers
3879 (symbol-value variable)))
3880 (read-file-name
3881 (concat prompt " (default "
3882 (file-name-nondirectory default-name) "): ")
3883 (file-name-directory default-name)
3884 default-name))
3885 ;; A single split name was found
3886 ((= 1 (length split-name))
3887 (let* ((name (expand-file-name
3888 (car split-name)
3889 gnus-article-save-directory))
3890 (dir (cond ((file-directory-p name)
3891 (file-name-as-directory name))
3892 ((file-exists-p name) name)
3893 (t gnus-article-save-directory))))
3894 (read-file-name
3895 (concat prompt " (default " name "): ")
3896 dir name)))
3897 ;; A list of splits was found.
3898 (t
3899 (setq split-name (nreverse split-name))
3900 (let (result)
3901 (let ((file-name-history
3902 (nconc split-name file-name-history)))
3903 (setq result
3904 (expand-file-name
3905 (read-file-name
3906 (concat prompt " (`M-p' for defaults): ")
3907 gnus-article-save-directory
3908 (car split-name))
3909 gnus-article-save-directory)))
3910 (car (push result file-name-history)))))))
3911 ;; Create the directory.
3912 (gnus-make-directory (file-name-directory file))
3913 ;; If we have read a directory, we append the default file name.
3914 (when (file-directory-p file)
3915 (setq file (expand-file-name (file-name-nondirectory
3916 default-name)
3917 (file-name-as-directory file))))
3918 ;; Possibly translate some characters.
3919 (nnheader-translate-file-chars file))))))
3920 (gnus-make-directory (file-name-directory result))
3921 (when variable
3922 (set variable result))
3923 (when dir-var
3924 (set dir-var (file-name-directory result)))
3925 result))
3926
3927 (defun gnus-article-archive-name (group)
3928 "Return the first instance of an \"Archive-name\" in the current buffer."
3929 (let ((case-fold-search t))
3930 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3931 (nnheader-concat gnus-article-save-directory
3932 (match-string 1)))))
3933
3934 (defun gnus-article-nndoc-name (group)
3935 "If GROUP is an nndoc group, return the name of the parent group."
3936 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3937 (gnus-group-get-parameter group 'save-article-group)))
3938
3939 (defun gnus-summary-save-in-rmail (&optional filename)
3940 "Append this article to Rmail file.
3941 Optional argument FILENAME specifies file name.
3942 Directory to save to is default to `gnus-article-save-directory'."
3943 (setq filename (gnus-read-save-file-name
3944 "Save %s in rmail file" filename
3945 gnus-rmail-save-name gnus-newsgroup-name
3946 gnus-current-headers 'gnus-newsgroup-last-rmail))
3947 (gnus-eval-in-buffer-window gnus-save-article-buffer
3948 (save-excursion
3949 (save-restriction
3950 (widen)
3951 ;; Note that unlike gnus-summary-save-in-mail, there is no
3952 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3953 ;; not use Babyl.
3954 (gnus-output-to-rmail filename))))
3955 filename)
3956
3957 (defun gnus-summary-save-in-mail (&optional filename)
3958 "Append this article to Unix mail file.
3959 Optional argument FILENAME specifies file name.
3960 Directory to save to is default to `gnus-article-save-directory'."
3961 (setq filename (gnus-read-save-file-name
3962 "Save %s in Unix mail file" filename
3963 gnus-mail-save-name gnus-newsgroup-name
3964 gnus-current-headers 'gnus-newsgroup-last-mail))
3965 (gnus-eval-in-buffer-window gnus-save-article-buffer
3966 (save-excursion
3967 (save-restriction
3968 (widen)
3969 (if (and (file-readable-p filename)
3970 (file-regular-p filename)
3971 (mail-file-babyl-p filename))
3972 (gnus-output-to-rmail filename)
3973 (gnus-output-to-mail filename)))))
3974 filename)
3975
3976 (put 'gnus-summary-save-in-file :decode t)
3977 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3978 (defun gnus-summary-save-in-file (&optional filename overwrite)
3979 "Append this article to file.
3980 Optional argument FILENAME specifies file name.
3981 Directory to save to is default to `gnus-article-save-directory'."
3982 (setq filename (gnus-read-save-file-name
3983 "Save %s in file" filename
3984 gnus-file-save-name gnus-newsgroup-name
3985 gnus-current-headers 'gnus-newsgroup-last-file))
3986 (gnus-eval-in-buffer-window gnus-save-article-buffer
3987 (save-excursion
3988 (save-restriction
3989 (widen)
3990 (when (and overwrite
3991 (file-exists-p filename))
3992 (delete-file filename))
3993 (gnus-output-to-file filename))))
3994 filename)
3995
3996 (put 'gnus-summary-write-to-file :decode t)
3997 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3998 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3999 (defun gnus-summary-write-to-file (&optional filename)
4000 "Write this article to a file, overwriting it if the file exists.
4001 Optional argument FILENAME specifies file name.
4002 The directory to save in defaults to `gnus-article-save-directory'."
4003 (setq filename (gnus-read-save-file-name
4004 "Save %s in file" filename
4005 gnus-file-save-name gnus-newsgroup-name
4006 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4007 (gnus-summary-save-in-file filename t))
4008
4009 (put 'gnus-summary-save-body-in-file :decode t)
4010 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4011 "Append this article body to a file.
4012 Optional argument FILENAME specifies file name.
4013 The directory to save in defaults to `gnus-article-save-directory'."
4014 (setq filename (gnus-read-save-file-name
4015 "Save %s body in file" filename
4016 gnus-file-save-name gnus-newsgroup-name
4017 gnus-current-headers 'gnus-newsgroup-last-file))
4018 (gnus-eval-in-buffer-window gnus-save-article-buffer
4019 (save-excursion
4020 (save-restriction
4021 (widen)
4022 (when (article-goto-body)
4023 (narrow-to-region (point) (point-max)))
4024 (when (and overwrite
4025 (file-exists-p filename))
4026 (delete-file filename))
4027 (gnus-output-to-file filename))))
4028 filename)
4029
4030 (put 'gnus-summary-write-body-to-file :decode t)
4031 (put 'gnus-summary-write-body-to-file
4032 :function 'gnus-summary-save-body-in-file)
4033 (defun gnus-summary-write-body-to-file (&optional filename)
4034 "Write this article body to a file, overwriting it if the file exists.
4035 Optional argument FILENAME specifies file name.
4036 The directory to save in defaults to `gnus-article-save-directory'."
4037 (setq filename (gnus-read-save-file-name
4038 "Save %s body in file" filename
4039 gnus-file-save-name gnus-newsgroup-name
4040 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4041 (gnus-summary-save-body-in-file filename t))
4042
4043 (put 'gnus-summary-save-in-pipe :decode t)
4044 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4045 (defun gnus-summary-save-in-pipe (&optional command raw)
4046 "Pipe this article to subprocess COMMAND.
4047 Valid values for COMMAND include:
4048 a string
4049 The executable command name and possibly arguments.
4050 nil
4051 You will be prompted for the command in the minibuffer.
4052 the symbol `default'
4053 It will be replaced with the command which the variable
4054 `gnus-summary-pipe-output-default-command' holds or the command
4055 last used for saving.
4056 Non-nil value for RAW overrides `:decode' and `:headers' properties
4057 and the raw article including all headers will be piped."
4058 (let ((article (gnus-summary-article-number))
4059 (decode (unless raw
4060 (get 'gnus-summary-save-in-pipe :decode)))
4061 save-buffer default)
4062 (if article
4063 (if (vectorp (gnus-summary-article-header article))
4064 (save-current-buffer
4065 (gnus-summary-select-article decode decode nil article)
4066 (insert-buffer-substring
4067 (prog1
4068 (if decode
4069 gnus-article-buffer
4070 gnus-original-article-buffer)
4071 (setq save-buffer
4072 (nnheader-set-temp-buffer " *Gnus Save*"))))
4073 ;; Remove unwanted headers.
4074 (when (and (not raw)
4075 (or (get 'gnus-summary-save-in-pipe :headers)
4076 (not gnus-save-all-headers)))
4077 (let ((gnus-visible-headers
4078 (or (symbol-value (get 'gnus-summary-save-in-pipe
4079 :headers))
4080 gnus-saved-headers gnus-visible-headers))
4081 (gnus-summary-buffer nil))
4082 (article-hide-headers 1 t))))
4083 (error "%d is not a real article" article))
4084 (error "No article to pipe"))
4085 (setq default (or gnus-summary-pipe-output-default-command
4086 gnus-last-shell-command))
4087 (unless (stringp command)
4088 (setq command
4089 (if (and (eq command 'default) default)
4090 default
4091 (gnus-read-shell-command "Shell command on this article: "
4092 default))))
4093 (when (string-equal command "")
4094 (if default
4095 (setq command default)
4096 (error "A command is required")))
4097 (gnus-eval-in-buffer-window save-buffer
4098 (save-restriction
4099 (widen)
4100 (shell-command-on-region (point-min) (point-max) command nil)))
4101 (gnus-kill-buffer save-buffer))
4102 (setq gnus-summary-pipe-output-default-command command))
4103
4104 (defun gnus-summary-pipe-to-muttprint (&optional command)
4105 "Pipe this article to muttprint."
4106 (unless (stringp command)
4107 (setq command (read-string
4108 "Print using command: " gnus-summary-muttprint-program
4109 nil gnus-summary-muttprint-program)))
4110 (let ((gnus-summary-pipe-output-default-command
4111 gnus-summary-pipe-output-default-command))
4112 (gnus-summary-save-in-pipe command))
4113 (setq gnus-summary-muttprint-program command))
4114
4115 ;;; Article file names when saving.
4116
4117 (defun gnus-capitalize-newsgroup (newsgroup)
4118 "Capitalize NEWSGROUP name."
4119 (when (not (zerop (length newsgroup)))
4120 (concat (char-to-string (upcase (aref newsgroup 0)))
4121 (substring newsgroup 1))))
4122
4123 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4124 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4125 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4126 Otherwise, it is like ~/News/news/group/num."
4127 (let ((default
4128 (expand-file-name
4129 (concat (if (gnus-use-long-file-name 'not-save)
4130 (gnus-capitalize-newsgroup newsgroup)
4131 (gnus-newsgroup-directory-form newsgroup))
4132 "/" (int-to-string (mail-header-number headers)))
4133 gnus-article-save-directory)))
4134 (if (and last-file
4135 (string-equal (file-name-directory default)
4136 (file-name-directory last-file))
4137 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4138 default
4139 (or last-file default))))
4140
4141 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4142 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4143 If variable `gnus-use-long-file-name' is non-nil, it is
4144 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4145 (let ((default
4146 (expand-file-name
4147 (concat (if (gnus-use-long-file-name 'not-save)
4148 newsgroup
4149 (gnus-newsgroup-directory-form newsgroup))
4150 "/" (int-to-string (mail-header-number headers)))
4151 gnus-article-save-directory)))
4152 (if (and last-file
4153 (string-equal (file-name-directory default)
4154 (file-name-directory last-file))
4155 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4156 default
4157 (or last-file default))))
4158
4159 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4160 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4161 If variable `gnus-use-long-file-name' is non-nil, it is
4162 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4163 (or last-file
4164 (expand-file-name
4165 (if (gnus-use-long-file-name 'not-save)
4166 newsgroup
4167 (file-relative-name
4168 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4169 default-directory))
4170 gnus-article-save-directory)))
4171
4172 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4173 "Generate file name from sender."
4174 (let ((from (mail-header-from headers)))
4175 (expand-file-name
4176 (if (and from (string-match "\\([^ <]+\\)@" from))
4177 (match-string 1 from)
4178 "nobody")
4179 gnus-article-save-directory)))
4180
4181 (defun article-verify-x-pgp-sig ()
4182 "Verify X-PGP-Sig."
4183 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4184 (interactive)
4185 (if (gnus-buffer-live-p gnus-original-article-buffer)
4186 (let ((sig (with-current-buffer gnus-original-article-buffer
4187 (gnus-fetch-field "X-PGP-Sig")))
4188 items info headers)
4189 (when (and sig
4190 mml2015-use
4191 (mml2015-clear-verify-function))
4192 (with-temp-buffer
4193 (insert-buffer-substring gnus-original-article-buffer)
4194 (setq items (split-string sig))
4195 (message-narrow-to-head)
4196 (let ((inhibit-point-motion-hooks t)
4197 (case-fold-search t))
4198 ;; Don't verify multiple headers.
4199 (setq headers (mapconcat (lambda (header)
4200 (concat header ": "
4201 (mail-fetch-field header)
4202 "\n"))
4203 (split-string (nth 1 items) ",") "")))
4204 (delete-region (point-min) (point-max))
4205 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4206 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4207 (insert headers)
4208 (widen)
4209 (forward-line)
4210 (while (not (eobp))
4211 (if (looking-at "^-")
4212 (insert "- "))
4213 (forward-line))
4214 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4215 (insert "Version: " (car items) "\n\n")
4216 (insert (mapconcat 'identity (cddr items) "\n"))
4217 (insert "\n-----END PGP SIGNATURE-----\n")
4218 (let ((mm-security-handle (list (format "multipart/signed"))))
4219 (mml2015-clean-buffer)
4220 (let ((coding-system-for-write (or gnus-newsgroup-charset
4221 'iso-8859-1)))
4222 (funcall (mml2015-clear-verify-function)))
4223 (setq info
4224 (or (mm-handle-multipart-ctl-parameter
4225 mm-security-handle 'gnus-details)
4226 (mm-handle-multipart-ctl-parameter
4227 mm-security-handle 'gnus-info)))))
4228 (when info
4229 (let ((inhibit-read-only t) bface eface)
4230 (save-restriction
4231 (message-narrow-to-head)
4232 (goto-char (point-max))
4233 (forward-line -1)
4234 (setq bface (get-text-property (point-at-bol) 'face)
4235 eface (get-text-property (1- (point-at-eol)) 'face))
4236 (message-remove-header "X-Gnus-PGP-Verify")
4237 (if (re-search-forward "^X-PGP-Sig:" nil t)
4238 (forward-line)
4239 (goto-char (point-max)))
4240 (narrow-to-region (point) (point))
4241 (insert "X-Gnus-PGP-Verify: " info "\n")
4242 (goto-char (point-min))
4243 (forward-line)
4244 (while (not (eobp))
4245 (if (not (looking-at "^[ \t]"))
4246 (insert " "))
4247 (forward-line))
4248 ;; Do highlighting.
4249 (goto-char (point-min))
4250 (when (looking-at "\\([^:]+\\): *")
4251 (put-text-property (match-beginning 1) (1+ (match-end 1))
4252 'face bface)
4253 (put-text-property (match-end 0) (point-max)
4254 'face eface)))))))))
4255
4256 (autoload 'canlock-verify "canlock" nil t) ;; for Emacs 21.
4257
4258 (defun article-verify-cancel-lock ()
4259 "Verify Cancel-Lock header."
4260 (interactive)
4261 (if (gnus-buffer-live-p gnus-original-article-buffer)
4262 (canlock-verify gnus-original-article-buffer)))
4263
4264 (eval-and-compile
4265 (mapc
4266 (lambda (func)
4267 (let (afunc gfunc)
4268 (if (consp func)
4269 (setq afunc (car func)
4270 gfunc (cdr func))
4271 (setq afunc func
4272 gfunc (intern (format "gnus-%s" func))))
4273 (defalias gfunc
4274 (when (fboundp afunc)
4275 `(lambda (&optional interactive &rest args)
4276 ,(documentation afunc t)
4277 (interactive (list t))
4278 (with-current-buffer gnus-article-buffer
4279 (if interactive
4280 (call-interactively ',afunc)
4281 (apply ',afunc args))))))))
4282 '(article-hide-headers
4283 article-verify-x-pgp-sig
4284 article-verify-cancel-lock
4285 article-hide-boring-headers
4286 article-treat-overstrike
4287 article-treat-ansi-sequences
4288 article-fill-long-lines
4289 article-capitalize-sentences
4290 article-remove-cr
4291 article-remove-leading-whitespace
4292 article-display-x-face
4293 article-display-face
4294 article-de-quoted-unreadable
4295 article-de-base64-unreadable
4296 article-decode-HZ
4297 article-wash-html
4298 article-unsplit-urls
4299 article-hide-list-identifiers
4300 article-strip-banner
4301 article-babel
4302 article-hide-pem
4303 article-hide-signature
4304 article-strip-headers-in-body
4305 article-remove-trailing-blank-lines
4306 article-strip-leading-blank-lines
4307 article-strip-multiple-blank-lines
4308 article-strip-leading-space
4309 article-strip-trailing-space
4310 article-strip-blank-lines
4311 article-strip-all-blank-lines
4312 article-date-local
4313 article-date-english
4314 article-date-iso8601
4315 article-date-original
4316 article-date-ut
4317 article-decode-mime-words
4318 article-decode-charset
4319 article-decode-encoded-words
4320 article-date-user
4321 article-date-lapsed
4322 article-emphasize
4323 article-treat-dumbquotes
4324 article-normalize-headers
4325 ;;(article-show-all . gnus-article-show-all-headers)
4326 )))
4327 \f
4328 ;;;
4329 ;;; Gnus article mode
4330 ;;;
4331
4332 (put 'gnus-article-mode 'mode-class 'special)
4333
4334 (set-keymap-parent gnus-article-mode-map widget-keymap)
4335
4336 (gnus-define-keys gnus-article-mode-map
4337 " " gnus-article-goto-next-page
4338 "\177" gnus-article-goto-prev-page
4339 [delete] gnus-article-goto-prev-page
4340 [backspace] gnus-article-goto-prev-page
4341 "\C-c^" gnus-article-refer-article
4342 "h" gnus-article-show-summary
4343 "s" gnus-article-show-summary
4344 "\C-c\C-m" gnus-article-mail
4345 "?" gnus-article-describe-briefly
4346 "<" beginning-of-buffer
4347 ">" end-of-buffer
4348 "\C-c\C-i" gnus-info-find-node
4349 "\C-c\C-b" gnus-bug
4350 "R" gnus-article-reply-with-original
4351 "F" gnus-article-followup-with-original
4352 "\C-hk" gnus-article-describe-key
4353 "\C-hc" gnus-article-describe-key-briefly
4354 "\C-hb" gnus-article-describe-bindings
4355
4356 "e" gnus-article-read-summary-keys
4357 "\C-d" gnus-article-read-summary-keys
4358 "\M-*" gnus-article-read-summary-keys
4359 "\M-#" gnus-article-read-summary-keys
4360 "\M-^" gnus-article-read-summary-keys
4361 "\M-g" gnus-article-read-summary-keys)
4362
4363 (substitute-key-definition
4364 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4365
4366 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4367 "W" gnus-article-wide-reply-with-original)
4368 (if (featurep 'xemacs)
4369 (set-keymap-default-binding gnus-article-send-map
4370 'gnus-article-read-summary-send-keys)
4371 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4372
4373 (defun gnus-article-make-menu-bar ()
4374 (unless (boundp 'gnus-article-commands-menu)
4375 (gnus-summary-make-menu-bar))
4376 (gnus-turn-off-edit-menu 'article)
4377 (unless (boundp 'gnus-article-article-menu)
4378 (easy-menu-define
4379 gnus-article-article-menu gnus-article-mode-map ""
4380 '("Article"
4381 ["Scroll forwards" gnus-article-goto-next-page t]
4382 ["Scroll backwards" gnus-article-goto-prev-page t]
4383 ["Show summary" gnus-article-show-summary t]
4384 ["Fetch Message-ID at point" gnus-article-refer-article t]
4385 ["Mail to address at point" gnus-article-mail t]
4386 ["Send a bug report" gnus-bug t]))
4387
4388 (easy-menu-define
4389 gnus-article-treatment-menu gnus-article-mode-map ""
4390 ;; Fixme: this should use :active (and maybe :visible).
4391 '("Treatment"
4392 ["Hide headers" gnus-article-hide-headers t]
4393 ["Hide signature" gnus-article-hide-signature t]
4394 ["Hide citation" gnus-article-hide-citation t]
4395 ["Treat overstrike" gnus-article-treat-overstrike t]
4396 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4397 ["Remove carriage return" gnus-article-remove-cr t]
4398 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4399 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4400 ["Remove base64" gnus-article-de-base64-unreadable t]
4401 ["Treat html" gnus-article-wash-html t]
4402 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4403 ["Decode HZ" gnus-article-decode-HZ t]))
4404
4405 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4406
4407 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4408
4409 (gnus-run-hooks 'gnus-article-menu-hook)))
4410
4411 (defun gnus-article-mode ()
4412 "Major mode for displaying an article.
4413
4414 All normal editing commands are switched off.
4415
4416 The following commands are available in addition to all summary mode
4417 commands:
4418 \\<gnus-article-mode-map>
4419 \\[gnus-article-next-page]\t Scroll the article one page forwards
4420 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4421 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4422 \\[gnus-article-show-summary]\t Display the summary buffer
4423 \\[gnus-article-mail]\t Send a reply to the address near point
4424 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4425 \\[gnus-info-find-node]\t Go to the Gnus info node"
4426 (interactive)
4427 (kill-all-local-variables)
4428 (gnus-simplify-mode-line)
4429 (setq mode-name "Article")
4430 (setq major-mode 'gnus-article-mode)
4431 (make-local-variable 'minor-mode-alist)
4432 (use-local-map gnus-article-mode-map)
4433 (when (gnus-visual-p 'article-menu 'menu)
4434 (gnus-article-make-menu-bar)
4435 (when gnus-summary-tool-bar-map
4436 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4437 (gnus-update-format-specifications nil 'article-mode)
4438 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4439 (set (make-local-variable 'gnus-page-broken) nil)
4440 (make-local-variable 'gnus-button-marker-list)
4441 (make-local-variable 'gnus-article-current-summary)
4442 (make-local-variable 'gnus-article-mime-handles)
4443 (make-local-variable 'gnus-article-decoded-p)
4444 (make-local-variable 'gnus-article-mime-handle-alist)
4445 (make-local-variable 'gnus-article-wash-types)
4446 (make-local-variable 'gnus-article-image-alist)
4447 (make-local-variable 'gnus-article-charset)
4448 (make-local-variable 'gnus-article-ignored-charsets)
4449 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4450 ;; face.
4451 (set (make-local-variable 'nobreak-char-display) nil)
4452 (setq cursor-in-non-selected-windows nil)
4453 (setq truncate-lines gnus-article-truncate-lines)
4454 (gnus-set-default-directory)
4455 (buffer-disable-undo)
4456 (setq buffer-read-only t
4457 show-trailing-whitespace nil)
4458 (set-syntax-table gnus-article-mode-syntax-table)
4459 (mm-enable-multibyte)
4460 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4461
4462 (defvar gnus-button-marker-list nil
4463 "Regexp matching any of the regexps from `gnus-button-alist'.
4464 Internal variable.")
4465
4466 (defun gnus-article-setup-buffer ()
4467 "Initialize the article buffer."
4468 (let* ((name (if gnus-single-article-buffer "*Article*"
4469 (concat "*Article " gnus-newsgroup-name "*")))
4470 (original
4471 (progn (string-match "\\*Article" name)
4472 (concat " *Original Article"
4473 (substring name (match-end 0))))))
4474 (setq gnus-article-buffer name)
4475 (setq gnus-original-article-buffer original)
4476 (setq gnus-article-mime-handle-alist nil)
4477 (with-current-buffer gnus-summary-buffer
4478 ;; This might be a variable local to the summary buffer.
4479 (unless gnus-single-article-buffer
4480 (setq gnus-article-buffer name)
4481 (setq gnus-original-article-buffer original)
4482 (gnus-set-global-variables)))
4483 (gnus-article-setup-highlight-words)
4484 ;; Init original article buffer.
4485 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4486 (mm-enable-multibyte)
4487 (setq major-mode 'gnus-original-article-mode)
4488 (make-local-variable 'gnus-original-article))
4489 (if (and (get-buffer name)
4490 (with-current-buffer name
4491 (if gnus-article-edit-mode
4492 (if (y-or-n-p "Article mode edit in progress; discard? ")
4493 (progn
4494 (set-buffer-modified-p nil)
4495 (gnus-kill-buffer name)
4496 (message "")
4497 nil)
4498 (error "Action aborted"))
4499 t)))
4500 (with-current-buffer name
4501 (set (make-local-variable 'gnus-article-edit-mode) nil)
4502 (when gnus-article-mime-handles
4503 (mm-destroy-parts gnus-article-mime-handles)
4504 (setq gnus-article-mime-handles nil))
4505 ;; Set it to nil in article-buffer!
4506 (setq gnus-article-mime-handle-alist nil)
4507 (buffer-disable-undo)
4508 (setq buffer-read-only t)
4509 ;; This list just keeps growing if we don't reset it.
4510 (setq gnus-button-marker-list nil)
4511 (unless (eq major-mode 'gnus-article-mode)
4512 (gnus-article-mode))
4513 (current-buffer))
4514 (with-current-buffer (gnus-get-buffer-create name)
4515 (gnus-article-mode)
4516 (make-local-variable 'gnus-summary-buffer)
4517 (setq gnus-summary-buffer
4518 (gnus-summary-buffer-name gnus-newsgroup-name))
4519 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4520 (current-buffer)))))
4521
4522 ;; Set article window start at LINE, where LINE is the number of lines
4523 ;; from the head of the article.
4524 (defun gnus-article-set-window-start (&optional line)
4525 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4526 (when article-window
4527 (set-window-start
4528 article-window
4529 (with-current-buffer gnus-article-buffer
4530 (goto-char (point-min))
4531 (if (not line)
4532 (point-min)
4533 (gnus-message 6 "Moved to bookmark")
4534 (search-forward "\n\n" nil t)
4535 (forward-line line)
4536 (point)))))))
4537
4538 (defun gnus-article-prepare (article &optional all-headers header)
4539 "Prepare ARTICLE in article mode buffer.
4540 ARTICLE should either be an article number or a Message-ID.
4541 If ARTICLE is an id, HEADER should be the article headers.
4542 If ALL-HEADERS is non-nil, no headers are hidden."
4543 (save-excursion
4544 ;; Make sure we start in a summary buffer.
4545 (unless (eq major-mode 'gnus-summary-mode)
4546 (set-buffer gnus-summary-buffer))
4547 (setq gnus-summary-buffer (current-buffer))
4548 (let* ((gnus-article (if header (mail-header-number header) article))
4549 (summary-buffer (current-buffer))
4550 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4551 (group gnus-newsgroup-name)
4552 result)
4553 (save-excursion
4554 (gnus-article-setup-buffer)
4555 (set-buffer gnus-article-buffer)
4556 ;; Deactivate active regions.
4557 (when (and (boundp 'transient-mark-mode)
4558 transient-mark-mode)
4559 (setq mark-active nil))
4560 (if (not (setq result (let ((inhibit-read-only t))
4561 (gnus-request-article-this-buffer
4562 article group))))
4563 ;; There is no such article.
4564 (save-excursion
4565 (when (and (numberp article)
4566 (not (memq article gnus-newsgroup-sparse)))
4567 (setq gnus-article-current
4568 (cons gnus-newsgroup-name article))
4569 (set-buffer gnus-summary-buffer)
4570 (setq gnus-current-article article)
4571 (if (and (memq article gnus-newsgroup-undownloaded)
4572 (not (gnus-online (gnus-find-method-for-group
4573 gnus-newsgroup-name))))
4574 (progn
4575 (gnus-summary-set-agent-mark article)
4576 (message "Message marked for downloading"))
4577 (gnus-summary-mark-article article gnus-canceled-mark)
4578 (unless (memq article gnus-newsgroup-sparse)
4579 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4580 (if (or (eq result 'pseudo)
4581 (eq result 'nneething))
4582 (progn
4583 (with-current-buffer summary-buffer
4584 (push article gnus-newsgroup-history)
4585 (setq gnus-last-article gnus-current-article
4586 gnus-current-article 0
4587 gnus-current-headers nil
4588 gnus-article-current nil)
4589 (if (eq result 'nneething)
4590 (gnus-configure-windows 'summary)
4591 (gnus-configure-windows 'article))
4592 (gnus-set-global-variables))
4593 (let ((gnus-article-mime-handle-alist-1
4594 gnus-article-mime-handle-alist))
4595 (gnus-set-mode-line 'article)))
4596 ;; The result from the `request' was an actual article -
4597 ;; or at least some text that is now displayed in the
4598 ;; article buffer.
4599 (when (and (numberp article)
4600 (not (eq article gnus-current-article)))
4601 ;; Seems like a new article has been selected.
4602 ;; `gnus-current-article' must be an article number.
4603 (with-current-buffer summary-buffer
4604 (push article gnus-newsgroup-history)
4605 (setq gnus-last-article gnus-current-article
4606 gnus-current-article article
4607 gnus-current-headers
4608 (gnus-summary-article-header gnus-current-article)
4609 gnus-article-current
4610 (cons gnus-newsgroup-name gnus-current-article))
4611 (unless (vectorp gnus-current-headers)
4612 (setq gnus-current-headers nil))
4613 (gnus-summary-goto-subject gnus-current-article)
4614 (when (gnus-summary-show-thread)
4615 ;; If the summary buffer really was folded, the
4616 ;; previous goto may not actually have gone to
4617 ;; the right article, but the thread root instead.
4618 ;; So we go again.
4619 (gnus-summary-goto-subject gnus-current-article))
4620 (gnus-run-hooks 'gnus-mark-article-hook)
4621 (gnus-set-mode-line 'summary)
4622 (when (gnus-visual-p 'article-highlight 'highlight)
4623 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4624 ;; Set the global newsgroup variables here.
4625 (gnus-set-global-variables)
4626 (setq gnus-have-all-headers
4627 (or all-headers gnus-show-all-headers))))
4628 (save-excursion
4629 (gnus-configure-windows 'article))
4630 (when (or (numberp article)
4631 (stringp article))
4632 (gnus-article-prepare-display)
4633 ;; Do page break.
4634 (goto-char (point-min))
4635 (when gnus-break-pages
4636 (gnus-narrow-to-page)))
4637 (let ((gnus-article-mime-handle-alist-1
4638 gnus-article-mime-handle-alist))
4639 (gnus-set-mode-line 'article))
4640 (article-goto-body)
4641 (unless (bobp)
4642 (forward-line -1))
4643 (set-window-point (get-buffer-window (current-buffer)) (point))
4644 (gnus-configure-windows 'article)
4645 t))))))
4646
4647 ;;;###autoload
4648 (defun gnus-article-prepare-display ()
4649 "Make the current buffer look like a nice article."
4650 ;; Hooks for getting information from the article.
4651 ;; This hook must be called before being narrowed.
4652 (let ((gnus-article-buffer (current-buffer))
4653 buffer-read-only
4654 (inhibit-read-only t))
4655 (unless (eq major-mode 'gnus-article-mode)
4656 (gnus-article-mode))
4657 (setq buffer-read-only nil
4658 gnus-article-wash-types nil
4659 gnus-article-image-alist nil)
4660 (gnus-run-hooks 'gnus-tmp-internal-hook)
4661 (when gnus-display-mime-function
4662 (funcall gnus-display-mime-function))
4663 (gnus-run-hooks 'gnus-article-prepare-hook)))
4664
4665 ;;;
4666 ;;; Gnus Sticky Article Mode
4667 ;;;
4668
4669 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4670 "Mode for sticky articles."
4671 ;; Release bindings that won't work.
4672 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4673 gnus-sticky-article-mode-map)
4674 (substitute-key-definition 'gnus-article-refer-article 'undefined
4675 gnus-sticky-article-mode-map)
4676 (dolist (k '("e" "h" "s" "F" "R"))
4677 (define-key gnus-sticky-article-mode-map k nil))
4678 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4679 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4680 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4681 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4682
4683 (defun gnus-sticky-article (arg)
4684 "Make the current article sticky.
4685 If a prefix ARG is given, ask for a name for this sticky article buffer."
4686 (interactive "P")
4687 (gnus-summary-show-thread)
4688 (gnus-summary-select-article nil nil 'pseudo)
4689 (let (new-art-buf-name)
4690 (gnus-eval-in-buffer-window gnus-article-buffer
4691 (setq new-art-buf-name
4692 (concat
4693 "*Sticky Article: "
4694 (if arg
4695 (read-from-minibuffer "Sticky article buffer name: ")
4696 (gnus-with-article-headers
4697 (gnus-article-goto-header "subject")
4698 (setq new-art-buf-name
4699 (buffer-substring-no-properties
4700 (line-beginning-position) (line-end-position)))
4701 (goto-char (point-min))
4702 (gnus-article-goto-header "from")
4703 (setq new-art-buf-name
4704 (concat
4705 new-art-buf-name ", "
4706 (buffer-substring-no-properties
4707 (line-beginning-position) (line-end-position))))
4708 (goto-char (point-min))
4709 (gnus-article-goto-header "date")
4710 (setq new-art-buf-name
4711 (concat
4712 new-art-buf-name ", "
4713 (buffer-substring-no-properties
4714 (line-beginning-position) (line-end-position))))))
4715 "*"))
4716 (if (and (gnus-buffer-live-p new-art-buf-name)
4717 (with-current-buffer new-art-buf-name
4718 (eq major-mode 'gnus-sticky-article-mode)))
4719 (switch-to-buffer new-art-buf-name)
4720 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4721 (gnus-sticky-article-mode))
4722 (setq gnus-article-buffer new-art-buf-name))
4723 (gnus-summary-recenter)
4724 (gnus-summary-position-point))
4725
4726 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4727 "Kill the given sticky article BUFFER.
4728 If none is given, assume the current buffer and kill it if it has
4729 `gnus-sticky-article-mode'."
4730 (interactive)
4731 (unless buffer
4732 (setq buffer (current-buffer)))
4733 (with-current-buffer buffer
4734 (when (eq major-mode 'gnus-sticky-article-mode)
4735 (gnus-kill-buffer buffer))))
4736
4737 (defun gnus-kill-sticky-article-buffers (arg)
4738 "Kill all sticky article buffers.
4739 If a prefix ARG is given, ask for confirmation."
4740 (interactive "P")
4741 (dolist (buf (gnus-buffers))
4742 (with-current-buffer buf
4743 (when (eq major-mode 'gnus-sticky-article-mode)
4744 (if (not arg)
4745 (gnus-kill-buffer buf)
4746 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4747 (gnus-kill-buffer buf)))))))
4748
4749 ;;;
4750 ;;; Gnus MIME viewing functions
4751 ;;;
4752
4753 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4754 "Format of the MIME buttons.
4755
4756 Valid specifiers include:
4757 %t The MIME type
4758 %T MIME type, along with additional info
4759 %n The `name' parameter
4760 %d The description, if any
4761 %l The length of the encoded part
4762 %p The part identifier number
4763 %e Dots if the part isn't displayed
4764
4765 General format specifiers can also be used. See Info node
4766 `(gnus)Formatting Variables'.")
4767
4768 (defvar gnus-mime-button-line-format-alist
4769 '((?t gnus-tmp-type ?s)
4770 (?T gnus-tmp-type-long ?s)
4771 (?n gnus-tmp-name ?s)
4772 (?d gnus-tmp-description ?s)
4773 (?p gnus-tmp-id ?s)
4774 (?l gnus-tmp-length ?d)
4775 (?e gnus-tmp-dots ?s)))
4776
4777 (defvar gnus-mime-button-commands
4778 '((gnus-article-press-button "\r" "Toggle Display")
4779 (gnus-mime-view-part "v" "View Interactively...")
4780 (gnus-mime-view-part-as-type "t" "View As Type...")
4781 (gnus-mime-view-part-as-charset "C" "View As charset...")
4782 (gnus-mime-save-part "o" "Save...")
4783 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4784 (gnus-mime-replace-part "r" "Replace part")
4785 (gnus-mime-delete-part "d" "Delete part")
4786 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4787 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4788 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4789 (gnus-mime-view-part-externally "e" "View Externally")
4790 (gnus-mime-print-part "p" "Print")
4791 (gnus-mime-pipe-part "|" "Pipe To Command...")
4792 (gnus-mime-action-on-part "." "Take action on the part...")))
4793
4794 (defun gnus-article-mime-part-status ()
4795 (if gnus-article-mime-handle-alist-1
4796 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4797 " (1 part)"
4798 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4799 ""))
4800
4801 (defvar gnus-mime-button-map
4802 (let ((map (make-sparse-keymap)))
4803 (define-key map gnus-mouse-2 'gnus-article-push-button)
4804 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4805 (dolist (c gnus-mime-button-commands)
4806 (define-key map (cadr c) (car c)))
4807 map))
4808
4809 (easy-menu-define
4810 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4811 `("MIME Part"
4812 ,@(mapcar (lambda (c)
4813 (vector (caddr c) (car c) :active t))
4814 gnus-mime-button-commands)))
4815
4816 (defmacro gnus-bind-safe-url-regexp (&rest body)
4817 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4818 `(let ((mm-w3m-safe-url-regexp
4819 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4820 (gnus-buffer-live-p
4821 gnus-article-current-summary))
4822 (with-current-buffer gnus-article-current-summary
4823 gnus-newsgroup-name)
4824 gnus-newsgroup-name)))
4825 (if (cond ((not group)
4826 ;; Maybe we're in a mml-preview buffer
4827 ;; and no group is selected.
4828 t)
4829 ((stringp gnus-safe-html-newsgroups)
4830 (string-match gnus-safe-html-newsgroups group))
4831 ((consp gnus-safe-html-newsgroups)
4832 (member group gnus-safe-html-newsgroups)))
4833 nil
4834 mm-w3m-safe-url-regexp))))
4835 ,@body))
4836
4837 (defun gnus-mime-button-menu (event prefix)
4838 "Construct a context-sensitive menu of MIME commands."
4839 (interactive "e\nP")
4840 (save-window-excursion
4841 (let ((pos (event-start event)))
4842 (select-window (posn-window pos))
4843 (goto-char (posn-point pos))
4844 (gnus-article-check-buffer)
4845 (popup-menu gnus-mime-button-menu nil prefix))))
4846
4847 (defun gnus-mime-view-all-parts (&optional handles)
4848 "View all the MIME parts."
4849 (interactive)
4850 (with-current-buffer gnus-article-buffer
4851 (let ((handles (or handles gnus-article-mime-handles))
4852 (mail-parse-charset gnus-newsgroup-charset)
4853 (mail-parse-ignored-charsets
4854 (with-current-buffer gnus-summary-buffer
4855 gnus-newsgroup-ignored-charsets)))
4856 (when handles
4857 (mm-remove-parts handles)
4858 (goto-char (point-min))
4859 (or (search-forward "\n\n") (goto-char (point-max)))
4860 (let ((inhibit-read-only t))
4861 (delete-region (point) (point-max))
4862 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4863
4864 (defun gnus-article-jump-to-part (n)
4865 "Jump to MIME part N."
4866 (interactive "P")
4867 (pop-to-buffer gnus-article-buffer)
4868 ;; FIXME: why is it necessary?
4869 (sit-for 0)
4870 (let ((parts (length gnus-article-mime-handle-alist)))
4871 (or n (setq n
4872 (string-to-number
4873 (read-string ;; Emacs 21 doesn't have `read-number'.
4874 (format "Jump to part (2..%s): " parts)))))
4875 (unless (and (integerp n) (<= n parts) (>= n 1))
4876 (setq n
4877 (progn
4878 (gnus-message 7 "Invalid part `%s', using %s instead."
4879 n parts)
4880 parts)))
4881 (gnus-message 9 "Jumping to part %s." n)
4882 (cond ((>= gnus-auto-select-part 1)
4883 (while (and (<= n parts)
4884 (not (gnus-article-goto-part n)))
4885 (setq n (1+ n))))
4886 ((< gnus-auto-select-part 0)
4887 (while (and (>= n 1)
4888 (not (gnus-article-goto-part n)))
4889 (setq n (1- n))))
4890 (t
4891 (gnus-article-goto-part n)))))
4892
4893 (eval-when-compile
4894 (defsubst gnus-article-edit-part (handles &optional current-id)
4895 "Edit an article in order to delete a mime part.
4896 This function is exclusively used by `gnus-mime-save-part-and-strip'
4897 and `gnus-mime-delete-part', and not provided at run-time normally."
4898 (gnus-article-edit-article
4899 `(lambda ()
4900 (buffer-disable-undo)
4901 (erase-buffer)
4902 (let ((mail-parse-charset (or gnus-article-charset
4903 ',gnus-newsgroup-charset))
4904 (mail-parse-ignored-charsets
4905 (or gnus-article-ignored-charsets
4906 ',gnus-newsgroup-ignored-charsets))
4907 (mbl mml-buffer-list))
4908 (setq mml-buffer-list nil)
4909 (insert-buffer-substring gnus-original-article-buffer)
4910 (mime-to-mml ',handles)
4911 (setq gnus-article-mime-handles nil)
4912 (let ((mbl1 mml-buffer-list))
4913 (setq mml-buffer-list mbl)
4914 (set (make-local-variable 'mml-buffer-list) mbl1))
4915 (gnus-make-local-hook 'kill-buffer-hook)
4916 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4917 `(lambda (no-highlight)
4918 (let ((mail-parse-charset (or gnus-article-charset
4919 ',gnus-newsgroup-charset))
4920 (message-options message-options)
4921 (message-options-set-recipient)
4922 (mail-parse-ignored-charsets
4923 (or gnus-article-ignored-charsets
4924 ',gnus-newsgroup-ignored-charsets)))
4925 (mml-to-mime)
4926 (mml-destroy-buffers)
4927 (remove-hook 'kill-buffer-hook
4928 'mml-destroy-buffers t)
4929 (kill-local-variable 'mml-buffer-list))
4930 (gnus-summary-edit-article-done
4931 ,(or (mail-header-references gnus-current-headers) "")
4932 ,(gnus-group-read-only-p)
4933 ,gnus-summary-buffer no-highlight))
4934 t)
4935 (gnus-article-edit-done)
4936 (gnus-configure-windows 'article)
4937 (when (and current-id (integerp gnus-auto-select-part))
4938 (gnus-article-jump-to-part (+ current-id gnus-auto-select-part)))))
4939
4940 (defun gnus-mime-replace-part (file)
4941 "Replace MIME part under point with an external body."
4942 ;; Useful if file has already been saved to disk
4943 (interactive
4944 (list
4945 (read-file-name "Replace MIME part with file: "
4946 (or mm-default-directory default-directory)
4947 nil nil)))
4948 (gnus-mime-save-part-and-strip file))
4949
4950 (defun gnus-mime-save-part-and-strip (&optional file)
4951 "Save the MIME part under point then replace it with an external body.
4952 If FILE is given, use it for the external part."
4953 (interactive)
4954 (gnus-article-check-buffer)
4955 (when (gnus-group-read-only-p)
4956 (error "The current group does not support deleting of parts"))
4957 (when (mm-complicated-handles gnus-article-mime-handles)
4958 (error "\
4959 The current article has a complicated MIME structure, giving up..."))
4960 (let* ((data (get-text-property (point) 'gnus-data))
4961 (id (get-text-property (point) 'gnus-part))
4962 param
4963 (handles gnus-article-mime-handles))
4964 (unless file
4965 (setq file
4966 (and data (mm-save-part data "Delete MIME part and save to: "))))
4967 (when file
4968 (with-current-buffer (mm-handle-buffer data)
4969 (erase-buffer)
4970 (insert "Content-Type: " (mm-handle-media-type data))
4971 (mml-insert-parameter-string (cdr (mm-handle-type data))
4972 '(charset))
4973 ;; Add a filename for the sake of saving the part again.
4974 (mml-insert-parameter
4975 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4976 (insert "\n")
4977 (insert "Content-ID: " (message-make-message-id) "\n")
4978 (insert "Content-Transfer-Encoding: binary\n")
4979 (insert "\n"))
4980 (setcdr data
4981 (cdr (mm-make-handle nil
4982 `("message/external-body"
4983 (access-type . "LOCAL-FILE")
4984 (name . ,file)))))
4985 ;; (set-buffer gnus-summary-buffer)
4986 (gnus-article-edit-part handles id))))
4987
4988 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4989 ;; parts...>') but with stripping would be nice.
4990
4991 (defun gnus-mime-delete-part ()
4992 "Delete the MIME part under point.
4993 Replace it with some information about the removed part."
4994 (interactive)
4995 (gnus-article-check-buffer)
4996 (when (gnus-group-read-only-p)
4997 (error "The current group does not support deleting of parts"))
4998 (when (mm-complicated-handles gnus-article-mime-handles)
4999 (error "\
5000 The current article has a complicated MIME structure, giving up..."))
5001 (when (or gnus-expert-user
5002 (gnus-yes-or-no-p "\
5003 Deleting parts may malfunction or destroy the article; continue? "))
5004 (let* ((data (get-text-property (point) 'gnus-data))
5005 (id (get-text-property (point) 'gnus-part))
5006 (handles gnus-article-mime-handles)
5007 (none "(none)")
5008 (description
5009 (let ((desc (mm-handle-description data)))
5010 (when desc
5011 (mail-decode-encoded-word-string desc))))
5012 (filename
5013 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5014 none))
5015 (type (mm-handle-media-type data)))
5016 (unless data
5017 (error "No MIME part under point"))
5018 (with-current-buffer (mm-handle-buffer data)
5019 (let ((bsize (format "%s" (buffer-size))))
5020 (erase-buffer)
5021 (insert
5022 (concat
5023 ",----\n"
5024 "| The following attachment has been deleted:\n"
5025 "|\n"
5026 "| Type: " type "\n"
5027 "| Filename: " filename "\n"
5028 "| Size (encoded): " bsize " Byte\n"
5029 (when description
5030 (concat "| Description: " description "\n"))
5031 "`----\n"))
5032 (setcdr data
5033 (cdr (mm-make-handle
5034 nil `("text/plain" (charset . gnus-decoded)) nil nil
5035 (list "attachment")
5036 (format "Deleted attachment (%s bytes)" bsize))))))
5037 ;; (set-buffer gnus-summary-buffer)
5038 (gnus-article-edit-part handles id))))
5039
5040 (defun gnus-mime-save-part ()
5041 "Save the MIME part under point."
5042 (interactive)
5043 (gnus-article-check-buffer)
5044 (let ((data (get-text-property (point) 'gnus-data)))
5045 (when data
5046 (mm-save-part data))))
5047
5048 (defun gnus-mime-pipe-part (&optional cmd)
5049 "Pipe the MIME part under point to a process.
5050 Use CMD as the process."
5051 (interactive)
5052 (gnus-article-check-buffer)
5053 (let ((data (get-text-property (point) 'gnus-data)))
5054 (when data
5055 (mm-pipe-part data cmd))))
5056
5057 (defun gnus-mime-view-part ()
5058 "Interactively choose a viewing method for the MIME part under point."
5059 (interactive)
5060 (gnus-article-check-buffer)
5061 (let ((data (get-text-property (point) 'gnus-data)))
5062 (when data
5063 (setq gnus-article-mime-handles
5064 (mm-merge-handles
5065 gnus-article-mime-handles (setq data (copy-sequence data))))
5066 (mm-interactively-view-part data))))
5067
5068 (defun gnus-mime-view-part-as-type-internal ()
5069 (gnus-article-check-buffer)
5070 (let* ((handle (get-text-property (point) 'gnus-data))
5071 (name (or
5072 ;; Content-Type: foo/bar; name=...
5073 (mail-content-type-get (mm-handle-type handle) 'name)
5074 ;; Content-Disposition: attachment; filename=...
5075 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5076 (def-type (and name (mm-default-file-encoding name))))
5077 (or (and def-type (cons def-type 0))
5078 (and handle
5079 (equal (mm-handle-media-supertype handle) "text")
5080 '("text/plain" . 0))
5081 '("application/octet-stream" . 0))))
5082
5083 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5084 "Choose a MIME media type, and view the part as such.
5085 If non-nil, PRED is a predicate to use during completion to limit the
5086 available media-types."
5087 (interactive)
5088 (unless mime-type
5089 (setq mime-type
5090 (let ((default (gnus-mime-view-part-as-type-internal)))
5091 (completing-read
5092 (format "View as MIME type (default %s): "
5093 (car default))
5094 (mapcar #'list (mailcap-mime-types))
5095 pred nil nil nil
5096 (car default)))))
5097 (gnus-article-check-buffer)
5098 (let ((handle (get-text-property (point) 'gnus-data)))
5099 (when handle
5100 (when (equal (mm-handle-media-type handle) "message/external-body")
5101 (unless (mm-handle-cache handle)
5102 (mm-extern-cache-contents handle))
5103 (setq handle (mm-handle-cache handle)))
5104 (setq handle
5105 (mm-make-handle (mm-handle-buffer handle)
5106 (cons mime-type (cdr (mm-handle-type handle)))
5107 (mm-handle-encoding handle)
5108 (mm-handle-undisplayer handle)
5109 (mm-handle-disposition handle)
5110 (mm-handle-description handle)
5111 nil
5112 (mm-handle-id handle)))
5113 (setq gnus-article-mime-handles
5114 (mm-merge-handles gnus-article-mime-handles handle))
5115 (when (mm-handle-displayed-p handle)
5116 (mm-remove-part handle))
5117 (gnus-mm-display-part handle))))
5118
5119 (defun gnus-mime-copy-part (&optional handle arg)
5120 "Put the MIME part under point into a new buffer.
5121 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5122 are decompressed."
5123 (interactive (list nil current-prefix-arg))
5124 (gnus-article-check-buffer)
5125 (unless handle
5126 (setq handle (get-text-property (point) 'gnus-data)))
5127 (when handle
5128 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5129 'name)
5130 (mail-content-type-get (mm-handle-disposition handle)
5131 'filename)))
5132 contents dont-decode charset coding-system)
5133 (mm-with-unibyte-buffer
5134 (mm-insert-part handle)
5135 (setq contents (or (condition-case nil
5136 (mm-decompress-buffer filename nil 'sig)
5137 (error
5138 (setq dont-decode t)
5139 nil))
5140 (buffer-string))))
5141 (setq filename (cond (filename (file-name-nondirectory filename))
5142 (dont-decode "*raw data*")
5143 (t "*decoded*")))
5144 (cond
5145 (dont-decode)
5146 ((not arg)
5147 (unless (setq charset (mail-content-type-get
5148 (mm-handle-type handle) 'charset))
5149 (unless (setq coding-system (mm-with-unibyte-buffer
5150 (insert contents)
5151 (mm-find-buffer-file-coding-system)))
5152 (setq charset gnus-newsgroup-charset))))
5153 ((numberp arg)
5154 (setq charset (or (cdr (assq arg
5155 gnus-summary-show-article-charset-alist))
5156 (mm-read-coding-system "Charset: ")))))
5157 (switch-to-buffer (generate-new-buffer filename))
5158 (if (or coding-system
5159 (and charset
5160 (setq coding-system (mm-charset-to-coding-system charset))
5161 (not (eq charset 'ascii))))
5162 (progn
5163 (mm-enable-multibyte)
5164 (insert (mm-decode-coding-string contents coding-system))
5165 (setq buffer-file-coding-system
5166 (if (boundp 'last-coding-system-used)
5167 (symbol-value 'last-coding-system-used)
5168 coding-system)))
5169 (mm-disable-multibyte)
5170 (insert contents)
5171 (setq buffer-file-coding-system mm-binary-coding-system))
5172 ;; We do it this way to make `normal-mode' set the appropriate mode.
5173 (unwind-protect
5174 (progn
5175 (setq buffer-file-name (expand-file-name filename))
5176 (normal-mode))
5177 (setq buffer-file-name nil))
5178 (goto-char (point-min)))))
5179
5180 (defun gnus-mime-print-part (&optional handle filename)
5181 "Print the MIME part under point."
5182 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5183 (gnus-article-check-buffer)
5184 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5185 (contents (and handle (mm-get-part handle)))
5186 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5187 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5188 (when contents
5189 (if printer
5190 (unwind-protect
5191 (progn
5192 (mm-save-part-to-file handle file)
5193 (call-process shell-file-name nil
5194 (generate-new-buffer " *mm*")
5195 nil
5196 shell-command-switch
5197 (mm-mailcap-command
5198 printer file (mm-handle-type handle))))
5199 (delete-file file))
5200 (with-temp-buffer
5201 (insert contents)
5202 (gnus-print-buffer))
5203 (ps-despool filename)))))
5204
5205 (defun gnus-mime-inline-part (&optional handle arg)
5206 "Insert the MIME part under point into the current buffer.
5207 Compressed files like .gz and .bz2 are decompressed."
5208 (interactive (list nil current-prefix-arg))
5209 (gnus-article-check-buffer)
5210 (unless handle
5211 (setq handle (get-text-property (point) 'gnus-data)))
5212 (when handle
5213 (let ((b (point))
5214 (inhibit-read-only t)
5215 contents charset coding-system)
5216 (if (and (not arg) (mm-handle-undisplayer handle))
5217 (mm-remove-part handle)
5218 (mm-with-unibyte-buffer
5219 (mm-insert-part handle)
5220 (setq contents
5221 (or (mm-decompress-buffer
5222 (or (mail-content-type-get (mm-handle-type handle)
5223 'name)
5224 (mail-content-type-get (mm-handle-disposition handle)
5225 'filename))
5226 nil t)
5227 (buffer-string))))
5228 (cond
5229 ((not arg)
5230 (unless (setq charset (mail-content-type-get
5231 (mm-handle-type handle) 'charset))
5232 (unless (setq coding-system
5233 (mm-with-unibyte-buffer
5234 (insert contents)
5235 (mm-find-buffer-file-coding-system)))
5236 (setq charset gnus-newsgroup-charset))))
5237 ((numberp arg)
5238 (if (mm-handle-undisplayer handle)
5239 (mm-remove-part handle))
5240 (setq charset
5241 (or (cdr (assq arg
5242 gnus-summary-show-article-charset-alist))
5243 (mm-read-coding-system "Charset: "))))
5244 (t
5245 (if (mm-handle-undisplayer handle)
5246 (mm-remove-part handle))))
5247 (forward-line 2)
5248 (mm-insert-inline
5249 handle
5250 (if (or coding-system
5251 (and charset
5252 (setq coding-system
5253 (mm-charset-to-coding-system charset))
5254 (not (eq coding-system 'ascii))))
5255 (mm-decode-coding-string contents coding-system)
5256 (mm-string-to-multibyte contents)))
5257 (goto-char b)))))
5258
5259 (defun gnus-mime-set-charset-parameters (handle charset)
5260 "Set CHARSET to parameters in HANDLE.
5261 CHARSET may either be a string or a symbol."
5262 (unless (stringp charset)
5263 (setq charset (symbol-name charset)))
5264 (if (stringp (car handle))
5265 (dolist (h (cdr handle))
5266 (gnus-mime-set-charset-parameters h charset))
5267 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5268 "message/external-body")
5269 (progn
5270 (unless (mm-handle-cache handle)
5271 (mm-extern-cache-contents handle))
5272 (mm-handle-cache handle))
5273 handle)))
5274 (param (assq 'charset (cdr type))))
5275 (if param
5276 (setcdr param charset)
5277 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5278
5279 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5280 "Insert the MIME part under point into the current buffer using the
5281 specified charset."
5282 (interactive (list nil current-prefix-arg))
5283 (gnus-article-check-buffer)
5284 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5285 (fun (get-text-property (point) 'gnus-callback))
5286 (gnus-newsgroup-ignored-charsets 'gnus-all)
5287 charset form preferred parts)
5288 (when handle
5289 (when (prog1
5290 (and fun
5291 (setq charset
5292 (or (cdr (assq
5293 arg
5294 gnus-summary-show-article-charset-alist))
5295 (mm-read-coding-system "Charset: "))))
5296 (if (mm-handle-undisplayer handle)
5297 (mm-remove-part handle)))
5298 (gnus-mime-set-charset-parameters handle charset)
5299 (when (and (consp (setq form (cdr-safe fun)))
5300 (setq form (ignore-errors
5301 (assq 'gnus-mime-display-alternative form)))
5302 (setq preferred (caddr form))
5303 (progn
5304 (when (eq (car preferred) 'quote)
5305 (setq preferred (cadr preferred)))
5306 (not (equal preferred
5307 (get-text-property (point) 'gnus-data))))
5308 (setq parts (get-text-property (point) 'gnus-part))
5309 (setq parts (cdr (assq parts
5310 gnus-article-mime-handle-alist)))
5311 (equal (mm-handle-media-type parts) "multipart/alternative")
5312 (setq parts (reverse (cdr parts))))
5313 (setcar (cddr form)
5314 (list 'quote (or (cadr (member preferred parts))
5315 (car parts)))))
5316 (funcall fun handle)))))
5317
5318 (defun gnus-mime-view-part-externally (&optional handle)
5319 "View the MIME part under point with an external viewer."
5320 (interactive)
5321 (gnus-article-check-buffer)
5322 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5323 (mm-user-display-methods nil)
5324 (mm-inlined-types nil)
5325 (mail-parse-charset gnus-newsgroup-charset)
5326 (mail-parse-ignored-charsets
5327 (with-current-buffer gnus-summary-buffer
5328 gnus-newsgroup-ignored-charsets))
5329 (type (mm-handle-media-type handle))
5330 (method (mailcap-mime-info type))
5331 (mm-enable-external t))
5332 (if (not (stringp method))
5333 (gnus-mime-view-part-as-type
5334 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5335 (when handle
5336 (if (mm-handle-undisplayer handle)
5337 (mm-remove-part handle)
5338 (mm-display-part handle))))))
5339
5340 (defun gnus-mime-view-part-internally (&optional handle)
5341 "View the MIME part under point with an internal viewer.
5342 If no internal viewer is available, use an external viewer."
5343 (interactive)
5344 (gnus-article-check-buffer)
5345 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5346 (mm-inlined-types '(".*"))
5347 (mm-inline-large-images t)
5348 (mail-parse-charset gnus-newsgroup-charset)
5349 (mail-parse-ignored-charsets
5350 (with-current-buffer gnus-summary-buffer
5351 gnus-newsgroup-ignored-charsets))
5352 (inhibit-read-only t))
5353 (if (not (mm-inlinable-p handle))
5354 (gnus-mime-view-part-as-type
5355 nil (lambda (types) (mm-inlinable-p handle (car types))))
5356 (when handle
5357 (if (mm-handle-undisplayer handle)
5358 (mm-remove-part handle)
5359 (gnus-bind-safe-url-regexp (mm-display-part handle)))))))
5360
5361 (defun gnus-mime-action-on-part (&optional action)
5362 "Do something with the MIME attachment at \(point\)."
5363 (interactive
5364 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5365 (gnus-article-check-buffer)
5366 (let ((action-pair (assoc action gnus-mime-action-alist)))
5367 (if action-pair
5368 (funcall (cdr action-pair)))))
5369
5370 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5371 "Call FUNCTION on MIME part N.
5372 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5373 If INTERACTIVE, call FUNCTION interactivly."
5374 (let (window frame)
5375 ;; Check whether the article is displayed.
5376 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5377 (setq window (get-buffer-window gnus-article-buffer t))
5378 (frame-visible-p (setq frame (window-frame window))))
5379 (error "No article is displayed"))
5380 (with-current-buffer gnus-article-buffer
5381 ;; Check whether the article displays the right contents.
5382 (unless (with-current-buffer gnus-summary-buffer
5383 (eq gnus-current-article (gnus-summary-article-number)))
5384 (error "You should select the right article first"))
5385 (if n
5386 (setq n (prefix-numeric-value n))
5387 (let ((pt (point)))
5388 (setq n (or (get-text-property pt 'gnus-part)
5389 (and (not (bobp))
5390 (get-text-property (1- pt) 'gnus-part))
5391 (get-text-property (prog2
5392 (forward-line 1)
5393 (point)
5394 (goto-char pt))
5395 'gnus-part)
5396 (get-text-property
5397 (or (and (setq pt (previous-single-property-change
5398 pt 'gnus-part))
5399 (1- pt))
5400 (next-single-property-change (point) 'gnus-part)
5401 (point))
5402 'gnus-part)
5403 1))))
5404 ;; Check whether the specified part exists.
5405 (when (> n (length gnus-article-mime-handle-alist))
5406 (error "No such part")))
5407 (unless
5408 (progn
5409 ;; To select the window is needed so that the cursor
5410 ;; might be visible on the MIME button.
5411 (select-window (prog1
5412 window
5413 (setq window (selected-window))
5414 ;; Article may be displayed in the other frame.
5415 (gnus-select-frame-set-input-focus
5416 (prog1
5417 frame
5418 (setq frame (selected-frame))))))
5419 (when (gnus-article-goto-part n)
5420 ;; We point the cursor and the arrow at the MIME button
5421 ;; when the `function' prompt the user for something.
5422 (let ((cursor-in-non-selected-windows t)
5423 (overlay-arrow-string "=>")
5424 (overlay-arrow-position (point-marker)))
5425 (unwind-protect
5426 (cond
5427 ((and no-handle interactive)
5428 (call-interactively function))
5429 (no-handle
5430 (funcall function))
5431 (interactive
5432 (call-interactively
5433 function
5434 (cdr (assq n gnus-article-mime-handle-alist))))
5435 (t
5436 (funcall function
5437 (cdr (assq n gnus-article-mime-handle-alist)))))
5438 (set-marker overlay-arrow-position nil)
5439 (unless gnus-auto-select-part
5440 (gnus-select-frame-set-input-focus frame)
5441 (select-window window))))
5442 t))
5443 (if gnus-inhibit-mime-unbuttonizing
5444 ;; This is the default though the program shouldn't reach here.
5445 (error "No such part")
5446 ;; The part which doesn't have the MIME button is selected.
5447 ;; So, we display all the buttons and redo it.
5448 (let ((gnus-inhibit-mime-unbuttonizing t))
5449 (gnus-summary-show-article)
5450 (gnus-article-part-wrapper n function no-handle))))))
5451
5452 (defun gnus-article-pipe-part (n)
5453 "Pipe MIME part N, which is the numerical prefix."
5454 (interactive "P")
5455 (gnus-article-part-wrapper n 'mm-pipe-part))
5456
5457 (defun gnus-article-save-part (n)
5458 "Save MIME part N, which is the numerical prefix."
5459 (interactive "P")
5460 (gnus-article-part-wrapper n 'mm-save-part))
5461
5462 (defun gnus-article-interactively-view-part (n)
5463 "View MIME part N interactively, which is the numerical prefix."
5464 (interactive "P")
5465 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5466
5467 (defun gnus-article-copy-part (n)
5468 "Copy MIME part N, which is the numerical prefix."
5469 (interactive "P")
5470 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5471
5472 (defun gnus-article-view-part-as-charset (n)
5473 "View MIME part N using a specified charset.
5474 N is the numerical prefix."
5475 (interactive "P")
5476 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5477
5478 (defun gnus-article-view-part-externally (n)
5479 "View MIME part N externally, which is the numerical prefix."
5480 (interactive "P")
5481 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5482
5483 (defun gnus-article-inline-part (n)
5484 "Inline MIME part N, which is the numerical prefix."
5485 (interactive "P")
5486 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5487
5488 (defun gnus-article-save-part-and-strip (n)
5489 "Save MIME part N and replace it with an external body.
5490 N is the numerical prefix."
5491 (interactive "P")
5492 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5493
5494 (defun gnus-article-replace-part (n)
5495 "Replace MIME part N with an external body.
5496 N is the numerical prefix."
5497 (interactive "P")
5498 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5499
5500 (defun gnus-article-delete-part (n)
5501 "Delete MIME part N and add some information about the removed part.
5502 N is the numerical prefix."
5503 (interactive "P")
5504 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5505
5506 (defun gnus-article-view-part-as-type (n)
5507 "Choose a MIME media type, and view part N as such.
5508 N is the numerical prefix."
5509 (interactive "P")
5510 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5511
5512 (defun gnus-article-mime-match-handle-first (condition)
5513 (if condition
5514 (let (n)
5515 (dolist (ihandle gnus-article-mime-handle-alist)
5516 (if (and (cond
5517 ((functionp condition)
5518 (funcall condition (cdr ihandle)))
5519 ((eq condition 'undisplayed)
5520 (not (or (mm-handle-undisplayer (cdr ihandle))
5521 (equal (mm-handle-media-type (cdr ihandle))
5522 "multipart/alternative"))))
5523 ((eq condition 'undisplayed-alternative)
5524 (not (mm-handle-undisplayer (cdr ihandle))))
5525 (t t))
5526 (gnus-article-goto-part (car ihandle))
5527 (or (not n) (< (car ihandle) n)))
5528 (setq n (car ihandle))))
5529 (or n 1))
5530 1))
5531
5532 (defun gnus-article-view-part (&optional n)
5533 "View MIME part N, which is the numerical prefix."
5534 (interactive "P")
5535 (with-current-buffer gnus-article-buffer
5536 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5537 gnus-article-mime-match-handle-function)))
5538 (when (> n (length gnus-article-mime-handle-alist))
5539 (error "No such part"))
5540 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5541 (when (gnus-article-goto-part n)
5542 (if (equal (car handle) "multipart/alternative")
5543 (gnus-article-press-button)
5544 (when (eq (gnus-mm-display-part handle) 'internal)
5545 (gnus-set-window-start)))))))
5546
5547 (defsubst gnus-article-mime-total-parts ()
5548 (if (bufferp (car gnus-article-mime-handles))
5549 1 ;; single part
5550 (1- (length gnus-article-mime-handles))))
5551
5552 (defun gnus-mm-display-part (handle)
5553 "Display HANDLE and fix MIME button."
5554 (let ((id (get-text-property (point) 'gnus-part))
5555 (point (point))
5556 (inhibit-read-only t))
5557 (forward-line 1)
5558 (prog1
5559 (let ((window (selected-window))
5560 (mail-parse-charset gnus-newsgroup-charset)
5561 (mail-parse-ignored-charsets
5562 (if (gnus-buffer-live-p gnus-summary-buffer)
5563 (with-current-buffer gnus-summary-buffer
5564 gnus-newsgroup-ignored-charsets)
5565 nil)))
5566 (save-excursion
5567 (unwind-protect
5568 (let ((win (gnus-get-buffer-window (current-buffer) t))
5569 (beg (point)))
5570 (when win
5571 (select-window win))
5572 (goto-char point)
5573 (forward-line)
5574 (if (mm-handle-displayed-p handle)
5575 ;; This will remove the part.
5576 (mm-display-part handle)
5577 (save-restriction
5578 (narrow-to-region (point)
5579 (if (eobp) (point) (1+ (point))))
5580 (gnus-bind-safe-url-regexp (mm-display-part handle))
5581 ;; We narrow to the part itself and
5582 ;; then call the treatment functions.
5583 (goto-char (point-min))
5584 (forward-line 1)
5585 (narrow-to-region (point) (point-max))
5586 (gnus-treat-article
5587 nil id
5588 (gnus-article-mime-total-parts)
5589 (mm-handle-media-type handle)))))
5590 (if (window-live-p window)
5591 (select-window window)))))
5592 (goto-char point)
5593 (gnus-delete-line)
5594 (gnus-insert-mime-button
5595 handle id (list (mm-handle-displayed-p handle)))
5596 (goto-char point))))
5597
5598 (defun gnus-article-goto-part (n)
5599 "Go to MIME part N."
5600 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5601
5602 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5603 (let ((gnus-tmp-name
5604 (or (mail-content-type-get (mm-handle-type handle) 'name)
5605 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5606 (mail-content-type-get (mm-handle-type handle) 'url)
5607 ""))
5608 (gnus-tmp-type (mm-handle-media-type handle))
5609 (gnus-tmp-description (or (mm-handle-description handle) ""))
5610 (gnus-tmp-dots
5611 (if (if displayed (car displayed)
5612 (mm-handle-displayed-p handle))
5613 "" "..."))
5614 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5615 (buffer-size)))
5616 gnus-tmp-type-long b e)
5617 (when (string-match ".*/" gnus-tmp-name)
5618 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5619 (setq gnus-tmp-type-long (concat gnus-tmp-type
5620 (and (not (equal gnus-tmp-name ""))
5621 (concat "; " gnus-tmp-name))))
5622 (unless (equal gnus-tmp-description "")
5623 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5624 (unless (bolp)
5625 (insert "\n"))
5626 (setq b (point))
5627 (gnus-eval-format
5628 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5629 `(keymap ,gnus-mime-button-map
5630 gnus-callback gnus-mm-display-part
5631 gnus-part ,gnus-tmp-id
5632 article-type annotation
5633 gnus-data ,handle))
5634 (setq e (if (bolp)
5635 ;; Exclude a newline.
5636 (1- (point))
5637 (point)))
5638 (when gnus-article-button-face
5639 (gnus-overlay-put (gnus-make-overlay b e nil t)
5640 'face gnus-article-button-face))
5641 (widget-convert-button
5642 'link b e
5643 :mime-handle handle
5644 :action 'gnus-widget-press-button
5645 :button-keymap gnus-mime-button-map
5646 :help-echo
5647 (lambda (widget/window &optional overlay pos)
5648 ;; Needed to properly clear the message due to a bug in
5649 ;; wid-edit (XEmacs only).
5650 (if (boundp 'help-echo-owns-message)
5651 (setq help-echo-owns-message t))
5652 (format
5653 "%S: %s the MIME part; %S: more options"
5654 (aref gnus-mouse-2 0)
5655 ;; XEmacs will get a single widget arg; Emacs 21 will get
5656 ;; window, overlay, position.
5657 (if (mm-handle-displayed-p
5658 (if overlay
5659 (with-current-buffer (gnus-overlay-buffer overlay)
5660 (widget-get (widget-at (gnus-overlay-start overlay))
5661 :mime-handle))
5662 (widget-get widget/window :mime-handle)))
5663 "hide" "show")
5664 (aref gnus-down-mouse-3 0))))))
5665
5666 (defun gnus-widget-press-button (elems el)
5667 (goto-char (widget-get elems :from))
5668 (gnus-article-press-button))
5669
5670 (defvar gnus-displaying-mime nil)
5671
5672 (defun gnus-display-mime (&optional ihandles)
5673 "Display the MIME parts."
5674 (save-excursion
5675 (save-selected-window
5676 (let ((window (get-buffer-window gnus-article-buffer))
5677 (point (point)))
5678 (when window
5679 (select-window window)
5680 ;; We have to do this since selecting the window
5681 ;; may change the point. So we set the window point.
5682 (set-window-point window point)))
5683 (let ((handles ihandles)
5684 (inhibit-read-only t)
5685 handle)
5686 (cond (handles)
5687 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5688 (when gnus-article-emulate-mime
5689 (mm-uu-dissect-text-parts handles)))
5690 (gnus-article-emulate-mime
5691 (setq handles (mm-uu-dissect))))
5692 (when (and (not ihandles)
5693 (not gnus-displaying-mime))
5694 ;; Top-level call; we clean up.
5695 (when gnus-article-mime-handles
5696 (mm-destroy-parts gnus-article-mime-handles)
5697 (setq gnus-article-mime-handle-alist nil));; A trick.
5698 (setq gnus-article-mime-handles handles)
5699 ;; We allow users to glean info from the handles.
5700 (when gnus-article-mime-part-function
5701 (gnus-mime-part-function handles)))
5702 (if (and handles
5703 (or (not (stringp (car handles)))
5704 (cdr handles)))
5705 (progn
5706 (when (and (not ihandles)
5707 (not gnus-displaying-mime))
5708 ;; Clean up for mime parts.
5709 (article-goto-body)
5710 (delete-region (point) (point-max)))
5711 (let ((gnus-displaying-mime t))
5712 (gnus-mime-display-part handles)))
5713 (save-restriction
5714 (article-goto-body)
5715 (narrow-to-region (point) (point-max))
5716 (gnus-treat-article nil 1 1)
5717 (widen)))
5718 (unless ihandles
5719 ;; Highlight the headers.
5720 (save-excursion
5721 (save-restriction
5722 (article-goto-body)
5723 (narrow-to-region (point-min) (point))
5724 (gnus-article-save-original-date
5725 (gnus-treat-article 'head)))))))
5726 ;; Cope with broken MIME messages.
5727 (goto-char (point-max))
5728 (unless (bolp)
5729 (insert "\n"))))
5730
5731 (defcustom gnus-mime-display-multipart-as-mixed nil
5732 "Display \"multipart\" parts as \"multipart/mixed\".
5733
5734 If t, it overrides nil values of
5735 `gnus-mime-display-multipart-alternative-as-mixed' and
5736 `gnus-mime-display-multipart-related-as-mixed'."
5737 :group 'gnus-article-mime
5738 :type 'boolean)
5739
5740 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5741 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5742 :version "22.1"
5743 :group 'gnus-article-mime
5744 :type 'boolean)
5745
5746 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5747 "Display \"multipart/related\" parts as \"multipart/mixed\".
5748
5749 If displaying \"text/html\" is discouraged \(see
5750 `mm-discouraged-alternatives'\) images or other material inside a
5751 \"multipart/related\" part might be overlooked when this variable is nil."
5752 :version "22.1"
5753 :group 'gnus-article-mime
5754 :type 'boolean)
5755
5756 (defun gnus-mime-display-part (handle)
5757 (cond
5758 ;; Maybe a broken MIME message.
5759 ((null handle))
5760 ;; Single part.
5761 ((not (stringp (car handle)))
5762 (gnus-mime-display-single handle))
5763 ;; User-defined multipart
5764 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5765 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5766 handle))
5767 ;; multipart/alternative
5768 ((and (equal (car handle) "multipart/alternative")
5769 (not (or gnus-mime-display-multipart-as-mixed
5770 gnus-mime-display-multipart-alternative-as-mixed)))
5771 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5772 (push (cons id handle) gnus-article-mime-handle-alist)
5773 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5774 ;; multipart/related
5775 ((and (equal (car handle) "multipart/related")
5776 (not (or gnus-mime-display-multipart-as-mixed
5777 gnus-mime-display-multipart-related-as-mixed)))
5778 ;;;!!!We should find the start part, but we just default
5779 ;;;!!!to the first part.
5780 ;;(gnus-mime-display-part (cadr handle))
5781 ;;;!!! Most multipart/related is an HTML message plus images.
5782 ;;;!!! Unfortunately we are unable to let W3 display those
5783 ;;;!!! included images, so we just display it as a mixed multipart.
5784 ;;(gnus-mime-display-mixed (cdr handle))
5785 ;;;!!! No, w3 can display everything just fine.
5786 (gnus-mime-display-part (cadr handle)))
5787 ((equal (car handle) "multipart/signed")
5788 (gnus-add-wash-type 'signed)
5789 (gnus-mime-display-security handle))
5790 ((equal (car handle) "multipart/encrypted")
5791 (gnus-add-wash-type 'encrypted)
5792 (gnus-mime-display-security handle))
5793 ;; Other multiparts are handled like multipart/mixed.
5794 (t
5795 (gnus-mime-display-mixed (cdr handle)))))
5796
5797 (defun gnus-mime-part-function (handles)
5798 (if (stringp (car handles))
5799 (mapcar 'gnus-mime-part-function (cdr handles))
5800 (funcall gnus-article-mime-part-function handles)))
5801
5802 (defun gnus-mime-display-mixed (handles)
5803 (mapcar 'gnus-mime-display-part handles))
5804
5805 (defun gnus-mime-display-single (handle)
5806 (let ((type (mm-handle-media-type handle))
5807 (ignored gnus-ignored-mime-types)
5808 (not-attachment t)
5809 (move nil)
5810 display text)
5811 (catch 'ignored
5812 (progn
5813 (while ignored
5814 (when (string-match (pop ignored) type)
5815 (throw 'ignored nil)))
5816 (if (and (setq not-attachment
5817 (and (not (mm-inline-override-p handle))
5818 (or (not (mm-handle-disposition handle))
5819 (equal (car (mm-handle-disposition handle))
5820 "inline")
5821 (mm-attachment-override-p handle))))
5822 (mm-automatic-display-p handle)
5823 (or (and
5824 (mm-inlinable-p handle)
5825 (mm-inlined-p handle))
5826 (mm-automatic-external-display-p type)))
5827 (setq display t)
5828 (when (equal (mm-handle-media-supertype handle) "text")
5829 (setq text t)))
5830 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5831 beg)
5832 (push (cons id handle) gnus-article-mime-handle-alist)
5833 (when (and display
5834 (equal (mm-handle-media-supertype handle) "message"))
5835 (insert-char
5836 ?\n
5837 (cond ((not (bolp)) 2)
5838 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5839 (t 1))))
5840 (when (or (not display)
5841 (not (gnus-unbuttonized-mime-type-p type)))
5842 (gnus-insert-mime-button
5843 handle id (list (or display (and not-attachment text))))
5844 (gnus-article-insert-newline)
5845 ;; Remember modify the number of forward lines.
5846 (setq move t))
5847 (setq beg (point))
5848 (cond
5849 (display
5850 (when move
5851 (forward-line -1)
5852 (setq beg (point)))
5853 (let ((mail-parse-charset gnus-newsgroup-charset)
5854 (mail-parse-ignored-charsets
5855 (save-excursion (condition-case ()
5856 (set-buffer gnus-summary-buffer)
5857 (error))
5858 gnus-newsgroup-ignored-charsets)))
5859 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5860 (goto-char (point-max)))
5861 ((and text not-attachment)
5862 (when move
5863 (forward-line -1)
5864 (setq beg (point)))
5865 (gnus-article-insert-newline)
5866 (mm-insert-inline
5867 handle
5868 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5869 'charset)
5870 (and (equal type "text/calendar") 'utf-8))))
5871 (cond ((not charset)
5872 (mm-string-as-multibyte (mm-get-part handle)))
5873 ((eq charset 'gnus-decoded)
5874 (with-current-buffer (mm-handle-buffer handle)
5875 (buffer-string)))
5876 (t
5877 (mm-decode-string (mm-get-part handle) charset)))))
5878 (goto-char (point-max))))
5879 ;; Do highlighting.
5880 (save-excursion
5881 (save-restriction
5882 (narrow-to-region beg (point))
5883 (if (eq handle gnus-article-mime-handles)
5884 ;; The format=flowed case.
5885 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5886 ;; Don't count signature parts that are never displayed.
5887 ;; The part number should be re-calculated supposing this
5888 ;; might be a message/rfc822 part.
5889 (let (handles)
5890 (dolist (part gnus-article-mime-handles)
5891 (unless (or (stringp part)
5892 (equal (car (mm-handle-type part))
5893 "application/pgp-signature"))
5894 (push part handles)))
5895 (gnus-treat-article
5896 nil (length (memq handle handles)) (length handles)
5897 (mm-handle-media-type handle)))))))))))
5898
5899 (defun gnus-unbuttonized-mime-type-p (type)
5900 "Say whether TYPE is to be unbuttonized."
5901 (unless gnus-inhibit-mime-unbuttonizing
5902 (when (catch 'found
5903 (let ((types gnus-unbuttonized-mime-types))
5904 (while types
5905 (when (string-match (pop types) type)
5906 (throw 'found t)))))
5907 (not (catch 'found
5908 (let ((types gnus-buttonized-mime-types))
5909 (while types
5910 (when (string-match (pop types) type)
5911 (throw 'found t)))))))))
5912
5913 (defun gnus-article-insert-newline ()
5914 "Insert a newline, but mark it as undeletable."
5915 (gnus-put-text-property
5916 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5917
5918 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5919 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5920 (ihandles handles)
5921 (point (point))
5922 handle (inhibit-read-only t) from props begend not-pref)
5923 (save-window-excursion
5924 (save-restriction
5925 (when ibegend
5926 (narrow-to-region (car ibegend)
5927 (or (cdr ibegend)
5928 (progn
5929 (goto-char (car ibegend))
5930 (forward-line 2)
5931 (point))))
5932 (delete-region (point-min) (point-max))
5933 (mm-remove-parts handles))
5934 (setq begend (list (point-marker)))
5935 ;; Do the toggle.
5936 (unless (setq not-pref (cadr (member preferred ihandles)))
5937 (setq not-pref (car ihandles)))
5938 (when (or ibegend
5939 (not preferred)
5940 (not (gnus-unbuttonized-mime-type-p
5941 "multipart/alternative")))
5942 (gnus-add-text-properties
5943 (setq from (point))
5944 (progn
5945 (insert (format "%d. " id))
5946 (point))
5947 `(gnus-callback
5948 (lambda (handles)
5949 (unless ,(not ibegend)
5950 (setq gnus-article-mime-handle-alist
5951 ',gnus-article-mime-handle-alist))
5952 (gnus-mime-display-alternative
5953 ',ihandles ',not-pref ',begend ,id))
5954 keymap ,gnus-mime-button-map
5955 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5956 face ,gnus-article-button-face
5957 gnus-part ,id
5958 article-type multipart))
5959 (widget-convert-button 'link from (point)
5960 :action 'gnus-widget-press-button
5961 :button-keymap gnus-widget-button-keymap)
5962 ;; Do the handles
5963 (while (setq handle (pop handles))
5964 (gnus-add-text-properties
5965 (setq from (point))
5966 (progn
5967 (insert (format "(%c) %-18s"
5968 (if (equal handle preferred) ?* ? )
5969 (mm-handle-media-type handle)))
5970 (point))
5971 `(gnus-callback
5972 (lambda (handles)
5973 (unless ,(not ibegend)
5974 (setq gnus-article-mime-handle-alist
5975 ',gnus-article-mime-handle-alist))
5976 (gnus-mime-display-alternative
5977 ',ihandles ',handle ',begend ,id))
5978 keymap ,gnus-mime-button-map
5979 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5980 face ,gnus-article-button-face
5981 gnus-part ,id
5982 gnus-data ,handle))
5983 (widget-convert-button 'link from (point)
5984 :action 'gnus-widget-press-button
5985 :button-keymap gnus-widget-button-keymap)
5986 (insert " "))
5987 (insert "\n\n"))
5988 (when preferred
5989 (if (stringp (car preferred))
5990 (gnus-display-mime preferred)
5991 (let ((mail-parse-charset gnus-newsgroup-charset)
5992 (mail-parse-ignored-charsets
5993 (with-current-buffer gnus-summary-buffer
5994 gnus-newsgroup-ignored-charsets)))
5995 (gnus-bind-safe-url-regexp (mm-display-part preferred))
5996 ;; Do highlighting.
5997 (save-excursion
5998 (save-restriction
5999 (narrow-to-region (car begend) (point-max))
6000 (gnus-treat-article
6001 nil (length gnus-article-mime-handle-alist)
6002 (gnus-article-mime-total-parts)
6003 (mm-handle-media-type handle))))))
6004 (goto-char (point-max))
6005 (setcdr begend (point-marker)))))
6006 (when ibegend
6007 (goto-char point))))
6008
6009 (defconst gnus-article-wash-status-strings
6010 (let ((alist '((cite "c" "Possible hidden citation text"
6011 " " "All citation text visible")
6012 (headers "h" "Hidden headers"
6013 " " "All headers visible.")
6014 (pgp "p" "Encrypted or signed message status hidden"
6015 " " "No hidden encryption nor digital signature status")
6016 (signature "s" "Signature has been hidden"
6017 " " "Signature is visible")
6018 (overstrike "o" "Overstrike (^H) characters applied"
6019 " " "No overstrike characters applied")
6020 (emphasis "e" "/*_Emphasis_*/ characters applied"
6021 " " "No /*_emphasis_*/ characters applied")))
6022 result)
6023 (dolist (entry alist result)
6024 (let ((key (nth 0 entry))
6025 (on (copy-sequence (nth 1 entry)))
6026 (on-help (nth 2 entry))
6027 (off (copy-sequence (nth 3 entry)))
6028 (off-help (nth 4 entry)))
6029 (put-text-property 0 1 'help-echo on-help on)
6030 (put-text-property 0 1 'help-echo off-help off)
6031 (push (list key on off) result))))
6032 "Alist of strings describing wash status in the mode line.
6033 Each entry has the form (KEY ON OF), where the KEY is a symbol
6034 representing the particular washing function, ON is the string to use
6035 in the article mode line when the washing function is active, and OFF
6036 is the string to use when it is inactive.")
6037
6038 (defun gnus-article-wash-status-entry (key value)
6039 (let ((entry (assoc key gnus-article-wash-status-strings)))
6040 (if value (nth 1 entry) (nth 2 entry))))
6041
6042 (defun gnus-article-wash-status ()
6043 "Return a string which display status of article washing."
6044 (with-current-buffer gnus-article-buffer
6045 (let ((cite (memq 'cite gnus-article-wash-types))
6046 (headers (memq 'headers gnus-article-wash-types))
6047 (boring (memq 'boring-headers gnus-article-wash-types))
6048 (pgp (memq 'pgp gnus-article-wash-types))
6049 (pem (memq 'pem gnus-article-wash-types))
6050 (signed (memq 'signed gnus-article-wash-types))
6051 (encrypted (memq 'encrypted gnus-article-wash-types))
6052 (signature (memq 'signature gnus-article-wash-types))
6053 (overstrike (memq 'overstrike gnus-article-wash-types))
6054 (emphasis (memq 'emphasis gnus-article-wash-types)))
6055 (concat
6056 (gnus-article-wash-status-entry 'cite cite)
6057 (gnus-article-wash-status-entry 'headers (or headers boring))
6058 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6059 (gnus-article-wash-status-entry 'signature signature)
6060 (gnus-article-wash-status-entry 'overstrike overstrike)
6061 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6062
6063 (defun gnus-add-wash-type (type)
6064 "Add a washing of TYPE to the current status."
6065 (add-to-list 'gnus-article-wash-types type))
6066
6067 (defun gnus-delete-wash-type (type)
6068 "Add a washing of TYPE to the current status."
6069 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6070
6071 (defun gnus-add-image (category image)
6072 "Add IMAGE of CATEGORY to the list of displayed images."
6073 (let ((entry (assq category gnus-article-image-alist)))
6074 (unless entry
6075 (setq entry (list category))
6076 (push entry gnus-article-image-alist))
6077 (nconc entry (list image))))
6078
6079 (defun gnus-delete-images (category)
6080 "Delete all images in CATEGORY."
6081 (let ((entry (assq category gnus-article-image-alist)))
6082 (dolist (image (cdr entry))
6083 (gnus-remove-image image category))
6084 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6085 (gnus-delete-wash-type category)))
6086
6087 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6088
6089 (defun gnus-article-maybe-hide-headers ()
6090 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6091 Provided for backwards compatibility."
6092 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6093 (not (with-current-buffer gnus-summary-buffer
6094 gnus-have-all-headers)))
6095 (not gnus-inhibit-hiding))
6096 (gnus-article-hide-headers)))
6097
6098 ;;; Article savers.
6099
6100 (defun gnus-output-to-file (file-name)
6101 "Append the current article to a file named FILE-NAME.
6102 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6103 text and used as the value of the coding cookie which is added to the
6104 top of a file. Otherwise, this function saves a raw article without
6105 the coding cookie."
6106 (let* ((artbuf (current-buffer))
6107 (file-name-coding-system nnmail-pathname-coding-system)
6108 (coding gnus-article-save-coding-system)
6109 (coding-system-for-read (if coding
6110 nil ;; Rely on the coding cookie.
6111 mm-text-coding-system))
6112 (coding-system-for-write (or coding
6113 mm-text-coding-system-for-write
6114 mm-text-coding-system))
6115 (exists (file-exists-p file-name)))
6116 (with-temp-buffer
6117 (when exists
6118 (insert-file-contents file-name)
6119 (goto-char (point-min))
6120 ;; Remove the existing coding cookie.
6121 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6122 (delete-region (match-beginning 0) (match-end 0))))
6123 (goto-char (point-max))
6124 (insert-buffer-substring artbuf)
6125 ;; Append newline at end of the buffer as separator, and then
6126 ;; save it to file.
6127 (goto-char (point-max))
6128 (insert "\n")
6129 (when coding
6130 ;; If the coding system is not suitable to encode the text,
6131 ;; ask a user for a proper one.
6132 (when (fboundp 'select-safe-coding-system)
6133 (setq coding (coding-system-base
6134 (save-window-excursion
6135 (select-safe-coding-system (point-min) (point-max)
6136 coding))))
6137 (setq coding-system-for-write
6138 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6139 coding)))
6140 (goto-char (point-min))
6141 ;; Add the coding cookie.
6142 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6143 coding-system-for-write)))
6144 (if exists
6145 (progn
6146 (write-region (point-min) (point-max) file-name nil 'no-message)
6147 (message "Appended to %s" file-name))
6148 (write-region (point-min) (point-max) file-name))))
6149 t)
6150
6151 (defun gnus-narrow-to-page (&optional arg)
6152 "Narrow the article buffer to a page.
6153 If given a numerical ARG, move forward ARG pages."
6154 (interactive "P")
6155 (setq arg (if arg (prefix-numeric-value arg) 0))
6156 (with-current-buffer gnus-article-buffer
6157 (widen)
6158 ;; Remove any old next/prev buttons.
6159 (when (gnus-visual-p 'page-marker)
6160 (let ((inhibit-read-only t))
6161 (gnus-remove-text-with-property 'gnus-prev)
6162 (gnus-remove-text-with-property 'gnus-next)))
6163 (let (st nd pt)
6164 (when (save-excursion
6165 (cond ((< arg 0)
6166 (if (re-search-backward page-delimiter nil 'move (abs arg))
6167 (prog1
6168 (setq nd (match-beginning 0)
6169 pt nd)
6170 (when (re-search-backward page-delimiter nil t)
6171 (setq st (match-end 0))))
6172 (when (re-search-forward page-delimiter nil t)
6173 (setq nd (match-beginning 0)
6174 pt (point-min)))))
6175 ((> arg 0)
6176 (if (re-search-forward page-delimiter nil 'move arg)
6177 (prog1
6178 (setq st (match-end 0)
6179 pt st)
6180 (when (re-search-forward page-delimiter nil t)
6181 (setq nd (match-beginning 0))))
6182 (when (re-search-backward page-delimiter nil t)
6183 (setq st (match-end 0)
6184 pt (point-max)))))
6185 (t
6186 (when (re-search-backward page-delimiter nil t)
6187 (goto-char (setq st (match-end 0))))
6188 (when (re-search-forward page-delimiter nil t)
6189 (setq nd (match-beginning 0)))
6190 (or st nd))))
6191 (setq gnus-page-broken t)
6192 (when pt (goto-char pt))
6193 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6194 (when (gnus-visual-p 'page-marker)
6195 (save-excursion
6196 (when nd
6197 (goto-char nd)
6198 (gnus-insert-next-page-button))
6199 (when st
6200 (goto-char st)
6201 (gnus-insert-prev-page-button))))))))
6202
6203 ;; Article mode commands
6204
6205 (defun gnus-article-goto-next-page ()
6206 "Show the next page of the article."
6207 (interactive)
6208 (when (gnus-article-next-page)
6209 (goto-char (point-min))
6210 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6211
6212
6213 (defun gnus-article-goto-prev-page ()
6214 "Show the previous page of the article."
6215 (interactive)
6216 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6217 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6218 (gnus-article-prev-page nil)))
6219
6220 ;; This is cleaner but currently breaks `gnus-pick-mode':
6221 ;;
6222 ;; (defun gnus-article-goto-next-page ()
6223 ;; "Show the next page of the article."
6224 ;; (interactive)
6225 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6226 ;; (gnus-summary-next-page)))
6227 ;;
6228 ;; (defun gnus-article-goto-prev-page ()
6229 ;; "Show the next page of the article."
6230 ;; (interactive)
6231 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6232 ;; (gnus-summary-prev-page)))
6233
6234 (defun gnus-article-next-page (&optional lines)
6235 "Show the next page of the current article.
6236 If end of article, return non-nil. Otherwise return nil.
6237 Argument LINES specifies lines to be scrolled up."
6238 (interactive "p")
6239 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6240 (if (and (not (and gnus-article-over-scroll
6241 (> (count-lines (window-start) (point-max))
6242 (if (featurep 'xemacs)
6243 (or lines (1- (window-height)))
6244 (+ (or lines (1- (window-height))) scroll-margin)))))
6245 (save-excursion
6246 (end-of-line)
6247 (and (pos-visible-in-window-p) ;Not continuation line.
6248 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
6249 ;; Nothing in this page.
6250 (if (or (not gnus-page-broken)
6251 (save-excursion
6252 (save-restriction
6253 (widen)
6254 (forward-line)
6255 (eobp)))) ;Real end-of-buffer?
6256 (progn
6257 (when gnus-article-over-scroll
6258 (gnus-article-next-page-1 lines))
6259 t) ;Nothing more.
6260 (gnus-narrow-to-page 1) ;Go to next page.
6261 nil)
6262 ;; More in this page.
6263 (gnus-article-next-page-1 lines)
6264 nil))
6265
6266 (defmacro gnus-article-beginning-of-window ()
6267 "Move point to the beginning of the window.
6268 In Emacs, the point is placed at the line number which `scroll-margin'
6269 specifies."
6270 (if (featurep 'xemacs)
6271 '(move-to-window-line 0)
6272 '(move-to-window-line
6273 (min (max 0 scroll-margin)
6274 (max 1 (- (window-height)
6275 (if mode-line-format 1 0)
6276 (if header-line-format 1 0)
6277 2))))))
6278
6279 (defun gnus-article-next-page-1 (lines)
6280 (unless (featurep 'xemacs)
6281 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6282 ;; too many number of lines if `scroll-margin' is set as two or greater.
6283 (when (and (numberp lines)
6284 (> lines 0)
6285 (> scroll-margin 0))
6286 (setq lines (min lines
6287 (max 0 (- (count-lines (window-start) (point-max))
6288 scroll-margin))))))
6289 (condition-case ()
6290 (let ((scroll-in-place nil))
6291 (scroll-up lines))
6292 (end-of-buffer
6293 ;; Long lines may cause an end-of-buffer error.
6294 (goto-char (point-max))))
6295 (gnus-article-beginning-of-window))
6296
6297 (defun gnus-article-prev-page (&optional lines)
6298 "Show previous page of current article.
6299 Argument LINES specifies lines to be scrolled down."
6300 (interactive "p")
6301 (move-to-window-line 0)
6302 (if (and gnus-page-broken
6303 (bobp)
6304 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6305 (progn
6306 (gnus-narrow-to-page -1) ;Go to previous page.
6307 (goto-char (point-max))
6308 (recenter (if gnus-article-over-scroll
6309 (if lines
6310 (max (if (featurep 'xemacs)
6311 lines
6312 (+ lines scroll-margin))
6313 3)
6314 (- (window-height) 2))
6315 -1)))
6316 (prog1
6317 (condition-case ()
6318 (let ((scroll-in-place nil))
6319 (scroll-down lines))
6320 (beginning-of-buffer
6321 (goto-char (point-min))))
6322 (gnus-article-beginning-of-window))))
6323
6324 (defun gnus-article-only-boring-p ()
6325 "Decide whether there is only boring text remaining in the article.
6326 Something \"interesting\" is a word of at least two letters that does
6327 not have a face in `gnus-article-boring-faces'."
6328 (when (and gnus-article-skip-boring
6329 (boundp 'gnus-article-boring-faces)
6330 (symbol-value 'gnus-article-boring-faces))
6331 (save-excursion
6332 (let ((inhibit-point-motion-hooks t))
6333 (catch 'only-boring
6334 (while (re-search-forward "\\b\\w\\w" nil t)
6335 (forward-char -1)
6336 (when (not (gnus-intersection
6337 (gnus-faces-at (point))
6338 (symbol-value 'gnus-article-boring-faces)))
6339 (throw 'only-boring nil)))
6340 (throw 'only-boring t))))))
6341
6342 (defun gnus-article-refer-article ()
6343 "Read article specified by message-id around point."
6344 (interactive)
6345 (save-excursion
6346 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6347 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6348 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6349 (let ((msg-id (concat "<" (match-string 0) ">")))
6350 (set-buffer gnus-summary-buffer)
6351 (gnus-summary-refer-article msg-id))
6352 (error "No references around point"))))
6353
6354 (defun gnus-article-show-summary ()
6355 "Reconfigure windows to show summary buffer."
6356 (interactive)
6357 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6358 (error "There is no summary buffer for this article buffer")
6359 (gnus-article-set-globals)
6360 (gnus-configure-windows 'article)
6361 (gnus-summary-goto-subject gnus-current-article)
6362 (gnus-summary-position-point)))
6363
6364 (defun gnus-article-describe-briefly ()
6365 "Describe article mode commands briefly."
6366 (interactive)
6367 (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")))
6368
6369 (defun gnus-article-check-buffer ()
6370 "Beep if not in an article buffer."
6371 (unless (equal major-mode 'gnus-article-mode)
6372 (error "Command invoked outside of a Gnus article buffer")))
6373
6374 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6375 "Read a summary buffer key sequence and execute it from the article buffer."
6376 (interactive "P")
6377 (gnus-article-check-buffer)
6378 (let ((nosaves
6379 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6380 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6381 "=" "^" "\M-^" "|"))
6382 (nosave-but-article
6383 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6384 "An" "Ap" [?A (meta return)] [?A delete]))
6385 (nosave-in-article
6386 '("AS" "\C-d"))
6387 (up-to-top
6388 '("n" "Gn" "p" "Gp"))
6389 keys new-sum-point)
6390 (with-current-buffer gnus-article-current-summary
6391 (let (gnus-pick-mode)
6392 (setq unread-command-events (nconc unread-command-events
6393 (list (or key last-command-event)))
6394 keys (if (featurep 'xemacs)
6395 (events-to-keys (read-key-sequence nil t))
6396 (read-key-sequence nil t)))))
6397
6398 (message "")
6399
6400 (cond
6401 ((eq (aref keys (1- (length keys))) ?\C-h)
6402 (gnus-article-describe-bindings (substring keys 0 -1)))
6403 ((or (member keys nosaves)
6404 (member keys nosave-but-article)
6405 (member keys nosave-in-article))
6406 (let (func)
6407 (save-window-excursion
6408 (pop-to-buffer gnus-article-current-summary)
6409 ;; We disable the pick minor mode commands.
6410 (let (gnus-pick-mode)
6411 (setq func (key-binding keys t))))
6412 (if (or (not func)
6413 (numberp func))
6414 (ding)
6415 (unless (member keys nosave-in-article)
6416 (set-buffer gnus-article-current-summary))
6417 (call-interactively func)
6418 (setq new-sum-point (point)))
6419 (when (member keys nosave-but-article)
6420 (pop-to-buffer gnus-article-buffer))))
6421 (t
6422 ;; These commands should restore window configuration.
6423 (let ((obuf (current-buffer))
6424 (owin (current-window-configuration))
6425 win func in-buffer selected new-sum-start new-sum-hscroll err)
6426 (cond (not-restore-window
6427 (pop-to-buffer gnus-article-current-summary)
6428 (setq win (selected-window)))
6429 ((setq win (get-buffer-window gnus-article-current-summary))
6430 (select-window win))
6431 (t
6432 (let ((summary-buffer gnus-article-current-summary))
6433 (gnus-configure-windows 'article)
6434 (unless (setq win (get-buffer-window summary-buffer 'visible))
6435 (let ((gnus-buffer-configuration
6436 '((article ((vertical 1.0
6437 (summary 0.25 point)
6438 (article 1.0)))))))
6439 (gnus-configure-windows 'article))
6440 (setq win (get-buffer-window summary-buffer 'visible)))
6441 (gnus-select-frame-set-input-focus (window-frame win))
6442 (select-window win))))
6443 (setq in-buffer (current-buffer))
6444 ;; We disable the pick minor mode commands.
6445 (if (and (setq func (let (gnus-pick-mode)
6446 (key-binding keys t)))
6447 (functionp func)
6448 (condition-case code
6449 (progn
6450 (call-interactively func)
6451 t)
6452 (error
6453 (setq err code)
6454 nil)))
6455 (progn
6456 (when (eq win (selected-window))
6457 (setq new-sum-point (point)
6458 new-sum-start (window-start win)
6459 new-sum-hscroll (window-hscroll win)))
6460 (when (or (eq in-buffer (current-buffer))
6461 (when (eq obuf (current-buffer))
6462 (set-buffer in-buffer)
6463 t))
6464 (setq selected (gnus-summary-select-article))
6465 (set-buffer obuf)
6466 (unless not-restore-window
6467 (set-window-configuration owin))
6468 (when (and (eq selected 'old)
6469 new-sum-point)
6470 (set-window-start (get-buffer-window (current-buffer))
6471 1)
6472 (set-window-point (get-buffer-window (current-buffer))
6473 (if (article-goto-body)
6474 (1- (point))
6475 (point))))
6476 (when (and (not not-restore-window)
6477 new-sum-point
6478 (window-live-p win)
6479 (with-current-buffer (window-buffer win)
6480 (eq major-mode 'gnus-summary-mode)))
6481 (set-window-point win new-sum-point)
6482 (set-window-start win new-sum-start)
6483 (set-window-hscroll win new-sum-hscroll))))
6484 (set-window-configuration owin)
6485 (if err
6486 (signal (car err) (cdr err))
6487 (ding))))))))
6488
6489 (defun gnus-article-read-summary-send-keys ()
6490 (interactive)
6491 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6492 (gnus-article-read-summary-keys)))
6493
6494 (defun gnus-article-describe-key (key)
6495 "Display documentation of the function invoked by KEY.
6496 KEY is a string or a vector."
6497 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6498 (read-key-sequence "Describe key: "))))
6499 (gnus-article-check-buffer)
6500 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6501 gnus-article-read-summary-send-keys))
6502 (with-current-buffer gnus-article-current-summary
6503 (setq unread-command-events
6504 (if (featurep 'xemacs)
6505 (append key nil)
6506 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6507 (list 'meta (- x 128))
6508 x))
6509 key)))
6510 (let ((cursor-in-echo-area t)
6511 gnus-pick-mode)
6512 (describe-key (read-key-sequence nil t))))
6513 (describe-key key)))
6514
6515 (defun gnus-article-describe-key-briefly (key &optional insert)
6516 "Display documentation of the function invoked by KEY.
6517 KEY is a string or a vector."
6518 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6519 (read-key-sequence "Describe key: "))
6520 current-prefix-arg))
6521 (gnus-article-check-buffer)
6522 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6523 gnus-article-read-summary-send-keys))
6524 (with-current-buffer gnus-article-current-summary
6525 (setq unread-command-events
6526 (if (featurep 'xemacs)
6527 (append key nil)
6528 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6529 (list 'meta (- x 128))
6530 x))
6531 key)))
6532 (let ((cursor-in-echo-area t)
6533 gnus-pick-mode)
6534 (describe-key-briefly (read-key-sequence nil t) insert)))
6535 (describe-key-briefly key insert)))
6536
6537 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6538 (defvar gnus-agent-summary-mode)
6539 (defvar gnus-draft-mode)
6540 ;; Calling help-buffer will autoload help-mode.
6541 (defvar help-xref-stack-item)
6542
6543 (defun gnus-article-describe-bindings (&optional prefix)
6544 "Show a list of all defined keys, and their definitions.
6545 The optional argument PREFIX, if non-nil, should be a key sequence;
6546 then we display only bindings that start with that prefix."
6547 (interactive)
6548 (gnus-article-check-buffer)
6549 (let ((keymap (copy-keymap gnus-article-mode-map))
6550 (map (copy-keymap gnus-article-send-map))
6551 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6552 parent agent draft)
6553 (define-key keymap "S" map)
6554 (define-key map [t] nil)
6555 (with-current-buffer gnus-article-current-summary
6556 (set-keymap-parent
6557 keymap
6558 (if (setq parent (keymap-parent gnus-article-mode-map))
6559 (prog1
6560 (setq parent (copy-keymap parent))
6561 (set-keymap-parent parent (current-local-map)))
6562 (current-local-map)))
6563 (set-keymap-parent map (key-binding "S"))
6564 (let (key def gnus-pick-mode)
6565 (while sumkeys
6566 (setq key (pop sumkeys))
6567 (cond ((and (vectorp key) (= (length key) 1)
6568 (consp (setq def (aref key 0)))
6569 (numberp (car def)) (numberp (cdr def)))
6570 (when (< (max (car def) (cdr def)) 128)
6571 (setq sumkeys
6572 (append (mapcar
6573 #'vector
6574 (nreverse (gnus-uncompress-range def)))
6575 sumkeys))))
6576 ((setq def (key-binding key))
6577 (unless (eq def 'undefined)
6578 (define-key keymap key def))))))
6579 (when (boundp 'gnus-agent-summary-mode)
6580 (setq agent gnus-agent-summary-mode))
6581 (when (boundp 'gnus-draft-mode)
6582 (setq draft gnus-draft-mode)))
6583 (with-temp-buffer
6584 (use-local-map keymap)
6585 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6586 (set (make-local-variable 'gnus-draft-mode) draft)
6587 (describe-bindings prefix))
6588 (let ((item `((lambda (prefix)
6589 (with-current-buffer ,(current-buffer)
6590 (gnus-article-describe-bindings prefix)))
6591 ,prefix)))
6592 (with-current-buffer (if (fboundp 'help-buffer)
6593 (let (help-xref-following) (help-buffer))
6594 "*Help*") ;; Emacs 21
6595 (setq help-xref-stack-item item)))))
6596
6597 (defun gnus-article-reply-with-original (&optional wide)
6598 "Start composing a reply mail to the current message.
6599 The text in the region will be yanked. If the region isn't active,
6600 the entire article will be yanked."
6601 (interactive)
6602 (let ((article (cdr gnus-article-current))
6603 contents)
6604 (if (not (gnus-region-active-p))
6605 (with-current-buffer gnus-summary-buffer
6606 (gnus-summary-reply (list (list article)) wide))
6607 (setq contents (buffer-substring (point) (mark t)))
6608 ;; Deactivate active regions.
6609 (when (and (boundp 'transient-mark-mode)
6610 transient-mark-mode)
6611 (setq mark-active nil))
6612 (with-current-buffer gnus-summary-buffer
6613 (gnus-summary-reply
6614 (list (list article contents)) wide)))))
6615
6616 (defun gnus-article-wide-reply-with-original ()
6617 "Start composing a wide reply mail to the current message.
6618 The text in the region will be yanked. If the region isn't active,
6619 the entire article will be yanked."
6620 (interactive)
6621 (gnus-article-reply-with-original t))
6622
6623 (defun gnus-article-followup-with-original ()
6624 "Compose a followup to the current article.
6625 The text in the region will be yanked. If the region isn't active,
6626 the entire article will be yanked."
6627 (interactive)
6628 (let ((article (cdr gnus-article-current))
6629 contents)
6630 (if (not (gnus-region-active-p))
6631 (with-current-buffer gnus-summary-buffer
6632 (gnus-summary-followup (list (list article))))
6633 (setq contents (buffer-substring (point) (mark t)))
6634 ;; Deactivate active regions.
6635 (when (and (boundp 'transient-mark-mode)
6636 transient-mark-mode)
6637 (setq mark-active nil))
6638 (with-current-buffer gnus-summary-buffer
6639 (gnus-summary-followup
6640 (list (list article contents)))))))
6641
6642 (defun gnus-article-hide (&optional arg force)
6643 "Hide all the gruft in the current article.
6644 This means that signatures, cited text and (some) headers will be
6645 hidden.
6646 If given a prefix, show the hidden text instead."
6647 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6648 (gnus-article-hide-headers arg)
6649 (gnus-article-hide-list-identifiers arg)
6650 (gnus-article-hide-citation-maybe arg force)
6651 (gnus-article-hide-signature arg))
6652
6653 (defun gnus-article-maybe-highlight ()
6654 "Do some article highlighting if article highlighting is requested."
6655 (when (gnus-visual-p 'article-highlight 'highlight)
6656 (gnus-article-highlight-some)))
6657
6658 (defun gnus-check-group-server ()
6659 ;; Make sure the connection to the server is alive.
6660 (unless (gnus-server-opened
6661 (gnus-find-method-for-group gnus-newsgroup-name))
6662 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6663 (gnus-request-group gnus-newsgroup-name t)))
6664
6665 (eval-when-compile
6666 (autoload 'nneething-get-file-name "nneething"))
6667
6668 (defun gnus-request-article-this-buffer (article group)
6669 "Get an article and insert it into this buffer."
6670 (let (do-update-line sparse-header)
6671 (prog1
6672 (save-excursion
6673 (erase-buffer)
6674 (gnus-kill-all-overlays)
6675 (setq group (or group gnus-newsgroup-name))
6676
6677 ;; Using `gnus-request-article' directly will insert the article into
6678 ;; `nntp-server-buffer' - so we'll save some time by not having to
6679 ;; copy it from the server buffer into the article buffer.
6680
6681 ;; We only request an article by message-id when we do not have the
6682 ;; headers for it, so we'll have to get those.
6683 (when (stringp article)
6684 (gnus-read-header article))
6685
6686 ;; If the article number is negative, that means that this article
6687 ;; doesn't belong in this newsgroup (possibly), so we find its
6688 ;; message-id and request it by id instead of number.
6689 (when (and (numberp article)
6690 gnus-summary-buffer
6691 (get-buffer gnus-summary-buffer)
6692 (gnus-buffer-exists-p gnus-summary-buffer))
6693 (with-current-buffer gnus-summary-buffer
6694 (let ((header (gnus-summary-article-header article)))
6695 (when (< article 0)
6696 (cond
6697 ((memq article gnus-newsgroup-sparse)
6698 ;; This is a sparse gap article.
6699 (setq do-update-line article)
6700 (setq article (mail-header-id header))
6701 (setq sparse-header (gnus-read-header article))
6702 (setq gnus-newsgroup-sparse
6703 (delq article gnus-newsgroup-sparse)))
6704 ((vectorp header)
6705 ;; It's a real article.
6706 (setq article (mail-header-id header)))
6707 (t
6708 ;; It is an extracted pseudo-article.
6709 (setq article 'pseudo)
6710 (gnus-request-pseudo-article header))))
6711
6712 (let ((method (gnus-find-method-for-group
6713 gnus-newsgroup-name)))
6714 (when (and (eq (car method) 'nneething)
6715 (vectorp header))
6716 (let ((dir (nneething-get-file-name
6717 (mail-header-id header))))
6718 (when (and (stringp dir)
6719 (file-directory-p dir))
6720 (setq article 'nneething)
6721 (gnus-group-enter-directory dir))))))))
6722
6723 (cond
6724 ;; Refuse to select canceled articles.
6725 ((and (numberp article)
6726 gnus-summary-buffer
6727 (get-buffer gnus-summary-buffer)
6728 (gnus-buffer-exists-p gnus-summary-buffer)
6729 (eq (cdr (with-current-buffer gnus-summary-buffer
6730 (assq article gnus-newsgroup-reads)))
6731 gnus-canceled-mark))
6732 nil)
6733 ;; We first check `gnus-original-article-buffer'.
6734 ((and (get-buffer gnus-original-article-buffer)
6735 (numberp article)
6736 (with-current-buffer gnus-original-article-buffer
6737 (and (equal (car gnus-original-article) group)
6738 (eq (cdr gnus-original-article) article))))
6739 ;; `insert-buffer-substring' would incorrectly use the
6740 ;; equivalent of string-make-multibyte which amount to decoding
6741 ;; with locale-coding-system, causing failure of
6742 ;; subsequent decoding.
6743 (insert (mm-string-to-multibyte
6744 (with-current-buffer gnus-original-article-buffer
6745 (buffer-substring (point-min) (point-max)))))
6746 'article)
6747 ;; Check the backlog.
6748 ((and gnus-keep-backlog
6749 (gnus-backlog-request-article group article (current-buffer)))
6750 'article)
6751 ;; Check asynchronous pre-fetch.
6752 ((gnus-async-request-fetched-article group article (current-buffer))
6753 (gnus-async-prefetch-next group article gnus-summary-buffer)
6754 (when (and (numberp article) gnus-keep-backlog)
6755 (gnus-backlog-enter-article group article (current-buffer)))
6756 'article)
6757 ;; Check the cache.
6758 ((and gnus-use-cache
6759 (numberp article)
6760 (gnus-cache-request-article article group))
6761 'article)
6762 ;; Check the agent cache.
6763 ((gnus-agent-request-article article group)
6764 'article)
6765 ;; Get the article and put into the article buffer.
6766 ((or (stringp article)
6767 (numberp article))
6768 (let ((gnus-override-method gnus-override-method)
6769 (methods (and (stringp article)
6770 gnus-refer-article-method))
6771 (backend (car (gnus-find-method-for-group
6772 gnus-newsgroup-name)))
6773 result
6774 (inhibit-read-only t))
6775 (if (or (not (listp methods))
6776 (and (symbolp (car methods))
6777 (assq (car methods) nnoo-definition-alist)))
6778 (setq methods (list methods)))
6779 (when (and (null gnus-override-method)
6780 methods)
6781 (setq gnus-override-method (pop methods)))
6782 (while (not result)
6783 (when (eq gnus-override-method 'current)
6784 (setq gnus-override-method
6785 (with-current-buffer gnus-summary-buffer
6786 gnus-current-select-method)))
6787 (erase-buffer)
6788 (gnus-kill-all-overlays)
6789 (let ((gnus-newsgroup-name group))
6790 (gnus-check-group-server))
6791 (cond
6792 ((gnus-request-article article group (current-buffer))
6793 (when (numberp article)
6794 (gnus-async-prefetch-next group article
6795 gnus-summary-buffer)
6796 (when gnus-keep-backlog
6797 (gnus-backlog-enter-article
6798 group article (current-buffer))))
6799 (setq result 'article))
6800 (methods
6801 (setq gnus-override-method (pop methods)))
6802 ((not (string-match "^400 "
6803 (nnheader-get-report backend)))
6804 ;; If we get 400 server disconnect, reconnect and
6805 ;; retry; otherwise, assume the article has expired.
6806 (setq result 'done))))
6807 (and (eq result 'article) 'article)))
6808 ;; It was a pseudo.
6809 (t article)))
6810
6811 ;; Associate this article with the current summary buffer.
6812 (setq gnus-article-current-summary gnus-summary-buffer)
6813
6814 ;; Take the article from the original article buffer
6815 ;; and place it in the buffer it's supposed to be in.
6816 (when (and (get-buffer gnus-article-buffer)
6817 (equal (buffer-name (current-buffer))
6818 (buffer-name (get-buffer gnus-article-buffer))))
6819 (save-excursion
6820 (if (get-buffer gnus-original-article-buffer)
6821 (set-buffer gnus-original-article-buffer)
6822 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6823 (buffer-disable-undo)
6824 (setq major-mode 'gnus-original-article-mode)
6825 (setq buffer-read-only t))
6826 (let ((inhibit-read-only t))
6827 (erase-buffer)
6828 (insert-buffer-substring gnus-article-buffer))
6829 (setq gnus-original-article (cons group article)))
6830
6831 ;; Decode charsets.
6832 (run-hooks 'gnus-article-decode-hook)
6833 ;; Mark article as decoded or not.
6834 (setq gnus-article-decoded-p gnus-article-decode-hook))
6835
6836 ;; Update sparse articles.
6837 (when (and do-update-line
6838 (or (numberp article)
6839 (stringp article)))
6840 (let ((buf (current-buffer)))
6841 (set-buffer gnus-summary-buffer)
6842 (gnus-summary-update-article do-update-line sparse-header)
6843 (gnus-summary-goto-subject do-update-line nil t)
6844 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6845 (point))
6846 (set-buffer buf))))))
6847
6848 ;;;
6849 ;;; Article editing
6850 ;;;
6851
6852 (defcustom gnus-article-edit-mode-hook nil
6853 "Hook run in article edit mode buffers."
6854 :group 'gnus-article-various
6855 :type 'hook)
6856
6857 (defvar gnus-article-edit-done-function nil)
6858
6859 (defvar gnus-article-edit-mode-map nil)
6860
6861 ;; Should we be using derived.el for this?
6862 (unless gnus-article-edit-mode-map
6863 (setq gnus-article-edit-mode-map (make-keymap))
6864 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6865
6866 (gnus-define-keys gnus-article-edit-mode-map
6867 "\C-c?" describe-mode
6868 "\C-c\C-c" gnus-article-edit-done
6869 "\C-c\C-k" gnus-article-edit-exit
6870 "\C-c\C-f\C-t" message-goto-to
6871 "\C-c\C-f\C-o" message-goto-from
6872 "\C-c\C-f\C-b" message-goto-bcc
6873 ;;"\C-c\C-f\C-w" message-goto-fcc
6874 "\C-c\C-f\C-c" message-goto-cc
6875 "\C-c\C-f\C-s" message-goto-subject
6876 "\C-c\C-f\C-r" message-goto-reply-to
6877 "\C-c\C-f\C-n" message-goto-newsgroups
6878 "\C-c\C-f\C-d" message-goto-distribution
6879 "\C-c\C-f\C-f" message-goto-followup-to
6880 "\C-c\C-f\C-m" message-goto-mail-followup-to
6881 "\C-c\C-f\C-k" message-goto-keywords
6882 "\C-c\C-f\C-u" message-goto-summary
6883 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6884 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6885 "\C-c\C-b" message-goto-body
6886 "\C-c\C-i" message-goto-signature
6887
6888 "\C-c\C-t" message-insert-to
6889 "\C-c\C-n" message-insert-newsgroups
6890 "\C-c\C-o" message-sort-headers
6891 "\C-c\C-e" message-elide-region
6892 "\C-c\C-v" message-delete-not-region
6893 "\C-c\C-z" message-kill-to-signature
6894 "\M-\r" message-newline-and-reformat
6895 "\C-c\C-a" mml-attach-file
6896 "\C-a" message-beginning-of-line
6897 "\t" message-tab
6898 "\M-;" comment-region)
6899
6900 (gnus-define-keys (gnus-article-edit-wash-map
6901 "\C-c\C-w" gnus-article-edit-mode-map)
6902 "f" gnus-article-edit-full-stops))
6903
6904 (easy-menu-define
6905 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6906 '("Field"
6907 ["Fetch To" message-insert-to t]
6908 ["Fetch Newsgroups" message-insert-newsgroups t]
6909 "----"
6910 ["To" message-goto-to t]
6911 ["From" message-goto-from t]
6912 ["Subject" message-goto-subject t]
6913 ["Cc" message-goto-cc t]
6914 ["Reply-To" message-goto-reply-to t]
6915 ["Summary" message-goto-summary t]
6916 ["Keywords" message-goto-keywords t]
6917 ["Newsgroups" message-goto-newsgroups t]
6918 ["Followup-To" message-goto-followup-to t]
6919 ["Mail-Followup-To" message-goto-mail-followup-to t]
6920 ["Distribution" message-goto-distribution t]
6921 ["Body" message-goto-body t]
6922 ["Signature" message-goto-signature t]))
6923
6924 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6925 "Major mode for editing articles.
6926 This is an extended text-mode.
6927
6928 \\{gnus-article-edit-mode-map}"
6929 (make-local-variable 'gnus-article-edit-done-function)
6930 (make-local-variable 'gnus-prev-winconf)
6931 (set (make-local-variable 'font-lock-defaults)
6932 '(message-font-lock-keywords t))
6933 (set (make-local-variable 'mail-header-separator) "")
6934 (set (make-local-variable 'gnus-article-edit-mode) t)
6935 (easy-menu-add message-mode-field-menu message-mode-map)
6936 (mml-mode)
6937 (setq buffer-read-only nil)
6938 (buffer-enable-undo)
6939 (widen))
6940
6941 (defun gnus-article-edit (&optional force)
6942 "Edit the current article.
6943 This will have permanent effect only in mail groups.
6944 If FORCE is non-nil, allow editing of articles even in read-only
6945 groups."
6946 (interactive "P")
6947 (when (and (not force)
6948 (gnus-group-read-only-p))
6949 (error "The current newsgroup does not support article editing"))
6950 (gnus-article-date-original)
6951 (gnus-article-edit-article
6952 'ignore
6953 `(lambda (no-highlight)
6954 'ignore
6955 (gnus-summary-edit-article-done
6956 ,(or (mail-header-references gnus-current-headers) "")
6957 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6958
6959 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6960 "Start editing the contents of the current article buffer."
6961 (let ((winconf (current-window-configuration)))
6962 (set-buffer gnus-article-buffer)
6963 (let ((message-auto-save-directory
6964 ;; Don't associate the article buffer with a draft file.
6965 nil))
6966 (gnus-article-edit-mode))
6967 (funcall start-func)
6968 (set-buffer-modified-p nil)
6969 (gnus-configure-windows 'edit-article)
6970 (setq gnus-article-edit-done-function exit-func)
6971 (setq gnus-prev-winconf winconf)
6972 (unless quiet
6973 (gnus-message 6 "C-c C-c to end edits"))))
6974
6975 (defun gnus-article-edit-done (&optional arg)
6976 "Update the article edits and exit."
6977 (interactive "P")
6978 (let ((func gnus-article-edit-done-function)
6979 (buf (current-buffer))
6980 (start (window-start))
6981 (p (point))
6982 (winconf gnus-prev-winconf))
6983 (widen) ;; Widen it in case that users narrowed the buffer.
6984 (funcall func arg)
6985 (set-buffer buf)
6986 ;; The cache and backlog have to be flushed somewhat.
6987 (when gnus-keep-backlog
6988 (gnus-backlog-remove-article
6989 (car gnus-article-current) (cdr gnus-article-current)))
6990 ;; Flush original article as well.
6991 (when (get-buffer gnus-original-article-buffer)
6992 (with-current-buffer gnus-original-article-buffer
6993 (setq gnus-original-article nil)))
6994 (when gnus-use-cache
6995 (gnus-cache-update-article
6996 (car gnus-article-current) (cdr gnus-article-current)))
6997 ;; We remove all text props from the article buffer.
6998 (kill-all-local-variables)
6999 (set-text-properties (point-min) (point-max) nil)
7000 (gnus-article-mode)
7001 (set-window-configuration winconf)
7002 (set-buffer buf)
7003 (set-window-start (get-buffer-window buf) start)
7004 (set-window-point (get-buffer-window buf) (point)))
7005 (gnus-summary-show-article))
7006
7007 (defun gnus-article-edit-exit ()
7008 "Exit the article editing without updating."
7009 (interactive)
7010 (when (or (not (buffer-modified-p))
7011 (yes-or-no-p "Article modified; kill anyway? "))
7012 (let ((curbuf (current-buffer))
7013 (p (point))
7014 (window-start (window-start)))
7015 (erase-buffer)
7016 (if (gnus-buffer-live-p gnus-original-article-buffer)
7017 (insert-buffer-substring gnus-original-article-buffer))
7018 (let ((winconf gnus-prev-winconf))
7019 (kill-all-local-variables)
7020 (gnus-article-mode)
7021 (set-window-configuration winconf)
7022 ;; Tippy-toe some to make sure that point remains where it was.
7023 (save-current-buffer
7024 (set-buffer curbuf)
7025 (set-window-start (get-buffer-window (current-buffer)) window-start)
7026 (goto-char p))))
7027 (gnus-summary-show-article)))
7028
7029 (defun gnus-article-edit-full-stops ()
7030 "Interactively repair spacing at end of sentences."
7031 (interactive)
7032 (save-excursion
7033 (goto-char (point-min))
7034 (search-forward-regexp "^$" nil t)
7035 (let ((case-fold-search nil))
7036 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7037
7038 ;;;
7039 ;;; Article highlights
7040 ;;;
7041
7042 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7043
7044 ;;; Internal Variables:
7045
7046 (defcustom gnus-button-url-regexp
7047 (concat
7048 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7049 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7050 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7051 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7052 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7053 (punct "!?:;.,"))
7054 (concat
7055 "\\(?:"
7056 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7057 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7058 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7059 "\\|"
7060 "[" chars punct "]+" "[" chars "]"
7061 "\\)"))
7062 (concat ;; XEmacs 21.4 doesn't support POSIX.
7063 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7064 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7065 "\\)")
7066 "Regular expression that matches URLs."
7067 :group 'gnus-article-buttons
7068 :type 'regexp)
7069
7070 (defcustom gnus-button-valid-fqdn-regexp
7071 message-valid-fqdn-regexp
7072 "Regular expression that matches a valid FQDN."
7073 :version "22.1"
7074 :group 'gnus-article-buttons
7075 :type 'regexp)
7076
7077 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7078 (defcustom gnus-button-valid-localpart-regexp
7079 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7080 "Regular expression that matches a localpart of mail addresses or MIDs."
7081 :version "22.1"
7082 :group 'gnus-article-buttons
7083 :type 'regexp)
7084
7085 (defcustom gnus-button-man-handler 'manual-entry
7086 "Function to use for displaying man pages.
7087 The function must take at least one argument with a string naming the
7088 man page."
7089 :version "22.1"
7090 :type '(choice (function-item :tag "Man" manual-entry)
7091 (function-item :tag "Woman" woman)
7092 (function :tag "Other"))
7093 :group 'gnus-article-buttons)
7094
7095 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
7096 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
7097 If the default site is too slow, try to find a CTAN mirror, see
7098 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
7099 the variable `gnus-button-handle-ctan'."
7100 :version "22.1"
7101 :group 'gnus-article-buttons
7102 :link '(custom-manual "(gnus)Group Parameters")
7103 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
7104 (const "http://tug.ctan.org/tex-archive/")
7105 (const "http://www.dante.de/CTAN/")
7106 (string :tag "Other")))
7107
7108 (defcustom gnus-button-ctan-handler 'browse-url
7109 "Function to use for displaying CTAN links.
7110 The function must take one argument, the string naming the URL."
7111 :version "22.1"
7112 :type '(choice (function-item :tag "Browse Url" browse-url)
7113 (function :tag "Other"))
7114 :group 'gnus-article-buttons)
7115
7116 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
7117 "Bogus strings removed from CTAN URLs."
7118 :version "22.1"
7119 :group 'gnus-article-buttons
7120 :type '(choice (const "^/?tex-archive/\\|/")
7121 (regexp :tag "Other")))
7122
7123 (defcustom gnus-button-ctan-directory-regexp
7124 (regexp-opt
7125 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
7126 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
7127 "languages" "macros" "nonfree" "obsolete" "support" "systems"
7128 "tds" "tools" "usergrps" "web") t)
7129 "Regular expression for ctan directories.
7130 It should match all directories in the top level of `gnus-ctan-url'."
7131 :version "22.1"
7132 :group 'gnus-article-buttons
7133 :type 'regexp)
7134
7135 (defcustom gnus-button-mid-or-mail-regexp
7136 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7137 gnus-button-valid-fqdn-regexp
7138 ">?\\)\\b")
7139 "Regular expression that matches a message ID or a mail address."
7140 :version "22.1"
7141 :group 'gnus-article-buttons
7142 :type 'regexp)
7143
7144 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7145 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7146 Strings like this can be either a message ID or a mail address. If it is one
7147 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7148 message ID or a mail address, respectively. If this variable is set to the
7149 symbol `ask', always query the user what do do. If it is a function, this
7150 function will be called with the string as its only argument. The function
7151 must return `mid', `mail', `invalid' or `ask'."
7152 :version "22.1"
7153 :group 'gnus-article-buttons
7154 :type '(choice (function-item :tag "Heuristic function"
7155 gnus-button-mid-or-mail-heuristic)
7156 (const ask)
7157 (const mid)
7158 (const mail)))
7159
7160 (defcustom gnus-button-mid-or-mail-heuristic-alist
7161 '((-10.0 . ".+\\$.+@")
7162 (-10.0 . "#")
7163 (-10.0 . "\\*")
7164 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7165 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7166 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7167 (-1.0 . "^[^a-z]+@")
7168 ;;
7169 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7170 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7171 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7172 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7173 ;;
7174 (-2.0 . "^[0-9]")
7175 (-1.0 . "^[0-9][0-9]")
7176 ;;
7177 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7178 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7179 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7180 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7181 ;;
7182 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7183 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7184 ;; "[0-9]{8,}.*\@"
7185 (-3.0
7186 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7187 ;; "[0-9]{12,}.*\@"
7188 ;; compensation for TDMA dated mail addresses:
7189 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7190 ;;
7191 (-20.0 . "\\.fsf@") ;; Gnus
7192 (-20.0 . "^slrn")
7193 (-20.0 . "^Pine")
7194 (-20.0 . "^alpine\\.")
7195 (-20.0 . "_-_") ;; Subject change in thread
7196 ;;
7197 (-20.0 . "\\.ln@") ;; leafnode
7198 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7199 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7200 ;;
7201 ;; (5.0 . "") ;; $local_part_len <= 7
7202 (10.0 . "^[^0-9]+@")
7203 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7204 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7205 (3.0 . "\@stud")
7206 ;;
7207 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7208 ;;
7209 (0.5 . "^[A-Z][a-z]")
7210 (0.5 . "^[A-Z][a-z][a-z]")
7211 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7212 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7213 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7214
7215 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7216 address. The REGEXP is processed with `case-fold-search' set to nil."
7217 :version "22.1"
7218 :group 'gnus-article-buttons
7219 :type '(repeat (cons (number :tag "Rate")
7220 (regexp :tag "Regexp"))))
7221
7222 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7223 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7224 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7225 address, `ask' if unsure and `invalid' if the string is invalid."
7226 (let ((case-fold-search nil)
7227 (list gnus-button-mid-or-mail-heuristic-alist)
7228 (result 0) rate regexp lpartlen elem)
7229 (setq lpartlen
7230 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7231 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7232 ;; Certain special cases...
7233 (when (string-match
7234 (concat
7235 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7236 "^[0-9]+\\.[0-9]+@compuserve\\|"
7237 "@public\\.gmane\\.org")
7238 mid-or-mail)
7239 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7240 (setq result 'mail))
7241 (when (string-match "@.*@\\| " mid-or-mail)
7242 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7243 (setq result 'invalid))
7244 ;; Nothing more to do, if result is not a number here...
7245 (when (numberp result)
7246 (while list
7247 (setq elem (car list)
7248 rate (car elem)
7249 regexp (cdr elem)
7250 list (cdr list))
7251 (when (string-match regexp mid-or-mail)
7252 (setq result (+ result rate))
7253 (gnus-message
7254 9 "`%s' matched `%s', rate `%s', result `%s'."
7255 mid-or-mail regexp rate result)))
7256 (when (<= lpartlen 7)
7257 (setq result (+ result 5.0))
7258 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7259 mid-or-mail result))
7260 (when (>= lpartlen 12)
7261 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7262 (cond
7263 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7264 ;; Long local part should contain realname if e-mail address,
7265 ;; too many digits: message-id.
7266 ;; $score -= 5.0 + 0.1 * $local_part_len;
7267 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7268 (setq result (+ result rate))
7269 (gnus-message
7270 9 "Many digits in `%s', rate `%s', result `%s'."
7271 mid-or-mail rate result))
7272 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7273 mid-or-mail)
7274 ;; Too few vowels [^aeiouy]{4,}.*\@
7275 (setq result (+ result -5.0))
7276 (gnus-message
7277 9 "Few vowels in `%s', rate `%s', result `%s'."
7278 mid-or-mail -5.0 result))
7279 (t
7280 (setq result (+ result 5.0))
7281 (gnus-message
7282 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7283 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7284 ;; Maybe we should make this a customizable alist: (condition . 'result)
7285 (cond
7286 ((symbolp result) result)
7287 ;; Now convert number into proper results:
7288 ((< result -10.0) 'mid)
7289 ((> result 10.0) 'mail)
7290 (t 'ask))))
7291
7292 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7293 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7294 (url-mid (concat "news" ":" mid-or-mail))
7295 (url-mailto (concat "mailto" ":" mid-or-mail)))
7296 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7297 (when (fboundp pref)
7298 (setq guessed
7299 ;; get rid of surrounding angles...
7300 (funcall pref
7301 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7302 (if (or (eq 'mid guessed) (eq 'mail guessed))
7303 (setq pref guessed)
7304 (setq pref 'ask)))
7305 (if (eq pref 'ask)
7306 (save-window-excursion
7307 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7308 (setq pref 'mail)
7309 (setq pref 'mid))))
7310 (cond ((eq pref 'mid)
7311 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7312 (gnus-button-handle-news url-mid))
7313 ((eq pref 'mail)
7314 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7315 (gnus-url-mailto url-mailto))
7316 (t (gnus-message 3 "Invalid string.")))))
7317
7318 (defun gnus-button-handle-custom (fun arg)
7319 "Call function FUN on argument ARG.
7320 Both FUN and ARG are supposed to be strings. ARG will be passed
7321 as a symbol to FUN."
7322 (funcall (intern fun)
7323 (if (string-match "^customize-apropos" fun)
7324 arg
7325 (intern arg))))
7326
7327 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7328
7329 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7330 ;; stuff?
7331
7332 (defun gnus-button-handle-describe-function (url)
7333 "Call `describe-function' when pushing the corresponding URL button."
7334 (describe-function
7335 (intern
7336 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7337
7338 (defun gnus-button-handle-describe-variable (url)
7339 "Call `describe-variable' when pushing the corresponding URL button."
7340 (describe-variable
7341 (intern
7342 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7343
7344 (defun gnus-button-handle-symbol (url)
7345 "Display help on variable or function.
7346 Calls `describe-variable' or `describe-function'."
7347 (let ((sym (intern url)))
7348 (cond
7349 ((fboundp sym) (describe-function sym))
7350 ((boundp sym) (describe-variable sym))
7351 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7352
7353 (defun gnus-button-handle-describe-key (url)
7354 "Call `describe-key' when pushing the corresponding URL button."
7355 (let* ((key-string
7356 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7357 (keys (ignore-errors (eval `(kbd ,key-string)))))
7358 (if keys
7359 (describe-key keys)
7360 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7361
7362 (defun gnus-button-handle-apropos (url)
7363 "Call `apropos' when pushing the corresponding URL button."
7364 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7365
7366 (defun gnus-button-handle-apropos-command (url)
7367 "Call `apropos' when pushing the corresponding URL button."
7368 (apropos-command
7369 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7370
7371 (defun gnus-button-handle-apropos-variable (url)
7372 "Call `apropos' when pushing the corresponding URL button."
7373 (funcall
7374 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7375 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7376
7377 (defun gnus-button-handle-apropos-documentation (url)
7378 "Call `apropos' when pushing the corresponding URL button."
7379 (funcall
7380 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7381 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7382
7383 (defun gnus-button-handle-library (url)
7384 "Call `locate-library' when pushing the corresponding URL button."
7385 (gnus-message 9 "url=`%s'" url)
7386 (let* ((lib (locate-library url))
7387 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7388 (if (not lib)
7389 (gnus-message 1 "Cannot locale library `%s'." url)
7390 (find-file-read-only file))))
7391
7392 (defun gnus-button-handle-ctan (url)
7393 "Call `browse-url' when pushing a CTAN URL button."
7394 (funcall
7395 gnus-button-ctan-handler
7396 (concat
7397 gnus-ctan-url
7398 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7399
7400 (defcustom gnus-button-tex-level 5
7401 "*Integer that says how many TeX-related buttons Gnus will show.
7402 The higher the number, the more buttons will appear and the more false
7403 positives are possible. Note that you can set this variable local to
7404 specific groups. Setting it higher in TeX groups is probably a good idea.
7405 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7406 how to set variables in specific groups."
7407 :version "22.1"
7408 :group 'gnus-article-buttons
7409 :link '(custom-manual "(gnus)Group Parameters")
7410 :type 'integer)
7411
7412 (defcustom gnus-button-man-level 5
7413 "*Integer that says how many man-related buttons Gnus will show.
7414 The higher the number, the more buttons will appear and the more false
7415 positives are possible. Note that you can set this variable local to
7416 specific groups. Setting it higher in Unix groups is probably a good idea.
7417 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7418 how to set variables in specific groups."
7419 :version "22.1"
7420 :group 'gnus-article-buttons
7421 :link '(custom-manual "(gnus)Group Parameters")
7422 :type 'integer)
7423
7424 (defcustom gnus-button-emacs-level 5
7425 "*Integer that says how many emacs-related buttons Gnus will show.
7426 The higher the number, the more buttons will appear and the more false
7427 positives are possible. Note that you can set this variable local to
7428 specific groups. Setting it higher in Emacs or Gnus related groups is
7429 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7430 `gnus-parameters' on how to set variables in specific groups."
7431 :version "22.1"
7432 :group 'gnus-article-buttons
7433 :link '(custom-manual "(gnus)Group Parameters")
7434 :type 'integer)
7435
7436 (defcustom gnus-button-message-level 5
7437 "*Integer that says how many buttons for news or mail messages will appear.
7438 The higher the number, the more buttons will appear and the more false
7439 positives are possible."
7440 ;; mail addresses, MIDs, URLs for news, ...
7441 :version "22.1"
7442 :group 'gnus-article-buttons
7443 :type 'integer)
7444
7445 (defcustom gnus-button-browse-level 5
7446 "*Integer that says how many buttons for browsing will appear.
7447 The higher the number, the more buttons will appear and the more false
7448 positives are possible."
7449 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7450 :version "22.1"
7451 :group 'gnus-article-buttons
7452 :type 'integer)
7453
7454 (defcustom gnus-button-alist
7455 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7456 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7457 ((concat "\\b\\(nntp\\|news\\):\\("
7458 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7459 0 t gnus-button-handle-news 2)
7460 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7461 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7462 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7463 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7464 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7465 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7466 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7467 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7468 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7469 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7470 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7471 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7472 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7473 ;; RFC 2368 (The mailto URL scheme)
7474 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7475 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7476 ("\\bmailto:\\([^ \n\t]+\\)"
7477 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7478 ;; CTAN
7479 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7480 gnus-button-ctan-directory-regexp
7481 "[^][>)!;:,'\n\t ]+\\)")
7482 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7483 ((concat "\\btex-archive/\\("
7484 gnus-button-ctan-directory-regexp
7485 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7486 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7487 ((concat
7488 "\\b\\("
7489 gnus-button-ctan-directory-regexp
7490 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7491 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7492 ;; Info Konqueror style <info:/foo/bar baz>.
7493 ;; Must come before " Gnus home-grown style".
7494 ("\\binfo://?\\([^'\">\n\t]+\\)"
7495 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7496 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7497 ("\\binfo://\\([^'\">\n\t ]+\\)"
7498 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7499 ;; Info GNOME style <info:foo#bar_baz>
7500 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7501 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7502 ;; Info KDE style <info:(foo)bar baz>
7503 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7504 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7505 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7506 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7507 ("\\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,]*\\)\\)?"
7508 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7509 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7510 ;; This is custom
7511 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7512 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7513 ;; Emacs help commands
7514 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7515 ;; regexp doesn't match arguments containing ` '.
7516 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7517 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7518 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7519 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7520 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7521 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7522 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7523 ;; The following entries may lead to many false positives so don't enable
7524 ;; them by default (use a high button level).
7525 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7526 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7527 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7528 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7529 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7530 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7531 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7532 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7533 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7534 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7535 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7536 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7537 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7538 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7539 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7540 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7541 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7542 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7543 ;; Unlike the other regexps we really have to require quoting
7544 ;; here to determine where it ends.
7545 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7546 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7547 ("<URL: *\\([^\n<>]*\\)>"
7548 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7549 ;; RFC 2396 (2.4.3., delims) ...
7550 ("\"URL: *\\([^\n\"]*\\)\""
7551 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7552 ;; Raw URLs.
7553 (gnus-button-url-regexp
7554 0 (>= gnus-button-browse-level 0) browse-url 0)
7555 ;; man pages
7556 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7557 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7558 gnus-button-handle-man 1)
7559 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7560 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7561 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7562 gnus-button-handle-man 1)
7563 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7564 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7565 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7566 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7567 ;; Recognizing patches to .el files. This is somewhat obscure,
7568 ;; but considering the percentage of Gnus users who hack Emacs
7569 ;; Lisp files...
7570 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7571 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7572 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7573 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7574 ;; MID or mail: To avoid too many false positives we don't try to catch
7575 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7576 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7577 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7578 ;; so that non-ambiguous entries (see above) match first.
7579 (gnus-button-mid-or-mail-regexp
7580 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7581 "*Alist of regexps matching buttons in article bodies.
7582
7583 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7584 REGEXP: is the string (case insensitive) matching text around the button (can
7585 also be Lisp expression evaluating to a string),
7586 BUTTON: is the number of the regexp grouping actually matching the button,
7587 FORM: is a Lisp expression which must eval to true for the button to
7588 be added,
7589 CALLBACK: is the function to call when the user push this button, and each
7590 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7591
7592 CALLBACK can also be a variable, in that case the value of that
7593 variable it the real callback function."
7594 :group 'gnus-article-buttons
7595 :type '(repeat (list (choice regexp variable sexp)
7596 (integer :tag "Button")
7597 (sexp :tag "Form")
7598 (function :tag "Callback")
7599 (repeat :tag "Par"
7600 :inline t
7601 (integer :tag "Regexp group")))))
7602 (put 'gnus-button-alist 'risky-local-variable t)
7603
7604 (defcustom gnus-header-button-alist
7605 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7606 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7607 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7608 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7609 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7610 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7611 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7612 0 (>= gnus-button-browse-level 0) browse-url 0)
7613 ("^Subject:" gnus-button-url-regexp
7614 0 (>= gnus-button-browse-level 0) browse-url 0)
7615 ("^[^:]+:" gnus-button-url-regexp
7616 0 (>= gnus-button-browse-level 0) browse-url 0)
7617 ("^OpenPGP:.*url=" gnus-button-url-regexp
7618 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7619 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7620 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7621 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7622 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7623 "*Alist of headers and regexps to match buttons in article heads.
7624
7625 This alist is very similar to `gnus-button-alist', except that each
7626 alist has an additional HEADER element first in each entry:
7627
7628 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7629
7630 HEADER is a regexp to match a header. For a fuller explanation, see
7631 `gnus-button-alist'."
7632 :group 'gnus-article-buttons
7633 :group 'gnus-article-headers
7634 :type '(repeat (list (regexp :tag "Header")
7635 (choice regexp variable)
7636 (integer :tag "Button")
7637 (sexp :tag "Form")
7638 (function :tag "Callback")
7639 (repeat :tag "Par"
7640 :inline t
7641 (integer :tag "Regexp group")))))
7642 (put 'gnus-header-button-alist 'risky-local-variable t)
7643
7644 ;;; Commands:
7645
7646 (defun gnus-article-push-button (event)
7647 "Check text under the mouse pointer for a callback function.
7648 If the text under the mouse pointer has a `gnus-callback' property,
7649 call it with the value of the `gnus-data' text property."
7650 (interactive "e")
7651 (set-buffer (window-buffer (posn-window (event-start event))))
7652 (let* ((pos (posn-point (event-start event)))
7653 (data (get-text-property pos 'gnus-data))
7654 (fun (get-text-property pos 'gnus-callback)))
7655 (goto-char pos)
7656 (when fun
7657 (funcall fun data))))
7658
7659 (defun gnus-article-press-button ()
7660 "Check text at point for a callback function.
7661 If the text at point has a `gnus-callback' property,
7662 call it with the value of the `gnus-data' text property."
7663 (interactive)
7664 (let ((data (get-text-property (point) 'gnus-data))
7665 (fun (get-text-property (point) 'gnus-callback)))
7666 (when fun
7667 (funcall fun data))))
7668
7669 (defun gnus-article-highlight (&optional force)
7670 "Highlight current article.
7671 This function calls `gnus-article-highlight-headers',
7672 `gnus-article-highlight-citation',
7673 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7674 do the highlighting. See the documentation for those functions."
7675 (interactive (list 'force))
7676 (gnus-article-highlight-headers)
7677 (gnus-article-highlight-citation force)
7678 (gnus-article-highlight-signature)
7679 (gnus-article-add-buttons force)
7680 (gnus-article-add-buttons-to-head))
7681
7682 (defun gnus-article-highlight-some (&optional force)
7683 "Highlight current article.
7684 This function calls `gnus-article-highlight-headers',
7685 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7686 do the highlighting. See the documentation for those functions."
7687 (interactive (list 'force))
7688 (gnus-article-highlight-headers)
7689 (gnus-article-highlight-signature)
7690 (gnus-article-add-buttons))
7691
7692 (defun gnus-article-highlight-headers ()
7693 "Highlight article headers as specified by `gnus-header-face-alist'."
7694 (interactive)
7695 (gnus-with-article-headers
7696 (let (regexp header-face field-face from hpoints fpoints)
7697 (dolist (entry gnus-header-face-alist)
7698 (goto-char (point-min))
7699 (setq regexp (concat "^\\("
7700 (if (string-equal "" (nth 0 entry))
7701 "[^\t ]"
7702 (nth 0 entry))
7703 "\\)")
7704 header-face (nth 1 entry)
7705 field-face (nth 2 entry))
7706 (while (and (re-search-forward regexp nil t)
7707 (not (eobp)))
7708 (beginning-of-line)
7709 (setq from (point))
7710 (unless (search-forward ":" nil t)
7711 (forward-char 1))
7712 (when (and header-face
7713 (not (memq (point) hpoints)))
7714 (push (point) hpoints)
7715 (gnus-put-text-property from (point) 'face header-face))
7716 (when (and field-face
7717 (not (memq (setq from (point)) fpoints)))
7718 (push from fpoints)
7719 (if (re-search-forward "^[^ \t]" nil t)
7720 (forward-char -2)
7721 (goto-char (point-max)))
7722 (gnus-put-text-property from (point) 'face field-face)))))))
7723
7724 (defun gnus-article-highlight-signature ()
7725 "Highlight the signature in an article.
7726 It does this by highlighting everything after
7727 `gnus-signature-separator' using the face `gnus-signature'."
7728 (interactive)
7729 (gnus-with-article-buffer
7730 (let ((inhibit-point-motion-hooks t))
7731 (save-restriction
7732 (when (and gnus-signature-face
7733 (gnus-article-narrow-to-signature))
7734 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7735 'face gnus-signature-face)
7736 (widen)
7737 (gnus-article-search-signature)
7738 (let ((start (match-beginning 0))
7739 (end (set-marker (make-marker) (1+ (match-end 0)))))
7740 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7741 end)))))))
7742
7743 (defun gnus-button-in-region-p (b e prop)
7744 "Say whether PROP exists in the region."
7745 (text-property-not-all b e prop nil))
7746
7747 (defun gnus-article-add-buttons (&optional force)
7748 "Find external references in the article and make buttons of them.
7749 \"External references\" are things like Message-IDs and URLs, as
7750 specified by `gnus-button-alist'."
7751 (interactive (list 'force))
7752 (gnus-with-article-buffer
7753 (let ((inhibit-point-motion-hooks t)
7754 (case-fold-search t)
7755 (alist gnus-button-alist)
7756 beg entry regexp)
7757 ;; Remove all old markers.
7758 (let (marker entry new-list)
7759 (while (setq marker (pop gnus-button-marker-list))
7760 (if (or (< marker (point-min)) (>= marker (point-max)))
7761 (push marker new-list)
7762 (goto-char marker)
7763 (when (setq entry (gnus-button-entry))
7764 (put-text-property (match-beginning (nth 1 entry))
7765 (match-end (nth 1 entry))
7766 'gnus-callback nil))
7767 (set-marker marker nil)))
7768 (setq gnus-button-marker-list new-list))
7769 ;; We skip the headers.
7770 (article-goto-body)
7771 (setq beg (point))
7772 (while (setq entry (pop alist))
7773 (setq regexp (eval (car entry)))
7774 (goto-char beg)
7775 (while (re-search-forward regexp nil t)
7776 (let ((start (match-beginning (nth 1 entry)))
7777 (end (match-end (nth 1 entry)))
7778 (from (match-beginning 0)))
7779 (when (and (or (eq t (nth 2 entry))
7780 (eval (nth 2 entry)))
7781 (not (gnus-button-in-region-p
7782 start end 'gnus-callback)))
7783 ;; That optional form returned non-nil, so we add the
7784 ;; button.
7785 (setq from (set-marker (make-marker) from))
7786 (push from gnus-button-marker-list)
7787 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7788 (gnus-article-extend-url-button from start end))
7789 (gnus-article-add-button start end
7790 'gnus-button-push from)))))))))
7791
7792 (defun gnus-article-extend-url-button (beg start end)
7793 "Extend url button if url is folded into two or more lines.
7794 Return non-nil if button is extended. BEG is a marker that points to
7795 the beginning position of a text containing url. START and END are
7796 the endpoints of a url button before it is extended. The concatenated
7797 url is put as the `gnus-button-url' overlay property on the button."
7798 (let ((opoint (point))
7799 (points (list start end))
7800 url delim regexp)
7801 (prog1
7802 (when (and (progn
7803 (goto-char end)
7804 (not (looking-at "[\t ]*[\">]")))
7805 (progn
7806 (goto-char start)
7807 (string-match
7808 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7809 (buffer-substring (point-at-bol) start)))
7810 (progn
7811 (setq url (list (buffer-substring start end))
7812 delim (if (match-beginning 1) ">" "\""))
7813 (beginning-of-line)
7814 (setq regexp (concat
7815 (when (and (looking-at
7816 message-cite-prefix-regexp)
7817 (< (match-end 0) start))
7818 (regexp-quote (match-string 0)))
7819 "\
7820 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7821 delim "\\)"))
7822 (while (progn
7823 (forward-line 1)
7824 (and (looking-at regexp)
7825 (prog1
7826 (match-beginning 1)
7827 (push (or (match-string 2)
7828 (match-string 1))
7829 url)
7830 (push (setq end (or (match-end 2)
7831 (match-end 1)))
7832 points)
7833 (push (or (match-beginning 2)
7834 (match-beginning 1))
7835 points)))))
7836 (match-beginning 2)))
7837 (let (gnus-article-mouse-face widget-mouse-face)
7838 (while points
7839 (gnus-article-add-button (pop points) (pop points)
7840 'gnus-button-push beg)))
7841 (let ((overlay (gnus-make-overlay start end)))
7842 (gnus-overlay-put overlay 'evaporate t)
7843 (gnus-overlay-put overlay 'gnus-button-url
7844 (list (mapconcat 'identity (nreverse url) "")))
7845 (when gnus-article-mouse-face
7846 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7847 t)
7848 (goto-char opoint))))
7849
7850 ;; Add buttons to the head of an article.
7851 (defun gnus-article-add-buttons-to-head ()
7852 "Add buttons to the head of the article."
7853 (interactive)
7854 (gnus-with-article-headers
7855 (let (beg end)
7856 (dolist (entry gnus-header-button-alist)
7857 ;; Each alist entry.
7858 (goto-char (point-min))
7859 (while (re-search-forward (car entry) nil t)
7860 ;; Each header matching the entry.
7861 (setq beg (match-beginning 0))
7862 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7863 (match-beginning 0))
7864 (point-max)))
7865 (goto-char beg)
7866 (while (re-search-forward (eval (nth 1 entry)) end t)
7867 ;; Each match within a header.
7868 (let* ((entry (cdr entry))
7869 (start (match-beginning (nth 1 entry)))
7870 (end (match-end (nth 1 entry)))
7871 (form (nth 2 entry)))
7872 (goto-char (match-end 0))
7873 (when (eval form)
7874 (gnus-article-add-button
7875 start end (nth 3 entry)
7876 (buffer-substring (match-beginning (nth 4 entry))
7877 (match-end (nth 4 entry)))))))
7878 (goto-char end))))))
7879
7880 ;;; External functions:
7881
7882 (defun gnus-article-add-button (from to fun &optional data)
7883 "Create a button between FROM and TO with callback FUN and data DATA."
7884 (when gnus-article-button-face
7885 (gnus-overlay-put (gnus-make-overlay from to nil t)
7886 'face gnus-article-button-face))
7887 (gnus-add-text-properties
7888 from to
7889 (nconc (and gnus-article-mouse-face
7890 (list gnus-mouse-face-prop gnus-article-mouse-face))
7891 (list 'gnus-callback fun)
7892 (and data (list 'gnus-data data))))
7893 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7894 :button-keymap gnus-widget-button-keymap))
7895
7896 ;;; Internal functions:
7897
7898 (defun gnus-article-set-globals ()
7899 (with-current-buffer gnus-summary-buffer
7900 (gnus-set-global-variables)))
7901
7902 (defun gnus-signature-toggle (end)
7903 (gnus-with-article-buffer
7904 (let ((inhibit-point-motion-hooks t))
7905 (if (text-property-any end (point-max) 'article-type 'signature)
7906 (progn
7907 (gnus-delete-wash-type 'signature)
7908 (gnus-remove-text-properties-when
7909 'article-type 'signature end (point-max)
7910 (cons 'article-type (cons 'signature
7911 gnus-hidden-properties))))
7912 (gnus-add-wash-type 'signature)
7913 (gnus-add-text-properties-when
7914 'article-type nil end (point-max)
7915 (cons 'article-type (cons 'signature
7916 gnus-hidden-properties)))))
7917 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7918 (gnus-set-mode-line 'article))))
7919
7920 (defun gnus-button-entry ()
7921 ;; Return the first entry in `gnus-button-alist' matching this place.
7922 (let ((alist gnus-button-alist)
7923 (entry nil))
7924 (while alist
7925 (setq entry (pop alist))
7926 (if (looking-at (eval (car entry)))
7927 (setq alist nil)
7928 (setq entry nil)))
7929 entry))
7930
7931 (defun gnus-button-push (marker)
7932 ;; Push button starting at MARKER.
7933 (save-excursion
7934 (goto-char marker)
7935 (let* ((entry (gnus-button-entry))
7936 (inhibit-point-motion-hooks t)
7937 (fun (nth 3 entry))
7938 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7939 (get-char-property marker 'gnus-button-url))
7940 (mapcar (lambda (group)
7941 (let ((string (match-string group)))
7942 (set-text-properties
7943 0 (length string) nil string)
7944 string))
7945 (nthcdr 4 entry)))))
7946 (cond
7947 ((fboundp fun)
7948 (apply fun args))
7949 ((and (boundp fun)
7950 (fboundp (symbol-value fun)))
7951 (apply (symbol-value fun) args))
7952 (t
7953 (gnus-message 1 "You must define `%S' to use this button"
7954 (cons fun args)))))))
7955
7956 (defun gnus-parse-news-url (url)
7957 (let (scheme server port group message-id articles)
7958 (with-temp-buffer
7959 (insert url)
7960 (goto-char (point-min))
7961 (when (looking-at "\\([A-Za-z]+\\):")
7962 (setq scheme (match-string 1))
7963 (goto-char (match-end 0)))
7964 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7965 (setq server (match-string 1))
7966 (setq port (if (stringp (match-string 3))
7967 (string-to-number (match-string 3))
7968 (match-string 3)))
7969 (goto-char (match-end 0)))
7970
7971 (cond
7972 ((looking-at "\\(.*@.*\\)")
7973 (setq message-id (match-string 1)))
7974 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7975 (setq group (match-string 1)
7976 articles (split-string (match-string 2) "-")))
7977 ((looking-at "\\([^/]+\\)/?")
7978 (setq group (match-string 1)))
7979 (t
7980 (error "Unknown news URL syntax"))))
7981 (list scheme server port group message-id articles)))
7982
7983 (defun gnus-button-handle-news (url)
7984 "Fetch a news URL."
7985 (destructuring-bind (scheme server port group message-id articles)
7986 (gnus-parse-news-url url)
7987 (cond
7988 (message-id
7989 (with-current-buffer gnus-summary-buffer
7990 (if server
7991 (let ((gnus-refer-article-method
7992 (nconc (list (list 'nntp server))
7993 gnus-refer-article-method))
7994 (nntp-port-number (or port "nntp")))
7995 (gnus-message 7 "Fetching %s with %s"
7996 message-id gnus-refer-article-method)
7997 (gnus-summary-refer-article message-id))
7998 (gnus-summary-refer-article message-id))))
7999 (group
8000 (gnus-button-fetch-group url)))))
8001
8002 (defun gnus-button-patch (library line)
8003 "Visit an Emacs Lisp library LIBRARY on line LINE."
8004 (interactive)
8005 (let ((file (locate-library (file-name-nondirectory library))))
8006 (unless file
8007 (error "Couldn't find library %s" library))
8008 (find-file file)
8009 (goto-char (point-min))
8010 (forward-line (1- (string-to-number line)))))
8011
8012 (defun gnus-button-handle-man (url)
8013 "Fetch a man page."
8014 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8015 (when (eq gnus-button-man-handler 'woman)
8016 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8017 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8018 (funcall gnus-button-man-handler url))
8019
8020 (defun gnus-button-handle-info-url (url)
8021 "Fetch an info URL."
8022 (setq url (mm-subst-char-in-string ?+ ?\ url))
8023 (cond
8024 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8025 (gnus-info-find-node
8026 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8027 "Gnus")
8028 ")" (gnus-url-unhex-string (match-string 2 url)))))
8029 ((string-match "([^)\"]+)[^\"]+" url)
8030 (setq url
8031 (gnus-replace-in-string
8032 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8033 (gnus-info-find-node url))
8034 (t (error "Can't parse %s" url))))
8035
8036 (defun gnus-button-handle-info-url-gnome (url)
8037 "Fetch GNOME style info URL."
8038 (setq url (mm-subst-char-in-string ?_ ?\ url))
8039 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8040 (gnus-info-find-node
8041 (concat "("
8042 (gnus-url-unhex-string
8043 (match-string 1 url))
8044 ")"
8045 (or (gnus-url-unhex-string
8046 (match-string 2 url))
8047 "Top")))
8048 (error "Can't parse %s" url)))
8049
8050 (defun gnus-button-handle-info-url-kde (url)
8051 "Fetch KDE style info URL."
8052 (gnus-info-find-node (gnus-url-unhex-string url)))
8053
8054 ;; (info) will autoload info.el
8055 (declare-function Info-menu "info" (menu-item &optional fork))
8056 (declare-function Info-index-next "info" (num))
8057
8058 (defun gnus-button-handle-info-keystrokes (url)
8059 "Call `info' when pushing the corresponding URL button."
8060 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8061 (let (node indx comma)
8062 (if (string-match
8063 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8064 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8065 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
8066 "\\(?:[ \t\n,]*\\)\\)?")
8067 url)
8068 (setq node (match-string 2 url)
8069 indx (match-string 3 url))
8070 (error "Can't parse %s" url))
8071 (info)
8072 (Info-directory)
8073 (Info-menu node)
8074 (when (> (length indx) 0)
8075 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8076 "\\([ \t\n,]*\\)")
8077 indx)
8078 (setq comma (match-string 2 indx))
8079 (setq indx (match-string 1 indx))
8080 (Info-index indx)
8081 (when comma
8082 (dotimes (i (with-temp-buffer
8083 (insert comma)
8084 ;; Note: the XEmacs version of `how-many' takes
8085 ;; no optional argument.
8086 (goto-char (point-min))
8087 (how-many ",")))
8088 (Info-index-next 1)))
8089 nil)))
8090
8091 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8092 (declare-function pgg-display-output-buffer "pgg" (start end status))
8093
8094 (defun gnus-button-openpgp (url)
8095 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8096 (with-temp-buffer
8097 (mm-url-insert-file-contents-external url)
8098 (pgg-snarf-keys-region (point-min) (point-max))
8099 (pgg-display-output-buffer nil nil nil)))
8100
8101 (defun gnus-button-message-id (message-id)
8102 "Fetch MESSAGE-ID."
8103 (with-current-buffer gnus-summary-buffer
8104 (gnus-summary-refer-article message-id)))
8105
8106 (defun gnus-button-fetch-group (address &rest ignore)
8107 "Fetch GROUP specified by ADDRESS."
8108 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8109 address)
8110 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8111 ;; for nntp:// and news://
8112 (setq address (match-string 3 address)))
8113 (if (not (string-match "[:/]" address))
8114 ;; This is just a simple group url.
8115 (gnus-group-read-ephemeral-group address gnus-select-method)
8116 (if (not
8117 (string-match
8118 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8119 address))
8120 (error "Can't parse %s" address)
8121 (gnus-group-read-ephemeral-group
8122 (match-string 4 address)
8123 `(nntp ,(match-string 1 address)
8124 (nntp-address ,(match-string 1 address))
8125 (nntp-port-number ,(if (match-end 3)
8126 (match-string 3 address)
8127 "nntp")))
8128 nil nil nil
8129 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8130
8131 (defun gnus-url-parse-query-string (query &optional downcase)
8132 (let (retval pairs cur key val)
8133 (setq pairs (split-string query "&"))
8134 (while pairs
8135 (setq cur (car pairs)
8136 pairs (cdr pairs))
8137 (if (not (string-match "=" cur))
8138 nil ; Grace
8139 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8140 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8141 (if downcase
8142 (setq key (downcase key)))
8143 (setq cur (assoc key retval))
8144 (if cur
8145 (setcdr cur (cons val (cdr cur)))
8146 (setq retval (cons (list key val) retval)))))
8147 retval))
8148
8149 (defun gnus-url-mailto (url)
8150 ;; Send mail to someone
8151 (when (string-match "mailto:/*\\(.*\\)" url)
8152 (setq url (substring url (match-beginning 1) nil)))
8153 (let (to args subject func)
8154 (setq args (gnus-url-parse-query-string
8155 (if (string-match "^\\?" url)
8156 (substring url 1)
8157 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8158 (concat "to=" (match-string 1 url) "&"
8159 (match-string 2 url))
8160 (concat "to=" url)))
8161 t)
8162 subject (cdr-safe (assoc "subject" args)))
8163 (gnus-msg-mail)
8164 (while args
8165 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8166 (if (fboundp func)
8167 (funcall func)
8168 (message-position-on-field (caar args)))
8169 (insert (gnus-replace-in-string
8170 (mapconcat 'identity (reverse (cdar args)) ", ")
8171 "\r\n" "\n" t))
8172 (setq args (cdr args)))
8173 (if subject
8174 (message-goto-body)
8175 (message-goto-subject))))
8176
8177 (defun gnus-button-embedded-url (address)
8178 "Activate ADDRESS with `browse-url'."
8179 (browse-url (gnus-strip-whitespace address)))
8180
8181 ;;; Next/prev buttons in the article buffer.
8182
8183 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8184 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8185
8186 (defvar gnus-prev-page-map
8187 (let ((map (make-sparse-keymap)))
8188 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8189 (define-key map "\r" 'gnus-button-prev-page)
8190 map))
8191
8192 (defvar gnus-next-page-map
8193 (let ((map (make-sparse-keymap)))
8194 (unless (>= emacs-major-version 21)
8195 ;; XEmacs doesn't care.
8196 (set-keymap-parent map gnus-article-mode-map))
8197 (define-key map gnus-mouse-2 'gnus-button-next-page)
8198 (define-key map "\r" 'gnus-button-next-page)
8199 map))
8200
8201 (defun gnus-insert-prev-page-button ()
8202 (let ((b (point)) e
8203 (inhibit-read-only t))
8204 (gnus-eval-format
8205 gnus-prev-page-line-format nil
8206 `(keymap ,gnus-prev-page-map
8207 gnus-prev t
8208 gnus-callback gnus-article-button-prev-page
8209 article-type annotation))
8210 (setq e (if (bolp)
8211 ;; Exclude a newline.
8212 (1- (point))
8213 (point)))
8214 (when gnus-article-button-face
8215 (gnus-overlay-put (gnus-make-overlay b e nil t)
8216 'face gnus-article-button-face))
8217 (widget-convert-button
8218 'link b e
8219 :action 'gnus-button-prev-page
8220 :button-keymap gnus-prev-page-map)))
8221
8222 (defun gnus-button-next-page (&optional args more-args)
8223 "Go to the next page."
8224 (interactive)
8225 (let ((win (selected-window)))
8226 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8227 (gnus-article-next-page)
8228 (select-window win)))
8229
8230 (defun gnus-button-prev-page (&optional args more-args)
8231 "Go to the prev page."
8232 (interactive)
8233 (let ((win (selected-window)))
8234 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8235 (gnus-article-prev-page)
8236 (select-window win)))
8237
8238 (defun gnus-insert-next-page-button ()
8239 (let ((b (point)) e
8240 (inhibit-read-only t))
8241 (gnus-eval-format gnus-next-page-line-format nil
8242 `(keymap ,gnus-next-page-map
8243 gnus-next t
8244 gnus-callback gnus-article-button-next-page
8245 article-type annotation))
8246 (setq e (if (bolp)
8247 ;; Exclude a newline.
8248 (1- (point))
8249 (point)))
8250 (when gnus-article-button-face
8251 (gnus-overlay-put (gnus-make-overlay b e nil t)
8252 'face gnus-article-button-face))
8253 (widget-convert-button
8254 'link b e
8255 :action 'gnus-button-next-page
8256 :button-keymap gnus-next-page-map)))
8257
8258 (defun gnus-article-button-next-page (arg)
8259 "Go to the next page."
8260 (interactive "P")
8261 (let ((win (selected-window)))
8262 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8263 (gnus-article-next-page)
8264 (select-window win)))
8265
8266 (defun gnus-article-button-prev-page (arg)
8267 "Go to the prev page."
8268 (interactive "P")
8269 (let ((win (selected-window)))
8270 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8271 (gnus-article-prev-page)
8272 (select-window win)))
8273
8274 (defvar gnus-decode-header-methods
8275 '(mail-decode-encoded-word-region)
8276 "List of methods used to decode headers.
8277
8278 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8279 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8280 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8281 whose names match REGEXP.
8282
8283 For example:
8284 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8285 mail-decode-encoded-word-region
8286 (\"chinese\" . rfc1843-decode-region))
8287 ")
8288
8289 (defvar gnus-decode-header-methods-cache nil)
8290
8291 (defun gnus-multi-decode-header (start end)
8292 "Apply the functions from `gnus-encoded-word-methods' that match."
8293 (unless (and gnus-decode-header-methods-cache
8294 (eq gnus-newsgroup-name
8295 (car gnus-decode-header-methods-cache)))
8296 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8297 (dolist (x gnus-decode-header-methods)
8298 (if (symbolp x)
8299 (nconc gnus-decode-header-methods-cache (list x))
8300 (if (and gnus-newsgroup-name
8301 (string-match (car x) gnus-newsgroup-name))
8302 (nconc gnus-decode-header-methods-cache
8303 (list (cdr x)))))))
8304 (let ((xlist gnus-decode-header-methods-cache))
8305 (pop xlist)
8306 (save-restriction
8307 (narrow-to-region start end)
8308 (while xlist
8309 (funcall (pop xlist) (point-min) (point-max))))))
8310
8311 ;;;
8312 ;;; Treatment top-level handling.
8313 ;;;
8314
8315 (defun gnus-treat-article (condition &optional part-number total-parts type)
8316 (let ((length (- (point-max) (point-min)))
8317 (alist gnus-treatment-function-alist)
8318 (article-goto-body-goes-to-point-min-p t)
8319 (treated-type
8320 (or (not type)
8321 (catch 'found
8322 (let ((list gnus-article-treat-types))
8323 (while list
8324 (when (string-match (pop list) type)
8325 (throw 'found t)))))))
8326 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8327 val elem)
8328 (gnus-run-hooks 'gnus-part-display-hook)
8329 (dolist (elem alist)
8330 (setq val
8331 (save-excursion
8332 (when (gnus-buffer-live-p gnus-summary-buffer)
8333 (set-buffer gnus-summary-buffer))
8334 (symbol-value (car elem))))
8335 (when (and (or (consp val)
8336 treated-type)
8337 (gnus-treat-predicate val)
8338 (or (not (get (car elem) 'highlight))
8339 highlightp))
8340 (save-restriction
8341 (funcall (cadr elem)))))))
8342
8343 ;; Dynamic variables.
8344 (defvar part-number)
8345 (defvar total-parts)
8346 (defvar type)
8347 (defvar condition)
8348 (defvar length)
8349
8350 (defun gnus-treat-predicate (val)
8351 (cond
8352 ((null val)
8353 nil)
8354 (condition
8355 (eq condition val))
8356 ((and (listp val)
8357 (stringp (car val)))
8358 (apply 'gnus-or (mapcar `(lambda (s)
8359 (string-match s ,(or gnus-newsgroup-name "")))
8360 val)))
8361 ((listp val)
8362 (let ((pred (pop val)))
8363 (cond
8364 ((eq pred 'or)
8365 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8366 ((eq pred 'and)
8367 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8368 ((eq pred 'not)
8369 (not (gnus-treat-predicate (car val))))
8370 ((eq pred 'typep)
8371 (equal (car val) type))
8372 (t
8373 (error "%S is not a valid predicate" pred)))))
8374 ((eq val t)
8375 t)
8376 ((eq val 'head)
8377 nil)
8378 ((eq val 'first)
8379 (eq part-number 1))
8380 ((eq val 'last)
8381 (eq part-number total-parts))
8382 ((numberp val)
8383 (< length val))
8384 (t
8385 (error "%S is not a valid value" val))))
8386
8387 (defun gnus-article-encrypt-body (protocol &optional n)
8388 "Encrypt the article body."
8389 (interactive
8390 (list
8391 (or gnus-article-encrypt-protocol
8392 (completing-read "Encrypt protocol: "
8393 gnus-article-encrypt-protocol-alist
8394 nil t))
8395 current-prefix-arg))
8396 ;; User might hit `K E' instead of `K e', so prompt once.
8397 (when (and gnus-article-encrypt-protocol
8398 gnus-novice-user)
8399 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8400 (error "Encrypt aborted")))
8401 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8402 (unless func
8403 (error "Can't find the encrypt protocol %s" protocol))
8404 (if (member gnus-newsgroup-name '("nndraft:delayed"
8405 "nndraft:drafts"
8406 "nndraft:queue"))
8407 (error "Can't encrypt the article in group %s"
8408 gnus-newsgroup-name))
8409 (gnus-summary-iterate n
8410 (with-current-buffer gnus-summary-buffer
8411 (let ((mail-parse-charset gnus-newsgroup-charset)
8412 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8413 (summary-buffer gnus-summary-buffer)
8414 references point)
8415 (gnus-set-global-variables)
8416 (when (gnus-group-read-only-p)
8417 (error "The current newsgroup does not support article encrypt"))
8418 (gnus-summary-show-article t)
8419 (setq references
8420 (or (mail-header-references gnus-current-headers) ""))
8421 (set-buffer gnus-article-buffer)
8422 (let* ((inhibit-read-only t)
8423 (headers
8424 (mapcar (lambda (field)
8425 (and (save-restriction
8426 (message-narrow-to-head)
8427 (goto-char (point-min))
8428 (search-forward field nil t))
8429 (prog2
8430 (message-narrow-to-field)
8431 (buffer-string)
8432 (delete-region (point-min) (point-max))
8433 (widen))))
8434 '("Content-Type:" "Content-Transfer-Encoding:"
8435 "Content-Disposition:"))))
8436 (message-narrow-to-head)
8437 (message-remove-header "MIME-Version")
8438 (goto-char (point-max))
8439 (setq point (point))
8440 (insert (apply 'concat headers))
8441 (widen)
8442 (narrow-to-region point (point-max))
8443 (let ((message-options message-options))
8444 (message-options-set 'message-sender user-mail-address)
8445 (message-options-set 'message-recipients user-mail-address)
8446 (message-options-set 'message-sign-encrypt 'not)
8447 (funcall func))
8448 (goto-char (point-min))
8449 (insert "MIME-Version: 1.0\n")
8450 (widen)
8451 (gnus-summary-edit-article-done
8452 references nil summary-buffer t))
8453 (when gnus-keep-backlog
8454 (gnus-backlog-remove-article
8455 (car gnus-article-current) (cdr gnus-article-current)))
8456 (when (get-buffer gnus-original-article-buffer)
8457 (with-current-buffer gnus-original-article-buffer
8458 (setq gnus-original-article nil)))
8459 (when gnus-use-cache
8460 (gnus-cache-update-article
8461 (car gnus-article-current) (cdr gnus-article-current))))))))
8462
8463 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8464 "The following specs can be used:
8465 %t The security MIME type
8466 %i Additional info
8467 %d Details
8468 %D Details if button is pressed")
8469
8470 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8471 "The following specs can be used:
8472 %t The security MIME type
8473 %i Additional info
8474 %d Details
8475 %D Details if button is pressed")
8476
8477 (defvar gnus-mime-security-button-line-format-alist
8478 '((?t gnus-tmp-type ?s)
8479 (?i gnus-tmp-info ?s)
8480 (?d gnus-tmp-details ?s)
8481 (?D gnus-tmp-pressed-details ?s)))
8482
8483 (defvar gnus-mime-security-button-commands
8484 '((gnus-article-press-button "\r" "Show Detail")
8485 (undefined "v")
8486 (undefined "t")
8487 (undefined "C")
8488 (gnus-mime-security-save-part "o" "Save...")
8489 (undefined "\C-o")
8490 (undefined "r")
8491 (undefined "d")
8492 (undefined "c")
8493 (undefined "i")
8494 (undefined "E")
8495 (undefined "e")
8496 (undefined "p")
8497 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8498 (undefined ".")))
8499
8500 (defvar gnus-mime-security-button-map
8501 (let ((map (make-sparse-keymap)))
8502 (define-key map gnus-mouse-2 'gnus-article-push-button)
8503 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8504 (dolist (c gnus-mime-security-button-commands)
8505 (define-key map (cadr c) (car c)))
8506 map))
8507
8508 (easy-menu-define
8509 gnus-mime-security-button-menu gnus-mime-security-button-map
8510 "Security button menu."
8511 `("Security Part"
8512 ,@(delq nil
8513 (mapcar (lambda (c)
8514 (unless (eq (car c) 'undefined)
8515 (vector (caddr c) (car c) :active t)))
8516 gnus-mime-security-button-commands))))
8517
8518 (defun gnus-mime-security-button-menu (event prefix)
8519 "Construct a context-sensitive menu of security commands."
8520 (interactive "e\nP")
8521 (save-window-excursion
8522 (let ((pos (event-start event)))
8523 (select-window (posn-window pos))
8524 (goto-char (posn-point pos))
8525 (gnus-article-check-buffer)
8526 (popup-menu gnus-mime-security-button-menu nil prefix))))
8527
8528 (defvar gnus-mime-security-details-buffer nil)
8529
8530 (defvar gnus-mime-security-button-pressed nil)
8531
8532 (defvar gnus-mime-security-show-details-inline t
8533 "If non-nil, show details in the article buffer.")
8534
8535 (defun gnus-mime-security-verify-or-decrypt (handle)
8536 (mm-remove-parts (cdr handle))
8537 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8538 point (inhibit-read-only t))
8539 (if region
8540 (goto-char (car region)))
8541 (setq point (point))
8542 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8543 (let* ((mm-verify-option 'known)
8544 (mm-decrypt-option 'known)
8545 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8546 (unless (eq nparts (cdr handle))
8547 (mm-destroy-parts (cdr handle))
8548 (setcdr handle nparts))))
8549 (gnus-mime-display-security handle)
8550 (when region
8551 (delete-region (point) (cdr region))
8552 (set-marker (car region) nil)
8553 (set-marker (cdr region) nil))
8554 (goto-char point)))
8555
8556 (defun gnus-mime-security-show-details (handle)
8557 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8558 (if (not details)
8559 (gnus-message 5 "No details.")
8560 (if gnus-mime-security-show-details-inline
8561 (let ((gnus-mime-security-button-pressed
8562 (not (get-text-property (point) 'gnus-mime-details)))
8563 (gnus-mime-security-button-line-format
8564 (get-text-property (point) 'gnus-line-format))
8565 (inhibit-read-only t))
8566 (forward-char -1)
8567 (while (eq (get-text-property (point) 'gnus-line-format)
8568 gnus-mime-security-button-line-format)
8569 (forward-char -1))
8570 (forward-char)
8571 (save-restriction
8572 (narrow-to-region (point) (point))
8573 (gnus-insert-mime-security-button handle))
8574 (delete-region (point)
8575 (or (text-property-not-all
8576 (point) (point-max)
8577 'gnus-line-format
8578 gnus-mime-security-button-line-format)
8579 (point-max))))
8580 ;; Not inlined.
8581 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8582 (with-current-buffer gnus-mime-security-details-buffer
8583 (erase-buffer)
8584 t)
8585 (setq gnus-mime-security-details-buffer
8586 (gnus-get-buffer-create "*MIME Security Details*")))
8587 (with-current-buffer gnus-mime-security-details-buffer
8588 (insert details)
8589 (goto-char (point-min)))
8590 (pop-to-buffer gnus-mime-security-details-buffer)))))
8591
8592 (defun gnus-mime-security-press-button (handle)
8593 (save-excursion
8594 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8595 (gnus-mime-security-show-details handle)
8596 (gnus-mime-security-verify-or-decrypt handle))))
8597
8598 (defun gnus-insert-mime-security-button (handle &optional displayed)
8599 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8600 (gnus-tmp-type
8601 (concat
8602 (or (nth 2 (assoc protocol mm-verify-function-alist))
8603 (nth 2 (assoc protocol mm-decrypt-function-alist))
8604 "Unknown")
8605 (if (equal (car handle) "multipart/signed")
8606 " Signed" " Encrypted")
8607 " Part"))
8608 (gnus-tmp-info
8609 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8610 "Undecided"))
8611 (gnus-tmp-details
8612 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8613 gnus-tmp-pressed-details
8614 b e)
8615 (setq gnus-tmp-details
8616 (if gnus-tmp-details
8617 (concat "\n" gnus-tmp-details)
8618 ""))
8619 (setq gnus-tmp-pressed-details
8620 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8621 (unless (bolp)
8622 (insert "\n"))
8623 (setq b (point))
8624 (gnus-eval-format
8625 gnus-mime-security-button-line-format
8626 gnus-mime-security-button-line-format-alist
8627 `(keymap ,gnus-mime-security-button-map
8628 gnus-callback gnus-mime-security-press-button
8629 gnus-line-format ,gnus-mime-security-button-line-format
8630 gnus-mime-details ,gnus-mime-security-button-pressed
8631 article-type annotation
8632 gnus-data ,handle))
8633 (setq e (if (bolp)
8634 ;; Exclude a newline.
8635 (1- (point))
8636 (point)))
8637 (when gnus-article-button-face
8638 (gnus-overlay-put (gnus-make-overlay b e nil t)
8639 'face gnus-article-button-face))
8640 (widget-convert-button
8641 'link b e
8642 :mime-handle handle
8643 :action 'gnus-widget-press-button
8644 :button-keymap gnus-mime-security-button-map
8645 :help-echo
8646 (lambda (widget/window &optional overlay pos)
8647 ;; Needed to properly clear the message due to a bug in
8648 ;; wid-edit (XEmacs only).
8649 (when (boundp 'help-echo-owns-message)
8650 (setq help-echo-owns-message t))
8651 (format
8652 "%S: show detail; %S: more options"
8653 (aref gnus-mouse-2 0)
8654 (aref gnus-down-mouse-3 0))))))
8655
8656 (defun gnus-mime-display-security (handle)
8657 (save-restriction
8658 (narrow-to-region (point) (point))
8659 (unless (gnus-unbuttonized-mime-type-p (car handle))
8660 (gnus-insert-mime-security-button handle))
8661 (gnus-mime-display-part (cadr handle))
8662 (unless (bolp)
8663 (insert "\n"))
8664 (unless (gnus-unbuttonized-mime-type-p (car handle))
8665 (let ((gnus-mime-security-button-line-format
8666 gnus-mime-security-button-end-line-format))
8667 (gnus-insert-mime-security-button handle)))
8668 (mm-set-handle-multipart-parameter
8669 handle 'gnus-region
8670 (cons (set-marker (make-marker) (point-min))
8671 (set-marker (make-marker) (point-max))))
8672 (goto-char (point-max))))
8673
8674 (defun gnus-mime-security-run-function (function)
8675 "Run FUNCTION with the security part under point."
8676 (gnus-article-check-buffer)
8677 (let ((data (get-text-property (point) 'gnus-data))
8678 buffer handle)
8679 (when (and (stringp (car-safe data))
8680 (setq buffer (mm-handle-multipart-original-buffer data))
8681 (setq handle (cadr data)))
8682 (if (bufferp (mm-handle-buffer handle))
8683 (progn
8684 (setq handle (cons buffer (copy-sequence (cdr handle))))
8685 (mm-handle-set-undisplayer handle nil))
8686 (setq handle (mm-make-handle
8687 buffer
8688 (mm-handle-multipart-ctl-parameter handle 'protocol)
8689 nil nil nil nil nil nil)))
8690 (funcall function handle))))
8691
8692 (defun gnus-mime-security-save-part ()
8693 "Save the security part under point."
8694 (interactive)
8695 (gnus-mime-security-run-function 'mm-save-part))
8696
8697 (defun gnus-mime-security-pipe-part ()
8698 "Pipe the security part under point to a process."
8699 (interactive)
8700 (gnus-mime-security-run-function 'mm-pipe-part))
8701
8702 (gnus-ems-redefine)
8703
8704 (provide 'gnus-art)
8705
8706 (run-hooks 'gnus-art-load-hook)
8707
8708 ;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8709 ;;; gnus-art.el ends here