Merge from emacs-24; up to 2013-01-02T16:37:04Z!eggert@cs.ucla.edu
[emacs.git] / lisp / gnus / gnus-art.el
blobe65b9fb99e4a2f4cb0e25c142fb17c6b9b2ed50b
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2013 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; For Emacs <22.2 and XEmacs.
28 (eval-and-compile
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30 (eval-when-compile
31 (require 'cl))
32 (defvar tool-bar-map)
33 (defvar w3m-minor-mode-map)
35 (require 'gnus)
36 (require 'gnus-sum)
37 (require 'gnus-spec)
38 (require 'gnus-int)
39 (require 'gnus-win)
40 (require 'mm-bodies)
41 (require 'mail-parse)
42 (require 'mm-decode)
43 (require 'mm-view)
44 (require 'wid-edit)
45 (require 'mm-uu)
46 (require 'message)
47 (require 'mouse)
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
57 (defgroup gnus-article nil
58 "Article display."
59 :link '(custom-manual "(gnus)Article Buffer")
60 :group 'gnus)
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
65 :group 'gnus-article)
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
70 :group 'gnus-article)
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
75 :group 'gnus-article
76 :group 'gnus-visual)
78 (defgroup gnus-article-signature nil
79 "Article signatures."
80 :link '(custom-manual "(gnus)Article Signature")
81 :group 'gnus-article)
83 (defgroup gnus-article-headers nil
84 "Article headers."
85 :link '(custom-manual "(gnus)Hiding Headers")
86 :group 'gnus-article)
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
91 :group 'gnus-article)
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
96 :group 'gnus-article)
98 (defgroup gnus-article-saving nil
99 "Saving articles."
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
119 (mapcar
120 (lambda (header)
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice regexp
167 (repeat regexp))
168 :group 'gnus-article-hiding)
170 (defcustom gnus-visible-headers
171 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
172 "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
175 :type '(choice
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
179 (or (stringp value)
180 (widget-editable-list-match widget value)))
181 regexp)
182 (const :tag "Use gnus-ignored-headers" nil)
183 regexp)
184 :group 'gnus-article-hiding)
186 (defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189 "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
192 this list."
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
210 :type '(set (const :tag "Headers with no content." empty)
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
217 (const :tag "Date less than four days old." date)
218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
219 (const :tag "Multiple To and/or Cc headers." many-to))
220 :group 'gnus-article-hiding)
222 (defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text. Boring text is controlled by
227 `gnus-article-boring-faces'."
228 :version "22.1"
229 :type 'boolean
230 :group 'gnus-article-hiding)
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234 This can also be a list of regexps. In that case, it will be checked
235 from head to tail looking for a separator. Searches will be done from
236 the end of the buffer."
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
238 (regexp)
239 (repeat :tag "List of regexp" regexp))
240 :group 'gnus-article-signature)
242 (defcustom gnus-signature-limit nil
243 "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number. If it is a floating point number, no signature may be
246 longer (in lines) than that number. If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer. If it is a string, it will be used as a
249 regexp. If it matches, the text in question is not a signature.
251 This can also be a list of the above values."
252 :type '(choice (const nil)
253 (integer :value 200)
254 (number :value 4.0)
255 function
256 (regexp :value ".*"))
257 :group 'gnus-article-signature)
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
261 :type 'sexp
262 :group 'gnus-article-hiding)
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
271 "{ echo \
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | ee -")
274 (if (gnus-image-type-available-p 'pbm)
275 'gnus-display-x-face-in-from
276 "{ echo \
277 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
278 ; uncompface; } | icontopbm | display -"))
279 "*String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
284 function)
285 :version "21.1"
286 :group 'gnus-picon
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
296 For example,
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
298 :version "21.1"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
303 banner
304 :variable-document
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
307 :parameter-type
308 '(choice :tag "Banner"
309 :value nil
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
312 regexp
313 (const :tag "None" nil))
314 :parameter-document
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
321 directly.")
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 :type '(repeat
334 (cons
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
339 regexp
340 (const :tag "None" nil))))
341 :version "22.1"
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
345 `(let ((format "\
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 ,@body))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
356 (nth 2 value))
357 value)))
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
364 "\\'"))
365 pattern)
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
368 (= (nth 2 value) 2)
369 (nth 3 value))
370 value))))
372 (defcustom gnus-emphasis-alist
373 (let ((types
374 '(("\\*" "\\*" bold nil 2)
375 ("_" "_" underline)
376 ("/" "/" italic)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
381 (nconc
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
385 (or (nth 3 spec) 2)
386 (or (nth 4 spec) 3)
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
388 types))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "*Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
407 :type
408 '(repeat
409 (menu-choice
410 :format "%[Customizing Style%]\n%v"
411 :indent 2
412 (group :tag "Default"
413 :value ("" 0 0 default)
414 :value-create
415 (lambda (widget)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
418 :args))
419 :value)))
420 (if (not (eq (nth 2 value) 'default))
421 (widget-put
422 widget
423 :value
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
426 regexp
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
429 face)
430 (group :tag "Simple"
431 :value (("_" . "_") nil default)
432 (cons :format "%v"
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
437 face)))
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
443 value)))
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
451 :version "21.1"
452 :group 'gnus-article-emphasis
453 :type 'regexp)
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
496 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
497 "Format for display of Date headers in article bodies.
498 See `format-time-string' for the possible values.
500 The variable can also be function, which should return a complete Date
501 header. The function is called with one argument, the time, which can
502 be fed to `format-time-string'."
503 :type '(choice string function)
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
507 (defcustom gnus-save-all-headers t
508 "*If non-nil, don't remove any headers before saving.
509 This will be overridden by the `:headers' property that the symbol of
510 the saver function, which is specified by `gnus-default-article-saver',
511 might have."
512 :group 'gnus-article-saving
513 :type 'boolean)
515 (defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517 If it is nil, no prompting will be done, and the articles will be
518 saved to the default files. If this variable is `always', each and
519 every article that is saved will be preceded by a prompt, even when
520 saving large batches of articles. If this variable is neither nil not
521 `always', there the user will be prompted once for a file name for
522 each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
526 (sexp :tag "once" :format "%t\n" :value t)))
528 (defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531 If that variable is nil, however, all headers that match this regexp
532 will be kept while the rest will be deleted before saving. This and
533 `gnus-save-all-headers' will be overridden by the `:headers' property
534 that the symbol of the saver function, which is specified by
535 `gnus-default-article-saver', might have."
536 :group 'gnus-article-saving
537 :type 'regexp)
539 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
540 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
541 "A function to save articles in your favorite format.
542 The function will be called by way of the `gnus-summary-save-article'
543 command, and friends such as `gnus-summary-save-article-rmail'.
545 Gnus provides the following functions:
547 * gnus-summary-save-in-rmail (Rmail format)
548 * gnus-summary-save-in-mail (Unix mail format)
549 * gnus-summary-save-in-folder (MH folder)
550 * gnus-summary-save-in-file (article format)
551 * gnus-summary-save-body-in-file (article body)
552 * gnus-summary-save-in-vm (use VM's folder format)
553 * gnus-summary-write-to-file (article format -- overwrite)
554 * gnus-summary-write-body-to-file (article body -- overwrite)
555 * gnus-summary-save-in-pipe (article format)
557 The symbol of each function may have the following properties:
559 * :decode
560 The value non-nil means save decoded articles. This is meaningful
561 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
562 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
563 `gnus-summary-save-in-pipe'.
565 * :function
566 The value specifies an alternative function which appends, not
567 overwrites, articles to a file. This implies that when saving many
568 articles at a time, `gnus-prompt-before-saving' is bound to t and all
569 articles are saved in a single file. This is meaningful only with
570 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
572 * :headers
573 The value specifies the symbol of a variable of which the value
574 specifies headers to be saved. If it is omitted,
575 `gnus-save-all-headers' and `gnus-saved-headers' control what
576 headers should be saved."
577 :group 'gnus-article-saving
578 :type '(radio (function-item gnus-summary-save-in-rmail)
579 (function-item gnus-summary-save-in-mail)
580 (function-item gnus-summary-save-in-folder)
581 (function-item gnus-summary-save-in-file)
582 (function-item gnus-summary-save-body-in-file)
583 (function-item gnus-summary-save-in-vm)
584 (function-item gnus-summary-write-to-file)
585 (function-item gnus-summary-write-body-to-file)
586 (function-item gnus-summary-save-in-pipe)
587 (function)))
589 (defcustom gnus-article-save-coding-system
590 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
591 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
592 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
593 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
594 "Coding system used to save decoded articles to a file.
596 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
597 which can safely encode any characters in text. This is used by the
598 commands including:
600 * gnus-summary-save-article-file
601 * gnus-summary-save-article-body-file
602 * gnus-summary-write-article-file
603 * gnus-summary-write-article-body-file
605 and the functions to which you may set `gnus-default-article-saver':
607 * gnus-summary-save-in-file
608 * gnus-summary-save-body-in-file
609 * gnus-summary-write-to-file
610 * gnus-summary-write-body-to-file
612 Those commands and functions save just text displayed in the article
613 buffer to a file if the value of this variable is non-nil. Note that
614 buttonized MIME parts will be lost in a saved file in that case.
615 Otherwise, raw articles will be saved."
616 :group 'gnus-article-saving
617 :type `(choice
618 :format "%{%t%}:\n %[Value Menu%] %v"
619 (const :tag "Save raw articles" nil)
620 ,@(delq nil
621 (mapcar
622 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
623 '((const :tag "UTF-8" utf-8)
624 (const :tag "iso-2022-7bit" iso-2022-7bit)
625 (const :tag "Emacs internal" emacs-mule)
626 (const :tag "escape-quoted" escape-quoted))))
627 (symbol :tag "Coding system")))
629 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
630 "A function generating a file name to save articles in Rmail format.
631 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
632 :group 'gnus-article-saving
633 :type 'function)
635 (defcustom gnus-mail-save-name 'gnus-plain-save-name
636 "A function generating a file name to save articles in Unix mail format.
637 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
638 :group 'gnus-article-saving
639 :type 'function)
641 (defcustom gnus-folder-save-name 'gnus-folder-save-name
642 "A function generating a file name to save articles in MH folder.
643 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
644 :group 'gnus-article-saving
645 :type 'function)
647 (defcustom gnus-file-save-name 'gnus-numeric-save-name
648 "A function generating a file name to save articles in article format.
649 The function is called with NEWSGROUP, HEADERS, and optional
650 LAST-FILE."
651 :group 'gnus-article-saving
652 :type 'function)
654 (defcustom gnus-split-methods
655 '((gnus-article-archive-name)
656 (gnus-article-nndoc-name))
657 "*Variable used to suggest where articles are to be saved.
658 For instance, if you would like to save articles related to Gnus in
659 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
660 you could set this variable to something like:
662 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
663 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
665 This variable is an alist where the key is the match and the
666 value is a list of possible files to save in if the match is
667 non-nil.
669 If the match is a string, it is used as a regexp match on the
670 article. If the match is a symbol, that symbol will be funcalled
671 from the buffer of the article to be saved with the newsgroup as the
672 parameter. If it is a list, it will be evalled in the same buffer.
674 If this form or function returns a string, this string will be used as a
675 possible file name; and if it returns a non-nil list, that list will be
676 used as possible file names."
677 :group 'gnus-article-saving
678 :type '(repeat (choice (list :value (fun) function)
679 (cons :value ("" "") regexp (repeat string))
680 (sexp :value nil))))
682 (defcustom gnus-page-delimiter "^\^L"
683 "*Regexp describing what to use as article page delimiters.
684 The default value is \"^\^L\", which is a form linefeed at the
685 beginning of a line."
686 :type 'regexp
687 :group 'gnus-article-various)
689 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
690 "*The format specification for the article mode line.
691 See `gnus-summary-mode-line-format' for a closer description.
693 The following additional specs are available:
695 %w The article washing status.
696 %m The number of MIME parts in the article."
697 :version "24.1"
698 :type 'string
699 :group 'gnus-article-various)
701 (defcustom gnus-article-mode-hook nil
702 "*A hook for Gnus article mode."
703 :type 'hook
704 :group 'gnus-article-various)
706 (when (featurep 'xemacs)
707 ;; Extracted from gnus-xmas-define in order to preserve user settings
708 (when (fboundp 'turn-off-scroll-in-place)
709 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
710 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
711 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
713 (defcustom gnus-article-menu-hook nil
714 "*Hook run after the creation of the article mode menu."
715 :type 'hook
716 :group 'gnus-article-various)
718 (defcustom gnus-article-prepare-hook nil
719 "*A hook called after an article has been prepared in the article buffer."
720 :type 'hook
721 :group 'gnus-article-various)
723 (defcustom gnus-copy-article-ignored-headers nil
724 "List of headers to be removed when copying an article.
725 Each element is a regular expression."
726 :version "23.1" ;; No Gnus
727 :type '(repeat regexp)
728 :group 'gnus-article-various)
730 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
731 "Gnus 5.10 (Emacs 22.1)")
733 (defface gnus-button
734 '((t (:weight bold)))
735 "Face used for highlighting a button in the article buffer."
736 :group 'gnus-article-buttons)
738 (defcustom gnus-article-button-face 'gnus-button
739 "Face used for highlighting buttons in the article buffer.
741 An article button is a piece of text that you can activate by pressing
742 `RET' or `mouse-2' above it."
743 :type 'face
744 :group 'gnus-article-buttons)
746 (defcustom gnus-article-mouse-face 'highlight
747 "Face used for mouse highlighting in the article buffer.
749 Article buttons will be displayed in this face when the cursor is
750 above them."
751 :type 'face
752 :group 'gnus-article-buttons)
754 (defcustom gnus-signature-face 'gnus-signature
755 "Face used for highlighting a signature in the article buffer.
756 Obsolete; use the face `gnus-signature' for customizations instead."
757 :type 'face
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
761 (defface gnus-signature
762 '((t
763 (:italic t)))
764 "Face used for highlighting a signature in the article buffer."
765 :group 'gnus-article-highlight
766 :group 'gnus-article-signature)
767 ;; backward-compatibility alias
768 (put 'gnus-signature-face 'face-alias 'gnus-signature)
769 (put 'gnus-signature-face 'obsolete-face "22.1")
771 (defface gnus-header-from
772 '((((class color)
773 (background dark))
774 (:foreground "PaleGreen1"))
775 (((class color)
776 (background light))
777 (:foreground "red3"))
779 (:italic t)))
780 "Face used for displaying from headers."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
783 ;; backward-compatibility alias
784 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
785 (put 'gnus-header-from-face 'obsolete-face "22.1")
787 (defface gnus-header-subject
788 '((((class color)
789 (background dark))
790 (:foreground "SeaGreen1"))
791 (((class color)
792 (background light))
793 (:foreground "red4"))
795 (:bold t :italic t)))
796 "Face used for displaying subject headers."
797 :group 'gnus-article-headers
798 :group 'gnus-article-highlight)
799 ;; backward-compatibility alias
800 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
801 (put 'gnus-header-subject-face 'obsolete-face "22.1")
803 (defface gnus-header-newsgroups
804 '((((class color)
805 (background dark))
806 (:foreground "yellow" :italic t))
807 (((class color)
808 (background light))
809 (:foreground "MidnightBlue" :italic t))
811 (:italic t)))
812 "Face used for displaying newsgroups headers.
813 In the default setup this face is only used for crossposted
814 articles."
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
817 ;; backward-compatibility alias
818 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
819 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
821 (defface gnus-header-name
822 '((((class color)
823 (background dark))
824 (:foreground "SpringGreen2"))
825 (((class color)
826 (background light))
827 (:foreground "maroon"))
829 (:bold t)))
830 "Face used for displaying header names."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight)
833 ;; backward-compatibility alias
834 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
835 (put 'gnus-header-name-face 'obsolete-face "22.1")
837 (defface gnus-header-content
838 '((((class color)
839 (background dark))
840 (:foreground "SpringGreen1" :italic t))
841 (((class color)
842 (background light))
843 (:foreground "indianred4" :italic t))
845 (:italic t))) "Face used for displaying header content."
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight)
848 ;; backward-compatibility alias
849 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
850 (put 'gnus-header-content-face 'obsolete-face "22.1")
852 (defcustom gnus-header-face-alist
853 '(("From" nil gnus-header-from)
854 ("Subject" nil gnus-header-subject)
855 ("Newsgroups:.*," nil gnus-header-newsgroups)
856 ("" gnus-header-name gnus-header-content))
857 "*Controls highlighting of article headers.
859 An alist of the form (HEADER NAME CONTENT).
861 HEADER is a regular expression which should match the name of a
862 header and NAME and CONTENT are either face names or nil.
864 The name of each header field will be displayed using the face
865 specified by the first element in the list where HEADER matches
866 the header name and NAME is non-nil. Similarly, the content will
867 be displayed by the first non-nil matching CONTENT face."
868 :group 'gnus-article-headers
869 :group 'gnus-article-highlight
870 :type '(repeat (list (regexp :tag "Header")
871 (choice :tag "Name"
872 (item :tag "skip" nil)
873 (face :value default))
874 (choice :tag "Content"
875 (item :tag "skip" nil)
876 (face :value default)))))
878 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
879 '((xface . (:face gnus-x-face)))
880 '((pbm . (:face gnus-x-face))
881 (png . nil)))
882 "Alist of image types and properties applied to Face and X-Face images.
883 Here are examples:
885 ;; Specify the altitude of Face images in the From header.
886 \(setq gnus-face-properties-alist
887 '((pbm . (:face gnus-x-face :ascent 80))
888 (png . (:ascent 80))))
890 ;; Show Face images as pressed buttons.
891 \(setq gnus-face-properties-alist
892 '((pbm . (:face gnus-x-face :relief -2))
893 (png . (:relief -2))))
895 See the manual for the valid properties for various image types.
896 Currently, `pbm' is used for X-Face images and `png' is used for Face
897 images in Emacs. Only the `:face' property is effective on the `xface'
898 image type in XEmacs if it is built with the libcompface library."
899 :version "23.1" ;; No Gnus
900 :group 'gnus-article-headers
901 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
903 (defcustom gnus-article-decode-hook
904 '(article-decode-charset article-decode-encoded-words
905 article-decode-group-name article-decode-idna-rhs)
906 "*Hook run to decode charsets in articles."
907 :group 'gnus-article-headers
908 :type 'hook)
910 (defcustom gnus-display-mime-function 'gnus-display-mime
911 "Function to display MIME articles."
912 :group 'gnus-article-mime
913 :type 'function)
915 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
916 "Function used to decode headers.")
918 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
919 "Function used to decode addresses.")
921 (defvar gnus-article-dumbquotes-map
922 '((?\200 "EUR")
923 (?\202 ",")
924 (?\203 "f")
925 (?\204 ",,")
926 (?\205 "...")
927 (?\213 "<")
928 (?\214 "OE")
929 (?\221 "`")
930 (?\222 "'")
931 (?\223 "``")
932 (?\224 "\"")
933 (?\225 "*")
934 (?\226 "-")
935 (?\227 "--")
936 (?\230 "~")
937 (?\231 "(TM)")
938 (?\233 ">")
939 (?\234 "oe")
940 (?\264 "'"))
941 "Table for MS-to-Latin1 translation.")
943 (defcustom gnus-ignored-mime-types nil
944 "List of MIME types that should be ignored by Gnus."
945 :version "21.1"
946 :group 'gnus-article-mime
947 :type '(repeat regexp))
949 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
950 "List of MIME types that should not be given buttons when rendered inline.
951 See also `gnus-buttonized-mime-types' which may override this variable.
952 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
953 :version "21.1"
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
957 (defcustom gnus-buttonized-mime-types nil
958 "List of MIME types that should be given buttons when rendered inline.
959 If set, this variable overrides `gnus-unbuttonized-mime-types'.
960 To see e.g. security buttons you could set this to
961 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
962 this list to display radio buttons that allow you to choose one of two
963 media types those mails include. See also `mm-discouraged-alternatives'.
964 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
965 :version "22.1"
966 :group 'gnus-article-mime
967 :type '(repeat regexp))
969 (defcustom gnus-inhibit-mime-unbuttonizing nil
970 "If non-nil, all MIME parts get buttons.
971 When nil (the default value), then some MIME parts do not get buttons,
972 as described by the variables `gnus-buttonized-mime-types' and
973 `gnus-unbuttonized-mime-types'."
974 :version "22.1"
975 :group 'gnus-article-mime
976 :type 'boolean)
978 (defcustom gnus-body-boundary-delimiter "_"
979 "String used to delimit header and body.
980 This variable is used by `gnus-article-treat-body-boundary' which can
981 be controlled by `gnus-treat-body-boundary'."
982 :version "22.1"
983 :group 'gnus-article-various
984 :type '(choice (item :tag "None" :value nil)
985 string))
987 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
988 "/usr/share/picons")
989 "Defines the location of the faces database.
990 For information on obtaining this database of pretty pictures, please
991 see http://www.cs.indiana.edu/picons/ftp/index.html"
992 :version "22.1"
993 :type '(repeat directory)
994 :link '(url-link :tag "download"
995 "http://www.cs.indiana.edu/picons/ftp/index.html")
996 :link '(custom-manual "(gnus)Picons")
997 :group 'gnus-picon)
999 (defun gnus-picons-installed-p ()
1000 "Say whether picons are installed on your machine."
1001 (let ((installed nil))
1002 (dolist (database gnus-picon-databases)
1003 (when (file-exists-p database)
1004 (setq installed t)))
1005 installed))
1007 (defcustom gnus-article-mime-part-function nil
1008 "Function called with a MIME handle as the argument.
1009 This is meant for people who want to do something automatic based
1010 on parts -- for instance, adding Vcard info to a database."
1011 :group 'gnus-article-mime
1012 :type '(choice (const nil)
1013 function))
1015 (defcustom gnus-mime-multipart-functions nil
1016 "An alist of MIME types to functions to display them."
1017 :version "21.1"
1018 :group 'gnus-article-mime
1019 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1021 (defcustom gnus-article-date-headers '(combined-lapsed)
1022 "A list of Date header formats to display.
1023 Valid formats are `ut' (universal time), `local' (local time
1024 zone), `english' (readable English), `lapsed' (elapsed time),
1025 `combined-lapsed' (both the original date and the elapsed time),
1026 `original' (the original date header), `iso8601' (ISO8601
1027 format), and `user-defined' (a user-defined format defined by the
1028 `gnus-article-time-format' variable).
1030 You have as many date headers as you want in the article buffer.
1031 Some of these headers are updated automatically. See
1032 `gnus-article-update-date-headers' for details."
1033 :version "24.1"
1034 :group 'gnus-article-headers
1035 :type '(set
1036 (const :tag "Universal time (UT)" ut)
1037 (const :tag "Local time zone" local)
1038 (const :tag "Readable English" english)
1039 (const :tag "Elapsed time" lapsed)
1040 (const :tag "Original and elapsed time" combined-lapsed)
1041 (const :tag "Original date header" original)
1042 (const :tag "ISO8601 format" iso8601)
1043 (const :tag "User-defined" user-defined)))
1045 (defcustom gnus-article-update-date-headers nil
1046 "A number that says how often to update the date header (in seconds).
1047 If nil, don't update it at all."
1048 :version "24.1"
1049 :group 'gnus-article-headers
1050 :type '(choice
1051 (item :tag "Don't update" :value nil)
1052 integer))
1054 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1055 "Function called with a MIME handle as the argument.
1056 This is meant for people who want to view first matched part.
1057 For `undisplayed-alternative' (default), the first undisplayed
1058 part or alternative part is used. For `undisplayed', the first
1059 undisplayed part is used. For a function, the first part which
1060 the function return t is used. For nil, the first part is
1061 used."
1062 :version "21.1"
1063 :group 'gnus-article-mime
1064 :type '(choice
1065 (item :tag "first" :value nil)
1066 (item :tag "undisplayed" :value undisplayed)
1067 (item :tag "undisplayed or alternative"
1068 :value undisplayed-alternative)
1069 (function)))
1071 (defcustom gnus-mime-action-alist
1072 '(("save to file" . gnus-mime-save-part)
1073 ("save and strip" . gnus-mime-save-part-and-strip)
1074 ("replace with file" . gnus-mime-replace-part)
1075 ("delete part" . gnus-mime-delete-part)
1076 ("display as text" . gnus-mime-inline-part)
1077 ("view the part" . gnus-mime-view-part)
1078 ("pipe to command" . gnus-mime-pipe-part)
1079 ("toggle display" . gnus-article-press-button)
1080 ("toggle display" . gnus-article-view-part-as-charset)
1081 ("view as type" . gnus-mime-view-part-as-type)
1082 ("view internally" . gnus-mime-view-part-internally)
1083 ("view externally" . gnus-mime-view-part-externally))
1084 "An alist of actions that run on the MIME attachment."
1085 :group 'gnus-article-mime
1086 :type '(repeat (cons (string :tag "name")
1087 (function))))
1089 (defcustom gnus-auto-select-part 1
1090 "Advance to next MIME part when deleting or stripping parts.
1092 When 0, point will be placed on the same part as before. When
1093 positive (negative), move point forward (backwards) this many
1094 parts. When nil, redisplay article."
1095 :version "23.1" ;; No Gnus
1096 :group 'gnus-article-mime
1097 :type '(choice (const nil :tag "Redisplay article.")
1098 (const 1 :tag "Next part.")
1099 (const 0 :tag "Current part.")
1100 integer))
1103 ;;; The treatment variables
1106 (defvar gnus-part-display-hook nil
1107 "Hook called on parts that are to receive treatment.")
1109 (defvar gnus-article-treat-custom
1110 '(choice (const :tag "Off" nil)
1111 (const :tag "On" t)
1112 (const :tag "Header" head)
1113 (const :tag "First" first)
1114 (const :tag "Last" last)
1115 (integer :tag "Less")
1116 (repeat :tag "Groups" regexp)
1117 (sexp :tag "Predicate")))
1119 (defvar gnus-article-treat-head-custom
1120 '(choice (const :tag "Off" nil)
1121 (const :tag "Header" head)))
1123 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1124 "text/x-patch" "text/html")
1125 "Part types eligible for treatment.")
1127 (defvar gnus-inhibit-treatment nil
1128 "Whether to inhibit treatment.")
1130 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1131 "Highlight the signature.
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate. See Info node `(gnus)Customizing Articles'."
1134 :group 'gnus-article-treat
1135 :link '(custom-manual "(gnus)Customizing Articles")
1136 :type gnus-article-treat-custom)
1137 (put 'gnus-treat-highlight-signature 'highlight t)
1139 (defcustom gnus-treat-buttonize 100000
1140 "Add buttons.
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1143 :group 'gnus-article-treat
1144 :link '(custom-manual "(gnus)Customizing Articles")
1145 :type gnus-article-treat-custom)
1146 (put 'gnus-treat-buttonize 'highlight t)
1148 (defcustom gnus-treat-buttonize-head 'head
1149 "Add buttons to the head.
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate. See Info node `(gnus)Customizing Articles'."
1152 :group 'gnus-article-treat
1153 :link '(custom-manual "(gnus)Customizing Articles")
1154 :type gnus-article-treat-head-custom)
1155 (put 'gnus-treat-buttonize-head 'highlight t)
1157 (defcustom gnus-treat-date 'head
1158 "Display dates according to the `gnus-article-date-headers' variable.
1159 Valid values are nil, t, `head', `first', `last', an integer or a
1160 predicate. See Info node `(gnus)Customizing Articles'."
1161 :version "24.1"
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-emphasize 50000
1167 "Emphasize text.
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-custom)
1173 (put 'gnus-treat-emphasize 'highlight t)
1175 (defcustom gnus-treat-strip-cr nil
1176 "Remove carriage returns.
1177 Valid values are nil, t, `head', `first', `last', an integer or a
1178 predicate. See Info node `(gnus)Customizing Articles'."
1179 :version "22.1"
1180 :group 'gnus-article-treat
1181 :link '(custom-manual "(gnus)Customizing Articles")
1182 :type gnus-article-treat-custom)
1184 (defcustom gnus-treat-unsplit-urls nil
1185 "Remove newlines from within URLs.
1186 Valid values are nil, t, `head', `first', `last', an integer or a
1187 predicate. See Info node `(gnus)Customizing Articles'."
1188 :version "22.1"
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-custom)
1193 (defcustom gnus-treat-leading-whitespace nil
1194 "Remove leading whitespace in headers.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1197 :version "22.1"
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-custom)
1202 (defcustom gnus-treat-hide-headers 'head
1203 "Hide headers.
1204 Valid values are nil, t, `head', `first', `last', an integer or a
1205 predicate. See Info node `(gnus)Customizing Articles'."
1206 :group 'gnus-article-treat
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-head-custom)
1210 (defcustom gnus-treat-hide-boring-headers nil
1211 "Hide boring headers.
1212 Valid values are nil, t, `head', `first', `last', an integer or a
1213 predicate. See Info node `(gnus)Customizing Articles'."
1214 :group 'gnus-article-treat
1215 :link '(custom-manual "(gnus)Customizing Articles")
1216 :type gnus-article-treat-head-custom)
1218 (defcustom gnus-treat-hide-signature nil
1219 "Hide the signature.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-fill-article nil
1227 "Fill the article.
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate. See Info node `(gnus)Customizing Articles'."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1234 (defcustom gnus-treat-hide-citation nil
1235 "Hide cited text.
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'.
1239 See `gnus-article-highlight-citation' for variables used to
1240 control what it hides."
1241 :group 'gnus-article-treat
1242 :link '(custom-manual "(gnus)Customizing Articles")
1243 :type gnus-article-treat-custom)
1245 (defcustom gnus-treat-hide-citation-maybe nil
1246 "Hide cited text according to certain conditions.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'.
1250 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1251 how to control what it hides."
1252 :group 'gnus-article-treat
1253 :link '(custom-manual "(gnus)Customizing Articles")
1254 :type gnus-article-treat-custom)
1256 (defcustom gnus-treat-strip-list-identifiers 'head
1257 "Strip list identifiers from `gnus-list-identifiers`.
1258 Valid values are nil, t, `head', `first', `last', an integer or a
1259 predicate. See Info node `(gnus)Customizing Articles'."
1260 :version "21.1"
1261 :group 'gnus-article-treat
1262 :link '(custom-manual "(gnus)Customizing Articles")
1263 :type gnus-article-treat-custom)
1265 (gnus-define-group-parameter
1266 list-identifier
1267 :variable-document
1268 "Alist of regexps and correspondent identifiers."
1269 :variable-group gnus-article-washing
1270 :parameter-type
1271 '(choice :tag "Identifier"
1272 :value nil
1273 (symbol :tag "Item in `gnus-list-identifiers'" none)
1274 regexp
1275 (const :tag "None" nil))
1276 :parameter-document
1277 "If non-nil, specify how to remove `identifiers' from articles' subject.
1279 Any symbol is used to look up a regular expression to match the
1280 banner in `gnus-list-identifiers'. A string is used as a regular
1281 expression to match the identifier directly.")
1283 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1284 "Gnus 5.10 (Emacs 22.1)")
1286 (defcustom gnus-treat-strip-pem nil
1287 "Strip PEM signatures.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-custom)
1294 (defcustom gnus-treat-strip-banner t
1295 "Strip banners from articles.
1296 The banner to be stripped is specified in the `banner' group parameter.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-custom)
1303 (defcustom gnus-treat-highlight-headers 'head
1304 "Highlight the headers.
1305 Valid values are nil, t, `head', `first', `last', an integer or a
1306 predicate. See Info node `(gnus)Customizing Articles'."
1307 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :type gnus-article-treat-head-custom)
1310 (put 'gnus-treat-highlight-headers 'highlight t)
1312 (defcustom gnus-treat-highlight-citation t
1313 "Highlight cited text.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1316 :group 'gnus-article-treat
1317 :link '(custom-manual "(gnus)Customizing Articles")
1318 :type gnus-article-treat-custom)
1319 (put 'gnus-treat-highlight-citation 'highlight t)
1321 (defcustom gnus-treat-strip-headers-in-body t
1322 "Strip the X-No-Archive header line from the beginning of the body.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'."
1325 :version "21.1"
1326 :group 'gnus-article-treat
1327 :link '(custom-manual "(gnus)Customizing Articles")
1328 :type gnus-article-treat-custom)
1330 (defcustom gnus-treat-strip-trailing-blank-lines nil
1331 "Strip trailing blank lines.
1332 Valid values are nil, t, `head', `first', `last', an integer or a
1333 predicate. See Info node `(gnus)Customizing Articles'.
1335 When set to t, it also strips trailing blanks in all MIME parts.
1336 Consider to use `last' instead."
1337 :group 'gnus-article-treat
1338 :link '(custom-manual "(gnus)Customizing Articles")
1339 :type gnus-article-treat-custom)
1341 (defcustom gnus-treat-strip-leading-blank-lines nil
1342 "Strip leading blank lines.
1343 Valid values are nil, t, `head', `first', `last', an integer or a
1344 predicate. See Info node `(gnus)Customizing Articles'.
1346 When set to t, it also strips trailing blanks in all MIME parts."
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1351 (defcustom gnus-treat-strip-multiple-blank-lines nil
1352 "Strip multiple blank lines.
1353 Valid values are nil, t, `head', `first', `last', an integer or a
1354 predicate. See Info node `(gnus)Customizing Articles'."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1359 (defcustom gnus-treat-unfold-headers 'head
1360 "Unfold folded header lines.
1361 Valid values are nil, t, `head', `first', `last', an integer or a
1362 predicate. See Info node `(gnus)Customizing Articles'."
1363 :version "22.1"
1364 :group 'gnus-article-treat
1365 :link '(custom-manual "(gnus)Customizing Articles")
1366 :type gnus-article-treat-custom)
1368 (defcustom gnus-article-unfold-long-headers nil
1369 "If non-nil, allow unfolding headers even if the header is long.
1370 If it is a regexp, only long headers matching this regexp are unfolded.
1371 If it is t, all long headers are unfolded.
1373 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1374 :version "23.1" ;; No Gnus
1375 :group 'gnus-article-treat
1376 :type '(choice (const nil)
1377 (const :tag "all" t)
1378 (regexp)))
1380 (defcustom gnus-treat-fold-headers nil
1381 "Fold headers.
1382 Valid values are nil, t, `head', `first', `last', an integer or a
1383 predicate. See Info node `(gnus)Customizing Articles'."
1384 :version "22.1"
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-fold-newsgroups 'head
1390 "Fold the Newsgroups and Followup-To headers.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1393 :version "22.1"
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1398 (defcustom gnus-treat-overstrike t
1399 "Treat overstrike highlighting.
1400 Valid values are nil, t, `head', `first', `last', an integer or a
1401 predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1405 (put 'gnus-treat-overstrike 'highlight t)
1407 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1408 "Treat ANSI SGR control sequences.
1409 Valid values are nil, t, `head', `first', `last', an integer or a
1410 predicate. See Info node `(gnus)Customizing Articles'."
1411 :group 'gnus-article-treat
1412 :link '(custom-manual "(gnus)Customizing Articles")
1413 :type gnus-article-treat-custom)
1415 (make-obsolete-variable 'gnus-treat-display-xface
1416 'gnus-treat-display-x-face "Emacs 22.1")
1418 (defcustom gnus-treat-display-x-face
1419 (and (not noninteractive)
1420 (gnus-image-type-available-p 'xbm)
1421 (if (featurep 'xemacs)
1422 (featurep 'xface)
1423 (condition-case nil
1424 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1425 (executable-find "icontopbm"))
1426 ;; shell-command-to-string may signal an error, e.g. if
1427 ;; shell-file-name is not found.
1428 (error nil)))
1429 'head)
1430 "Display X-Face headers.
1431 Valid values are nil and `head'.
1432 See Info node `(gnus)Customizing Articles' and Info node
1433 `(gnus)X-Face' for details."
1434 :group 'gnus-article-treat
1435 :version "21.1"
1436 :link '(custom-manual "(gnus)Customizing Articles")
1437 :link '(custom-manual "(gnus)X-Face")
1438 :type gnus-article-treat-head-custom
1439 :set (lambda (symbol value)
1440 (set-default
1441 symbol
1442 (cond ((or (boundp symbol) (get symbol 'saved-value))
1443 value)
1444 ((boundp 'gnus-treat-display-xface)
1445 (message "\
1446 ** gnus-treat-display-xface is an obsolete variable;\
1447 use gnus-treat-display-x-face instead")
1448 (default-value 'gnus-treat-display-xface))
1449 ((get 'gnus-treat-display-xface 'saved-value)
1450 (message "\
1451 ** gnus-treat-display-xface is an obsolete variable;\
1452 use gnus-treat-display-x-face instead")
1453 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1455 value)))))
1456 (put 'gnus-treat-display-x-face 'highlight t)
1458 (defcustom gnus-treat-display-face
1459 (and (not noninteractive)
1460 (gnus-image-type-available-p 'png)
1461 'head)
1462 "Display Face headers.
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles' and Info
1465 node `(gnus)Face' for details."
1466 :group 'gnus-article-treat
1467 :version "22.1"
1468 :link '(custom-manual "(gnus)Customizing Articles")
1469 :link '(custom-manual "(gnus)X-Face")
1470 :type gnus-article-treat-head-custom)
1471 (put 'gnus-treat-display-face 'highlight t)
1473 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1474 "Display smileys.
1475 Valid values are nil, t, `head', `first', `last', an integer or a
1476 predicate. See Info node `(gnus)Customizing Articles' and Info
1477 node `(gnus)Smileys' for details."
1478 :group 'gnus-article-treat
1479 :version "21.1"
1480 :link '(custom-manual "(gnus)Customizing Articles")
1481 :link '(custom-manual "(gnus)Smileys")
1482 :type gnus-article-treat-custom)
1483 (put 'gnus-treat-display-smileys 'highlight t)
1485 (defcustom gnus-treat-from-picon
1486 (if (and (gnus-image-type-available-p 'xpm)
1487 (gnus-picons-installed-p))
1488 'head nil)
1489 "Display picons in the From header.
1490 Valid values are nil, t, `head', `first', `last', an integer or a
1491 predicate. See Info node `(gnus)Customizing Articles' and Info
1492 node `(gnus)Picons' for details."
1493 :version "22.1"
1494 :group 'gnus-article-treat
1495 :group 'gnus-picon
1496 :link '(custom-manual "(gnus)Customizing Articles")
1497 :link '(custom-manual "(gnus)Picons")
1498 :type gnus-article-treat-head-custom)
1499 (put 'gnus-treat-from-picon 'highlight t)
1501 (defcustom gnus-treat-mail-picon
1502 (if (and (gnus-image-type-available-p 'xpm)
1503 (gnus-picons-installed-p))
1504 'head nil)
1505 "Display picons in To and Cc headers.
1506 Valid values are nil, t, `head', `first', `last', an integer or a
1507 predicate. See Info node `(gnus)Customizing Articles' and Info
1508 node `(gnus)Picons' for details."
1509 :version "22.1"
1510 :group 'gnus-article-treat
1511 :group 'gnus-picon
1512 :link '(custom-manual "(gnus)Customizing Articles")
1513 :link '(custom-manual "(gnus)Picons")
1514 :type gnus-article-treat-head-custom)
1515 (put 'gnus-treat-mail-picon 'highlight t)
1517 (defcustom gnus-treat-newsgroups-picon
1518 (if (and (gnus-image-type-available-p 'xpm)
1519 (gnus-picons-installed-p))
1520 'head nil)
1521 "Display picons in the Newsgroups and Followup-To headers.
1522 Valid values are nil, t, `head', `first', `last', an integer or a
1523 predicate. See Info node `(gnus)Customizing Articles' and Info
1524 node `(gnus)Picons' for details."
1525 :version "22.1"
1526 :group 'gnus-article-treat
1527 :group 'gnus-picon
1528 :link '(custom-manual "(gnus)Customizing Articles")
1529 :link '(custom-manual "(gnus)Picons")
1530 :type gnus-article-treat-head-custom)
1531 (put 'gnus-treat-newsgroups-picon 'highlight t)
1533 (defcustom gnus-treat-from-gravatar nil
1534 "Display gravatars in the From header.
1535 Valid values are nil, t, `head', `first', `last', an integer or a
1536 predicate. See Info node `(gnus)Customizing Articles' and Info
1537 node `(gnus)Gravatars' for details."
1538 :version "24.1"
1539 :group 'gnus-article-treat
1540 :group 'gnus-gravatar
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :link '(custom-manual "(gnus)Gravatars")
1543 :type gnus-article-treat-head-custom)
1544 (put 'gnus-treat-from-gravatar 'highlight t)
1546 (defcustom gnus-treat-mail-gravatar nil
1547 "Display gravatars in To and Cc headers.
1548 Valid values are nil, t, `head', `first', `last', an integer or a
1549 predicate. See Info node `(gnus)Customizing Articles' and Info
1550 node `(gnus)Gravatars' for details."
1551 :version "24.1"
1552 :group 'gnus-article-treat
1553 :group 'gnus-gravatar
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :link '(custom-manual "(gnus)Gravatars")
1556 :type gnus-article-treat-head-custom)
1557 (put 'gnus-treat-mail-gravatar 'highlight t)
1559 (defcustom gnus-treat-body-boundary
1560 (if (or gnus-treat-newsgroups-picon
1561 gnus-treat-mail-picon
1562 gnus-treat-from-picon
1563 gnus-treat-from-gravatar
1564 gnus-treat-mail-gravatar)
1565 ;; If there's much decoration, the user might prefer a boundary.
1566 'head
1567 nil)
1568 "Draw a boundary at the end of the headers.
1569 Valid values are nil and `head'.
1570 See Info node `(gnus)Customizing Articles' for details."
1571 :version "22.1"
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-head-custom)
1576 (defcustom gnus-treat-capitalize-sentences nil
1577 "Capitalize sentence-starting words.
1578 Valid values are nil, t, `head', `first', `last', an integer or a
1579 predicate. See Info node `(gnus)Customizing Articles'."
1580 :version "21.1"
1581 :group 'gnus-article-treat
1582 :link '(custom-manual "(gnus)Customizing Articles")
1583 :type gnus-article-treat-custom)
1585 (defcustom gnus-treat-wash-html nil
1586 "Format as HTML.
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1589 :version "22.1"
1590 :group 'gnus-article-treat
1591 :link '(custom-manual "(gnus)Customizing Articles")
1592 :type gnus-article-treat-custom)
1594 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1595 "Fill long lines.
1596 Valid values are nil, t, `head', `first', `last', an integer or a
1597 predicate. See Info node `(gnus)Customizing Articles'."
1598 :version "24.1"
1599 :group 'gnus-article-treat
1600 :link '(custom-manual "(gnus)Customizing Articles")
1601 :type gnus-article-treat-custom)
1603 (defcustom gnus-treat-x-pgp-sig nil
1604 "Verify X-PGP-Sig.
1605 To automatically treat X-PGP-Sig, set it to head.
1606 Valid values are nil, t, `head', `first', `last', an integer or a
1607 predicate. See Info node `(gnus)Customizing Articles'."
1608 :version "22.1"
1609 :group 'gnus-article-treat
1610 :group 'mime-security
1611 :link '(custom-manual "(gnus)Customizing Articles")
1612 :type gnus-article-treat-custom)
1614 (defvar gnus-article-encrypt-protocol-alist
1615 '(("PGP" . mml2015-self-encrypt)))
1617 ;; Set to nil if more than one protocol added to
1618 ;; gnus-article-encrypt-protocol-alist.
1619 (defcustom gnus-article-encrypt-protocol "PGP"
1620 "The protocol used for encrypt articles.
1621 It is a string, such as \"PGP\". If nil, ask user."
1622 :version "22.1"
1623 :type 'string
1624 :group 'mime-security)
1626 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1627 (mm-coding-system-p 'utf-8)
1628 (executable-find idna-program))
1629 "Whether IDNA decoding of headers is used when viewing messages.
1630 This requires GNU Libidn, and by default only enabled if it is found."
1631 :version "22.1"
1632 :group 'gnus-article-headers
1633 :type 'boolean)
1635 (defcustom gnus-article-over-scroll nil
1636 "If non-nil, allow scrolling the article buffer even when there no more text."
1637 :version "22.1"
1638 :group 'gnus-article
1639 :type 'boolean)
1641 (defcustom gnus-inhibit-images nil
1642 "Non-nil means inhibit displaying of images inline in the article body."
1643 :version "24.1"
1644 :group 'gnus-article
1645 :type 'boolean)
1647 (defcustom gnus-blocked-images 'gnus-block-private-groups
1648 "Images that have URLs matching this regexp will be blocked.
1649 This can also be a function to be evaluated. If so, it will be
1650 called with the group name as the parameter, and should return a
1651 regexp."
1652 :version "24.1"
1653 :group 'gnus-art
1654 :type '(choice regexp function))
1656 ;;; Internal variables
1658 (defvar gnus-english-month-names
1659 '("January" "February" "March" "April" "May" "June" "July" "August"
1660 "September" "October" "November" "December"))
1662 (defvar article-goto-body-goes-to-point-min-p nil)
1663 (defvar gnus-article-wash-types nil)
1664 (defvar gnus-article-emphasis-alist nil)
1665 (defvar gnus-article-image-alist nil)
1667 (defvar gnus-article-mime-handle-alist-1 nil)
1668 (defvar gnus-treatment-function-alist
1669 '((gnus-treat-strip-cr gnus-article-remove-cr)
1670 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1671 (gnus-treat-strip-banner gnus-article-strip-banner)
1672 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1673 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1674 (gnus-treat-buttonize gnus-article-add-buttons)
1675 (gnus-treat-fill-article gnus-article-fill-cited-article)
1676 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1677 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1678 (gnus-treat-display-x-face gnus-article-display-x-face)
1679 (gnus-treat-display-face gnus-article-display-face)
1680 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1681 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1682 (gnus-treat-hide-signature gnus-article-hide-signature)
1683 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1684 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1685 (gnus-treat-from-picon gnus-treat-from-picon)
1686 (gnus-treat-mail-picon gnus-treat-mail-picon)
1687 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1688 (gnus-treat-strip-pem gnus-article-hide-pem)
1689 (gnus-treat-date gnus-article-treat-date)
1690 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1691 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1692 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1693 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1694 (gnus-treat-strip-trailing-blank-lines
1695 gnus-article-remove-trailing-blank-lines)
1696 (gnus-treat-strip-leading-blank-lines
1697 gnus-article-strip-leading-blank-lines)
1698 (gnus-treat-strip-multiple-blank-lines
1699 gnus-article-strip-multiple-blank-lines)
1700 (gnus-treat-overstrike gnus-article-treat-overstrike)
1701 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1702 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1703 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1704 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1705 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1706 (gnus-treat-display-smileys gnus-treat-smiley)
1707 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1708 (gnus-treat-wash-html gnus-article-wash-html)
1709 (gnus-treat-emphasize gnus-article-emphasize)
1710 (gnus-treat-hide-citation gnus-article-hide-citation)
1711 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1712 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1713 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1715 (defvar gnus-article-mime-handle-alist nil)
1716 (defvar article-lapsed-timer nil)
1717 (defvar gnus-article-current-summary nil)
1719 (defvar gnus-article-mode-syntax-table
1720 (let ((table (copy-syntax-table text-mode-syntax-table)))
1721 ;; This causes the citation match run O(2^n).
1722 ;; (modify-syntax-entry ?- "w" table)
1723 (modify-syntax-entry ?> ")<" table)
1724 (modify-syntax-entry ?< "(>" table)
1725 ;; make M-. in article buffers work for `foo' strings
1726 (modify-syntax-entry ?' " " table)
1727 (modify-syntax-entry ?` " " table)
1728 table)
1729 "Syntax table used in article mode buffers.
1730 Initialized from `text-mode-syntax-table.")
1732 (defvar gnus-save-article-buffer nil)
1734 (defvar gnus-number-of-articles-to-be-saved nil)
1736 (defvar gnus-inhibit-hiding nil)
1738 (defvar gnus-article-edit-mode nil)
1740 ;;; Macros for dealing with the article buffer.
1742 (defmacro gnus-with-article-headers (&rest forms)
1743 `(with-current-buffer gnus-article-buffer
1744 (save-restriction
1745 (let ((inhibit-read-only t)
1746 (inhibit-point-motion-hooks t)
1747 (case-fold-search t))
1748 (article-narrow-to-head)
1749 ,@forms))))
1751 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1752 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1754 (defmacro gnus-with-article-buffer (&rest forms)
1755 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1756 (with-current-buffer gnus-article-buffer
1757 (let ((inhibit-read-only t))
1758 ,@forms))))
1760 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1761 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1763 (defun gnus-article-goto-header (header)
1764 "Go to HEADER, which is a regular expression."
1765 (re-search-forward (concat "^\\(" header "\\):") nil t))
1767 (defsubst gnus-article-hide-text (b e props)
1768 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1769 (gnus-add-text-properties-when 'article-type nil b e props)
1770 (when (memq 'intangible props)
1771 (put-text-property
1772 (max (1- b) (point-min))
1773 b 'intangible (cddr (memq 'intangible props)))))
1775 (defsubst gnus-article-unhide-text (b e)
1776 "Remove hidden text properties from region between B and E."
1777 (remove-text-properties b e gnus-hidden-properties)
1778 (when (memq 'intangible gnus-hidden-properties)
1779 (put-text-property (max (1- b) (point-min))
1780 b 'intangible nil)))
1782 (defun gnus-article-hide-text-type (b e type)
1783 "Hide text of TYPE between B and E."
1784 (gnus-add-wash-type type)
1785 (gnus-article-hide-text
1786 b e (cons 'article-type (cons type gnus-hidden-properties))))
1788 (defun gnus-article-unhide-text-type (b e type)
1789 "Unhide text of TYPE between B and E."
1790 (gnus-delete-wash-type type)
1791 (remove-text-properties
1792 b e (cons 'article-type (cons type gnus-hidden-properties)))
1793 (when (memq 'intangible gnus-hidden-properties)
1794 (put-text-property (max (1- b) (point-min))
1795 b 'intangible nil)))
1797 (defun gnus-article-delete-text-of-type (type)
1798 "Delete text of TYPE in the current buffer."
1799 (save-excursion
1800 (let ((b (point-min)))
1801 (if (eq type 'multipart)
1802 ;; Remove MIME buttons associated with multipart/alternative parts.
1803 (progn
1804 (goto-char b)
1805 (while (if (get-text-property (point) 'gnus-part)
1806 (setq b (point))
1807 (when (setq b (next-single-property-change (point)
1808 'gnus-part))
1809 (goto-char b)
1811 (end-of-line)
1812 (skip-chars-forward "\n")
1813 (when (eq (get-text-property b 'article-type) 'multipart)
1814 (delete-region b (point)))))
1815 (while (setq b (text-property-any b (point-max) 'article-type type))
1816 (delete-region
1817 b (or (text-property-not-all b (point-max) 'article-type type)
1818 (point-max))))))))
1820 (defun gnus-article-delete-invisible-text ()
1821 "Delete all invisible text in the current buffer."
1822 (save-excursion
1823 (let ((b (point-min)))
1824 (while (setq b (text-property-any b (point-max) 'invisible t))
1825 (delete-region
1826 b (or (text-property-not-all b (point-max) 'invisible t)
1827 (point-max)))))))
1829 (defsubst gnus-article-header-rank ()
1830 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1831 (let ((list gnus-sorted-header-list)
1832 (i 1))
1833 (while list
1834 (if (looking-at (car list))
1835 (setq list nil)
1836 (setq list (cdr list))
1837 (incf i)))
1840 (defun article-hide-headers (&optional arg delete)
1841 "Hide unwanted headers and possibly sort them as well."
1842 (interactive)
1843 ;; This function might be inhibited.
1844 (unless gnus-inhibit-hiding
1845 (let ((inhibit-read-only t)
1846 (case-fold-search t)
1847 (max (1+ (length gnus-sorted-header-list)))
1848 (inhibit-point-motion-hooks t)
1849 (cur (current-buffer))
1850 ignored visible beg)
1851 (save-excursion
1852 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1853 ;; group parameters, so we should go to the summary buffer.
1854 (when (prog1
1855 (condition-case nil
1856 (progn (set-buffer gnus-summary-buffer) t)
1857 (error nil))
1858 (setq ignored (when (not gnus-visible-headers)
1859 (cond ((stringp gnus-ignored-headers)
1860 gnus-ignored-headers)
1861 ((listp gnus-ignored-headers)
1862 (mapconcat 'identity
1863 gnus-ignored-headers
1864 "\\|"))))
1865 visible (cond ((stringp gnus-visible-headers)
1866 gnus-visible-headers)
1867 ((and gnus-visible-headers
1868 (listp gnus-visible-headers))
1869 (mapconcat 'identity
1870 gnus-visible-headers
1871 "\\|")))))
1872 (set-buffer cur))
1873 (save-restriction
1874 ;; First we narrow to just the headers.
1875 (article-narrow-to-head)
1876 ;; Hide any "From " lines at the beginning of (mail) articles.
1877 (while (looking-at "From ")
1878 (forward-line 1))
1879 (unless (bobp)
1880 (delete-region (point-min) (point)))
1881 ;; Then treat the rest of the header lines.
1882 ;; Then we use the two regular expressions
1883 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1884 ;; select which header lines is to remain visible in the
1885 ;; article buffer.
1886 (while (re-search-forward "^[^ \t:]*:" nil t)
1887 (beginning-of-line)
1888 ;; Mark the rank of the header.
1889 (put-text-property
1890 (point) (1+ (point)) 'message-rank
1891 (if (or (and visible (looking-at visible))
1892 (and ignored
1893 (not (looking-at ignored))))
1894 (gnus-article-header-rank)
1895 (+ 2 max)))
1896 (forward-line 1))
1897 (message-sort-headers-1)
1898 (when (setq beg (text-property-any
1899 (point-min) (point-max) 'message-rank (+ 2 max)))
1900 ;; We delete the unwanted headers.
1901 (gnus-add-wash-type 'headers)
1902 (add-text-properties (point-min) (+ 5 (point-min))
1903 '(article-type headers dummy-invisible t))
1904 (delete-region beg (point-max))))))))
1906 (defun article-hide-boring-headers (&optional arg)
1907 "Toggle hiding of headers that aren't very interesting.
1908 If given a negative prefix, always show; if given a positive prefix,
1909 always hide."
1910 (interactive (gnus-article-hidden-arg))
1911 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1912 (not gnus-show-all-headers))
1913 (save-excursion
1914 (save-restriction
1915 (let ((inhibit-read-only t)
1916 (inhibit-point-motion-hooks t))
1917 (article-narrow-to-head)
1918 (dolist (elem gnus-boring-article-headers)
1919 (goto-char (point-min))
1920 (cond
1921 ;; Hide empty headers.
1922 ((eq elem 'empty)
1923 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1924 (forward-line -1)
1925 (gnus-article-hide-text-type
1926 (point-at-bol)
1927 (progn
1928 (end-of-line)
1929 (if (re-search-forward "^[^ \t]" nil t)
1930 (match-beginning 0)
1931 (point-max)))
1932 'boring-headers)))
1933 ;; Hide boring Newsgroups header.
1934 ((eq elem 'newsgroups)
1935 (when (gnus-string-equal
1936 (gnus-fetch-field "newsgroups")
1937 (gnus-group-real-name
1938 (if (boundp 'gnus-newsgroup-name)
1939 gnus-newsgroup-name
1940 "")))
1941 (gnus-article-hide-header "newsgroups")))
1942 ((eq elem 'to-address)
1943 (let ((to (message-fetch-field "to"))
1944 (to-address
1945 (gnus-parameter-to-address
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-address
1949 (ignore-errors
1950 (gnus-string-equal
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1953 to-address)))
1954 (gnus-article-hide-header "to"))))
1955 ((eq elem 'to-list)
1956 (let ((to (message-fetch-field "to"))
1957 (to-list
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and to to-list
1962 (ignore-errors
1963 (gnus-string-equal
1964 ;; only one address in To
1965 (nth 1 (mail-extract-address-components to))
1966 to-list)))
1967 (gnus-article-hide-header "to"))))
1968 ((eq elem 'cc-list)
1969 (let ((cc (message-fetch-field "cc"))
1970 (to-list
1971 (gnus-parameter-to-list
1972 (if (boundp 'gnus-newsgroup-name)
1973 gnus-newsgroup-name ""))))
1974 (when (and cc to-list
1975 (ignore-errors
1976 (gnus-string-equal
1977 ;; only one address in CC
1978 (nth 1 (mail-extract-address-components cc))
1979 to-list)))
1980 (gnus-article-hide-header "cc"))))
1981 ((eq elem 'followup-to)
1982 (when (gnus-string-equal
1983 (message-fetch-field "followup-to")
1984 (message-fetch-field "newsgroups"))
1985 (gnus-article-hide-header "followup-to")))
1986 ((eq elem 'reply-to)
1987 (if (gnus-group-find-parameter
1988 gnus-newsgroup-name 'broken-reply-to)
1989 (gnus-article-hide-header "reply-to")
1990 (let ((from (message-fetch-field "from"))
1991 (reply-to (message-fetch-field "reply-to")))
1992 (when
1993 (and
1994 from reply-to
1995 (ignore-errors
1996 (equal
1997 (sort (mapcar
1998 (lambda (x) (downcase (cadr x)))
1999 (mail-extract-address-components from t))
2000 'string<)
2001 (sort (mapcar
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components reply-to t))
2004 'string<))))
2005 (gnus-article-hide-header "reply-to")))))
2006 ((eq elem 'date)
2007 (let ((date (with-current-buffer gnus-original-article-buffer
2008 ;; If date in `gnus-article-buffer' is localized
2009 ;; (`gnus-treat-date-user-defined'),
2010 ;; `days-between' might fail.
2011 (message-fetch-field "date"))))
2012 (when (and date
2013 (< (days-between (current-time-string) date)
2015 (gnus-article-hide-header "date"))))
2016 ((eq elem 'long-to)
2017 (let ((to (message-fetch-field "to"))
2018 (cc (message-fetch-field "cc")))
2019 (when (> (length to) 1024)
2020 (gnus-article-hide-header "to"))
2021 (when (> (length cc) 1024)
2022 (gnus-article-hide-header "cc"))))
2023 ((eq elem 'many-to)
2024 (let ((to-count 0)
2025 (cc-count 0))
2026 (goto-char (point-min))
2027 (while (re-search-forward "^to:" nil t)
2028 (setq to-count (1+ to-count)))
2029 (when (> to-count 1)
2030 (while (> to-count 0)
2031 (goto-char (point-min))
2032 (save-restriction
2033 (re-search-forward "^to:" nil nil to-count)
2034 (forward-line -1)
2035 (narrow-to-region (point) (point-max))
2036 (gnus-article-hide-header "to"))
2037 (setq to-count (1- to-count))))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^cc:" nil t)
2040 (setq cc-count (1+ cc-count)))
2041 (when (> cc-count 1)
2042 (while (> cc-count 0)
2043 (goto-char (point-min))
2044 (save-restriction
2045 (re-search-forward "^cc:" nil nil cc-count)
2046 (forward-line -1)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "cc"))
2049 (setq cc-count (1- cc-count)))))))))))))
2051 (defun gnus-article-hide-header (header)
2052 (save-excursion
2053 (goto-char (point-min))
2054 (when (re-search-forward (concat "^" header ":") nil t)
2055 (gnus-article-hide-text-type
2056 (point-at-bol)
2057 (progn
2058 (end-of-line)
2059 (if (re-search-forward "^[^ \t]" nil t)
2060 (match-beginning 0)
2061 (point-max)))
2062 'boring-headers))))
2064 (defvar gnus-article-normalized-header-length 40
2065 "Length of normalized headers.")
2067 (defun article-normalize-headers ()
2068 "Make all header lines 40 characters long."
2069 (interactive)
2070 (let ((inhibit-read-only t)
2071 column)
2072 (save-excursion
2073 (save-restriction
2074 (article-narrow-to-head)
2075 (while (not (eobp))
2076 (cond
2077 ((< (setq column (- (point-at-eol) (point)))
2078 gnus-article-normalized-header-length)
2079 (end-of-line)
2080 (insert (make-string
2081 (- gnus-article-normalized-header-length column)
2082 ? )))
2083 ((> column gnus-article-normalized-header-length)
2084 (gnus-put-text-property
2085 (progn
2086 (forward-char gnus-article-normalized-header-length)
2087 (point))
2088 (point-at-eol)
2089 'invisible t))
2091 ;; Do nothing.
2093 (forward-line 1))))))
2095 (defun article-treat-dumbquotes ()
2096 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2097 Note that this function guesses whether a character is a sm*rtq**t* or
2098 not, so it should only be used interactively.
2100 Sm*rtq**t*s are M****s***'s unilateral extension to the
2101 iso-8859-1 character map in an attempt to provide more quoting
2102 characters. If you see something like \\222 or \\264 where
2103 you're expecting some kind of apostrophe or quotation mark, then
2104 try this wash."
2105 (interactive)
2106 (article-translate-strings gnus-article-dumbquotes-map))
2108 (defvar org-entities)
2110 (defun article-treat-non-ascii ()
2111 "Translate many Unicode characters into their ASCII equivalents."
2112 (interactive)
2113 (require 'org-entities)
2114 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2115 (dolist (elem org-entities)
2116 (when (and (listp elem)
2117 (= (length (nth 6 elem)) 1))
2118 (if (featurep 'xemacs)
2119 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2120 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2121 (save-excursion
2122 (when (article-goto-body)
2123 (let ((inhibit-read-only t)
2124 replace props)
2125 (while (not (eobp))
2126 (if (not (setq replace (if (featurep 'xemacs)
2127 (get-char-table (following-char) table)
2128 (aref table (following-char)))))
2129 (forward-char 1)
2130 (if (prog1
2131 (setq props (text-properties-at (point)))
2132 (delete-char 1))
2133 (add-text-properties (point) (progn (insert replace) (point))
2134 props)
2135 (insert replace)))))))))
2137 (defun article-translate-strings (map)
2138 "Translate all string in the body of the article according to MAP.
2139 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2140 (save-excursion
2141 (when (article-goto-body)
2142 (let ((inhibit-read-only t))
2143 (dolist (elem map)
2144 (let ((from (car elem))
2145 (to (cadr elem)))
2146 (save-excursion
2147 (if (stringp from)
2148 (while (search-forward from nil t)
2149 (replace-match to))
2150 (while (not (eobp))
2151 (if (eq (following-char) from)
2152 (progn
2153 (delete-char 1)
2154 (insert to))
2155 (forward-char 1)))))))))))
2157 (defun article-treat-overstrike ()
2158 "Translate overstrikes into bold text."
2159 (interactive)
2160 (save-excursion
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (while (search-forward "\b" nil t)
2164 (let ((next (char-after))
2165 (previous (char-after (- (point) 2))))
2166 ;; We do the boldification/underlining by hiding the
2167 ;; overstrikes and putting the proper text property
2168 ;; on the letters.
2169 (cond
2170 ((eq next previous)
2171 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2172 (put-text-property (point) (1+ (point)) 'face 'bold))
2173 ((eq next ?_)
2174 (gnus-article-hide-text-type
2175 (1- (point)) (1+ (point)) 'overstrike)
2176 (put-text-property
2177 (- (point) 2) (1- (point)) 'face 'underline))
2178 ((eq previous ?_)
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2180 (put-text-property
2181 (point) (1+ (point)) 'face 'underline)))))))))
2183 (defun article-treat-ansi-sequences ()
2184 "Translate ANSI SGR control sequences into overlays or extents."
2185 (interactive)
2186 (save-excursion
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (ansi-color-apply-on-region (point) (point-max))))))
2191 (defun gnus-article-treat-unfold-headers ()
2192 "Unfold folded message headers.
2193 Only the headers that fit into the current window width will be
2194 unfolded."
2195 (interactive)
2196 (gnus-with-article-headers
2197 (let (length)
2198 (while (not (eobp))
2199 (save-restriction
2200 (mail-header-narrow-to-field)
2201 (let* ((header (buffer-string))
2202 (unfoldable
2203 (or (equal gnus-article-unfold-long-headers t)
2204 (and (stringp gnus-article-unfold-long-headers)
2205 (string-match gnus-article-unfold-long-headers
2206 header)))))
2207 (with-temp-buffer
2208 (insert header)
2209 (goto-char (point-min))
2210 (while (re-search-forward "\n[\t ]" nil t)
2211 (replace-match " " t t)))
2212 (setq length (- (point-max) (point-min) 1))
2213 (when (or unfoldable
2214 (< length (window-width)))
2215 (while (re-search-forward "\n[\t ]" nil t)
2216 (replace-match " " t t))))
2217 (goto-char (point-max)))))))
2219 (defun gnus-article-treat-fold-headers ()
2220 "Fold message headers."
2221 (interactive)
2222 (gnus-with-article-headers
2223 (while (not (eobp))
2224 (save-restriction
2225 (mail-header-narrow-to-field)
2226 (mail-header-fold-field)
2227 (goto-char (point-max))))))
2229 (defun gnus-treat-smiley ()
2230 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2231 (interactive)
2232 (gnus-with-article-buffer
2233 (if (memq 'smiley gnus-article-wash-types)
2234 (gnus-delete-images 'smiley)
2235 (article-goto-body)
2236 (let ((images (smiley-region (point) (point-max))))
2237 (when images
2238 (gnus-add-wash-type 'smiley)
2239 (dolist (image images)
2240 (gnus-add-image 'smiley image)))))))
2242 (defun gnus-article-remove-images ()
2243 "Remove all images from the article buffer."
2244 (interactive)
2245 (gnus-with-article-buffer
2246 (save-restriction
2247 (widen)
2248 (dolist (elem gnus-article-image-alist)
2249 (gnus-delete-images (car elem))))))
2251 (autoload 'w3m-toggle-inline-images "w3m")
2253 (defun gnus-article-show-images ()
2254 "Show any images that are in the HTML-rendered article buffer.
2255 This only works if the article in question is HTML."
2256 (interactive)
2257 (gnus-with-article-buffer
2258 (save-restriction
2259 (widen)
2260 (if (eq mm-text-html-renderer 'w3m)
2261 (let ((mm-inline-text-html-with-images nil))
2262 (w3m-toggle-inline-images))
2263 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2264 'image-displayer))
2265 (destructuring-bind (start end function) region
2266 (funcall function (get-text-property start 'image-url)
2267 start end)))))))
2269 (defun gnus-article-treat-fold-newsgroups ()
2270 "Unfold folded message headers.
2271 Only the headers that fit into the current window width will be
2272 unfolded."
2273 (interactive)
2274 (gnus-with-article-headers
2275 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2276 (save-restriction
2277 (mail-header-narrow-to-field)
2278 (while (re-search-forward ", *" nil t)
2279 (replace-match ", " t t))
2280 (mail-header-fold-field)
2281 (goto-char (point-max))))))
2283 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2284 "Value of `truncate-lines' in Gnus Article buffer.
2285 Valid values are nil, t, `head', `first', `last', an integer or a
2286 predicate. See Info node `(gnus)Customizing Articles'."
2287 :version "23.1" ;; No Gnus
2288 :group 'gnus-article
2289 ;; :link '(custom-manual "(gnus)Customizing Articles")
2290 :type 'boolean)
2292 (defun gnus-article-toggle-truncate-lines (&optional arg)
2293 "Toggle whether to fold or truncate long lines in article the buffer.
2294 If ARG is non-nil and not a number, toggle
2295 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2296 long lines if and only if arg is positive."
2297 (interactive "P")
2298 (cond
2299 ((and (numberp arg) (> arg 0))
2300 (setq gnus-article-truncate-lines t))
2301 ((numberp arg)
2302 (setq gnus-article-truncate-lines nil))
2303 (arg
2304 (setq gnus-article-truncate-lines
2305 (not gnus-article-truncate-lines))))
2306 (gnus-with-article-buffer
2307 (cond
2308 ((and (numberp arg) (> arg 0))
2309 (setq truncate-lines nil))
2310 ((numberp arg)
2311 (setq truncate-lines t)))
2312 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2313 ;; `toggle-truncate-lines' needs an argument.
2314 (toggle-truncate-lines)))
2316 (defun gnus-article-treat-body-boundary ()
2317 "Place a boundary line at the end of the headers."
2318 (interactive)
2319 (when (and gnus-body-boundary-delimiter
2320 (> (length gnus-body-boundary-delimiter) 0))
2321 (gnus-with-article-headers
2322 (goto-char (point-max))
2323 (let ((start (point)))
2324 (insert "X-Boundary: ")
2325 (gnus-add-text-properties start (point) '(invisible t intangible t))
2326 (insert (let (str (max (window-width)))
2327 (if (featurep 'xemacs)
2328 (setq max (1- max)))
2329 (while (>= max (length str))
2330 (setq str (concat str gnus-body-boundary-delimiter)))
2331 (substring str 0 max))
2332 "\n")
2333 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2335 (defun article-fill-long-lines ()
2336 "Fill lines that are wider than the window width."
2337 (interactive)
2338 (save-excursion
2339 (let ((inhibit-read-only t)
2340 (width (window-width (get-buffer-window (current-buffer)))))
2341 (save-restriction
2342 (article-goto-body)
2343 (let ((adaptive-fill-mode nil)) ;Why? -sm
2344 (while (not (eobp))
2345 (end-of-line)
2346 (when (>= (current-column) (min fill-column width))
2347 (narrow-to-region (min (1+ (point)) (point-max))
2348 (point-at-bol))
2349 (let ((goback (point-marker)))
2350 (fill-paragraph nil)
2351 (goto-char (marker-position goback)))
2352 (widen))
2353 (forward-line 1)))))))
2355 (defun article-capitalize-sentences ()
2356 "Capitalize the first word in each sentence."
2357 (interactive)
2358 (save-excursion
2359 (let ((inhibit-read-only t)
2360 (paragraph-start "^[\n\^L]"))
2361 (article-goto-body)
2362 (while (not (eobp))
2363 (capitalize-word 1)
2364 (forward-sentence)))))
2366 (defun article-remove-cr ()
2367 "Remove trailing CRs and then translate remaining CRs into LFs."
2368 (interactive)
2369 (save-excursion
2370 (let ((inhibit-read-only t))
2371 (goto-char (point-min))
2372 (while (re-search-forward "\r+$" nil t)
2373 (replace-match "" t t))
2374 (goto-char (point-min))
2375 (while (search-forward "\r" nil t)
2376 (replace-match "\n" t t)))))
2378 (defun article-remove-trailing-blank-lines ()
2379 "Remove all trailing blank lines from the article."
2380 (interactive)
2381 (save-excursion
2382 (let ((inhibit-read-only t))
2383 (goto-char (point-max))
2384 (delete-region
2385 (point)
2386 (progn
2387 (while (and (not (bobp))
2388 (looking-at "^[ \t]*$")
2389 (not (gnus-annotation-in-region-p
2390 (point) (point-at-eol))))
2391 (forward-line -1))
2392 (forward-line 1)
2393 (point))))))
2395 (defvar gnus-face-properties-alist)
2397 (defun article-display-face (&optional force)
2398 "Display any Face headers in the header."
2399 (interactive (list 'force))
2400 (let ((wash-face-p buffer-read-only))
2401 (gnus-with-article-headers
2402 ;; When displaying parts, this function can be called several times on
2403 ;; the same article, without any intended toggle semantic (as typing `W
2404 ;; D d' would have). So face deletion must occur only when we come from
2405 ;; an interactive command, that is when the *Article* buffer is
2406 ;; read-only.
2407 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2408 (gnus-delete-images 'face)
2409 (let ((from (message-fetch-field "from"))
2410 face faces)
2411 (save-current-buffer
2412 (when (and wash-face-p
2413 (gnus-buffer-live-p gnus-original-article-buffer)
2414 (not (re-search-forward "^Face:[\t ]*" nil t)))
2415 (set-buffer gnus-original-article-buffer))
2416 (save-restriction
2417 (mail-narrow-to-head)
2418 (when (or force
2419 ;; Check whether this face is censored.
2420 (not (and gnus-article-x-face-too-ugly
2421 (or from
2422 (setq from (message-fetch-field "from")))
2423 (string-match gnus-article-x-face-too-ugly
2424 from))))
2425 (while (gnus-article-goto-header "Face")
2426 (push (mail-header-field-value) faces)))))
2427 (when faces
2428 (goto-char (point-min))
2429 (let (png image)
2430 (unless (setq from (gnus-article-goto-header "from"))
2431 (insert "From:")
2432 (setq from (point))
2433 (insert " [no `from' set]\n"))
2434 (while faces
2435 (when (setq png (gnus-convert-face-to-png (pop faces)))
2436 (setq image
2437 (apply 'gnus-create-image png 'png t
2438 (cdr (assq 'png gnus-face-properties-alist))))
2439 (goto-char from)
2440 (when image
2441 (gnus-add-wash-type 'face)
2442 (gnus-add-image 'face image)
2443 (gnus-put-image image nil 'face)))))))))))
2445 (defun article-display-x-face (&optional force)
2446 "Look for an X-Face header and display it if present."
2447 (interactive (list 'force))
2448 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2449 (gnus-with-article-headers
2450 ;; Delete the old process, if any.
2451 (when (process-status "article-x-face")
2452 (delete-process "article-x-face"))
2453 ;; See the comment in `article-display-face'.
2454 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2455 ;; We have already displayed X-Faces, so we remove them
2456 ;; instead.
2457 (gnus-delete-images 'xface)
2458 ;; Display X-Faces.
2459 (let ((from (message-fetch-field "from"))
2460 x-faces face)
2461 (save-current-buffer
2462 (when (and wash-face-p
2463 (gnus-buffer-live-p gnus-original-article-buffer)
2464 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2465 ;; If type `W f', use gnus-original-article-buffer,
2466 ;; otherwise use the current buffer because displaying
2467 ;; RFC822 parts calls this function too.
2468 (set-buffer gnus-original-article-buffer))
2469 (save-restriction
2470 (mail-narrow-to-head)
2471 (and gnus-article-x-face-command
2472 (or force
2473 ;; Check whether this face is censored.
2474 (not (and gnus-article-x-face-too-ugly
2475 (or from
2476 (setq from (message-fetch-field "from")))
2477 (string-match gnus-article-x-face-too-ugly
2478 from))))
2479 (while (gnus-article-goto-header "X-Face")
2480 (push (mail-header-field-value) x-faces)))))
2481 (when x-faces
2482 ;; We display the face.
2483 (cond ((functionp gnus-article-x-face-command)
2484 ;; The command is a lisp function, so we call it.
2485 (mapc gnus-article-x-face-command x-faces))
2486 ((stringp gnus-article-x-face-command)
2487 ;; The command is a string, so we interpret the command
2488 ;; as a, well, command, and fork it off.
2489 (let ((process-connection-type nil))
2490 (gnus-set-process-query-on-exit-flag
2491 (start-process
2492 "article-x-face" nil shell-file-name
2493 shell-command-switch gnus-article-x-face-command)
2494 nil)
2495 ;; Sending multiple EOFs to xv doesn't work,
2496 ;; so we only do a single external face.
2497 (with-temp-buffer
2498 (insert (car x-faces))
2499 (process-send-region "article-x-face"
2500 (point-min) (point-max)))
2501 (process-send-eof "article-x-face")))
2503 (error "`%s' set to `%s' is not a function"
2504 gnus-article-x-face-command
2505 'gnus-article-x-face-command)))))))))
2507 (defun article-decode-mime-words ()
2508 "Decode all MIME-encoded words in the article."
2509 (interactive)
2510 (gnus-with-article-buffer
2511 (let ((inhibit-point-motion-hooks t)
2512 (mail-parse-charset gnus-newsgroup-charset)
2513 (mail-parse-ignored-charsets
2514 (with-current-buffer gnus-summary-buffer
2515 gnus-newsgroup-ignored-charsets)))
2516 (mail-decode-encoded-word-region (point-min) (point-max)))))
2518 (defun article-decode-charset (&optional prompt)
2519 "Decode charset-encoded text in the article.
2520 If PROMPT (the prefix), prompt for a coding system to use."
2521 (interactive "P")
2522 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2523 (inhibit-read-only t)
2524 (mail-parse-charset gnus-newsgroup-charset)
2525 (mail-parse-ignored-charsets
2526 (save-excursion (condition-case nil
2527 (set-buffer gnus-summary-buffer)
2528 (error))
2529 gnus-newsgroup-ignored-charsets))
2530 ct cte ctl charset format)
2531 (save-excursion
2532 (save-restriction
2533 (article-narrow-to-head)
2534 (setq ct (message-fetch-field "Content-Type" t)
2535 cte (message-fetch-field "Content-Transfer-Encoding" t)
2536 ctl (and ct (mail-header-parse-content-type ct))
2537 charset (cond
2538 (prompt
2539 (mm-read-coding-system "Charset to decode: "))
2540 (ctl
2541 (mail-content-type-get ctl 'charset)))
2542 format (and ctl (mail-content-type-get ctl 'format)))
2543 (when cte
2544 (setq cte (mail-header-strip cte)))
2545 (if (and ctl (not (string-match "/" (car ctl))))
2546 (setq ctl nil))
2547 (goto-char (point-max)))
2548 (forward-line 1)
2549 (save-restriction
2550 (narrow-to-region (point) (point-max))
2551 (when (and (eq mail-parse-charset 'gnus-decoded)
2552 (eq (mm-body-7-or-8) '8bit))
2553 ;; The text code could have been decoded.
2554 (setq charset mail-parse-charset))
2555 (when (and (or (not ctl)
2556 (equal (car ctl) "text/plain"))
2557 (not format)) ;; article with format will decode later.
2558 (mm-decode-body
2559 charset (and cte (intern (downcase
2560 (gnus-strip-whitespace cte))))
2561 (car ctl)))))))
2563 (defun article-decode-encoded-words ()
2564 "Remove encoded-word encoding from headers."
2565 (let ((inhibit-point-motion-hooks t)
2566 (mail-parse-charset gnus-newsgroup-charset)
2567 (mail-parse-ignored-charsets
2568 (save-excursion (condition-case nil
2569 (set-buffer gnus-summary-buffer)
2570 (error))
2571 gnus-newsgroup-ignored-charsets))
2572 (inhibit-read-only t)
2573 end start)
2574 (goto-char (point-min))
2575 (when (search-forward "\n\n" nil 'move)
2576 (forward-line -1))
2577 (setq end (point))
2578 (while (not (bobp))
2579 (while (progn
2580 (forward-line -1)
2581 (and (not (bobp))
2582 (memq (char-after) '(?\t ? )))))
2583 (setq start (point))
2584 (if (looking-at "\
2585 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2586 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2587 (funcall gnus-decode-address-function start end)
2588 (funcall gnus-decode-header-function start end))
2589 (goto-char (setq end start)))))
2591 (defun article-decode-group-name ()
2592 "Decode group names in Newsgroups, Followup-To and Xref headers."
2593 (let ((inhibit-point-motion-hooks t)
2594 (inhibit-read-only t)
2595 (method (gnus-find-method-for-group gnus-newsgroup-name))
2596 regexp)
2597 (when (and (or gnus-group-name-charset-method-alist
2598 gnus-group-name-charset-group-alist)
2599 (gnus-buffer-live-p gnus-original-article-buffer))
2600 (save-restriction
2601 (article-narrow-to-head)
2602 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2603 (with-current-buffer gnus-original-article-buffer
2604 (goto-char (point-min)))
2605 (setq regexp (concat "^" header
2606 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2607 (while (re-search-forward regexp nil t)
2608 (replace-match (save-match-data
2609 (gnus-decode-newsgroups
2610 ;; XXX how to use data in article buffer?
2611 (with-current-buffer gnus-original-article-buffer
2612 (re-search-forward regexp nil t)
2613 (match-string 1))
2614 gnus-newsgroup-name method))
2615 t t nil 1))
2616 (goto-char (point-min)))))))
2618 (autoload 'idna-to-unicode "idna")
2620 (defun article-decode-idna-rhs ()
2621 "Decode IDNA strings in RHS in various headers in current buffer.
2622 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2623 Mail-Reply-To: and Mail-Followup-To:."
2624 (when gnus-use-idna
2625 (save-restriction
2626 (let ((inhibit-point-motion-hooks t)
2627 (inhibit-read-only t))
2628 (article-narrow-to-head)
2629 (goto-char (point-min))
2630 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2631 (let (ace unicode)
2632 (when (save-match-data
2633 (and (setq ace (match-string 1))
2634 (save-excursion
2635 (and (re-search-backward "^[^ \t]" nil t)
2636 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2637 (setq unicode (idna-to-unicode ace))))
2638 (unless (string= ace unicode)
2639 (replace-match unicode nil nil nil 1)))))))))
2641 (defun article-de-quoted-unreadable (&optional force read-charset)
2642 "Translate a quoted-printable-encoded article.
2643 If FORCE, decode the article whether it is marked as quoted-printable
2644 or not.
2645 If READ-CHARSET, ask for a coding system."
2646 (interactive (list 'force current-prefix-arg))
2647 (save-excursion
2648 (let ((inhibit-read-only t) type charset)
2649 (if (gnus-buffer-live-p gnus-original-article-buffer)
2650 (with-current-buffer gnus-original-article-buffer
2651 (setq type
2652 (gnus-fetch-field "content-transfer-encoding"))
2653 (let* ((ct (gnus-fetch-field "content-type"))
2654 (ctl (and ct (mail-header-parse-content-type ct))))
2655 (setq charset (and ctl
2656 (mail-content-type-get ctl 'charset)))
2657 (if (stringp charset)
2658 (setq charset (intern (downcase charset)))))))
2659 (if read-charset
2660 (setq charset (mm-read-coding-system "Charset: " charset)))
2661 (unless charset
2662 (setq charset gnus-newsgroup-charset))
2663 (when (or force
2664 (and type (let ((case-fold-search t))
2665 (string-match "quoted-printable" type))))
2666 (article-goto-body)
2667 (quoted-printable-decode-region
2668 (point) (point-max) (mm-charset-to-coding-system charset))))))
2670 (defun article-de-base64-unreadable (&optional force read-charset)
2671 "Translate a base64 article.
2672 If FORCE, decode the article whether it is marked as base64 not.
2673 If READ-CHARSET, ask for a coding system."
2674 (interactive (list 'force current-prefix-arg))
2675 (save-excursion
2676 (let ((inhibit-read-only t) type charset)
2677 (if (gnus-buffer-live-p gnus-original-article-buffer)
2678 (with-current-buffer gnus-original-article-buffer
2679 (setq type
2680 (gnus-fetch-field "content-transfer-encoding"))
2681 (let* ((ct (gnus-fetch-field "content-type"))
2682 (ctl (and ct (mail-header-parse-content-type ct))))
2683 (setq charset (and ctl
2684 (mail-content-type-get ctl 'charset)))
2685 (if (stringp charset)
2686 (setq charset (intern (downcase charset)))))))
2687 (if read-charset
2688 (setq charset (mm-read-coding-system "Charset: " charset)))
2689 (unless charset
2690 (setq charset gnus-newsgroup-charset))
2691 (when (or force
2692 (and type (let ((case-fold-search t))
2693 (string-match "base64" type))))
2694 (article-goto-body)
2695 (save-restriction
2696 (narrow-to-region (point) (point-max))
2697 (base64-decode-region (point-min) (point-max))
2698 (mm-decode-coding-region
2699 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2701 (eval-when-compile
2702 (require 'rfc1843))
2704 (defun article-decode-HZ ()
2705 "Translate a HZ-encoded article."
2706 (interactive)
2707 (require 'rfc1843)
2708 (save-excursion
2709 (let ((inhibit-read-only t))
2710 (rfc1843-decode-region (point-min) (point-max)))))
2712 (defun article-unsplit-urls ()
2713 "Remove the newlines that some other mailers insert into URLs."
2714 (interactive)
2715 (save-excursion
2716 (let ((inhibit-read-only t))
2717 (goto-char (point-min))
2718 (while (re-search-forward
2719 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2720 (replace-match "\\1\\3" t)))
2721 (when (gmm-called-interactively-p 'any)
2722 (gnus-treat-article nil))))
2724 (defun article-wash-html ()
2725 "Format an HTML article."
2726 (interactive)
2727 (let ((handles nil)
2728 (buffer-read-only nil))
2729 (when (gnus-buffer-live-p gnus-original-article-buffer)
2730 (with-current-buffer gnus-original-article-buffer
2731 (setq handles (mm-dissect-buffer t t))))
2732 (article-goto-body)
2733 (delete-region (point) (point-max))
2734 (mm-enable-multibyte)
2735 (mm-inline-text-html handles)))
2737 (defvar gnus-article-browse-html-temp-list nil
2738 "List of temporary files created by `gnus-article-browse-html-parts'.
2739 Internal variable.")
2741 (defcustom gnus-article-browse-delete-temp 'ask
2742 "What to do with temporary files from `gnus-article-browse-html-parts'.
2743 If nil, don't delete temporary files. If it is t, delete them on
2744 exit from the summary buffer. If it is the symbol `file', query
2745 on each file, if it is `ask' ask once when exiting from the
2746 summary buffer."
2747 :group 'gnus-article
2748 :version "23.1" ;; No Gnus
2749 :type '(choice (const :tag "Don't delete" nil)
2750 (const :tag "Don't ask" t)
2751 (const :tag "Ask" ask)
2752 (const :tag "Ask for each file" file)))
2754 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2756 (defun gnus-article-browse-delete-temp-files (&optional how)
2757 "Delete temp-files created by `gnus-article-browse-html-parts'."
2758 (when (and gnus-article-browse-html-temp-list
2759 (progn
2760 (or how (setq how gnus-article-browse-delete-temp))
2761 (if (eq how 'ask)
2762 (let ((files (length gnus-article-browse-html-temp-list)))
2763 (or (gnus-y-or-n-p
2764 (if (= files 1)
2765 "Delete the temporary HTML file? "
2766 (format "Delete all %s temporary HTML files? "
2767 files)))
2768 (setq gnus-article-browse-html-temp-list nil)))
2769 how)))
2770 (dolist (file gnus-article-browse-html-temp-list)
2771 (cond ((file-directory-p file)
2772 (when (or (not (eq how 'file))
2773 (gnus-y-or-n-p
2774 (format
2775 "Delete temporary HTML file(s) in directory `%s'? "
2776 (file-name-as-directory file))))
2777 (gnus-delete-directory file)))
2778 ((file-exists-p file)
2779 (when (or (not (eq how 'file))
2780 (gnus-y-or-n-p
2781 (format "Delete temporary HTML file `%s'? " file)))
2782 (delete-file file)))))
2783 ;; Also remove file from the list when not deleted or if file doesn't
2784 ;; exist anymore.
2785 (setq gnus-article-browse-html-temp-list nil))
2786 gnus-article-browse-html-temp-list)
2788 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2789 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2790 Return file name."
2791 (save-match-data
2792 (let (file type)
2793 (catch 'found
2794 (dolist (handle handles)
2795 (cond
2796 ((not (listp handle)))
2797 ((equal (mm-handle-media-supertype handle) "multipart")
2798 (when (setq file (gnus-article-browse-html-save-cid-content
2799 cid handle directory))
2800 (throw 'found file)))
2801 ((equal (concat "<" cid ">") (mm-handle-id handle))
2802 (setq file
2803 (expand-file-name
2804 (or (mm-handle-filename handle)
2805 (concat
2806 (make-temp-name "cid")
2807 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2808 directory))
2809 (mm-save-part-to-file handle file)
2810 (throw 'found file))))))))
2812 (defun gnus-article-browse-html-parts (list &optional header)
2813 "View all \"text/html\" parts from LIST.
2814 Recurse into multiparts. The optional HEADER that should be a decoded
2815 message header will be added to the bodies of the \"text/html\" parts."
2816 ;; Internal function used by `gnus-article-browse-html-article'.
2817 (let (type file charset content cid-dir tmp-file showed)
2818 ;; Find and show the html-parts.
2819 (dolist (handle list)
2820 ;; If HTML, show it:
2821 (cond ((not (listp handle)))
2822 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2823 (and (equal (car type) "message/external-body")
2824 (or header
2825 (setq file (mm-handle-filename handle)))
2826 (or (mm-handle-cache handle)
2827 (condition-case code
2828 (progn (mm-extern-cache-contents handle) t)
2829 (error
2830 (gnus-message 3 "%s" (error-message-string code))
2831 (when (>= gnus-verbose 3) (sit-for 2))
2832 nil)))
2833 (progn
2834 (setq handle (mm-handle-cache handle)
2835 type (mm-handle-type handle))
2836 (equal (car type) "text/html"))))
2837 (setq charset (mail-content-type-get type 'charset)
2838 content (mm-get-part handle))
2839 (with-temp-buffer
2840 (if (eq charset 'gnus-decoded)
2841 (mm-enable-multibyte)
2842 (mm-disable-multibyte))
2843 (insert content)
2844 ;; resolve cid contents
2845 (let ((case-fold-search t)
2846 cid-file)
2847 (goto-char (point-min))
2848 (while (re-search-forward "\
2849 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2850 nil t)
2851 (unless cid-dir
2852 (setq cid-dir (mm-make-temp-file "cid" t))
2853 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2854 (setq file nil
2855 content nil)
2856 (when (setq cid-file
2857 (gnus-article-browse-html-save-cid-content
2858 (match-string 2)
2859 (with-current-buffer gnus-article-buffer
2860 gnus-article-mime-handles)
2861 cid-dir))
2862 (when (eq system-type 'cygwin)
2863 (setq cid-file
2864 (concat "/" (substring
2865 (with-output-to-string
2866 (call-process "cygpath" nil
2867 standard-output
2868 nil "-m" cid-file))
2869 0 -1))))
2870 (replace-match (concat "file://" cid-file)
2871 nil nil nil 1))))
2872 (unless content (setq content (buffer-string))))
2873 (when (or charset header (not file))
2874 (setq tmp-file (mm-make-temp-file
2875 ;; Do we need to care for 8.3 filenames?
2876 "mm-" nil ".html")))
2877 ;; Add a meta html tag to specify charset and a header.
2878 (cond
2879 (header
2880 (let (title eheader body hcharset coding)
2881 (with-temp-buffer
2882 (mm-enable-multibyte)
2883 (setq case-fold-search t)
2884 (insert header "\n")
2885 (setq title (message-fetch-field "subject"))
2886 (goto-char (point-min))
2887 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2888 nil t)
2889 (replace-match (cond ((match-beginning 1) "&lt;")
2890 ((match-beginning 2) "&gt;")
2891 ((match-beginning 3) "&amp;")
2892 (t "<br>\n"))))
2893 (goto-char (point-min))
2894 (insert "<div align=\"left\">\n")
2895 (goto-char (point-max))
2896 (insert "</div>\n<hr>\n")
2897 ;; We have to examine charset one by one since
2898 ;; charset specified in parts might be different.
2899 (if (eq charset 'gnus-decoded)
2900 (setq charset 'utf-8
2901 eheader (mm-encode-coding-string (buffer-string)
2902 charset)
2903 title (when title
2904 (mm-encode-coding-string title charset))
2905 body (mm-encode-coding-string content charset))
2906 (setq hcharset (mm-find-mime-charset-region (point-min)
2907 (point-max)))
2908 (cond ((= (length hcharset) 1)
2909 (setq hcharset (car hcharset)
2910 coding (mm-charset-to-coding-system
2911 hcharset)))
2912 ((> (length hcharset) 1)
2913 (setq hcharset 'utf-8
2914 coding hcharset)))
2915 (if coding
2916 (if charset
2917 (progn
2918 (setq body
2919 (mm-charset-to-coding-system charset))
2920 (if (eq coding body)
2921 (setq eheader (mm-encode-coding-string
2922 (buffer-string) coding)
2923 title (when title
2924 (mm-encode-coding-string
2925 title coding))
2926 body content)
2927 (setq charset 'utf-8
2928 eheader (mm-encode-coding-string
2929 (buffer-string) charset)
2930 title (when title
2931 (mm-encode-coding-string
2932 title charset))
2933 body (mm-encode-coding-string
2934 (mm-decode-coding-string
2935 content body)
2936 charset))))
2937 (setq charset hcharset
2938 eheader (mm-encode-coding-string
2939 (buffer-string) coding)
2940 title (when title
2941 (mm-encode-coding-string
2942 title coding))
2943 body content))
2944 (setq eheader (mm-string-as-unibyte (buffer-string))
2945 body content)))
2946 (erase-buffer)
2947 (mm-disable-multibyte)
2948 (insert body)
2949 (when charset
2950 (mm-add-meta-html-tag handle charset t))
2951 (when title
2952 (goto-char (point-min))
2953 (unless (search-forward "<title>" nil t)
2954 (re-search-forward "<head>\\s-*" nil t)
2955 (insert "<title>" title "</title>\n")))
2956 (goto-char (point-min))
2957 (or (re-search-forward
2958 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2959 (re-search-forward
2960 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2961 (insert eheader)
2962 (mm-write-region (point-min) (point-max)
2963 tmp-file nil nil nil 'binary t))))
2964 (charset
2965 (mm-with-unibyte-buffer
2966 (insert (if (eq charset 'gnus-decoded)
2967 (mm-encode-coding-string content
2968 (setq charset 'utf-8))
2969 content))
2970 (if (or (mm-add-meta-html-tag handle charset)
2971 (not file))
2972 (mm-write-region (point-min) (point-max)
2973 tmp-file nil nil nil 'binary t)
2974 (setq tmp-file nil))))
2975 (tmp-file
2976 (mm-save-part-to-file handle tmp-file)))
2977 (when tmp-file
2978 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2979 (add-hook 'gnus-summary-prepare-exit-hook
2980 'gnus-article-browse-delete-temp-files)
2981 (add-hook 'gnus-exit-gnus-hook
2982 (lambda ()
2983 (gnus-article-browse-delete-temp-files t)))
2984 ;; FIXME: Warn if there's an <img> tag?
2985 (browse-url-of-file (or tmp-file (expand-file-name file)))
2986 (setq showed t))
2987 ;; If multipart, recurse
2988 ((equal (mm-handle-media-supertype handle) "multipart")
2989 (when (gnus-article-browse-html-parts handle header)
2990 (setq showed t)))
2991 ((equal (mm-handle-media-type handle) "message/rfc822")
2992 (mm-with-multibyte-buffer
2993 (mm-insert-part handle)
2994 (setq handle (mm-dissect-buffer t t))
2995 (when (and (bufferp (car handle))
2996 (stringp (car (mm-handle-type handle))))
2997 (setq handle (list handle)))
2998 (when header
2999 (article-decode-encoded-words)
3000 (let ((gnus-visible-headers
3001 (or (get 'gnus-visible-headers 'standard-value)
3002 gnus-visible-headers)))
3003 (article-hide-headers))
3004 (goto-char (point-min))
3005 (search-forward "\n\n" nil 'move)
3006 (skip-chars-backward "\t\n ")
3007 (setq header (buffer-substring (point-min) (point)))))
3008 (when (prog1
3009 (gnus-article-browse-html-parts handle header)
3010 (mm-destroy-parts handle))
3011 (setq showed t)))))
3012 showed))
3014 (defun gnus-article-browse-html-article (&optional arg)
3015 "View \"text/html\" parts of the current article with a WWW browser.
3016 Inline images embedded in a message using the cid scheme, as they are
3017 generally considered to be safe, will be processed properly.
3018 The message header is added to the beginning of every html part unless
3019 the prefix argument ARG is given.
3021 Warning: Spammers use links to images (using the http scheme) in HTML
3022 articles to verify whether you have read the message. As
3023 `gnus-article-browse-html-article' passes the HTML content to the
3024 browser without eliminating these \"web bugs\" you should only
3025 use it for mails from trusted senders.
3027 If you always want to display HTML parts in the browser, set
3028 `mm-text-html-renderer' to nil.
3030 This command creates temporary files to pass HTML contents including
3031 images if any to the browser, and deletes them when exiting the group
3032 \(if you want)."
3033 ;; Cf. `mm-w3m-safe-url-regexp'
3034 (interactive "P")
3035 (if arg
3036 (gnus-summary-show-article)
3037 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3038 gnus-visible-headers))
3039 ;; As we insert a <hr>, there's no need for the body boundary.
3040 (gnus-treat-body-boundary nil))
3041 (gnus-summary-show-article)))
3042 (with-current-buffer gnus-article-buffer
3043 (let ((header (unless arg
3044 (save-restriction
3045 (widen)
3046 (buffer-substring-no-properties
3047 (goto-char (point-min))
3048 (if (search-forward "\n\n" nil t)
3049 (match-beginning 0)
3050 (goto-char (point-max))
3051 (skip-chars-backward "\t\n ")
3052 (point))))))
3053 parts)
3054 (set-buffer gnus-original-article-buffer)
3055 (setq parts (mm-dissect-buffer t t))
3056 ;; If singlepart, enforce a list.
3057 (when (and (bufferp (car parts))
3058 (stringp (car (mm-handle-type parts))))
3059 (setq parts (list parts)))
3060 ;; Process the list
3061 (unless (gnus-article-browse-html-parts parts header)
3062 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3063 (mm-destroy-parts parts)
3064 (unless arg
3065 (gnus-summary-show-article)))))
3067 (defun article-hide-list-identifiers ()
3068 "Remove list identifies from the Subject header.
3069 The `gnus-list-identifiers' variable specifies what to do."
3070 (interactive)
3071 (let ((inhibit-point-motion-hooks t)
3072 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3073 (inhibit-read-only t))
3074 (when regexp
3075 (save-excursion
3076 (save-restriction
3077 (article-narrow-to-head)
3078 (goto-char (point-min))
3079 (while (re-search-forward
3080 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3081 nil t)
3082 (delete-region (match-beginning 2) (match-end 0))
3083 (beginning-of-line))
3084 (when (re-search-forward
3085 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3086 (delete-region (match-beginning 1) (match-end 1))))))))
3088 (defun article-hide-pem (&optional arg)
3089 "Toggle hiding of any PEM headers and signatures in the current article.
3090 If given a negative prefix, always show; if given a positive prefix,
3091 always hide."
3092 (interactive (gnus-article-hidden-arg))
3093 (unless (gnus-article-check-hidden-text 'pem arg)
3094 (save-excursion
3095 (let ((inhibit-read-only t) end)
3096 (goto-char (point-min))
3097 ;; Hide the horrendously ugly "header".
3098 (when (and (search-forward
3099 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3100 nil t)
3101 (setq end (1+ (match-beginning 0))))
3102 (gnus-add-wash-type 'pem)
3103 (gnus-article-hide-text-type
3105 (if (search-forward "\n\n" nil t)
3106 (match-end 0)
3107 (point-max))
3108 'pem)
3109 ;; Hide the trailer as well
3110 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3111 nil t)
3112 (gnus-article-hide-text-type
3113 (match-beginning 0) (match-end 0) 'pem)))))))
3115 (defun article-strip-banner ()
3116 "Strip the banners specified by the `banner' group parameter and by
3117 `gnus-article-address-banner-alist'."
3118 (interactive)
3119 (save-excursion
3120 (save-restriction
3121 (let ((inhibit-point-motion-hooks t))
3122 (when (gnus-parameter-banner gnus-newsgroup-name)
3123 (article-really-strip-banner
3124 (gnus-parameter-banner gnus-newsgroup-name)))
3125 (when gnus-article-address-banner-alist
3126 ;; Note that the From header is decoded here, so it is
3127 ;; required that the *-extract-address-components function
3128 ;; supports non-ASCII text.
3129 (let ((from (save-restriction
3130 (widen)
3131 (article-narrow-to-head)
3132 (mail-fetch-field "from"))))
3133 (when (and from
3134 (setq from
3135 (cadr (funcall gnus-extract-address-components
3136 from))))
3137 (catch 'found
3138 (dolist (pair gnus-article-address-banner-alist)
3139 (when (string-match (car pair) from)
3140 (throw 'found
3141 (article-really-strip-banner (cdr pair)))))))))))))
3143 (defun article-really-strip-banner (banner)
3144 "Strip the banner specified by the argument."
3145 (save-excursion
3146 (save-restriction
3147 (let ((inhibit-point-motion-hooks t)
3148 (gnus-signature-limit nil)
3149 (inhibit-read-only t))
3150 (article-goto-body)
3151 (cond
3152 ((eq banner 'signature)
3153 (when (gnus-article-narrow-to-signature)
3154 (widen)
3155 (forward-line -1)
3156 (delete-region (point) (point-max))))
3157 ((symbolp banner)
3158 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3159 (while (re-search-forward banner nil t)
3160 (delete-region (match-beginning 0) (match-end 0)))))
3161 ((stringp banner)
3162 (while (re-search-forward banner nil t)
3163 (delete-region (match-beginning 0) (match-end 0)))))))))
3165 (defun article-babel ()
3166 "Translate article using an online translation service."
3167 (interactive)
3168 (require 'babel)
3169 (gnus-with-article-buffer
3170 (when (article-goto-body)
3171 (let* ((start (point))
3172 (end (point-max))
3173 (orig (buffer-substring start end))
3174 (trans (babel-as-string orig)))
3175 (save-restriction
3176 (narrow-to-region start end)
3177 (delete-region start end)
3178 (insert trans))))))
3180 (defun article-hide-signature (&optional arg)
3181 "Hide the signature in the current article.
3182 If given a negative prefix, always show; if given a positive prefix,
3183 always hide."
3184 (interactive (gnus-article-hidden-arg))
3185 (unless (gnus-article-check-hidden-text 'signature arg)
3186 (save-excursion
3187 (save-restriction
3188 (let ((inhibit-read-only t))
3189 (when (gnus-article-narrow-to-signature)
3190 (gnus-article-hide-text-type
3191 (point-min) (point-max) 'signature))))))
3192 (gnus-set-mode-line 'article))
3194 (defun article-strip-headers-in-body ()
3195 "Strip offensive headers from bodies."
3196 (interactive)
3197 (save-excursion
3198 (article-goto-body)
3199 (let ((case-fold-search t))
3200 (when (looking-at "x-no-archive:")
3201 (gnus-delete-line)))))
3203 (defun article-strip-leading-blank-lines ()
3204 "Remove all blank lines from the beginning of the article."
3205 (interactive)
3206 (save-excursion
3207 (let ((inhibit-point-motion-hooks t)
3208 (inhibit-read-only t))
3209 (when (article-goto-body)
3210 (while (and (not (eobp))
3211 (looking-at "[ \t]*$"))
3212 (gnus-delete-line))))))
3214 (defun article-narrow-to-head ()
3215 "Narrow the buffer to the head of the message.
3216 Point is left at the beginning of the narrowed-to region."
3217 (narrow-to-region
3218 (goto-char (point-min))
3219 (cond
3220 ;; Absolutely no headers displayed.
3221 ((looking-at "\n")
3222 (point))
3223 ;; Normal headers.
3224 ((search-forward "\n\n" nil 1)
3225 (1- (point)))
3226 ;; Nothing but headers.
3228 (point-max))))
3229 (goto-char (point-min)))
3231 (defun article-goto-body ()
3232 "Place point at the start of the body."
3233 (goto-char (point-min))
3234 (cond
3235 ;; This variable is only bound when dealing with separate
3236 ;; MIME body parts.
3237 (article-goto-body-goes-to-point-min-p
3239 ((search-forward "\n\n" nil t)
3242 (goto-char (point-max))
3243 nil)))
3245 (defun article-strip-multiple-blank-lines ()
3246 "Replace consecutive blank lines with one empty line."
3247 (interactive)
3248 (save-excursion
3249 (let ((inhibit-point-motion-hooks t)
3250 (inhibit-read-only t))
3251 ;; First make all blank lines empty.
3252 (article-goto-body)
3253 (while (re-search-forward "^[ \t]+$" nil t)
3254 (unless (gnus-annotation-in-region-p
3255 (match-beginning 0) (match-end 0))
3256 (replace-match "" nil t)))
3257 ;; Then replace multiple empty lines with a single empty line.
3258 (article-goto-body)
3259 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3260 (unless (gnus-annotation-in-region-p
3261 (match-beginning 0) (match-end 0))
3262 (delete-region (match-beginning 1) (match-end 1)))))))
3264 (defun article-strip-leading-space ()
3265 "Remove all white space from the beginning of the lines in the article."
3266 (interactive)
3267 (save-excursion
3268 (let ((inhibit-point-motion-hooks t)
3269 (inhibit-read-only t))
3270 (article-goto-body)
3271 (while (re-search-forward "^[ \t]+" nil t)
3272 (replace-match "" t t)))))
3274 (defun article-strip-trailing-space ()
3275 "Remove all white space from the end of the lines in the article."
3276 (interactive)
3277 (save-excursion
3278 (let ((inhibit-point-motion-hooks t)
3279 (inhibit-read-only t))
3280 (article-goto-body)
3281 (while (re-search-forward "[ \t]+$" nil t)
3282 (replace-match "" t t)))))
3284 (defun article-strip-blank-lines ()
3285 "Strip leading, trailing and multiple blank lines."
3286 (interactive)
3287 (article-strip-leading-blank-lines)
3288 (article-remove-trailing-blank-lines)
3289 (article-strip-multiple-blank-lines))
3291 (defun article-strip-all-blank-lines ()
3292 "Strip all blank lines."
3293 (interactive)
3294 (save-excursion
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3297 (article-goto-body)
3298 (while (re-search-forward "^[ \t]*\n" nil t)
3299 (replace-match "" t t)))))
3301 (defun gnus-article-narrow-to-signature ()
3302 "Narrow to the signature; return t if a signature is found, else nil."
3303 (let ((inhibit-point-motion-hooks t))
3304 (when (gnus-article-search-signature)
3305 (forward-line 1)
3306 ;; Check whether we have some limits to what we consider
3307 ;; to be a signature.
3308 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3309 (list gnus-signature-limit)))
3310 limit limited)
3311 (while (setq limit (pop limits))
3312 (if (or (and (integerp limit)
3313 (< (- (point-max) (point)) limit))
3314 (and (floatp limit)
3315 (< (count-lines (point) (point-max)) limit))
3316 (and (functionp limit)
3317 (funcall limit))
3318 (and (stringp limit)
3319 (not (re-search-forward limit nil t))))
3320 () ; This limit did not succeed.
3321 (setq limited t
3322 limits nil)))
3323 (unless limited
3324 (narrow-to-region (point) (point-max))
3325 t)))))
3327 (defun gnus-article-search-signature ()
3328 "Search the current buffer for the signature separator.
3329 Put point at the beginning of the signature separator."
3330 (let ((cur (point)))
3331 (goto-char (point-max))
3332 (if (if (stringp gnus-signature-separator)
3333 (re-search-backward gnus-signature-separator nil t)
3334 (let ((seps gnus-signature-separator))
3335 (while (and seps
3336 (not (re-search-backward (car seps) nil t)))
3337 (pop seps))
3338 seps))
3340 (goto-char cur)
3341 nil)))
3343 (defun gnus-article-hidden-arg ()
3344 "Return the current prefix arg as a number, or 0 if no prefix."
3345 (list (if current-prefix-arg
3346 (prefix-numeric-value current-prefix-arg)
3347 0)))
3349 (defun gnus-article-check-hidden-text (type arg)
3350 "Return nil if hiding is necessary.
3351 Arg can be nil or a number. nil and positive means hide, negative
3352 means show, 0 means toggle."
3353 (save-excursion
3354 (save-restriction
3355 (let ((hide (gnus-article-hidden-text-p type)))
3356 (cond
3357 ((or (null arg)
3358 (> arg 0))
3359 nil)
3360 ((< arg 0)
3361 (gnus-article-show-hidden-text type)
3364 (if (eq hide 'hidden)
3365 (progn
3366 (gnus-article-show-hidden-text type)
3368 nil)))))))
3370 (defun gnus-article-hidden-text-p (type)
3371 "Say whether the current buffer contains hidden text of type TYPE."
3372 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3373 (while (and pos
3374 (not (get-text-property pos 'invisible))
3375 (not (get-text-property pos 'dummy-invisible)))
3376 (setq pos
3377 (text-property-any (1+ pos) (point-max) 'article-type type)))
3378 (if pos
3379 'hidden
3380 nil)))
3382 (defun gnus-article-show-hidden-text (type &optional dummy)
3383 "Show all hidden text of type TYPE.
3384 Originally it is hide instead of DUMMY."
3385 (let ((inhibit-read-only t)
3386 (inhibit-point-motion-hooks t))
3387 (gnus-remove-text-properties-when
3388 'article-type type
3389 (point-min) (point-max)
3390 (cons 'article-type (cons type
3391 gnus-hidden-properties)))
3392 (gnus-delete-wash-type type)))
3394 (defconst article-time-units
3395 `((year . ,(* 365.25 24 60 60))
3396 (week . ,(* 7 24 60 60))
3397 (day . ,(* 24 60 60))
3398 (hour . ,(* 60 60))
3399 (minute . 60)
3400 (second . 1))
3401 "Mapping from time units to seconds.")
3403 (defun gnus-article-forward-header ()
3404 "Move point to the start of the next header.
3405 If the current header is a continuation header, this can be several
3406 lines forward."
3407 (let ((ended nil))
3408 (while (not ended)
3409 (forward-line 1)
3410 (if (looking-at "[ \t]+[^ \t]")
3411 (forward-line 1)
3412 (setq ended t)))))
3414 (defun article-treat-date ()
3415 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3416 (with-current-buffer gnus-summary-buffer
3417 gnus-article-date-headers)
3418 gnus-article-date-headers)
3421 (defun article-date-ut (&optional type highlight date-position)
3422 "Convert DATE date to TYPE in the current article.
3423 The default type is `ut'. See `gnus-article-date-headers' for
3424 possible values."
3425 (interactive (list 'ut t))
3426 (let* ((case-fold-search t)
3427 (inhibit-read-only t)
3428 (inhibit-point-motion-hooks t)
3429 (first t)
3430 (visible-date (mail-fetch-field "Date"))
3431 pos date bface eface)
3432 (save-excursion
3433 (if date-position
3434 (progn
3435 (goto-char date-position)
3436 (setq date (get-text-property (point) 'original-date))
3437 (when (looking-at "[^:]+:[\t ]*")
3438 (setq bface (get-text-property (match-beginning 0) 'face)
3439 eface (get-text-property (match-end 0) 'face)))
3440 (delete-region (point)
3441 (progn
3442 (gnus-article-forward-header)
3443 (point)))
3444 (article-transform-date date type bface eface))
3445 (save-restriction
3446 (widen)
3447 (goto-char (point-min))
3448 (while (or (get-text-property (setq pos (point)) 'original-date)
3449 (and (setq pos (next-single-property-change
3450 (point) 'original-date))
3451 (goto-char pos)))
3452 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3453 (1+ (match-beginning 0))
3454 (point-max)))
3455 (while (setq pos (text-property-not-all pos (point-max)
3456 'gnus-date-type nil))
3457 (setq date (get-text-property pos 'original-date))
3458 (goto-char pos)
3459 (when (looking-at "[^:]+:[\t ]*")
3460 (setq bface (get-text-property (match-beginning 0) 'face)
3461 eface (get-text-property (match-end 0) 'face)))
3462 (delete-region pos (or (text-property-any pos (point-max)
3463 'gnus-date-type nil)
3464 (point-max))))
3465 (unless date ;; the 1st time
3466 (goto-char (point-min))
3467 (while (re-search-forward "^Date:[\t ]*" nil t)
3468 (setq date (get-text-property (match-beginning 0)
3469 'original-date)
3470 bface (get-text-property (match-beginning 0) 'face)
3471 eface (get-text-property (match-end 0) 'face))
3472 (delete-region (point-at-bol) (progn
3473 (gnus-article-forward-header)
3474 (point)))))
3475 (when (and (not date)
3476 visible-date)
3477 (setq date visible-date))
3478 (when date
3479 (article-transform-date date type bface eface))
3480 (goto-char (point-max))
3481 (widen)))))))
3483 (defun article-transform-date (date type bface eface)
3484 (dolist (this-type (cond
3485 ((null type)
3486 (list 'ut))
3487 ((atom type)
3488 (list type))
3490 type)))
3491 (goto-char
3492 (prog1
3493 (point)
3494 (add-text-properties
3495 (point)
3496 (progn
3497 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3498 (point))
3499 (list 'original-date date 'gnus-date-type this-type))))
3500 ;; Do highlighting.
3501 (when (looking-at
3502 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3503 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3504 (when (match-beginning 2)
3505 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3506 (while (and (zerop (forward-line 1))
3507 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3508 (when (match-beginning 1)
3509 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3511 (defun article-make-date-line (date type)
3512 "Return a DATE line of TYPE."
3513 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3514 combined-lapsed))
3515 (error "Unknown conversion type: %s" type))
3516 (condition-case ()
3517 (let ((time (ignore-errors (date-to-time date))))
3518 (cond
3519 ;; Convert to the local timezone.
3520 ((eq type 'local)
3521 (concat "Date: " (message-make-date time)))
3522 ;; Convert to Universal Time.
3523 ((eq type 'ut)
3524 (concat "Date: "
3525 (substring
3526 (message-make-date
3527 (let* ((e (parse-time-string date))
3528 (tm (apply 'encode-time e))
3529 (ms (car tm))
3530 (ls (- (cadr tm) (car (current-time-zone time)))))
3531 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3532 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3533 (t (list ms ls)))))
3534 0 -5)
3535 "UT"))
3536 ;; Get the original date from the article.
3537 ((eq type 'original)
3538 (concat "Date: " (if (string-match "\n+$" date)
3539 (substring date 0 (match-beginning 0))
3540 date)))
3541 ;; Let the user define the format.
3542 ((eq type 'user-defined)
3543 (let ((format (or (condition-case nil
3544 (with-current-buffer gnus-summary-buffer
3545 gnus-article-time-format)
3546 (error nil))
3547 gnus-article-time-format)))
3548 (if (functionp format)
3549 (funcall format time)
3550 (concat "Date: " (format-time-string format time)))))
3551 ;; ISO 8601.
3552 ((eq type 'iso8601)
3553 (let ((tz (car (current-time-zone time))))
3554 (concat
3555 "Date: "
3556 (format-time-string "%Y%m%dT%H%M%S" time)
3557 (format "%s%02d%02d"
3558 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3559 (/ (% (abs tz) 3600) 60)))))
3560 ;; Do a lapsed format.
3561 ((eq type 'lapsed)
3562 (concat "Date: " (article-lapsed-string time)))
3563 ;; A combined date/lapsed format.
3564 ((eq type 'combined-lapsed)
3565 (let ((date-string (article-make-date-line date 'original))
3566 (segments 3)
3567 lapsed-string)
3568 (while (and
3569 time
3570 (setq lapsed-string
3571 (concat " (" (article-lapsed-string time segments) ")"))
3572 (> (+ (length date-string)
3573 (length lapsed-string))
3574 (+ fill-column 6))
3575 (> segments 0))
3576 (setq segments (1- segments)))
3577 (if (> segments 0)
3578 (concat date-string lapsed-string)
3579 date-string)))
3580 ;; Display the date in proper English
3581 ((eq type 'english)
3582 (let ((dtime (decode-time time)))
3583 (concat
3584 "Date: the "
3585 (number-to-string (nth 3 dtime))
3586 (let ((digit (% (nth 3 dtime) 10)))
3587 (cond
3588 ((memq (nth 3 dtime) '(11 12 13)) "th")
3589 ((= digit 1) "st")
3590 ((= digit 2) "nd")
3591 ((= digit 3) "rd")
3592 (t "th")))
3593 " of "
3594 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3596 (number-to-string (nth 5 dtime))
3597 " at "
3598 (format "%02d" (nth 2 dtime))
3600 (format "%02d" (nth 1 dtime)))))))
3601 (foo
3602 (format "Date: %s (from Gnus)" date))))
3604 (defun article-lapsed-string (time &optional max-segments)
3605 ;; If the date is seriously mangled, the timezone functions are
3606 ;; liable to bug out, so we ignore all errors.
3607 (let* ((now (current-time))
3608 (real-time (subtract-time now time))
3609 (real-sec (and real-time
3610 (+ (* (float (car real-time)) 65536)
3611 (cadr real-time))))
3612 (sec (and real-time (abs real-sec)))
3613 (segments 0)
3614 num prev)
3615 (unless max-segments
3616 (setq max-segments (length article-time-units)))
3617 (cond
3618 ((null real-time)
3619 "Unknown")
3620 ((zerop sec)
3621 "Now")
3623 (concat
3624 ;; This is a bit convoluted, but basically we go
3625 ;; through the time units for years, weeks, etc,
3626 ;; and divide things to see whether that results
3627 ;; in positive answers.
3628 (mapconcat
3629 (lambda (unit)
3630 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3631 (>= segments max-segments))
3632 ;; The (remaining) seconds are too few to
3633 ;; be divided into this time unit.
3635 ;; It's big enough, so we output it.
3636 (setq sec (- sec (* num (cdr unit))))
3637 (prog1
3638 (concat (if prev ", " "") (int-to-string
3639 (floor num))
3640 " " (symbol-name (car unit))
3641 (if (> num 1) "s" ""))
3642 (setq prev t
3643 segments (1+ segments)))))
3644 article-time-units "")
3645 ;; If dates are odd, then it might appear like the
3646 ;; article was sent in the future.
3647 (if (> real-sec 0)
3648 " ago"
3649 " in the future"))))))
3651 (defun article-date-local (&optional highlight)
3652 "Convert the current article date to the local timezone."
3653 (interactive (list t))
3654 (article-date-ut 'local highlight))
3656 (defun article-date-english (&optional highlight)
3657 "Convert the current article date to something that is proper English."
3658 (interactive (list t))
3659 (article-date-ut 'english highlight))
3661 (defun article-date-original (&optional highlight)
3662 "Convert the current article date to what it was originally.
3663 This is only useful if you have used some other date conversion
3664 function and want to see what the date was before converting."
3665 (interactive (list t))
3666 (article-date-ut 'original highlight))
3668 (defun article-date-lapsed (&optional highlight)
3669 "Convert the current article date to time lapsed since it was sent."
3670 (interactive (list t))
3671 (article-date-ut 'lapsed highlight))
3673 (defun article-date-combined-lapsed (&optional highlight)
3674 "Convert the current article date to time lapsed since it was sent."
3675 (interactive (list t))
3676 (article-date-ut 'combined-lapsed highlight))
3678 (defun article-update-date-lapsed ()
3679 "Function to be run from a timer to update the lapsed time line."
3680 (save-match-data
3681 (let ((buffer (current-buffer)))
3682 (ignore-errors
3683 (walk-windows
3684 (lambda (w)
3685 (set-buffer (window-buffer w))
3686 (when (eq major-mode 'gnus-article-mode)
3687 (let ((old-line (count-lines (point-min) (point)))
3688 (old-column (- (point) (line-beginning-position)))
3689 (window-start (window-start w))
3690 (pos (point-min))
3691 type next end)
3692 (while (setq pos (text-property-not-all pos (point-max)
3693 'gnus-date-type nil))
3694 (setq next (or (next-single-property-change pos
3695 'gnus-date-type)
3696 (point-max)))
3697 (setq type (get-text-property pos 'gnus-date-type))
3698 (when (memq type '(lapsed combined-lapsed user-defined))
3699 (article-date-ut type t pos)
3700 (setq end (or (next-single-property-change pos
3701 'gnus-date-type)
3702 (point-max)))
3703 (when window-start
3704 (if (/= window-start next)
3705 (setq window-start nil)
3706 (set-window-start w end)))
3707 (setq next end))
3708 (setq pos next))
3709 (goto-char (point-min))
3710 (when (> old-column 0)
3711 (setq old-line (1- old-line)))
3712 (forward-line old-line)
3713 (end-of-line)
3714 (when (> (current-column) old-column)
3715 (beginning-of-line)
3716 (forward-char old-column)))))
3717 nil 'visible))
3718 (set-buffer buffer))))
3720 (defun gnus-start-date-timer (&optional n)
3721 "Start a timer to update the Date headers in the article buffers.
3722 The numerical prefix says how frequently (in seconds) the function
3723 is to run."
3724 (interactive "p")
3725 (unless n
3726 (setq n 1))
3727 (gnus-stop-date-timer)
3728 (setq article-lapsed-timer
3729 (run-at-time 1 n 'article-update-date-lapsed)))
3731 (defun gnus-stop-date-timer ()
3732 "Stop the Date timer."
3733 (interactive)
3734 (when article-lapsed-timer
3735 (nnheader-cancel-timer article-lapsed-timer)
3736 (setq article-lapsed-timer nil)))
3738 (defun article-date-user (&optional highlight)
3739 "Convert the current article date to the user-defined format.
3740 This format is defined by the `gnus-article-time-format' variable."
3741 (interactive (list t))
3742 (article-date-ut 'user highlight))
3744 (defun article-date-iso8601 (&optional highlight)
3745 "Convert the current article date to ISO8601."
3746 (interactive (list t))
3747 (article-date-ut 'iso8601 highlight))
3749 (defmacro gnus-article-save-original-date (&rest forms)
3750 "Save the original date as a text property and evaluate FORMS."
3751 `(let* ((case-fold-search t)
3752 (start (progn
3753 (goto-char (point-min))
3754 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3755 (not (bolp)))
3756 (match-end 0))))
3757 (date (when (and start
3758 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3759 nil t))
3760 (buffer-substring-no-properties start
3761 (match-beginning 0)))))
3762 (goto-char (point-max))
3763 (skip-chars-backward "\n")
3764 (put-text-property (point-min) (point) 'original-date date)
3765 ,@forms
3766 (goto-char (point-max))
3767 (skip-chars-backward "\n")
3768 (put-text-property (point-min) (point) 'original-date date)))
3770 ;; (defun article-show-all ()
3771 ;; "Show all hidden text in the article buffer."
3772 ;; (interactive)
3773 ;; (save-excursion
3774 ;; (let ((inhibit-read-only t))
3775 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3777 (defun article-remove-leading-whitespace ()
3778 "Remove excessive whitespace from all headers."
3779 (interactive)
3780 (save-excursion
3781 (save-restriction
3782 (let ((inhibit-read-only t))
3783 (article-narrow-to-head)
3784 (goto-char (point-min))
3785 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3786 (delete-region (match-beginning 1) (match-end 1)))))))
3788 (defun article-emphasize (&optional arg)
3789 "Emphasize text according to `gnus-emphasis-alist'."
3790 (interactive (gnus-article-hidden-arg))
3791 (unless (gnus-article-check-hidden-text 'emphasis arg)
3792 (save-excursion
3793 (let ((alist (or
3794 (condition-case nil
3795 (with-current-buffer gnus-summary-buffer
3796 gnus-article-emphasis-alist)
3797 (error))
3798 gnus-emphasis-alist))
3799 (inhibit-read-only t)
3800 (props (append '(article-type emphasis)
3801 gnus-hidden-properties))
3802 regexp elem beg invisible visible face)
3803 (article-goto-body)
3804 (setq beg (point))
3805 (while (setq elem (pop alist))
3806 (goto-char beg)
3807 (setq regexp (car elem)
3808 invisible (nth 1 elem)
3809 visible (nth 2 elem)
3810 face (nth 3 elem))
3811 (while (re-search-forward regexp nil t)
3812 (when (and (match-beginning visible) (match-beginning invisible))
3813 (gnus-article-hide-text
3814 (match-beginning invisible) (match-end invisible) props)
3815 (gnus-article-unhide-text-type
3816 (match-beginning visible) (match-end visible) 'emphasis)
3817 (gnus-put-overlay-excluding-newlines
3818 (match-beginning visible) (match-end visible) 'face face)
3819 (gnus-add-wash-type 'emphasis)
3820 (goto-char (match-end invisible)))))))))
3822 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3823 "Setup newsgroup emphasis alist."
3824 (unless gnus-article-emphasis-alist
3825 (let ((name (and gnus-newsgroup-name
3826 (gnus-group-real-name gnus-newsgroup-name))))
3827 (make-local-variable 'gnus-article-emphasis-alist)
3828 (setq gnus-article-emphasis-alist
3829 (nconc
3830 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3831 (while (setq elem (pop alist))
3832 (when (and name (string-match (car elem) name))
3833 (setq alist nil
3834 highlight (copy-sequence (cdr elem)))))
3835 highlight)
3836 (copy-sequence highlight-words)
3837 (if gnus-newsgroup-name
3838 (copy-sequence (gnus-group-find-parameter
3839 gnus-newsgroup-name 'highlight-words t)))
3840 gnus-emphasis-alist)))))
3842 (defvar gnus-summary-article-menu)
3843 (defvar gnus-summary-post-menu)
3845 ;;; Saving functions.
3847 (defun gnus-article-save (save-buffer file &optional num)
3848 "Save the currently selected article."
3849 (when (or (get gnus-default-article-saver :headers)
3850 (not gnus-save-all-headers))
3851 ;; Remove headers according to `gnus-saved-headers' or the value
3852 ;; of the `:headers' property that the saver function might have.
3853 (let ((gnus-visible-headers
3854 (or (symbol-value (get gnus-default-article-saver :headers))
3855 gnus-saved-headers gnus-visible-headers))
3856 ;; Ignore group parameter. See `article-hide-headers'.
3857 (gnus-summary-buffer nil))
3858 (with-current-buffer save-buffer
3859 (article-hide-headers 1 t))))
3860 (save-window-excursion
3861 (if (not gnus-default-article-saver)
3862 (error "No default saver is defined")
3863 ;; !!! Magic! The saving functions all save
3864 ;; `gnus-save-article-buffer' (or so they think), but we
3865 ;; bind that variable to our save-buffer.
3866 (set-buffer gnus-article-buffer)
3867 (let* ((gnus-save-article-buffer save-buffer)
3868 (filename
3869 (cond
3870 ((not gnus-prompt-before-saving) 'default)
3871 ((eq gnus-prompt-before-saving 'always) nil)
3872 (t file)))
3873 (gnus-number-of-articles-to-be-saved
3874 (when (eq gnus-prompt-before-saving t)
3875 num))) ; Magic
3876 (set-buffer gnus-article-current-summary)
3877 (funcall gnus-default-article-saver filename)))))
3879 (defun gnus-read-save-file-name (prompt &optional filename
3880 function group headers variable
3881 dir-var)
3882 (let ((default-name
3883 (funcall function group headers (symbol-value variable)))
3884 result)
3885 (setq result
3886 (expand-file-name
3887 (cond
3888 ((eq filename 'default)
3889 default-name)
3890 ((eq filename t)
3891 default-name)
3892 (filename filename)
3894 (when (symbol-value dir-var)
3895 (setq default-name (expand-file-name
3896 (file-name-nondirectory default-name)
3897 (symbol-value dir-var))))
3898 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3899 (prompt
3900 (format prompt
3901 (if (and gnus-number-of-articles-to-be-saved
3902 (> gnus-number-of-articles-to-be-saved 1))
3903 (format "these %d articles"
3904 gnus-number-of-articles-to-be-saved)
3905 "this article")))
3906 (file
3907 ;; Let the split methods have their say.
3908 (cond
3909 ;; No split name was found.
3910 ((null split-name)
3911 (read-file-name
3912 (concat prompt " (default "
3913 (file-name-nondirectory default-name) "): ")
3914 (file-name-directory default-name)
3915 default-name))
3916 ;; A single group name is returned.
3917 ((stringp split-name)
3918 (setq default-name
3919 (funcall function split-name headers
3920 (symbol-value variable)))
3921 (read-file-name
3922 (concat prompt " (default "
3923 (file-name-nondirectory default-name) "): ")
3924 (file-name-directory default-name)
3925 default-name))
3926 ;; A single split name was found
3927 ((= 1 (length split-name))
3928 (let* ((name (expand-file-name
3929 (car split-name)
3930 gnus-article-save-directory))
3931 (dir (cond ((file-directory-p name)
3932 (file-name-as-directory name))
3933 ((file-exists-p name) name)
3934 (t gnus-article-save-directory))))
3935 (read-file-name
3936 (concat prompt " (default " name "): ")
3937 dir name)))
3938 ;; A list of splits was found.
3940 (setq split-name (nreverse split-name))
3941 (let (result)
3942 (let ((file-name-history
3943 (nconc split-name file-name-history)))
3944 (setq result
3945 (expand-file-name
3946 (read-file-name
3947 (concat prompt " (`M-p' for defaults): ")
3948 gnus-article-save-directory
3949 (car split-name))
3950 gnus-article-save-directory)))
3951 (car (push result file-name-history)))))))
3952 ;; Create the directory.
3953 (gnus-make-directory (file-name-directory file))
3954 ;; If we have read a directory, we append the default file name.
3955 (when (file-directory-p file)
3956 (setq file (expand-file-name (file-name-nondirectory
3957 default-name)
3958 (file-name-as-directory file))))
3959 ;; Possibly translate some characters.
3960 (nnheader-translate-file-chars file))))))
3961 (gnus-make-directory (file-name-directory result))
3962 (when variable
3963 (set variable result))
3964 (when dir-var
3965 (set dir-var (file-name-directory result)))
3966 result))
3968 (defun gnus-article-archive-name (group)
3969 "Return the first instance of an \"Archive-name\" in the current buffer."
3970 (let ((case-fold-search t))
3971 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3972 (nnheader-concat gnus-article-save-directory
3973 (match-string 1)))))
3975 (defun gnus-article-nndoc-name (group)
3976 "If GROUP is an nndoc group, return the name of the parent group."
3977 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3978 (gnus-group-get-parameter group 'save-article-group)))
3980 (defun gnus-summary-save-in-rmail (&optional filename)
3981 "Append this article to Rmail file.
3982 Optional argument FILENAME specifies file name.
3983 Directory to save to is default to `gnus-article-save-directory'."
3984 (setq filename (gnus-read-save-file-name
3985 "Save %s in rmail file" filename
3986 gnus-rmail-save-name gnus-newsgroup-name
3987 gnus-current-headers 'gnus-newsgroup-last-rmail))
3988 (with-current-buffer gnus-save-article-buffer
3989 (save-excursion
3990 (save-restriction
3991 (widen)
3992 ;; Note that unlike gnus-summary-save-in-mail, there is no
3993 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3994 ;; not use Babyl.
3995 (gnus-output-to-rmail filename))))
3996 filename)
3998 (defun gnus-summary-save-in-mail (&optional filename)
3999 "Append this article to Unix mail file.
4000 Optional argument FILENAME specifies file name.
4001 Directory to save to is default to `gnus-article-save-directory'."
4002 (setq filename (gnus-read-save-file-name
4003 "Save %s in Unix mail file" filename
4004 gnus-mail-save-name gnus-newsgroup-name
4005 gnus-current-headers 'gnus-newsgroup-last-mail))
4006 (with-current-buffer gnus-save-article-buffer
4007 (save-excursion
4008 (save-restriction
4009 (widen)
4010 (if (and (file-readable-p filename)
4011 (file-regular-p filename)
4012 (mail-file-babyl-p filename))
4013 (gnus-output-to-rmail filename)
4014 (gnus-output-to-mail filename)))))
4015 filename)
4017 (put 'gnus-summary-save-in-file :decode t)
4018 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4019 (defun gnus-summary-save-in-file (&optional filename overwrite)
4020 "Append this article to file.
4021 Optional argument FILENAME specifies file name.
4022 Directory to save to is default to `gnus-article-save-directory'."
4023 (setq filename (gnus-read-save-file-name
4024 "Save %s in file" filename
4025 gnus-file-save-name gnus-newsgroup-name
4026 gnus-current-headers 'gnus-newsgroup-last-file))
4027 (with-current-buffer gnus-save-article-buffer
4028 (save-excursion
4029 (save-restriction
4030 (widen)
4031 (when (and overwrite
4032 (file-exists-p filename))
4033 (delete-file filename))
4034 (gnus-output-to-file filename))))
4035 filename)
4037 (put 'gnus-summary-write-to-file :decode t)
4038 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4039 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4040 (defun gnus-summary-write-to-file (&optional filename)
4041 "Write this article to a file, overwriting it if the file exists.
4042 Optional argument FILENAME specifies file name.
4043 The directory to save in defaults to `gnus-article-save-directory'."
4044 (setq filename (gnus-read-save-file-name
4045 "Save %s in file" filename
4046 gnus-file-save-name gnus-newsgroup-name
4047 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4048 (gnus-summary-save-in-file filename t))
4050 (put 'gnus-summary-save-body-in-file :decode t)
4051 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4052 "Append this article body to a file.
4053 Optional argument FILENAME specifies file name.
4054 The directory to save in defaults to `gnus-article-save-directory'."
4055 (setq filename (gnus-read-save-file-name
4056 "Save %s body in file" filename
4057 gnus-file-save-name gnus-newsgroup-name
4058 gnus-current-headers 'gnus-newsgroup-last-file))
4059 (with-current-buffer gnus-save-article-buffer
4060 (save-excursion
4061 (save-restriction
4062 (widen)
4063 (when (article-goto-body)
4064 (narrow-to-region (point) (point-max)))
4065 (when (and overwrite
4066 (file-exists-p filename))
4067 (delete-file filename))
4068 (gnus-output-to-file filename))))
4069 filename)
4071 (put 'gnus-summary-write-body-to-file :decode t)
4072 (put 'gnus-summary-write-body-to-file
4073 :function 'gnus-summary-save-body-in-file)
4074 (defun gnus-summary-write-body-to-file (&optional filename)
4075 "Write this article body to a file, overwriting it if the file exists.
4076 Optional argument FILENAME specifies file name.
4077 The directory to save in defaults to `gnus-article-save-directory'."
4078 (setq filename (gnus-read-save-file-name
4079 "Save %s body in file" filename
4080 gnus-file-save-name gnus-newsgroup-name
4081 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4082 (gnus-summary-save-body-in-file filename t))
4084 (put 'gnus-summary-save-in-pipe :decode t)
4085 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4086 (defun gnus-summary-save-in-pipe (&optional command raw)
4087 "Pipe this article to subprocess COMMAND.
4088 Valid values for COMMAND include:
4089 a string
4090 The executable command name and possibly arguments.
4092 You will be prompted for the command in the minibuffer.
4093 the symbol `default'
4094 It will be replaced with the command which the variable
4095 `gnus-summary-pipe-output-default-command' holds or the command
4096 last used for saving.
4097 Non-nil value for RAW overrides `:decode' and `:headers' properties
4098 and the raw article including all headers will be piped."
4099 (let ((article (gnus-summary-article-number))
4100 (decode (unless raw
4101 (get 'gnus-summary-save-in-pipe :decode)))
4102 save-buffer default)
4103 (if article
4104 (if (vectorp (gnus-summary-article-header article))
4105 (save-current-buffer
4106 (gnus-summary-select-article decode decode nil article)
4107 (insert-buffer-substring
4108 (prog1
4109 (if decode
4110 gnus-article-buffer
4111 gnus-original-article-buffer)
4112 (setq save-buffer
4113 (nnheader-set-temp-buffer " *Gnus Save*"))))
4114 ;; Remove unwanted headers.
4115 (when (and (not raw)
4116 (or (get 'gnus-summary-save-in-pipe :headers)
4117 (not gnus-save-all-headers)))
4118 (let ((gnus-visible-headers
4119 (or (symbol-value (get 'gnus-summary-save-in-pipe
4120 :headers))
4121 gnus-saved-headers gnus-visible-headers))
4122 (gnus-summary-buffer nil))
4123 (article-hide-headers 1 t))))
4124 (error "%d is not a real article" article))
4125 (error "No article to pipe"))
4126 (setq default (or gnus-summary-pipe-output-default-command
4127 gnus-last-shell-command))
4128 (unless (stringp command)
4129 (setq command
4130 (if (and (eq command 'default) default)
4131 default
4132 (gnus-read-shell-command "Shell command on this article: "
4133 default))))
4134 (when (string-equal command "")
4135 (if default
4136 (setq command default)
4137 (error "A command is required")))
4138 (with-current-buffer save-buffer
4139 (save-restriction
4140 (widen)
4141 (shell-command-on-region (point-min) (point-max) command nil)))
4142 (gnus-kill-buffer save-buffer))
4143 (setq gnus-summary-pipe-output-default-command command))
4145 (defun gnus-summary-pipe-to-muttprint (&optional command)
4146 "Pipe this article to muttprint."
4147 (unless (stringp command)
4148 (setq command (read-string
4149 "Print using command: " gnus-summary-muttprint-program
4150 nil gnus-summary-muttprint-program)))
4151 (let ((gnus-summary-pipe-output-default-command
4152 gnus-summary-pipe-output-default-command))
4153 (gnus-summary-save-in-pipe command))
4154 (setq gnus-summary-muttprint-program command))
4156 ;;; Article file names when saving.
4158 (defun gnus-capitalize-newsgroup (newsgroup)
4159 "Capitalize NEWSGROUP name."
4160 (when (not (zerop (length newsgroup)))
4161 (concat (char-to-string (upcase (aref newsgroup 0)))
4162 (substring newsgroup 1))))
4164 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4165 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4166 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4167 Otherwise, it is like ~/News/news/group/num."
4168 (let ((default
4169 (expand-file-name
4170 (concat (if (gnus-use-long-file-name 'not-save)
4171 (gnus-capitalize-newsgroup newsgroup)
4172 (gnus-newsgroup-directory-form newsgroup))
4173 "/" (int-to-string (mail-header-number headers)))
4174 gnus-article-save-directory)))
4175 (if (and last-file
4176 (string-equal (file-name-directory default)
4177 (file-name-directory last-file))
4178 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4179 default
4180 (or last-file default))))
4182 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4183 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4184 If variable `gnus-use-long-file-name' is non-nil, it is
4185 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4186 (let ((default
4187 (expand-file-name
4188 (concat (if (gnus-use-long-file-name 'not-save)
4189 newsgroup
4190 (gnus-newsgroup-directory-form newsgroup))
4191 "/" (int-to-string (mail-header-number headers)))
4192 gnus-article-save-directory)))
4193 (if (and last-file
4194 (string-equal (file-name-directory default)
4195 (file-name-directory last-file))
4196 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4197 default
4198 (or last-file default))))
4200 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4201 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4202 If variable `gnus-use-long-file-name' is non-nil, it is
4203 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4204 (or last-file
4205 (expand-file-name
4206 (if (gnus-use-long-file-name 'not-save)
4207 newsgroup
4208 (file-relative-name
4209 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4210 default-directory))
4211 gnus-article-save-directory)))
4213 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4214 "Generate file name from sender."
4215 (let ((from (mail-header-from headers)))
4216 (expand-file-name
4217 (if (and from (string-match "\\([^ <]+\\)@" from))
4218 (match-string 1 from)
4219 "nobody")
4220 gnus-article-save-directory)))
4222 (defun article-verify-x-pgp-sig ()
4223 "Verify X-PGP-Sig."
4224 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4225 (interactive)
4226 (if (gnus-buffer-live-p gnus-original-article-buffer)
4227 (let ((sig (with-current-buffer gnus-original-article-buffer
4228 (gnus-fetch-field "X-PGP-Sig")))
4229 items info headers)
4230 (when (and sig
4231 mml2015-use
4232 (mml2015-clear-verify-function))
4233 (with-temp-buffer
4234 (insert-buffer-substring gnus-original-article-buffer)
4235 (setq items (split-string sig))
4236 (message-narrow-to-head)
4237 (let ((inhibit-point-motion-hooks t)
4238 (case-fold-search t))
4239 ;; Don't verify multiple headers.
4240 (setq headers (mapconcat (lambda (header)
4241 (concat header ": "
4242 (mail-fetch-field header)
4243 "\n"))
4244 (split-string (nth 1 items) ",") "")))
4245 (delete-region (point-min) (point-max))
4246 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4247 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4248 (insert headers)
4249 (widen)
4250 (forward-line)
4251 (while (not (eobp))
4252 (if (looking-at "^-")
4253 (insert "- "))
4254 (forward-line))
4255 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4256 (insert "Version: " (car items) "\n\n")
4257 (insert (mapconcat 'identity (cddr items) "\n"))
4258 (insert "\n-----END PGP SIGNATURE-----\n")
4259 (let ((mm-security-handle (list (format "multipart/signed"))))
4260 (mml2015-clean-buffer)
4261 (let ((coding-system-for-write (or gnus-newsgroup-charset
4262 'iso-8859-1)))
4263 (funcall (mml2015-clear-verify-function)))
4264 (setq info
4265 (or (mm-handle-multipart-ctl-parameter
4266 mm-security-handle 'gnus-details)
4267 (mm-handle-multipart-ctl-parameter
4268 mm-security-handle 'gnus-info)))))
4269 (when info
4270 (let ((inhibit-read-only t) bface eface)
4271 (save-restriction
4272 (message-narrow-to-head)
4273 (goto-char (point-max))
4274 (forward-line -1)
4275 (setq bface (get-text-property (point-at-bol) 'face)
4276 eface (get-text-property (1- (point-at-eol)) 'face))
4277 (message-remove-header "X-Gnus-PGP-Verify")
4278 (if (re-search-forward "^X-PGP-Sig:" nil t)
4279 (forward-line)
4280 (goto-char (point-max)))
4281 (narrow-to-region (point) (point))
4282 (insert "X-Gnus-PGP-Verify: " info "\n")
4283 (goto-char (point-min))
4284 (forward-line)
4285 (while (not (eobp))
4286 (if (not (looking-at "^[ \t]"))
4287 (insert " "))
4288 (forward-line))
4289 ;; Do highlighting.
4290 (goto-char (point-min))
4291 (when (looking-at "\\([^:]+\\): *")
4292 (put-text-property (match-beginning 1) (1+ (match-end 1))
4293 'face bface)
4294 (put-text-property (match-end 0) (point-max)
4295 'face eface)))))))))
4297 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4299 (defun article-verify-cancel-lock ()
4300 "Verify Cancel-Lock header."
4301 (interactive)
4302 (if (gnus-buffer-live-p gnus-original-article-buffer)
4303 (canlock-verify gnus-original-article-buffer)))
4305 (eval-and-compile
4306 (mapc
4307 (lambda (func)
4308 (let (afunc gfunc)
4309 (if (consp func)
4310 (setq afunc (car func)
4311 gfunc (cdr func))
4312 (setq afunc func
4313 gfunc (intern (format "gnus-%s" func))))
4314 (defalias gfunc
4315 (when (fboundp afunc)
4316 `(lambda (&optional interactive &rest args)
4317 ,(documentation afunc t)
4318 (interactive (list t))
4319 (with-current-buffer gnus-article-buffer
4320 (if interactive
4321 (call-interactively ',afunc)
4322 (apply ',afunc args))))))))
4323 '(article-hide-headers
4324 article-verify-x-pgp-sig
4325 article-verify-cancel-lock
4326 article-hide-boring-headers
4327 article-treat-overstrike
4328 article-treat-ansi-sequences
4329 article-fill-long-lines
4330 article-capitalize-sentences
4331 article-remove-cr
4332 article-remove-leading-whitespace
4333 article-display-x-face
4334 article-display-face
4335 article-de-quoted-unreadable
4336 article-de-base64-unreadable
4337 article-decode-HZ
4338 article-wash-html
4339 article-unsplit-urls
4340 article-hide-list-identifiers
4341 article-strip-banner
4342 article-babel
4343 article-hide-pem
4344 article-hide-signature
4345 article-strip-headers-in-body
4346 article-remove-trailing-blank-lines
4347 article-strip-leading-blank-lines
4348 article-strip-multiple-blank-lines
4349 article-strip-leading-space
4350 article-strip-trailing-space
4351 article-strip-blank-lines
4352 article-strip-all-blank-lines
4353 article-date-local
4354 article-date-english
4355 article-date-iso8601
4356 article-date-original
4357 article-treat-date
4358 article-date-ut
4359 article-decode-mime-words
4360 article-decode-charset
4361 article-decode-encoded-words
4362 article-date-user
4363 article-date-lapsed
4364 article-date-combined-lapsed
4365 article-emphasize
4366 article-treat-dumbquotes
4367 article-treat-non-ascii
4368 article-normalize-headers
4369 ;;(article-show-all . gnus-article-show-all-headers)
4373 ;;; Gnus article mode
4376 (put 'gnus-article-mode 'mode-class 'special)
4378 (set-keymap-parent gnus-article-mode-map widget-keymap)
4380 (gnus-define-keys gnus-article-mode-map
4381 " " gnus-article-goto-next-page
4382 [?\S-\ ] gnus-article-goto-prev-page
4383 "\177" gnus-article-goto-prev-page
4384 [delete] gnus-article-goto-prev-page
4385 [backspace] gnus-article-goto-prev-page
4386 "\C-c^" gnus-article-refer-article
4387 "h" gnus-article-show-summary
4388 "s" gnus-article-show-summary
4389 "\C-c\C-m" gnus-article-mail
4390 "?" gnus-article-describe-briefly
4391 "<" beginning-of-buffer
4392 ">" end-of-buffer
4393 "\C-c\C-i" gnus-info-find-node
4394 "\C-c\C-b" gnus-bug
4395 "R" gnus-article-reply-with-original
4396 "F" gnus-article-followup-with-original
4397 "\C-hk" gnus-article-describe-key
4398 "\C-hc" gnus-article-describe-key-briefly
4399 "\C-hb" gnus-article-describe-bindings
4401 "e" gnus-article-read-summary-keys
4402 "\C-d" gnus-article-read-summary-keys
4403 "\M-*" gnus-article-read-summary-keys
4404 "\M-#" gnus-article-read-summary-keys
4405 "\M-^" gnus-article-read-summary-keys
4406 "\M-g" gnus-article-read-summary-keys)
4408 (substitute-key-definition
4409 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4411 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4412 "W" gnus-article-wide-reply-with-original)
4413 (if (featurep 'xemacs)
4414 (set-keymap-default-binding gnus-article-send-map
4415 'gnus-article-read-summary-send-keys)
4416 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4418 (defun gnus-article-make-menu-bar ()
4419 (unless (boundp 'gnus-article-commands-menu)
4420 (gnus-summary-make-menu-bar))
4421 (unless (boundp 'gnus-article-article-menu)
4422 (easy-menu-define
4423 gnus-article-article-menu gnus-article-mode-map ""
4424 '("Article"
4425 ["Scroll forwards" gnus-article-goto-next-page t]
4426 ["Scroll backwards" gnus-article-goto-prev-page t]
4427 ["Show summary" gnus-article-show-summary t]
4428 ["Fetch Message-ID at point" gnus-article-refer-article t]
4429 ["Mail to address at point" gnus-article-mail t]
4430 ["Send a bug report" gnus-bug t]))
4432 (easy-menu-define
4433 gnus-article-treatment-menu gnus-article-mode-map ""
4434 ;; Fixme: this should use :active (and maybe :visible).
4435 '("Treatment"
4436 ["Hide headers" gnus-article-hide-headers t]
4437 ["Hide signature" gnus-article-hide-signature t]
4438 ["Hide citation" gnus-article-hide-citation t]
4439 ["Treat overstrike" gnus-article-treat-overstrike t]
4440 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4441 ["Remove carriage return" gnus-article-remove-cr t]
4442 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4443 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4444 ["Remove base64" gnus-article-de-base64-unreadable t]
4445 ["Treat html" gnus-article-wash-html t]
4446 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4447 ["Decode HZ" gnus-article-decode-HZ t]))
4449 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4451 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4453 (gnus-run-hooks 'gnus-article-menu-hook)))
4455 (defvar bookmark-make-record-function)
4456 (defvar shr-put-image-function)
4458 (defun gnus-article-mode ()
4459 "Major mode for displaying an article.
4461 All normal editing commands are switched off.
4463 The following commands are available in addition to all summary mode
4464 commands:
4465 \\<gnus-article-mode-map>
4466 \\[gnus-article-next-page]\t Scroll the article one page forwards
4467 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4468 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4469 \\[gnus-article-show-summary]\t Display the summary buffer
4470 \\[gnus-article-mail]\t Send a reply to the address near point
4471 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4472 \\[gnus-info-find-node]\t Go to the Gnus info node"
4473 (interactive)
4474 (kill-all-local-variables)
4475 (gnus-simplify-mode-line)
4476 (setq mode-name "Article")
4477 (setq major-mode 'gnus-article-mode)
4478 (make-local-variable 'minor-mode-alist)
4479 (use-local-map gnus-article-mode-map)
4480 (when (gnus-visual-p 'article-menu 'menu)
4481 (gnus-article-make-menu-bar)
4482 (when gnus-summary-tool-bar-map
4483 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4484 (gnus-update-format-specifications nil 'article-mode)
4485 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4486 (set (make-local-variable 'gnus-page-broken) nil)
4487 (make-local-variable 'gnus-article-current-summary)
4488 (make-local-variable 'gnus-article-mime-handles)
4489 (make-local-variable 'gnus-article-decoded-p)
4490 (make-local-variable 'gnus-article-mime-handle-alist)
4491 (make-local-variable 'gnus-article-wash-types)
4492 (make-local-variable 'gnus-article-image-alist)
4493 (make-local-variable 'gnus-article-charset)
4494 (make-local-variable 'gnus-article-ignored-charsets)
4495 (set (make-local-variable 'bookmark-make-record-function)
4496 'gnus-summary-bookmark-make-record)
4497 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4498 ;; face.
4499 (set (make-local-variable 'nobreak-char-display) nil)
4500 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4501 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4502 (setq cursor-in-non-selected-windows nil)
4503 (gnus-set-default-directory)
4504 (buffer-disable-undo)
4505 (setq buffer-read-only t
4506 show-trailing-whitespace nil)
4507 (set-syntax-table gnus-article-mode-syntax-table)
4508 (mm-enable-multibyte)
4509 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4511 (defun gnus-article-setup-buffer ()
4512 "Initialize the article buffer."
4513 (let* ((name (if gnus-single-article-buffer "*Article*"
4514 (concat "*Article "
4515 (gnus-group-decoded-name gnus-newsgroup-name)
4516 "*")))
4517 (original
4518 (progn (string-match "\\*Article" name)
4519 (concat " *Original Article"
4520 (substring name (match-end 0))))))
4521 (setq gnus-article-buffer name)
4522 (setq gnus-original-article-buffer original)
4523 (setq gnus-article-mime-handle-alist nil)
4524 (with-current-buffer gnus-summary-buffer
4525 ;; This might be a variable local to the summary buffer.
4526 (unless gnus-single-article-buffer
4527 (setq gnus-article-buffer name)
4528 (setq gnus-original-article-buffer original)
4529 (gnus-set-global-variables)))
4530 (gnus-article-setup-highlight-words)
4531 ;; Init original article buffer.
4532 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4533 (mm-enable-multibyte)
4534 (setq major-mode 'gnus-original-article-mode)
4535 (make-local-variable 'gnus-original-article))
4536 (if (and (get-buffer name)
4537 (with-current-buffer name
4538 (if gnus-article-edit-mode
4539 (if (y-or-n-p "Article mode edit in progress; discard? ")
4540 (progn
4541 (set-buffer-modified-p nil)
4542 (gnus-kill-buffer name)
4543 (message "")
4544 nil)
4545 (error "Action aborted"))
4546 t)))
4547 (with-current-buffer name
4548 (set (make-local-variable 'gnus-article-edit-mode) nil)
4549 (gnus-article-stop-animations)
4550 (when gnus-article-mime-handles
4551 (mm-destroy-parts gnus-article-mime-handles)
4552 (setq gnus-article-mime-handles nil))
4553 ;; Set it to nil in article-buffer!
4554 (setq gnus-article-mime-handle-alist nil)
4555 (buffer-disable-undo)
4556 (setq buffer-read-only t)
4557 (unless (eq major-mode 'gnus-article-mode)
4558 (gnus-article-mode))
4559 (setq truncate-lines gnus-article-truncate-lines)
4560 (current-buffer))
4561 (let ((summary gnus-summary-buffer))
4562 (with-current-buffer (gnus-get-buffer-create name)
4563 (gnus-article-mode)
4564 (setq truncate-lines gnus-article-truncate-lines)
4565 (set (make-local-variable 'gnus-summary-buffer) summary)
4566 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4567 (when article-lapsed-timer
4568 (gnus-stop-date-timer))
4569 (when gnus-article-update-date-headers
4570 (gnus-start-date-timer gnus-article-update-date-headers))
4571 (current-buffer))))))
4573 (defun gnus-article-stop-animations ()
4574 (dolist (timer (and (boundp 'timer-list)
4575 timer-list))
4576 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4577 (cancel-timer timer))))
4579 (defun gnus-stop-downloads ()
4580 (when (boundp 'url-queue)
4581 (set (intern "url-queue" obarray) nil)))
4583 ;; Set article window start at LINE, where LINE is the number of lines
4584 ;; from the head of the article.
4585 (defun gnus-article-set-window-start (&optional line)
4586 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4587 (when article-window
4588 (set-window-start
4589 article-window
4590 (with-current-buffer gnus-article-buffer
4591 (goto-char (point-min))
4592 (if (not line)
4593 (point-min)
4594 (gnus-message 6 "Moved to bookmark")
4595 (search-forward "\n\n" nil t)
4596 (forward-line line)
4597 (point)))))))
4599 (defun gnus-article-prepare (article &optional all-headers header)
4600 "Prepare ARTICLE in article mode buffer.
4601 ARTICLE should either be an article number or a Message-ID.
4602 If ARTICLE is an id, HEADER should be the article headers.
4603 If ALL-HEADERS is non-nil, no headers are hidden."
4604 (save-excursion
4605 ;; Make sure we start in a summary buffer.
4606 (unless (eq major-mode 'gnus-summary-mode)
4607 (set-buffer gnus-summary-buffer))
4608 (setq gnus-summary-buffer (current-buffer))
4609 (let* ((gnus-article (if header (mail-header-number header) article))
4610 (summary-buffer (current-buffer))
4611 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4612 (group gnus-newsgroup-name)
4613 result)
4614 (save-excursion
4615 (gnus-article-setup-buffer)
4616 (set-buffer gnus-article-buffer)
4617 ;; Deactivate active regions.
4618 (when (and (boundp 'transient-mark-mode)
4619 transient-mark-mode)
4620 (setq mark-active nil))
4621 (if (not (setq result (let ((inhibit-read-only t))
4622 (gnus-request-article-this-buffer
4623 article group))))
4624 ;; There is no such article.
4625 (save-excursion
4626 (when (and (numberp article)
4627 (not (memq article gnus-newsgroup-sparse)))
4628 (setq gnus-article-current
4629 (cons gnus-newsgroup-name article))
4630 (set-buffer gnus-summary-buffer)
4631 (setq gnus-current-article article)
4632 (if (and (memq article gnus-newsgroup-undownloaded)
4633 (not (gnus-online (gnus-find-method-for-group
4634 gnus-newsgroup-name))))
4635 (progn
4636 (gnus-summary-set-agent-mark article)
4637 (message "Message marked for downloading"))
4638 (gnus-summary-mark-article article gnus-canceled-mark)
4639 (unless (memq article gnus-newsgroup-sparse)
4640 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4641 (if (or (eq result 'pseudo)
4642 (eq result 'nneething))
4643 (progn
4644 (with-current-buffer summary-buffer
4645 (push article gnus-newsgroup-history)
4646 (setq gnus-last-article gnus-current-article
4647 gnus-current-article 0
4648 gnus-current-headers nil
4649 gnus-article-current nil)
4650 (if (eq result 'nneething)
4651 (gnus-configure-windows 'summary)
4652 (gnus-configure-windows 'article))
4653 (gnus-set-global-variables))
4654 (let ((gnus-article-mime-handle-alist-1
4655 gnus-article-mime-handle-alist))
4656 (gnus-set-mode-line 'article)))
4657 ;; The result from the `request' was an actual article -
4658 ;; or at least some text that is now displayed in the
4659 ;; article buffer.
4660 (when (and (numberp article)
4661 (not (eq article gnus-current-article)))
4662 ;; Seems like a new article has been selected.
4663 ;; `gnus-current-article' must be an article number.
4664 (with-current-buffer summary-buffer
4665 (push article gnus-newsgroup-history)
4666 (setq gnus-last-article gnus-current-article
4667 gnus-current-article article
4668 gnus-current-headers
4669 (gnus-summary-article-header gnus-current-article)
4670 gnus-article-current
4671 (cons gnus-newsgroup-name gnus-current-article))
4672 (unless (vectorp gnus-current-headers)
4673 (setq gnus-current-headers nil))
4674 (gnus-summary-goto-subject gnus-current-article)
4675 (when (gnus-summary-show-thread)
4676 ;; If the summary buffer really was folded, the
4677 ;; previous goto may not actually have gone to
4678 ;; the right article, but the thread root instead.
4679 ;; So we go again.
4680 (gnus-summary-goto-subject gnus-current-article))
4681 (gnus-run-hooks 'gnus-mark-article-hook)
4682 (gnus-set-mode-line 'summary)
4683 (when (gnus-visual-p 'article-highlight 'highlight)
4684 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4685 ;; Set the global newsgroup variables here.
4686 (gnus-set-global-variables)
4687 (setq gnus-have-all-headers
4688 (or all-headers gnus-show-all-headers))))
4689 (save-excursion
4690 (gnus-configure-windows 'article))
4691 (when (or (numberp article)
4692 (stringp article))
4693 (gnus-article-prepare-display)
4694 ;; Do page break.
4695 (goto-char (point-min))
4696 (when gnus-break-pages
4697 (gnus-narrow-to-page)))
4698 (let ((gnus-article-mime-handle-alist-1
4699 gnus-article-mime-handle-alist))
4700 (gnus-set-mode-line 'article))
4701 (article-goto-body)
4702 (unless (bobp)
4703 (forward-line -1))
4704 (set-window-point (get-buffer-window (current-buffer)) (point))
4705 (gnus-configure-windows 'article)
4706 (gnus-run-hooks 'gnus-article-prepare-hook)
4707 t))))))
4709 ;;;###autoload
4710 (defun gnus-article-prepare-display ()
4711 "Make the current buffer look like a nice article."
4712 ;; Hooks for getting information from the article.
4713 ;; This hook must be called before being narrowed.
4714 (let ((gnus-article-buffer (current-buffer))
4715 buffer-read-only
4716 (inhibit-read-only t))
4717 (unless (eq major-mode 'gnus-article-mode)
4718 (gnus-article-mode))
4719 (setq buffer-read-only nil
4720 gnus-article-wash-types nil
4721 gnus-article-image-alist nil)
4722 (gnus-run-hooks 'gnus-tmp-internal-hook)
4723 (when gnus-display-mime-function
4724 (funcall gnus-display-mime-function))))
4727 ;;; Gnus Sticky Article Mode
4730 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4731 "Mode for sticky articles."
4732 ;; Release bindings that won't work.
4733 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4734 gnus-sticky-article-mode-map)
4735 (substitute-key-definition 'gnus-article-refer-article 'undefined
4736 gnus-sticky-article-mode-map)
4737 (dolist (k '("e" "h" "s" "F" "R"))
4738 (define-key gnus-sticky-article-mode-map k nil))
4739 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4740 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4741 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4742 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4744 (defun gnus-sticky-article (arg)
4745 "Make the current article sticky.
4746 If a prefix ARG is given, ask for a name for this sticky article buffer."
4747 (interactive "P")
4748 (gnus-summary-show-thread)
4749 (gnus-summary-select-article nil nil 'pseudo)
4750 (let (new-art-buf-name)
4751 (gnus-eval-in-buffer-window gnus-article-buffer
4752 (setq new-art-buf-name
4753 (concat
4754 "*Sticky Article: "
4755 (if arg
4756 (read-from-minibuffer "Sticky article buffer name: ")
4757 (gnus-with-article-headers
4758 (gnus-article-goto-header "subject")
4759 (setq new-art-buf-name
4760 (buffer-substring-no-properties
4761 (line-beginning-position) (line-end-position)))
4762 (goto-char (point-min))
4763 (gnus-article-goto-header "from")
4764 (setq new-art-buf-name
4765 (concat
4766 new-art-buf-name ", "
4767 (buffer-substring-no-properties
4768 (line-beginning-position) (line-end-position))))
4769 (goto-char (point-min))
4770 (gnus-article-goto-header "date")
4771 (setq new-art-buf-name
4772 (concat
4773 new-art-buf-name ", "
4774 (buffer-substring-no-properties
4775 (line-beginning-position) (line-end-position))))))
4776 "*"))
4777 (if (and (gnus-buffer-live-p new-art-buf-name)
4778 (with-current-buffer new-art-buf-name
4779 (eq major-mode 'gnus-sticky-article-mode)))
4780 (switch-to-buffer new-art-buf-name)
4781 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4782 (gnus-sticky-article-mode))
4783 (setq gnus-article-buffer new-art-buf-name))
4784 (gnus-summary-recenter)
4785 (gnus-summary-position-point))
4787 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4788 "Kill the given sticky article BUFFER.
4789 If none is given, assume the current buffer and kill it if it has
4790 `gnus-sticky-article-mode'."
4791 (interactive)
4792 (unless buffer
4793 (setq buffer (current-buffer)))
4794 (with-current-buffer buffer
4795 (when (eq major-mode 'gnus-sticky-article-mode)
4796 (gnus-kill-buffer buffer))))
4798 (defun gnus-kill-sticky-article-buffers (arg)
4799 "Kill all sticky article buffers.
4800 If a prefix ARG is given, ask for confirmation."
4801 (interactive "P")
4802 (dolist (buf (gnus-buffers))
4803 (with-current-buffer buf
4804 (when (eq major-mode 'gnus-sticky-article-mode)
4805 (if (not arg)
4806 (gnus-kill-buffer buf)
4807 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4808 (gnus-kill-buffer buf)))))))
4811 ;;; Gnus MIME viewing functions
4814 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4815 "Format of the MIME buttons.
4817 Valid specifiers include:
4818 %t The MIME type
4819 %T MIME type, along with additional info
4820 %n The `name' parameter
4821 %d The description, if any
4822 %l The length of the encoded part
4823 %p The part identifier number
4824 %e Dots if the part isn't displayed
4826 General format specifiers can also be used. See Info node
4827 `(gnus)Formatting Variables'.")
4829 (defvar gnus-mime-button-line-format-alist
4830 '((?t gnus-tmp-type ?s)
4831 (?T gnus-tmp-type-long ?s)
4832 (?n gnus-tmp-name ?s)
4833 (?d gnus-tmp-description ?s)
4834 (?p gnus-tmp-id ?s)
4835 (?l gnus-tmp-length ?d)
4836 (?e gnus-tmp-dots ?s)))
4838 (defvar gnus-mime-button-commands
4839 '((gnus-article-press-button "\r" "Toggle Display")
4840 (gnus-mime-view-part "v" "View Interactively...")
4841 (gnus-mime-view-part-as-type "t" "View As Type...")
4842 (gnus-mime-view-part-as-charset "C" "View As charset...")
4843 (gnus-mime-save-part "o" "Save...")
4844 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4845 (gnus-mime-replace-part "r" "Replace part")
4846 (gnus-mime-delete-part "d" "Delete part")
4847 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4848 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4849 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4850 (gnus-mime-view-part-externally "e" "View Externally")
4851 (gnus-mime-print-part "p" "Print")
4852 (gnus-mime-pipe-part "|" "Pipe To Command...")
4853 (gnus-mime-action-on-part "." "Take action on the part...")))
4855 (defun gnus-article-mime-part-status ()
4856 (if gnus-article-mime-handle-alist-1
4857 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4858 " (1 part)"
4859 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4860 ""))
4862 (defvar gnus-mime-button-map
4863 (let ((map (make-sparse-keymap)))
4864 (define-key map gnus-mouse-2 'gnus-article-push-button)
4865 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4866 (dolist (c gnus-mime-button-commands)
4867 (define-key map (cadr c) (car c)))
4868 map))
4870 (easy-menu-define
4871 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4872 `("MIME Part"
4873 ,@(mapcar (lambda (c)
4874 (vector (caddr c) (car c) :active t))
4875 gnus-mime-button-commands)))
4877 (defvar gnus-url-button-commands
4878 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4880 (defvar gnus-url-button-map
4881 (let ((map (make-sparse-keymap)))
4882 (dolist (c gnus-url-button-commands)
4883 (define-key map (cadr c) (car c)))
4884 map))
4886 (easy-menu-define
4887 gnus-url-button-menu gnus-url-button-map "URL button menu."
4888 `("Url Button"
4889 ,@(mapcar (lambda (c)
4890 (vector (caddr c) (car c) :active t))
4891 gnus-url-button-commands)))
4893 (defmacro gnus-bind-safe-url-regexp (&rest body)
4894 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4895 `(let ((mm-w3m-safe-url-regexp
4896 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4897 (gnus-buffer-live-p
4898 gnus-article-current-summary))
4899 (with-current-buffer gnus-article-current-summary
4900 gnus-newsgroup-name)
4901 gnus-newsgroup-name)))
4902 (if (cond ((not group)
4903 ;; Maybe we're in a mml-preview buffer
4904 ;; and no group is selected.
4906 ((stringp gnus-safe-html-newsgroups)
4907 (string-match gnus-safe-html-newsgroups group))
4908 ((consp gnus-safe-html-newsgroups)
4909 (member group gnus-safe-html-newsgroups)))
4911 mm-w3m-safe-url-regexp))))
4912 ,@body))
4914 (defun gnus-mime-button-menu (event prefix)
4915 "Construct a context-sensitive menu of MIME commands."
4916 (interactive "e\nP")
4917 (save-window-excursion
4918 (let ((pos (event-start event)))
4919 (select-window (posn-window pos))
4920 (goto-char (posn-point pos))
4921 (gnus-article-check-buffer)
4922 (popup-menu gnus-mime-button-menu nil prefix))))
4924 (defun gnus-mime-view-all-parts (&optional handles)
4925 "View all the MIME parts."
4926 (interactive)
4927 (with-current-buffer gnus-article-buffer
4928 (let ((handles (or handles gnus-article-mime-handles))
4929 (mail-parse-charset gnus-newsgroup-charset)
4930 (mail-parse-ignored-charsets
4931 (with-current-buffer gnus-summary-buffer
4932 gnus-newsgroup-ignored-charsets)))
4933 (when handles
4934 (mm-remove-parts handles)
4935 (goto-char (point-min))
4936 (or (search-forward "\n\n") (goto-char (point-max)))
4937 (let ((inhibit-read-only t))
4938 (delete-region (point) (point-max))
4939 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4941 (defun gnus-article-jump-to-part (n)
4942 "Jump to MIME part N."
4943 (interactive "P")
4944 (let ((parts (with-current-buffer gnus-article-buffer
4945 (length gnus-article-mime-handle-alist))))
4946 (when (zerop parts)
4947 (error "No such part"))
4948 (pop-to-buffer gnus-article-buffer)
4949 (or n
4950 (setq n (if (= parts 1)
4952 (read-number (format "Jump to part (1..%s): " parts)))))
4953 (unless (and (integerp n) (<= n parts) (>= n 1))
4954 (setq n
4955 (progn
4956 (gnus-message 7 "Invalid part `%s', using %s instead."
4957 n parts)
4958 parts)))
4959 (gnus-message 9 "Jumping to part %s." n)
4960 (cond ((>= gnus-auto-select-part 1)
4961 (while (and (<= n parts)
4962 (not (gnus-article-goto-part n)))
4963 (setq n (1+ n))))
4964 ((< gnus-auto-select-part 0)
4965 (while (and (>= n 1)
4966 (not (gnus-article-goto-part n)))
4967 (setq n (1- n))))
4969 (gnus-article-goto-part n)))))
4971 (defvar gnus-mime-buttonized-part-id nil
4972 "ID of a mime part that should be buttonized.
4973 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4975 (eval-when-compile
4976 (defsubst gnus-article-edit-part (handles &optional current-id)
4977 "Edit an article in order to delete a mime part.
4978 This function is exclusively used by `gnus-mime-save-part-and-strip'
4979 and `gnus-mime-delete-part', and not provided at run-time normally."
4980 (gnus-article-edit-article
4981 `(lambda ()
4982 (buffer-disable-undo)
4983 (erase-buffer)
4984 (let ((mail-parse-charset (or gnus-article-charset
4985 ',gnus-newsgroup-charset))
4986 (mail-parse-ignored-charsets
4987 (or gnus-article-ignored-charsets
4988 ',gnus-newsgroup-ignored-charsets))
4989 (mbl mml-buffer-list))
4990 (setq mml-buffer-list nil)
4991 (insert-buffer-substring gnus-original-article-buffer)
4992 (mime-to-mml ',handles)
4993 (setq gnus-article-mime-handles nil)
4994 (let ((mbl1 mml-buffer-list))
4995 (setq mml-buffer-list mbl)
4996 (set (make-local-variable 'mml-buffer-list) mbl1))
4997 (gnus-make-local-hook 'kill-buffer-hook)
4998 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4999 `(lambda (no-highlight)
5000 (let ((mail-parse-charset (or gnus-article-charset
5001 ',gnus-newsgroup-charset))
5002 (message-options message-options)
5003 (message-options-set-recipient)
5004 (mail-parse-ignored-charsets
5005 (or gnus-article-ignored-charsets
5006 ',gnus-newsgroup-ignored-charsets)))
5007 (mml-to-mime)
5008 (mml-destroy-buffers)
5009 (remove-hook 'kill-buffer-hook
5010 'mml-destroy-buffers t)
5011 (kill-local-variable 'mml-buffer-list))
5012 (gnus-summary-edit-article-done
5013 ,(or (mail-header-references gnus-current-headers) "")
5014 ,(gnus-group-read-only-p)
5015 ,gnus-summary-buffer no-highlight))
5017 ;; Force buttonizing this part.
5018 (let ((gnus-mime-buttonized-part-id current-id))
5019 (gnus-article-edit-done))
5020 (gnus-configure-windows 'article)
5021 (when (and current-id (integerp gnus-auto-select-part))
5022 (gnus-article-jump-to-part
5023 (min (max (+ current-id gnus-auto-select-part) 1)
5024 (with-current-buffer gnus-article-buffer
5025 (length gnus-article-mime-handle-alist)))))))
5027 (defun gnus-mime-replace-part (file)
5028 "Replace MIME part under point with an external body."
5029 ;; Useful if file has already been saved to disk
5030 (interactive
5031 (list
5032 (read-file-name "Replace MIME part with file: "
5033 (or mm-default-directory default-directory)
5034 nil nil)))
5035 (gnus-mime-save-part-and-strip file))
5037 (defun gnus-mime-save-part-and-strip (&optional file)
5038 "Save the MIME part under point then replace it with an external body.
5039 If FILE is given, use it for the external part."
5040 (interactive)
5041 (gnus-article-check-buffer)
5042 (when (gnus-group-read-only-p)
5043 (error "The current group does not support deleting of parts"))
5044 (when (mm-complicated-handles gnus-article-mime-handles)
5045 (error "\
5046 The current article has a complicated MIME structure, giving up..."))
5047 (let* ((data (get-text-property (point) 'gnus-data))
5048 (id (get-text-property (point) 'gnus-part))
5049 param
5050 (handles gnus-article-mime-handles))
5051 (unless file
5052 (setq file
5053 (and data (mm-save-part data "Delete MIME part and save to: "))))
5054 (when file
5055 (with-current-buffer (mm-handle-buffer data)
5056 (erase-buffer)
5057 (insert "Content-Type: " (mm-handle-media-type data))
5058 (mml-insert-parameter-string (cdr (mm-handle-type data))
5059 '(charset))
5060 ;; Add a filename for the sake of saving the part again.
5061 (mml-insert-parameter
5062 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5063 (insert "\n")
5064 (insert "Content-ID: " (message-make-message-id) "\n")
5065 (insert "Content-Transfer-Encoding: binary\n")
5066 (insert "\n"))
5067 (setcdr data
5068 (cdr (mm-make-handle nil
5069 `("message/external-body"
5070 (access-type . "LOCAL-FILE")
5071 (name . ,file)))))
5072 ;; (set-buffer gnus-summary-buffer)
5073 (gnus-article-edit-part handles id))))
5075 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5076 ;; parts...>') but with stripping would be nice.
5078 (defun gnus-mime-delete-part ()
5079 "Delete the MIME part under point.
5080 Replace it with some information about the removed part."
5081 (interactive)
5082 (gnus-article-check-buffer)
5083 (when (gnus-group-read-only-p)
5084 (error "The current group does not support deleting of parts"))
5085 (when (mm-complicated-handles gnus-article-mime-handles)
5086 (error "\
5087 The current article has a complicated MIME structure, giving up..."))
5088 (when (or gnus-expert-user
5089 (gnus-yes-or-no-p "\
5090 Deleting parts may malfunction or destroy the article; continue? "))
5091 (let* ((data (get-text-property (point) 'gnus-data))
5092 (id (get-text-property (point) 'gnus-part))
5093 (handles gnus-article-mime-handles)
5094 (description
5095 (let ((desc (mm-handle-description data)))
5096 (when desc
5097 (mail-decode-encoded-word-string desc))))
5098 (filename (or (mm-handle-filename data) "(none)"))
5099 (type (mm-handle-media-type data)))
5100 (unless data
5101 (error "No MIME part under point"))
5102 (with-current-buffer (mm-handle-buffer data)
5103 (let ((bsize (buffer-size)))
5104 (erase-buffer)
5105 (insert
5106 (concat
5107 ",----\n"
5108 "| The following attachment has been deleted:\n"
5109 "|\n"
5110 "| Type: " type "\n"
5111 "| Filename: " filename "\n"
5112 "| Size (encoded): " (format "%s byte%s\n"
5113 bsize (if (= bsize 1)
5115 "s"))
5116 (when description
5117 (concat "| Description: " description "\n"))
5118 "`----\n"))
5119 (setcdr data
5120 (cdr (mm-make-handle
5121 nil `("text/plain" (charset . gnus-decoded)) nil nil
5122 (list "attachment")
5123 (format "Deleted attachment (%s bytes)" bsize))))))
5124 ;; (set-buffer gnus-summary-buffer)
5125 (gnus-article-edit-part handles id))))
5127 (defun gnus-mime-save-part ()
5128 "Save the MIME part under point."
5129 (interactive)
5130 (gnus-article-check-buffer)
5131 (let ((data (get-text-property (point) 'gnus-data)))
5132 (when data
5133 (mm-save-part data))))
5135 (defun gnus-mime-pipe-part (&optional cmd)
5136 "Pipe the MIME part under point to a process.
5137 Use CMD as the process."
5138 (interactive)
5139 (gnus-article-check-buffer)
5140 (let ((data (get-text-property (point) 'gnus-data)))
5141 (when data
5142 (mm-pipe-part data cmd))))
5144 (defun gnus-mime-view-part ()
5145 "Interactively choose a viewing method for the MIME part under point."
5146 (interactive)
5147 (gnus-article-check-buffer)
5148 (let ((data (get-text-property (point) 'gnus-data)))
5149 (when data
5150 (setq gnus-article-mime-handles
5151 (mm-merge-handles
5152 gnus-article-mime-handles (setq data (copy-sequence data))))
5153 (mm-interactively-view-part data))))
5155 (defun gnus-mime-view-part-as-type-internal ()
5156 (gnus-article-check-buffer)
5157 (let* ((handle (get-text-property (point) 'gnus-data))
5158 (name (or
5159 ;; Content-Type: foo/bar; name=...
5160 (mail-content-type-get (mm-handle-type handle) 'name)
5161 ;; Content-Disposition: attachment; filename=...
5162 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5163 (def-type (and name (mm-default-file-encoding name))))
5164 (or (and def-type (cons def-type 0))
5165 (and handle
5166 (equal (mm-handle-media-supertype handle) "text")
5167 '("text/plain" . 0))
5168 '("application/octet-stream" . 0))))
5170 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5171 "Choose a MIME media type, and view the part as such.
5172 If non-nil, PRED is a predicate to use during completion to limit the
5173 available media-types."
5174 (interactive)
5175 (unless mime-type
5176 (setq mime-type
5177 (let ((default (gnus-mime-view-part-as-type-internal)))
5178 (gnus-completing-read
5179 "View as MIME type"
5180 (if pred
5181 (gnus-remove-if-not pred (mailcap-mime-types))
5182 (mailcap-mime-types))
5183 nil nil nil
5184 (car default)))))
5185 (gnus-article-check-buffer)
5186 (let ((handle (get-text-property (point) 'gnus-data)))
5187 (when handle
5188 (when (equal (mm-handle-media-type handle) "message/external-body")
5189 (unless (mm-handle-cache handle)
5190 (mm-extern-cache-contents handle))
5191 (setq handle (mm-handle-cache handle)))
5192 (setq handle
5193 (mm-make-handle (mm-handle-buffer handle)
5194 (cons mime-type (cdr (mm-handle-type handle)))
5195 (mm-handle-encoding handle)
5196 (mm-handle-undisplayer handle)
5197 (mm-handle-disposition handle)
5198 (mm-handle-description handle)
5200 (mm-handle-id handle)))
5201 (setq gnus-article-mime-handles
5202 (mm-merge-handles gnus-article-mime-handles handle))
5203 (when (mm-handle-displayed-p handle)
5204 (mm-remove-part handle))
5205 (gnus-mm-display-part handle))))
5207 (defun gnus-mime-copy-part (&optional handle arg)
5208 "Put the MIME part under point into a new buffer.
5209 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5210 are decompressed."
5211 (interactive (list nil current-prefix-arg))
5212 (gnus-article-check-buffer)
5213 (unless handle
5214 (setq handle (get-text-property (point) 'gnus-data)))
5215 (when handle
5216 (let ((filename (mm-handle-filename handle))
5217 contents dont-decode charset coding-system)
5218 (mm-with-unibyte-buffer
5219 (mm-insert-part handle)
5220 (setq contents (or (condition-case nil
5221 (mm-decompress-buffer filename nil 'sig)
5222 (error
5223 (setq dont-decode t)
5224 nil))
5225 (buffer-string))))
5226 (setq filename (cond (filename (file-name-nondirectory filename))
5227 (dont-decode "*raw data*")
5228 (t "*decoded*")))
5229 (cond
5230 (dont-decode)
5231 ((not arg)
5232 (unless (setq charset (mail-content-type-get
5233 (mm-handle-type handle) 'charset))
5234 (unless (setq coding-system (mm-with-unibyte-buffer
5235 (insert contents)
5236 (mm-find-buffer-file-coding-system)))
5237 (setq charset gnus-newsgroup-charset))))
5238 ((numberp arg)
5239 (setq charset (or (cdr (assq arg
5240 gnus-summary-show-article-charset-alist))
5241 (mm-read-coding-system "Charset: ")))))
5242 (switch-to-buffer (generate-new-buffer filename))
5243 (if (or coding-system
5244 (and charset
5245 (setq coding-system (mm-charset-to-coding-system charset))
5246 (not (eq coding-system 'ascii))))
5247 (progn
5248 (mm-enable-multibyte)
5249 (insert (mm-decode-coding-string contents coding-system))
5250 (setq buffer-file-coding-system
5251 (if (boundp 'last-coding-system-used)
5252 (symbol-value 'last-coding-system-used)
5253 coding-system)))
5254 (mm-disable-multibyte)
5255 (insert contents)
5256 (setq buffer-file-coding-system mm-binary-coding-system))
5257 ;; We do it this way to make `normal-mode' set the appropriate mode.
5258 (unwind-protect
5259 (progn
5260 (setq buffer-file-name (expand-file-name filename))
5261 (normal-mode))
5262 (setq buffer-file-name nil))
5263 (goto-char (point-min)))))
5265 (defun gnus-mime-print-part (&optional handle filename)
5266 "Print the MIME part under point."
5267 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5268 (gnus-article-check-buffer)
5269 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5270 (contents (and handle (mm-get-part handle)))
5271 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5272 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5273 (when contents
5274 (if printer
5275 (unwind-protect
5276 (progn
5277 (mm-save-part-to-file handle file)
5278 (call-process shell-file-name nil
5279 (generate-new-buffer " *mm*")
5281 shell-command-switch
5282 (mm-mailcap-command
5283 printer file (mm-handle-type handle))))
5284 (delete-file file))
5285 (with-temp-buffer
5286 (insert contents)
5287 (gnus-print-buffer))
5288 (ps-despool filename)))))
5290 (defun gnus-mime-inline-part (&optional handle arg)
5291 "Insert the MIME part under point into the current buffer.
5292 Compressed files like .gz and .bz2 are decompressed."
5293 (interactive (list nil current-prefix-arg))
5294 (gnus-article-check-buffer)
5295 (unless handle
5296 (setq handle (get-text-property (point) 'gnus-data)))
5297 (when handle
5298 (let ((b (point))
5299 (inhibit-read-only t)
5300 contents charset coding-system)
5301 (if (and (not arg) (mm-handle-undisplayer handle))
5302 (mm-remove-part handle)
5303 (mm-with-unibyte-buffer
5304 (mm-insert-part handle)
5305 (setq contents
5306 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5307 (buffer-string))))
5308 (cond
5309 ((not arg)
5310 (unless (setq charset (mail-content-type-get
5311 (mm-handle-type handle) 'charset))
5312 (unless (setq coding-system
5313 (mm-with-unibyte-buffer
5314 (insert contents)
5315 (mm-find-buffer-file-coding-system)))
5316 (setq charset gnus-newsgroup-charset))))
5317 ((numberp arg)
5318 (if (mm-handle-undisplayer handle)
5319 (mm-remove-part handle))
5320 (setq charset
5321 (or (cdr (assq arg
5322 gnus-summary-show-article-charset-alist))
5323 (mm-read-coding-system "Charset: "))))
5324 ((mm-handle-undisplayer handle)
5325 (mm-remove-part handle)))
5326 (forward-line 2)
5327 (mm-display-inline handle)
5328 (goto-char b)))))
5330 (defun gnus-mime-set-charset-parameters (handle charset)
5331 "Set CHARSET to parameters in HANDLE.
5332 CHARSET may either be a string or a symbol."
5333 (unless (stringp charset)
5334 (setq charset (symbol-name charset)))
5335 (if (stringp (car handle))
5336 (dolist (h (cdr handle))
5337 (gnus-mime-set-charset-parameters h charset))
5338 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5339 "message/external-body")
5340 (progn
5341 (unless (mm-handle-cache handle)
5342 (mm-extern-cache-contents handle))
5343 (mm-handle-cache handle))
5344 handle)))
5345 (param (assq 'charset (cdr type))))
5346 (if param
5347 (setcdr param charset)
5348 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5350 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5351 "Insert the MIME part under point into the current buffer using the
5352 specified charset."
5353 (interactive (list nil current-prefix-arg))
5354 (gnus-article-check-buffer)
5355 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5356 (fun (get-text-property (point) 'gnus-callback))
5357 (gnus-newsgroup-ignored-charsets 'gnus-all)
5358 charset form preferred parts)
5359 (when handle
5360 (when (prog1
5361 (and fun
5362 (setq charset
5363 (or (cdr (assq
5365 gnus-summary-show-article-charset-alist))
5366 (mm-read-coding-system "Charset: "))))
5367 (if (mm-handle-undisplayer handle)
5368 (mm-remove-part handle)))
5369 (gnus-mime-set-charset-parameters handle charset)
5370 (when (and (consp (setq form (cdr-safe fun)))
5371 (setq form (ignore-errors
5372 (assq 'gnus-mime-display-alternative form)))
5373 (setq preferred (caddr form))
5374 (progn
5375 (when (eq (car preferred) 'quote)
5376 (setq preferred (cadr preferred)))
5377 (not (equal preferred
5378 (get-text-property (point) 'gnus-data))))
5379 (setq parts (get-text-property (point) 'gnus-part))
5380 (setq parts (cdr (assq parts
5381 gnus-article-mime-handle-alist)))
5382 (equal (mm-handle-media-type parts) "multipart/alternative")
5383 (setq parts (reverse (cdr parts))))
5384 (setcar (cddr form)
5385 (list 'quote (or (cadr (member preferred parts))
5386 (car parts)))))
5387 (funcall fun handle)))))
5389 (defun gnus-mime-view-part-externally (&optional handle)
5390 "View the MIME part under point with an external viewer."
5391 (interactive)
5392 (gnus-article-check-buffer)
5393 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5394 (mm-user-display-methods nil)
5395 (mm-inlined-types nil)
5396 (mail-parse-charset gnus-newsgroup-charset)
5397 (mail-parse-ignored-charsets
5398 (with-current-buffer gnus-summary-buffer
5399 gnus-newsgroup-ignored-charsets))
5400 (type (mm-handle-media-type handle))
5401 (method (mailcap-mime-info type))
5402 (mm-enable-external t))
5403 (if (not (stringp method))
5404 (gnus-mime-view-part-as-type
5405 nil (lambda (type) (stringp (mailcap-mime-info type))))
5406 (when handle
5407 (mm-display-part handle nil t)))))
5409 (defun gnus-mime-view-part-internally (&optional handle)
5410 "View the MIME part under point with an internal viewer.
5411 If no internal viewer is available, use an external viewer."
5412 (interactive)
5413 (gnus-article-check-buffer)
5414 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5415 (mm-inlined-types '(".*"))
5416 (mm-inline-large-images t)
5417 (mail-parse-charset gnus-newsgroup-charset)
5418 (mail-parse-ignored-charsets
5419 (with-current-buffer gnus-summary-buffer
5420 gnus-newsgroup-ignored-charsets))
5421 (inhibit-read-only t))
5422 (if (not (mm-inlinable-p handle))
5423 (gnus-mime-view-part-as-type
5424 nil (lambda (type) (mm-inlinable-p handle type)))
5425 (when handle
5426 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5428 (defun gnus-mime-action-on-part (&optional action)
5429 "Do something with the MIME attachment at \(point\)."
5430 (interactive
5431 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5432 (gnus-article-check-buffer)
5433 (let ((action-pair (assoc action gnus-mime-action-alist)))
5434 (if action-pair
5435 (funcall (cdr action-pair)))))
5437 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5438 "Call FUNCTION on MIME part N.
5439 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5440 If INTERACTIVE, call FUNCTION interactively."
5441 (let (window frame)
5442 ;; Check whether the article is displayed.
5443 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5444 (setq window (get-buffer-window gnus-article-buffer t))
5445 (frame-visible-p (setq frame (window-frame window))))
5446 (error "No article is displayed"))
5447 (with-current-buffer gnus-article-buffer
5448 ;; Check whether the article displays the right contents.
5449 (unless (with-current-buffer gnus-summary-buffer
5450 (eq gnus-current-article (gnus-summary-article-number)))
5451 (error "You should select the right article first"))
5452 (if n
5453 (setq n (prefix-numeric-value n))
5454 (let ((pt (point)))
5455 (setq n (or (get-text-property pt 'gnus-part)
5456 (and (not (bobp))
5457 (get-text-property (1- pt) 'gnus-part))
5458 (get-text-property (prog2
5459 (forward-line 1)
5460 (point)
5461 (goto-char pt))
5462 'gnus-part)
5463 (get-text-property
5464 (or (and (setq pt (previous-single-property-change
5465 pt 'gnus-part))
5466 (1- pt))
5467 (next-single-property-change (point) 'gnus-part)
5468 (point))
5469 'gnus-part)
5470 1))))
5471 ;; Check whether the specified part exists.
5472 (when (> n (length gnus-article-mime-handle-alist))
5473 (error "No such part")))
5474 (unless
5475 (progn
5476 ;; To select the window is needed so that the cursor
5477 ;; might be visible on the MIME button.
5478 (select-window (prog1
5479 window
5480 (setq window (selected-window))
5481 ;; Article may be displayed in the other frame.
5482 (gnus-select-frame-set-input-focus
5483 (prog1
5484 frame
5485 (setq frame (selected-frame))))))
5486 (when (gnus-article-goto-part n)
5487 ;; We point the cursor and the arrow at the MIME button
5488 ;; when the `function' prompt the user for something.
5489 (unless (and (pos-visible-in-window-p)
5490 (> (count-lines (point) (window-end))
5491 (/ (1- (window-height)) 3)))
5492 (recenter (/ (1- (window-height)) 3)))
5493 (let ((cursor-in-non-selected-windows t)
5494 (overlay-arrow-string "=>")
5495 (overlay-arrow-position (point-marker)))
5496 (unwind-protect
5497 (cond
5498 ((and no-handle interactive)
5499 (call-interactively function))
5500 (no-handle
5501 (funcall function))
5502 (interactive
5503 (call-interactively
5504 function (get-text-property (point) 'gnus-data)))
5506 (funcall function
5507 (get-text-property (point) 'gnus-data))))
5508 (set-marker overlay-arrow-position nil)
5509 (unless gnus-auto-select-part
5510 (gnus-select-frame-set-input-focus frame)
5511 (select-window window))))
5513 (if gnus-inhibit-mime-unbuttonizing
5514 ;; This is the default though the program shouldn't reach here.
5515 (error "No such part")
5516 ;; The part which doesn't have the MIME button is selected.
5517 ;; So, we display all the buttons and redo it.
5518 (let ((gnus-inhibit-mime-unbuttonizing t))
5519 (gnus-summary-show-article)
5520 (gnus-article-part-wrapper n function no-handle))))))
5522 (defun gnus-article-pipe-part (n)
5523 "Pipe MIME part N, which is the numerical prefix."
5524 (interactive "P")
5525 (gnus-article-part-wrapper n 'mm-pipe-part))
5527 (defun gnus-article-save-part (n)
5528 "Save MIME part N, which is the numerical prefix."
5529 (interactive "P")
5530 (gnus-article-part-wrapper n 'mm-save-part))
5532 (defun gnus-article-interactively-view-part (n)
5533 "View MIME part N interactively, which is the numerical prefix."
5534 (interactive "P")
5535 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5537 (defun gnus-article-copy-part (n)
5538 "Copy MIME part N, which is the numerical prefix."
5539 (interactive "P")
5540 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5542 (defun gnus-article-view-part-as-charset (n)
5543 "View MIME part N using a specified charset.
5544 N is the numerical prefix."
5545 (interactive "P")
5546 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5548 (defun gnus-article-view-part-externally (n)
5549 "View MIME part N externally, which is the numerical prefix."
5550 (interactive "P")
5551 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5553 (defun gnus-article-inline-part (n)
5554 "Inline MIME part N, which is the numerical prefix."
5555 (interactive "P")
5556 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5558 (defun gnus-article-save-part-and-strip (n)
5559 "Save MIME part N and replace it with an external body.
5560 N is the numerical prefix."
5561 (interactive "P")
5562 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5564 (defun gnus-article-replace-part (n)
5565 "Replace MIME part N with an external body.
5566 N is the numerical prefix."
5567 (interactive "P")
5568 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5570 (defun gnus-article-delete-part (n)
5571 "Delete MIME part N and add some information about the removed part.
5572 N is the numerical prefix."
5573 (interactive "P")
5574 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5576 (defun gnus-article-view-part-as-type (n)
5577 "Choose a MIME media type, and view part N as such.
5578 N is the numerical prefix."
5579 (interactive "P")
5580 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5582 (defun gnus-article-mime-match-handle-first (condition)
5583 (if condition
5584 (let (n)
5585 (dolist (ihandle gnus-article-mime-handle-alist)
5586 (if (and (cond
5587 ((functionp condition)
5588 (funcall condition (cdr ihandle)))
5589 ((eq condition 'undisplayed)
5590 (not (or (mm-handle-undisplayer (cdr ihandle))
5591 (equal (mm-handle-media-type (cdr ihandle))
5592 "multipart/alternative"))))
5593 ((eq condition 'undisplayed-alternative)
5594 (not (mm-handle-undisplayer (cdr ihandle))))
5595 (t t))
5596 (gnus-article-goto-part (car ihandle))
5597 (or (not n) (< (car ihandle) n)))
5598 (setq n (car ihandle))))
5599 (or n 1))
5602 (defun gnus-article-view-part (&optional n)
5603 "View MIME part N, which is the numerical prefix.
5604 If the part is already shown, hide the part. If N is nil, view
5605 all parts."
5606 (interactive "P")
5607 (with-current-buffer gnus-article-buffer
5608 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5609 gnus-article-mime-match-handle-function)))
5610 (when (> n (length gnus-article-mime-handle-alist))
5611 (error "No such part"))
5612 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5613 (when (gnus-article-goto-part n)
5614 (if (equal (car handle) "multipart/alternative")
5615 (progn
5616 (beginning-of-line) ;; Make it toggle subparts
5617 (gnus-article-press-button))
5618 (when (eq (gnus-mm-display-part handle) 'internal)
5619 (gnus-set-window-start)))))))
5621 (defsubst gnus-article-mime-total-parts ()
5622 (if (bufferp (car gnus-article-mime-handles))
5623 1 ;; single part
5624 (1- (length gnus-article-mime-handles))))
5626 (defun gnus-mm-display-part (handle)
5627 "Display HANDLE and fix MIME button."
5628 (let ((id (get-text-property (point) 'gnus-part))
5629 (point (point))
5630 (inhibit-read-only t))
5631 (forward-line 1)
5632 (prog1
5633 (let ((window (selected-window))
5634 (mail-parse-charset gnus-newsgroup-charset)
5635 (mail-parse-ignored-charsets
5636 (if (gnus-buffer-live-p gnus-summary-buffer)
5637 (with-current-buffer gnus-summary-buffer
5638 gnus-newsgroup-ignored-charsets)
5639 nil)))
5640 (save-excursion
5641 (unwind-protect
5642 (let ((win (gnus-get-buffer-window (current-buffer) t))
5643 (beg (point)))
5644 (when win
5645 (select-window win))
5646 (goto-char point)
5647 (forward-line)
5648 (if (mm-handle-displayed-p handle)
5649 ;; This will remove the part.
5650 (mm-display-part handle)
5651 (save-restriction
5652 (narrow-to-region (point)
5653 (if (eobp) (point) (1+ (point))))
5654 (gnus-bind-safe-url-regexp (mm-display-part handle))
5655 ;; We narrow to the part itself and
5656 ;; then call the treatment functions.
5657 (goto-char (point-min))
5658 (forward-line 1)
5659 (narrow-to-region (point) (point-max))
5660 (gnus-treat-article
5661 nil id
5662 (gnus-article-mime-total-parts)
5663 (mm-handle-media-type handle)))))
5664 (if (window-live-p window)
5665 (select-window window)))))
5666 (goto-char point)
5667 (gnus-delete-line)
5668 (gnus-insert-mime-button
5669 handle id (list (mm-handle-displayed-p handle)))
5670 (goto-char point))))
5672 (defun gnus-article-goto-part (n)
5673 "Go to MIME part N."
5674 (when gnus-break-pages
5675 (widen))
5676 (prog1
5677 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5678 part handle end next handles)
5679 (when start
5680 (goto-char start)
5681 (if (setq handle (get-text-property start 'gnus-data))
5682 start
5683 ;; Go to the displayed subpart, assuming this is
5684 ;; multipart/alternative.
5685 (setq part start
5686 end (point-at-eol))
5687 (while (and (not handle)
5688 part
5689 (< part end)
5690 (setq next (text-property-not-all part end
5691 'gnus-data nil)))
5692 (setq part next
5693 handle (get-text-property part 'gnus-data))
5694 (push (cons handle part) handles)
5695 (unless (mm-handle-displayed-p handle)
5696 (setq handle nil
5697 part (text-property-any part end 'gnus-data nil))))
5698 (unless handle
5699 ;; No subpart is displayed, so we find preferred one.
5700 (setq part
5701 (cdr (assq (mm-preferred-alternative
5702 (nreverse (mapcar 'car handles)))
5703 handles))))
5704 (if part
5705 (goto-char (1+ part))
5706 start))))
5707 (when gnus-break-pages
5708 (gnus-narrow-to-page))))
5710 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5711 (let ((gnus-tmp-name
5712 (or (mm-handle-filename handle)
5713 (mail-content-type-get (mm-handle-type handle) 'url)
5714 ""))
5715 (gnus-tmp-type (mm-handle-media-type handle))
5716 (gnus-tmp-description (or (mm-handle-description handle) ""))
5717 (gnus-tmp-dots
5718 (if (if displayed (car displayed)
5719 (mm-handle-displayed-p handle))
5720 "" "..."))
5721 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5722 (buffer-size)))
5723 gnus-tmp-type-long b e)
5724 (when (string-match ".*/" gnus-tmp-name)
5725 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5726 (setq gnus-tmp-type-long (concat gnus-tmp-type
5727 (and (not (equal gnus-tmp-name ""))
5728 (concat "; " gnus-tmp-name))))
5729 (unless (equal gnus-tmp-description "")
5730 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5731 (unless (bolp)
5732 (insert "\n"))
5733 (setq b (point))
5734 (gnus-eval-format
5735 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5736 `(keymap ,gnus-mime-button-map
5737 gnus-callback gnus-mm-display-part
5738 gnus-part ,gnus-tmp-id
5739 article-type annotation
5740 gnus-data ,handle
5741 rear-nonsticky t))
5742 (setq e (if (bolp)
5743 ;; Exclude a newline.
5744 (1- (point))
5745 (point)))
5746 (when gnus-article-button-face
5747 (gnus-overlay-put (gnus-make-overlay b e nil t)
5748 'face gnus-article-button-face))
5749 (widget-convert-button
5750 'link b e
5751 :mime-handle handle
5752 :action 'gnus-widget-press-button
5753 :button-keymap gnus-mime-button-map
5754 :help-echo
5755 (lambda (widget)
5756 ;; Needed to properly clear the message due to a bug in
5757 ;; wid-edit (XEmacs only).
5758 (if (boundp 'help-echo-owns-message)
5759 (setq help-echo-owns-message t))
5760 (format
5761 "%S: %s the MIME part; %S: more options"
5762 (aref gnus-mouse-2 0)
5763 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5764 "hide" "show")
5765 (aref gnus-down-mouse-3 0))))))
5767 (defun gnus-widget-press-button (elems el)
5768 (goto-char (widget-get elems :from))
5769 (gnus-article-press-button))
5771 (defvar gnus-displaying-mime nil)
5773 (defun gnus-display-mime (&optional ihandles)
5774 "Display the MIME parts."
5775 (save-excursion
5776 (save-selected-window
5777 (let ((window (get-buffer-window gnus-article-buffer))
5778 (point (point)))
5779 (when window
5780 (select-window window)
5781 ;; We have to do this since selecting the window
5782 ;; may change the point. So we set the window point.
5783 (set-window-point window point)))
5784 (let ((handles ihandles)
5785 (inhibit-read-only t)
5786 handle)
5787 (cond (handles)
5788 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5789 (when gnus-article-emulate-mime
5790 (mm-uu-dissect-text-parts handles)))
5791 (gnus-article-emulate-mime
5792 (setq handles (mm-uu-dissect))))
5793 (when (and (not ihandles)
5794 (not gnus-displaying-mime))
5795 ;; Top-level call; we clean up.
5796 (when gnus-article-mime-handles
5797 (mm-destroy-parts gnus-article-mime-handles)
5798 (setq gnus-article-mime-handle-alist nil));; A trick.
5799 (setq gnus-article-mime-handles handles)
5800 ;; We allow users to glean info from the handles.
5801 (when gnus-article-mime-part-function
5802 (gnus-mime-part-function handles)))
5803 (if (and handles
5804 (or (not (stringp (car handles)))
5805 (cdr handles)))
5806 (progn
5807 (when (and (not ihandles)
5808 (not gnus-displaying-mime))
5809 ;; Clean up for mime parts.
5810 (article-goto-body)
5811 (delete-region (point) (point-max)))
5812 (let ((gnus-displaying-mime t))
5813 (gnus-mime-display-part handles)))
5814 (save-restriction
5815 (article-goto-body)
5816 (narrow-to-region (point) (point-max))
5817 (gnus-treat-article nil 1 1 "text/plain")
5818 (widen)))
5819 (unless ihandles
5820 ;; Highlight the headers.
5821 (save-excursion
5822 (save-restriction
5823 (article-goto-body)
5824 (narrow-to-region (point-min) (point))
5825 (gnus-article-save-original-date
5826 (gnus-treat-article 'head)))))))
5827 ;; Cope with broken MIME messages.
5828 (goto-char (point-max))
5829 (unless (bolp)
5830 (insert "\n"))))
5832 (defcustom gnus-mime-display-multipart-as-mixed nil
5833 "Display \"multipart\" parts as \"multipart/mixed\".
5835 If t, it overrides nil values of
5836 `gnus-mime-display-multipart-alternative-as-mixed' and
5837 `gnus-mime-display-multipart-related-as-mixed'."
5838 :group 'gnus-article-mime
5839 :type 'boolean)
5841 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5842 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5843 :version "22.1"
5844 :group 'gnus-article-mime
5845 :type 'boolean)
5847 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5848 "Display \"multipart/related\" parts as \"multipart/mixed\".
5850 If displaying \"text/html\" is discouraged \(see
5851 `mm-discouraged-alternatives'\) images or other material inside a
5852 \"multipart/related\" part might be overlooked when this variable is nil."
5853 :version "22.1"
5854 :group 'gnus-article-mime
5855 :type 'boolean)
5857 (defun gnus-mime-display-part (handle)
5858 (cond
5859 ;; Maybe a broken MIME message.
5860 ((null handle))
5861 ;; Single part.
5862 ((not (stringp (car handle)))
5863 (gnus-mime-display-single handle))
5864 ;; User-defined multipart
5865 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5866 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5867 handle))
5868 ;; multipart/alternative
5869 ((and (equal (car handle) "multipart/alternative")
5870 (not (or gnus-mime-display-multipart-as-mixed
5871 gnus-mime-display-multipart-alternative-as-mixed)))
5872 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5873 (push (cons id handle) gnus-article-mime-handle-alist)
5874 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5875 ;; multipart/related
5876 ((and (equal (car handle) "multipart/related")
5877 (not (or gnus-mime-display-multipart-as-mixed
5878 gnus-mime-display-multipart-related-as-mixed)))
5879 ;;;!!!We should find the start part, but we just default
5880 ;;;!!!to the first part.
5881 ;;(gnus-mime-display-part (cadr handle))
5882 ;;;!!! Most multipart/related is an HTML message plus images.
5883 ;;;!!! Unfortunately we are unable to let W3 display those
5884 ;;;!!! included images, so we just display it as a mixed multipart.
5885 ;;(gnus-mime-display-mixed (cdr handle))
5886 ;;;!!! No, w3 can display everything just fine.
5887 (gnus-mime-display-part (cadr handle)))
5888 ((equal (car handle) "multipart/signed")
5889 (gnus-add-wash-type 'signed)
5890 (gnus-mime-display-security handle))
5891 ((equal (car handle) "multipart/encrypted")
5892 (gnus-add-wash-type 'encrypted)
5893 (gnus-mime-display-security handle))
5894 ;; Other multiparts are handled like multipart/mixed.
5896 (gnus-mime-display-mixed (cdr handle)))))
5898 (defun gnus-mime-part-function (handles)
5899 (if (stringp (car handles))
5900 (mapcar 'gnus-mime-part-function (cdr handles))
5901 (funcall gnus-article-mime-part-function handles)))
5903 (defun gnus-mime-display-mixed (handles)
5904 (mapcar 'gnus-mime-display-part handles))
5906 (defun gnus-mime-display-single (handle)
5907 (let ((type (mm-handle-media-type handle))
5908 (ignored gnus-ignored-mime-types)
5909 (not-attachment t)
5910 (move nil)
5911 display text)
5912 (catch 'ignored
5913 (progn
5914 (while ignored
5915 (when (string-match (pop ignored) type)
5916 (throw 'ignored nil)))
5917 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5918 (with-current-buffer gnus-summary-buffer
5919 gnus-inhibit-images)
5920 gnus-inhibit-images)
5921 (string-match "\\`image/" type)))
5922 (setq not-attachment
5923 (and (not (mm-inline-override-p handle))
5924 (or (not (mm-handle-disposition handle))
5925 (equal (car (mm-handle-disposition handle))
5926 "inline")
5927 (mm-attachment-override-p handle))))
5928 (mm-automatic-display-p handle)
5929 (or (and
5930 (mm-inlinable-p handle)
5931 (mm-inlined-p handle))
5932 (mm-automatic-external-display-p type)))
5933 (setq display t)
5934 (when (equal (mm-handle-media-supertype handle) "text")
5935 (setq text t)))
5936 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5937 beg)
5938 (push (cons id handle) gnus-article-mime-handle-alist)
5939 (when (and display
5940 (equal (mm-handle-media-supertype handle) "message"))
5941 (insert-char
5943 (cond ((not (bolp)) 2)
5944 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5945 (t 1))))
5946 (when (or (not display)
5947 (not (gnus-unbuttonized-mime-type-p type))
5948 (eq id gnus-mime-buttonized-part-id))
5949 (gnus-insert-mime-button
5950 handle id (list (or display (and not-attachment text))))
5951 (gnus-article-insert-newline)
5952 ;; Remember modify the number of forward lines.
5953 (setq move t))
5954 (setq beg (point))
5955 (cond
5956 (display
5957 (when move
5958 (forward-line -1)
5959 (setq beg (point)))
5960 (let ((mail-parse-charset gnus-newsgroup-charset)
5961 (mail-parse-ignored-charsets
5962 (save-excursion (condition-case ()
5963 (set-buffer gnus-summary-buffer)
5964 (error))
5965 gnus-newsgroup-ignored-charsets)))
5966 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5967 (goto-char (point-max)))
5968 ((and text not-attachment)
5969 (when move
5970 (forward-line -1)
5971 (setq beg (point)))
5972 (gnus-article-insert-newline)
5973 (mm-display-inline handle)
5974 (goto-char (point-max))))
5975 ;; Do highlighting.
5976 (save-excursion
5977 (save-restriction
5978 (narrow-to-region beg (point))
5979 (if (eq handle gnus-article-mime-handles)
5980 ;; The format=flowed case.
5981 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5982 ;; Don't count signature parts that are never displayed.
5983 ;; The part number should be re-calculated supposing this
5984 ;; might be a message/rfc822 part.
5985 (let (handles)
5986 (dolist (part gnus-article-mime-handles)
5987 (unless (or (stringp part)
5988 (equal (car (mm-handle-type part))
5989 "application/pgp-signature"))
5990 (push part handles)))
5991 (gnus-treat-article
5992 nil (length (memq handle handles)) (length handles)
5993 (mm-handle-media-type handle)))))))))))
5995 (defun gnus-unbuttonized-mime-type-p (type)
5996 "Say whether TYPE is to be unbuttonized."
5997 (unless gnus-inhibit-mime-unbuttonizing
5998 (when (catch 'found
5999 (let ((types gnus-unbuttonized-mime-types))
6000 (while types
6001 (when (string-match (pop types) type)
6002 (throw 'found t)))))
6003 (not (catch 'found
6004 (let ((types gnus-buttonized-mime-types))
6005 (while types
6006 (when (string-match (pop types) type)
6007 (throw 'found t)))))))))
6009 (defun gnus-article-insert-newline ()
6010 "Insert a newline, but mark it as undeletable."
6011 (gnus-put-text-property
6012 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6014 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6015 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6016 (ihandles handles)
6017 (point (point))
6018 handle (inhibit-read-only t) from props begend not-pref)
6019 (save-window-excursion
6020 (save-restriction
6021 (when ibegend
6022 (narrow-to-region (car ibegend)
6023 (or (cdr ibegend)
6024 (progn
6025 (goto-char (car ibegend))
6026 (forward-line 2)
6027 (point))))
6028 (delete-region (point-min) (point-max))
6029 (mm-remove-parts handles))
6030 (setq begend (list (point-marker)))
6031 ;; Do the toggle.
6032 (unless (setq not-pref (cadr (member preferred ihandles)))
6033 (setq not-pref (car ihandles)))
6034 (when (or ibegend
6035 (not preferred)
6036 (not (gnus-unbuttonized-mime-type-p
6037 "multipart/alternative")))
6038 (gnus-add-text-properties
6039 (setq from (point))
6040 (progn
6041 (insert (format "%d. " id))
6042 (point))
6043 `(gnus-callback
6044 (lambda (handles)
6045 (unless ,(not ibegend)
6046 (setq gnus-article-mime-handle-alist
6047 ',gnus-article-mime-handle-alist))
6048 (gnus-mime-display-alternative
6049 ',ihandles ',not-pref ',begend ,id))
6050 keymap ,gnus-mime-button-map
6051 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6052 face ,gnus-article-button-face
6053 gnus-part ,id
6054 article-type multipart
6055 rear-nonsticky t))
6056 (widget-convert-button 'link from (point)
6057 :action 'gnus-widget-press-button
6058 :button-keymap gnus-widget-button-keymap)
6059 ;; Do the handles
6060 (while (setq handle (pop handles))
6061 (gnus-add-text-properties
6062 (setq from (point))
6063 (progn
6064 (insert (format "(%c) %-18s"
6065 (if (equal handle preferred) ?* ? )
6066 (mm-handle-media-type handle)))
6067 (point))
6068 `(gnus-callback
6069 (lambda (handles)
6070 (unless ,(not ibegend)
6071 (setq gnus-article-mime-handle-alist
6072 ',gnus-article-mime-handle-alist))
6073 (gnus-mime-display-alternative
6074 ',ihandles ',handle ',begend ,id))
6075 keymap ,gnus-mime-button-map
6076 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6077 face ,gnus-article-button-face
6078 gnus-part ,id
6079 gnus-data ,handle
6080 rear-nonsticky t))
6081 (widget-convert-button 'link from (point)
6082 :action 'gnus-widget-press-button
6083 :button-keymap gnus-widget-button-keymap)
6084 (insert " "))
6085 (insert "\n\n"))
6086 (when preferred
6087 (if (stringp (car preferred))
6088 (gnus-display-mime preferred)
6089 (let ((mail-parse-charset gnus-newsgroup-charset)
6090 (mail-parse-ignored-charsets
6091 (with-current-buffer gnus-summary-buffer
6092 gnus-newsgroup-ignored-charsets)))
6093 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6094 ;; Do highlighting.
6095 (save-excursion
6096 (save-restriction
6097 (narrow-to-region (car begend) (point-max))
6098 (gnus-treat-article
6099 nil (length gnus-article-mime-handle-alist)
6100 (gnus-article-mime-total-parts)
6101 (mm-handle-media-type preferred))))))
6102 (goto-char (point-max))
6103 (setcdr begend (point-marker)))))
6104 (when ibegend
6105 (goto-char point))))
6107 (defconst gnus-article-wash-status-strings
6108 (let ((alist '((cite "c" "Possible hidden citation text"
6109 " " "All citation text visible")
6110 (headers "h" "Hidden headers"
6111 " " "All headers visible.")
6112 (pgp "p" "Encrypted or signed message status hidden"
6113 " " "No hidden encryption nor digital signature status")
6114 (signature "s" "Signature has been hidden"
6115 " " "Signature is visible")
6116 (overstrike "o" "Overstrike (^H) characters applied"
6117 " " "No overstrike characters applied")
6118 (emphasis "e" "/*_Emphasis_*/ characters applied"
6119 " " "No /*_emphasis_*/ characters applied")))
6120 result)
6121 (dolist (entry alist result)
6122 (let ((key (nth 0 entry))
6123 (on (copy-sequence (nth 1 entry)))
6124 (on-help (nth 2 entry))
6125 (off (copy-sequence (nth 3 entry)))
6126 (off-help (nth 4 entry)))
6127 (put-text-property 0 1 'help-echo on-help on)
6128 (put-text-property 0 1 'help-echo off-help off)
6129 (push (list key on off) result))))
6130 "Alist of strings describing wash status in the mode line.
6131 Each entry has the form (KEY ON OF), where the KEY is a symbol
6132 representing the particular washing function, ON is the string to use
6133 in the article mode line when the washing function is active, and OFF
6134 is the string to use when it is inactive.")
6136 (defun gnus-article-wash-status-entry (key value)
6137 (let ((entry (assoc key gnus-article-wash-status-strings)))
6138 (if value (nth 1 entry) (nth 2 entry))))
6140 (defun gnus-article-wash-status ()
6141 "Return a string which display status of article washing."
6142 (with-current-buffer gnus-article-buffer
6143 (let ((cite (memq 'cite gnus-article-wash-types))
6144 (headers (memq 'headers gnus-article-wash-types))
6145 (boring (memq 'boring-headers gnus-article-wash-types))
6146 (pgp (memq 'pgp gnus-article-wash-types))
6147 (pem (memq 'pem gnus-article-wash-types))
6148 (signed (memq 'signed gnus-article-wash-types))
6149 (encrypted (memq 'encrypted gnus-article-wash-types))
6150 (signature (memq 'signature gnus-article-wash-types))
6151 (overstrike (memq 'overstrike gnus-article-wash-types))
6152 (emphasis (memq 'emphasis gnus-article-wash-types)))
6153 (concat
6154 (gnus-article-wash-status-entry 'cite cite)
6155 (gnus-article-wash-status-entry 'headers (or headers boring))
6156 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6157 (gnus-article-wash-status-entry 'signature signature)
6158 (gnus-article-wash-status-entry 'overstrike overstrike)
6159 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6161 (defun gnus-add-wash-type (type)
6162 "Add a washing of TYPE to the current status."
6163 (add-to-list 'gnus-article-wash-types type))
6165 (defun gnus-delete-wash-type (type)
6166 "Add a washing of TYPE to the current status."
6167 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6169 (defun gnus-add-image (category image)
6170 "Add IMAGE of CATEGORY to the list of displayed images."
6171 (let ((entry (assq category gnus-article-image-alist)))
6172 (unless entry
6173 (setq entry (list category))
6174 (push entry gnus-article-image-alist))
6175 (nconc entry (list image))))
6177 (defun gnus-delete-images (category)
6178 "Delete all images in CATEGORY."
6179 (let ((entry (assq category gnus-article-image-alist)))
6180 (dolist (image (cdr entry))
6181 (gnus-remove-image image category))
6182 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6183 (gnus-delete-wash-type category)))
6185 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6187 (defun gnus-article-maybe-hide-headers ()
6188 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6189 Provided for backwards compatibility."
6190 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6191 (not (with-current-buffer gnus-summary-buffer
6192 gnus-have-all-headers)))
6193 (not gnus-inhibit-hiding))
6194 (gnus-article-hide-headers)))
6196 (declare-function shr-put-image "shr" (data alt &optional flags))
6198 (defun gnus-shr-put-image (data alt &optional flags)
6199 "Put image DATA with a string ALT. Enable image to be deleted."
6200 (let ((image (if flags
6201 (shr-put-image data (propertize (or alt "*")
6202 'gnus-image-category 'shr)
6203 flags)
6204 ;; Old `shr-put-image' doesn't take the optional `flags'
6205 ;; argument.
6206 (shr-put-image data (propertize (or alt "*")
6207 'gnus-image-category 'shr)))))
6208 (when image
6209 (gnus-add-image 'shr image))))
6211 ;;; Article savers.
6213 (defun gnus-output-to-file (file-name)
6214 "Append the current article to a file named FILE-NAME.
6215 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6216 text and used as the value of the coding cookie which is added to the
6217 top of a file. Otherwise, this function saves a raw article without
6218 the coding cookie."
6219 (let* ((artbuf (current-buffer))
6220 (file-name-coding-system nnmail-pathname-coding-system)
6221 (coding gnus-article-save-coding-system)
6222 (coding-system-for-read (if coding
6223 nil ;; Rely on the coding cookie.
6224 mm-text-coding-system))
6225 (coding-system-for-write (or coding
6226 mm-text-coding-system-for-write
6227 mm-text-coding-system))
6228 (exists (file-exists-p file-name)))
6229 (with-temp-buffer
6230 (when exists
6231 (insert-file-contents file-name)
6232 (goto-char (point-min))
6233 ;; Remove the existing coding cookie.
6234 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6235 (delete-region (match-beginning 0) (match-end 0))))
6236 (goto-char (point-max))
6237 (insert-buffer-substring artbuf)
6238 ;; Append newline at end of the buffer as separator, and then
6239 ;; save it to file.
6240 (goto-char (point-max))
6241 (insert "\n")
6242 (when coding
6243 ;; If the coding system is not suitable to encode the text,
6244 ;; ask a user for a proper one.
6245 (when (fboundp 'select-safe-coding-system)
6246 (setq coding (coding-system-base
6247 (save-window-excursion
6248 (select-safe-coding-system (point-min) (point-max)
6249 coding))))
6250 (setq coding-system-for-write
6251 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6252 coding)))
6253 (goto-char (point-min))
6254 ;; Add the coding cookie.
6255 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6256 coding-system-for-write)))
6257 (if exists
6258 (progn
6259 (write-region (point-min) (point-max) file-name nil 'no-message)
6260 (message "Appended to %s" file-name))
6261 (write-region (point-min) (point-max) file-name))))
6264 (defun gnus-narrow-to-page (&optional arg)
6265 "Narrow the article buffer to a page.
6266 If given a numerical ARG, move forward ARG pages."
6267 (interactive "P")
6268 (setq arg (if arg (prefix-numeric-value arg) 0))
6269 (with-current-buffer gnus-article-buffer
6270 (widen)
6271 ;; Remove any old next/prev buttons.
6272 (when (gnus-visual-p 'page-marker)
6273 (let ((inhibit-read-only t))
6274 (gnus-remove-text-with-property 'gnus-prev)
6275 (gnus-remove-text-with-property 'gnus-next)))
6276 (let (st nd pt)
6277 (when (save-excursion
6278 (cond ((< arg 0)
6279 (if (re-search-backward page-delimiter nil 'move (abs arg))
6280 (prog1
6281 (setq nd (match-beginning 0)
6282 pt nd)
6283 (when (re-search-backward page-delimiter nil t)
6284 (setq st (match-end 0))))
6285 (when (re-search-forward page-delimiter nil t)
6286 (setq nd (match-beginning 0)
6287 pt (point-min)))))
6288 ((> arg 0)
6289 (if (re-search-forward page-delimiter nil 'move arg)
6290 (prog1
6291 (setq st (match-end 0)
6292 pt st)
6293 (when (re-search-forward page-delimiter nil t)
6294 (setq nd (match-beginning 0))))
6295 (when (re-search-backward page-delimiter nil t)
6296 (setq st (match-end 0)
6297 pt (point-max)))))
6299 (when (re-search-backward page-delimiter nil t)
6300 (goto-char (setq st (match-end 0))))
6301 (when (re-search-forward page-delimiter nil t)
6302 (setq nd (match-beginning 0)))
6303 (or st nd))))
6304 (setq gnus-page-broken t)
6305 (when pt (goto-char pt))
6306 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6307 (when (gnus-visual-p 'page-marker)
6308 (save-excursion
6309 (when nd
6310 (goto-char nd)
6311 (gnus-insert-next-page-button))
6312 (when st
6313 (goto-char st)
6314 (gnus-insert-prev-page-button))))))))
6316 ;; Article mode commands
6318 (defun gnus-article-goto-next-page ()
6319 "Show the next page of the article."
6320 (interactive)
6321 (when (gnus-article-next-page)
6322 (goto-char (point-min))
6323 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6326 (defun gnus-article-goto-prev-page ()
6327 "Show the previous page of the article."
6328 (interactive)
6329 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6330 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6331 (gnus-article-prev-page nil)))
6333 ;; This is cleaner but currently breaks `gnus-pick-mode':
6335 ;; (defun gnus-article-goto-next-page ()
6336 ;; "Show the next page of the article."
6337 ;; (interactive)
6338 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6339 ;; (gnus-summary-next-page)))
6341 ;; (defun gnus-article-goto-prev-page ()
6342 ;; "Show the next page of the article."
6343 ;; (interactive)
6344 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6345 ;; (gnus-summary-prev-page)))
6347 (defun gnus-article-next-page (&optional lines)
6348 "Show the next page of the current article.
6349 If end of article, return non-nil. Otherwise return nil.
6350 Argument LINES specifies lines to be scrolled up."
6351 (interactive "p")
6352 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6353 (if (and (not (and gnus-article-over-scroll
6354 (> (count-lines (window-start) (point-max))
6355 (if (featurep 'xemacs)
6356 (or lines (1- (window-height)))
6357 (+ (or lines (1- (window-height))) scroll-margin)))))
6358 (save-excursion
6359 (end-of-line)
6360 (and (pos-visible-in-window-p) ;Not continuation line.
6361 (>= (point) (point-max)))))
6362 ;; Nothing in this page.
6363 (if (or (not gnus-page-broken)
6364 (save-excursion
6365 (save-restriction
6366 (widen)
6367 (forward-line)
6368 (eobp)))) ;Real end-of-buffer?
6369 (progn
6370 (when gnus-article-over-scroll
6371 (gnus-article-next-page-1 lines))
6372 t) ;Nothing more.
6373 (gnus-narrow-to-page 1) ;Go to next page.
6374 nil)
6375 ;; More in this page.
6376 (gnus-article-next-page-1 lines)
6377 nil))
6379 (defun gnus-article-beginning-of-window ()
6380 "Move point to the beginning of the window.
6381 In Emacs, the point is placed at the line number which `scroll-margin'
6382 specifies."
6383 (if (featurep 'xemacs)
6384 (move-to-window-line 0)
6385 ;; There is an obscure bug in Emacs that makes it impossible to
6386 ;; scroll past big pictures in the article buffer. Try to fix
6387 ;; this by adding a sanity check by counting the lines visible.
6388 (when (> (count-lines (window-start) (window-end)) 30)
6389 (move-to-window-line
6390 (min (max 0 scroll-margin)
6391 (max 1 (- (window-height)
6392 (if mode-line-format 1 0)
6393 (if header-line-format 1 0)
6394 2)))))))
6396 (defun gnus-article-next-page-1 (lines)
6397 (condition-case ()
6398 (let ((scroll-in-place nil)
6399 (auto-window-vscroll nil))
6400 (scroll-up lines))
6401 (end-of-buffer
6402 ;; Long lines may cause an end-of-buffer error.
6403 (goto-char (point-max))))
6404 (gnus-article-beginning-of-window))
6406 (defun gnus-article-prev-page (&optional lines)
6407 "Show previous page of current article.
6408 Argument LINES specifies lines to be scrolled down."
6409 (interactive "p")
6410 (move-to-window-line 0)
6411 (if (and gnus-page-broken
6412 (bobp)
6413 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6414 (progn
6415 (gnus-narrow-to-page -1) ;Go to previous page.
6416 (goto-char (point-max))
6417 (recenter (if gnus-article-over-scroll
6418 (if lines
6419 (max (if (featurep 'xemacs)
6420 lines
6421 (+ lines scroll-margin))
6423 (- (window-height) 2))
6424 -1)))
6425 (prog1
6426 (condition-case ()
6427 (let ((scroll-in-place nil))
6428 (scroll-down lines))
6429 (beginning-of-buffer
6430 (goto-char (point-min))))
6431 (gnus-article-beginning-of-window))))
6433 (defun gnus-article-only-boring-p ()
6434 "Decide whether there is only boring text remaining in the article.
6435 Something \"interesting\" is a word of at least two letters that does
6436 not have a face in `gnus-article-boring-faces'."
6437 (when (and gnus-article-skip-boring
6438 (boundp 'gnus-article-boring-faces)
6439 (symbol-value 'gnus-article-boring-faces))
6440 (save-excursion
6441 (let ((inhibit-point-motion-hooks t))
6442 (catch 'only-boring
6443 (while (re-search-forward "\\b\\w\\w" nil t)
6444 (forward-char -1)
6445 (when (not (gnus-intersection
6446 (gnus-faces-at (point))
6447 (symbol-value 'gnus-article-boring-faces)))
6448 (throw 'only-boring nil)))
6449 (throw 'only-boring t))))))
6451 (defun gnus-article-refer-article ()
6452 "Read article specified by message-id around point."
6453 (interactive)
6454 (save-excursion
6455 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6456 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6457 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6458 (let ((msg-id (concat "<" (match-string 0) ">")))
6459 (set-buffer gnus-summary-buffer)
6460 (gnus-summary-refer-article msg-id))
6461 (error "No references around point"))))
6463 (defun gnus-article-show-summary ()
6464 "Reconfigure windows to show summary buffer."
6465 (interactive)
6466 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6467 (error "There is no summary buffer for this article buffer")
6468 (gnus-article-set-globals)
6469 (gnus-configure-windows 'article)
6470 (gnus-summary-goto-subject gnus-current-article)
6471 (gnus-summary-position-point)))
6473 (defun gnus-article-describe-briefly ()
6474 "Describe article mode commands briefly."
6475 (interactive)
6476 (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")))
6478 (defun gnus-article-check-buffer ()
6479 "Beep if not in an article buffer."
6480 (unless (equal major-mode 'gnus-article-mode)
6481 (error "Command invoked outside of a Gnus article buffer")))
6483 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6484 "Read a summary buffer key sequence and execute it from the article buffer."
6485 (interactive "P")
6486 (gnus-article-check-buffer)
6487 (let ((nosaves
6488 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6489 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6490 "=" "^" "\M-^" "|"))
6491 (nosave-but-article
6492 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6493 "An" "Ap" [?A (meta return)] [?A delete]))
6494 (nosave-in-article
6495 '("AS" "\C-d"))
6496 (up-to-top
6497 '("n" "Gn" "p" "Gp"))
6498 keys new-sum-point)
6499 (with-current-buffer gnus-article-current-summary
6500 (let (gnus-pick-mode)
6501 (setq unread-command-events (nconc unread-command-events
6502 (list (or key last-command-event)))
6503 keys (if (featurep 'xemacs)
6504 (events-to-keys (read-key-sequence nil t))
6505 (read-key-sequence nil t)))))
6507 (message "")
6509 (cond
6510 ((eq (aref keys (1- (length keys))) ?\C-h)
6511 (gnus-article-describe-bindings (substring keys 0 -1)))
6512 ((or (member keys nosaves)
6513 (member keys nosave-but-article)
6514 (member keys nosave-in-article))
6515 (let (func)
6516 (save-window-excursion
6517 (pop-to-buffer gnus-article-current-summary)
6518 ;; We disable the pick minor mode commands.
6519 (let (gnus-pick-mode)
6520 (setq func (key-binding keys t))))
6521 (if (or (not func)
6522 (numberp func))
6523 (ding)
6524 (unless (member keys nosave-in-article)
6525 (set-buffer gnus-article-current-summary))
6526 (when (and (symbolp func)
6527 (get func 'disabled))
6528 (error "Function %s disabled" func))
6529 (call-interactively func)
6530 (setq new-sum-point (point)))
6531 (when (member keys nosave-but-article)
6532 (pop-to-buffer gnus-article-buffer))))
6534 ;; These commands should restore window configuration.
6535 (let ((obuf (current-buffer))
6536 (owin (current-window-configuration))
6537 win func in-buffer selected new-sum-start new-sum-hscroll err)
6538 (cond (not-restore-window
6539 (pop-to-buffer gnus-article-current-summary)
6540 (setq win (selected-window)))
6541 ((setq win (get-buffer-window gnus-article-current-summary))
6542 (select-window win))
6544 (let ((summary-buffer gnus-article-current-summary))
6545 (gnus-configure-windows 'article)
6546 (unless (setq win (get-buffer-window summary-buffer 'visible))
6547 (let ((gnus-buffer-configuration
6548 '((article ((vertical 1.0
6549 (summary 0.25 point)
6550 (article 1.0)))))))
6551 (gnus-configure-windows 'article))
6552 (setq win (get-buffer-window summary-buffer 'visible)))
6553 (gnus-select-frame-set-input-focus (window-frame win))
6554 (select-window win))))
6555 (setq in-buffer (current-buffer))
6556 ;; We disable the pick minor mode commands.
6557 (setq func (let (gnus-pick-mode)
6558 (key-binding keys t)))
6559 (when (get func 'disabled)
6560 (error "Function %s disabled" func))
6561 (if (and func
6562 (functionp func)
6563 (condition-case code
6564 (progn
6565 (call-interactively func)
6567 (error
6568 (setq err code)
6569 nil)))
6570 (progn
6571 (when (eq win (selected-window))
6572 (setq new-sum-point (point)
6573 new-sum-start (window-start win)
6574 new-sum-hscroll (window-hscroll win)))
6575 (when (or (eq in-buffer (current-buffer))
6576 (when (eq obuf (current-buffer))
6577 (set-buffer in-buffer)
6579 (setq selected (gnus-summary-select-article))
6580 (set-buffer obuf)
6581 (unless not-restore-window
6582 (set-window-configuration owin))
6583 (when (and (eq selected 'old)
6584 new-sum-point)
6585 (set-window-start (get-buffer-window (current-buffer))
6587 (set-window-point (get-buffer-window (current-buffer))
6588 (if (article-goto-body)
6589 (1- (point))
6590 (point))))
6591 (when (and (not not-restore-window)
6592 new-sum-point
6593 (window-live-p win)
6594 (with-current-buffer (window-buffer win)
6595 (eq major-mode 'gnus-summary-mode)))
6596 (set-window-point win new-sum-point)
6597 (set-window-start win new-sum-start)
6598 (set-window-hscroll win new-sum-hscroll))))
6599 (set-window-configuration owin)
6600 (if err
6601 (signal (car err) (cdr err))
6602 (ding))))))))
6604 (defun gnus-article-read-summary-send-keys ()
6605 (interactive)
6606 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6607 (gnus-article-read-summary-keys)))
6609 (defun gnus-article-describe-key (key)
6610 "Display documentation of the function invoked by KEY.
6611 KEY is a string or a vector."
6612 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6613 (read-key-sequence "Describe key: "))))
6614 (gnus-article-check-buffer)
6615 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6616 gnus-article-read-summary-send-keys))
6617 (with-current-buffer gnus-article-current-summary
6618 (setq unread-command-events
6619 (if (featurep 'xemacs)
6620 (append key nil)
6621 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6622 (list 'meta (- x 128))
6624 key)))
6625 (let ((cursor-in-echo-area t)
6626 gnus-pick-mode)
6627 (describe-key (read-key-sequence nil t))))
6628 (describe-key key)))
6630 (defun gnus-article-describe-key-briefly (key &optional insert)
6631 "Display documentation of the function invoked by KEY.
6632 KEY is a string or a vector."
6633 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6634 (read-key-sequence "Describe key: "))
6635 current-prefix-arg))
6636 (gnus-article-check-buffer)
6637 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6638 gnus-article-read-summary-send-keys))
6639 (with-current-buffer gnus-article-current-summary
6640 (setq unread-command-events
6641 (if (featurep 'xemacs)
6642 (append key nil)
6643 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6644 (list 'meta (- x 128))
6646 key)))
6647 (let ((cursor-in-echo-area t)
6648 gnus-pick-mode)
6649 (describe-key-briefly (read-key-sequence nil t) insert)))
6650 (describe-key-briefly key insert)))
6652 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6653 (defvar gnus-agent-summary-mode)
6654 (defvar gnus-draft-mode)
6655 (defvar help-xref-stack-item)
6657 (defun gnus-article-describe-bindings (&optional prefix)
6658 "Show a list of all defined keys, and their definitions.
6659 The optional argument PREFIX, if non-nil, should be a key sequence;
6660 then we display only bindings that start with that prefix."
6661 (interactive)
6662 (gnus-article-check-buffer)
6663 (let ((keymap (copy-keymap gnus-article-mode-map))
6664 (map (copy-keymap gnus-article-send-map))
6665 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6666 parent agent draft)
6667 (define-key keymap "S" map)
6668 (define-key map [t] nil)
6669 (with-current-buffer gnus-article-current-summary
6670 (set-keymap-parent
6671 keymap
6672 (if (setq parent (keymap-parent gnus-article-mode-map))
6673 (prog1
6674 (setq parent (copy-keymap parent))
6675 (set-keymap-parent parent (current-local-map)))
6676 (current-local-map)))
6677 (set-keymap-parent map (key-binding "S"))
6678 (let (key def gnus-pick-mode)
6679 (while sumkeys
6680 (setq key (pop sumkeys))
6681 (cond ((and (vectorp key) (= (length key) 1)
6682 (consp (setq def (aref key 0)))
6683 (numberp (car def)) (numberp (cdr def)))
6684 (when (< (max (car def) (cdr def)) 128)
6685 (setq sumkeys
6686 (append (mapcar
6687 #'vector
6688 (nreverse (gnus-uncompress-range def)))
6689 sumkeys))))
6690 ((setq def (key-binding key))
6691 (unless (eq def 'undefined)
6692 (define-key keymap key def))))))
6693 (when (boundp 'gnus-agent-summary-mode)
6694 (setq agent gnus-agent-summary-mode))
6695 (when (boundp 'gnus-draft-mode)
6696 (setq draft gnus-draft-mode)))
6697 (with-temp-buffer
6698 (use-local-map keymap)
6699 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6700 (set (make-local-variable 'gnus-draft-mode) draft)
6701 (describe-bindings prefix))
6702 (let ((item `((lambda (prefix)
6703 (with-current-buffer ,(current-buffer)
6704 (gnus-article-describe-bindings prefix)))
6705 ,prefix)))
6706 ;; Loading `help-mode' here is necessary if `describe-bindings'
6707 ;; is replaced with something, e.g. `helm-descbinds'.
6708 (require 'help-mode)
6709 (with-current-buffer (let (help-xref-following) (help-buffer))
6710 (setq help-xref-stack-item item)))))
6712 (defun gnus-article-reply-with-original (&optional wide)
6713 "Start composing a reply mail to the current message.
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-reply (list (list article)) wide))
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-reply
6729 (list (list article contents)) wide)))))
6731 (defun gnus-article-wide-reply-with-original ()
6732 "Start composing a wide reply mail to the current message.
6733 The text in the region will be yanked. If the region isn't active,
6734 the entire article will be yanked."
6735 (interactive)
6736 (gnus-article-reply-with-original t))
6738 (defun gnus-article-followup-with-original ()
6739 "Compose a followup to the current article.
6740 The text in the region will be yanked. If the region isn't active,
6741 the entire article will be yanked."
6742 (interactive)
6743 (let ((article (cdr gnus-article-current))
6744 contents)
6745 (if (not (gnus-region-active-p))
6746 (with-current-buffer gnus-summary-buffer
6747 (gnus-summary-followup (list (list article))))
6748 (setq contents (buffer-substring (point) (mark t)))
6749 ;; Deactivate active regions.
6750 (when (and (boundp 'transient-mark-mode)
6751 transient-mark-mode)
6752 (setq mark-active nil))
6753 (with-current-buffer gnus-summary-buffer
6754 (gnus-summary-followup
6755 (list (list article contents)))))))
6757 (defun gnus-article-hide (&optional arg force)
6758 "Hide all the gruft in the current article.
6759 This means that signatures, cited text and (some) headers will be
6760 hidden.
6761 If given a prefix, show the hidden text instead."
6762 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6763 (gnus-article-hide-headers arg)
6764 (gnus-article-hide-list-identifiers arg)
6765 (gnus-article-hide-citation-maybe arg force)
6766 (gnus-article-hide-signature arg))
6768 (defun gnus-check-group-server ()
6769 ;; Make sure the connection to the server is alive.
6770 (unless (gnus-server-opened
6771 (gnus-find-method-for-group gnus-newsgroup-name))
6772 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6773 (gnus-request-group gnus-newsgroup-name t)))
6775 (eval-when-compile
6776 (autoload 'nneething-get-file-name "nneething"))
6778 (defun gnus-request-article-this-buffer (article group)
6779 "Get an article and insert it into this buffer."
6780 (let (do-update-line sparse-header)
6781 (prog1
6782 (save-excursion
6783 (erase-buffer)
6784 (gnus-kill-all-overlays)
6785 (setq group (or group gnus-newsgroup-name))
6787 ;; Using `gnus-request-article' directly will insert the article into
6788 ;; `nntp-server-buffer' - so we'll save some time by not having to
6789 ;; copy it from the server buffer into the article buffer.
6791 ;; We only request an article by message-id when we do not have the
6792 ;; headers for it, so we'll have to get those.
6793 (when (stringp article)
6794 (gnus-read-header article))
6796 ;; If the article number is negative, that means that this article
6797 ;; doesn't belong in this newsgroup (possibly), so we find its
6798 ;; message-id and request it by id instead of number.
6799 (when (and (numberp article)
6800 gnus-summary-buffer
6801 (get-buffer gnus-summary-buffer)
6802 (gnus-buffer-exists-p gnus-summary-buffer))
6803 (with-current-buffer gnus-summary-buffer
6804 (let ((header (gnus-summary-article-header article)))
6805 (when (< article 0)
6806 (cond
6807 ((memq article gnus-newsgroup-sparse)
6808 ;; This is a sparse gap article.
6809 (setq do-update-line article)
6810 (setq article (mail-header-id header))
6811 (setq sparse-header (gnus-read-header article))
6812 (setq gnus-newsgroup-sparse
6813 (delq article gnus-newsgroup-sparse)))
6814 ((vectorp header)
6815 ;; It's a real article.
6816 (setq article (mail-header-id header)))
6818 ;; It is an extracted pseudo-article.
6819 (setq article 'pseudo)
6820 (gnus-request-pseudo-article header))))
6822 (let ((method (gnus-find-method-for-group
6823 gnus-newsgroup-name)))
6824 (when (and (eq (car method) 'nneething)
6825 (vectorp header))
6826 (let ((dir (nneething-get-file-name
6827 (mail-header-id header))))
6828 (when (and (stringp dir)
6829 (file-directory-p dir))
6830 (setq article 'nneething)
6831 (gnus-group-enter-directory dir))))))))
6833 (cond
6834 ;; Refuse to select canceled articles.
6835 ((and (numberp article)
6836 gnus-summary-buffer
6837 (get-buffer gnus-summary-buffer)
6838 (gnus-buffer-exists-p gnus-summary-buffer)
6839 (eq (cdr (with-current-buffer gnus-summary-buffer
6840 (assq article gnus-newsgroup-reads)))
6841 gnus-canceled-mark))
6842 nil)
6843 ;; We first check `gnus-original-article-buffer'.
6844 ((and (get-buffer gnus-original-article-buffer)
6845 (numberp article)
6846 (with-current-buffer gnus-original-article-buffer
6847 (and (equal (car gnus-original-article) group)
6848 (eq (cdr gnus-original-article) article))))
6849 ;; `insert-buffer-substring' would incorrectly use the
6850 ;; equivalent of string-make-multibyte which amount to decoding
6851 ;; with locale-coding-system, causing failure of
6852 ;; subsequent decoding.
6853 (insert (mm-string-to-multibyte
6854 (with-current-buffer gnus-original-article-buffer
6855 (buffer-substring (point-min) (point-max)))))
6856 'article)
6857 ;; Check the backlog.
6858 ((and gnus-keep-backlog
6859 (gnus-backlog-request-article group article (current-buffer)))
6860 'article)
6861 ;; Check asynchronous pre-fetch.
6862 ((gnus-async-request-fetched-article group article (current-buffer))
6863 (gnus-async-prefetch-next group article gnus-summary-buffer)
6864 (when (and (numberp article) gnus-keep-backlog)
6865 (gnus-backlog-enter-article group article (current-buffer)))
6866 'article)
6867 ;; Check the cache.
6868 ((and gnus-use-cache
6869 (numberp article)
6870 (gnus-cache-request-article article group))
6871 'article)
6872 ;; Check the agent cache.
6873 ((gnus-agent-request-article article group)
6874 'article)
6875 ;; Get the article and put into the article buffer.
6876 ((or (stringp article)
6877 (numberp article))
6878 (let ((gnus-override-method gnus-override-method)
6879 (methods (and (stringp article)
6880 (with-current-buffer gnus-summary-buffer
6881 (gnus-refer-article-methods))))
6882 (backend (car (gnus-find-method-for-group
6883 gnus-newsgroup-name)))
6884 result
6885 (inhibit-read-only t))
6886 (when (and (null gnus-override-method)
6887 methods)
6888 (setq gnus-override-method (pop methods)))
6889 (while (not result)
6890 (erase-buffer)
6891 (gnus-kill-all-overlays)
6892 (let ((gnus-newsgroup-name group))
6893 (gnus-check-group-server))
6894 (cond
6895 ((gnus-request-article article group (current-buffer))
6896 (when (numberp article)
6897 (gnus-async-prefetch-next group article
6898 gnus-summary-buffer)
6899 (when gnus-keep-backlog
6900 (gnus-backlog-enter-article
6901 group article (current-buffer)))
6902 (when (and gnus-agent
6903 (gnus-agent-group-covered-p group))
6904 (gnus-agent-store-article article group)))
6905 (setq result 'article))
6906 (methods
6907 (setq gnus-override-method (pop methods)))
6908 ((not (string-match "^400 "
6909 (nnheader-get-report backend)))
6910 ;; If we get 400 server disconnect, reconnect and
6911 ;; retry; otherwise, assume the article has expired.
6912 (setq result 'done))))
6913 (and (eq result 'article) 'article)))
6914 ;; It was a pseudo.
6915 (t article)))
6917 ;; Associate this article with the current summary buffer.
6918 (setq gnus-article-current-summary gnus-summary-buffer)
6920 ;; Take the article from the original article buffer
6921 ;; and place it in the buffer it's supposed to be in.
6922 (when (and (get-buffer gnus-article-buffer)
6923 (equal (buffer-name (current-buffer))
6924 (buffer-name (get-buffer gnus-article-buffer))))
6925 (save-excursion
6926 (if (get-buffer gnus-original-article-buffer)
6927 (set-buffer gnus-original-article-buffer)
6928 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6929 (buffer-disable-undo)
6930 (setq major-mode 'gnus-original-article-mode)
6931 (setq buffer-read-only t))
6932 (let ((inhibit-read-only t))
6933 (erase-buffer)
6934 (insert-buffer-substring gnus-article-buffer))
6935 (setq gnus-original-article (cons group article)))
6937 ;; Decode charsets.
6938 (run-hooks 'gnus-article-decode-hook)
6939 ;; Mark article as decoded or not.
6940 (setq gnus-article-decoded-p gnus-article-decode-hook))
6942 ;; Update sparse articles.
6943 (when (and do-update-line
6944 (or (numberp article)
6945 (stringp article)))
6946 (let ((buf (current-buffer)))
6947 (set-buffer gnus-summary-buffer)
6948 (gnus-summary-update-article do-update-line sparse-header)
6949 (gnus-summary-goto-subject do-update-line nil t)
6950 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6951 (point))
6952 (set-buffer buf))))))
6954 (defun gnus-block-private-groups (group)
6955 (if (or (gnus-news-group-p group)
6956 (gnus-member-of-valid 'global group))
6957 ;; Block nothing in news groups.
6959 ;; Block everything anywhere else.
6960 "."))
6962 (defun gnus-blocked-images ()
6963 (if (functionp gnus-blocked-images)
6964 (funcall gnus-blocked-images gnus-newsgroup-name)
6965 gnus-blocked-images))
6968 ;;; Article editing
6971 (defcustom gnus-article-edit-mode-hook nil
6972 "Hook run in article edit mode buffers."
6973 :group 'gnus-article-various
6974 :type 'hook)
6976 (defvar gnus-article-edit-done-function nil)
6978 (defvar gnus-article-edit-mode-map nil)
6980 ;; Should we be using derived.el for this?
6981 (unless gnus-article-edit-mode-map
6982 (setq gnus-article-edit-mode-map (make-keymap))
6983 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6985 (gnus-define-keys gnus-article-edit-mode-map
6986 "\C-c?" describe-mode
6987 "\C-c\C-c" gnus-article-edit-done
6988 "\C-c\C-k" gnus-article-edit-exit
6989 "\C-c\C-f\C-t" message-goto-to
6990 "\C-c\C-f\C-o" message-goto-from
6991 "\C-c\C-f\C-b" message-goto-bcc
6992 ;;"\C-c\C-f\C-w" message-goto-fcc
6993 "\C-c\C-f\C-c" message-goto-cc
6994 "\C-c\C-f\C-s" message-goto-subject
6995 "\C-c\C-f\C-r" message-goto-reply-to
6996 "\C-c\C-f\C-n" message-goto-newsgroups
6997 "\C-c\C-f\C-d" message-goto-distribution
6998 "\C-c\C-f\C-f" message-goto-followup-to
6999 "\C-c\C-f\C-m" message-goto-mail-followup-to
7000 "\C-c\C-f\C-k" message-goto-keywords
7001 "\C-c\C-f\C-u" message-goto-summary
7002 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7003 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7004 "\C-c\C-b" message-goto-body
7005 "\C-c\C-i" message-goto-signature
7007 "\C-c\C-t" message-insert-to
7008 "\C-c\C-n" message-insert-newsgroups
7009 "\C-c\C-o" message-sort-headers
7010 "\C-c\C-e" message-elide-region
7011 "\C-c\C-v" message-delete-not-region
7012 "\C-c\C-z" message-kill-to-signature
7013 "\M-\r" message-newline-and-reformat
7014 "\C-c\C-a" mml-attach-file
7015 "\C-a" message-beginning-of-line
7016 "\t" message-tab
7017 "\M-;" comment-region)
7019 (gnus-define-keys (gnus-article-edit-wash-map
7020 "\C-c\C-w" gnus-article-edit-mode-map)
7021 "f" gnus-article-edit-full-stops))
7023 (easy-menu-define
7024 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7025 '("Field"
7026 ["Fetch To" message-insert-to t]
7027 ["Fetch Newsgroups" message-insert-newsgroups t]
7028 "----"
7029 ["To" message-goto-to t]
7030 ["From" message-goto-from t]
7031 ["Subject" message-goto-subject t]
7032 ["Cc" message-goto-cc t]
7033 ["Reply-To" message-goto-reply-to t]
7034 ["Summary" message-goto-summary t]
7035 ["Keywords" message-goto-keywords t]
7036 ["Newsgroups" message-goto-newsgroups t]
7037 ["Followup-To" message-goto-followup-to t]
7038 ["Mail-Followup-To" message-goto-mail-followup-to t]
7039 ["Distribution" message-goto-distribution t]
7040 ["Body" message-goto-body t]
7041 ["Signature" message-goto-signature t]))
7043 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7044 "Major mode for editing articles.
7045 This is an extended text-mode.
7047 \\{gnus-article-edit-mode-map}"
7048 (make-local-variable 'gnus-article-edit-done-function)
7049 (make-local-variable 'gnus-prev-winconf)
7050 (set (make-local-variable 'font-lock-defaults)
7051 '(message-font-lock-keywords t))
7052 (set (make-local-variable 'mail-header-separator) "")
7053 (set (make-local-variable 'gnus-article-edit-mode) t)
7054 (easy-menu-add message-mode-field-menu message-mode-map)
7055 (mml-mode)
7056 (setq buffer-read-only nil)
7057 (buffer-enable-undo)
7058 (widen))
7060 (defun gnus-article-edit (&optional force)
7061 "Edit the current article.
7062 This will have permanent effect only in mail groups.
7063 If FORCE is non-nil, allow editing of articles even in read-only
7064 groups."
7065 (interactive "P")
7066 (when (and (not force)
7067 (gnus-group-read-only-p))
7068 (error "The current newsgroup does not support article editing"))
7069 (gnus-article-date-original)
7070 (gnus-article-edit-article
7071 'ignore
7072 `(lambda (no-highlight)
7073 'ignore
7074 (gnus-summary-edit-article-done
7075 ,(or (mail-header-references gnus-current-headers) "")
7076 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7078 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7079 "Start editing the contents of the current article buffer."
7080 (let ((winconf (current-window-configuration)))
7081 (set-buffer gnus-article-buffer)
7082 (let ((message-auto-save-directory
7083 ;; Don't associate the article buffer with a draft file.
7084 nil))
7085 (gnus-article-edit-mode))
7086 (funcall start-func)
7087 (set-buffer-modified-p nil)
7088 (gnus-configure-windows 'edit-article)
7089 (setq gnus-article-edit-done-function exit-func)
7090 (setq gnus-prev-winconf winconf)
7091 (unless quiet
7092 (gnus-message 6 "C-c C-c to end edits"))))
7094 (defun gnus-article-edit-done (&optional arg)
7095 "Update the article edits and exit."
7096 (interactive "P")
7097 (let ((func gnus-article-edit-done-function)
7098 (buf (current-buffer))
7099 (start (window-start))
7100 (p (point))
7101 (winconf gnus-prev-winconf))
7102 (widen) ;; Widen it in case that users narrowed the buffer.
7103 (funcall func arg)
7104 (set-buffer buf)
7105 ;; The cache and backlog have to be flushed somewhat.
7106 (when gnus-keep-backlog
7107 (gnus-backlog-remove-article
7108 (car gnus-article-current) (cdr gnus-article-current)))
7109 ;; Flush original article as well.
7110 (gnus-flush-original-article-buffer)
7111 (when gnus-use-cache
7112 (gnus-cache-update-article
7113 (car gnus-article-current) (cdr gnus-article-current)))
7114 ;; We remove all text props from the article buffer.
7115 (kill-all-local-variables)
7116 (set-text-properties (point-min) (point-max) nil)
7117 (gnus-article-mode)
7118 (set-window-configuration winconf)
7119 (set-buffer buf)
7120 (set-window-start (get-buffer-window buf) start)
7121 (set-window-point (get-buffer-window buf) (point)))
7122 (gnus-summary-show-article))
7124 (defun gnus-flush-original-article-buffer ()
7125 (when (get-buffer gnus-original-article-buffer)
7126 (with-current-buffer gnus-original-article-buffer
7127 (setq gnus-original-article nil))))
7129 (defun gnus-article-edit-exit ()
7130 "Exit the article editing without updating."
7131 (interactive)
7132 (when (or (not (buffer-modified-p))
7133 (yes-or-no-p "Article modified; kill anyway? "))
7134 (let ((curbuf (current-buffer))
7135 (p (point))
7136 (window-start (window-start)))
7137 (erase-buffer)
7138 (if (gnus-buffer-live-p gnus-original-article-buffer)
7139 (insert-buffer-substring gnus-original-article-buffer))
7140 (let ((winconf gnus-prev-winconf))
7141 (kill-all-local-variables)
7142 (gnus-article-mode)
7143 (set-window-configuration winconf)
7144 ;; Tippy-toe some to make sure that point remains where it was.
7145 (save-current-buffer
7146 (set-buffer curbuf)
7147 (set-window-start (get-buffer-window (current-buffer)) window-start)
7148 (goto-char p))))
7149 (gnus-summary-show-article)))
7151 (defun gnus-article-edit-full-stops ()
7152 "Interactively repair spacing at end of sentences."
7153 (interactive)
7154 (save-excursion
7155 (goto-char (point-min))
7156 (search-forward-regexp "^$" nil t)
7157 (let ((case-fold-search nil))
7158 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7161 ;;; Article highlights
7164 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7166 ;;; Internal Variables:
7168 (defcustom gnus-button-url-regexp
7169 (concat
7170 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7171 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7172 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7173 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7174 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7175 (punct "!?:;.,"))
7176 (concat
7177 "\\(?:"
7178 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7179 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7180 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7181 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7182 "\\|"
7183 "[" chars punct "]+" "[" chars "]"
7184 "\\)"))
7185 (concat ;; XEmacs 21.4 doesn't support POSIX.
7186 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7187 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7188 "\\)")
7189 "Regular expression that matches URLs."
7190 :version "24.4"
7191 :group 'gnus-article-buttons
7192 :type 'regexp)
7194 (defcustom gnus-button-valid-fqdn-regexp
7195 message-valid-fqdn-regexp
7196 "Regular expression that matches a valid FQDN."
7197 :version "22.1"
7198 :group 'gnus-article-buttons
7199 :type 'regexp)
7201 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7202 (defcustom gnus-button-valid-localpart-regexp
7203 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7204 "Regular expression that matches a localpart of mail addresses or MIDs."
7205 :version "22.1"
7206 :group 'gnus-article-buttons
7207 :type 'regexp)
7209 (defcustom gnus-button-man-handler 'manual-entry
7210 "Function to use for displaying man pages.
7211 The function must take at least one argument with a string naming the
7212 man page."
7213 :version "22.1"
7214 :type '(choice (function-item :tag "Man" manual-entry)
7215 (function-item :tag "Woman" woman)
7216 (function :tag "Other"))
7217 :group 'gnus-article-buttons)
7219 (defcustom gnus-button-mid-or-mail-regexp
7220 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7221 gnus-button-valid-fqdn-regexp
7222 ">?\\)\\b")
7223 "Regular expression that matches a message ID or a mail address."
7224 :version "22.1"
7225 :group 'gnus-article-buttons
7226 :type 'regexp)
7228 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7229 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7230 Strings like this can be either a message ID or a mail address. If it is one
7231 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7232 message ID or a mail address, respectively. If this variable is set to the
7233 symbol `ask', always query the user what do do. If it is a function, this
7234 function will be called with the string as its only argument. The function
7235 must return `mid', `mail', `invalid' or `ask'."
7236 :version "22.1"
7237 :group 'gnus-article-buttons
7238 :type '(choice (function-item :tag "Heuristic function"
7239 gnus-button-mid-or-mail-heuristic)
7240 (const ask)
7241 (const mid)
7242 (const mail)))
7244 (defcustom gnus-button-mid-or-mail-heuristic-alist
7245 '((-10.0 . ".+\\$.+@")
7246 (-10.0 . "#")
7247 (-10.0 . "\\*")
7248 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7249 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7250 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7251 (-1.0 . "^[^a-z]+@")
7253 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7254 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7255 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7256 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7258 (-2.0 . "^[0-9]")
7259 (-1.0 . "^[0-9][0-9]")
7261 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7262 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7263 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7264 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7266 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7267 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7268 ;; "[0-9]{8,}.*\@"
7269 (-3.0
7270 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7271 ;; "[0-9]{12,}.*\@"
7272 ;; compensation for TDMA dated mail addresses:
7273 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7275 (-20.0 . "\\.fsf@") ;; Gnus
7276 (-20.0 . "^slrn")
7277 (-20.0 . "^Pine")
7278 (-20.0 . "^alpine\\.")
7279 (-20.0 . "_-_") ;; Subject change in thread
7281 (-20.0 . "\\.ln@") ;; leafnode
7282 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7283 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7285 ;; (5.0 . "") ;; $local_part_len <= 7
7286 (10.0 . "^[^0-9]+@")
7287 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7288 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7289 (3.0 . "\@stud")
7291 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7293 (0.5 . "^[A-Z][a-z]")
7294 (0.5 . "^[A-Z][a-z][a-z]")
7295 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7296 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7297 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7299 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7300 address. The REGEXP is processed with `case-fold-search' set to nil."
7301 :version "22.1"
7302 :group 'gnus-article-buttons
7303 :type '(repeat (cons (number :tag "Rate")
7304 (regexp :tag "Regexp"))))
7306 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7307 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7308 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7309 address, `ask' if unsure and `invalid' if the string is invalid."
7310 (let ((case-fold-search nil)
7311 (list gnus-button-mid-or-mail-heuristic-alist)
7312 (result 0) rate regexp lpartlen elem)
7313 (setq lpartlen
7314 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7315 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7316 ;; Certain special cases...
7317 (when (string-match
7318 (concat
7319 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7320 "^[0-9]+\\.[0-9]+@compuserve\\|"
7321 "@public\\.gmane\\.org")
7322 mid-or-mail)
7323 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7324 (setq result 'mail))
7325 (when (string-match "@.*@\\| " mid-or-mail)
7326 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7327 (setq result 'invalid))
7328 ;; Nothing more to do, if result is not a number here...
7329 (when (numberp result)
7330 (while list
7331 (setq elem (car list)
7332 rate (car elem)
7333 regexp (cdr elem)
7334 list (cdr list))
7335 (when (string-match regexp mid-or-mail)
7336 (setq result (+ result rate))
7337 (gnus-message
7338 9 "`%s' matched `%s', rate `%s', result `%s'."
7339 mid-or-mail regexp rate result)))
7340 (when (<= lpartlen 7)
7341 (setq result (+ result 5.0))
7342 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7343 mid-or-mail result))
7344 (when (>= lpartlen 12)
7345 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7346 (cond
7347 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7348 ;; Long local part should contain realname if e-mail address,
7349 ;; too many digits: message-id.
7350 ;; $score -= 5.0 + 0.1 * $local_part_len;
7351 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7352 (setq result (+ result rate))
7353 (gnus-message
7354 9 "Many digits in `%s', rate `%s', result `%s'."
7355 mid-or-mail rate result))
7356 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7357 mid-or-mail)
7358 ;; Too few vowels [^aeiouy]{4,}.*\@
7359 (setq result (+ result -5.0))
7360 (gnus-message
7361 9 "Few vowels in `%s', rate `%s', result `%s'."
7362 mid-or-mail -5.0 result))
7364 (setq result (+ result 5.0))
7365 (gnus-message
7366 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7367 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7368 ;; Maybe we should make this a customizable alist: (condition . 'result)
7369 (cond
7370 ((symbolp result) result)
7371 ;; Now convert number into proper results:
7372 ((< result -10.0) 'mid)
7373 ((> result 10.0) 'mail)
7374 (t 'ask))))
7376 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7377 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7378 (url-mid (concat "news" ":" mid-or-mail))
7379 (url-mailto (concat "mailto" ":" mid-or-mail)))
7380 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7381 (when (fboundp pref)
7382 (setq guessed
7383 ;; get rid of surrounding angles...
7384 (funcall pref
7385 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7386 (if (or (eq 'mid guessed) (eq 'mail guessed))
7387 (setq pref guessed)
7388 (setq pref 'ask)))
7389 (if (eq pref 'ask)
7390 (save-window-excursion
7391 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7392 (setq pref 'mail)
7393 (setq pref 'mid))))
7394 (cond ((eq pref 'mid)
7395 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7396 (gnus-button-handle-news url-mid))
7397 ((eq pref 'mail)
7398 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7399 (gnus-url-mailto url-mailto))
7400 (t (gnus-message 3 "Invalid string.")))))
7402 (defun gnus-button-handle-custom (fun arg)
7403 "Call function FUN on argument ARG.
7404 Both FUN and ARG are supposed to be strings. ARG will be passed
7405 as a symbol to FUN."
7406 (funcall (intern fun)
7407 (if (string-match "^customize-apropos" fun)
7409 (intern arg))))
7411 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7413 (defun gnus-button-handle-describe-function (url)
7414 "Call `describe-function' when pushing the corresponding URL button."
7415 (describe-function
7416 (intern
7417 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7419 (defun gnus-button-handle-describe-variable (url)
7420 "Call `describe-variable' when pushing the corresponding URL button."
7421 (describe-variable
7422 (intern
7423 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7425 (defun gnus-button-handle-symbol (url)
7426 "Display help on variable or function.
7427 Calls `describe-variable' or `describe-function'."
7428 (let ((sym (intern url)))
7429 (cond
7430 ((fboundp sym) (describe-function sym))
7431 ((boundp sym) (describe-variable sym))
7432 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7434 (defun gnus-button-handle-describe-key (url)
7435 "Call `describe-key' when pushing the corresponding URL button."
7436 (let* ((key-string
7437 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7438 (keys (ignore-errors (eval `(kbd ,key-string)))))
7439 (if keys
7440 (describe-key keys)
7441 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7443 (defun gnus-button-handle-apropos (url)
7444 "Call `apropos' when pushing the corresponding URL button."
7445 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7447 (defun gnus-button-handle-apropos-command (url)
7448 "Call `apropos' when pushing the corresponding URL button."
7449 (apropos-command
7450 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7452 (defun gnus-button-handle-apropos-variable (url)
7453 "Call `apropos' when pushing the corresponding URL button."
7454 (funcall
7455 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7456 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7458 (defun gnus-button-handle-apropos-documentation (url)
7459 "Call `apropos' when pushing the corresponding URL button."
7460 (funcall
7461 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7462 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7464 (defun gnus-button-handle-library (url)
7465 "Call `locate-library' when pushing the corresponding URL button."
7466 (gnus-message 9 "url=`%s'" url)
7467 (let* ((lib (locate-library url))
7468 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7469 (if (not lib)
7470 (gnus-message 1 "Cannot locale library `%s'." url)
7471 (find-file-read-only file))))
7473 (defcustom gnus-button-man-level 5
7474 "*Integer that says how many man-related buttons Gnus will show.
7475 The higher the number, the more buttons will appear and the more false
7476 positives are possible. Note that you can set this variable local to
7477 specific groups. Setting it higher in Unix groups is probably a good idea.
7478 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7479 how to set variables in specific groups."
7480 :version "22.1"
7481 :group 'gnus-article-buttons
7482 :link '(custom-manual "(gnus)Group Parameters")
7483 :type 'integer)
7485 (defcustom gnus-button-emacs-level 5
7486 "*Integer that says how many emacs-related buttons Gnus will show.
7487 The higher the number, the more buttons will appear and the more false
7488 positives are possible. Note that you can set this variable local to
7489 specific groups. Setting it higher in Emacs or Gnus related groups is
7490 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7491 `gnus-parameters' on how to set variables in specific groups."
7492 :version "22.1"
7493 :group 'gnus-article-buttons
7494 :link '(custom-manual "(gnus)Group Parameters")
7495 :type 'integer)
7497 (defcustom gnus-button-message-level 5
7498 "*Integer that says how many buttons for news or mail messages will appear.
7499 The higher the number, the more buttons will appear and the more false
7500 positives are possible."
7501 ;; mail addresses, MIDs, URLs for news, ...
7502 :version "22.1"
7503 :group 'gnus-article-buttons
7504 :type 'integer)
7506 (defcustom gnus-button-browse-level 5
7507 "*Integer that says how many buttons for browsing will appear.
7508 The higher the number, the more buttons will appear and the more false
7509 positives are possible."
7510 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7511 :version "22.1"
7512 :group 'gnus-article-buttons
7513 :type 'integer)
7515 (defcustom gnus-button-alist
7516 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7517 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7518 ((concat "\\b\\(nntp\\|news\\):\\("
7519 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7520 0 t gnus-button-handle-news 2)
7521 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7522 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7523 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7524 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7525 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7526 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7527 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7528 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7529 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7530 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7531 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7532 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7533 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7534 ;; RFC 2368 (The mailto URL scheme)
7535 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7536 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7537 ("\\bmailto:\\([^ \n\t]+\\)"
7538 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7539 ;; Info Konqueror style <info:/foo/bar baz>.
7540 ;; Must come before " Gnus home-grown style".
7541 ("\\binfo://?\\([^'\">\n\t]+\\)"
7542 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7543 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7544 ("\\binfo://\\([^'\">\n\t ]+\\)"
7545 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7546 ;; Info GNOME style <info:foo#bar_baz>
7547 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7548 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7549 ;; Info KDE style <info:(foo)bar baz>
7550 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7551 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7552 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7553 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7554 ("\\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,]*\\)\\)?"
7555 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7556 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7557 ;; This is custom
7558 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7559 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7560 ;; Emacs help commands
7561 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7562 ;; regexp doesn't match arguments containing ` '.
7563 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7564 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7565 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7566 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7567 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7568 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7569 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7570 ;; The following entries may lead to many false positives so don't enable
7571 ;; them by default (use a high button level).
7572 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7573 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7574 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7575 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7576 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7577 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7578 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7579 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7580 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7581 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7582 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7583 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7584 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7585 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7586 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7587 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7588 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7589 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7590 ;; Unlike the other regexps we really have to require quoting
7591 ;; here to determine where it ends.
7592 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7593 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7594 ("<URL: *\\([^\n<>]*\\)>"
7595 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7596 ;; RFC 2396 (2.4.3., delims) ...
7597 ("\"URL: *\\([^\n\"]*\\)\""
7598 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7599 ;; Raw URLs.
7600 (gnus-button-url-regexp
7601 0 (>= gnus-button-browse-level 0) browse-url 0)
7602 ;; man pages
7603 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7604 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7605 gnus-button-handle-man 1)
7606 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7607 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7608 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7609 gnus-button-handle-man 1)
7610 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7611 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7612 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7613 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7614 ;; Recognizing patches to .el files. This is somewhat obscure,
7615 ;; but considering the percentage of Gnus users who hack Emacs
7616 ;; Lisp files...
7617 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7618 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7619 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7620 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7621 ;; MID or mail: To avoid too many false positives we don't try to catch
7622 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7623 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7624 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7625 ;; so that non-ambiguous entries (see above) match first.
7626 (gnus-button-mid-or-mail-regexp
7627 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7628 "*Alist of regexps matching buttons in article bodies.
7630 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7631 REGEXP: is the string (case insensitive) matching text around the button (can
7632 also be Lisp expression evaluating to a string),
7633 BUTTON: is the number of the regexp grouping actually matching the button,
7634 FORM: is a Lisp expression which must eval to true for the button to
7635 be added,
7636 CALLBACK: is the function to call when the user push this button, and each
7637 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7639 CALLBACK can also be a variable, in that case the value of that
7640 variable it the real callback function."
7641 :group 'gnus-article-buttons
7642 :type '(repeat (list (choice regexp variable sexp)
7643 (integer :tag "Button")
7644 (sexp :tag "Form")
7645 (function :tag "Callback")
7646 (repeat :tag "Par"
7647 :inline t
7648 (integer :tag "Regexp group")))))
7649 (put 'gnus-button-alist 'risky-local-variable t)
7651 (defcustom gnus-header-button-alist
7652 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7653 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7654 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7655 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7656 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7657 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7658 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7659 0 (>= gnus-button-browse-level 0) browse-url 0)
7660 ("^Subject:" gnus-button-url-regexp
7661 0 (>= gnus-button-browse-level 0) browse-url 0)
7662 ("^[^:]+:" gnus-button-url-regexp
7663 0 (>= gnus-button-browse-level 0) browse-url 0)
7664 ("^OpenPGP:.*url=" gnus-button-url-regexp
7665 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7666 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7667 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7668 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7669 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7670 "*Alist of headers and regexps to match buttons in article heads.
7672 This alist is very similar to `gnus-button-alist', except that each
7673 alist has an additional HEADER element first in each entry:
7675 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7677 HEADER is a regexp to match a header. For a fuller explanation, see
7678 `gnus-button-alist'."
7679 :group 'gnus-article-buttons
7680 :group 'gnus-article-headers
7681 :type '(repeat (list (regexp :tag "Header")
7682 (choice regexp variable)
7683 (integer :tag "Button")
7684 (sexp :tag "Form")
7685 (function :tag "Callback")
7686 (repeat :tag "Par"
7687 :inline t
7688 (integer :tag "Regexp group")))))
7689 (put 'gnus-header-button-alist 'risky-local-variable t)
7691 ;;; Commands:
7693 (defun gnus-article-push-button (event)
7694 "Check text under the mouse pointer for a callback function.
7695 If the text under the mouse pointer has a `gnus-callback' property,
7696 call it with the value of the `gnus-data' text property."
7697 (interactive "e")
7698 (set-buffer (window-buffer (posn-window (event-start event))))
7699 (let* ((pos (posn-point (event-start event)))
7700 (data (get-text-property pos 'gnus-data))
7701 (fun (get-text-property pos 'gnus-callback)))
7702 (goto-char pos)
7703 (when fun
7704 (funcall fun data))))
7706 (defun gnus-article-press-button ()
7707 "Check text at point for a callback function.
7708 If the text at point has a `gnus-callback' property,
7709 call it with the value of the `gnus-data' text property."
7710 (interactive)
7711 (let ((data (get-text-property (point) 'gnus-data))
7712 (fun (get-text-property (point) 'gnus-callback)))
7713 (when fun
7714 (funcall fun data))))
7716 (defun gnus-article-highlight (&optional force)
7717 "Highlight current article.
7718 This function calls `gnus-article-highlight-headers',
7719 `gnus-article-highlight-citation',
7720 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7721 do the highlighting. See the documentation for those functions."
7722 (interactive (list 'force))
7723 (gnus-article-highlight-headers)
7724 (gnus-article-highlight-citation force)
7725 (gnus-article-highlight-signature)
7726 (gnus-article-add-buttons)
7727 (gnus-article-add-buttons-to-head))
7729 (defun gnus-article-highlight-some (&optional force)
7730 "Highlight current article.
7731 This function calls `gnus-article-highlight-headers',
7732 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7733 do the highlighting. See the documentation for those functions."
7734 (interactive (list 'force))
7735 (gnus-article-highlight-headers)
7736 (gnus-article-highlight-signature)
7737 (gnus-article-add-buttons))
7739 (defun gnus-article-highlight-headers ()
7740 "Highlight article headers as specified by `gnus-header-face-alist'."
7741 (interactive)
7742 (gnus-with-article-headers
7743 (let (regexp header-face field-face from hpoints fpoints)
7744 (dolist (entry gnus-header-face-alist)
7745 (goto-char (point-min))
7746 (setq regexp (concat "^\\("
7747 (if (string-equal "" (nth 0 entry))
7748 "[^\t ]"
7749 (nth 0 entry))
7750 "\\)")
7751 header-face (nth 1 entry)
7752 field-face (nth 2 entry))
7753 (while (and (re-search-forward regexp nil t)
7754 (not (eobp)))
7755 (beginning-of-line)
7756 (setq from (point))
7757 (unless (search-forward ":" nil t)
7758 (forward-char 1))
7759 (when (and header-face
7760 (not (memq (point) hpoints)))
7761 (push (point) hpoints)
7762 (gnus-put-text-property from (point) 'face header-face))
7763 (when (and field-face
7764 (not (memq (setq from (point)) fpoints)))
7765 (push from fpoints)
7766 (if (re-search-forward "^[^ \t]" nil t)
7767 (forward-char -2)
7768 (goto-char (point-max)))
7769 (gnus-put-text-property from (point) 'face field-face)))))))
7771 (defun gnus-article-highlight-signature ()
7772 "Highlight the signature in an article.
7773 It does this by highlighting everything after
7774 `gnus-signature-separator' using the face `gnus-signature'."
7775 (interactive)
7776 (gnus-with-article-buffer
7777 (let ((inhibit-point-motion-hooks t))
7778 (save-restriction
7779 (when (and gnus-signature-face
7780 (gnus-article-narrow-to-signature))
7781 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7782 'face gnus-signature-face)
7783 (widen)
7784 (gnus-article-search-signature)
7785 (let ((start (match-beginning 0))
7786 (end (set-marker (make-marker) (1+ (match-end 0)))))
7787 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7788 end)))))))
7790 (defun gnus-button-in-region-p (b e prop)
7791 "Say whether PROP exists in the region."
7792 (text-property-not-all b e prop nil))
7794 (defun gnus-article-add-buttons ()
7795 "Find external references in the article and make buttons of them.
7796 \"External references\" are things like Message-IDs and URLs, as
7797 specified by `gnus-button-alist'."
7798 (interactive)
7799 (gnus-with-article-buffer
7800 (let ((inhibit-point-motion-hooks t)
7801 (case-fold-search t)
7802 (alist gnus-button-alist)
7803 beg entry regexp)
7804 ;; We skip the headers.
7805 (article-goto-body)
7806 (setq beg (point))
7807 (while (setq entry (pop alist))
7808 (setq regexp (eval (car entry)))
7809 (goto-char beg)
7810 (while (re-search-forward regexp nil t)
7811 (let ((start (match-beginning (nth 1 entry)))
7812 (end (match-end (nth 1 entry)))
7813 (from (match-beginning 0)))
7814 (when (and (eval (nth 2 entry))
7815 (not (gnus-button-in-region-p
7816 start end 'gnus-callback)))
7817 ;; That optional form returned non-nil, so we add the
7818 ;; button.
7819 (setq from (set-marker (make-marker) from))
7820 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7821 (gnus-article-extend-url-button from start end))
7822 (gnus-article-add-button start end
7823 'gnus-button-push (list from entry))
7824 (gnus-put-text-property
7825 start end
7826 'gnus-string (buffer-substring-no-properties
7827 start end))))))))))
7829 (defun gnus-article-extend-url-button (beg start end)
7830 "Extend url button if url is folded into two or more lines.
7831 Return non-nil if button is extended. BEG is a marker that points to
7832 the beginning position of a text containing url. START and END are
7833 the endpoints of a url button before it is extended. The concatenated
7834 url is put as the `gnus-button-url' overlay property on the button."
7835 (let ((opoint (point))
7836 (points (list start end))
7837 url delim regexp)
7838 (prog1
7839 (when (and (progn
7840 (goto-char end)
7841 (not (looking-at "[\t ]*[\">]")))
7842 (progn
7843 (goto-char start)
7844 (string-match
7845 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7846 (buffer-substring (point-at-bol) start)))
7847 (progn
7848 (setq url (list (buffer-substring start end))
7849 delim (if (match-beginning 1) ">" "\""))
7850 (beginning-of-line)
7851 (setq regexp (concat
7852 (when (and (looking-at
7853 message-cite-prefix-regexp)
7854 (< (match-end 0) start))
7855 (regexp-quote (match-string 0)))
7857 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7858 delim "\\)"))
7859 (while (progn
7860 (forward-line 1)
7861 (and (looking-at regexp)
7862 (prog1
7863 (match-beginning 1)
7864 (push (or (match-string 2)
7865 (match-string 1))
7866 url)
7867 (push (setq end (or (match-end 2)
7868 (match-end 1)))
7869 points)
7870 (push (or (match-beginning 2)
7871 (match-beginning 1))
7872 points)))))
7873 (match-beginning 2)))
7874 (let (gnus-article-mouse-face widget-mouse-face)
7875 (while points
7876 (gnus-article-add-button (pop points) (pop points)
7877 'gnus-button-push
7878 (list beg (assq 'gnus-button-url-regexp
7879 gnus-button-alist)))))
7880 (let ((overlay (gnus-make-overlay start end)))
7881 (gnus-overlay-put overlay 'evaporate t)
7882 (gnus-overlay-put overlay 'gnus-button-url
7883 (list (mapconcat 'identity (nreverse url) "")))
7884 (when gnus-article-mouse-face
7885 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7887 (goto-char opoint))))
7889 ;; Add buttons to the head of an article.
7890 (defun gnus-article-add-buttons-to-head ()
7891 "Add buttons to the head of the article."
7892 (interactive)
7893 (gnus-with-article-headers
7894 (let (beg end)
7895 (dolist (entry gnus-header-button-alist)
7896 ;; Each alist entry.
7897 (goto-char (point-min))
7898 (while (re-search-forward (car entry) nil t)
7899 ;; Each header matching the entry.
7900 (setq beg (match-beginning 0))
7901 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7902 (match-beginning 0))
7903 (point-max)))
7904 (goto-char beg)
7905 (while (re-search-forward (eval (nth 1 entry)) end t)
7906 ;; Each match within a header.
7907 (let* ((entry (cdr entry))
7908 (start (match-beginning (nth 1 entry)))
7909 (end (match-end (nth 1 entry)))
7910 (form (nth 2 entry)))
7911 (goto-char (match-end 0))
7912 (when (eval form)
7913 (gnus-article-add-button
7914 start end (nth 3 entry)
7915 (buffer-substring (match-beginning (nth 4 entry))
7916 (match-end (nth 4 entry)))))))
7917 (goto-char end))))))
7919 ;;; External functions:
7921 (defun gnus-article-add-button (from to fun &optional data text)
7922 "Create a button between FROM and TO with callback FUN and data DATA."
7923 (when gnus-article-button-face
7924 (gnus-overlay-put (gnus-make-overlay from to nil t)
7925 'face gnus-article-button-face))
7926 (gnus-add-text-properties
7927 from to
7928 (nconc (and gnus-article-mouse-face
7929 (list gnus-mouse-face-prop gnus-article-mouse-face))
7930 (list 'gnus-callback fun)
7931 (and data (list 'gnus-data data))))
7932 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7933 :help-echo (or text "Follow the link")
7934 :keymap gnus-url-button-map
7935 :button-keymap gnus-widget-button-keymap))
7937 (defun gnus-article-copy-string ()
7938 "Copy the string in the button to the kill ring."
7939 (interactive)
7940 (gnus-article-check-buffer)
7941 (let ((data (get-text-property (point) 'gnus-string)))
7942 (when data
7943 (with-temp-buffer
7944 (insert data)
7945 (copy-region-as-kill (point-min) (point-max))
7946 (message "Copied %s" data)))))
7948 ;;; Internal functions:
7950 (defun gnus-article-set-globals ()
7951 (with-current-buffer gnus-summary-buffer
7952 (gnus-set-global-variables)))
7954 (defun gnus-signature-toggle (end)
7955 (gnus-with-article-buffer
7956 (let ((inhibit-point-motion-hooks t))
7957 (if (text-property-any end (point-max) 'article-type 'signature)
7958 (progn
7959 (gnus-delete-wash-type 'signature)
7960 (gnus-remove-text-properties-when
7961 'article-type 'signature end (point-max)
7962 (cons 'article-type (cons 'signature
7963 gnus-hidden-properties))))
7964 (gnus-add-wash-type 'signature)
7965 (gnus-add-text-properties-when
7966 'article-type nil end (point-max)
7967 (cons 'article-type (cons 'signature
7968 gnus-hidden-properties)))))
7969 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7970 (gnus-set-mode-line 'article))))
7972 (defun gnus-button-push (marker-and-entry)
7973 ;; Push button starting at MARKER.
7974 (save-excursion
7975 (let* ((marker (car marker-and-entry))
7976 (entry (cadr marker-and-entry))
7977 (regexp (car entry))
7978 (inhibit-point-motion-hooks t))
7979 (goto-char marker)
7980 ;; This is obviously true, or something bad is happening :)
7981 ;; But we need it to have the match-data
7982 (when (looking-at (or (if (symbolp regexp)
7983 (symbol-value regexp)
7984 regexp)))
7985 (let ((fun (nth 3 entry))
7986 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7987 (get-char-property marker 'gnus-button-url))
7988 (mapcar (lambda (group)
7989 (let ((string (match-string group)))
7990 (set-text-properties
7991 0 (length string) nil string)
7992 string))
7993 (nthcdr 4 entry)))))
7995 (cond
7996 ((fboundp fun)
7997 (apply fun args))
7998 ((and (boundp fun)
7999 (fboundp (symbol-value fun)))
8000 (apply (symbol-value fun) args))
8002 (gnus-message 1 "You must define `%S' to use this button"
8003 (cons fun args)))))))))
8005 (defun gnus-parse-news-url (url)
8006 (let (scheme server port group message-id articles)
8007 (with-temp-buffer
8008 (insert url)
8009 (goto-char (point-min))
8010 (when (looking-at "\\([A-Za-z]+\\):")
8011 (setq scheme (match-string 1))
8012 (goto-char (match-end 0)))
8013 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8014 (setq server (match-string 1))
8015 (setq port (if (stringp (match-string 3))
8016 (string-to-number (match-string 3))
8017 (match-string 3)))
8018 (goto-char (match-end 0)))
8020 (cond
8021 ((looking-at "\\(.*@.*\\)")
8022 (setq message-id (match-string 1)))
8023 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8024 (setq group (match-string 1)
8025 articles (split-string (match-string 2) "-")))
8026 ((looking-at "\\([^/]+\\)/?")
8027 (setq group (match-string 1)))
8029 (error "Unknown news URL syntax"))))
8030 (list scheme server port group message-id articles)))
8032 (defun gnus-button-handle-news (url)
8033 "Fetch a news URL."
8034 (destructuring-bind (scheme server port group message-id articles)
8035 (gnus-parse-news-url url)
8036 (cond
8037 (message-id
8038 (with-current-buffer gnus-summary-buffer
8039 (if server
8040 (let ((gnus-refer-article-method
8041 (nconc (list (list 'nntp server))
8042 gnus-refer-article-method))
8043 (nntp-port-number (or port "nntp")))
8044 (gnus-message 7 "Fetching %s with %s"
8045 message-id gnus-refer-article-method)
8046 (gnus-summary-refer-article message-id))
8047 (gnus-summary-refer-article message-id))))
8048 (group
8049 (gnus-button-fetch-group url)))))
8051 (defun gnus-button-patch (library line)
8052 "Visit an Emacs Lisp library LIBRARY on line LINE."
8053 (interactive)
8054 (let ((file (locate-library (file-name-nondirectory library))))
8055 (unless file
8056 (error "Couldn't find library %s" library))
8057 (find-file file)
8058 (goto-char (point-min))
8059 (forward-line (1- (string-to-number line)))))
8061 (defun gnus-button-handle-man (url)
8062 "Fetch a man page."
8063 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8064 (when (eq gnus-button-man-handler 'woman)
8065 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8066 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8067 (funcall gnus-button-man-handler url))
8069 (defun gnus-button-handle-info-url (url)
8070 "Fetch an info URL."
8071 (setq url (mm-subst-char-in-string ?+ ?\ url))
8072 (cond
8073 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8074 (gnus-info-find-node
8075 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8076 "Gnus")
8077 ")" (gnus-url-unhex-string (match-string 2 url)))))
8078 ((string-match "([^)\"]+)[^\"]+" url)
8079 (setq url
8080 (gnus-replace-in-string
8081 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8082 (gnus-info-find-node url))
8083 (t (error "Can't parse %s" url))))
8085 (defun gnus-button-handle-info-url-gnome (url)
8086 "Fetch GNOME style info URL."
8087 (setq url (mm-subst-char-in-string ?_ ?\ url))
8088 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8089 (gnus-info-find-node
8090 (concat "("
8091 (gnus-url-unhex-string
8092 (match-string 1 url))
8094 (or (gnus-url-unhex-string
8095 (match-string 2 url))
8096 "Top")))
8097 (error "Can't parse %s" url)))
8099 (defun gnus-button-handle-info-url-kde (url)
8100 "Fetch KDE style info URL."
8101 (gnus-info-find-node (gnus-url-unhex-string url)))
8103 ;; (info) will autoload info.el
8104 (declare-function Info-menu "info" (menu-item &optional fork))
8105 (declare-function Info-index-next "info" (num))
8107 (defun gnus-button-handle-info-keystrokes (url)
8108 "Call `info' when pushing the corresponding URL button."
8109 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8110 (let (node indx comma)
8111 (if (string-match
8112 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8113 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8114 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8115 "\\(?:[ \t\n,]*\\)\\)?")
8116 url)
8117 (setq node (match-string 2 url)
8118 indx (match-string 3 url))
8119 (error "Can't parse %s" url))
8120 (info)
8121 (Info-directory)
8122 (Info-menu node)
8123 (when (> (length indx) 0)
8124 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8125 "\\([ \t\n,]*\\)")
8126 indx)
8127 (setq comma (match-string 2 indx))
8128 (setq indx (match-string 1 indx))
8129 (Info-index indx)
8130 (when comma
8131 (dotimes (i (with-temp-buffer
8132 (insert comma)
8133 ;; Note: the XEmacs version of `how-many' takes
8134 ;; no optional argument.
8135 (goto-char (point-min))
8136 (how-many ",")))
8137 (Info-index-next 1)))
8138 nil)))
8140 (autoload 'pgg-snarf-keys-region "pgg")
8141 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8142 (declare-function pgg-display-output-buffer "pgg" (start end status))
8144 (defun gnus-button-openpgp (url)
8145 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8146 (with-temp-buffer
8147 (mm-url-insert-file-contents-external url)
8148 (pgg-snarf-keys-region (point-min) (point-max))
8149 (pgg-display-output-buffer nil nil nil)))
8151 (defun gnus-button-message-id (message-id)
8152 "Fetch MESSAGE-ID."
8153 (with-current-buffer gnus-summary-buffer
8154 (gnus-summary-refer-article message-id)))
8156 (defun gnus-button-fetch-group (address &rest ignore)
8157 "Fetch GROUP specified by ADDRESS."
8158 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8159 address)
8160 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8161 ;; for nntp:// and news://
8162 (setq address (match-string 3 address)))
8163 (if (not (string-match "[:/]" address))
8164 ;; This is just a simple group url.
8165 (gnus-group-read-ephemeral-group address gnus-select-method)
8166 (if (not
8167 (string-match
8168 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8169 address))
8170 (error "Can't parse %s" address)
8171 (gnus-group-read-ephemeral-group
8172 (match-string 4 address)
8173 `(nntp ,(match-string 1 address)
8174 (nntp-address ,(match-string 1 address))
8175 (nntp-port-number ,(if (match-end 3)
8176 (match-string 3 address)
8177 "nntp")))
8178 nil nil nil
8179 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8181 (defun gnus-url-parse-query-string (query &optional downcase)
8182 (let (retval pairs cur key val)
8183 (setq pairs (split-string query "&"))
8184 (while pairs
8185 (setq cur (car pairs)
8186 pairs (cdr pairs))
8187 (if (not (string-match "=" cur))
8188 nil ; Grace
8189 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8190 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8191 (if downcase
8192 (setq key (downcase key)))
8193 (setq cur (assoc key retval))
8194 (if cur
8195 (setcdr cur (cons val (cdr cur)))
8196 (setq retval (cons (list key val) retval)))))
8197 retval))
8199 (defun gnus-url-mailto (url)
8200 ;; Send mail to someone
8201 (setq url (replace-regexp-in-string "\n" " " url))
8202 (when (string-match "mailto:/*\\(.*\\)" url)
8203 (setq url (substring url (match-beginning 1) nil)))
8204 (let (to args subject func)
8205 (setq args (gnus-url-parse-query-string
8206 (if (string-match "^\\?" url)
8207 (substring url 1)
8208 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8209 (concat "to=" (match-string 1 url) "&"
8210 (match-string 2 url))
8211 (concat "to=" url))))
8212 subject (cdr-safe (assoc "subject" args)))
8213 (gnus-msg-mail)
8214 (while args
8215 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8216 (if (fboundp func)
8217 (funcall func)
8218 (message-position-on-field (caar args)))
8219 (insert (gnus-replace-in-string
8220 (mapconcat 'identity (reverse (cdar args)) ", ")
8221 "\r\n" "\n" t))
8222 (setq args (cdr args)))
8223 (if subject
8224 (message-goto-body)
8225 (message-goto-subject))))
8227 (defun gnus-button-embedded-url (address)
8228 "Activate ADDRESS with `browse-url'."
8229 (browse-url (gnus-strip-whitespace address)))
8231 ;;; Next/prev buttons in the article buffer.
8233 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8234 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8236 (defvar gnus-prev-page-map
8237 (let ((map (make-sparse-keymap)))
8238 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8239 (define-key map "\r" 'gnus-button-prev-page)
8240 map))
8242 (defvar gnus-next-page-map
8243 (let ((map (make-sparse-keymap)))
8244 (define-key map gnus-mouse-2 'gnus-button-next-page)
8245 (define-key map "\r" 'gnus-button-next-page)
8246 map))
8248 (defun gnus-insert-prev-page-button ()
8249 (let ((b (point)) e
8250 (inhibit-read-only t))
8251 (gnus-eval-format
8252 gnus-prev-page-line-format nil
8253 `(keymap ,gnus-prev-page-map
8254 gnus-prev t
8255 gnus-callback gnus-article-button-prev-page
8256 article-type annotation))
8257 (setq e (if (bolp)
8258 ;; Exclude a newline.
8259 (1- (point))
8260 (point)))
8261 (when gnus-article-button-face
8262 (gnus-overlay-put (gnus-make-overlay b e nil t)
8263 'face gnus-article-button-face))
8264 (widget-convert-button
8265 'link b e
8266 :action 'gnus-button-prev-page
8267 :button-keymap gnus-prev-page-map)))
8269 (defun gnus-button-next-page (&optional args more-args)
8270 "Go to the next page."
8271 (interactive)
8272 (let ((win (selected-window)))
8273 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8274 (gnus-article-next-page)
8275 (select-window win)))
8277 (defun gnus-button-prev-page (&optional args more-args)
8278 "Go to the prev page."
8279 (interactive)
8280 (let ((win (selected-window)))
8281 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8282 (gnus-article-prev-page)
8283 (select-window win)))
8285 (defun gnus-insert-next-page-button ()
8286 (let ((b (point)) e
8287 (inhibit-read-only t))
8288 (gnus-eval-format gnus-next-page-line-format nil
8289 `(keymap ,gnus-next-page-map
8290 gnus-next t
8291 gnus-callback gnus-article-button-next-page
8292 article-type annotation))
8293 (setq e (if (bolp)
8294 ;; Exclude a newline.
8295 (1- (point))
8296 (point)))
8297 (when gnus-article-button-face
8298 (gnus-overlay-put (gnus-make-overlay b e nil t)
8299 'face gnus-article-button-face))
8300 (widget-convert-button
8301 'link b e
8302 :action 'gnus-button-next-page
8303 :button-keymap gnus-next-page-map)))
8305 (defun gnus-article-button-next-page (arg)
8306 "Go to the next page."
8307 (interactive "P")
8308 (let ((win (selected-window)))
8309 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8310 (gnus-article-next-page)
8311 (select-window win)))
8313 (defun gnus-article-button-prev-page (arg)
8314 "Go to the prev page."
8315 (interactive "P")
8316 (let ((win (selected-window)))
8317 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8318 (gnus-article-prev-page)
8319 (select-window win)))
8321 (defvar gnus-decode-header-methods
8322 '(mail-decode-encoded-word-region)
8323 "List of methods used to decode headers.
8325 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8326 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8327 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8328 whose names match REGEXP.
8330 For example:
8331 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8332 mail-decode-encoded-word-region
8333 (\"chinese\" . rfc1843-decode-region))
8336 (defvar gnus-decode-header-methods-cache nil)
8338 (defun gnus-multi-decode-header (start end)
8339 "Apply the functions from `gnus-encoded-word-methods' that match."
8340 (unless (and gnus-decode-header-methods-cache
8341 (eq gnus-newsgroup-name
8342 (car gnus-decode-header-methods-cache)))
8343 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8344 (dolist (x gnus-decode-header-methods)
8345 (if (symbolp x)
8346 (nconc gnus-decode-header-methods-cache (list x))
8347 (if (and gnus-newsgroup-name
8348 (string-match (car x) gnus-newsgroup-name))
8349 (nconc gnus-decode-header-methods-cache
8350 (list (cdr x)))))))
8351 (let ((xlist gnus-decode-header-methods-cache))
8352 (pop xlist)
8353 (save-restriction
8354 (narrow-to-region start end)
8355 (while xlist
8356 (funcall (pop xlist) (point-min) (point-max))))))
8359 ;;; Treatment top-level handling.
8362 (defvar gnus-inhibit-article-treatments nil)
8364 (defun gnus-treat-article (gnus-treat-condition
8365 &optional part-number total-parts gnus-treat-type)
8366 (let ((gnus-treat-length (- (point-max) (point-min)))
8367 (alist gnus-treatment-function-alist)
8368 (article-goto-body-goes-to-point-min-p t)
8369 (treated-type
8370 (or (not gnus-treat-type)
8371 (catch 'found
8372 (let ((list gnus-article-treat-types))
8373 (while list
8374 (when (string-match (pop list) gnus-treat-type)
8375 (throw 'found t)))))))
8376 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8377 val elem)
8378 (gnus-run-hooks 'gnus-part-display-hook)
8379 (dolist (elem alist)
8380 (setq val
8381 (save-excursion
8382 (when (gnus-buffer-live-p gnus-summary-buffer)
8383 (set-buffer gnus-summary-buffer))
8384 (symbol-value (car elem))))
8385 (when (and (or (consp val)
8386 treated-type)
8387 (or (not gnus-inhibit-article-treatments)
8388 (eq gnus-treat-condition 'head))
8389 (gnus-treat-predicate val)
8390 (or (not (get (car elem) 'highlight))
8391 highlightp))
8392 (save-restriction
8393 (funcall (cadr elem)))))))
8395 ;; Dynamic variables.
8396 (defvar part-number)
8397 (defvar total-parts)
8398 (defvar gnus-treat-type)
8399 (defvar gnus-treat-condition)
8400 (defvar gnus-treat-length)
8402 (defun gnus-treat-predicate (val)
8403 (cond
8404 ((null val)
8405 nil)
8406 (gnus-treat-condition
8407 (eq gnus-treat-condition val))
8408 ((and (listp val)
8409 (stringp (car val)))
8410 (apply 'gnus-or (mapcar `(lambda (s)
8411 (string-match s ,(or gnus-newsgroup-name "")))
8412 val)))
8413 ((listp val)
8414 (let ((pred (pop val)))
8415 (cond
8416 ((eq pred 'or)
8417 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8418 ((eq pred 'and)
8419 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8420 ((eq pred 'not)
8421 (not (gnus-treat-predicate (car val))))
8422 ((eq pred 'typep)
8423 (equal (car val) gnus-treat-type))
8424 ((functionp pred)
8425 (funcall pred))
8427 (error "%S is not a valid predicate" pred)))))
8428 ((eq val t)
8430 ((eq val 'head)
8431 nil)
8432 ((eq val 'first)
8433 (eq part-number 1))
8434 ((eq val 'last)
8435 (eq part-number total-parts))
8436 ((numberp val)
8437 (< gnus-treat-length val))
8439 (error "%S is not a valid value" val))))
8441 (defun gnus-article-encrypt-body (protocol &optional n)
8442 "Encrypt the article body."
8443 (interactive
8444 (list
8445 (or gnus-article-encrypt-protocol
8446 (gnus-completing-read "Encrypt protocol"
8447 (mapcar 'car gnus-article-encrypt-protocol-alist)
8449 current-prefix-arg))
8450 ;; User might hit `K E' instead of `K e', so prompt once.
8451 (when (and gnus-article-encrypt-protocol
8452 gnus-novice-user)
8453 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8454 (error "Encrypt aborted")))
8455 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8456 (unless func
8457 (error "Can't find the encrypt protocol %s" protocol))
8458 (if (member gnus-newsgroup-name '("nndraft:delayed"
8459 "nndraft:drafts"
8460 "nndraft:queue"))
8461 (error "Can't encrypt the article in group %s"
8462 gnus-newsgroup-name))
8463 (gnus-summary-iterate n
8464 (with-current-buffer gnus-summary-buffer
8465 (let ((mail-parse-charset gnus-newsgroup-charset)
8466 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8467 (summary-buffer gnus-summary-buffer)
8468 references point)
8469 (gnus-set-global-variables)
8470 (when (gnus-group-read-only-p)
8471 (error "The current newsgroup does not support article encrypt"))
8472 (gnus-summary-show-article t)
8473 (setq references
8474 (or (mail-header-references gnus-current-headers) ""))
8475 (set-buffer gnus-article-buffer)
8476 (let* ((inhibit-read-only t)
8477 (headers
8478 (mapcar (lambda (field)
8479 (and (save-restriction
8480 (message-narrow-to-head)
8481 (goto-char (point-min))
8482 (search-forward field nil t))
8483 (prog2
8484 (message-narrow-to-field)
8485 (buffer-string)
8486 (delete-region (point-min) (point-max))
8487 (widen))))
8488 '("Content-Type:" "Content-Transfer-Encoding:"
8489 "Content-Disposition:"))))
8490 (message-narrow-to-head)
8491 (message-remove-header "MIME-Version")
8492 (goto-char (point-max))
8493 (setq point (point))
8494 (insert (apply 'concat headers))
8495 (widen)
8496 (narrow-to-region point (point-max))
8497 (let ((message-options message-options))
8498 (message-options-set 'message-sender user-mail-address)
8499 (message-options-set 'message-recipients user-mail-address)
8500 (message-options-set 'message-sign-encrypt 'not)
8501 (funcall func))
8502 (goto-char (point-min))
8503 (insert "MIME-Version: 1.0\n")
8504 (widen)
8505 (gnus-summary-edit-article-done
8506 references nil summary-buffer t))
8507 (when gnus-keep-backlog
8508 (gnus-backlog-remove-article
8509 (car gnus-article-current) (cdr gnus-article-current)))
8510 (gnus-flush-original-article-buffer)
8511 (when gnus-use-cache
8512 (gnus-cache-update-article
8513 (car gnus-article-current) (cdr gnus-article-current))))))))
8515 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8516 "The following specs can be used:
8517 %t The security MIME type
8518 %i Additional info
8519 %d Details
8520 %D Details if button is pressed")
8522 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8523 "The following specs can be used:
8524 %t The security MIME type
8525 %i Additional info
8526 %d Details
8527 %D Details if button is pressed")
8529 (defvar gnus-mime-security-button-line-format-alist
8530 '((?t gnus-tmp-type ?s)
8531 (?i gnus-tmp-info ?s)
8532 (?d gnus-tmp-details ?s)
8533 (?D gnus-tmp-pressed-details ?s)))
8535 (defvar gnus-mime-security-button-commands
8536 '((gnus-article-press-button "\r" "Show Detail")
8537 (undefined "v")
8538 (undefined "t")
8539 (undefined "C")
8540 (gnus-mime-security-save-part "o" "Save...")
8541 (undefined "\C-o")
8542 (undefined "r")
8543 (undefined "d")
8544 (undefined "c")
8545 (undefined "i")
8546 (undefined "E")
8547 (undefined "e")
8548 (undefined "p")
8549 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8550 (undefined ".")))
8552 (defvar gnus-mime-security-button-map
8553 (let ((map (make-sparse-keymap)))
8554 (define-key map gnus-mouse-2 'gnus-article-push-button)
8555 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8556 (dolist (c gnus-mime-security-button-commands)
8557 (define-key map (cadr c) (car c)))
8558 map))
8560 (easy-menu-define
8561 gnus-mime-security-button-menu gnus-mime-security-button-map
8562 "Security button menu."
8563 `("Security Part"
8564 ,@(delq nil
8565 (mapcar (lambda (c)
8566 (unless (eq (car c) 'undefined)
8567 (vector (caddr c) (car c) :active t)))
8568 gnus-mime-security-button-commands))))
8570 (defun gnus-mime-security-button-menu (event prefix)
8571 "Construct a context-sensitive menu of security commands."
8572 (interactive "e\nP")
8573 (save-window-excursion
8574 (let ((pos (event-start event)))
8575 (select-window (posn-window pos))
8576 (goto-char (posn-point pos))
8577 (gnus-article-check-buffer)
8578 (popup-menu gnus-mime-security-button-menu nil prefix))))
8580 (defvar gnus-mime-security-details-buffer nil)
8582 (defvar gnus-mime-security-button-pressed nil)
8584 (defvar gnus-mime-security-show-details-inline t
8585 "If non-nil, show details in the article buffer.")
8587 (defun gnus-mime-security-verify-or-decrypt (handle)
8588 (mm-remove-parts (cdr handle))
8589 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8590 point (inhibit-read-only t))
8591 (if region
8592 (goto-char (car region)))
8593 (setq point (point))
8594 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8595 (let* ((mm-verify-option 'known)
8596 (mm-decrypt-option 'known)
8597 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8598 (unless (eq nparts (cdr handle))
8599 (mm-destroy-parts (cdr handle))
8600 (setcdr handle nparts))))
8601 (gnus-mime-display-security handle)
8602 (when region
8603 (delete-region (point) (cdr region))
8604 (set-marker (car region) nil)
8605 (set-marker (cdr region) nil))
8606 (goto-char point)))
8608 (defun gnus-mime-security-show-details (handle)
8609 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8610 (if (not details)
8611 (gnus-message 5 "No details.")
8612 (if gnus-mime-security-show-details-inline
8613 (let ((gnus-mime-security-button-pressed
8614 (not (get-text-property (point) 'gnus-mime-details)))
8615 (gnus-mime-security-button-line-format
8616 (get-text-property (point) 'gnus-line-format))
8617 (inhibit-read-only t))
8618 (forward-char -1)
8619 (while (eq (get-text-property (point) 'gnus-line-format)
8620 gnus-mime-security-button-line-format)
8621 (forward-char -1))
8622 (forward-char)
8623 (save-restriction
8624 (narrow-to-region (point) (point))
8625 (gnus-insert-mime-security-button handle))
8626 (delete-region (point)
8627 (or (text-property-not-all
8628 (point) (point-max)
8629 'gnus-line-format
8630 gnus-mime-security-button-line-format)
8631 (point-max))))
8632 ;; Not inlined.
8633 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8634 (with-current-buffer gnus-mime-security-details-buffer
8635 (erase-buffer)
8637 (setq gnus-mime-security-details-buffer
8638 (gnus-get-buffer-create "*MIME Security Details*")))
8639 (with-current-buffer gnus-mime-security-details-buffer
8640 (insert details)
8641 (goto-char (point-min)))
8642 (pop-to-buffer gnus-mime-security-details-buffer)))))
8644 (defun gnus-mime-security-press-button (handle)
8645 (save-excursion
8646 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8647 (gnus-mime-security-show-details handle)
8648 (gnus-mime-security-verify-or-decrypt handle))))
8650 (defun gnus-insert-mime-security-button (handle &optional displayed)
8651 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8652 (gnus-tmp-type
8653 (concat
8654 (or (nth 2 (assoc protocol mm-verify-function-alist))
8655 (nth 2 (assoc protocol mm-decrypt-function-alist))
8656 "Unknown")
8657 (if (equal (car handle) "multipart/signed")
8658 " Signed" " Encrypted")
8659 " Part"))
8660 (gnus-tmp-info
8661 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8662 "Undecided"))
8663 (gnus-tmp-details
8664 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8665 gnus-tmp-pressed-details
8666 b e)
8667 (setq gnus-tmp-details
8668 (if gnus-tmp-details
8669 (concat "\n" gnus-tmp-details)
8670 ""))
8671 (setq gnus-tmp-pressed-details
8672 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8673 (unless (bolp)
8674 (insert "\n"))
8675 (setq b (point))
8676 (gnus-eval-format
8677 gnus-mime-security-button-line-format
8678 gnus-mime-security-button-line-format-alist
8679 `(keymap ,gnus-mime-security-button-map
8680 gnus-callback gnus-mime-security-press-button
8681 gnus-line-format ,gnus-mime-security-button-line-format
8682 gnus-mime-details ,gnus-mime-security-button-pressed
8683 article-type annotation
8684 gnus-data ,handle))
8685 (setq e (if (bolp)
8686 ;; Exclude a newline.
8687 (1- (point))
8688 (point)))
8689 (when gnus-article-button-face
8690 (gnus-overlay-put (gnus-make-overlay b e nil t)
8691 'face gnus-article-button-face))
8692 (widget-convert-button
8693 'link b e
8694 :mime-handle handle
8695 :action 'gnus-widget-press-button
8696 :button-keymap gnus-mime-security-button-map
8697 :help-echo
8698 (lambda (widget)
8699 ;; Needed to properly clear the message due to a bug in
8700 ;; wid-edit (XEmacs only).
8701 (when (boundp 'help-echo-owns-message)
8702 (setq help-echo-owns-message t))
8703 (format
8704 "%S: show detail; %S: more options"
8705 (aref gnus-mouse-2 0)
8706 (aref gnus-down-mouse-3 0))))))
8708 (defun gnus-mime-display-security (handle)
8709 (save-restriction
8710 (narrow-to-region (point) (point))
8711 (unless (gnus-unbuttonized-mime-type-p (car handle))
8712 (gnus-insert-mime-security-button handle))
8713 (gnus-mime-display-part (cadr handle))
8714 (unless (bolp)
8715 (insert "\n"))
8716 (unless (gnus-unbuttonized-mime-type-p (car handle))
8717 (let ((gnus-mime-security-button-line-format
8718 gnus-mime-security-button-end-line-format))
8719 (gnus-insert-mime-security-button handle)))
8720 (mm-set-handle-multipart-parameter
8721 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8722 (goto-char (point-max))))
8724 (defun gnus-mime-security-run-function (function)
8725 "Run FUNCTION with the security part under point."
8726 (gnus-article-check-buffer)
8727 (let ((data (get-text-property (point) 'gnus-data))
8728 buffer handle)
8729 (when (and (stringp (car-safe data))
8730 (setq buffer (mm-handle-multipart-original-buffer data))
8731 (setq handle (cadr data)))
8732 (if (bufferp (mm-handle-buffer handle))
8733 (progn
8734 (setq handle (cons buffer (copy-sequence (cdr handle))))
8735 (mm-handle-set-undisplayer handle nil))
8736 (setq handle (mm-make-handle
8737 buffer
8738 (mm-handle-multipart-ctl-parameter handle 'protocol)
8739 nil nil nil nil nil nil)))
8740 (funcall function handle))))
8742 (defun gnus-mime-security-save-part ()
8743 "Save the security part under point."
8744 (interactive)
8745 (gnus-mime-security-run-function 'mm-save-part))
8747 (defun gnus-mime-security-pipe-part ()
8748 "Pipe the security part under point to a process."
8749 (interactive)
8750 (gnus-mime-security-run-function 'mm-pipe-part))
8752 (gnus-ems-redefine)
8754 (provide 'gnus-art)
8756 (run-hooks 'gnus-art-load-hook)
8758 ;;; gnus-art.el ends here