lisp/gnus/gnus-art.el (gnus-mime-inline-part, gnus-mm-display-part): Fix last change
[emacs/old-mirror.git] / lisp / gnus / gnus-art.el
blobc9ceb2eeef53c396495f085130d160d4d70d5502
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2014 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 (eval-when-compile
28 (require 'cl))
29 (defvar tool-bar-map)
30 (defvar w3m-minor-mode-map)
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-spec)
35 (require 'gnus-int)
36 (require 'gnus-win)
37 (require 'mm-bodies)
38 (require 'mail-parse)
39 (require 'mm-decode)
40 (require 'mm-view)
41 (require 'wid-edit)
42 (require 'mm-uu)
43 (require 'message)
44 (require 'mouse)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
116 (mapcar
117 (lambda (header)
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
157 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
158 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
159 "Envelope-Sender" "Envelope-Recipients"))
160 "*All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice regexp
164 (repeat regexp))
165 :group 'gnus-article-hiding)
167 (defcustom gnus-visible-headers
168 "^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:"
169 "*All headers that do not match this regexp will be hidden.
170 This variable can also be a list of regexp of headers to remain visible.
171 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
172 :type '(choice
173 (repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
176 (or (stringp value)
177 (widget-editable-list-match widget value)))
178 regexp)
179 (const :tag "Use gnus-ignored-headers" nil)
180 regexp)
181 :group 'gnus-article-hiding)
183 (defcustom gnus-sorted-header-list
184 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
185 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
186 "*This variable is a list of regular expressions.
187 If it is non-nil, headers that match the regular expressions will
188 be placed first in the article buffer in the sequence specified by
189 this list."
190 :type '(repeat regexp)
191 :group 'gnus-article-hiding)
193 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
194 "Headers that are only to be displayed if they have interesting data.
195 Possible values in this list are:
197 'empty Headers with no content.
198 'newsgroups Newsgroup identical to Gnus group.
199 'to-address To identical to To-address.
200 'to-list To identical to To-list.
201 'cc-list CC identical to To-list.
202 'followup-to Followup-to identical to Newsgroups.
203 'reply-to Reply-to identical to From.
204 'date Date less than four days old.
205 'long-to To and/or Cc longer than 1024 characters.
206 'many-to Multiple To and/or Cc."
207 :type '(set (const :tag "Headers with no content." empty)
208 (const :tag "Newsgroups identical to Gnus group." newsgroups)
209 (const :tag "To identical to To-address." to-address)
210 (const :tag "To identical to To-list." to-list)
211 (const :tag "CC identical to To-list." cc-list)
212 (const :tag "Followup-to identical to Newsgroups." followup-to)
213 (const :tag "Reply-to identical to From." reply-to)
214 (const :tag "Date less than four days old." date)
215 (const :tag "To and/or Cc longer than 1024 characters." long-to)
216 (const :tag "Multiple To and/or Cc headers." many-to))
217 :group 'gnus-article-hiding)
219 (defcustom gnus-article-skip-boring nil
220 "Skip over text that is not worth reading.
221 By default, if you set this t, then Gnus will display citations and
222 signatures, but will never scroll down to show you a page consisting
223 only of boring text. Boring text is controlled by
224 `gnus-article-boring-faces'."
225 :version "22.1"
226 :type 'boolean
227 :group 'gnus-article-hiding)
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (regexp)
236 (repeat :tag "List of regexp" regexp))
237 :group 'gnus-article-signature)
239 (defcustom gnus-signature-limit nil
240 "Provide a limit to what is considered a signature.
241 If it is a number, no signature may not be longer (in characters) than
242 that number. If it is a floating point number, no signature may be
243 longer (in lines) than that number. If it is a function, the function
244 will be called without any parameters, and if it returns nil, there is
245 no signature in the buffer. If it is a string, it will be used as a
246 regexp. If it matches, the text in question is not a signature.
248 This can also be a list of the above values."
249 :type '(choice (const nil)
250 (integer :value 200)
251 (number :value 4.0)
252 function
253 (regexp :value ".*"))
254 :group 'gnus-article-signature)
256 (defcustom gnus-hidden-properties '(invisible t intangible t)
257 "Property list to use for hiding text."
258 :type 'sexp
259 :group 'gnus-article-hiding)
261 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
262 ;; frames in a session.
263 (defcustom gnus-article-x-face-command
264 (if (featurep 'xemacs)
265 (if (or (gnus-image-type-available-p 'xface)
266 (gnus-image-type-available-p 'pbm))
267 'gnus-display-x-face-in-from
268 "{ echo \
269 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
270 ; uncompface; } | icontopbm | ee -")
271 (if (gnus-image-type-available-p 'pbm)
272 'gnus-display-x-face-in-from
273 "{ echo \
274 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
275 ; uncompface; } | icontopbm | display -"))
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
281 function)
282 :version "21.1"
283 :group 'gnus-picon
284 :group 'gnus-article-washing)
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
293 For example,
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
295 :version "21.1"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
299 (gnus-define-group-parameter
300 banner
301 :variable-document
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
304 :parameter-type
305 '(choice :tag "Banner"
306 :value nil
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
309 regexp
310 (const :tag "None" nil))
311 :parameter-document
312 "If non-nil, specify how to remove `banners' from articles.
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
318 directly.")
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330 :type '(repeat
331 (cons
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
336 regexp
337 (const :tag "None" nil))))
338 :version "22.1"
339 :group 'gnus-article-washing)
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
342 `(let ((format "\
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345 ,@body))
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
352 (if (nth 1 value) 2 3)
353 (nth 2 value))
354 value)))
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
361 "\\'"))
362 pattern)
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
365 (= (nth 2 value) 2)
366 (nth 3 value))
367 value))))
369 (defcustom gnus-emphasis-alist
370 (let ((types
371 '(("\\*" "\\*" bold nil 2)
372 ("_" "_" underline)
373 ("/" "/" italic)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
378 (nconc
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
382 (or (nth 3 spec) 2)
383 (or (nth 4 spec) 3)
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
385 types))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
404 :type
405 '(repeat
406 (menu-choice
407 :format "%[Customizing Style%]\n%v"
408 :indent 2
409 (group :tag "Default"
410 :value ("" 0 0 default)
411 :value-create
412 (lambda (widget)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
415 :args))
416 :value)))
417 (if (not (eq (nth 2 value) 'default))
418 (widget-put
419 widget
420 :value
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
423 regexp
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
426 face)
427 (group :tag "Simple"
428 :value (("_" . "_") nil default)
429 (cons :format "%v"
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
434 face)))
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
440 value)))
441 :group 'gnus-article-emphasis)
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
448 :version "21.1"
449 :group 'gnus-article-emphasis
450 :type 'regexp)
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
508 might have."
509 :group 'gnus-article-saving
510 :type 'boolean)
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
534 :type 'regexp)
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favorite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
542 Gnus provides the following functions:
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
554 The symbol of each function may have the following properties:
556 * :decode
557 The value non-nil means save decoded articles. This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
562 * :function
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
569 * :headers
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function-item gnus-summary-save-in-pipe)
584 (function)))
586 (defcustom gnus-article-save-coding-system
587 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591 "Coding system used to save decoded articles to a file.
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text. This is used by the
595 commands including:
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
602 and the functions to which you may set `gnus-default-article-saver':
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil. Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613 :group 'gnus-article-saving
614 :type `(choice
615 :format "%{%t%}:\n %[Value Menu%] %v"
616 (const :tag "Save raw articles" nil)
617 ,@(delq nil
618 (mapcar
619 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620 '((const :tag "UTF-8" utf-8)
621 (const :tag "iso-2022-7bit" iso-2022-7bit)
622 (const :tag "Emacs internal" emacs-mule)
623 (const :tag "escape-quoted" escape-quoted))))
624 (symbol :tag "Coding system")))
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
630 :type 'function)
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
647 LAST-FILE."
648 :group 'gnus-article-saving
649 :type 'function)
651 (defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
654 "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
664 non-nil.
666 If the match is a string, it is used as a regexp match on the
667 article. If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter. If it is a list, it will be evalled in the same buffer.
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674 :group 'gnus-article-saving
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
677 (sexp :value nil))))
679 (defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
683 :type 'regexp
684 :group 'gnus-article-various)
686 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
687 "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
690 The following additional specs are available:
692 %w The article washing status.
693 %m The number of MIME parts in the article."
694 :version "24.1"
695 :type 'string
696 :group 'gnus-article-various)
698 (defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
700 :type 'hook
701 :group 'gnus-article-various)
703 (when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
710 (defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "*A hook called after an article has been prepared in the article buffer."
717 :type 'hook
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
730 (defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748 :type 'face
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
759 '((t
760 (:italic t)))
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
769 '((((class color)
770 (background dark))
771 (:foreground "PaleGreen1"))
772 (((class color)
773 (background light))
774 (:foreground "red3"))
776 (:italic t)))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
785 '((((class color)
786 (background dark))
787 (:foreground "SeaGreen1"))
788 (((class color)
789 (background light))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
801 '((((class color)
802 (background dark))
803 (:foreground "yellow" :italic t))
804 (((class color)
805 (background light))
806 (:foreground "MidnightBlue" :italic t))
808 (:italic t)))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen2"))
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
826 (:bold t)))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
835 '((((class color)
836 (background dark))
837 (:foreground "SpringGreen1" :italic t))
838 (((class color)
839 (background light))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "*Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
878 (png . nil)))
879 "Alist of image types and properties applied to Face and X-Face images.
880 Here are examples:
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs. Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896 :version "23.1" ;; No Gnus
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
900 (defcustom gnus-article-decode-hook
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
905 :type 'hook)
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
910 :type 'function)
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
918 (defvar gnus-article-dumbquotes-map
919 '((?\200 "EUR")
920 (?\202 ",")
921 (?\203 "f")
922 (?\204 ",,")
923 (?\205 "...")
924 (?\213 "<")
925 (?\214 "OE")
926 (?\221 "`")
927 (?\222 "'")
928 (?\223 "``")
929 (?\224 "\"")
930 (?\225 "*")
931 (?\226 "-")
932 (?\227 "--")
933 (?\230 "~")
934 (?\231 "(TM)")
935 (?\233 ">")
936 (?\234 "oe")
937 (?\264 "'"))
938 "Table for MS-to-Latin1 translation.")
940 (defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
942 :version "21.1"
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947 "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :version "21.1"
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
954 (defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include. See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962 :version "22.1"
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
971 :version "22.1"
972 :group 'gnus-article-mime
973 :type 'boolean)
975 (defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
979 :version "22.1"
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
982 string))
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "/usr/share/picons")
986 "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
989 :version "22.1"
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
994 :group 'gnus-picon)
996 (defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1002 installed))
1004 (defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
1009 :type '(choice (const nil)
1010 function))
1012 (defcustom gnus-mime-multipart-functions nil
1013 "An alist of MIME types to functions to display them."
1014 :version "21.1"
1015 :group 'gnus-article-mime
1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1018 (defcustom gnus-article-date-headers '(combined-lapsed)
1019 "A list of Date header formats to display.
1020 Valid formats are `ut' (universal time), `local' (local time
1021 zone), `english' (readable English), `lapsed' (elapsed time),
1022 `combined-lapsed' (both the original date and the elapsed time),
1023 `original' (the original date header), `iso8601' (ISO8601
1024 format), and `user-defined' (a user-defined format defined by the
1025 `gnus-article-time-format' variable).
1027 You have as many date headers as you want in the article buffer.
1028 Some of these headers are updated automatically. See
1029 `gnus-article-update-date-headers' for details."
1030 :version "24.1"
1031 :group 'gnus-article-headers
1032 :type '(set
1033 (const :tag "Universal time (UT)" ut)
1034 (const :tag "Local time zone" local)
1035 (const :tag "Readable English" english)
1036 (const :tag "Elapsed time" lapsed)
1037 (const :tag "Original and elapsed time" combined-lapsed)
1038 (const :tag "Original date header" original)
1039 (const :tag "ISO8601 format" iso8601)
1040 (const :tag "User-defined" user-defined)))
1042 (defcustom gnus-article-update-date-headers nil
1043 "A number that says how often to update the date header (in seconds).
1044 If nil, don't update it at all."
1045 :version "24.1"
1046 :group 'gnus-article-headers
1047 :type '(choice
1048 (item :tag "Don't update" :value nil)
1049 integer))
1051 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1052 "Function called with a MIME handle as the argument.
1053 This is meant for people who want to view first matched part.
1054 For `undisplayed-alternative' (default), the first undisplayed
1055 part or alternative part is used. For `undisplayed', the first
1056 undisplayed part is used. For a function, the first part which
1057 the function return t is used. For nil, the first part is
1058 used."
1059 :version "21.1"
1060 :group 'gnus-article-mime
1061 :type '(choice
1062 (item :tag "first" :value nil)
1063 (item :tag "undisplayed" :value undisplayed)
1064 (item :tag "undisplayed or alternative"
1065 :value undisplayed-alternative)
1066 (function)))
1068 (defcustom gnus-mime-action-alist
1069 '(("save to file" . gnus-mime-save-part)
1070 ("save and strip" . gnus-mime-save-part-and-strip)
1071 ("replace with file" . gnus-mime-replace-part)
1072 ("delete part" . gnus-mime-delete-part)
1073 ("display as text" . gnus-mime-inline-part)
1074 ("view the part" . gnus-mime-view-part)
1075 ("pipe to command" . gnus-mime-pipe-part)
1076 ("toggle display" . gnus-article-press-button)
1077 ("toggle display" . gnus-article-view-part-as-charset)
1078 ("view as type" . gnus-mime-view-part-as-type)
1079 ("view internally" . gnus-mime-view-part-internally)
1080 ("view externally" . gnus-mime-view-part-externally))
1081 "An alist of actions that run on the MIME attachment."
1082 :group 'gnus-article-mime
1083 :type '(repeat (cons (string :tag "name")
1084 (function))))
1086 (defcustom gnus-auto-select-part 1
1087 "Advance to next MIME part when deleting or stripping parts.
1089 When 0, point will be placed on the same part as before. When
1090 positive (negative), move point forward (backwards) this many
1091 parts. When nil, redisplay article."
1092 :version "23.1" ;; No Gnus
1093 :group 'gnus-article-mime
1094 :type '(choice (const nil :tag "Redisplay article.")
1095 (const 1 :tag "Next part.")
1096 (const 0 :tag "Current part.")
1097 integer))
1100 ;;; The treatment variables
1103 (defvar gnus-part-display-hook nil
1104 "Hook called on parts that are to receive treatment.")
1106 (defvar gnus-article-treat-custom
1107 '(choice (const :tag "Off" nil)
1108 (const :tag "On" t)
1109 (const :tag "Header" head)
1110 (const :tag "First" first)
1111 (const :tag "Last" last)
1112 (integer :tag "Less")
1113 (repeat :tag "Groups" regexp)
1114 (sexp :tag "Predicate")))
1116 (defvar gnus-article-treat-head-custom
1117 '(choice (const :tag "Off" nil)
1118 (const :tag "Header" head)))
1120 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1121 "text/x-patch" "text/html")
1122 "Part types eligible for treatment.")
1124 (defvar gnus-inhibit-treatment nil
1125 "Whether to inhibit treatment.")
1127 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1128 "Highlight the signature.
1129 Valid values are nil, t, `head', `first', `last', an integer or a
1130 predicate. See Info node `(gnus)Customizing Articles'."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-custom)
1134 (put 'gnus-treat-highlight-signature 'highlight t)
1136 (defcustom gnus-treat-buttonize 100000
1137 "Add buttons.
1138 Valid values are nil, t, `head', `first', `last', an integer or a
1139 predicate. See Info node `(gnus)Customizing Articles'."
1140 :group 'gnus-article-treat
1141 :link '(custom-manual "(gnus)Customizing Articles")
1142 :type gnus-article-treat-custom)
1143 (put 'gnus-treat-buttonize 'highlight t)
1145 (defcustom gnus-treat-buttonize-head 'head
1146 "Add buttons to the head.
1147 Valid values are nil, t, `head', `first', `last', an integer or a
1148 predicate. See Info node `(gnus)Customizing Articles'."
1149 :group 'gnus-article-treat
1150 :link '(custom-manual "(gnus)Customizing Articles")
1151 :type gnus-article-treat-head-custom)
1152 (put 'gnus-treat-buttonize-head 'highlight t)
1154 (defcustom gnus-treat-date 'head
1155 "Display dates according to the `gnus-article-date-headers' variable.
1156 Valid values are nil, t, `head', `first', `last', an integer or a
1157 predicate. See Info node `(gnus)Customizing Articles'."
1158 :version "24.1"
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-head-custom)
1163 (defcustom gnus-treat-emphasize 50000
1164 "Emphasize text.
1165 Valid values are nil, t, `head', `first', `last', an integer or a
1166 predicate. See Info node `(gnus)Customizing Articles'."
1167 :group 'gnus-article-treat
1168 :link '(custom-manual "(gnus)Customizing Articles")
1169 :type gnus-article-treat-custom)
1170 (put 'gnus-treat-emphasize 'highlight t)
1172 (defcustom gnus-treat-strip-cr nil
1173 "Remove carriage returns.
1174 Valid values are nil, t, `head', `first', `last', an integer or a
1175 predicate. See Info node `(gnus)Customizing Articles'."
1176 :version "22.1"
1177 :group 'gnus-article-treat
1178 :link '(custom-manual "(gnus)Customizing Articles")
1179 :type gnus-article-treat-custom)
1181 (defcustom gnus-treat-unsplit-urls nil
1182 "Remove newlines from within URLs.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate. See Info node `(gnus)Customizing Articles'."
1185 :version "22.1"
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-leading-whitespace nil
1191 "Remove leading whitespace in headers.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :version "22.1"
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-hide-headers 'head
1200 "Hide headers.
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1207 (defcustom gnus-treat-hide-boring-headers nil
1208 "Hide boring headers.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-head-custom)
1215 (defcustom gnus-treat-hide-signature nil
1216 "Hide the signature.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1223 (defcustom gnus-treat-fill-article nil
1224 "Fill the article.
1225 Valid values are nil, t, `head', `first', `last', an integer or a
1226 predicate. See Info node `(gnus)Customizing Articles'."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (defcustom gnus-treat-hide-citation nil
1232 "Hide cited text.
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'.
1236 See `gnus-article-highlight-citation' for variables used to
1237 control what it hides."
1238 :group 'gnus-article-treat
1239 :link '(custom-manual "(gnus)Customizing Articles")
1240 :type gnus-article-treat-custom)
1242 (defcustom gnus-treat-hide-citation-maybe nil
1243 "Hide cited text according to certain conditions.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate. See Info node `(gnus)Customizing Articles'.
1247 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1248 how to control what it hides."
1249 :group 'gnus-article-treat
1250 :link '(custom-manual "(gnus)Customizing Articles")
1251 :type gnus-article-treat-custom)
1253 (defcustom gnus-treat-strip-list-identifiers 'head
1254 "Strip list identifiers from `gnus-list-identifiers`.
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :version "21.1"
1258 :group 'gnus-article-treat
1259 :link '(custom-manual "(gnus)Customizing Articles")
1260 :type gnus-article-treat-custom)
1262 (gnus-define-group-parameter
1263 list-identifier
1264 :variable-document
1265 "Alist of regexps and correspondent identifiers."
1266 :variable-group gnus-article-washing
1267 :parameter-type
1268 '(choice :tag "Identifier"
1269 :value nil
1270 (symbol :tag "Item in `gnus-list-identifiers'" none)
1271 regexp
1272 (const :tag "None" nil))
1273 :parameter-document
1274 "If non-nil, specify how to remove `identifiers' from articles' subject.
1276 Any symbol is used to look up a regular expression to match the
1277 banner in `gnus-list-identifiers'. A string is used as a regular
1278 expression to match the identifier directly.")
1280 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1281 "Gnus 5.10 (Emacs 22.1)")
1283 (defcustom gnus-treat-strip-pem nil
1284 "Strip PEM signatures.
1285 Valid values are nil, t, `head', `first', `last', an integer or a
1286 predicate. See Info node `(gnus)Customizing Articles'."
1287 :group 'gnus-article-treat
1288 :link '(custom-manual "(gnus)Customizing Articles")
1289 :type gnus-article-treat-custom)
1291 (defcustom gnus-treat-strip-banner t
1292 "Strip banners from articles.
1293 The banner to be stripped is specified in the `banner' group parameter.
1294 Valid values are nil, t, `head', `first', `last', an integer or a
1295 predicate. See Info node `(gnus)Customizing Articles'."
1296 :group 'gnus-article-treat
1297 :link '(custom-manual "(gnus)Customizing Articles")
1298 :type gnus-article-treat-custom)
1300 (defcustom gnus-treat-highlight-headers 'head
1301 "Highlight the headers.
1302 Valid values are nil, t, `head', `first', `last', an integer or a
1303 predicate. See Info node `(gnus)Customizing Articles'."
1304 :group 'gnus-article-treat
1305 :link '(custom-manual "(gnus)Customizing Articles")
1306 :type gnus-article-treat-head-custom)
1307 (put 'gnus-treat-highlight-headers 'highlight t)
1309 (defcustom gnus-treat-highlight-citation t
1310 "Highlight cited text.
1311 Valid values are nil, t, `head', `first', `last', an integer or a
1312 predicate. See Info node `(gnus)Customizing Articles'."
1313 :group 'gnus-article-treat
1314 :link '(custom-manual "(gnus)Customizing Articles")
1315 :type gnus-article-treat-custom)
1316 (put 'gnus-treat-highlight-citation 'highlight t)
1318 (defcustom gnus-treat-strip-headers-in-body t
1319 "Strip the X-No-Archive header line from the beginning of the body.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'."
1322 :version "21.1"
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-custom)
1327 (defcustom gnus-treat-strip-trailing-blank-lines nil
1328 "Strip trailing blank lines.
1329 Valid values are nil, t, `head', `first', `last', an integer or a
1330 predicate. See Info node `(gnus)Customizing Articles'.
1332 When set to t, it also strips trailing blanks in all MIME parts.
1333 Consider to use `last' instead."
1334 :group 'gnus-article-treat
1335 :link '(custom-manual "(gnus)Customizing Articles")
1336 :type gnus-article-treat-custom)
1338 (defcustom gnus-treat-strip-leading-blank-lines nil
1339 "Strip leading blank lines.
1340 Valid values are nil, t, `head', `first', `last', an integer or a
1341 predicate. See Info node `(gnus)Customizing Articles'.
1343 When set to t, it also strips trailing blanks in all MIME parts."
1344 :group 'gnus-article-treat
1345 :link '(custom-manual "(gnus)Customizing Articles")
1346 :type gnus-article-treat-custom)
1348 (defcustom gnus-treat-strip-multiple-blank-lines nil
1349 "Strip multiple blank lines.
1350 Valid values are nil, t, `head', `first', `last', an integer or a
1351 predicate. See Info node `(gnus)Customizing Articles'."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1356 (defcustom gnus-treat-unfold-headers 'head
1357 "Unfold folded header lines.
1358 Valid values are nil, t, `head', `first', `last', an integer or a
1359 predicate. See Info node `(gnus)Customizing Articles'."
1360 :version "22.1"
1361 :group 'gnus-article-treat
1362 :link '(custom-manual "(gnus)Customizing Articles")
1363 :type gnus-article-treat-custom)
1365 (defcustom gnus-article-unfold-long-headers nil
1366 "If non-nil, allow unfolding headers even if the header is long.
1367 If it is a regexp, only long headers matching this regexp are unfolded.
1368 If it is t, all long headers are unfolded.
1370 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1371 :version "23.1" ;; No Gnus
1372 :group 'gnus-article-treat
1373 :type '(choice (const nil)
1374 (const :tag "all" t)
1375 (regexp)))
1377 (defcustom gnus-treat-fold-headers nil
1378 "Fold headers.
1379 Valid values are nil, t, `head', `first', `last', an integer or a
1380 predicate. See Info node `(gnus)Customizing Articles'."
1381 :version "22.1"
1382 :group 'gnus-article-treat
1383 :link '(custom-manual "(gnus)Customizing Articles")
1384 :type gnus-article-treat-custom)
1386 (defcustom gnus-treat-fold-newsgroups 'head
1387 "Fold the Newsgroups and Followup-To headers.
1388 Valid values are nil, t, `head', `first', `last', an integer or a
1389 predicate. See Info node `(gnus)Customizing Articles'."
1390 :version "22.1"
1391 :group 'gnus-article-treat
1392 :link '(custom-manual "(gnus)Customizing Articles")
1393 :type gnus-article-treat-custom)
1395 (defcustom gnus-treat-overstrike t
1396 "Treat overstrike highlighting.
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1399 :group 'gnus-article-treat
1400 :link '(custom-manual "(gnus)Customizing Articles")
1401 :type gnus-article-treat-custom)
1402 (put 'gnus-treat-overstrike 'highlight t)
1404 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1405 "Treat ANSI SGR control sequences.
1406 Valid values are nil, t, `head', `first', `last', an integer or a
1407 predicate. See Info node `(gnus)Customizing Articles'."
1408 :group 'gnus-article-treat
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :type gnus-article-treat-custom)
1412 (make-obsolete-variable 'gnus-treat-display-xface
1413 'gnus-treat-display-x-face "Emacs 22.1")
1415 (defcustom gnus-treat-display-x-face
1416 (and (not noninteractive)
1417 (gnus-image-type-available-p 'xbm)
1418 (if (featurep 'xemacs)
1419 (featurep 'xface)
1420 (condition-case nil
1421 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1422 (executable-find "icontopbm"))
1423 ;; shell-command-to-string may signal an error, e.g. if
1424 ;; shell-file-name is not found.
1425 (error nil)))
1426 'head)
1427 "Display X-Face headers.
1428 Valid values are nil and `head'.
1429 See Info node `(gnus)Customizing Articles' and Info node
1430 `(gnus)X-Face' for details."
1431 :group 'gnus-article-treat
1432 :version "21.1"
1433 :link '(custom-manual "(gnus)Customizing Articles")
1434 :link '(custom-manual "(gnus)X-Face")
1435 :type gnus-article-treat-head-custom
1436 :set (lambda (symbol value)
1437 (set-default
1438 symbol
1439 (cond ((or (boundp symbol) (get symbol 'saved-value))
1440 value)
1441 ((boundp 'gnus-treat-display-xface)
1442 (message "\
1443 ** gnus-treat-display-xface is an obsolete variable;\
1444 use gnus-treat-display-x-face instead")
1445 (default-value 'gnus-treat-display-xface))
1446 ((get 'gnus-treat-display-xface 'saved-value)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1452 value)))))
1453 (put 'gnus-treat-display-x-face 'highlight t)
1455 (defcustom gnus-treat-display-face
1456 (and (not noninteractive)
1457 (gnus-image-type-available-p 'png)
1458 'head)
1459 "Display Face headers.
1460 Valid values are nil, t, `head', `first', `last', an integer or a
1461 predicate. See Info node `(gnus)Customizing Articles' and Info
1462 node `(gnus)Face' for details."
1463 :group 'gnus-article-treat
1464 :version "22.1"
1465 :link '(custom-manual "(gnus)Customizing Articles")
1466 :link '(custom-manual "(gnus)X-Face")
1467 :type gnus-article-treat-head-custom)
1468 (put 'gnus-treat-display-face 'highlight t)
1470 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1471 "Display smileys.
1472 Valid values are nil, t, `head', `first', `last', an integer or a
1473 predicate. See Info node `(gnus)Customizing Articles' and Info
1474 node `(gnus)Smileys' for details."
1475 :group 'gnus-article-treat
1476 :version "21.1"
1477 :link '(custom-manual "(gnus)Customizing Articles")
1478 :link '(custom-manual "(gnus)Smileys")
1479 :type gnus-article-treat-custom)
1480 (put 'gnus-treat-display-smileys 'highlight t)
1482 (defcustom gnus-treat-from-picon
1483 (if (and (gnus-image-type-available-p 'xpm)
1484 (gnus-picons-installed-p))
1485 'head nil)
1486 "Display picons in the From header.
1487 Valid values are nil, t, `head', `first', `last', an integer or a
1488 predicate. See Info node `(gnus)Customizing Articles' and Info
1489 node `(gnus)Picons' for details."
1490 :version "22.1"
1491 :group 'gnus-article-treat
1492 :group 'gnus-picon
1493 :link '(custom-manual "(gnus)Customizing Articles")
1494 :link '(custom-manual "(gnus)Picons")
1495 :type gnus-article-treat-head-custom)
1496 (put 'gnus-treat-from-picon 'highlight t)
1498 (defcustom gnus-treat-mail-picon
1499 (if (and (gnus-image-type-available-p 'xpm)
1500 (gnus-picons-installed-p))
1501 'head nil)
1502 "Display picons in To and Cc headers.
1503 Valid values are nil, t, `head', `first', `last', an integer or a
1504 predicate. See Info node `(gnus)Customizing Articles' and Info
1505 node `(gnus)Picons' for details."
1506 :version "22.1"
1507 :group 'gnus-article-treat
1508 :group 'gnus-picon
1509 :link '(custom-manual "(gnus)Customizing Articles")
1510 :link '(custom-manual "(gnus)Picons")
1511 :type gnus-article-treat-head-custom)
1512 (put 'gnus-treat-mail-picon 'highlight t)
1514 (defcustom gnus-treat-newsgroups-picon
1515 (if (and (gnus-image-type-available-p 'xpm)
1516 (gnus-picons-installed-p))
1517 'head nil)
1518 "Display picons in the Newsgroups and Followup-To headers.
1519 Valid values are nil, t, `head', `first', `last', an integer or a
1520 predicate. See Info node `(gnus)Customizing Articles' and Info
1521 node `(gnus)Picons' for details."
1522 :version "22.1"
1523 :group 'gnus-article-treat
1524 :group 'gnus-picon
1525 :link '(custom-manual "(gnus)Customizing Articles")
1526 :link '(custom-manual "(gnus)Picons")
1527 :type gnus-article-treat-head-custom)
1528 (put 'gnus-treat-newsgroups-picon 'highlight t)
1530 (defcustom gnus-treat-from-gravatar nil
1531 "Display gravatars in the From header.
1532 Valid values are nil, t, `head', `first', `last', an integer or a
1533 predicate. See Info node `(gnus)Customizing Articles' and Info
1534 node `(gnus)Gravatars' for details."
1535 :version "24.1"
1536 :group 'gnus-article-treat
1537 :group 'gnus-gravatar
1538 :link '(custom-manual "(gnus)Customizing Articles")
1539 :link '(custom-manual "(gnus)Gravatars")
1540 :type gnus-article-treat-head-custom)
1541 (put 'gnus-treat-from-gravatar 'highlight t)
1543 (defcustom gnus-treat-mail-gravatar nil
1544 "Display gravatars in To and Cc headers.
1545 Valid values are nil, t, `head', `first', `last', an integer or a
1546 predicate. See Info node `(gnus)Customizing Articles' and Info
1547 node `(gnus)Gravatars' for details."
1548 :version "24.1"
1549 :group 'gnus-article-treat
1550 :group 'gnus-gravatar
1551 :link '(custom-manual "(gnus)Customizing Articles")
1552 :link '(custom-manual "(gnus)Gravatars")
1553 :type gnus-article-treat-head-custom)
1554 (put 'gnus-treat-mail-gravatar 'highlight t)
1556 (defcustom gnus-treat-body-boundary
1557 (if (or gnus-treat-newsgroups-picon
1558 gnus-treat-mail-picon
1559 gnus-treat-from-picon
1560 gnus-treat-from-gravatar
1561 gnus-treat-mail-gravatar)
1562 ;; If there's much decoration, the user might prefer a boundary.
1563 'head
1564 nil)
1565 "Draw a boundary at the end of the headers.
1566 Valid values are nil and `head'.
1567 See Info node `(gnus)Customizing Articles' for details."
1568 :version "22.1"
1569 :group 'gnus-article-treat
1570 :link '(custom-manual "(gnus)Customizing Articles")
1571 :type gnus-article-treat-head-custom)
1573 (defcustom gnus-treat-capitalize-sentences nil
1574 "Capitalize sentence-starting words.
1575 Valid values are nil, t, `head', `first', `last', an integer or a
1576 predicate. See Info node `(gnus)Customizing Articles'."
1577 :version "21.1"
1578 :group 'gnus-article-treat
1579 :link '(custom-manual "(gnus)Customizing Articles")
1580 :type gnus-article-treat-custom)
1582 (defcustom gnus-treat-wash-html nil
1583 "Format as HTML.
1584 Valid values are nil, t, `head', `first', `last', an integer or a
1585 predicate. See Info node `(gnus)Customizing Articles'."
1586 :version "22.1"
1587 :group 'gnus-article-treat
1588 :link '(custom-manual "(gnus)Customizing Articles")
1589 :type gnus-article-treat-custom)
1591 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1592 "Fill long lines.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1595 :version "24.1"
1596 :group 'gnus-article-treat
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1600 (defcustom gnus-treat-x-pgp-sig nil
1601 "Verify X-PGP-Sig.
1602 To automatically treat X-PGP-Sig, set it to head.
1603 Valid values are nil, t, `head', `first', `last', an integer or a
1604 predicate. See Info node `(gnus)Customizing Articles'."
1605 :version "22.1"
1606 :group 'gnus-article-treat
1607 :group 'mime-security
1608 :link '(custom-manual "(gnus)Customizing Articles")
1609 :type gnus-article-treat-custom)
1611 (defvar gnus-article-encrypt-protocol-alist
1612 '(("PGP" . mml2015-self-encrypt)))
1614 ;; Set to nil if more than one protocol added to
1615 ;; gnus-article-encrypt-protocol-alist.
1616 (defcustom gnus-article-encrypt-protocol "PGP"
1617 "The protocol used for encrypt articles.
1618 It is a string, such as \"PGP\". If nil, ask user."
1619 :version "22.1"
1620 :type 'string
1621 :group 'mime-security)
1623 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1624 (mm-coding-system-p 'utf-8)
1625 (executable-find idna-program))
1626 "Whether IDNA decoding of headers is used when viewing messages.
1627 This requires GNU Libidn, and by default only enabled if it is found."
1628 :version "22.1"
1629 :group 'gnus-article-headers
1630 :type 'boolean)
1632 (defcustom gnus-article-over-scroll nil
1633 "If non-nil, allow scrolling the article buffer even when there no more text."
1634 :version "22.1"
1635 :group 'gnus-article
1636 :type 'boolean)
1638 (defcustom gnus-inhibit-images nil
1639 "Non-nil means inhibit displaying of images inline in the article body."
1640 :version "24.1"
1641 :group 'gnus-article
1642 :type 'boolean)
1644 (defcustom gnus-blocked-images 'gnus-block-private-groups
1645 "Images that have URLs matching this regexp will be blocked.
1646 This can also be a function to be evaluated. If so, it will be
1647 called with the group name as the parameter, and should return a
1648 regexp."
1649 :version "24.1"
1650 :group 'gnus-art
1651 :type '(choice regexp function))
1653 ;;; Internal variables
1655 (defvar gnus-english-month-names
1656 '("January" "February" "March" "April" "May" "June" "July" "August"
1657 "September" "October" "November" "December"))
1659 (defvar article-goto-body-goes-to-point-min-p nil)
1660 (defvar gnus-article-wash-types nil)
1661 (defvar gnus-article-emphasis-alist nil)
1662 (defvar gnus-article-image-alist nil)
1664 (defvar gnus-article-mime-handle-alist-1 nil)
1665 (defvar gnus-treatment-function-alist
1666 '((gnus-treat-strip-cr gnus-article-remove-cr)
1667 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1668 (gnus-treat-strip-banner gnus-article-strip-banner)
1669 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1670 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1671 (gnus-treat-buttonize gnus-article-add-buttons)
1672 (gnus-treat-fill-article gnus-article-fill-cited-article)
1673 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1674 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1675 (gnus-treat-display-x-face gnus-article-display-x-face)
1676 (gnus-treat-display-face gnus-article-display-face)
1677 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1678 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1679 (gnus-treat-hide-signature gnus-article-hide-signature)
1680 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1681 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1682 (gnus-treat-from-picon gnus-treat-from-picon)
1683 (gnus-treat-mail-picon gnus-treat-mail-picon)
1684 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1685 (gnus-treat-strip-pem gnus-article-hide-pem)
1686 (gnus-treat-date gnus-article-treat-date)
1687 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1688 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1689 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1690 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1691 (gnus-treat-strip-trailing-blank-lines
1692 gnus-article-remove-trailing-blank-lines)
1693 (gnus-treat-strip-leading-blank-lines
1694 gnus-article-strip-leading-blank-lines)
1695 (gnus-treat-strip-multiple-blank-lines
1696 gnus-article-strip-multiple-blank-lines)
1697 (gnus-treat-overstrike gnus-article-treat-overstrike)
1698 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1699 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1700 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1701 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1702 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1703 (gnus-treat-display-smileys gnus-treat-smiley)
1704 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1705 (gnus-treat-wash-html gnus-article-wash-html)
1706 (gnus-treat-emphasize gnus-article-emphasize)
1707 (gnus-treat-hide-citation gnus-article-hide-citation)
1708 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1709 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1710 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1712 (defvar gnus-article-mime-handle-alist nil)
1713 (defvar article-lapsed-timer nil)
1714 (defvar gnus-article-current-summary nil)
1716 (defvar gnus-article-mode-syntax-table
1717 (let ((table (copy-syntax-table text-mode-syntax-table)))
1718 ;; This causes the citation match run O(2^n).
1719 ;; (modify-syntax-entry ?- "w" table)
1720 (modify-syntax-entry ?> ")<" table)
1721 (modify-syntax-entry ?< "(>" table)
1722 ;; make M-. in article buffers work for `foo' strings
1723 (modify-syntax-entry ?' " " table)
1724 (modify-syntax-entry ?` " " table)
1725 table)
1726 "Syntax table used in article mode buffers.
1727 Initialized from `text-mode-syntax-table.")
1729 (defvar gnus-save-article-buffer nil)
1731 (defvar gnus-number-of-articles-to-be-saved nil)
1733 (defvar gnus-inhibit-hiding nil)
1735 (defvar gnus-article-edit-mode nil)
1737 ;;; Macros for dealing with the article buffer.
1739 (defmacro gnus-with-article-headers (&rest forms)
1740 `(with-current-buffer gnus-article-buffer
1741 (save-restriction
1742 (let ((inhibit-read-only t)
1743 (inhibit-point-motion-hooks t)
1744 (case-fold-search t))
1745 (article-narrow-to-head)
1746 ,@forms))))
1748 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1749 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1751 (defmacro gnus-with-article-buffer (&rest forms)
1752 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1753 (with-current-buffer gnus-article-buffer
1754 (let ((inhibit-read-only t))
1755 ,@forms))))
1757 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1758 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1760 (defun gnus-article-goto-header (header)
1761 "Go to HEADER, which is a regular expression."
1762 (re-search-forward (concat "^\\(" header "\\):") nil t))
1764 (defsubst gnus-article-hide-text (b e props)
1765 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1766 (gnus-add-text-properties-when 'article-type nil b e props)
1767 (when (memq 'intangible props)
1768 (put-text-property
1769 (max (1- b) (point-min))
1770 b 'intangible (cddr (memq 'intangible props)))))
1772 (defsubst gnus-article-unhide-text (b e)
1773 "Remove hidden text properties from region between B and E."
1774 (remove-text-properties b e gnus-hidden-properties)
1775 (when (memq 'intangible gnus-hidden-properties)
1776 (put-text-property (max (1- b) (point-min))
1777 b 'intangible nil)))
1779 (defun gnus-article-hide-text-type (b e type)
1780 "Hide text of TYPE between B and E."
1781 (gnus-add-wash-type type)
1782 (gnus-article-hide-text
1783 b e (cons 'article-type (cons type gnus-hidden-properties))))
1785 (defun gnus-article-unhide-text-type (b e type)
1786 "Unhide text of TYPE between B and E."
1787 (gnus-delete-wash-type type)
1788 (remove-text-properties
1789 b e (cons 'article-type (cons type gnus-hidden-properties)))
1790 (when (memq 'intangible gnus-hidden-properties)
1791 (put-text-property (max (1- b) (point-min))
1792 b 'intangible nil)))
1794 (defun gnus-article-delete-text-of-type (type)
1795 "Delete text of TYPE in the current buffer."
1796 (save-excursion
1797 (let ((b (point-min)))
1798 (if (eq type 'multipart)
1799 ;; Remove MIME buttons associated with multipart/alternative parts.
1800 (progn
1801 (goto-char b)
1802 (while (if (get-text-property (point) 'gnus-part)
1803 (setq b (point))
1804 (when (setq b (next-single-property-change (point)
1805 'gnus-part))
1806 (goto-char b)
1808 (end-of-line)
1809 (skip-chars-forward "\n")
1810 (when (eq (get-text-property b 'article-type) 'multipart)
1811 (delete-region b (point)))))
1812 (while (setq b (text-property-any b (point-max) 'article-type type))
1813 (delete-region
1814 b (or (text-property-not-all b (point-max) 'article-type type)
1815 (point-max))))))))
1817 (defun gnus-article-delete-invisible-text ()
1818 "Delete all invisible text in the current buffer."
1819 (save-excursion
1820 (let ((b (point-min)))
1821 (while (setq b (text-property-any b (point-max) 'invisible t))
1822 (delete-region
1823 b (or (text-property-not-all b (point-max) 'invisible t)
1824 (point-max)))))))
1826 (defsubst gnus-article-header-rank ()
1827 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1828 (let ((list gnus-sorted-header-list)
1829 (i 1))
1830 (while list
1831 (if (looking-at (car list))
1832 (setq list nil)
1833 (setq list (cdr list))
1834 (incf i)))
1837 (defun article-hide-headers (&optional arg delete)
1838 "Hide unwanted headers and possibly sort them as well."
1839 (interactive)
1840 ;; This function might be inhibited.
1841 (unless gnus-inhibit-hiding
1842 (let ((inhibit-read-only t)
1843 (case-fold-search t)
1844 (max (1+ (length gnus-sorted-header-list)))
1845 (inhibit-point-motion-hooks t)
1846 (cur (current-buffer))
1847 ignored visible beg)
1848 (save-excursion
1849 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1850 ;; group parameters, so we should go to the summary buffer.
1851 (when (prog1
1852 (condition-case nil
1853 (progn (set-buffer gnus-summary-buffer) t)
1854 (error nil))
1855 (setq ignored (when (not gnus-visible-headers)
1856 (cond ((stringp gnus-ignored-headers)
1857 gnus-ignored-headers)
1858 ((listp gnus-ignored-headers)
1859 (mapconcat 'identity
1860 gnus-ignored-headers
1861 "\\|"))))
1862 visible (cond ((stringp gnus-visible-headers)
1863 gnus-visible-headers)
1864 ((and gnus-visible-headers
1865 (listp gnus-visible-headers))
1866 (mapconcat 'identity
1867 gnus-visible-headers
1868 "\\|")))))
1869 (set-buffer cur))
1870 (save-restriction
1871 ;; First we narrow to just the headers.
1872 (article-narrow-to-head)
1873 ;; Hide any "From " lines at the beginning of (mail) articles.
1874 (while (looking-at "From ")
1875 (forward-line 1))
1876 (unless (bobp)
1877 (delete-region (point-min) (point)))
1878 ;; Then treat the rest of the header lines.
1879 ;; Then we use the two regular expressions
1880 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1881 ;; select which header lines is to remain visible in the
1882 ;; article buffer.
1883 (while (re-search-forward "^[^ \t:]*:" nil t)
1884 (beginning-of-line)
1885 ;; Mark the rank of the header.
1886 (put-text-property
1887 (point) (1+ (point)) 'message-rank
1888 (if (or (and visible (looking-at visible))
1889 (and ignored
1890 (not (looking-at ignored))))
1891 (gnus-article-header-rank)
1892 (+ 2 max)))
1893 (forward-line 1))
1894 (message-sort-headers-1)
1895 (when (setq beg (text-property-any
1896 (point-min) (point-max) 'message-rank (+ 2 max)))
1897 ;; We delete the unwanted headers.
1898 (gnus-add-wash-type 'headers)
1899 (add-text-properties (point-min) (+ 5 (point-min))
1900 '(article-type headers dummy-invisible t))
1901 (delete-region beg (point-max))))))))
1903 (defun article-hide-boring-headers (&optional arg)
1904 "Toggle hiding of headers that aren't very interesting.
1905 If given a negative prefix, always show; if given a positive prefix,
1906 always hide."
1907 (interactive (gnus-article-hidden-arg))
1908 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1909 (not gnus-show-all-headers))
1910 (save-excursion
1911 (save-restriction
1912 (let ((inhibit-read-only t)
1913 (inhibit-point-motion-hooks t))
1914 (article-narrow-to-head)
1915 (dolist (elem gnus-boring-article-headers)
1916 (goto-char (point-min))
1917 (cond
1918 ;; Hide empty headers.
1919 ((eq elem 'empty)
1920 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1921 (forward-line -1)
1922 (gnus-article-hide-text-type
1923 (point-at-bol)
1924 (progn
1925 (end-of-line)
1926 (if (re-search-forward "^[^ \t]" nil t)
1927 (match-beginning 0)
1928 (point-max)))
1929 'boring-headers)))
1930 ;; Hide boring Newsgroups header.
1931 ((eq elem 'newsgroups)
1932 (when (gnus-string-equal
1933 (gnus-fetch-field "newsgroups")
1934 (gnus-group-real-name
1935 (if (boundp 'gnus-newsgroup-name)
1936 gnus-newsgroup-name
1937 "")))
1938 (gnus-article-hide-header "newsgroups")))
1939 ((eq elem 'to-address)
1940 (let ((to (message-fetch-field "to"))
1941 (to-address
1942 (gnus-parameter-to-address
1943 (if (boundp 'gnus-newsgroup-name)
1944 gnus-newsgroup-name ""))))
1945 (when (and to to-address
1946 (ignore-errors
1947 (gnus-string-equal
1948 ;; only one address in To
1949 (nth 1 (mail-extract-address-components to))
1950 to-address)))
1951 (gnus-article-hide-header "to"))))
1952 ((eq elem 'to-list)
1953 (let ((to (message-fetch-field "to"))
1954 (to-list
1955 (gnus-parameter-to-list
1956 (if (boundp 'gnus-newsgroup-name)
1957 gnus-newsgroup-name ""))))
1958 (when (and to to-list
1959 (ignore-errors
1960 (gnus-string-equal
1961 ;; only one address in To
1962 (nth 1 (mail-extract-address-components to))
1963 to-list)))
1964 (gnus-article-hide-header "to"))))
1965 ((eq elem 'cc-list)
1966 (let ((cc (message-fetch-field "cc"))
1967 (to-list
1968 (gnus-parameter-to-list
1969 (if (boundp 'gnus-newsgroup-name)
1970 gnus-newsgroup-name ""))))
1971 (when (and cc to-list
1972 (ignore-errors
1973 (gnus-string-equal
1974 ;; only one address in CC
1975 (nth 1 (mail-extract-address-components cc))
1976 to-list)))
1977 (gnus-article-hide-header "cc"))))
1978 ((eq elem 'followup-to)
1979 (when (gnus-string-equal
1980 (message-fetch-field "followup-to")
1981 (message-fetch-field "newsgroups"))
1982 (gnus-article-hide-header "followup-to")))
1983 ((eq elem 'reply-to)
1984 (if (gnus-group-find-parameter
1985 gnus-newsgroup-name 'broken-reply-to)
1986 (gnus-article-hide-header "reply-to")
1987 (let ((from (message-fetch-field "from"))
1988 (reply-to (message-fetch-field "reply-to")))
1989 (when
1990 (and
1991 from reply-to
1992 (ignore-errors
1993 (equal
1994 (sort (mapcar
1995 (lambda (x) (downcase (cadr x)))
1996 (mail-extract-address-components from t))
1997 'string<)
1998 (sort (mapcar
1999 (lambda (x) (downcase (cadr x)))
2000 (mail-extract-address-components reply-to t))
2001 'string<))))
2002 (gnus-article-hide-header "reply-to")))))
2003 ((eq elem 'date)
2004 (let ((date (with-current-buffer gnus-original-article-buffer
2005 ;; If date in `gnus-article-buffer' is localized
2006 ;; (`gnus-treat-date-user-defined'),
2007 ;; `days-between' might fail.
2008 (message-fetch-field "date"))))
2009 (when (and date
2010 (< (days-between (current-time-string) date)
2012 (gnus-article-hide-header "date"))))
2013 ((eq elem 'long-to)
2014 (let ((to (message-fetch-field "to"))
2015 (cc (message-fetch-field "cc")))
2016 (when (> (length to) 1024)
2017 (gnus-article-hide-header "to"))
2018 (when (> (length cc) 1024)
2019 (gnus-article-hide-header "cc"))))
2020 ((eq elem 'many-to)
2021 (let ((to-count 0)
2022 (cc-count 0))
2023 (goto-char (point-min))
2024 (while (re-search-forward "^to:" nil t)
2025 (setq to-count (1+ to-count)))
2026 (when (> to-count 1)
2027 (while (> to-count 0)
2028 (goto-char (point-min))
2029 (save-restriction
2030 (re-search-forward "^to:" nil nil to-count)
2031 (forward-line -1)
2032 (narrow-to-region (point) (point-max))
2033 (gnus-article-hide-header "to"))
2034 (setq to-count (1- to-count))))
2035 (goto-char (point-min))
2036 (while (re-search-forward "^cc:" nil t)
2037 (setq cc-count (1+ cc-count)))
2038 (when (> cc-count 1)
2039 (while (> cc-count 0)
2040 (goto-char (point-min))
2041 (save-restriction
2042 (re-search-forward "^cc:" nil nil cc-count)
2043 (forward-line -1)
2044 (narrow-to-region (point) (point-max))
2045 (gnus-article-hide-header "cc"))
2046 (setq cc-count (1- cc-count)))))))))))))
2048 (defun gnus-article-hide-header (header)
2049 (save-excursion
2050 (goto-char (point-min))
2051 (when (re-search-forward (concat "^" header ":") nil t)
2052 (gnus-article-hide-text-type
2053 (point-at-bol)
2054 (progn
2055 (end-of-line)
2056 (if (re-search-forward "^[^ \t]" nil t)
2057 (match-beginning 0)
2058 (point-max)))
2059 'boring-headers))))
2061 (defvar gnus-article-normalized-header-length 40
2062 "Length of normalized headers.")
2064 (defun article-normalize-headers ()
2065 "Make all header lines 40 characters long."
2066 (interactive)
2067 (let ((inhibit-read-only t)
2068 column)
2069 (save-excursion
2070 (save-restriction
2071 (article-narrow-to-head)
2072 (while (not (eobp))
2073 (cond
2074 ((< (setq column (- (point-at-eol) (point)))
2075 gnus-article-normalized-header-length)
2076 (end-of-line)
2077 (insert (make-string
2078 (- gnus-article-normalized-header-length column)
2079 ? )))
2080 ((> column gnus-article-normalized-header-length)
2081 (gnus-put-text-property
2082 (progn
2083 (forward-char gnus-article-normalized-header-length)
2084 (point))
2085 (point-at-eol)
2086 'invisible t))
2088 ;; Do nothing.
2090 (forward-line 1))))))
2092 (defun article-treat-dumbquotes ()
2093 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2094 Note that this function guesses whether a character is a sm*rtq**t* or
2095 not, so it should only be used interactively.
2097 Sm*rtq**t*s are M****s***'s unilateral extension to the
2098 iso-8859-1 character map in an attempt to provide more quoting
2099 characters. If you see something like \\222 or \\264 where
2100 you're expecting some kind of apostrophe or quotation mark, then
2101 try this wash."
2102 (interactive)
2103 (article-translate-strings gnus-article-dumbquotes-map))
2105 (defvar org-entities)
2107 (defun article-treat-non-ascii ()
2108 "Translate many Unicode characters into their ASCII equivalents."
2109 (interactive)
2110 (require 'org-entities)
2111 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2112 (dolist (elem org-entities)
2113 (when (and (listp elem)
2114 (= (length (nth 6 elem)) 1))
2115 (if (featurep 'xemacs)
2116 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2117 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2118 (save-excursion
2119 (when (article-goto-body)
2120 (let ((inhibit-read-only t)
2121 replace props)
2122 (while (not (eobp))
2123 (if (not (setq replace (if (featurep 'xemacs)
2124 (get-char-table (following-char) table)
2125 (aref table (following-char)))))
2126 (forward-char 1)
2127 (if (prog1
2128 (setq props (text-properties-at (point)))
2129 (delete-char 1))
2130 (add-text-properties (point) (progn (insert replace) (point))
2131 props)
2132 (insert replace)))))))))
2134 (defun article-translate-strings (map)
2135 "Translate all string in the body of the article according to MAP.
2136 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2137 (save-excursion
2138 (when (article-goto-body)
2139 (let ((inhibit-read-only t))
2140 (dolist (elem map)
2141 (let ((from (car elem))
2142 (to (cadr elem)))
2143 (save-excursion
2144 (if (stringp from)
2145 (while (search-forward from nil t)
2146 (replace-match to))
2147 (while (not (eobp))
2148 (if (eq (following-char) from)
2149 (progn
2150 (delete-char 1)
2151 (insert to))
2152 (forward-char 1)))))))))))
2154 (defun article-treat-overstrike ()
2155 "Translate overstrikes into bold text."
2156 (interactive)
2157 (save-excursion
2158 (when (article-goto-body)
2159 (let ((inhibit-read-only t))
2160 (while (search-forward "\b" nil t)
2161 (let ((next (char-after))
2162 (previous (char-after (- (point) 2))))
2163 ;; We do the boldification/underlining by hiding the
2164 ;; overstrikes and putting the proper text property
2165 ;; on the letters.
2166 (cond
2167 ((eq next previous)
2168 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2169 (put-text-property (point) (1+ (point)) 'face 'bold))
2170 ((eq next ?_)
2171 (gnus-article-hide-text-type
2172 (1- (point)) (1+ (point)) 'overstrike)
2173 (put-text-property
2174 (- (point) 2) (1- (point)) 'face 'underline))
2175 ((eq previous ?_)
2176 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2177 (put-text-property
2178 (point) (1+ (point)) 'face 'underline)))))))))
2180 (defun article-treat-ansi-sequences ()
2181 "Translate ANSI SGR control sequences into overlays or extents."
2182 (interactive)
2183 (save-excursion
2184 (when (article-goto-body)
2185 (let ((inhibit-read-only t))
2186 (ansi-color-apply-on-region (point) (point-max))))))
2188 (defun gnus-article-treat-unfold-headers ()
2189 "Unfold folded message headers.
2190 Only the headers that fit into the current window width will be
2191 unfolded."
2192 (interactive)
2193 (gnus-with-article-headers
2194 (let (length)
2195 (while (not (eobp))
2196 (save-restriction
2197 (mail-header-narrow-to-field)
2198 (let* ((header (buffer-string))
2199 (unfoldable
2200 (or (equal gnus-article-unfold-long-headers t)
2201 (and (stringp gnus-article-unfold-long-headers)
2202 (string-match gnus-article-unfold-long-headers
2203 header)))))
2204 (with-temp-buffer
2205 (insert header)
2206 (goto-char (point-min))
2207 (while (re-search-forward "\n[\t ]" nil t)
2208 (replace-match " " t t)))
2209 (setq length (- (point-max) (point-min) 1))
2210 (when (or unfoldable
2211 (< length (window-width)))
2212 (while (re-search-forward "\n[\t ]" nil t)
2213 (replace-match " " t t))))
2214 (goto-char (point-max)))))))
2216 (defun gnus-article-treat-fold-headers ()
2217 "Fold message headers."
2218 (interactive)
2219 (gnus-with-article-headers
2220 (while (not (eobp))
2221 (save-restriction
2222 (mail-header-narrow-to-field)
2223 (mail-header-fold-field)
2224 (goto-char (point-max))))))
2226 (defun gnus-treat-smiley ()
2227 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2228 (interactive)
2229 (gnus-with-article-buffer
2230 (if (memq 'smiley gnus-article-wash-types)
2231 (gnus-delete-images 'smiley)
2232 (article-goto-body)
2233 (let ((images (smiley-region (point) (point-max))))
2234 (when images
2235 (gnus-add-wash-type 'smiley)
2236 (dolist (image images)
2237 (gnus-add-image 'smiley image)))))))
2239 (defun gnus-article-remove-images ()
2240 "Remove all images from the article buffer."
2241 (interactive)
2242 (gnus-with-article-buffer
2243 (save-restriction
2244 (widen)
2245 (dolist (elem gnus-article-image-alist)
2246 (gnus-delete-images (car elem))))))
2248 (autoload 'w3m-toggle-inline-images "w3m")
2250 (defun gnus-article-show-images ()
2251 "Show any images that are in the HTML-rendered article buffer.
2252 This only works if the article in question is HTML."
2253 (interactive)
2254 (gnus-with-article-buffer
2255 (save-restriction
2256 (widen)
2257 (if (eq mm-text-html-renderer 'w3m)
2258 (let ((mm-inline-text-html-with-images nil))
2259 (w3m-toggle-inline-images))
2260 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2261 'image-displayer))
2262 (destructuring-bind (start end function) region
2263 (funcall function (get-text-property start 'image-url)
2264 start end)))))))
2266 (defun gnus-article-treat-fold-newsgroups ()
2267 "Unfold folded message headers.
2268 Only the headers that fit into the current window width will be
2269 unfolded."
2270 (interactive)
2271 (gnus-with-article-headers
2272 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2273 (save-restriction
2274 (mail-header-narrow-to-field)
2275 (while (re-search-forward ", *" nil t)
2276 (replace-match ", " t t))
2277 (mail-header-fold-field)
2278 (goto-char (point-max))))))
2280 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2281 "Value of `truncate-lines' in Gnus Article buffer.
2282 Valid values are nil, t, `head', `first', `last', an integer or a
2283 predicate. See Info node `(gnus)Customizing Articles'."
2284 :version "23.1" ;; No Gnus
2285 :group 'gnus-article
2286 ;; :link '(custom-manual "(gnus)Customizing Articles")
2287 :type 'boolean)
2289 (defun gnus-article-toggle-truncate-lines (&optional arg)
2290 "Toggle whether to fold or truncate long lines in article the buffer.
2291 If ARG is non-nil and not a number, toggle
2292 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2293 long lines if and only if arg is positive."
2294 (interactive "P")
2295 (cond
2296 ((and (numberp arg) (> arg 0))
2297 (setq gnus-article-truncate-lines t))
2298 ((numberp arg)
2299 (setq gnus-article-truncate-lines nil))
2300 (arg
2301 (setq gnus-article-truncate-lines
2302 (not gnus-article-truncate-lines))))
2303 (gnus-with-article-buffer
2304 (cond
2305 ((and (numberp arg) (> arg 0))
2306 (setq truncate-lines nil))
2307 ((numberp arg)
2308 (setq truncate-lines t)))
2309 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2310 ;; `toggle-truncate-lines' needs an argument.
2311 (toggle-truncate-lines)))
2313 (defun gnus-article-treat-body-boundary ()
2314 "Place a boundary line at the end of the headers."
2315 (interactive)
2316 (when (and gnus-body-boundary-delimiter
2317 (> (length gnus-body-boundary-delimiter) 0))
2318 (gnus-with-article-headers
2319 (goto-char (point-max))
2320 (let ((start (point)))
2321 (insert "X-Boundary: ")
2322 (gnus-add-text-properties start (point) '(invisible t intangible t))
2323 (insert (let (str (max (window-width)))
2324 (if (featurep 'xemacs)
2325 (setq max (1- max)))
2326 (while (>= max (length str))
2327 (setq str (concat str gnus-body-boundary-delimiter)))
2328 (substring str 0 max))
2329 "\n")
2330 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2332 (defun article-fill-long-lines ()
2333 "Fill lines that are wider than the window width."
2334 (interactive)
2335 (save-excursion
2336 (let ((inhibit-read-only t)
2337 (width (window-width (get-buffer-window (current-buffer)))))
2338 (save-restriction
2339 (article-goto-body)
2340 (let ((adaptive-fill-mode nil)) ;Why? -sm
2341 (while (not (eobp))
2342 (end-of-line)
2343 (when (>= (current-column) (min fill-column width))
2344 (narrow-to-region (min (1+ (point)) (point-max))
2345 (point-at-bol))
2346 (let ((goback (point-marker)))
2347 (fill-paragraph nil)
2348 (goto-char (marker-position goback)))
2349 (widen))
2350 (forward-line 1)))))))
2352 (defun article-capitalize-sentences ()
2353 "Capitalize the first word in each sentence."
2354 (interactive)
2355 (save-excursion
2356 (let ((inhibit-read-only t)
2357 (paragraph-start "^[\n\^L]"))
2358 (article-goto-body)
2359 (while (not (eobp))
2360 (capitalize-word 1)
2361 (forward-sentence)))))
2363 (defun article-remove-cr ()
2364 "Remove trailing CRs and then translate remaining CRs into LFs."
2365 (interactive)
2366 (save-excursion
2367 (let ((inhibit-read-only t))
2368 (goto-char (point-min))
2369 (while (re-search-forward "\r+$" nil t)
2370 (replace-match "" t t))
2371 (goto-char (point-min))
2372 (while (search-forward "\r" nil t)
2373 (replace-match "\n" t t)))))
2375 (defun article-remove-trailing-blank-lines ()
2376 "Remove all trailing blank lines from the article."
2377 (interactive)
2378 (save-excursion
2379 (let ((inhibit-read-only t))
2380 (goto-char (point-max))
2381 (delete-region
2382 (point)
2383 (progn
2384 (while (and (not (bobp))
2385 (looking-at "^[ \t]*$")
2386 (not (gnus-annotation-in-region-p
2387 (point) (point-at-eol))))
2388 (forward-line -1))
2389 (forward-line 1)
2390 (point))))))
2392 (defvar gnus-face-properties-alist)
2394 (defun article-display-face (&optional force)
2395 "Display any Face headers in the header."
2396 (interactive (list 'force))
2397 (let ((wash-face-p buffer-read-only))
2398 (gnus-with-article-headers
2399 ;; When displaying parts, this function can be called several times on
2400 ;; the same article, without any intended toggle semantic (as typing `W
2401 ;; D d' would have). So face deletion must occur only when we come from
2402 ;; an interactive command, that is when the *Article* buffer is
2403 ;; read-only.
2404 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2405 (gnus-delete-images 'face)
2406 (let ((from (message-fetch-field "from"))
2407 face faces)
2408 (save-current-buffer
2409 (when (and wash-face-p
2410 (gnus-buffer-live-p gnus-original-article-buffer)
2411 (not (re-search-forward "^Face:[\t ]*" nil t)))
2412 (set-buffer gnus-original-article-buffer))
2413 (save-restriction
2414 (mail-narrow-to-head)
2415 (when (or force
2416 ;; Check whether this face is censored.
2417 (not (and gnus-article-x-face-too-ugly
2418 (or from
2419 (setq from (message-fetch-field "from")))
2420 (string-match gnus-article-x-face-too-ugly
2421 from))))
2422 (while (gnus-article-goto-header "Face")
2423 (push (mail-header-field-value) faces)))))
2424 (when faces
2425 (goto-char (point-min))
2426 (let (png image)
2427 (unless (setq from (gnus-article-goto-header "from"))
2428 (insert "From:")
2429 (setq from (point))
2430 (insert " [no `from' set]\n"))
2431 (while faces
2432 (when (setq png (gnus-convert-face-to-png (pop faces)))
2433 (setq image
2434 (apply 'gnus-create-image png 'png t
2435 (cdr (assq 'png gnus-face-properties-alist))))
2436 (goto-char from)
2437 (when image
2438 (gnus-add-wash-type 'face)
2439 (gnus-add-image 'face image)
2440 (gnus-put-image image nil 'face)))))))))))
2442 (defun article-display-x-face (&optional force)
2443 "Look for an X-Face header and display it if present."
2444 (interactive (list 'force))
2445 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2446 (gnus-with-article-headers
2447 ;; Delete the old process, if any.
2448 (when (process-status "article-x-face")
2449 (delete-process "article-x-face"))
2450 ;; See the comment in `article-display-face'.
2451 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2452 ;; We have already displayed X-Faces, so we remove them
2453 ;; instead.
2454 (gnus-delete-images 'xface)
2455 ;; Display X-Faces.
2456 (let ((from (message-fetch-field "from"))
2457 x-faces face)
2458 (save-current-buffer
2459 (when (and wash-face-p
2460 (gnus-buffer-live-p gnus-original-article-buffer)
2461 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2462 ;; If type `W f', use gnus-original-article-buffer,
2463 ;; otherwise use the current buffer because displaying
2464 ;; RFC822 parts calls this function too.
2465 (set-buffer gnus-original-article-buffer))
2466 (save-restriction
2467 (mail-narrow-to-head)
2468 (and gnus-article-x-face-command
2469 (or force
2470 ;; Check whether this face is censored.
2471 (not (and gnus-article-x-face-too-ugly
2472 (or from
2473 (setq from (message-fetch-field "from")))
2474 (string-match gnus-article-x-face-too-ugly
2475 from))))
2476 (while (gnus-article-goto-header "X-Face")
2477 (push (mail-header-field-value) x-faces)))))
2478 (when x-faces
2479 ;; We display the face.
2480 (cond ((functionp gnus-article-x-face-command)
2481 ;; The command is a lisp function, so we call it.
2482 (mapc gnus-article-x-face-command x-faces))
2483 ((stringp gnus-article-x-face-command)
2484 ;; The command is a string, so we interpret the command
2485 ;; as a, well, command, and fork it off.
2486 (let ((process-connection-type nil))
2487 (gnus-set-process-query-on-exit-flag
2488 (start-process
2489 "article-x-face" nil shell-file-name
2490 shell-command-switch gnus-article-x-face-command)
2491 nil)
2492 ;; Sending multiple EOFs to xv doesn't work,
2493 ;; so we only do a single external face.
2494 (with-temp-buffer
2495 (insert (car x-faces))
2496 (process-send-region "article-x-face"
2497 (point-min) (point-max)))
2498 (process-send-eof "article-x-face")))
2500 (error "`%s' set to `%s' is not a function"
2501 gnus-article-x-face-command
2502 'gnus-article-x-face-command)))))))))
2504 (defun article-decode-mime-words ()
2505 "Decode all MIME-encoded words in the article."
2506 (interactive)
2507 (gnus-with-article-buffer
2508 (let ((inhibit-point-motion-hooks t)
2509 (mail-parse-charset gnus-newsgroup-charset)
2510 (mail-parse-ignored-charsets
2511 (with-current-buffer gnus-summary-buffer
2512 gnus-newsgroup-ignored-charsets)))
2513 (mail-decode-encoded-word-region (point-min) (point-max)))))
2515 (defun article-decode-charset (&optional prompt)
2516 "Decode charset-encoded text in the article.
2517 If PROMPT (the prefix), prompt for a coding system to use."
2518 (interactive "P")
2519 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2520 (inhibit-read-only t)
2521 (mail-parse-charset gnus-newsgroup-charset)
2522 (mail-parse-ignored-charsets
2523 (save-excursion (condition-case nil
2524 (set-buffer gnus-summary-buffer)
2525 (error))
2526 gnus-newsgroup-ignored-charsets))
2527 ct cte ctl charset format)
2528 (save-excursion
2529 (save-restriction
2530 (article-narrow-to-head)
2531 (setq ct (message-fetch-field "Content-Type" t)
2532 cte (message-fetch-field "Content-Transfer-Encoding" t)
2533 ctl (and ct (mail-header-parse-content-type ct))
2534 charset (cond
2535 (prompt
2536 (mm-read-coding-system "Charset to decode: "))
2537 (ctl
2538 (mail-content-type-get ctl 'charset)))
2539 format (and ctl (mail-content-type-get ctl 'format)))
2540 (when cte
2541 (setq cte (mail-header-strip cte)))
2542 (if (and ctl (not (string-match "/" (car ctl))))
2543 (setq ctl nil))
2544 (goto-char (point-max)))
2545 (forward-line 1)
2546 (save-restriction
2547 (narrow-to-region (point) (point-max))
2548 (when (and (eq mail-parse-charset 'gnus-decoded)
2549 (eq (mm-body-7-or-8) '8bit))
2550 ;; The text code could have been decoded.
2551 (setq charset mail-parse-charset))
2552 (when (and (or (not ctl)
2553 (equal (car ctl) "text/plain"))
2554 (not format)) ;; article with format will decode later.
2555 (mm-decode-body
2556 charset (and cte (intern (downcase
2557 (gnus-strip-whitespace cte))))
2558 (car ctl)))))))
2560 (defun article-decode-encoded-words ()
2561 "Remove encoded-word encoding from headers."
2562 (let ((inhibit-point-motion-hooks t)
2563 (mail-parse-charset gnus-newsgroup-charset)
2564 (mail-parse-ignored-charsets
2565 (save-excursion (condition-case nil
2566 (set-buffer gnus-summary-buffer)
2567 (error))
2568 gnus-newsgroup-ignored-charsets))
2569 (inhibit-read-only t)
2570 end start)
2571 (goto-char (point-min))
2572 (when (search-forward "\n\n" nil 'move)
2573 (forward-line -1))
2574 (setq end (point))
2575 (while (not (bobp))
2576 (while (progn
2577 (forward-line -1)
2578 (and (not (bobp))
2579 (memq (char-after) '(?\t ? )))))
2580 (setq start (point))
2581 (if (looking-at "\
2582 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2583 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2584 (funcall gnus-decode-address-function start end)
2585 (funcall gnus-decode-header-function start end))
2586 (goto-char (setq end start)))))
2588 (defun article-decode-group-name ()
2589 "Decode group names in Newsgroups, Followup-To and Xref headers."
2590 (let ((inhibit-point-motion-hooks t)
2591 (inhibit-read-only t)
2592 (method (gnus-find-method-for-group gnus-newsgroup-name))
2593 regexp)
2594 (when (and (or gnus-group-name-charset-method-alist
2595 gnus-group-name-charset-group-alist)
2596 (gnus-buffer-live-p gnus-original-article-buffer))
2597 (save-restriction
2598 (article-narrow-to-head)
2599 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2600 (with-current-buffer gnus-original-article-buffer
2601 (goto-char (point-min)))
2602 (setq regexp (concat "^" header
2603 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2604 (while (re-search-forward regexp nil t)
2605 (replace-match (save-match-data
2606 (gnus-decode-newsgroups
2607 ;; XXX how to use data in article buffer?
2608 (with-current-buffer gnus-original-article-buffer
2609 (re-search-forward regexp nil t)
2610 (match-string 1))
2611 gnus-newsgroup-name method))
2612 t t nil 1))
2613 (goto-char (point-min)))))))
2615 (autoload 'idna-to-unicode "idna")
2617 (defun article-decode-idna-rhs ()
2618 "Decode IDNA strings in RHS in various headers in current buffer.
2619 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2620 Mail-Reply-To: and Mail-Followup-To:."
2621 (when gnus-use-idna
2622 (save-restriction
2623 (let ((inhibit-point-motion-hooks t)
2624 (inhibit-read-only t))
2625 (article-narrow-to-head)
2626 (goto-char (point-min))
2627 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2628 (let (ace unicode)
2629 (when (save-match-data
2630 (and (setq ace (match-string 1))
2631 (save-excursion
2632 (and (re-search-backward "^[^ \t]" nil t)
2633 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2634 (setq unicode (idna-to-unicode ace))))
2635 (unless (string= ace unicode)
2636 (replace-match unicode nil nil nil 1)))))))))
2638 (defun article-de-quoted-unreadable (&optional force read-charset)
2639 "Translate a quoted-printable-encoded article.
2640 If FORCE, decode the article whether it is marked as quoted-printable
2641 or not.
2642 If READ-CHARSET, ask for a coding system."
2643 (interactive (list 'force current-prefix-arg))
2644 (save-excursion
2645 (let ((inhibit-read-only t) type charset)
2646 (if (gnus-buffer-live-p gnus-original-article-buffer)
2647 (with-current-buffer gnus-original-article-buffer
2648 (setq type
2649 (gnus-fetch-field "content-transfer-encoding"))
2650 (let* ((ct (gnus-fetch-field "content-type"))
2651 (ctl (and ct (mail-header-parse-content-type ct))))
2652 (setq charset (and ctl
2653 (mail-content-type-get ctl 'charset)))
2654 (if (stringp charset)
2655 (setq charset (intern (downcase charset)))))))
2656 (if read-charset
2657 (setq charset (mm-read-coding-system "Charset: " charset)))
2658 (unless charset
2659 (setq charset gnus-newsgroup-charset))
2660 (when (or force
2661 (and type (let ((case-fold-search t))
2662 (string-match "quoted-printable" type))))
2663 (article-goto-body)
2664 (quoted-printable-decode-region
2665 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2667 (defun article-de-base64-unreadable (&optional force read-charset)
2668 "Translate a base64 article.
2669 If FORCE, decode the article whether it is marked as base64 not.
2670 If READ-CHARSET, ask for a coding system."
2671 (interactive (list 'force current-prefix-arg))
2672 (save-excursion
2673 (let ((inhibit-read-only t) type charset)
2674 (if (gnus-buffer-live-p gnus-original-article-buffer)
2675 (with-current-buffer gnus-original-article-buffer
2676 (setq type
2677 (gnus-fetch-field "content-transfer-encoding"))
2678 (let* ((ct (gnus-fetch-field "content-type"))
2679 (ctl (and ct (mail-header-parse-content-type ct))))
2680 (setq charset (and ctl
2681 (mail-content-type-get ctl 'charset)))
2682 (if (stringp charset)
2683 (setq charset (intern (downcase charset)))))))
2684 (if read-charset
2685 (setq charset (mm-read-coding-system "Charset: " charset)))
2686 (unless charset
2687 (setq charset gnus-newsgroup-charset))
2688 (when (or force
2689 (and type (let ((case-fold-search t))
2690 (string-match "base64" type))))
2691 (article-goto-body)
2692 (save-restriction
2693 (narrow-to-region (point) (point-max))
2694 (base64-decode-region (point-min) (point-max))
2695 (mm-decode-coding-region
2696 (point-min) (point-max)
2697 (mm-charset-to-coding-system charset nil t)))))))
2699 (eval-when-compile
2700 (require 'rfc1843))
2702 (defun article-decode-HZ ()
2703 "Translate a HZ-encoded article."
2704 (interactive)
2705 (require 'rfc1843)
2706 (save-excursion
2707 (let ((inhibit-read-only t))
2708 (rfc1843-decode-region (point-min) (point-max)))))
2710 (defun article-unsplit-urls ()
2711 "Remove the newlines that some other mailers insert into URLs."
2712 (interactive)
2713 (save-excursion
2714 (let ((inhibit-read-only t))
2715 (goto-char (point-min))
2716 (while (re-search-forward
2717 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2718 (replace-match "\\1\\3" t)))
2719 (when (gmm-called-interactively-p 'any)
2720 (gnus-treat-article nil))))
2722 (defun article-wash-html ()
2723 "Format an HTML article."
2724 (interactive)
2725 (let ((handles nil)
2726 (buffer-read-only nil))
2727 (when (gnus-buffer-live-p gnus-original-article-buffer)
2728 (with-current-buffer gnus-original-article-buffer
2729 (setq handles (mm-dissect-buffer t t))))
2730 (article-goto-body)
2731 (delete-region (point) (point-max))
2732 (mm-enable-multibyte)
2733 (mm-inline-text-html handles)))
2735 (defvar gnus-article-browse-html-temp-list nil
2736 "List of temporary files created by `gnus-article-browse-html-parts'.
2737 Internal variable.")
2739 (defcustom gnus-article-browse-delete-temp 'ask
2740 "What to do with temporary files from `gnus-article-browse-html-parts'.
2741 If nil, don't delete temporary files. If it is t, delete them on
2742 exit from the summary buffer. If it is the symbol `file', query
2743 on each file, if it is `ask' ask once when exiting from the
2744 summary buffer."
2745 :group 'gnus-article
2746 :version "23.1" ;; No Gnus
2747 :type '(choice (const :tag "Don't delete" nil)
2748 (const :tag "Don't ask" t)
2749 (const :tag "Ask" ask)
2750 (const :tag "Ask for each file" file)))
2752 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2754 (defun gnus-article-browse-delete-temp-files (&optional how)
2755 "Delete temp-files created by `gnus-article-browse-html-parts'."
2756 (when (and gnus-article-browse-html-temp-list
2757 (progn
2758 (or how (setq how gnus-article-browse-delete-temp))
2759 (if (eq how 'ask)
2760 (let ((files (length gnus-article-browse-html-temp-list)))
2761 (or (gnus-y-or-n-p
2762 (if (= files 1)
2763 "Delete the temporary HTML file? "
2764 (format "Delete all %s temporary HTML files? "
2765 files)))
2766 (setq gnus-article-browse-html-temp-list nil)))
2767 how)))
2768 (dolist (file gnus-article-browse-html-temp-list)
2769 (cond ((file-directory-p file)
2770 (when (or (not (eq how 'file))
2771 (gnus-y-or-n-p
2772 (format
2773 "Delete temporary HTML file(s) in directory `%s'? "
2774 (file-name-as-directory file))))
2775 (gnus-delete-directory file)))
2776 ((file-exists-p file)
2777 (when (or (not (eq how 'file))
2778 (gnus-y-or-n-p
2779 (format "Delete temporary HTML file `%s'? " file)))
2780 (delete-file file)))))
2781 ;; Also remove file from the list when not deleted or if file doesn't
2782 ;; exist anymore.
2783 (setq gnus-article-browse-html-temp-list nil))
2784 gnus-article-browse-html-temp-list)
2786 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2787 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2788 Return file name."
2789 (save-match-data
2790 (let (file type)
2791 (catch 'found
2792 (dolist (handle handles)
2793 (cond
2794 ((not (listp handle)))
2795 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2796 ;; may create.
2797 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2798 ((equal (mm-handle-media-supertype handle) "multipart")
2799 (when (setq file (gnus-article-browse-html-save-cid-content
2800 cid handle directory))
2801 (throw 'found file)))
2802 ((equal (concat "<" cid ">") (mm-handle-id handle))
2803 (setq file
2804 (expand-file-name
2805 (or (mm-handle-filename handle)
2806 (concat
2807 (make-temp-name "cid")
2808 (car (rassoc (car (mm-handle-type handle))
2809 mailcap-mime-extensions))))
2810 directory))
2811 (mm-save-part-to-file handle file)
2812 (throw 'found file))))))))
2814 (defun gnus-article-browse-html-parts (list &optional header)
2815 "View all \"text/html\" parts from LIST.
2816 Recurse into multiparts. The optional HEADER that should be a decoded
2817 message header will be added to the bodies of the \"text/html\" parts."
2818 ;; Internal function used by `gnus-article-browse-html-article'.
2819 (let (type file charset content cid-dir tmp-file showed)
2820 ;; Find and show the html-parts.
2821 (dolist (handle list)
2822 ;; If HTML, show it:
2823 (cond ((not (listp handle)))
2824 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2825 (and (equal (car type) "message/external-body")
2826 (or header
2827 (setq file (mm-handle-filename handle)))
2828 (or (mm-handle-cache handle)
2829 (condition-case code
2830 (progn (mm-extern-cache-contents handle) t)
2831 (error
2832 (gnus-message 3 "%s" (error-message-string code))
2833 (when (>= gnus-verbose 3) (sit-for 2))
2834 nil)))
2835 (progn
2836 (setq handle (mm-handle-cache handle)
2837 type (mm-handle-type handle))
2838 (equal (car type) "text/html"))))
2839 (setq charset (mail-content-type-get type 'charset)
2840 content (mm-get-part handle))
2841 (with-temp-buffer
2842 (if (eq charset 'gnus-decoded)
2843 (mm-enable-multibyte)
2844 (mm-disable-multibyte))
2845 (insert content)
2846 ;; resolve cid contents
2847 (let ((case-fold-search t)
2848 cid-file)
2849 (goto-char (point-min))
2850 (while (re-search-forward "\
2851 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2852 nil t)
2853 (unless cid-dir
2854 (setq cid-dir (mm-make-temp-file "cid" t))
2855 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2856 (setq file nil
2857 content nil)
2858 (when (setq cid-file
2859 (gnus-article-browse-html-save-cid-content
2860 (match-string 2)
2861 (with-current-buffer gnus-article-buffer
2862 gnus-article-mime-handles)
2863 cid-dir))
2864 (when (eq system-type 'cygwin)
2865 (setq cid-file
2866 (concat "/" (substring
2867 (with-output-to-string
2868 (call-process "cygpath" nil
2869 standard-output
2870 nil "-m" cid-file))
2871 0 -1))))
2872 (replace-match (concat "file://" cid-file)
2873 nil nil nil 1))))
2874 (unless content (setq content (buffer-string))))
2875 (when (or charset header (not file))
2876 (setq tmp-file (mm-make-temp-file
2877 ;; Do we need to care for 8.3 filenames?
2878 "mm-" nil ".html")))
2879 ;; Add a meta html tag to specify charset and a header.
2880 (cond
2881 (header
2882 (let (title eheader body hcharset coding)
2883 (with-temp-buffer
2884 (mm-enable-multibyte)
2885 (setq case-fold-search t)
2886 (insert header "\n")
2887 (setq title (message-fetch-field "subject"))
2888 (goto-char (point-min))
2889 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2890 nil t)
2891 (replace-match (cond ((match-beginning 1) "&lt;")
2892 ((match-beginning 2) "&gt;")
2893 ((match-beginning 3) "&amp;")
2894 (t "<br>\n"))))
2895 (goto-char (point-min))
2896 (while (re-search-forward "^[\t ]+" nil t)
2897 (dotimes (i (prog1
2898 (current-column)
2899 (delete-region (match-beginning 0)
2900 (match-end 0))))
2901 (insert "&nbsp;")))
2902 (goto-char (point-min))
2903 (insert "<div align=\"left\">\n")
2904 (goto-char (point-max))
2905 (insert "</div>\n<hr>\n")
2906 ;; We have to examine charset one by one since
2907 ;; charset specified in parts might be different.
2908 (if (eq charset 'gnus-decoded)
2909 (setq charset 'utf-8
2910 eheader (mm-encode-coding-string (buffer-string)
2911 charset)
2912 title (when title
2913 (mm-encode-coding-string title charset))
2914 body (mm-encode-coding-string content charset))
2915 (setq hcharset (mm-find-mime-charset-region (point-min)
2916 (point-max)))
2917 (cond ((= (length hcharset) 1)
2918 (setq hcharset (car hcharset)
2919 coding (mm-charset-to-coding-system
2920 hcharset nil t)))
2921 ((> (length hcharset) 1)
2922 (setq hcharset 'utf-8
2923 coding hcharset)))
2924 (if coding
2925 (if charset
2926 (progn
2927 (setq body
2928 (mm-charset-to-coding-system charset
2929 nil t))
2930 (if (eq coding body)
2931 (setq eheader (mm-encode-coding-string
2932 (buffer-string) coding)
2933 title (when title
2934 (mm-encode-coding-string
2935 title coding))
2936 body content)
2937 (setq charset 'utf-8
2938 eheader (mm-encode-coding-string
2939 (buffer-string) charset)
2940 title (when title
2941 (mm-encode-coding-string
2942 title charset))
2943 body (mm-encode-coding-string
2944 (mm-decode-coding-string
2945 content body)
2946 charset))))
2947 (setq charset hcharset
2948 eheader (mm-encode-coding-string
2949 (buffer-string) coding)
2950 title (when title
2951 (mm-encode-coding-string
2952 title coding))
2953 body content))
2954 (setq eheader (mm-string-as-unibyte (buffer-string))
2955 body content)))
2956 (erase-buffer)
2957 (mm-disable-multibyte)
2958 (insert body)
2959 (when charset
2960 (mm-add-meta-html-tag handle charset t))
2961 (when title
2962 (goto-char (point-min))
2963 (unless (search-forward "<title>" nil t)
2964 (re-search-forward "<head>\\s-*" nil t)
2965 (insert "<title>" title "</title>\n")))
2966 (goto-char (point-min))
2967 (or (re-search-forward
2968 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2969 (re-search-forward
2970 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2971 (insert eheader)
2972 (mm-write-region (point-min) (point-max)
2973 tmp-file nil nil nil 'binary t))))
2974 (charset
2975 (mm-with-unibyte-buffer
2976 (insert (if (eq charset 'gnus-decoded)
2977 (mm-encode-coding-string content
2978 (setq charset 'utf-8))
2979 content))
2980 (if (or (mm-add-meta-html-tag handle charset)
2981 (not file))
2982 (mm-write-region (point-min) (point-max)
2983 tmp-file nil nil nil 'binary t)
2984 (setq tmp-file nil))))
2985 (tmp-file
2986 (mm-save-part-to-file handle tmp-file)))
2987 (when tmp-file
2988 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2989 (add-hook 'gnus-summary-prepare-exit-hook
2990 'gnus-article-browse-delete-temp-files)
2991 (add-hook 'gnus-exit-gnus-hook
2992 (lambda ()
2993 (gnus-article-browse-delete-temp-files t)))
2994 ;; FIXME: Warn if there's an <img> tag?
2995 (browse-url-of-file (or tmp-file (expand-file-name file)))
2996 (setq showed t))
2997 ;; If multipart, recurse
2998 ((equal (mm-handle-media-supertype handle) "multipart")
2999 (when (gnus-article-browse-html-parts handle header)
3000 (setq showed t)))
3001 ((equal (mm-handle-media-type handle) "message/rfc822")
3002 (mm-with-multibyte-buffer
3003 (mm-insert-part handle)
3004 (setq handle (mm-dissect-buffer t t))
3005 (when (and (bufferp (car handle))
3006 (stringp (car (mm-handle-type handle))))
3007 (setq handle (list handle)))
3008 (when header
3009 (article-decode-encoded-words)
3010 (let ((gnus-visible-headers
3011 (or (get 'gnus-visible-headers 'standard-value)
3012 gnus-visible-headers)))
3013 (article-hide-headers))
3014 (goto-char (point-min))
3015 (search-forward "\n\n" nil 'move)
3016 (skip-chars-backward "\t\n ")
3017 (setq header (buffer-substring (point-min) (point)))))
3018 (when (prog1
3019 (gnus-article-browse-html-parts handle header)
3020 (mm-destroy-parts handle))
3021 (setq showed t)))))
3022 showed))
3024 (defun gnus-article-browse-html-article (&optional arg)
3025 "View \"text/html\" parts of the current article with a WWW browser.
3026 Inline images embedded in a message using the cid scheme, as they are
3027 generally considered to be safe, will be processed properly.
3028 The message header is added to the beginning of every html part unless
3029 the prefix argument ARG is given.
3031 Warning: Spammers use links to images (using the http scheme) in HTML
3032 articles to verify whether you have read the message. As
3033 `gnus-article-browse-html-article' passes the HTML content to the
3034 browser without eliminating these \"web bugs\" you should only
3035 use it for mails from trusted senders.
3037 If you always want to display HTML parts in the browser, set
3038 `mm-text-html-renderer' to nil.
3040 This command creates temporary files to pass HTML contents including
3041 images if any to the browser, and deletes them when exiting the group
3042 \(if you want)."
3043 ;; Cf. `mm-w3m-safe-url-regexp'
3044 (interactive "P")
3045 (if arg
3046 (gnus-summary-show-article)
3047 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3048 gnus-visible-headers))
3049 ;; As we insert a <hr>, there's no need for the body boundary.
3050 (gnus-treat-body-boundary nil))
3051 (gnus-summary-show-article)))
3052 (with-current-buffer gnus-article-buffer
3053 (let ((header (unless arg
3054 (save-restriction
3055 (widen)
3056 (buffer-substring-no-properties
3057 (goto-char (point-min))
3058 (if (search-forward "\n\n" nil t)
3059 (match-beginning 0)
3060 (goto-char (point-max))
3061 (skip-chars-backward "\t\n ")
3062 (point))))))
3063 parts)
3064 (set-buffer gnus-original-article-buffer)
3065 (setq parts (mm-dissect-buffer t t))
3066 ;; If singlepart, enforce a list.
3067 (when (and (bufferp (car parts))
3068 (stringp (car (mm-handle-type parts))))
3069 (setq parts (list parts)))
3070 ;; Process the list
3071 (unless (gnus-article-browse-html-parts parts header)
3072 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3073 (mm-destroy-parts parts)
3074 (unless arg
3075 (gnus-summary-show-article)))))
3077 (defun article-hide-list-identifiers ()
3078 "Remove list identifies from the Subject header.
3079 The `gnus-list-identifiers' variable specifies what to do."
3080 (interactive)
3081 (let ((inhibit-point-motion-hooks t)
3082 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3083 (inhibit-read-only t))
3084 (when regexp
3085 (save-excursion
3086 (save-restriction
3087 (article-narrow-to-head)
3088 (goto-char (point-min))
3089 (while (re-search-forward
3090 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3091 nil t)
3092 (delete-region (match-beginning 2) (match-end 0))
3093 (beginning-of-line))
3094 (when (re-search-forward
3095 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3096 (delete-region (match-beginning 1) (match-end 1))))))))
3098 (defun article-hide-pem (&optional arg)
3099 "Toggle hiding of any PEM headers and signatures in the current article.
3100 If given a negative prefix, always show; if given a positive prefix,
3101 always hide."
3102 (interactive (gnus-article-hidden-arg))
3103 (unless (gnus-article-check-hidden-text 'pem arg)
3104 (save-excursion
3105 (let ((inhibit-read-only t) end)
3106 (goto-char (point-min))
3107 ;; Hide the horrendously ugly "header".
3108 (when (and (search-forward
3109 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3110 nil t)
3111 (setq end (1+ (match-beginning 0))))
3112 (gnus-add-wash-type 'pem)
3113 (gnus-article-hide-text-type
3115 (if (search-forward "\n\n" nil t)
3116 (match-end 0)
3117 (point-max))
3118 'pem)
3119 ;; Hide the trailer as well
3120 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3121 nil t)
3122 (gnus-article-hide-text-type
3123 (match-beginning 0) (match-end 0) 'pem)))))))
3125 (defun article-strip-banner ()
3126 "Strip the banners specified by the `banner' group parameter and by
3127 `gnus-article-address-banner-alist'."
3128 (interactive)
3129 (save-excursion
3130 (save-restriction
3131 (let ((inhibit-point-motion-hooks t))
3132 (when (gnus-parameter-banner gnus-newsgroup-name)
3133 (article-really-strip-banner
3134 (gnus-parameter-banner gnus-newsgroup-name)))
3135 (when gnus-article-address-banner-alist
3136 ;; Note that the From header is decoded here, so it is
3137 ;; required that the *-extract-address-components function
3138 ;; supports non-ASCII text.
3139 (let ((from (save-restriction
3140 (widen)
3141 (article-narrow-to-head)
3142 (mail-fetch-field "from"))))
3143 (when (and from
3144 (setq from
3145 (cadr (funcall gnus-extract-address-components
3146 from))))
3147 (catch 'found
3148 (dolist (pair gnus-article-address-banner-alist)
3149 (when (string-match (car pair) from)
3150 (throw 'found
3151 (article-really-strip-banner (cdr pair)))))))))))))
3153 (defun article-really-strip-banner (banner)
3154 "Strip the banner specified by the argument."
3155 (save-excursion
3156 (save-restriction
3157 (let ((inhibit-point-motion-hooks t)
3158 (gnus-signature-limit nil)
3159 (inhibit-read-only t))
3160 (article-goto-body)
3161 (cond
3162 ((eq banner 'signature)
3163 (when (gnus-article-narrow-to-signature)
3164 (widen)
3165 (forward-line -1)
3166 (delete-region (point) (point-max))))
3167 ((symbolp banner)
3168 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3169 (while (re-search-forward banner nil t)
3170 (delete-region (match-beginning 0) (match-end 0)))))
3171 ((stringp banner)
3172 (while (re-search-forward banner nil t)
3173 (delete-region (match-beginning 0) (match-end 0)))))))))
3175 (defun article-babel ()
3176 "Translate article using an online translation service."
3177 (interactive)
3178 (require 'babel)
3179 (gnus-with-article-buffer
3180 (when (article-goto-body)
3181 (let* ((start (point))
3182 (end (point-max))
3183 (orig (buffer-substring start end))
3184 (trans (babel-as-string orig)))
3185 (save-restriction
3186 (narrow-to-region start end)
3187 (delete-region start end)
3188 (insert trans))))))
3190 (defun article-hide-signature (&optional arg)
3191 "Hide the signature in the current article.
3192 If given a negative prefix, always show; if given a positive prefix,
3193 always hide."
3194 (interactive (gnus-article-hidden-arg))
3195 (unless (gnus-article-check-hidden-text 'signature arg)
3196 (save-excursion
3197 (save-restriction
3198 (let ((inhibit-read-only t))
3199 (when (gnus-article-narrow-to-signature)
3200 (gnus-article-hide-text-type
3201 (point-min) (point-max) 'signature))))))
3202 (gnus-set-mode-line 'article))
3204 (defun article-strip-headers-in-body ()
3205 "Strip offensive headers from bodies."
3206 (interactive)
3207 (save-excursion
3208 (article-goto-body)
3209 (let ((case-fold-search t))
3210 (when (looking-at "x-no-archive:")
3211 (gnus-delete-line)))))
3213 (defun article-strip-leading-blank-lines ()
3214 "Remove all blank lines from the beginning of the article."
3215 (interactive)
3216 (save-excursion
3217 (let ((inhibit-point-motion-hooks t)
3218 (inhibit-read-only t))
3219 (when (article-goto-body)
3220 (while (and (not (eobp))
3221 (looking-at "[ \t]*$"))
3222 (gnus-delete-line))))))
3224 (defun article-narrow-to-head ()
3225 "Narrow the buffer to the head of the message.
3226 Point is left at the beginning of the narrowed-to region."
3227 (narrow-to-region
3228 (goto-char (point-min))
3229 (cond
3230 ;; Absolutely no headers displayed.
3231 ((looking-at "\n")
3232 (point))
3233 ;; Normal headers.
3234 ((search-forward "\n\n" nil 1)
3235 (1- (point)))
3236 ;; Nothing but headers.
3238 (point-max))))
3239 (goto-char (point-min)))
3241 (defun article-goto-body ()
3242 "Place point at the start of the body."
3243 (goto-char (point-min))
3244 (cond
3245 ;; This variable is only bound when dealing with separate
3246 ;; MIME body parts.
3247 (article-goto-body-goes-to-point-min-p
3249 ((search-forward "\n\n" nil t)
3252 (goto-char (point-max))
3253 nil)))
3255 (defun article-strip-multiple-blank-lines ()
3256 "Replace consecutive blank lines with one empty line."
3257 (interactive)
3258 (save-excursion
3259 (let ((inhibit-point-motion-hooks t)
3260 (inhibit-read-only t))
3261 ;; First make all blank lines empty.
3262 (article-goto-body)
3263 (while (re-search-forward "^[ \t]+$" nil t)
3264 (unless (gnus-annotation-in-region-p
3265 (match-beginning 0) (match-end 0))
3266 (replace-match "" nil t)))
3267 ;; Then replace multiple empty lines with a single empty line.
3268 (article-goto-body)
3269 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3270 (unless (gnus-annotation-in-region-p
3271 (match-beginning 0) (match-end 0))
3272 (delete-region (match-beginning 1) (match-end 1)))))))
3274 (defun article-strip-leading-space ()
3275 "Remove all white space from the beginning 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-trailing-space ()
3285 "Remove all white space from the end of the lines in the article."
3286 (interactive)
3287 (save-excursion
3288 (let ((inhibit-point-motion-hooks t)
3289 (inhibit-read-only t))
3290 (article-goto-body)
3291 (while (re-search-forward "[ \t]+$" nil t)
3292 (replace-match "" t t)))))
3294 (defun article-strip-blank-lines ()
3295 "Strip leading, trailing and multiple blank lines."
3296 (interactive)
3297 (article-strip-leading-blank-lines)
3298 (article-remove-trailing-blank-lines)
3299 (article-strip-multiple-blank-lines))
3301 (defun article-strip-all-blank-lines ()
3302 "Strip all blank lines."
3303 (interactive)
3304 (save-excursion
3305 (let ((inhibit-point-motion-hooks t)
3306 (inhibit-read-only t))
3307 (article-goto-body)
3308 (while (re-search-forward "^[ \t]*\n" nil t)
3309 (replace-match "" t t)))))
3311 (defun gnus-article-narrow-to-signature ()
3312 "Narrow to the signature; return t if a signature is found, else nil."
3313 (let ((inhibit-point-motion-hooks t))
3314 (when (gnus-article-search-signature)
3315 (forward-line 1)
3316 ;; Check whether we have some limits to what we consider
3317 ;; to be a signature.
3318 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3319 (list gnus-signature-limit)))
3320 limit limited)
3321 (while (setq limit (pop limits))
3322 (if (or (and (integerp limit)
3323 (< (- (point-max) (point)) limit))
3324 (and (floatp limit)
3325 (< (count-lines (point) (point-max)) limit))
3326 (and (functionp limit)
3327 (funcall limit))
3328 (and (stringp limit)
3329 (not (re-search-forward limit nil t))))
3330 () ; This limit did not succeed.
3331 (setq limited t
3332 limits nil)))
3333 (unless limited
3334 (narrow-to-region (point) (point-max))
3335 t)))))
3337 (defun gnus-article-search-signature ()
3338 "Search the current buffer for the signature separator.
3339 Put point at the beginning of the signature separator."
3340 (let ((cur (point)))
3341 (goto-char (point-max))
3342 (if (if (stringp gnus-signature-separator)
3343 (re-search-backward gnus-signature-separator nil t)
3344 (let ((seps gnus-signature-separator))
3345 (while (and seps
3346 (not (re-search-backward (car seps) nil t)))
3347 (pop seps))
3348 seps))
3350 (goto-char cur)
3351 nil)))
3353 (defun gnus-article-hidden-arg ()
3354 "Return the current prefix arg as a number, or 0 if no prefix."
3355 (list (if current-prefix-arg
3356 (prefix-numeric-value current-prefix-arg)
3357 0)))
3359 (defun gnus-article-check-hidden-text (type arg)
3360 "Return nil if hiding is necessary.
3361 Arg can be nil or a number. nil and positive means hide, negative
3362 means show, 0 means toggle."
3363 (save-excursion
3364 (save-restriction
3365 (let ((hide (gnus-article-hidden-text-p type)))
3366 (cond
3367 ((or (null arg)
3368 (> arg 0))
3369 nil)
3370 ((< arg 0)
3371 (gnus-article-show-hidden-text type)
3374 (if (eq hide 'hidden)
3375 (progn
3376 (gnus-article-show-hidden-text type)
3378 nil)))))))
3380 (defun gnus-article-hidden-text-p (type)
3381 "Say whether the current buffer contains hidden text of type TYPE."
3382 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3383 (while (and pos
3384 (not (get-text-property pos 'invisible))
3385 (not (get-text-property pos 'dummy-invisible)))
3386 (setq pos
3387 (text-property-any (1+ pos) (point-max) 'article-type type)))
3388 (if pos
3389 'hidden
3390 nil)))
3392 (defun gnus-article-show-hidden-text (type &optional dummy)
3393 "Show all hidden text of type TYPE.
3394 Originally it is hide instead of DUMMY."
3395 (let ((inhibit-read-only t)
3396 (inhibit-point-motion-hooks t))
3397 (gnus-remove-text-properties-when
3398 'article-type type
3399 (point-min) (point-max)
3400 (cons 'article-type (cons type
3401 gnus-hidden-properties)))
3402 (gnus-delete-wash-type type)))
3404 (defconst article-time-units
3405 `((year . ,(* 365.25 24 60 60))
3406 (week . ,(* 7 24 60 60))
3407 (day . ,(* 24 60 60))
3408 (hour . ,(* 60 60))
3409 (minute . 60)
3410 (second . 1))
3411 "Mapping from time units to seconds.")
3413 (defun gnus-article-forward-header ()
3414 "Move point to the start of the next header.
3415 If the current header is a continuation header, this can be several
3416 lines forward."
3417 (let ((ended nil))
3418 (while (not ended)
3419 (forward-line 1)
3420 (if (looking-at "[ \t]+[^ \t]")
3421 (forward-line 1)
3422 (setq ended t)))))
3424 (defun article-treat-date ()
3425 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3426 (with-current-buffer gnus-summary-buffer
3427 gnus-article-date-headers)
3428 gnus-article-date-headers)
3431 (defun article-date-ut (&optional type highlight date-position)
3432 "Convert DATE date to TYPE in the current article.
3433 The default type is `ut'. See `gnus-article-date-headers' for
3434 possible values."
3435 (interactive (list 'ut t))
3436 (let* ((case-fold-search t)
3437 (inhibit-read-only t)
3438 (inhibit-point-motion-hooks t)
3439 (first t)
3440 (visible-date (mail-fetch-field "Date"))
3441 pos date bface eface)
3442 (save-excursion
3443 (if date-position
3444 (progn
3445 (goto-char date-position)
3446 (setq date (get-text-property (point) 'original-date))
3447 (when (looking-at "[^:]+:[\t ]*")
3448 (setq bface (get-text-property (match-beginning 0) 'face)
3449 eface (get-text-property (match-end 0) 'face)))
3450 (delete-region (point)
3451 (progn
3452 (gnus-article-forward-header)
3453 (point)))
3454 (article-transform-date date type bface eface))
3455 (save-restriction
3456 (widen)
3457 (goto-char (point-min))
3458 (while (or (get-text-property (setq pos (point)) 'original-date)
3459 (and (setq pos (next-single-property-change
3460 (point) 'original-date))
3461 (goto-char pos)))
3462 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3463 (1+ (match-beginning 0))
3464 (point-max)))
3465 (while (setq pos (text-property-not-all pos (point-max)
3466 'gnus-date-type nil))
3467 (setq date (get-text-property pos 'original-date))
3468 (goto-char pos)
3469 (when (looking-at "[^:]+:[\t ]*")
3470 (setq bface (get-text-property (match-beginning 0) 'face)
3471 eface (get-text-property (match-end 0) 'face)))
3472 (delete-region pos (or (text-property-any pos (point-max)
3473 'gnus-date-type nil)
3474 (point-max))))
3475 (unless date ;; the 1st time
3476 (goto-char (point-min))
3477 (while (re-search-forward "^Date:[\t ]*" nil t)
3478 (setq date (get-text-property (match-beginning 0)
3479 'original-date)
3480 bface (get-text-property (match-beginning 0) 'face)
3481 eface (get-text-property (match-end 0) 'face))
3482 (delete-region (point-at-bol) (progn
3483 (gnus-article-forward-header)
3484 (point)))))
3485 (when (and (not date)
3486 visible-date)
3487 (setq date visible-date))
3488 (when date
3489 (article-transform-date date type bface eface))
3490 (goto-char (point-max))
3491 (widen)))))))
3493 (defun article-transform-date (date type bface eface)
3494 (dolist (this-type (cond
3495 ((null type)
3496 (list 'ut))
3497 ((atom type)
3498 (list type))
3500 type)))
3501 (goto-char
3502 (prog1
3503 (point)
3504 (add-text-properties
3505 (point)
3506 (progn
3507 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3508 (point))
3509 (list 'original-date date 'gnus-date-type this-type))))
3510 ;; Do highlighting.
3511 (when (looking-at
3512 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3513 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3514 (when (match-beginning 2)
3515 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3516 (while (and (zerop (forward-line 1))
3517 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3518 (when (match-beginning 1)
3519 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3521 (defun article-make-date-line (date type)
3522 "Return a DATE line of TYPE."
3523 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3524 combined-lapsed))
3525 (error "Unknown conversion type: %s" type))
3526 (condition-case ()
3527 (let ((time (ignore-errors (date-to-time date))))
3528 (cond
3529 ;; Convert to the local timezone.
3530 ((eq type 'local)
3531 (concat "Date: " (message-make-date time)))
3532 ;; Convert to Universal Time.
3533 ((eq type 'ut)
3534 (concat "Date: "
3535 (substring
3536 (message-make-date
3537 (let* ((e (parse-time-string date))
3538 (tm (apply 'encode-time e))
3539 (ms (car tm))
3540 (ls (- (cadr tm) (car (current-time-zone time)))))
3541 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3542 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3543 (t (list ms ls)))))
3544 0 -5)
3545 "UT"))
3546 ;; Get the original date from the article.
3547 ((eq type 'original)
3548 (concat "Date: " (if (string-match "\n+$" date)
3549 (substring date 0 (match-beginning 0))
3550 date)))
3551 ;; Let the user define the format.
3552 ((eq type 'user-defined)
3553 (let ((format (or (condition-case nil
3554 (with-current-buffer gnus-summary-buffer
3555 gnus-article-time-format)
3556 (error nil))
3557 gnus-article-time-format)))
3558 (if (functionp format)
3559 (funcall format time)
3560 (concat "Date: " (format-time-string format time)))))
3561 ;; ISO 8601.
3562 ((eq type 'iso8601)
3563 (let ((tz (car (current-time-zone time))))
3564 (concat
3565 "Date: "
3566 (format-time-string "%Y%m%dT%H%M%S" time)
3567 (format "%s%02d%02d"
3568 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3569 (/ (% (abs tz) 3600) 60)))))
3570 ;; Do a lapsed format.
3571 ((eq type 'lapsed)
3572 (concat "Date: " (article-lapsed-string time)))
3573 ;; A combined date/lapsed format.
3574 ((eq type 'combined-lapsed)
3575 (let ((date-string (article-make-date-line date 'original))
3576 (segments 3)
3577 lapsed-string)
3578 (while (and
3579 time
3580 (setq lapsed-string
3581 (concat " (" (article-lapsed-string time segments) ")"))
3582 (> (+ (length date-string)
3583 (length lapsed-string))
3584 (+ fill-column 6))
3585 (> segments 0))
3586 (setq segments (1- segments)))
3587 (if (> segments 0)
3588 (concat date-string lapsed-string)
3589 date-string)))
3590 ;; Display the date in proper English
3591 ((eq type 'english)
3592 (let ((dtime (decode-time time)))
3593 (concat
3594 "Date: the "
3595 (number-to-string (nth 3 dtime))
3596 (let ((digit (% (nth 3 dtime) 10)))
3597 (cond
3598 ((memq (nth 3 dtime) '(11 12 13)) "th")
3599 ((= digit 1) "st")
3600 ((= digit 2) "nd")
3601 ((= digit 3) "rd")
3602 (t "th")))
3603 " of "
3604 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3606 (number-to-string (nth 5 dtime))
3607 " at "
3608 (format "%02d" (nth 2 dtime))
3610 (format "%02d" (nth 1 dtime)))))))
3611 (foo
3612 (format "Date: %s (from Gnus)" date))))
3614 (defun article-lapsed-string (time &optional max-segments)
3615 ;; If the date is seriously mangled, the timezone functions are
3616 ;; liable to bug out, so we ignore all errors.
3617 (let* ((now (current-time))
3618 (real-time (subtract-time now time))
3619 (real-sec (and real-time
3620 (+ (* (float (car real-time)) 65536)
3621 (cadr real-time))))
3622 (sec (and real-time (abs real-sec)))
3623 (segments 0)
3624 num prev)
3625 (unless max-segments
3626 (setq max-segments (length article-time-units)))
3627 (cond
3628 ((null real-time)
3629 "Unknown")
3630 ((zerop sec)
3631 "Now")
3633 (concat
3634 ;; This is a bit convoluted, but basically we go
3635 ;; through the time units for years, weeks, etc,
3636 ;; and divide things to see whether that results
3637 ;; in positive answers.
3638 (mapconcat
3639 (lambda (unit)
3640 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3641 (>= segments max-segments))
3642 ;; The (remaining) seconds are too few to
3643 ;; be divided into this time unit.
3645 ;; It's big enough, so we output it.
3646 (setq sec (- sec (* num (cdr unit))))
3647 (prog1
3648 (concat (if prev ", " "") (int-to-string
3649 (floor num))
3650 " " (symbol-name (car unit))
3651 (if (> num 1) "s" ""))
3652 (setq prev t
3653 segments (1+ segments)))))
3654 article-time-units "")
3655 ;; If dates are odd, then it might appear like the
3656 ;; article was sent in the future.
3657 (if (> real-sec 0)
3658 " ago"
3659 " in the future"))))))
3661 (defun article-date-local (&optional highlight)
3662 "Convert the current article date to the local timezone."
3663 (interactive (list t))
3664 (article-date-ut 'local highlight))
3666 (defun article-date-english (&optional highlight)
3667 "Convert the current article date to something that is proper English."
3668 (interactive (list t))
3669 (article-date-ut 'english highlight))
3671 (defun article-date-original (&optional highlight)
3672 "Convert the current article date to what it was originally.
3673 This is only useful if you have used some other date conversion
3674 function and want to see what the date was before converting."
3675 (interactive (list t))
3676 (article-date-ut 'original highlight))
3678 (defun article-date-lapsed (&optional highlight)
3679 "Convert the current article date to time lapsed since it was sent."
3680 (interactive (list t))
3681 (article-date-ut 'lapsed highlight))
3683 (defun article-date-combined-lapsed (&optional highlight)
3684 "Convert the current article date to time lapsed since it was sent."
3685 (interactive (list t))
3686 (article-date-ut 'combined-lapsed highlight))
3688 (defun article-update-date-lapsed ()
3689 "Function to be run from a timer to update the lapsed time line."
3690 (save-match-data
3691 (let ((buffer (current-buffer)))
3692 (ignore-errors
3693 (walk-windows
3694 (lambda (w)
3695 (set-buffer (window-buffer w))
3696 (when (derived-mode-p 'gnus-article-mode)
3697 (let ((old-line (count-lines (point-min) (point)))
3698 (old-column (- (point) (line-beginning-position)))
3699 (window-start (window-start w))
3700 (pos (point-min))
3701 type next end)
3702 (while (setq pos (text-property-not-all pos (point-max)
3703 'gnus-date-type nil))
3704 (setq next (or (next-single-property-change pos
3705 'gnus-date-type)
3706 (point-max)))
3707 (setq type (get-text-property pos 'gnus-date-type))
3708 (when (memq type '(lapsed combined-lapsed user-defined))
3709 (article-date-ut type t pos)
3710 (setq end (or (next-single-property-change pos
3711 'gnus-date-type)
3712 (point-max)))
3713 (when window-start
3714 (if (/= window-start next)
3715 (setq window-start nil)
3716 (set-window-start w end)))
3717 (setq next end))
3718 (setq pos next))
3719 (goto-char (point-min))
3720 (when (> old-column 0)
3721 (setq old-line (1- old-line)))
3722 (forward-line old-line)
3723 (end-of-line)
3724 (when (> (current-column) old-column)
3725 (beginning-of-line)
3726 (forward-char old-column)))))
3727 nil 'visible))
3728 (set-buffer buffer))))
3730 (defun gnus-start-date-timer (&optional n)
3731 "Start a timer to update the Date headers in the article buffers.
3732 The numerical prefix says how frequently (in seconds) the function
3733 is to run."
3734 (interactive "p")
3735 (unless n
3736 (setq n 1))
3737 (gnus-stop-date-timer)
3738 (setq article-lapsed-timer
3739 (run-at-time 1 n 'article-update-date-lapsed)))
3741 (defun gnus-stop-date-timer ()
3742 "Stop the Date timer."
3743 (interactive)
3744 (when article-lapsed-timer
3745 (nnheader-cancel-timer article-lapsed-timer)
3746 (setq article-lapsed-timer nil)))
3748 (defun article-date-user (&optional highlight)
3749 "Convert the current article date to the user-defined format.
3750 This format is defined by the `gnus-article-time-format' variable."
3751 (interactive (list t))
3752 (article-date-ut 'user highlight))
3754 (defun article-date-iso8601 (&optional highlight)
3755 "Convert the current article date to ISO8601."
3756 (interactive (list t))
3757 (article-date-ut 'iso8601 highlight))
3759 (defmacro gnus-article-save-original-date (&rest forms)
3760 "Save the original date as a text property and evaluate FORMS."
3761 `(let* ((case-fold-search t)
3762 (start (progn
3763 (goto-char (point-min))
3764 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3765 (not (bolp)))
3766 (match-end 0))))
3767 (date (when (and start
3768 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3769 nil t))
3770 (buffer-substring-no-properties start
3771 (match-beginning 0)))))
3772 (goto-char (point-max))
3773 (skip-chars-backward "\n")
3774 (put-text-property (point-min) (point) 'original-date date)
3775 ,@forms
3776 (goto-char (point-max))
3777 (skip-chars-backward "\n")
3778 (put-text-property (point-min) (point) 'original-date date)))
3780 ;; (defun article-show-all ()
3781 ;; "Show all hidden text in the article buffer."
3782 ;; (interactive)
3783 ;; (save-excursion
3784 ;; (let ((inhibit-read-only t))
3785 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3787 (defun article-remove-leading-whitespace ()
3788 "Remove excessive whitespace from all headers."
3789 (interactive)
3790 (save-excursion
3791 (save-restriction
3792 (let ((inhibit-read-only t))
3793 (article-narrow-to-head)
3794 (goto-char (point-min))
3795 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3796 (delete-region (match-beginning 1) (match-end 1)))))))
3798 (defun article-emphasize (&optional arg)
3799 "Emphasize text according to `gnus-emphasis-alist'."
3800 (interactive (gnus-article-hidden-arg))
3801 (unless (gnus-article-check-hidden-text 'emphasis arg)
3802 (save-excursion
3803 (let ((alist (or
3804 (condition-case nil
3805 (with-current-buffer gnus-summary-buffer
3806 gnus-article-emphasis-alist)
3807 (error))
3808 gnus-emphasis-alist))
3809 (inhibit-read-only t)
3810 (props (append '(article-type emphasis)
3811 gnus-hidden-properties))
3812 regexp elem beg invisible visible face)
3813 (article-goto-body)
3814 (setq beg (point))
3815 (while (setq elem (pop alist))
3816 (goto-char beg)
3817 (setq regexp (car elem)
3818 invisible (nth 1 elem)
3819 visible (nth 2 elem)
3820 face (nth 3 elem))
3821 (while (re-search-forward regexp nil t)
3822 (when (and (match-beginning visible) (match-beginning invisible))
3823 (gnus-article-hide-text
3824 (match-beginning invisible) (match-end invisible) props)
3825 (gnus-article-unhide-text-type
3826 (match-beginning visible) (match-end visible) 'emphasis)
3827 (gnus-put-overlay-excluding-newlines
3828 (match-beginning visible) (match-end visible) 'face face)
3829 (gnus-add-wash-type 'emphasis)
3830 (goto-char (match-end invisible)))))))))
3832 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3833 "Setup newsgroup emphasis alist."
3834 (unless gnus-article-emphasis-alist
3835 (let ((name (and gnus-newsgroup-name
3836 (gnus-group-real-name gnus-newsgroup-name))))
3837 (make-local-variable 'gnus-article-emphasis-alist)
3838 (setq gnus-article-emphasis-alist
3839 (nconc
3840 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3841 (while (setq elem (pop alist))
3842 (when (and name (string-match (car elem) name))
3843 (setq alist nil
3844 highlight (copy-sequence (cdr elem)))))
3845 highlight)
3846 (copy-sequence highlight-words)
3847 (if gnus-newsgroup-name
3848 (copy-sequence (gnus-group-find-parameter
3849 gnus-newsgroup-name 'highlight-words t)))
3850 gnus-emphasis-alist)))))
3852 (defvar gnus-summary-article-menu)
3853 (defvar gnus-summary-post-menu)
3855 ;;; Saving functions.
3857 (defun gnus-article-save (save-buffer file &optional num)
3858 "Save the currently selected article."
3859 (when (or (get gnus-default-article-saver :headers)
3860 (not gnus-save-all-headers))
3861 ;; Remove headers according to `gnus-saved-headers' or the value
3862 ;; of the `:headers' property that the saver function might have.
3863 (let ((gnus-visible-headers
3864 (or (symbol-value (get gnus-default-article-saver :headers))
3865 gnus-saved-headers gnus-visible-headers))
3866 ;; Ignore group parameter. See `article-hide-headers'.
3867 (gnus-summary-buffer nil))
3868 (with-current-buffer save-buffer
3869 (article-hide-headers 1 t))))
3870 (save-window-excursion
3871 (if (not gnus-default-article-saver)
3872 (error "No default saver is defined")
3873 ;; !!! Magic! The saving functions all save
3874 ;; `gnus-save-article-buffer' (or so they think), but we
3875 ;; bind that variable to our save-buffer.
3876 (set-buffer gnus-article-buffer)
3877 (let* ((gnus-save-article-buffer save-buffer)
3878 (filename
3879 (cond
3880 ((not gnus-prompt-before-saving) 'default)
3881 ((eq gnus-prompt-before-saving 'always) nil)
3882 (t file)))
3883 (gnus-number-of-articles-to-be-saved
3884 (when (eq gnus-prompt-before-saving t)
3885 num))) ; Magic
3886 (set-buffer gnus-article-current-summary)
3887 (funcall gnus-default-article-saver filename)))))
3889 (defun gnus-read-save-file-name (prompt &optional filename
3890 function group headers variable
3891 dir-var)
3892 (let ((default-name
3893 (funcall function group headers (symbol-value variable)))
3894 result)
3895 (setq result
3896 (expand-file-name
3897 (cond
3898 ((eq filename 'default)
3899 default-name)
3900 ((eq filename t)
3901 default-name)
3902 (filename filename)
3904 (when (symbol-value dir-var)
3905 (setq default-name (expand-file-name
3906 (file-name-nondirectory default-name)
3907 (symbol-value dir-var))))
3908 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3909 (prompt
3910 (format prompt
3911 (if (and gnus-number-of-articles-to-be-saved
3912 (> gnus-number-of-articles-to-be-saved 1))
3913 (format "these %d articles"
3914 gnus-number-of-articles-to-be-saved)
3915 "this article")))
3916 (file
3917 ;; Let the split methods have their say.
3918 (cond
3919 ;; No split name was found.
3920 ((null split-name)
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 group name is returned.
3927 ((stringp split-name)
3928 (setq default-name
3929 (funcall function split-name headers
3930 (symbol-value variable)))
3931 (read-file-name
3932 (concat prompt " (default "
3933 (file-name-nondirectory default-name) "): ")
3934 (file-name-directory default-name)
3935 default-name))
3936 ;; A single split name was found
3937 ((= 1 (length split-name))
3938 (let* ((name (expand-file-name
3939 (car split-name)
3940 gnus-article-save-directory))
3941 (dir (cond ((file-directory-p name)
3942 (file-name-as-directory name))
3943 ((file-exists-p name) name)
3944 (t gnus-article-save-directory))))
3945 (read-file-name
3946 (concat prompt " (default " name "): ")
3947 dir name)))
3948 ;; A list of splits was found.
3950 (setq split-name (nreverse split-name))
3951 (let (result)
3952 (let ((file-name-history
3953 (nconc split-name file-name-history)))
3954 (setq result
3955 (expand-file-name
3956 (read-file-name
3957 (concat prompt " (`M-p' for defaults): ")
3958 gnus-article-save-directory
3959 (car split-name))
3960 gnus-article-save-directory)))
3961 (car (push result file-name-history)))))))
3962 ;; Create the directory.
3963 (gnus-make-directory (file-name-directory file))
3964 ;; If we have read a directory, we append the default file name.
3965 (when (file-directory-p file)
3966 (setq file (expand-file-name (file-name-nondirectory
3967 default-name)
3968 (file-name-as-directory file))))
3969 ;; Possibly translate some characters.
3970 (nnheader-translate-file-chars file))))))
3971 (gnus-make-directory (file-name-directory result))
3972 (when variable
3973 (set variable result))
3974 (when dir-var
3975 (set dir-var (file-name-directory result)))
3976 result))
3978 (defun gnus-article-archive-name (group)
3979 "Return the first instance of an \"Archive-name\" in the current buffer."
3980 (let ((case-fold-search t))
3981 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3982 (nnheader-concat gnus-article-save-directory
3983 (match-string 1)))))
3985 (defun gnus-article-nndoc-name (group)
3986 "If GROUP is an nndoc group, return the name of the parent group."
3987 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3988 (gnus-group-get-parameter group 'save-article-group)))
3990 (defun gnus-summary-save-in-rmail (&optional filename)
3991 "Append this article to Rmail file.
3992 Optional argument FILENAME specifies file name.
3993 Directory to save to is default to `gnus-article-save-directory'."
3994 (setq filename (gnus-read-save-file-name
3995 "Save %s in rmail file" filename
3996 gnus-rmail-save-name gnus-newsgroup-name
3997 gnus-current-headers 'gnus-newsgroup-last-rmail))
3998 (with-current-buffer gnus-save-article-buffer
3999 (save-excursion
4000 (save-restriction
4001 (widen)
4002 ;; Note that unlike gnus-summary-save-in-mail, there is no
4003 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4004 ;; not use Babyl.
4005 (gnus-output-to-rmail filename))))
4006 filename)
4008 (defun gnus-summary-save-in-mail (&optional filename)
4009 "Append this article to Unix mail file.
4010 Optional argument FILENAME specifies file name.
4011 Directory to save to is default to `gnus-article-save-directory'."
4012 (setq filename (gnus-read-save-file-name
4013 "Save %s in Unix mail file" filename
4014 gnus-mail-save-name gnus-newsgroup-name
4015 gnus-current-headers 'gnus-newsgroup-last-mail))
4016 (with-current-buffer gnus-save-article-buffer
4017 (save-excursion
4018 (save-restriction
4019 (widen)
4020 (if (and (file-readable-p filename)
4021 (file-regular-p filename)
4022 (mail-file-babyl-p filename))
4023 (gnus-output-to-rmail filename)
4024 (gnus-output-to-mail filename)))))
4025 filename)
4027 (put 'gnus-summary-save-in-file :decode t)
4028 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4029 (defun gnus-summary-save-in-file (&optional filename overwrite)
4030 "Append this article to file.
4031 Optional argument FILENAME specifies file name.
4032 Directory to save to is default to `gnus-article-save-directory'."
4033 (setq filename (gnus-read-save-file-name
4034 "Save %s in file" filename
4035 gnus-file-save-name gnus-newsgroup-name
4036 gnus-current-headers 'gnus-newsgroup-last-file))
4037 (with-current-buffer gnus-save-article-buffer
4038 (save-excursion
4039 (save-restriction
4040 (widen)
4041 (when (and overwrite
4042 (file-exists-p filename))
4043 (delete-file filename))
4044 (gnus-output-to-file filename))))
4045 filename)
4047 (put 'gnus-summary-write-to-file :decode t)
4048 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4049 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4050 (defun gnus-summary-write-to-file (&optional filename)
4051 "Write this article to a file, overwriting it if the file exists.
4052 Optional argument FILENAME specifies file name.
4053 The directory to save in defaults to `gnus-article-save-directory'."
4054 (setq filename (gnus-read-save-file-name
4055 "Save %s in file" filename
4056 gnus-file-save-name gnus-newsgroup-name
4057 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4058 (gnus-summary-save-in-file filename t))
4060 (put 'gnus-summary-save-body-in-file :decode t)
4061 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4062 "Append this article body to a file.
4063 Optional argument FILENAME specifies file name.
4064 The directory to save in defaults to `gnus-article-save-directory'."
4065 (setq filename (gnus-read-save-file-name
4066 "Save %s body in file" filename
4067 gnus-file-save-name gnus-newsgroup-name
4068 gnus-current-headers 'gnus-newsgroup-last-file))
4069 (with-current-buffer gnus-save-article-buffer
4070 (save-excursion
4071 (save-restriction
4072 (widen)
4073 (when (article-goto-body)
4074 (narrow-to-region (point) (point-max)))
4075 (when (and overwrite
4076 (file-exists-p filename))
4077 (delete-file filename))
4078 (gnus-output-to-file filename))))
4079 filename)
4081 (put 'gnus-summary-write-body-to-file :decode t)
4082 (put 'gnus-summary-write-body-to-file
4083 :function 'gnus-summary-save-body-in-file)
4084 (defun gnus-summary-write-body-to-file (&optional filename)
4085 "Write this article body to a file, overwriting it if the file exists.
4086 Optional argument FILENAME specifies file name.
4087 The directory to save in defaults to `gnus-article-save-directory'."
4088 (setq filename (gnus-read-save-file-name
4089 "Save %s body in file" filename
4090 gnus-file-save-name gnus-newsgroup-name
4091 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4092 (gnus-summary-save-body-in-file filename t))
4094 (put 'gnus-summary-save-in-pipe :decode t)
4095 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4096 (defun gnus-summary-save-in-pipe (&optional command raw)
4097 "Pipe this article to subprocess COMMAND.
4098 Valid values for COMMAND include:
4099 a string
4100 The executable command name and possibly arguments.
4102 You will be prompted for the command in the minibuffer.
4103 the symbol `default'
4104 It will be replaced with the command which the variable
4105 `gnus-summary-pipe-output-default-command' holds or the command
4106 last used for saving.
4107 Non-nil value for RAW overrides `:decode' and `:headers' properties
4108 and the raw article including all headers will be piped."
4109 (let ((article (gnus-summary-article-number))
4110 (decode (unless raw
4111 (get 'gnus-summary-save-in-pipe :decode)))
4112 save-buffer default)
4113 (if article
4114 (if (vectorp (gnus-summary-article-header article))
4115 (save-current-buffer
4116 (gnus-summary-select-article decode decode nil article)
4117 (insert-buffer-substring
4118 (prog1
4119 (if decode
4120 gnus-article-buffer
4121 gnus-original-article-buffer)
4122 (setq save-buffer
4123 (nnheader-set-temp-buffer " *Gnus Save*"))))
4124 ;; Remove unwanted headers.
4125 (when (and (not raw)
4126 (or (get 'gnus-summary-save-in-pipe :headers)
4127 (not gnus-save-all-headers)))
4128 (let ((gnus-visible-headers
4129 (or (symbol-value (get 'gnus-summary-save-in-pipe
4130 :headers))
4131 gnus-saved-headers gnus-visible-headers))
4132 (gnus-summary-buffer nil))
4133 (article-hide-headers 1 t))))
4134 (error "%d is not a real article" article))
4135 (error "No article to pipe"))
4136 (setq default (or gnus-summary-pipe-output-default-command
4137 gnus-last-shell-command))
4138 (unless (stringp command)
4139 (setq command
4140 (if (and (eq command 'default) default)
4141 default
4142 (gnus-read-shell-command "Shell command on this article: "
4143 default))))
4144 (when (string-equal command "")
4145 (if default
4146 (setq command default)
4147 (error "A command is required")))
4148 (with-current-buffer save-buffer
4149 (save-restriction
4150 (widen)
4151 (shell-command-on-region (point-min) (point-max) command nil)))
4152 (gnus-kill-buffer save-buffer))
4153 (setq gnus-summary-pipe-output-default-command command))
4155 (defun gnus-summary-pipe-to-muttprint (&optional command)
4156 "Pipe this article to muttprint."
4157 (unless (stringp command)
4158 (setq command (read-string
4159 "Print using command: " gnus-summary-muttprint-program
4160 nil gnus-summary-muttprint-program)))
4161 (let ((gnus-summary-pipe-output-default-command
4162 gnus-summary-pipe-output-default-command))
4163 (gnus-summary-save-in-pipe command))
4164 (setq gnus-summary-muttprint-program command))
4166 ;;; Article file names when saving.
4168 (defun gnus-capitalize-newsgroup (newsgroup)
4169 "Capitalize NEWSGROUP name."
4170 (when (not (zerop (length newsgroup)))
4171 (concat (char-to-string (upcase (aref newsgroup 0)))
4172 (substring newsgroup 1))))
4174 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4175 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4176 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4177 Otherwise, it is like ~/News/news/group/num."
4178 (let ((default
4179 (expand-file-name
4180 (concat (if (gnus-use-long-file-name 'not-save)
4181 (gnus-capitalize-newsgroup newsgroup)
4182 (gnus-newsgroup-directory-form newsgroup))
4183 "/" (int-to-string (mail-header-number headers)))
4184 gnus-article-save-directory)))
4185 (if (and last-file
4186 (string-equal (file-name-directory default)
4187 (file-name-directory last-file))
4188 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4189 default
4190 (or last-file default))))
4192 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4193 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4194 If variable `gnus-use-long-file-name' is non-nil, it is
4195 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4196 (let ((default
4197 (expand-file-name
4198 (concat (if (gnus-use-long-file-name 'not-save)
4199 newsgroup
4200 (gnus-newsgroup-directory-form newsgroup))
4201 "/" (int-to-string (mail-header-number headers)))
4202 gnus-article-save-directory)))
4203 (if (and last-file
4204 (string-equal (file-name-directory default)
4205 (file-name-directory last-file))
4206 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4207 default
4208 (or last-file default))))
4210 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4211 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4212 If variable `gnus-use-long-file-name' is non-nil, it is
4213 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4214 (or last-file
4215 (expand-file-name
4216 (if (gnus-use-long-file-name 'not-save)
4217 newsgroup
4218 (file-relative-name
4219 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4220 default-directory))
4221 gnus-article-save-directory)))
4223 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4224 "Generate file name from sender."
4225 (let ((from (mail-header-from headers)))
4226 (expand-file-name
4227 (if (and from (string-match "\\([^ <]+\\)@" from))
4228 (match-string 1 from)
4229 "nobody")
4230 gnus-article-save-directory)))
4232 (defun article-verify-x-pgp-sig ()
4233 "Verify X-PGP-Sig."
4234 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4235 (interactive)
4236 (if (gnus-buffer-live-p gnus-original-article-buffer)
4237 (let ((sig (with-current-buffer gnus-original-article-buffer
4238 (gnus-fetch-field "X-PGP-Sig")))
4239 items info headers)
4240 (when (and sig
4241 mml2015-use
4242 (mml2015-clear-verify-function))
4243 (with-temp-buffer
4244 (insert-buffer-substring gnus-original-article-buffer)
4245 (setq items (split-string sig))
4246 (message-narrow-to-head)
4247 (let ((inhibit-point-motion-hooks t)
4248 (case-fold-search t))
4249 ;; Don't verify multiple headers.
4250 (setq headers (mapconcat (lambda (header)
4251 (concat header ": "
4252 (mail-fetch-field header)
4253 "\n"))
4254 (split-string (nth 1 items) ",") "")))
4255 (delete-region (point-min) (point-max))
4256 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4257 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4258 (insert headers)
4259 (widen)
4260 (forward-line)
4261 (while (not (eobp))
4262 (if (looking-at "^-")
4263 (insert "- "))
4264 (forward-line))
4265 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4266 (insert "Version: " (car items) "\n\n")
4267 (insert (mapconcat 'identity (cddr items) "\n"))
4268 (insert "\n-----END PGP SIGNATURE-----\n")
4269 (let ((mm-security-handle (list (format "multipart/signed"))))
4270 (mml2015-clean-buffer)
4271 (let ((coding-system-for-write (or gnus-newsgroup-charset
4272 'iso-8859-1)))
4273 (funcall (mml2015-clear-verify-function)))
4274 (setq info
4275 (or (mm-handle-multipart-ctl-parameter
4276 mm-security-handle 'gnus-details)
4277 (mm-handle-multipart-ctl-parameter
4278 mm-security-handle 'gnus-info)))))
4279 (when info
4280 (let ((inhibit-read-only t) bface eface)
4281 (save-restriction
4282 (message-narrow-to-head)
4283 (goto-char (point-max))
4284 (forward-line -1)
4285 (setq bface (get-text-property (point-at-bol) 'face)
4286 eface (get-text-property (1- (point-at-eol)) 'face))
4287 (message-remove-header "X-Gnus-PGP-Verify")
4288 (if (re-search-forward "^X-PGP-Sig:" nil t)
4289 (forward-line)
4290 (goto-char (point-max)))
4291 (narrow-to-region (point) (point))
4292 (insert "X-Gnus-PGP-Verify: " info "\n")
4293 (goto-char (point-min))
4294 (forward-line)
4295 (while (not (eobp))
4296 (if (not (looking-at "^[ \t]"))
4297 (insert " "))
4298 (forward-line))
4299 ;; Do highlighting.
4300 (goto-char (point-min))
4301 (when (looking-at "\\([^:]+\\): *")
4302 (put-text-property (match-beginning 1) (1+ (match-end 1))
4303 'face bface)
4304 (put-text-property (match-end 0) (point-max)
4305 'face eface)))))))))
4307 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4309 (defun article-verify-cancel-lock ()
4310 "Verify Cancel-Lock header."
4311 (interactive)
4312 (if (gnus-buffer-live-p gnus-original-article-buffer)
4313 (canlock-verify gnus-original-article-buffer)))
4315 (eval-and-compile
4316 (mapc
4317 (lambda (func)
4318 (let (afunc gfunc)
4319 (if (consp func)
4320 (setq afunc (car func)
4321 gfunc (cdr func))
4322 (setq afunc func
4323 gfunc (intern (format "gnus-%s" func))))
4324 (defalias gfunc
4325 (when (fboundp afunc)
4326 `(lambda (&optional interactive &rest args)
4327 ,(documentation afunc t)
4328 (interactive (list t))
4329 (with-current-buffer gnus-article-buffer
4330 (if interactive
4331 (call-interactively ',afunc)
4332 (apply ',afunc args))))))))
4333 '(article-hide-headers
4334 article-verify-x-pgp-sig
4335 article-verify-cancel-lock
4336 article-hide-boring-headers
4337 article-treat-overstrike
4338 article-treat-ansi-sequences
4339 article-fill-long-lines
4340 article-capitalize-sentences
4341 article-remove-cr
4342 article-remove-leading-whitespace
4343 article-display-x-face
4344 article-display-face
4345 article-de-quoted-unreadable
4346 article-de-base64-unreadable
4347 article-decode-HZ
4348 article-wash-html
4349 article-unsplit-urls
4350 article-hide-list-identifiers
4351 article-strip-banner
4352 article-babel
4353 article-hide-pem
4354 article-hide-signature
4355 article-strip-headers-in-body
4356 article-remove-trailing-blank-lines
4357 article-strip-leading-blank-lines
4358 article-strip-multiple-blank-lines
4359 article-strip-leading-space
4360 article-strip-trailing-space
4361 article-strip-blank-lines
4362 article-strip-all-blank-lines
4363 article-date-local
4364 article-date-english
4365 article-date-iso8601
4366 article-date-original
4367 article-treat-date
4368 article-date-ut
4369 article-decode-mime-words
4370 article-decode-charset
4371 article-decode-encoded-words
4372 article-date-user
4373 article-date-lapsed
4374 article-date-combined-lapsed
4375 article-emphasize
4376 article-treat-dumbquotes
4377 article-treat-non-ascii
4378 article-normalize-headers
4379 ;;(article-show-all . gnus-article-show-all-headers)
4383 ;;; Gnus article mode
4386 (put 'gnus-article-mode 'mode-class 'special)
4388 (set-keymap-parent gnus-article-mode-map widget-keymap)
4390 (gnus-define-keys gnus-article-mode-map
4391 " " gnus-article-goto-next-page
4392 [?\S-\ ] gnus-article-goto-prev-page
4393 "\177" gnus-article-goto-prev-page
4394 [delete] gnus-article-goto-prev-page
4395 "\C-c^" gnus-article-refer-article
4396 "h" gnus-article-show-summary
4397 "s" gnus-article-show-summary
4398 "\C-c\C-m" gnus-article-mail
4399 "?" gnus-article-describe-briefly
4400 "<" beginning-of-buffer
4401 ">" end-of-buffer
4402 "\C-c\C-i" gnus-info-find-node
4403 "\C-c\C-b" gnus-bug
4404 "R" gnus-article-reply-with-original
4405 "F" gnus-article-followup-with-original
4406 "\C-hk" gnus-article-describe-key
4407 "\C-hc" gnus-article-describe-key-briefly
4408 "\C-hb" gnus-article-describe-bindings
4410 "e" gnus-article-read-summary-keys
4411 "\C-d" gnus-article-read-summary-keys
4412 "\M-*" gnus-article-read-summary-keys
4413 "\M-#" gnus-article-read-summary-keys
4414 "\M-^" gnus-article-read-summary-keys
4415 "\M-g" gnus-article-read-summary-keys)
4417 (substitute-key-definition
4418 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4420 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4421 "W" gnus-article-wide-reply-with-original)
4422 (if (featurep 'xemacs)
4423 (set-keymap-default-binding gnus-article-send-map
4424 'gnus-article-read-summary-send-keys)
4425 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4427 (defun gnus-article-make-menu-bar ()
4428 (unless (boundp 'gnus-article-commands-menu)
4429 (gnus-summary-make-menu-bar))
4430 (unless (boundp 'gnus-article-article-menu)
4431 (easy-menu-define
4432 gnus-article-article-menu gnus-article-mode-map ""
4433 '("Article"
4434 ["Scroll forwards" gnus-article-goto-next-page t]
4435 ["Scroll backwards" gnus-article-goto-prev-page t]
4436 ["Show summary" gnus-article-show-summary t]
4437 ["Fetch Message-ID at point" gnus-article-refer-article t]
4438 ["Mail to address at point" gnus-article-mail t]
4439 ["Send a bug report" gnus-bug t]))
4441 (easy-menu-define
4442 gnus-article-treatment-menu gnus-article-mode-map ""
4443 ;; Fixme: this should use :active (and maybe :visible).
4444 '("Treatment"
4445 ["Hide headers" gnus-article-hide-headers t]
4446 ["Hide signature" gnus-article-hide-signature t]
4447 ["Hide citation" gnus-article-hide-citation t]
4448 ["Treat overstrike" gnus-article-treat-overstrike t]
4449 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4450 ["Remove carriage return" gnus-article-remove-cr t]
4451 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4452 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4453 ["Remove base64" gnus-article-de-base64-unreadable t]
4454 ["Treat html" gnus-article-wash-html t]
4455 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4456 ["Decode HZ" gnus-article-decode-HZ t]))
4458 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4460 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4462 (gnus-run-hooks 'gnus-article-menu-hook)))
4464 (defvar bookmark-make-record-function)
4465 (defvar shr-put-image-function)
4467 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4468 "Major mode for displaying an article.
4470 All normal editing commands are switched off.
4472 The following commands are available in addition to all summary mode
4473 commands:
4474 \\<gnus-article-mode-map>
4475 \\[gnus-article-next-page]\t Scroll the article one page forwards
4476 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4477 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4478 \\[gnus-article-show-summary]\t Display the summary buffer
4479 \\[gnus-article-mail]\t Send a reply to the address near point
4480 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4481 \\[gnus-info-find-node]\t Go to the Gnus info node"
4482 (gnus-simplify-mode-line)
4483 (make-local-variable 'minor-mode-alist)
4484 (when (gnus-visual-p 'article-menu 'menu)
4485 (gnus-article-make-menu-bar)
4486 (when gnus-summary-tool-bar-map
4487 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4488 (gnus-update-format-specifications nil 'article-mode)
4489 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4490 (set (make-local-variable 'gnus-page-broken) nil)
4491 (make-local-variable 'gnus-article-current-summary)
4492 (make-local-variable 'gnus-article-mime-handles)
4493 (make-local-variable 'gnus-article-decoded-p)
4494 (make-local-variable 'gnus-article-mime-handle-alist)
4495 (make-local-variable 'gnus-article-wash-types)
4496 (make-local-variable 'gnus-article-image-alist)
4497 (make-local-variable 'gnus-article-charset)
4498 (make-local-variable 'gnus-article-ignored-charsets)
4499 (set (make-local-variable 'bookmark-make-record-function)
4500 'gnus-summary-bookmark-make-record)
4501 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4502 ;; face.
4503 (set (make-local-variable 'nobreak-char-display) nil)
4504 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4505 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4506 (setq cursor-in-non-selected-windows nil)
4507 (gnus-set-default-directory)
4508 (buffer-disable-undo)
4509 (setq buffer-read-only t
4510 show-trailing-whitespace nil)
4511 (mm-enable-multibyte))
4513 (defun gnus-article-setup-buffer ()
4514 "Initialize the article buffer."
4515 (let* ((name (if gnus-single-article-buffer "*Article*"
4516 (concat "*Article "
4517 (gnus-group-decoded-name gnus-newsgroup-name)
4518 "*")))
4519 (original
4520 (progn (string-match "\\*Article" name)
4521 (concat " *Original Article"
4522 (substring name (match-end 0))))))
4523 (setq gnus-article-buffer name)
4524 (setq gnus-original-article-buffer original)
4525 (setq gnus-article-mime-handle-alist nil)
4526 (with-current-buffer gnus-summary-buffer
4527 ;; This might be a variable local to the summary buffer.
4528 (unless gnus-single-article-buffer
4529 (setq gnus-article-buffer name)
4530 (setq gnus-original-article-buffer original)
4531 (gnus-set-global-variables)))
4532 (gnus-article-setup-highlight-words)
4533 ;; Init original article buffer.
4534 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4535 (mm-enable-multibyte)
4536 (setq major-mode 'gnus-original-article-mode)
4537 (make-local-variable 'gnus-original-article))
4538 (if (and (get-buffer name)
4539 (with-current-buffer name
4540 (if gnus-article-edit-mode
4541 (if (y-or-n-p "Article mode edit in progress; discard? ")
4542 (progn
4543 (set-buffer-modified-p nil)
4544 (gnus-kill-buffer name)
4545 (message "")
4546 nil)
4547 (error "Action aborted"))
4548 t)))
4549 (let ((summary gnus-summary-buffer))
4550 (with-current-buffer name
4551 (set (make-local-variable 'gnus-article-edit-mode) nil)
4552 (gnus-article-stop-animations)
4553 (when gnus-article-mime-handles
4554 (mm-destroy-parts gnus-article-mime-handles)
4555 (setq gnus-article-mime-handles nil))
4556 ;; Set it to nil in article-buffer!
4557 (setq gnus-article-mime-handle-alist nil)
4558 (buffer-disable-undo)
4559 (setq buffer-read-only t)
4560 (unless (derived-mode-p 'gnus-article-mode)
4561 (gnus-article-mode))
4562 (set (make-local-variable 'gnus-summary-buffer) summary)
4563 (setq truncate-lines gnus-article-truncate-lines)
4564 (current-buffer)))
4565 (let ((summary gnus-summary-buffer))
4566 (with-current-buffer (gnus-get-buffer-create name)
4567 (gnus-article-mode)
4568 (setq truncate-lines gnus-article-truncate-lines)
4569 (set (make-local-variable 'gnus-summary-buffer) summary)
4570 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4571 (when article-lapsed-timer
4572 (gnus-stop-date-timer))
4573 (when gnus-article-update-date-headers
4574 (gnus-start-date-timer gnus-article-update-date-headers))
4575 (current-buffer))))))
4577 (defun gnus-article-stop-animations ()
4578 (dolist (timer (and (boundp 'timer-list)
4579 timer-list))
4580 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4581 (cancel-timer timer))))
4583 (defun gnus-stop-downloads ()
4584 (when (boundp 'url-queue)
4585 (set (intern "url-queue" obarray) nil)))
4587 ;; Set article window start at LINE, where LINE is the number of lines
4588 ;; from the head of the article.
4589 (defun gnus-article-set-window-start (&optional line)
4590 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4591 (when article-window
4592 (set-window-start
4593 article-window
4594 (with-current-buffer gnus-article-buffer
4595 (goto-char (point-min))
4596 (if (not line)
4597 (point-min)
4598 (gnus-message 6 "Moved to bookmark")
4599 (search-forward "\n\n" nil t)
4600 (forward-line line)
4601 (point)))))))
4603 (defun gnus-article-prepare (article &optional all-headers header)
4604 "Prepare ARTICLE in article mode buffer.
4605 ARTICLE should either be an article number or a Message-ID.
4606 If ARTICLE is an id, HEADER should be the article headers.
4607 If ALL-HEADERS is non-nil, no headers are hidden."
4608 (save-excursion
4609 ;; Make sure we start in a summary buffer.
4610 (unless (derived-mode-p 'gnus-summary-mode)
4611 (set-buffer gnus-summary-buffer))
4612 (setq gnus-summary-buffer (current-buffer))
4613 (let* ((gnus-article (if header (mail-header-number header) article))
4614 (summary-buffer (current-buffer))
4615 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4616 (group gnus-newsgroup-name)
4617 result)
4618 (save-excursion
4619 (gnus-article-setup-buffer)
4620 (set-buffer gnus-article-buffer)
4621 ;; Deactivate active regions.
4622 (when (and (boundp 'transient-mark-mode)
4623 transient-mark-mode)
4624 (setq mark-active nil))
4625 (if (not (setq result (let ((inhibit-read-only t))
4626 (gnus-request-article-this-buffer
4627 article group))))
4628 ;; There is no such article.
4629 (save-excursion
4630 (when (and (numberp article)
4631 (not (memq article gnus-newsgroup-sparse)))
4632 (setq gnus-article-current
4633 (cons gnus-newsgroup-name article))
4634 (set-buffer gnus-summary-buffer)
4635 (setq gnus-current-article article)
4636 (if (and (memq article gnus-newsgroup-undownloaded)
4637 (not (gnus-online (gnus-find-method-for-group
4638 gnus-newsgroup-name))))
4639 (progn
4640 (gnus-summary-set-agent-mark article)
4641 (message "Message marked for downloading"))
4642 (gnus-summary-mark-article article gnus-canceled-mark)
4643 (unless (memq article gnus-newsgroup-sparse)
4644 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4645 (if (or (eq result 'pseudo)
4646 (eq result 'nneething))
4647 (progn
4648 (with-current-buffer summary-buffer
4649 (push article gnus-newsgroup-history)
4650 (setq gnus-last-article gnus-current-article
4651 gnus-current-article 0
4652 gnus-current-headers nil
4653 gnus-article-current nil)
4654 (if (eq result 'nneething)
4655 (gnus-configure-windows 'summary)
4656 (gnus-configure-windows 'article))
4657 (gnus-set-global-variables))
4658 (let ((gnus-article-mime-handle-alist-1
4659 gnus-article-mime-handle-alist))
4660 (gnus-set-mode-line 'article)))
4661 ;; The result from the `request' was an actual article -
4662 ;; or at least some text that is now displayed in the
4663 ;; article buffer.
4664 (when (and (numberp article)
4665 (not (eq article gnus-current-article)))
4666 ;; Seems like a new article has been selected.
4667 ;; `gnus-current-article' must be an article number.
4668 (with-current-buffer summary-buffer
4669 (push article gnus-newsgroup-history)
4670 (setq gnus-last-article gnus-current-article
4671 gnus-current-article article
4672 gnus-current-headers
4673 (gnus-summary-article-header gnus-current-article)
4674 gnus-article-current
4675 (cons gnus-newsgroup-name gnus-current-article))
4676 (unless (vectorp gnus-current-headers)
4677 (setq gnus-current-headers nil))
4678 (gnus-summary-goto-subject gnus-current-article)
4679 (when (gnus-summary-show-thread)
4680 ;; If the summary buffer really was folded, the
4681 ;; previous goto may not actually have gone to
4682 ;; the right article, but the thread root instead.
4683 ;; So we go again.
4684 (gnus-summary-goto-subject gnus-current-article))
4685 (gnus-run-hooks 'gnus-mark-article-hook)
4686 (gnus-set-mode-line 'summary)
4687 (when (gnus-visual-p 'article-highlight 'highlight)
4688 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4689 ;; Set the global newsgroup variables here.
4690 (gnus-set-global-variables)
4691 (setq gnus-have-all-headers
4692 (or all-headers gnus-show-all-headers))))
4693 (save-excursion
4694 (gnus-configure-windows 'article))
4695 (when (or (numberp article)
4696 (stringp article))
4697 (gnus-article-prepare-display)
4698 ;; Do page break.
4699 (goto-char (point-min))
4700 (when gnus-break-pages
4701 (gnus-narrow-to-page)))
4702 (let ((gnus-article-mime-handle-alist-1
4703 gnus-article-mime-handle-alist))
4704 (gnus-set-mode-line 'article))
4705 (article-goto-body)
4706 (unless (bobp)
4707 (forward-line -1))
4708 (set-window-point (get-buffer-window (current-buffer)) (point))
4709 (gnus-configure-windows 'article)
4710 (gnus-run-hooks 'gnus-article-prepare-hook)
4711 t))))))
4713 ;;;###autoload
4714 (defun gnus-article-prepare-display ()
4715 "Make the current buffer look like a nice article."
4716 ;; Hooks for getting information from the article.
4717 ;; This hook must be called before being narrowed.
4718 (let ((gnus-article-buffer (current-buffer))
4719 buffer-read-only
4720 (inhibit-read-only t))
4721 (unless (derived-mode-p 'gnus-article-mode)
4722 (gnus-article-mode))
4723 (setq buffer-read-only nil
4724 gnus-article-wash-types nil
4725 gnus-article-image-alist nil)
4726 (gnus-run-hooks 'gnus-tmp-internal-hook)
4727 (when gnus-display-mime-function
4728 (funcall gnus-display-mime-function))
4729 ;; Add attachment buttons to the header.
4730 (when gnus-mime-display-attachment-buttons-in-header
4731 (gnus-mime-buttonize-attachments-in-header))))
4734 ;;; Gnus Sticky Article Mode
4737 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4738 "Mode for sticky articles."
4739 ;; Release bindings that won't work.
4740 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4741 gnus-sticky-article-mode-map)
4742 (substitute-key-definition 'gnus-article-refer-article 'undefined
4743 gnus-sticky-article-mode-map)
4744 (dolist (k '("e" "h" "s" "F" "R"))
4745 (define-key gnus-sticky-article-mode-map k nil))
4746 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4747 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4748 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4749 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4751 (defun gnus-sticky-article (arg)
4752 "Make the current article sticky.
4753 If a prefix ARG is given, ask for a name for this sticky article buffer."
4754 (interactive "P")
4755 (gnus-summary-show-thread)
4756 (gnus-summary-select-article nil nil 'pseudo)
4757 (let (new-art-buf-name)
4758 (gnus-eval-in-buffer-window gnus-article-buffer
4759 (setq new-art-buf-name
4760 (concat
4761 "*Sticky Article: "
4762 (if arg
4763 (read-from-minibuffer "Sticky article buffer name: ")
4764 (gnus-with-article-headers
4765 (gnus-article-goto-header "subject")
4766 (setq 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 "from")
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 (goto-char (point-min))
4777 (gnus-article-goto-header "date")
4778 (setq new-art-buf-name
4779 (concat
4780 new-art-buf-name ", "
4781 (buffer-substring-no-properties
4782 (line-beginning-position) (line-end-position))))))
4783 "*"))
4784 (if (and (gnus-buffer-live-p new-art-buf-name)
4785 (with-current-buffer new-art-buf-name
4786 (derived-mode-p 'gnus-sticky-article-mode)))
4787 (switch-to-buffer new-art-buf-name)
4788 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4789 (gnus-sticky-article-mode))
4790 (setq gnus-article-buffer new-art-buf-name))
4791 (gnus-summary-recenter)
4792 (gnus-summary-position-point))
4794 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4795 "Kill the given sticky article BUFFER.
4796 If none is given, assume the current buffer and kill it if it has
4797 `gnus-sticky-article-mode'."
4798 (interactive)
4799 (unless buffer
4800 (setq buffer (current-buffer)))
4801 (with-current-buffer buffer
4802 (when (derived-mode-p 'gnus-sticky-article-mode)
4803 (gnus-kill-buffer buffer))))
4805 (defun gnus-kill-sticky-article-buffers (arg)
4806 "Kill all sticky article buffers.
4807 If a prefix ARG is given, ask for confirmation."
4808 (interactive "P")
4809 (dolist (buf (gnus-buffers))
4810 (with-current-buffer buf
4811 (when (derived-mode-p 'gnus-sticky-article-mode)
4812 (if (not arg)
4813 (gnus-kill-buffer buf)
4814 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4815 (gnus-kill-buffer buf)))))))
4818 ;;; Gnus MIME viewing functions
4821 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4822 "Format of the MIME buttons.
4824 Valid specifiers include:
4825 %t The MIME type
4826 %T MIME type, along with additional info
4827 %n The `name' parameter
4828 %d The description, if any
4829 %l The length of the encoded part
4830 %p The part identifier number
4831 %e Dots if the part isn't displayed
4833 General format specifiers can also be used. See Info node
4834 `(gnus)Formatting Variables'.")
4836 (defvar gnus-mime-button-line-format-alist
4837 '((?t gnus-tmp-type ?s)
4838 (?T gnus-tmp-type-long ?s)
4839 (?n gnus-tmp-name ?s)
4840 (?d gnus-tmp-description ?s)
4841 (?p gnus-tmp-id ?s)
4842 (?l gnus-tmp-length ?d)
4843 (?e gnus-tmp-dots ?s)))
4845 (defvar gnus-mime-button-commands
4846 '((gnus-article-press-button "\r" "Toggle Display")
4847 (gnus-mime-view-part "v" "View Interactively...")
4848 (gnus-mime-view-part-as-type "t" "View As Type...")
4849 (gnus-mime-view-part-as-charset "C" "View As charset...")
4850 (gnus-mime-save-part "o" "Save...")
4851 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4852 (gnus-mime-replace-part "r" "Replace part")
4853 (gnus-mime-delete-part "d" "Delete part")
4854 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4855 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4856 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4857 (gnus-mime-view-part-externally "e" "View Externally")
4858 (gnus-mime-print-part "p" "Print")
4859 (gnus-mime-pipe-part "|" "Pipe To Command...")
4860 (gnus-mime-action-on-part "." "Take action on the part...")))
4862 (defun gnus-article-mime-part-status ()
4863 (if gnus-article-mime-handle-alist-1
4864 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4865 " (1 part)"
4866 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4867 ""))
4869 (defvar gnus-mime-button-map
4870 (let ((map (make-sparse-keymap)))
4871 (define-key map gnus-mouse-2 'gnus-article-push-button)
4872 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4873 (dolist (c gnus-mime-button-commands)
4874 (define-key map (cadr c) (car c)))
4875 map))
4877 (easy-menu-define
4878 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4879 `("MIME Part"
4880 ,@(mapcar (lambda (c)
4881 (vector (caddr c) (car c) :active t))
4882 gnus-mime-button-commands)))
4884 (defvar gnus-url-button-commands
4885 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4887 (defvar gnus-url-button-map
4888 (let ((map (make-sparse-keymap)))
4889 (dolist (c gnus-url-button-commands)
4890 (define-key map (cadr c) (car c)))
4891 map))
4893 (easy-menu-define
4894 gnus-url-button-menu gnus-url-button-map "URL button menu."
4895 `("Url Button"
4896 ,@(mapcar (lambda (c)
4897 (vector (caddr c) (car c) :active t))
4898 gnus-url-button-commands)))
4900 (defmacro gnus-bind-safe-url-regexp (&rest body)
4901 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4902 `(let ((mm-w3m-safe-url-regexp
4903 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4904 (gnus-buffer-live-p
4905 gnus-article-current-summary))
4906 (with-current-buffer gnus-article-current-summary
4907 gnus-newsgroup-name)
4908 gnus-newsgroup-name)))
4909 (if (cond ((not group)
4910 ;; Maybe we're in a mml-preview buffer
4911 ;; and no group is selected.
4913 ((stringp gnus-safe-html-newsgroups)
4914 (string-match gnus-safe-html-newsgroups group))
4915 ((consp gnus-safe-html-newsgroups)
4916 (member group gnus-safe-html-newsgroups)))
4918 mm-w3m-safe-url-regexp))))
4919 ,@body))
4921 (defun gnus-mime-button-menu (event prefix)
4922 "Construct a context-sensitive menu of MIME commands."
4923 (interactive "e\nP")
4924 (save-window-excursion
4925 (let ((pos (event-start event)))
4926 (select-window (posn-window pos))
4927 (goto-char (posn-point pos))
4928 (gnus-article-check-buffer)
4929 (popup-menu gnus-mime-button-menu nil prefix))))
4931 (defun gnus-mime-view-all-parts (&optional handles)
4932 "View all the MIME parts."
4933 (interactive)
4934 (with-current-buffer gnus-article-buffer
4935 (let ((handles (or handles gnus-article-mime-handles))
4936 (mail-parse-charset gnus-newsgroup-charset)
4937 (mail-parse-ignored-charsets
4938 (with-current-buffer gnus-summary-buffer
4939 gnus-newsgroup-ignored-charsets)))
4940 (when handles
4941 (mm-remove-parts handles)
4942 (goto-char (point-min))
4943 (or (search-forward "\n\n") (goto-char (point-max)))
4944 (let ((inhibit-read-only t))
4945 (delete-region (point) (point-max))
4946 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4948 (defun gnus-article-jump-to-part (n)
4949 "Jump to MIME part N."
4950 (interactive "P")
4951 (let ((parts (with-current-buffer gnus-article-buffer
4952 (length gnus-article-mime-handle-alist))))
4953 (when (zerop parts)
4954 (error "No such part"))
4955 (pop-to-buffer gnus-article-buffer)
4956 (or n
4957 (setq n (if (= parts 1)
4959 (read-number (format "Jump to part (1..%s): " parts)))))
4960 (unless (and (integerp n) (<= n parts) (>= n 1))
4961 (setq n
4962 (progn
4963 (gnus-message 7 "Invalid part `%s', using %s instead."
4964 n parts)
4965 parts)))
4966 (gnus-message 9 "Jumping to part %s." n)
4967 (cond ((>= gnus-auto-select-part 1)
4968 (while (and (<= n parts)
4969 (not (gnus-article-goto-part n)))
4970 (setq n (1+ n))))
4971 ((< gnus-auto-select-part 0)
4972 (while (and (>= n 1)
4973 (not (gnus-article-goto-part n)))
4974 (setq n (1- n))))
4976 (gnus-article-goto-part n)))))
4978 (defvar gnus-mime-buttonized-part-id nil
4979 "ID of a mime part that should be buttonized.
4980 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4982 (eval-when-compile
4983 (defsubst gnus-article-edit-part (handles &optional current-id)
4984 "Edit an article in order to delete a mime part.
4985 This function is exclusively used by `gnus-mime-save-part-and-strip'
4986 and `gnus-mime-delete-part', and not provided at run-time normally."
4987 (gnus-article-edit-article
4988 `(lambda ()
4989 (buffer-disable-undo)
4990 (erase-buffer)
4991 (let ((mail-parse-charset (or gnus-article-charset
4992 ',gnus-newsgroup-charset))
4993 (mail-parse-ignored-charsets
4994 (or gnus-article-ignored-charsets
4995 ',gnus-newsgroup-ignored-charsets))
4996 (mbl mml-buffer-list))
4997 (setq mml-buffer-list nil)
4998 (insert-buffer-substring gnus-original-article-buffer)
4999 (mime-to-mml ',handles)
5000 (setq gnus-article-mime-handles nil)
5001 (let ((mbl1 mml-buffer-list))
5002 (setq mml-buffer-list mbl)
5003 (set (make-local-variable 'mml-buffer-list) mbl1))
5004 (gnus-make-local-hook 'kill-buffer-hook)
5005 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5006 `(lambda (no-highlight)
5007 (let ((mail-parse-charset (or gnus-article-charset
5008 ',gnus-newsgroup-charset))
5009 (message-options message-options)
5010 (message-options-set-recipient)
5011 (mail-parse-ignored-charsets
5012 (or gnus-article-ignored-charsets
5013 ',gnus-newsgroup-ignored-charsets)))
5014 (mml-to-mime)
5015 (mml-destroy-buffers)
5016 (remove-hook 'kill-buffer-hook
5017 'mml-destroy-buffers t)
5018 (kill-local-variable 'mml-buffer-list))
5019 (gnus-summary-edit-article-done
5020 ,(or (mail-header-references gnus-current-headers) "")
5021 ,(gnus-group-read-only-p)
5022 ,gnus-summary-buffer no-highlight))
5024 ;; Force buttonizing this part.
5025 (let ((gnus-mime-buttonized-part-id current-id))
5026 (gnus-article-edit-done))
5027 (gnus-configure-windows 'article)
5028 (when (and current-id (integerp gnus-auto-select-part))
5029 (gnus-article-jump-to-part
5030 (min (max (+ current-id gnus-auto-select-part) 1)
5031 (with-current-buffer gnus-article-buffer
5032 (length gnus-article-mime-handle-alist)))))))
5034 (defun gnus-mime-replace-part (file)
5035 "Replace MIME part under point with an external body."
5036 ;; Useful if file has already been saved to disk
5037 (interactive
5038 (list
5039 (read-file-name "Replace MIME part with file: "
5040 (or mm-default-directory default-directory)
5041 nil nil)))
5042 (gnus-mime-save-part-and-strip file))
5044 (defun gnus-mime-save-part-and-strip (&optional file)
5045 "Save the MIME part under point then replace it with an external body.
5046 If FILE is given, use it for the external part."
5047 (interactive)
5048 (gnus-article-check-buffer)
5049 (when (gnus-group-read-only-p)
5050 (error "The current group does not support deleting of parts"))
5051 (when (mm-complicated-handles gnus-article-mime-handles)
5052 (error "\
5053 The current article has a complicated MIME structure, giving up..."))
5054 (let* ((data (get-text-property (point) 'gnus-data))
5055 (id (get-text-property (point) 'gnus-part))
5056 param
5057 (handles gnus-article-mime-handles))
5058 (unless file
5059 (setq file
5060 (and data (mm-save-part data "Delete MIME part and save to: "))))
5061 (when file
5062 (with-current-buffer (mm-handle-buffer data)
5063 (erase-buffer)
5064 (insert "Content-Type: " (mm-handle-media-type data))
5065 (mml-insert-parameter-string (cdr (mm-handle-type data))
5066 '(charset))
5067 ;; Add a filename for the sake of saving the part again.
5068 (mml-insert-parameter
5069 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5070 (insert "\n")
5071 (insert "Content-ID: " (message-make-message-id) "\n")
5072 (insert "Content-Transfer-Encoding: binary\n")
5073 (insert "\n"))
5074 (setcdr data
5075 (cdr (mm-make-handle nil
5076 `("message/external-body"
5077 (access-type . "LOCAL-FILE")
5078 (name . ,file)))))
5079 ;; (set-buffer gnus-summary-buffer)
5080 (gnus-article-edit-part handles id))))
5082 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5083 ;; parts...>') but with stripping would be nice.
5085 (defun gnus-mime-delete-part ()
5086 "Delete the MIME part under point.
5087 Replace it with some information about the removed part."
5088 (interactive)
5089 (gnus-article-check-buffer)
5090 (when (gnus-group-read-only-p)
5091 (error "The current group does not support deleting of parts"))
5092 (when (mm-complicated-handles gnus-article-mime-handles)
5093 (error "\
5094 The current article has a complicated MIME structure, giving up..."))
5095 (when (or gnus-expert-user
5096 (gnus-yes-or-no-p "\
5097 Deleting parts may malfunction or destroy the article; continue? "))
5098 (let* ((data (get-text-property (point) 'gnus-data))
5099 (id (get-text-property (point) 'gnus-part))
5100 (handles gnus-article-mime-handles)
5101 (description
5102 (let ((desc (mm-handle-description data)))
5103 (when desc
5104 (mail-decode-encoded-word-string desc))))
5105 (filename (or (mm-handle-filename data) "(none)"))
5106 (type (mm-handle-media-type data)))
5107 (unless data
5108 (error "No MIME part under point"))
5109 (with-current-buffer (mm-handle-buffer data)
5110 (let ((bsize (buffer-size)))
5111 (erase-buffer)
5112 (insert
5113 (concat
5114 ",----\n"
5115 "| The following attachment has been deleted:\n"
5116 "|\n"
5117 "| Type: " type "\n"
5118 "| Filename: " filename "\n"
5119 "| Size (encoded): " (format "%s byte%s\n"
5120 bsize (if (= bsize 1)
5122 "s"))
5123 (when description
5124 (concat "| Description: " description "\n"))
5125 "`----\n"))
5126 (setcdr data
5127 (cdr (mm-make-handle
5128 nil `("text/plain" (charset . gnus-decoded)) nil nil
5129 (list "attachment")
5130 (format "Deleted attachment (%s bytes)" bsize))))))
5131 ;; (set-buffer gnus-summary-buffer)
5132 (gnus-article-edit-part handles id))))
5134 (defun gnus-mime-save-part ()
5135 "Save the MIME part under point."
5136 (interactive)
5137 (gnus-article-check-buffer)
5138 (let ((data (get-text-property (point) 'gnus-data)))
5139 (when data
5140 (mm-save-part data))))
5142 (defun gnus-mime-pipe-part (&optional cmd)
5143 "Pipe the MIME part under point to a process.
5144 Use CMD as the process."
5145 (interactive)
5146 (gnus-article-check-buffer)
5147 (let ((data (get-text-property (point) 'gnus-data)))
5148 (when data
5149 (mm-pipe-part data cmd))))
5151 (defun gnus-mime-view-part ()
5152 "Interactively choose a viewing method for the MIME part under point."
5153 (interactive)
5154 (gnus-article-check-buffer)
5155 (let ((data (get-text-property (point) 'gnus-data)))
5156 (when data
5157 (setq gnus-article-mime-handles
5158 (mm-merge-handles
5159 gnus-article-mime-handles (setq data (copy-sequence data))))
5160 (mm-interactively-view-part data))))
5162 (defun gnus-mime-view-part-as-type-internal ()
5163 (gnus-article-check-buffer)
5164 (let* ((handle (get-text-property (point) 'gnus-data))
5165 (name (or
5166 ;; Content-Type: foo/bar; name=...
5167 (mail-content-type-get (mm-handle-type handle) 'name)
5168 ;; Content-Disposition: attachment; filename=...
5169 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5170 (def-type (and name (mm-default-file-encoding name))))
5171 (or (and def-type (cons def-type 0))
5172 (and handle
5173 (equal (mm-handle-media-supertype handle) "text")
5174 '("text/plain" . 0))
5175 '("application/octet-stream" . 0))))
5177 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5178 "Choose a MIME media type, and view the part as such.
5179 If non-nil, PRED is a predicate to use during completion to limit the
5180 available media-types."
5181 (interactive)
5182 (unless mime-type
5183 (setq mime-type
5184 (let ((default (gnus-mime-view-part-as-type-internal)))
5185 (gnus-completing-read
5186 "View as MIME type"
5187 (if pred
5188 (gnus-remove-if-not pred (mailcap-mime-types))
5189 (mailcap-mime-types))
5190 nil nil nil
5191 (car default)))))
5192 (gnus-article-check-buffer)
5193 (let ((handle (get-text-property (point) 'gnus-data)))
5194 (when handle
5195 (when (equal (mm-handle-media-type handle) "message/external-body")
5196 (unless (mm-handle-cache handle)
5197 (mm-extern-cache-contents handle))
5198 (setq handle (mm-handle-cache handle)))
5199 (setq handle
5200 (mm-make-handle (mm-handle-buffer handle)
5201 (cons mime-type (cdr (mm-handle-type handle)))
5202 (mm-handle-encoding handle)
5203 (mm-handle-undisplayer handle)
5204 (mm-handle-disposition handle)
5205 (mm-handle-description handle)
5207 (mm-handle-id handle)))
5208 (setq gnus-article-mime-handles
5209 (mm-merge-handles gnus-article-mime-handles handle))
5210 (when (mm-handle-displayed-p handle)
5211 (mm-remove-part handle))
5212 (gnus-mm-display-part handle))))
5214 (defun gnus-mime-copy-part (&optional handle arg)
5215 "Put the MIME part under point into a new buffer.
5216 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5217 are decompressed."
5218 (interactive (list nil current-prefix-arg))
5219 (gnus-article-check-buffer)
5220 (unless handle
5221 (setq handle (get-text-property (point) 'gnus-data)))
5222 (when handle
5223 (let ((filename (mm-handle-filename handle))
5224 contents dont-decode charset coding-system)
5225 (mm-with-unibyte-buffer
5226 (mm-insert-part handle)
5227 (setq contents (or (condition-case nil
5228 (mm-decompress-buffer filename nil 'sig)
5229 (error
5230 (setq dont-decode t)
5231 nil))
5232 (buffer-string))))
5233 (setq filename (cond (filename (file-name-nondirectory filename))
5234 (dont-decode "*raw data*")
5235 (t "*decoded*")))
5236 (cond
5237 (dont-decode)
5238 ((not arg)
5239 (unless (setq charset (mail-content-type-get
5240 (mm-handle-type handle) 'charset))
5241 (unless (setq coding-system (mm-with-unibyte-buffer
5242 (insert contents)
5243 (mm-find-buffer-file-coding-system)))
5244 (setq charset gnus-newsgroup-charset))))
5245 ((numberp arg)
5246 (setq charset (or (cdr (assq arg
5247 gnus-summary-show-article-charset-alist))
5248 (mm-read-coding-system "Charset: ")))))
5249 (switch-to-buffer (generate-new-buffer filename))
5250 (if (or coding-system
5251 (and charset
5252 (setq coding-system (mm-charset-to-coding-system
5253 charset nil t))
5254 (not (eq coding-system 'ascii))))
5255 (progn
5256 (mm-enable-multibyte)
5257 (insert (mm-decode-coding-string contents coding-system))
5258 (setq buffer-file-coding-system
5259 (if (boundp 'last-coding-system-used)
5260 (symbol-value 'last-coding-system-used)
5261 coding-system)))
5262 (mm-disable-multibyte)
5263 (insert contents)
5264 (setq buffer-file-coding-system mm-binary-coding-system))
5265 ;; We do it this way to make `normal-mode' set the appropriate mode.
5266 (unwind-protect
5267 (progn
5268 (setq buffer-file-name (expand-file-name filename))
5269 (normal-mode))
5270 (setq buffer-file-name nil))
5271 (goto-char (point-min)))))
5273 (defun gnus-mime-print-part (&optional handle filename)
5274 "Print the MIME part under point."
5275 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5276 (gnus-article-check-buffer)
5277 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5278 (contents (and handle (mm-get-part handle)))
5279 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5280 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5281 (when contents
5282 (if printer
5283 (unwind-protect
5284 (progn
5285 (mm-save-part-to-file handle file)
5286 (call-process shell-file-name nil
5287 (generate-new-buffer " *mm*")
5289 shell-command-switch
5290 (mm-mailcap-command
5291 printer file (mm-handle-type handle))))
5292 (delete-file file))
5293 (with-temp-buffer
5294 (insert contents)
5295 (gnus-print-buffer))
5296 (ps-despool filename)))))
5298 (defun gnus-mime-inline-part (&optional handle arg)
5299 "Insert the MIME part under point into the current buffer.
5300 Compressed files like .gz and .bz2 are decompressed."
5301 (interactive (list nil current-prefix-arg))
5302 (gnus-article-check-buffer)
5303 (let* ((inhibit-read-only t)
5304 (b (point))
5305 (btn ;; position where the MIME button exists
5306 (if handle
5307 (if (eq handle (get-text-property b 'gnus-data))
5309 (article-goto-body)
5310 (or (text-property-any (point) (point-max) 'gnus-data handle)
5311 (text-property-any (point-min) (point) 'gnus-data handle)))
5312 (setq handle (get-text-property b 'gnus-data))
5314 start contents charset coding-system)
5315 (when handle
5316 (when (= b (prog1
5318 (setq start (next-single-property-change btn 'gnus-data
5319 nil (point-max))
5320 btn (previous-single-property-change start
5321 'gnus-data))))
5322 (setq b btn))
5323 (if (and (not arg) (mm-handle-undisplayer handle))
5324 (mm-remove-part handle)
5325 (mm-with-unibyte-buffer
5326 (mm-insert-part handle)
5327 (setq contents
5328 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5329 (buffer-string))))
5330 (cond
5331 ((not arg)
5332 (unless (setq charset (mail-content-type-get
5333 (mm-handle-type handle) 'charset))
5334 (unless (setq coding-system
5335 (mm-with-unibyte-buffer
5336 (insert contents)
5337 (mm-find-buffer-file-coding-system)))
5338 (setq charset gnus-newsgroup-charset))))
5339 ((numberp arg)
5340 (if (mm-handle-undisplayer handle)
5341 (mm-remove-part handle))
5342 (setq charset
5343 (or (cdr (assq arg
5344 gnus-summary-show-article-charset-alist))
5345 (mm-read-coding-system "Charset: "))))
5346 ((mm-handle-undisplayer handle)
5347 (mm-remove-part handle)))
5348 (goto-char start)
5349 (unless (bolp)
5350 ;; This is a header button.
5351 (forward-line 1))
5352 (mm-display-inline handle))
5353 ;; Toggle the button appearance between `[button]...' and `[button]'.
5354 (goto-char btn)
5355 (let ((displayed-p (mm-handle-displayed-p handle)))
5356 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5357 (list displayed-p))
5358 (if (featurep 'emacs)
5359 (delete-region
5360 (point)
5361 (next-single-property-change (point) 'gnus-data nil (point-max)))
5362 (let* ((end (next-single-property-change (point) 'gnus-data))
5363 (annots (annotations-at (or end (point-max)))))
5364 (delete-region (point)
5365 (if end
5366 (if annots (1+ end) end)
5367 (point-max)))
5368 (dolist (annot annots)
5369 (set-extent-endpoints annot (point) (point)))))
5370 (setq start (point))
5371 (if (search-backward "\n\n" nil t)
5372 (progn
5373 (goto-char start)
5374 (unless (or displayed-p (eolp))
5375 ;; Add extra newline.
5376 (insert (propertize (buffer-substring (1- start) start)
5377 'gnus-undeletable t))))
5378 ;; We're in the article header.
5379 (delete-char -1)
5380 (dolist (ovl (gnus-overlays-in btn (point)))
5381 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5382 (gnus-overlay-put ovl 'face nil))
5383 (save-restriction
5384 (message-narrow-to-field)
5385 (let ((gnus-treatment-function-alist
5386 '((gnus-treat-highlight-headers
5387 gnus-article-highlight-headers))))
5388 (gnus-treat-article 'head)))))
5389 (goto-char b))))
5391 (defun gnus-mime-set-charset-parameters (handle charset)
5392 "Set CHARSET to parameters in HANDLE.
5393 CHARSET may either be a string or a symbol."
5394 (unless (stringp charset)
5395 (setq charset (symbol-name charset)))
5396 (if (stringp (car handle))
5397 (dolist (h (cdr handle))
5398 (gnus-mime-set-charset-parameters h charset))
5399 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5400 "message/external-body")
5401 (progn
5402 (unless (mm-handle-cache handle)
5403 (mm-extern-cache-contents handle))
5404 (mm-handle-cache handle))
5405 handle)))
5406 (param (assq 'charset (cdr type))))
5407 (if param
5408 (setcdr param charset)
5409 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5411 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5412 "Insert the MIME part under point into the current buffer using the
5413 specified charset."
5414 (interactive (list nil current-prefix-arg))
5415 (gnus-article-check-buffer)
5416 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5417 (fun (get-text-property (point) 'gnus-callback))
5418 (gnus-newsgroup-ignored-charsets 'gnus-all)
5419 charset form preferred parts)
5420 (when handle
5421 (when (prog1
5422 (and fun
5423 (setq charset
5424 (or (cdr (assq
5426 gnus-summary-show-article-charset-alist))
5427 (mm-read-coding-system "Charset: "))))
5428 (if (mm-handle-undisplayer handle)
5429 (mm-remove-part handle)))
5430 (gnus-mime-set-charset-parameters handle charset)
5431 (when (and (consp (setq form (cdr-safe fun)))
5432 (setq form (ignore-errors
5433 (assq 'gnus-mime-display-alternative form)))
5434 (setq preferred (caddr form))
5435 (progn
5436 (when (eq (car preferred) 'quote)
5437 (setq preferred (cadr preferred)))
5438 (not (equal preferred
5439 (get-text-property (point) 'gnus-data))))
5440 (setq parts (get-text-property (point) 'gnus-part))
5441 (setq parts (cdr (assq parts
5442 gnus-article-mime-handle-alist)))
5443 (equal (mm-handle-media-type parts) "multipart/alternative")
5444 (setq parts (reverse (cdr parts))))
5445 (setcar (cddr form)
5446 (list 'quote (or (cadr (member preferred parts))
5447 (car parts)))))
5448 (funcall fun handle)))))
5450 (defun gnus-mime-view-part-externally (&optional handle)
5451 "View the MIME part under point with an external viewer."
5452 (interactive)
5453 (gnus-article-check-buffer)
5454 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5455 (mm-user-display-methods nil)
5456 (mm-inlined-types nil)
5457 (mail-parse-charset gnus-newsgroup-charset)
5458 (mail-parse-ignored-charsets
5459 (with-current-buffer gnus-summary-buffer
5460 gnus-newsgroup-ignored-charsets))
5461 (type (mm-handle-media-type handle))
5462 (method (mailcap-mime-info type))
5463 (mm-enable-external t))
5464 (if (not (stringp method))
5465 (gnus-mime-view-part-as-type
5466 nil (lambda (type) (stringp (mailcap-mime-info type))))
5467 (when handle
5468 (mm-display-part handle nil t)))))
5470 (defun gnus-mime-view-part-internally (&optional handle)
5471 "View the MIME part under point with an internal viewer.
5472 If no internal viewer is available, use an external viewer."
5473 (interactive)
5474 (gnus-article-check-buffer)
5475 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5476 (mm-inlined-types '(".*"))
5477 (mm-inline-large-images t)
5478 (mail-parse-charset gnus-newsgroup-charset)
5479 (mail-parse-ignored-charsets
5480 (with-current-buffer gnus-summary-buffer
5481 gnus-newsgroup-ignored-charsets))
5482 (inhibit-read-only t))
5483 (if (not (mm-inlinable-p handle))
5484 (gnus-mime-view-part-as-type
5485 nil (lambda (type) (mm-inlinable-p handle type)))
5486 (when handle
5487 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5489 (defun gnus-mime-action-on-part (&optional action)
5490 "Do something with the MIME attachment at \(point\)."
5491 (interactive
5492 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5493 (gnus-article-check-buffer)
5494 (let ((action-pair (assoc action gnus-mime-action-alist)))
5495 (if action-pair
5496 (funcall (cdr action-pair)))))
5498 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5499 "Call FUNCTION on MIME part N.
5500 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5501 If INTERACTIVE, call FUNCTION interactively."
5502 (let (window frame)
5503 ;; Check whether the article is displayed.
5504 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5505 (setq window (get-buffer-window gnus-article-buffer t))
5506 (frame-visible-p (setq frame (window-frame window))))
5507 (error "No article is displayed"))
5508 (with-current-buffer gnus-article-buffer
5509 ;; Check whether the article displays the right contents.
5510 (unless (with-current-buffer gnus-summary-buffer
5511 (eq gnus-current-article (gnus-summary-article-number)))
5512 (error "You should select the right article first"))
5513 (if n
5514 (setq n (prefix-numeric-value n))
5515 (let ((pt (point)))
5516 (setq n (or (get-text-property pt 'gnus-part)
5517 (and (not (bobp))
5518 (get-text-property (1- pt) 'gnus-part))
5519 (get-text-property (prog2
5520 (forward-line 1)
5521 (point)
5522 (goto-char pt))
5523 'gnus-part)
5524 (get-text-property
5525 (or (and (setq pt (previous-single-property-change
5526 pt 'gnus-part))
5527 (1- pt))
5528 (next-single-property-change (point) 'gnus-part)
5529 (point))
5530 'gnus-part)
5531 1))))
5532 ;; Check whether the specified part exists.
5533 (when (> n (length gnus-article-mime-handle-alist))
5534 (error "No such part")))
5535 (unless
5536 (progn
5537 ;; To select the window is needed so that the cursor
5538 ;; might be visible on the MIME button.
5539 (select-window (prog1
5540 window
5541 (setq window (selected-window))
5542 ;; Article may be displayed in the other frame.
5543 (gnus-select-frame-set-input-focus
5544 (prog1
5545 frame
5546 (setq frame (selected-frame))))))
5547 (when (gnus-article-goto-part n)
5548 ;; We point the cursor and the arrow at the MIME button
5549 ;; when the `function' prompt the user for something.
5550 (unless (and (pos-visible-in-window-p)
5551 (> (count-lines (point) (window-end))
5552 (/ (1- (window-height)) 3)))
5553 (recenter (/ (1- (window-height)) 3)))
5554 (let ((cursor-in-non-selected-windows t)
5555 (overlay-arrow-string "=>")
5556 (overlay-arrow-position (point-marker)))
5557 (unwind-protect
5558 (cond
5559 ((and no-handle interactive)
5560 (call-interactively function))
5561 (no-handle
5562 (funcall function))
5563 (interactive
5564 (call-interactively
5565 function (get-text-property (point) 'gnus-data)))
5567 (funcall function
5568 (get-text-property (point) 'gnus-data))))
5569 (set-marker overlay-arrow-position nil)
5570 (unless gnus-auto-select-part
5571 (gnus-select-frame-set-input-focus frame)
5572 (select-window window))))
5574 (if gnus-inhibit-mime-unbuttonizing
5575 ;; This is the default though the program shouldn't reach here.
5576 (error "No such part")
5577 ;; The part which doesn't have the MIME button is selected.
5578 ;; So, we display all the buttons and redo it.
5579 (let ((gnus-inhibit-mime-unbuttonizing t))
5580 (gnus-summary-show-article)
5581 (gnus-article-part-wrapper n function no-handle))))))
5583 (defun gnus-article-pipe-part (n)
5584 "Pipe MIME part N, which is the numerical prefix."
5585 (interactive "P")
5586 (gnus-article-part-wrapper n 'mm-pipe-part))
5588 (defun gnus-article-save-part (n)
5589 "Save MIME part N, which is the numerical prefix."
5590 (interactive "P")
5591 (gnus-article-part-wrapper n 'mm-save-part))
5593 (defun gnus-article-interactively-view-part (n)
5594 "View MIME part N interactively, which is the numerical prefix."
5595 (interactive "P")
5596 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5598 (defun gnus-article-copy-part (n)
5599 "Copy MIME part N, which is the numerical prefix."
5600 (interactive "P")
5601 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5603 (defun gnus-article-view-part-as-charset (n)
5604 "View MIME part N using a specified charset.
5605 N is the numerical prefix."
5606 (interactive "P")
5607 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5609 (defun gnus-article-view-part-externally (n)
5610 "View MIME part N externally, which is the numerical prefix."
5611 (interactive "P")
5612 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5614 (defun gnus-article-inline-part (n)
5615 "Inline MIME part N, which is the numerical prefix."
5616 (interactive "P")
5617 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5619 (defun gnus-article-save-part-and-strip (n)
5620 "Save MIME part N and replace it with an external body.
5621 N is the numerical prefix."
5622 (interactive "P")
5623 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5625 (defun gnus-article-replace-part (n)
5626 "Replace MIME part N with an external body.
5627 N is the numerical prefix."
5628 (interactive "P")
5629 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5631 (defun gnus-article-delete-part (n)
5632 "Delete MIME part N and add some information about the removed part.
5633 N is the numerical prefix."
5634 (interactive "P")
5635 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5637 (defun gnus-article-view-part-as-type (n)
5638 "Choose a MIME media type, and view part N as such.
5639 N is the numerical prefix."
5640 (interactive "P")
5641 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5643 (defun gnus-article-mime-match-handle-first (condition)
5644 (if condition
5645 (let (n)
5646 (dolist (ihandle gnus-article-mime-handle-alist)
5647 (if (and (cond
5648 ((functionp condition)
5649 (funcall condition (cdr ihandle)))
5650 ((eq condition 'undisplayed)
5651 (not (or (mm-handle-undisplayer (cdr ihandle))
5652 (equal (mm-handle-media-type (cdr ihandle))
5653 "multipart/alternative"))))
5654 ((eq condition 'undisplayed-alternative)
5655 (not (mm-handle-undisplayer (cdr ihandle))))
5656 (t t))
5657 (gnus-article-goto-part (car ihandle))
5658 (or (not n) (< (car ihandle) n)))
5659 (setq n (car ihandle))))
5660 (or n 1))
5663 (defun gnus-article-view-part (&optional n)
5664 "View MIME part N, which is the numerical prefix.
5665 If the part is already shown, hide the part. If N is nil, view
5666 all parts."
5667 (interactive "P")
5668 (with-current-buffer gnus-article-buffer
5669 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5670 gnus-article-mime-match-handle-function)))
5671 (when (> n (length gnus-article-mime-handle-alist))
5672 (error "No such part"))
5673 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5674 (when (gnus-article-goto-part n)
5675 (if (equal (car handle) "multipart/alternative")
5676 (progn
5677 (beginning-of-line) ;; Make it toggle subparts
5678 (gnus-article-press-button))
5679 (when (eq (gnus-mm-display-part handle) 'internal)
5680 (gnus-set-window-start)))))))
5682 (defsubst gnus-article-mime-total-parts ()
5683 (if (bufferp (car gnus-article-mime-handles))
5684 1 ;; single part
5685 (1- (length gnus-article-mime-handles))))
5687 (defun gnus-mm-display-part (handle)
5688 "Display HANDLE and fix MIME button."
5689 (let ((id (get-text-property (point) 'gnus-part))
5690 (point (point))
5691 (inhibit-read-only t)
5692 (window (selected-window))
5693 (mail-parse-charset gnus-newsgroup-charset)
5694 (mail-parse-ignored-charsets
5695 (if (gnus-buffer-live-p gnus-summary-buffer)
5696 (with-current-buffer gnus-summary-buffer
5697 gnus-newsgroup-ignored-charsets)
5698 nil))
5699 start retval)
5700 (unwind-protect
5701 (progn
5702 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5703 (when win
5704 (select-window win)
5705 (goto-char point)))
5706 (setq start (next-single-property-change point 'gnus-data
5707 nil (point-max))
5708 point (previous-single-property-change start 'gnus-data))
5709 (if (mm-handle-displayed-p handle)
5710 ;; This will remove the part.
5711 (setq retval (mm-display-part handle))
5712 (let ((part (or (and (mm-inlinable-p handle)
5713 (mm-inlined-p handle)
5715 (with-temp-buffer
5716 (gnus-bind-safe-url-regexp
5717 (setq retval (mm-display-part handle)))
5718 (unless (zerop (buffer-size))
5719 (buffer-string))))))
5720 (goto-char start)
5721 (unless (bolp)
5722 ;; This is a header button.
5723 (forward-line 1))
5724 (cond ((stringp part)
5725 (save-restriction
5726 (narrow-to-region (point)
5727 (progn
5728 (insert part)
5729 (unless (bolp) (insert "\n"))
5730 (point)))
5731 (gnus-treat-article nil id
5732 (gnus-article-mime-total-parts)
5733 (mm-handle-media-type handle))
5734 (mm-handle-set-undisplayer
5735 handle
5736 `(lambda ()
5737 (let ((inhibit-read-only t))
5738 (delete-region ,(copy-marker (point-min) t)
5739 ,(point-max-marker)))))))
5740 (part
5741 (mm-display-inline handle))))))
5742 (goto-char point)
5743 ;; Toggle the button appearance between `[button]...' and `[button]'.
5744 (let ((displayed-p (mm-handle-displayed-p handle)))
5745 (gnus-insert-mime-button handle id (list displayed-p))
5746 (if (featurep 'emacs)
5747 (delete-region
5748 (point)
5749 (next-single-property-change (point) 'gnus-data nil (point-max)))
5750 (let* ((end (next-single-property-change (point) 'gnus-data))
5751 (annots (annotations-at (or end (point-max)))))
5752 (delete-region (point)
5753 (if end
5754 (if annots (1+ end) end)
5755 (point-max)))
5756 (dolist (annot annots)
5757 (set-extent-endpoints annot (point) (point)))))
5758 (setq start (point))
5759 (if (search-backward "\n\n" nil t)
5760 (progn
5761 (goto-char start)
5762 (unless (or displayed-p (eolp))
5763 ;; Add extra newline.
5764 (insert (propertize (buffer-substring (1- start) start)
5765 'gnus-undeletable t))))
5766 ;; We're in the article header.
5767 (delete-char -1)
5768 (dolist (ovl (gnus-overlays-in point (point)))
5769 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5770 (gnus-overlay-put ovl 'face nil))
5771 (save-restriction
5772 (message-narrow-to-field)
5773 (let ((gnus-treatment-function-alist
5774 '((gnus-treat-highlight-headers
5775 gnus-article-highlight-headers))))
5776 (gnus-treat-article 'head)))))
5777 (goto-char point)
5778 (if (window-live-p window)
5779 (select-window window)))
5780 retval))
5782 (defun gnus-article-goto-part (n)
5783 "Go to MIME part N."
5784 (when gnus-break-pages
5785 (widen))
5786 (article-goto-body)
5787 (prog1
5788 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5789 ;; There may be header buttons.
5790 (text-property-any (point-min) (point) 'gnus-part n)))
5791 part handle end next handles)
5792 (when start
5793 (goto-char start)
5794 (if (setq handle (get-text-property start 'gnus-data))
5795 start
5796 ;; Go to the displayed subpart, assuming this is
5797 ;; multipart/alternative.
5798 (setq part start
5799 end (point-at-eol))
5800 (while (and (not handle)
5801 part
5802 (< part end)
5803 (setq next (text-property-not-all part end
5804 'gnus-data nil)))
5805 (setq part next
5806 handle (get-text-property part 'gnus-data))
5807 (push (cons handle part) handles)
5808 (unless (mm-handle-displayed-p handle)
5809 (setq handle nil
5810 part (text-property-any part end 'gnus-data nil))))
5811 (unless handle
5812 ;; No subpart is displayed, so we find preferred one.
5813 (setq part
5814 (cdr (assq (mm-preferred-alternative
5815 (nreverse (mapcar 'car handles)))
5816 handles))))
5817 (if part
5818 (goto-char (1+ part))
5819 start))))
5820 (when gnus-break-pages
5821 (gnus-narrow-to-page))))
5823 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5824 (let ((gnus-tmp-name
5825 (or (mm-handle-filename handle)
5826 (mail-content-type-get (mm-handle-type handle) 'url)
5827 ""))
5828 (gnus-tmp-type (mm-handle-media-type handle))
5829 (gnus-tmp-description (or (mm-handle-description handle) ""))
5830 (gnus-tmp-dots
5831 (if (if displayed (car displayed)
5832 (mm-handle-displayed-p handle))
5833 "" "..."))
5834 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5835 (buffer-size)))
5836 gnus-tmp-type-long b e)
5837 (when (string-match ".*/" gnus-tmp-name)
5838 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5839 (setq gnus-tmp-type-long (concat gnus-tmp-type
5840 (and (not (equal gnus-tmp-name ""))
5841 (concat "; " gnus-tmp-name))))
5842 (unless (equal gnus-tmp-description "")
5843 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5844 (setq b (point))
5845 (gnus-eval-format
5846 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5847 `(keymap ,gnus-mime-button-map
5848 gnus-callback gnus-mm-display-part
5849 gnus-part ,gnus-tmp-id
5850 article-type annotation
5851 gnus-data ,handle
5852 rear-nonsticky t))
5853 (setq e (if (bolp)
5854 ;; Exclude a newline.
5855 (1- (point))
5856 (point)))
5857 (when gnus-article-button-face
5858 (gnus-overlay-put (gnus-make-overlay b e nil t)
5859 'face gnus-article-button-face))
5860 (widget-convert-button
5861 'link b e
5862 :mime-handle handle
5863 :action 'gnus-widget-press-button
5864 :button-keymap gnus-mime-button-map
5865 :help-echo
5866 (lambda (widget)
5867 ;; Needed to properly clear the message due to a bug in
5868 ;; wid-edit (XEmacs only).
5869 (if (boundp 'help-echo-owns-message)
5870 (setq help-echo-owns-message t))
5871 (format
5872 "%S: %s the MIME part; %S: more options"
5873 (aref gnus-mouse-2 0)
5874 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5875 "hide" "show")
5876 (aref gnus-down-mouse-3 0))))))
5878 (defun gnus-widget-press-button (elems el)
5879 (goto-char (widget-get elems :from))
5880 (gnus-article-press-button))
5882 (defvar gnus-displaying-mime nil)
5884 (defun gnus-display-mime (&optional ihandles)
5885 "Display the MIME parts."
5886 (save-excursion
5887 (save-selected-window
5888 (let ((window (get-buffer-window gnus-article-buffer))
5889 (point (point)))
5890 (when window
5891 (select-window window)
5892 ;; We have to do this since selecting the window
5893 ;; may change the point. So we set the window point.
5894 (set-window-point window point)))
5895 (let ((handles ihandles)
5896 (inhibit-read-only t)
5897 handle)
5898 (cond (handles)
5899 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5900 (when gnus-article-emulate-mime
5901 (mm-uu-dissect-text-parts handles)))
5902 (gnus-article-emulate-mime
5903 (setq handles (mm-uu-dissect))))
5904 (when (and (not ihandles)
5905 (not gnus-displaying-mime))
5906 ;; Top-level call; we clean up.
5907 (when gnus-article-mime-handles
5908 (mm-destroy-parts gnus-article-mime-handles)
5909 (setq gnus-article-mime-handle-alist nil));; A trick.
5910 (setq gnus-article-mime-handles handles)
5911 ;; We allow users to glean info from the handles.
5912 (when gnus-article-mime-part-function
5913 (gnus-mime-part-function handles)))
5914 (if (and handles
5915 (or (not (stringp (car handles)))
5916 (cdr handles)))
5917 (progn
5918 (when (and (not ihandles)
5919 (not gnus-displaying-mime))
5920 ;; Clean up for mime parts.
5921 (article-goto-body)
5922 (delete-region (point) (point-max)))
5923 (let ((gnus-displaying-mime t))
5924 (gnus-mime-display-part handles)))
5925 (save-restriction
5926 (article-goto-body)
5927 (narrow-to-region (point) (point-max))
5928 (gnus-treat-article nil 1 1 "text/plain")
5929 (widen)))
5930 (unless ihandles
5931 ;; Highlight the headers.
5932 (save-excursion
5933 (save-restriction
5934 (article-goto-body)
5935 (narrow-to-region (point-min) (point))
5936 (gnus-article-save-original-date
5937 (gnus-treat-article 'head)))))))
5938 ;; Cope with broken MIME messages.
5939 (goto-char (point-max))
5940 (unless (bolp)
5941 (insert "\n"))))
5943 (defcustom gnus-mime-display-multipart-as-mixed nil
5944 "Display \"multipart\" parts as \"multipart/mixed\".
5946 If t, it overrides nil values of
5947 `gnus-mime-display-multipart-alternative-as-mixed' and
5948 `gnus-mime-display-multipart-related-as-mixed'."
5949 :group 'gnus-article-mime
5950 :type 'boolean)
5952 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5953 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5954 :version "22.1"
5955 :group 'gnus-article-mime
5956 :type 'boolean)
5958 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5959 "Display \"multipart/related\" parts as \"multipart/mixed\".
5961 If displaying \"text/html\" is discouraged \(see
5962 `mm-discouraged-alternatives'\) images or other material inside a
5963 \"multipart/related\" part might be overlooked when this variable is nil."
5964 :version "22.1"
5965 :group 'gnus-article-mime
5966 :type 'boolean)
5968 (defcustom gnus-mime-display-attachment-buttons-in-header t
5969 "Add attachment buttons in the end of the header of an article.
5970 Since MIME attachments tend to be put at the end of an article, we may
5971 overlook them if there is a huge body. This option offers you a copy
5972 of all non-inlinable MIME parts as buttons shown in front of an article.
5973 If nil, don't show those extra buttons."
5974 :version "24.5"
5975 :group 'gnus-article-mime
5976 :type 'boolean)
5978 (defun gnus-mime-display-part (handle)
5979 (cond
5980 ;; Maybe a broken MIME message.
5981 ((null handle))
5982 ;; Single part.
5983 ((not (stringp (car handle)))
5984 (gnus-mime-display-single handle))
5985 ;; User-defined multipart
5986 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5987 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5988 handle))
5989 ;; multipart/alternative
5990 ((and (equal (car handle) "multipart/alternative")
5991 (not (or gnus-mime-display-multipart-as-mixed
5992 gnus-mime-display-multipart-alternative-as-mixed)))
5993 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5994 (push (cons id handle) gnus-article-mime-handle-alist)
5995 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5996 ;; multipart/related
5997 ((and (equal (car handle) "multipart/related")
5998 (not (or gnus-mime-display-multipart-as-mixed
5999 gnus-mime-display-multipart-related-as-mixed)))
6000 (gnus-mime-display-part (cadr handle)))
6001 ((equal (car handle) "multipart/signed")
6002 (gnus-add-wash-type 'signed)
6003 (gnus-mime-display-security handle))
6004 ((equal (car handle) "multipart/encrypted")
6005 (gnus-add-wash-type 'encrypted)
6006 (gnus-mime-display-security handle))
6007 ;; Other multiparts are handled like multipart/mixed.
6009 (gnus-mime-display-mixed (cdr handle)))))
6011 (defun gnus-mime-part-function (handles)
6012 (if (stringp (car handles))
6013 (mapcar 'gnus-mime-part-function (cdr handles))
6014 (funcall gnus-article-mime-part-function handles)))
6016 (defun gnus-mime-display-mixed (handles)
6017 (mapcar 'gnus-mime-display-part handles))
6019 (defun gnus-mime-display-single (handle)
6020 (let ((type (mm-handle-media-type handle))
6021 (ignored gnus-ignored-mime-types)
6022 (not-attachment t)
6023 display text)
6024 (catch 'ignored
6025 (progn
6026 (while ignored
6027 (when (string-match (pop ignored) type)
6028 (throw 'ignored nil)))
6029 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6030 (with-current-buffer gnus-summary-buffer
6031 gnus-inhibit-images)
6032 gnus-inhibit-images)
6033 (string-match "\\`image/" type)))
6034 (setq not-attachment
6035 (and (not (mm-inline-override-p handle))
6036 (or (not (mm-handle-disposition handle))
6037 (equal (car (mm-handle-disposition handle))
6038 "inline")
6039 (mm-attachment-override-p handle))))
6040 (mm-automatic-display-p handle)
6041 (or (and
6042 (mm-inlinable-p handle)
6043 (mm-inlined-p handle))
6044 (mm-automatic-external-display-p type)))
6045 (setq display t)
6046 (when (equal (mm-handle-media-supertype handle) "text")
6047 (setq text t)))
6048 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6049 beg)
6050 (unless id
6051 (setq id (1+ (length gnus-article-mime-handle-alist)))
6052 (push (cons id handle) gnus-article-mime-handle-alist))
6053 (when (and display
6054 (equal (mm-handle-media-supertype handle) "message"))
6055 (insert-char
6057 (cond ((not (bolp)) 2)
6058 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6059 (t 1))))
6060 (when (or (not display)
6061 (not (gnus-unbuttonized-mime-type-p type))
6062 (eq id gnus-mime-buttonized-part-id))
6063 (gnus-insert-mime-button
6064 handle id (list (or display (and not-attachment text)))))
6065 (setq beg (point))
6066 (cond
6067 (display
6068 (let ((mail-parse-charset gnus-newsgroup-charset)
6069 (mail-parse-ignored-charsets
6070 (save-excursion (condition-case ()
6071 (set-buffer gnus-summary-buffer)
6072 (error))
6073 gnus-newsgroup-ignored-charsets)))
6074 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6075 ((and text not-attachment)
6076 (mm-display-inline handle)))
6077 (goto-char (point-max))
6078 (if (string-match "\\`image/" type)
6079 (gnus-article-insert-newline)
6080 (if (prog1
6081 (= (skip-chars-backward "\n") -1)
6082 (forward-char 1))
6083 (gnus-article-insert-newline)
6084 (put-text-property (point) (point-max) 'gnus-undeletable t))
6085 (goto-char (point-max)))
6086 ;; Do highlighting.
6087 (save-excursion
6088 (save-restriction
6089 (narrow-to-region beg (point))
6090 (if (eq handle gnus-article-mime-handles)
6091 ;; The format=flowed case.
6092 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6093 ;; Don't count signature parts that are never displayed.
6094 ;; The part number should be re-calculated supposing this
6095 ;; might be a message/rfc822 part.
6096 (let (handles)
6097 (dolist (part gnus-article-mime-handles)
6098 (unless (or (stringp part)
6099 (equal (car (mm-handle-type part))
6100 "application/pgp-signature"))
6101 (push part handles)))
6102 (gnus-treat-article
6103 nil (length (memq handle handles)) (length handles)
6104 (mm-handle-media-type handle)))))))))))
6106 (defun gnus-unbuttonized-mime-type-p (type)
6107 "Say whether TYPE is to be unbuttonized."
6108 (unless gnus-inhibit-mime-unbuttonizing
6109 (when (catch 'found
6110 (let ((types gnus-unbuttonized-mime-types))
6111 (while types
6112 (when (string-match (pop types) type)
6113 (throw 'found t)))))
6114 (not (catch 'found
6115 (let ((types gnus-buttonized-mime-types))
6116 (while types
6117 (when (string-match (pop types) type)
6118 (throw 'found t)))))))))
6120 (defun gnus-article-insert-newline ()
6121 "Insert a newline, but mark it as undeletable."
6122 (gnus-put-text-property
6123 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6125 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6126 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6127 (ihandles handles)
6128 (point (point))
6129 handle (inhibit-read-only t) from props begend not-pref)
6130 (save-window-excursion
6131 (save-restriction
6132 (when ibegend
6133 (narrow-to-region (car ibegend)
6134 (or (cdr ibegend)
6135 (progn
6136 (goto-char (car ibegend))
6137 (forward-line 2)
6138 (point))))
6139 (delete-region (point-min) (point-max))
6140 (mm-remove-parts handles))
6141 (setq begend (list (point-marker)))
6142 ;; Do the toggle.
6143 (unless (setq not-pref (cadr (member preferred ihandles)))
6144 (setq not-pref (car ihandles)))
6145 (when (or ibegend
6146 (not preferred)
6147 (not (gnus-unbuttonized-mime-type-p
6148 "multipart/alternative")))
6149 (gnus-add-text-properties
6150 (setq from (point))
6151 (progn
6152 (insert (format "%d. " id))
6153 (point))
6154 `(gnus-callback
6155 (lambda (handles)
6156 (unless ,(not ibegend)
6157 (setq gnus-article-mime-handle-alist
6158 ',gnus-article-mime-handle-alist))
6159 (gnus-mime-display-alternative
6160 ',ihandles ',not-pref ',begend ,id))
6161 keymap ,gnus-mime-button-map
6162 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6163 face ,gnus-article-button-face
6164 gnus-part ,id
6165 article-type multipart
6166 rear-nonsticky t))
6167 (widget-convert-button 'link from (point)
6168 :action 'gnus-widget-press-button
6169 :button-keymap gnus-widget-button-keymap)
6170 ;; Do the handles
6171 (while (setq handle (pop handles))
6172 (gnus-add-text-properties
6173 (setq from (point))
6174 (progn
6175 (insert (format "(%c) %-18s"
6176 (if (equal handle preferred) ?* ? )
6177 (mm-handle-media-type handle)))
6178 (point))
6179 `(gnus-callback
6180 (lambda (handles)
6181 (unless ,(not ibegend)
6182 (setq gnus-article-mime-handle-alist
6183 ',gnus-article-mime-handle-alist))
6184 (gnus-mime-display-alternative
6185 ',ihandles ',handle ',begend ,id))
6186 keymap ,gnus-mime-button-map
6187 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6188 face ,gnus-article-button-face
6189 gnus-part ,id
6190 gnus-data ,handle
6191 rear-nonsticky t))
6192 (widget-convert-button 'link from (point)
6193 :action 'gnus-widget-press-button
6194 :button-keymap gnus-widget-button-keymap)
6195 (insert " "))
6196 (insert "\n\n"))
6197 (when preferred
6198 (if (stringp (car preferred))
6199 (gnus-display-mime preferred)
6200 (let ((mail-parse-charset gnus-newsgroup-charset)
6201 (mail-parse-ignored-charsets
6202 (with-current-buffer gnus-summary-buffer
6203 gnus-newsgroup-ignored-charsets)))
6204 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6205 ;; Do highlighting.
6206 (save-excursion
6207 (save-restriction
6208 (narrow-to-region (car begend) (point-max))
6209 (gnus-treat-article
6210 nil (length gnus-article-mime-handle-alist)
6211 (gnus-article-mime-total-parts)
6212 (mm-handle-media-type preferred))))))
6213 (goto-char (point-max))
6214 (setcdr begend (point-marker)))))
6215 (when ibegend
6216 (goto-char point)))
6217 ;; Redraw attachment buttons in the header.
6218 (when gnus-mime-display-attachment-buttons-in-header
6219 (gnus-mime-buttonize-attachments-in-header)))
6221 (defconst gnus-article-wash-status-strings
6222 (let ((alist '((cite "c" "Possible hidden citation text"
6223 " " "All citation text visible")
6224 (headers "h" "Hidden headers"
6225 " " "All headers visible.")
6226 (pgp "p" "Encrypted or signed message status hidden"
6227 " " "No hidden encryption nor digital signature status")
6228 (signature "s" "Signature has been hidden"
6229 " " "Signature is visible")
6230 (overstrike "o" "Overstrike (^H) characters applied"
6231 " " "No overstrike characters applied")
6232 (emphasis "e" "/*_Emphasis_*/ characters applied"
6233 " " "No /*_emphasis_*/ characters applied")))
6234 result)
6235 (dolist (entry alist result)
6236 (let ((key (nth 0 entry))
6237 (on (copy-sequence (nth 1 entry)))
6238 (on-help (nth 2 entry))
6239 (off (copy-sequence (nth 3 entry)))
6240 (off-help (nth 4 entry)))
6241 (put-text-property 0 1 'help-echo on-help on)
6242 (put-text-property 0 1 'help-echo off-help off)
6243 (push (list key on off) result))))
6244 "Alist of strings describing wash status in the mode line.
6245 Each entry has the form (KEY ON OF), where the KEY is a symbol
6246 representing the particular washing function, ON is the string to use
6247 in the article mode line when the washing function is active, and OFF
6248 is the string to use when it is inactive.")
6250 (defun gnus-article-wash-status-entry (key value)
6251 (let ((entry (assoc key gnus-article-wash-status-strings)))
6252 (if value (nth 1 entry) (nth 2 entry))))
6254 (defun gnus-article-wash-status ()
6255 "Return a string which display status of article washing."
6256 (with-current-buffer gnus-article-buffer
6257 (let ((cite (memq 'cite gnus-article-wash-types))
6258 (headers (memq 'headers gnus-article-wash-types))
6259 (boring (memq 'boring-headers gnus-article-wash-types))
6260 (pgp (memq 'pgp gnus-article-wash-types))
6261 (pem (memq 'pem gnus-article-wash-types))
6262 (signed (memq 'signed gnus-article-wash-types))
6263 (encrypted (memq 'encrypted gnus-article-wash-types))
6264 (signature (memq 'signature gnus-article-wash-types))
6265 (overstrike (memq 'overstrike gnus-article-wash-types))
6266 (emphasis (memq 'emphasis gnus-article-wash-types)))
6267 (concat
6268 (gnus-article-wash-status-entry 'cite cite)
6269 (gnus-article-wash-status-entry 'headers (or headers boring))
6270 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6271 (gnus-article-wash-status-entry 'signature signature)
6272 (gnus-article-wash-status-entry 'overstrike overstrike)
6273 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6275 (defun gnus-add-wash-type (type)
6276 "Add a washing of TYPE to the current status."
6277 (add-to-list 'gnus-article-wash-types type))
6279 (defun gnus-delete-wash-type (type)
6280 "Add a washing of TYPE to the current status."
6281 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6283 (defun gnus-add-image (category image)
6284 "Add IMAGE of CATEGORY to the list of displayed images."
6285 (let ((entry (assq category gnus-article-image-alist)))
6286 (unless entry
6287 (setq entry (list category))
6288 (push entry gnus-article-image-alist))
6289 (nconc entry (list image))))
6291 (defun gnus-delete-images (category)
6292 "Delete all images in CATEGORY."
6293 (let ((entry (assq category gnus-article-image-alist)))
6294 (dolist (image (cdr entry))
6295 (gnus-remove-image image category))
6296 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6297 (gnus-delete-wash-type category)))
6299 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6301 (defun gnus-article-maybe-hide-headers ()
6302 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6303 Provided for backwards compatibility."
6304 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6305 (not (with-current-buffer gnus-summary-buffer
6306 gnus-have-all-headers)))
6307 (not gnus-inhibit-hiding))
6308 (gnus-article-hide-headers)))
6310 (declare-function shr-put-image "shr" (data alt &optional flags))
6312 (defun gnus-shr-put-image (data alt &optional flags)
6313 "Put image DATA with a string ALT. Enable image to be deleted."
6314 (let ((image (if flags
6315 (shr-put-image data (propertize (or alt "*")
6316 'gnus-image-category 'shr)
6317 flags)
6318 ;; Old `shr-put-image' doesn't take the optional `flags'
6319 ;; argument.
6320 (shr-put-image data (propertize (or alt "*")
6321 'gnus-image-category 'shr)))))
6322 (when image
6323 (gnus-add-image 'shr image))))
6325 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6326 "Show attachments as buttons in the end of the header of an article.
6327 This function toggles the display when called interactively. Note that
6328 buttons to be added to the header are only the ones that aren't inlined
6329 in the body. Use `gnus-header-face-alist' to highlight buttons."
6330 (interactive (list t))
6331 (gnus-with-article-buffer
6332 (gmm-labels
6333 ;; Function that returns a flattened version of
6334 ;; `gnus-article-mime-handle-alist'.
6335 ((flattened-alist
6336 (&optional alist id all)
6337 (if alist
6338 (let ((i 1) newid flat)
6339 (dolist (handle alist flat)
6340 (setq newid (append id (list i))
6341 i (1+ i))
6342 (if (stringp (car handle))
6343 (setq flat (nconc flat (flattened-alist (cdr handle)
6344 newid all)))
6345 (delq (rassq handle all) all)
6346 (setq flat (nconc flat (list (cons newid handle)))))))
6347 (let ((flat (list nil)))
6348 ;; Assume that elements of `gnus-article-mime-handle-alist'
6349 ;; are in the decreasing order, but unnumbered subsidiaries
6350 ;; in each element are in the increasing order.
6351 (dolist (handle (reverse gnus-article-mime-handle-alist))
6352 (if (stringp (cadr handle))
6353 (setq flat (nconc flat (flattened-alist (cddr handle)
6354 (list (car handle))
6355 flat)))
6356 (delq (rassq (cdr handle) flat) flat)
6357 (setq flat (nconc flat (list (cons (list (car handle))
6358 (cdr handle)))))))
6359 (setq flat (cdr flat))
6360 (mapc (lambda (handle)
6361 (if (cdar handle)
6362 ;; This is a hidden (i.e. unnumbered) handle.
6363 (progn
6364 (setcar handle
6365 (1+ (caar gnus-article-mime-handle-alist)))
6366 (push handle gnus-article-mime-handle-alist))
6367 (setcar handle (caar handle))))
6368 flat)
6369 flat))))
6370 (let ((case-fold-search t) buttons st handle)
6371 (save-excursion
6372 (save-restriction
6373 (widen)
6374 (article-narrow-to-head)
6375 ;; Header buttons exist?
6376 (while (and (not buttons)
6377 (re-search-forward "^attachments?:[\n ]+" nil t))
6378 (when (get-char-property (match-end 0)
6379 'gnus-button-attachment-extra)
6380 (setq buttons (match-beginning 0))))
6381 (widen)
6382 (when buttons
6383 ;; Delete header buttons.
6384 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6385 (match-beginning 0)
6386 (point-max))))
6387 (unless (and interactive buttons)
6388 ;; Find buttons.
6389 (setq buttons nil)
6390 (dolist (handle (flattened-alist))
6391 (when (and (not (stringp (cadr handle)))
6392 (or (equal (car (mm-handle-disposition
6393 (cdr handle)))
6394 "attachment")
6395 (not (and (mm-inlinable-p (cdr handle))
6396 (mm-inlined-p (cdr handle))))))
6397 (push handle buttons)))
6398 (when buttons
6399 ;; Add header buttons.
6400 (article-goto-body)
6401 (forward-line -1)
6402 (narrow-to-region (point) (point))
6403 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6404 (dolist (button (nreverse buttons))
6405 (setq st (point))
6406 (insert " ")
6407 (mm-handle-set-undisplayer
6408 (setq handle (copy-sequence (cdr button))) nil)
6409 (gnus-insert-mime-button handle (car button))
6410 (skip-chars-backward "\t\n ")
6411 (delete-region (point) (point-max))
6412 (when (> (current-column) (window-width))
6413 (goto-char st)
6414 (insert "\n")
6415 (end-of-line)))
6416 (insert "\n")
6417 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6418 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6419 (gnus-overlay-put ovl 'face nil))
6420 (let ((gnus-treatment-function-alist
6421 '((gnus-treat-highlight-headers
6422 gnus-article-highlight-headers))))
6423 (gnus-treat-article 'head))))))))))
6425 ;;; Article savers.
6427 (defun gnus-output-to-file (file-name)
6428 "Append the current article to a file named FILE-NAME.
6429 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6430 text and used as the value of the coding cookie which is added to the
6431 top of a file. Otherwise, this function saves a raw article without
6432 the coding cookie."
6433 (let* ((artbuf (current-buffer))
6434 (file-name-coding-system nnmail-pathname-coding-system)
6435 (coding gnus-article-save-coding-system)
6436 (coding-system-for-read (if coding
6437 nil ;; Rely on the coding cookie.
6438 mm-text-coding-system))
6439 (coding-system-for-write (or coding
6440 mm-text-coding-system-for-write
6441 mm-text-coding-system))
6442 (exists (file-exists-p file-name)))
6443 (with-temp-buffer
6444 (when exists
6445 (insert-file-contents file-name)
6446 (goto-char (point-min))
6447 ;; Remove the existing coding cookie.
6448 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6449 (delete-region (match-beginning 0) (match-end 0))))
6450 (goto-char (point-max))
6451 (insert-buffer-substring artbuf)
6452 ;; Append newline at end of the buffer as separator, and then
6453 ;; save it to file.
6454 (goto-char (point-max))
6455 (insert "\n")
6456 (when coding
6457 ;; If the coding system is not suitable to encode the text,
6458 ;; ask a user for a proper one.
6459 (when (fboundp 'select-safe-coding-system)
6460 (setq coding (coding-system-base
6461 (save-window-excursion
6462 (select-safe-coding-system (point-min) (point-max)
6463 coding))))
6464 (setq coding-system-for-write
6465 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6466 coding)))
6467 (goto-char (point-min))
6468 ;; Add the coding cookie.
6469 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6470 coding-system-for-write)))
6471 (if exists
6472 (progn
6473 (write-region (point-min) (point-max) file-name nil 'no-message)
6474 (message "Appended to %s" file-name))
6475 (write-region (point-min) (point-max) file-name))))
6478 (defun gnus-narrow-to-page (&optional arg)
6479 "Narrow the article buffer to a page.
6480 If given a numerical ARG, move forward ARG pages."
6481 (interactive "P")
6482 (setq arg (if arg (prefix-numeric-value arg) 0))
6483 (with-current-buffer gnus-article-buffer
6484 (widen)
6485 ;; Remove any old next/prev buttons.
6486 (when (gnus-visual-p 'page-marker)
6487 (let ((inhibit-read-only t))
6488 (gnus-remove-text-with-property 'gnus-prev)
6489 (gnus-remove-text-with-property 'gnus-next)))
6490 (let (st nd pt)
6491 (when (save-excursion
6492 (cond ((< arg 0)
6493 (if (re-search-backward page-delimiter nil 'move (abs arg))
6494 (prog1
6495 (setq nd (match-beginning 0)
6496 pt nd)
6497 (when (re-search-backward page-delimiter nil t)
6498 (setq st (match-end 0))))
6499 (when (re-search-forward page-delimiter nil t)
6500 (setq nd (match-beginning 0)
6501 pt (point-min)))))
6502 ((> arg 0)
6503 (if (re-search-forward page-delimiter nil 'move arg)
6504 (prog1
6505 (setq st (match-end 0)
6506 pt st)
6507 (when (re-search-forward page-delimiter nil t)
6508 (setq nd (match-beginning 0))))
6509 (when (re-search-backward page-delimiter nil t)
6510 (setq st (match-end 0)
6511 pt (point-max)))))
6513 (when (re-search-backward page-delimiter nil t)
6514 (goto-char (setq st (match-end 0))))
6515 (when (re-search-forward page-delimiter nil t)
6516 (setq nd (match-beginning 0)))
6517 (or st nd))))
6518 (setq gnus-page-broken t)
6519 (when pt (goto-char pt))
6520 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6521 (when (gnus-visual-p 'page-marker)
6522 (save-excursion
6523 (when nd
6524 (goto-char nd)
6525 (gnus-insert-next-page-button))
6526 (when st
6527 (goto-char st)
6528 (gnus-insert-prev-page-button))))))))
6530 ;; Article mode commands
6532 (defun gnus-article-goto-next-page ()
6533 "Show the next page of the article."
6534 (interactive)
6535 (when (gnus-article-next-page)
6536 (goto-char (point-min))
6537 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6540 (defun gnus-article-goto-prev-page ()
6541 "Show the previous page of the article."
6542 (interactive)
6543 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6544 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6545 (gnus-article-prev-page nil)))
6547 ;; This is cleaner but currently breaks `gnus-pick-mode':
6549 ;; (defun gnus-article-goto-next-page ()
6550 ;; "Show the next page of the article."
6551 ;; (interactive)
6552 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6553 ;; (gnus-summary-next-page)))
6555 ;; (defun gnus-article-goto-prev-page ()
6556 ;; "Show the next page of the article."
6557 ;; (interactive)
6558 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6559 ;; (gnus-summary-prev-page)))
6561 (defun gnus-article-next-page (&optional lines)
6562 "Show the next page of the current article.
6563 If end of article, return non-nil. Otherwise return nil.
6564 Argument LINES specifies lines to be scrolled up."
6565 (interactive "p")
6566 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6567 (if (and (not (and gnus-article-over-scroll
6568 (> (count-lines (window-start) (point-max))
6569 (if (featurep 'xemacs)
6570 (or lines (1- (window-height)))
6571 (+ (or lines (1- (window-height))) scroll-margin)))))
6572 (save-excursion
6573 (end-of-line)
6574 (and (pos-visible-in-window-p) ;Not continuation line.
6575 (>= (point) (point-max)))))
6576 ;; Nothing in this page.
6577 (if (or (not gnus-page-broken)
6578 (save-excursion
6579 (save-restriction
6580 (widen)
6581 (forward-line)
6582 (eobp)))) ;Real end-of-buffer?
6583 (progn
6584 (when gnus-article-over-scroll
6585 (gnus-article-next-page-1 lines))
6586 t) ;Nothing more.
6587 (gnus-narrow-to-page 1) ;Go to next page.
6588 nil)
6589 ;; More in this page.
6590 (gnus-article-next-page-1 lines)
6591 nil))
6593 (defun gnus-article-beginning-of-window ()
6594 "Move point to the beginning of the window.
6595 In Emacs, the point is placed at the line number which `scroll-margin'
6596 specifies."
6597 (if (featurep 'xemacs)
6598 (move-to-window-line 0)
6599 ;; There is an obscure bug in Emacs that makes it impossible to
6600 ;; scroll past big pictures in the article buffer. Try to fix
6601 ;; this by adding a sanity check by counting the lines visible.
6602 (when (> (count-lines (window-start) (window-end)) 30)
6603 (move-to-window-line
6604 (min (max 0 scroll-margin)
6605 (max 1 (- (window-height)
6606 (if mode-line-format 1 0)
6607 (if header-line-format 1 0)
6608 2)))))))
6610 (defun gnus-article-next-page-1 (lines)
6611 (condition-case ()
6612 (let ((scroll-in-place nil)
6613 (auto-window-vscroll nil))
6614 (scroll-up lines))
6615 (end-of-buffer
6616 ;; Long lines may cause an end-of-buffer error.
6617 (goto-char (point-max))))
6618 (gnus-article-beginning-of-window))
6620 (defun gnus-article-prev-page (&optional lines)
6621 "Show previous page of current article.
6622 Argument LINES specifies lines to be scrolled down."
6623 (interactive "p")
6624 (move-to-window-line 0)
6625 (if (and gnus-page-broken
6626 (bobp)
6627 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6628 (progn
6629 (gnus-narrow-to-page -1) ;Go to previous page.
6630 (goto-char (point-max))
6631 (recenter (if gnus-article-over-scroll
6632 (if lines
6633 (max (if (featurep 'xemacs)
6634 lines
6635 (+ lines scroll-margin))
6637 (- (window-height) 2))
6638 -1)))
6639 (prog1
6640 (condition-case ()
6641 (let ((scroll-in-place nil))
6642 (scroll-down lines))
6643 (beginning-of-buffer
6644 (goto-char (point-min))))
6645 (gnus-article-beginning-of-window))))
6647 (defun gnus-article-only-boring-p ()
6648 "Decide whether there is only boring text remaining in the article.
6649 Something \"interesting\" is a word of at least two letters that does
6650 not have a face in `gnus-article-boring-faces'."
6651 (when (and gnus-article-skip-boring
6652 (boundp 'gnus-article-boring-faces)
6653 (symbol-value 'gnus-article-boring-faces))
6654 (save-excursion
6655 (let ((inhibit-point-motion-hooks t))
6656 (catch 'only-boring
6657 (while (re-search-forward "\\b\\w\\w" nil t)
6658 (forward-char -1)
6659 (when (not (gnus-intersection
6660 (gnus-faces-at (point))
6661 (symbol-value 'gnus-article-boring-faces)))
6662 (throw 'only-boring nil)))
6663 (throw 'only-boring t))))))
6665 (defun gnus-article-refer-article ()
6666 "Read article specified by message-id around point."
6667 (interactive)
6668 (save-excursion
6669 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6670 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6671 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6672 (let ((msg-id (concat "<" (match-string 0) ">")))
6673 (set-buffer gnus-summary-buffer)
6674 (gnus-summary-refer-article msg-id))
6675 (error "No references around point"))))
6677 (defun gnus-article-show-summary ()
6678 "Reconfigure windows to show summary buffer."
6679 (interactive)
6680 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6681 (error "There is no summary buffer for this article buffer")
6682 (gnus-article-set-globals)
6683 (gnus-configure-windows 'article)
6684 (gnus-summary-goto-subject gnus-current-article)
6685 (gnus-summary-position-point)))
6687 (defun gnus-article-describe-briefly ()
6688 "Describe article mode commands briefly."
6689 (interactive)
6690 (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")))
6692 (defun gnus-article-check-buffer ()
6693 "Beep if not in an article buffer."
6694 (unless (derived-mode-p 'gnus-article-mode)
6695 (error "Command invoked outside of a Gnus article buffer")))
6697 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6698 "Read a summary buffer key sequence and execute it from the article buffer."
6699 (interactive "P")
6700 (gnus-article-check-buffer)
6701 (let ((nosaves
6702 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6703 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6704 "=" "^" "\M-^" "|"))
6705 (nosave-but-article
6706 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6707 "An" "Ap" [?A (meta return)] [?A delete]))
6708 (nosave-in-article
6709 '("AS" "\C-d"))
6710 (up-to-top
6711 '("n" "Gn" "p" "Gp"))
6712 keys new-sum-point)
6713 (with-current-buffer gnus-article-current-summary
6714 (let (gnus-pick-mode)
6715 (setq unread-command-events (nconc unread-command-events
6716 (list (or key last-command-event)))
6717 keys (if (featurep 'xemacs)
6718 (events-to-keys (read-key-sequence nil t))
6719 (read-key-sequence nil t)))))
6721 (message "")
6723 (cond
6724 ((eq (aref keys (1- (length keys))) ?\C-h)
6725 (gnus-article-describe-bindings (substring keys 0 -1)))
6726 ((or (member keys nosaves)
6727 (member keys nosave-but-article)
6728 (member keys nosave-in-article))
6729 (let (func)
6730 (save-window-excursion
6731 (pop-to-buffer gnus-article-current-summary)
6732 ;; We disable the pick minor mode commands.
6733 (let (gnus-pick-mode)
6734 (setq func (key-binding keys t))))
6735 (if (or (not func)
6736 (numberp func))
6737 (ding)
6738 (unless (member keys nosave-in-article)
6739 (set-buffer gnus-article-current-summary))
6740 (when (and (symbolp func)
6741 (get func 'disabled))
6742 (error "Function %s disabled" func))
6743 (call-interactively func)
6744 (setq new-sum-point (point)))
6745 (when (member keys nosave-but-article)
6746 (pop-to-buffer gnus-article-buffer))))
6748 ;; These commands should restore window configuration.
6749 (let ((obuf (current-buffer))
6750 (owin (current-window-configuration))
6751 win func in-buffer selected new-sum-start new-sum-hscroll err)
6752 (cond (not-restore-window
6753 (pop-to-buffer gnus-article-current-summary)
6754 (setq win (selected-window)))
6755 ((setq win (get-buffer-window gnus-article-current-summary))
6756 (select-window win))
6758 (let ((summary-buffer gnus-article-current-summary))
6759 (gnus-configure-windows 'article)
6760 (unless (setq win (get-buffer-window summary-buffer 'visible))
6761 (let ((gnus-buffer-configuration
6762 '((article ((vertical 1.0
6763 (summary 0.25 point)
6764 (article 1.0)))))))
6765 (gnus-configure-windows 'article))
6766 (setq win (get-buffer-window summary-buffer 'visible)))
6767 (gnus-select-frame-set-input-focus (window-frame win))
6768 (select-window win))))
6769 (setq in-buffer (current-buffer))
6770 ;; We disable the pick minor mode commands.
6771 (setq func (let (gnus-pick-mode)
6772 (key-binding keys t)))
6773 (when (get func 'disabled)
6774 (error "Function %s disabled" func))
6775 (if (and func
6776 (functionp func)
6777 (condition-case code
6778 (progn
6779 (call-interactively func)
6781 (error
6782 (setq err code)
6783 nil)))
6784 (progn
6785 (when (eq win (selected-window))
6786 (setq new-sum-point (point)
6787 new-sum-start (window-start win)
6788 new-sum-hscroll (window-hscroll win)))
6789 (when (or (eq in-buffer (current-buffer))
6790 (when (eq obuf (current-buffer))
6791 (set-buffer in-buffer)
6793 (setq selected (gnus-summary-select-article))
6794 (set-buffer obuf)
6795 (unless not-restore-window
6796 (set-window-configuration owin))
6797 (when (and (eq selected 'old)
6798 new-sum-point)
6799 (set-window-start (get-buffer-window (current-buffer))
6801 (set-window-point (get-buffer-window (current-buffer))
6802 (if (article-goto-body)
6803 (1- (point))
6804 (point))))
6805 (when (and (not not-restore-window)
6806 new-sum-point
6807 (window-live-p win)
6808 (with-current-buffer (window-buffer win)
6809 (derived-mode-p 'gnus-summary-mode)))
6810 (set-window-point win new-sum-point)
6811 (set-window-start win new-sum-start)
6812 (set-window-hscroll win new-sum-hscroll))))
6813 (set-window-configuration owin)
6814 (if err
6815 (signal (car err) (cdr err))
6816 (ding))))))))
6818 (defun gnus-article-read-summary-send-keys ()
6819 (interactive)
6820 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6821 (gnus-article-read-summary-keys)))
6823 (defun gnus-article-describe-key (key)
6824 "Display documentation of the function invoked by KEY.
6825 KEY is a string or a vector."
6826 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6827 (read-key-sequence "Describe key: "))))
6828 (gnus-article-check-buffer)
6829 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6830 gnus-article-read-summary-send-keys))
6831 (with-current-buffer gnus-article-current-summary
6832 (setq unread-command-events
6833 (if (featurep 'xemacs)
6834 (append key nil)
6835 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6836 (list 'meta (- x 128))
6838 key)))
6839 (let ((cursor-in-echo-area t)
6840 gnus-pick-mode)
6841 (describe-key (read-key-sequence nil t))))
6842 (describe-key key)))
6844 (defun gnus-article-describe-key-briefly (key &optional insert)
6845 "Display documentation of the function invoked by KEY.
6846 KEY is a string or a vector."
6847 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6848 (read-key-sequence "Describe key: "))
6849 current-prefix-arg))
6850 (gnus-article-check-buffer)
6851 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6852 gnus-article-read-summary-send-keys))
6853 (with-current-buffer gnus-article-current-summary
6854 (setq unread-command-events
6855 (if (featurep 'xemacs)
6856 (append key nil)
6857 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6858 (list 'meta (- x 128))
6860 key)))
6861 (let ((cursor-in-echo-area t)
6862 gnus-pick-mode)
6863 (describe-key-briefly (read-key-sequence nil t) insert)))
6864 (describe-key-briefly key insert)))
6866 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6867 (defvar gnus-agent-summary-mode)
6868 (defvar gnus-draft-mode)
6869 (defvar help-xref-stack-item)
6871 (defun gnus-article-describe-bindings (&optional prefix)
6872 "Show a list of all defined keys, and their definitions.
6873 The optional argument PREFIX, if non-nil, should be a key sequence;
6874 then we display only bindings that start with that prefix."
6875 (interactive)
6876 (gnus-article-check-buffer)
6877 (let ((keymap (copy-keymap gnus-article-mode-map))
6878 (map (copy-keymap gnus-article-send-map))
6879 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6880 parent agent draft)
6881 (define-key keymap "S" map)
6882 (define-key map [t] nil)
6883 (with-current-buffer gnus-article-current-summary
6884 (set-keymap-parent
6885 keymap
6886 (if (setq parent (keymap-parent gnus-article-mode-map))
6887 (prog1
6888 (setq parent (copy-keymap parent))
6889 (set-keymap-parent parent (current-local-map)))
6890 (current-local-map)))
6891 (set-keymap-parent map (key-binding "S"))
6892 (let (key def gnus-pick-mode)
6893 (while sumkeys
6894 (setq key (pop sumkeys))
6895 (cond ((and (vectorp key) (= (length key) 1)
6896 (consp (setq def (aref key 0)))
6897 (numberp (car def)) (numberp (cdr def)))
6898 (when (< (max (car def) (cdr def)) 128)
6899 (setq sumkeys
6900 (append (mapcar
6901 #'vector
6902 (nreverse (gnus-uncompress-range def)))
6903 sumkeys))))
6904 ((setq def (key-binding key))
6905 (unless (eq def 'undefined)
6906 (define-key keymap key def))))))
6907 (when (boundp 'gnus-agent-summary-mode)
6908 (setq agent gnus-agent-summary-mode))
6909 (when (boundp 'gnus-draft-mode)
6910 (setq draft gnus-draft-mode)))
6911 (with-temp-buffer
6912 (use-local-map keymap)
6913 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6914 (set (make-local-variable 'gnus-draft-mode) draft)
6915 (describe-bindings prefix))
6916 (let ((item `((lambda (prefix)
6917 (with-current-buffer ,(current-buffer)
6918 (gnus-article-describe-bindings prefix)))
6919 ,prefix)))
6920 ;; Loading `help-mode' here is necessary if `describe-bindings'
6921 ;; is replaced with something, e.g. `helm-descbinds'.
6922 (require 'help-mode)
6923 (with-current-buffer (let (help-xref-following) (help-buffer))
6924 (setq help-xref-stack-item item)))))
6926 (defun gnus-article-reply-with-original (&optional wide)
6927 "Start composing a reply mail to the current message.
6928 The text in the region will be yanked. If the region isn't active,
6929 the entire article will be yanked."
6930 (interactive)
6931 (let ((article (cdr gnus-article-current))
6932 contents)
6933 (if (not (gnus-region-active-p))
6934 (with-current-buffer gnus-summary-buffer
6935 (gnus-summary-reply (list (list article)) wide))
6936 (setq contents (buffer-substring (point) (mark t)))
6937 ;; Deactivate active regions.
6938 (when (and (boundp 'transient-mark-mode)
6939 transient-mark-mode)
6940 (setq mark-active nil))
6941 (with-current-buffer gnus-summary-buffer
6942 (gnus-summary-reply
6943 (list (list article contents)) wide)))))
6945 (defun gnus-article-wide-reply-with-original ()
6946 "Start composing a wide reply mail to the current message.
6947 The text in the region will be yanked. If the region isn't active,
6948 the entire article will be yanked."
6949 (interactive)
6950 (gnus-article-reply-with-original t))
6952 (defun gnus-article-followup-with-original ()
6953 "Compose a followup to the current article.
6954 The text in the region will be yanked. If the region isn't active,
6955 the entire article will be yanked."
6956 (interactive)
6957 (let ((article (cdr gnus-article-current))
6958 contents)
6959 (if (not (gnus-region-active-p))
6960 (with-current-buffer gnus-summary-buffer
6961 (gnus-summary-followup (list (list article))))
6962 (setq contents (buffer-substring (point) (mark t)))
6963 ;; Deactivate active regions.
6964 (when (and (boundp 'transient-mark-mode)
6965 transient-mark-mode)
6966 (setq mark-active nil))
6967 (with-current-buffer gnus-summary-buffer
6968 (gnus-summary-followup
6969 (list (list article contents)))))))
6971 (defun gnus-article-hide (&optional arg force)
6972 "Hide all the gruft in the current article.
6973 This means that signatures, cited text and (some) headers will be
6974 hidden.
6975 If given a prefix, show the hidden text instead."
6976 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6977 (gnus-article-hide-headers arg)
6978 (gnus-article-hide-list-identifiers arg)
6979 (gnus-article-hide-citation-maybe arg force)
6980 (gnus-article-hide-signature arg))
6982 (defun gnus-check-group-server ()
6983 ;; Make sure the connection to the server is alive.
6984 (unless (gnus-server-opened
6985 (gnus-find-method-for-group gnus-newsgroup-name))
6986 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6987 (gnus-request-group gnus-newsgroup-name t)))
6989 (eval-when-compile
6990 (autoload 'nneething-get-file-name "nneething"))
6992 (defun gnus-request-article-this-buffer (article group)
6993 "Get an article and insert it into this buffer."
6994 (let (do-update-line sparse-header)
6995 (prog1
6996 (save-excursion
6997 (erase-buffer)
6998 (gnus-kill-all-overlays)
6999 (setq group (or group gnus-newsgroup-name))
7001 ;; Using `gnus-request-article' directly will insert the article into
7002 ;; `nntp-server-buffer' - so we'll save some time by not having to
7003 ;; copy it from the server buffer into the article buffer.
7005 ;; We only request an article by message-id when we do not have the
7006 ;; headers for it, so we'll have to get those.
7007 (when (stringp article)
7008 (gnus-read-header article))
7010 ;; If the article number is negative, that means that this article
7011 ;; doesn't belong in this newsgroup (possibly), so we find its
7012 ;; message-id and request it by id instead of number.
7013 (when (and (numberp article)
7014 gnus-summary-buffer
7015 (get-buffer gnus-summary-buffer)
7016 (gnus-buffer-exists-p gnus-summary-buffer))
7017 (with-current-buffer gnus-summary-buffer
7018 (let ((header (gnus-summary-article-header article)))
7019 (when (< article 0)
7020 (cond
7021 ((memq article gnus-newsgroup-sparse)
7022 ;; This is a sparse gap article.
7023 (setq do-update-line article)
7024 (setq article (mail-header-id header))
7025 (setq sparse-header (gnus-read-header article))
7026 (setq gnus-newsgroup-sparse
7027 (delq article gnus-newsgroup-sparse)))
7028 ((vectorp header)
7029 ;; It's a real article.
7030 (setq article (mail-header-id header)))
7032 ;; It is an extracted pseudo-article.
7033 (setq article 'pseudo)
7034 (gnus-request-pseudo-article header))))
7036 (let ((method (gnus-find-method-for-group
7037 gnus-newsgroup-name)))
7038 (when (and (eq (car method) 'nneething)
7039 (vectorp header))
7040 (let ((dir (nneething-get-file-name
7041 (mail-header-id header))))
7042 (when (and (stringp dir)
7043 (file-directory-p dir))
7044 (setq article 'nneething)
7045 (gnus-group-enter-directory dir))))))))
7047 (cond
7048 ;; Refuse to select canceled articles.
7049 ((and (numberp article)
7050 gnus-summary-buffer
7051 (get-buffer gnus-summary-buffer)
7052 (gnus-buffer-exists-p gnus-summary-buffer)
7053 (eq (cdr (with-current-buffer gnus-summary-buffer
7054 (assq article gnus-newsgroup-reads)))
7055 gnus-canceled-mark))
7056 nil)
7057 ;; We first check `gnus-original-article-buffer'.
7058 ((and (get-buffer gnus-original-article-buffer)
7059 (numberp article)
7060 (with-current-buffer gnus-original-article-buffer
7061 (and (equal (car gnus-original-article) group)
7062 (eq (cdr gnus-original-article) article))))
7063 ;; `insert-buffer-substring' would incorrectly use the
7064 ;; equivalent of string-make-multibyte which amount to decoding
7065 ;; with locale-coding-system, causing failure of
7066 ;; subsequent decoding.
7067 (insert (mm-string-to-multibyte
7068 (with-current-buffer gnus-original-article-buffer
7069 (buffer-substring (point-min) (point-max)))))
7070 'article)
7071 ;; Check the backlog.
7072 ((and gnus-keep-backlog
7073 (gnus-backlog-request-article group article (current-buffer)))
7074 'article)
7075 ;; Check asynchronous pre-fetch.
7076 ((gnus-async-request-fetched-article group article (current-buffer))
7077 (gnus-async-prefetch-next group article gnus-summary-buffer)
7078 (when (and (numberp article) gnus-keep-backlog)
7079 (gnus-backlog-enter-article group article (current-buffer)))
7080 'article)
7081 ;; Check the cache.
7082 ((and gnus-use-cache
7083 (numberp article)
7084 (gnus-cache-request-article article group))
7085 'article)
7086 ;; Check the agent cache.
7087 ((gnus-agent-request-article article group)
7088 'article)
7089 ;; Get the article and put into the article buffer.
7090 ((or (stringp article)
7091 (numberp article))
7092 (let ((gnus-override-method gnus-override-method)
7093 (methods (and (stringp article)
7094 (with-current-buffer gnus-summary-buffer
7095 (gnus-refer-article-methods))))
7096 (backend (car (gnus-find-method-for-group
7097 gnus-newsgroup-name)))
7098 result
7099 (inhibit-read-only t))
7100 (when (and (null gnus-override-method)
7101 methods)
7102 (setq gnus-override-method (pop methods)))
7103 (while (not result)
7104 (erase-buffer)
7105 (gnus-kill-all-overlays)
7106 (let ((gnus-newsgroup-name group))
7107 (gnus-check-group-server))
7108 (cond
7109 ((gnus-request-article article group (current-buffer))
7110 (when (numberp article)
7111 (gnus-async-prefetch-next group article
7112 gnus-summary-buffer)
7113 (when gnus-keep-backlog
7114 (gnus-backlog-enter-article
7115 group article (current-buffer)))
7116 (when (and gnus-agent
7117 (gnus-agent-group-covered-p group))
7118 (gnus-agent-store-article article group)))
7119 (setq result 'article))
7120 (methods
7121 (setq gnus-override-method (pop methods)))
7122 ((not (string-match "^400 "
7123 (nnheader-get-report backend)))
7124 ;; If we get 400 server disconnect, reconnect and
7125 ;; retry; otherwise, assume the article has expired.
7126 (setq result 'done))))
7127 (and (eq result 'article) 'article)))
7128 ;; It was a pseudo.
7129 (t article)))
7131 ;; Associate this article with the current summary buffer.
7132 (setq gnus-article-current-summary gnus-summary-buffer)
7134 ;; Take the article from the original article buffer
7135 ;; and place it in the buffer it's supposed to be in.
7136 (when (and (get-buffer gnus-article-buffer)
7137 (equal (buffer-name (current-buffer))
7138 (buffer-name (get-buffer gnus-article-buffer))))
7139 (save-excursion
7140 (if (get-buffer gnus-original-article-buffer)
7141 (set-buffer gnus-original-article-buffer)
7142 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7143 (buffer-disable-undo)
7144 (setq major-mode 'gnus-original-article-mode)
7145 (setq buffer-read-only t))
7146 (let ((inhibit-read-only t))
7147 (erase-buffer)
7148 (insert-buffer-substring gnus-article-buffer))
7149 (setq gnus-original-article (cons group article)))
7151 ;; Decode charsets.
7152 (run-hooks 'gnus-article-decode-hook)
7153 ;; Mark article as decoded or not.
7154 (setq gnus-article-decoded-p gnus-article-decode-hook))
7156 ;; Update sparse articles.
7157 (when (and do-update-line
7158 (or (numberp article)
7159 (stringp article)))
7160 (let ((buf (current-buffer)))
7161 (set-buffer gnus-summary-buffer)
7162 (gnus-summary-update-article do-update-line sparse-header)
7163 (gnus-summary-goto-subject do-update-line nil t)
7164 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7165 (point))
7166 (set-buffer buf))))))
7168 (defun gnus-block-private-groups (group)
7169 (if (or (gnus-news-group-p group)
7170 (gnus-member-of-valid 'global group))
7171 ;; Block nothing in news groups.
7173 ;; Block everything anywhere else.
7174 "."))
7176 (defun gnus-blocked-images ()
7177 (if (functionp gnus-blocked-images)
7178 (funcall gnus-blocked-images gnus-newsgroup-name)
7179 gnus-blocked-images))
7182 ;;; Article editing
7185 (defcustom gnus-article-edit-mode-hook nil
7186 "Hook run in article edit mode buffers."
7187 :group 'gnus-article-various
7188 :type 'hook)
7190 (defvar gnus-article-edit-done-function nil)
7192 (defvar gnus-article-edit-mode-map nil)
7194 ;; Should we be using derived.el for this?
7195 (unless gnus-article-edit-mode-map
7196 (setq gnus-article-edit-mode-map (make-keymap))
7197 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7199 (gnus-define-keys gnus-article-edit-mode-map
7200 "\C-c?" describe-mode
7201 "\C-c\C-c" gnus-article-edit-done
7202 "\C-c\C-k" gnus-article-edit-exit
7203 "\C-c\C-f\C-t" message-goto-to
7204 "\C-c\C-f\C-o" message-goto-from
7205 "\C-c\C-f\C-b" message-goto-bcc
7206 ;;"\C-c\C-f\C-w" message-goto-fcc
7207 "\C-c\C-f\C-c" message-goto-cc
7208 "\C-c\C-f\C-s" message-goto-subject
7209 "\C-c\C-f\C-r" message-goto-reply-to
7210 "\C-c\C-f\C-n" message-goto-newsgroups
7211 "\C-c\C-f\C-d" message-goto-distribution
7212 "\C-c\C-f\C-f" message-goto-followup-to
7213 "\C-c\C-f\C-m" message-goto-mail-followup-to
7214 "\C-c\C-f\C-k" message-goto-keywords
7215 "\C-c\C-f\C-u" message-goto-summary
7216 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7217 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7218 "\C-c\C-b" message-goto-body
7219 "\C-c\C-i" message-goto-signature
7221 "\C-c\C-t" message-insert-to
7222 "\C-c\C-n" message-insert-newsgroups
7223 "\C-c\C-o" message-sort-headers
7224 "\C-c\C-e" message-elide-region
7225 "\C-c\C-v" message-delete-not-region
7226 "\C-c\C-z" message-kill-to-signature
7227 "\M-\r" message-newline-and-reformat
7228 "\C-c\C-a" mml-attach-file
7229 "\C-a" message-beginning-of-line
7230 "\t" message-tab
7231 "\M-;" comment-region)
7233 (gnus-define-keys (gnus-article-edit-wash-map
7234 "\C-c\C-w" gnus-article-edit-mode-map)
7235 "f" gnus-article-edit-full-stops))
7237 (easy-menu-define
7238 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7239 '("Field"
7240 ["Fetch To" message-insert-to t]
7241 ["Fetch Newsgroups" message-insert-newsgroups t]
7242 "----"
7243 ["To" message-goto-to t]
7244 ["From" message-goto-from t]
7245 ["Subject" message-goto-subject t]
7246 ["Cc" message-goto-cc t]
7247 ["Reply-To" message-goto-reply-to t]
7248 ["Summary" message-goto-summary t]
7249 ["Keywords" message-goto-keywords t]
7250 ["Newsgroups" message-goto-newsgroups t]
7251 ["Followup-To" message-goto-followup-to t]
7252 ["Mail-Followup-To" message-goto-mail-followup-to t]
7253 ["Distribution" message-goto-distribution t]
7254 ["Body" message-goto-body t]
7255 ["Signature" message-goto-signature t]))
7257 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7258 "Major mode for editing articles.
7259 This is an extended text-mode.
7261 \\{gnus-article-edit-mode-map}"
7262 (make-local-variable 'gnus-article-edit-done-function)
7263 (make-local-variable 'gnus-prev-winconf)
7264 (set (make-local-variable 'font-lock-defaults)
7265 '(message-font-lock-keywords t))
7266 (set (make-local-variable 'mail-header-separator) "")
7267 (set (make-local-variable 'gnus-article-edit-mode) t)
7268 (easy-menu-add message-mode-field-menu message-mode-map)
7269 (mml-mode)
7270 (setq buffer-read-only nil)
7271 (buffer-enable-undo)
7272 (widen))
7274 (defun gnus-article-edit (&optional force)
7275 "Edit the current article.
7276 This will have permanent effect only in mail groups.
7277 If FORCE is non-nil, allow editing of articles even in read-only
7278 groups."
7279 (interactive "P")
7280 (when (and (not force)
7281 (gnus-group-read-only-p))
7282 (error "The current newsgroup does not support article editing"))
7283 (gnus-article-date-original)
7284 (gnus-article-edit-article
7285 'ignore
7286 `(lambda (no-highlight)
7287 'ignore
7288 (gnus-summary-edit-article-done
7289 ,(or (mail-header-references gnus-current-headers) "")
7290 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7292 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7293 "Start editing the contents of the current article buffer."
7294 (let ((winconf (current-window-configuration)))
7295 (set-buffer gnus-article-buffer)
7296 (let ((message-auto-save-directory
7297 ;; Don't associate the article buffer with a draft file.
7298 nil))
7299 (gnus-article-edit-mode))
7300 (funcall start-func)
7301 (set-buffer-modified-p nil)
7302 (gnus-configure-windows 'edit-article)
7303 (setq gnus-article-edit-done-function exit-func)
7304 (setq gnus-prev-winconf winconf)
7305 (unless quiet
7306 (gnus-message 6 "C-c C-c to end edits"))))
7308 (defun gnus-article-edit-done (&optional arg)
7309 "Update the article edits and exit."
7310 (interactive "P")
7311 (let ((func gnus-article-edit-done-function)
7312 (buf (current-buffer))
7313 (start (window-start))
7314 (p (point))
7315 (winconf gnus-prev-winconf))
7316 (widen) ;; Widen it in case that users narrowed the buffer.
7317 (funcall func arg)
7318 (set-buffer buf)
7319 ;; The cache and backlog have to be flushed somewhat.
7320 (when gnus-keep-backlog
7321 (gnus-backlog-remove-article
7322 (car gnus-article-current) (cdr gnus-article-current)))
7323 ;; Flush original article as well.
7324 (gnus-flush-original-article-buffer)
7325 (when gnus-use-cache
7326 (gnus-cache-update-article
7327 (car gnus-article-current) (cdr gnus-article-current)))
7328 ;; We remove all text props from the article buffer.
7329 (kill-all-local-variables)
7330 (set-text-properties (point-min) (point-max) nil)
7331 (gnus-article-mode)
7332 (set-window-configuration winconf)
7333 (set-buffer buf)
7334 (set-window-start (get-buffer-window buf) start)
7335 (set-window-point (get-buffer-window buf) (point)))
7336 (gnus-summary-show-article))
7338 (defun gnus-flush-original-article-buffer ()
7339 (when (get-buffer gnus-original-article-buffer)
7340 (with-current-buffer gnus-original-article-buffer
7341 (setq gnus-original-article nil))))
7343 (defun gnus-article-edit-exit ()
7344 "Exit the article editing without updating."
7345 (interactive)
7346 (when (or (not (buffer-modified-p))
7347 (yes-or-no-p "Article modified; kill anyway? "))
7348 (let ((curbuf (current-buffer))
7349 (p (point))
7350 (window-start (window-start)))
7351 (erase-buffer)
7352 (if (gnus-buffer-live-p gnus-original-article-buffer)
7353 (insert-buffer-substring gnus-original-article-buffer))
7354 (let ((winconf gnus-prev-winconf))
7355 (kill-all-local-variables)
7356 (gnus-article-mode)
7357 (set-window-configuration winconf)
7358 ;; Tippy-toe some to make sure that point remains where it was.
7359 (save-current-buffer
7360 (set-buffer curbuf)
7361 (set-window-start (get-buffer-window (current-buffer)) window-start)
7362 (goto-char p))))
7363 (gnus-summary-show-article)))
7365 (defun gnus-article-edit-full-stops ()
7366 "Interactively repair spacing at end of sentences."
7367 (interactive)
7368 (save-excursion
7369 (goto-char (point-min))
7370 (search-forward-regexp "^$" nil t)
7371 (let ((case-fold-search nil))
7372 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7375 ;;; Article highlights
7378 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7380 ;;; Internal Variables:
7382 (defcustom gnus-button-url-regexp
7383 (concat
7384 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7385 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7386 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7387 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7388 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7389 (punct "!?:;.,"))
7390 (concat
7391 "\\(?:"
7392 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7393 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7394 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7395 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7396 "\\|"
7397 "[" chars punct "]+" "[" chars "]"
7398 "\\)"))
7399 (concat ;; XEmacs 21.4 doesn't support POSIX.
7400 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7401 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7402 "\\)")
7403 "Regular expression that matches URLs."
7404 :version "24.4"
7405 :group 'gnus-article-buttons
7406 :type 'regexp)
7408 (defcustom gnus-button-valid-fqdn-regexp
7409 message-valid-fqdn-regexp
7410 "Regular expression that matches a valid FQDN."
7411 :version "22.1"
7412 :group 'gnus-article-buttons
7413 :type 'regexp)
7415 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7416 (defcustom gnus-button-valid-localpart-regexp
7417 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7418 "Regular expression that matches a localpart of mail addresses or MIDs."
7419 :version "22.1"
7420 :group 'gnus-article-buttons
7421 :type 'regexp)
7423 (defcustom gnus-button-man-handler 'manual-entry
7424 "Function to use for displaying man pages.
7425 The function must take at least one argument with a string naming the
7426 man page."
7427 :version "22.1"
7428 :type '(choice (function-item :tag "Man" manual-entry)
7429 (function-item :tag "Woman" woman)
7430 (function :tag "Other"))
7431 :group 'gnus-article-buttons)
7433 (defcustom gnus-button-mid-or-mail-regexp
7434 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7435 gnus-button-valid-fqdn-regexp
7436 ">?\\)\\b")
7437 "Regular expression that matches a message ID or a mail address."
7438 :version "22.1"
7439 :group 'gnus-article-buttons
7440 :type 'regexp)
7442 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7443 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7444 Strings like this can be either a message ID or a mail address. If it is one
7445 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7446 message ID or a mail address, respectively. If this variable is set to the
7447 symbol `ask', always query the user what do do. If it is a function, this
7448 function will be called with the string as its only argument. The function
7449 must return `mid', `mail', `invalid' or `ask'."
7450 :version "22.1"
7451 :group 'gnus-article-buttons
7452 :type '(choice (function-item :tag "Heuristic function"
7453 gnus-button-mid-or-mail-heuristic)
7454 (const ask)
7455 (const mid)
7456 (const mail)))
7458 (defcustom gnus-button-mid-or-mail-heuristic-alist
7459 '((-10.0 . ".+\\$.+@")
7460 (-10.0 . "#")
7461 (-10.0 . "\\*")
7462 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7463 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7464 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7465 (-1.0 . "^[^a-z]+@")
7467 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7468 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7469 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7470 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7472 (-2.0 . "^[0-9]")
7473 (-1.0 . "^[0-9][0-9]")
7475 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7476 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7477 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7478 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7480 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7481 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7482 ;; "[0-9]{8,}.*\@"
7483 (-3.0
7484 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7485 ;; "[0-9]{12,}.*\@"
7486 ;; compensation for TDMA dated mail addresses:
7487 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7489 (-20.0 . "\\.fsf@") ;; Gnus
7490 (-20.0 . "^slrn")
7491 (-20.0 . "^Pine")
7492 (-20.0 . "^alpine\\.")
7493 (-20.0 . "_-_") ;; Subject change in thread
7495 (-20.0 . "\\.ln@") ;; leafnode
7496 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7497 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7499 ;; (5.0 . "") ;; $local_part_len <= 7
7500 (10.0 . "^[^0-9]+@")
7501 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7502 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7503 (3.0 . "\@stud")
7505 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7507 (0.5 . "^[A-Z][a-z]")
7508 (0.5 . "^[A-Z][a-z][a-z]")
7509 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7510 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7511 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7513 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7514 address. The REGEXP is processed with `case-fold-search' set to nil."
7515 :version "22.1"
7516 :group 'gnus-article-buttons
7517 :type '(repeat (cons (number :tag "Rate")
7518 (regexp :tag "Regexp"))))
7520 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7521 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7522 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7523 address, `ask' if unsure and `invalid' if the string is invalid."
7524 (let ((case-fold-search nil)
7525 (list gnus-button-mid-or-mail-heuristic-alist)
7526 (result 0) rate regexp lpartlen elem)
7527 (setq lpartlen
7528 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7529 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7530 ;; Certain special cases...
7531 (when (string-match
7532 (concat
7533 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7534 "^[0-9]+\\.[0-9]+@compuserve\\|"
7535 "@public\\.gmane\\.org")
7536 mid-or-mail)
7537 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7538 (setq result 'mail))
7539 (when (string-match "@.*@\\| " mid-or-mail)
7540 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7541 (setq result 'invalid))
7542 ;; Nothing more to do, if result is not a number here...
7543 (when (numberp result)
7544 (while list
7545 (setq elem (car list)
7546 rate (car elem)
7547 regexp (cdr elem)
7548 list (cdr list))
7549 (when (string-match regexp mid-or-mail)
7550 (setq result (+ result rate))
7551 (gnus-message
7552 9 "`%s' matched `%s', rate `%s', result `%s'."
7553 mid-or-mail regexp rate result)))
7554 (when (<= lpartlen 7)
7555 (setq result (+ result 5.0))
7556 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7557 mid-or-mail result))
7558 (when (>= lpartlen 12)
7559 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7560 (cond
7561 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7562 ;; Long local part should contain realname if e-mail address,
7563 ;; too many digits: message-id.
7564 ;; $score -= 5.0 + 0.1 * $local_part_len;
7565 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7566 (setq result (+ result rate))
7567 (gnus-message
7568 9 "Many digits in `%s', rate `%s', result `%s'."
7569 mid-or-mail rate result))
7570 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7571 mid-or-mail)
7572 ;; Too few vowels [^aeiouy]{4,}.*\@
7573 (setq result (+ result -5.0))
7574 (gnus-message
7575 9 "Few vowels in `%s', rate `%s', result `%s'."
7576 mid-or-mail -5.0 result))
7578 (setq result (+ result 5.0))
7579 (gnus-message
7580 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7581 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7582 ;; Maybe we should make this a customizable alist: (condition . 'result)
7583 (cond
7584 ((symbolp result) result)
7585 ;; Now convert number into proper results:
7586 ((< result -10.0) 'mid)
7587 ((> result 10.0) 'mail)
7588 (t 'ask))))
7590 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7591 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7592 (url-mid (concat "news" ":" mid-or-mail))
7593 (url-mailto (concat "mailto" ":" mid-or-mail)))
7594 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7595 (when (fboundp pref)
7596 (setq guessed
7597 ;; get rid of surrounding angles...
7598 (funcall pref
7599 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7600 (if (or (eq 'mid guessed) (eq 'mail guessed))
7601 (setq pref guessed)
7602 (setq pref 'ask)))
7603 (if (eq pref 'ask)
7604 (save-window-excursion
7605 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7606 (setq pref 'mail)
7607 (setq pref 'mid))))
7608 (cond ((eq pref 'mid)
7609 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7610 (gnus-button-handle-news url-mid))
7611 ((eq pref 'mail)
7612 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7613 (gnus-url-mailto url-mailto))
7614 (t (gnus-message 3 "Invalid string.")))))
7616 (defun gnus-button-handle-custom (fun arg)
7617 "Call function FUN on argument ARG.
7618 Both FUN and ARG are supposed to be strings. ARG will be passed
7619 as a symbol to FUN."
7620 (funcall (intern fun)
7621 (if (string-match "^customize-apropos" fun)
7623 (intern arg))))
7625 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7627 (defun gnus-button-handle-describe-function (url)
7628 "Call `describe-function' when pushing the corresponding URL button."
7629 (describe-function
7630 (intern
7631 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7633 (defun gnus-button-handle-describe-variable (url)
7634 "Call `describe-variable' when pushing the corresponding URL button."
7635 (describe-variable
7636 (intern
7637 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7639 (defun gnus-button-handle-symbol (url)
7640 "Display help on variable or function.
7641 Calls `describe-variable' or `describe-function'."
7642 (let ((sym (intern url)))
7643 (cond
7644 ((fboundp sym) (describe-function sym))
7645 ((boundp sym) (describe-variable sym))
7646 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7648 (defun gnus-button-handle-describe-key (url)
7649 "Call `describe-key' when pushing the corresponding URL button."
7650 (let* ((key-string
7651 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7652 (keys (ignore-errors (eval `(kbd ,key-string)))))
7653 (if keys
7654 (describe-key keys)
7655 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7657 (defun gnus-button-handle-apropos (url)
7658 "Call `apropos' when pushing the corresponding URL button."
7659 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7661 (defun gnus-button-handle-apropos-command (url)
7662 "Call `apropos' when pushing the corresponding URL button."
7663 (apropos-command
7664 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7666 (defun gnus-button-handle-apropos-variable (url)
7667 "Call `apropos' when pushing the corresponding URL button."
7668 (funcall
7669 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7670 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7672 (defun gnus-button-handle-apropos-documentation (url)
7673 "Call `apropos' when pushing the corresponding URL button."
7674 (funcall
7675 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7676 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7678 (defun gnus-button-handle-library (url)
7679 "Call `locate-library' when pushing the corresponding URL button."
7680 (gnus-message 9 "url=`%s'" url)
7681 (let* ((lib (locate-library url))
7682 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7683 (if (not lib)
7684 (gnus-message 1 "Cannot locale library `%s'." url)
7685 (find-file-read-only file))))
7687 (defcustom gnus-button-man-level 5
7688 "*Integer that says how many man-related buttons Gnus will show.
7689 The higher the number, the more buttons will appear and the more false
7690 positives are possible. Note that you can set this variable local to
7691 specific groups. Setting it higher in Unix groups is probably a good idea.
7692 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7693 how to set variables in specific groups."
7694 :version "22.1"
7695 :group 'gnus-article-buttons
7696 :link '(custom-manual "(gnus)Group Parameters")
7697 :type 'integer)
7699 (defcustom gnus-button-emacs-level 5
7700 "*Integer that says how many emacs-related buttons Gnus will show.
7701 The higher the number, the more buttons will appear and the more false
7702 positives are possible. Note that you can set this variable local to
7703 specific groups. Setting it higher in Emacs or Gnus related groups is
7704 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7705 `gnus-parameters' on how to set variables in specific groups."
7706 :version "22.1"
7707 :group 'gnus-article-buttons
7708 :link '(custom-manual "(gnus)Group Parameters")
7709 :type 'integer)
7711 (defcustom gnus-button-message-level 5
7712 "*Integer that says how many buttons for news or mail messages will appear.
7713 The higher the number, the more buttons will appear and the more false
7714 positives are possible."
7715 ;; mail addresses, MIDs, URLs for news, ...
7716 :version "22.1"
7717 :group 'gnus-article-buttons
7718 :type 'integer)
7720 (defcustom gnus-button-browse-level 5
7721 "*Integer that says how many buttons for browsing will appear.
7722 The higher the number, the more buttons will appear and the more false
7723 positives are possible."
7724 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7725 :version "22.1"
7726 :group 'gnus-article-buttons
7727 :type 'integer)
7729 (defcustom gnus-button-alist
7730 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7731 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7732 ((concat "\\b\\(nntp\\|news\\):\\("
7733 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7734 0 t gnus-button-handle-news 2)
7735 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7736 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7737 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7738 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7739 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7740 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7741 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7742 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7743 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7744 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7745 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7746 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7747 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7748 ;; RFC 2368 (The mailto URL scheme)
7749 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7750 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7751 ("\\bmailto:\\([^ \n\t]+\\)"
7752 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7753 ;; Info Konqueror style <info:/foo/bar baz>.
7754 ;; Must come before " Gnus home-grown style".
7755 ("\\binfo://?\\([^'\">\n\t]+\\)"
7756 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7757 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7758 ("\\binfo://\\([^'\">\n\t ]+\\)"
7759 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7760 ;; Info GNOME style <info:foo#bar_baz>
7761 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7762 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7763 ;; Info KDE style <info:(foo)bar baz>
7764 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7765 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7766 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7767 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7768 ("\\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,]*\\)\\)?"
7769 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7770 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7771 ;; This is custom
7772 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7773 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7774 ;; Emacs help commands
7775 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7776 ;; regexp doesn't match arguments containing ` '.
7777 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7778 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7779 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7780 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7781 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7782 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7783 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7784 ;; The following entries may lead to many false positives so don't enable
7785 ;; them by default (use a high button level).
7786 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7787 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7788 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7789 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7790 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7791 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7792 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7793 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7794 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7795 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7796 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7797 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7798 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7799 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7800 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7801 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7802 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7803 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7804 ;; Unlike the other regexps we really have to require quoting
7805 ;; here to determine where it ends.
7806 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7807 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7808 ("<URL: *\\([^\n<>]*\\)>"
7809 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7810 ;; RFC 2396 (2.4.3., delims) ...
7811 ("\"URL: *\\([^\n\"]*\\)\""
7812 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7813 ;; Raw URLs.
7814 (gnus-button-url-regexp
7815 0 (>= gnus-button-browse-level 0) browse-url 0)
7816 ;; man pages
7817 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7818 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7819 gnus-button-handle-man 1)
7820 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7821 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7822 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7823 gnus-button-handle-man 1)
7824 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7825 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7826 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7827 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7828 ;; Recognizing patches to .el files. This is somewhat obscure,
7829 ;; but considering the percentage of Gnus users who hack Emacs
7830 ;; Lisp files...
7831 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7832 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7833 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7834 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7835 ;; MID or mail: To avoid too many false positives we don't try to catch
7836 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7837 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7838 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7839 ;; so that non-ambiguous entries (see above) match first.
7840 (gnus-button-mid-or-mail-regexp
7841 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7842 "*Alist of regexps matching buttons in article bodies.
7844 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7845 REGEXP: is the string (case insensitive) matching text around the button (can
7846 also be Lisp expression evaluating to a string),
7847 BUTTON: is the number of the regexp grouping actually matching the button,
7848 FORM: is a Lisp expression which must eval to true for the button to
7849 be added,
7850 CALLBACK: is the function to call when the user push this button, and each
7851 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7853 CALLBACK can also be a variable, in that case the value of that
7854 variable it the real callback function."
7855 :group 'gnus-article-buttons
7856 :type '(repeat (list (choice regexp variable sexp)
7857 (integer :tag "Button")
7858 (sexp :tag "Form")
7859 (function :tag "Callback")
7860 (repeat :tag "Par"
7861 :inline t
7862 (integer :tag "Regexp group")))))
7863 (put 'gnus-button-alist 'risky-local-variable t)
7865 (defcustom gnus-header-button-alist
7866 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7867 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7868 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7869 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7870 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7871 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7872 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7873 0 (>= gnus-button-browse-level 0) browse-url 0)
7874 ("^Subject:" gnus-button-url-regexp
7875 0 (>= gnus-button-browse-level 0) browse-url 0)
7876 ("^[^:]+:" gnus-button-url-regexp
7877 0 (>= gnus-button-browse-level 0) browse-url 0)
7878 ("^OpenPGP:.*url=" gnus-button-url-regexp
7879 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7880 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7881 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7882 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7883 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7884 "*Alist of headers and regexps to match buttons in article heads.
7886 This alist is very similar to `gnus-button-alist', except that each
7887 alist has an additional HEADER element first in each entry:
7889 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7891 HEADER is a regexp to match a header. For a fuller explanation, see
7892 `gnus-button-alist'."
7893 :group 'gnus-article-buttons
7894 :group 'gnus-article-headers
7895 :type '(repeat (list (regexp :tag "Header")
7896 (choice regexp variable)
7897 (integer :tag "Button")
7898 (sexp :tag "Form")
7899 (function :tag "Callback")
7900 (repeat :tag "Par"
7901 :inline t
7902 (integer :tag "Regexp group")))))
7903 (put 'gnus-header-button-alist 'risky-local-variable t)
7905 ;;; Commands:
7907 (defun gnus-article-push-button (event)
7908 "Check text under the mouse pointer for a callback function.
7909 If the text under the mouse pointer has a `gnus-callback' property,
7910 call it with the value of the `gnus-data' text property."
7911 (interactive "e")
7912 (set-buffer (window-buffer (posn-window (event-start event))))
7913 (let* ((pos (posn-point (event-start event)))
7914 (data (get-text-property pos 'gnus-data))
7915 (fun (get-text-property pos 'gnus-callback)))
7916 (goto-char pos)
7917 (when fun
7918 (funcall fun data))))
7920 (defun gnus-article-press-button ()
7921 "Check text at point for a callback function.
7922 If the text at point has a `gnus-callback' property,
7923 call it with the value of the `gnus-data' text property."
7924 (interactive)
7925 (let ((data (get-text-property (point) 'gnus-data))
7926 (fun (get-text-property (point) 'gnus-callback)))
7927 (when fun
7928 (funcall fun data))))
7930 (defun gnus-article-highlight (&optional force)
7931 "Highlight current article.
7932 This function calls `gnus-article-highlight-headers',
7933 `gnus-article-highlight-citation',
7934 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7935 do the highlighting. See the documentation for those functions."
7936 (interactive (list 'force))
7937 (gnus-article-highlight-headers)
7938 (gnus-article-highlight-citation force)
7939 (gnus-article-highlight-signature)
7940 (gnus-article-add-buttons)
7941 (gnus-article-add-buttons-to-head))
7943 (defun gnus-article-highlight-some (&optional force)
7944 "Highlight current article.
7945 This function calls `gnus-article-highlight-headers',
7946 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7947 do the highlighting. See the documentation for those functions."
7948 (interactive (list 'force))
7949 (gnus-article-highlight-headers)
7950 (gnus-article-highlight-signature)
7951 (gnus-article-add-buttons))
7953 (defun gnus-article-highlight-headers ()
7954 "Highlight article headers as specified by `gnus-header-face-alist'."
7955 (interactive)
7956 (gnus-with-article-headers
7957 (let (regexp header-face field-face from hpoints fpoints)
7958 (dolist (entry gnus-header-face-alist)
7959 (goto-char (point-min))
7960 (setq regexp (concat "^\\("
7961 (if (string-equal "" (nth 0 entry))
7962 "[^\t ]"
7963 (nth 0 entry))
7964 "\\)")
7965 header-face (nth 1 entry)
7966 field-face (nth 2 entry))
7967 (while (and (re-search-forward regexp nil t)
7968 (not (eobp)))
7969 (beginning-of-line)
7970 (setq from (point))
7971 (unless (search-forward ":" nil t)
7972 (forward-char 1))
7973 (when (and header-face
7974 (not (memq (point) hpoints)))
7975 (push (point) hpoints)
7976 (gnus-put-text-property from (point) 'face header-face))
7977 (when (and field-face
7978 (not (memq (setq from (point)) fpoints)))
7979 (push from fpoints)
7980 (if (re-search-forward "^[^ \t]" nil t)
7981 (forward-char -2)
7982 (goto-char (point-max)))
7983 (gnus-put-text-property from (point) 'face field-face)))))))
7985 (defun gnus-article-highlight-signature ()
7986 "Highlight the signature in an article.
7987 It does this by highlighting everything after
7988 `gnus-signature-separator' using the face `gnus-signature'."
7989 (interactive)
7990 (gnus-with-article-buffer
7991 (let ((inhibit-point-motion-hooks t))
7992 (save-restriction
7993 (when (and gnus-signature-face
7994 (gnus-article-narrow-to-signature))
7995 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7996 'face gnus-signature-face)
7997 (widen)
7998 (gnus-article-search-signature)
7999 (let ((start (match-beginning 0))
8000 (end (set-marker (make-marker) (1+ (match-end 0)))))
8001 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8002 end)))))))
8004 (defun gnus-button-in-region-p (b e prop)
8005 "Say whether PROP exists in the region."
8006 (text-property-not-all b e prop nil))
8008 (defun gnus-article-add-buttons ()
8009 "Find external references in the article and make buttons of them.
8010 \"External references\" are things like Message-IDs and URLs, as
8011 specified by `gnus-button-alist'."
8012 (interactive)
8013 (gnus-with-article-buffer
8014 (let ((inhibit-point-motion-hooks t)
8015 (case-fold-search t)
8016 (alist gnus-button-alist)
8017 beg entry regexp)
8018 ;; We skip the headers.
8019 (article-goto-body)
8020 (setq beg (point))
8021 (while (setq entry (pop alist))
8022 (setq regexp (eval (car entry)))
8023 (goto-char beg)
8024 (while (re-search-forward regexp nil t)
8025 (let ((start (match-beginning (nth 1 entry)))
8026 (end (match-end (nth 1 entry)))
8027 (from (match-beginning 0)))
8028 (when (and (eval (nth 2 entry))
8029 (not (gnus-button-in-region-p
8030 start end 'gnus-callback)))
8031 ;; That optional form returned non-nil, so we add the
8032 ;; button.
8033 (setq from (set-marker (make-marker) from))
8034 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8035 (gnus-article-extend-url-button from start end))
8036 (gnus-article-add-button start end
8037 'gnus-button-push (list from entry))
8038 (gnus-put-text-property
8039 start end
8040 'gnus-string (buffer-substring-no-properties
8041 start end))))))))))
8043 (defun gnus-article-extend-url-button (beg start end)
8044 "Extend url button if url is folded into two or more lines.
8045 Return non-nil if button is extended. BEG is a marker that points to
8046 the beginning position of a text containing url. START and END are
8047 the endpoints of a url button before it is extended. The concatenated
8048 url is put as the `gnus-button-url' overlay property on the button."
8049 (let ((opoint (point))
8050 (points (list start end))
8051 url delim regexp)
8052 (prog1
8053 (when (and (progn
8054 (goto-char end)
8055 (not (looking-at "[\t ]*[\">]")))
8056 (progn
8057 (goto-char start)
8058 (string-match
8059 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8060 (buffer-substring (point-at-bol) start)))
8061 (progn
8062 (setq url (list (buffer-substring start end))
8063 delim (if (match-beginning 1) ">" "\""))
8064 (beginning-of-line)
8065 (setq regexp (concat
8066 (when (and (looking-at
8067 message-cite-prefix-regexp)
8068 (< (match-end 0) start))
8069 (regexp-quote (match-string 0)))
8071 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8072 delim "\\)"))
8073 (while (progn
8074 (forward-line 1)
8075 (and (looking-at regexp)
8076 (prog1
8077 (match-beginning 1)
8078 (push (or (match-string 2)
8079 (match-string 1))
8080 url)
8081 (push (setq end (or (match-end 2)
8082 (match-end 1)))
8083 points)
8084 (push (or (match-beginning 2)
8085 (match-beginning 1))
8086 points)))))
8087 (match-beginning 2)))
8088 (let (gnus-article-mouse-face widget-mouse-face)
8089 (while points
8090 (gnus-article-add-button (pop points) (pop points)
8091 'gnus-button-push
8092 (list beg (assq 'gnus-button-url-regexp
8093 gnus-button-alist)))))
8094 (let ((overlay (gnus-make-overlay start end)))
8095 (gnus-overlay-put overlay 'evaporate t)
8096 (gnus-overlay-put overlay 'gnus-button-url
8097 (list (mapconcat 'identity (nreverse url) "")))
8098 (when gnus-article-mouse-face
8099 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8101 (goto-char opoint))))
8103 ;; Add buttons to the head of an article.
8104 (defun gnus-article-add-buttons-to-head ()
8105 "Add buttons to the head of the article."
8106 (interactive)
8107 (gnus-with-article-headers
8108 (let (beg end)
8109 (dolist (entry gnus-header-button-alist)
8110 ;; Each alist entry.
8111 (goto-char (point-min))
8112 (while (re-search-forward (car entry) nil t)
8113 ;; Each header matching the entry.
8114 (setq beg (match-beginning 0))
8115 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8116 (match-beginning 0))
8117 (point-max)))
8118 (goto-char beg)
8119 (while (re-search-forward (eval (nth 1 entry)) end t)
8120 ;; Each match within a header.
8121 (let* ((entry (cdr entry))
8122 (start (match-beginning (nth 1 entry)))
8123 (end (match-end (nth 1 entry)))
8124 (form (nth 2 entry)))
8125 (goto-char (match-end 0))
8126 (when (eval form)
8127 (gnus-article-add-button
8128 start end (nth 3 entry)
8129 (buffer-substring (match-beginning (nth 4 entry))
8130 (match-end (nth 4 entry)))))))
8131 (goto-char end))))))
8133 ;;; External functions:
8135 (defun gnus-article-add-button (from to fun &optional data text)
8136 "Create a button between FROM and TO with callback FUN and data DATA."
8137 (when gnus-article-button-face
8138 (gnus-overlay-put (gnus-make-overlay from to nil t)
8139 'face gnus-article-button-face))
8140 (gnus-add-text-properties
8141 from to
8142 (nconc (and gnus-article-mouse-face
8143 (list gnus-mouse-face-prop gnus-article-mouse-face))
8144 (list 'gnus-callback fun)
8145 (and data (list 'gnus-data data))))
8146 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8147 :help-echo (or text "Follow the link")
8148 :keymap gnus-url-button-map
8149 :button-keymap gnus-widget-button-keymap))
8151 (defun gnus-article-copy-string ()
8152 "Copy the string in the button to the kill ring."
8153 (interactive)
8154 (gnus-article-check-buffer)
8155 (let ((data (get-text-property (point) 'gnus-string)))
8156 (when data
8157 (with-temp-buffer
8158 (insert data)
8159 (copy-region-as-kill (point-min) (point-max))
8160 (message "Copied %s" data)))))
8162 ;;; Internal functions:
8164 (defun gnus-article-set-globals ()
8165 (with-current-buffer gnus-summary-buffer
8166 (gnus-set-global-variables)))
8168 (defun gnus-signature-toggle (end)
8169 (gnus-with-article-buffer
8170 (let ((inhibit-point-motion-hooks t))
8171 (if (text-property-any end (point-max) 'article-type 'signature)
8172 (progn
8173 (gnus-delete-wash-type 'signature)
8174 (gnus-remove-text-properties-when
8175 'article-type 'signature end (point-max)
8176 (cons 'article-type (cons 'signature
8177 gnus-hidden-properties))))
8178 (gnus-add-wash-type 'signature)
8179 (gnus-add-text-properties-when
8180 'article-type nil end (point-max)
8181 (cons 'article-type (cons 'signature
8182 gnus-hidden-properties)))))
8183 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8184 (gnus-set-mode-line 'article))))
8186 (defun gnus-button-push (marker-and-entry)
8187 ;; Push button starting at MARKER.
8188 (save-excursion
8189 (let* ((marker (car marker-and-entry))
8190 (entry (cadr marker-and-entry))
8191 (regexp (car entry))
8192 (inhibit-point-motion-hooks t))
8193 (goto-char marker)
8194 ;; This is obviously true, or something bad is happening :)
8195 ;; But we need it to have the match-data
8196 (when (looking-at (or (if (symbolp regexp)
8197 (symbol-value regexp)
8198 regexp)))
8199 (let ((fun (nth 3 entry))
8200 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8201 (get-char-property marker 'gnus-button-url))
8202 (mapcar (lambda (group)
8203 (let ((string (match-string group)))
8204 (set-text-properties
8205 0 (length string) nil string)
8206 string))
8207 (nthcdr 4 entry)))))
8209 (cond
8210 ((fboundp fun)
8211 (apply fun args))
8212 ((and (boundp fun)
8213 (fboundp (symbol-value fun)))
8214 (apply (symbol-value fun) args))
8216 (gnus-message 1 "You must define `%S' to use this button"
8217 (cons fun args)))))))))
8219 (defun gnus-parse-news-url (url)
8220 (let (scheme server port group message-id articles)
8221 (with-temp-buffer
8222 (insert url)
8223 (goto-char (point-min))
8224 (when (looking-at "\\([A-Za-z]+\\):")
8225 (setq scheme (match-string 1))
8226 (goto-char (match-end 0)))
8227 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8228 (setq server (match-string 1))
8229 (setq port (if (stringp (match-string 3))
8230 (string-to-number (match-string 3))
8231 (match-string 3)))
8232 (goto-char (match-end 0)))
8234 (cond
8235 ((looking-at "\\(.*@.*\\)")
8236 (setq message-id (match-string 1)))
8237 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8238 (setq group (match-string 1)
8239 articles (split-string (match-string 2) "-")))
8240 ((looking-at "\\([^/]+\\)/?")
8241 (setq group (match-string 1)))
8243 (error "Unknown news URL syntax"))))
8244 (list scheme server port group message-id articles)))
8246 (defun gnus-button-handle-news (url)
8247 "Fetch a news URL."
8248 (destructuring-bind (scheme server port group message-id articles)
8249 (gnus-parse-news-url url)
8250 (cond
8251 (message-id
8252 (with-current-buffer gnus-summary-buffer
8253 (if server
8254 (let ((gnus-refer-article-method
8255 (nconc (list (list 'nntp server))
8256 gnus-refer-article-method))
8257 (nntp-port-number (or port "nntp")))
8258 (gnus-message 7 "Fetching %s with %s"
8259 message-id gnus-refer-article-method)
8260 (gnus-summary-refer-article message-id))
8261 (gnus-summary-refer-article message-id))))
8262 (group
8263 (gnus-button-fetch-group url)))))
8265 (defun gnus-button-patch (library line)
8266 "Visit an Emacs Lisp library LIBRARY on line LINE."
8267 (interactive)
8268 (let ((file (locate-library (file-name-nondirectory library))))
8269 (unless file
8270 (error "Couldn't find library %s" library))
8271 (find-file file)
8272 (goto-char (point-min))
8273 (forward-line (1- (string-to-number line)))))
8275 (defun gnus-button-handle-man (url)
8276 "Fetch a man page."
8277 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8278 (when (eq gnus-button-man-handler 'woman)
8279 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8280 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8281 (funcall gnus-button-man-handler url))
8283 (defun gnus-button-handle-info-url (url)
8284 "Fetch an info URL."
8285 (setq url (mm-subst-char-in-string ?+ ?\ url))
8286 (cond
8287 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8288 (gnus-info-find-node
8289 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8290 "Gnus")
8291 ")" (gnus-url-unhex-string (match-string 2 url)))))
8292 ((string-match "([^)\"]+)[^\"]+" url)
8293 (setq url
8294 (gnus-replace-in-string
8295 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8296 (gnus-info-find-node url))
8297 (t (error "Can't parse %s" url))))
8299 (defun gnus-button-handle-info-url-gnome (url)
8300 "Fetch GNOME style info URL."
8301 (setq url (mm-subst-char-in-string ?_ ?\ url))
8302 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8303 (gnus-info-find-node
8304 (concat "("
8305 (gnus-url-unhex-string
8306 (match-string 1 url))
8308 (or (gnus-url-unhex-string
8309 (match-string 2 url))
8310 "Top")))
8311 (error "Can't parse %s" url)))
8313 (defun gnus-button-handle-info-url-kde (url)
8314 "Fetch KDE style info URL."
8315 (gnus-info-find-node (gnus-url-unhex-string url)))
8317 ;; (info) will autoload info.el
8318 (declare-function Info-menu "info" (menu-item &optional fork))
8319 (declare-function Info-index-next "info" (num))
8321 (defun gnus-button-handle-info-keystrokes (url)
8322 "Call `info' when pushing the corresponding URL button."
8323 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8324 (let (node indx comma)
8325 (if (string-match
8326 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8327 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8328 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8329 "\\(?:[ \t\n,]*\\)\\)?")
8330 url)
8331 (setq node (match-string 2 url)
8332 indx (match-string 3 url))
8333 (error "Can't parse %s" url))
8334 (info)
8335 (Info-directory)
8336 (Info-menu node)
8337 (when (> (length indx) 0)
8338 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8339 "\\([ \t\n,]*\\)")
8340 indx)
8341 (setq comma (match-string 2 indx))
8342 (setq indx (match-string 1 indx))
8343 (Info-index indx)
8344 (when comma
8345 (dotimes (i (with-temp-buffer
8346 (insert comma)
8347 ;; Note: the XEmacs version of `how-many' takes
8348 ;; no optional argument.
8349 (goto-char (point-min))
8350 (how-many ",")))
8351 (Info-index-next 1)))
8352 nil)))
8354 (autoload 'pgg-snarf-keys-region "pgg")
8355 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8356 (declare-function pgg-display-output-buffer "pgg" (start end status))
8358 (defun gnus-button-openpgp (url)
8359 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8360 (with-temp-buffer
8361 (mm-url-insert-file-contents-external url)
8362 (pgg-snarf-keys-region (point-min) (point-max))
8363 (pgg-display-output-buffer nil nil nil)))
8365 (defun gnus-button-message-id (message-id)
8366 "Fetch MESSAGE-ID."
8367 (with-current-buffer gnus-summary-buffer
8368 (gnus-summary-refer-article message-id)))
8370 (defun gnus-button-fetch-group (address &rest ignore)
8371 "Fetch GROUP specified by ADDRESS."
8372 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8373 address)
8374 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8375 ;; for nntp:// and news://
8376 (setq address (match-string 3 address)))
8377 (if (not (string-match "[:/]" address))
8378 ;; This is just a simple group url.
8379 (gnus-group-read-ephemeral-group address gnus-select-method)
8380 (if (not
8381 (string-match
8382 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8383 address))
8384 (error "Can't parse %s" address)
8385 (gnus-group-read-ephemeral-group
8386 (match-string 4 address)
8387 `(nntp ,(match-string 1 address)
8388 (nntp-address ,(match-string 1 address))
8389 (nntp-port-number ,(if (match-end 3)
8390 (match-string 3 address)
8391 "nntp")))
8392 nil nil nil
8393 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8395 (defun gnus-url-parse-query-string (query &optional downcase)
8396 (let (retval pairs cur key val)
8397 (setq pairs (split-string query "&"))
8398 (while pairs
8399 (setq cur (car pairs)
8400 pairs (cdr pairs))
8401 (if (not (string-match "=" cur))
8402 nil ; Grace
8403 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8404 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8405 (if downcase
8406 (setq key (downcase key)))
8407 (setq cur (assoc key retval))
8408 (if cur
8409 (setcdr cur (cons val (cdr cur)))
8410 (setq retval (cons (list key val) retval)))))
8411 retval))
8413 (defun gnus-url-mailto (url)
8414 ;; Send mail to someone
8415 (setq url (replace-regexp-in-string "\n" " " url))
8416 (when (string-match "mailto:/*\\(.*\\)" url)
8417 (setq url (substring url (match-beginning 1) nil)))
8418 (let (to args subject func)
8419 (setq args (gnus-url-parse-query-string
8420 (if (string-match "^\\?" url)
8421 (substring url 1)
8422 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8423 (concat "to=" (match-string 1 url) "&"
8424 (match-string 2 url))
8425 (concat "to=" url))))
8426 subject (cdr-safe (assoc "subject" args)))
8427 (gnus-msg-mail)
8428 (while args
8429 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8430 (if (fboundp func)
8431 (funcall func)
8432 (message-position-on-field (caar args)))
8433 (insert (gnus-replace-in-string
8434 (mapconcat 'identity (reverse (cdar args)) ", ")
8435 "\r\n" "\n" t))
8436 (setq args (cdr args)))
8437 (if subject
8438 (message-goto-body)
8439 (message-goto-subject))))
8441 (defun gnus-button-embedded-url (address)
8442 "Activate ADDRESS with `browse-url'."
8443 (browse-url (gnus-strip-whitespace address)))
8445 ;;; Next/prev buttons in the article buffer.
8447 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8448 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8450 (defvar gnus-prev-page-map
8451 (let ((map (make-sparse-keymap)))
8452 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8453 (define-key map "\r" 'gnus-button-prev-page)
8454 map))
8456 (defvar gnus-next-page-map
8457 (let ((map (make-sparse-keymap)))
8458 (define-key map gnus-mouse-2 'gnus-button-next-page)
8459 (define-key map "\r" 'gnus-button-next-page)
8460 map))
8462 (defun gnus-insert-prev-page-button ()
8463 (let ((b (point)) e
8464 (inhibit-read-only t))
8465 (gnus-eval-format
8466 gnus-prev-page-line-format nil
8467 `(keymap ,gnus-prev-page-map
8468 gnus-prev t
8469 gnus-callback gnus-article-button-prev-page
8470 article-type annotation))
8471 (setq e (if (bolp)
8472 ;; Exclude a newline.
8473 (1- (point))
8474 (point)))
8475 (when gnus-article-button-face
8476 (gnus-overlay-put (gnus-make-overlay b e nil t)
8477 'face gnus-article-button-face))
8478 (widget-convert-button
8479 'link b e
8480 :action 'gnus-button-prev-page
8481 :button-keymap gnus-prev-page-map)))
8483 (defun gnus-button-next-page (&optional args more-args)
8484 "Go to the next page."
8485 (interactive)
8486 (let ((win (selected-window)))
8487 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8488 (gnus-article-next-page)
8489 (select-window win)))
8491 (defun gnus-button-prev-page (&optional args more-args)
8492 "Go to the prev page."
8493 (interactive)
8494 (let ((win (selected-window)))
8495 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8496 (gnus-article-prev-page)
8497 (select-window win)))
8499 (defun gnus-insert-next-page-button ()
8500 (let ((b (point)) e
8501 (inhibit-read-only t))
8502 (gnus-eval-format gnus-next-page-line-format nil
8503 `(keymap ,gnus-next-page-map
8504 gnus-next t
8505 gnus-callback gnus-article-button-next-page
8506 article-type annotation))
8507 (setq e (if (bolp)
8508 ;; Exclude a newline.
8509 (1- (point))
8510 (point)))
8511 (when gnus-article-button-face
8512 (gnus-overlay-put (gnus-make-overlay b e nil t)
8513 'face gnus-article-button-face))
8514 (widget-convert-button
8515 'link b e
8516 :action 'gnus-button-next-page
8517 :button-keymap gnus-next-page-map)))
8519 (defun gnus-article-button-next-page (arg)
8520 "Go to the next page."
8521 (interactive "P")
8522 (let ((win (selected-window)))
8523 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8524 (gnus-article-next-page)
8525 (select-window win)))
8527 (defun gnus-article-button-prev-page (arg)
8528 "Go to the prev page."
8529 (interactive "P")
8530 (let ((win (selected-window)))
8531 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8532 (gnus-article-prev-page)
8533 (select-window win)))
8535 (defvar gnus-decode-header-methods
8536 '(mail-decode-encoded-word-region)
8537 "List of methods used to decode headers.
8539 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8540 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8541 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8542 whose names match REGEXP.
8544 For example:
8545 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8546 mail-decode-encoded-word-region
8547 (\"chinese\" . rfc1843-decode-region))
8550 (defvar gnus-decode-header-methods-cache nil)
8552 (defun gnus-multi-decode-header (start end)
8553 "Apply the functions from `gnus-encoded-word-methods' that match."
8554 (unless (and gnus-decode-header-methods-cache
8555 (eq gnus-newsgroup-name
8556 (car gnus-decode-header-methods-cache)))
8557 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8558 (dolist (x gnus-decode-header-methods)
8559 (if (symbolp x)
8560 (nconc gnus-decode-header-methods-cache (list x))
8561 (if (and gnus-newsgroup-name
8562 (string-match (car x) gnus-newsgroup-name))
8563 (nconc gnus-decode-header-methods-cache
8564 (list (cdr x)))))))
8565 (let ((xlist gnus-decode-header-methods-cache))
8566 (pop xlist)
8567 (save-restriction
8568 (narrow-to-region start end)
8569 (while xlist
8570 (funcall (pop xlist) (point-min) (point-max))))))
8573 ;;; Treatment top-level handling.
8576 (defvar gnus-inhibit-article-treatments nil)
8578 (defun gnus-treat-article (gnus-treat-condition
8579 &optional part-number total-parts gnus-treat-type)
8580 (let ((gnus-treat-length (- (point-max) (point-min)))
8581 (alist gnus-treatment-function-alist)
8582 (article-goto-body-goes-to-point-min-p t)
8583 (treated-type
8584 (or (not gnus-treat-type)
8585 (catch 'found
8586 (let ((list gnus-article-treat-types))
8587 (while list
8588 (when (string-match (pop list) gnus-treat-type)
8589 (throw 'found t)))))))
8590 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8591 val elem)
8592 (gnus-run-hooks 'gnus-part-display-hook)
8593 (dolist (elem alist)
8594 (setq val
8595 (save-excursion
8596 (when (gnus-buffer-live-p gnus-summary-buffer)
8597 (set-buffer gnus-summary-buffer))
8598 (symbol-value (car elem))))
8599 (when (and (or (consp val)
8600 treated-type)
8601 (or (not gnus-inhibit-article-treatments)
8602 (eq gnus-treat-condition 'head))
8603 (gnus-treat-predicate val)
8604 (or (not (get (car elem) 'highlight))
8605 highlightp))
8606 (save-restriction
8607 (funcall (cadr elem)))))))
8609 ;; Dynamic variables.
8610 (defvar part-number)
8611 (defvar total-parts)
8612 (defvar gnus-treat-type)
8613 (defvar gnus-treat-condition)
8614 (defvar gnus-treat-length)
8616 (defun gnus-treat-predicate (val)
8617 (cond
8618 ((null val)
8619 nil)
8620 (gnus-treat-condition
8621 (eq gnus-treat-condition val))
8622 ((and (listp val)
8623 (stringp (car val)))
8624 (apply 'gnus-or (mapcar `(lambda (s)
8625 (string-match s ,(or gnus-newsgroup-name "")))
8626 val)))
8627 ((listp val)
8628 (let ((pred (pop val)))
8629 (cond
8630 ((eq pred 'or)
8631 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8632 ((eq pred 'and)
8633 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8634 ((eq pred 'not)
8635 (not (gnus-treat-predicate (car val))))
8636 ((eq pred 'typep)
8637 (equal (car val) gnus-treat-type))
8638 ((functionp pred)
8639 (funcall pred))
8641 (error "%S is not a valid predicate" pred)))))
8642 ((eq val t)
8644 ((eq val 'head)
8645 nil)
8646 ((eq val 'first)
8647 (eq part-number 1))
8648 ((eq val 'last)
8649 (eq part-number total-parts))
8650 ((numberp val)
8651 (< gnus-treat-length val))
8653 (error "%S is not a valid value" val))))
8655 (defun gnus-article-encrypt-body (protocol &optional n)
8656 "Encrypt the article body."
8657 (interactive
8658 (list
8659 (or gnus-article-encrypt-protocol
8660 (gnus-completing-read "Encrypt protocol"
8661 (mapcar 'car gnus-article-encrypt-protocol-alist)
8663 current-prefix-arg))
8664 ;; User might hit `K E' instead of `K e', so prompt once.
8665 (when (and gnus-article-encrypt-protocol
8666 gnus-novice-user)
8667 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8668 (error "Encrypt aborted")))
8669 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8670 (unless func
8671 (error "Can't find the encrypt protocol %s" protocol))
8672 (if (member gnus-newsgroup-name '("nndraft:delayed"
8673 "nndraft:drafts"
8674 "nndraft:queue"))
8675 (error "Can't encrypt the article in group %s"
8676 gnus-newsgroup-name))
8677 (gnus-summary-iterate n
8678 (with-current-buffer gnus-summary-buffer
8679 (let ((mail-parse-charset gnus-newsgroup-charset)
8680 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8681 (summary-buffer gnus-summary-buffer)
8682 references point)
8683 (gnus-set-global-variables)
8684 (when (gnus-group-read-only-p)
8685 (error "The current newsgroup does not support article encrypt"))
8686 (gnus-summary-show-article t)
8687 (setq references
8688 (or (mail-header-references gnus-current-headers) ""))
8689 (set-buffer gnus-article-buffer)
8690 (let* ((inhibit-read-only t)
8691 (headers
8692 (mapcar (lambda (field)
8693 (and (save-restriction
8694 (message-narrow-to-head)
8695 (goto-char (point-min))
8696 (search-forward field nil t))
8697 (prog2
8698 (message-narrow-to-field)
8699 (buffer-string)
8700 (delete-region (point-min) (point-max))
8701 (widen))))
8702 '("Content-Type:" "Content-Transfer-Encoding:"
8703 "Content-Disposition:"))))
8704 (message-narrow-to-head)
8705 (message-remove-header "MIME-Version")
8706 (goto-char (point-max))
8707 (setq point (point))
8708 (insert (apply 'concat headers))
8709 (widen)
8710 (narrow-to-region point (point-max))
8711 (let ((message-options message-options))
8712 (message-options-set 'message-sender user-mail-address)
8713 (message-options-set 'message-recipients user-mail-address)
8714 (message-options-set 'message-sign-encrypt 'not)
8715 (funcall func))
8716 (goto-char (point-min))
8717 (insert "MIME-Version: 1.0\n")
8718 (widen)
8719 (gnus-summary-edit-article-done
8720 references nil summary-buffer t))
8721 (when gnus-keep-backlog
8722 (gnus-backlog-remove-article
8723 (car gnus-article-current) (cdr gnus-article-current)))
8724 (gnus-flush-original-article-buffer)
8725 (when gnus-use-cache
8726 (gnus-cache-update-article
8727 (car gnus-article-current) (cdr gnus-article-current))))))))
8729 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8730 "The following specs can be used:
8731 %t The security MIME type
8732 %i Additional info
8733 %d Details
8734 %D Details if button is pressed")
8736 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8737 "The following specs can be used:
8738 %t The security MIME type
8739 %i Additional info
8740 %d Details
8741 %D Details if button is pressed")
8743 (defvar gnus-mime-security-button-line-format-alist
8744 '((?t gnus-tmp-type ?s)
8745 (?i gnus-tmp-info ?s)
8746 (?d gnus-tmp-details ?s)
8747 (?D gnus-tmp-pressed-details ?s)))
8749 (defvar gnus-mime-security-button-commands
8750 '((gnus-article-press-button "\r" "Show Detail")
8751 (undefined "v")
8752 (undefined "t")
8753 (undefined "C")
8754 (gnus-mime-security-save-part "o" "Save...")
8755 (undefined "\C-o")
8756 (undefined "r")
8757 (undefined "d")
8758 (undefined "c")
8759 (undefined "i")
8760 (undefined "E")
8761 (undefined "e")
8762 (undefined "p")
8763 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8764 (undefined ".")))
8766 (defvar gnus-mime-security-button-map
8767 (let ((map (make-sparse-keymap)))
8768 (define-key map gnus-mouse-2 'gnus-article-push-button)
8769 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8770 (dolist (c gnus-mime-security-button-commands)
8771 (define-key map (cadr c) (car c)))
8772 map))
8774 (easy-menu-define
8775 gnus-mime-security-button-menu gnus-mime-security-button-map
8776 "Security button menu."
8777 `("Security Part"
8778 ,@(delq nil
8779 (mapcar (lambda (c)
8780 (unless (eq (car c) 'undefined)
8781 (vector (caddr c) (car c) :active t)))
8782 gnus-mime-security-button-commands))))
8784 (defun gnus-mime-security-button-menu (event prefix)
8785 "Construct a context-sensitive menu of security commands."
8786 (interactive "e\nP")
8787 (save-window-excursion
8788 (let ((pos (event-start event)))
8789 (select-window (posn-window pos))
8790 (goto-char (posn-point pos))
8791 (gnus-article-check-buffer)
8792 (popup-menu gnus-mime-security-button-menu nil prefix))))
8794 (defvar gnus-mime-security-details-buffer nil)
8796 (defvar gnus-mime-security-button-pressed nil)
8798 (defvar gnus-mime-security-show-details-inline t
8799 "If non-nil, show details in the article buffer.")
8801 (defun gnus-mime-security-verify-or-decrypt (handle)
8802 (mm-remove-parts (cdr handle))
8803 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8804 point (inhibit-read-only t))
8805 (if region
8806 (goto-char (car region)))
8807 (setq point (point))
8808 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8809 (let* ((mm-verify-option 'known)
8810 (mm-decrypt-option 'known)
8811 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8812 (unless (eq nparts (cdr handle))
8813 (mm-destroy-parts (cdr handle))
8814 (setcdr handle nparts))))
8815 (gnus-mime-display-security handle)
8816 (when region
8817 (delete-region (point) (cdr region))
8818 (set-marker (car region) nil)
8819 (set-marker (cdr region) nil))
8820 (goto-char point)))
8822 (defun gnus-mime-security-show-details (handle)
8823 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8824 (if (not details)
8825 (gnus-message 5 "No details.")
8826 (if gnus-mime-security-show-details-inline
8827 (let ((gnus-mime-security-button-pressed
8828 (not (get-text-property (point) 'gnus-mime-details)))
8829 (gnus-mime-security-button-line-format
8830 (get-text-property (point) 'gnus-line-format))
8831 (inhibit-read-only t))
8832 (forward-char -1)
8833 (while (eq (get-text-property (point) 'gnus-line-format)
8834 gnus-mime-security-button-line-format)
8835 (forward-char -1))
8836 (forward-char)
8837 (save-restriction
8838 (narrow-to-region (point) (point))
8839 (gnus-insert-mime-security-button handle))
8840 (delete-region (point)
8841 (or (text-property-not-all
8842 (point) (point-max)
8843 'gnus-line-format
8844 gnus-mime-security-button-line-format)
8845 (point-max))))
8846 ;; Not inlined.
8847 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8848 (with-current-buffer gnus-mime-security-details-buffer
8849 (erase-buffer)
8851 (setq gnus-mime-security-details-buffer
8852 (gnus-get-buffer-create "*MIME Security Details*")))
8853 (with-current-buffer gnus-mime-security-details-buffer
8854 (insert details)
8855 (goto-char (point-min)))
8856 (pop-to-buffer gnus-mime-security-details-buffer)))))
8858 (defun gnus-mime-security-press-button (handle)
8859 (save-excursion
8860 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8861 (gnus-mime-security-show-details handle)
8862 (gnus-mime-security-verify-or-decrypt handle))))
8864 (defun gnus-insert-mime-security-button (handle &optional displayed)
8865 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8866 (gnus-tmp-type
8867 (concat
8868 (or (nth 2 (assoc protocol mm-verify-function-alist))
8869 (nth 2 (assoc protocol mm-decrypt-function-alist))
8870 "Unknown")
8871 (if (equal (car handle) "multipart/signed")
8872 " Signed" " Encrypted")
8873 " Part"))
8874 (gnus-tmp-info
8875 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8876 "Undecided"))
8877 (gnus-tmp-details
8878 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8879 gnus-tmp-pressed-details
8880 b e)
8881 (setq gnus-tmp-details
8882 (if gnus-tmp-details
8883 (concat "\n" gnus-tmp-details)
8884 ""))
8885 (setq gnus-tmp-pressed-details
8886 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8887 (unless (bolp)
8888 (insert "\n"))
8889 (setq b (point))
8890 (gnus-eval-format
8891 gnus-mime-security-button-line-format
8892 gnus-mime-security-button-line-format-alist
8893 `(keymap ,gnus-mime-security-button-map
8894 gnus-callback gnus-mime-security-press-button
8895 gnus-line-format ,gnus-mime-security-button-line-format
8896 gnus-mime-details ,gnus-mime-security-button-pressed
8897 article-type annotation
8898 gnus-data ,handle))
8899 (setq e (if (bolp)
8900 ;; Exclude a newline.
8901 (1- (point))
8902 (point)))
8903 (when gnus-article-button-face
8904 (gnus-overlay-put (gnus-make-overlay b e nil t)
8905 'face gnus-article-button-face))
8906 (widget-convert-button
8907 'link b e
8908 :mime-handle handle
8909 :action 'gnus-widget-press-button
8910 :button-keymap gnus-mime-security-button-map
8911 :help-echo
8912 (lambda (widget)
8913 ;; Needed to properly clear the message due to a bug in
8914 ;; wid-edit (XEmacs only).
8915 (when (boundp 'help-echo-owns-message)
8916 (setq help-echo-owns-message t))
8917 (format
8918 "%S: show detail; %S: more options"
8919 (aref gnus-mouse-2 0)
8920 (aref gnus-down-mouse-3 0))))))
8922 (defun gnus-mime-display-security (handle)
8923 (save-restriction
8924 (narrow-to-region (point) (point))
8925 (unless (gnus-unbuttonized-mime-type-p (car handle))
8926 (gnus-insert-mime-security-button handle))
8927 (gnus-mime-display-part (cadr handle))
8928 (unless (bolp)
8929 (insert "\n"))
8930 (unless (gnus-unbuttonized-mime-type-p (car handle))
8931 (let ((gnus-mime-security-button-line-format
8932 gnus-mime-security-button-end-line-format))
8933 (gnus-insert-mime-security-button handle)))
8934 (mm-set-handle-multipart-parameter
8935 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8936 (goto-char (point-max))))
8938 (defun gnus-mime-security-run-function (function)
8939 "Run FUNCTION with the security part under point."
8940 (gnus-article-check-buffer)
8941 (let ((data (get-text-property (point) 'gnus-data))
8942 buffer handle)
8943 (when (and (stringp (car-safe data))
8944 (setq buffer (mm-handle-multipart-original-buffer data))
8945 (setq handle (cadr data)))
8946 (if (bufferp (mm-handle-buffer handle))
8947 (progn
8948 (setq handle (cons buffer (copy-sequence (cdr handle))))
8949 (mm-handle-set-undisplayer handle nil))
8950 (setq handle (mm-make-handle
8951 buffer
8952 (mm-handle-multipart-ctl-parameter handle 'protocol)
8953 nil nil nil nil nil nil)))
8954 (funcall function handle))))
8956 (defun gnus-mime-security-save-part ()
8957 "Save the security part under point."
8958 (interactive)
8959 (gnus-mime-security-run-function 'mm-save-part))
8961 (defun gnus-mime-security-pipe-part ()
8962 "Pipe the security part under point to a process."
8963 (interactive)
8964 (gnus-mime-security-run-function 'mm-pipe-part))
8966 (gnus-ems-redefine)
8968 (provide 'gnus-art)
8970 (run-hooks 'gnus-art-load-hook)
8972 ;;; gnus-art.el ends here