Spelling fixes.
[emacs.git] / lisp / gnus / gnus-art.el
bloba11e9ebf0fa4ec4bfcfc339deab2c496719ac470
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; For Emacs <22.2 and XEmacs.
28 (eval-and-compile
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30 (eval-when-compile
31 (require 'cl))
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map)
35 (require 'gnus)
36 (require 'gnus-sum)
37 (require 'gnus-spec)
38 (require 'gnus-int)
39 (require 'gnus-win)
40 (require 'mm-bodies)
41 (require 'mail-parse)
42 (require 'mm-decode)
43 (require 'mm-view)
44 (require 'wid-edit)
45 (require 'mm-uu)
46 (require 'message)
47 (require 'mouse)
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
57 (defgroup gnus-article nil
58 "Article display."
59 :link '(custom-manual "(gnus)Article Buffer")
60 :group 'gnus)
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
65 :group 'gnus-article)
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
70 :group 'gnus-article)
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
75 :group 'gnus-article
76 :group 'gnus-visual)
78 (defgroup gnus-article-signature nil
79 "Article signatures."
80 :link '(custom-manual "(gnus)Article Signature")
81 :group 'gnus-article)
83 (defgroup gnus-article-headers nil
84 "Article headers."
85 :link '(custom-manual "(gnus)Hiding Headers")
86 :group 'gnus-article)
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
91 :group 'gnus-article)
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
96 :group 'gnus-article)
98 (defgroup gnus-article-saving nil
99 "Saving articles."
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
119 (mapcar
120 (lambda (header)
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice regexp
167 (repeat regexp))
168 :group 'gnus-article-hiding)
170 (defcustom gnus-visible-headers
171 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
172 "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
175 :type '(choice
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
179 (or (stringp value)
180 (widget-editable-list-match widget value)))
181 regexp)
182 (const :tag "Use gnus-ignored-headers" nil)
183 regexp)
184 :group 'gnus-article-hiding)
186 (defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189 "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
192 this list."
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
210 :type '(set (const :tag "Headers with no content." empty)
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
217 (const :tag "Date less than four days old." date)
218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
219 (const :tag "Multiple To and/or Cc headers." many-to))
220 :group 'gnus-article-hiding)
222 (defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text. Boring text is controlled by
227 `gnus-article-boring-faces'."
228 :version "22.1"
229 :type 'boolean
230 :group 'gnus-article-hiding)
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234 This can also be a list of regexps. In that case, it will be checked
235 from head to tail looking for a separator. Searches will be done from
236 the end of the buffer."
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238 (regexp)
239 (repeat :tag "List of regexp" regexp))
240 :group 'gnus-article-signature)
242 (defcustom gnus-signature-limit nil
243 "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number. If it is a floating point number, no signature may be
246 longer (in lines) than that number. If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer. If it is a string, it will be used as a
249 regexp. If it matches, the text in question is not a signature.
251 This can also be a list of the above values."
252 :type '(choice (const nil)
253 (integer :value 200)
254 (number :value 4.0)
255 function
256 (regexp :value ".*"))
257 :group 'gnus-article-signature)
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
261 :type 'sexp
262 :group 'gnus-article-hiding)
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
271 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272 (if (gnus-image-type-available-p 'pbm)
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
275 display -"))
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
281 function)
282 :version "21.1"
283 :group 'gnus-picon
284 :group 'gnus-article-washing)
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
293 For example,
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295 :version "21.1"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
299 (gnus-define-group-parameter
300 banner
301 :variable-document
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
304 :parameter-type
305 '(choice :tag "Banner"
306 :value nil
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
309 regexp
310 (const :tag "None" nil))
311 :parameter-document
312 "If non-nil, specify how to remove `banners' from articles.
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330 :type '(repeat
331 (cons
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
336 regexp
337 (const :tag "None" nil))))
338 :version "22.1"
339 :group 'gnus-article-washing)
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342 `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345 ,@body))
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
352 (if (nth 1 value) 2 3)
353 (nth 2 value))
354 value)))
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
361 "\\'"))
362 pattern)
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
365 (= (nth 2 value) 2)
366 (nth 3 value))
367 value))))
369 (defcustom gnus-emphasis-alist
370 (let ((types
371 '(("\\*" "\\*" bold nil 2)
372 ("_" "_" underline)
373 ("/" "/" italic)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
378 (nconc
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
382 (or (nth 3 spec) 2)
383 (or (nth 4 spec) 3)
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385 types))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
404 :type
405 '(repeat
406 (menu-choice
407 :format "%[Customizing Style%]\n%v"
408 :indent 2
409 (group :tag "Default"
410 :value ("" 0 0 default)
411 :value-create
412 (lambda (widget)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
415 :args))
416 :value)))
417 (if (not (eq (nth 2 value) 'default))
418 (widget-put
419 widget
420 :value
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
423 regexp
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
426 face)
427 (group :tag "Simple"
428 :value (("_" . "_") nil default)
429 (cons :format "%v"
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
434 face)))
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440 value)))
441 :group 'gnus-article-emphasis)
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448 :version "21.1"
449 :group 'gnus-article-emphasis
450 :type 'regexp)
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
508 might have."
509 :group 'gnus-article-saving
510 :type 'boolean)
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
534 :type 'regexp)
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favourite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
542 Gnus provides the following functions:
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
554 The symbol of each function may have the following properties:
556 * :decode
557 The value non-nil means save decoded articles. This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function-item gnus-summary-save-in-pipe)
584 (function)))
586 (defcustom gnus-article-save-coding-system
587 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591 "Coding system used to save decoded articles to a file.
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text. This is used by the
595 commands including:
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
602 and the functions to which you may set `gnus-default-article-saver':
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil. Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613 :group 'gnus-article-saving
614 :type `(choice
615 :format "%{%t%}:\n %[Value Menu%] %v"
616 (const :tag "Save raw articles" nil)
617 ,@(delq nil
618 (mapcar
619 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620 '((const :tag "UTF-8" utf-8)
621 (const :tag "iso-2022-7bit" iso-2022-7bit)
622 (const :tag "Emacs internal" emacs-mule)
623 (const :tag "escape-quoted" escape-quoted))))
624 (symbol :tag "Coding system")))
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
630 :type 'function)
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
647 LAST-FILE."
648 :group 'gnus-article-saving
649 :type 'function)
651 (defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
654 "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
664 non-nil.
666 If the match is a string, it is used as a regexp match on the
667 article. If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter. If it is a list, it will be evaled in the same buffer.
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674 :group 'gnus-article-saving
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
677 (sexp :value nil))))
679 (defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
683 :type 'regexp
684 :group 'gnus-article-various)
686 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
687 "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
690 The following additional specs are available:
692 %w The article washing status.
693 %m The number of MIME parts in the article."
694 :version "24.1"
695 :type 'string
696 :group 'gnus-article-various)
698 (defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
700 :type 'hook
701 :group 'gnus-article-various)
703 (when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
710 (defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "*A hook called after an article has been prepared in the article buffer."
717 :type 'hook
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
730 (defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748 :type 'face
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
759 '((t
760 (:italic t)))
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
769 '((((class color)
770 (background dark))
771 (:foreground "PaleGreen1"))
772 (((class color)
773 (background light))
774 (:foreground "red3"))
776 (:italic t)))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
785 '((((class color)
786 (background dark))
787 (:foreground "SeaGreen1"))
788 (((class color)
789 (background light))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
801 '((((class color)
802 (background dark))
803 (:foreground "yellow" :italic t))
804 (((class color)
805 (background light))
806 (:foreground "MidnightBlue" :italic t))
808 (:italic t)))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen2"))
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
826 (:bold t)))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
835 '((((class color)
836 (background dark))
837 (:foreground "SpringGreen1" :italic t))
838 (((class color)
839 (background light))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "*Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
878 (png . nil)))
879 "Alist of image types and properties applied to Face and X-Face images.
880 Here are examples:
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs. Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896 :version "23.1" ;; No Gnus
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
900 (defcustom gnus-article-decode-hook
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
905 :type 'hook)
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
910 :type 'function)
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
918 (defvar gnus-article-dumbquotes-map
919 '((?\200 "EUR")
920 (?\202 ",")
921 (?\203 "f")
922 (?\204 ",,")
923 (?\205 "...")
924 (?\213 "<")
925 (?\214 "OE")
926 (?\221 "`")
927 (?\222 "'")
928 (?\223 "``")
929 (?\224 "\"")
930 (?\225 "*")
931 (?\226 "-")
932 (?\227 "--")
933 (?\230 "~")
934 (?\231 "(TM)")
935 (?\233 ">")
936 (?\234 "oe")
937 (?\264 "'"))
938 "Table for MS-to-Latin1 translation.")
940 (defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947 "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :version "21.1"
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
954 (defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include. See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962 :version "22.1"
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
971 :version "22.1"
972 :group 'gnus-article-mime
973 :type 'boolean)
975 (defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
979 :version "22.1"
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
982 string))
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "/usr/share/picons")
986 "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
989 :version "22.1"
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
994 :group 'gnus-picon)
996 (defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1002 installed))
1004 (defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
1009 :type '(choice (const nil)
1010 function))
1012 (defcustom gnus-mime-multipart-functions nil
1013 "An alist of MIME types to functions to display them."
1014 :version "21.1"
1015 :group 'gnus-article-mime
1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1018 (defcustom gnus-article-date-headers '(combined-lapsed)
1019 "A list of Date header formats to display.
1020 Valid formats are `ut' (universal time), `local' (local time
1021 zone), `english' (readable English), `lapsed' (elapsed time),
1022 `combined-lapsed' (both the original date and the elapsed time),
1023 `original' (the original date header), `iso8601' (ISO8601
1024 format), and `user-defined' (a user-defined format defined by the
1025 `gnus-article-time-format' variable).
1027 You have as many date headers as you want in the article buffer.
1028 Some of these headers are updated automatically. See
1029 `gnus-article-update-date-headers' for details."
1030 :version "24.1"
1031 :group 'gnus-article-headers
1032 :type '(repeat
1033 (item :tag "Universal time (UT)" :value 'ut)
1034 (item :tag "Local time zone" :value 'local)
1035 (item :tag "Readable English" :value 'english)
1036 (item :tag "Elapsed time" :value 'lapsed)
1037 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1038 (item :tag "Original date header" :value 'original)
1039 (item :tag "ISO8601 format" :value 'iso8601)
1040 (item :tag "User-defined" :value 'user-defined)))
1042 (defcustom gnus-article-update-date-headers nil
1043 "A number that says how often to update the date header (in seconds).
1044 If nil, don't update it at all."
1045 :version "24.1"
1046 :group 'gnus-article-headers
1047 :type '(choice
1048 (item :tag "Don't update" :value nil)
1049 integer))
1051 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1052 "Function called with a MIME handle as the argument.
1053 This is meant for people who want to view first matched part.
1054 For `undisplayed-alternative' (default), the first undisplayed
1055 part or alternative part is used. For `undisplayed', the first
1056 undisplayed part is used. For a function, the first part which
1057 the function return t is used. For nil, the first part is
1058 used."
1059 :version "21.1"
1060 :group 'gnus-article-mime
1061 :type '(choice
1062 (item :tag "first" :value nil)
1063 (item :tag "undisplayed" :value undisplayed)
1064 (item :tag "undisplayed or alternative"
1065 :value undisplayed-alternative)
1066 (function)))
1068 (defcustom gnus-mime-action-alist
1069 '(("save to file" . gnus-mime-save-part)
1070 ("save and strip" . gnus-mime-save-part-and-strip)
1071 ("replace with file" . gnus-mime-replace-part)
1072 ("delete part" . gnus-mime-delete-part)
1073 ("display as text" . gnus-mime-inline-part)
1074 ("view the part" . gnus-mime-view-part)
1075 ("pipe to command" . gnus-mime-pipe-part)
1076 ("toggle display" . gnus-article-press-button)
1077 ("toggle display" . gnus-article-view-part-as-charset)
1078 ("view as type" . gnus-mime-view-part-as-type)
1079 ("view internally" . gnus-mime-view-part-internally)
1080 ("view externally" . gnus-mime-view-part-externally))
1081 "An alist of actions that run on the MIME attachment."
1082 :group 'gnus-article-mime
1083 :type '(repeat (cons (string :tag "name")
1084 (function))))
1086 (defcustom gnus-auto-select-part 1
1087 "Advance to next MIME part when deleting or stripping parts.
1089 When 0, point will be placed on the same part as before. When
1090 positive (negative), move point forward (backwards) this many
1091 parts. When nil, redisplay article."
1092 :version "23.1" ;; No Gnus
1093 :group 'gnus-article-mime
1094 :type '(choice (const nil :tag "Redisplay article.")
1095 (const 1 :tag "Next part.")
1096 (const 0 :tag "Current part.")
1097 integer))
1100 ;;; The treatment variables
1103 (defvar gnus-part-display-hook nil
1104 "Hook called on parts that are to receive treatment.")
1106 (defvar gnus-article-treat-custom
1107 '(choice (const :tag "Off" nil)
1108 (const :tag "On" t)
1109 (const :tag "Header" head)
1110 (const :tag "First" first)
1111 (const :tag "Last" last)
1112 (integer :tag "Less")
1113 (repeat :tag "Groups" regexp)
1114 (sexp :tag "Predicate")))
1116 (defvar gnus-article-treat-head-custom
1117 '(choice (const :tag "Off" nil)
1118 (const :tag "Header" head)))
1120 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1121 "text/x-patch")
1122 "Parts to treat.")
1124 (defvar gnus-inhibit-treatment nil
1125 "Whether to inhibit treatment.")
1127 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1128 "Highlight the signature.
1129 Valid values are nil, t, `head', `first', `last', an integer or a
1130 predicate. See Info node `(gnus)Customizing Articles'."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-custom)
1134 (put 'gnus-treat-highlight-signature 'highlight t)
1136 (defcustom gnus-treat-buttonize 100000
1137 "Add buttons.
1138 Valid values are nil, t, `head', `first', `last', an integer or a
1139 predicate. See Info node `(gnus)Customizing Articles'."
1140 :group 'gnus-article-treat
1141 :link '(custom-manual "(gnus)Customizing Articles")
1142 :type gnus-article-treat-custom)
1143 (put 'gnus-treat-buttonize 'highlight t)
1145 (defcustom gnus-treat-buttonize-head 'head
1146 "Add buttons to the head.
1147 Valid values are nil, t, `head', `first', `last', an integer or a
1148 predicate. See Info node `(gnus)Customizing Articles'."
1149 :group 'gnus-article-treat
1150 :link '(custom-manual "(gnus)Customizing Articles")
1151 :type gnus-article-treat-head-custom)
1152 (put 'gnus-treat-buttonize-head 'highlight t)
1154 (defcustom gnus-treat-date 'head
1155 "Display dates according to the `gnus-article-date-headers' variable.
1156 Valid values are nil, t, `head', `first', `last', an integer or a
1157 predicate. See Info node `(gnus)Customizing Articles'."
1158 :version "24.1"
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-head-custom)
1163 (defcustom gnus-treat-emphasize 50000
1164 "Emphasize text.
1165 Valid values are nil, t, `head', `first', `last', an integer or a
1166 predicate. See Info node `(gnus)Customizing Articles'."
1167 :group 'gnus-article-treat
1168 :link '(custom-manual "(gnus)Customizing Articles")
1169 :type gnus-article-treat-custom)
1170 (put 'gnus-treat-emphasize 'highlight t)
1172 (defcustom gnus-treat-strip-cr nil
1173 "Remove carriage returns.
1174 Valid values are nil, t, `head', `first', `last', an integer or a
1175 predicate. See Info node `(gnus)Customizing Articles'."
1176 :version "22.1"
1177 :group 'gnus-article-treat
1178 :link '(custom-manual "(gnus)Customizing Articles")
1179 :type gnus-article-treat-custom)
1181 (defcustom gnus-treat-unsplit-urls nil
1182 "Remove newlines from within URLs.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate. See Info node `(gnus)Customizing Articles'."
1185 :version "22.1"
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-leading-whitespace nil
1191 "Remove leading whitespace in headers.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :version "22.1"
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-hide-headers 'head
1200 "Hide headers.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1207 (defcustom gnus-treat-hide-boring-headers nil
1208 "Hide boring headers.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-head-custom)
1215 (defcustom gnus-treat-hide-signature nil
1216 "Hide the signature.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1223 (defcustom gnus-treat-fill-article nil
1224 "Fill the article.
1225 Valid values are nil, t, `head', `first', `last', an integer or a
1226 predicate. See Info node `(gnus)Customizing Articles'."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (defcustom gnus-treat-hide-citation nil
1232 "Hide cited text.
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'.
1236 See `gnus-article-highlight-citation' for variables used to
1237 control what it hides."
1238 :group 'gnus-article-treat
1239 :link '(custom-manual "(gnus)Customizing Articles")
1240 :type gnus-article-treat-custom)
1242 (defcustom gnus-treat-hide-citation-maybe nil
1243 "Hide cited text according to certain conditions.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate. See Info node `(gnus)Customizing Articles'.
1247 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1248 how to control what it hides."
1249 :group 'gnus-article-treat
1250 :link '(custom-manual "(gnus)Customizing Articles")
1251 :type gnus-article-treat-custom)
1253 (defcustom gnus-treat-strip-list-identifiers 'head
1254 "Strip list identifiers from `gnus-list-identifiers`.
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :version "21.1"
1258 :group 'gnus-article-treat
1259 :link '(custom-manual "(gnus)Customizing Articles")
1260 :type gnus-article-treat-custom)
1262 (gnus-define-group-parameter
1263 list-identifier
1264 :variable-document
1265 "Alist of regexps and correspondent identifiers."
1266 :variable-group gnus-article-washing
1267 :parameter-type
1268 '(choice :tag "Identifier"
1269 :value nil
1270 (symbol :tag "Item in `gnus-list-identifiers'" none)
1271 regexp
1272 (const :tag "None" nil))
1273 :parameter-document
1274 "If non-nil, specify how to remove `identifiers' from articles' subject.
1276 Any symbol is used to look up a regular expression to match the
1277 banner in `gnus-list-identifiers'. A string is used as a regular
1278 expression to match the identifier directly.")
1280 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1281 "Gnus 5.10 (Emacs 22.1)")
1283 (defcustom gnus-treat-strip-pem nil
1284 "Strip PEM signatures.
1285 Valid values are nil, t, `head', `first', `last', an integer or a
1286 predicate. See Info node `(gnus)Customizing Articles'."
1287 :group 'gnus-article-treat
1288 :link '(custom-manual "(gnus)Customizing Articles")
1289 :type gnus-article-treat-custom)
1291 (defcustom gnus-treat-strip-banner t
1292 "Strip banners from articles.
1293 The banner to be stripped is specified in the `banner' group parameter.
1294 Valid values are nil, t, `head', `first', `last', an integer or a
1295 predicate. See Info node `(gnus)Customizing Articles'."
1296 :group 'gnus-article-treat
1297 :link '(custom-manual "(gnus)Customizing Articles")
1298 :type gnus-article-treat-custom)
1300 (defcustom gnus-treat-highlight-headers 'head
1301 "Highlight the headers.
1302 Valid values are nil, t, `head', `first', `last', an integer or a
1303 predicate. See Info node `(gnus)Customizing Articles'."
1304 :group 'gnus-article-treat
1305 :link '(custom-manual "(gnus)Customizing Articles")
1306 :type gnus-article-treat-head-custom)
1307 (put 'gnus-treat-highlight-headers 'highlight t)
1309 (defcustom gnus-treat-highlight-citation t
1310 "Highlight cited text.
1311 Valid values are nil, t, `head', `first', `last', an integer or a
1312 predicate. See Info node `(gnus)Customizing Articles'."
1313 :group 'gnus-article-treat
1314 :link '(custom-manual "(gnus)Customizing Articles")
1315 :type gnus-article-treat-custom)
1316 (put 'gnus-treat-highlight-citation 'highlight t)
1318 (defcustom gnus-treat-strip-headers-in-body t
1319 "Strip the X-No-Archive header line from the beginning of the body.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'."
1322 :version "21.1"
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-custom)
1327 (defcustom gnus-treat-strip-trailing-blank-lines nil
1328 "Strip trailing blank lines.
1329 Valid values are nil, t, `head', `first', `last', an integer or a
1330 predicate. See Info node `(gnus)Customizing Articles'.
1332 When set to t, it also strips trailing blanks in all MIME parts.
1333 Consider to use `last' instead."
1334 :group 'gnus-article-treat
1335 :link '(custom-manual "(gnus)Customizing Articles")
1336 :type gnus-article-treat-custom)
1338 (defcustom gnus-treat-strip-leading-blank-lines nil
1339 "Strip leading blank lines.
1340 Valid values are nil, t, `head', `first', `last', an integer or a
1341 predicate. See Info node `(gnus)Customizing Articles'.
1343 When set to t, it also strips trailing blanks in all MIME parts."
1344 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :type gnus-article-treat-custom)
1348 (defcustom gnus-treat-strip-multiple-blank-lines nil
1349 "Strip multiple blank lines.
1350 Valid values are nil, t, `head', `first', `last', an integer or a
1351 predicate. See Info node `(gnus)Customizing Articles'."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1356 (defcustom gnus-treat-unfold-headers 'head
1357 "Unfold folded header lines.
1358 Valid values are nil, t, `head', `first', `last', an integer or a
1359 predicate. See Info node `(gnus)Customizing Articles'."
1360 :version "22.1"
1361 :group 'gnus-article-treat
1362 :link '(custom-manual "(gnus)Customizing Articles")
1363 :type gnus-article-treat-custom)
1365 (defcustom gnus-article-unfold-long-headers nil
1366 "If non-nil, allow unfolding headers even if the header is long.
1367 If it is a regexp, only long headers matching this regexp are unfolded.
1368 If it is t, all long headers are unfolded.
1370 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1371 :version "23.1" ;; No Gnus
1372 :group 'gnus-article-treat
1373 :type '(choice (const nil)
1374 (const :tag "all" t)
1375 (regexp)))
1377 (defcustom gnus-treat-fold-headers nil
1378 "Fold headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate. See Info node `(gnus)Customizing Articles'."
1381 :version "22.1"
1382 :group 'gnus-article-treat
1383 :link '(custom-manual "(gnus)Customizing Articles")
1384 :type gnus-article-treat-custom)
1386 (defcustom gnus-treat-fold-newsgroups 'head
1387 "Fold the Newsgroups and Followup-To headers.
1388 Valid values are nil, t, `head', `first', `last', an integer or a
1389 predicate. See Info node `(gnus)Customizing Articles'."
1390 :version "22.1"
1391 :group 'gnus-article-treat
1392 :link '(custom-manual "(gnus)Customizing Articles")
1393 :type gnus-article-treat-custom)
1395 (defcustom gnus-treat-overstrike t
1396 "Treat overstrike highlighting.
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1399 :group 'gnus-article-treat
1400 :link '(custom-manual "(gnus)Customizing Articles")
1401 :type gnus-article-treat-custom)
1402 (put 'gnus-treat-overstrike 'highlight t)
1404 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1405 "Treat ANSI SGR control sequences.
1406 Valid values are nil, t, `head', `first', `last', an integer or a
1407 predicate. See Info node `(gnus)Customizing Articles'."
1408 :group 'gnus-article-treat
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :type gnus-article-treat-custom)
1412 (make-obsolete-variable 'gnus-treat-display-xface
1413 'gnus-treat-display-x-face "Emacs 22.1")
1415 (defcustom gnus-treat-display-x-face
1416 (and (not noninteractive)
1417 (gnus-image-type-available-p 'xbm)
1418 (if (featurep 'xemacs)
1419 (featurep 'xface)
1420 (condition-case nil
1421 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1422 (executable-find "icontopbm"))
1423 ;; shell-command-to-string may signal an error, e.g. if
1424 ;; shell-file-name is not found.
1425 (error nil)))
1426 'head)
1427 "Display X-Face headers.
1428 Valid values are nil and `head'.
1429 See Info node `(gnus)Customizing Articles' and Info node
1430 `(gnus)X-Face' for details."
1431 :group 'gnus-article-treat
1432 :version "21.1"
1433 :link '(custom-manual "(gnus)Customizing Articles")
1434 :link '(custom-manual "(gnus)X-Face")
1435 :type gnus-article-treat-head-custom
1436 :set (lambda (symbol value)
1437 (set-default
1438 symbol
1439 (cond ((or (boundp symbol) (get symbol 'saved-value))
1440 value)
1441 ((boundp 'gnus-treat-display-xface)
1442 (message "\
1443 ** gnus-treat-display-xface is an obsolete variable;\
1444 use gnus-treat-display-x-face instead")
1445 (default-value 'gnus-treat-display-xface))
1446 ((get 'gnus-treat-display-xface 'saved-value)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1452 value)))))
1453 (put 'gnus-treat-display-x-face 'highlight t)
1455 (defcustom gnus-treat-display-face
1456 (and (not noninteractive)
1457 (gnus-image-type-available-p 'png)
1458 'head)
1459 "Display Face headers.
1460 Valid values are nil, t, `head', `first', `last', an integer or a
1461 predicate. See Info node `(gnus)Customizing Articles' and Info
1462 node `(gnus)Face' for details."
1463 :group 'gnus-article-treat
1464 :version "22.1"
1465 :link '(custom-manual "(gnus)Customizing Articles")
1466 :link '(custom-manual "(gnus)X-Face")
1467 :type gnus-article-treat-head-custom)
1468 (put 'gnus-treat-display-face 'highlight t)
1470 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1471 "Display smileys.
1472 Valid values are nil, t, `head', `first', `last', an integer or a
1473 predicate. See Info node `(gnus)Customizing Articles' and Info
1474 node `(gnus)Smileys' for details."
1475 :group 'gnus-article-treat
1476 :version "21.1"
1477 :link '(custom-manual "(gnus)Customizing Articles")
1478 :link '(custom-manual "(gnus)Smileys")
1479 :type gnus-article-treat-custom)
1480 (put 'gnus-treat-display-smileys 'highlight t)
1482 (defcustom gnus-treat-from-picon
1483 (if (and (gnus-image-type-available-p 'xpm)
1484 (gnus-picons-installed-p))
1485 'head nil)
1486 "Display picons in the From header.
1487 Valid values are nil, t, `head', `first', `last', an integer or a
1488 predicate. See Info node `(gnus)Customizing Articles' and Info
1489 node `(gnus)Picons' for details."
1490 :version "22.1"
1491 :group 'gnus-article-treat
1492 :group 'gnus-picon
1493 :link '(custom-manual "(gnus)Customizing Articles")
1494 :link '(custom-manual "(gnus)Picons")
1495 :type gnus-article-treat-head-custom)
1496 (put 'gnus-treat-from-picon 'highlight t)
1498 (defcustom gnus-treat-mail-picon
1499 (if (and (gnus-image-type-available-p 'xpm)
1500 (gnus-picons-installed-p))
1501 'head nil)
1502 "Display picons in To and Cc headers.
1503 Valid values are nil, t, `head', `first', `last', an integer or a
1504 predicate. See Info node `(gnus)Customizing Articles' and Info
1505 node `(gnus)Picons' for details."
1506 :version "22.1"
1507 :group 'gnus-article-treat
1508 :group 'gnus-picon
1509 :link '(custom-manual "(gnus)Customizing Articles")
1510 :link '(custom-manual "(gnus)Picons")
1511 :type gnus-article-treat-head-custom)
1512 (put 'gnus-treat-mail-picon 'highlight t)
1514 (defcustom gnus-treat-newsgroups-picon
1515 (if (and (gnus-image-type-available-p 'xpm)
1516 (gnus-picons-installed-p))
1517 'head nil)
1518 "Display picons in the Newsgroups and Followup-To headers.
1519 Valid values are nil, t, `head', `first', `last', an integer or a
1520 predicate. See Info node `(gnus)Customizing Articles' and Info
1521 node `(gnus)Picons' for details."
1522 :version "22.1"
1523 :group 'gnus-article-treat
1524 :group 'gnus-picon
1525 :link '(custom-manual "(gnus)Customizing Articles")
1526 :link '(custom-manual "(gnus)Picons")
1527 :type gnus-article-treat-head-custom)
1528 (put 'gnus-treat-newsgroups-picon 'highlight t)
1530 (defcustom gnus-treat-from-gravatar nil
1531 "Display gravatars in the From header.
1532 Valid values are nil, t, `head', `first', `last', an integer or a
1533 predicate. See Info node `(gnus)Customizing Articles' and Info
1534 node `(gnus)Gravatars' for details."
1535 :version "24.1"
1536 :group 'gnus-article-treat
1537 :group 'gnus-gravatar
1538 :link '(custom-manual "(gnus)Customizing Articles")
1539 :link '(custom-manual "(gnus)Gravatars")
1540 :type gnus-article-treat-head-custom)
1541 (put 'gnus-treat-from-gravatar 'highlight t)
1543 (defcustom gnus-treat-mail-gravatar nil
1544 "Display gravatars in To and Cc headers.
1545 Valid values are nil, t, `head', `first', `last', an integer or a
1546 predicate. See Info node `(gnus)Customizing Articles' and Info
1547 node `(gnus)Gravatars' for details."
1548 :version "24.1"
1549 :group 'gnus-article-treat
1550 :group 'gnus-gravatar
1551 :link '(custom-manual "(gnus)Customizing Articles")
1552 :link '(custom-manual "(gnus)Gravatars")
1553 :type gnus-article-treat-head-custom)
1554 (put 'gnus-treat-mail-gravatar 'highlight t)
1556 (defcustom gnus-treat-body-boundary
1557 (if (or gnus-treat-newsgroups-picon
1558 gnus-treat-mail-picon
1559 gnus-treat-from-picon
1560 gnus-treat-from-gravatar
1561 gnus-treat-mail-gravatar)
1562 ;; If there's much decoration, the user might prefer a boundary.
1563 'head
1564 nil)
1565 "Draw a boundary at the end of the headers.
1566 Valid values are nil and `head'.
1567 See Info node `(gnus)Customizing Articles' for details."
1568 :version "22.1"
1569 :group 'gnus-article-treat
1570 :link '(custom-manual "(gnus)Customizing Articles")
1571 :type gnus-article-treat-head-custom)
1573 (defcustom gnus-treat-capitalize-sentences nil
1574 "Capitalize sentence-starting words.
1575 Valid values are nil, t, `head', `first', `last', an integer or a
1576 predicate. See Info node `(gnus)Customizing Articles'."
1577 :version "21.1"
1578 :group 'gnus-article-treat
1579 :link '(custom-manual "(gnus)Customizing Articles")
1580 :type gnus-article-treat-custom)
1582 (defcustom gnus-treat-wash-html nil
1583 "Format as HTML.
1584 Valid values are nil, t, `head', `first', `last', an integer or a
1585 predicate. See Info node `(gnus)Customizing Articles'."
1586 :version "22.1"
1587 :group 'gnus-article-treat
1588 :link '(custom-manual "(gnus)Customizing Articles")
1589 :type gnus-article-treat-custom)
1591 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1592 "Fill long lines.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1595 :version "24.1"
1596 :group 'gnus-article-treat
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1600 (defcustom gnus-treat-x-pgp-sig nil
1601 "Verify X-PGP-Sig.
1602 To automatically treat X-PGP-Sig, set it to head.
1603 Valid values are nil, t, `head', `first', `last', an integer or a
1604 predicate. See Info node `(gnus)Customizing Articles'."
1605 :version "22.1"
1606 :group 'gnus-article-treat
1607 :group 'mime-security
1608 :link '(custom-manual "(gnus)Customizing Articles")
1609 :type gnus-article-treat-custom)
1611 (defvar gnus-article-encrypt-protocol-alist
1612 '(("PGP" . mml2015-self-encrypt)))
1614 ;; Set to nil if more than one protocol added to
1615 ;; gnus-article-encrypt-protocol-alist.
1616 (defcustom gnus-article-encrypt-protocol "PGP"
1617 "The protocol used for encrypt articles.
1618 It is a string, such as \"PGP\". If nil, ask user."
1619 :version "22.1"
1620 :type 'string
1621 :group 'mime-security)
1623 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1624 (mm-coding-system-p 'utf-8)
1625 (executable-find idna-program))
1626 "Whether IDNA decoding of headers is used when viewing messages.
1627 This requires GNU Libidn, and by default only enabled if it is found."
1628 :version "22.1"
1629 :group 'gnus-article-headers
1630 :type 'boolean)
1632 (defcustom gnus-article-over-scroll nil
1633 "If non-nil, allow scrolling the article buffer even when there no more text."
1634 :version "22.1"
1635 :group 'gnus-article
1636 :type 'boolean)
1638 (defcustom gnus-inhibit-images nil
1639 "Non-nil means inhibit displaying of images inline in the article body."
1640 :version "24.1"
1641 :group 'gnus-article
1642 :type 'boolean)
1644 (defcustom gnus-blocked-images 'gnus-block-private-groups
1645 "Images that have URLs matching this regexp will be blocked.
1646 This can also be a function to be evaluated. If so, it will be
1647 called with the group name as the parameter, and should return a
1648 regexp."
1649 :version "24.1"
1650 :group 'gnus-art
1651 :type 'regexp)
1653 ;;; Internal variables
1655 (defvar gnus-english-month-names
1656 '("January" "February" "March" "April" "May" "June" "July" "August"
1657 "September" "October" "November" "December"))
1659 (defvar article-goto-body-goes-to-point-min-p nil)
1660 (defvar gnus-article-wash-types nil)
1661 (defvar gnus-article-emphasis-alist nil)
1662 (defvar gnus-article-image-alist nil)
1664 (defvar gnus-article-mime-handle-alist-1 nil)
1665 (defvar gnus-treatment-function-alist
1666 '((gnus-treat-strip-cr gnus-article-remove-cr)
1667 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1668 (gnus-treat-strip-banner gnus-article-strip-banner)
1669 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1670 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1671 (gnus-treat-buttonize gnus-article-add-buttons)
1672 (gnus-treat-fill-article gnus-article-fill-cited-article)
1673 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1674 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1675 (gnus-treat-display-x-face gnus-article-display-x-face)
1676 (gnus-treat-display-face gnus-article-display-face)
1677 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1678 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1679 (gnus-treat-hide-signature gnus-article-hide-signature)
1680 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1681 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1682 (gnus-treat-from-picon gnus-treat-from-picon)
1683 (gnus-treat-mail-picon gnus-treat-mail-picon)
1684 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1685 (gnus-treat-strip-pem gnus-article-hide-pem)
1686 (gnus-treat-date gnus-article-treat-date)
1687 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1688 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1689 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1690 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1691 (gnus-treat-strip-trailing-blank-lines
1692 gnus-article-remove-trailing-blank-lines)
1693 (gnus-treat-strip-leading-blank-lines
1694 gnus-article-strip-leading-blank-lines)
1695 (gnus-treat-strip-multiple-blank-lines
1696 gnus-article-strip-multiple-blank-lines)
1697 (gnus-treat-overstrike gnus-article-treat-overstrike)
1698 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1699 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1700 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1701 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1702 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1703 (gnus-treat-display-smileys gnus-treat-smiley)
1704 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1705 (gnus-treat-wash-html gnus-article-wash-html)
1706 (gnus-treat-emphasize gnus-article-emphasize)
1707 (gnus-treat-hide-citation gnus-article-hide-citation)
1708 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1709 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1710 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1712 (defvar gnus-article-mime-handle-alist nil)
1713 (defvar article-lapsed-timer nil)
1714 (defvar gnus-article-current-summary nil)
1716 (defvar gnus-article-mode-syntax-table
1717 (let ((table (copy-syntax-table text-mode-syntax-table)))
1718 ;; This causes the citation match run O(2^n).
1719 ;; (modify-syntax-entry ?- "w" table)
1720 (modify-syntax-entry ?> ")<" table)
1721 (modify-syntax-entry ?< "(>" table)
1722 ;; make M-. in article buffers work for `foo' strings
1723 (modify-syntax-entry ?' " " table)
1724 (modify-syntax-entry ?` " " table)
1725 table)
1726 "Syntax table used in article mode buffers.
1727 Initialized from `text-mode-syntax-table.")
1729 (defvar gnus-save-article-buffer nil)
1731 (defvar gnus-number-of-articles-to-be-saved nil)
1733 (defvar gnus-inhibit-hiding nil)
1735 (defvar gnus-article-edit-mode nil)
1737 ;;; Macros for dealing with the article buffer.
1739 (defmacro gnus-with-article-headers (&rest forms)
1740 `(with-current-buffer gnus-article-buffer
1741 (save-restriction
1742 (let ((inhibit-read-only t)
1743 (inhibit-point-motion-hooks t)
1744 (case-fold-search t))
1745 (article-narrow-to-head)
1746 ,@forms))))
1748 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1749 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1751 (defmacro gnus-with-article-buffer (&rest forms)
1752 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1753 (with-current-buffer gnus-article-buffer
1754 (let ((inhibit-read-only t))
1755 ,@forms))))
1757 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1758 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1760 (defun gnus-article-goto-header (header)
1761 "Go to HEADER, which is a regular expression."
1762 (re-search-forward (concat "^\\(" header "\\):") nil t))
1764 (defsubst gnus-article-hide-text (b e props)
1765 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1766 (gnus-add-text-properties-when 'article-type nil b e props)
1767 (when (memq 'intangible props)
1768 (put-text-property
1769 (max (1- b) (point-min))
1770 b 'intangible (cddr (memq 'intangible props)))))
1772 (defsubst gnus-article-unhide-text (b e)
1773 "Remove hidden text properties from region between B and E."
1774 (remove-text-properties b e gnus-hidden-properties)
1775 (when (memq 'intangible gnus-hidden-properties)
1776 (put-text-property (max (1- b) (point-min))
1777 b 'intangible nil)))
1779 (defun gnus-article-hide-text-type (b e type)
1780 "Hide text of TYPE between B and E."
1781 (gnus-add-wash-type type)
1782 (gnus-article-hide-text
1783 b e (cons 'article-type (cons type gnus-hidden-properties))))
1785 (defun gnus-article-unhide-text-type (b e type)
1786 "Unhide text of TYPE between B and E."
1787 (gnus-delete-wash-type type)
1788 (remove-text-properties
1789 b e (cons 'article-type (cons type gnus-hidden-properties)))
1790 (when (memq 'intangible gnus-hidden-properties)
1791 (put-text-property (max (1- b) (point-min))
1792 b 'intangible nil)))
1794 (defun gnus-article-hide-text-of-type (type)
1795 "Hide text of TYPE in the current buffer."
1796 (save-excursion
1797 (let ((b (point-min))
1798 (e (point-max)))
1799 (while (setq b (text-property-any b e 'article-type type))
1800 (add-text-properties b (incf b) gnus-hidden-properties)))))
1802 (defun gnus-article-delete-text-of-type (type)
1803 "Delete text of TYPE in the current buffer."
1804 (save-excursion
1805 (let ((b (point-min)))
1806 (if (eq type 'multipart)
1807 ;; Remove MIME buttons associated with multipart/alternative parts.
1808 (progn
1809 (goto-char b)
1810 (while (if (get-text-property (point) 'gnus-part)
1811 (setq b (point))
1812 (when (setq b (next-single-property-change (point)
1813 'gnus-part))
1814 (goto-char b)
1816 (end-of-line)
1817 (skip-chars-forward "\n")
1818 (when (eq (get-text-property b 'article-type) 'multipart)
1819 (delete-region b (point)))))
1820 (while (setq b (text-property-any b (point-max) 'article-type type))
1821 (delete-region
1822 b (or (text-property-not-all b (point-max) 'article-type type)
1823 (point-max))))))))
1825 (defun gnus-article-delete-invisible-text ()
1826 "Delete all invisible text in the current buffer."
1827 (save-excursion
1828 (let ((b (point-min)))
1829 (while (setq b (text-property-any b (point-max) 'invisible t))
1830 (delete-region
1831 b (or (text-property-not-all b (point-max) 'invisible t)
1832 (point-max)))))))
1834 (defun gnus-article-text-type-exists-p (type)
1835 "Say whether any text of type TYPE exists in the buffer."
1836 (text-property-any (point-min) (point-max) 'article-type type))
1838 (defsubst gnus-article-header-rank ()
1839 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1840 (let ((list gnus-sorted-header-list)
1841 (i 1))
1842 (while list
1843 (if (looking-at (car list))
1844 (setq list nil)
1845 (setq list (cdr list))
1846 (incf i)))
1849 (defun article-hide-headers (&optional arg delete)
1850 "Hide unwanted headers and possibly sort them as well."
1851 (interactive)
1852 ;; This function might be inhibited.
1853 (unless gnus-inhibit-hiding
1854 (let ((inhibit-read-only t)
1855 (case-fold-search t)
1856 (max (1+ (length gnus-sorted-header-list)))
1857 (inhibit-point-motion-hooks t)
1858 (cur (current-buffer))
1859 ignored visible beg)
1860 (save-excursion
1861 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1862 ;; group parameters, so we should go to the summary buffer.
1863 (when (prog1
1864 (condition-case nil
1865 (progn (set-buffer gnus-summary-buffer) t)
1866 (error nil))
1867 (setq ignored (when (not gnus-visible-headers)
1868 (cond ((stringp gnus-ignored-headers)
1869 gnus-ignored-headers)
1870 ((listp gnus-ignored-headers)
1871 (mapconcat 'identity
1872 gnus-ignored-headers
1873 "\\|"))))
1874 visible (cond ((stringp gnus-visible-headers)
1875 gnus-visible-headers)
1876 ((and gnus-visible-headers
1877 (listp gnus-visible-headers))
1878 (mapconcat 'identity
1879 gnus-visible-headers
1880 "\\|")))))
1881 (set-buffer cur))
1882 (save-restriction
1883 ;; First we narrow to just the headers.
1884 (article-narrow-to-head)
1885 ;; Hide any "From " lines at the beginning of (mail) articles.
1886 (while (looking-at "From ")
1887 (forward-line 1))
1888 (unless (bobp)
1889 (delete-region (point-min) (point)))
1890 ;; Then treat the rest of the header lines.
1891 ;; Then we use the two regular expressions
1892 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1893 ;; select which header lines is to remain visible in the
1894 ;; article buffer.
1895 (while (re-search-forward "^[^ \t:]*:" nil t)
1896 (beginning-of-line)
1897 ;; Mark the rank of the header.
1898 (put-text-property
1899 (point) (1+ (point)) 'message-rank
1900 (if (or (and visible (looking-at visible))
1901 (and ignored
1902 (not (looking-at ignored))))
1903 (gnus-article-header-rank)
1904 (+ 2 max)))
1905 (forward-line 1))
1906 (message-sort-headers-1)
1907 (when (setq beg (text-property-any
1908 (point-min) (point-max) 'message-rank (+ 2 max)))
1909 ;; We delete the unwanted headers.
1910 (gnus-add-wash-type 'headers)
1911 (add-text-properties (point-min) (+ 5 (point-min))
1912 '(article-type headers dummy-invisible t))
1913 (delete-region beg (point-max))))))))
1915 (defun article-hide-boring-headers (&optional arg)
1916 "Toggle hiding of headers that aren't very interesting.
1917 If given a negative prefix, always show; if given a positive prefix,
1918 always hide."
1919 (interactive (gnus-article-hidden-arg))
1920 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1921 (not gnus-show-all-headers))
1922 (save-excursion
1923 (save-restriction
1924 (let ((inhibit-read-only t)
1925 (inhibit-point-motion-hooks t))
1926 (article-narrow-to-head)
1927 (dolist (elem gnus-boring-article-headers)
1928 (goto-char (point-min))
1929 (cond
1930 ;; Hide empty headers.
1931 ((eq elem 'empty)
1932 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1933 (forward-line -1)
1934 (gnus-article-hide-text-type
1935 (point-at-bol)
1936 (progn
1937 (end-of-line)
1938 (if (re-search-forward "^[^ \t]" nil t)
1939 (match-beginning 0)
1940 (point-max)))
1941 'boring-headers)))
1942 ;; Hide boring Newsgroups header.
1943 ((eq elem 'newsgroups)
1944 (when (gnus-string-equal
1945 (gnus-fetch-field "newsgroups")
1946 (gnus-group-real-name
1947 (if (boundp 'gnus-newsgroup-name)
1948 gnus-newsgroup-name
1949 "")))
1950 (gnus-article-hide-header "newsgroups")))
1951 ((eq elem 'to-address)
1952 (let ((to (message-fetch-field "to"))
1953 (to-address
1954 (gnus-parameter-to-address
1955 (if (boundp 'gnus-newsgroup-name)
1956 gnus-newsgroup-name ""))))
1957 (when (and to to-address
1958 (ignore-errors
1959 (gnus-string-equal
1960 ;; only one address in To
1961 (nth 1 (mail-extract-address-components to))
1962 to-address)))
1963 (gnus-article-hide-header "to"))))
1964 ((eq elem 'to-list)
1965 (let ((to (message-fetch-field "to"))
1966 (to-list
1967 (gnus-parameter-to-list
1968 (if (boundp 'gnus-newsgroup-name)
1969 gnus-newsgroup-name ""))))
1970 (when (and to to-list
1971 (ignore-errors
1972 (gnus-string-equal
1973 ;; only one address in To
1974 (nth 1 (mail-extract-address-components to))
1975 to-list)))
1976 (gnus-article-hide-header "to"))))
1977 ((eq elem 'cc-list)
1978 (let ((cc (message-fetch-field "cc"))
1979 (to-list
1980 (gnus-parameter-to-list
1981 (if (boundp 'gnus-newsgroup-name)
1982 gnus-newsgroup-name ""))))
1983 (when (and cc to-list
1984 (ignore-errors
1985 (gnus-string-equal
1986 ;; only one address in CC
1987 (nth 1 (mail-extract-address-components cc))
1988 to-list)))
1989 (gnus-article-hide-header "cc"))))
1990 ((eq elem 'followup-to)
1991 (when (gnus-string-equal
1992 (message-fetch-field "followup-to")
1993 (message-fetch-field "newsgroups"))
1994 (gnus-article-hide-header "followup-to")))
1995 ((eq elem 'reply-to)
1996 (if (gnus-group-find-parameter
1997 gnus-newsgroup-name 'broken-reply-to)
1998 (gnus-article-hide-header "reply-to")
1999 (let ((from (message-fetch-field "from"))
2000 (reply-to (message-fetch-field "reply-to")))
2001 (when
2002 (and
2003 from reply-to
2004 (ignore-errors
2005 (equal
2006 (sort (mapcar
2007 (lambda (x) (downcase (cadr x)))
2008 (mail-extract-address-components from t))
2009 'string<)
2010 (sort (mapcar
2011 (lambda (x) (downcase (cadr x)))
2012 (mail-extract-address-components reply-to t))
2013 'string<))))
2014 (gnus-article-hide-header "reply-to")))))
2015 ((eq elem 'date)
2016 (let ((date (with-current-buffer gnus-original-article-buffer
2017 ;; If date in `gnus-article-buffer' is localized
2018 ;; (`gnus-treat-date-user-defined'),
2019 ;; `days-between' might fail.
2020 (message-fetch-field "date"))))
2021 (when (and date
2022 (< (days-between (current-time-string) date)
2024 (gnus-article-hide-header "date"))))
2025 ((eq elem 'long-to)
2026 (let ((to (message-fetch-field "to"))
2027 (cc (message-fetch-field "cc")))
2028 (when (> (length to) 1024)
2029 (gnus-article-hide-header "to"))
2030 (when (> (length cc) 1024)
2031 (gnus-article-hide-header "cc"))))
2032 ((eq elem 'many-to)
2033 (let ((to-count 0)
2034 (cc-count 0))
2035 (goto-char (point-min))
2036 (while (re-search-forward "^to:" nil t)
2037 (setq to-count (1+ to-count)))
2038 (when (> to-count 1)
2039 (while (> to-count 0)
2040 (goto-char (point-min))
2041 (save-restriction
2042 (re-search-forward "^to:" nil nil to-count)
2043 (forward-line -1)
2044 (narrow-to-region (point) (point-max))
2045 (gnus-article-hide-header "to"))
2046 (setq to-count (1- to-count))))
2047 (goto-char (point-min))
2048 (while (re-search-forward "^cc:" nil t)
2049 (setq cc-count (1+ cc-count)))
2050 (when (> cc-count 1)
2051 (while (> cc-count 0)
2052 (goto-char (point-min))
2053 (save-restriction
2054 (re-search-forward "^cc:" nil nil cc-count)
2055 (forward-line -1)
2056 (narrow-to-region (point) (point-max))
2057 (gnus-article-hide-header "cc"))
2058 (setq cc-count (1- cc-count)))))))))))))
2060 (defun gnus-article-hide-header (header)
2061 (save-excursion
2062 (goto-char (point-min))
2063 (when (re-search-forward (concat "^" header ":") nil t)
2064 (gnus-article-hide-text-type
2065 (point-at-bol)
2066 (progn
2067 (end-of-line)
2068 (if (re-search-forward "^[^ \t]" nil t)
2069 (match-beginning 0)
2070 (point-max)))
2071 'boring-headers))))
2073 (defvar gnus-article-normalized-header-length 40
2074 "Length of normalized headers.")
2076 (defun article-normalize-headers ()
2077 "Make all header lines 40 characters long."
2078 (interactive)
2079 (let ((inhibit-read-only t)
2080 column)
2081 (save-excursion
2082 (save-restriction
2083 (article-narrow-to-head)
2084 (while (not (eobp))
2085 (cond
2086 ((< (setq column (- (point-at-eol) (point)))
2087 gnus-article-normalized-header-length)
2088 (end-of-line)
2089 (insert (make-string
2090 (- gnus-article-normalized-header-length column)
2091 ? )))
2092 ((> column gnus-article-normalized-header-length)
2093 (gnus-put-text-property
2094 (progn
2095 (forward-char gnus-article-normalized-header-length)
2096 (point))
2097 (point-at-eol)
2098 'invisible t))
2100 ;; Do nothing.
2102 (forward-line 1))))))
2104 (defun article-treat-dumbquotes ()
2105 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2106 Note that this function guesses whether a character is a sm*rtq**t* or
2107 not, so it should only be used interactively.
2109 Sm*rtq**t*s are M****s***'s unilateral extension to the
2110 iso-8859-1 character map in an attempt to provide more quoting
2111 characters. If you see something like \\222 or \\264 where
2112 you're expecting some kind of apostrophe or quotation mark, then
2113 try this wash."
2114 (interactive)
2115 (article-translate-strings gnus-article-dumbquotes-map))
2117 (defvar org-entities)
2119 (defun article-treat-non-ascii ()
2120 "Translate many Unicode characters into their ASCII equivalents."
2121 (interactive)
2122 (require 'org-entities)
2123 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2124 (dolist (elem org-entities)
2125 (when (and (listp elem)
2126 (= (length (nth 6 elem)) 1))
2127 (if (featurep 'xemacs)
2128 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2129 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2130 (save-excursion
2131 (when (article-goto-body)
2132 (let ((inhibit-read-only t)
2133 replace props)
2134 (while (not (eobp))
2135 (if (not (setq replace (if (featurep 'xemacs)
2136 (get-char-table (following-char) table)
2137 (aref table (following-char)))))
2138 (forward-char 1)
2139 (if (prog1
2140 (setq props (text-properties-at (point)))
2141 (delete-char 1))
2142 (add-text-properties (point) (progn (insert replace) (point))
2143 props)
2144 (insert replace)))))))))
2146 (defun article-translate-characters (from to)
2147 "Translate all characters in the body of the article according to FROM and TO.
2148 FROM is a string of characters to translate from; to is a string of
2149 characters to translate to."
2150 (save-excursion
2151 (when (article-goto-body)
2152 (let ((inhibit-read-only t)
2153 (x (make-string 225 ?x))
2154 (i -1))
2155 (while (< (incf i) (length x))
2156 (aset x i i))
2157 (setq i 0)
2158 (while (< i (length from))
2159 (aset x (aref from i) (aref to i))
2160 (incf i))
2161 (translate-region (point) (point-max) x)))))
2163 (defun article-translate-strings (map)
2164 "Translate all string in the body of the article according to MAP.
2165 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2166 (save-excursion
2167 (when (article-goto-body)
2168 (let ((inhibit-read-only t))
2169 (dolist (elem map)
2170 (let ((from (car elem))
2171 (to (cadr elem)))
2172 (save-excursion
2173 (if (stringp from)
2174 (while (search-forward from nil t)
2175 (replace-match to))
2176 (while (not (eobp))
2177 (if (eq (following-char) from)
2178 (progn
2179 (delete-char 1)
2180 (insert to))
2181 (forward-char 1)))))))))))
2183 (defun article-treat-overstrike ()
2184 "Translate overstrikes into bold text."
2185 (interactive)
2186 (save-excursion
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (while (search-forward "\b" nil t)
2190 (let ((next (char-after))
2191 (previous (char-after (- (point) 2))))
2192 ;; We do the boldification/underlining by hiding the
2193 ;; overstrikes and putting the proper text property
2194 ;; on the letters.
2195 (cond
2196 ((eq next previous)
2197 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2198 (put-text-property (point) (1+ (point)) 'face 'bold))
2199 ((eq next ?_)
2200 (gnus-article-hide-text-type
2201 (1- (point)) (1+ (point)) 'overstrike)
2202 (put-text-property
2203 (- (point) 2) (1- (point)) 'face 'underline))
2204 ((eq previous ?_)
2205 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2206 (put-text-property
2207 (point) (1+ (point)) 'face 'underline)))))))))
2209 (defun article-treat-ansi-sequences ()
2210 "Translate ANSI SGR control sequences into overlays or extents."
2211 (interactive)
2212 (save-excursion
2213 (when (article-goto-body)
2214 (let ((inhibit-read-only t))
2215 (ansi-color-apply-on-region (point) (point-max))))))
2217 (defun gnus-article-treat-unfold-headers ()
2218 "Unfold folded message headers.
2219 Only the headers that fit into the current window width will be
2220 unfolded."
2221 (interactive)
2222 (gnus-with-article-headers
2223 (let (length)
2224 (while (not (eobp))
2225 (save-restriction
2226 (mail-header-narrow-to-field)
2227 (let* ((header (buffer-string))
2228 (unfoldable
2229 (or (equal gnus-article-unfold-long-headers t)
2230 (and (stringp gnus-article-unfold-long-headers)
2231 (string-match gnus-article-unfold-long-headers header)))))
2232 (with-temp-buffer
2233 (insert header)
2234 (goto-char (point-min))
2235 (while (re-search-forward "\n[\t ]" nil t)
2236 (replace-match " " t t)))
2237 (setq length (- (point-max) (point-min) 1))
2238 (when (or unfoldable
2239 (< length (window-width)))
2240 (while (re-search-forward "\n[\t ]" nil t)
2241 (replace-match " " t t))))
2242 (goto-char (point-max)))))))
2244 (defun gnus-article-treat-fold-headers ()
2245 "Fold message headers."
2246 (interactive)
2247 (gnus-with-article-headers
2248 (while (not (eobp))
2249 (save-restriction
2250 (mail-header-narrow-to-field)
2251 (mail-header-fold-field)
2252 (goto-char (point-max))))))
2254 (defun gnus-treat-smiley ()
2255 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2256 (interactive)
2257 (gnus-with-article-buffer
2258 (if (memq 'smiley gnus-article-wash-types)
2259 (gnus-delete-images 'smiley)
2260 (article-goto-body)
2261 (let ((images (smiley-region (point) (point-max))))
2262 (when images
2263 (gnus-add-wash-type 'smiley)
2264 (dolist (image images)
2265 (gnus-add-image 'smiley image)))))))
2267 (defun gnus-article-remove-images ()
2268 "Remove all images from the article buffer."
2269 (interactive)
2270 (gnus-with-article-buffer
2271 (save-restriction
2272 (widen)
2273 (dolist (elem gnus-article-image-alist)
2274 (gnus-delete-images (car elem))))))
2276 (autoload 'w3m-toggle-inline-images "w3m")
2278 (defun gnus-article-show-images ()
2279 "Show any images that are in the HTML-rendered article buffer.
2280 This only works if the article in question is HTML."
2281 (interactive)
2282 (gnus-with-article-buffer
2283 (save-restriction
2284 (widen)
2285 (if (eq mm-text-html-renderer 'w3m)
2286 (let ((mm-inline-text-html-with-images nil))
2287 (w3m-toggle-inline-images))
2288 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2289 'image-displayer))
2290 (destructuring-bind (start end function) region
2291 (funcall function (get-text-property start 'image-url)
2292 start end)))))))
2294 (defun gnus-article-treat-fold-newsgroups ()
2295 "Unfold folded message headers.
2296 Only the headers that fit into the current window width will be
2297 unfolded."
2298 (interactive)
2299 (gnus-with-article-headers
2300 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2301 (save-restriction
2302 (mail-header-narrow-to-field)
2303 (while (re-search-forward ", *" nil t)
2304 (replace-match ", " t t))
2305 (mail-header-fold-field)
2306 (goto-char (point-max))))))
2308 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2309 "Value of `truncate-lines' in Gnus Article buffer.
2310 Valid values are nil, t, `head', `first', `last', an integer or a
2311 predicate. See Info node `(gnus)Customizing Articles'."
2312 :version "23.1" ;; No Gnus
2313 :group 'gnus-article
2314 ;; :link '(custom-manual "(gnus)Customizing Articles")
2315 :type 'boolean)
2317 (defun gnus-article-toggle-truncate-lines (&optional arg)
2318 "Toggle whether to fold or truncate long lines in article the buffer.
2319 If ARG is non-nil and not a number, toggle
2320 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2321 long lines if and only if arg is positive."
2322 (interactive "P")
2323 (cond
2324 ((and (numberp arg) (> arg 0))
2325 (setq gnus-article-truncate-lines t))
2326 ((numberp arg)
2327 (setq gnus-article-truncate-lines nil))
2328 (arg
2329 (setq gnus-article-truncate-lines
2330 (not gnus-article-truncate-lines))))
2331 (gnus-with-article-buffer
2332 (cond
2333 ((and (numberp arg) (> arg 0))
2334 (setq truncate-lines nil))
2335 ((numberp arg)
2336 (setq truncate-lines t)))
2337 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2338 ;; `toggle-truncate-lines' needs an argument.
2339 (toggle-truncate-lines)))
2341 (defun gnus-article-treat-body-boundary ()
2342 "Place a boundary line at the end of the headers."
2343 (interactive)
2344 (when (and gnus-body-boundary-delimiter
2345 (> (length gnus-body-boundary-delimiter) 0))
2346 (gnus-with-article-headers
2347 (goto-char (point-max))
2348 (let ((start (point)))
2349 (insert "X-Boundary: ")
2350 (gnus-add-text-properties start (point) '(invisible t intangible t))
2351 (insert (let (str (max (window-width)))
2352 (if (featurep 'xemacs)
2353 (setq max (1- max)))
2354 (while (>= max (length str))
2355 (setq str (concat str gnus-body-boundary-delimiter)))
2356 (substring str 0 max))
2357 "\n")
2358 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2360 (defun article-fill-long-lines ()
2361 "Fill lines that are wider than the window width."
2362 (interactive)
2363 (save-excursion
2364 (let ((inhibit-read-only t)
2365 (width (window-width (get-buffer-window (current-buffer)))))
2366 (save-restriction
2367 (article-goto-body)
2368 (let ((adaptive-fill-mode nil)) ;Why? -sm
2369 (while (not (eobp))
2370 (end-of-line)
2371 (when (>= (current-column) (min fill-column width))
2372 (narrow-to-region (min (1+ (point)) (point-max))
2373 (point-at-bol))
2374 (let ((goback (point-marker)))
2375 (fill-paragraph nil)
2376 (goto-char (marker-position goback)))
2377 (widen))
2378 (forward-line 1)))))))
2380 (defun article-capitalize-sentences ()
2381 "Capitalize the first word in each sentence."
2382 (interactive)
2383 (save-excursion
2384 (let ((inhibit-read-only t)
2385 (paragraph-start "^[\n\^L]"))
2386 (article-goto-body)
2387 (while (not (eobp))
2388 (capitalize-word 1)
2389 (forward-sentence)))))
2391 (defun article-remove-cr ()
2392 "Remove trailing CRs and then translate remaining CRs into LFs."
2393 (interactive)
2394 (save-excursion
2395 (let ((inhibit-read-only t))
2396 (goto-char (point-min))
2397 (while (re-search-forward "\r+$" nil t)
2398 (replace-match "" t t))
2399 (goto-char (point-min))
2400 (while (search-forward "\r" nil t)
2401 (replace-match "\n" t t)))))
2403 (defun article-remove-trailing-blank-lines ()
2404 "Remove all trailing blank lines from the article."
2405 (interactive)
2406 (save-excursion
2407 (let ((inhibit-read-only t))
2408 (goto-char (point-max))
2409 (delete-region
2410 (point)
2411 (progn
2412 (while (and (not (bobp))
2413 (looking-at "^[ \t]*$")
2414 (not (gnus-annotation-in-region-p
2415 (point) (point-at-eol))))
2416 (forward-line -1))
2417 (forward-line 1)
2418 (point))))))
2420 (defvar gnus-face-properties-alist)
2422 (defun article-display-face (&optional force)
2423 "Display any Face headers in the header."
2424 (interactive (list 'force))
2425 (let ((wash-face-p buffer-read-only))
2426 (gnus-with-article-headers
2427 ;; When displaying parts, this function can be called several times on
2428 ;; the same article, without any intended toggle semantic (as typing `W
2429 ;; D d' would have). So face deletion must occur only when we come from
2430 ;; an interactive command, that is when the *Article* buffer is
2431 ;; read-only.
2432 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2433 (gnus-delete-images 'face)
2434 (let ((from (message-fetch-field "from"))
2435 face faces)
2436 (save-current-buffer
2437 (when (and wash-face-p
2438 (gnus-buffer-live-p gnus-original-article-buffer)
2439 (not (re-search-forward "^Face:[\t ]*" nil t)))
2440 (set-buffer gnus-original-article-buffer))
2441 (save-restriction
2442 (mail-narrow-to-head)
2443 (when (or force
2444 ;; Check whether this face is censored.
2445 (not (and gnus-article-x-face-too-ugly
2446 (or from
2447 (setq from (message-fetch-field "from")))
2448 (string-match gnus-article-x-face-too-ugly
2449 from))))
2450 (while (gnus-article-goto-header "Face")
2451 (push (mail-header-field-value) faces)))))
2452 (when faces
2453 (goto-char (point-min))
2454 (let (png image)
2455 (unless (setq from (gnus-article-goto-header "from"))
2456 (insert "From:")
2457 (setq from (point))
2458 (insert " [no `from' set]\n"))
2459 (while faces
2460 (when (setq png (gnus-convert-face-to-png (pop faces)))
2461 (setq image
2462 (apply 'gnus-create-image png 'png t
2463 (cdr (assq 'png gnus-face-properties-alist))))
2464 (goto-char from)
2465 (gnus-add-wash-type 'face)
2466 (gnus-add-image 'face image)
2467 (gnus-put-image image nil 'face))))))))))
2469 (defun article-display-x-face (&optional force)
2470 "Look for an X-Face header and display it if present."
2471 (interactive (list 'force))
2472 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2473 (gnus-with-article-headers
2474 ;; Delete the old process, if any.
2475 (when (process-status "article-x-face")
2476 (delete-process "article-x-face"))
2477 ;; See the comment in `article-display-face'.
2478 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2479 ;; We have already displayed X-Faces, so we remove them
2480 ;; instead.
2481 (gnus-delete-images 'xface)
2482 ;; Display X-Faces.
2483 (let ((from (message-fetch-field "from"))
2484 x-faces face)
2485 (save-current-buffer
2486 (when (and wash-face-p
2487 (gnus-buffer-live-p gnus-original-article-buffer)
2488 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2489 ;; If type `W f', use gnus-original-article-buffer,
2490 ;; otherwise use the current buffer because displaying
2491 ;; RFC822 parts calls this function too.
2492 (set-buffer gnus-original-article-buffer))
2493 (save-restriction
2494 (mail-narrow-to-head)
2495 (and gnus-article-x-face-command
2496 (or force
2497 ;; Check whether this face is censored.
2498 (not (and gnus-article-x-face-too-ugly
2499 (or from
2500 (setq from (message-fetch-field "from")))
2501 (string-match gnus-article-x-face-too-ugly
2502 from))))
2503 (while (gnus-article-goto-header "X-Face")
2504 (push (mail-header-field-value) x-faces)))))
2505 (when x-faces
2506 ;; We display the face.
2507 (cond ((functionp gnus-article-x-face-command)
2508 ;; The command is a lisp function, so we call it.
2509 (mapc gnus-article-x-face-command x-faces))
2510 ((stringp gnus-article-x-face-command)
2511 ;; The command is a string, so we interpret the command
2512 ;; as a, well, command, and fork it off.
2513 (let ((process-connection-type nil))
2514 (gnus-set-process-query-on-exit-flag
2515 (start-process
2516 "article-x-face" nil shell-file-name
2517 shell-command-switch gnus-article-x-face-command)
2518 nil)
2519 ;; Sending multiple EOFs to xv doesn't work,
2520 ;; so we only do a single external face.
2521 (with-temp-buffer
2522 (insert (car x-faces))
2523 (process-send-region "article-x-face"
2524 (point-min) (point-max)))
2525 (process-send-eof "article-x-face")))
2527 (error "`%s' set to `%s' is not a function"
2528 gnus-article-x-face-command
2529 'gnus-article-x-face-command)))))))))
2531 (defun article-decode-mime-words ()
2532 "Decode all MIME-encoded words in the article."
2533 (interactive)
2534 (gnus-with-article-buffer
2535 (let ((inhibit-point-motion-hooks t)
2536 (mail-parse-charset gnus-newsgroup-charset)
2537 (mail-parse-ignored-charsets
2538 (with-current-buffer gnus-summary-buffer
2539 gnus-newsgroup-ignored-charsets)))
2540 (mail-decode-encoded-word-region (point-min) (point-max)))))
2542 (defun article-decode-charset (&optional prompt)
2543 "Decode charset-encoded text in the article.
2544 If PROMPT (the prefix), prompt for a coding system to use."
2545 (interactive "P")
2546 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2547 (inhibit-read-only t)
2548 (mail-parse-charset gnus-newsgroup-charset)
2549 (mail-parse-ignored-charsets
2550 (save-excursion (condition-case nil
2551 (set-buffer gnus-summary-buffer)
2552 (error))
2553 gnus-newsgroup-ignored-charsets))
2554 ct cte ctl charset format)
2555 (save-excursion
2556 (save-restriction
2557 (article-narrow-to-head)
2558 (setq ct (message-fetch-field "Content-Type" t)
2559 cte (message-fetch-field "Content-Transfer-Encoding" t)
2560 ctl (and ct (mail-header-parse-content-type ct))
2561 charset (cond
2562 (prompt
2563 (mm-read-coding-system "Charset to decode: "))
2564 (ctl
2565 (mail-content-type-get ctl 'charset)))
2566 format (and ctl (mail-content-type-get ctl 'format)))
2567 (when cte
2568 (setq cte (mail-header-strip cte)))
2569 (if (and ctl (not (string-match "/" (car ctl))))
2570 (setq ctl nil))
2571 (goto-char (point-max)))
2572 (forward-line 1)
2573 (save-restriction
2574 (narrow-to-region (point) (point-max))
2575 (when (and (eq mail-parse-charset 'gnus-decoded)
2576 (eq (mm-body-7-or-8) '8bit))
2577 ;; The text code could have been decoded.
2578 (setq charset mail-parse-charset))
2579 (when (and (or (not ctl)
2580 (equal (car ctl) "text/plain"))
2581 (not format)) ;; article with format will decode later.
2582 (mm-decode-body
2583 charset (and cte (intern (downcase
2584 (gnus-strip-whitespace cte))))
2585 (car ctl)))))))
2587 (defun article-decode-encoded-words ()
2588 "Remove encoded-word encoding from headers."
2589 (let ((inhibit-point-motion-hooks t)
2590 (mail-parse-charset gnus-newsgroup-charset)
2591 (mail-parse-ignored-charsets
2592 (save-excursion (condition-case nil
2593 (set-buffer gnus-summary-buffer)
2594 (error))
2595 gnus-newsgroup-ignored-charsets))
2596 (inhibit-read-only t)
2597 end start)
2598 (goto-char (point-min))
2599 (when (search-forward "\n\n" nil 'move)
2600 (forward-line -1))
2601 (setq end (point))
2602 (while (not (bobp))
2603 (while (progn
2604 (forward-line -1)
2605 (and (not (bobp))
2606 (memq (char-after) '(?\t ? )))))
2607 (setq start (point))
2608 (if (looking-at "\
2609 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2610 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2611 (funcall gnus-decode-address-function start end)
2612 (funcall gnus-decode-header-function start end))
2613 (goto-char (setq end start)))))
2615 (defun article-decode-group-name ()
2616 "Decode group names in Newsgroups, Followup-To and Xref headers."
2617 (let ((inhibit-point-motion-hooks t)
2618 (inhibit-read-only t)
2619 (method (gnus-find-method-for-group gnus-newsgroup-name))
2620 regexp)
2621 (when (and (or gnus-group-name-charset-method-alist
2622 gnus-group-name-charset-group-alist)
2623 (gnus-buffer-live-p gnus-original-article-buffer))
2624 (save-restriction
2625 (article-narrow-to-head)
2626 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2627 (with-current-buffer gnus-original-article-buffer
2628 (goto-char (point-min)))
2629 (setq regexp (concat "^" header
2630 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2631 (while (re-search-forward regexp nil t)
2632 (replace-match (save-match-data
2633 (gnus-decode-newsgroups
2634 ;; XXX how to use data in article buffer?
2635 (with-current-buffer gnus-original-article-buffer
2636 (re-search-forward regexp nil t)
2637 (match-string 1))
2638 gnus-newsgroup-name method))
2639 t t nil 1))
2640 (goto-char (point-min)))))))
2642 (autoload 'idna-to-unicode "idna")
2644 (defun article-decode-idna-rhs ()
2645 "Decode IDNA strings in RHS in various headers in current buffer.
2646 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2647 Mail-Reply-To: and Mail-Followup-To:."
2648 (when gnus-use-idna
2649 (save-restriction
2650 (let ((inhibit-point-motion-hooks t)
2651 (inhibit-read-only t))
2652 (article-narrow-to-head)
2653 (goto-char (point-min))
2654 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2655 (let (ace unicode)
2656 (when (save-match-data
2657 (and (setq ace (match-string 1))
2658 (save-excursion
2659 (and (re-search-backward "^[^ \t]" nil t)
2660 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2661 (setq unicode (idna-to-unicode ace))))
2662 (unless (string= ace unicode)
2663 (replace-match unicode nil nil nil 1)))))))))
2665 (defun article-de-quoted-unreadable (&optional force read-charset)
2666 "Translate a quoted-printable-encoded article.
2667 If FORCE, decode the article whether it is marked as quoted-printable
2668 or not.
2669 If READ-CHARSET, ask for a coding system."
2670 (interactive (list 'force current-prefix-arg))
2671 (save-excursion
2672 (let ((inhibit-read-only t) type charset)
2673 (if (gnus-buffer-live-p gnus-original-article-buffer)
2674 (with-current-buffer gnus-original-article-buffer
2675 (setq type
2676 (gnus-fetch-field "content-transfer-encoding"))
2677 (let* ((ct (gnus-fetch-field "content-type"))
2678 (ctl (and ct (mail-header-parse-content-type ct))))
2679 (setq charset (and ctl
2680 (mail-content-type-get ctl 'charset)))
2681 (if (stringp charset)
2682 (setq charset (intern (downcase charset)))))))
2683 (if read-charset
2684 (setq charset (mm-read-coding-system "Charset: " charset)))
2685 (unless charset
2686 (setq charset gnus-newsgroup-charset))
2687 (when (or force
2688 (and type (let ((case-fold-search t))
2689 (string-match "quoted-printable" type))))
2690 (article-goto-body)
2691 (quoted-printable-decode-region
2692 (point) (point-max) (mm-charset-to-coding-system charset))))))
2694 (defun article-de-base64-unreadable (&optional force read-charset)
2695 "Translate a base64 article.
2696 If FORCE, decode the article whether it is marked as base64 not.
2697 If READ-CHARSET, ask for a coding system."
2698 (interactive (list 'force current-prefix-arg))
2699 (save-excursion
2700 (let ((inhibit-read-only t) type charset)
2701 (if (gnus-buffer-live-p gnus-original-article-buffer)
2702 (with-current-buffer gnus-original-article-buffer
2703 (setq type
2704 (gnus-fetch-field "content-transfer-encoding"))
2705 (let* ((ct (gnus-fetch-field "content-type"))
2706 (ctl (and ct (mail-header-parse-content-type ct))))
2707 (setq charset (and ctl
2708 (mail-content-type-get ctl 'charset)))
2709 (if (stringp charset)
2710 (setq charset (intern (downcase charset)))))))
2711 (if read-charset
2712 (setq charset (mm-read-coding-system "Charset: " charset)))
2713 (unless charset
2714 (setq charset gnus-newsgroup-charset))
2715 (when (or force
2716 (and type (let ((case-fold-search t))
2717 (string-match "base64" type))))
2718 (article-goto-body)
2719 (save-restriction
2720 (narrow-to-region (point) (point-max))
2721 (base64-decode-region (point-min) (point-max))
2722 (mm-decode-coding-region
2723 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2725 (eval-when-compile
2726 (require 'rfc1843))
2728 (defun article-decode-HZ ()
2729 "Translate a HZ-encoded article."
2730 (interactive)
2731 (require 'rfc1843)
2732 (save-excursion
2733 (let ((inhibit-read-only t))
2734 (rfc1843-decode-region (point-min) (point-max)))))
2736 (defun article-unsplit-urls ()
2737 "Remove the newlines that some other mailers insert into URLs."
2738 (interactive)
2739 (save-excursion
2740 (let ((inhibit-read-only t))
2741 (goto-char (point-min))
2742 (while (re-search-forward
2743 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2744 (replace-match "\\1\\3" t)))
2745 (when (interactive-p)
2746 (gnus-treat-article nil))))
2748 (defun article-wash-html ()
2749 "Format an HTML article."
2750 (interactive)
2751 (let ((handles nil)
2752 (buffer-read-only nil))
2753 (when (gnus-buffer-live-p gnus-original-article-buffer)
2754 (setq handles (mm-dissect-buffer t t)))
2755 (article-goto-body)
2756 (delete-region (point) (point-max))
2757 (mm-inline-text-html handles)))
2759 (defvar gnus-article-browse-html-temp-list nil
2760 "List of temporary files created by `gnus-article-browse-html-parts'.
2761 Internal variable.")
2763 (defcustom gnus-article-browse-delete-temp 'ask
2764 "What to do with temporary files from `gnus-article-browse-html-parts'.
2765 If nil, don't delete temporary files. If it is t, delete them on
2766 exit from the summary buffer. If it is the symbol `file', query
2767 on each file, if it is `ask' ask once when exiting from the
2768 summary buffer."
2769 :group 'gnus-article
2770 :version "23.1" ;; No Gnus
2771 :type '(choice (const :tag "Don't delete" nil)
2772 (const :tag "Don't ask" t)
2773 (const :tag "Ask" ask)
2774 (const :tag "Ask for each file" file)))
2776 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2778 (defun gnus-article-browse-delete-temp-files (&optional how)
2779 "Delete temp-files created by `gnus-article-browse-html-parts'."
2780 (when (and gnus-article-browse-html-temp-list
2781 (progn
2782 (or how (setq how gnus-article-browse-delete-temp))
2783 (if (eq how 'ask)
2784 (let ((files (length gnus-article-browse-html-temp-list)))
2785 (gnus-y-or-n-p (format
2786 "Delete all %s temporary HTML file%s? "
2787 files
2788 (if (> files 1) "s" ""))))
2789 how)))
2790 (dolist (file gnus-article-browse-html-temp-list)
2791 (cond ((file-directory-p file)
2792 (when (or (not (eq how 'file))
2793 (gnus-y-or-n-p
2794 (format
2795 "Delete temporary HTML file(s) in directory `%s'? "
2796 (file-name-as-directory file))))
2797 (gnus-delete-directory file)))
2798 ((file-exists-p file)
2799 (when (or (not (eq how 'file))
2800 (gnus-y-or-n-p
2801 (format "Delete temporary HTML file `%s'? " file)))
2802 (delete-file file)))))
2803 ;; Also remove file from the list when not deleted or if file doesn't
2804 ;; exist anymore.
2805 (setq gnus-article-browse-html-temp-list nil))
2806 gnus-article-browse-html-temp-list)
2808 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2809 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2810 Return file name."
2811 (save-match-data
2812 (let (file type)
2813 (catch 'found
2814 (dolist (handle handles)
2815 (cond
2816 ((not (listp handle)))
2817 ((equal (mm-handle-media-supertype handle) "multipart")
2818 (when (setq file (gnus-article-browse-html-save-cid-content
2819 cid handle directory))
2820 (throw 'found file)))
2821 ((equal (concat "<" cid ">") (mm-handle-id handle))
2822 (setq file
2823 (expand-file-name
2824 (or (mm-handle-filename handle)
2825 (concat
2826 (make-temp-name "cid")
2827 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2828 directory))
2829 (mm-save-part-to-file handle file)
2830 (throw 'found file))))))))
2832 (defun gnus-article-browse-html-parts (list &optional header)
2833 "View all \"text/html\" parts from LIST.
2834 Recurse into multiparts. The optional HEADER that should be a decoded
2835 message header will be added to the bodies of the \"text/html\" parts."
2836 ;; Internal function used by `gnus-article-browse-html-article'.
2837 (let (type file charset content cid-dir tmp-file showed)
2838 ;; Find and show the html-parts.
2839 (dolist (handle list)
2840 ;; If HTML, show it:
2841 (cond ((not (listp handle)))
2842 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2843 (and (equal (car type) "message/external-body")
2844 (or header
2845 (setq file (mm-handle-filename handle)))
2846 (or (mm-handle-cache handle)
2847 (condition-case code
2848 (progn (mm-extern-cache-contents handle) t)
2849 (error
2850 (gnus-message 3 "%s" (error-message-string code))
2851 (when (>= gnus-verbose 3) (sit-for 2))
2852 nil)))
2853 (progn
2854 (setq handle (mm-handle-cache handle)
2855 type (mm-handle-type handle))
2856 (equal (car type) "text/html"))))
2857 (setq charset (mail-content-type-get type 'charset)
2858 content (mm-get-part handle))
2859 (with-temp-buffer
2860 (if (eq charset 'gnus-decoded)
2861 (mm-enable-multibyte)
2862 (mm-disable-multibyte))
2863 (insert content)
2864 ;; resolve cid contents
2865 (let ((case-fold-search t)
2866 cid-file)
2867 (goto-char (point-min))
2868 (while (re-search-forward "\
2869 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2870 nil t)
2871 (unless cid-dir
2872 (setq cid-dir (mm-make-temp-file "cid" t))
2873 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2874 (setq file nil
2875 content nil)
2876 (when (setq cid-file
2877 (gnus-article-browse-html-save-cid-content
2878 (match-string 2)
2879 (with-current-buffer gnus-article-buffer
2880 gnus-article-mime-handles)
2881 cid-dir))
2882 (replace-match (concat "file://" cid-file)
2883 nil nil nil 1))))
2884 (unless content (setq content (buffer-string))))
2885 (when (or charset header (not file))
2886 (setq tmp-file (mm-make-temp-file
2887 ;; Do we need to care for 8.3 filenames?
2888 "mm-" nil ".html")))
2889 ;; Add a meta html tag to specify charset and a header.
2890 (cond
2891 (header
2892 (let (title eheader body hcharset coding force-charset)
2893 (with-temp-buffer
2894 (mm-enable-multibyte)
2895 (setq case-fold-search t)
2896 (insert header "\n")
2897 (setq title (message-fetch-field "subject"))
2898 (goto-char (point-min))
2899 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2900 (replace-match (cond ((match-beginning 1) "&lt;")
2901 ((match-beginning 2) "&gt;")
2902 (t "&amp;"))))
2903 (goto-char (point-min))
2904 (insert "<pre>\n")
2905 (goto-char (point-max))
2906 (insert "</pre>\n<hr>\n")
2907 ;; We have to examine charset one by one since
2908 ;; charset specified in parts might be different.
2909 (if (eq charset 'gnus-decoded)
2910 (setq charset 'utf-8
2911 eheader (mm-encode-coding-string (buffer-string)
2912 charset)
2913 title (when title
2914 (mm-encode-coding-string title charset))
2915 body (mm-encode-coding-string content charset)
2916 force-charset t)
2917 (setq hcharset (mm-find-mime-charset-region (point-min)
2918 (point-max)))
2919 (cond ((= (length hcharset) 1)
2920 (setq hcharset (car hcharset)
2921 coding (mm-charset-to-coding-system
2922 hcharset)))
2923 ((> (length hcharset) 1)
2924 (setq hcharset 'utf-8
2925 coding hcharset)))
2926 (if coding
2927 (if charset
2928 (progn
2929 (setq body
2930 (mm-charset-to-coding-system charset))
2931 (if (eq coding body)
2932 (setq eheader (mm-encode-coding-string
2933 (buffer-string) coding)
2934 title (when title
2935 (mm-encode-coding-string
2936 title coding))
2937 body content)
2938 (setq charset 'utf-8
2939 eheader (mm-encode-coding-string
2940 (buffer-string) charset)
2941 title (when title
2942 (mm-encode-coding-string
2943 title charset))
2944 body (mm-encode-coding-string
2945 (mm-decode-coding-string
2946 content body)
2947 charset)
2948 force-charset t)))
2949 (setq charset hcharset
2950 eheader (mm-encode-coding-string
2951 (buffer-string) coding)
2952 title (when title
2953 (mm-encode-coding-string
2954 title coding))
2955 body content))
2956 (setq eheader (mm-string-as-unibyte (buffer-string))
2957 body content)))
2958 (erase-buffer)
2959 (mm-disable-multibyte)
2960 (insert body)
2961 (when charset
2962 (mm-add-meta-html-tag handle charset force-charset))
2963 (when title
2964 (goto-char (point-min))
2965 (unless (search-forward "<title>" nil t)
2966 (re-search-forward "<head>\\s-*" nil t)
2967 (insert "<title>" title "</title>\n")))
2968 (goto-char (point-min))
2969 (or (re-search-forward
2970 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2971 (re-search-forward
2972 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2973 (insert eheader)
2974 (mm-write-region (point-min) (point-max)
2975 tmp-file nil nil nil 'binary t))))
2976 (charset
2977 (mm-with-unibyte-buffer
2978 (insert (if (eq charset 'gnus-decoded)
2979 (mm-encode-coding-string content
2980 (setq charset 'utf-8))
2981 content))
2982 (if (or (mm-add-meta-html-tag handle charset)
2983 (not file))
2984 (mm-write-region (point-min) (point-max)
2985 tmp-file nil nil nil 'binary t)
2986 (setq tmp-file nil))))
2987 (tmp-file
2988 (mm-save-part-to-file handle tmp-file)))
2989 (when tmp-file
2990 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2991 (add-hook 'gnus-summary-prepare-exit-hook
2992 'gnus-article-browse-delete-temp-files)
2993 (add-hook 'gnus-exit-gnus-hook
2994 (lambda ()
2995 (gnus-article-browse-delete-temp-files t)))
2996 ;; FIXME: Warn if there's an <img> tag?
2997 (browse-url-of-file (or tmp-file (expand-file-name file)))
2998 (setq showed t))
2999 ;; If multipart, recurse
3000 ((equal (mm-handle-media-supertype handle) "multipart")
3001 (when (gnus-article-browse-html-parts handle header)
3002 (setq showed t)))
3003 ((equal (mm-handle-media-type handle) "message/rfc822")
3004 (mm-with-multibyte-buffer
3005 (mm-insert-part handle)
3006 (setq handle (mm-dissect-buffer t t))
3007 (when (and (bufferp (car handle))
3008 (stringp (car (mm-handle-type handle))))
3009 (setq handle (list handle)))
3010 (when header
3011 (article-decode-encoded-words)
3012 (let ((gnus-visible-headers
3013 (or (get 'gnus-visible-headers 'standard-value)
3014 gnus-visible-headers)))
3015 (article-hide-headers))
3016 (goto-char (point-min))
3017 (search-forward "\n\n" nil 'move)
3018 (skip-chars-backward "\t\n ")
3019 (setq header (buffer-substring (point-min) (point)))))
3020 (when (prog1
3021 (gnus-article-browse-html-parts handle header)
3022 (mm-destroy-parts handle))
3023 (setq showed t)))))
3024 showed))
3026 (defun gnus-article-browse-html-article (&optional arg)
3027 "View \"text/html\" parts of the current article with a WWW browser.
3028 Inline images embedded in a message using the cid scheme, as they are
3029 generally considered to be safe, will be processed properly.
3030 The message header is added to the beginning of every html part unless
3031 the prefix argument ARG is given.
3033 Warning: Spammers use links to images (using the http scheme) in HTML
3034 articles to verify whether you have read the message. As
3035 `gnus-article-browse-html-article' passes the HTML content to the
3036 browser without eliminating these \"web bugs\" you should only
3037 use it for mails from trusted senders.
3039 If you always want to display HTML parts in the browser, set
3040 `mm-text-html-renderer' to nil.
3042 This command creates temporary files to pass HTML contents including
3043 images if any to the browser, and deletes them when exiting the group
3044 \(if you want)."
3045 ;; Cf. `mm-w3m-safe-url-regexp'
3046 (interactive "P")
3047 (if arg
3048 (gnus-summary-show-article)
3049 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3050 gnus-visible-headers))
3051 ;; As we insert a <hr>, there's no need for the body boundary.
3052 (gnus-treat-body-boundary nil))
3053 (gnus-summary-show-article)))
3054 (with-current-buffer gnus-article-buffer
3055 (let ((header (unless arg
3056 (save-restriction
3057 (widen)
3058 (buffer-substring-no-properties
3059 (goto-char (point-min))
3060 (if (search-forward "\n\n" nil t)
3061 (match-beginning 0)
3062 (goto-char (point-max))
3063 (skip-chars-backward "\t\n ")
3064 (point))))))
3065 parts)
3066 (set-buffer gnus-original-article-buffer)
3067 (setq parts (mm-dissect-buffer t t))
3068 ;; If singlepart, enforce a list.
3069 (when (and (bufferp (car parts))
3070 (stringp (car (mm-handle-type parts))))
3071 (setq parts (list parts)))
3072 ;; Process the list
3073 (unless (gnus-article-browse-html-parts parts header)
3074 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3075 (mm-destroy-parts parts)
3076 (unless arg
3077 (gnus-summary-show-article)))))
3079 (defun article-hide-list-identifiers ()
3080 "Remove list identifies from the Subject header.
3081 The `gnus-list-identifiers' variable specifies what to do."
3082 (interactive)
3083 (let ((inhibit-point-motion-hooks t)
3084 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3085 (inhibit-read-only t))
3086 (when regexp
3087 (save-excursion
3088 (save-restriction
3089 (article-narrow-to-head)
3090 (goto-char (point-min))
3091 (while (re-search-forward
3092 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3093 nil t)
3094 (delete-region (match-beginning 2) (match-end 0))
3095 (beginning-of-line))
3096 (when (re-search-forward
3097 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3098 (delete-region (match-beginning 1) (match-end 1))))))))
3100 (defun article-hide-pem (&optional arg)
3101 "Toggle hiding of any PEM headers and signatures in the current article.
3102 If given a negative prefix, always show; if given a positive prefix,
3103 always hide."
3104 (interactive (gnus-article-hidden-arg))
3105 (unless (gnus-article-check-hidden-text 'pem arg)
3106 (save-excursion
3107 (let ((inhibit-read-only t) end)
3108 (goto-char (point-min))
3109 ;; Hide the horrendously ugly "header".
3110 (when (and (search-forward
3111 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3112 nil t)
3113 (setq end (1+ (match-beginning 0))))
3114 (gnus-add-wash-type 'pem)
3115 (gnus-article-hide-text-type
3117 (if (search-forward "\n\n" nil t)
3118 (match-end 0)
3119 (point-max))
3120 'pem)
3121 ;; Hide the trailer as well
3122 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3123 nil t)
3124 (gnus-article-hide-text-type
3125 (match-beginning 0) (match-end 0) 'pem)))))))
3127 (defun article-strip-banner ()
3128 "Strip the banners specified by the `banner' group parameter and by
3129 `gnus-article-address-banner-alist'."
3130 (interactive)
3131 (save-excursion
3132 (save-restriction
3133 (let ((inhibit-point-motion-hooks t))
3134 (when (gnus-parameter-banner gnus-newsgroup-name)
3135 (article-really-strip-banner
3136 (gnus-parameter-banner gnus-newsgroup-name)))
3137 (when gnus-article-address-banner-alist
3138 ;; Note that the From header is decoded here, so it is
3139 ;; required that the *-extract-address-components function
3140 ;; supports non-ASCII text.
3141 (let ((from (save-restriction
3142 (widen)
3143 (article-narrow-to-head)
3144 (mail-fetch-field "from"))))
3145 (when (and from
3146 (setq from
3147 (cadr (funcall gnus-extract-address-components
3148 from))))
3149 (catch 'found
3150 (dolist (pair gnus-article-address-banner-alist)
3151 (when (string-match (car pair) from)
3152 (throw 'found
3153 (article-really-strip-banner (cdr pair)))))))))))))
3155 (defun article-really-strip-banner (banner)
3156 "Strip the banner specified by the argument."
3157 (save-excursion
3158 (save-restriction
3159 (let ((inhibit-point-motion-hooks t)
3160 (gnus-signature-limit nil)
3161 (inhibit-read-only t))
3162 (article-goto-body)
3163 (cond
3164 ((eq banner 'signature)
3165 (when (gnus-article-narrow-to-signature)
3166 (widen)
3167 (forward-line -1)
3168 (delete-region (point) (point-max))))
3169 ((symbolp banner)
3170 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3171 (while (re-search-forward banner nil t)
3172 (delete-region (match-beginning 0) (match-end 0)))))
3173 ((stringp banner)
3174 (while (re-search-forward banner nil t)
3175 (delete-region (match-beginning 0) (match-end 0)))))))))
3177 (defun article-babel ()
3178 "Translate article using an online translation service."
3179 (interactive)
3180 (require 'babel)
3181 (gnus-with-article-buffer
3182 (when (article-goto-body)
3183 (let* ((start (point))
3184 (end (point-max))
3185 (orig (buffer-substring start end))
3186 (trans (babel-as-string orig)))
3187 (save-restriction
3188 (narrow-to-region start end)
3189 (delete-region start end)
3190 (insert trans))))))
3192 (defun article-hide-signature (&optional arg)
3193 "Hide the signature in the current article.
3194 If given a negative prefix, always show; if given a positive prefix,
3195 always hide."
3196 (interactive (gnus-article-hidden-arg))
3197 (unless (gnus-article-check-hidden-text 'signature arg)
3198 (save-excursion
3199 (save-restriction
3200 (let ((inhibit-read-only t))
3201 (when (gnus-article-narrow-to-signature)
3202 (gnus-article-hide-text-type
3203 (point-min) (point-max) 'signature))))))
3204 (gnus-set-mode-line 'article))
3206 (defun article-strip-headers-in-body ()
3207 "Strip offensive headers from bodies."
3208 (interactive)
3209 (save-excursion
3210 (article-goto-body)
3211 (let ((case-fold-search t))
3212 (when (looking-at "x-no-archive:")
3213 (gnus-delete-line)))))
3215 (defun article-strip-leading-blank-lines ()
3216 "Remove all blank lines from the beginning of the article."
3217 (interactive)
3218 (save-excursion
3219 (let ((inhibit-point-motion-hooks t)
3220 (inhibit-read-only t))
3221 (when (article-goto-body)
3222 (while (and (not (eobp))
3223 (looking-at "[ \t]*$"))
3224 (gnus-delete-line))))))
3226 (defun article-narrow-to-head ()
3227 "Narrow the buffer to the head of the message.
3228 Point is left at the beginning of the narrowed-to region."
3229 (narrow-to-region
3230 (goto-char (point-min))
3231 (if (search-forward "\n\n" nil 1)
3232 (1- (point))
3233 (point-max)))
3234 (goto-char (point-min)))
3236 (defun article-goto-body ()
3237 "Place point at the start of the body."
3238 (goto-char (point-min))
3239 (cond
3240 ;; This variable is only bound when dealing with separate
3241 ;; MIME body parts.
3242 (article-goto-body-goes-to-point-min-p
3244 ((search-forward "\n\n" nil t)
3247 (goto-char (point-max))
3248 nil)))
3250 (defun article-strip-multiple-blank-lines ()
3251 "Replace consecutive blank lines with one empty line."
3252 (interactive)
3253 (save-excursion
3254 (let ((inhibit-point-motion-hooks t)
3255 (inhibit-read-only t))
3256 ;; First make all blank lines empty.
3257 (article-goto-body)
3258 (while (re-search-forward "^[ \t]+$" nil t)
3259 (unless (gnus-annotation-in-region-p
3260 (match-beginning 0) (match-end 0))
3261 (replace-match "" nil t)))
3262 ;; Then replace multiple empty lines with a single empty line.
3263 (article-goto-body)
3264 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3265 (unless (gnus-annotation-in-region-p
3266 (match-beginning 0) (match-end 0))
3267 (delete-region (match-beginning 1) (match-end 1)))))))
3269 (defun article-strip-leading-space ()
3270 "Remove all white space from the beginning of the lines in the article."
3271 (interactive)
3272 (save-excursion
3273 (let ((inhibit-point-motion-hooks t)
3274 (inhibit-read-only t))
3275 (article-goto-body)
3276 (while (re-search-forward "^[ \t]+" nil t)
3277 (replace-match "" t t)))))
3279 (defun article-strip-trailing-space ()
3280 "Remove all white space from the end of the lines in the article."
3281 (interactive)
3282 (save-excursion
3283 (let ((inhibit-point-motion-hooks t)
3284 (inhibit-read-only t))
3285 (article-goto-body)
3286 (while (re-search-forward "[ \t]+$" nil t)
3287 (replace-match "" t t)))))
3289 (defun article-strip-blank-lines ()
3290 "Strip leading, trailing and multiple blank lines."
3291 (interactive)
3292 (article-strip-leading-blank-lines)
3293 (article-remove-trailing-blank-lines)
3294 (article-strip-multiple-blank-lines))
3296 (defun article-strip-all-blank-lines ()
3297 "Strip all blank lines."
3298 (interactive)
3299 (save-excursion
3300 (let ((inhibit-point-motion-hooks t)
3301 (inhibit-read-only t))
3302 (article-goto-body)
3303 (while (re-search-forward "^[ \t]*\n" nil t)
3304 (replace-match "" t t)))))
3306 (defun gnus-article-narrow-to-signature ()
3307 "Narrow to the signature; return t if a signature is found, else nil."
3308 (let ((inhibit-point-motion-hooks t))
3309 (when (gnus-article-search-signature)
3310 (forward-line 1)
3311 ;; Check whether we have some limits to what we consider
3312 ;; to be a signature.
3313 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3314 (list gnus-signature-limit)))
3315 limit limited)
3316 (while (setq limit (pop limits))
3317 (if (or (and (integerp limit)
3318 (< (- (point-max) (point)) limit))
3319 (and (floatp limit)
3320 (< (count-lines (point) (point-max)) limit))
3321 (and (functionp limit)
3322 (funcall limit))
3323 (and (stringp limit)
3324 (not (re-search-forward limit nil t))))
3325 () ; This limit did not succeed.
3326 (setq limited t
3327 limits nil)))
3328 (unless limited
3329 (narrow-to-region (point) (point-max))
3330 t)))))
3332 (defun gnus-article-search-signature ()
3333 "Search the current buffer for the signature separator.
3334 Put point at the beginning of the signature separator."
3335 (let ((cur (point)))
3336 (goto-char (point-max))
3337 (if (if (stringp gnus-signature-separator)
3338 (re-search-backward gnus-signature-separator nil t)
3339 (let ((seps gnus-signature-separator))
3340 (while (and seps
3341 (not (re-search-backward (car seps) nil t)))
3342 (pop seps))
3343 seps))
3345 (goto-char cur)
3346 nil)))
3348 (defun gnus-article-hidden-arg ()
3349 "Return the current prefix arg as a number, or 0 if no prefix."
3350 (list (if current-prefix-arg
3351 (prefix-numeric-value current-prefix-arg)
3352 0)))
3354 (defun gnus-article-check-hidden-text (type arg)
3355 "Return nil if hiding is necessary.
3356 Arg can be nil or a number. nil and positive means hide, negative
3357 means show, 0 means toggle."
3358 (save-excursion
3359 (save-restriction
3360 (let ((hide (gnus-article-hidden-text-p type)))
3361 (cond
3362 ((or (null arg)
3363 (> arg 0))
3364 nil)
3365 ((< arg 0)
3366 (gnus-article-show-hidden-text type)
3369 (if (eq hide 'hidden)
3370 (progn
3371 (gnus-article-show-hidden-text type)
3373 nil)))))))
3375 (defun gnus-article-hidden-text-p (type)
3376 "Say whether the current buffer contains hidden text of type TYPE."
3377 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3378 (while (and pos
3379 (not (get-text-property pos 'invisible))
3380 (not (get-text-property pos 'dummy-invisible)))
3381 (setq pos
3382 (text-property-any (1+ pos) (point-max) 'article-type type)))
3383 (if pos
3384 'hidden
3385 nil)))
3387 (defun gnus-article-show-hidden-text (type &optional dummy)
3388 "Show all hidden text of type TYPE.
3389 Originally it is hide instead of DUMMY."
3390 (let ((inhibit-read-only t)
3391 (inhibit-point-motion-hooks t))
3392 (gnus-remove-text-properties-when
3393 'article-type type
3394 (point-min) (point-max)
3395 (cons 'article-type (cons type
3396 gnus-hidden-properties)))
3397 (gnus-delete-wash-type type)))
3399 (defconst article-time-units
3400 `((year . ,(* 365.25 24 60 60))
3401 (week . ,(* 7 24 60 60))
3402 (day . ,(* 24 60 60))
3403 (hour . ,(* 60 60))
3404 (minute . 60)
3405 (second . 1))
3406 "Mapping from time units to seconds.")
3408 (defun gnus-article-forward-header ()
3409 "Move point to the start of the next header.
3410 If the current header is a continuation header, this can be several
3411 lines forward."
3412 (let ((ended nil))
3413 (while (not ended)
3414 (forward-line 1)
3415 (if (looking-at "[ \t]+[^ \t]")
3416 (forward-line 1)
3417 (setq ended t)))))
3419 (defun article-treat-date ()
3420 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3421 (with-current-buffer gnus-summary-buffer
3422 gnus-article-date-headers)
3423 gnus-article-date-headers)
3426 (defun article-date-ut (&optional type highlight date-position)
3427 "Convert DATE date to TYPE in the current article.
3428 The default type is `ut'. See `gnus-article-date-headers' for
3429 possible values."
3430 (interactive (list 'ut t))
3431 (let* ((case-fold-search t)
3432 (inhibit-read-only t)
3433 (inhibit-point-motion-hooks t)
3434 (first t)
3435 (visible-date (mail-fetch-field "Date"))
3436 pos date bface eface)
3437 (save-excursion
3438 (goto-char (point-min))
3439 (when (re-search-forward "^Date:" nil t)
3440 (setq bface (get-text-property (point-at-bol) 'face)
3441 eface (get-text-property (1- (point-at-eol)) 'face)))
3442 ;; Delete any old Date headers.
3443 (if date-position
3444 (progn
3445 (goto-char date-position)
3446 (setq date (get-text-property (point) 'original-date))
3447 (delete-region (point)
3448 (progn
3449 (gnus-article-forward-header)
3450 (point)))
3451 (article-transform-date date type bface eface))
3452 (save-restriction
3453 (widen)
3454 (goto-char (point-min))
3455 (while (or (get-text-property (setq pos (point)) 'original-date)
3456 (and (setq pos (next-single-property-change
3457 (point) 'original-date))
3458 (goto-char pos)))
3459 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3460 (1+ (match-beginning 0))
3461 (point-max)))
3462 (goto-char (point-min))
3463 (while (re-search-forward "^Date:" nil t)
3464 (setq date (get-text-property (match-beginning 0) 'original-date))
3465 (delete-region (point-at-bol) (progn
3466 (gnus-article-forward-header)
3467 (point))))
3468 (when (and (not date)
3469 visible-date)
3470 (setq date visible-date))
3471 (when date
3472 (article-transform-date date type bface eface))
3473 (goto-char (point-max))
3474 (widen)))))))
3476 (defun article-transform-date (date type bface eface)
3477 (dolist (this-type (cond
3478 ((null type)
3479 (list 'ut))
3480 ((atom type)
3481 (list type))
3483 type)))
3484 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3485 (forward-line -1)
3486 (beginning-of-line)
3487 (put-text-property (point) (1+ (point))
3488 'original-date date)
3489 (put-text-property (point) (1+ (point))
3490 'gnus-date-type this-type)
3491 ;; Do highlighting.
3492 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3493 (put-text-property (match-beginning 1) (1+ (match-end 1))
3494 'face bface)
3495 (put-text-property (match-beginning 2) (match-end 2)
3496 'face eface))
3497 (forward-line 1)))
3499 (defun article-make-date-line (date type)
3500 "Return a DATE line of TYPE."
3501 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3502 combined-lapsed))
3503 (error "Unknown conversion type: %s" type))
3504 (condition-case ()
3505 (let ((time (ignore-errors (date-to-time date))))
3506 (cond
3507 ;; Convert to the local timezone.
3508 ((eq type 'local)
3509 (concat "Date: " (message-make-date time)))
3510 ;; Convert to Universal Time.
3511 ((eq type 'ut)
3512 (concat "Date: "
3513 (substring
3514 (message-make-date
3515 (let* ((e (parse-time-string date))
3516 (tm (apply 'encode-time e))
3517 (ms (car tm))
3518 (ls (- (cadr tm) (car (current-time-zone time)))))
3519 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3520 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3521 (t (list ms ls)))))
3522 0 -5)
3523 "UT"))
3524 ;; Get the original date from the article.
3525 ((eq type 'original)
3526 (concat "Date: " (if (string-match "\n+$" date)
3527 (substring date 0 (match-beginning 0))
3528 date)))
3529 ;; Let the user define the format.
3530 ((eq type 'user-defined)
3531 (let ((format (or (condition-case nil
3532 (with-current-buffer gnus-summary-buffer
3533 gnus-article-time-format)
3534 (error nil))
3535 gnus-article-time-format)))
3536 (if (functionp format)
3537 (funcall format time)
3538 (concat "Date: " (format-time-string format time)))))
3539 ;; ISO 8601.
3540 ((eq type 'iso8601)
3541 (let ((tz (car (current-time-zone time))))
3542 (concat
3543 "Date: "
3544 (format-time-string "%Y%m%dT%H%M%S" time)
3545 (format "%s%02d%02d"
3546 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3547 (/ (% (abs tz) 3600) 60)))))
3548 ;; Do a lapsed format.
3549 ((eq type 'lapsed)
3550 (concat "Date: " (article-lapsed-string time)))
3551 ;; A combined date/lapsed format.
3552 ((eq type 'combined-lapsed)
3553 (let ((date-string (article-make-date-line date 'original))
3554 (segments 3)
3555 lapsed-string)
3556 (while (and
3557 time
3558 (setq lapsed-string
3559 (concat " (" (article-lapsed-string time segments) ")"))
3560 (> (+ (length date-string)
3561 (length lapsed-string))
3562 (+ fill-column 6))
3563 (> segments 0))
3564 (setq segments (1- segments)))
3565 (if (> segments 0)
3566 (concat date-string lapsed-string)
3567 date-string)))
3568 ;; Display the date in proper English
3569 ((eq type 'english)
3570 (let ((dtime (decode-time time)))
3571 (concat
3572 "Date: the "
3573 (number-to-string (nth 3 dtime))
3574 (let ((digit (% (nth 3 dtime) 10)))
3575 (cond
3576 ((memq (nth 3 dtime) '(11 12 13)) "th")
3577 ((= digit 1) "st")
3578 ((= digit 2) "nd")
3579 ((= digit 3) "rd")
3580 (t "th")))
3581 " of "
3582 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3584 (number-to-string (nth 5 dtime))
3585 " at "
3586 (format "%02d" (nth 2 dtime))
3588 (format "%02d" (nth 1 dtime)))))))
3589 (foo
3590 (format "Date: %s (from Gnus)" date))))
3592 (defun article-lapsed-string (time &optional max-segments)
3593 ;; If the date is seriously mangled, the timezone functions are
3594 ;; liable to bug out, so we ignore all errors.
3595 (let* ((now (current-time))
3596 (real-time (subtract-time now time))
3597 (real-sec (and real-time
3598 (+ (* (float (car real-time)) 65536)
3599 (cadr real-time))))
3600 (sec (and real-time (abs real-sec)))
3601 (segments 0)
3602 num prev)
3603 (unless max-segments
3604 (setq max-segments (length article-time-units)))
3605 (cond
3606 ((null real-time)
3607 "Unknown")
3608 ((zerop sec)
3609 "Now")
3611 (concat
3612 ;; This is a bit convoluted, but basically we go
3613 ;; through the time units for years, weeks, etc,
3614 ;; and divide things to see whether that results
3615 ;; in positive answers.
3616 (mapconcat
3617 (lambda (unit)
3618 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3619 (>= segments max-segments))
3620 ;; The (remaining) seconds are too few to
3621 ;; be divided into this time unit.
3623 ;; It's big enough, so we output it.
3624 (setq sec (- sec (* num (cdr unit))))
3625 (prog1
3626 (concat (if prev ", " "") (int-to-string
3627 (floor num))
3628 " " (symbol-name (car unit))
3629 (if (> num 1) "s" ""))
3630 (setq prev t
3631 segments (1+ segments)))))
3632 article-time-units "")
3633 ;; If dates are odd, then it might appear like the
3634 ;; article was sent in the future.
3635 (if (> real-sec 0)
3636 " ago"
3637 " in the future"))))))
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))
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))
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))
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))
3661 (defun article-date-combined-lapsed (&optional highlight)
3662 "Convert the current article date to time lapsed since it was sent."
3663 (interactive (list t))
3664 (article-date-ut 'combined-lapsed highlight))
3666 (defun article-update-date-lapsed ()
3667 "Function to be run from a timer to update the lapsed time line."
3668 (save-match-data
3669 (let ((buffer (current-buffer)))
3670 (ignore-errors
3671 (walk-windows
3672 (lambda (w)
3673 (set-buffer (window-buffer w))
3674 (when (eq major-mode 'gnus-article-mode)
3675 (let ((old-line (count-lines (point-min) (point)))
3676 (old-column (- (point) (line-beginning-position)))
3677 (window-start
3678 (window-start (get-buffer-window (current-buffer)))))
3679 (goto-char (point-min))
3680 (while (re-search-forward "^Date:" nil t)
3681 (let ((type (get-text-property (match-beginning 0)
3682 'gnus-date-type)))
3683 (when (memq type '(lapsed combined-lapsed user-format))
3684 (when (and window-start
3685 (not (= window-start
3686 (save-excursion
3687 (forward-line 1)
3688 (point)))))
3689 (setq window-start nil))
3690 (save-excursion
3691 (article-date-ut type t (match-beginning 0)))
3692 (forward-line 1)
3693 (when window-start
3694 (set-window-start (get-buffer-window (current-buffer))
3695 (point))))))
3696 (goto-char (point-min))
3697 (when (> old-column 0)
3698 (setq old-line (1- old-line)))
3699 (forward-line old-line)
3700 (end-of-line)
3701 (when (> (current-column) old-column)
3702 (beginning-of-line)
3703 (forward-char old-column)))))
3704 nil 'visible))
3705 (set-buffer buffer))))
3707 (defun gnus-start-date-timer (&optional n)
3708 "Start a timer to update the Date headers in the article buffers.
3709 The numerical prefix says how frequently (in seconds) the function
3710 is to run."
3711 (interactive "p")
3712 (unless n
3713 (setq n 1))
3714 (gnus-stop-date-timer)
3715 (setq article-lapsed-timer
3716 (run-at-time 1 n 'article-update-date-lapsed)))
3718 (defun gnus-stop-date-timer ()
3719 "Stop the Date timer."
3720 (interactive)
3721 (when article-lapsed-timer
3722 (nnheader-cancel-timer article-lapsed-timer)
3723 (setq article-lapsed-timer nil)))
3725 (defun article-date-user (&optional highlight)
3726 "Convert the current article date to the user-defined format.
3727 This format is defined by the `gnus-article-time-format' variable."
3728 (interactive (list t))
3729 (article-date-ut 'user highlight))
3731 (defun article-date-iso8601 (&optional highlight)
3732 "Convert the current article date to ISO8601."
3733 (interactive (list t))
3734 (article-date-ut 'iso8601 highlight))
3736 (defmacro gnus-article-save-original-date (&rest forms)
3737 "Save the original date as a text property and evaluate FORMS."
3738 `(let* ((case-fold-search t)
3739 (start (progn
3740 (goto-char (point-min))
3741 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3742 (not (bolp)))
3743 (match-end 0))))
3744 (date (when (and start
3745 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3746 nil t))
3747 (buffer-substring-no-properties start
3748 (match-beginning 0)))))
3749 (goto-char (point-max))
3750 (skip-chars-backward "\n")
3751 (put-text-property (point-min) (point) 'original-date date)
3752 ,@forms
3753 (goto-char (point-max))
3754 (skip-chars-backward "\n")
3755 (put-text-property (point-min) (point) 'original-date date)))
3757 ;; (defun article-show-all ()
3758 ;; "Show all hidden text in the article buffer."
3759 ;; (interactive)
3760 ;; (save-excursion
3761 ;; (let ((inhibit-read-only t))
3762 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3764 (defun article-remove-leading-whitespace ()
3765 "Remove excessive whitespace from all headers."
3766 (interactive)
3767 (save-excursion
3768 (save-restriction
3769 (let ((inhibit-read-only t))
3770 (article-narrow-to-head)
3771 (goto-char (point-min))
3772 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3773 (delete-region (match-beginning 1) (match-end 1)))))))
3775 (defun article-emphasize (&optional arg)
3776 "Emphasize text according to `gnus-emphasis-alist'."
3777 (interactive (gnus-article-hidden-arg))
3778 (unless (gnus-article-check-hidden-text 'emphasis arg)
3779 (save-excursion
3780 (let ((alist (or
3781 (condition-case nil
3782 (with-current-buffer gnus-summary-buffer
3783 gnus-article-emphasis-alist)
3784 (error))
3785 gnus-emphasis-alist))
3786 (inhibit-read-only t)
3787 (props (append '(article-type emphasis)
3788 gnus-hidden-properties))
3789 regexp elem beg invisible visible face)
3790 (article-goto-body)
3791 (setq beg (point))
3792 (while (setq elem (pop alist))
3793 (goto-char beg)
3794 (setq regexp (car elem)
3795 invisible (nth 1 elem)
3796 visible (nth 2 elem)
3797 face (nth 3 elem))
3798 (while (re-search-forward regexp nil t)
3799 (when (and (match-beginning visible) (match-beginning invisible))
3800 (gnus-article-hide-text
3801 (match-beginning invisible) (match-end invisible) props)
3802 (gnus-article-unhide-text-type
3803 (match-beginning visible) (match-end visible) 'emphasis)
3804 (gnus-put-overlay-excluding-newlines
3805 (match-beginning visible) (match-end visible) 'face face)
3806 (gnus-add-wash-type 'emphasis)
3807 (goto-char (match-end invisible)))))))))
3809 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3810 "Setup newsgroup emphasis alist."
3811 (unless gnus-article-emphasis-alist
3812 (let ((name (and gnus-newsgroup-name
3813 (gnus-group-real-name gnus-newsgroup-name))))
3814 (make-local-variable 'gnus-article-emphasis-alist)
3815 (setq gnus-article-emphasis-alist
3816 (nconc
3817 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3818 (while (setq elem (pop alist))
3819 (when (and name (string-match (car elem) name))
3820 (setq alist nil
3821 highlight (copy-sequence (cdr elem)))))
3822 highlight)
3823 (copy-sequence highlight-words)
3824 (if gnus-newsgroup-name
3825 (copy-sequence (gnus-group-find-parameter
3826 gnus-newsgroup-name 'highlight-words t)))
3827 gnus-emphasis-alist)))))
3829 (defvar gnus-summary-article-menu)
3830 (defvar gnus-summary-post-menu)
3832 ;;; Saving functions.
3834 (defun gnus-article-save (save-buffer file &optional num)
3835 "Save the currently selected article."
3836 (when (or (get gnus-default-article-saver :headers)
3837 (not gnus-save-all-headers))
3838 ;; Remove headers according to `gnus-saved-headers' or the value
3839 ;; of the `:headers' property that the saver function might have.
3840 (let ((gnus-visible-headers
3841 (or (symbol-value (get gnus-default-article-saver :headers))
3842 gnus-saved-headers gnus-visible-headers))
3843 ;; Ignore group parameter. See `article-hide-headers'.
3844 (gnus-summary-buffer nil))
3845 (with-current-buffer save-buffer
3846 (article-hide-headers 1 t))))
3847 (save-window-excursion
3848 (if (not gnus-default-article-saver)
3849 (error "No default saver is defined")
3850 ;; !!! Magic! The saving functions all save
3851 ;; `gnus-save-article-buffer' (or so they think), but we
3852 ;; bind that variable to our save-buffer.
3853 (set-buffer gnus-article-buffer)
3854 (let* ((gnus-save-article-buffer save-buffer)
3855 (filename
3856 (cond
3857 ((not gnus-prompt-before-saving) 'default)
3858 ((eq gnus-prompt-before-saving 'always) nil)
3859 (t file)))
3860 (gnus-number-of-articles-to-be-saved
3861 (when (eq gnus-prompt-before-saving t)
3862 num))) ; Magic
3863 (set-buffer gnus-article-current-summary)
3864 (funcall gnus-default-article-saver filename)))))
3866 (defun gnus-read-save-file-name (prompt &optional filename
3867 function group headers variable
3868 dir-var)
3869 (let ((default-name
3870 (funcall function group headers (symbol-value variable)))
3871 result)
3872 (setq result
3873 (expand-file-name
3874 (cond
3875 ((eq filename 'default)
3876 default-name)
3877 ((eq filename t)
3878 default-name)
3879 (filename filename)
3881 (when (symbol-value dir-var)
3882 (setq default-name (expand-file-name
3883 (file-name-nondirectory default-name)
3884 (symbol-value dir-var))))
3885 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3886 (prompt
3887 (format prompt
3888 (if (and gnus-number-of-articles-to-be-saved
3889 (> gnus-number-of-articles-to-be-saved 1))
3890 (format "these %d articles"
3891 gnus-number-of-articles-to-be-saved)
3892 "this article")))
3893 (file
3894 ;; Let the split methods have their say.
3895 (cond
3896 ;; No split name was found.
3897 ((null split-name)
3898 (read-file-name
3899 (concat prompt " (default "
3900 (file-name-nondirectory default-name) "): ")
3901 (file-name-directory default-name)
3902 default-name))
3903 ;; A single group name is returned.
3904 ((stringp split-name)
3905 (setq default-name
3906 (funcall function split-name headers
3907 (symbol-value variable)))
3908 (read-file-name
3909 (concat prompt " (default "
3910 (file-name-nondirectory default-name) "): ")
3911 (file-name-directory default-name)
3912 default-name))
3913 ;; A single split name was found
3914 ((= 1 (length split-name))
3915 (let* ((name (expand-file-name
3916 (car split-name)
3917 gnus-article-save-directory))
3918 (dir (cond ((file-directory-p name)
3919 (file-name-as-directory name))
3920 ((file-exists-p name) name)
3921 (t gnus-article-save-directory))))
3922 (read-file-name
3923 (concat prompt " (default " name "): ")
3924 dir name)))
3925 ;; A list of splits was found.
3927 (setq split-name (nreverse split-name))
3928 (let (result)
3929 (let ((file-name-history
3930 (nconc split-name file-name-history)))
3931 (setq result
3932 (expand-file-name
3933 (read-file-name
3934 (concat prompt " (`M-p' for defaults): ")
3935 gnus-article-save-directory
3936 (car split-name))
3937 gnus-article-save-directory)))
3938 (car (push result file-name-history)))))))
3939 ;; Create the directory.
3940 (gnus-make-directory (file-name-directory file))
3941 ;; If we have read a directory, we append the default file name.
3942 (when (file-directory-p file)
3943 (setq file (expand-file-name (file-name-nondirectory
3944 default-name)
3945 (file-name-as-directory file))))
3946 ;; Possibly translate some characters.
3947 (nnheader-translate-file-chars file))))))
3948 (gnus-make-directory (file-name-directory result))
3949 (when variable
3950 (set variable result))
3951 (when dir-var
3952 (set dir-var (file-name-directory result)))
3953 result))
3955 (defun gnus-article-archive-name (group)
3956 "Return the first instance of an \"Archive-name\" in the current buffer."
3957 (let ((case-fold-search t))
3958 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3959 (nnheader-concat gnus-article-save-directory
3960 (match-string 1)))))
3962 (defun gnus-article-nndoc-name (group)
3963 "If GROUP is an nndoc group, return the name of the parent group."
3964 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3965 (gnus-group-get-parameter group 'save-article-group)))
3967 (defun gnus-summary-save-in-rmail (&optional filename)
3968 "Append this article to Rmail file.
3969 Optional argument FILENAME specifies file name.
3970 Directory to save to is default to `gnus-article-save-directory'."
3971 (setq filename (gnus-read-save-file-name
3972 "Save %s in rmail file" filename
3973 gnus-rmail-save-name gnus-newsgroup-name
3974 gnus-current-headers 'gnus-newsgroup-last-rmail))
3975 (with-current-buffer gnus-save-article-buffer
3976 (save-excursion
3977 (save-restriction
3978 (widen)
3979 ;; Note that unlike gnus-summary-save-in-mail, there is no
3980 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3981 ;; not use Babyl.
3982 (gnus-output-to-rmail filename))))
3983 filename)
3985 (defun gnus-summary-save-in-mail (&optional filename)
3986 "Append this article to Unix mail file.
3987 Optional argument FILENAME specifies file name.
3988 Directory to save to is default to `gnus-article-save-directory'."
3989 (setq filename (gnus-read-save-file-name
3990 "Save %s in Unix mail file" filename
3991 gnus-mail-save-name gnus-newsgroup-name
3992 gnus-current-headers 'gnus-newsgroup-last-mail))
3993 (with-current-buffer gnus-save-article-buffer
3994 (save-excursion
3995 (save-restriction
3996 (widen)
3997 (if (and (file-readable-p filename)
3998 (file-regular-p filename)
3999 (mail-file-babyl-p filename))
4000 (gnus-output-to-rmail filename)
4001 (gnus-output-to-mail filename)))))
4002 filename)
4004 (put 'gnus-summary-save-in-file :decode t)
4005 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4006 (defun gnus-summary-save-in-file (&optional filename overwrite)
4007 "Append this article to file.
4008 Optional argument FILENAME specifies file name.
4009 Directory to save to is default to `gnus-article-save-directory'."
4010 (setq filename (gnus-read-save-file-name
4011 "Save %s in file" filename
4012 gnus-file-save-name gnus-newsgroup-name
4013 gnus-current-headers 'gnus-newsgroup-last-file))
4014 (with-current-buffer gnus-save-article-buffer
4015 (save-excursion
4016 (save-restriction
4017 (widen)
4018 (when (and overwrite
4019 (file-exists-p filename))
4020 (delete-file filename))
4021 (gnus-output-to-file filename))))
4022 filename)
4024 (put 'gnus-summary-write-to-file :decode t)
4025 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4026 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4027 (defun gnus-summary-write-to-file (&optional filename)
4028 "Write this article to a file, overwriting it if the file exists.
4029 Optional argument FILENAME specifies file name.
4030 The directory to save in defaults to `gnus-article-save-directory'."
4031 (setq filename (gnus-read-save-file-name
4032 "Save %s in file" filename
4033 gnus-file-save-name gnus-newsgroup-name
4034 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4035 (gnus-summary-save-in-file filename t))
4037 (put 'gnus-summary-save-body-in-file :decode t)
4038 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4039 "Append this article body to a file.
4040 Optional argument FILENAME specifies file name.
4041 The directory to save in defaults to `gnus-article-save-directory'."
4042 (setq filename (gnus-read-save-file-name
4043 "Save %s body in file" filename
4044 gnus-file-save-name gnus-newsgroup-name
4045 gnus-current-headers 'gnus-newsgroup-last-file))
4046 (with-current-buffer gnus-save-article-buffer
4047 (save-excursion
4048 (save-restriction
4049 (widen)
4050 (when (article-goto-body)
4051 (narrow-to-region (point) (point-max)))
4052 (when (and overwrite
4053 (file-exists-p filename))
4054 (delete-file filename))
4055 (gnus-output-to-file filename))))
4056 filename)
4058 (put 'gnus-summary-write-body-to-file :decode t)
4059 (put 'gnus-summary-write-body-to-file
4060 :function 'gnus-summary-save-body-in-file)
4061 (defun gnus-summary-write-body-to-file (&optional filename)
4062 "Write this article body to a file, overwriting it if the file exists.
4063 Optional argument FILENAME specifies file name.
4064 The directory to save in defaults to `gnus-article-save-directory'."
4065 (setq filename (gnus-read-save-file-name
4066 "Save %s body in file" filename
4067 gnus-file-save-name gnus-newsgroup-name
4068 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4069 (gnus-summary-save-body-in-file filename t))
4071 (put 'gnus-summary-save-in-pipe :decode t)
4072 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4073 (defun gnus-summary-save-in-pipe (&optional command raw)
4074 "Pipe this article to subprocess COMMAND.
4075 Valid values for COMMAND include:
4076 a string
4077 The executable command name and possibly arguments.
4079 You will be prompted for the command in the minibuffer.
4080 the symbol `default'
4081 It will be replaced with the command which the variable
4082 `gnus-summary-pipe-output-default-command' holds or the command
4083 last used for saving.
4084 Non-nil value for RAW overrides `:decode' and `:headers' properties
4085 and the raw article including all headers will be piped."
4086 (let ((article (gnus-summary-article-number))
4087 (decode (unless raw
4088 (get 'gnus-summary-save-in-pipe :decode)))
4089 save-buffer default)
4090 (if article
4091 (if (vectorp (gnus-summary-article-header article))
4092 (save-current-buffer
4093 (gnus-summary-select-article decode decode nil article)
4094 (insert-buffer-substring
4095 (prog1
4096 (if decode
4097 gnus-article-buffer
4098 gnus-original-article-buffer)
4099 (setq save-buffer
4100 (nnheader-set-temp-buffer " *Gnus Save*"))))
4101 ;; Remove unwanted headers.
4102 (when (and (not raw)
4103 (or (get 'gnus-summary-save-in-pipe :headers)
4104 (not gnus-save-all-headers)))
4105 (let ((gnus-visible-headers
4106 (or (symbol-value (get 'gnus-summary-save-in-pipe
4107 :headers))
4108 gnus-saved-headers gnus-visible-headers))
4109 (gnus-summary-buffer nil))
4110 (article-hide-headers 1 t))))
4111 (error "%d is not a real article" article))
4112 (error "No article to pipe"))
4113 (setq default (or gnus-summary-pipe-output-default-command
4114 gnus-last-shell-command))
4115 (unless (stringp command)
4116 (setq command
4117 (if (and (eq command 'default) default)
4118 default
4119 (gnus-read-shell-command "Shell command on this article: "
4120 default))))
4121 (when (string-equal command "")
4122 (if default
4123 (setq command default)
4124 (error "A command is required")))
4125 (with-current-buffer save-buffer
4126 (save-restriction
4127 (widen)
4128 (shell-command-on-region (point-min) (point-max) command nil)))
4129 (gnus-kill-buffer save-buffer))
4130 (setq gnus-summary-pipe-output-default-command command))
4132 (defun gnus-summary-pipe-to-muttprint (&optional command)
4133 "Pipe this article to muttprint."
4134 (unless (stringp command)
4135 (setq command (read-string
4136 "Print using command: " gnus-summary-muttprint-program
4137 nil gnus-summary-muttprint-program)))
4138 (let ((gnus-summary-pipe-output-default-command
4139 gnus-summary-pipe-output-default-command))
4140 (gnus-summary-save-in-pipe command))
4141 (setq gnus-summary-muttprint-program command))
4143 ;;; Article file names when saving.
4145 (defun gnus-capitalize-newsgroup (newsgroup)
4146 "Capitalize NEWSGROUP name."
4147 (when (not (zerop (length newsgroup)))
4148 (concat (char-to-string (upcase (aref newsgroup 0)))
4149 (substring newsgroup 1))))
4151 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4152 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4153 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4154 Otherwise, it is like ~/News/news/group/num."
4155 (let ((default
4156 (expand-file-name
4157 (concat (if (gnus-use-long-file-name 'not-save)
4158 (gnus-capitalize-newsgroup newsgroup)
4159 (gnus-newsgroup-directory-form newsgroup))
4160 "/" (int-to-string (mail-header-number headers)))
4161 gnus-article-save-directory)))
4162 (if (and last-file
4163 (string-equal (file-name-directory default)
4164 (file-name-directory last-file))
4165 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4166 default
4167 (or last-file default))))
4169 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4170 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4171 If variable `gnus-use-long-file-name' is non-nil, it is
4172 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4173 (let ((default
4174 (expand-file-name
4175 (concat (if (gnus-use-long-file-name 'not-save)
4176 newsgroup
4177 (gnus-newsgroup-directory-form newsgroup))
4178 "/" (int-to-string (mail-header-number headers)))
4179 gnus-article-save-directory)))
4180 (if (and last-file
4181 (string-equal (file-name-directory default)
4182 (file-name-directory last-file))
4183 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4184 default
4185 (or last-file default))))
4187 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4188 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4189 If variable `gnus-use-long-file-name' is non-nil, it is
4190 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4191 (or last-file
4192 (expand-file-name
4193 (if (gnus-use-long-file-name 'not-save)
4194 newsgroup
4195 (file-relative-name
4196 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4197 default-directory))
4198 gnus-article-save-directory)))
4200 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4201 "Generate file name from sender."
4202 (let ((from (mail-header-from headers)))
4203 (expand-file-name
4204 (if (and from (string-match "\\([^ <]+\\)@" from))
4205 (match-string 1 from)
4206 "nobody")
4207 gnus-article-save-directory)))
4209 (defun article-verify-x-pgp-sig ()
4210 "Verify X-PGP-Sig."
4211 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4212 (interactive)
4213 (if (gnus-buffer-live-p gnus-original-article-buffer)
4214 (let ((sig (with-current-buffer gnus-original-article-buffer
4215 (gnus-fetch-field "X-PGP-Sig")))
4216 items info headers)
4217 (when (and sig
4218 mml2015-use
4219 (mml2015-clear-verify-function))
4220 (with-temp-buffer
4221 (insert-buffer-substring gnus-original-article-buffer)
4222 (setq items (split-string sig))
4223 (message-narrow-to-head)
4224 (let ((inhibit-point-motion-hooks t)
4225 (case-fold-search t))
4226 ;; Don't verify multiple headers.
4227 (setq headers (mapconcat (lambda (header)
4228 (concat header ": "
4229 (mail-fetch-field header)
4230 "\n"))
4231 (split-string (nth 1 items) ",") "")))
4232 (delete-region (point-min) (point-max))
4233 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4234 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4235 (insert headers)
4236 (widen)
4237 (forward-line)
4238 (while (not (eobp))
4239 (if (looking-at "^-")
4240 (insert "- "))
4241 (forward-line))
4242 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4243 (insert "Version: " (car items) "\n\n")
4244 (insert (mapconcat 'identity (cddr items) "\n"))
4245 (insert "\n-----END PGP SIGNATURE-----\n")
4246 (let ((mm-security-handle (list (format "multipart/signed"))))
4247 (mml2015-clean-buffer)
4248 (let ((coding-system-for-write (or gnus-newsgroup-charset
4249 'iso-8859-1)))
4250 (funcall (mml2015-clear-verify-function)))
4251 (setq info
4252 (or (mm-handle-multipart-ctl-parameter
4253 mm-security-handle 'gnus-details)
4254 (mm-handle-multipart-ctl-parameter
4255 mm-security-handle 'gnus-info)))))
4256 (when info
4257 (let ((inhibit-read-only t) bface eface)
4258 (save-restriction
4259 (message-narrow-to-head)
4260 (goto-char (point-max))
4261 (forward-line -1)
4262 (setq bface (get-text-property (point-at-bol) 'face)
4263 eface (get-text-property (1- (point-at-eol)) 'face))
4264 (message-remove-header "X-Gnus-PGP-Verify")
4265 (if (re-search-forward "^X-PGP-Sig:" nil t)
4266 (forward-line)
4267 (goto-char (point-max)))
4268 (narrow-to-region (point) (point))
4269 (insert "X-Gnus-PGP-Verify: " info "\n")
4270 (goto-char (point-min))
4271 (forward-line)
4272 (while (not (eobp))
4273 (if (not (looking-at "^[ \t]"))
4274 (insert " "))
4275 (forward-line))
4276 ;; Do highlighting.
4277 (goto-char (point-min))
4278 (when (looking-at "\\([^:]+\\): *")
4279 (put-text-property (match-beginning 1) (1+ (match-end 1))
4280 'face bface)
4281 (put-text-property (match-end 0) (point-max)
4282 'face eface)))))))))
4284 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4286 (defun article-verify-cancel-lock ()
4287 "Verify Cancel-Lock header."
4288 (interactive)
4289 (if (gnus-buffer-live-p gnus-original-article-buffer)
4290 (canlock-verify gnus-original-article-buffer)))
4292 (eval-and-compile
4293 (mapc
4294 (lambda (func)
4295 (let (afunc gfunc)
4296 (if (consp func)
4297 (setq afunc (car func)
4298 gfunc (cdr func))
4299 (setq afunc func
4300 gfunc (intern (format "gnus-%s" func))))
4301 (defalias gfunc
4302 (when (fboundp afunc)
4303 `(lambda (&optional interactive &rest args)
4304 ,(documentation afunc t)
4305 (interactive (list t))
4306 (with-current-buffer gnus-article-buffer
4307 (if interactive
4308 (call-interactively ',afunc)
4309 (apply ',afunc args))))))))
4310 '(article-hide-headers
4311 article-verify-x-pgp-sig
4312 article-verify-cancel-lock
4313 article-hide-boring-headers
4314 article-treat-overstrike
4315 article-treat-ansi-sequences
4316 article-fill-long-lines
4317 article-capitalize-sentences
4318 article-remove-cr
4319 article-remove-leading-whitespace
4320 article-display-x-face
4321 article-display-face
4322 article-de-quoted-unreadable
4323 article-de-base64-unreadable
4324 article-decode-HZ
4325 article-wash-html
4326 article-unsplit-urls
4327 article-hide-list-identifiers
4328 article-strip-banner
4329 article-babel
4330 article-hide-pem
4331 article-hide-signature
4332 article-strip-headers-in-body
4333 article-remove-trailing-blank-lines
4334 article-strip-leading-blank-lines
4335 article-strip-multiple-blank-lines
4336 article-strip-leading-space
4337 article-strip-trailing-space
4338 article-strip-blank-lines
4339 article-strip-all-blank-lines
4340 article-date-local
4341 article-date-english
4342 article-date-iso8601
4343 article-date-original
4344 article-treat-date
4345 article-date-ut
4346 article-decode-mime-words
4347 article-decode-charset
4348 article-decode-encoded-words
4349 article-date-user
4350 article-date-lapsed
4351 article-date-combined-lapsed
4352 article-emphasize
4353 article-treat-dumbquotes
4354 article-treat-non-ascii
4355 article-normalize-headers
4356 ;;(article-show-all . gnus-article-show-all-headers)
4360 ;;; Gnus article mode
4363 (put 'gnus-article-mode 'mode-class 'special)
4365 (set-keymap-parent gnus-article-mode-map widget-keymap)
4367 (gnus-define-keys gnus-article-mode-map
4368 " " gnus-article-goto-next-page
4369 "\177" gnus-article-goto-prev-page
4370 [delete] gnus-article-goto-prev-page
4371 [backspace] gnus-article-goto-prev-page
4372 "\C-c^" gnus-article-refer-article
4373 "h" gnus-article-show-summary
4374 "s" gnus-article-show-summary
4375 "\C-c\C-m" gnus-article-mail
4376 "?" gnus-article-describe-briefly
4377 "<" beginning-of-buffer
4378 ">" end-of-buffer
4379 "\C-c\C-i" gnus-info-find-node
4380 "\C-c\C-b" gnus-bug
4381 "R" gnus-article-reply-with-original
4382 "F" gnus-article-followup-with-original
4383 "\C-hk" gnus-article-describe-key
4384 "\C-hc" gnus-article-describe-key-briefly
4385 "\C-hb" gnus-article-describe-bindings
4387 "e" gnus-article-read-summary-keys
4388 "\C-d" gnus-article-read-summary-keys
4389 "\M-*" gnus-article-read-summary-keys
4390 "\M-#" gnus-article-read-summary-keys
4391 "\M-^" gnus-article-read-summary-keys
4392 "\M-g" gnus-article-read-summary-keys)
4394 (substitute-key-definition
4395 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4397 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4398 "W" gnus-article-wide-reply-with-original)
4399 (if (featurep 'xemacs)
4400 (set-keymap-default-binding gnus-article-send-map
4401 'gnus-article-read-summary-send-keys)
4402 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4404 (defun gnus-article-make-menu-bar ()
4405 (unless (boundp 'gnus-article-commands-menu)
4406 (gnus-summary-make-menu-bar))
4407 (unless (boundp 'gnus-article-article-menu)
4408 (easy-menu-define
4409 gnus-article-article-menu gnus-article-mode-map ""
4410 '("Article"
4411 ["Scroll forwards" gnus-article-goto-next-page t]
4412 ["Scroll backwards" gnus-article-goto-prev-page t]
4413 ["Show summary" gnus-article-show-summary t]
4414 ["Fetch Message-ID at point" gnus-article-refer-article t]
4415 ["Mail to address at point" gnus-article-mail t]
4416 ["Send a bug report" gnus-bug t]))
4418 (easy-menu-define
4419 gnus-article-treatment-menu gnus-article-mode-map ""
4420 ;; Fixme: this should use :active (and maybe :visible).
4421 '("Treatment"
4422 ["Hide headers" gnus-article-hide-headers t]
4423 ["Hide signature" gnus-article-hide-signature t]
4424 ["Hide citation" gnus-article-hide-citation t]
4425 ["Treat overstrike" gnus-article-treat-overstrike t]
4426 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4427 ["Remove carriage return" gnus-article-remove-cr t]
4428 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4429 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4430 ["Remove base64" gnus-article-de-base64-unreadable t]
4431 ["Treat html" gnus-article-wash-html t]
4432 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4433 ["Decode HZ" gnus-article-decode-HZ t]))
4435 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4437 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4439 (gnus-run-hooks 'gnus-article-menu-hook)))
4441 (defvar bookmark-make-record-function)
4442 (defvar shr-put-image-function)
4444 (defun gnus-article-mode ()
4445 "Major mode for displaying an article.
4447 All normal editing commands are switched off.
4449 The following commands are available in addition to all summary mode
4450 commands:
4451 \\<gnus-article-mode-map>
4452 \\[gnus-article-next-page]\t Scroll the article one page forwards
4453 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4454 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4455 \\[gnus-article-show-summary]\t Display the summary buffer
4456 \\[gnus-article-mail]\t Send a reply to the address near point
4457 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4458 \\[gnus-info-find-node]\t Go to the Gnus info node"
4459 (interactive)
4460 (kill-all-local-variables)
4461 (gnus-simplify-mode-line)
4462 (setq mode-name "Article")
4463 (setq major-mode 'gnus-article-mode)
4464 (make-local-variable 'minor-mode-alist)
4465 (use-local-map gnus-article-mode-map)
4466 (when (gnus-visual-p 'article-menu 'menu)
4467 (gnus-article-make-menu-bar)
4468 (when gnus-summary-tool-bar-map
4469 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4470 (gnus-update-format-specifications nil 'article-mode)
4471 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4472 (set (make-local-variable 'gnus-page-broken) nil)
4473 (make-local-variable 'gnus-article-current-summary)
4474 (make-local-variable 'gnus-article-mime-handles)
4475 (make-local-variable 'gnus-article-decoded-p)
4476 (make-local-variable 'gnus-article-mime-handle-alist)
4477 (make-local-variable 'gnus-article-wash-types)
4478 (make-local-variable 'gnus-article-image-alist)
4479 (make-local-variable 'gnus-article-charset)
4480 (make-local-variable 'gnus-article-ignored-charsets)
4481 (set (make-local-variable 'bookmark-make-record-function)
4482 'gnus-summary-bookmark-make-record)
4483 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4484 ;; face.
4485 (set (make-local-variable 'nobreak-char-display) nil)
4486 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4487 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4488 (setq cursor-in-non-selected-windows nil)
4489 (gnus-set-default-directory)
4490 (buffer-disable-undo)
4491 (setq buffer-read-only t
4492 show-trailing-whitespace nil)
4493 (set-syntax-table gnus-article-mode-syntax-table)
4494 (mm-enable-multibyte)
4495 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4497 (defun gnus-article-setup-buffer ()
4498 "Initialize the article buffer."
4499 (let* ((name (if gnus-single-article-buffer "*Article*"
4500 (concat "*Article " gnus-newsgroup-name "*")))
4501 (original
4502 (progn (string-match "\\*Article" name)
4503 (concat " *Original Article"
4504 (substring name (match-end 0))))))
4505 (setq gnus-article-buffer name)
4506 (setq gnus-original-article-buffer original)
4507 (setq gnus-article-mime-handle-alist nil)
4508 (with-current-buffer gnus-summary-buffer
4509 ;; This might be a variable local to the summary buffer.
4510 (unless gnus-single-article-buffer
4511 (setq gnus-article-buffer name)
4512 (setq gnus-original-article-buffer original)
4513 (gnus-set-global-variables)))
4514 (gnus-article-setup-highlight-words)
4515 ;; Init original article buffer.
4516 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4517 (mm-enable-multibyte)
4518 (setq major-mode 'gnus-original-article-mode)
4519 (make-local-variable 'gnus-original-article))
4520 (if (and (get-buffer name)
4521 (with-current-buffer name
4522 (if gnus-article-edit-mode
4523 (if (y-or-n-p "Article mode edit in progress; discard? ")
4524 (progn
4525 (set-buffer-modified-p nil)
4526 (gnus-kill-buffer name)
4527 (message "")
4528 nil)
4529 (error "Action aborted"))
4530 t)))
4531 (with-current-buffer name
4532 (set (make-local-variable 'gnus-article-edit-mode) nil)
4533 (gnus-article-stop-animations)
4534 (when gnus-article-mime-handles
4535 (mm-destroy-parts gnus-article-mime-handles)
4536 (setq gnus-article-mime-handles nil))
4537 ;; Set it to nil in article-buffer!
4538 (setq gnus-article-mime-handle-alist nil)
4539 (buffer-disable-undo)
4540 (setq buffer-read-only t)
4541 (unless (eq major-mode 'gnus-article-mode)
4542 (gnus-article-mode))
4543 (setq truncate-lines gnus-article-truncate-lines)
4544 (current-buffer))
4545 (with-current-buffer (gnus-get-buffer-create name)
4546 (gnus-article-mode)
4547 (setq truncate-lines gnus-article-truncate-lines)
4548 (make-local-variable 'gnus-summary-buffer)
4549 (setq gnus-summary-buffer
4550 (gnus-summary-buffer-name gnus-newsgroup-name))
4551 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4552 (when article-lapsed-timer
4553 (gnus-stop-date-timer))
4554 (when gnus-article-update-date-headers
4555 (gnus-start-date-timer gnus-article-update-date-headers))
4556 (current-buffer)))))
4558 (defun gnus-article-stop-animations ()
4559 (dolist (timer (and (boundp 'timer-list)
4560 timer-list))
4561 (when (eq (elt timer 5) 'image-animate-timeout)
4562 (cancel-timer timer))))
4564 ;; Set article window start at LINE, where LINE is the number of lines
4565 ;; from the head of the article.
4566 (defun gnus-article-set-window-start (&optional line)
4567 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4568 (when article-window
4569 (set-window-start
4570 article-window
4571 (with-current-buffer gnus-article-buffer
4572 (goto-char (point-min))
4573 (if (not line)
4574 (point-min)
4575 (gnus-message 6 "Moved to bookmark")
4576 (search-forward "\n\n" nil t)
4577 (forward-line line)
4578 (point)))))))
4580 (defun gnus-article-prepare (article &optional all-headers header)
4581 "Prepare ARTICLE in article mode buffer.
4582 ARTICLE should either be an article number or a Message-ID.
4583 If ARTICLE is an id, HEADER should be the article headers.
4584 If ALL-HEADERS is non-nil, no headers are hidden."
4585 (save-excursion
4586 ;; Make sure we start in a summary buffer.
4587 (unless (eq major-mode 'gnus-summary-mode)
4588 (set-buffer gnus-summary-buffer))
4589 (setq gnus-summary-buffer (current-buffer))
4590 (let* ((gnus-article (if header (mail-header-number header) article))
4591 (summary-buffer (current-buffer))
4592 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4593 (group gnus-newsgroup-name)
4594 result)
4595 (save-excursion
4596 (gnus-article-setup-buffer)
4597 (set-buffer gnus-article-buffer)
4598 ;; Deactivate active regions.
4599 (when (and (boundp 'transient-mark-mode)
4600 transient-mark-mode)
4601 (setq mark-active nil))
4602 (if (not (setq result (let ((inhibit-read-only t))
4603 (gnus-request-article-this-buffer
4604 article group))))
4605 ;; There is no such article.
4606 (save-excursion
4607 (when (and (numberp article)
4608 (not (memq article gnus-newsgroup-sparse)))
4609 (setq gnus-article-current
4610 (cons gnus-newsgroup-name article))
4611 (set-buffer gnus-summary-buffer)
4612 (setq gnus-current-article article)
4613 (if (and (memq article gnus-newsgroup-undownloaded)
4614 (not (gnus-online (gnus-find-method-for-group
4615 gnus-newsgroup-name))))
4616 (progn
4617 (gnus-summary-set-agent-mark article)
4618 (message "Message marked for downloading"))
4619 (gnus-summary-mark-article article gnus-canceled-mark)
4620 (unless (memq article gnus-newsgroup-sparse)
4621 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4622 (if (or (eq result 'pseudo)
4623 (eq result 'nneething))
4624 (progn
4625 (with-current-buffer summary-buffer
4626 (push article gnus-newsgroup-history)
4627 (setq gnus-last-article gnus-current-article
4628 gnus-current-article 0
4629 gnus-current-headers nil
4630 gnus-article-current nil)
4631 (if (eq result 'nneething)
4632 (gnus-configure-windows 'summary)
4633 (gnus-configure-windows 'article))
4634 (gnus-set-global-variables))
4635 (let ((gnus-article-mime-handle-alist-1
4636 gnus-article-mime-handle-alist))
4637 (gnus-set-mode-line 'article)))
4638 ;; The result from the `request' was an actual article -
4639 ;; or at least some text that is now displayed in the
4640 ;; article buffer.
4641 (when (and (numberp article)
4642 (not (eq article gnus-current-article)))
4643 ;; Seems like a new article has been selected.
4644 ;; `gnus-current-article' must be an article number.
4645 (with-current-buffer summary-buffer
4646 (push article gnus-newsgroup-history)
4647 (setq gnus-last-article gnus-current-article
4648 gnus-current-article article
4649 gnus-current-headers
4650 (gnus-summary-article-header gnus-current-article)
4651 gnus-article-current
4652 (cons gnus-newsgroup-name gnus-current-article))
4653 (unless (vectorp gnus-current-headers)
4654 (setq gnus-current-headers nil))
4655 (gnus-summary-goto-subject gnus-current-article)
4656 (when (gnus-summary-show-thread)
4657 ;; If the summary buffer really was folded, the
4658 ;; previous goto may not actually have gone to
4659 ;; the right article, but the thread root instead.
4660 ;; So we go again.
4661 (gnus-summary-goto-subject gnus-current-article))
4662 (gnus-run-hooks 'gnus-mark-article-hook)
4663 (gnus-set-mode-line 'summary)
4664 (when (gnus-visual-p 'article-highlight 'highlight)
4665 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4666 ;; Set the global newsgroup variables here.
4667 (gnus-set-global-variables)
4668 (setq gnus-have-all-headers
4669 (or all-headers gnus-show-all-headers))))
4670 (save-excursion
4671 (gnus-configure-windows 'article))
4672 (when (or (numberp article)
4673 (stringp article))
4674 (gnus-article-prepare-display)
4675 ;; Do page break.
4676 (goto-char (point-min))
4677 (when gnus-break-pages
4678 (gnus-narrow-to-page)))
4679 (let ((gnus-article-mime-handle-alist-1
4680 gnus-article-mime-handle-alist))
4681 (gnus-set-mode-line 'article))
4682 (article-goto-body)
4683 (unless (bobp)
4684 (forward-line -1))
4685 (set-window-point (get-buffer-window (current-buffer)) (point))
4686 (gnus-configure-windows 'article)
4687 (gnus-run-hooks 'gnus-article-prepare-hook)
4688 t))))))
4690 ;;;###autoload
4691 (defun gnus-article-prepare-display ()
4692 "Make the current buffer look like a nice article."
4693 ;; Hooks for getting information from the article.
4694 ;; This hook must be called before being narrowed.
4695 (let ((gnus-article-buffer (current-buffer))
4696 buffer-read-only
4697 (inhibit-read-only t))
4698 (unless (eq major-mode 'gnus-article-mode)
4699 (gnus-article-mode))
4700 (setq buffer-read-only nil
4701 gnus-article-wash-types nil
4702 gnus-article-image-alist nil)
4703 (gnus-run-hooks 'gnus-tmp-internal-hook)
4704 (when gnus-display-mime-function
4705 (funcall gnus-display-mime-function))))
4708 ;;; Gnus Sticky Article Mode
4711 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4712 "Mode for sticky articles."
4713 ;; Release bindings that won't work.
4714 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4715 gnus-sticky-article-mode-map)
4716 (substitute-key-definition 'gnus-article-refer-article 'undefined
4717 gnus-sticky-article-mode-map)
4718 (dolist (k '("e" "h" "s" "F" "R"))
4719 (define-key gnus-sticky-article-mode-map k nil))
4720 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4721 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4722 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4723 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4725 (defun gnus-sticky-article (arg)
4726 "Make the current article sticky.
4727 If a prefix ARG is given, ask for a name for this sticky article buffer."
4728 (interactive "P")
4729 (gnus-summary-show-thread)
4730 (gnus-summary-select-article nil nil 'pseudo)
4731 (let (new-art-buf-name)
4732 (gnus-eval-in-buffer-window gnus-article-buffer
4733 (setq new-art-buf-name
4734 (concat
4735 "*Sticky Article: "
4736 (if arg
4737 (read-from-minibuffer "Sticky article buffer name: ")
4738 (gnus-with-article-headers
4739 (gnus-article-goto-header "subject")
4740 (setq new-art-buf-name
4741 (buffer-substring-no-properties
4742 (line-beginning-position) (line-end-position)))
4743 (goto-char (point-min))
4744 (gnus-article-goto-header "from")
4745 (setq new-art-buf-name
4746 (concat
4747 new-art-buf-name ", "
4748 (buffer-substring-no-properties
4749 (line-beginning-position) (line-end-position))))
4750 (goto-char (point-min))
4751 (gnus-article-goto-header "date")
4752 (setq new-art-buf-name
4753 (concat
4754 new-art-buf-name ", "
4755 (buffer-substring-no-properties
4756 (line-beginning-position) (line-end-position))))))
4757 "*"))
4758 (if (and (gnus-buffer-live-p new-art-buf-name)
4759 (with-current-buffer new-art-buf-name
4760 (eq major-mode 'gnus-sticky-article-mode)))
4761 (switch-to-buffer new-art-buf-name)
4762 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4763 (gnus-sticky-article-mode))
4764 (setq gnus-article-buffer new-art-buf-name))
4765 (gnus-summary-recenter)
4766 (gnus-summary-position-point))
4768 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4769 "Kill the given sticky article BUFFER.
4770 If none is given, assume the current buffer and kill it if it has
4771 `gnus-sticky-article-mode'."
4772 (interactive)
4773 (unless buffer
4774 (setq buffer (current-buffer)))
4775 (with-current-buffer buffer
4776 (when (eq major-mode 'gnus-sticky-article-mode)
4777 (gnus-kill-buffer buffer))))
4779 (defun gnus-kill-sticky-article-buffers (arg)
4780 "Kill all sticky article buffers.
4781 If a prefix ARG is given, ask for confirmation."
4782 (interactive "P")
4783 (dolist (buf (gnus-buffers))
4784 (with-current-buffer buf
4785 (when (eq major-mode 'gnus-sticky-article-mode)
4786 (if (not arg)
4787 (gnus-kill-buffer buf)
4788 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4789 (gnus-kill-buffer buf)))))))
4792 ;;; Gnus MIME viewing functions
4795 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4796 "Format of the MIME buttons.
4798 Valid specifiers include:
4799 %t The MIME type
4800 %T MIME type, along with additional info
4801 %n The `name' parameter
4802 %d The description, if any
4803 %l The length of the encoded part
4804 %p The part identifier number
4805 %e Dots if the part isn't displayed
4807 General format specifiers can also be used. See Info node
4808 `(gnus)Formatting Variables'.")
4810 (defvar gnus-mime-button-line-format-alist
4811 '((?t gnus-tmp-type ?s)
4812 (?T gnus-tmp-type-long ?s)
4813 (?n gnus-tmp-name ?s)
4814 (?d gnus-tmp-description ?s)
4815 (?p gnus-tmp-id ?s)
4816 (?l gnus-tmp-length ?d)
4817 (?e gnus-tmp-dots ?s)))
4819 (defvar gnus-mime-button-commands
4820 '((gnus-article-press-button "\r" "Toggle Display")
4821 (gnus-mime-view-part "v" "View Interactively...")
4822 (gnus-mime-view-part-as-type "t" "View As Type...")
4823 (gnus-mime-view-part-as-charset "C" "View As charset...")
4824 (gnus-mime-save-part "o" "Save...")
4825 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4826 (gnus-mime-replace-part "r" "Replace part")
4827 (gnus-mime-delete-part "d" "Delete part")
4828 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4829 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4830 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4831 (gnus-mime-view-part-externally "e" "View Externally")
4832 (gnus-mime-print-part "p" "Print")
4833 (gnus-mime-pipe-part "|" "Pipe To Command...")
4834 (gnus-mime-action-on-part "." "Take action on the part...")))
4836 (defun gnus-article-mime-part-status ()
4837 (if gnus-article-mime-handle-alist-1
4838 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4839 " (1 part)"
4840 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4841 ""))
4843 (defvar gnus-mime-button-map
4844 (let ((map (make-sparse-keymap)))
4845 (define-key map gnus-mouse-2 'gnus-article-push-button)
4846 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4847 (dolist (c gnus-mime-button-commands)
4848 (define-key map (cadr c) (car c)))
4849 map))
4851 (easy-menu-define
4852 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4853 `("MIME Part"
4854 ,@(mapcar (lambda (c)
4855 (vector (caddr c) (car c) :active t))
4856 gnus-mime-button-commands)))
4858 (defvar gnus-url-button-commands
4859 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4861 (defvar gnus-url-button-map
4862 (let ((map (make-sparse-keymap)))
4863 (dolist (c gnus-url-button-commands)
4864 (define-key map (cadr c) (car c)))
4865 map))
4867 (easy-menu-define
4868 gnus-url-button-menu gnus-url-button-map "URL button menu."
4869 `("Url Button"
4870 ,@(mapcar (lambda (c)
4871 (vector (caddr c) (car c) :active t))
4872 gnus-url-button-commands)))
4874 (defmacro gnus-bind-safe-url-regexp (&rest body)
4875 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4876 `(let ((mm-w3m-safe-url-regexp
4877 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4878 (gnus-buffer-live-p
4879 gnus-article-current-summary))
4880 (with-current-buffer gnus-article-current-summary
4881 gnus-newsgroup-name)
4882 gnus-newsgroup-name)))
4883 (if (cond ((not group)
4884 ;; Maybe we're in a mml-preview buffer
4885 ;; and no group is selected.
4887 ((stringp gnus-safe-html-newsgroups)
4888 (string-match gnus-safe-html-newsgroups group))
4889 ((consp gnus-safe-html-newsgroups)
4890 (member group gnus-safe-html-newsgroups)))
4892 mm-w3m-safe-url-regexp))))
4893 ,@body))
4895 (defun gnus-mime-button-menu (event prefix)
4896 "Construct a context-sensitive menu of MIME commands."
4897 (interactive "e\nP")
4898 (save-window-excursion
4899 (let ((pos (event-start event)))
4900 (select-window (posn-window pos))
4901 (goto-char (posn-point pos))
4902 (gnus-article-check-buffer)
4903 (popup-menu gnus-mime-button-menu nil prefix))))
4905 (defun gnus-mime-view-all-parts (&optional handles)
4906 "View all the MIME parts."
4907 (interactive)
4908 (with-current-buffer gnus-article-buffer
4909 (let ((handles (or handles gnus-article-mime-handles))
4910 (mail-parse-charset gnus-newsgroup-charset)
4911 (mail-parse-ignored-charsets
4912 (with-current-buffer gnus-summary-buffer
4913 gnus-newsgroup-ignored-charsets)))
4914 (when handles
4915 (mm-remove-parts handles)
4916 (goto-char (point-min))
4917 (or (search-forward "\n\n") (goto-char (point-max)))
4918 (let ((inhibit-read-only t))
4919 (delete-region (point) (point-max))
4920 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4922 (defun gnus-article-jump-to-part (n)
4923 "Jump to MIME part N."
4924 (interactive "P")
4925 (let ((parts (with-current-buffer gnus-article-buffer
4926 (length gnus-article-mime-handle-alist))))
4927 (when (zerop parts)
4928 (error "No such part"))
4929 (pop-to-buffer gnus-article-buffer)
4930 (or n
4931 (setq n (if (= parts 1)
4933 (read-number (format "Jump to part (1..%s): " parts)))))
4934 (unless (and (integerp n) (<= n parts) (>= n 1))
4935 (setq n
4936 (progn
4937 (gnus-message 7 "Invalid part `%s', using %s instead."
4938 n parts)
4939 parts)))
4940 (gnus-message 9 "Jumping to part %s." n)
4941 (cond ((>= gnus-auto-select-part 1)
4942 (while (and (<= n parts)
4943 (not (gnus-article-goto-part n)))
4944 (setq n (1+ n))))
4945 ((< gnus-auto-select-part 0)
4946 (while (and (>= n 1)
4947 (not (gnus-article-goto-part n)))
4948 (setq n (1- n))))
4950 (gnus-article-goto-part n)))))
4952 (defvar gnus-mime-buttonized-part-id nil
4953 "ID of a mime part that should be buttonized.
4954 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4956 (eval-when-compile
4957 (defsubst gnus-article-edit-part (handles &optional current-id)
4958 "Edit an article in order to delete a mime part.
4959 This function is exclusively used by `gnus-mime-save-part-and-strip'
4960 and `gnus-mime-delete-part', and not provided at run-time normally."
4961 (gnus-article-edit-article
4962 `(lambda ()
4963 (buffer-disable-undo)
4964 (erase-buffer)
4965 (let ((mail-parse-charset (or gnus-article-charset
4966 ',gnus-newsgroup-charset))
4967 (mail-parse-ignored-charsets
4968 (or gnus-article-ignored-charsets
4969 ',gnus-newsgroup-ignored-charsets))
4970 (mbl mml-buffer-list))
4971 (setq mml-buffer-list nil)
4972 (insert-buffer-substring gnus-original-article-buffer)
4973 (mime-to-mml ',handles)
4974 (setq gnus-article-mime-handles nil)
4975 (let ((mbl1 mml-buffer-list))
4976 (setq mml-buffer-list mbl)
4977 (set (make-local-variable 'mml-buffer-list) mbl1))
4978 (gnus-make-local-hook 'kill-buffer-hook)
4979 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4980 `(lambda (no-highlight)
4981 (let ((mail-parse-charset (or gnus-article-charset
4982 ',gnus-newsgroup-charset))
4983 (message-options message-options)
4984 (message-options-set-recipient)
4985 (mail-parse-ignored-charsets
4986 (or gnus-article-ignored-charsets
4987 ',gnus-newsgroup-ignored-charsets)))
4988 (mml-to-mime)
4989 (mml-destroy-buffers)
4990 (remove-hook 'kill-buffer-hook
4991 'mml-destroy-buffers t)
4992 (kill-local-variable 'mml-buffer-list))
4993 (gnus-summary-edit-article-done
4994 ,(or (mail-header-references gnus-current-headers) "")
4995 ,(gnus-group-read-only-p)
4996 ,gnus-summary-buffer no-highlight))
4998 ;; Force buttonizing this part.
4999 (let ((gnus-mime-buttonized-part-id current-id))
5000 (gnus-article-edit-done))
5001 (gnus-configure-windows 'article)
5002 (when (and current-id (integerp gnus-auto-select-part))
5003 (gnus-article-jump-to-part
5004 (min (max (+ current-id gnus-auto-select-part) 1)
5005 (with-current-buffer gnus-article-buffer
5006 (length gnus-article-mime-handle-alist)))))))
5008 (defun gnus-mime-replace-part (file)
5009 "Replace MIME part under point with an external body."
5010 ;; Useful if file has already been saved to disk
5011 (interactive
5012 (list
5013 (read-file-name "Replace MIME part with file: "
5014 (or mm-default-directory default-directory)
5015 nil nil)))
5016 (gnus-mime-save-part-and-strip file))
5018 (defun gnus-mime-save-part-and-strip (&optional file)
5019 "Save the MIME part under point then replace it with an external body.
5020 If FILE is given, use it for the external part."
5021 (interactive)
5022 (gnus-article-check-buffer)
5023 (when (gnus-group-read-only-p)
5024 (error "The current group does not support deleting of parts"))
5025 (when (mm-complicated-handles gnus-article-mime-handles)
5026 (error "\
5027 The current article has a complicated MIME structure, giving up..."))
5028 (let* ((data (get-text-property (point) 'gnus-data))
5029 (id (get-text-property (point) 'gnus-part))
5030 param
5031 (handles gnus-article-mime-handles))
5032 (unless file
5033 (setq file
5034 (and data (mm-save-part data "Delete MIME part and save to: "))))
5035 (when file
5036 (with-current-buffer (mm-handle-buffer data)
5037 (erase-buffer)
5038 (insert "Content-Type: " (mm-handle-media-type data))
5039 (mml-insert-parameter-string (cdr (mm-handle-type data))
5040 '(charset))
5041 ;; Add a filename for the sake of saving the part again.
5042 (mml-insert-parameter
5043 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5044 (insert "\n")
5045 (insert "Content-ID: " (message-make-message-id) "\n")
5046 (insert "Content-Transfer-Encoding: binary\n")
5047 (insert "\n"))
5048 (setcdr data
5049 (cdr (mm-make-handle nil
5050 `("message/external-body"
5051 (access-type . "LOCAL-FILE")
5052 (name . ,file)))))
5053 ;; (set-buffer gnus-summary-buffer)
5054 (gnus-article-edit-part handles id))))
5056 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5057 ;; parts...>') but with stripping would be nice.
5059 (defun gnus-mime-delete-part ()
5060 "Delete the MIME part under point.
5061 Replace it with some information about the removed part."
5062 (interactive)
5063 (gnus-article-check-buffer)
5064 (when (gnus-group-read-only-p)
5065 (error "The current group does not support deleting of parts"))
5066 (when (mm-complicated-handles gnus-article-mime-handles)
5067 (error "\
5068 The current article has a complicated MIME structure, giving up..."))
5069 (when (or gnus-expert-user
5070 (gnus-yes-or-no-p "\
5071 Deleting parts may malfunction or destroy the article; continue? "))
5072 (let* ((data (get-text-property (point) 'gnus-data))
5073 (id (get-text-property (point) 'gnus-part))
5074 (handles gnus-article-mime-handles)
5075 (description
5076 (let ((desc (mm-handle-description data)))
5077 (when desc
5078 (mail-decode-encoded-word-string desc))))
5079 (filename (or (mm-handle-filename data) "(none)"))
5080 (type (mm-handle-media-type data)))
5081 (unless data
5082 (error "No MIME part under point"))
5083 (with-current-buffer (mm-handle-buffer data)
5084 (let ((bsize (buffer-size)))
5085 (erase-buffer)
5086 (insert
5087 (concat
5088 ",----\n"
5089 "| The following attachment has been deleted:\n"
5090 "|\n"
5091 "| Type: " type "\n"
5092 "| Filename: " filename "\n"
5093 "| Size (encoded): " (format "%s byte%s\n"
5094 bsize (if (= bsize 1)
5096 "s"))
5097 (when description
5098 (concat "| Description: " description "\n"))
5099 "`----\n"))
5100 (setcdr data
5101 (cdr (mm-make-handle
5102 nil `("text/plain" (charset . gnus-decoded)) nil nil
5103 (list "attachment")
5104 (format "Deleted attachment (%s bytes)" bsize))))))
5105 ;; (set-buffer gnus-summary-buffer)
5106 (gnus-article-edit-part handles id))))
5108 (defun gnus-mime-save-part ()
5109 "Save the MIME part under point."
5110 (interactive)
5111 (gnus-article-check-buffer)
5112 (let ((data (get-text-property (point) 'gnus-data)))
5113 (when data
5114 (mm-save-part data))))
5116 (defun gnus-mime-pipe-part (&optional cmd)
5117 "Pipe the MIME part under point to a process.
5118 Use CMD as the process."
5119 (interactive)
5120 (gnus-article-check-buffer)
5121 (let ((data (get-text-property (point) 'gnus-data)))
5122 (when data
5123 (mm-pipe-part data cmd))))
5125 (defun gnus-mime-view-part ()
5126 "Interactively choose a viewing method for the MIME part under point."
5127 (interactive)
5128 (gnus-article-check-buffer)
5129 (let ((data (get-text-property (point) 'gnus-data)))
5130 (when data
5131 (setq gnus-article-mime-handles
5132 (mm-merge-handles
5133 gnus-article-mime-handles (setq data (copy-sequence data))))
5134 (mm-interactively-view-part data))))
5136 (defun gnus-mime-view-part-as-type-internal ()
5137 (gnus-article-check-buffer)
5138 (let* ((handle (get-text-property (point) 'gnus-data))
5139 (name (or
5140 ;; Content-Type: foo/bar; name=...
5141 (mail-content-type-get (mm-handle-type handle) 'name)
5142 ;; Content-Disposition: attachment; filename=...
5143 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5144 (def-type (and name (mm-default-file-encoding name))))
5145 (or (and def-type (cons def-type 0))
5146 (and handle
5147 (equal (mm-handle-media-supertype handle) "text")
5148 '("text/plain" . 0))
5149 '("application/octet-stream" . 0))))
5151 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5152 "Choose a MIME media type, and view the part as such.
5153 If non-nil, PRED is a predicate to use during completion to limit the
5154 available media-types."
5155 (interactive)
5156 (unless mime-type
5157 (setq mime-type
5158 (let ((default (gnus-mime-view-part-as-type-internal)))
5159 (gnus-completing-read
5160 "View as MIME type"
5161 (if pred
5162 (gnus-remove-if-not pred (mailcap-mime-types))
5163 (mailcap-mime-types))
5164 nil nil nil
5165 (car default)))))
5166 (gnus-article-check-buffer)
5167 (let ((handle (get-text-property (point) 'gnus-data)))
5168 (when handle
5169 (when (equal (mm-handle-media-type handle) "message/external-body")
5170 (unless (mm-handle-cache handle)
5171 (mm-extern-cache-contents handle))
5172 (setq handle (mm-handle-cache handle)))
5173 (setq handle
5174 (mm-make-handle (mm-handle-buffer handle)
5175 (cons mime-type (cdr (mm-handle-type handle)))
5176 (mm-handle-encoding handle)
5177 (mm-handle-undisplayer handle)
5178 (mm-handle-disposition handle)
5179 (mm-handle-description handle)
5181 (mm-handle-id handle)))
5182 (setq gnus-article-mime-handles
5183 (mm-merge-handles gnus-article-mime-handles handle))
5184 (when (mm-handle-displayed-p handle)
5185 (mm-remove-part handle))
5186 (gnus-mm-display-part handle))))
5188 (defun gnus-mime-copy-part (&optional handle arg)
5189 "Put the MIME part under point into a new buffer.
5190 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5191 are decompressed."
5192 (interactive (list nil current-prefix-arg))
5193 (gnus-article-check-buffer)
5194 (unless handle
5195 (setq handle (get-text-property (point) 'gnus-data)))
5196 (when handle
5197 (let ((filename (mm-handle-filename handle))
5198 contents dont-decode charset coding-system)
5199 (mm-with-unibyte-buffer
5200 (mm-insert-part handle)
5201 (setq contents (or (condition-case nil
5202 (mm-decompress-buffer filename nil 'sig)
5203 (error
5204 (setq dont-decode t)
5205 nil))
5206 (buffer-string))))
5207 (setq filename (cond (filename (file-name-nondirectory filename))
5208 (dont-decode "*raw data*")
5209 (t "*decoded*")))
5210 (cond
5211 (dont-decode)
5212 ((not arg)
5213 (unless (setq charset (mail-content-type-get
5214 (mm-handle-type handle) 'charset))
5215 (unless (setq coding-system (mm-with-unibyte-buffer
5216 (insert contents)
5217 (mm-find-buffer-file-coding-system)))
5218 (setq charset gnus-newsgroup-charset))))
5219 ((numberp arg)
5220 (setq charset (or (cdr (assq arg
5221 gnus-summary-show-article-charset-alist))
5222 (mm-read-coding-system "Charset: ")))))
5223 (switch-to-buffer (generate-new-buffer filename))
5224 (if (or coding-system
5225 (and charset
5226 (setq coding-system (mm-charset-to-coding-system charset))
5227 (not (eq coding-system 'ascii))))
5228 (progn
5229 (mm-enable-multibyte)
5230 (insert (mm-decode-coding-string contents coding-system))
5231 (setq buffer-file-coding-system
5232 (if (boundp 'last-coding-system-used)
5233 (symbol-value 'last-coding-system-used)
5234 coding-system)))
5235 (mm-disable-multibyte)
5236 (insert contents)
5237 (setq buffer-file-coding-system mm-binary-coding-system))
5238 ;; We do it this way to make `normal-mode' set the appropriate mode.
5239 (unwind-protect
5240 (progn
5241 (setq buffer-file-name (expand-file-name filename))
5242 (normal-mode))
5243 (setq buffer-file-name nil))
5244 (goto-char (point-min)))))
5246 (defun gnus-mime-print-part (&optional handle filename)
5247 "Print the MIME part under point."
5248 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5249 (gnus-article-check-buffer)
5250 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5251 (contents (and handle (mm-get-part handle)))
5252 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5253 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5254 (when contents
5255 (if printer
5256 (unwind-protect
5257 (progn
5258 (mm-save-part-to-file handle file)
5259 (call-process shell-file-name nil
5260 (generate-new-buffer " *mm*")
5262 shell-command-switch
5263 (mm-mailcap-command
5264 printer file (mm-handle-type handle))))
5265 (delete-file file))
5266 (with-temp-buffer
5267 (insert contents)
5268 (gnus-print-buffer))
5269 (ps-despool filename)))))
5271 (defun gnus-mime-inline-part (&optional handle arg)
5272 "Insert the MIME part under point into the current buffer.
5273 Compressed files like .gz and .bz2 are decompressed."
5274 (interactive (list nil current-prefix-arg))
5275 (gnus-article-check-buffer)
5276 (unless handle
5277 (setq handle (get-text-property (point) 'gnus-data)))
5278 (when handle
5279 (let ((b (point))
5280 (inhibit-read-only t)
5281 contents charset coding-system)
5282 (if (and (not arg) (mm-handle-undisplayer handle))
5283 (mm-remove-part handle)
5284 (mm-with-unibyte-buffer
5285 (mm-insert-part handle)
5286 (setq contents
5287 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5288 (buffer-string))))
5289 (cond
5290 ((not arg)
5291 (unless (setq charset (mail-content-type-get
5292 (mm-handle-type handle) 'charset))
5293 (unless (setq coding-system
5294 (mm-with-unibyte-buffer
5295 (insert contents)
5296 (mm-find-buffer-file-coding-system)))
5297 (setq charset gnus-newsgroup-charset))))
5298 ((numberp arg)
5299 (if (mm-handle-undisplayer handle)
5300 (mm-remove-part handle))
5301 (setq charset
5302 (or (cdr (assq arg
5303 gnus-summary-show-article-charset-alist))
5304 (mm-read-coding-system "Charset: "))))
5306 (if (mm-handle-undisplayer handle)
5307 (mm-remove-part handle))))
5308 (forward-line 2)
5309 (mm-display-inline handle)
5310 (goto-char b)))))
5312 (defun gnus-mime-set-charset-parameters (handle charset)
5313 "Set CHARSET to parameters in HANDLE.
5314 CHARSET may either be a string or a symbol."
5315 (unless (stringp charset)
5316 (setq charset (symbol-name charset)))
5317 (if (stringp (car handle))
5318 (dolist (h (cdr handle))
5319 (gnus-mime-set-charset-parameters h charset))
5320 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5321 "message/external-body")
5322 (progn
5323 (unless (mm-handle-cache handle)
5324 (mm-extern-cache-contents handle))
5325 (mm-handle-cache handle))
5326 handle)))
5327 (param (assq 'charset (cdr type))))
5328 (if param
5329 (setcdr param charset)
5330 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5332 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5333 "Insert the MIME part under point into the current buffer using the
5334 specified charset."
5335 (interactive (list nil current-prefix-arg))
5336 (gnus-article-check-buffer)
5337 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5338 (fun (get-text-property (point) 'gnus-callback))
5339 (gnus-newsgroup-ignored-charsets 'gnus-all)
5340 charset form preferred parts)
5341 (when handle
5342 (when (prog1
5343 (and fun
5344 (setq charset
5345 (or (cdr (assq
5347 gnus-summary-show-article-charset-alist))
5348 (mm-read-coding-system "Charset: "))))
5349 (if (mm-handle-undisplayer handle)
5350 (mm-remove-part handle)))
5351 (gnus-mime-set-charset-parameters handle charset)
5352 (when (and (consp (setq form (cdr-safe fun)))
5353 (setq form (ignore-errors
5354 (assq 'gnus-mime-display-alternative form)))
5355 (setq preferred (caddr form))
5356 (progn
5357 (when (eq (car preferred) 'quote)
5358 (setq preferred (cadr preferred)))
5359 (not (equal preferred
5360 (get-text-property (point) 'gnus-data))))
5361 (setq parts (get-text-property (point) 'gnus-part))
5362 (setq parts (cdr (assq parts
5363 gnus-article-mime-handle-alist)))
5364 (equal (mm-handle-media-type parts) "multipart/alternative")
5365 (setq parts (reverse (cdr parts))))
5366 (setcar (cddr form)
5367 (list 'quote (or (cadr (member preferred parts))
5368 (car parts)))))
5369 (funcall fun handle)))))
5371 (defun gnus-mime-view-part-externally (&optional handle)
5372 "View the MIME part under point with an external viewer."
5373 (interactive)
5374 (gnus-article-check-buffer)
5375 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5376 (mm-user-display-methods nil)
5377 (mm-inlined-types nil)
5378 (mail-parse-charset gnus-newsgroup-charset)
5379 (mail-parse-ignored-charsets
5380 (with-current-buffer gnus-summary-buffer
5381 gnus-newsgroup-ignored-charsets))
5382 (type (mm-handle-media-type handle))
5383 (method (mailcap-mime-info type))
5384 (mm-enable-external t))
5385 (if (not (stringp method))
5386 (gnus-mime-view-part-as-type
5387 nil (lambda (type) (stringp (mailcap-mime-info type))))
5388 (when handle
5389 (mm-display-part handle nil t)))))
5391 (defun gnus-mime-view-part-internally (&optional handle)
5392 "View the MIME part under point with an internal viewer.
5393 If no internal viewer is available, use an external viewer."
5394 (interactive)
5395 (gnus-article-check-buffer)
5396 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5397 (mm-inlined-types '(".*"))
5398 (mm-inline-large-images t)
5399 (mail-parse-charset gnus-newsgroup-charset)
5400 (mail-parse-ignored-charsets
5401 (with-current-buffer gnus-summary-buffer
5402 gnus-newsgroup-ignored-charsets))
5403 (inhibit-read-only t))
5404 (if (not (mm-inlinable-p handle))
5405 (gnus-mime-view-part-as-type
5406 nil (lambda (type) (mm-inlinable-p handle type)))
5407 (when handle
5408 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5410 (defun gnus-mime-action-on-part (&optional action)
5411 "Do something with the MIME attachment at \(point\)."
5412 (interactive
5413 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5414 (gnus-article-check-buffer)
5415 (let ((action-pair (assoc action gnus-mime-action-alist)))
5416 (if action-pair
5417 (funcall (cdr action-pair)))))
5419 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5420 "Call FUNCTION on MIME part N.
5421 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5422 If INTERACTIVE, call FUNCTION interactivly."
5423 (let (window frame)
5424 ;; Check whether the article is displayed.
5425 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5426 (setq window (get-buffer-window gnus-article-buffer t))
5427 (frame-visible-p (setq frame (window-frame window))))
5428 (error "No article is displayed"))
5429 (with-current-buffer gnus-article-buffer
5430 ;; Check whether the article displays the right contents.
5431 (unless (with-current-buffer gnus-summary-buffer
5432 (eq gnus-current-article (gnus-summary-article-number)))
5433 (error "You should select the right article first"))
5434 (if n
5435 (setq n (prefix-numeric-value n))
5436 (let ((pt (point)))
5437 (setq n (or (get-text-property pt 'gnus-part)
5438 (and (not (bobp))
5439 (get-text-property (1- pt) 'gnus-part))
5440 (get-text-property (prog2
5441 (forward-line 1)
5442 (point)
5443 (goto-char pt))
5444 'gnus-part)
5445 (get-text-property
5446 (or (and (setq pt (previous-single-property-change
5447 pt 'gnus-part))
5448 (1- pt))
5449 (next-single-property-change (point) 'gnus-part)
5450 (point))
5451 'gnus-part)
5452 1))))
5453 ;; Check whether the specified part exists.
5454 (when (> n (length gnus-article-mime-handle-alist))
5455 (error "No such part")))
5456 (unless
5457 (progn
5458 ;; To select the window is needed so that the cursor
5459 ;; might be visible on the MIME button.
5460 (select-window (prog1
5461 window
5462 (setq window (selected-window))
5463 ;; Article may be displayed in the other frame.
5464 (gnus-select-frame-set-input-focus
5465 (prog1
5466 frame
5467 (setq frame (selected-frame))))))
5468 (when (gnus-article-goto-part n)
5469 ;; We point the cursor and the arrow at the MIME button
5470 ;; when the `function' prompt the user for something.
5471 (unless (and (pos-visible-in-window-p)
5472 (> (count-lines (point) (window-end))
5473 (/ (1- (window-height)) 3)))
5474 (recenter (/ (1- (window-height)) 3)))
5475 (let ((cursor-in-non-selected-windows t)
5476 (overlay-arrow-string "=>")
5477 (overlay-arrow-position (point-marker)))
5478 (unwind-protect
5479 (cond
5480 ((and no-handle interactive)
5481 (call-interactively function))
5482 (no-handle
5483 (funcall function))
5484 (interactive
5485 (call-interactively
5486 function (get-text-property (point) 'gnus-data)))
5488 (funcall function
5489 (get-text-property (point) 'gnus-data))))
5490 (set-marker overlay-arrow-position nil)
5491 (unless gnus-auto-select-part
5492 (gnus-select-frame-set-input-focus frame)
5493 (select-window window))))
5495 (if gnus-inhibit-mime-unbuttonizing
5496 ;; This is the default though the program shouldn't reach here.
5497 (error "No such part")
5498 ;; The part which doesn't have the MIME button is selected.
5499 ;; So, we display all the buttons and redo it.
5500 (let ((gnus-inhibit-mime-unbuttonizing t))
5501 (gnus-summary-show-article)
5502 (gnus-article-part-wrapper n function no-handle))))))
5504 (defun gnus-article-pipe-part (n)
5505 "Pipe MIME part N, which is the numerical prefix."
5506 (interactive "P")
5507 (gnus-article-part-wrapper n 'mm-pipe-part))
5509 (defun gnus-article-save-part (n)
5510 "Save MIME part N, which is the numerical prefix."
5511 (interactive "P")
5512 (gnus-article-part-wrapper n 'mm-save-part))
5514 (defun gnus-article-interactively-view-part (n)
5515 "View MIME part N interactively, which is the numerical prefix."
5516 (interactive "P")
5517 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5519 (defun gnus-article-copy-part (n)
5520 "Copy MIME part N, which is the numerical prefix."
5521 (interactive "P")
5522 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5524 (defun gnus-article-view-part-as-charset (n)
5525 "View MIME part N using a specified charset.
5526 N is the numerical prefix."
5527 (interactive "P")
5528 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5530 (defun gnus-article-view-part-externally (n)
5531 "View MIME part N externally, which is the numerical prefix."
5532 (interactive "P")
5533 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5535 (defun gnus-article-inline-part (n)
5536 "Inline MIME part N, which is the numerical prefix."
5537 (interactive "P")
5538 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5540 (defun gnus-article-save-part-and-strip (n)
5541 "Save MIME part N and replace it with an external body.
5542 N is the numerical prefix."
5543 (interactive "P")
5544 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5546 (defun gnus-article-replace-part (n)
5547 "Replace MIME part N with an external body.
5548 N is the numerical prefix."
5549 (interactive "P")
5550 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5552 (defun gnus-article-delete-part (n)
5553 "Delete MIME part N and add some information about the removed part.
5554 N is the numerical prefix."
5555 (interactive "P")
5556 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5558 (defun gnus-article-view-part-as-type (n)
5559 "Choose a MIME media type, and view part N as such.
5560 N is the numerical prefix."
5561 (interactive "P")
5562 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5564 (defun gnus-article-mime-match-handle-first (condition)
5565 (if condition
5566 (let (n)
5567 (dolist (ihandle gnus-article-mime-handle-alist)
5568 (if (and (cond
5569 ((functionp condition)
5570 (funcall condition (cdr ihandle)))
5571 ((eq condition 'undisplayed)
5572 (not (or (mm-handle-undisplayer (cdr ihandle))
5573 (equal (mm-handle-media-type (cdr ihandle))
5574 "multipart/alternative"))))
5575 ((eq condition 'undisplayed-alternative)
5576 (not (mm-handle-undisplayer (cdr ihandle))))
5577 (t t))
5578 (gnus-article-goto-part (car ihandle))
5579 (or (not n) (< (car ihandle) n)))
5580 (setq n (car ihandle))))
5581 (or n 1))
5584 (defun gnus-article-view-part (&optional n)
5585 "View MIME part N, which is the numerical prefix.
5586 If the part is already shown, hide the part. If N is nil, view
5587 all parts."
5588 (interactive "P")
5589 (with-current-buffer gnus-article-buffer
5590 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5591 gnus-article-mime-match-handle-function)))
5592 (when (> n (length gnus-article-mime-handle-alist))
5593 (error "No such part"))
5594 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5595 (when (gnus-article-goto-part n)
5596 (if (equal (car handle) "multipart/alternative")
5597 (gnus-article-press-button)
5598 (when (eq (gnus-mm-display-part handle) 'internal)
5599 (gnus-set-window-start)))))))
5601 (defsubst gnus-article-mime-total-parts ()
5602 (if (bufferp (car gnus-article-mime-handles))
5603 1 ;; single part
5604 (1- (length gnus-article-mime-handles))))
5606 (defun gnus-mm-display-part (handle)
5607 "Display HANDLE and fix MIME button."
5608 (let ((id (get-text-property (point) 'gnus-part))
5609 (point (point))
5610 (inhibit-read-only t))
5611 (forward-line 1)
5612 (prog1
5613 (let ((window (selected-window))
5614 (mail-parse-charset gnus-newsgroup-charset)
5615 (mail-parse-ignored-charsets
5616 (if (gnus-buffer-live-p gnus-summary-buffer)
5617 (with-current-buffer gnus-summary-buffer
5618 gnus-newsgroup-ignored-charsets)
5619 nil)))
5620 (save-excursion
5621 (unwind-protect
5622 (let ((win (gnus-get-buffer-window (current-buffer) t))
5623 (beg (point)))
5624 (when win
5625 (select-window win))
5626 (goto-char point)
5627 (forward-line)
5628 (if (mm-handle-displayed-p handle)
5629 ;; This will remove the part.
5630 (mm-display-part handle)
5631 (save-restriction
5632 (narrow-to-region (point)
5633 (if (eobp) (point) (1+ (point))))
5634 (gnus-bind-safe-url-regexp (mm-display-part handle))
5635 ;; We narrow to the part itself and
5636 ;; then call the treatment functions.
5637 (goto-char (point-min))
5638 (forward-line 1)
5639 (narrow-to-region (point) (point-max))
5640 (gnus-treat-article
5641 nil id
5642 (gnus-article-mime-total-parts)
5643 (mm-handle-media-type handle)))))
5644 (if (window-live-p window)
5645 (select-window window)))))
5646 (goto-char point)
5647 (gnus-delete-line)
5648 (gnus-insert-mime-button
5649 handle id (list (mm-handle-displayed-p handle)))
5650 (goto-char point))))
5652 (defun gnus-article-goto-part (n)
5653 "Go to MIME part N."
5654 (when gnus-break-pages
5655 (widen))
5656 (prog1
5657 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5658 part handle end next handles)
5659 (when start
5660 (goto-char start)
5661 (if (setq handle (get-text-property start 'gnus-data))
5662 start
5663 ;; Go to the displayed subpart, assuming this is
5664 ;; multipart/alternative.
5665 (setq part start
5666 end (point-at-eol))
5667 (while (and (not handle)
5668 part
5669 (< part end)
5670 (setq next (text-property-not-all part end
5671 'gnus-data nil)))
5672 (setq part next
5673 handle (get-text-property part 'gnus-data))
5674 (push (cons handle part) handles)
5675 (unless (mm-handle-displayed-p handle)
5676 (setq handle nil
5677 part (text-property-any part end 'gnus-data nil))))
5678 (unless handle
5679 ;; No subpart is displayed, so we find preferred one.
5680 (setq part
5681 (cdr (assq (mm-preferred-alternative
5682 (nreverse (mapcar 'car handles)))
5683 handles))))
5684 (if part
5685 (goto-char (1+ part))
5686 start))))
5687 (when gnus-break-pages
5688 (gnus-narrow-to-page))))
5690 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5691 (let ((gnus-tmp-name
5692 (or (mm-handle-filename handle)
5693 (mail-content-type-get (mm-handle-type handle) 'url)
5694 ""))
5695 (gnus-tmp-type (mm-handle-media-type handle))
5696 (gnus-tmp-description (or (mm-handle-description handle) ""))
5697 (gnus-tmp-dots
5698 (if (if displayed (car displayed)
5699 (mm-handle-displayed-p handle))
5700 "" "..."))
5701 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5702 (buffer-size)))
5703 gnus-tmp-type-long b e)
5704 (when (string-match ".*/" gnus-tmp-name)
5705 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5706 (setq gnus-tmp-type-long (concat gnus-tmp-type
5707 (and (not (equal gnus-tmp-name ""))
5708 (concat "; " gnus-tmp-name))))
5709 (unless (equal gnus-tmp-description "")
5710 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5711 (unless (bolp)
5712 (insert "\n"))
5713 (setq b (point))
5714 (gnus-eval-format
5715 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5716 `(keymap ,gnus-mime-button-map
5717 gnus-callback gnus-mm-display-part
5718 gnus-part ,gnus-tmp-id
5719 article-type annotation
5720 gnus-data ,handle
5721 rear-nonsticky t))
5722 (setq e (if (bolp)
5723 ;; Exclude a newline.
5724 (1- (point))
5725 (point)))
5726 (when gnus-article-button-face
5727 (gnus-overlay-put (gnus-make-overlay b e nil t)
5728 'face gnus-article-button-face))
5729 (widget-convert-button
5730 'link b e
5731 :mime-handle handle
5732 :action 'gnus-widget-press-button
5733 :button-keymap gnus-mime-button-map
5734 :help-echo
5735 (lambda (widget)
5736 ;; Needed to properly clear the message due to a bug in
5737 ;; wid-edit (XEmacs only).
5738 (if (boundp 'help-echo-owns-message)
5739 (setq help-echo-owns-message t))
5740 (format
5741 "%S: %s the MIME part; %S: more options"
5742 (aref gnus-mouse-2 0)
5743 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5744 "hide" "show")
5745 (aref gnus-down-mouse-3 0))))))
5747 (defun gnus-widget-press-button (elems el)
5748 (goto-char (widget-get elems :from))
5749 (gnus-article-press-button))
5751 (defvar gnus-displaying-mime nil)
5753 (defun gnus-display-mime (&optional ihandles)
5754 "Display the MIME parts."
5755 (save-excursion
5756 (save-selected-window
5757 (let ((window (get-buffer-window gnus-article-buffer))
5758 (point (point)))
5759 (when window
5760 (select-window window)
5761 ;; We have to do this since selecting the window
5762 ;; may change the point. So we set the window point.
5763 (set-window-point window point)))
5764 (let ((handles ihandles)
5765 (inhibit-read-only t)
5766 handle)
5767 (cond (handles)
5768 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5769 (when gnus-article-emulate-mime
5770 (mm-uu-dissect-text-parts handles)))
5771 (gnus-article-emulate-mime
5772 (setq handles (mm-uu-dissect))))
5773 (when (and (not ihandles)
5774 (not gnus-displaying-mime))
5775 ;; Top-level call; we clean up.
5776 (when gnus-article-mime-handles
5777 (mm-destroy-parts gnus-article-mime-handles)
5778 (setq gnus-article-mime-handle-alist nil));; A trick.
5779 (setq gnus-article-mime-handles handles)
5780 ;; We allow users to glean info from the handles.
5781 (when gnus-article-mime-part-function
5782 (gnus-mime-part-function handles)))
5783 (if (and handles
5784 (or (not (stringp (car handles)))
5785 (cdr handles)))
5786 (progn
5787 (when (and (not ihandles)
5788 (not gnus-displaying-mime))
5789 ;; Clean up for mime parts.
5790 (article-goto-body)
5791 (delete-region (point) (point-max)))
5792 (let ((gnus-displaying-mime t))
5793 (gnus-mime-display-part handles)))
5794 (save-restriction
5795 (article-goto-body)
5796 (narrow-to-region (point) (point-max))
5797 (gnus-treat-article nil 1 1 "text/plain")
5798 (widen)))
5799 (unless ihandles
5800 ;; Highlight the headers.
5801 (save-excursion
5802 (save-restriction
5803 (article-goto-body)
5804 (narrow-to-region (point-min) (point))
5805 (gnus-article-save-original-date
5806 (gnus-treat-article 'head)))))))
5807 ;; Cope with broken MIME messages.
5808 (goto-char (point-max))
5809 (unless (bolp)
5810 (insert "\n"))))
5812 (defcustom gnus-mime-display-multipart-as-mixed nil
5813 "Display \"multipart\" parts as \"multipart/mixed\".
5815 If t, it overrides nil values of
5816 `gnus-mime-display-multipart-alternative-as-mixed' and
5817 `gnus-mime-display-multipart-related-as-mixed'."
5818 :group 'gnus-article-mime
5819 :type 'boolean)
5821 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5822 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5823 :version "22.1"
5824 :group 'gnus-article-mime
5825 :type 'boolean)
5827 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5828 "Display \"multipart/related\" parts as \"multipart/mixed\".
5830 If displaying \"text/html\" is discouraged \(see
5831 `mm-discouraged-alternatives'\) images or other material inside a
5832 \"multipart/related\" part might be overlooked when this variable is nil."
5833 :version "22.1"
5834 :group 'gnus-article-mime
5835 :type 'boolean)
5837 (defun gnus-mime-display-part (handle)
5838 (cond
5839 ;; Maybe a broken MIME message.
5840 ((null handle))
5841 ;; Single part.
5842 ((not (stringp (car handle)))
5843 (gnus-mime-display-single handle))
5844 ;; User-defined multipart
5845 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5846 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5847 handle))
5848 ;; multipart/alternative
5849 ((and (equal (car handle) "multipart/alternative")
5850 (not (or gnus-mime-display-multipart-as-mixed
5851 gnus-mime-display-multipart-alternative-as-mixed)))
5852 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5853 (push (cons id handle) gnus-article-mime-handle-alist)
5854 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5855 ;; multipart/related
5856 ((and (equal (car handle) "multipart/related")
5857 (not (or gnus-mime-display-multipart-as-mixed
5858 gnus-mime-display-multipart-related-as-mixed)))
5859 ;;;!!!We should find the start part, but we just default
5860 ;;;!!!to the first part.
5861 ;;(gnus-mime-display-part (cadr handle))
5862 ;;;!!! Most multipart/related is an HTML message plus images.
5863 ;;;!!! Unfortunately we are unable to let W3 display those
5864 ;;;!!! included images, so we just display it as a mixed multipart.
5865 ;;(gnus-mime-display-mixed (cdr handle))
5866 ;;;!!! No, w3 can display everything just fine.
5867 (gnus-mime-display-part (cadr handle)))
5868 ((equal (car handle) "multipart/signed")
5869 (gnus-add-wash-type 'signed)
5870 (gnus-mime-display-security handle))
5871 ((equal (car handle) "multipart/encrypted")
5872 (gnus-add-wash-type 'encrypted)
5873 (gnus-mime-display-security handle))
5874 ;; Other multiparts are handled like multipart/mixed.
5876 (gnus-mime-display-mixed (cdr handle)))))
5878 (defun gnus-mime-part-function (handles)
5879 (if (stringp (car handles))
5880 (mapcar 'gnus-mime-part-function (cdr handles))
5881 (funcall gnus-article-mime-part-function handles)))
5883 (defun gnus-mime-display-mixed (handles)
5884 (mapcar 'gnus-mime-display-part handles))
5886 (defun gnus-mime-display-single (handle)
5887 (let ((type (mm-handle-media-type handle))
5888 (ignored gnus-ignored-mime-types)
5889 (not-attachment t)
5890 (move nil)
5891 display text)
5892 (catch 'ignored
5893 (progn
5894 (while ignored
5895 (when (string-match (pop ignored) type)
5896 (throw 'ignored nil)))
5897 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5898 (with-current-buffer gnus-summary-buffer
5899 gnus-inhibit-images)
5900 gnus-inhibit-images)
5901 (string-match "\\`image/" type)))
5902 (setq not-attachment
5903 (and (not (mm-inline-override-p handle))
5904 (or (not (mm-handle-disposition handle))
5905 (equal (car (mm-handle-disposition handle))
5906 "inline")
5907 (mm-attachment-override-p handle))))
5908 (mm-automatic-display-p handle)
5909 (or (and
5910 (mm-inlinable-p handle)
5911 (mm-inlined-p handle))
5912 (mm-automatic-external-display-p type)))
5913 (setq display t)
5914 (when (equal (mm-handle-media-supertype handle) "text")
5915 (setq text t)))
5916 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5917 beg)
5918 (push (cons id handle) gnus-article-mime-handle-alist)
5919 (when (and display
5920 (equal (mm-handle-media-supertype handle) "message"))
5921 (insert-char
5923 (cond ((not (bolp)) 2)
5924 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5925 (t 1))))
5926 (when (or (not display)
5927 (not (gnus-unbuttonized-mime-type-p type))
5928 (eq id gnus-mime-buttonized-part-id))
5929 (gnus-insert-mime-button
5930 handle id (list (or display (and not-attachment text))))
5931 (gnus-article-insert-newline)
5932 ;; Remember modify the number of forward lines.
5933 (setq move t))
5934 (setq beg (point))
5935 (cond
5936 (display
5937 (when move
5938 (forward-line -1)
5939 (setq beg (point)))
5940 (let ((mail-parse-charset gnus-newsgroup-charset)
5941 (mail-parse-ignored-charsets
5942 (save-excursion (condition-case ()
5943 (set-buffer gnus-summary-buffer)
5944 (error))
5945 gnus-newsgroup-ignored-charsets)))
5946 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5947 (goto-char (point-max)))
5948 ((and text not-attachment)
5949 (when move
5950 (forward-line -1)
5951 (setq beg (point)))
5952 (gnus-article-insert-newline)
5953 (mm-display-inline handle)
5954 (goto-char (point-max))))
5955 ;; Do highlighting.
5956 (save-excursion
5957 (save-restriction
5958 (narrow-to-region beg (point))
5959 (if (eq handle gnus-article-mime-handles)
5960 ;; The format=flowed case.
5961 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5962 ;; Don't count signature parts that are never displayed.
5963 ;; The part number should be re-calculated supposing this
5964 ;; might be a message/rfc822 part.
5965 (let (handles)
5966 (dolist (part gnus-article-mime-handles)
5967 (unless (or (stringp part)
5968 (equal (car (mm-handle-type part))
5969 "application/pgp-signature"))
5970 (push part handles)))
5971 (gnus-treat-article
5972 nil (length (memq handle handles)) (length handles)
5973 (mm-handle-media-type handle)))))))))))
5975 (defun gnus-unbuttonized-mime-type-p (type)
5976 "Say whether TYPE is to be unbuttonized."
5977 (unless gnus-inhibit-mime-unbuttonizing
5978 (when (catch 'found
5979 (let ((types gnus-unbuttonized-mime-types))
5980 (while types
5981 (when (string-match (pop types) type)
5982 (throw 'found t)))))
5983 (not (catch 'found
5984 (let ((types gnus-buttonized-mime-types))
5985 (while types
5986 (when (string-match (pop types) type)
5987 (throw 'found t)))))))))
5989 (defun gnus-article-insert-newline ()
5990 "Insert a newline, but mark it as undeletable."
5991 (gnus-put-text-property
5992 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5994 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5995 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5996 (ihandles handles)
5997 (point (point))
5998 handle (inhibit-read-only t) from props begend not-pref)
5999 (save-window-excursion
6000 (save-restriction
6001 (when ibegend
6002 (narrow-to-region (car ibegend)
6003 (or (cdr ibegend)
6004 (progn
6005 (goto-char (car ibegend))
6006 (forward-line 2)
6007 (point))))
6008 (delete-region (point-min) (point-max))
6009 (mm-remove-parts handles))
6010 (setq begend (list (point-marker)))
6011 ;; Do the toggle.
6012 (unless (setq not-pref (cadr (member preferred ihandles)))
6013 (setq not-pref (car ihandles)))
6014 (when (or ibegend
6015 (not preferred)
6016 (not (gnus-unbuttonized-mime-type-p
6017 "multipart/alternative")))
6018 (gnus-add-text-properties
6019 (setq from (point))
6020 (progn
6021 (insert (format "%d. " id))
6022 (point))
6023 `(gnus-callback
6024 (lambda (handles)
6025 (unless ,(not ibegend)
6026 (setq gnus-article-mime-handle-alist
6027 ',gnus-article-mime-handle-alist))
6028 (gnus-mime-display-alternative
6029 ',ihandles ',not-pref ',begend ,id))
6030 keymap ,gnus-mime-button-map
6031 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6032 face ,gnus-article-button-face
6033 gnus-part ,id
6034 article-type multipart
6035 rear-nonsticky t))
6036 (widget-convert-button 'link from (point)
6037 :action 'gnus-widget-press-button
6038 :button-keymap gnus-widget-button-keymap)
6039 ;; Do the handles
6040 (while (setq handle (pop handles))
6041 (gnus-add-text-properties
6042 (setq from (point))
6043 (progn
6044 (insert (format "(%c) %-18s"
6045 (if (equal handle preferred) ?* ? )
6046 (mm-handle-media-type handle)))
6047 (point))
6048 `(gnus-callback
6049 (lambda (handles)
6050 (unless ,(not ibegend)
6051 (setq gnus-article-mime-handle-alist
6052 ',gnus-article-mime-handle-alist))
6053 (gnus-mime-display-alternative
6054 ',ihandles ',handle ',begend ,id))
6055 keymap ,gnus-mime-button-map
6056 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6057 face ,gnus-article-button-face
6058 gnus-part ,id
6059 gnus-data ,handle
6060 rear-nonsticky t))
6061 (widget-convert-button 'link from (point)
6062 :action 'gnus-widget-press-button
6063 :button-keymap gnus-widget-button-keymap)
6064 (insert " "))
6065 (insert "\n\n"))
6066 (when preferred
6067 (if (stringp (car preferred))
6068 (gnus-display-mime preferred)
6069 (let ((mail-parse-charset gnus-newsgroup-charset)
6070 (mail-parse-ignored-charsets
6071 (with-current-buffer gnus-summary-buffer
6072 gnus-newsgroup-ignored-charsets)))
6073 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6074 ;; Do highlighting.
6075 (save-excursion
6076 (save-restriction
6077 (narrow-to-region (car begend) (point-max))
6078 (gnus-treat-article
6079 nil (length gnus-article-mime-handle-alist)
6080 (gnus-article-mime-total-parts)
6081 (mm-handle-media-type preferred))))))
6082 (goto-char (point-max))
6083 (setcdr begend (point-marker)))))
6084 (when ibegend
6085 (goto-char point))))
6087 (defconst gnus-article-wash-status-strings
6088 (let ((alist '((cite "c" "Possible hidden citation text"
6089 " " "All citation text visible")
6090 (headers "h" "Hidden headers"
6091 " " "All headers visible.")
6092 (pgp "p" "Encrypted or signed message status hidden"
6093 " " "No hidden encryption nor digital signature status")
6094 (signature "s" "Signature has been hidden"
6095 " " "Signature is visible")
6096 (overstrike "o" "Overstrike (^H) characters applied"
6097 " " "No overstrike characters applied")
6098 (emphasis "e" "/*_Emphasis_*/ characters applied"
6099 " " "No /*_emphasis_*/ characters applied")))
6100 result)
6101 (dolist (entry alist result)
6102 (let ((key (nth 0 entry))
6103 (on (copy-sequence (nth 1 entry)))
6104 (on-help (nth 2 entry))
6105 (off (copy-sequence (nth 3 entry)))
6106 (off-help (nth 4 entry)))
6107 (put-text-property 0 1 'help-echo on-help on)
6108 (put-text-property 0 1 'help-echo off-help off)
6109 (push (list key on off) result))))
6110 "Alist of strings describing wash status in the mode line.
6111 Each entry has the form (KEY ON OF), where the KEY is a symbol
6112 representing the particular washing function, ON is the string to use
6113 in the article mode line when the washing function is active, and OFF
6114 is the string to use when it is inactive.")
6116 (defun gnus-article-wash-status-entry (key value)
6117 (let ((entry (assoc key gnus-article-wash-status-strings)))
6118 (if value (nth 1 entry) (nth 2 entry))))
6120 (defun gnus-article-wash-status ()
6121 "Return a string which display status of article washing."
6122 (with-current-buffer gnus-article-buffer
6123 (let ((cite (memq 'cite gnus-article-wash-types))
6124 (headers (memq 'headers gnus-article-wash-types))
6125 (boring (memq 'boring-headers gnus-article-wash-types))
6126 (pgp (memq 'pgp gnus-article-wash-types))
6127 (pem (memq 'pem gnus-article-wash-types))
6128 (signed (memq 'signed gnus-article-wash-types))
6129 (encrypted (memq 'encrypted gnus-article-wash-types))
6130 (signature (memq 'signature gnus-article-wash-types))
6131 (overstrike (memq 'overstrike gnus-article-wash-types))
6132 (emphasis (memq 'emphasis gnus-article-wash-types)))
6133 (concat
6134 (gnus-article-wash-status-entry 'cite cite)
6135 (gnus-article-wash-status-entry 'headers (or headers boring))
6136 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6137 (gnus-article-wash-status-entry 'signature signature)
6138 (gnus-article-wash-status-entry 'overstrike overstrike)
6139 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6141 (defun gnus-add-wash-type (type)
6142 "Add a washing of TYPE to the current status."
6143 (add-to-list 'gnus-article-wash-types type))
6145 (defun gnus-delete-wash-type (type)
6146 "Add a washing of TYPE to the current status."
6147 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6149 (defun gnus-add-image (category image)
6150 "Add IMAGE of CATEGORY to the list of displayed images."
6151 (let ((entry (assq category gnus-article-image-alist)))
6152 (unless entry
6153 (setq entry (list category))
6154 (push entry gnus-article-image-alist))
6155 (nconc entry (list image))))
6157 (defun gnus-delete-images (category)
6158 "Delete all images in CATEGORY."
6159 (let ((entry (assq category gnus-article-image-alist)))
6160 (dolist (image (cdr entry))
6161 (gnus-remove-image image category))
6162 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6163 (gnus-delete-wash-type category)))
6165 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6167 (defun gnus-article-maybe-hide-headers ()
6168 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6169 Provided for backwards compatibility."
6170 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6171 (not (with-current-buffer gnus-summary-buffer
6172 gnus-have-all-headers)))
6173 (not gnus-inhibit-hiding))
6174 (gnus-article-hide-headers)))
6176 (declare-function shr-put-image "shr" (data alt))
6178 (defun gnus-shr-put-image (data alt)
6179 "Put image DATA with a string ALT. Enable image to be deleted."
6180 (let ((image (shr-put-image data (propertize (or alt "*")
6181 'gnus-image-category 'shr))))
6182 (when image
6183 (gnus-add-image 'shr image))))
6185 ;;; Article savers.
6187 (defun gnus-output-to-file (file-name)
6188 "Append the current article to a file named FILE-NAME.
6189 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6190 text and used as the value of the coding cookie which is added to the
6191 top of a file. Otherwise, this function saves a raw article without
6192 the coding cookie."
6193 (let* ((artbuf (current-buffer))
6194 (file-name-coding-system nnmail-pathname-coding-system)
6195 (coding gnus-article-save-coding-system)
6196 (coding-system-for-read (if coding
6197 nil ;; Rely on the coding cookie.
6198 mm-text-coding-system))
6199 (coding-system-for-write (or coding
6200 mm-text-coding-system-for-write
6201 mm-text-coding-system))
6202 (exists (file-exists-p file-name)))
6203 (with-temp-buffer
6204 (when exists
6205 (insert-file-contents file-name)
6206 (goto-char (point-min))
6207 ;; Remove the existing coding cookie.
6208 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6209 (delete-region (match-beginning 0) (match-end 0))))
6210 (goto-char (point-max))
6211 (insert-buffer-substring artbuf)
6212 ;; Append newline at end of the buffer as separator, and then
6213 ;; save it to file.
6214 (goto-char (point-max))
6215 (insert "\n")
6216 (when coding
6217 ;; If the coding system is not suitable to encode the text,
6218 ;; ask a user for a proper one.
6219 (when (fboundp 'select-safe-coding-system)
6220 (setq coding (coding-system-base
6221 (save-window-excursion
6222 (select-safe-coding-system (point-min) (point-max)
6223 coding))))
6224 (setq coding-system-for-write
6225 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6226 coding)))
6227 (goto-char (point-min))
6228 ;; Add the coding cookie.
6229 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6230 coding-system-for-write)))
6231 (if exists
6232 (progn
6233 (write-region (point-min) (point-max) file-name nil 'no-message)
6234 (message "Appended to %s" file-name))
6235 (write-region (point-min) (point-max) file-name))))
6238 (defun gnus-narrow-to-page (&optional arg)
6239 "Narrow the article buffer to a page.
6240 If given a numerical ARG, move forward ARG pages."
6241 (interactive "P")
6242 (setq arg (if arg (prefix-numeric-value arg) 0))
6243 (with-current-buffer gnus-article-buffer
6244 (widen)
6245 ;; Remove any old next/prev buttons.
6246 (when (gnus-visual-p 'page-marker)
6247 (let ((inhibit-read-only t))
6248 (gnus-remove-text-with-property 'gnus-prev)
6249 (gnus-remove-text-with-property 'gnus-next)))
6250 (let (st nd pt)
6251 (when (save-excursion
6252 (cond ((< arg 0)
6253 (if (re-search-backward page-delimiter nil 'move (abs arg))
6254 (prog1
6255 (setq nd (match-beginning 0)
6256 pt nd)
6257 (when (re-search-backward page-delimiter nil t)
6258 (setq st (match-end 0))))
6259 (when (re-search-forward page-delimiter nil t)
6260 (setq nd (match-beginning 0)
6261 pt (point-min)))))
6262 ((> arg 0)
6263 (if (re-search-forward page-delimiter nil 'move arg)
6264 (prog1
6265 (setq st (match-end 0)
6266 pt st)
6267 (when (re-search-forward page-delimiter nil t)
6268 (setq nd (match-beginning 0))))
6269 (when (re-search-backward page-delimiter nil t)
6270 (setq st (match-end 0)
6271 pt (point-max)))))
6273 (when (re-search-backward page-delimiter nil t)
6274 (goto-char (setq st (match-end 0))))
6275 (when (re-search-forward page-delimiter nil t)
6276 (setq nd (match-beginning 0)))
6277 (or st nd))))
6278 (setq gnus-page-broken t)
6279 (when pt (goto-char pt))
6280 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6281 (when (gnus-visual-p 'page-marker)
6282 (save-excursion
6283 (when nd
6284 (goto-char nd)
6285 (gnus-insert-next-page-button))
6286 (when st
6287 (goto-char st)
6288 (gnus-insert-prev-page-button))))))))
6290 ;; Article mode commands
6292 (defun gnus-article-goto-next-page ()
6293 "Show the next page of the article."
6294 (interactive)
6295 (when (gnus-article-next-page)
6296 (goto-char (point-min))
6297 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6300 (defun gnus-article-goto-prev-page ()
6301 "Show the previous page of the article."
6302 (interactive)
6303 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6304 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6305 (gnus-article-prev-page nil)))
6307 ;; This is cleaner but currently breaks `gnus-pick-mode':
6309 ;; (defun gnus-article-goto-next-page ()
6310 ;; "Show the next page of the article."
6311 ;; (interactive)
6312 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6313 ;; (gnus-summary-next-page)))
6315 ;; (defun gnus-article-goto-prev-page ()
6316 ;; "Show the next page of the article."
6317 ;; (interactive)
6318 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6319 ;; (gnus-summary-prev-page)))
6321 (defun gnus-article-next-page (&optional lines)
6322 "Show the next page of the current article.
6323 If end of article, return non-nil. Otherwise return nil.
6324 Argument LINES specifies lines to be scrolled up."
6325 (interactive "p")
6326 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6327 (if (and (not (and gnus-article-over-scroll
6328 (> (count-lines (window-start) (point-max))
6329 (if (featurep 'xemacs)
6330 (or lines (1- (window-height)))
6331 (+ (or lines (1- (window-height))) scroll-margin)))))
6332 (save-excursion
6333 (end-of-line)
6334 (and (pos-visible-in-window-p) ;Not continuation line.
6335 (>= (point) (point-max)))))
6336 ;; Nothing in this page.
6337 (if (or (not gnus-page-broken)
6338 (save-excursion
6339 (save-restriction
6340 (widen)
6341 (forward-line)
6342 (eobp)))) ;Real end-of-buffer?
6343 (progn
6344 (when gnus-article-over-scroll
6345 (gnus-article-next-page-1 lines))
6346 t) ;Nothing more.
6347 (gnus-narrow-to-page 1) ;Go to next page.
6348 nil)
6349 ;; More in this page.
6350 (gnus-article-next-page-1 lines)
6351 nil))
6353 (defun gnus-article-beginning-of-window ()
6354 "Move point to the beginning of the window.
6355 In Emacs, the point is placed at the line number which `scroll-margin'
6356 specifies."
6357 (if (featurep 'xemacs)
6358 (move-to-window-line 0)
6359 ;; There is an obscure bug in Emacs that makes it impossible to
6360 ;; scroll past big pictures in the article buffer. Try to fix
6361 ;; this by adding a sanity check by counting the lines visible.
6362 (when (> (count-lines (window-start) (window-end)) 30)
6363 (move-to-window-line
6364 (min (max 0 scroll-margin)
6365 (max 1 (- (window-height)
6366 (if mode-line-format 1 0)
6367 (if header-line-format 1 0)
6368 2)))))))
6370 (defun gnus-article-next-page-1 (lines)
6371 (condition-case ()
6372 (let ((scroll-in-place nil)
6373 (auto-window-vscroll nil))
6374 (scroll-up lines))
6375 (end-of-buffer
6376 ;; Long lines may cause an end-of-buffer error.
6377 (goto-char (point-max))))
6378 (gnus-article-beginning-of-window))
6380 (defun gnus-article-prev-page (&optional lines)
6381 "Show previous page of current article.
6382 Argument LINES specifies lines to be scrolled down."
6383 (interactive "p")
6384 (move-to-window-line 0)
6385 (if (and gnus-page-broken
6386 (bobp)
6387 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6388 (progn
6389 (gnus-narrow-to-page -1) ;Go to previous page.
6390 (goto-char (point-max))
6391 (recenter (if gnus-article-over-scroll
6392 (if lines
6393 (max (if (featurep 'xemacs)
6394 lines
6395 (+ lines scroll-margin))
6397 (- (window-height) 2))
6398 -1)))
6399 (prog1
6400 (condition-case ()
6401 (let ((scroll-in-place nil))
6402 (scroll-down lines))
6403 (beginning-of-buffer
6404 (goto-char (point-min))))
6405 (gnus-article-beginning-of-window))))
6407 (defun gnus-article-only-boring-p ()
6408 "Decide whether there is only boring text remaining in the article.
6409 Something \"interesting\" is a word of at least two letters that does
6410 not have a face in `gnus-article-boring-faces'."
6411 (when (and gnus-article-skip-boring
6412 (boundp 'gnus-article-boring-faces)
6413 (symbol-value 'gnus-article-boring-faces))
6414 (save-excursion
6415 (let ((inhibit-point-motion-hooks t))
6416 (catch 'only-boring
6417 (while (re-search-forward "\\b\\w\\w" nil t)
6418 (forward-char -1)
6419 (when (not (gnus-intersection
6420 (gnus-faces-at (point))
6421 (symbol-value 'gnus-article-boring-faces)))
6422 (throw 'only-boring nil)))
6423 (throw 'only-boring t))))))
6425 (defun gnus-article-refer-article ()
6426 "Read article specified by message-id around point."
6427 (interactive)
6428 (save-excursion
6429 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6430 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6431 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6432 (let ((msg-id (concat "<" (match-string 0) ">")))
6433 (set-buffer gnus-summary-buffer)
6434 (gnus-summary-refer-article msg-id))
6435 (error "No references around point"))))
6437 (defun gnus-article-show-summary ()
6438 "Reconfigure windows to show summary buffer."
6439 (interactive)
6440 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6441 (error "There is no summary buffer for this article buffer")
6442 (gnus-article-set-globals)
6443 (gnus-configure-windows 'article)
6444 (gnus-summary-goto-subject gnus-current-article)
6445 (gnus-summary-position-point)))
6447 (defun gnus-article-describe-briefly ()
6448 "Describe article mode commands briefly."
6449 (interactive)
6450 (gnus-message 6 "%s" (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
6452 (defun gnus-article-check-buffer ()
6453 "Beep if not in an article buffer."
6454 (unless (equal major-mode 'gnus-article-mode)
6455 (error "Command invoked outside of a Gnus article buffer")))
6457 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6458 "Read a summary buffer key sequence and execute it from the article buffer."
6459 (interactive "P")
6460 (gnus-article-check-buffer)
6461 (let ((nosaves
6462 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6463 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6464 "=" "^" "\M-^" "|"))
6465 (nosave-but-article
6466 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6467 "An" "Ap" [?A (meta return)] [?A delete]))
6468 (nosave-in-article
6469 '("AS" "\C-d"))
6470 (up-to-top
6471 '("n" "Gn" "p" "Gp"))
6472 keys new-sum-point)
6473 (with-current-buffer gnus-article-current-summary
6474 (let (gnus-pick-mode)
6475 (setq unread-command-events (nconc unread-command-events
6476 (list (or key last-command-event)))
6477 keys (if (featurep 'xemacs)
6478 (events-to-keys (read-key-sequence nil t))
6479 (read-key-sequence nil t)))))
6481 (message "")
6483 (cond
6484 ((eq (aref keys (1- (length keys))) ?\C-h)
6485 (gnus-article-describe-bindings (substring keys 0 -1)))
6486 ((or (member keys nosaves)
6487 (member keys nosave-but-article)
6488 (member keys nosave-in-article))
6489 (let (func)
6490 (save-window-excursion
6491 (pop-to-buffer gnus-article-current-summary)
6492 ;; We disable the pick minor mode commands.
6493 (let (gnus-pick-mode)
6494 (setq func (key-binding keys t))))
6495 (if (or (not func)
6496 (numberp func))
6497 (ding)
6498 (unless (member keys nosave-in-article)
6499 (set-buffer gnus-article-current-summary))
6500 (when (get func 'disabled)
6501 (error "Function %s disabled" func))
6502 (call-interactively func)
6503 (setq new-sum-point (point)))
6504 (when (member keys nosave-but-article)
6505 (pop-to-buffer gnus-article-buffer))))
6507 ;; These commands should restore window configuration.
6508 (let ((obuf (current-buffer))
6509 (owin (current-window-configuration))
6510 win func in-buffer selected new-sum-start new-sum-hscroll err)
6511 (cond (not-restore-window
6512 (pop-to-buffer gnus-article-current-summary)
6513 (setq win (selected-window)))
6514 ((setq win (get-buffer-window gnus-article-current-summary))
6515 (select-window win))
6517 (let ((summary-buffer gnus-article-current-summary))
6518 (gnus-configure-windows 'article)
6519 (unless (setq win (get-buffer-window summary-buffer 'visible))
6520 (let ((gnus-buffer-configuration
6521 '((article ((vertical 1.0
6522 (summary 0.25 point)
6523 (article 1.0)))))))
6524 (gnus-configure-windows 'article))
6525 (setq win (get-buffer-window summary-buffer 'visible)))
6526 (gnus-select-frame-set-input-focus (window-frame win))
6527 (select-window win))))
6528 (setq in-buffer (current-buffer))
6529 ;; We disable the pick minor mode commands.
6530 (setq func (let (gnus-pick-mode)
6531 (key-binding keys t)))
6532 (when (get func 'disabled)
6533 (error "Function %s disabled" func))
6534 (if (and func
6535 (functionp func)
6536 (condition-case code
6537 (progn
6538 (call-interactively func)
6540 (error
6541 (setq err code)
6542 nil)))
6543 (progn
6544 (when (eq win (selected-window))
6545 (setq new-sum-point (point)
6546 new-sum-start (window-start win)
6547 new-sum-hscroll (window-hscroll win)))
6548 (when (or (eq in-buffer (current-buffer))
6549 (when (eq obuf (current-buffer))
6550 (set-buffer in-buffer)
6552 (setq selected (gnus-summary-select-article))
6553 (set-buffer obuf)
6554 (unless not-restore-window
6555 (set-window-configuration owin))
6556 (when (and (eq selected 'old)
6557 new-sum-point)
6558 (set-window-start (get-buffer-window (current-buffer))
6560 (set-window-point (get-buffer-window (current-buffer))
6561 (if (article-goto-body)
6562 (1- (point))
6563 (point))))
6564 (when (and (not not-restore-window)
6565 new-sum-point
6566 (window-live-p win)
6567 (with-current-buffer (window-buffer win)
6568 (eq major-mode 'gnus-summary-mode)))
6569 (set-window-point win new-sum-point)
6570 (set-window-start win new-sum-start)
6571 (set-window-hscroll win new-sum-hscroll))))
6572 (set-window-configuration owin)
6573 (if err
6574 (signal (car err) (cdr err))
6575 (ding))))))))
6577 (defun gnus-article-read-summary-send-keys ()
6578 (interactive)
6579 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6580 (gnus-article-read-summary-keys)))
6582 (defun gnus-article-describe-key (key)
6583 "Display documentation of the function invoked by KEY.
6584 KEY is a string or a vector."
6585 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6586 (read-key-sequence "Describe key: "))))
6587 (gnus-article-check-buffer)
6588 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6589 gnus-article-read-summary-send-keys))
6590 (with-current-buffer gnus-article-current-summary
6591 (setq unread-command-events
6592 (if (featurep 'xemacs)
6593 (append key nil)
6594 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6595 (list 'meta (- x 128))
6597 key)))
6598 (let ((cursor-in-echo-area t)
6599 gnus-pick-mode)
6600 (describe-key (read-key-sequence nil t))))
6601 (describe-key key)))
6603 (defun gnus-article-describe-key-briefly (key &optional insert)
6604 "Display documentation of the function invoked by KEY.
6605 KEY is a string or a vector."
6606 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6607 (read-key-sequence "Describe key: "))
6608 current-prefix-arg))
6609 (gnus-article-check-buffer)
6610 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6611 gnus-article-read-summary-send-keys))
6612 (with-current-buffer gnus-article-current-summary
6613 (setq unread-command-events
6614 (if (featurep 'xemacs)
6615 (append key nil)
6616 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6617 (list 'meta (- x 128))
6619 key)))
6620 (let ((cursor-in-echo-area t)
6621 gnus-pick-mode)
6622 (describe-key-briefly (read-key-sequence nil t) insert)))
6623 (describe-key-briefly key insert)))
6625 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6626 (defvar gnus-agent-summary-mode)
6627 (defvar gnus-draft-mode)
6628 ;; Calling help-buffer will autoload help-mode.
6629 (defvar help-xref-stack-item)
6630 ;; Emacs 22 doesn't load it in the batch mode.
6631 (eval-when-compile
6632 (autoload 'help-buffer "help-mode"))
6634 (defun gnus-article-describe-bindings (&optional prefix)
6635 "Show a list of all defined keys, and their definitions.
6636 The optional argument PREFIX, if non-nil, should be a key sequence;
6637 then we display only bindings that start with that prefix."
6638 (interactive)
6639 (gnus-article-check-buffer)
6640 (let ((keymap (copy-keymap gnus-article-mode-map))
6641 (map (copy-keymap gnus-article-send-map))
6642 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6643 parent agent draft)
6644 (define-key keymap "S" map)
6645 (define-key map [t] nil)
6646 (with-current-buffer gnus-article-current-summary
6647 (set-keymap-parent
6648 keymap
6649 (if (setq parent (keymap-parent gnus-article-mode-map))
6650 (prog1
6651 (setq parent (copy-keymap parent))
6652 (set-keymap-parent parent (current-local-map)))
6653 (current-local-map)))
6654 (set-keymap-parent map (key-binding "S"))
6655 (let (key def gnus-pick-mode)
6656 (while sumkeys
6657 (setq key (pop sumkeys))
6658 (cond ((and (vectorp key) (= (length key) 1)
6659 (consp (setq def (aref key 0)))
6660 (numberp (car def)) (numberp (cdr def)))
6661 (when (< (max (car def) (cdr def)) 128)
6662 (setq sumkeys
6663 (append (mapcar
6664 #'vector
6665 (nreverse (gnus-uncompress-range def)))
6666 sumkeys))))
6667 ((setq def (key-binding key))
6668 (unless (eq def 'undefined)
6669 (define-key keymap key def))))))
6670 (when (boundp 'gnus-agent-summary-mode)
6671 (setq agent gnus-agent-summary-mode))
6672 (when (boundp 'gnus-draft-mode)
6673 (setq draft gnus-draft-mode)))
6674 (with-temp-buffer
6675 (use-local-map keymap)
6676 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6677 (set (make-local-variable 'gnus-draft-mode) draft)
6678 (describe-bindings prefix))
6679 (let ((item `((lambda (prefix)
6680 (with-current-buffer ,(current-buffer)
6681 (gnus-article-describe-bindings prefix)))
6682 ,prefix)))
6683 (with-current-buffer (let (help-xref-following) (help-buffer))
6684 (setq help-xref-stack-item item)))))
6686 (defun gnus-article-reply-with-original (&optional wide)
6687 "Start composing a reply mail to the current message.
6688 The text in the region will be yanked. If the region isn't active,
6689 the entire article will be yanked."
6690 (interactive)
6691 (let ((article (cdr gnus-article-current))
6692 contents)
6693 (if (not (gnus-region-active-p))
6694 (with-current-buffer gnus-summary-buffer
6695 (gnus-summary-reply (list (list article)) wide))
6696 (setq contents (buffer-substring (point) (mark t)))
6697 ;; Deactivate active regions.
6698 (when (and (boundp 'transient-mark-mode)
6699 transient-mark-mode)
6700 (setq mark-active nil))
6701 (with-current-buffer gnus-summary-buffer
6702 (gnus-summary-reply
6703 (list (list article contents)) wide)))))
6705 (defun gnus-article-wide-reply-with-original ()
6706 "Start composing a wide reply mail to the current message.
6707 The text in the region will be yanked. If the region isn't active,
6708 the entire article will be yanked."
6709 (interactive)
6710 (gnus-article-reply-with-original t))
6712 (defun gnus-article-followup-with-original ()
6713 "Compose a followup to the current article.
6714 The text in the region will be yanked. If the region isn't active,
6715 the entire article will be yanked."
6716 (interactive)
6717 (let ((article (cdr gnus-article-current))
6718 contents)
6719 (if (not (gnus-region-active-p))
6720 (with-current-buffer gnus-summary-buffer
6721 (gnus-summary-followup (list (list article))))
6722 (setq contents (buffer-substring (point) (mark t)))
6723 ;; Deactivate active regions.
6724 (when (and (boundp 'transient-mark-mode)
6725 transient-mark-mode)
6726 (setq mark-active nil))
6727 (with-current-buffer gnus-summary-buffer
6728 (gnus-summary-followup
6729 (list (list article contents)))))))
6731 (defun gnus-article-hide (&optional arg force)
6732 "Hide all the gruft in the current article.
6733 This means that signatures, cited text and (some) headers will be
6734 hidden.
6735 If given a prefix, show the hidden text instead."
6736 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6737 (gnus-article-hide-headers arg)
6738 (gnus-article-hide-list-identifiers arg)
6739 (gnus-article-hide-citation-maybe arg force)
6740 (gnus-article-hide-signature arg))
6742 (defun gnus-article-maybe-highlight ()
6743 "Do some article highlighting if article highlighting is requested."
6744 (when (gnus-visual-p 'article-highlight 'highlight)
6745 (gnus-article-highlight-some)))
6747 (defun gnus-check-group-server ()
6748 ;; Make sure the connection to the server is alive.
6749 (unless (gnus-server-opened
6750 (gnus-find-method-for-group gnus-newsgroup-name))
6751 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6752 (gnus-request-group gnus-newsgroup-name t)))
6754 (eval-when-compile
6755 (autoload 'nneething-get-file-name "nneething"))
6757 (defun gnus-request-article-this-buffer (article group)
6758 "Get an article and insert it into this buffer."
6759 (let (do-update-line sparse-header)
6760 (prog1
6761 (save-excursion
6762 (erase-buffer)
6763 (gnus-kill-all-overlays)
6764 (setq group (or group gnus-newsgroup-name))
6766 ;; Using `gnus-request-article' directly will insert the article into
6767 ;; `nntp-server-buffer' - so we'll save some time by not having to
6768 ;; copy it from the server buffer into the article buffer.
6770 ;; We only request an article by message-id when we do not have the
6771 ;; headers for it, so we'll have to get those.
6772 (when (stringp article)
6773 (gnus-read-header article))
6775 ;; If the article number is negative, that means that this article
6776 ;; doesn't belong in this newsgroup (possibly), so we find its
6777 ;; message-id and request it by id instead of number.
6778 (when (and (numberp article)
6779 gnus-summary-buffer
6780 (get-buffer gnus-summary-buffer)
6781 (gnus-buffer-exists-p gnus-summary-buffer))
6782 (with-current-buffer gnus-summary-buffer
6783 (let ((header (gnus-summary-article-header article)))
6784 (when (< article 0)
6785 (cond
6786 ((memq article gnus-newsgroup-sparse)
6787 ;; This is a sparse gap article.
6788 (setq do-update-line article)
6789 (setq article (mail-header-id header))
6790 (setq sparse-header (gnus-read-header article))
6791 (setq gnus-newsgroup-sparse
6792 (delq article gnus-newsgroup-sparse)))
6793 ((vectorp header)
6794 ;; It's a real article.
6795 (setq article (mail-header-id header)))
6797 ;; It is an extracted pseudo-article.
6798 (setq article 'pseudo)
6799 (gnus-request-pseudo-article header))))
6801 (let ((method (gnus-find-method-for-group
6802 gnus-newsgroup-name)))
6803 (when (and (eq (car method) 'nneething)
6804 (vectorp header))
6805 (let ((dir (nneething-get-file-name
6806 (mail-header-id header))))
6807 (when (and (stringp dir)
6808 (file-directory-p dir))
6809 (setq article 'nneething)
6810 (gnus-group-enter-directory dir))))))))
6812 (cond
6813 ;; Refuse to select canceled articles.
6814 ((and (numberp article)
6815 gnus-summary-buffer
6816 (get-buffer gnus-summary-buffer)
6817 (gnus-buffer-exists-p gnus-summary-buffer)
6818 (eq (cdr (with-current-buffer gnus-summary-buffer
6819 (assq article gnus-newsgroup-reads)))
6820 gnus-canceled-mark))
6821 nil)
6822 ;; We first check `gnus-original-article-buffer'.
6823 ((and (get-buffer gnus-original-article-buffer)
6824 (numberp article)
6825 (with-current-buffer gnus-original-article-buffer
6826 (and (equal (car gnus-original-article) group)
6827 (eq (cdr gnus-original-article) article))))
6828 ;; `insert-buffer-substring' would incorrectly use the
6829 ;; equivalent of string-make-multibyte which amount to decoding
6830 ;; with locale-coding-system, causing failure of
6831 ;; subsequent decoding.
6832 (insert (mm-string-to-multibyte
6833 (with-current-buffer gnus-original-article-buffer
6834 (buffer-substring (point-min) (point-max)))))
6835 'article)
6836 ;; Check the backlog.
6837 ((and gnus-keep-backlog
6838 (gnus-backlog-request-article group article (current-buffer)))
6839 'article)
6840 ;; Check asynchronous pre-fetch.
6841 ((gnus-async-request-fetched-article group article (current-buffer))
6842 (gnus-async-prefetch-next group article gnus-summary-buffer)
6843 (when (and (numberp article) gnus-keep-backlog)
6844 (gnus-backlog-enter-article group article (current-buffer)))
6845 'article)
6846 ;; Check the cache.
6847 ((and gnus-use-cache
6848 (numberp article)
6849 (gnus-cache-request-article article group))
6850 'article)
6851 ;; Check the agent cache.
6852 ((gnus-agent-request-article article group)
6853 'article)
6854 ;; Get the article and put into the article buffer.
6855 ((or (stringp article)
6856 (numberp article))
6857 (let ((gnus-override-method gnus-override-method)
6858 (methods (and (stringp article)
6859 (with-current-buffer gnus-summary-buffer
6860 (gnus-refer-article-methods))))
6861 (backend (car (gnus-find-method-for-group
6862 gnus-newsgroup-name)))
6863 result
6864 (inhibit-read-only t))
6865 (when (and (null gnus-override-method)
6866 methods)
6867 (setq gnus-override-method (pop methods)))
6868 (while (not result)
6869 (erase-buffer)
6870 (gnus-kill-all-overlays)
6871 (let ((gnus-newsgroup-name group))
6872 (gnus-check-group-server))
6873 (cond
6874 ((gnus-request-article article group (current-buffer))
6875 (when (numberp article)
6876 (gnus-async-prefetch-next group article
6877 gnus-summary-buffer)
6878 (when gnus-keep-backlog
6879 (gnus-backlog-enter-article
6880 group article (current-buffer)))
6881 (when (and gnus-agent
6882 (gnus-agent-group-covered-p group))
6883 (gnus-agent-store-article article group)))
6884 (setq result 'article))
6885 (methods
6886 (setq gnus-override-method (pop methods)))
6887 ((not (string-match "^400 "
6888 (nnheader-get-report backend)))
6889 ;; If we get 400 server disconnect, reconnect and
6890 ;; retry; otherwise, assume the article has expired.
6891 (setq result 'done))))
6892 (and (eq result 'article) 'article)))
6893 ;; It was a pseudo.
6894 (t article)))
6896 ;; Associate this article with the current summary buffer.
6897 (setq gnus-article-current-summary gnus-summary-buffer)
6899 ;; Take the article from the original article buffer
6900 ;; and place it in the buffer it's supposed to be in.
6901 (when (and (get-buffer gnus-article-buffer)
6902 (equal (buffer-name (current-buffer))
6903 (buffer-name (get-buffer gnus-article-buffer))))
6904 (save-excursion
6905 (if (get-buffer gnus-original-article-buffer)
6906 (set-buffer gnus-original-article-buffer)
6907 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6908 (buffer-disable-undo)
6909 (setq major-mode 'gnus-original-article-mode)
6910 (setq buffer-read-only t))
6911 (let ((inhibit-read-only t))
6912 (erase-buffer)
6913 (insert-buffer-substring gnus-article-buffer))
6914 (setq gnus-original-article (cons group article)))
6916 ;; Decode charsets.
6917 (run-hooks 'gnus-article-decode-hook)
6918 ;; Mark article as decoded or not.
6919 (setq gnus-article-decoded-p gnus-article-decode-hook))
6921 ;; Update sparse articles.
6922 (when (and do-update-line
6923 (or (numberp article)
6924 (stringp article)))
6925 (let ((buf (current-buffer)))
6926 (set-buffer gnus-summary-buffer)
6927 (gnus-summary-update-article do-update-line sparse-header)
6928 (gnus-summary-goto-subject do-update-line nil t)
6929 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6930 (point))
6931 (set-buffer buf))))))
6933 (defun gnus-block-private-groups (group)
6934 (if (gnus-news-group-p group)
6935 ;; Block nothing in news groups.
6937 ;; Block everything anywhere else.
6938 "."))
6940 (defun gnus-blocked-images ()
6941 (if (functionp gnus-blocked-images)
6942 (funcall gnus-blocked-images gnus-newsgroup-name)
6943 gnus-blocked-images))
6946 ;;; Article editing
6949 (defcustom gnus-article-edit-mode-hook nil
6950 "Hook run in article edit mode buffers."
6951 :group 'gnus-article-various
6952 :type 'hook)
6954 (defvar gnus-article-edit-done-function nil)
6956 (defvar gnus-article-edit-mode-map nil)
6958 ;; Should we be using derived.el for this?
6959 (unless gnus-article-edit-mode-map
6960 (setq gnus-article-edit-mode-map (make-keymap))
6961 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6963 (gnus-define-keys gnus-article-edit-mode-map
6964 "\C-c?" describe-mode
6965 "\C-c\C-c" gnus-article-edit-done
6966 "\C-c\C-k" gnus-article-edit-exit
6967 "\C-c\C-f\C-t" message-goto-to
6968 "\C-c\C-f\C-o" message-goto-from
6969 "\C-c\C-f\C-b" message-goto-bcc
6970 ;;"\C-c\C-f\C-w" message-goto-fcc
6971 "\C-c\C-f\C-c" message-goto-cc
6972 "\C-c\C-f\C-s" message-goto-subject
6973 "\C-c\C-f\C-r" message-goto-reply-to
6974 "\C-c\C-f\C-n" message-goto-newsgroups
6975 "\C-c\C-f\C-d" message-goto-distribution
6976 "\C-c\C-f\C-f" message-goto-followup-to
6977 "\C-c\C-f\C-m" message-goto-mail-followup-to
6978 "\C-c\C-f\C-k" message-goto-keywords
6979 "\C-c\C-f\C-u" message-goto-summary
6980 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6981 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6982 "\C-c\C-b" message-goto-body
6983 "\C-c\C-i" message-goto-signature
6985 "\C-c\C-t" message-insert-to
6986 "\C-c\C-n" message-insert-newsgroups
6987 "\C-c\C-o" message-sort-headers
6988 "\C-c\C-e" message-elide-region
6989 "\C-c\C-v" message-delete-not-region
6990 "\C-c\C-z" message-kill-to-signature
6991 "\M-\r" message-newline-and-reformat
6992 "\C-c\C-a" mml-attach-file
6993 "\C-a" message-beginning-of-line
6994 "\t" message-tab
6995 "\M-;" comment-region)
6997 (gnus-define-keys (gnus-article-edit-wash-map
6998 "\C-c\C-w" gnus-article-edit-mode-map)
6999 "f" gnus-article-edit-full-stops))
7001 (easy-menu-define
7002 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7003 '("Field"
7004 ["Fetch To" message-insert-to t]
7005 ["Fetch Newsgroups" message-insert-newsgroups t]
7006 "----"
7007 ["To" message-goto-to t]
7008 ["From" message-goto-from t]
7009 ["Subject" message-goto-subject t]
7010 ["Cc" message-goto-cc t]
7011 ["Reply-To" message-goto-reply-to t]
7012 ["Summary" message-goto-summary t]
7013 ["Keywords" message-goto-keywords t]
7014 ["Newsgroups" message-goto-newsgroups t]
7015 ["Followup-To" message-goto-followup-to t]
7016 ["Mail-Followup-To" message-goto-mail-followup-to t]
7017 ["Distribution" message-goto-distribution t]
7018 ["Body" message-goto-body t]
7019 ["Signature" message-goto-signature t]))
7021 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7022 "Major mode for editing articles.
7023 This is an extended text-mode.
7025 \\{gnus-article-edit-mode-map}"
7026 (make-local-variable 'gnus-article-edit-done-function)
7027 (make-local-variable 'gnus-prev-winconf)
7028 (set (make-local-variable 'font-lock-defaults)
7029 '(message-font-lock-keywords t))
7030 (set (make-local-variable 'mail-header-separator) "")
7031 (set (make-local-variable 'gnus-article-edit-mode) t)
7032 (easy-menu-add message-mode-field-menu message-mode-map)
7033 (mml-mode)
7034 (setq buffer-read-only nil)
7035 (buffer-enable-undo)
7036 (widen))
7038 (defun gnus-article-edit (&optional force)
7039 "Edit the current article.
7040 This will have permanent effect only in mail groups.
7041 If FORCE is non-nil, allow editing of articles even in read-only
7042 groups."
7043 (interactive "P")
7044 (when (and (not force)
7045 (gnus-group-read-only-p))
7046 (error "The current newsgroup does not support article editing"))
7047 (gnus-article-date-original)
7048 (gnus-article-edit-article
7049 'ignore
7050 `(lambda (no-highlight)
7051 'ignore
7052 (gnus-summary-edit-article-done
7053 ,(or (mail-header-references gnus-current-headers) "")
7054 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7056 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7057 "Start editing the contents of the current article buffer."
7058 (let ((winconf (current-window-configuration)))
7059 (set-buffer gnus-article-buffer)
7060 (let ((message-auto-save-directory
7061 ;; Don't associate the article buffer with a draft file.
7062 nil))
7063 (gnus-article-edit-mode))
7064 (funcall start-func)
7065 (set-buffer-modified-p nil)
7066 (gnus-configure-windows 'edit-article)
7067 (setq gnus-article-edit-done-function exit-func)
7068 (setq gnus-prev-winconf winconf)
7069 (unless quiet
7070 (gnus-message 6 "C-c C-c to end edits"))))
7072 (defun gnus-article-edit-done (&optional arg)
7073 "Update the article edits and exit."
7074 (interactive "P")
7075 (let ((func gnus-article-edit-done-function)
7076 (buf (current-buffer))
7077 (start (window-start))
7078 (p (point))
7079 (winconf gnus-prev-winconf))
7080 (widen) ;; Widen it in case that users narrowed the buffer.
7081 (funcall func arg)
7082 (set-buffer buf)
7083 ;; The cache and backlog have to be flushed somewhat.
7084 (when gnus-keep-backlog
7085 (gnus-backlog-remove-article
7086 (car gnus-article-current) (cdr gnus-article-current)))
7087 ;; Flush original article as well.
7088 (gnus-flush-original-article-buffer)
7089 (when gnus-use-cache
7090 (gnus-cache-update-article
7091 (car gnus-article-current) (cdr gnus-article-current)))
7092 ;; We remove all text props from the article buffer.
7093 (kill-all-local-variables)
7094 (set-text-properties (point-min) (point-max) nil)
7095 (gnus-article-mode)
7096 (set-window-configuration winconf)
7097 (set-buffer buf)
7098 (set-window-start (get-buffer-window buf) start)
7099 (set-window-point (get-buffer-window buf) (point)))
7100 (gnus-summary-show-article))
7102 (defun gnus-flush-original-article-buffer ()
7103 (when (get-buffer gnus-original-article-buffer)
7104 (with-current-buffer gnus-original-article-buffer
7105 (setq gnus-original-article nil))))
7107 (defun gnus-article-edit-exit ()
7108 "Exit the article editing without updating."
7109 (interactive)
7110 (when (or (not (buffer-modified-p))
7111 (yes-or-no-p "Article modified; kill anyway? "))
7112 (let ((curbuf (current-buffer))
7113 (p (point))
7114 (window-start (window-start)))
7115 (erase-buffer)
7116 (if (gnus-buffer-live-p gnus-original-article-buffer)
7117 (insert-buffer-substring gnus-original-article-buffer))
7118 (let ((winconf gnus-prev-winconf))
7119 (kill-all-local-variables)
7120 (gnus-article-mode)
7121 (set-window-configuration winconf)
7122 ;; Tippy-toe some to make sure that point remains where it was.
7123 (save-current-buffer
7124 (set-buffer curbuf)
7125 (set-window-start (get-buffer-window (current-buffer)) window-start)
7126 (goto-char p))))
7127 (gnus-summary-show-article)))
7129 (defun gnus-article-edit-full-stops ()
7130 "Interactively repair spacing at end of sentences."
7131 (interactive)
7132 (save-excursion
7133 (goto-char (point-min))
7134 (search-forward-regexp "^$" nil t)
7135 (let ((case-fold-search nil))
7136 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7139 ;;; Article highlights
7142 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7144 ;;; Internal Variables:
7146 (defcustom gnus-button-url-regexp
7147 (concat
7148 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7149 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7150 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7151 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7152 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7153 (punct "!?:;.,"))
7154 (concat
7155 "\\(?:"
7156 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7157 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7158 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7159 "\\|"
7160 "[" chars punct "]+" "[" chars "]"
7161 "\\)"))
7162 (concat ;; XEmacs 21.4 doesn't support POSIX.
7163 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7164 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7165 "\\)")
7166 "Regular expression that matches URLs."
7167 :group 'gnus-article-buttons
7168 :type 'regexp)
7170 (defcustom gnus-button-valid-fqdn-regexp
7171 message-valid-fqdn-regexp
7172 "Regular expression that matches a valid FQDN."
7173 :version "22.1"
7174 :group 'gnus-article-buttons
7175 :type 'regexp)
7177 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7178 (defcustom gnus-button-valid-localpart-regexp
7179 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7180 "Regular expression that matches a localpart of mail addresses or MIDs."
7181 :version "22.1"
7182 :group 'gnus-article-buttons
7183 :type 'regexp)
7185 (defcustom gnus-button-man-handler 'manual-entry
7186 "Function to use for displaying man pages.
7187 The function must take at least one argument with a string naming the
7188 man page."
7189 :version "22.1"
7190 :type '(choice (function-item :tag "Man" manual-entry)
7191 (function-item :tag "Woman" woman)
7192 (function :tag "Other"))
7193 :group 'gnus-article-buttons)
7195 (defcustom gnus-button-mid-or-mail-regexp
7196 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7197 gnus-button-valid-fqdn-regexp
7198 ">?\\)\\b")
7199 "Regular expression that matches a message ID or a mail address."
7200 :version "22.1"
7201 :group 'gnus-article-buttons
7202 :type 'regexp)
7204 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7205 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7206 Strings like this can be either a message ID or a mail address. If it is one
7207 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7208 message ID or a mail address, respectively. If this variable is set to the
7209 symbol `ask', always query the user what do do. If it is a function, this
7210 function will be called with the string as its only argument. The function
7211 must return `mid', `mail', `invalid' or `ask'."
7212 :version "22.1"
7213 :group 'gnus-article-buttons
7214 :type '(choice (function-item :tag "Heuristic function"
7215 gnus-button-mid-or-mail-heuristic)
7216 (const ask)
7217 (const mid)
7218 (const mail)))
7220 (defcustom gnus-button-mid-or-mail-heuristic-alist
7221 '((-10.0 . ".+\\$.+@")
7222 (-10.0 . "#")
7223 (-10.0 . "\\*")
7224 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7225 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7226 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7227 (-1.0 . "^[^a-z]+@")
7229 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7230 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7231 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7232 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7234 (-2.0 . "^[0-9]")
7235 (-1.0 . "^[0-9][0-9]")
7237 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7238 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7239 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7240 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7242 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7243 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7244 ;; "[0-9]{8,}.*\@"
7245 (-3.0
7246 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7247 ;; "[0-9]{12,}.*\@"
7248 ;; compensation for TDMA dated mail addresses:
7249 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7251 (-20.0 . "\\.fsf@") ;; Gnus
7252 (-20.0 . "^slrn")
7253 (-20.0 . "^Pine")
7254 (-20.0 . "^alpine\\.")
7255 (-20.0 . "_-_") ;; Subject change in thread
7257 (-20.0 . "\\.ln@") ;; leafnode
7258 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7259 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7261 ;; (5.0 . "") ;; $local_part_len <= 7
7262 (10.0 . "^[^0-9]+@")
7263 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7264 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7265 (3.0 . "\@stud")
7267 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7269 (0.5 . "^[A-Z][a-z]")
7270 (0.5 . "^[A-Z][a-z][a-z]")
7271 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7272 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7273 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7275 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7276 address. The REGEXP is processed with `case-fold-search' set to nil."
7277 :version "22.1"
7278 :group 'gnus-article-buttons
7279 :type '(repeat (cons (number :tag "Rate")
7280 (regexp :tag "Regexp"))))
7282 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7283 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7284 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7285 address, `ask' if unsure and `invalid' if the string is invalid."
7286 (let ((case-fold-search nil)
7287 (list gnus-button-mid-or-mail-heuristic-alist)
7288 (result 0) rate regexp lpartlen elem)
7289 (setq lpartlen
7290 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7291 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7292 ;; Certain special cases...
7293 (when (string-match
7294 (concat
7295 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7296 "^[0-9]+\\.[0-9]+@compuserve\\|"
7297 "@public\\.gmane\\.org")
7298 mid-or-mail)
7299 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7300 (setq result 'mail))
7301 (when (string-match "@.*@\\| " mid-or-mail)
7302 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7303 (setq result 'invalid))
7304 ;; Nothing more to do, if result is not a number here...
7305 (when (numberp result)
7306 (while list
7307 (setq elem (car list)
7308 rate (car elem)
7309 regexp (cdr elem)
7310 list (cdr list))
7311 (when (string-match regexp mid-or-mail)
7312 (setq result (+ result rate))
7313 (gnus-message
7314 9 "`%s' matched `%s', rate `%s', result `%s'."
7315 mid-or-mail regexp rate result)))
7316 (when (<= lpartlen 7)
7317 (setq result (+ result 5.0))
7318 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7319 mid-or-mail result))
7320 (when (>= lpartlen 12)
7321 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7322 (cond
7323 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7324 ;; Long local part should contain realname if e-mail address,
7325 ;; too many digits: message-id.
7326 ;; $score -= 5.0 + 0.1 * $local_part_len;
7327 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7328 (setq result (+ result rate))
7329 (gnus-message
7330 9 "Many digits in `%s', rate `%s', result `%s'."
7331 mid-or-mail rate result))
7332 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7333 mid-or-mail)
7334 ;; Too few vowels [^aeiouy]{4,}.*\@
7335 (setq result (+ result -5.0))
7336 (gnus-message
7337 9 "Few vowels in `%s', rate `%s', result `%s'."
7338 mid-or-mail -5.0 result))
7340 (setq result (+ result 5.0))
7341 (gnus-message
7342 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7343 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7344 ;; Maybe we should make this a customizable alist: (condition . 'result)
7345 (cond
7346 ((symbolp result) result)
7347 ;; Now convert number into proper results:
7348 ((< result -10.0) 'mid)
7349 ((> result 10.0) 'mail)
7350 (t 'ask))))
7352 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7353 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7354 (url-mid (concat "news" ":" mid-or-mail))
7355 (url-mailto (concat "mailto" ":" mid-or-mail)))
7356 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7357 (when (fboundp pref)
7358 (setq guessed
7359 ;; get rid of surrounding angles...
7360 (funcall pref
7361 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7362 (if (or (eq 'mid guessed) (eq 'mail guessed))
7363 (setq pref guessed)
7364 (setq pref 'ask)))
7365 (if (eq pref 'ask)
7366 (save-window-excursion
7367 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7368 (setq pref 'mail)
7369 (setq pref 'mid))))
7370 (cond ((eq pref 'mid)
7371 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7372 (gnus-button-handle-news url-mid))
7373 ((eq pref 'mail)
7374 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7375 (gnus-url-mailto url-mailto))
7376 (t (gnus-message 3 "Invalid string.")))))
7378 (defun gnus-button-handle-custom (fun arg)
7379 "Call function FUN on argument ARG.
7380 Both FUN and ARG are supposed to be strings. ARG will be passed
7381 as a symbol to FUN."
7382 (funcall (intern fun)
7383 (if (string-match "^customize-apropos" fun)
7385 (intern arg))))
7387 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7389 (defun gnus-button-handle-describe-function (url)
7390 "Call `describe-function' when pushing the corresponding URL button."
7391 (describe-function
7392 (intern
7393 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7395 (defun gnus-button-handle-describe-variable (url)
7396 "Call `describe-variable' when pushing the corresponding URL button."
7397 (describe-variable
7398 (intern
7399 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7401 (defun gnus-button-handle-symbol (url)
7402 "Display help on variable or function.
7403 Calls `describe-variable' or `describe-function'."
7404 (let ((sym (intern url)))
7405 (cond
7406 ((fboundp sym) (describe-function sym))
7407 ((boundp sym) (describe-variable sym))
7408 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7410 (defun gnus-button-handle-describe-key (url)
7411 "Call `describe-key' when pushing the corresponding URL button."
7412 (let* ((key-string
7413 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7414 (keys (ignore-errors (eval `(kbd ,key-string)))))
7415 (if keys
7416 (describe-key keys)
7417 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7419 (defun gnus-button-handle-apropos (url)
7420 "Call `apropos' when pushing the corresponding URL button."
7421 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7423 (defun gnus-button-handle-apropos-command (url)
7424 "Call `apropos' when pushing the corresponding URL button."
7425 (apropos-command
7426 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7428 (defun gnus-button-handle-apropos-variable (url)
7429 "Call `apropos' when pushing the corresponding URL button."
7430 (funcall
7431 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7432 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7434 (defun gnus-button-handle-apropos-documentation (url)
7435 "Call `apropos' when pushing the corresponding URL button."
7436 (funcall
7437 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7438 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7440 (defun gnus-button-handle-library (url)
7441 "Call `locate-library' when pushing the corresponding URL button."
7442 (gnus-message 9 "url=`%s'" url)
7443 (let* ((lib (locate-library url))
7444 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7445 (if (not lib)
7446 (gnus-message 1 "Cannot locale library `%s'." url)
7447 (find-file-read-only file))))
7449 (defcustom gnus-button-man-level 5
7450 "*Integer that says how many man-related buttons Gnus will show.
7451 The higher the number, the more buttons will appear and the more false
7452 positives are possible. Note that you can set this variable local to
7453 specific groups. Setting it higher in Unix groups is probably a good idea.
7454 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7455 how to set variables in specific groups."
7456 :version "22.1"
7457 :group 'gnus-article-buttons
7458 :link '(custom-manual "(gnus)Group Parameters")
7459 :type 'integer)
7461 (defcustom gnus-button-emacs-level 5
7462 "*Integer that says how many emacs-related buttons Gnus will show.
7463 The higher the number, the more buttons will appear and the more false
7464 positives are possible. Note that you can set this variable local to
7465 specific groups. Setting it higher in Emacs or Gnus related groups is
7466 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7467 `gnus-parameters' on how to set variables in specific groups."
7468 :version "22.1"
7469 :group 'gnus-article-buttons
7470 :link '(custom-manual "(gnus)Group Parameters")
7471 :type 'integer)
7473 (defcustom gnus-button-message-level 5
7474 "*Integer that says how many buttons for news or mail messages will appear.
7475 The higher the number, the more buttons will appear and the more false
7476 positives are possible."
7477 ;; mail addresses, MIDs, URLs for news, ...
7478 :version "22.1"
7479 :group 'gnus-article-buttons
7480 :type 'integer)
7482 (defcustom gnus-button-browse-level 5
7483 "*Integer that says how many buttons for browsing will appear.
7484 The higher the number, the more buttons will appear and the more false
7485 positives are possible."
7486 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7487 :version "22.1"
7488 :group 'gnus-article-buttons
7489 :type 'integer)
7491 (defcustom gnus-button-alist
7492 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7493 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7494 ((concat "\\b\\(nntp\\|news\\):\\("
7495 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7496 0 t gnus-button-handle-news 2)
7497 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7498 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7499 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7500 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7501 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7502 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7503 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7504 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7505 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7506 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7507 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7508 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7509 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7510 ;; RFC 2368 (The mailto URL scheme)
7511 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7512 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7513 ("\\bmailto:\\([^ \n\t]+\\)"
7514 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7515 ;; Info Konqueror style <info:/foo/bar baz>.
7516 ;; Must come before " Gnus home-grown style".
7517 ("\\binfo://?\\([^'\">\n\t]+\\)"
7518 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7519 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7520 ("\\binfo://\\([^'\">\n\t ]+\\)"
7521 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7522 ;; Info GNOME style <info:foo#bar_baz>
7523 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7524 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7525 ;; Info KDE style <info:(foo)bar baz>
7526 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7527 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7528 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7529 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7530 ("\\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,]*\\)\\)?"
7531 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7532 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7533 ;; This is custom
7534 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7535 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7536 ;; Emacs help commands
7537 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7538 ;; regexp doesn't match arguments containing ` '.
7539 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7540 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7541 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7542 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7543 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7544 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7545 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7546 ;; The following entries may lead to many false positives so don't enable
7547 ;; them by default (use a high button level).
7548 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7549 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7550 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7551 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7552 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7553 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7554 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7555 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7556 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7557 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7558 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7559 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7560 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7561 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7562 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7563 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7564 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7565 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7566 ;; Unlike the other regexps we really have to require quoting
7567 ;; here to determine where it ends.
7568 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7569 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7570 ("<URL: *\\([^\n<>]*\\)>"
7571 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7572 ;; RFC 2396 (2.4.3., delims) ...
7573 ("\"URL: *\\([^\n\"]*\\)\""
7574 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7575 ;; Raw URLs.
7576 (gnus-button-url-regexp
7577 0 (>= gnus-button-browse-level 0) browse-url 0)
7578 ;; man pages
7579 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7580 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7581 gnus-button-handle-man 1)
7582 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7583 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7584 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7585 gnus-button-handle-man 1)
7586 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7587 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7588 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7589 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7590 ;; Recognizing patches to .el files. This is somewhat obscure,
7591 ;; but considering the percentage of Gnus users who hack Emacs
7592 ;; Lisp files...
7593 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7594 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7595 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7596 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7597 ;; MID or mail: To avoid too many false positives we don't try to catch
7598 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7599 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7600 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7601 ;; so that non-ambiguous entries (see above) match first.
7602 (gnus-button-mid-or-mail-regexp
7603 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7604 "*Alist of regexps matching buttons in article bodies.
7606 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7607 REGEXP: is the string (case insensitive) matching text around the button (can
7608 also be Lisp expression evaluating to a string),
7609 BUTTON: is the number of the regexp grouping actually matching the button,
7610 FORM: is a Lisp expression which must eval to true for the button to
7611 be added,
7612 CALLBACK: is the function to call when the user push this button, and each
7613 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7615 CALLBACK can also be a variable, in that case the value of that
7616 variable it the real callback function."
7617 :group 'gnus-article-buttons
7618 :type '(repeat (list (choice regexp variable sexp)
7619 (integer :tag "Button")
7620 (sexp :tag "Form")
7621 (function :tag "Callback")
7622 (repeat :tag "Par"
7623 :inline t
7624 (integer :tag "Regexp group")))))
7625 (put 'gnus-button-alist 'risky-local-variable t)
7627 (defcustom gnus-header-button-alist
7628 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7629 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7630 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7631 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7632 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7633 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7634 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7635 0 (>= gnus-button-browse-level 0) browse-url 0)
7636 ("^Subject:" gnus-button-url-regexp
7637 0 (>= gnus-button-browse-level 0) browse-url 0)
7638 ("^[^:]+:" gnus-button-url-regexp
7639 0 (>= gnus-button-browse-level 0) browse-url 0)
7640 ("^OpenPGP:.*url=" gnus-button-url-regexp
7641 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7642 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7643 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7644 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7645 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7646 "*Alist of headers and regexps to match buttons in article heads.
7648 This alist is very similar to `gnus-button-alist', except that each
7649 alist has an additional HEADER element first in each entry:
7651 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7653 HEADER is a regexp to match a header. For a fuller explanation, see
7654 `gnus-button-alist'."
7655 :group 'gnus-article-buttons
7656 :group 'gnus-article-headers
7657 :type '(repeat (list (regexp :tag "Header")
7658 (choice regexp variable)
7659 (integer :tag "Button")
7660 (sexp :tag "Form")
7661 (function :tag "Callback")
7662 (repeat :tag "Par"
7663 :inline t
7664 (integer :tag "Regexp group")))))
7665 (put 'gnus-header-button-alist 'risky-local-variable t)
7667 ;;; Commands:
7669 (defun gnus-article-push-button (event)
7670 "Check text under the mouse pointer for a callback function.
7671 If the text under the mouse pointer has a `gnus-callback' property,
7672 call it with the value of the `gnus-data' text property."
7673 (interactive "e")
7674 (set-buffer (window-buffer (posn-window (event-start event))))
7675 (let* ((pos (posn-point (event-start event)))
7676 (data (get-text-property pos 'gnus-data))
7677 (fun (get-text-property pos 'gnus-callback)))
7678 (goto-char pos)
7679 (when fun
7680 (funcall fun data))))
7682 (defun gnus-article-press-button ()
7683 "Check text at point for a callback function.
7684 If the text at point has a `gnus-callback' property,
7685 call it with the value of the `gnus-data' text property."
7686 (interactive)
7687 (let ((data (get-text-property (point) 'gnus-data))
7688 (fun (get-text-property (point) 'gnus-callback)))
7689 (when fun
7690 (funcall fun data))))
7692 (defun gnus-article-highlight (&optional force)
7693 "Highlight current article.
7694 This function calls `gnus-article-highlight-headers',
7695 `gnus-article-highlight-citation',
7696 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7697 do the highlighting. See the documentation for those functions."
7698 (interactive (list 'force))
7699 (gnus-article-highlight-headers)
7700 (gnus-article-highlight-citation force)
7701 (gnus-article-highlight-signature)
7702 (gnus-article-add-buttons)
7703 (gnus-article-add-buttons-to-head))
7705 (defun gnus-article-highlight-some (&optional force)
7706 "Highlight current article.
7707 This function calls `gnus-article-highlight-headers',
7708 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7709 do the highlighting. See the documentation for those functions."
7710 (interactive (list 'force))
7711 (gnus-article-highlight-headers)
7712 (gnus-article-highlight-signature)
7713 (gnus-article-add-buttons))
7715 (defun gnus-article-highlight-headers ()
7716 "Highlight article headers as specified by `gnus-header-face-alist'."
7717 (interactive)
7718 (gnus-with-article-headers
7719 (let (regexp header-face field-face from hpoints fpoints)
7720 (dolist (entry gnus-header-face-alist)
7721 (goto-char (point-min))
7722 (setq regexp (concat "^\\("
7723 (if (string-equal "" (nth 0 entry))
7724 "[^\t ]"
7725 (nth 0 entry))
7726 "\\)")
7727 header-face (nth 1 entry)
7728 field-face (nth 2 entry))
7729 (while (and (re-search-forward regexp nil t)
7730 (not (eobp)))
7731 (beginning-of-line)
7732 (setq from (point))
7733 (unless (search-forward ":" nil t)
7734 (forward-char 1))
7735 (when (and header-face
7736 (not (memq (point) hpoints)))
7737 (push (point) hpoints)
7738 (gnus-put-text-property from (point) 'face header-face))
7739 (when (and field-face
7740 (not (memq (setq from (point)) fpoints)))
7741 (push from fpoints)
7742 (if (re-search-forward "^[^ \t]" nil t)
7743 (forward-char -2)
7744 (goto-char (point-max)))
7745 (gnus-put-text-property from (point) 'face field-face)))))))
7747 (defun gnus-article-highlight-signature ()
7748 "Highlight the signature in an article.
7749 It does this by highlighting everything after
7750 `gnus-signature-separator' using the face `gnus-signature'."
7751 (interactive)
7752 (gnus-with-article-buffer
7753 (let ((inhibit-point-motion-hooks t))
7754 (save-restriction
7755 (when (and gnus-signature-face
7756 (gnus-article-narrow-to-signature))
7757 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7758 'face gnus-signature-face)
7759 (widen)
7760 (gnus-article-search-signature)
7761 (let ((start (match-beginning 0))
7762 (end (set-marker (make-marker) (1+ (match-end 0)))))
7763 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7764 end)))))))
7766 (defun gnus-button-in-region-p (b e prop)
7767 "Say whether PROP exists in the region."
7768 (text-property-not-all b e prop nil))
7770 (defun gnus-article-add-buttons ()
7771 "Find external references in the article and make buttons of them.
7772 \"External references\" are things like Message-IDs and URLs, as
7773 specified by `gnus-button-alist'."
7774 (interactive)
7775 (gnus-with-article-buffer
7776 (let ((inhibit-point-motion-hooks t)
7777 (case-fold-search t)
7778 (alist gnus-button-alist)
7779 beg entry regexp)
7780 ;; We skip the headers.
7781 (article-goto-body)
7782 (setq beg (point))
7783 (while (setq entry (pop alist))
7784 (setq regexp (eval (car entry)))
7785 (goto-char beg)
7786 (while (re-search-forward regexp nil t)
7787 (let ((start (match-beginning (nth 1 entry)))
7788 (end (match-end (nth 1 entry)))
7789 (from (match-beginning 0)))
7790 (when (and (eval (nth 2 entry))
7791 (not (gnus-button-in-region-p
7792 start end 'gnus-callback)))
7793 ;; That optional form returned non-nil, so we add the
7794 ;; button.
7795 (setq from (set-marker (make-marker) from))
7796 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7797 (gnus-article-extend-url-button from start end))
7798 (gnus-article-add-button start end
7799 'gnus-button-push (list from entry))
7800 (gnus-put-text-property
7801 start end
7802 'gnus-string (buffer-substring-no-properties
7803 start end))))))))))
7805 (defun gnus-article-extend-url-button (beg start end)
7806 "Extend url button if url is folded into two or more lines.
7807 Return non-nil if button is extended. BEG is a marker that points to
7808 the beginning position of a text containing url. START and END are
7809 the endpoints of a url button before it is extended. The concatenated
7810 url is put as the `gnus-button-url' overlay property on the button."
7811 (let ((opoint (point))
7812 (points (list start end))
7813 url delim regexp)
7814 (prog1
7815 (when (and (progn
7816 (goto-char end)
7817 (not (looking-at "[\t ]*[\">]")))
7818 (progn
7819 (goto-char start)
7820 (string-match
7821 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7822 (buffer-substring (point-at-bol) start)))
7823 (progn
7824 (setq url (list (buffer-substring start end))
7825 delim (if (match-beginning 1) ">" "\""))
7826 (beginning-of-line)
7827 (setq regexp (concat
7828 (when (and (looking-at
7829 message-cite-prefix-regexp)
7830 (< (match-end 0) start))
7831 (regexp-quote (match-string 0)))
7833 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7834 delim "\\)"))
7835 (while (progn
7836 (forward-line 1)
7837 (and (looking-at regexp)
7838 (prog1
7839 (match-beginning 1)
7840 (push (or (match-string 2)
7841 (match-string 1))
7842 url)
7843 (push (setq end (or (match-end 2)
7844 (match-end 1)))
7845 points)
7846 (push (or (match-beginning 2)
7847 (match-beginning 1))
7848 points)))))
7849 (match-beginning 2)))
7850 (let (gnus-article-mouse-face widget-mouse-face)
7851 (while points
7852 (gnus-article-add-button (pop points) (pop points)
7853 'gnus-button-push beg)))
7854 (let ((overlay (gnus-make-overlay start end)))
7855 (gnus-overlay-put overlay 'evaporate t)
7856 (gnus-overlay-put overlay 'gnus-button-url
7857 (list (mapconcat 'identity (nreverse url) "")))
7858 (when gnus-article-mouse-face
7859 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7861 (goto-char opoint))))
7863 ;; Add buttons to the head of an article.
7864 (defun gnus-article-add-buttons-to-head ()
7865 "Add buttons to the head of the article."
7866 (interactive)
7867 (gnus-with-article-headers
7868 (let (beg end)
7869 (dolist (entry gnus-header-button-alist)
7870 ;; Each alist entry.
7871 (goto-char (point-min))
7872 (while (re-search-forward (car entry) nil t)
7873 ;; Each header matching the entry.
7874 (setq beg (match-beginning 0))
7875 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7876 (match-beginning 0))
7877 (point-max)))
7878 (goto-char beg)
7879 (while (re-search-forward (eval (nth 1 entry)) end t)
7880 ;; Each match within a header.
7881 (let* ((entry (cdr entry))
7882 (start (match-beginning (nth 1 entry)))
7883 (end (match-end (nth 1 entry)))
7884 (form (nth 2 entry)))
7885 (goto-char (match-end 0))
7886 (when (eval form)
7887 (gnus-article-add-button
7888 start end (nth 3 entry)
7889 (buffer-substring (match-beginning (nth 4 entry))
7890 (match-end (nth 4 entry)))))))
7891 (goto-char end))))))
7893 ;;; External functions:
7895 (defun gnus-article-add-button (from to fun &optional data text)
7896 "Create a button between FROM and TO with callback FUN and data DATA."
7897 (when gnus-article-button-face
7898 (gnus-overlay-put (gnus-make-overlay from to nil t)
7899 'face gnus-article-button-face))
7900 (gnus-add-text-properties
7901 from to
7902 (nconc (and gnus-article-mouse-face
7903 (list gnus-mouse-face-prop gnus-article-mouse-face))
7904 (list 'gnus-callback fun)
7905 (and data (list 'gnus-data data))))
7906 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7907 :help-echo (or text "Follow the link")
7908 :keymap gnus-url-button-map
7909 :button-keymap gnus-widget-button-keymap))
7911 (defun gnus-article-copy-string ()
7912 "Copy the string in the button to the kill ring."
7913 (interactive)
7914 (gnus-article-check-buffer)
7915 (let ((data (get-text-property (point) 'gnus-string)))
7916 (when data
7917 (with-temp-buffer
7918 (insert data)
7919 (copy-region-as-kill (point-min) (point-max))
7920 (message "Copied %s" data)))))
7922 ;;; Internal functions:
7924 (defun gnus-article-set-globals ()
7925 (with-current-buffer gnus-summary-buffer
7926 (gnus-set-global-variables)))
7928 (defun gnus-signature-toggle (end)
7929 (gnus-with-article-buffer
7930 (let ((inhibit-point-motion-hooks t))
7931 (if (text-property-any end (point-max) 'article-type 'signature)
7932 (progn
7933 (gnus-delete-wash-type 'signature)
7934 (gnus-remove-text-properties-when
7935 'article-type 'signature end (point-max)
7936 (cons 'article-type (cons 'signature
7937 gnus-hidden-properties))))
7938 (gnus-add-wash-type 'signature)
7939 (gnus-add-text-properties-when
7940 'article-type nil end (point-max)
7941 (cons 'article-type (cons 'signature
7942 gnus-hidden-properties)))))
7943 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7944 (gnus-set-mode-line 'article))))
7946 (defun gnus-button-push (marker-and-entry)
7947 ;; Push button starting at MARKER.
7948 (save-excursion
7949 (let* ((marker (car marker-and-entry))
7950 (entry (cadr marker-and-entry))
7951 (regexp (car entry))
7952 (inhibit-point-motion-hooks t))
7953 (goto-char marker)
7954 ;; This is obviously true, or something bad is happening :)
7955 ;; But we need it to have the match-data
7956 (when (looking-at (or (if (symbolp regexp)
7957 (symbol-value regexp)
7958 regexp)))
7959 (let ((fun (nth 3 entry))
7960 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7961 (get-char-property marker 'gnus-button-url))
7962 (mapcar (lambda (group)
7963 (let ((string (match-string group)))
7964 (set-text-properties
7965 0 (length string) nil string)
7966 string))
7967 (nthcdr 4 entry)))))
7969 (cond
7970 ((fboundp fun)
7971 (apply fun args))
7972 ((and (boundp fun)
7973 (fboundp (symbol-value fun)))
7974 (apply (symbol-value fun) args))
7976 (gnus-message 1 "You must define `%S' to use this button"
7977 (cons fun args)))))))))
7979 (defun gnus-parse-news-url (url)
7980 (let (scheme server port group message-id articles)
7981 (with-temp-buffer
7982 (insert url)
7983 (goto-char (point-min))
7984 (when (looking-at "\\([A-Za-z]+\\):")
7985 (setq scheme (match-string 1))
7986 (goto-char (match-end 0)))
7987 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7988 (setq server (match-string 1))
7989 (setq port (if (stringp (match-string 3))
7990 (string-to-number (match-string 3))
7991 (match-string 3)))
7992 (goto-char (match-end 0)))
7994 (cond
7995 ((looking-at "\\(.*@.*\\)")
7996 (setq message-id (match-string 1)))
7997 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7998 (setq group (match-string 1)
7999 articles (split-string (match-string 2) "-")))
8000 ((looking-at "\\([^/]+\\)/?")
8001 (setq group (match-string 1)))
8003 (error "Unknown news URL syntax"))))
8004 (list scheme server port group message-id articles)))
8006 (defun gnus-button-handle-news (url)
8007 "Fetch a news URL."
8008 (destructuring-bind (scheme server port group message-id articles)
8009 (gnus-parse-news-url url)
8010 (cond
8011 (message-id
8012 (with-current-buffer gnus-summary-buffer
8013 (if server
8014 (let ((gnus-refer-article-method
8015 (nconc (list (list 'nntp server))
8016 gnus-refer-article-method))
8017 (nntp-port-number (or port "nntp")))
8018 (gnus-message 7 "Fetching %s with %s"
8019 message-id gnus-refer-article-method)
8020 (gnus-summary-refer-article message-id))
8021 (gnus-summary-refer-article message-id))))
8022 (group
8023 (gnus-button-fetch-group url)))))
8025 (defun gnus-button-patch (library line)
8026 "Visit an Emacs Lisp library LIBRARY on line LINE."
8027 (interactive)
8028 (let ((file (locate-library (file-name-nondirectory library))))
8029 (unless file
8030 (error "Couldn't find library %s" library))
8031 (find-file file)
8032 (goto-char (point-min))
8033 (forward-line (1- (string-to-number line)))))
8035 (defun gnus-button-handle-man (url)
8036 "Fetch a man page."
8037 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8038 (when (eq gnus-button-man-handler 'woman)
8039 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8040 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8041 (funcall gnus-button-man-handler url))
8043 (defun gnus-button-handle-info-url (url)
8044 "Fetch an info URL."
8045 (setq url (mm-subst-char-in-string ?+ ?\ url))
8046 (cond
8047 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8048 (gnus-info-find-node
8049 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8050 "Gnus")
8051 ")" (gnus-url-unhex-string (match-string 2 url)))))
8052 ((string-match "([^)\"]+)[^\"]+" url)
8053 (setq url
8054 (gnus-replace-in-string
8055 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8056 (gnus-info-find-node url))
8057 (t (error "Can't parse %s" url))))
8059 (defun gnus-button-handle-info-url-gnome (url)
8060 "Fetch GNOME style info URL."
8061 (setq url (mm-subst-char-in-string ?_ ?\ url))
8062 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8063 (gnus-info-find-node
8064 (concat "("
8065 (gnus-url-unhex-string
8066 (match-string 1 url))
8068 (or (gnus-url-unhex-string
8069 (match-string 2 url))
8070 "Top")))
8071 (error "Can't parse %s" url)))
8073 (defun gnus-button-handle-info-url-kde (url)
8074 "Fetch KDE style info URL."
8075 (gnus-info-find-node (gnus-url-unhex-string url)))
8077 ;; (info) will autoload info.el
8078 (declare-function Info-menu "info" (menu-item &optional fork))
8079 (declare-function Info-index-next "info" (num))
8081 (defun gnus-button-handle-info-keystrokes (url)
8082 "Call `info' when pushing the corresponding URL button."
8083 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8084 (let (node indx comma)
8085 (if (string-match
8086 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8087 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8088 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8089 "\\(?:[ \t\n,]*\\)\\)?")
8090 url)
8091 (setq node (match-string 2 url)
8092 indx (match-string 3 url))
8093 (error "Can't parse %s" url))
8094 (info)
8095 (Info-directory)
8096 (Info-menu node)
8097 (when (> (length indx) 0)
8098 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8099 "\\([ \t\n,]*\\)")
8100 indx)
8101 (setq comma (match-string 2 indx))
8102 (setq indx (match-string 1 indx))
8103 (Info-index indx)
8104 (when comma
8105 (dotimes (i (with-temp-buffer
8106 (insert comma)
8107 ;; Note: the XEmacs version of `how-many' takes
8108 ;; no optional argument.
8109 (goto-char (point-min))
8110 (how-many ",")))
8111 (Info-index-next 1)))
8112 nil)))
8114 (autoload 'pgg-snarf-keys-region "pgg")
8115 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8116 (declare-function pgg-display-output-buffer "pgg" (start end status))
8118 (defun gnus-button-openpgp (url)
8119 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8120 (with-temp-buffer
8121 (mm-url-insert-file-contents-external url)
8122 (pgg-snarf-keys-region (point-min) (point-max))
8123 (pgg-display-output-buffer nil nil nil)))
8125 (defun gnus-button-message-id (message-id)
8126 "Fetch MESSAGE-ID."
8127 (with-current-buffer gnus-summary-buffer
8128 (gnus-summary-refer-article message-id)))
8130 (defun gnus-button-fetch-group (address &rest ignore)
8131 "Fetch GROUP specified by ADDRESS."
8132 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8133 address)
8134 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8135 ;; for nntp:// and news://
8136 (setq address (match-string 3 address)))
8137 (if (not (string-match "[:/]" address))
8138 ;; This is just a simple group url.
8139 (gnus-group-read-ephemeral-group address gnus-select-method)
8140 (if (not
8141 (string-match
8142 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8143 address))
8144 (error "Can't parse %s" address)
8145 (gnus-group-read-ephemeral-group
8146 (match-string 4 address)
8147 `(nntp ,(match-string 1 address)
8148 (nntp-address ,(match-string 1 address))
8149 (nntp-port-number ,(if (match-end 3)
8150 (match-string 3 address)
8151 "nntp")))
8152 nil nil nil
8153 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8155 (defun gnus-url-parse-query-string (query &optional downcase)
8156 (let (retval pairs cur key val)
8157 (setq pairs (split-string query "&"))
8158 (while pairs
8159 (setq cur (car pairs)
8160 pairs (cdr pairs))
8161 (if (not (string-match "=" cur))
8162 nil ; Grace
8163 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8164 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8165 (if downcase
8166 (setq key (downcase key)))
8167 (setq cur (assoc key retval))
8168 (if cur
8169 (setcdr cur (cons val (cdr cur)))
8170 (setq retval (cons (list key val) retval)))))
8171 retval))
8173 (defun gnus-url-mailto (url)
8174 ;; Send mail to someone
8175 (setq url (replace-regexp-in-string "\n" " " url))
8176 (when (string-match "mailto:/*\\(.*\\)" url)
8177 (setq url (substring url (match-beginning 1) nil)))
8178 (let (to args subject func)
8179 (setq args (gnus-url-parse-query-string
8180 (if (string-match "^\\?" url)
8181 (substring url 1)
8182 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8183 (concat "to=" (match-string 1 url) "&"
8184 (match-string 2 url))
8185 (concat "to=" url))))
8186 subject (cdr-safe (assoc "subject" args)))
8187 (gnus-msg-mail)
8188 (while args
8189 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8190 (if (fboundp func)
8191 (funcall func)
8192 (message-position-on-field (caar args)))
8193 (insert (gnus-replace-in-string
8194 (mapconcat 'identity (reverse (cdar args)) ", ")
8195 "\r\n" "\n" t))
8196 (setq args (cdr args)))
8197 (if subject
8198 (message-goto-body)
8199 (message-goto-subject))))
8201 (defun gnus-button-embedded-url (address)
8202 "Activate ADDRESS with `browse-url'."
8203 (browse-url (gnus-strip-whitespace address)))
8205 ;;; Next/prev buttons in the article buffer.
8207 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8208 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8210 (defvar gnus-prev-page-map
8211 (let ((map (make-sparse-keymap)))
8212 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8213 (define-key map "\r" 'gnus-button-prev-page)
8214 map))
8216 (defvar gnus-next-page-map
8217 (let ((map (make-sparse-keymap)))
8218 (define-key map gnus-mouse-2 'gnus-button-next-page)
8219 (define-key map "\r" 'gnus-button-next-page)
8220 map))
8222 (defun gnus-insert-prev-page-button ()
8223 (let ((b (point)) e
8224 (inhibit-read-only t))
8225 (gnus-eval-format
8226 gnus-prev-page-line-format nil
8227 `(keymap ,gnus-prev-page-map
8228 gnus-prev t
8229 gnus-callback gnus-article-button-prev-page
8230 article-type annotation))
8231 (setq e (if (bolp)
8232 ;; Exclude a newline.
8233 (1- (point))
8234 (point)))
8235 (when gnus-article-button-face
8236 (gnus-overlay-put (gnus-make-overlay b e nil t)
8237 'face gnus-article-button-face))
8238 (widget-convert-button
8239 'link b e
8240 :action 'gnus-button-prev-page
8241 :button-keymap gnus-prev-page-map)))
8243 (defun gnus-button-next-page (&optional args more-args)
8244 "Go to the next page."
8245 (interactive)
8246 (let ((win (selected-window)))
8247 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8248 (gnus-article-next-page)
8249 (select-window win)))
8251 (defun gnus-button-prev-page (&optional args more-args)
8252 "Go to the prev page."
8253 (interactive)
8254 (let ((win (selected-window)))
8255 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8256 (gnus-article-prev-page)
8257 (select-window win)))
8259 (defun gnus-insert-next-page-button ()
8260 (let ((b (point)) e
8261 (inhibit-read-only t))
8262 (gnus-eval-format gnus-next-page-line-format nil
8263 `(keymap ,gnus-next-page-map
8264 gnus-next t
8265 gnus-callback gnus-article-button-next-page
8266 article-type annotation))
8267 (setq e (if (bolp)
8268 ;; Exclude a newline.
8269 (1- (point))
8270 (point)))
8271 (when gnus-article-button-face
8272 (gnus-overlay-put (gnus-make-overlay b e nil t)
8273 'face gnus-article-button-face))
8274 (widget-convert-button
8275 'link b e
8276 :action 'gnus-button-next-page
8277 :button-keymap gnus-next-page-map)))
8279 (defun gnus-article-button-next-page (arg)
8280 "Go to the next page."
8281 (interactive "P")
8282 (let ((win (selected-window)))
8283 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8284 (gnus-article-next-page)
8285 (select-window win)))
8287 (defun gnus-article-button-prev-page (arg)
8288 "Go to the prev page."
8289 (interactive "P")
8290 (let ((win (selected-window)))
8291 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8292 (gnus-article-prev-page)
8293 (select-window win)))
8295 (defvar gnus-decode-header-methods
8296 '(mail-decode-encoded-word-region)
8297 "List of methods used to decode headers.
8299 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8300 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8301 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8302 whose names match REGEXP.
8304 For example:
8305 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8306 mail-decode-encoded-word-region
8307 (\"chinese\" . rfc1843-decode-region))
8310 (defvar gnus-decode-header-methods-cache nil)
8312 (defun gnus-multi-decode-header (start end)
8313 "Apply the functions from `gnus-encoded-word-methods' that match."
8314 (unless (and gnus-decode-header-methods-cache
8315 (eq gnus-newsgroup-name
8316 (car gnus-decode-header-methods-cache)))
8317 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8318 (dolist (x gnus-decode-header-methods)
8319 (if (symbolp x)
8320 (nconc gnus-decode-header-methods-cache (list x))
8321 (if (and gnus-newsgroup-name
8322 (string-match (car x) gnus-newsgroup-name))
8323 (nconc gnus-decode-header-methods-cache
8324 (list (cdr x)))))))
8325 (let ((xlist gnus-decode-header-methods-cache))
8326 (pop xlist)
8327 (save-restriction
8328 (narrow-to-region start end)
8329 (while xlist
8330 (funcall (pop xlist) (point-min) (point-max))))))
8333 ;;; Treatment top-level handling.
8336 (defvar gnus-inhibit-article-treatments nil)
8338 (defun gnus-treat-article (gnus-treat-condition
8339 &optional part-number total-parts gnus-treat-type)
8340 (let ((gnus-treat-length (- (point-max) (point-min)))
8341 (alist gnus-treatment-function-alist)
8342 (article-goto-body-goes-to-point-min-p t)
8343 (treated-type
8344 (or (not gnus-treat-type)
8345 (catch 'found
8346 (let ((list gnus-article-treat-types))
8347 (while list
8348 (when (string-match (pop list) gnus-treat-type)
8349 (throw 'found t)))))))
8350 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8351 val elem)
8352 (gnus-run-hooks 'gnus-part-display-hook)
8353 (dolist (elem alist)
8354 (setq val
8355 (save-excursion
8356 (when (gnus-buffer-live-p gnus-summary-buffer)
8357 (set-buffer gnus-summary-buffer))
8358 (symbol-value (car elem))))
8359 (when (and (or (consp val)
8360 treated-type)
8361 (or (not gnus-inhibit-article-treatments)
8362 (eq gnus-treat-condition 'head))
8363 (gnus-treat-predicate val)
8364 (or (not (get (car elem) 'highlight))
8365 highlightp))
8366 (save-restriction
8367 (funcall (cadr elem)))))))
8369 ;; Dynamic variables.
8370 (defvar part-number)
8371 (defvar total-parts)
8372 (defvar gnus-treat-type)
8373 (defvar gnus-treat-condition)
8374 (defvar gnus-treat-length)
8376 (defun gnus-treat-predicate (val)
8377 (cond
8378 ((null val)
8379 nil)
8380 (gnus-treat-condition
8381 (eq gnus-treat-condition val))
8382 ((and (listp val)
8383 (stringp (car val)))
8384 (apply 'gnus-or (mapcar `(lambda (s)
8385 (string-match s ,(or gnus-newsgroup-name "")))
8386 val)))
8387 ((listp val)
8388 (let ((pred (pop val)))
8389 (cond
8390 ((eq pred 'or)
8391 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8392 ((eq pred 'and)
8393 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8394 ((eq pred 'not)
8395 (not (gnus-treat-predicate (car val))))
8396 ((eq pred 'typep)
8397 (equal (car val) gnus-treat-type))
8399 (error "%S is not a valid predicate" pred)))))
8400 ((eq val t)
8402 ((eq val 'head)
8403 nil)
8404 ((eq val 'first)
8405 (eq part-number 1))
8406 ((eq val 'last)
8407 (eq part-number total-parts))
8408 ((numberp val)
8409 (< gnus-treat-length val))
8411 (error "%S is not a valid value" val))))
8413 (defun gnus-article-encrypt-body (protocol &optional n)
8414 "Encrypt the article body."
8415 (interactive
8416 (list
8417 (or gnus-article-encrypt-protocol
8418 (gnus-completing-read "Encrypt protocol"
8419 (mapcar 'car gnus-article-encrypt-protocol-alist)
8421 current-prefix-arg))
8422 ;; User might hit `K E' instead of `K e', so prompt once.
8423 (when (and gnus-article-encrypt-protocol
8424 gnus-novice-user)
8425 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8426 (error "Encrypt aborted")))
8427 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8428 (unless func
8429 (error "Can't find the encrypt protocol %s" protocol))
8430 (if (member gnus-newsgroup-name '("nndraft:delayed"
8431 "nndraft:drafts"
8432 "nndraft:queue"))
8433 (error "Can't encrypt the article in group %s"
8434 gnus-newsgroup-name))
8435 (gnus-summary-iterate n
8436 (with-current-buffer gnus-summary-buffer
8437 (let ((mail-parse-charset gnus-newsgroup-charset)
8438 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8439 (summary-buffer gnus-summary-buffer)
8440 references point)
8441 (gnus-set-global-variables)
8442 (when (gnus-group-read-only-p)
8443 (error "The current newsgroup does not support article encrypt"))
8444 (gnus-summary-show-article t)
8445 (setq references
8446 (or (mail-header-references gnus-current-headers) ""))
8447 (set-buffer gnus-article-buffer)
8448 (let* ((inhibit-read-only t)
8449 (headers
8450 (mapcar (lambda (field)
8451 (and (save-restriction
8452 (message-narrow-to-head)
8453 (goto-char (point-min))
8454 (search-forward field nil t))
8455 (prog2
8456 (message-narrow-to-field)
8457 (buffer-string)
8458 (delete-region (point-min) (point-max))
8459 (widen))))
8460 '("Content-Type:" "Content-Transfer-Encoding:"
8461 "Content-Disposition:"))))
8462 (message-narrow-to-head)
8463 (message-remove-header "MIME-Version")
8464 (goto-char (point-max))
8465 (setq point (point))
8466 (insert (apply 'concat headers))
8467 (widen)
8468 (narrow-to-region point (point-max))
8469 (let ((message-options message-options))
8470 (message-options-set 'message-sender user-mail-address)
8471 (message-options-set 'message-recipients user-mail-address)
8472 (message-options-set 'message-sign-encrypt 'not)
8473 (funcall func))
8474 (goto-char (point-min))
8475 (insert "MIME-Version: 1.0\n")
8476 (widen)
8477 (gnus-summary-edit-article-done
8478 references nil summary-buffer t))
8479 (when gnus-keep-backlog
8480 (gnus-backlog-remove-article
8481 (car gnus-article-current) (cdr gnus-article-current)))
8482 (gnus-flush-original-article-buffer)
8483 (when gnus-use-cache
8484 (gnus-cache-update-article
8485 (car gnus-article-current) (cdr gnus-article-current))))))))
8487 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8488 "The following specs can be used:
8489 %t The security MIME type
8490 %i Additional info
8491 %d Details
8492 %D Details if button is pressed")
8494 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8495 "The following specs can be used:
8496 %t The security MIME type
8497 %i Additional info
8498 %d Details
8499 %D Details if button is pressed")
8501 (defvar gnus-mime-security-button-line-format-alist
8502 '((?t gnus-tmp-type ?s)
8503 (?i gnus-tmp-info ?s)
8504 (?d gnus-tmp-details ?s)
8505 (?D gnus-tmp-pressed-details ?s)))
8507 (defvar gnus-mime-security-button-commands
8508 '((gnus-article-press-button "\r" "Show Detail")
8509 (undefined "v")
8510 (undefined "t")
8511 (undefined "C")
8512 (gnus-mime-security-save-part "o" "Save...")
8513 (undefined "\C-o")
8514 (undefined "r")
8515 (undefined "d")
8516 (undefined "c")
8517 (undefined "i")
8518 (undefined "E")
8519 (undefined "e")
8520 (undefined "p")
8521 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8522 (undefined ".")))
8524 (defvar gnus-mime-security-button-map
8525 (let ((map (make-sparse-keymap)))
8526 (define-key map gnus-mouse-2 'gnus-article-push-button)
8527 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8528 (dolist (c gnus-mime-security-button-commands)
8529 (define-key map (cadr c) (car c)))
8530 map))
8532 (easy-menu-define
8533 gnus-mime-security-button-menu gnus-mime-security-button-map
8534 "Security button menu."
8535 `("Security Part"
8536 ,@(delq nil
8537 (mapcar (lambda (c)
8538 (unless (eq (car c) 'undefined)
8539 (vector (caddr c) (car c) :active t)))
8540 gnus-mime-security-button-commands))))
8542 (defun gnus-mime-security-button-menu (event prefix)
8543 "Construct a context-sensitive menu of security commands."
8544 (interactive "e\nP")
8545 (save-window-excursion
8546 (let ((pos (event-start event)))
8547 (select-window (posn-window pos))
8548 (goto-char (posn-point pos))
8549 (gnus-article-check-buffer)
8550 (popup-menu gnus-mime-security-button-menu nil prefix))))
8552 (defvar gnus-mime-security-details-buffer nil)
8554 (defvar gnus-mime-security-button-pressed nil)
8556 (defvar gnus-mime-security-show-details-inline t
8557 "If non-nil, show details in the article buffer.")
8559 (defun gnus-mime-security-verify-or-decrypt (handle)
8560 (mm-remove-parts (cdr handle))
8561 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8562 point (inhibit-read-only t))
8563 (if region
8564 (goto-char (car region)))
8565 (setq point (point))
8566 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8567 (let* ((mm-verify-option 'known)
8568 (mm-decrypt-option 'known)
8569 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8570 (unless (eq nparts (cdr handle))
8571 (mm-destroy-parts (cdr handle))
8572 (setcdr handle nparts))))
8573 (gnus-mime-display-security handle)
8574 (when region
8575 (delete-region (point) (cdr region))
8576 (set-marker (car region) nil)
8577 (set-marker (cdr region) nil))
8578 (goto-char point)))
8580 (defun gnus-mime-security-show-details (handle)
8581 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8582 (if (not details)
8583 (gnus-message 5 "No details.")
8584 (if gnus-mime-security-show-details-inline
8585 (let ((gnus-mime-security-button-pressed
8586 (not (get-text-property (point) 'gnus-mime-details)))
8587 (gnus-mime-security-button-line-format
8588 (get-text-property (point) 'gnus-line-format))
8589 (inhibit-read-only t))
8590 (forward-char -1)
8591 (while (eq (get-text-property (point) 'gnus-line-format)
8592 gnus-mime-security-button-line-format)
8593 (forward-char -1))
8594 (forward-char)
8595 (save-restriction
8596 (narrow-to-region (point) (point))
8597 (gnus-insert-mime-security-button handle))
8598 (delete-region (point)
8599 (or (text-property-not-all
8600 (point) (point-max)
8601 'gnus-line-format
8602 gnus-mime-security-button-line-format)
8603 (point-max))))
8604 ;; Not inlined.
8605 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8606 (with-current-buffer gnus-mime-security-details-buffer
8607 (erase-buffer)
8609 (setq gnus-mime-security-details-buffer
8610 (gnus-get-buffer-create "*MIME Security Details*")))
8611 (with-current-buffer gnus-mime-security-details-buffer
8612 (insert details)
8613 (goto-char (point-min)))
8614 (pop-to-buffer gnus-mime-security-details-buffer)))))
8616 (defun gnus-mime-security-press-button (handle)
8617 (save-excursion
8618 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8619 (gnus-mime-security-show-details handle)
8620 (gnus-mime-security-verify-or-decrypt handle))))
8622 (defun gnus-insert-mime-security-button (handle &optional displayed)
8623 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8624 (gnus-tmp-type
8625 (concat
8626 (or (nth 2 (assoc protocol mm-verify-function-alist))
8627 (nth 2 (assoc protocol mm-decrypt-function-alist))
8628 "Unknown")
8629 (if (equal (car handle) "multipart/signed")
8630 " Signed" " Encrypted")
8631 " Part"))
8632 (gnus-tmp-info
8633 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8634 "Undecided"))
8635 (gnus-tmp-details
8636 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8637 gnus-tmp-pressed-details
8638 b e)
8639 (setq gnus-tmp-details
8640 (if gnus-tmp-details
8641 (concat "\n" gnus-tmp-details)
8642 ""))
8643 (setq gnus-tmp-pressed-details
8644 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8645 (unless (bolp)
8646 (insert "\n"))
8647 (setq b (point))
8648 (gnus-eval-format
8649 gnus-mime-security-button-line-format
8650 gnus-mime-security-button-line-format-alist
8651 `(keymap ,gnus-mime-security-button-map
8652 gnus-callback gnus-mime-security-press-button
8653 gnus-line-format ,gnus-mime-security-button-line-format
8654 gnus-mime-details ,gnus-mime-security-button-pressed
8655 article-type annotation
8656 gnus-data ,handle))
8657 (setq e (if (bolp)
8658 ;; Exclude a newline.
8659 (1- (point))
8660 (point)))
8661 (when gnus-article-button-face
8662 (gnus-overlay-put (gnus-make-overlay b e nil t)
8663 'face gnus-article-button-face))
8664 (widget-convert-button
8665 'link b e
8666 :mime-handle handle
8667 :action 'gnus-widget-press-button
8668 :button-keymap gnus-mime-security-button-map
8669 :help-echo
8670 (lambda (widget)
8671 ;; Needed to properly clear the message due to a bug in
8672 ;; wid-edit (XEmacs only).
8673 (when (boundp 'help-echo-owns-message)
8674 (setq help-echo-owns-message t))
8675 (format
8676 "%S: show detail; %S: more options"
8677 (aref gnus-mouse-2 0)
8678 (aref gnus-down-mouse-3 0))))))
8680 (defun gnus-mime-display-security (handle)
8681 (save-restriction
8682 (narrow-to-region (point) (point))
8683 (unless (gnus-unbuttonized-mime-type-p (car handle))
8684 (gnus-insert-mime-security-button handle))
8685 (gnus-mime-display-part (cadr handle))
8686 (unless (bolp)
8687 (insert "\n"))
8688 (unless (gnus-unbuttonized-mime-type-p (car handle))
8689 (let ((gnus-mime-security-button-line-format
8690 gnus-mime-security-button-end-line-format))
8691 (gnus-insert-mime-security-button handle)))
8692 (mm-set-handle-multipart-parameter
8693 handle 'gnus-region
8694 (cons (set-marker (make-marker) (point-min))
8695 (set-marker (make-marker) (point-max))))
8696 (goto-char (point-max))))
8698 (defun gnus-mime-security-run-function (function)
8699 "Run FUNCTION with the security part under point."
8700 (gnus-article-check-buffer)
8701 (let ((data (get-text-property (point) 'gnus-data))
8702 buffer handle)
8703 (when (and (stringp (car-safe data))
8704 (setq buffer (mm-handle-multipart-original-buffer data))
8705 (setq handle (cadr data)))
8706 (if (bufferp (mm-handle-buffer handle))
8707 (progn
8708 (setq handle (cons buffer (copy-sequence (cdr handle))))
8709 (mm-handle-set-undisplayer handle nil))
8710 (setq handle (mm-make-handle
8711 buffer
8712 (mm-handle-multipart-ctl-parameter handle 'protocol)
8713 nil nil nil nil nil nil)))
8714 (funcall function handle))))
8716 (defun gnus-mime-security-save-part ()
8717 "Save the security part under point."
8718 (interactive)
8719 (gnus-mime-security-run-function 'mm-save-part))
8721 (defun gnus-mime-security-pipe-part ()
8722 "Pipe the security part under point to a process."
8723 (interactive)
8724 (gnus-mime-security-run-function 'mm-pipe-part))
8726 (gnus-ems-redefine)
8728 (provide 'gnus-art)
8730 (run-hooks 'gnus-art-load-hook)
8732 ;;; gnus-art.el ends here