Improve the custom type of some user options.
[emacs.git] / lisp / gnus / gnus-art.el
blob366d14aca1d026f27cd313a852f89eeb7f3c8003
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2016 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")
53 (autoload 'url-expand-file-name "url-expand")
55 (defgroup gnus-article nil
56 "Article display."
57 :link '(custom-manual "(gnus)Article Buffer")
58 :group 'gnus)
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
63 :group 'gnus-article)
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
68 :group 'gnus-article)
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
73 :group 'gnus-article
74 :group 'gnus-visual)
76 (defgroup gnus-article-signature nil
77 "Article signatures."
78 :link '(custom-manual "(gnus)Article Signature")
79 :group 'gnus-article)
81 (defgroup gnus-article-headers nil
82 "Article headers."
83 :link '(custom-manual "(gnus)Hiding Headers")
84 :group 'gnus-article)
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
89 :group 'gnus-article)
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
94 :group 'gnus-article)
96 (defgroup gnus-article-saving nil
97 "Saving articles."
98 :link '(custom-manual "(gnus)Saving Articles")
99 :group 'gnus-article)
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
116 (defcustom gnus-ignored-headers
117 (mapcar
118 (lambda (header)
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
165 (repeat regexp))
166 :group 'gnus-article-hiding)
168 (defcustom gnus-visible-headers
169 "^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:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
173 :type '(choice
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
177 (or (stringp value)
178 (widget-editable-list-match widget value)))
179 regexp)
180 (const :tag "Use gnus-ignored-headers" nil)
181 regexp)
182 :group 'gnus-article-hiding)
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
190 this list."
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
198 `empty' Headers with no content.
199 `newsgroups' Newsgroup identical to Gnus group.
200 `to-address' To identical to To-address.
201 `to-list' To identical to To-list.
202 `cc-list' CC identical to To-list.
203 `followup-to' Followup-to identical to Newsgroups.
204 `reply-to' Reply-to identical to From.
205 `date' Date less than four days old.
206 `long-to' To and/or Cc longer than 1024 characters.
207 `many-to' Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
226 :version "22.1"
227 :type 'boolean
228 :group 'gnus-article-hiding)
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
236 (regexp)
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
249 This can also be a list of the above values."
250 :type '(choice (const nil)
251 (integer :value 200)
252 (number :value 4.0)
253 function
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
257 (defcustom gnus-hidden-properties
258 ;; We use to have `intangible' here as well, but Emacs's command loop moves
259 ;; point out of invisible text anyway, so `intangible' is clearly not
260 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
261 '(invisible t)
262 "Property list to use for hiding text."
263 :type 'plist
264 :group 'gnus-article-hiding)
266 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
267 ;; frames in a session.
268 (defcustom gnus-article-x-face-command
269 (if (featurep 'xemacs)
270 (if (or (gnus-image-type-available-p 'xface)
271 (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 | ee -")
276 (if (gnus-image-type-available-p 'pbm)
277 'gnus-display-x-face-in-from
278 "{ echo \
279 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
280 ; uncompface; } | icontopbm | display -"))
281 "*String or function to be executed to display an X-Face header.
282 If it is a string, the command will be executed in a sub-shell
283 asynchronously. The compressed face will be piped to this command."
284 :type `(choice string
285 (function-item gnus-display-x-face-in-from)
286 function)
287 :version "21.1"
288 :group 'gnus-picon
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-x-face-too-ugly nil
292 "Regexp matching posters whose face shouldn't be shown automatically."
293 :type '(choice regexp (const nil))
294 :group 'gnus-article-washing)
296 (defcustom gnus-article-banner-alist nil
297 "Banner alist for stripping.
298 For example,
299 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
300 :version "21.1"
301 :type '(repeat (cons symbol regexp))
302 :group 'gnus-article-washing)
304 (gnus-define-group-parameter
305 banner
306 :variable-document
307 "Alist of regexps (to match group names) and banner."
308 :variable-group gnus-article-washing
309 :parameter-type
310 '(choice :tag "Banner"
311 :value nil
312 (const :tag "Remove signature" signature)
313 (symbol :tag "Item in `gnus-article-banner-alist'" none)
314 regexp
315 (const :tag "None" nil))
316 :parameter-document
317 "If non-nil, specify how to remove `banners' from articles.
319 Symbol `signature' means to remove signatures delimited by
320 `gnus-signature-separator'. Any other symbol is used to look up a
321 regular expression to match the banner in `gnus-article-banner-alist'.
322 A string is used as a regular expression to match the banner
323 directly.")
325 (defcustom gnus-article-address-banner-alist nil
326 "Alist of mail addresses and banners.
327 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
328 to match a mail address in the From: header, BANNER is one of a symbol
329 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
330 If ADDRESS matches author's mail address, it will remove things like
331 advertisements. For example:
333 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 :type '(repeat
336 (cons
337 (regexp :tag "Address")
338 (choice :tag "Banner" :value nil
339 (const :tag "Remove signature" signature)
340 (symbol :tag "Item in `gnus-article-banner-alist'" none)
341 regexp
342 (const :tag "None" nil))))
343 :version "22.1"
344 :group 'gnus-article-washing)
346 (defmacro gnus-emphasis-custom-with-format (&rest body)
347 `(let ((format "\
348 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
349 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 ,@body))
352 (defun gnus-emphasis-custom-value-to-external (value)
353 (gnus-emphasis-custom-with-format
354 (if (consp (car value))
355 (list (format format (car (car value)) (cdr (car value)))
357 (if (nth 1 value) 2 3)
358 (nth 2 value))
359 value)))
361 (defun gnus-emphasis-custom-value-to-internal (value)
362 (gnus-emphasis-custom-with-format
363 (let ((regexp (concat "\\`"
364 (format (regexp-quote format)
365 "\\([^()]+\\)" "\\([^()]+\\)")
366 "\\'"))
367 pattern)
368 (if (string-match regexp (setq pattern (car value)))
369 (list (cons (match-string 1 pattern) (match-string 2 pattern))
370 (= (nth 2 value) 2)
371 (nth 3 value))
372 value))))
374 (defcustom gnus-emphasis-alist
375 (let ((types
376 '(("\\*" "\\*" bold nil 2)
377 ("_" "_" underline)
378 ("/" "/" italic)
379 ("_/" "/_" underline-italic)
380 ("_\\*" "\\*_" underline-bold)
381 ("\\*/" "/\\*" bold-italic)
382 ("_\\*/" "/\\*_" underline-bold-italic))))
383 (nconc
384 (gnus-emphasis-custom-with-format
385 (mapcar (lambda (spec)
386 (list (format format (car spec) (cadr spec))
387 (or (nth 3 spec) 2)
388 (or (nth 4 spec) 3)
389 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
390 types))
391 '(;; I've never seen anyone use this strikethru convention whereas I've
392 ;; several times seen it triggered by normal text. --Stef
393 ;; Miles suggests that this form is sometimes used but for italics,
394 ;; so maybe we should map it to `italic'.
395 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
396 ;; 2 3 gnus-emphasis-strikethru)
397 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
398 2 3 gnus-emphasis-underline))))
399 "*Alist that says how to fontify certain phrases.
400 Each item looks like this:
402 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
404 The first element is a regular expression to be matched. The second
405 is a number that says what regular expression grouping used to find
406 the entire emphasized word. The third is a number that says what
407 regexp grouping should be displayed and highlighted. The fourth
408 is the face used for highlighting."
409 :type
410 '(repeat
411 (menu-choice
412 :format "%[Customizing Style%]\n%v"
413 :indent 2
414 (group :tag "Default"
415 :value ("" 0 0 default)
416 :value-create
417 (lambda (widget)
418 (let ((value (widget-get
419 (cadr (widget-get (widget-get widget :parent)
420 :args))
421 :value)))
422 (if (not (eq (nth 2 value) 'default))
423 (widget-put
424 widget
425 :value
426 (gnus-emphasis-custom-value-to-external value))))
427 (widget-group-value-create widget))
428 regexp
429 (integer :format "Match group: %v")
430 (integer :format "Emphasize group: %v")
431 face)
432 (group :tag "Simple"
433 :value (("_" . "_") nil default)
434 (cons :format "%v"
435 (regexp :format "Start regexp: %v")
436 (regexp :format "End regexp: %v"))
437 (boolean :format "Show start and end patterns: %[%v%]\n"
438 :on " On " :off " Off ")
439 face)))
440 :get (lambda (symbol)
441 (mapcar 'gnus-emphasis-custom-value-to-internal
442 (default-value symbol)))
443 :set (lambda (symbol value)
444 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
445 value)))
446 :group 'gnus-article-emphasis)
448 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
449 "A regexp to describe whitespace which should not be emphasized.
450 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
451 The former avoids underlining of leading and trailing whitespace,
452 and the latter avoids underlining any whitespace at all."
453 :version "21.1"
454 :group 'gnus-article-emphasis
455 :type 'regexp)
457 (defface gnus-emphasis-bold '((t (:bold t)))
458 "Face used for displaying strong emphasized text (*word*)."
459 :group 'gnus-article-emphasis)
461 (defface gnus-emphasis-italic '((t (:italic t)))
462 "Face used for displaying italic emphasized text (/word/)."
463 :group 'gnus-article-emphasis)
465 (defface gnus-emphasis-underline '((t (:underline t)))
466 "Face used for displaying underlined emphasized text (_word_)."
467 :group 'gnus-article-emphasis)
469 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
470 "Face used for displaying underlined bold emphasized text (_*word*_)."
471 :group 'gnus-article-emphasis)
473 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
474 "Face used for displaying underlined italic emphasized text (_/word/_)."
475 :group 'gnus-article-emphasis)
477 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
478 "Face used for displaying bold italic emphasized text (/*word*/)."
479 :group 'gnus-article-emphasis)
481 (defface gnus-emphasis-underline-bold-italic
482 '((t (:bold t :italic t :underline t)))
483 "Face used for displaying underlined bold italic emphasized text.
484 Example: (_/*word*/_)."
485 :group 'gnus-article-emphasis)
487 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
488 '((t (:strikethru t)))
489 '((t (:strike-through t))))
490 "Face used for displaying strike-through text (-word-)."
491 :group 'gnus-article-emphasis)
493 (defface gnus-emphasis-highlight-words
494 '((t (:background "black" :foreground "yellow")))
495 "Face used for displaying highlighted words."
496 :group 'gnus-article-emphasis)
498 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
499 "Format for display of Date headers in article bodies.
500 See `format-time-string' for the possible values.
502 The variable can also be function, which should return a complete Date
503 header. The function is called with one argument, the time, which can
504 be fed to `format-time-string'."
505 :type '(choice string function)
506 :link '(custom-manual "(gnus)Article Date")
507 :group 'gnus-article-washing)
509 (defcustom gnus-save-all-headers t
510 "*If non-nil, don't remove any headers before saving.
511 This will be overridden by the `:headers' property that the symbol of
512 the saver function, which is specified by `gnus-default-article-saver',
513 might have."
514 :group 'gnus-article-saving
515 :type 'boolean)
517 (defcustom gnus-prompt-before-saving 'always
518 "*This variable says how much prompting is to be done when saving articles.
519 If it is nil, no prompting will be done, and the articles will be
520 saved to the default files. If this variable is `always', each and
521 every article that is saved will be preceded by a prompt, even when
522 saving large batches of articles. If this variable is neither nil not
523 `always', there the user will be prompted once for a file name for
524 each invocation of the saving commands."
525 :group 'gnus-article-saving
526 :type '(choice (item always)
527 (item :tag "never" nil)
528 (sexp :tag "once" :format "%t\n" :value t)))
530 (defcustom gnus-saved-headers gnus-visible-headers
531 "Headers to keep if `gnus-save-all-headers' is nil.
532 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
533 If that variable is nil, however, all headers that match this regexp
534 will be kept while the rest will be deleted before saving. This and
535 `gnus-save-all-headers' will be overridden by the `:headers' property
536 that the symbol of the saver function, which is specified by
537 `gnus-default-article-saver', might have."
538 :group 'gnus-article-saving
539 :type 'regexp)
541 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
542 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
543 "A function to save articles in your favorite format.
544 The function will be called by way of the `gnus-summary-save-article'
545 command, and friends such as `gnus-summary-save-article-rmail'.
547 Gnus provides the following functions:
549 * gnus-summary-save-in-rmail (Rmail format)
550 * gnus-summary-save-in-mail (Unix mail format)
551 * gnus-summary-save-in-folder (MH folder)
552 * gnus-summary-save-in-file (article format)
553 * gnus-summary-save-body-in-file (article body)
554 * gnus-summary-save-in-vm (use VM's folder format)
555 * gnus-summary-write-to-file (article format -- overwrite)
556 * gnus-summary-write-body-to-file (article body -- overwrite)
557 * gnus-summary-save-in-pipe (article format)
559 The symbol of each function may have the following properties:
561 * :decode
562 The value non-nil means save decoded articles. This is meaningful
563 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
564 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
565 `gnus-summary-save-in-pipe'.
567 * :function
568 The value specifies an alternative function which appends, not
569 overwrites, articles to a file. This implies that when saving many
570 articles at a time, `gnus-prompt-before-saving' is bound to t and all
571 articles are saved in a single file. This is meaningful only with
572 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
574 * :headers
575 The value specifies the symbol of a variable of which the value
576 specifies headers to be saved. If it is omitted,
577 `gnus-save-all-headers' and `gnus-saved-headers' control what
578 headers should be saved."
579 :group 'gnus-article-saving
580 :type '(radio (function-item gnus-summary-save-in-rmail)
581 (function-item gnus-summary-save-in-mail)
582 (function-item gnus-summary-save-in-folder)
583 (function-item gnus-summary-save-in-file)
584 (function-item gnus-summary-save-body-in-file)
585 (function-item gnus-summary-save-in-vm)
586 (function-item gnus-summary-write-to-file)
587 (function-item gnus-summary-write-body-to-file)
588 (function-item gnus-summary-save-in-pipe)
589 (function)))
591 (defcustom gnus-article-save-coding-system
592 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
593 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
594 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
595 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
596 "Coding system used to save decoded articles to a file.
598 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
599 which can safely encode any characters in text. This is used by the
600 commands including:
602 * gnus-summary-save-article-file
603 * gnus-summary-save-article-body-file
604 * gnus-summary-write-article-file
605 * gnus-summary-write-article-body-file
607 and the functions to which you may set `gnus-default-article-saver':
609 * gnus-summary-save-in-file
610 * gnus-summary-save-body-in-file
611 * gnus-summary-write-to-file
612 * gnus-summary-write-body-to-file
614 Those commands and functions save just text displayed in the article
615 buffer to a file if the value of this variable is non-nil. Note that
616 buttonized MIME parts will be lost in a saved file in that case.
617 Otherwise, raw articles will be saved."
618 :group 'gnus-article-saving
619 :type `(choice
620 :format "%{%t%}:\n %[Value Menu%] %v"
621 (const :tag "Save raw articles" nil)
622 ,@(delq nil
623 (mapcar
624 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
625 '((const :tag "UTF-8" utf-8)
626 (const :tag "iso-2022-7bit" iso-2022-7bit)
627 (const :tag "Emacs internal" emacs-mule)
628 (const :tag "escape-quoted" escape-quoted))))
629 (symbol :tag "Coding system")))
631 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Rmail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
635 :type 'function)
637 (defcustom gnus-mail-save-name 'gnus-plain-save-name
638 "A function generating a file name to save articles in Unix mail format.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
640 :group 'gnus-article-saving
641 :type 'function)
643 (defcustom gnus-folder-save-name 'gnus-folder-save-name
644 "A function generating a file name to save articles in MH folder.
645 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
646 :group 'gnus-article-saving
647 :type 'function)
649 (defcustom gnus-file-save-name 'gnus-numeric-save-name
650 "A function generating a file name to save articles in article format.
651 The function is called with NEWSGROUP, HEADERS, and optional
652 LAST-FILE."
653 :group 'gnus-article-saving
654 :type 'function)
656 (defcustom gnus-split-methods
657 '((gnus-article-archive-name)
658 (gnus-article-nndoc-name))
659 "*Variable used to suggest where articles are to be saved.
660 For instance, if you would like to save articles related to Gnus in
661 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
662 you could set this variable to something like:
664 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
665 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
667 This variable is an alist where the key is the match and the
668 value is a list of possible files to save in if the match is
669 non-nil.
671 If the match is a string, it is used as a regexp match on the
672 article. If the match is a symbol, that symbol will be funcalled
673 from the buffer of the article to be saved with the newsgroup as the
674 parameter. If it is a list, it will be evalled in the same buffer.
676 If this form or function returns a string, this string will be used as a
677 possible file name; and if it returns a non-nil list, that list will be
678 used as possible file names."
679 :group 'gnus-article-saving
680 :type '(repeat (choice (list :value (fun) function)
681 (cons :value ("" "") regexp (repeat string))
682 (sexp :value nil))))
684 (defcustom gnus-page-delimiter "^\^L"
685 "*Regexp describing what to use as article page delimiters.
686 The default value is \"^\^L\", which is a form linefeed at the
687 beginning of a line."
688 :type 'regexp
689 :group 'gnus-article-various)
691 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
692 "*The format specification for the article mode line.
693 See `gnus-summary-mode-line-format' for a closer description.
695 The following additional specs are available:
697 %w The article washing status.
698 %m The number of MIME parts in the article."
699 :version "24.1"
700 :type 'string
701 :group 'gnus-article-various)
703 (defcustom gnus-article-mode-hook nil
704 "*A hook for Gnus article mode."
705 :type 'hook
706 :group 'gnus-article-various)
708 (when (featurep 'xemacs)
709 ;; Extracted from gnus-xmas-define in order to preserve user settings
710 (when (fboundp 'turn-off-scroll-in-place)
711 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
712 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
713 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
715 (defcustom gnus-article-menu-hook nil
716 "*Hook run after the creation of the article mode menu."
717 :type 'hook
718 :group 'gnus-article-various)
720 (defcustom gnus-article-prepare-hook nil
721 "*A hook called after an article has been prepared in the article buffer."
722 :type 'hook
723 :group 'gnus-article-various)
725 (defcustom gnus-copy-article-ignored-headers nil
726 "List of headers to be removed when copying an article.
727 Each element is a regular expression."
728 :version "23.1" ;; No Gnus
729 :type '(repeat regexp)
730 :group 'gnus-article-various)
732 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
733 "Gnus 5.10 (Emacs 22.1)")
735 (defface gnus-button
736 '((t (:weight bold)))
737 "Face used for highlighting a button in the article buffer."
738 :group 'gnus-article-buttons)
740 (defcustom gnus-article-button-face 'gnus-button
741 "Face used for highlighting buttons in the article buffer.
743 An article button is a piece of text that you can activate by pressing
744 `RET' or `mouse-2' above it."
745 :type 'face
746 :group 'gnus-article-buttons)
748 (defcustom gnus-article-mouse-face 'highlight
749 "Face used for mouse highlighting in the article buffer.
751 Article buttons will be displayed in this face when the cursor is
752 above them."
753 :type 'face
754 :group 'gnus-article-buttons)
756 (defcustom gnus-signature-face 'gnus-signature
757 "Face used for highlighting a signature in the article buffer.
758 Obsolete; use the face `gnus-signature' for customizations instead."
759 :type 'face
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
763 (defface gnus-signature
764 '((t
765 (:italic t)))
766 "Face used for highlighting a signature in the article buffer."
767 :group 'gnus-article-highlight
768 :group 'gnus-article-signature)
769 ;; backward-compatibility alias
770 (put 'gnus-signature-face 'face-alias 'gnus-signature)
771 (put 'gnus-signature-face 'obsolete-face "22.1")
773 (defface gnus-header-from
774 '((((class color)
775 (background dark))
776 (:foreground "PaleGreen1"))
777 (((class color)
778 (background light))
779 (:foreground "red3"))
781 (:italic t)))
782 "Face used for displaying from headers."
783 :group 'gnus-article-headers
784 :group 'gnus-article-highlight)
785 ;; backward-compatibility alias
786 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
787 (put 'gnus-header-from-face 'obsolete-face "22.1")
789 (defface gnus-header-subject
790 '((((class color)
791 (background dark))
792 (:foreground "SeaGreen1"))
793 (((class color)
794 (background light))
795 (:foreground "red4"))
797 (:bold t :italic t)))
798 "Face used for displaying subject headers."
799 :group 'gnus-article-headers
800 :group 'gnus-article-highlight)
801 ;; backward-compatibility alias
802 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
803 (put 'gnus-header-subject-face 'obsolete-face "22.1")
805 (defface gnus-header-newsgroups
806 '((((class color)
807 (background dark))
808 (:foreground "yellow" :italic t))
809 (((class color)
810 (background light))
811 (:foreground "MidnightBlue" :italic t))
813 (:italic t)))
814 "Face used for displaying newsgroups headers.
815 In the default setup this face is only used for crossposted
816 articles."
817 :group 'gnus-article-headers
818 :group 'gnus-article-highlight)
819 ;; backward-compatibility alias
820 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
821 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
823 (defface gnus-header-name
824 '((((class color)
825 (background dark))
826 (:foreground "SpringGreen2"))
827 (((class color)
828 (background light))
829 (:foreground "maroon"))
831 (:bold t)))
832 "Face used for displaying header names."
833 :group 'gnus-article-headers
834 :group 'gnus-article-highlight)
835 ;; backward-compatibility alias
836 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
837 (put 'gnus-header-name-face 'obsolete-face "22.1")
839 (defface gnus-header-content
840 '((((class color)
841 (background dark))
842 (:foreground "SpringGreen1" :italic t))
843 (((class color)
844 (background light))
845 (:foreground "indianred4" :italic t))
847 (:italic t))) "Face used for displaying header content."
848 :group 'gnus-article-headers
849 :group 'gnus-article-highlight)
850 ;; backward-compatibility alias
851 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
852 (put 'gnus-header-content-face 'obsolete-face "22.1")
854 (defcustom gnus-header-face-alist
855 '(("From" nil gnus-header-from)
856 ("Subject" nil gnus-header-subject)
857 ("Newsgroups:.*," nil gnus-header-newsgroups)
858 ("" gnus-header-name gnus-header-content))
859 "*Controls highlighting of article headers.
861 An alist of the form (HEADER NAME CONTENT).
863 HEADER is a regular expression which should match the name of a
864 header and NAME and CONTENT are either face names or nil.
866 The name of each header field will be displayed using the face
867 specified by the first element in the list where HEADER matches
868 the header name and NAME is non-nil. Similarly, the content will
869 be displayed by the first non-nil matching CONTENT face."
870 :group 'gnus-article-headers
871 :group 'gnus-article-highlight
872 :type '(repeat (list (regexp :tag "Header")
873 (choice :tag "Name"
874 (item :tag "skip" nil)
875 (face :value default))
876 (choice :tag "Content"
877 (item :tag "skip" nil)
878 (face :value default)))))
880 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
881 '((xface . (:face gnus-x-face)))
882 '((pbm . (:face gnus-x-face))
883 (png . nil)))
884 "Alist of image types and properties applied to Face and X-Face images.
885 Here are examples:
887 ;; Specify the altitude of Face images in the From header.
888 \(setq gnus-face-properties-alist
889 \\='((pbm . (:face gnus-x-face :ascent 80))
890 (png . (:ascent 80))))
892 ;; Show Face images as pressed buttons.
893 \(setq gnus-face-properties-alist
894 \\='((pbm . (:face gnus-x-face :relief -2))
895 (png . (:relief -2))))
897 See the manual for the valid properties for various image types.
898 Currently, `pbm' is used for X-Face images and `png' is used for Face
899 images in Emacs. Only the `:face' property is effective on the `xface'
900 image type in XEmacs if it is built with the libcompface library."
901 :version "23.1" ;; No Gnus
902 :group 'gnus-article-headers
903 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
905 (defcustom gnus-article-decode-hook
906 '(article-decode-charset article-decode-encoded-words
907 article-decode-group-name article-decode-idna-rhs)
908 "*Hook run to decode charsets in articles."
909 :group 'gnus-article-headers
910 :type 'hook)
912 (defcustom gnus-display-mime-function 'gnus-display-mime
913 "Function to display MIME articles."
914 :group 'gnus-article-mime
915 :type 'function)
917 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
918 "Function used to decode headers.")
920 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
921 "Function used to decode addresses.")
923 (defvar gnus-article-dumbquotes-map
924 '((?\200 "EUR")
925 (?\202 ",")
926 (?\203 "f")
927 (?\204 ",,")
928 (?\205 "...")
929 (?\213 "<")
930 (?\214 "OE")
931 (?\221 "`")
932 (?\222 "'")
933 (?\223 "``")
934 (?\224 "\"")
935 (?\225 "*")
936 (?\226 "-")
937 (?\227 "--")
938 (?\230 "~")
939 (?\231 "(TM)")
940 (?\233 ">")
941 (?\234 "oe")
942 (?\264 "'"))
943 "Table for MS-to-Latin1 translation.")
945 (defcustom gnus-ignored-mime-types nil
946 "List of MIME types that should be ignored by Gnus."
947 :version "21.1"
948 :group 'gnus-article-mime
949 :type '(repeat regexp))
951 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
952 "List of MIME types that should not be given buttons when rendered inline.
953 See also `gnus-buttonized-mime-types' which may override this variable.
954 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
955 :version "21.1"
956 :group 'gnus-article-mime
957 :type '(repeat regexp))
959 (defcustom gnus-buttonized-mime-types nil
960 "List of MIME types that should be given buttons when rendered inline.
961 If set, this variable overrides `gnus-unbuttonized-mime-types'.
962 To see e.g. security buttons you could set this to
963 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
964 this list to display radio buttons that allow you to choose one of two
965 media types those mails include. See also `mm-discouraged-alternatives'.
966 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
967 :version "22.1"
968 :group 'gnus-article-mime
969 :type '(repeat regexp))
971 (defcustom gnus-inhibit-mime-unbuttonizing nil
972 "If non-nil, all MIME parts get buttons.
973 When nil (the default value), then some MIME parts do not get buttons,
974 as described by the variables `gnus-buttonized-mime-types' and
975 `gnus-unbuttonized-mime-types'."
976 :version "22.1"
977 :group 'gnus-article-mime
978 :type 'boolean)
980 (defcustom gnus-body-boundary-delimiter "_"
981 "String used to delimit header and body.
982 This variable is used by `gnus-article-treat-body-boundary' which can
983 be controlled by `gnus-treat-body-boundary'."
984 :version "22.1"
985 :group 'gnus-article-various
986 :type '(choice (item :tag "None" :value nil)
987 string))
989 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
990 "/usr/share/picons")
991 "Defines the location of the faces database.
992 For information on obtaining this database of pretty pictures, please
993 see http://www.cs.indiana.edu/picons/ftp/index.html"
994 :version "22.1"
995 :type '(repeat directory)
996 :link '(url-link :tag "download"
997 "http://www.cs.indiana.edu/picons/ftp/index.html")
998 :link '(custom-manual "(gnus)Picons")
999 :group 'gnus-picon)
1001 (defun gnus-picons-installed-p ()
1002 "Say whether picons are installed on your machine."
1003 (let ((installed nil))
1004 (dolist (database gnus-picon-databases)
1005 (when (file-exists-p database)
1006 (setq installed t)))
1007 installed))
1009 (defcustom gnus-article-mime-part-function nil
1010 "Function called with a MIME handle as the argument.
1011 This is meant for people who want to do something automatic based
1012 on parts -- for instance, adding Vcard info to a database."
1013 :group 'gnus-article-mime
1014 :type '(choice (const nil)
1015 function))
1017 (defcustom gnus-mime-multipart-functions nil
1018 "An alist of MIME types to functions to display them."
1019 :version "21.1"
1020 :group 'gnus-article-mime
1021 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1023 (defcustom gnus-article-date-headers '(combined-lapsed)
1024 "A list of Date header formats to display.
1025 Valid formats are `ut' (universal time), `local' (local time
1026 zone), `english' (readable English), `lapsed' (elapsed time),
1027 `combined-lapsed' (both the original date and the elapsed time),
1028 `original' (the original date header), `iso8601' (ISO8601
1029 format), and `user-defined' (a user-defined format defined by the
1030 `gnus-article-time-format' variable).
1032 You have as many date headers as you want in the article buffer.
1033 Some of these headers are updated automatically. See
1034 `gnus-article-update-date-headers' for details."
1035 :version "24.1"
1036 :group 'gnus-article-headers
1037 :type '(set
1038 (const :tag "Universal time (UT)" ut)
1039 (const :tag "Local time zone" local)
1040 (const :tag "Readable English" english)
1041 (const :tag "Elapsed time" lapsed)
1042 (const :tag "Original and elapsed time" combined-lapsed)
1043 (const :tag "Original date header" original)
1044 (const :tag "ISO8601 format" iso8601)
1045 (const :tag "User-defined" user-defined)))
1047 (defcustom gnus-article-update-date-headers nil
1048 "A number that says how often to update the date header (in seconds).
1049 If nil, don't update it at all."
1050 :version "24.1"
1051 :group 'gnus-article-headers
1052 :type '(choice
1053 (item :tag "Don't update" :value nil)
1054 integer))
1056 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1057 "Function called with a MIME handle as the argument.
1058 This is meant for people who want to view first matched part.
1059 For `undisplayed-alternative' (default), the first undisplayed
1060 part or alternative part is used. For `undisplayed', the first
1061 undisplayed part is used. For a function, the first part which
1062 the function return t is used. For nil, the first part is
1063 used."
1064 :version "21.1"
1065 :group 'gnus-article-mime
1066 :type '(choice
1067 (item :tag "first" :value nil)
1068 (item :tag "undisplayed" :value undisplayed)
1069 (item :tag "undisplayed or alternative"
1070 :value undisplayed-alternative)
1071 (function)))
1073 (defcustom gnus-mime-action-alist
1074 '(("save to file" . gnus-mime-save-part)
1075 ("save and strip" . gnus-mime-save-part-and-strip)
1076 ("replace with file" . gnus-mime-replace-part)
1077 ("delete part" . gnus-mime-delete-part)
1078 ("display as text" . gnus-mime-inline-part)
1079 ("view the part" . gnus-mime-view-part)
1080 ("pipe to command" . gnus-mime-pipe-part)
1081 ("toggle display" . gnus-article-press-button)
1082 ("toggle display" . gnus-article-view-part-as-charset)
1083 ("view as type" . gnus-mime-view-part-as-type)
1084 ("view internally" . gnus-mime-view-part-internally)
1085 ("view externally" . gnus-mime-view-part-externally))
1086 "An alist of actions that run on the MIME attachment."
1087 :group 'gnus-article-mime
1088 :type '(repeat (cons (string :tag "name")
1089 (function))))
1091 (defcustom gnus-auto-select-part 1
1092 "Advance to next MIME part when deleting or stripping parts.
1094 When 0, point will be placed on the same part as before. When
1095 positive (negative), move point forward (backwards) this many
1096 parts. When nil, redisplay article."
1097 :version "23.1" ;; No Gnus
1098 :group 'gnus-article-mime
1099 :type '(choice (const nil :tag "Redisplay article.")
1100 (const 1 :tag "Next part.")
1101 (const 0 :tag "Current part.")
1102 integer))
1105 ;;; The treatment variables
1108 (defvar gnus-part-display-hook nil
1109 "Hook called on parts that are to receive treatment.")
1111 (defvar gnus-article-treat-custom
1112 '(choice (const :tag "Off" nil)
1113 (const :tag "On" t)
1114 (const :tag "Header" head)
1115 (const :tag "First" first)
1116 (const :tag "Last" last)
1117 (integer :tag "Less")
1118 (repeat :tag "Groups" regexp)
1119 (sexp :tag "Predicate")))
1121 (defvar gnus-article-treat-head-custom
1122 '(choice (const :tag "Off" nil)
1123 (const :tag "Header" head)))
1125 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1126 "text/x-patch" "text/html")
1127 "Part types eligible for treatment.")
1129 (defvar gnus-inhibit-treatment nil
1130 "Whether to inhibit treatment.")
1132 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1133 "Highlight the signature.
1134 Valid values are nil, t, `head', `first', `last', an integer or a
1135 predicate. See Info node `(gnus)Customizing Articles'."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1139 (put 'gnus-treat-highlight-signature 'highlight t)
1141 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1142 "Add buttons.
1143 Valid values are nil, t, `head', `first', `last', an integer or a
1144 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1148 (put 'gnus-treat-buttonize 'highlight t)
1150 (defcustom gnus-treat-buttonize-head 'head
1151 "Add buttons to the head.
1152 Valid values are nil, t, `head', `first', `last', an integer or a
1153 predicate. See Info node `(gnus)Customizing Articles'."
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-head-custom)
1157 (put 'gnus-treat-buttonize-head 'highlight t)
1159 (defcustom gnus-treat-date 'head
1160 "Display dates according to the `gnus-article-date-headers' variable.
1161 Valid values are nil, t, `head', `first', `last', an integer or a
1162 predicate. See Info node `(gnus)Customizing Articles'."
1163 :version "24.1"
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-head-custom)
1168 (defcustom gnus-treat-emphasize 50000
1169 "Emphasize text.
1170 Valid values are nil, t, `head', `first', `last', an integer or a
1171 predicate. See Info node `(gnus)Customizing Articles'."
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-custom)
1175 (put 'gnus-treat-emphasize 'highlight t)
1177 (defcustom gnus-treat-strip-cr nil
1178 "Remove carriage returns.
1179 Valid values are nil, t, `head', `first', `last', an integer or a
1180 predicate. See Info node `(gnus)Customizing Articles'."
1181 :version "22.1"
1182 :group 'gnus-article-treat
1183 :link '(custom-manual "(gnus)Customizing Articles")
1184 :type gnus-article-treat-custom)
1186 (defcustom gnus-treat-unsplit-urls nil
1187 "Remove newlines from within URLs.
1188 Valid values are nil, t, `head', `first', `last', an integer or a
1189 predicate. See Info node `(gnus)Customizing Articles'."
1190 :version "22.1"
1191 :group 'gnus-article-treat
1192 :link '(custom-manual "(gnus)Customizing Articles")
1193 :type gnus-article-treat-custom)
1195 (defcustom gnus-treat-leading-whitespace nil
1196 "Remove leading whitespace in headers.
1197 Valid values are nil, t, `head', `first', `last', an integer or a
1198 predicate. See Info node `(gnus)Customizing Articles'."
1199 :version "22.1"
1200 :group 'gnus-article-treat
1201 :link '(custom-manual "(gnus)Customizing Articles")
1202 :type gnus-article-treat-custom)
1204 (defcustom gnus-treat-hide-headers 'head
1205 "Hide headers.
1206 Valid values are nil, t, `head', `first', `last', an integer or a
1207 predicate. See Info node `(gnus)Customizing Articles'."
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
1210 :type gnus-article-treat-head-custom)
1212 (defcustom gnus-treat-hide-boring-headers nil
1213 "Hide boring headers.
1214 Valid values are nil, t, `head', `first', `last', an integer or a
1215 predicate. See Info node `(gnus)Customizing Articles'."
1216 :group 'gnus-article-treat
1217 :link '(custom-manual "(gnus)Customizing Articles")
1218 :type gnus-article-treat-head-custom)
1220 (defcustom gnus-treat-hide-signature nil
1221 "Hide the signature.
1222 Valid values are nil, t, `head', `first', `last', an integer or a
1223 predicate. See Info node `(gnus)Customizing Articles'."
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1228 (defcustom gnus-treat-fill-article nil
1229 "Fill the article.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'."
1232 :group 'gnus-article-treat
1233 :link '(custom-manual "(gnus)Customizing Articles")
1234 :type gnus-article-treat-custom)
1236 (defcustom gnus-treat-hide-citation nil
1237 "Hide cited text.
1238 Valid values are nil, t, `head', `first', `last', an integer or a
1239 predicate. See Info node `(gnus)Customizing Articles'.
1241 See `gnus-article-highlight-citation' for variables used to
1242 control what it hides."
1243 :group 'gnus-article-treat
1244 :link '(custom-manual "(gnus)Customizing Articles")
1245 :type gnus-article-treat-custom)
1247 (defcustom gnus-treat-hide-citation-maybe nil
1248 "Hide cited text according to certain conditions.
1249 Valid values are nil, t, `head', `first', `last', an integer or a
1250 predicate. See Info node `(gnus)Customizing Articles'.
1252 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1253 how to control what it hides."
1254 :group 'gnus-article-treat
1255 :link '(custom-manual "(gnus)Customizing Articles")
1256 :type gnus-article-treat-custom)
1258 (defcustom gnus-treat-strip-list-identifiers 'head
1259 "Strip list identifiers from `gnus-list-identifiers'.
1260 Valid values are nil, t, `head', `first', `last', an integer or a
1261 predicate. See Info node `(gnus)Customizing Articles'."
1262 :version "21.1"
1263 :group 'gnus-article-treat
1264 :link '(custom-manual "(gnus)Customizing Articles")
1265 :type gnus-article-treat-custom)
1267 (gnus-define-group-parameter
1268 list-identifier
1269 :variable-document
1270 "Alist of regexps and correspondent identifiers."
1271 :variable-group gnus-article-washing
1272 :parameter-type
1273 '(choice :tag "Identifier"
1274 :value nil
1275 (symbol :tag "Item in `gnus-list-identifiers'" none)
1276 regexp
1277 (const :tag "None" nil))
1278 :parameter-document
1279 "If non-nil, specify how to remove `identifiers' from articles' subject.
1281 Any symbol is used to look up a regular expression to match the
1282 banner in `gnus-list-identifiers'. A string is used as a regular
1283 expression to match the identifier directly.")
1285 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1286 "Gnus 5.10 (Emacs 22.1)")
1288 (defcustom gnus-treat-strip-pem nil
1289 "Strip PEM signatures.
1290 Valid values are nil, t, `head', `first', `last', an integer or a
1291 predicate. See Info node `(gnus)Customizing Articles'."
1292 :group 'gnus-article-treat
1293 :link '(custom-manual "(gnus)Customizing Articles")
1294 :type gnus-article-treat-custom)
1296 (defcustom gnus-treat-strip-banner t
1297 "Strip banners from articles.
1298 The banner to be stripped is specified in the `banner' group parameter.
1299 Valid values are nil, t, `head', `first', `last', an integer or a
1300 predicate. See Info node `(gnus)Customizing Articles'."
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-custom)
1305 (defcustom gnus-treat-highlight-headers 'head
1306 "Highlight the headers.
1307 Valid values are nil, t, `head', `first', `last', an integer or a
1308 predicate. See Info node `(gnus)Customizing Articles'."
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-head-custom)
1312 (put 'gnus-treat-highlight-headers 'highlight t)
1314 (defcustom gnus-treat-highlight-citation t
1315 "Highlight cited text.
1316 Valid values are nil, t, `head', `first', `last', an integer or a
1317 predicate. See Info node `(gnus)Customizing Articles'."
1318 :group 'gnus-article-treat
1319 :link '(custom-manual "(gnus)Customizing Articles")
1320 :type gnus-article-treat-custom)
1321 (put 'gnus-treat-highlight-citation 'highlight t)
1323 (defcustom gnus-treat-strip-headers-in-body t
1324 "Strip the X-No-Archive header line from the beginning of the body.
1325 Valid values are nil, t, `head', `first', `last', an integer or a
1326 predicate. See Info node `(gnus)Customizing Articles'."
1327 :version "21.1"
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1332 (defcustom gnus-treat-strip-trailing-blank-lines nil
1333 "Strip trailing blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1337 When set to t, it also strips trailing blanks in all MIME parts.
1338 Consider to use `last' instead."
1339 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :type gnus-article-treat-custom)
1343 (defcustom gnus-treat-strip-leading-blank-lines nil
1344 "Strip leading blank lines.
1345 Valid values are nil, t, `head', `first', `last', an integer or a
1346 predicate. See Info node `(gnus)Customizing Articles'.
1348 When set to t, it also strips trailing blanks in all MIME parts."
1349 :group 'gnus-article-treat
1350 :link '(custom-manual "(gnus)Customizing Articles")
1351 :type gnus-article-treat-custom)
1353 (defcustom gnus-treat-strip-multiple-blank-lines nil
1354 "Strip multiple blank lines.
1355 Valid values are nil, t, `head', `first', `last', an integer or a
1356 predicate. See Info node `(gnus)Customizing Articles'."
1357 :group 'gnus-article-treat
1358 :link '(custom-manual "(gnus)Customizing Articles")
1359 :type gnus-article-treat-custom)
1361 (defcustom gnus-treat-unfold-headers 'head
1362 "Unfold folded header lines.
1363 Valid values are nil, t, `head', `first', `last', an integer or a
1364 predicate. See Info node `(gnus)Customizing Articles'."
1365 :version "22.1"
1366 :group 'gnus-article-treat
1367 :link '(custom-manual "(gnus)Customizing Articles")
1368 :type gnus-article-treat-custom)
1370 (defcustom gnus-article-unfold-long-headers nil
1371 "If non-nil, allow unfolding headers even if the header is long.
1372 If it is a regexp, only long headers matching this regexp are unfolded.
1373 If it is t, all long headers are unfolded.
1375 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1376 :version "23.1" ;; No Gnus
1377 :group 'gnus-article-treat
1378 :type '(choice (const nil)
1379 (const :tag "all" t)
1380 (regexp)))
1382 (defcustom gnus-treat-fold-headers nil
1383 "Fold headers.
1384 Valid values are nil, t, `head', `first', `last', an integer or a
1385 predicate. See Info node `(gnus)Customizing Articles'."
1386 :version "22.1"
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1391 (defcustom gnus-treat-fold-newsgroups 'head
1392 "Fold the Newsgroups and Followup-To headers.
1393 Valid values are nil, t, `head', `first', `last', an integer or a
1394 predicate. See Info node `(gnus)Customizing Articles'."
1395 :version "22.1"
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1400 (defcustom gnus-treat-overstrike t
1401 "Treat overstrike highlighting.
1402 Valid values are nil, t, `head', `first', `last', an integer or a
1403 predicate. See Info node `(gnus)Customizing Articles'."
1404 :group 'gnus-article-treat
1405 :link '(custom-manual "(gnus)Customizing Articles")
1406 :type gnus-article-treat-custom)
1407 (put 'gnus-treat-overstrike 'highlight t)
1409 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1410 "Treat ANSI SGR control sequences.
1411 Valid values are nil, t, `head', `first', `last', an integer or a
1412 predicate. See Info node `(gnus)Customizing Articles'."
1413 :group 'gnus-article-treat
1414 :link '(custom-manual "(gnus)Customizing Articles")
1415 :type gnus-article-treat-custom)
1417 (make-obsolete-variable 'gnus-treat-display-xface
1418 'gnus-treat-display-x-face "Emacs 22.1")
1420 (defcustom gnus-treat-display-x-face
1421 (and (not noninteractive)
1422 (gnus-image-type-available-p 'xbm)
1423 (if (featurep 'xemacs)
1424 (featurep 'xface)
1425 (condition-case nil
1426 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1427 (executable-find "icontopbm"))
1428 ;; shell-command-to-string may signal an error, e.g. if
1429 ;; shell-file-name is not found.
1430 (error nil)))
1431 'head)
1432 "Display X-Face headers.
1433 Valid values are nil and `head'.
1434 See Info node `(gnus)Customizing Articles' and Info node
1435 `(gnus)X-Face' for details."
1436 :group 'gnus-article-treat
1437 :version "21.1"
1438 :link '(custom-manual "(gnus)Customizing Articles")
1439 :link '(custom-manual "(gnus)X-Face")
1440 :type gnus-article-treat-head-custom
1441 :set (lambda (symbol value)
1442 (set-default
1443 symbol
1444 (cond ((or (boundp symbol) (get symbol 'saved-value))
1445 value)
1446 ((boundp 'gnus-treat-display-xface)
1447 (message "\
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (default-value 'gnus-treat-display-xface))
1451 ((get 'gnus-treat-display-xface 'saved-value)
1452 (message "\
1453 ** gnus-treat-display-xface is an obsolete variable;\
1454 use gnus-treat-display-x-face instead")
1455 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1457 value)))))
1458 (put 'gnus-treat-display-x-face 'highlight t)
1460 (defcustom gnus-treat-display-face
1461 (and (not noninteractive)
1462 (gnus-image-type-available-p 'png)
1463 'head)
1464 "Display Face headers.
1465 Valid values are nil, t, `head', `first', `last', an integer or a
1466 predicate. See Info node `(gnus)Customizing Articles' and Info
1467 node `(gnus)Face' for details."
1468 :group 'gnus-article-treat
1469 :version "22.1"
1470 :link '(custom-manual "(gnus)Customizing Articles")
1471 :link '(custom-manual "(gnus)X-Face")
1472 :type gnus-article-treat-head-custom)
1473 (put 'gnus-treat-display-face 'highlight t)
1475 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1476 "Display smileys.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Smileys' for details."
1480 :group 'gnus-article-treat
1481 :version "21.1"
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :link '(custom-manual "(gnus)Smileys")
1484 :type gnus-article-treat-custom)
1485 (put 'gnus-treat-display-smileys 'highlight t)
1487 (defcustom gnus-treat-from-picon
1488 (if (and (gnus-image-type-available-p 'xpm)
1489 (gnus-picons-installed-p))
1490 'head nil)
1491 "Display picons in the From header.
1492 Valid values are nil, t, `head', `first', `last', an integer or a
1493 predicate. See Info node `(gnus)Customizing Articles' and Info
1494 node `(gnus)Picons' for details."
1495 :version "22.1"
1496 :group 'gnus-article-treat
1497 :group 'gnus-picon
1498 :link '(custom-manual "(gnus)Customizing Articles")
1499 :link '(custom-manual "(gnus)Picons")
1500 :type gnus-article-treat-head-custom)
1501 (put 'gnus-treat-from-picon 'highlight t)
1503 (defcustom gnus-treat-mail-picon
1504 (if (and (gnus-image-type-available-p 'xpm)
1505 (gnus-picons-installed-p))
1506 'head nil)
1507 "Display picons in To and Cc headers.
1508 Valid values are nil, t, `head', `first', `last', an integer or a
1509 predicate. See Info node `(gnus)Customizing Articles' and Info
1510 node `(gnus)Picons' for details."
1511 :version "22.1"
1512 :group 'gnus-article-treat
1513 :group 'gnus-picon
1514 :link '(custom-manual "(gnus)Customizing Articles")
1515 :link '(custom-manual "(gnus)Picons")
1516 :type gnus-article-treat-head-custom)
1517 (put 'gnus-treat-mail-picon 'highlight t)
1519 (defcustom gnus-treat-newsgroups-picon
1520 (if (and (gnus-image-type-available-p 'xpm)
1521 (gnus-picons-installed-p))
1522 'head nil)
1523 "Display picons in the Newsgroups and Followup-To headers.
1524 Valid values are nil, t, `head', `first', `last', an integer or a
1525 predicate. See Info node `(gnus)Customizing Articles' and Info
1526 node `(gnus)Picons' for details."
1527 :version "22.1"
1528 :group 'gnus-article-treat
1529 :group 'gnus-picon
1530 :link '(custom-manual "(gnus)Customizing Articles")
1531 :link '(custom-manual "(gnus)Picons")
1532 :type gnus-article-treat-head-custom)
1533 (put 'gnus-treat-newsgroups-picon 'highlight t)
1535 (defcustom gnus-treat-from-gravatar nil
1536 "Display gravatars in the From header.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles' and Info
1539 node `(gnus)Gravatars' for details."
1540 :version "24.1"
1541 :group 'gnus-article-treat
1542 :group 'gnus-gravatar
1543 :link '(custom-manual "(gnus)Customizing Articles")
1544 :link '(custom-manual "(gnus)Gravatars")
1545 :type gnus-article-treat-head-custom)
1546 (put 'gnus-treat-from-gravatar 'highlight t)
1548 (defcustom gnus-treat-mail-gravatar nil
1549 "Display gravatars in To and Cc headers.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate. See Info node `(gnus)Customizing Articles' and Info
1552 node `(gnus)Gravatars' for details."
1553 :version "24.1"
1554 :group 'gnus-article-treat
1555 :group 'gnus-gravatar
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :link '(custom-manual "(gnus)Gravatars")
1558 :type gnus-article-treat-head-custom)
1559 (put 'gnus-treat-mail-gravatar 'highlight t)
1561 (defcustom gnus-treat-body-boundary
1562 (if (or gnus-treat-newsgroups-picon
1563 gnus-treat-mail-picon
1564 gnus-treat-from-picon
1565 gnus-treat-from-gravatar
1566 gnus-treat-mail-gravatar)
1567 ;; If there's much decoration, the user might prefer a boundary.
1568 'head
1569 nil)
1570 "Draw a boundary at the end of the headers.
1571 Valid values are nil and `head'.
1572 See Info node `(gnus)Customizing Articles' for details."
1573 :version "22.1"
1574 :group 'gnus-article-treat
1575 :link '(custom-manual "(gnus)Customizing Articles")
1576 :type gnus-article-treat-head-custom)
1578 (defcustom gnus-treat-capitalize-sentences nil
1579 "Capitalize sentence-starting words.
1580 Valid values are nil, t, `head', `first', `last', an integer or a
1581 predicate. See Info node `(gnus)Customizing Articles'."
1582 :version "21.1"
1583 :group 'gnus-article-treat
1584 :link '(custom-manual "(gnus)Customizing Articles")
1585 :type gnus-article-treat-custom)
1587 (defcustom gnus-treat-wash-html nil
1588 "Format as HTML.
1589 Valid values are nil, t, `head', `first', `last', an integer or a
1590 predicate. See Info node `(gnus)Customizing Articles'."
1591 :version "22.1"
1592 :group 'gnus-article-treat
1593 :link '(custom-manual "(gnus)Customizing Articles")
1594 :type gnus-article-treat-custom)
1596 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1597 "Fill long lines.
1598 Valid values are nil, t, `head', `first', `last', an integer or a
1599 predicate. See Info node `(gnus)Customizing Articles'."
1600 :version "24.1"
1601 :group 'gnus-article-treat
1602 :link '(custom-manual "(gnus)Customizing Articles")
1603 :type gnus-article-treat-custom)
1605 (defcustom gnus-treat-x-pgp-sig nil
1606 "Verify X-PGP-Sig.
1607 To automatically treat X-PGP-Sig, set it to head.
1608 Valid values are nil, t, `head', `first', `last', an integer or a
1609 predicate. See Info node `(gnus)Customizing Articles'."
1610 :version "22.1"
1611 :group 'gnus-article-treat
1612 :group 'mime-security
1613 :link '(custom-manual "(gnus)Customizing Articles")
1614 :type gnus-article-treat-custom)
1616 (defvar gnus-article-encrypt-protocol-alist
1617 '(("PGP" . mml2015-self-encrypt)))
1619 ;; Set to nil if more than one protocol added to
1620 ;; gnus-article-encrypt-protocol-alist.
1621 (defcustom gnus-article-encrypt-protocol "PGP"
1622 "The protocol used for encrypt articles.
1623 It is a string, such as \"PGP\". If nil, ask user."
1624 :version "22.1"
1625 :type 'string
1626 :group 'mime-security)
1628 (defvar idna-program)
1630 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1631 (condition-case nil
1632 (require 'idna)
1633 (file-error)
1634 (invalid-operation))
1635 idna-program
1636 (executable-find idna-program))
1637 "Whether IDNA decoding of headers is used when viewing messages.
1638 This requires GNU Libidn, and by default only enabled if it is found."
1639 :version "22.1"
1640 :group 'gnus-article-headers
1641 :type 'boolean)
1643 (defcustom gnus-article-over-scroll nil
1644 "If non-nil, allow scrolling the article buffer even when there no more text."
1645 :version "22.1"
1646 :group 'gnus-article
1647 :type 'boolean)
1649 (defcustom gnus-inhibit-images nil
1650 "Non-nil means inhibit displaying of images inline in the article body."
1651 :version "24.1"
1652 :group 'gnus-article
1653 :type 'boolean)
1655 (defcustom gnus-blocked-images 'gnus-block-private-groups
1656 "Images that have URLs matching this regexp will be blocked.
1657 This can also be a function to be evaluated. If so, it will be
1658 called with the group name as the parameter, and should return a
1659 regexp."
1660 :version "24.1"
1661 :group 'gnus-art
1662 :type '(choice (const :tag "Allow all" nil)
1663 (regexp :tag "Regular expression")
1664 (function :tag "Use a function")))
1666 ;;; Internal variables
1668 (defvar gnus-english-month-names
1669 '("January" "February" "March" "April" "May" "June" "July" "August"
1670 "September" "October" "November" "December"))
1672 (defvar article-goto-body-goes-to-point-min-p nil)
1673 (defvar gnus-article-wash-types nil)
1674 (defvar gnus-article-emphasis-alist nil)
1675 (defvar gnus-article-image-alist nil)
1677 (defvar gnus-article-mime-handle-alist-1 nil)
1678 (defvar gnus-treatment-function-alist
1679 '((gnus-treat-strip-cr gnus-article-remove-cr)
1680 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1681 (gnus-treat-strip-banner gnus-article-strip-banner)
1682 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1683 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1684 (gnus-treat-buttonize gnus-article-add-buttons)
1685 (gnus-treat-fill-article gnus-article-fill-cited-article)
1686 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1687 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1688 (gnus-treat-display-x-face gnus-article-display-x-face)
1689 (gnus-treat-display-face gnus-article-display-face)
1690 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1691 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1692 (gnus-treat-hide-signature gnus-article-hide-signature)
1693 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1694 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1695 (gnus-treat-from-picon gnus-treat-from-picon)
1696 (gnus-treat-mail-picon gnus-treat-mail-picon)
1697 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1698 (gnus-treat-strip-pem gnus-article-hide-pem)
1699 (gnus-treat-date gnus-article-treat-date)
1700 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1701 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1702 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1703 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1704 (gnus-treat-strip-trailing-blank-lines
1705 gnus-article-remove-trailing-blank-lines)
1706 (gnus-treat-strip-leading-blank-lines
1707 gnus-article-strip-leading-blank-lines)
1708 (gnus-treat-strip-multiple-blank-lines
1709 gnus-article-strip-multiple-blank-lines)
1710 (gnus-treat-overstrike gnus-article-treat-overstrike)
1711 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1712 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1713 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1714 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1715 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1716 (gnus-treat-display-smileys gnus-treat-smiley)
1717 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1718 (gnus-treat-wash-html gnus-article-wash-html)
1719 (gnus-treat-emphasize gnus-article-emphasize)
1720 (gnus-treat-hide-citation gnus-article-hide-citation)
1721 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1722 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1723 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1725 (defvar gnus-article-mime-handle-alist nil)
1726 (defvar article-lapsed-timer nil)
1727 (defvar gnus-article-current-summary nil)
1729 (defvar gnus-article-mode-syntax-table
1730 (let ((table (copy-syntax-table text-mode-syntax-table)))
1731 ;; This causes the citation match run O(2^n).
1732 ;; (modify-syntax-entry ?- "w" table)
1733 (modify-syntax-entry ?> ")<" table)
1734 (modify-syntax-entry ?< "(>" table)
1735 ;; make M-. in article buffers work for `foo' strings
1736 (modify-syntax-entry ?' " " table)
1737 (modify-syntax-entry ?` " " table)
1738 table)
1739 "Syntax table used in article mode buffers.
1740 Initialized from `text-mode-syntax-table'.")
1742 (defvar gnus-save-article-buffer nil)
1744 (defvar gnus-number-of-articles-to-be-saved nil)
1746 (defvar gnus-inhibit-hiding nil)
1748 (defvar gnus-article-edit-mode nil)
1750 ;;; Macros for dealing with the article buffer.
1752 (defmacro gnus-with-article-headers (&rest forms)
1753 `(with-current-buffer gnus-article-buffer
1754 (save-restriction
1755 (let ((inhibit-read-only t)
1756 (inhibit-point-motion-hooks t)
1757 (case-fold-search t))
1758 (article-narrow-to-head)
1759 ,@forms))))
1761 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1762 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1764 (defmacro gnus-with-article-buffer (&rest forms)
1765 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1766 (with-current-buffer gnus-article-buffer
1767 (let ((inhibit-read-only t))
1768 ,@forms))))
1770 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1771 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1773 (defun gnus-article-goto-header (header)
1774 "Go to HEADER, which is a regular expression."
1775 (re-search-forward (concat "^\\(" header "\\):") nil t))
1777 (defsubst gnus-article-hide-text (b e props)
1778 "Set text PROPS on the B to E region."
1779 (gnus-add-text-properties-when 'article-type nil b e props))
1781 (defsubst gnus-article-unhide-text (b e)
1782 "Remove hidden text properties from region between B and E."
1783 (remove-text-properties b e gnus-hidden-properties))
1785 (defun gnus-article-hide-text-type (b e type)
1786 "Hide text of TYPE between B and E."
1787 (gnus-add-wash-type type)
1788 (gnus-article-hide-text
1789 b e (cons 'article-type (cons type gnus-hidden-properties))))
1791 (defun gnus-article-unhide-text-type (b e type)
1792 "Unhide text of TYPE between B and E."
1793 (gnus-delete-wash-type type)
1794 (remove-text-properties
1795 b e (cons 'article-type (cons type gnus-hidden-properties))))
1797 (defun gnus-article-delete-text-of-type (type)
1798 "Delete text of TYPE in the current buffer."
1799 (save-excursion
1800 (let ((b (point-min)))
1801 (if (eq type 'multipart)
1802 ;; Remove MIME buttons associated with multipart/alternative parts.
1803 (progn
1804 (goto-char b)
1805 (while (if (get-text-property (point) 'gnus-part)
1806 (setq b (point))
1807 (when (setq b (next-single-property-change (point)
1808 'gnus-part))
1809 (goto-char b)
1811 (end-of-line)
1812 (skip-chars-forward "\n")
1813 (when (eq (get-text-property b 'article-type) 'multipart)
1814 (delete-region b (point)))))
1815 (while (setq b (text-property-any b (point-max) 'article-type type))
1816 (delete-region
1817 b (or (text-property-not-all b (point-max) 'article-type type)
1818 (point-max))))))))
1820 (defun gnus-article-delete-invisible-text ()
1821 "Delete all invisible text in the current buffer."
1822 (save-excursion
1823 (let ((b (point-min)))
1824 (while (setq b (text-property-any b (point-max) 'invisible t))
1825 (delete-region
1826 b (or (text-property-not-all b (point-max) 'invisible t)
1827 (point-max)))))))
1829 (defsubst gnus-article-header-rank ()
1830 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1831 (let ((list gnus-sorted-header-list)
1832 (i 1))
1833 (while list
1834 (if (looking-at (car list))
1835 (setq list nil)
1836 (setq list (cdr list))
1837 (incf i)))
1840 (defun article-hide-headers (&optional _arg _delete)
1841 "Hide unwanted headers and possibly sort them as well."
1842 (interactive)
1843 ;; This function might be inhibited.
1844 (unless gnus-inhibit-hiding
1845 (let ((inhibit-read-only t)
1846 (case-fold-search t)
1847 (max (1+ (length gnus-sorted-header-list)))
1848 (inhibit-point-motion-hooks t)
1849 (cur (current-buffer))
1850 ignored visible beg)
1851 (save-excursion
1852 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1853 ;; group parameters, so we should go to the summary buffer.
1854 (when (prog1
1855 (condition-case nil
1856 (progn (set-buffer gnus-summary-buffer) t)
1857 (error nil))
1858 (setq ignored (when (not gnus-visible-headers)
1859 (cond ((stringp gnus-ignored-headers)
1860 gnus-ignored-headers)
1861 ((listp gnus-ignored-headers)
1862 (mapconcat 'identity
1863 gnus-ignored-headers
1864 "\\|"))))
1865 visible (cond ((stringp gnus-visible-headers)
1866 gnus-visible-headers)
1867 ((and gnus-visible-headers
1868 (listp gnus-visible-headers))
1869 (mapconcat 'identity
1870 gnus-visible-headers
1871 "\\|")))))
1872 (set-buffer cur))
1873 (save-restriction
1874 ;; First we narrow to just the headers.
1875 (article-narrow-to-head)
1876 ;; Hide any "From " lines at the beginning of (mail) articles.
1877 (while (looking-at "From ")
1878 (forward-line 1))
1879 (unless (bobp)
1880 (delete-region (point-min) (point)))
1881 ;; Then treat the rest of the header lines.
1882 ;; Then we use the two regular expressions
1883 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1884 ;; select which header lines is to remain visible in the
1885 ;; article buffer.
1886 (while (re-search-forward "^[^ \t:]*:" nil t)
1887 (beginning-of-line)
1888 ;; Mark the rank of the header.
1889 (put-text-property
1890 (point) (1+ (point)) 'message-rank
1891 (if (or (and visible (looking-at visible))
1892 (and ignored
1893 (not (looking-at ignored))))
1894 (gnus-article-header-rank)
1895 (+ 2 max)))
1896 (forward-line 1))
1897 (message-sort-headers-1)
1898 (when (setq beg (text-property-any
1899 (point-min) (point-max) 'message-rank (+ 2 max)))
1900 ;; We delete the unwanted headers.
1901 (gnus-add-wash-type 'headers)
1902 (add-text-properties (point-min) (+ 5 (point-min))
1903 '(article-type headers dummy-invisible t))
1904 (delete-region beg (point-max))))))))
1906 (defun article-hide-boring-headers (&optional arg)
1907 "Toggle hiding of headers that aren't very interesting.
1908 If given a negative prefix, always show; if given a positive prefix,
1909 always hide."
1910 (interactive (gnus-article-hidden-arg))
1911 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1912 (not gnus-show-all-headers))
1913 (save-excursion
1914 (save-restriction
1915 (let ((inhibit-read-only t)
1916 (inhibit-point-motion-hooks t))
1917 (article-narrow-to-head)
1918 (dolist (elem gnus-boring-article-headers)
1919 (goto-char (point-min))
1920 (cond
1921 ;; Hide empty headers.
1922 ((eq elem 'empty)
1923 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1924 (forward-line -1)
1925 (gnus-article-hide-text-type
1926 (point-at-bol)
1927 (progn
1928 (end-of-line)
1929 (if (re-search-forward "^[^ \t]" nil t)
1930 (match-beginning 0)
1931 (point-max)))
1932 'boring-headers)))
1933 ;; Hide boring Newsgroups header.
1934 ((eq elem 'newsgroups)
1935 (when (gnus-string-equal
1936 (gnus-fetch-field "newsgroups")
1937 (gnus-group-real-name
1938 (if (boundp 'gnus-newsgroup-name)
1939 gnus-newsgroup-name
1940 "")))
1941 (gnus-article-hide-header "newsgroups")))
1942 ((eq elem 'to-address)
1943 (let ((to (message-fetch-field "to"))
1944 (to-address
1945 (gnus-parameter-to-address
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-address
1949 (ignore-errors
1950 (gnus-string-equal
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1953 to-address)))
1954 (gnus-article-hide-header "to"))))
1955 ((eq elem 'to-list)
1956 (let ((to (message-fetch-field "to"))
1957 (to-list
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and to to-list
1962 (ignore-errors
1963 (gnus-string-equal
1964 ;; only one address in To
1965 (nth 1 (mail-extract-address-components to))
1966 to-list)))
1967 (gnus-article-hide-header "to"))))
1968 ((eq elem 'cc-list)
1969 (let ((cc (message-fetch-field "cc"))
1970 (to-list
1971 (gnus-parameter-to-list
1972 (if (boundp 'gnus-newsgroup-name)
1973 gnus-newsgroup-name ""))))
1974 (when (and cc to-list
1975 (ignore-errors
1976 (gnus-string-equal
1977 ;; only one address in CC
1978 (nth 1 (mail-extract-address-components cc))
1979 to-list)))
1980 (gnus-article-hide-header "cc"))))
1981 ((eq elem 'followup-to)
1982 (when (gnus-string-equal
1983 (message-fetch-field "followup-to")
1984 (message-fetch-field "newsgroups"))
1985 (gnus-article-hide-header "followup-to")))
1986 ((eq elem 'reply-to)
1987 (if (gnus-group-find-parameter
1988 gnus-newsgroup-name 'broken-reply-to)
1989 (gnus-article-hide-header "reply-to")
1990 (let ((from (message-fetch-field "from"))
1991 (reply-to (message-fetch-field "reply-to")))
1992 (when
1993 (and
1994 from reply-to
1995 (ignore-errors
1996 (equal
1997 (sort (mapcar
1998 (lambda (x) (downcase (cadr x)))
1999 (mail-extract-address-components from t))
2000 'string<)
2001 (sort (mapcar
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components reply-to t))
2004 'string<))))
2005 (gnus-article-hide-header "reply-to")))))
2006 ((eq elem 'date)
2007 (let ((date (with-current-buffer gnus-original-article-buffer
2008 ;; If date in `gnus-article-buffer' is localized
2009 ;; (`gnus-treat-date-user-defined'),
2010 ;; `days-between' might fail.
2011 (message-fetch-field "date"))))
2012 (when (and date
2013 (< (days-between (current-time-string) date)
2015 (gnus-article-hide-header "date"))))
2016 ((eq elem 'long-to)
2017 (let ((to (message-fetch-field "to"))
2018 (cc (message-fetch-field "cc")))
2019 (when (> (length to) 1024)
2020 (gnus-article-hide-header "to"))
2021 (when (> (length cc) 1024)
2022 (gnus-article-hide-header "cc"))))
2023 ((eq elem 'many-to)
2024 (let ((to-count 0)
2025 (cc-count 0))
2026 (goto-char (point-min))
2027 (while (re-search-forward "^to:" nil t)
2028 (setq to-count (1+ to-count)))
2029 (when (> to-count 1)
2030 (while (> to-count 0)
2031 (goto-char (point-min))
2032 (save-restriction
2033 (re-search-forward "^to:" nil nil to-count)
2034 (forward-line -1)
2035 (narrow-to-region (point) (point-max))
2036 (gnus-article-hide-header "to"))
2037 (setq to-count (1- to-count))))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^cc:" nil t)
2040 (setq cc-count (1+ cc-count)))
2041 (when (> cc-count 1)
2042 (while (> cc-count 0)
2043 (goto-char (point-min))
2044 (save-restriction
2045 (re-search-forward "^cc:" nil nil cc-count)
2046 (forward-line -1)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "cc"))
2049 (setq cc-count (1- cc-count)))))))))))))
2051 (defun gnus-article-hide-header (header)
2052 (save-excursion
2053 (goto-char (point-min))
2054 (when (re-search-forward (concat "^" header ":") nil t)
2055 (gnus-article-hide-text-type
2056 (point-at-bol)
2057 (progn
2058 (end-of-line)
2059 (if (re-search-forward "^[^ \t]" nil t)
2060 (match-beginning 0)
2061 (point-max)))
2062 'boring-headers))))
2064 (defvar gnus-article-normalized-header-length 40
2065 "Length of normalized headers.")
2067 (defun article-normalize-headers ()
2068 "Make all header lines 40 characters long."
2069 (interactive)
2070 (let ((inhibit-read-only t)
2071 column)
2072 (save-excursion
2073 (save-restriction
2074 (article-narrow-to-head)
2075 (while (not (eobp))
2076 (cond
2077 ((< (setq column (- (point-at-eol) (point)))
2078 gnus-article-normalized-header-length)
2079 (end-of-line)
2080 (insert (make-string
2081 (- gnus-article-normalized-header-length column)
2082 ? )))
2083 ((> column gnus-article-normalized-header-length)
2084 (gnus-put-text-property
2085 (progn
2086 (forward-char gnus-article-normalized-header-length)
2087 (point))
2088 (point-at-eol)
2089 'invisible t))
2091 ;; Do nothing.
2093 (forward-line 1))))))
2095 (defun article-treat-dumbquotes ()
2096 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2097 Note that this function guesses whether a character is a sm*rtq**t* or
2098 not, so it should only be used interactively.
2100 Sm*rtq**t*s are M****s***'s unilateral extension to the
2101 iso-8859-1 character map in an attempt to provide more quoting
2102 characters. If you see something like \\222 or \\264 where
2103 you're expecting some kind of apostrophe or quotation mark, then
2104 try this wash."
2105 (interactive)
2106 (article-translate-strings gnus-article-dumbquotes-map))
2108 (defvar org-entities)
2110 (defun article-treat-non-ascii ()
2111 "Translate many Unicode characters into their ASCII equivalents."
2112 (interactive)
2113 (require 'org-entities)
2114 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2115 (dolist (elem org-entities)
2116 (when (and (listp elem)
2117 (= (length (nth 6 elem)) 1))
2118 (if (featurep 'xemacs)
2119 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2120 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2121 (save-excursion
2122 (when (article-goto-body)
2123 (let ((inhibit-read-only t)
2124 replace props)
2125 (while (not (eobp))
2126 (if (not (setq replace (if (featurep 'xemacs)
2127 (get-char-table (following-char) table)
2128 (aref table (following-char)))))
2129 (forward-char 1)
2130 (if (prog1
2131 (setq props (text-properties-at (point)))
2132 (delete-char 1))
2133 (add-text-properties (point) (progn (insert replace) (point))
2134 props)
2135 (insert replace)))))))))
2137 (defun article-translate-strings (map)
2138 "Translate all string in the body of the article according to MAP.
2139 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2140 (save-excursion
2141 (when (article-goto-body)
2142 (let ((inhibit-read-only t))
2143 (dolist (elem map)
2144 (let ((from (car elem))
2145 (to (cadr elem)))
2146 (save-excursion
2147 (if (stringp from)
2148 (while (search-forward from nil t)
2149 (replace-match to))
2150 (while (not (eobp))
2151 (if (eq (following-char) from)
2152 (progn
2153 (delete-char 1)
2154 (insert to))
2155 (forward-char 1)))))))))))
2157 (defun article-treat-overstrike ()
2158 "Translate overstrikes into bold text."
2159 (interactive)
2160 (save-excursion
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (while (search-forward "\b" nil t)
2164 (let ((next (char-after))
2165 (previous (char-after (- (point) 2))))
2166 ;; We do the boldification/underlining by hiding the
2167 ;; overstrikes and putting the proper text property
2168 ;; on the letters.
2169 (cond
2170 ((eq next previous)
2171 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2172 (put-text-property (point) (1+ (point)) 'face 'bold))
2173 ((eq next ?_)
2174 (gnus-article-hide-text-type
2175 (1- (point)) (1+ (point)) 'overstrike)
2176 (put-text-property
2177 (- (point) 2) (1- (point)) 'face 'underline))
2178 ((eq previous ?_)
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2180 (put-text-property
2181 (point) (1+ (point)) 'face 'underline)))))))))
2183 (defun article-treat-ansi-sequences ()
2184 "Translate ANSI SGR control sequences into overlays or extents."
2185 (interactive)
2186 (save-excursion
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (ansi-color-apply-on-region (point) (point-max))))))
2191 (defun gnus-article-treat-unfold-headers ()
2192 "Unfold folded message headers.
2193 Only the headers that fit into the current window width will be
2194 unfolded."
2195 (interactive)
2196 (gnus-with-article-headers
2197 (let (length)
2198 (while (not (eobp))
2199 (save-restriction
2200 (mail-header-narrow-to-field)
2201 (let* ((header (buffer-string))
2202 (unfoldable
2203 (or (equal gnus-article-unfold-long-headers t)
2204 (and (stringp gnus-article-unfold-long-headers)
2205 (string-match gnus-article-unfold-long-headers
2206 header)))))
2207 (with-temp-buffer
2208 (insert header)
2209 (goto-char (point-min))
2210 (while (re-search-forward "\n[\t ]" nil t)
2211 (replace-match " " t t)))
2212 (setq length (- (point-max) (point-min) 1))
2213 (when (or unfoldable
2214 (< length (window-width)))
2215 (while (re-search-forward "\n[\t ]" nil t)
2216 (replace-match " " t t))))
2217 (goto-char (point-max)))))))
2219 (defun gnus-article-treat-fold-headers ()
2220 "Fold message headers."
2221 (interactive)
2222 (gnus-with-article-headers
2223 (while (not (eobp))
2224 (save-restriction
2225 (mail-header-narrow-to-field)
2226 (mail-header-fold-field)
2227 (goto-char (point-max))))))
2229 (defun gnus-treat-smiley ()
2230 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2231 (interactive)
2232 (gnus-with-article-buffer
2233 (if (memq 'smiley gnus-article-wash-types)
2234 (gnus-delete-images 'smiley)
2235 (article-goto-body)
2236 (let ((images (smiley-region (point) (point-max))))
2237 (when images
2238 (gnus-add-wash-type 'smiley)
2239 (dolist (image images)
2240 (gnus-add-image 'smiley image)))))))
2242 (defun gnus-article-remove-images ()
2243 "Remove all images from the article buffer."
2244 (interactive)
2245 (gnus-with-article-buffer
2246 (save-restriction
2247 (widen)
2248 (dolist (elem gnus-article-image-alist)
2249 (gnus-delete-images (car elem))))))
2251 (autoload 'w3m-toggle-inline-images "w3m")
2253 (defun gnus-article-show-images ()
2254 "Show any images that are in the HTML-rendered article buffer.
2255 This only works if the article in question is HTML."
2256 (interactive)
2257 (gnus-with-article-buffer
2258 (save-restriction
2259 (widen)
2260 (if (eq mm-text-html-renderer 'w3m)
2261 (let ((mm-inline-text-html-with-images nil))
2262 (w3m-toggle-inline-images))
2263 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2264 'image-displayer))
2265 (destructuring-bind (start end function) region
2266 (funcall function (get-text-property start 'image-url)
2267 start end)))))))
2269 (defun gnus-article-treat-fold-newsgroups ()
2270 "Unfold folded message headers.
2271 Only the headers that fit into the current window width will be
2272 unfolded."
2273 (interactive)
2274 (gnus-with-article-headers
2275 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2276 (save-restriction
2277 (mail-header-narrow-to-field)
2278 (while (re-search-forward ", *" nil t)
2279 (replace-match ", " t t))
2280 (mail-header-fold-field)
2281 (goto-char (point-max))))))
2283 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2284 "Value of `truncate-lines' in Gnus Article buffer.
2285 Valid values are nil, t, `head', `first', `last', an integer or a
2286 predicate. See Info node `(gnus)Customizing Articles'."
2287 :version "23.1" ;; No Gnus
2288 :group 'gnus-article
2289 ;; :link '(custom-manual "(gnus)Customizing Articles")
2290 :type 'boolean)
2292 (defun gnus-article-toggle-truncate-lines (&optional arg)
2293 "Toggle whether to fold or truncate long lines in article the buffer.
2294 If ARG is non-nil and not a number, toggle
2295 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2296 long lines if and only if arg is positive."
2297 (interactive "P")
2298 (cond
2299 ((and (numberp arg) (> arg 0))
2300 (setq gnus-article-truncate-lines t))
2301 ((numberp arg)
2302 (setq gnus-article-truncate-lines nil))
2303 (arg
2304 (setq gnus-article-truncate-lines
2305 (not gnus-article-truncate-lines))))
2306 (gnus-with-article-buffer
2307 (cond
2308 ((and (numberp arg) (> arg 0))
2309 (setq truncate-lines nil))
2310 ((numberp arg)
2311 (setq truncate-lines t)))
2312 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2313 ;; `toggle-truncate-lines' needs an argument.
2314 (toggle-truncate-lines)))
2316 (defun gnus-article-treat-body-boundary ()
2317 "Place a boundary line at the end of the headers."
2318 (interactive)
2319 (when (and gnus-body-boundary-delimiter
2320 (> (length gnus-body-boundary-delimiter) 0))
2321 (gnus-with-article-headers
2322 (goto-char (point-max))
2323 (let ((start (point)))
2324 (insert "X-Boundary: ")
2325 (gnus-add-text-properties start (point) gnus-hidden-properties)
2326 (insert (let (str (max (window-width)))
2327 (if (featurep 'xemacs)
2328 (setq max (1- max)))
2329 (while (>= max (length str))
2330 (setq str (concat str gnus-body-boundary-delimiter)))
2331 (substring str 0 max))
2332 "\n")
2333 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2335 (defun article-fill-long-lines ()
2336 "Fill lines that are wider than the window width."
2337 (interactive)
2338 (save-excursion
2339 (let ((inhibit-read-only t)
2340 (width (window-width (get-buffer-window (current-buffer)))))
2341 (save-restriction
2342 (article-goto-body)
2343 (let ((adaptive-fill-mode nil)) ;Why? -sm
2344 (while (not (eobp))
2345 (end-of-line)
2346 (when (>= (current-column) (min fill-column width))
2347 (narrow-to-region (min (1+ (point)) (point-max))
2348 (point-at-bol))
2349 (let ((goback (point-marker)))
2350 (fill-paragraph nil)
2351 (goto-char (marker-position goback)))
2352 (widen))
2353 (forward-line 1)))))))
2355 (defun article-capitalize-sentences ()
2356 "Capitalize the first word in each sentence."
2357 (interactive)
2358 (save-excursion
2359 (let ((inhibit-read-only t)
2360 (paragraph-start "^[\n\^L]"))
2361 (article-goto-body)
2362 (while (not (eobp))
2363 (capitalize-word 1)
2364 (forward-sentence)))))
2366 (defun article-remove-cr ()
2367 "Remove trailing CRs and then translate remaining CRs into LFs."
2368 (interactive)
2369 (save-excursion
2370 (let ((inhibit-read-only t))
2371 (goto-char (point-min))
2372 (while (re-search-forward "\r+$" nil t)
2373 (replace-match "" t t))
2374 (goto-char (point-min))
2375 (while (search-forward "\r" nil t)
2376 (replace-match "\n" t t)))))
2378 (defun article-remove-trailing-blank-lines ()
2379 "Remove all trailing blank lines from the article."
2380 (interactive)
2381 (save-excursion
2382 (let ((inhibit-read-only t))
2383 (goto-char (point-max))
2384 (delete-region
2385 (point)
2386 (progn
2387 (while (and (not (bobp))
2388 (looking-at "^[ \t]*$")
2389 (not (gnus-annotation-in-region-p
2390 (point) (point-at-eol))))
2391 (forward-line -1))
2392 (forward-line 1)
2393 (point))))))
2395 (defvar gnus-face-properties-alist)
2397 (defun article-display-face (&optional force)
2398 "Display any Face headers in the header."
2399 (interactive (list 'force))
2400 (let ((wash-face-p buffer-read-only))
2401 (gnus-with-article-headers
2402 ;; When displaying parts, this function can be called several times on
2403 ;; the same article, without any intended toggle semantic (as typing `W
2404 ;; D d' would have). So face deletion must occur only when we come from
2405 ;; an interactive command, that is when the *Article* buffer is
2406 ;; read-only.
2407 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2408 (gnus-delete-images 'face)
2409 (let ((from (message-fetch-field "from"))
2410 faces)
2411 (save-current-buffer
2412 (when (and wash-face-p
2413 (gnus-buffer-live-p gnus-original-article-buffer)
2414 (not (re-search-forward "^Face:[\t ]*" nil t)))
2415 (set-buffer gnus-original-article-buffer))
2416 (save-restriction
2417 (mail-narrow-to-head)
2418 (when (or force
2419 ;; Check whether this face is censored.
2420 (not (and gnus-article-x-face-too-ugly
2421 (or from
2422 (setq from (message-fetch-field "from")))
2423 (string-match gnus-article-x-face-too-ugly
2424 from))))
2425 (while (gnus-article-goto-header "Face")
2426 (push (mail-header-field-value) faces)))))
2427 (when faces
2428 (goto-char (point-min))
2429 (let (png image)
2430 (unless (setq from (gnus-article-goto-header "from"))
2431 (insert "From:")
2432 (setq from (point))
2433 (insert " [no 'from' set]\n"))
2434 (while faces
2435 (when (setq png (gnus-convert-face-to-png (pop faces)))
2436 (setq image
2437 (apply 'gnus-create-image png 'png t
2438 (cdr (assq 'png gnus-face-properties-alist))))
2439 (goto-char from)
2440 (when image
2441 (gnus-add-wash-type 'face)
2442 (gnus-add-image 'face image)
2443 (gnus-put-image image nil 'face)))))))))))
2445 (defun article-display-x-face (&optional force)
2446 "Look for an X-Face header and display it if present."
2447 (interactive (list 'force))
2448 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2449 (gnus-with-article-headers
2450 ;; Delete the old process, if any.
2451 (when (process-status "article-x-face")
2452 (delete-process "article-x-face"))
2453 ;; See the comment in `article-display-face'.
2454 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2455 ;; We have already displayed X-Faces, so we remove them
2456 ;; instead.
2457 (gnus-delete-images 'xface)
2458 ;; Display X-Faces.
2459 (let ((from (message-fetch-field "from"))
2460 x-faces)
2461 (save-current-buffer
2462 (when (and wash-face-p
2463 (gnus-buffer-live-p gnus-original-article-buffer)
2464 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2465 ;; If type `W f', use gnus-original-article-buffer,
2466 ;; otherwise use the current buffer because displaying
2467 ;; RFC822 parts calls this function too.
2468 (set-buffer gnus-original-article-buffer))
2469 (save-restriction
2470 (mail-narrow-to-head)
2471 (and gnus-article-x-face-command
2472 (or force
2473 ;; Check whether this face is censored.
2474 (not (and gnus-article-x-face-too-ugly
2475 (or from
2476 (setq from (message-fetch-field "from")))
2477 (string-match gnus-article-x-face-too-ugly
2478 from))))
2479 (while (gnus-article-goto-header "X-Face")
2480 (push (mail-header-field-value) x-faces)))))
2481 (when x-faces
2482 ;; We display the face.
2483 (cond ((functionp gnus-article-x-face-command)
2484 ;; The command is a lisp function, so we call it.
2485 (mapc gnus-article-x-face-command x-faces))
2486 ((stringp gnus-article-x-face-command)
2487 ;; The command is a string, so we interpret the command
2488 ;; as a, well, command, and fork it off.
2489 (let ((process-connection-type nil))
2490 (gnus-set-process-query-on-exit-flag
2491 (start-process
2492 "article-x-face" nil shell-file-name
2493 shell-command-switch gnus-article-x-face-command)
2494 nil)
2495 ;; Sending multiple EOFs to xv doesn't work,
2496 ;; so we only do a single external face.
2497 (with-temp-buffer
2498 (insert (car x-faces))
2499 (process-send-region "article-x-face"
2500 (point-min) (point-max)))
2501 (process-send-eof "article-x-face")))
2503 (error "`%s' set to `%s' is not a function"
2504 gnus-article-x-face-command
2505 'gnus-article-x-face-command)))))))))
2507 (defun article-decode-mime-words ()
2508 "Decode all MIME-encoded words in the article."
2509 (interactive)
2510 (gnus-with-article-buffer
2511 (let ((inhibit-point-motion-hooks t)
2512 (mail-parse-charset gnus-newsgroup-charset)
2513 (mail-parse-ignored-charsets
2514 (with-current-buffer gnus-summary-buffer
2515 gnus-newsgroup-ignored-charsets)))
2516 (mail-decode-encoded-word-region (point-min) (point-max)))))
2518 (defun article-decode-charset (&optional prompt)
2519 "Decode charset-encoded text in the article.
2520 If PROMPT (the prefix), prompt for a coding system to use."
2521 (interactive "P")
2522 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2523 (inhibit-read-only t)
2524 (mail-parse-charset gnus-newsgroup-charset)
2525 (mail-parse-ignored-charsets
2526 (save-excursion (condition-case nil
2527 (set-buffer gnus-summary-buffer)
2528 (error))
2529 gnus-newsgroup-ignored-charsets))
2530 ct cte ctl charset format)
2531 (save-excursion
2532 (save-restriction
2533 (article-narrow-to-head)
2534 (setq ct (message-fetch-field "Content-Type" t)
2535 cte (message-fetch-field "Content-Transfer-Encoding" t)
2536 ctl (and ct (mail-header-parse-content-type ct))
2537 charset (cond
2538 (prompt
2539 (mm-read-coding-system "Charset to decode: "))
2540 (ctl
2541 (mail-content-type-get ctl 'charset)))
2542 format (and ctl (mail-content-type-get ctl 'format)))
2543 (when cte
2544 (setq cte (mail-header-strip cte)))
2545 (if (and ctl (not (string-match "/" (car ctl))))
2546 (setq ctl nil))
2547 (goto-char (point-max)))
2548 (forward-line 1)
2549 (save-restriction
2550 (narrow-to-region (point) (point-max))
2551 (when (and (eq mail-parse-charset 'gnus-decoded)
2552 (eq (mm-body-7-or-8) '8bit))
2553 ;; The text code could have been decoded.
2554 (setq charset mail-parse-charset))
2555 (when (and (or (not ctl)
2556 (equal (car ctl) "text/plain"))
2557 (not format)) ;; article with format will decode later.
2558 (mm-decode-body
2559 charset (and cte (intern (downcase
2560 (gnus-strip-whitespace cte))))
2561 (car ctl)))))))
2563 (defun article-decode-encoded-words ()
2564 "Remove encoded-word encoding from headers."
2565 (let ((inhibit-point-motion-hooks t)
2566 (mail-parse-charset gnus-newsgroup-charset)
2567 (mail-parse-ignored-charsets
2568 (save-excursion (condition-case nil
2569 (set-buffer gnus-summary-buffer)
2570 (error))
2571 gnus-newsgroup-ignored-charsets))
2572 (inhibit-read-only t)
2573 end start)
2574 (goto-char (point-min))
2575 (when (search-forward "\n\n" nil 'move)
2576 (forward-line -1))
2577 (setq end (point))
2578 (while (not (bobp))
2579 (while (progn
2580 (forward-line -1)
2581 (and (not (bobp))
2582 (memq (char-after) '(?\t ? )))))
2583 (setq start (point))
2584 (if (looking-at "\
2585 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2586 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2587 (funcall gnus-decode-address-function start end)
2588 (funcall gnus-decode-header-function start end))
2589 (goto-char (setq end start)))))
2591 (defun article-decode-group-name ()
2592 "Decode group names in Newsgroups, Followup-To and Xref headers."
2593 (let ((inhibit-point-motion-hooks t)
2594 (inhibit-read-only t)
2595 (method (gnus-find-method-for-group gnus-newsgroup-name))
2596 regexp)
2597 (when (and (or gnus-group-name-charset-method-alist
2598 gnus-group-name-charset-group-alist)
2599 (gnus-buffer-live-p gnus-original-article-buffer))
2600 (save-restriction
2601 (article-narrow-to-head)
2602 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2603 (with-current-buffer gnus-original-article-buffer
2604 (goto-char (point-min)))
2605 (setq regexp (concat "^" header
2606 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2607 (while (re-search-forward regexp nil t)
2608 (replace-match (save-match-data
2609 (gnus-decode-newsgroups
2610 ;; XXX how to use data in article buffer?
2611 (with-current-buffer gnus-original-article-buffer
2612 (re-search-forward regexp nil t)
2613 (match-string 1))
2614 gnus-newsgroup-name method))
2615 t t nil 1))
2616 (goto-char (point-min)))))))
2618 (autoload 'idna-to-unicode "idna")
2620 (defun article-decode-idna-rhs ()
2621 "Decode IDNA strings in RHS in various headers in current buffer.
2622 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2623 Mail-Reply-To: and Mail-Followup-To:."
2624 (when gnus-use-idna
2625 (save-restriction
2626 (let ((inhibit-point-motion-hooks t)
2627 (inhibit-read-only t))
2628 (article-narrow-to-head)
2629 (goto-char (point-min))
2630 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2631 (let (ace unicode)
2632 (when (save-match-data
2633 (and (setq ace (match-string 1))
2634 (save-excursion
2635 (and (re-search-backward "^[^ \t]" nil t)
2636 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2637 (setq unicode (idna-to-unicode ace))))
2638 (unless (string= ace unicode)
2639 (replace-match unicode nil nil nil 1)))))))))
2641 (defun article-de-quoted-unreadable (&optional force read-charset)
2642 "Translate a quoted-printable-encoded article.
2643 If FORCE, decode the article whether it is marked as quoted-printable
2644 or not.
2645 If READ-CHARSET, ask for a coding system."
2646 (interactive (list 'force current-prefix-arg))
2647 (save-excursion
2648 (let ((inhibit-read-only t) type charset)
2649 (if (gnus-buffer-live-p gnus-original-article-buffer)
2650 (with-current-buffer gnus-original-article-buffer
2651 (setq type
2652 (gnus-fetch-field "content-transfer-encoding"))
2653 (let* ((ct (gnus-fetch-field "content-type"))
2654 (ctl (and ct (mail-header-parse-content-type ct))))
2655 (setq charset (and ctl
2656 (mail-content-type-get ctl 'charset)))
2657 (if (stringp charset)
2658 (setq charset (intern (downcase charset)))))))
2659 (if read-charset
2660 (setq charset (mm-read-coding-system "Charset: " charset)))
2661 (unless charset
2662 (setq charset gnus-newsgroup-charset))
2663 (when (or force
2664 (and type (let ((case-fold-search t))
2665 (string-match "quoted-printable" type))))
2666 (article-goto-body)
2667 (quoted-printable-decode-region
2668 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2670 (defun article-de-base64-unreadable (&optional force read-charset)
2671 "Translate a base64 article.
2672 If FORCE, decode the article whether it is marked as base64 not.
2673 If READ-CHARSET, ask for a coding system."
2674 (interactive (list 'force current-prefix-arg))
2675 (save-excursion
2676 (let ((inhibit-read-only t) type charset)
2677 (if (gnus-buffer-live-p gnus-original-article-buffer)
2678 (with-current-buffer gnus-original-article-buffer
2679 (setq type
2680 (gnus-fetch-field "content-transfer-encoding"))
2681 (let* ((ct (gnus-fetch-field "content-type"))
2682 (ctl (and ct (mail-header-parse-content-type ct))))
2683 (setq charset (and ctl
2684 (mail-content-type-get ctl 'charset)))
2685 (if (stringp charset)
2686 (setq charset (intern (downcase charset)))))))
2687 (if read-charset
2688 (setq charset (mm-read-coding-system "Charset: " charset)))
2689 (unless charset
2690 (setq charset gnus-newsgroup-charset))
2691 (when (or force
2692 (and type (let ((case-fold-search t))
2693 (string-match "base64" type))))
2694 (article-goto-body)
2695 (save-restriction
2696 (narrow-to-region (point) (point-max))
2697 (base64-decode-region (point-min) (point-max))
2698 (mm-decode-coding-region
2699 (point-min) (point-max)
2700 (mm-charset-to-coding-system charset nil t)))))))
2702 (eval-when-compile
2703 (require 'rfc1843))
2705 (defun article-decode-HZ ()
2706 "Translate a HZ-encoded article."
2707 (interactive)
2708 (require 'rfc1843)
2709 (save-excursion
2710 (let ((inhibit-read-only t))
2711 (rfc1843-decode-region (point-min) (point-max)))))
2713 (defun article-unsplit-urls ()
2714 "Remove the newlines that some other mailers insert into URLs."
2715 (interactive)
2716 (save-excursion
2717 (let ((inhibit-read-only t))
2718 (goto-char (point-min))
2719 (while (re-search-forward
2720 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2721 (replace-match "\\1\\3" t)))
2722 (when (gmm-called-interactively-p 'any)
2723 (gnus-treat-article nil))))
2725 (defun article-wash-html ()
2726 "Format an HTML article."
2727 (interactive)
2728 (let ((handles nil)
2729 (buffer-read-only nil))
2730 (when (gnus-buffer-live-p gnus-original-article-buffer)
2731 (with-current-buffer gnus-original-article-buffer
2732 (setq handles (mm-dissect-buffer t t))))
2733 (article-goto-body)
2734 (delete-region (point) (point-max))
2735 (mm-enable-multibyte)
2736 (mm-inline-text-html handles)))
2738 (defvar gnus-article-browse-html-temp-list nil
2739 "List of temporary files created by `gnus-article-browse-html-parts'.
2740 Internal variable.")
2742 (defcustom gnus-article-browse-delete-temp 'ask
2743 "What to do with temporary files from `gnus-article-browse-html-parts'.
2744 If nil, don't delete temporary files. If it is t, delete them on
2745 exit from the summary buffer. If it is the symbol `file', query
2746 on each file, if it is `ask' ask once when exiting from the
2747 summary buffer."
2748 :group 'gnus-article
2749 :version "23.1" ;; No Gnus
2750 :type '(choice (const :tag "Don't delete" nil)
2751 (const :tag "Don't ask" t)
2752 (const :tag "Ask" ask)
2753 (const :tag "Ask for each file" file)))
2755 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2757 (defun gnus-article-browse-delete-temp-files (&optional how)
2758 "Delete temp-files created by `gnus-article-browse-html-parts'."
2759 (when (and gnus-article-browse-html-temp-list
2760 (progn
2761 (or how (setq how gnus-article-browse-delete-temp))
2762 (if (eq how 'ask)
2763 (let ((files (length gnus-article-browse-html-temp-list)))
2764 (or (gnus-y-or-n-p
2765 (if (= files 1)
2766 "Delete the temporary HTML file? "
2767 (format "Delete all %s temporary HTML files? "
2768 files)))
2769 (setq gnus-article-browse-html-temp-list nil)))
2770 how)))
2771 (dolist (file gnus-article-browse-html-temp-list)
2772 (cond ((file-directory-p file)
2773 (when (or (not (eq how 'file))
2774 (gnus-y-or-n-p
2775 (gnus-format-message
2776 "Delete temporary HTML file(s) in directory `%s'? "
2777 (file-name-as-directory file))))
2778 (gnus-delete-directory file)))
2779 ((file-exists-p file)
2780 (when (or (not (eq how 'file))
2781 (gnus-y-or-n-p
2782 (format "Delete temporary HTML file `%s'? " file)))
2783 (delete-file file)))))
2784 ;; Also remove file from the list when not deleted or if file doesn't
2785 ;; exist anymore.
2786 (setq gnus-article-browse-html-temp-list nil))
2787 gnus-article-browse-html-temp-list)
2789 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2790 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2791 Return file name relative to the parent of DIRECTORY."
2792 (save-match-data
2793 (let (file afile)
2794 (catch 'found
2795 (dolist (handle handles)
2796 (cond
2797 ((not (listp handle)))
2798 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2799 ;; may create.
2800 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2801 ((equal (mm-handle-media-supertype handle) "multipart")
2802 (when (setq file (gnus-article-browse-html-save-cid-content
2803 cid handle directory))
2804 (throw 'found file)))
2805 ((equal (concat "<" cid ">") (mm-handle-id handle))
2806 (setq file (or (mm-handle-filename handle)
2807 (concat
2808 (make-temp-name "cid")
2809 (car (rassoc (car (mm-handle-type handle))
2810 mailcap-mime-extensions))))
2811 afile (expand-file-name file directory))
2812 (mm-save-part-to-file handle afile)
2813 (throw 'found (concat (file-name-nondirectory
2814 (directory-file-name directory))
2815 "/" file)))))))))
2817 (defun gnus-article-browse-html-parts (list &optional header)
2818 "View all \"text/html\" parts from LIST.
2819 Recurse into multiparts. The optional HEADER that should be a decoded
2820 message header will be added to the bodies of the \"text/html\" parts."
2821 ;; Internal function used by `gnus-article-browse-html-article'.
2822 (let (type file charset content cid-dir tmp-file showed)
2823 ;; Find and show the html-parts.
2824 (dolist (handle list)
2825 ;; If HTML, show it:
2826 (cond ((not (listp handle)))
2827 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2828 (and (equal (car type) "message/external-body")
2829 (or header
2830 (setq file (mm-handle-filename handle)))
2831 (or (mm-handle-cache handle)
2832 (condition-case code
2833 (progn (mm-extern-cache-contents handle) t)
2834 (error
2835 (gnus-message 3 "%s" (error-message-string code))
2836 (when (>= gnus-verbose 3) (sit-for 2))
2837 nil)))
2838 (progn
2839 (setq handle (mm-handle-cache handle)
2840 type (mm-handle-type handle))
2841 (equal (car type) "text/html"))))
2842 (setq charset (mail-content-type-get type 'charset)
2843 content (mm-get-part handle))
2844 (with-temp-buffer
2845 (if (eq charset 'gnus-decoded)
2846 (mm-enable-multibyte)
2847 (mm-disable-multibyte))
2848 (insert content)
2849 ;; resolve cid contents
2850 (let ((case-fold-search t)
2851 st base regexp cid-file)
2852 (goto-char (point-min))
2853 (when (and (re-search-forward "<head[\t\n >]" nil t)
2854 (progn
2855 (setq st (match-end 0))
2856 (re-search-forward "</head[\t\n >]" nil t))
2857 (re-search-backward "<base\
2858 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2859 (setq base (match-string 1))
2860 (replace-match "<!--\\&-->")
2861 (setq st (point))
2862 (dolist (tag '(("a" . "href") ("form" . "action")
2863 ("img" . "src")))
2864 (setq regexp (concat "<" (car tag)
2865 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2866 (cdr tag) "=\"\\([^\"]+\\)"))
2867 (while (re-search-forward regexp nil t)
2868 (insert (prog1
2869 (condition-case nil
2870 (save-match-data
2871 (url-expand-file-name (match-string 1)
2872 base))
2873 (error (match-string 1)))
2874 (delete-region (match-beginning 1)
2875 (match-end 1)))))
2876 (goto-char st)))
2877 (while (re-search-forward "\
2878 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2879 nil t)
2880 (unless cid-dir
2881 (setq cid-dir (mm-make-temp-file "cid" t))
2882 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2883 (setq file nil
2884 content nil)
2885 (when (setq cid-file
2886 (gnus-article-browse-html-save-cid-content
2887 (match-string 2)
2888 (with-current-buffer gnus-article-buffer
2889 gnus-article-mime-handles)
2890 cid-dir))
2891 (replace-match cid-file nil nil nil 1))))
2892 (unless content (setq content (buffer-string))))
2893 (when (or charset header (not file))
2894 (setq tmp-file (mm-make-temp-file
2895 ;; Do we need to care for 8.3 filenames?
2896 "mm-" nil ".html")))
2897 ;; Add a meta html tag to specify charset and a header.
2898 (cond
2899 (header
2900 (let (title eheader body hcharset coding)
2901 (with-temp-buffer
2902 (mm-enable-multibyte)
2903 (setq case-fold-search t)
2904 (insert header "\n")
2905 (setq title (message-fetch-field "subject"))
2906 (goto-char (point-min))
2907 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2908 nil t)
2909 (replace-match (cond ((match-beginning 1) "&lt;")
2910 ((match-beginning 2) "&gt;")
2911 ((match-beginning 3) "&amp;")
2912 (t "<br>\n"))))
2913 (goto-char (point-min))
2914 (while (re-search-forward "^[\t ]+" nil t)
2915 (dotimes (i (prog1
2916 (current-column)
2917 (delete-region (match-beginning 0)
2918 (match-end 0))))
2919 (insert "&nbsp;")))
2920 (goto-char (point-min))
2921 (insert "<div align=\"left\">\n")
2922 (goto-char (point-max))
2923 (insert "</div>\n<hr>\n")
2924 ;; We have to examine charset one by one since
2925 ;; charset specified in parts might be different.
2926 (if (eq charset 'gnus-decoded)
2927 (setq charset 'utf-8
2928 eheader (mm-encode-coding-string (buffer-string)
2929 charset)
2930 title (when title
2931 (mm-encode-coding-string title charset))
2932 body (mm-encode-coding-string content charset))
2933 (setq hcharset (mm-find-mime-charset-region (point-min)
2934 (point-max)))
2935 (cond ((= (length hcharset) 1)
2936 (setq hcharset (car hcharset)
2937 coding (mm-charset-to-coding-system
2938 hcharset nil t)))
2939 ((> (length hcharset) 1)
2940 (setq hcharset 'utf-8
2941 coding hcharset)))
2942 (if coding
2943 (if charset
2944 (progn
2945 (setq body
2946 (mm-charset-to-coding-system charset
2947 nil t))
2948 (if (eq coding body)
2949 (setq eheader (mm-encode-coding-string
2950 (buffer-string) coding)
2951 title (when title
2952 (mm-encode-coding-string
2953 title coding))
2954 body content)
2955 (setq charset 'utf-8
2956 eheader (mm-encode-coding-string
2957 (buffer-string) charset)
2958 title (when title
2959 (mm-encode-coding-string
2960 title charset))
2961 body (mm-encode-coding-string
2962 (mm-decode-coding-string
2963 content body)
2964 charset))))
2965 (setq charset hcharset
2966 eheader (mm-encode-coding-string
2967 (buffer-string) coding)
2968 title (when title
2969 (mm-encode-coding-string
2970 title coding))
2971 body content))
2972 (setq eheader (mm-string-as-unibyte (buffer-string))
2973 body content)))
2974 (erase-buffer)
2975 (mm-disable-multibyte)
2976 (insert body)
2977 (when charset
2978 (mm-add-meta-html-tag handle charset t))
2979 (when title
2980 (goto-char (point-min))
2981 (unless (search-forward "<title>" nil t)
2982 (re-search-forward "<head>\\s-*" nil t)
2983 (insert "<title>" title "</title>\n")))
2984 (goto-char (point-min))
2985 (or (re-search-forward
2986 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2987 (re-search-forward
2988 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2989 (insert eheader)
2990 (mm-write-region (point-min) (point-max)
2991 tmp-file nil nil nil 'binary t))))
2992 (charset
2993 (mm-with-unibyte-buffer
2994 (insert (if (eq charset 'gnus-decoded)
2995 (mm-encode-coding-string content
2996 (setq charset 'utf-8))
2997 content))
2998 (if (or (mm-add-meta-html-tag handle charset)
2999 (not file))
3000 (mm-write-region (point-min) (point-max)
3001 tmp-file nil nil nil 'binary t)
3002 (setq tmp-file nil))))
3003 (tmp-file
3004 (mm-save-part-to-file handle tmp-file)))
3005 (when tmp-file
3006 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3007 (add-hook 'gnus-summary-prepare-exit-hook
3008 'gnus-article-browse-delete-temp-files)
3009 (add-hook 'gnus-exit-gnus-hook
3010 (lambda ()
3011 (gnus-article-browse-delete-temp-files t)))
3012 ;; FIXME: Warn if there's an <img> tag?
3013 (browse-url-of-file (or tmp-file (expand-file-name file)))
3014 (setq showed t))
3015 ;; If multipart, recurse
3016 ((equal (mm-handle-media-supertype handle) "multipart")
3017 (when (gnus-article-browse-html-parts handle header)
3018 (setq showed t)))
3019 ((equal (mm-handle-media-type handle) "message/rfc822")
3020 (mm-with-multibyte-buffer
3021 (mm-insert-part handle)
3022 (setq handle (mm-dissect-buffer t t))
3023 (when (and (bufferp (car handle))
3024 (stringp (car (mm-handle-type handle))))
3025 (setq handle (list handle)))
3026 (when header
3027 (article-decode-encoded-words)
3028 (let ((gnus-visible-headers
3029 (or (get 'gnus-visible-headers 'standard-value)
3030 gnus-visible-headers)))
3031 (article-hide-headers))
3032 (goto-char (point-min))
3033 (search-forward "\n\n" nil 'move)
3034 (skip-chars-backward "\t\n ")
3035 (setq header (buffer-substring (point-min) (point)))))
3036 (when (prog1
3037 (gnus-article-browse-html-parts handle header)
3038 (mm-destroy-parts handle))
3039 (setq showed t)))))
3040 showed))
3042 (defun gnus-article-browse-html-article (&optional arg)
3043 "View \"text/html\" parts of the current article with a WWW browser.
3044 Inline images embedded in a message using the cid scheme, as they are
3045 generally considered to be safe, will be processed properly.
3046 The message header is added to the beginning of every html part unless
3047 the prefix argument ARG is given.
3049 Warning: Spammers use links to images (using the http scheme) in HTML
3050 articles to verify whether you have read the message. As
3051 `gnus-article-browse-html-article' passes the HTML content to the
3052 browser without eliminating these \"web bugs\" you should only
3053 use it for mails from trusted senders.
3055 If you always want to display HTML parts in the browser, set
3056 `mm-text-html-renderer' to nil.
3058 This command creates temporary files to pass HTML contents including
3059 images if any to the browser, and deletes them when exiting the group
3060 \(if you want)."
3061 ;; Cf. `mm-w3m-safe-url-regexp'
3062 (interactive "P")
3063 (if arg
3064 (gnus-summary-show-article)
3065 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3066 gnus-visible-headers))
3067 ;; As we insert a <hr>, there's no need for the body boundary.
3068 (gnus-treat-body-boundary nil))
3069 (gnus-summary-show-article)))
3070 (with-current-buffer gnus-article-buffer
3071 (let ((header (unless arg
3072 (save-restriction
3073 (widen)
3074 (buffer-substring-no-properties
3075 (goto-char (point-min))
3076 (if (search-forward "\n\n" nil t)
3077 (match-beginning 0)
3078 (goto-char (point-max))
3079 (skip-chars-backward "\t\n ")
3080 (point))))))
3081 parts)
3082 (set-buffer gnus-original-article-buffer)
3083 (setq parts (mm-dissect-buffer t t))
3084 ;; If singlepart, enforce a list.
3085 (when (and (bufferp (car parts))
3086 (stringp (car (mm-handle-type parts))))
3087 (setq parts (list parts)))
3088 ;; Process the list
3089 (unless (gnus-article-browse-html-parts parts header)
3090 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3091 (mm-destroy-parts parts)
3092 (unless arg
3093 (gnus-summary-show-article)))))
3095 (defun article-hide-list-identifiers ()
3096 "Remove list identifiers from the Subject header.
3097 The `gnus-list-identifiers' variable specifies what to do."
3098 (interactive)
3099 (let ((inhibit-point-motion-hooks t)
3100 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3101 (inhibit-read-only t))
3102 (when regexp
3103 (save-excursion
3104 (save-restriction
3105 (article-narrow-to-head)
3106 (goto-char (point-min))
3107 (while (re-search-forward
3108 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3109 nil t)
3110 (delete-region (match-beginning 2) (match-end 0))
3111 (beginning-of-line))
3112 (when (re-search-forward
3113 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3114 (delete-region (match-beginning 1) (match-end 1))))))))
3116 (defun article-hide-pem (&optional arg)
3117 "Toggle hiding of any PEM headers and signatures in the current article.
3118 If given a negative prefix, always show; if given a positive prefix,
3119 always hide."
3120 (interactive (gnus-article-hidden-arg))
3121 (unless (gnus-article-check-hidden-text 'pem arg)
3122 (save-excursion
3123 (let ((inhibit-read-only t) end)
3124 (goto-char (point-min))
3125 ;; Hide the horrendously ugly "header".
3126 (when (and (search-forward
3127 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3128 nil t)
3129 (setq end (1+ (match-beginning 0))))
3130 (gnus-add-wash-type 'pem)
3131 (gnus-article-hide-text-type
3133 (if (search-forward "\n\n" nil t)
3134 (match-end 0)
3135 (point-max))
3136 'pem)
3137 ;; Hide the trailer as well
3138 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3139 nil t)
3140 (gnus-article-hide-text-type
3141 (match-beginning 0) (match-end 0) 'pem)))))))
3143 (defun article-strip-banner ()
3144 "Strip the banners specified by the `banner' group parameter and by
3145 `gnus-article-address-banner-alist'."
3146 (interactive)
3147 (save-excursion
3148 (save-restriction
3149 (let ((inhibit-point-motion-hooks t))
3150 (when (gnus-parameter-banner gnus-newsgroup-name)
3151 (article-really-strip-banner
3152 (gnus-parameter-banner gnus-newsgroup-name)))
3153 (when gnus-article-address-banner-alist
3154 ;; Note that the From header is decoded here, so it is
3155 ;; required that the *-extract-address-components function
3156 ;; supports non-ASCII text.
3157 (let ((from (save-restriction
3158 (widen)
3159 (article-narrow-to-head)
3160 (mail-fetch-field "from"))))
3161 (when (and from
3162 (setq from
3163 (cadr (funcall gnus-extract-address-components
3164 from))))
3165 (catch 'found
3166 (dolist (pair gnus-article-address-banner-alist)
3167 (when (string-match (car pair) from)
3168 (throw 'found
3169 (article-really-strip-banner (cdr pair)))))))))))))
3171 (defun article-really-strip-banner (banner)
3172 "Strip the banner specified by the argument."
3173 (save-excursion
3174 (save-restriction
3175 (let ((inhibit-point-motion-hooks t)
3176 (gnus-signature-limit nil)
3177 (inhibit-read-only t))
3178 (article-goto-body)
3179 (cond
3180 ((eq banner 'signature)
3181 (when (gnus-article-narrow-to-signature)
3182 (widen)
3183 (forward-line -1)
3184 (delete-region (point) (point-max))))
3185 ((symbolp banner)
3186 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3187 (while (re-search-forward banner nil t)
3188 (delete-region (match-beginning 0) (match-end 0)))))
3189 ((stringp banner)
3190 (while (re-search-forward banner nil t)
3191 (delete-region (match-beginning 0) (match-end 0)))))))))
3193 (defun article-babel ()
3194 "Translate article using an online translation service."
3195 (interactive)
3196 (require 'babel)
3197 (gnus-with-article-buffer
3198 (when (article-goto-body)
3199 (let* ((start (point))
3200 (end (point-max))
3201 (orig (buffer-substring start end))
3202 (trans (babel-as-string orig)))
3203 (save-restriction
3204 (narrow-to-region start end)
3205 (delete-region start end)
3206 (insert trans))))))
3208 (defun article-hide-signature (&optional arg)
3209 "Hide the signature in the current article.
3210 If given a negative prefix, always show; if given a positive prefix,
3211 always hide."
3212 (interactive (gnus-article-hidden-arg))
3213 (unless (gnus-article-check-hidden-text 'signature arg)
3214 (save-excursion
3215 (save-restriction
3216 (let ((inhibit-read-only t))
3217 (when (gnus-article-narrow-to-signature)
3218 (gnus-article-hide-text-type
3219 (point-min) (point-max) 'signature))))))
3220 (gnus-set-mode-line 'article))
3222 (defun article-strip-headers-in-body ()
3223 "Strip offensive headers from bodies."
3224 (interactive)
3225 (save-excursion
3226 (article-goto-body)
3227 (let ((case-fold-search t))
3228 (when (looking-at "x-no-archive:")
3229 (gnus-delete-line)))))
3231 (defun article-strip-leading-blank-lines ()
3232 "Remove all blank lines from the beginning of the article."
3233 (interactive)
3234 (save-excursion
3235 (let ((inhibit-point-motion-hooks t)
3236 (inhibit-read-only t))
3237 (when (article-goto-body)
3238 (while (and (not (eobp))
3239 (looking-at "[ \t]*$"))
3240 (gnus-delete-line))))))
3242 (defun article-narrow-to-head ()
3243 "Narrow the buffer to the head of the message.
3244 Point is left at the beginning of the narrowed-to region."
3245 (narrow-to-region
3246 (goto-char (point-min))
3247 (cond
3248 ;; Absolutely no headers displayed.
3249 ((looking-at "\n")
3250 (point))
3251 ;; Normal headers.
3252 ((search-forward "\n\n" nil 1)
3253 (1- (point)))
3254 ;; Nothing but headers.
3256 (point-max))))
3257 (goto-char (point-min)))
3259 (defun article-goto-body ()
3260 "Place point at the start of the body."
3261 (goto-char (point-min))
3262 (cond
3263 ;; This variable is only bound when dealing with separate
3264 ;; MIME body parts.
3265 (article-goto-body-goes-to-point-min-p
3267 ((search-forward "\n\n" nil t)
3270 (goto-char (point-max))
3271 nil)))
3273 (defun article-strip-multiple-blank-lines ()
3274 "Replace consecutive blank lines with one empty line."
3275 (interactive)
3276 (save-excursion
3277 (let ((inhibit-point-motion-hooks t)
3278 (inhibit-read-only t))
3279 ;; First make all blank lines empty.
3280 (article-goto-body)
3281 (while (re-search-forward "^[ \t]+$" nil t)
3282 (unless (gnus-annotation-in-region-p
3283 (match-beginning 0) (match-end 0))
3284 (replace-match "" nil t)))
3285 ;; Then replace multiple empty lines with a single empty line.
3286 (article-goto-body)
3287 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3288 (unless (gnus-annotation-in-region-p
3289 (match-beginning 0) (match-end 0))
3290 (delete-region (match-beginning 1) (match-end 1)))))))
3292 (defun article-strip-leading-space ()
3293 "Remove all white space from the beginning of the lines in the article."
3294 (interactive)
3295 (save-excursion
3296 (let ((inhibit-point-motion-hooks t)
3297 (inhibit-read-only t))
3298 (article-goto-body)
3299 (while (re-search-forward "^[ \t]+" nil t)
3300 (replace-match "" t t)))))
3302 (defun article-strip-trailing-space ()
3303 "Remove all white space from the end of the lines in the article."
3304 (interactive)
3305 (save-excursion
3306 (let ((inhibit-point-motion-hooks t)
3307 (inhibit-read-only t))
3308 (article-goto-body)
3309 (while (re-search-forward "[ \t]+$" nil t)
3310 (replace-match "" t t)))))
3312 (defun article-strip-blank-lines ()
3313 "Strip leading, trailing and multiple blank lines."
3314 (interactive)
3315 (article-strip-leading-blank-lines)
3316 (article-remove-trailing-blank-lines)
3317 (article-strip-multiple-blank-lines))
3319 (defun article-strip-all-blank-lines ()
3320 "Strip all blank lines."
3321 (interactive)
3322 (save-excursion
3323 (let ((inhibit-point-motion-hooks t)
3324 (inhibit-read-only t))
3325 (article-goto-body)
3326 (while (re-search-forward "^[ \t]*\n" nil t)
3327 (replace-match "" t t)))))
3329 (defun gnus-article-narrow-to-signature ()
3330 "Narrow to the signature; return t if a signature is found, else nil."
3331 (let ((inhibit-point-motion-hooks t))
3332 (when (gnus-article-search-signature)
3333 (forward-line 1)
3334 ;; Check whether we have some limits to what we consider
3335 ;; to be a signature.
3336 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3337 (list gnus-signature-limit)))
3338 limit limited)
3339 (while (setq limit (pop limits))
3340 (if (or (and (integerp limit)
3341 (< (- (point-max) (point)) limit))
3342 (and (floatp limit)
3343 (< (count-lines (point) (point-max)) limit))
3344 (and (functionp limit)
3345 (funcall limit))
3346 (and (stringp limit)
3347 (not (re-search-forward limit nil t))))
3348 () ; This limit did not succeed.
3349 (setq limited t
3350 limits nil)))
3351 (unless limited
3352 (narrow-to-region (point) (point-max))
3353 t)))))
3355 (defun gnus-article-search-signature ()
3356 "Search the current buffer for the signature separator.
3357 Put point at the beginning of the signature separator."
3358 (let ((cur (point)))
3359 (goto-char (point-max))
3360 (if (if (stringp gnus-signature-separator)
3361 (re-search-backward gnus-signature-separator nil t)
3362 (let ((seps gnus-signature-separator))
3363 (while (and seps
3364 (not (re-search-backward (car seps) nil t)))
3365 (pop seps))
3366 seps))
3368 (goto-char cur)
3369 nil)))
3371 (defun gnus-article-hidden-arg ()
3372 "Return the current prefix arg as a number, or 0 if no prefix."
3373 (list (if current-prefix-arg
3374 (prefix-numeric-value current-prefix-arg)
3375 0)))
3377 (defun gnus-article-check-hidden-text (type arg)
3378 "Return nil if hiding is necessary.
3379 Arg can be nil or a number. nil and positive means hide, negative
3380 means show, 0 means toggle."
3381 (save-excursion
3382 (save-restriction
3383 (let ((hide (gnus-article-hidden-text-p type)))
3384 (cond
3385 ((or (null arg)
3386 (> arg 0))
3387 nil)
3388 ((< arg 0)
3389 (gnus-article-show-hidden-text type)
3392 (if (eq hide 'hidden)
3393 (progn
3394 (gnus-article-show-hidden-text type)
3396 nil)))))))
3398 (defun gnus-article-hidden-text-p (type)
3399 "Say whether the current buffer contains hidden text of type TYPE."
3400 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3401 (while (and pos
3402 (not (get-text-property pos 'invisible))
3403 (not (get-text-property pos 'dummy-invisible)))
3404 (setq pos
3405 (text-property-any (1+ pos) (point-max) 'article-type type)))
3406 (if pos
3407 'hidden
3408 nil)))
3410 (defun gnus-article-show-hidden-text (type &optional _dummy)
3411 "Show all hidden text of type TYPE.
3412 Originally it is hide instead of DUMMY."
3413 (let ((inhibit-read-only t)
3414 (inhibit-point-motion-hooks t))
3415 (gnus-remove-text-properties-when
3416 'article-type type
3417 (point-min) (point-max)
3418 (cons 'article-type (cons type
3419 gnus-hidden-properties)))
3420 (gnus-delete-wash-type type)))
3422 (defconst article-time-units
3423 `((year . ,(* 365.25 24 60 60))
3424 (week . ,(* 7 24 60 60))
3425 (day . ,(* 24 60 60))
3426 (hour . ,(* 60 60))
3427 (minute . 60)
3428 (second . 1))
3429 "Mapping from time units to seconds.")
3431 (defun gnus-article-forward-header ()
3432 "Move point to the start of the next header.
3433 If the current header is a continuation header, this can be several
3434 lines forward."
3435 (let ((ended nil))
3436 (while (not ended)
3437 (forward-line 1)
3438 (if (looking-at "[ \t]+[^ \t]")
3439 (forward-line 1)
3440 (setq ended t)))))
3442 (defun article-treat-date ()
3443 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3444 (with-current-buffer gnus-summary-buffer
3445 gnus-article-date-headers)
3446 gnus-article-date-headers)
3449 (defun article-date-ut (&optional type _highlight date-position)
3450 "Convert DATE date to TYPE in the current article.
3451 The default type is `ut'. See `gnus-article-date-headers' for
3452 possible values."
3453 (interactive (list 'ut t))
3454 (let* ((case-fold-search t)
3455 (inhibit-read-only t)
3456 (inhibit-point-motion-hooks t)
3457 (visible-date (mail-fetch-field "Date"))
3458 pos date bface eface)
3459 (save-excursion
3460 (if date-position
3461 (progn
3462 (goto-char date-position)
3463 (setq date (get-text-property (point) 'original-date))
3464 (when (looking-at "[^:]+:[\t ]*")
3465 (setq bface (get-text-property (match-beginning 0) 'face)
3466 eface (get-text-property (match-end 0) 'face)))
3467 (delete-region (point)
3468 (progn
3469 (gnus-article-forward-header)
3470 (point)))
3471 (article-transform-date date type bface eface))
3472 (save-restriction
3473 (widen)
3474 (goto-char (point-min))
3475 (while (or (get-text-property (setq pos (point)) 'original-date)
3476 (and (setq pos (next-single-property-change
3477 (point) 'original-date))
3478 (goto-char pos)))
3479 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3480 (1+ (match-beginning 0))
3481 (point-max)))
3482 (while (setq pos (text-property-not-all pos (point-max)
3483 'gnus-date-type nil))
3484 (setq date (get-text-property pos 'original-date))
3485 (goto-char pos)
3486 (when (looking-at "[^:]+:[\t ]*")
3487 (setq bface (get-text-property (match-beginning 0) 'face)
3488 eface (get-text-property (match-end 0) 'face)))
3489 (delete-region pos (or (text-property-any pos (point-max)
3490 'gnus-date-type nil)
3491 (point-max))))
3492 (unless date ;; the 1st time
3493 (goto-char (point-min))
3494 (while (re-search-forward "^Date:[\t ]*" nil t)
3495 (setq date (get-text-property (match-beginning 0)
3496 'original-date)
3497 bface (get-text-property (match-beginning 0) 'face)
3498 eface (get-text-property (match-end 0) 'face))
3499 (delete-region (point-at-bol) (progn
3500 (gnus-article-forward-header)
3501 (point)))))
3502 (when (and (not date)
3503 visible-date)
3504 (setq date visible-date))
3505 (when date
3506 (article-transform-date date type bface eface))
3507 (goto-char (point-max))
3508 (widen)))))))
3510 (defun article-transform-date (date type bface eface)
3511 (dolist (this-type (cond
3512 ((null type)
3513 (list 'ut))
3514 ((atom type)
3515 (list type))
3517 type)))
3518 (goto-char
3519 (prog1
3520 (point)
3521 (add-text-properties
3522 (point)
3523 (progn
3524 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3525 (point))
3526 (list 'original-date date 'gnus-date-type this-type))))
3527 ;; Do highlighting.
3528 (when (looking-at
3529 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3530 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3531 (when (match-beginning 2)
3532 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3533 (while (and (zerop (forward-line 1))
3534 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3535 (when (match-beginning 1)
3536 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3538 (defun article-make-date-line (date type)
3539 "Return a DATE line of TYPE."
3540 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3541 combined-lapsed))
3542 (error "Unknown conversion type: %s" type))
3543 (condition-case ()
3544 (let ((time (ignore-errors (date-to-time date))))
3545 (cond
3546 ;; Convert to the local timezone.
3547 ((eq type 'local)
3548 (concat "Date: " (message-make-date time)))
3549 ;; Convert to Universal Time.
3550 ((eq type 'ut)
3551 (concat "Date: "
3552 (substring
3553 (message-make-date
3554 (let* ((e (parse-time-string date))
3555 (tm (apply 'encode-time e))
3556 (ms (car tm))
3557 (ls (- (cadr tm) (car (current-time-zone time)))))
3558 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3559 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3560 (t (list ms ls)))))
3561 0 -5)
3562 "UT"))
3563 ;; Get the original date from the article.
3564 ((eq type 'original)
3565 (concat "Date: " (if (string-match "\n+$" date)
3566 (substring date 0 (match-beginning 0))
3567 date)))
3568 ;; Let the user define the format.
3569 ((eq type 'user-defined)
3570 (let ((format (or (condition-case nil
3571 (with-current-buffer gnus-summary-buffer
3572 gnus-article-time-format)
3573 (error nil))
3574 gnus-article-time-format)))
3575 (if (functionp format)
3576 (funcall format time)
3577 (concat "Date: " (format-time-string format time)))))
3578 ;; ISO 8601.
3579 ((eq type 'iso8601)
3580 (let ((tz (car (current-time-zone time))))
3581 (concat
3582 "Date: "
3583 (format-time-string "%Y%m%dT%H%M%S" time)
3584 (format "%s%02d%02d"
3585 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3586 (/ (% (abs tz) 3600) 60)))))
3587 ;; Do a lapsed format.
3588 ((eq type 'lapsed)
3589 (concat "Date: " (article-lapsed-string time)))
3590 ;; A combined date/lapsed format.
3591 ((eq type 'combined-lapsed)
3592 (let ((date-string (article-make-date-line date 'original))
3593 (segments 3)
3594 lapsed-string)
3595 (while (and
3596 time
3597 (setq lapsed-string
3598 (concat " (" (article-lapsed-string time segments) ")"))
3599 (> (+ (length date-string)
3600 (length lapsed-string))
3601 (+ fill-column 6))
3602 (> segments 0))
3603 (setq segments (1- segments)))
3604 (if (> segments 0)
3605 (concat date-string lapsed-string)
3606 date-string)))
3607 ;; Display the date in proper English
3608 ((eq type 'english)
3609 (let ((dtime (decode-time time)))
3610 (concat
3611 "Date: the "
3612 (number-to-string (nth 3 dtime))
3613 (let ((digit (% (nth 3 dtime) 10)))
3614 (cond
3615 ((memq (nth 3 dtime) '(11 12 13)) "th")
3616 ((= digit 1) "st")
3617 ((= digit 2) "nd")
3618 ((= digit 3) "rd")
3619 (t "th")))
3620 " of "
3621 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3623 (number-to-string (nth 5 dtime))
3624 " at "
3625 (format "%02d" (nth 2 dtime))
3627 (format "%02d" (nth 1 dtime)))))))
3628 (foo
3629 (format "Date: %s (from Gnus)" date))))
3631 (defun article-lapsed-string (time &optional max-segments)
3632 ;; If the date is seriously mangled, the timezone functions are
3633 ;; liable to bug out, so we ignore all errors.
3634 (let* ((now (current-time))
3635 (real-time (subtract-time now time))
3636 (real-sec (and real-time
3637 (+ (* (float (car real-time)) 65536)
3638 (cadr real-time))))
3639 (sec (and real-time (abs real-sec)))
3640 (segments 0)
3641 num prev)
3642 (unless max-segments
3643 (setq max-segments (length article-time-units)))
3644 (cond
3645 ((null real-time)
3646 "Unknown")
3647 ((zerop sec)
3648 "Now")
3650 (concat
3651 ;; This is a bit convoluted, but basically we go
3652 ;; through the time units for years, weeks, etc,
3653 ;; and divide things to see whether that results
3654 ;; in positive answers.
3655 (mapconcat
3656 (lambda (unit)
3657 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3658 (>= segments max-segments))
3659 ;; The (remaining) seconds are too few to
3660 ;; be divided into this time unit.
3662 ;; It's big enough, so we output it.
3663 (setq sec (- sec (* num (cdr unit))))
3664 (prog1
3665 (concat (if prev ", " "") (int-to-string
3666 (floor num))
3667 " " (symbol-name (car unit))
3668 (if (> num 1) "s" ""))
3669 (setq prev t
3670 segments (1+ segments)))))
3671 article-time-units "")
3672 ;; If dates are odd, then it might appear like the
3673 ;; article was sent in the future.
3674 (if (> real-sec 0)
3675 " ago"
3676 " in the future"))))))
3678 (defun article-date-local (&optional highlight)
3679 "Convert the current article date to the local timezone."
3680 (interactive (list t))
3681 (article-date-ut 'local highlight))
3683 (defun article-date-english (&optional highlight)
3684 "Convert the current article date to something that is proper English."
3685 (interactive (list t))
3686 (article-date-ut 'english highlight))
3688 (defun article-date-original (&optional highlight)
3689 "Convert the current article date to what it was originally.
3690 This is only useful if you have used some other date conversion
3691 function and want to see what the date was before converting."
3692 (interactive (list t))
3693 (article-date-ut 'original highlight))
3695 (defun article-date-lapsed (&optional highlight)
3696 "Convert the current article date to time lapsed since it was sent."
3697 (interactive (list t))
3698 (article-date-ut 'lapsed highlight))
3700 (defun article-date-combined-lapsed (&optional highlight)
3701 "Convert the current article date to time lapsed since it was sent."
3702 (interactive (list t))
3703 (article-date-ut 'combined-lapsed highlight))
3705 (defun article-update-date-lapsed ()
3706 "Function to be run from a timer to update the lapsed time line."
3707 (save-match-data
3708 (let ((buffer (current-buffer)))
3709 (ignore-errors
3710 (walk-windows
3711 (lambda (w)
3712 (set-buffer (window-buffer w))
3713 (when (derived-mode-p 'gnus-article-mode)
3714 (let ((old-line (count-lines (point-min) (point)))
3715 (old-column (- (point) (line-beginning-position)))
3716 (window-start (window-start w))
3717 (pos (point-min))
3718 type next end)
3719 (while (setq pos (text-property-not-all pos (point-max)
3720 'gnus-date-type nil))
3721 (setq next (or (next-single-property-change pos
3722 'gnus-date-type)
3723 (point-max)))
3724 (setq type (get-text-property pos 'gnus-date-type))
3725 (when (memq type '(lapsed combined-lapsed user-defined))
3726 (article-date-ut type t pos)
3727 (setq end (or (next-single-property-change pos
3728 'gnus-date-type)
3729 (point-max)))
3730 (when window-start
3731 (if (/= window-start next)
3732 (setq window-start nil)
3733 (set-window-start w end)))
3734 (setq next end))
3735 (setq pos next))
3736 (goto-char (point-min))
3737 (when (> old-column 0)
3738 (setq old-line (1- old-line)))
3739 (forward-line old-line)
3740 (end-of-line)
3741 (when (> (current-column) old-column)
3742 (beginning-of-line)
3743 (forward-char old-column)))))
3744 nil 'visible))
3745 (set-buffer buffer))))
3747 (defun gnus-start-date-timer (&optional n)
3748 "Start a timer to update the Date headers in the article buffers.
3749 The numerical prefix says how frequently (in seconds) the function
3750 is to run."
3751 (interactive "p")
3752 (unless n
3753 (setq n 1))
3754 (gnus-stop-date-timer)
3755 (setq article-lapsed-timer
3756 (run-at-time 1 n 'article-update-date-lapsed)))
3758 (defun gnus-stop-date-timer ()
3759 "Stop the Date timer."
3760 (interactive)
3761 (when article-lapsed-timer
3762 (nnheader-cancel-timer article-lapsed-timer)
3763 (setq article-lapsed-timer nil)))
3765 (defun article-date-user (&optional highlight)
3766 "Convert the current article date to the user-defined format.
3767 This format is defined by the `gnus-article-time-format' variable."
3768 (interactive (list t))
3769 (article-date-ut 'user highlight))
3771 (defun article-date-iso8601 (&optional highlight)
3772 "Convert the current article date to ISO8601."
3773 (interactive (list t))
3774 (article-date-ut 'iso8601 highlight))
3776 (defmacro gnus-article-save-original-date (&rest forms)
3777 "Save the original date as a text property and evaluate FORMS."
3778 `(let* ((case-fold-search t)
3779 (start (progn
3780 (goto-char (point-min))
3781 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3782 (not (bolp)))
3783 (match-end 0))))
3784 (date (when (and start
3785 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3786 nil t))
3787 (buffer-substring-no-properties start
3788 (match-beginning 0)))))
3789 (goto-char (point-max))
3790 (skip-chars-backward "\n")
3791 (put-text-property (point-min) (point) 'original-date date)
3792 ,@forms
3793 (goto-char (point-max))
3794 (skip-chars-backward "\n")
3795 (put-text-property (point-min) (point) 'original-date date)))
3797 ;; (defun article-show-all ()
3798 ;; "Show all hidden text in the article buffer."
3799 ;; (interactive)
3800 ;; (save-excursion
3801 ;; (let ((inhibit-read-only t))
3802 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3804 (defun article-remove-leading-whitespace ()
3805 "Remove excessive whitespace from all headers."
3806 (interactive)
3807 (save-excursion
3808 (save-restriction
3809 (let ((inhibit-read-only t))
3810 (article-narrow-to-head)
3811 (goto-char (point-min))
3812 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3813 (delete-region (match-beginning 1) (match-end 1)))))))
3815 (defun article-emphasize (&optional arg)
3816 "Emphasize text according to `gnus-emphasis-alist'."
3817 (interactive (gnus-article-hidden-arg))
3818 (unless (gnus-article-check-hidden-text 'emphasis arg)
3819 (save-excursion
3820 (let ((alist (or
3821 (condition-case nil
3822 (with-current-buffer gnus-summary-buffer
3823 gnus-article-emphasis-alist)
3824 (error))
3825 gnus-emphasis-alist))
3826 (inhibit-read-only t)
3827 (props (append '(article-type emphasis)
3828 gnus-hidden-properties))
3829 regexp elem beg invisible visible face)
3830 (article-goto-body)
3831 (setq beg (point))
3832 (while (setq elem (pop alist))
3833 (goto-char beg)
3834 (setq regexp (car elem)
3835 invisible (nth 1 elem)
3836 visible (nth 2 elem)
3837 face (nth 3 elem))
3838 (while (re-search-forward regexp nil t)
3839 (when (and (match-beginning visible) (match-beginning invisible))
3840 (gnus-article-hide-text
3841 (match-beginning invisible) (match-end invisible) props)
3842 (gnus-article-unhide-text-type
3843 (match-beginning visible) (match-end visible) 'emphasis)
3844 (gnus-put-overlay-excluding-newlines
3845 (match-beginning visible) (match-end visible) 'face face)
3846 (gnus-add-wash-type 'emphasis)
3847 (goto-char (match-end invisible)))))))))
3849 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3850 "Setup newsgroup emphasis alist."
3851 (unless gnus-article-emphasis-alist
3852 (let ((name (and gnus-newsgroup-name
3853 (gnus-group-real-name gnus-newsgroup-name))))
3854 (make-local-variable 'gnus-article-emphasis-alist)
3855 (setq gnus-article-emphasis-alist
3856 (nconc
3857 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3858 (while (setq elem (pop alist))
3859 (when (and name (string-match (car elem) name))
3860 (setq alist nil
3861 highlight (copy-sequence (cdr elem)))))
3862 highlight)
3863 (copy-sequence highlight-words)
3864 (if gnus-newsgroup-name
3865 (copy-sequence (gnus-group-find-parameter
3866 gnus-newsgroup-name 'highlight-words t)))
3867 gnus-emphasis-alist)))))
3869 (defvar gnus-summary-article-menu)
3870 (defvar gnus-summary-post-menu)
3872 ;;; Saving functions.
3874 (defun gnus-article-save (save-buffer file &optional num)
3875 "Save the currently selected article."
3876 (when (or (get gnus-default-article-saver :headers)
3877 (not gnus-save-all-headers))
3878 ;; Remove headers according to `gnus-saved-headers' or the value
3879 ;; of the `:headers' property that the saver function might have.
3880 (let ((gnus-visible-headers
3881 (or (symbol-value (get gnus-default-article-saver :headers))
3882 gnus-saved-headers gnus-visible-headers))
3883 ;; Ignore group parameter. See `article-hide-headers'.
3884 (gnus-summary-buffer nil))
3885 (with-current-buffer save-buffer
3886 (article-hide-headers 1 t))))
3887 (save-window-excursion
3888 (if (not gnus-default-article-saver)
3889 (error "No default saver is defined")
3890 ;; !!! Magic! The saving functions all save
3891 ;; `gnus-save-article-buffer' (or so they think), but we
3892 ;; bind that variable to our save-buffer.
3893 (set-buffer gnus-article-buffer)
3894 (let* ((gnus-save-article-buffer save-buffer)
3895 (filename
3896 (cond
3897 ((not gnus-prompt-before-saving) 'default)
3898 ((eq gnus-prompt-before-saving 'always) nil)
3899 (t file)))
3900 (gnus-number-of-articles-to-be-saved
3901 (when (eq gnus-prompt-before-saving t)
3902 num))) ; Magic
3903 (set-buffer gnus-article-current-summary)
3904 (funcall gnus-default-article-saver filename)))))
3906 (defun gnus-read-save-file-name (prompt &optional filename
3907 function group headers variable
3908 dir-var)
3909 (let ((default-name
3910 (funcall function group headers (symbol-value variable)))
3911 result)
3912 (setq result
3913 (expand-file-name
3914 (cond
3915 ((eq filename 'default)
3916 default-name)
3917 ((eq filename t)
3918 default-name)
3919 (filename filename)
3921 (when (symbol-value dir-var)
3922 (setq default-name (expand-file-name
3923 (file-name-nondirectory default-name)
3924 (symbol-value dir-var))))
3925 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3926 (prompt
3927 (format prompt
3928 (if (and gnus-number-of-articles-to-be-saved
3929 (> gnus-number-of-articles-to-be-saved 1))
3930 (format "these %d articles"
3931 gnus-number-of-articles-to-be-saved)
3932 "this article")))
3933 (file
3934 ;; Let the split methods have their say.
3935 (cond
3936 ;; No split name was found.
3937 ((null split-name)
3938 (read-file-name
3939 (concat prompt " (default "
3940 (file-name-nondirectory default-name) "): ")
3941 (file-name-directory default-name)
3942 default-name))
3943 ;; A single group name is returned.
3944 ((stringp split-name)
3945 (setq default-name
3946 (funcall function split-name headers
3947 (symbol-value variable)))
3948 (read-file-name
3949 (concat prompt " (default "
3950 (file-name-nondirectory default-name) "): ")
3951 (file-name-directory default-name)
3952 default-name))
3953 ;; A single split name was found
3954 ((= 1 (length split-name))
3955 (let* ((name (expand-file-name
3956 (car split-name)
3957 gnus-article-save-directory))
3958 (dir (cond ((file-directory-p name)
3959 (file-name-as-directory name))
3960 ((file-exists-p name) name)
3961 (t gnus-article-save-directory))))
3962 (read-file-name
3963 (concat prompt " (default " name "): ")
3964 dir name)))
3965 ;; A list of splits was found.
3967 (setq split-name (nreverse split-name))
3968 (let (result)
3969 (let ((file-name-history
3970 (nconc split-name file-name-history)))
3971 (setq result
3972 (expand-file-name
3973 (read-file-name
3974 (concat prompt " (`M-p' for defaults): ")
3975 gnus-article-save-directory
3976 (car split-name))
3977 gnus-article-save-directory)))
3978 (car (push result file-name-history)))))))
3979 ;; Create the directory.
3980 (gnus-make-directory (file-name-directory file))
3981 ;; If we have read a directory, we append the default file name.
3982 (when (file-directory-p file)
3983 (setq file (expand-file-name (file-name-nondirectory
3984 default-name)
3985 (file-name-as-directory file))))
3986 ;; Possibly translate some characters.
3987 (nnheader-translate-file-chars file))))))
3988 (gnus-make-directory (file-name-directory result))
3989 (when variable
3990 (set variable result))
3991 (when dir-var
3992 (set dir-var (file-name-directory result)))
3993 result))
3995 (defun gnus-article-archive-name (_group)
3996 "Return the first instance of an \"Archive-name\" in the current buffer."
3997 (let ((case-fold-search t))
3998 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3999 (nnheader-concat gnus-article-save-directory
4000 (match-string 1)))))
4002 (defun gnus-article-nndoc-name (group)
4003 "If GROUP is an nndoc group, return the name of the parent group."
4004 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4005 (gnus-group-get-parameter group 'save-article-group)))
4007 (defun gnus-summary-save-in-rmail (&optional filename)
4008 "Append this article to Rmail file.
4009 Optional argument FILENAME specifies file name.
4010 Directory to save to is default to `gnus-article-save-directory'."
4011 (setq filename (gnus-read-save-file-name
4012 "Save %s in rmail file" filename
4013 gnus-rmail-save-name gnus-newsgroup-name
4014 gnus-current-headers 'gnus-newsgroup-last-rmail))
4015 (with-current-buffer gnus-save-article-buffer
4016 (save-excursion
4017 (save-restriction
4018 (widen)
4019 ;; Note that unlike gnus-summary-save-in-mail, there is no
4020 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4021 ;; not use Babyl.
4022 (gnus-output-to-rmail filename))))
4023 filename)
4025 (defun gnus-summary-save-in-mail (&optional filename)
4026 "Append this article to Unix mail file.
4027 Optional argument FILENAME specifies file name.
4028 Directory to save to is default to `gnus-article-save-directory'."
4029 (setq filename (gnus-read-save-file-name
4030 "Save %s in Unix mail file" filename
4031 gnus-mail-save-name gnus-newsgroup-name
4032 gnus-current-headers 'gnus-newsgroup-last-mail))
4033 (with-current-buffer gnus-save-article-buffer
4034 (save-excursion
4035 (save-restriction
4036 (widen)
4037 (if (and (file-readable-p filename)
4038 (file-regular-p filename)
4039 (mail-file-babyl-p filename))
4040 (gnus-output-to-rmail filename)
4041 (gnus-output-to-mail filename)))))
4042 filename)
4044 (put 'gnus-summary-save-in-file :decode t)
4045 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4046 (defun gnus-summary-save-in-file (&optional filename overwrite)
4047 "Append this article to file.
4048 Optional argument FILENAME specifies file name.
4049 Directory to save to is default to `gnus-article-save-directory'."
4050 (setq filename (gnus-read-save-file-name
4051 "Save %s in file" filename
4052 gnus-file-save-name gnus-newsgroup-name
4053 gnus-current-headers 'gnus-newsgroup-last-file))
4054 (with-current-buffer gnus-save-article-buffer
4055 (save-excursion
4056 (save-restriction
4057 (widen)
4058 (when (and overwrite
4059 (file-exists-p filename))
4060 (delete-file filename))
4061 (gnus-output-to-file filename))))
4062 filename)
4064 (put 'gnus-summary-write-to-file :decode t)
4065 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4066 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4067 (defun gnus-summary-write-to-file (&optional filename)
4068 "Write this article to a file, overwriting it if the file exists.
4069 Optional argument FILENAME specifies file name.
4070 The directory to save in defaults to `gnus-article-save-directory'."
4071 (setq filename (gnus-read-save-file-name
4072 "Save %s in file" filename
4073 gnus-file-save-name gnus-newsgroup-name
4074 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4075 (gnus-summary-save-in-file filename t))
4077 (put 'gnus-summary-save-body-in-file :decode t)
4078 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4079 "Append this article body to a file.
4080 Optional argument FILENAME specifies file name.
4081 The directory to save in defaults to `gnus-article-save-directory'."
4082 (setq filename (gnus-read-save-file-name
4083 "Save %s body in file" filename
4084 gnus-file-save-name gnus-newsgroup-name
4085 gnus-current-headers 'gnus-newsgroup-last-file))
4086 (with-current-buffer gnus-save-article-buffer
4087 (save-excursion
4088 (save-restriction
4089 (widen)
4090 (when (article-goto-body)
4091 (narrow-to-region (point) (point-max)))
4092 (when (and overwrite
4093 (file-exists-p filename))
4094 (delete-file filename))
4095 (gnus-output-to-file filename))))
4096 filename)
4098 (put 'gnus-summary-write-body-to-file :decode t)
4099 (put 'gnus-summary-write-body-to-file
4100 :function 'gnus-summary-save-body-in-file)
4101 (defun gnus-summary-write-body-to-file (&optional filename)
4102 "Write this article body to a file, overwriting it if the file exists.
4103 Optional argument FILENAME specifies file name.
4104 The directory to save in defaults to `gnus-article-save-directory'."
4105 (setq filename (gnus-read-save-file-name
4106 "Save %s body in file" filename
4107 gnus-file-save-name gnus-newsgroup-name
4108 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4109 (gnus-summary-save-body-in-file filename t))
4111 (put 'gnus-summary-save-in-pipe :decode t)
4112 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4113 (defun gnus-summary-save-in-pipe (&optional command raw)
4114 "Pipe this article to subprocess COMMAND.
4115 Valid values for COMMAND include:
4116 a string
4117 The executable command name and possibly arguments.
4119 You will be prompted for the command in the minibuffer.
4120 the symbol `default'
4121 It will be replaced with the command which the variable
4122 `gnus-summary-pipe-output-default-command' holds or the command
4123 last used for saving.
4124 Non-nil value for RAW overrides `:decode' and `:headers' properties
4125 and the raw article including all headers will be piped."
4126 (let ((article (gnus-summary-article-number))
4127 (decode (unless raw
4128 (get 'gnus-summary-save-in-pipe :decode)))
4129 save-buffer default)
4130 (if article
4131 (if (vectorp (gnus-summary-article-header article))
4132 (save-current-buffer
4133 (gnus-summary-select-article decode decode nil article)
4134 (insert-buffer-substring
4135 (prog1
4136 (if decode
4137 gnus-article-buffer
4138 gnus-original-article-buffer)
4139 (setq save-buffer
4140 (nnheader-set-temp-buffer " *Gnus Save*"))))
4141 ;; Remove unwanted headers.
4142 (when (and (not raw)
4143 (or (get 'gnus-summary-save-in-pipe :headers)
4144 (not gnus-save-all-headers)))
4145 (let ((gnus-visible-headers
4146 (or (symbol-value (get 'gnus-summary-save-in-pipe
4147 :headers))
4148 gnus-saved-headers gnus-visible-headers))
4149 (gnus-summary-buffer nil))
4150 (article-hide-headers 1 t))))
4151 (error "%d is not a real article" article))
4152 (error "No article to pipe"))
4153 (setq default (or gnus-summary-pipe-output-default-command
4154 gnus-last-shell-command))
4155 (unless (stringp command)
4156 (setq command
4157 (if (and (eq command 'default) default)
4158 default
4159 (gnus-read-shell-command "Shell command on this article: "
4160 default))))
4161 (when (string-equal command "")
4162 (if default
4163 (setq command default)
4164 (error "A command is required")))
4165 (with-current-buffer save-buffer
4166 (save-restriction
4167 (widen)
4168 (shell-command-on-region (point-min) (point-max) command nil)))
4169 (gnus-kill-buffer save-buffer))
4170 (setq gnus-summary-pipe-output-default-command command))
4172 (defun gnus-summary-pipe-to-muttprint (&optional command)
4173 "Pipe this article to muttprint."
4174 (unless (stringp command)
4175 (setq command (read-string
4176 "Print using command: " gnus-summary-muttprint-program
4177 nil gnus-summary-muttprint-program)))
4178 (let ((gnus-summary-pipe-output-default-command
4179 gnus-summary-pipe-output-default-command))
4180 (gnus-summary-save-in-pipe command))
4181 (setq gnus-summary-muttprint-program command))
4183 ;;; Article file names when saving.
4185 (defun gnus-capitalize-newsgroup (newsgroup)
4186 "Capitalize NEWSGROUP name."
4187 (when (not (zerop (length newsgroup)))
4188 (concat (char-to-string (upcase (aref newsgroup 0)))
4189 (substring newsgroup 1))))
4191 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4192 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4193 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4194 Otherwise, it is like ~/News/news/group/num."
4195 (let ((default
4196 (expand-file-name
4197 (concat (if (gnus-use-long-file-name 'not-save)
4198 (gnus-capitalize-newsgroup newsgroup)
4199 (gnus-newsgroup-directory-form newsgroup))
4200 "/" (int-to-string (mail-header-number headers)))
4201 gnus-article-save-directory)))
4202 (if (and last-file
4203 (string-equal (file-name-directory default)
4204 (file-name-directory last-file))
4205 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4206 default
4207 (or last-file default))))
4209 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4210 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4211 If variable `gnus-use-long-file-name' is non-nil, it is
4212 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4213 (let ((default
4214 (expand-file-name
4215 (concat (if (gnus-use-long-file-name 'not-save)
4216 newsgroup
4217 (gnus-newsgroup-directory-form newsgroup))
4218 "/" (int-to-string (mail-header-number headers)))
4219 gnus-article-save-directory)))
4220 (if (and last-file
4221 (string-equal (file-name-directory default)
4222 (file-name-directory last-file))
4223 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4224 default
4225 (or last-file default))))
4227 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4228 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4229 If variable `gnus-use-long-file-name' is non-nil, it is
4230 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4231 (or last-file
4232 (expand-file-name
4233 (if (gnus-use-long-file-name 'not-save)
4234 newsgroup
4235 (file-relative-name
4236 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4237 default-directory))
4238 gnus-article-save-directory)))
4240 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4241 "Generate file name from sender."
4242 (let ((from (mail-header-from headers)))
4243 (expand-file-name
4244 (if (and from (string-match "\\([^ <]+\\)@" from))
4245 (match-string 1 from)
4246 "nobody")
4247 gnus-article-save-directory)))
4249 (defun article-verify-x-pgp-sig ()
4250 "Verify X-PGP-Sig."
4251 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4252 (interactive)
4253 (if (gnus-buffer-live-p gnus-original-article-buffer)
4254 (let ((sig (with-current-buffer gnus-original-article-buffer
4255 (gnus-fetch-field "X-PGP-Sig")))
4256 items info headers)
4257 (when (and sig
4258 mml2015-use
4259 (mml2015-clear-verify-function))
4260 (with-temp-buffer
4261 (insert-buffer-substring gnus-original-article-buffer)
4262 (setq items (split-string sig))
4263 (message-narrow-to-head)
4264 (let ((inhibit-point-motion-hooks t)
4265 (case-fold-search t))
4266 ;; Don't verify multiple headers.
4267 (setq headers (mapconcat (lambda (header)
4268 (concat header ": "
4269 (mail-fetch-field header)
4270 "\n"))
4271 (split-string (nth 1 items) ",") "")))
4272 (delete-region (point-min) (point-max))
4273 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4274 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4275 (insert headers)
4276 (widen)
4277 (forward-line)
4278 (while (not (eobp))
4279 (if (looking-at "^-")
4280 (insert "- "))
4281 (forward-line))
4282 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4283 (insert "Version: " (car items) "\n\n")
4284 (insert (mapconcat 'identity (cddr items) "\n"))
4285 (insert "\n-----END PGP SIGNATURE-----\n")
4286 (let ((mm-security-handle (list (format "multipart/signed"))))
4287 (mml2015-clean-buffer)
4288 (let ((coding-system-for-write (or gnus-newsgroup-charset
4289 'iso-8859-1)))
4290 (funcall (mml2015-clear-verify-function)))
4291 (setq info
4292 (or (mm-handle-multipart-ctl-parameter
4293 mm-security-handle 'gnus-details)
4294 (mm-handle-multipart-ctl-parameter
4295 mm-security-handle 'gnus-info)))))
4296 (when info
4297 (let ((inhibit-read-only t) bface eface)
4298 (save-restriction
4299 (message-narrow-to-head)
4300 (goto-char (point-max))
4301 (forward-line -1)
4302 (setq bface (get-text-property (point-at-bol) 'face)
4303 eface (get-text-property (1- (point-at-eol)) 'face))
4304 (message-remove-header "X-Gnus-PGP-Verify")
4305 (if (re-search-forward "^X-PGP-Sig:" nil t)
4306 (forward-line)
4307 (goto-char (point-max)))
4308 (narrow-to-region (point) (point))
4309 (insert "X-Gnus-PGP-Verify: " info "\n")
4310 (goto-char (point-min))
4311 (forward-line)
4312 (while (not (eobp))
4313 (if (not (looking-at "^[ \t]"))
4314 (insert " "))
4315 (forward-line))
4316 ;; Do highlighting.
4317 (goto-char (point-min))
4318 (when (looking-at "\\([^:]+\\): *")
4319 (put-text-property (match-beginning 1) (1+ (match-end 1))
4320 'face bface)
4321 (put-text-property (match-end 0) (point-max)
4322 'face eface)))))))))
4324 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4326 (defun article-verify-cancel-lock ()
4327 "Verify Cancel-Lock header."
4328 (interactive)
4329 (if (gnus-buffer-live-p gnus-original-article-buffer)
4330 (canlock-verify gnus-original-article-buffer)))
4332 (eval-and-compile
4333 (mapc
4334 (lambda (func)
4335 (let (afunc gfunc)
4336 (if (consp func)
4337 (setq afunc (car func)
4338 gfunc (cdr func))
4339 (setq afunc func
4340 gfunc (intern (format "gnus-%s" func))))
4341 (defalias gfunc
4342 (when (fboundp afunc)
4343 `(lambda (&optional interactive &rest args)
4344 ,(documentation afunc t)
4345 (interactive (list t))
4346 (with-current-buffer gnus-article-buffer
4347 (if interactive
4348 (call-interactively ',afunc)
4349 (apply ',afunc args))))))))
4350 '(article-hide-headers
4351 article-verify-x-pgp-sig
4352 article-verify-cancel-lock
4353 article-hide-boring-headers
4354 article-treat-overstrike
4355 article-treat-ansi-sequences
4356 article-fill-long-lines
4357 article-capitalize-sentences
4358 article-remove-cr
4359 article-remove-leading-whitespace
4360 article-display-x-face
4361 article-display-face
4362 article-de-quoted-unreadable
4363 article-de-base64-unreadable
4364 article-decode-HZ
4365 article-wash-html
4366 article-unsplit-urls
4367 article-hide-list-identifiers
4368 article-strip-banner
4369 article-babel
4370 article-hide-pem
4371 article-hide-signature
4372 article-strip-headers-in-body
4373 article-remove-trailing-blank-lines
4374 article-strip-leading-blank-lines
4375 article-strip-multiple-blank-lines
4376 article-strip-leading-space
4377 article-strip-trailing-space
4378 article-strip-blank-lines
4379 article-strip-all-blank-lines
4380 article-date-local
4381 article-date-english
4382 article-date-iso8601
4383 article-date-original
4384 article-treat-date
4385 article-date-ut
4386 article-decode-mime-words
4387 article-decode-charset
4388 article-decode-encoded-words
4389 article-date-user
4390 article-date-lapsed
4391 article-date-combined-lapsed
4392 article-emphasize
4393 article-treat-dumbquotes
4394 article-treat-non-ascii
4395 article-normalize-headers
4396 ;;(article-show-all . gnus-article-show-all-headers)
4400 ;;; Gnus article mode
4403 (put 'gnus-article-mode 'mode-class 'special)
4405 (set-keymap-parent gnus-article-mode-map widget-keymap)
4407 (gnus-define-keys gnus-article-mode-map
4408 " " gnus-article-goto-next-page
4409 [?\S-\ ] gnus-article-goto-prev-page
4410 "\177" gnus-article-goto-prev-page
4411 [delete] gnus-article-goto-prev-page
4412 "\C-c^" gnus-article-refer-article
4413 "h" gnus-article-show-summary
4414 "s" gnus-article-show-summary
4415 "\C-c\C-m" gnus-article-mail
4416 "?" gnus-article-describe-briefly
4417 "<" beginning-of-buffer
4418 ">" end-of-buffer
4419 "\C-c\C-i" gnus-info-find-node
4420 "\C-c\C-b" gnus-bug
4421 "R" gnus-article-reply-with-original
4422 "F" gnus-article-followup-with-original
4423 "\C-hk" gnus-article-describe-key
4424 "\C-hc" gnus-article-describe-key-briefly
4425 "\C-hb" gnus-article-describe-bindings
4427 "e" gnus-article-read-summary-keys
4428 "\C-d" gnus-article-read-summary-keys
4429 "\M-*" gnus-article-read-summary-keys
4430 "\M-#" gnus-article-read-summary-keys
4431 "\M-^" gnus-article-read-summary-keys
4432 "\M-g" gnus-article-read-summary-keys)
4434 (substitute-key-definition
4435 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4437 (defvar gnus-article-send-map)
4439 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4440 "W" gnus-article-wide-reply-with-original)
4441 (if (featurep 'xemacs)
4442 (set-keymap-default-binding gnus-article-send-map
4443 'gnus-article-read-summary-send-keys)
4444 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4446 (defun gnus-article-make-menu-bar ()
4447 (unless (boundp 'gnus-article-commands-menu)
4448 (gnus-summary-make-menu-bar))
4449 (unless (boundp 'gnus-article-article-menu)
4450 (easy-menu-define
4451 gnus-article-article-menu gnus-article-mode-map ""
4452 '("Article"
4453 ["Scroll forwards" gnus-article-goto-next-page t]
4454 ["Scroll backwards" gnus-article-goto-prev-page t]
4455 ["Show summary" gnus-article-show-summary t]
4456 ["Fetch Message-ID at point" gnus-article-refer-article t]
4457 ["Mail to address at point" gnus-article-mail t]
4458 ["Send a bug report" gnus-bug t]))
4460 (easy-menu-define
4461 gnus-article-treatment-menu gnus-article-mode-map ""
4462 ;; Fixme: this should use :active (and maybe :visible).
4463 '("Treatment"
4464 ["Hide headers" gnus-article-hide-headers t]
4465 ["Hide signature" gnus-article-hide-signature t]
4466 ["Hide citation" gnus-article-hide-citation t]
4467 ["Treat overstrike" gnus-article-treat-overstrike t]
4468 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4469 ["Remove carriage return" gnus-article-remove-cr t]
4470 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4471 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4472 ["Remove base64" gnus-article-de-base64-unreadable t]
4473 ["Treat html" gnus-article-wash-html t]
4474 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4475 ["Decode HZ" gnus-article-decode-HZ t]))
4477 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4479 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4481 (gnus-run-hooks 'gnus-article-menu-hook)))
4483 (defvar bookmark-make-record-function)
4484 (defvar shr-put-image-function)
4486 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4487 "Major mode for displaying an article.
4489 All normal editing commands are switched off.
4491 The following commands are available in addition to all summary mode
4492 commands:
4493 \\<gnus-article-mode-map>
4494 \\[gnus-article-next-page]\t Scroll the article one page forwards
4495 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4496 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4497 \\[gnus-article-show-summary]\t Display the summary buffer
4498 \\[gnus-article-mail]\t Send a reply to the address near point
4499 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4500 \\[gnus-info-find-node]\t Go to the Gnus info node"
4501 (gnus-simplify-mode-line)
4502 (make-local-variable 'minor-mode-alist)
4503 (when (gnus-visual-p 'article-menu 'menu)
4504 (gnus-article-make-menu-bar)
4505 (when gnus-summary-tool-bar-map
4506 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4507 (gnus-update-format-specifications nil 'article-mode)
4508 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4509 (set (make-local-variable 'gnus-page-broken) nil)
4510 (make-local-variable 'gnus-article-current-summary)
4511 (make-local-variable 'gnus-article-mime-handles)
4512 (make-local-variable 'gnus-article-decoded-p)
4513 (make-local-variable 'gnus-article-mime-handle-alist)
4514 (make-local-variable 'gnus-article-wash-types)
4515 (make-local-variable 'gnus-article-image-alist)
4516 (make-local-variable 'gnus-article-charset)
4517 (make-local-variable 'gnus-article-ignored-charsets)
4518 (set (make-local-variable 'bookmark-make-record-function)
4519 'gnus-summary-bookmark-make-record)
4520 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4521 ;; face.
4522 (set (make-local-variable 'nobreak-char-display) nil)
4523 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4524 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4525 (setq cursor-in-non-selected-windows nil)
4526 (gnus-set-default-directory)
4527 (buffer-disable-undo)
4528 (setq buffer-read-only t
4529 show-trailing-whitespace nil)
4530 (mm-enable-multibyte))
4532 (defun gnus-article-setup-buffer ()
4533 "Initialize the article buffer."
4534 (let* ((name (if gnus-single-article-buffer "*Article*"
4535 (concat "*Article "
4536 (gnus-group-decoded-name gnus-newsgroup-name)
4537 "*")))
4538 (original
4539 (progn (string-match "\\*Article" name)
4540 (concat " *Original Article"
4541 (substring name (match-end 0))))))
4542 (setq gnus-article-buffer name)
4543 (setq gnus-original-article-buffer original)
4544 (setq gnus-article-mime-handle-alist nil)
4545 (with-current-buffer gnus-summary-buffer
4546 ;; This might be a variable local to the summary buffer.
4547 (unless gnus-single-article-buffer
4548 (setq gnus-article-buffer name)
4549 (setq gnus-original-article-buffer original)
4550 (gnus-set-global-variables)))
4551 (gnus-article-setup-highlight-words)
4552 ;; Init original article buffer.
4553 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4554 (mm-enable-multibyte)
4555 (setq major-mode 'gnus-original-article-mode)
4556 (make-local-variable 'gnus-original-article))
4557 (if (and (get-buffer name)
4558 (with-current-buffer name
4559 (if gnus-article-edit-mode
4560 (if (y-or-n-p "Article mode edit in progress; discard? ")
4561 (progn
4562 (set-buffer-modified-p nil)
4563 (gnus-kill-buffer name)
4564 (message "")
4565 nil)
4566 (error "Action aborted"))
4567 t)))
4568 (let ((summary gnus-summary-buffer))
4569 (with-current-buffer name
4570 (set (make-local-variable 'gnus-article-edit-mode) nil)
4571 (gnus-article-stop-animations)
4572 (when gnus-article-mime-handles
4573 (mm-destroy-parts gnus-article-mime-handles)
4574 (setq gnus-article-mime-handles nil))
4575 ;; Set it to nil in article-buffer!
4576 (setq gnus-article-mime-handle-alist nil)
4577 (buffer-disable-undo)
4578 (setq buffer-read-only t)
4579 (unless (derived-mode-p 'gnus-article-mode)
4580 (gnus-article-mode))
4581 (set (make-local-variable 'gnus-summary-buffer) summary)
4582 (setq truncate-lines gnus-article-truncate-lines)
4583 (current-buffer)))
4584 (let ((summary gnus-summary-buffer))
4585 (with-current-buffer (gnus-get-buffer-create name)
4586 (gnus-article-mode)
4587 (setq truncate-lines gnus-article-truncate-lines)
4588 (set (make-local-variable 'gnus-summary-buffer) summary)
4589 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4590 (when article-lapsed-timer
4591 (gnus-stop-date-timer))
4592 (when gnus-article-update-date-headers
4593 (gnus-start-date-timer gnus-article-update-date-headers))
4594 (current-buffer))))))
4596 (defun gnus-article-stop-animations ()
4597 (dolist (timer (and (boundp 'timer-list)
4598 timer-list))
4599 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4600 (cancel-timer timer))))
4602 (defun gnus-stop-downloads ()
4603 (when (boundp 'url-queue)
4604 (set (intern "url-queue" obarray) nil)))
4606 ;; Set article window start at LINE, where LINE is the number of lines
4607 ;; from the head of the article.
4608 (defun gnus-article-set-window-start (&optional line)
4609 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4610 (when article-window
4611 (set-window-start
4612 article-window
4613 (with-current-buffer gnus-article-buffer
4614 (goto-char (point-min))
4615 (if (not line)
4616 (point-min)
4617 (gnus-message 6 "Moved to bookmark")
4618 (search-forward "\n\n" nil t)
4619 (forward-line line)
4620 (point)))))))
4622 (defvar gnus-tmp-internal-hook)
4624 (defun gnus-article-prepare (article &optional all-headers _header)
4625 "Prepare ARTICLE in article mode buffer.
4626 ARTICLE should either be an article number or a Message-ID.
4627 If ARTICLE is an id, HEADER should be the article headers.
4628 If ALL-HEADERS is non-nil, no headers are hidden."
4629 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4630 ;; Make sure we start in a summary buffer.
4631 (unless (derived-mode-p 'gnus-summary-mode)
4632 (set-buffer gnus-summary-buffer))
4633 (setq gnus-summary-buffer (current-buffer))
4634 (let* ((summary-buffer (current-buffer))
4635 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4636 (group gnus-newsgroup-name)
4637 result)
4638 (save-excursion
4639 (gnus-article-setup-buffer)
4640 (set-buffer gnus-article-buffer)
4641 ;; Deactivate active regions.
4642 (when (and (boundp 'transient-mark-mode)
4643 transient-mark-mode)
4644 (setq mark-active nil))
4645 (if (not (setq result (let ((inhibit-read-only t))
4646 (gnus-request-article-this-buffer
4647 article group))))
4648 ;; There is no such article.
4649 (save-excursion
4650 (when (and (numberp article)
4651 (not (memq article gnus-newsgroup-sparse)))
4652 (setq gnus-article-current
4653 (cons gnus-newsgroup-name article))
4654 (set-buffer gnus-summary-buffer)
4655 (setq gnus-current-article article)
4656 (if (and (memq article gnus-newsgroup-undownloaded)
4657 (not (gnus-online (gnus-find-method-for-group
4658 gnus-newsgroup-name))))
4659 (progn
4660 (gnus-summary-set-agent-mark article)
4661 (message "Message marked for downloading"))
4662 (gnus-summary-mark-article article gnus-canceled-mark)
4663 (unless (memq article gnus-newsgroup-sparse)
4664 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4665 (if (or (eq result 'pseudo)
4666 (eq result 'nneething))
4667 (progn
4668 (with-current-buffer summary-buffer
4669 (push article gnus-newsgroup-history)
4670 (setq gnus-last-article gnus-current-article
4671 gnus-current-article 0
4672 gnus-current-headers nil
4673 gnus-article-current nil)
4674 (if (eq result 'nneething)
4675 (gnus-configure-windows 'summary)
4676 (gnus-configure-windows 'article))
4677 (gnus-set-global-variables))
4678 (let ((gnus-article-mime-handle-alist-1
4679 gnus-article-mime-handle-alist))
4680 (gnus-set-mode-line 'article)))
4681 ;; The result from the `request' was an actual article -
4682 ;; or at least some text that is now displayed in the
4683 ;; article buffer.
4684 (when (and (numberp article)
4685 (not (eq article gnus-current-article)))
4686 ;; Seems like a new article has been selected.
4687 ;; `gnus-current-article' must be an article number.
4688 (with-current-buffer summary-buffer
4689 (push article gnus-newsgroup-history)
4690 (setq gnus-last-article gnus-current-article
4691 gnus-current-article article
4692 gnus-current-headers
4693 (gnus-summary-article-header gnus-current-article)
4694 gnus-article-current
4695 (cons gnus-newsgroup-name gnus-current-article))
4696 (unless (vectorp gnus-current-headers)
4697 (setq gnus-current-headers nil))
4698 (gnus-summary-goto-subject gnus-current-article)
4699 (when (gnus-summary-show-thread)
4700 ;; If the summary buffer really was folded, the
4701 ;; previous goto may not actually have gone to
4702 ;; the right article, but the thread root instead.
4703 ;; So we go again.
4704 (gnus-summary-goto-subject gnus-current-article))
4705 (gnus-run-hooks 'gnus-mark-article-hook)
4706 (gnus-set-mode-line 'summary)
4707 (when (gnus-visual-p 'article-highlight 'highlight)
4708 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4709 ;; Set the global newsgroup variables here.
4710 (gnus-set-global-variables)
4711 (setq gnus-have-all-headers
4712 (or all-headers gnus-show-all-headers))))
4713 (save-excursion
4714 (gnus-configure-windows 'article))
4715 (when (or (numberp article)
4716 (stringp article))
4717 (gnus-article-prepare-display)
4718 ;; Do page break.
4719 (goto-char (point-min))
4720 (when gnus-break-pages
4721 (gnus-narrow-to-page)))
4722 (let ((gnus-article-mime-handle-alist-1
4723 gnus-article-mime-handle-alist))
4724 (gnus-set-mode-line 'article))
4725 (article-goto-body)
4726 (unless (bobp)
4727 (forward-line -1))
4728 (set-window-point (get-buffer-window (current-buffer)) (point))
4729 (gnus-configure-windows 'article)
4730 (gnus-run-hooks 'gnus-article-prepare-hook)
4731 t))))))
4733 (defvar gnus-mime-display-attachment-buttons-in-header)
4735 ;;;###autoload
4736 (defun gnus-article-prepare-display ()
4737 "Make the current buffer look like a nice article."
4738 ;; Hooks for getting information from the article.
4739 ;; This hook must be called before being narrowed.
4740 (let ((gnus-article-buffer (current-buffer))
4741 buffer-read-only
4742 (inhibit-read-only t))
4743 (unless (derived-mode-p 'gnus-article-mode)
4744 (gnus-article-mode))
4745 (setq buffer-read-only nil
4746 gnus-article-wash-types nil
4747 gnus-article-image-alist nil)
4748 (gnus-run-hooks 'gnus-tmp-internal-hook)
4749 (when gnus-display-mime-function
4750 (funcall gnus-display-mime-function))
4751 ;; Add attachment buttons to the header.
4752 (when gnus-mime-display-attachment-buttons-in-header
4753 (gnus-mime-buttonize-attachments-in-header))))
4756 ;;; Gnus Sticky Article Mode
4759 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4760 "Mode for sticky articles."
4761 ;; Release bindings that won't work.
4762 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4763 gnus-sticky-article-mode-map)
4764 (substitute-key-definition 'gnus-article-refer-article 'undefined
4765 gnus-sticky-article-mode-map)
4766 (dolist (k '("e" "h" "s" "F" "R"))
4767 (define-key gnus-sticky-article-mode-map k nil))
4768 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4769 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4770 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4771 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4773 (defun gnus-sticky-article (arg)
4774 "Make the current article sticky.
4775 If a prefix ARG is given, ask for a name for this sticky article buffer."
4776 (interactive "P")
4777 (gnus-summary-show-thread)
4778 (gnus-summary-select-article nil nil 'pseudo)
4779 (let (new-art-buf-name)
4780 (gnus-eval-in-buffer-window gnus-article-buffer
4781 (setq new-art-buf-name
4782 (concat
4783 "*Sticky Article: "
4784 (if arg
4785 (read-from-minibuffer "Sticky article buffer name: ")
4786 (gnus-with-article-headers
4787 (gnus-article-goto-header "subject")
4788 (setq new-art-buf-name
4789 (buffer-substring-no-properties
4790 (line-beginning-position) (line-end-position)))
4791 (goto-char (point-min))
4792 (gnus-article-goto-header "from")
4793 (setq new-art-buf-name
4794 (concat
4795 new-art-buf-name ", "
4796 (buffer-substring-no-properties
4797 (line-beginning-position) (line-end-position))))
4798 (goto-char (point-min))
4799 (gnus-article-goto-header "date")
4800 (setq new-art-buf-name
4801 (concat
4802 new-art-buf-name ", "
4803 (buffer-substring-no-properties
4804 (line-beginning-position) (line-end-position))))))
4805 "*"))
4806 (if (and (gnus-buffer-live-p new-art-buf-name)
4807 (with-current-buffer new-art-buf-name
4808 (derived-mode-p 'gnus-sticky-article-mode)))
4809 (switch-to-buffer new-art-buf-name)
4810 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4811 (gnus-sticky-article-mode))
4812 (setq gnus-article-buffer new-art-buf-name))
4813 (gnus-summary-recenter)
4814 (gnus-summary-position-point))
4816 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4817 "Kill the given sticky article BUFFER.
4818 If none is given, assume the current buffer and kill it if it has
4819 `gnus-sticky-article-mode'."
4820 (interactive)
4821 (unless buffer
4822 (setq buffer (current-buffer)))
4823 (with-current-buffer buffer
4824 (when (derived-mode-p 'gnus-sticky-article-mode)
4825 (gnus-kill-buffer buffer))))
4827 (defun gnus-kill-sticky-article-buffers (arg)
4828 "Kill all sticky article buffers.
4829 If a prefix ARG is given, ask for confirmation."
4830 (interactive "P")
4831 (dolist (buf (gnus-buffers))
4832 (with-current-buffer buf
4833 (when (derived-mode-p 'gnus-sticky-article-mode)
4834 (if (not arg)
4835 (gnus-kill-buffer buf)
4836 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4837 (gnus-kill-buffer buf)))))))
4840 ;;; Gnus MIME viewing functions
4843 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4844 "Format of the MIME buttons.
4846 Valid specifiers include:
4847 %t The MIME type
4848 %T MIME type, along with additional info
4849 %n The `name' parameter
4850 %d The description, if any
4851 %l The length of the encoded part
4852 %p The part identifier number
4853 %e Dots if the part isn't displayed
4855 General format specifiers can also be used. See Info node
4856 `(gnus)Formatting Variables'.")
4858 (defvar gnus-tmp-type)
4859 (defvar gnus-tmp-type-long)
4860 (defvar gnus-tmp-name)
4861 (defvar gnus-tmp-description)
4862 (defvar gnus-tmp-id)
4863 (defvar gnus-tmp-length)
4864 (defvar gnus-tmp-dots)
4865 (defvar gnus-tmp-info)
4866 (defvar gnus-tmp-pressed-details)
4868 (defvar gnus-mime-button-line-format-alist
4869 '((?t gnus-tmp-type ?s)
4870 (?T gnus-tmp-type-long ?s)
4871 (?n gnus-tmp-name ?s)
4872 (?d gnus-tmp-description ?s)
4873 (?p gnus-tmp-id ?s)
4874 (?l gnus-tmp-length ?d)
4875 (?e gnus-tmp-dots ?s)))
4877 (defvar gnus-mime-button-commands
4878 '((gnus-article-press-button "\r" "Toggle Display")
4879 (gnus-mime-view-part "v" "View Interactively...")
4880 (gnus-mime-view-part-as-type "t" "View As Type...")
4881 (gnus-mime-view-part-as-charset "C" "View As charset...")
4882 (gnus-mime-save-part "o" "Save...")
4883 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4884 (gnus-mime-replace-part "r" "Replace part")
4885 (gnus-mime-delete-part "d" "Delete part")
4886 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4887 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4888 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4889 (gnus-mime-view-part-externally "e" "View Externally")
4890 (gnus-mime-print-part "p" "Print")
4891 (gnus-mime-pipe-part "|" "Pipe To Command...")
4892 (gnus-mime-action-on-part "." "Take action on the part...")))
4894 (defun gnus-article-mime-part-status ()
4895 (if gnus-article-mime-handle-alist-1
4896 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4897 " (1 part)"
4898 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4899 ""))
4901 (defvar gnus-mime-button-map
4902 (let ((map (make-sparse-keymap)))
4903 (define-key map gnus-mouse-2 'gnus-article-push-button)
4904 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4905 (dolist (c gnus-mime-button-commands)
4906 (define-key map (cadr c) (car c)))
4907 map))
4909 (easy-menu-define
4910 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4911 `("MIME Part"
4912 ,@(mapcar (lambda (c)
4913 (vector (caddr c) (car c) :active t))
4914 gnus-mime-button-commands)))
4916 (defvar gnus-url-button-commands
4917 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4919 (defvar gnus-url-button-map
4920 (let ((map (make-sparse-keymap)))
4921 (dolist (c gnus-url-button-commands)
4922 (define-key map (cadr c) (car c)))
4923 map))
4925 (easy-menu-define
4926 gnus-url-button-menu gnus-url-button-map "URL button menu."
4927 `("Url Button"
4928 ,@(mapcar (lambda (c)
4929 (vector (caddr c) (car c) :active t))
4930 gnus-url-button-commands)))
4932 (defmacro gnus-bind-safe-url-regexp (&rest body)
4933 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4934 `(let ((mm-w3m-safe-url-regexp
4935 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4936 (gnus-buffer-live-p
4937 gnus-article-current-summary))
4938 (with-current-buffer gnus-article-current-summary
4939 gnus-newsgroup-name)
4940 gnus-newsgroup-name)))
4941 (if (cond ((not group)
4942 ;; Maybe we're in a mml-preview buffer
4943 ;; and no group is selected.
4945 ((stringp gnus-safe-html-newsgroups)
4946 (string-match gnus-safe-html-newsgroups group))
4947 ((consp gnus-safe-html-newsgroups)
4948 (member group gnus-safe-html-newsgroups)))
4950 mm-w3m-safe-url-regexp))))
4951 ,@body))
4953 (defun gnus-mime-button-menu (event prefix)
4954 "Construct a context-sensitive menu of MIME commands."
4955 (interactive "e\nP")
4956 (save-window-excursion
4957 (let ((pos (event-start event)))
4958 (select-window (posn-window pos))
4959 (goto-char (posn-point pos))
4960 (gnus-article-check-buffer)
4961 (popup-menu gnus-mime-button-menu nil prefix))))
4963 (defun gnus-mime-view-all-parts (&optional handles)
4964 "View all the MIME parts."
4965 (interactive)
4966 (with-current-buffer gnus-article-buffer
4967 (let ((handles (or handles gnus-article-mime-handles))
4968 (mail-parse-charset gnus-newsgroup-charset)
4969 (mail-parse-ignored-charsets
4970 (with-current-buffer gnus-summary-buffer
4971 gnus-newsgroup-ignored-charsets)))
4972 (when handles
4973 (mm-remove-parts handles)
4974 (goto-char (point-min))
4975 (or (search-forward "\n\n") (goto-char (point-max)))
4976 (let ((inhibit-read-only t))
4977 (delete-region (point) (point-max))
4978 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4980 (defun gnus-article-jump-to-part (n)
4981 "Jump to MIME part N."
4982 (interactive "P")
4983 (let ((parts (with-current-buffer gnus-article-buffer
4984 (length gnus-article-mime-handle-alist))))
4985 (when (zerop parts)
4986 (error "No such part"))
4987 (pop-to-buffer gnus-article-buffer)
4988 (or n
4989 (setq n (if (= parts 1)
4991 (read-number (format "Jump to part (1..%s): " parts)))))
4992 (unless (and (integerp n) (<= n parts) (>= n 1))
4993 (setq n
4994 (progn
4995 (gnus-message 7 "Invalid part `%s', using %s instead."
4996 n parts)
4997 parts)))
4998 (gnus-message 9 "Jumping to part %s." n)
4999 (cond ((>= gnus-auto-select-part 1)
5000 (while (and (<= n parts)
5001 (not (gnus-article-goto-part n)))
5002 (setq n (1+ n))))
5003 ((< gnus-auto-select-part 0)
5004 (while (and (>= n 1)
5005 (not (gnus-article-goto-part n)))
5006 (setq n (1- n))))
5008 (gnus-article-goto-part n)))))
5010 (defvar gnus-mime-buttonized-part-id nil
5011 "ID of a mime part that should be buttonized.
5012 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5014 (eval-when-compile
5015 (defsubst gnus-article-edit-part (handles &optional current-id)
5016 "Edit an article in order to delete a mime part.
5017 This function is exclusively used by `gnus-mime-save-part-and-strip'
5018 and `gnus-mime-delete-part', and not provided at run-time normally."
5019 (gnus-article-edit-article
5020 `(lambda ()
5021 (buffer-disable-undo)
5022 (let ((mail-parse-charset (or gnus-article-charset
5023 ',gnus-newsgroup-charset))
5024 (mail-parse-ignored-charsets
5025 (or gnus-article-ignored-charsets
5026 ',gnus-newsgroup-ignored-charsets))
5027 (mbl mml-buffer-list))
5028 (setq mml-buffer-list nil)
5029 ;; A new text must be inserted before deleting existing ones
5030 ;; at the end so as not to move existing markers of which
5031 ;; the insertion type is t.
5032 (delete-region
5033 (point-min)
5034 (prog1
5035 (goto-char (point-max))
5036 (insert-buffer-substring gnus-original-article-buffer)))
5037 (mime-to-mml ',handles)
5038 (setq gnus-article-mime-handles nil)
5039 (let ((mbl1 mml-buffer-list))
5040 (setq mml-buffer-list mbl)
5041 (set (make-local-variable 'mml-buffer-list) mbl1))
5042 (gnus-make-local-hook 'kill-buffer-hook)
5043 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5044 `(lambda (no-highlight)
5045 (let ((mail-parse-charset (or gnus-article-charset
5046 ',gnus-newsgroup-charset))
5047 (message-options message-options)
5048 (message-options-set-recipient)
5049 (mail-parse-ignored-charsets
5050 (or gnus-article-ignored-charsets
5051 ',gnus-newsgroup-ignored-charsets)))
5052 (mml-to-mime)
5053 (mml-destroy-buffers)
5054 (remove-hook 'kill-buffer-hook
5055 'mml-destroy-buffers t)
5056 (kill-local-variable 'mml-buffer-list))
5057 (gnus-summary-edit-article-done
5058 ,(or (mail-header-references gnus-current-headers) "")
5059 ,(gnus-group-read-only-p)
5060 ,gnus-summary-buffer no-highlight))
5062 ;; Force buttonizing this part.
5063 (let ((gnus-mime-buttonized-part-id current-id))
5064 (gnus-article-edit-done))
5065 (gnus-configure-windows 'article)
5066 (sit-for 0)
5067 (when (and current-id (integerp gnus-auto-select-part))
5068 (gnus-article-jump-to-part
5069 (min (max (+ current-id gnus-auto-select-part) 1)
5070 (with-current-buffer gnus-article-buffer
5071 (length gnus-article-mime-handle-alist)))))))
5073 (defun gnus-mime-replace-part (file)
5074 "Replace MIME part under point with an external body."
5075 ;; Useful if file has already been saved to disk
5076 (interactive
5077 (list
5078 (read-file-name "Replace MIME part with file: "
5079 (or mm-default-directory default-directory)
5080 nil nil)))
5081 (gnus-mime-save-part-and-strip file))
5083 (defun gnus-mime-save-part-and-strip (&optional file)
5084 "Save the MIME part under point then replace it with an external body.
5085 If FILE is given, use it for the external part."
5086 (interactive)
5087 (gnus-article-check-buffer)
5088 (when (gnus-group-read-only-p)
5089 (error "The current group does not support deleting of parts"))
5090 (when (mm-complicated-handles gnus-article-mime-handles)
5091 (error "\
5092 The current article has a complicated MIME structure, giving up..."))
5093 (let* ((data (get-text-property (point) 'gnus-data))
5094 (id (get-text-property (point) 'gnus-part))
5095 (handles gnus-article-mime-handles))
5096 (unless file
5097 (setq file
5098 (and data (mm-save-part data "Delete MIME part and save to: "))))
5099 (when file
5100 (with-current-buffer (mm-handle-buffer data)
5101 (erase-buffer)
5102 (insert "Content-Type: " (mm-handle-media-type data))
5103 (mml-insert-parameter-string (cdr (mm-handle-type data))
5104 '(charset))
5105 ;; Add a filename for the sake of saving the part again.
5106 (mml-insert-parameter
5107 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5108 (insert "\n")
5109 (insert "Content-ID: " (message-make-message-id) "\n")
5110 (insert "Content-Transfer-Encoding: binary\n")
5111 (insert "\n"))
5112 (setcdr data
5113 (cdr (mm-make-handle nil
5114 `("message/external-body"
5115 (access-type . "LOCAL-FILE")
5116 (name . ,file)))))
5117 ;; (set-buffer gnus-summary-buffer)
5118 (gnus-article-edit-part handles id))))
5120 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5121 ;; parts...>') but with stripping would be nice.
5123 (defun gnus-mime-delete-part ()
5124 "Delete the MIME part under point.
5125 Replace it with some information about the removed part."
5126 (interactive)
5127 (gnus-article-check-buffer)
5128 (when (gnus-group-read-only-p)
5129 (error "The current group does not support deleting of parts"))
5130 (when (mm-complicated-handles gnus-article-mime-handles)
5131 (error "\
5132 The current article has a complicated MIME structure, giving up..."))
5133 (when (or gnus-expert-user
5134 (gnus-yes-or-no-p "\
5135 Deleting parts may malfunction or destroy the article; continue? "))
5136 (let* ((data (get-text-property (point) 'gnus-data))
5137 (id (get-text-property (point) 'gnus-part))
5138 (handles gnus-article-mime-handles)
5139 (description
5140 (let ((desc (mm-handle-description data)))
5141 (when desc
5142 (mail-decode-encoded-word-string desc))))
5143 (filename (or (mm-handle-filename data) "(none)"))
5144 (type (mm-handle-media-type data)))
5145 (unless data
5146 (error "No MIME part under point"))
5147 (with-current-buffer (mm-handle-buffer data)
5148 (let ((bsize (buffer-size)))
5149 (erase-buffer)
5150 (insert
5151 (concat
5152 ",----\n"
5153 "| The following attachment has been deleted:\n"
5154 "|\n"
5155 "| Type: " type "\n"
5156 "| Filename: " filename "\n"
5157 "| Size (encoded): " (format "%s byte%s\n"
5158 bsize (if (= bsize 1)
5160 "s"))
5161 (when description
5162 (concat "| Description: " description "\n"))
5163 "`----\n"))
5164 (setcdr data
5165 (cdr (mm-make-handle
5166 nil `("text/plain" (charset . gnus-decoded)) nil nil
5167 (list "attachment")
5168 (format "Deleted attachment (%s bytes)" bsize))))))
5169 ;; (set-buffer gnus-summary-buffer)
5170 (gnus-article-edit-part handles id))))
5172 (defun gnus-mime-save-part ()
5173 "Save the MIME part under point."
5174 (interactive)
5175 (gnus-article-check-buffer)
5176 (let ((data (get-text-property (point) 'gnus-data)))
5177 (when data
5178 (mm-save-part data))))
5180 (defun gnus-mime-pipe-part (&optional cmd)
5181 "Pipe the MIME part under point to a process.
5182 Use CMD as the process."
5183 (interactive)
5184 (gnus-article-check-buffer)
5185 (let ((data (get-text-property (point) 'gnus-data)))
5186 (when data
5187 (mm-pipe-part data cmd))))
5189 (defun gnus-mime-view-part ()
5190 "Interactively choose a viewing method for the MIME part under point."
5191 (interactive)
5192 (gnus-article-check-buffer)
5193 (let ((data (get-text-property (point) 'gnus-data)))
5194 (when data
5195 (setq gnus-article-mime-handles
5196 (mm-merge-handles
5197 gnus-article-mime-handles (setq data (copy-sequence data))))
5198 (mm-interactively-view-part data))))
5200 (defun gnus-mime-view-part-as-type-internal ()
5201 (gnus-article-check-buffer)
5202 (let* ((handle (get-text-property (point) 'gnus-data))
5203 (name (or
5204 ;; Content-Type: foo/bar; name=...
5205 (mail-content-type-get (mm-handle-type handle) 'name)
5206 ;; Content-Disposition: attachment; filename=...
5207 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5208 (def-type (and name (mm-default-file-encoding name))))
5209 (or (and def-type (cons def-type 0))
5210 (and handle
5211 (equal (mm-handle-media-supertype handle) "text")
5212 '("text/plain" . 0))
5213 '("application/octet-stream" . 0))))
5215 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5216 "Choose a MIME media type, and view the part as such.
5217 If non-nil, PRED is a predicate to use during completion to limit the
5218 available media-types."
5219 (interactive)
5220 (unless mime-type
5221 (setq mime-type
5222 (let ((default (gnus-mime-view-part-as-type-internal)))
5223 (gnus-completing-read
5224 "View as MIME type"
5225 (if pred
5226 (gnus-remove-if-not pred (mailcap-mime-types))
5227 (mailcap-mime-types))
5228 nil nil nil
5229 (car default)))))
5230 (gnus-article-check-buffer)
5231 (let ((handle (get-text-property (point) 'gnus-data)))
5232 (when handle
5233 (when (equal (mm-handle-media-type handle) "message/external-body")
5234 (unless (mm-handle-cache handle)
5235 (mm-extern-cache-contents handle))
5236 (setq handle (mm-handle-cache handle)))
5237 (setq handle
5238 (mm-make-handle (mm-handle-buffer handle)
5239 (cons mime-type (cdr (mm-handle-type handle)))
5240 (mm-handle-encoding handle)
5241 (mm-handle-undisplayer handle)
5242 (mm-handle-disposition handle)
5243 (mm-handle-description handle)
5245 (mm-handle-id handle)))
5246 (setq gnus-article-mime-handles
5247 (mm-merge-handles gnus-article-mime-handles handle))
5248 (when (mm-handle-displayed-p handle)
5249 (mm-remove-part handle))
5250 (gnus-mm-display-part handle))))
5252 (defun gnus-mime-copy-part (&optional handle arg)
5253 "Put the MIME part under point into a new buffer.
5254 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5255 are decompressed."
5256 (interactive (list nil current-prefix-arg))
5257 (gnus-article-check-buffer)
5258 (unless handle
5259 (setq handle (get-text-property (point) 'gnus-data)))
5260 (when handle
5261 (let ((filename (mm-handle-filename handle))
5262 contents dont-decode charset coding-system)
5263 (mm-with-unibyte-buffer
5264 (mm-insert-part handle)
5265 (setq contents (or (condition-case nil
5266 (mm-decompress-buffer filename nil 'sig)
5267 (error
5268 (setq dont-decode t)
5269 nil))
5270 (buffer-string))))
5271 (setq filename (cond (filename (file-name-nondirectory filename))
5272 (dont-decode "*raw data*")
5273 (t "*decoded*")))
5274 (cond
5275 (dont-decode)
5276 ((not arg)
5277 (unless (setq charset (mail-content-type-get
5278 (mm-handle-type handle) 'charset))
5279 (unless (setq coding-system (mm-with-unibyte-buffer
5280 (insert contents)
5281 (mm-find-buffer-file-coding-system)))
5282 (setq charset gnus-newsgroup-charset))))
5283 ((numberp arg)
5284 (setq charset (or (cdr (assq arg
5285 gnus-summary-show-article-charset-alist))
5286 (mm-read-coding-system "Charset: ")))))
5287 (switch-to-buffer (generate-new-buffer filename))
5288 (if (or coding-system
5289 (and charset
5290 (setq coding-system (mm-charset-to-coding-system
5291 charset nil t))
5292 (not (eq coding-system 'ascii))))
5293 (progn
5294 (mm-enable-multibyte)
5295 (insert (mm-decode-coding-string contents coding-system))
5296 (setq buffer-file-coding-system
5297 (if (boundp 'last-coding-system-used)
5298 (symbol-value 'last-coding-system-used)
5299 coding-system)))
5300 (mm-disable-multibyte)
5301 (insert contents)
5302 (setq buffer-file-coding-system mm-binary-coding-system))
5303 ;; We do it this way to make `normal-mode' set the appropriate mode.
5304 (unwind-protect
5305 (progn
5306 (setq buffer-file-name (expand-file-name filename))
5307 (normal-mode))
5308 (setq buffer-file-name nil))
5309 (goto-char (point-min)))))
5311 (defun gnus-mime-print-part (&optional handle filename)
5312 "Print the MIME part under point."
5313 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5314 (gnus-article-check-buffer)
5315 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5316 (contents (and handle (mm-get-part handle)))
5317 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5318 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5319 (when contents
5320 (if printer
5321 (unwind-protect
5322 (progn
5323 (mm-save-part-to-file handle file)
5324 (call-process shell-file-name nil
5325 (generate-new-buffer " *mm*")
5327 shell-command-switch
5328 (mm-mailcap-command
5329 printer file (mm-handle-type handle))))
5330 (delete-file file))
5331 (with-temp-buffer
5332 (insert contents)
5333 (gnus-print-buffer))
5334 (ps-despool filename)))))
5336 (defun gnus-mime-inline-part (&optional handle arg)
5337 "Insert the MIME part under point into the current buffer.
5338 Compressed files like .gz and .bz2 are decompressed."
5339 (interactive (list nil current-prefix-arg))
5340 (gnus-article-check-buffer)
5341 (let* ((inhibit-read-only t)
5342 (b (point))
5343 (btn ;; position where the MIME button exists
5344 (if handle
5345 (if (eq handle (get-text-property b 'gnus-data))
5347 (article-goto-body)
5348 (or (text-property-any (point) (point-max) 'gnus-data handle)
5349 (text-property-any (point-min) (point) 'gnus-data handle)))
5350 (setq handle (get-text-property b 'gnus-data))
5352 start)
5353 (when handle
5354 (when (= b (prog1
5356 (setq start (next-single-property-change btn 'gnus-data
5357 nil (point-max))
5358 btn (previous-single-property-change start
5359 'gnus-data))))
5360 (setq b btn))
5361 (if (and (not arg) (mm-handle-undisplayer handle))
5362 (progn
5363 (setq b (copy-marker b)
5364 btn (copy-marker btn))
5365 (mm-remove-part handle))
5366 (cond
5367 ((not arg) nil)
5368 ((numberp arg)
5369 (if (mm-handle-undisplayer handle)
5370 (mm-remove-part handle)))
5371 ((mm-handle-undisplayer handle)
5372 (mm-remove-part handle)))
5373 (goto-char start)
5374 (unless (bolp)
5375 ;; This is a header button.
5376 (forward-line 1))
5377 (mm-display-inline handle))
5378 ;; Toggle the button appearance between `[button]...' and `[button]'.
5379 (when (markerp btn)
5380 (setq btn (prog1 (marker-position btn)
5381 (set-marker btn nil))))
5382 (goto-char btn)
5383 (let ((displayed-p (mm-handle-displayed-p handle)))
5384 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5385 (list displayed-p))
5386 (if (featurep 'emacs)
5387 (delete-region
5388 (point)
5389 (next-single-property-change (point) 'gnus-data nil (point-max)))
5390 (let* ((end (next-single-property-change (point) 'gnus-data))
5391 (annots (annotations-at (or end (point-max)))))
5392 (delete-region (point)
5393 (if end
5394 (if annots (1+ end) end)
5395 (point-max)))
5396 (dolist (annot annots)
5397 (set-extent-endpoints annot (point) (point)))))
5398 (setq start (point))
5399 (if (search-backward "\n\n" nil t)
5400 (progn
5401 (goto-char start)
5402 (unless (or displayed-p (eolp))
5403 ;; Add extra newline.
5404 (insert (propertize (buffer-substring (1- start) start)
5405 'gnus-undeletable t))))
5406 ;; We're in the article header.
5407 (delete-char -1)
5408 (dolist (ovl (overlays-in btn (point)))
5409 (overlay-put ovl 'gnus-button-attachment-extra t)
5410 (overlay-put ovl 'face nil))
5411 (save-restriction
5412 (message-narrow-to-field)
5413 (let ((gnus-treatment-function-alist
5414 '((gnus-treat-highlight-headers
5415 gnus-article-highlight-headers))))
5416 (gnus-treat-article 'head)))))
5417 (when (markerp b)
5418 (setq b (prog1 (marker-position b)
5419 (set-marker b nil))))
5420 (goto-char b))))
5422 (defun gnus-mime-set-charset-parameters (handle charset)
5423 "Set CHARSET to parameters in HANDLE.
5424 CHARSET may either be a string or a symbol."
5425 (unless (stringp charset)
5426 (setq charset (symbol-name charset)))
5427 (if (stringp (car handle))
5428 (dolist (h (cdr handle))
5429 (gnus-mime-set-charset-parameters h charset))
5430 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5431 "message/external-body")
5432 (progn
5433 (unless (mm-handle-cache handle)
5434 (mm-extern-cache-contents handle))
5435 (mm-handle-cache handle))
5436 handle)))
5437 (param (assq 'charset (cdr type))))
5438 (if param
5439 (setcdr param charset)
5440 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5442 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5443 "Insert the MIME part under point into the current buffer using the
5444 specified charset."
5445 (interactive (list nil current-prefix-arg))
5446 (gnus-article-check-buffer)
5447 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5448 (fun (get-text-property (point) 'gnus-callback))
5449 (gnus-newsgroup-ignored-charsets 'gnus-all)
5450 charset form preferred parts)
5451 (when handle
5452 (when (prog1
5453 (and fun
5454 (setq charset
5455 (or (cdr (assq
5457 gnus-summary-show-article-charset-alist))
5458 (mm-read-coding-system "Charset: "))))
5459 (if (mm-handle-undisplayer handle)
5460 (mm-remove-part handle)))
5461 (gnus-mime-set-charset-parameters handle charset)
5462 (when (and (consp (setq form (cdr-safe fun)))
5463 (setq form (ignore-errors
5464 (assq 'gnus-mime-display-alternative form)))
5465 (setq preferred (caddr form))
5466 (progn
5467 (when (eq (car preferred) 'quote)
5468 (setq preferred (cadr preferred)))
5469 (not (equal preferred
5470 (get-text-property (point) 'gnus-data))))
5471 (setq parts (get-text-property (point) 'gnus-part))
5472 (setq parts (cdr (assq parts
5473 gnus-article-mime-handle-alist)))
5474 (equal (mm-handle-media-type parts) "multipart/alternative")
5475 (setq parts (reverse (cdr parts))))
5476 (setcar (cddr form)
5477 (list 'quote (or (cadr (member preferred parts))
5478 (car parts)))))
5479 (funcall fun handle)))))
5481 (defun gnus-mime-view-part-externally (&optional handle)
5482 "View the MIME part under point with an external viewer."
5483 (interactive)
5484 (gnus-article-check-buffer)
5485 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5486 (mm-inlined-types nil)
5487 (mail-parse-charset gnus-newsgroup-charset)
5488 (mail-parse-ignored-charsets
5489 (with-current-buffer gnus-summary-buffer
5490 gnus-newsgroup-ignored-charsets))
5491 (type (mm-handle-media-type handle))
5492 (method (mailcap-mime-info type))
5493 (mm-enable-external t))
5494 (if (not (stringp method))
5495 (gnus-mime-view-part-as-type
5496 nil (lambda (type) (stringp (mailcap-mime-info type))))
5497 (when handle
5498 (mm-display-part handle nil t)))))
5500 (defun gnus-mime-view-part-internally (&optional handle)
5501 "View the MIME part under point with an internal viewer.
5502 If no internal viewer is available, use an external viewer."
5503 (interactive)
5504 (gnus-article-check-buffer)
5505 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5506 (mm-inlined-types '(".*"))
5507 (mm-inline-large-images t)
5508 (mail-parse-charset gnus-newsgroup-charset)
5509 (mail-parse-ignored-charsets
5510 (with-current-buffer gnus-summary-buffer
5511 gnus-newsgroup-ignored-charsets))
5512 (inhibit-read-only t))
5513 (if (not (mm-inlinable-p handle))
5514 (gnus-mime-view-part-as-type
5515 nil (lambda (type) (mm-inlinable-p handle type)))
5516 (when handle
5517 (gnus-bind-safe-url-regexp
5518 (mm-display-part handle nil t))))))
5520 (defun gnus-mime-action-on-part (&optional action)
5521 "Do something with the MIME attachment at (point)."
5522 (interactive
5523 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5524 (gnus-article-check-buffer)
5525 (let ((action-pair (assoc action gnus-mime-action-alist)))
5526 (if action-pair
5527 (funcall (cdr action-pair)))))
5529 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5530 "Call FUNCTION on MIME part N.
5531 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5532 If INTERACTIVE, call FUNCTION interactively."
5533 (let (window frame)
5534 ;; Check whether the article is displayed.
5535 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5536 (setq window (get-buffer-window gnus-article-buffer t))
5537 (frame-visible-p (setq frame (window-frame window))))
5538 (error "No article is displayed"))
5539 (with-current-buffer gnus-article-buffer
5540 ;; Check whether the article displays the right contents.
5541 (unless (with-current-buffer gnus-summary-buffer
5542 (eq gnus-current-article (gnus-summary-article-number)))
5543 (error "You should select the right article first"))
5544 (if n
5545 (setq n (prefix-numeric-value n))
5546 (let ((pt (point)))
5547 (setq n (or (get-text-property pt 'gnus-part)
5548 (and (not (bobp))
5549 (get-text-property (1- pt) 'gnus-part))
5550 (get-text-property (prog2
5551 (forward-line 1)
5552 (point)
5553 (goto-char pt))
5554 'gnus-part)
5555 (get-text-property
5556 (or (and (setq pt (previous-single-property-change
5557 pt 'gnus-part))
5558 (1- pt))
5559 (next-single-property-change (point) 'gnus-part)
5560 (point))
5561 'gnus-part)
5562 1))))
5563 ;; Check whether the specified part exists.
5564 (when (> n (length gnus-article-mime-handle-alist))
5565 (error "No such part")))
5566 (unless
5567 (progn
5568 ;; To select the window is needed so that the cursor
5569 ;; might be visible on the MIME button.
5570 (select-window (prog1
5571 window
5572 (setq window (selected-window))
5573 ;; Article may be displayed in the other frame.
5574 (gnus-select-frame-set-input-focus
5575 (prog1
5576 frame
5577 (setq frame (selected-frame))))))
5578 (when (gnus-article-goto-part n)
5579 ;; We point the cursor and the arrow at the MIME button
5580 ;; when the `function' prompt the user for something.
5581 (unless (and (pos-visible-in-window-p)
5582 (> (count-lines (point) (window-end))
5583 (/ (1- (window-height)) 3)))
5584 (recenter (/ (1- (window-height)) 3)))
5585 (let ((cursor-in-non-selected-windows t)
5586 (overlay-arrow-string "=>")
5587 (overlay-arrow-position (point-marker)))
5588 (unwind-protect
5589 (cond
5590 ((and no-handle interactive)
5591 (call-interactively function))
5592 (no-handle
5593 (funcall function))
5594 (interactive
5595 (call-interactively
5596 function (get-text-property (point) 'gnus-data)))
5598 (funcall function
5599 (get-text-property (point) 'gnus-data))))
5600 (set-marker overlay-arrow-position nil)
5601 (unless gnus-auto-select-part
5602 (gnus-select-frame-set-input-focus frame)
5603 (select-window window))))
5605 (if gnus-inhibit-mime-unbuttonizing
5606 ;; This is the default though the program shouldn't reach here.
5607 (error "No such part")
5608 ;; The part which doesn't have the MIME button is selected.
5609 ;; So, we display all the buttons and redo it.
5610 (let ((gnus-inhibit-mime-unbuttonizing t))
5611 (gnus-summary-show-article)
5612 (gnus-article-part-wrapper n function no-handle))))))
5614 (defun gnus-article-pipe-part (n)
5615 "Pipe MIME part N, which is the numerical prefix."
5616 (interactive "P")
5617 (gnus-article-part-wrapper n 'mm-pipe-part))
5619 (defun gnus-article-save-part (n)
5620 "Save MIME part N, which is the numerical prefix."
5621 (interactive "P")
5622 (gnus-article-part-wrapper n 'mm-save-part))
5624 (defun gnus-article-interactively-view-part (n)
5625 "View MIME part N interactively, which is the numerical prefix."
5626 (interactive "P")
5627 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5629 (defun gnus-article-copy-part (n)
5630 "Copy MIME part N, which is the numerical prefix."
5631 (interactive "P")
5632 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5634 (defun gnus-article-view-part-as-charset (n)
5635 "View MIME part N using a specified charset.
5636 N is the numerical prefix."
5637 (interactive "P")
5638 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5640 (defun gnus-article-view-part-externally (n)
5641 "View MIME part N externally, which is the numerical prefix."
5642 (interactive "P")
5643 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5645 (defun gnus-article-inline-part (n)
5646 "Inline MIME part N, which is the numerical prefix."
5647 (interactive "P")
5648 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5650 (defun gnus-article-save-part-and-strip (n)
5651 "Save MIME part N and replace it with an external body.
5652 N is the numerical prefix."
5653 (interactive "P")
5654 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5656 (defun gnus-article-replace-part (n)
5657 "Replace MIME part N with an external body.
5658 N is the numerical prefix."
5659 (interactive "P")
5660 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5662 (defun gnus-article-delete-part (n)
5663 "Delete MIME part N and add some information about the removed part.
5664 N is the numerical prefix."
5665 (interactive "P")
5666 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5668 (defun gnus-article-view-part-as-type (n)
5669 "Choose a MIME media type, and view part N as such.
5670 N is the numerical prefix."
5671 (interactive "P")
5672 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5674 (defun gnus-article-mime-match-handle-first (condition)
5675 (if condition
5676 (let (n)
5677 (dolist (ihandle gnus-article-mime-handle-alist)
5678 (if (and (cond
5679 ((functionp condition)
5680 (funcall condition (cdr ihandle)))
5681 ((eq condition 'undisplayed)
5682 (not (or (mm-handle-undisplayer (cdr ihandle))
5683 (equal (mm-handle-media-type (cdr ihandle))
5684 "multipart/alternative"))))
5685 ((eq condition 'undisplayed-alternative)
5686 (not (mm-handle-undisplayer (cdr ihandle))))
5687 (t t))
5688 (gnus-article-goto-part (car ihandle))
5689 (or (not n) (< (car ihandle) n)))
5690 (setq n (car ihandle))))
5691 (or n 1))
5694 (defun gnus-article-view-part (&optional n)
5695 "View MIME part N, which is the numerical prefix.
5696 If the part is already shown, hide the part. If N is nil, view
5697 all parts."
5698 (interactive "P")
5699 (with-current-buffer gnus-article-buffer
5700 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5701 gnus-article-mime-match-handle-function)))
5702 (when (> n (length gnus-article-mime-handle-alist))
5703 (error "No such part"))
5704 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5705 (when (gnus-article-goto-part n)
5706 (if (equal (car handle) "multipart/alternative")
5707 (progn
5708 (beginning-of-line) ;; Make it toggle subparts
5709 (gnus-article-press-button))
5710 (when (eq (gnus-mm-display-part handle) 'internal)
5711 (gnus-set-window-start)))))))
5713 (defsubst gnus-article-mime-total-parts ()
5714 (if (bufferp (car gnus-article-mime-handles))
5715 1 ;; single part
5716 (1- (length gnus-article-mime-handles))))
5718 (defun gnus-mm-display-part (handle)
5719 "Display HANDLE and fix MIME button."
5720 (let ((id (get-text-property (point) 'gnus-part))
5721 (point (point))
5722 (inhibit-read-only t)
5723 (window (selected-window))
5724 (mail-parse-charset gnus-newsgroup-charset)
5725 (mail-parse-ignored-charsets
5726 (if (gnus-buffer-live-p gnus-summary-buffer)
5727 (with-current-buffer gnus-summary-buffer
5728 gnus-newsgroup-ignored-charsets)
5729 nil))
5730 start retval)
5731 (unwind-protect
5732 (progn
5733 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5734 (when win
5735 (select-window win)
5736 (goto-char point)))
5737 (setq start (next-single-property-change point 'gnus-data
5738 nil (point-max))
5739 point (previous-single-property-change start 'gnus-data))
5740 (if (mm-handle-displayed-p handle)
5741 ;; This will remove the part.
5742 (setq point (copy-marker point)
5743 retval (mm-display-part handle))
5744 (let ((part (or (and (mm-inlinable-p handle)
5745 (mm-inlined-p handle)
5747 (with-temp-buffer
5748 (gnus-bind-safe-url-regexp
5749 (setq retval (mm-display-part handle)))
5750 (unless (zerop (buffer-size))
5751 (buffer-string))))))
5752 (goto-char start)
5753 (unless (bolp)
5754 ;; This is a header button.
5755 (forward-line 1))
5756 (cond ((stringp part)
5757 (save-restriction
5758 (narrow-to-region (point)
5759 (progn
5760 (insert part)
5761 (unless (bolp) (insert "\n"))
5762 (point)))
5763 (gnus-treat-article nil id
5764 (gnus-article-mime-total-parts)
5765 (mm-handle-media-type handle))
5766 (mm-handle-set-undisplayer
5767 handle
5768 `(lambda ()
5769 (let ((inhibit-read-only t))
5770 (delete-region ,(copy-marker (point-min) t)
5771 ,(point-max-marker)))))))
5772 (part
5773 (mm-display-inline handle))))))
5774 (when (markerp point)
5775 (setq point (prog1 (marker-position point)
5776 (set-marker point nil))))
5777 (goto-char point)
5778 ;; Toggle the button appearance between `[button]...' and `[button]'.
5779 (let ((displayed-p (mm-handle-displayed-p handle)))
5780 (gnus-insert-mime-button handle id (list displayed-p))
5781 (if (featurep 'emacs)
5782 (delete-region
5783 (point)
5784 (next-single-property-change (point) 'gnus-data nil (point-max)))
5785 (let* ((end (next-single-property-change (point) 'gnus-data))
5786 (annots (annotations-at (or end (point-max)))))
5787 (delete-region (point)
5788 (if end
5789 (if annots (1+ end) end)
5790 (point-max)))
5791 (dolist (annot annots)
5792 (set-extent-endpoints annot (point) (point)))))
5793 (setq start (point))
5794 (if (search-backward "\n\n" nil t)
5795 (progn
5796 (goto-char start)
5797 (unless (or displayed-p (eolp))
5798 ;; Add extra newline.
5799 (insert (propertize (buffer-substring (1- start) start)
5800 'gnus-undeletable t))))
5801 ;; We're in the article header.
5802 (delete-char -1)
5803 (dolist (ovl (overlays-in point (point)))
5804 (overlay-put ovl 'gnus-button-attachment-extra t)
5805 (overlay-put ovl 'face nil))
5806 (save-restriction
5807 (message-narrow-to-field)
5808 (let ((gnus-treatment-function-alist
5809 '((gnus-treat-highlight-headers
5810 gnus-article-highlight-headers))))
5811 (gnus-treat-article 'head)))))
5812 (goto-char point)
5813 (if (window-live-p window)
5814 (select-window window)))
5815 retval))
5817 (defun gnus-article-goto-part (n)
5818 "Go to MIME part N."
5819 (when gnus-break-pages
5820 (widen))
5821 (article-goto-body)
5822 (prog1
5823 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5824 ;; There may be header buttons.
5825 (text-property-any (point-min) (point) 'gnus-part n)))
5826 part handle end next handles)
5827 (when start
5828 (goto-char start)
5829 (if (setq handle (get-text-property start 'gnus-data))
5830 start
5831 ;; Go to the displayed subpart, assuming this is
5832 ;; multipart/alternative.
5833 (setq part start
5834 end (point-at-eol))
5835 (while (and (not handle)
5836 part
5837 (< part end)
5838 (setq next (text-property-not-all part end
5839 'gnus-data nil)))
5840 (setq part next
5841 handle (get-text-property part 'gnus-data))
5842 (push (cons handle part) handles)
5843 (unless (mm-handle-displayed-p handle)
5844 (setq handle nil
5845 part (text-property-any part end 'gnus-data nil))))
5846 (unless handle
5847 ;; No subpart is displayed, so we find preferred one.
5848 (setq part
5849 (cdr (assq (mm-preferred-alternative
5850 (nreverse (mapcar 'car handles)))
5851 handles))))
5852 (if part
5853 (goto-char (1+ part))
5854 start))))
5855 (when gnus-break-pages
5856 (gnus-narrow-to-page))))
5858 (defun gnus-insert-mime-button (handle id &optional displayed)
5859 (let ((gnus-tmp-name
5860 (or (mm-handle-filename handle)
5861 (mail-content-type-get (mm-handle-type handle) 'url)
5862 ""))
5863 (gnus-tmp-id id)
5864 (gnus-tmp-type (mm-handle-media-type handle))
5865 (gnus-tmp-description (or (mm-handle-description handle) ""))
5866 (gnus-tmp-dots
5867 (if (if displayed (car displayed)
5868 (mm-handle-displayed-p handle))
5869 "" "..."))
5870 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5871 (buffer-size)))
5872 gnus-tmp-type-long b e)
5873 (when (string-match ".*/" gnus-tmp-name)
5874 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5875 (setq gnus-tmp-type-long (concat gnus-tmp-type
5876 (and (not (equal gnus-tmp-name ""))
5877 (concat "; " gnus-tmp-name))))
5878 (unless (equal gnus-tmp-description "")
5879 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5880 (setq b (point))
5881 (gnus-eval-format
5882 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5883 `(keymap ,gnus-mime-button-map
5884 gnus-callback gnus-mm-display-part
5885 gnus-part ,gnus-tmp-id
5886 article-type annotation
5887 gnus-data ,handle
5888 rear-nonsticky t))
5889 (setq e (if (bolp)
5890 ;; Exclude a newline.
5891 (1- (point))
5892 (point)))
5893 (when gnus-article-button-face
5894 (overlay-put (make-overlay b e nil t)
5895 'face gnus-article-button-face))
5896 (widget-convert-button
5897 'link b e
5898 :mime-handle handle
5899 :action 'gnus-widget-press-button
5900 :button-keymap gnus-mime-button-map
5901 :help-echo
5902 (lambda (widget)
5903 ;; Needed to properly clear the message due to a bug in
5904 ;; wid-edit (XEmacs only).
5905 (if (boundp 'help-echo-owns-message)
5906 (setq help-echo-owns-message t))
5907 (format
5908 "%S: %s the MIME part; %S: more options"
5909 (aref gnus-mouse-2 0)
5910 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5911 "hide" "show")
5912 (aref gnus-down-mouse-3 0))))))
5914 (defun gnus-widget-press-button (elems _el)
5915 (goto-char (widget-get elems :from))
5916 (gnus-article-press-button))
5918 (defvar gnus-displaying-mime nil)
5920 (defun gnus-display-mime (&optional ihandles)
5921 "Display the MIME parts."
5922 (save-excursion
5923 (save-selected-window
5924 (let ((window (get-buffer-window gnus-article-buffer))
5925 (point (point)))
5926 (when window
5927 (select-window window)
5928 ;; We have to do this since selecting the window
5929 ;; may change the point. So we set the window point.
5930 (set-window-point window point)))
5931 (let ((handles ihandles)
5932 (inhibit-read-only t))
5933 (cond (handles)
5934 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5935 (when gnus-article-emulate-mime
5936 (mm-uu-dissect-text-parts handles)))
5937 (gnus-article-emulate-mime
5938 (setq handles (mm-uu-dissect))))
5939 (when (and (not ihandles)
5940 (not gnus-displaying-mime))
5941 ;; Top-level call; we clean up.
5942 (when gnus-article-mime-handles
5943 (mm-destroy-parts gnus-article-mime-handles)
5944 (setq gnus-article-mime-handle-alist nil));; A trick.
5945 (setq gnus-article-mime-handles handles)
5946 ;; We allow users to glean info from the handles.
5947 (when gnus-article-mime-part-function
5948 (gnus-mime-part-function handles)))
5949 (if (and handles
5950 (or (not (stringp (car handles)))
5951 (cdr handles)))
5952 (progn
5953 (when (and (not ihandles)
5954 (not gnus-displaying-mime))
5955 ;; Clean up for mime parts.
5956 (article-goto-body)
5957 (delete-region (point) (point-max)))
5958 (let ((gnus-displaying-mime t))
5959 (gnus-mime-display-part handles)))
5960 (save-restriction
5961 (article-goto-body)
5962 (narrow-to-region (point) (point-max))
5963 (gnus-treat-article nil 1 1 "text/plain")
5964 (widen)))
5965 (unless ihandles
5966 ;; Highlight the headers.
5967 (save-excursion
5968 (save-restriction
5969 (article-goto-body)
5970 (narrow-to-region (point-min) (point))
5971 (gnus-article-save-original-date
5972 (gnus-treat-article 'head)))))))
5973 ;; Cope with broken MIME messages.
5974 (goto-char (point-max))
5975 (unless (bolp)
5976 (insert "\n"))))
5978 (defcustom gnus-mime-display-multipart-as-mixed nil
5979 "Display \"multipart\" parts as \"multipart/mixed\".
5981 If t, it overrides nil values of
5982 `gnus-mime-display-multipart-alternative-as-mixed' and
5983 `gnus-mime-display-multipart-related-as-mixed'."
5984 :group 'gnus-article-mime
5985 :type 'boolean)
5987 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5988 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5989 :version "22.1"
5990 :group 'gnus-article-mime
5991 :type 'boolean)
5993 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5994 "Display \"multipart/related\" parts as \"multipart/mixed\".
5996 If displaying \"text/html\" is discouraged \(see
5997 `mm-discouraged-alternatives') images or other material inside a
5998 \"multipart/related\" part might be overlooked when this variable is nil."
5999 :version "22.1"
6000 :group 'gnus-article-mime
6001 :type 'boolean)
6003 (defcustom gnus-mime-display-attachment-buttons-in-header t
6004 "Add attachment buttons in the end of the header of an article.
6005 Since MIME attachments tend to be put at the end of an article, we may
6006 overlook them if there is a huge body. This option offers you a copy
6007 of all non-inlinable MIME parts as buttons shown in front of an article.
6008 If nil, don't show those extra buttons."
6009 :version "25.1"
6010 :group 'gnus-article-mime
6011 :type 'boolean)
6013 (defun gnus-mime-display-part (handle)
6014 (cond
6015 ;; Maybe a broken MIME message.
6016 ((null handle))
6017 ;; Single part.
6018 ((not (stringp (car handle)))
6019 (gnus-mime-display-single handle))
6020 ;; User-defined multipart
6021 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6022 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6023 handle))
6024 ;; multipart/alternative
6025 ((and (equal (car handle) "multipart/alternative")
6026 (not (or gnus-mime-display-multipart-as-mixed
6027 gnus-mime-display-multipart-alternative-as-mixed)))
6028 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6029 (push (cons id handle) gnus-article-mime-handle-alist)
6030 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6031 ;; multipart/related
6032 ((and (equal (car handle) "multipart/related")
6033 (not (or gnus-mime-display-multipart-as-mixed
6034 gnus-mime-display-multipart-related-as-mixed)))
6035 (gnus-mime-display-part (cadr handle)))
6036 ((equal (car handle) "multipart/signed")
6037 (gnus-add-wash-type 'signed)
6038 (gnus-mime-display-security handle))
6039 ((equal (car handle) "multipart/encrypted")
6040 (gnus-add-wash-type 'encrypted)
6041 (gnus-mime-display-security handle))
6042 ;; Other multiparts are handled like multipart/mixed.
6044 (gnus-mime-display-mixed (cdr handle)))))
6046 (defun gnus-mime-part-function (handles)
6047 (if (stringp (car handles))
6048 (mapcar 'gnus-mime-part-function (cdr handles))
6049 (funcall gnus-article-mime-part-function handles)))
6051 (defun gnus-mime-display-mixed (handles)
6052 (mapcar 'gnus-mime-display-part handles))
6054 (defun gnus-mime-display-single (handle)
6055 (let ((type (mm-handle-media-type handle))
6056 (ignored gnus-ignored-mime-types)
6057 (not-attachment t)
6058 display text)
6059 (catch 'ignored
6060 (progn
6061 (while ignored
6062 (when (string-match (pop ignored) type)
6063 (throw 'ignored nil)))
6064 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6065 (with-current-buffer gnus-summary-buffer
6066 gnus-inhibit-images)
6067 gnus-inhibit-images)
6068 (string-match "\\`image/" type)))
6069 (setq not-attachment
6070 (and (not (mm-inline-override-p handle))
6071 (or (not (mm-handle-disposition handle))
6072 (equal (car (mm-handle-disposition handle))
6073 "inline")
6074 (mm-attachment-override-p handle))))
6075 (mm-automatic-display-p handle)
6076 (or (and
6077 (mm-inlinable-p handle)
6078 (mm-inlined-p handle))
6079 (mm-automatic-external-display-p type)))
6080 (setq display t)
6081 (when (equal (mm-handle-media-supertype handle) "text")
6082 (setq text t)))
6083 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6084 beg)
6085 (unless id
6086 (setq id (1+ (length gnus-article-mime-handle-alist)))
6087 (push (cons id handle) gnus-article-mime-handle-alist))
6088 (when (and display
6089 (equal (mm-handle-media-supertype handle) "message"))
6090 (insert-char
6092 (cond ((not (bolp)) 2)
6093 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6094 (t 1))))
6095 (when (or (not display)
6096 (not (gnus-unbuttonized-mime-type-p type))
6097 (eq id gnus-mime-buttonized-part-id))
6098 (gnus-insert-mime-button
6099 handle id (list (or display (and not-attachment text)))))
6100 (setq beg (point))
6101 (cond
6102 (display
6103 (let ((mail-parse-charset gnus-newsgroup-charset)
6104 (mail-parse-ignored-charsets
6105 (save-excursion (condition-case ()
6106 (set-buffer gnus-summary-buffer)
6107 (error))
6108 gnus-newsgroup-ignored-charsets)))
6109 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6110 ((and text not-attachment)
6111 (mm-display-inline handle)))
6112 (goto-char (point-max))
6113 (if (string-match "\\`image/" type)
6114 (gnus-article-insert-newline)
6115 (if (prog1
6116 (= (skip-chars-backward "\n") -1)
6117 (unless (eobp) (forward-char 1)))
6118 (gnus-article-insert-newline)
6119 (put-text-property (point) (point-max) 'gnus-undeletable t))
6120 (goto-char (point-max)))
6121 ;; Do highlighting.
6122 (save-excursion
6123 (save-restriction
6124 (narrow-to-region beg (point))
6125 (if (eq handle gnus-article-mime-handles)
6126 ;; The format=flowed case.
6127 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6128 ;; Don't count signature parts that are never displayed.
6129 ;; The part number should be re-calculated supposing this
6130 ;; might be a message/rfc822 part.
6131 (let (handles)
6132 (dolist (part gnus-article-mime-handles)
6133 (unless (or (stringp part)
6134 (equal (car (mm-handle-type part))
6135 "application/pgp-signature"))
6136 (push part handles)))
6137 (gnus-treat-article
6138 nil (length (memq handle handles)) (length handles)
6139 (mm-handle-media-type handle)))))))))))
6141 (defun gnus-unbuttonized-mime-type-p (type)
6142 "Say whether TYPE is to be unbuttonized."
6143 (unless gnus-inhibit-mime-unbuttonizing
6144 (when (catch 'found
6145 (let ((types gnus-unbuttonized-mime-types))
6146 (while types
6147 (when (string-match (pop types) type)
6148 (throw 'found t)))))
6149 (not (catch 'found
6150 (let ((types gnus-buttonized-mime-types))
6151 (while types
6152 (when (string-match (pop types) type)
6153 (throw 'found t)))))))))
6155 (defun gnus-article-insert-newline ()
6156 "Insert a newline, but mark it as undeletable."
6157 (gnus-put-text-property
6158 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6160 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6161 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6162 (ihandles handles)
6163 (point (point))
6164 handle (inhibit-read-only t) from begend not-pref)
6165 (save-window-excursion
6166 (save-restriction
6167 (when ibegend
6168 (narrow-to-region (car ibegend)
6169 (or (cdr ibegend)
6170 (progn
6171 (goto-char (car ibegend))
6172 (forward-line 2)
6173 (point))))
6174 (delete-region (point-min) (point-max))
6175 (mm-remove-parts handles))
6176 (setq begend (list (point-marker)))
6177 ;; Do the toggle.
6178 (unless (setq not-pref (cadr (member preferred ihandles)))
6179 (setq not-pref (car ihandles)))
6180 (when (or ibegend
6181 (not preferred)
6182 (not (gnus-unbuttonized-mime-type-p
6183 "multipart/alternative")))
6184 (gnus-add-text-properties
6185 (setq from (point))
6186 (progn
6187 (insert (format "%d. " id))
6188 (point))
6189 `(gnus-callback
6190 (lambda (handles)
6191 (unless ,(not ibegend)
6192 (setq gnus-article-mime-handle-alist
6193 ',gnus-article-mime-handle-alist))
6194 (gnus-mime-display-alternative
6195 ',ihandles ',not-pref ',begend ,id))
6196 keymap ,gnus-mime-button-map
6197 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6198 face ,gnus-article-button-face
6199 gnus-part ,id
6200 article-type multipart
6201 rear-nonsticky t))
6202 (widget-convert-button 'link from (point)
6203 :action 'gnus-widget-press-button
6204 :button-keymap gnus-widget-button-keymap)
6205 ;; Do the handles
6206 (while (setq handle (pop handles))
6207 (gnus-add-text-properties
6208 (setq from (point))
6209 (progn
6210 (insert (format "(%c) %-18s"
6211 (if (equal handle preferred) ?* ? )
6212 (mm-handle-media-type handle)))
6213 (point))
6214 `(gnus-callback
6215 (lambda (handles)
6216 (unless ,(not ibegend)
6217 (setq gnus-article-mime-handle-alist
6218 ',gnus-article-mime-handle-alist))
6219 (gnus-mime-display-alternative
6220 ',ihandles ',handle ',begend ,id))
6221 keymap ,gnus-mime-button-map
6222 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6223 face ,gnus-article-button-face
6224 gnus-part ,id
6225 gnus-data ,handle
6226 rear-nonsticky t))
6227 (widget-convert-button 'link from (point)
6228 :action 'gnus-widget-press-button
6229 :button-keymap gnus-widget-button-keymap)
6230 (insert " "))
6231 (insert "\n\n"))
6232 (when preferred
6233 (if (stringp (car preferred))
6234 (gnus-display-mime preferred)
6235 (let ((mail-parse-charset gnus-newsgroup-charset)
6236 (mail-parse-ignored-charsets
6237 (with-current-buffer gnus-summary-buffer
6238 gnus-newsgroup-ignored-charsets)))
6239 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6240 ;; Do highlighting.
6241 (save-excursion
6242 (save-restriction
6243 (narrow-to-region (car begend) (point-max))
6244 (gnus-treat-article
6245 nil (length gnus-article-mime-handle-alist)
6246 (gnus-article-mime-total-parts)
6247 (mm-handle-media-type preferred))))))
6248 (goto-char (point-max))
6249 (setcdr begend (point-marker)))))
6250 (when ibegend
6251 (goto-char point)))
6252 ;; Redraw attachment buttons in the header.
6253 (when gnus-mime-display-attachment-buttons-in-header
6254 (gnus-mime-buttonize-attachments-in-header)))
6256 (defconst gnus-article-wash-status-strings
6257 (let ((alist '((cite "c" "Possible hidden citation text"
6258 " " "All citation text visible")
6259 (headers "h" "Hidden headers"
6260 " " "All headers visible.")
6261 (pgp "p" "Encrypted or signed message status hidden"
6262 " " "No hidden encryption nor digital signature status")
6263 (signature "s" "Signature has been hidden"
6264 " " "Signature is visible")
6265 (overstrike "o" "Overstrike (^H) characters applied"
6266 " " "No overstrike characters applied")
6267 (emphasis "e" "/*_Emphasis_*/ characters applied"
6268 " " "No /*_emphasis_*/ characters applied")))
6269 result)
6270 (dolist (entry alist result)
6271 (let ((key (nth 0 entry))
6272 (on (copy-sequence (nth 1 entry)))
6273 (on-help (nth 2 entry))
6274 (off (copy-sequence (nth 3 entry)))
6275 (off-help (nth 4 entry)))
6276 (put-text-property 0 1 'help-echo on-help on)
6277 (put-text-property 0 1 'help-echo off-help off)
6278 (push (list key on off) result))))
6279 "Alist of strings describing wash status in the mode line.
6280 Each entry has the form (KEY ON OF), where the KEY is a symbol
6281 representing the particular washing function, ON is the string to use
6282 in the article mode line when the washing function is active, and OFF
6283 is the string to use when it is inactive.")
6285 (defun gnus-article-wash-status-entry (key value)
6286 (let ((entry (assoc key gnus-article-wash-status-strings)))
6287 (if value (nth 1 entry) (nth 2 entry))))
6289 (defun gnus-article-wash-status ()
6290 "Return a string which display status of article washing."
6291 (with-current-buffer gnus-article-buffer
6292 (let ((cite (memq 'cite gnus-article-wash-types))
6293 (headers (memq 'headers gnus-article-wash-types))
6294 (boring (memq 'boring-headers gnus-article-wash-types))
6295 (pgp (memq 'pgp gnus-article-wash-types))
6296 (pem (memq 'pem gnus-article-wash-types))
6297 (signed (memq 'signed gnus-article-wash-types))
6298 (encrypted (memq 'encrypted gnus-article-wash-types))
6299 (signature (memq 'signature gnus-article-wash-types))
6300 (overstrike (memq 'overstrike gnus-article-wash-types))
6301 (emphasis (memq 'emphasis gnus-article-wash-types)))
6302 (concat
6303 (gnus-article-wash-status-entry 'cite cite)
6304 (gnus-article-wash-status-entry 'headers (or headers boring))
6305 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6306 (gnus-article-wash-status-entry 'signature signature)
6307 (gnus-article-wash-status-entry 'overstrike overstrike)
6308 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6310 (defun gnus-add-wash-type (type)
6311 "Add a washing of TYPE to the current status."
6312 (add-to-list 'gnus-article-wash-types type))
6314 (defun gnus-delete-wash-type (type)
6315 "Add a washing of TYPE to the current status."
6316 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6318 (defun gnus-add-image (category image)
6319 "Add IMAGE of CATEGORY to the list of displayed images."
6320 (let ((entry (assq category gnus-article-image-alist)))
6321 (unless entry
6322 (setq entry (list category))
6323 (push entry gnus-article-image-alist))
6324 (nconc entry (list image))))
6326 (defun gnus-delete-images (category)
6327 "Delete all images in CATEGORY."
6328 (let ((entry (assq category gnus-article-image-alist)))
6329 (dolist (image (cdr entry))
6330 (gnus-remove-image image category))
6331 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6332 (gnus-delete-wash-type category)))
6334 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6336 (defun gnus-article-maybe-hide-headers ()
6337 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6338 Provided for backwards compatibility."
6339 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6340 (not (with-current-buffer gnus-summary-buffer
6341 gnus-have-all-headers)))
6342 (not gnus-inhibit-hiding))
6343 (gnus-article-hide-headers)))
6345 (declare-function shr-put-image "shr" (data alt &optional flags))
6347 (defun gnus-shr-put-image (data alt &optional flags)
6348 "Put image DATA with a string ALT. Enable image to be deleted."
6349 (let ((image (if flags
6350 (shr-put-image data (propertize (or alt "*")
6351 'gnus-image-category 'shr)
6352 flags)
6353 ;; Old `shr-put-image' doesn't take the optional `flags'
6354 ;; argument.
6355 (shr-put-image data (propertize (or alt "*")
6356 'gnus-image-category 'shr)))))
6357 (when image
6358 (gnus-add-image 'shr image))))
6360 (defun gnus-article-mime-handles (&optional alist id all)
6361 (if alist
6362 (let ((i 1) newid flat)
6363 (dolist (handle alist flat)
6364 (setq newid (append id (list i))
6365 i (1+ i))
6366 (if (stringp (car handle))
6367 (setq flat (nconc flat (gnus-article-mime-handles
6368 (cdr handle) newid all)))
6369 (delq (rassq handle all) all)
6370 (setq flat (nconc flat (list (cons newid handle)))))))
6371 (let ((flat (list nil)))
6372 ;; Assume that elements of `gnus-article-mime-handle-alist'
6373 ;; are in the decreasing order, but unnumbered subsidiaries
6374 ;; in each element are in the increasing order.
6375 (dolist (handle (reverse gnus-article-mime-handle-alist))
6376 (if (stringp (cadr handle))
6377 (setq flat (nconc flat (gnus-article-mime-handles
6378 (cddr handle) (list (car handle)) flat)))
6379 (delq (rassq (cdr handle) flat) flat)
6380 (setq flat (nconc flat (list (cons (list (car handle))
6381 (cdr handle)))))))
6382 (setq flat (cdr flat))
6383 (mapc (lambda (handle)
6384 (if (cdar handle)
6385 ;; This is a hidden (i.e. unnumbered) handle.
6386 (progn
6387 (setcar handle
6388 (1+ (caar gnus-article-mime-handle-alist)))
6389 (push handle gnus-article-mime-handle-alist))
6390 (setcar handle (caar handle))))
6391 flat)
6392 flat)))
6394 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6395 "Show attachments as buttons in the end of the header of an article.
6396 This function toggles the display when called interactively. Note that
6397 buttons to be added to the header are only the ones that aren't inlined
6398 in the body. Use `gnus-header-face-alist' to highlight buttons."
6399 (interactive (list t))
6400 (gnus-with-article-buffer
6401 (let ((case-fold-search t) buttons handle type st)
6402 (save-excursion
6403 (save-restriction
6404 (widen)
6405 (article-narrow-to-head)
6406 ;; Header buttons exist?
6407 (while (and (not buttons)
6408 (re-search-forward "^attachments?:[\n ]+" nil t))
6409 (when (get-char-property (match-end 0)
6410 'gnus-button-attachment-extra)
6411 (setq buttons (match-beginning 0))))
6412 (widen)
6413 (when buttons
6414 ;; Delete header buttons.
6415 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6416 (match-beginning 0)
6417 (point-max))))
6418 (unless (and interactive buttons)
6419 ;; Find buttons.
6420 (setq buttons nil)
6421 (dolist (button (gnus-article-mime-handles))
6422 (setq handle (cdr button)
6423 type (mm-handle-media-type handle))
6424 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6425 (with-current-buffer gnus-summary-buffer
6426 gnus-inhibit-images)
6427 gnus-inhibit-images)
6428 (string-match "\\`image/" type))
6429 (mm-inline-override-p handle)
6430 (and (mm-handle-disposition handle)
6431 (not (equal (car (mm-handle-disposition handle))
6432 "inline"))
6433 (not (mm-attachment-override-p handle)))
6434 (not (mm-automatic-display-p handle))
6435 (not (or (and (mm-inlinable-p handle)
6436 (mm-inlined-p handle))
6437 (mm-automatic-external-display-p type))))
6438 (push button buttons)))
6439 (when buttons
6440 ;; Add header buttons.
6441 (article-goto-body)
6442 (forward-line -1)
6443 (narrow-to-region (point) (point))
6444 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6445 (dolist (button (nreverse buttons))
6446 (setq st (point))
6447 (insert " ")
6448 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6449 (gnus-insert-mime-button handle (car button))
6450 (skip-chars-backward "\t\n ")
6451 (delete-region (point) (point-max))
6452 (when (> (current-column) (window-width))
6453 (goto-char st)
6454 (insert "\n")
6455 (end-of-line)))
6456 (insert "\n")
6457 (dolist (ovl (overlays-in (point-min) (point)))
6458 (overlay-put ovl 'gnus-button-attachment-extra t)
6459 (overlay-put ovl 'face nil))
6460 (let ((gnus-treatment-function-alist
6461 '((gnus-treat-highlight-headers
6462 gnus-article-highlight-headers))))
6463 (gnus-treat-article 'head)))))))))
6465 ;;; Article savers.
6467 (defun gnus-output-to-file (file-name)
6468 "Append the current article to a file named FILE-NAME.
6469 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6470 text and used as the value of the coding cookie which is added to the
6471 top of a file. Otherwise, this function saves a raw article without
6472 the coding cookie."
6473 (let* ((artbuf (current-buffer))
6474 (file-name-coding-system nnmail-pathname-coding-system)
6475 (coding gnus-article-save-coding-system)
6476 (coding-system-for-read (if coding
6477 nil ;; Rely on the coding cookie.
6478 mm-text-coding-system))
6479 (coding-system-for-write (or coding
6480 mm-text-coding-system-for-write
6481 mm-text-coding-system))
6482 (exists (file-exists-p file-name)))
6483 (with-temp-buffer
6484 (when exists
6485 (insert-file-contents file-name)
6486 (goto-char (point-min))
6487 ;; Remove the existing coding cookie.
6488 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6489 (delete-region (match-beginning 0) (match-end 0))))
6490 (goto-char (point-max))
6491 (insert-buffer-substring artbuf)
6492 ;; Append newline at end of the buffer as separator, and then
6493 ;; save it to file.
6494 (goto-char (point-max))
6495 (insert "\n")
6496 (when coding
6497 ;; If the coding system is not suitable to encode the text,
6498 ;; ask a user for a proper one.
6499 (when (fboundp 'select-safe-coding-system)
6500 (setq coding (coding-system-base
6501 (save-window-excursion
6502 (select-safe-coding-system (point-min) (point-max)
6503 coding))))
6504 (setq coding-system-for-write
6505 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6506 coding)))
6507 (goto-char (point-min))
6508 ;; Add the coding cookie.
6509 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6510 coding-system-for-write)))
6511 (if exists
6512 (progn
6513 (write-region (point-min) (point-max) file-name nil 'no-message)
6514 (message "Appended to %s" file-name))
6515 (write-region (point-min) (point-max) file-name))))
6518 (defun gnus-narrow-to-page (&optional arg)
6519 "Narrow the article buffer to a page.
6520 If given a numerical ARG, move forward ARG pages."
6521 (interactive "P")
6522 (setq arg (if arg (prefix-numeric-value arg) 0))
6523 (with-current-buffer gnus-article-buffer
6524 (widen)
6525 ;; Remove any old next/prev buttons.
6526 (when (gnus-visual-p 'page-marker)
6527 (let ((inhibit-read-only t))
6528 (gnus-remove-text-with-property 'gnus-prev)
6529 (gnus-remove-text-with-property 'gnus-next)))
6530 (let (st nd pt)
6531 (when (save-excursion
6532 (cond ((< arg 0)
6533 (if (re-search-backward page-delimiter nil 'move (abs arg))
6534 (prog1
6535 (setq nd (match-beginning 0)
6536 pt nd)
6537 (when (re-search-backward page-delimiter nil t)
6538 (setq st (match-end 0))))
6539 (when (re-search-forward page-delimiter nil t)
6540 (setq nd (match-beginning 0)
6541 pt (point-min)))))
6542 ((> arg 0)
6543 (if (re-search-forward page-delimiter nil 'move arg)
6544 (prog1
6545 (setq st (match-end 0)
6546 pt st)
6547 (when (re-search-forward page-delimiter nil t)
6548 (setq nd (match-beginning 0))))
6549 (when (re-search-backward page-delimiter nil t)
6550 (setq st (match-end 0)
6551 pt (point-max)))))
6553 (when (re-search-backward page-delimiter nil t)
6554 (goto-char (setq st (match-end 0))))
6555 (when (re-search-forward page-delimiter nil t)
6556 (setq nd (match-beginning 0)))
6557 (or st nd))))
6558 (setq gnus-page-broken t)
6559 (when pt (goto-char pt))
6560 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6561 (when (gnus-visual-p 'page-marker)
6562 (save-excursion
6563 (when nd
6564 (goto-char nd)
6565 (gnus-insert-next-page-button))
6566 (when st
6567 (goto-char st)
6568 (gnus-insert-prev-page-button))))))))
6570 ;; Article mode commands
6572 (defun gnus-article-goto-next-page ()
6573 "Show the next page of the article."
6574 (interactive)
6575 (when (gnus-article-next-page)
6576 (goto-char (point-min))
6577 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6580 (defun gnus-article-goto-prev-page ()
6581 "Show the previous page of the article."
6582 (interactive)
6583 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6584 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6585 (gnus-article-prev-page nil)))
6587 ;; This is cleaner but currently breaks `gnus-pick-mode':
6589 ;; (defun gnus-article-goto-next-page ()
6590 ;; "Show the next page of the article."
6591 ;; (interactive)
6592 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6593 ;; (gnus-summary-next-page)))
6595 ;; (defun gnus-article-goto-prev-page ()
6596 ;; "Show the next page of the article."
6597 ;; (interactive)
6598 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6599 ;; (gnus-summary-prev-page)))
6601 (defun gnus-article-next-page (&optional lines)
6602 "Show the next page of the current article.
6603 If end of article, return non-nil. Otherwise return nil.
6604 Argument LINES specifies lines to be scrolled up."
6605 (interactive "p")
6606 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6607 (if (and (not (and gnus-article-over-scroll
6608 (> (count-lines (window-start) (point-max))
6609 (if (featurep 'xemacs)
6610 (or lines (1- (window-height)))
6611 (+ (or lines (1- (window-height))) scroll-margin)))))
6612 (save-excursion
6613 (end-of-line)
6614 (and (pos-visible-in-window-p) ;Not continuation line.
6615 (>= (point) (point-max)))))
6616 ;; Nothing in this page.
6617 (if (or (not gnus-page-broken)
6618 (save-excursion
6619 (save-restriction
6620 (widen)
6621 (forward-line)
6622 (eobp)))) ;Real end-of-buffer?
6623 (progn
6624 (when gnus-article-over-scroll
6625 (gnus-article-next-page-1 lines))
6626 t) ;Nothing more.
6627 (gnus-narrow-to-page 1) ;Go to next page.
6628 nil)
6629 ;; More in this page.
6630 (gnus-article-next-page-1 lines)
6631 nil))
6633 (defun gnus-article-beginning-of-window ()
6634 "Move point to the beginning of the window.
6635 In Emacs, the point is placed at the line number which `scroll-margin'
6636 specifies."
6637 (if (featurep 'xemacs)
6638 (move-to-window-line 0)
6639 ;; There is an obscure bug in Emacs that makes it impossible to
6640 ;; scroll past big pictures in the article buffer. Try to fix
6641 ;; this by adding a sanity check by counting the lines visible.
6642 (when (> (count-lines (window-start) (window-end)) 30)
6643 (move-to-window-line
6644 (min (max 0 scroll-margin)
6645 (max 1 (- (window-height)
6646 (if mode-line-format 1 0)
6647 (if header-line-format 1 0)
6648 2)))))))
6650 (defvar scroll-in-place)
6652 (defun gnus-article-next-page-1 (lines)
6653 (condition-case ()
6654 (let ((scroll-in-place nil)
6655 (auto-window-vscroll nil))
6656 (scroll-up lines))
6657 (end-of-buffer
6658 ;; Long lines may cause an end-of-buffer error.
6659 (goto-char (point-max))))
6660 (gnus-article-beginning-of-window))
6662 (defun gnus-article-prev-page (&optional lines)
6663 "Show previous page of current article.
6664 Argument LINES specifies lines to be scrolled down."
6665 (interactive "p")
6666 (move-to-window-line 0)
6667 (if (and gnus-page-broken
6668 (bobp)
6669 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6670 (progn
6671 (gnus-narrow-to-page -1) ;Go to previous page.
6672 (goto-char (point-max))
6673 (recenter (if gnus-article-over-scroll
6674 (if lines
6675 (max (if (featurep 'xemacs)
6676 lines
6677 (+ lines scroll-margin))
6679 (- (window-height) 2))
6680 -1)))
6681 (prog1
6682 (condition-case ()
6683 (let ((scroll-in-place nil))
6684 (scroll-down lines))
6685 (beginning-of-buffer
6686 (goto-char (point-min))))
6687 (gnus-article-beginning-of-window))))
6689 (defun gnus-article-only-boring-p ()
6690 "Decide whether there is only boring text remaining in the article.
6691 Something \"interesting\" is a word of at least two letters that does
6692 not have a face in `gnus-article-boring-faces'."
6693 (when (and gnus-article-skip-boring
6694 (boundp 'gnus-article-boring-faces)
6695 (symbol-value 'gnus-article-boring-faces))
6696 (save-excursion
6697 (let ((inhibit-point-motion-hooks t))
6698 (catch 'only-boring
6699 (while (re-search-forward "\\b\\w\\w" nil t)
6700 (forward-char -1)
6701 (when (not (gnus-intersection
6702 (gnus-faces-at (point))
6703 (symbol-value 'gnus-article-boring-faces)))
6704 (throw 'only-boring nil)))
6705 (throw 'only-boring t))))))
6707 (defun gnus-article-refer-article ()
6708 "Read article specified by message-id around point."
6709 (interactive)
6710 (save-excursion
6711 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6712 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6713 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6714 (let ((msg-id (concat "<" (match-string 0) ">")))
6715 (set-buffer gnus-summary-buffer)
6716 (gnus-summary-refer-article msg-id))
6717 (error "No references around point"))))
6719 (defun gnus-article-show-summary ()
6720 "Reconfigure windows to show summary buffer."
6721 (interactive)
6722 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6723 (error "There is no summary buffer for this article buffer")
6724 (gnus-article-set-globals)
6725 (gnus-configure-windows 'article)
6726 (gnus-summary-goto-subject gnus-current-article)
6727 (gnus-summary-position-point)))
6729 (defun gnus-article-describe-briefly ()
6730 "Describe article mode commands briefly."
6731 (interactive)
6732 (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")))
6734 (defun gnus-article-check-buffer ()
6735 "Beep if not in an article buffer."
6736 (unless (derived-mode-p 'gnus-article-mode)
6737 (error "Command invoked outside of a Gnus article buffer")))
6739 (defvar gnus-pick-mode)
6741 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6742 "Read a summary buffer key sequence and execute it from the article buffer."
6743 (interactive "P")
6744 (gnus-article-check-buffer)
6745 (let ((nosaves
6746 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6747 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6748 "=" "^" "\M-^" "|"))
6749 (nosave-but-article
6750 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6751 "An" "Ap" [?A (meta return)] [?A delete]))
6752 (nosave-in-article
6753 '("AS" "\C-d"))
6754 keys new-sum-point)
6755 (with-current-buffer gnus-article-current-summary
6756 (let (gnus-pick-mode)
6757 (setq unread-command-events (nconc unread-command-events
6758 (list (or key last-command-event)))
6759 keys (if (featurep 'xemacs)
6760 (events-to-keys (read-key-sequence nil t))
6761 (read-key-sequence nil t)))))
6763 (message "")
6765 (cond
6766 ((eq (aref keys (1- (length keys))) ?\C-h)
6767 (gnus-article-describe-bindings (substring keys 0 -1)))
6768 ((or (member keys nosaves)
6769 (member keys nosave-but-article)
6770 (member keys nosave-in-article))
6771 (let (func)
6772 (save-window-excursion
6773 (pop-to-buffer gnus-article-current-summary)
6774 ;; We disable the pick minor mode commands.
6775 (let (gnus-pick-mode)
6776 (setq func (key-binding keys t))))
6777 (if (or (not func)
6778 (numberp func))
6779 (ding)
6780 (unless (member keys nosave-in-article)
6781 (set-buffer gnus-article-current-summary))
6782 (when (and (symbolp func)
6783 (get func 'disabled))
6784 (error "Function %s disabled" func))
6785 (call-interactively func)
6786 (setq new-sum-point (point)))
6787 (when (member keys nosave-but-article)
6788 (pop-to-buffer gnus-article-buffer))))
6790 ;; These commands should restore window configuration.
6791 (let ((obuf (current-buffer))
6792 (owin (current-window-configuration))
6793 win func in-buffer selected new-sum-start new-sum-hscroll err)
6794 (cond (not-restore-window
6795 (pop-to-buffer gnus-article-current-summary)
6796 (setq win (selected-window)))
6797 ((setq win (get-buffer-window gnus-article-current-summary))
6798 (select-window win))
6800 (let ((summary-buffer gnus-article-current-summary))
6801 (gnus-configure-windows 'article)
6802 (unless (setq win (get-buffer-window summary-buffer 'visible))
6803 (let ((gnus-buffer-configuration
6804 '((article ((vertical 1.0
6805 (summary 0.25 point)
6806 (article 1.0)))))))
6807 (gnus-configure-windows 'article))
6808 (setq win (get-buffer-window summary-buffer 'visible)))
6809 (gnus-select-frame-set-input-focus (window-frame win))
6810 (select-window win))))
6811 (setq in-buffer (current-buffer))
6812 ;; We disable the pick minor mode commands.
6813 (setq func (let (gnus-pick-mode)
6814 (key-binding keys t)))
6815 (when (get func 'disabled)
6816 (error "Function %s disabled" func))
6817 (if (and func
6818 (functionp func)
6819 (condition-case code
6820 (progn
6821 (call-interactively func)
6823 (error
6824 (setq err code)
6825 nil)))
6826 (progn
6827 (when (eq win (selected-window))
6828 (setq new-sum-point (point)
6829 new-sum-start (window-start win)
6830 new-sum-hscroll (window-hscroll win)))
6831 (when (or (eq in-buffer (current-buffer))
6832 (when (eq obuf (current-buffer))
6833 (set-buffer in-buffer)
6835 (setq selected (ignore-errors (gnus-summary-select-article)))
6836 (set-buffer obuf)
6837 (unless not-restore-window
6838 (set-window-configuration owin))
6839 (when (and (eq selected 'old)
6840 new-sum-point)
6841 (set-window-start (get-buffer-window (current-buffer))
6843 (set-window-point (get-buffer-window (current-buffer))
6844 (if (article-goto-body)
6845 (1- (point))
6846 (point))))
6847 (when (and (not not-restore-window)
6848 new-sum-point
6849 (window-live-p win)
6850 (with-current-buffer (window-buffer win)
6851 (derived-mode-p 'gnus-summary-mode)))
6852 (set-window-point win new-sum-point)
6853 (set-window-start win new-sum-start)
6854 (set-window-hscroll win new-sum-hscroll))))
6855 (set-window-configuration owin)
6856 (if err
6857 (signal (car err) (cdr err))
6858 (ding))))))))
6860 (defun gnus-article-read-summary-send-keys ()
6861 (interactive)
6862 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6863 (gnus-article-read-summary-keys)))
6865 (defun gnus-article-describe-key (key)
6866 "Display documentation of the function invoked by KEY.
6867 KEY is a string or a vector."
6868 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6869 (read-key-sequence "Describe key: "))))
6870 (gnus-article-check-buffer)
6871 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6872 gnus-article-read-summary-send-keys))
6873 (with-current-buffer gnus-article-current-summary
6874 (setq unread-command-events
6875 (if (featurep 'xemacs)
6876 (append key unread-command-events)
6877 (nconc
6878 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6879 (list 'meta (- x 128))
6881 key)
6882 unread-command-events)))
6883 (let ((cursor-in-echo-area t)
6884 gnus-pick-mode)
6885 (describe-key (read-key-sequence nil t))))
6886 (describe-key key)))
6888 (defun gnus-article-describe-key-briefly (key &optional insert)
6889 "Display documentation of the function invoked by KEY.
6890 KEY is a string or a vector."
6891 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6892 (read-key-sequence "Describe key: "))
6893 current-prefix-arg))
6894 (gnus-article-check-buffer)
6895 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6896 gnus-article-read-summary-send-keys))
6897 (with-current-buffer gnus-article-current-summary
6898 (setq unread-command-events
6899 (if (featurep 'xemacs)
6900 (append key unread-command-events)
6901 (nconc
6902 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6903 (list 'meta (- x 128))
6905 key)
6906 unread-command-events)))
6907 (let ((cursor-in-echo-area t)
6908 gnus-pick-mode)
6909 (describe-key-briefly (read-key-sequence nil t) insert)))
6910 (describe-key-briefly key insert)))
6912 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6913 (defvar gnus-agent-summary-mode)
6914 (defvar gnus-draft-mode)
6915 (defvar help-xref-stack-item)
6916 (defvar help-xref-following)
6918 (defun gnus-article-describe-bindings (&optional prefix)
6919 "Show a list of all defined keys, and their definitions.
6920 The optional argument PREFIX, if non-nil, should be a key sequence;
6921 then we display only bindings that start with that prefix."
6922 (interactive)
6923 (gnus-article-check-buffer)
6924 (let ((keymap (copy-keymap gnus-article-mode-map))
6925 (map (copy-keymap gnus-article-send-map))
6926 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6927 parent agent draft)
6928 (define-key keymap "S" map)
6929 (define-key map [t] nil)
6930 (with-current-buffer gnus-article-current-summary
6931 (set-keymap-parent
6932 keymap
6933 (if (setq parent (keymap-parent gnus-article-mode-map))
6934 (prog1
6935 (setq parent (copy-keymap parent))
6936 (set-keymap-parent parent (current-local-map)))
6937 (current-local-map)))
6938 (set-keymap-parent map (key-binding "S"))
6939 (let (key def gnus-pick-mode)
6940 (while sumkeys
6941 (setq key (pop sumkeys))
6942 (cond ((and (vectorp key) (= (length key) 1)
6943 (consp (setq def (aref key 0)))
6944 (numberp (car def)) (numberp (cdr def)))
6945 (when (< (max (car def) (cdr def)) 128)
6946 (setq sumkeys
6947 (append (mapcar
6948 #'vector
6949 (nreverse (gnus-uncompress-range def)))
6950 sumkeys))))
6951 ((setq def (key-binding key))
6952 (unless (eq def 'undefined)
6953 (define-key keymap key def))))))
6954 (when (boundp 'gnus-agent-summary-mode)
6955 (setq agent gnus-agent-summary-mode))
6956 (when (boundp 'gnus-draft-mode)
6957 (setq draft gnus-draft-mode)))
6958 (with-temp-buffer
6959 (use-local-map keymap)
6960 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6961 (set (make-local-variable 'gnus-draft-mode) draft)
6962 (describe-bindings prefix))
6963 (let ((item `((lambda (prefix)
6964 (with-current-buffer ,(current-buffer)
6965 (gnus-article-describe-bindings prefix)))
6966 ,prefix)))
6967 ;; Loading `help-mode' here is necessary if `describe-bindings'
6968 ;; is replaced with something, e.g. `helm-descbinds'.
6969 (require 'help-mode)
6970 (with-current-buffer (let (help-xref-following) (help-buffer))
6971 (setq help-xref-stack-item item)))))
6973 (defun gnus-article-reply-with-original (&optional wide)
6974 "Start composing a reply mail to the current message.
6975 The text in the region will be yanked. If the region isn't active,
6976 the entire article will be yanked."
6977 (interactive)
6978 (let ((article (cdr gnus-article-current))
6979 contents)
6980 (if (not (gnus-region-active-p))
6981 (with-current-buffer gnus-summary-buffer
6982 (gnus-summary-reply (list (list article)) wide))
6983 (setq contents (buffer-substring (point) (mark t)))
6984 ;; Deactivate active regions.
6985 (when (and (boundp 'transient-mark-mode)
6986 transient-mark-mode)
6987 (setq mark-active nil))
6988 (with-current-buffer gnus-summary-buffer
6989 (gnus-summary-reply
6990 (list (list article contents)) wide)))))
6992 (defun gnus-article-wide-reply-with-original ()
6993 "Start composing a wide reply mail to the current message.
6994 The text in the region will be yanked. If the region isn't active,
6995 the entire article will be yanked."
6996 (interactive)
6997 (gnus-article-reply-with-original t))
6999 (defun gnus-article-followup-with-original ()
7000 "Compose a followup to the current article.
7001 The text in the region will be yanked. If the region isn't active,
7002 the entire article will be yanked."
7003 (interactive)
7004 (let ((article (cdr gnus-article-current))
7005 contents)
7006 (if (not (gnus-region-active-p))
7007 (with-current-buffer gnus-summary-buffer
7008 (gnus-summary-followup (list (list article))))
7009 (setq contents (buffer-substring (point) (mark t)))
7010 ;; Deactivate active regions.
7011 (when (and (boundp 'transient-mark-mode)
7012 transient-mark-mode)
7013 (setq mark-active nil))
7014 (with-current-buffer gnus-summary-buffer
7015 (gnus-summary-followup
7016 (list (list article contents)))))))
7018 (defun gnus-article-hide (&optional arg force)
7019 "Hide all the gruft in the current article.
7020 This means that signatures, cited text and (some) headers will be
7021 hidden.
7022 If given a prefix, show the hidden text instead."
7023 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7024 (gnus-article-hide-headers arg)
7025 (gnus-article-hide-list-identifiers arg)
7026 (gnus-article-hide-citation-maybe arg force)
7027 (gnus-article-hide-signature arg))
7029 (defun gnus-check-group-server ()
7030 ;; Make sure the connection to the server is alive.
7031 (unless (gnus-server-opened
7032 (gnus-find-method-for-group gnus-newsgroup-name))
7033 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7034 (gnus-request-group gnus-newsgroup-name t)))
7036 (declare-function nneething-get-file-name "nneething" (id))
7038 (defun gnus-request-article-this-buffer (article group)
7039 "Get an article and insert it into this buffer."
7040 (let (do-update-line sparse-header)
7041 (prog1
7042 (save-excursion
7043 (erase-buffer)
7044 (gnus-kill-all-overlays)
7045 (setq group (or group gnus-newsgroup-name))
7047 ;; Using `gnus-request-article' directly will insert the article into
7048 ;; `nntp-server-buffer' - so we'll save some time by not having to
7049 ;; copy it from the server buffer into the article buffer.
7051 ;; We only request an article by message-id when we do not have the
7052 ;; headers for it, so we'll have to get those.
7053 (when (stringp article)
7054 (gnus-read-header article))
7056 ;; If the article number is negative, that means that this article
7057 ;; doesn't belong in this newsgroup (possibly), so we find its
7058 ;; message-id and request it by id instead of number.
7059 (when (and (numberp article)
7060 gnus-summary-buffer
7061 (get-buffer gnus-summary-buffer)
7062 (gnus-buffer-exists-p gnus-summary-buffer))
7063 (with-current-buffer gnus-summary-buffer
7064 (let ((header (gnus-summary-article-header article)))
7065 (when (< article 0)
7066 (cond
7067 ((memq article gnus-newsgroup-sparse)
7068 ;; This is a sparse gap article.
7069 (setq do-update-line article)
7070 (setq article (mail-header-id header))
7071 (setq sparse-header (gnus-read-header article))
7072 (setq gnus-newsgroup-sparse
7073 (delq article gnus-newsgroup-sparse)))
7074 ((vectorp header)
7075 ;; It's a real article.
7076 (setq article (mail-header-id header)))
7078 ;; It is an extracted pseudo-article.
7079 (setq article 'pseudo)
7080 (gnus-request-pseudo-article header))))
7082 (let ((method (gnus-find-method-for-group
7083 gnus-newsgroup-name)))
7084 (when (and (eq (car method) 'nneething)
7085 (vectorp header))
7086 (let ((dir (nneething-get-file-name
7087 (mail-header-id header))))
7088 (when (and (stringp dir)
7089 (file-directory-p dir))
7090 (setq article 'nneething)
7091 (gnus-group-enter-directory dir))))))))
7093 (cond
7094 ;; Refuse to select canceled articles.
7095 ((and (numberp article)
7096 gnus-summary-buffer
7097 (get-buffer gnus-summary-buffer)
7098 (gnus-buffer-exists-p gnus-summary-buffer)
7099 (eq (cdr (with-current-buffer gnus-summary-buffer
7100 (assq article gnus-newsgroup-reads)))
7101 gnus-canceled-mark))
7102 nil)
7103 ;; We first check `gnus-original-article-buffer'.
7104 ((and (get-buffer gnus-original-article-buffer)
7105 (numberp article)
7106 (with-current-buffer gnus-original-article-buffer
7107 (and (equal (car gnus-original-article) group)
7108 (eq (cdr gnus-original-article) article))))
7109 ;; `insert-buffer-substring' would incorrectly use the
7110 ;; equivalent of string-make-multibyte which amount to decoding
7111 ;; with locale-coding-system, causing failure of
7112 ;; subsequent decoding.
7113 (insert (mm-string-to-multibyte
7114 (with-current-buffer gnus-original-article-buffer
7115 (buffer-substring (point-min) (point-max)))))
7116 'article)
7117 ;; Check the backlog.
7118 ((and gnus-keep-backlog
7119 (gnus-backlog-request-article group article (current-buffer)))
7120 'article)
7121 ;; Check asynchronous pre-fetch.
7122 ((gnus-async-request-fetched-article group article (current-buffer))
7123 (gnus-async-prefetch-next group article gnus-summary-buffer)
7124 (when (and (numberp article) gnus-keep-backlog)
7125 (gnus-backlog-enter-article group article (current-buffer)))
7126 'article)
7127 ;; Check the cache.
7128 ((and gnus-use-cache
7129 (numberp article)
7130 (gnus-cache-request-article article group))
7131 'article)
7132 ;; Check the agent cache.
7133 ((gnus-agent-request-article article group)
7134 'article)
7135 ;; Get the article and put into the article buffer.
7136 ((or (stringp article)
7137 (numberp article))
7138 (let ((gnus-override-method gnus-override-method)
7139 (methods (and (stringp article)
7140 (with-current-buffer gnus-summary-buffer
7141 (gnus-refer-article-methods))))
7142 (backend (car (gnus-find-method-for-group
7143 gnus-newsgroup-name)))
7144 result
7145 (inhibit-read-only t))
7146 (when (and (null gnus-override-method)
7147 methods)
7148 (setq gnus-override-method (pop methods)))
7149 (while (not result)
7150 (erase-buffer)
7151 (gnus-kill-all-overlays)
7152 (let ((gnus-newsgroup-name group))
7153 (gnus-check-group-server))
7154 (cond
7155 ((gnus-request-article article group (current-buffer))
7156 (when (numberp article)
7157 (gnus-async-prefetch-next group article
7158 gnus-summary-buffer)
7159 (when gnus-keep-backlog
7160 (gnus-backlog-enter-article
7161 group article (current-buffer)))
7162 (when (and gnus-agent
7163 (gnus-agent-group-covered-p group))
7164 (gnus-agent-store-article article group)))
7165 (setq result 'article))
7166 (methods
7167 (setq gnus-override-method (pop methods)))
7168 ((not (string-match "^400 "
7169 (nnheader-get-report backend)))
7170 ;; If we get 400 server disconnect, reconnect and
7171 ;; retry; otherwise, assume the article has expired.
7172 (setq result 'done))))
7173 (and (eq result 'article) 'article)))
7174 ;; It was a pseudo.
7175 (t article)))
7177 ;; Associate this article with the current summary buffer.
7178 (setq gnus-article-current-summary gnus-summary-buffer)
7180 ;; Take the article from the original article buffer
7181 ;; and place it in the buffer it's supposed to be in.
7182 (when (and (get-buffer gnus-article-buffer)
7183 (equal (buffer-name (current-buffer))
7184 (buffer-name (get-buffer gnus-article-buffer))))
7185 (save-excursion
7186 (if (get-buffer gnus-original-article-buffer)
7187 (set-buffer gnus-original-article-buffer)
7188 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7189 (buffer-disable-undo)
7190 (setq major-mode 'gnus-original-article-mode)
7191 (setq buffer-read-only t))
7192 (let ((inhibit-read-only t))
7193 (erase-buffer)
7194 (insert-buffer-substring gnus-article-buffer))
7195 (setq gnus-original-article (cons group article)))
7197 ;; Decode charsets.
7198 (run-hooks 'gnus-article-decode-hook)
7199 ;; Mark article as decoded or not.
7200 (setq gnus-article-decoded-p gnus-article-decode-hook))
7202 ;; Update sparse articles.
7203 (when (and do-update-line
7204 (or (numberp article)
7205 (stringp article)))
7206 (let ((buf (current-buffer)))
7207 (set-buffer gnus-summary-buffer)
7208 (gnus-summary-update-article do-update-line sparse-header)
7209 (gnus-summary-goto-subject do-update-line nil t)
7210 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7211 (point))
7212 (set-buffer buf))))))
7214 (defun gnus-block-private-groups (group)
7215 "Allows images in newsgroups to be shown, blocks images in all
7216 other groups."
7217 (if (or (gnus-news-group-p group)
7218 (gnus-member-of-valid 'global group))
7219 ;; Block nothing in news groups.
7221 ;; Block everything anywhere else.
7222 "."))
7224 (defun gnus-blocked-images ()
7225 (if (functionp gnus-blocked-images)
7226 (funcall gnus-blocked-images gnus-newsgroup-name)
7227 gnus-blocked-images))
7230 ;;; Article editing
7233 (defcustom gnus-article-edit-mode-hook nil
7234 "Hook run in article edit mode buffers."
7235 :group 'gnus-article-various
7236 :type 'hook)
7238 (defvar gnus-article-edit-done-function nil)
7240 (defvar gnus-article-edit-mode-map nil)
7242 ;; Should we be using derived.el for this?
7243 (unless gnus-article-edit-mode-map
7244 (setq gnus-article-edit-mode-map (make-keymap))
7245 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7247 (gnus-define-keys gnus-article-edit-mode-map
7248 "\C-c?" describe-mode
7249 "\C-c\C-c" gnus-article-edit-done
7250 "\C-c\C-k" gnus-article-edit-exit
7251 "\C-c\C-f\C-t" message-goto-to
7252 "\C-c\C-f\C-o" message-goto-from
7253 "\C-c\C-f\C-b" message-goto-bcc
7254 ;;"\C-c\C-f\C-w" message-goto-fcc
7255 "\C-c\C-f\C-c" message-goto-cc
7256 "\C-c\C-f\C-s" message-goto-subject
7257 "\C-c\C-f\C-r" message-goto-reply-to
7258 "\C-c\C-f\C-n" message-goto-newsgroups
7259 "\C-c\C-f\C-d" message-goto-distribution
7260 "\C-c\C-f\C-f" message-goto-followup-to
7261 "\C-c\C-f\C-m" message-goto-mail-followup-to
7262 "\C-c\C-f\C-k" message-goto-keywords
7263 "\C-c\C-f\C-u" message-goto-summary
7264 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7265 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7266 "\C-c\C-b" message-goto-body
7267 "\C-c\C-i" message-goto-signature
7269 "\C-c\C-t" message-insert-to
7270 "\C-c\C-n" message-insert-newsgroups
7271 "\C-c\C-o" message-sort-headers
7272 "\C-c\C-e" message-elide-region
7273 "\C-c\C-v" message-delete-not-region
7274 "\C-c\C-z" message-kill-to-signature
7275 "\M-\r" message-newline-and-reformat
7276 "\C-c\C-a" mml-attach-file
7277 "\C-a" message-beginning-of-line
7278 "\t" message-tab
7279 "\M-;" comment-region)
7281 (gnus-define-keys (gnus-article-edit-wash-map
7282 "\C-c\C-w" gnus-article-edit-mode-map)
7283 "f" gnus-article-edit-full-stops))
7285 (easy-menu-define
7286 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7287 '("Field"
7288 ["Fetch To" message-insert-to t]
7289 ["Fetch Newsgroups" message-insert-newsgroups t]
7290 "----"
7291 ["To" message-goto-to t]
7292 ["From" message-goto-from t]
7293 ["Subject" message-goto-subject t]
7294 ["Cc" message-goto-cc t]
7295 ["Reply-To" message-goto-reply-to t]
7296 ["Summary" message-goto-summary t]
7297 ["Keywords" message-goto-keywords t]
7298 ["Newsgroups" message-goto-newsgroups t]
7299 ["Followup-To" message-goto-followup-to t]
7300 ["Mail-Followup-To" message-goto-mail-followup-to t]
7301 ["Distribution" message-goto-distribution t]
7302 ["Body" message-goto-body t]
7303 ["Signature" message-goto-signature t]))
7305 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7306 "Major mode for editing articles.
7307 This is an extended text-mode.
7309 \\{gnus-article-edit-mode-map}"
7310 (make-local-variable 'gnus-article-edit-done-function)
7311 (make-local-variable 'gnus-prev-winconf)
7312 (set (make-local-variable 'font-lock-defaults)
7313 '(message-font-lock-keywords t))
7314 (set (make-local-variable 'mail-header-separator) "")
7315 (set (make-local-variable 'gnus-article-edit-mode) t)
7316 (easy-menu-add message-mode-field-menu message-mode-map)
7317 (mml-mode)
7318 (setq buffer-read-only nil)
7319 (buffer-enable-undo)
7320 (widen))
7322 (defun gnus-article-edit (&optional force)
7323 "Edit the current article.
7324 This will have permanent effect only in mail groups.
7325 If FORCE is non-nil, allow editing of articles even in read-only
7326 groups."
7327 (interactive "P")
7328 (when (and (not force)
7329 (gnus-group-read-only-p))
7330 (error "The current newsgroup does not support article editing"))
7331 (gnus-article-date-original)
7332 (gnus-article-edit-article
7333 'ignore
7334 `(lambda (no-highlight)
7335 'ignore
7336 (gnus-summary-edit-article-done
7337 ,(or (mail-header-references gnus-current-headers) "")
7338 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7340 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7341 "Start editing the contents of the current article buffer."
7342 (let ((winconf (current-window-configuration)))
7343 (set-buffer gnus-article-buffer)
7344 (let ((message-auto-save-directory
7345 ;; Don't associate the article buffer with a draft file.
7346 nil))
7347 (gnus-article-edit-mode))
7348 (funcall start-func)
7349 (set-buffer-modified-p nil)
7350 (gnus-configure-windows 'edit-article)
7351 (setq gnus-article-edit-done-function exit-func)
7352 (setq gnus-prev-winconf winconf)
7353 (unless quiet
7354 (gnus-message 6 "C-c C-c to end edits"))))
7356 (defun gnus-article-edit-done (&optional arg)
7357 "Update the article edits and exit."
7358 (interactive "P")
7359 (let ((func gnus-article-edit-done-function)
7360 (buf (current-buffer))
7361 (start (window-start))
7362 (winconf gnus-prev-winconf))
7363 (widen) ;; Widen it in case that users narrowed the buffer.
7364 (funcall func arg)
7365 (set-buffer buf)
7366 ;; The cache and backlog have to be flushed somewhat.
7367 (when gnus-keep-backlog
7368 (gnus-backlog-remove-article
7369 (car gnus-article-current) (cdr gnus-article-current)))
7370 ;; Flush original article as well.
7371 (gnus-flush-original-article-buffer)
7372 (when gnus-use-cache
7373 (gnus-cache-update-article
7374 (car gnus-article-current) (cdr gnus-article-current)))
7375 ;; We remove all text props from the article buffer.
7376 (kill-all-local-variables)
7377 (set-text-properties (point-min) (point-max) nil)
7378 (gnus-article-mode)
7379 (set-window-configuration winconf)
7380 (set-buffer buf)
7381 (set-window-start (get-buffer-window buf) start)
7382 (set-window-point (get-buffer-window buf) (point)))
7383 (gnus-summary-show-article))
7385 (defun gnus-flush-original-article-buffer ()
7386 (when (get-buffer gnus-original-article-buffer)
7387 (with-current-buffer gnus-original-article-buffer
7388 (setq gnus-original-article nil))))
7390 (defun gnus-article-edit-exit ()
7391 "Exit the article editing without updating."
7392 (interactive)
7393 (when (or (not (buffer-modified-p))
7394 (yes-or-no-p "Article modified; kill anyway? "))
7395 (let ((curbuf (current-buffer))
7396 (p (point))
7397 (window-start (window-start)))
7398 (erase-buffer)
7399 (if (gnus-buffer-live-p gnus-original-article-buffer)
7400 (insert-buffer-substring gnus-original-article-buffer))
7401 (let ((winconf gnus-prev-winconf))
7402 (kill-all-local-variables)
7403 (gnus-article-mode)
7404 (set-window-configuration winconf)
7405 ;; Tippy-toe some to make sure that point remains where it was.
7406 (save-current-buffer
7407 (set-buffer curbuf)
7408 (set-window-start (get-buffer-window (current-buffer)) window-start)
7409 (goto-char p))))
7410 (gnus-summary-show-article)))
7412 (defun gnus-article-edit-full-stops ()
7413 "Interactively repair spacing at end of sentences."
7414 (interactive)
7415 (save-excursion
7416 (goto-char (point-min))
7417 (search-forward-regexp "^$" nil t)
7418 (let ((case-fold-search nil))
7419 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7422 ;;; Article highlights
7425 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7427 ;;; Internal Variables:
7429 (defcustom gnus-button-url-regexp
7430 (concat
7431 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7432 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7433 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7434 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7435 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7436 (punct "!?:;.,"))
7437 (concat
7438 "\\(?:"
7439 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7440 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7441 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7442 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7443 "\\|"
7444 "[" chars punct "]+" "[" chars "]"
7445 "\\)"))
7446 (concat ;; XEmacs 21.4 doesn't support POSIX.
7447 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7448 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7449 "\\)")
7450 "Regular expression that matches URLs."
7451 :version "24.4"
7452 :group 'gnus-article-buttons
7453 :type 'regexp)
7455 (defcustom gnus-button-valid-fqdn-regexp
7456 message-valid-fqdn-regexp
7457 "Regular expression that matches a valid FQDN."
7458 :version "22.1"
7459 :group 'gnus-article-buttons
7460 :type 'regexp)
7462 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7463 (defcustom gnus-button-valid-localpart-regexp
7464 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7465 "Regular expression that matches a localpart of mail addresses or MIDs."
7466 :version "22.1"
7467 :group 'gnus-article-buttons
7468 :type 'regexp)
7470 (defcustom gnus-button-man-handler 'manual-entry
7471 "Function to use for displaying man pages.
7472 The function must take at least one argument with a string naming the
7473 man page."
7474 :version "22.1"
7475 :type '(choice (function-item :tag "Man" manual-entry)
7476 (function-item :tag "Woman" woman)
7477 (function :tag "Other"))
7478 :group 'gnus-article-buttons)
7480 (defcustom gnus-button-mid-or-mail-regexp
7481 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7482 gnus-button-valid-fqdn-regexp
7483 ">?\\)\\b")
7484 "Regular expression that matches a message ID or a mail address."
7485 :version "22.1"
7486 :group 'gnus-article-buttons
7487 :type 'regexp)
7489 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7490 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7491 Strings like this can be either a message ID or a mail address. If it is one
7492 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7493 message ID or a mail address, respectively. If this variable is set to the
7494 symbol `ask', always query the user what do do. If it is a function, this
7495 function will be called with the string as its only argument. The function
7496 must return `mid', `mail', `invalid' or `ask'."
7497 :version "22.1"
7498 :group 'gnus-article-buttons
7499 :type '(choice (function-item :tag "Heuristic function"
7500 gnus-button-mid-or-mail-heuristic)
7501 (const ask)
7502 (const mid)
7503 (const mail)))
7505 (defcustom gnus-button-mid-or-mail-heuristic-alist
7506 '((-10.0 . ".+\\$.+@")
7507 (-10.0 . "#")
7508 (-10.0 . "\\*")
7509 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7510 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7511 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7512 (-1.0 . "^[^a-z]+@")
7514 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7515 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7516 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7517 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7519 (-2.0 . "^[0-9]")
7520 (-1.0 . "^[0-9][0-9]")
7522 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7523 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7524 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7525 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7527 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7528 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7529 ;; "[0-9]{8,}.*\@"
7530 (-3.0
7531 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7532 ;; "[0-9]{12,}.*\@"
7533 ;; compensation for TDMA dated mail addresses:
7534 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7536 (-20.0 . "\\.fsf@") ;; Gnus
7537 (-20.0 . "^slrn")
7538 (-20.0 . "^Pine")
7539 (-20.0 . "^alpine\\.")
7540 (-20.0 . "_-_") ;; Subject change in thread
7542 (-20.0 . "\\.ln@") ;; leafnode
7543 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7544 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7546 ;; (5.0 . "") ;; $local_part_len <= 7
7547 (10.0 . "^[^0-9]+@")
7548 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7549 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7550 (3.0 . "@stud")
7552 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7554 (0.5 . "^[A-Z][a-z]")
7555 (0.5 . "^[A-Z][a-z][a-z]")
7556 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7557 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7558 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7560 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7561 address. The REGEXP is processed with `case-fold-search' set to nil."
7562 :version "22.1"
7563 :group 'gnus-article-buttons
7564 :type '(repeat (cons (number :tag "Rate")
7565 (regexp :tag "Regexp"))))
7567 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7568 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7569 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7570 address, `ask' if unsure and `invalid' if the string is invalid."
7571 (let ((case-fold-search nil)
7572 (list gnus-button-mid-or-mail-heuristic-alist)
7573 (result 0) rate regexp lpartlen elem)
7574 (setq lpartlen
7575 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7576 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7577 ;; Certain special cases...
7578 (when (string-match
7579 (concat
7580 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7581 "^[0-9]+\\.[0-9]+@compuserve\\|"
7582 "@public\\.gmane\\.org")
7583 mid-or-mail)
7584 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7585 (setq result 'mail))
7586 (when (string-match "@.*@\\| " mid-or-mail)
7587 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7588 (setq result 'invalid))
7589 ;; Nothing more to do, if result is not a number here...
7590 (when (numberp result)
7591 (while list
7592 (setq elem (car list)
7593 rate (car elem)
7594 regexp (cdr elem)
7595 list (cdr list))
7596 (when (string-match regexp mid-or-mail)
7597 (setq result (+ result rate))
7598 (gnus-message
7599 9 "`%s' matched `%s', rate `%s', result `%s'."
7600 mid-or-mail regexp rate result)))
7601 (when (<= lpartlen 7)
7602 (setq result (+ result 5.0))
7603 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7604 mid-or-mail result))
7605 (when (>= lpartlen 12)
7606 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7607 (cond
7608 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7609 ;; Long local part should contain realname if e-mail address,
7610 ;; too many digits: message-id.
7611 ;; $score -= 5.0 + 0.1 * $local_part_len;
7612 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7613 (setq result (+ result rate))
7614 (gnus-message
7615 9 "Many digits in `%s', rate `%s', result `%s'."
7616 mid-or-mail rate result))
7617 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7618 mid-or-mail)
7619 ;; Too few vowels [^aeiouy]{4,}.*@
7620 (setq result (+ result -5.0))
7621 (gnus-message
7622 9 "Few vowels in `%s', rate `%s', result `%s'."
7623 mid-or-mail -5.0 result))
7625 (setq result (+ result 5.0))
7626 (gnus-message
7627 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7628 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7629 ;; Maybe we should make this a customizable alist: (condition . 'result)
7630 (cond
7631 ((symbolp result) result)
7632 ;; Now convert number into proper results:
7633 ((< result -10.0) 'mid)
7634 ((> result 10.0) 'mail)
7635 (t 'ask))))
7637 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7638 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7639 (url-mid (concat "news" ":" mid-or-mail))
7640 (url-mailto (concat "mailto" ":" mid-or-mail)))
7641 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7642 (when (fboundp pref)
7643 (setq guessed
7644 ;; get rid of surrounding angles...
7645 (funcall pref
7646 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7647 (if (or (eq 'mid guessed) (eq 'mail guessed))
7648 (setq pref guessed)
7649 (setq pref 'ask)))
7650 (if (eq pref 'ask)
7651 (save-window-excursion
7652 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7653 (setq pref 'mail)
7654 (setq pref 'mid))))
7655 (cond ((eq pref 'mid)
7656 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7657 (gnus-button-handle-news url-mid))
7658 ((eq pref 'mail)
7659 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7660 (gnus-url-mailto url-mailto))
7661 (t (gnus-message 3 "Invalid string.")))))
7663 (defun gnus-button-handle-custom (fun arg)
7664 "Call function FUN on argument ARG.
7665 Both FUN and ARG are supposed to be strings. ARG will be passed
7666 as a symbol to FUN."
7667 (funcall (intern fun)
7668 (if (string-match "^customize-apropos" fun)
7670 (intern arg))))
7672 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7674 (defun gnus-button-handle-describe-function (url)
7675 "Call `describe-function' when pushing the corresponding URL button."
7676 (describe-function
7677 (intern
7678 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7680 (defun gnus-button-handle-describe-variable (url)
7681 "Call `describe-variable' when pushing the corresponding URL button."
7682 (describe-variable
7683 (intern
7684 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7686 (defun gnus-button-handle-symbol (url)
7687 "Display help on variable or function.
7688 Calls `describe-variable' or `describe-function'."
7689 (let ((sym (intern url)))
7690 (cond
7691 ((fboundp sym) (describe-function sym))
7692 ((boundp sym) (describe-variable sym))
7693 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7695 (defun gnus-button-handle-describe-key (url)
7696 "Call `describe-key' when pushing the corresponding URL button."
7697 (let* ((key-string
7698 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7699 (keys (ignore-errors (eval `(kbd ,key-string)))))
7700 (if keys
7701 (describe-key keys)
7702 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7704 (defun gnus-button-handle-apropos (url)
7705 "Call `apropos' when pushing the corresponding URL button."
7706 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7708 (defun gnus-button-handle-apropos-command (url)
7709 "Call `apropos' when pushing the corresponding URL button."
7710 (apropos-command
7711 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7713 (defun gnus-button-handle-apropos-variable (url)
7714 "Call `apropos' when pushing the corresponding URL button."
7715 (funcall
7716 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7717 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7719 (defun gnus-button-handle-apropos-documentation (url)
7720 "Call `apropos' when pushing the corresponding URL button."
7721 (funcall
7722 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7723 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7725 (defun gnus-button-handle-library (url)
7726 "Call `locate-library' when pushing the corresponding URL button."
7727 (gnus-message 9 "url=`%s'" url)
7728 (let* ((lib (locate-library url))
7729 (file (gnus-replace-in-string (or lib "") "\\.elc" ".el")))
7730 (if (not lib)
7731 (gnus-message 1 "Cannot locale library `%s'." url)
7732 (find-file-read-only file))))
7734 (defcustom gnus-button-man-level 5
7735 "*Integer that says how many man-related buttons Gnus will show.
7736 The higher the number, the more buttons will appear and the more false
7737 positives are possible. Note that you can set this variable local to
7738 specific groups. Setting it higher in Unix groups is probably a good idea.
7739 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7740 how to set variables in specific groups."
7741 :version "22.1"
7742 :group 'gnus-article-buttons
7743 :link '(custom-manual "(gnus)Group Parameters")
7744 :type 'integer)
7746 (defcustom gnus-button-emacs-level 5
7747 "*Integer that says how many emacs-related buttons Gnus will show.
7748 The higher the number, the more buttons will appear and the more false
7749 positives are possible. Note that you can set this variable local to
7750 specific groups. Setting it higher in Emacs or Gnus related groups is
7751 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7752 `gnus-parameters' on how to set variables in specific groups."
7753 :version "22.1"
7754 :group 'gnus-article-buttons
7755 :link '(custom-manual "(gnus)Group Parameters")
7756 :type 'integer)
7758 (defcustom gnus-button-message-level 5
7759 "*Integer that says how many buttons for news or mail messages will appear.
7760 The higher the number, the more buttons will appear and the more false
7761 positives are possible."
7762 ;; mail addresses, MIDs, URLs for news, ...
7763 :version "22.1"
7764 :group 'gnus-article-buttons
7765 :type 'integer)
7767 (defcustom gnus-button-browse-level 5
7768 "*Integer that says how many buttons for browsing will appear.
7769 The higher the number, the more buttons will appear and the more false
7770 positives are possible."
7771 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7772 :version "22.1"
7773 :group 'gnus-article-buttons
7774 :type 'integer)
7776 (defcustom gnus-button-alist
7777 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7778 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7779 ((concat "\\b\\(nntp\\|news\\):\\("
7780 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7781 0 t gnus-button-handle-news 2)
7782 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7783 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7784 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7785 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7786 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7787 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7788 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7789 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7790 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7791 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7792 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7793 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7794 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7795 ;; RFC 2368 (The mailto URL scheme)
7796 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7797 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7798 ("\\bmailto:\\([^ \n\t]+\\)"
7799 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7800 ;; Info Konqueror style <info:/foo/bar baz>.
7801 ;; Must come before " Gnus home-grown style".
7802 ("\\binfo://?\\([^'\">\n\t]+\\)"
7803 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7804 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7805 ("\\binfo://\\([^'\">\n\t ]+\\)"
7806 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7807 ;; Info GNOME style <info:foo#bar_baz>
7808 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7809 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7810 ;; Info KDE style <info:(foo)bar baz>
7811 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7812 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7813 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7814 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7815 ("\\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,]*\\)\\)?"
7816 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7817 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7818 ;; This is custom
7819 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7820 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7821 ;; Emacs help commands
7822 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7823 ;; regexp doesn't match arguments containing ` '.
7824 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7825 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7826 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7827 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7828 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7829 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7830 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7831 ;; The following entries may lead to many false positives so don't enable
7832 ;; them by default (use a high button level).
7833 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7834 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7835 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7836 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7837 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7838 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7839 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7840 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7841 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7842 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7843 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7844 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7845 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7846 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7847 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7848 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7849 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7850 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7851 ;; Unlike the other regexps we really have to require quoting
7852 ;; here to determine where it ends.
7853 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7854 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7855 ("<URL: *\\([^\n<>]*\\)>"
7856 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7857 ;; RFC 2396 (2.4.3., delims) ...
7858 ("\"URL: *\\([^\n\"]*\\)\""
7859 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7860 ;; Raw URLs.
7861 (gnus-button-url-regexp
7862 0 (>= gnus-button-browse-level 0) browse-url 0)
7863 ;; man pages
7864 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7865 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7866 gnus-button-handle-man 1)
7867 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7868 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7869 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7870 gnus-button-handle-man 1)
7871 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7872 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7873 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7874 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7875 ;; Recognizing patches to .el files. This is somewhat obscure,
7876 ;; but considering the percentage of Gnus users who hack Emacs
7877 ;; Lisp files...
7878 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7879 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7880 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7881 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7882 ;; MID or mail: To avoid too many false positives we don't try to catch
7883 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7884 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7885 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7886 ;; so that non-ambiguous entries (see above) match first.
7887 (gnus-button-mid-or-mail-regexp
7888 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7889 "*Alist of regexps matching buttons in article bodies.
7891 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7892 REGEXP: is the string (case insensitive) matching text around the button (can
7893 also be Lisp expression evaluating to a string),
7894 BUTTON: is the number of the regexp grouping actually matching the button,
7895 FORM: is a Lisp expression which must eval to true for the button to
7896 be added,
7897 CALLBACK: is the function to call when the user push this button, and each
7898 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7900 CALLBACK can also be a variable, in that case the value of that
7901 variable it the real callback function."
7902 :group 'gnus-article-buttons
7903 :type '(repeat (list (choice regexp variable sexp)
7904 (integer :tag "Button")
7905 (sexp :tag "Form")
7906 (function :tag "Callback")
7907 (repeat :tag "Par"
7908 :inline t
7909 (integer :tag "Regexp group")))))
7910 (put 'gnus-button-alist 'risky-local-variable t)
7912 (defcustom gnus-header-button-alist
7913 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7914 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7915 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7916 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7917 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7918 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7919 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7920 0 (>= gnus-button-browse-level 0) browse-url 0)
7921 ("^Subject:" gnus-button-url-regexp
7922 0 (>= gnus-button-browse-level 0) browse-url 0)
7923 ("^[^:]+:" gnus-button-url-regexp
7924 0 (>= gnus-button-browse-level 0) browse-url 0)
7925 ("^OpenPGP:.*url=" gnus-button-url-regexp
7926 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7927 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7928 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7929 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7930 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7931 "*Alist of headers and regexps to match buttons in article heads.
7933 This alist is very similar to `gnus-button-alist', except that each
7934 alist has an additional HEADER element first in each entry:
7936 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7938 HEADER is a regexp to match a header. For a fuller explanation, see
7939 `gnus-button-alist'."
7940 :group 'gnus-article-buttons
7941 :group 'gnus-article-headers
7942 :type '(repeat (list (regexp :tag "Header")
7943 (choice regexp variable)
7944 (integer :tag "Button")
7945 (sexp :tag "Form")
7946 (function :tag "Callback")
7947 (repeat :tag "Par"
7948 :inline t
7949 (integer :tag "Regexp group")))))
7950 (put 'gnus-header-button-alist 'risky-local-variable t)
7952 ;;; Commands:
7954 (defun gnus-article-push-button (event)
7955 "Check text under the mouse pointer for a callback function.
7956 If the text under the mouse pointer has a `gnus-callback' property,
7957 call it with the value of the `gnus-data' text property."
7958 (interactive "e")
7959 (set-buffer (window-buffer (posn-window (event-start event))))
7960 (let* ((pos (posn-point (event-start event)))
7961 (data (get-text-property pos 'gnus-data))
7962 (fun (get-text-property pos 'gnus-callback)))
7963 (goto-char pos)
7964 (when fun
7965 (funcall fun data))))
7967 (defun gnus-article-press-button ()
7968 "Check text at point for a callback function.
7969 If the text at point has a `gnus-callback' property,
7970 call it with the value of the `gnus-data' text property."
7971 (interactive)
7972 (let ((data (get-text-property (point) 'gnus-data))
7973 (fun (get-text-property (point) 'gnus-callback)))
7974 (when fun
7975 (funcall fun data))))
7977 (defun gnus-article-highlight (&optional force)
7978 "Highlight current article.
7979 This function calls `gnus-article-highlight-headers',
7980 `gnus-article-highlight-citation',
7981 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7982 do the highlighting. See the documentation for those functions."
7983 (interactive (list 'force))
7984 (gnus-article-highlight-headers)
7985 (gnus-article-highlight-citation force)
7986 (gnus-article-highlight-signature)
7987 (gnus-article-add-buttons)
7988 (gnus-article-add-buttons-to-head))
7990 (defun gnus-article-highlight-some (&optional _force)
7991 "Highlight current article.
7992 This function calls `gnus-article-highlight-headers',
7993 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7994 do the highlighting. See the documentation for those functions."
7995 (interactive (list 'force))
7996 (gnus-article-highlight-headers)
7997 (gnus-article-highlight-signature)
7998 (gnus-article-add-buttons))
8000 (defun gnus-article-highlight-headers ()
8001 "Highlight article headers as specified by `gnus-header-face-alist'."
8002 (interactive)
8003 (gnus-with-article-headers
8004 (let (regexp header-face field-face from hpoints fpoints)
8005 (dolist (entry gnus-header-face-alist)
8006 (goto-char (point-min))
8007 (setq regexp (concat "^\\("
8008 (if (string-equal "" (nth 0 entry))
8009 "[^\t ]"
8010 (nth 0 entry))
8011 "\\)")
8012 header-face (nth 1 entry)
8013 field-face (nth 2 entry))
8014 (while (and (re-search-forward regexp nil t)
8015 (not (eobp)))
8016 (beginning-of-line)
8017 (setq from (point))
8018 (unless (search-forward ":" nil t)
8019 (forward-char 1))
8020 (when (and header-face
8021 (not (memq (point) hpoints)))
8022 (push (point) hpoints)
8023 (gnus-put-text-property from (point) 'face header-face))
8024 (when (and field-face
8025 (not (memq (setq from (point)) fpoints)))
8026 (push from fpoints)
8027 (if (re-search-forward "^[^ \t]" nil t)
8028 (forward-char -2)
8029 (goto-char (point-max)))
8030 (gnus-put-text-property from (point) 'face field-face)))))))
8032 (defun gnus-article-highlight-signature ()
8033 "Highlight the signature in an article.
8034 It does this by highlighting everything after
8035 `gnus-signature-separator' using the face `gnus-signature'."
8036 (interactive)
8037 (gnus-with-article-buffer
8038 (let ((inhibit-point-motion-hooks t))
8039 (save-restriction
8040 (when (and gnus-signature-face
8041 (gnus-article-narrow-to-signature))
8042 (overlay-put (make-overlay (point-min) (point-max) nil t)
8043 'face gnus-signature-face)
8044 (widen)
8045 (gnus-article-search-signature)
8046 (let ((start (match-beginning 0))
8047 (end (set-marker (make-marker) (1+ (match-end 0)))))
8048 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8049 end)))))))
8051 (defun gnus-button-in-region-p (b e prop)
8052 "Say whether PROP exists in the region."
8053 (text-property-not-all b e prop nil))
8055 (defun gnus-article-add-buttons ()
8056 "Find external references in the article and make buttons of them.
8057 \"External references\" are things like Message-IDs and URLs, as
8058 specified by `gnus-button-alist'."
8059 (interactive)
8060 (gnus-with-article-buffer
8061 (let ((inhibit-point-motion-hooks t)
8062 (case-fold-search t)
8063 (alist gnus-button-alist)
8064 beg entry regexp)
8065 ;; We skip the headers.
8066 (article-goto-body)
8067 (setq beg (point))
8068 (while (setq entry (pop alist))
8069 (setq regexp (eval (car entry)))
8070 (goto-char beg)
8071 (while (re-search-forward regexp nil t)
8072 (let ((start (match-beginning (nth 1 entry)))
8073 (end (match-end (nth 1 entry)))
8074 (from (match-beginning 0)))
8075 (when (and (eval (nth 2 entry))
8076 (not (gnus-button-in-region-p
8077 start end 'gnus-callback)))
8078 ;; That optional form returned non-nil, so we add the
8079 ;; button.
8080 (setq from (set-marker (make-marker) from))
8081 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8082 (gnus-article-extend-url-button from start end))
8083 (gnus-article-add-button start end
8084 'gnus-button-push (list from entry))
8085 (gnus-put-text-property
8086 start end
8087 'gnus-string (buffer-substring-no-properties
8088 start end))))))))))
8090 (defun gnus-article-extend-url-button (beg start end)
8091 "Extend url button if url is folded into two or more lines.
8092 Return non-nil if button is extended. BEG is a marker that points to
8093 the beginning position of a text containing url. START and END are
8094 the endpoints of a url button before it is extended. The concatenated
8095 url is put as the `gnus-button-url' overlay property on the button."
8096 (let ((opoint (point))
8097 (points (list start end))
8098 url delim regexp)
8099 (prog1
8100 (when (and (progn
8101 (goto-char end)
8102 (not (looking-at "[\t ]*[\">]")))
8103 (progn
8104 (goto-char start)
8105 (string-match
8106 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8107 (buffer-substring (point-at-bol) start)))
8108 (progn
8109 (setq url (list (buffer-substring start end))
8110 delim (if (match-beginning 1) ">" "\""))
8111 (beginning-of-line)
8112 (setq regexp (concat
8113 (when (and (looking-at
8114 message-cite-prefix-regexp)
8115 (< (match-end 0) start))
8116 (regexp-quote (match-string 0)))
8118 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8119 delim "\\)"))
8120 (while (progn
8121 (forward-line 1)
8122 (and (looking-at regexp)
8123 (prog1
8124 (match-beginning 1)
8125 (push (or (match-string 2)
8126 (match-string 1))
8127 url)
8128 (push (setq end (or (match-end 2)
8129 (match-end 1)))
8130 points)
8131 (push (or (match-beginning 2)
8132 (match-beginning 1))
8133 points)))))
8134 (match-beginning 2)))
8135 (let (gnus-article-mouse-face widget-mouse-face)
8136 (while points
8137 (gnus-article-add-button (pop points) (pop points)
8138 'gnus-button-push
8139 (list beg (assq 'gnus-button-url-regexp
8140 gnus-button-alist)))))
8141 (let ((overlay (make-overlay start end)))
8142 (overlay-put overlay 'evaporate t)
8143 (overlay-put overlay 'gnus-button-url
8144 (list (mapconcat 'identity (nreverse url) "")))
8145 (when gnus-article-mouse-face
8146 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8148 (goto-char opoint))))
8150 ;; Add buttons to the head of an article.
8151 (defun gnus-article-add-buttons-to-head ()
8152 "Add buttons to the head of the article."
8153 (interactive)
8154 (gnus-with-article-headers
8155 (let (beg end)
8156 (dolist (entry gnus-header-button-alist)
8157 ;; Each alist entry.
8158 (goto-char (point-min))
8159 (while (re-search-forward (car entry) nil t)
8160 ;; Each header matching the entry.
8161 (setq beg (match-beginning 0))
8162 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8163 (match-beginning 0))
8164 (point-max)))
8165 (goto-char beg)
8166 (while (re-search-forward (eval (nth 1 entry)) end t)
8167 ;; Each match within a header.
8168 (let* ((entry (cdr entry))
8169 (start (match-beginning (nth 1 entry)))
8170 (end (match-end (nth 1 entry)))
8171 (form (nth 2 entry)))
8172 (goto-char (match-end 0))
8173 (when (eval form)
8174 (gnus-article-add-button
8175 start end (nth 3 entry)
8176 (buffer-substring (match-beginning (nth 4 entry))
8177 (match-end (nth 4 entry)))))))
8178 (goto-char end))))))
8180 ;;; External functions:
8182 (defun gnus-article-add-button (from to fun &optional data text)
8183 "Create a button between FROM and TO with callback FUN and data DATA."
8184 (when gnus-article-button-face
8185 (overlay-put (make-overlay from to nil t)
8186 'face gnus-article-button-face))
8187 (gnus-add-text-properties
8188 from to
8189 (nconc (and gnus-article-mouse-face
8190 (list gnus-mouse-face-prop gnus-article-mouse-face))
8191 (list 'gnus-callback fun)
8192 (and data (list 'gnus-data data))))
8193 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8194 :help-echo (or text "Follow the link")
8195 :keymap gnus-url-button-map
8196 :button-keymap gnus-widget-button-keymap))
8198 (defun gnus-article-copy-string ()
8199 "Copy the string in the button to the kill ring."
8200 (interactive)
8201 (gnus-article-check-buffer)
8202 (let ((data (get-text-property (point) 'gnus-string)))
8203 (when data
8204 (with-temp-buffer
8205 (insert data)
8206 (copy-region-as-kill (point-min) (point-max))
8207 (message "Copied %s" data)))))
8209 ;;; Internal functions:
8211 (defun gnus-article-set-globals ()
8212 (with-current-buffer gnus-summary-buffer
8213 (gnus-set-global-variables)))
8215 (defun gnus-signature-toggle (end)
8216 (gnus-with-article-buffer
8217 (let ((inhibit-point-motion-hooks t))
8218 (if (text-property-any end (point-max) 'article-type 'signature)
8219 (progn
8220 (gnus-delete-wash-type 'signature)
8221 (gnus-remove-text-properties-when
8222 'article-type 'signature end (point-max)
8223 (cons 'article-type (cons 'signature
8224 gnus-hidden-properties))))
8225 (gnus-add-wash-type 'signature)
8226 (gnus-add-text-properties-when
8227 'article-type nil end (point-max)
8228 (cons 'article-type (cons 'signature
8229 gnus-hidden-properties)))))
8230 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8231 (gnus-set-mode-line 'article))))
8233 (defun gnus-button-push (marker-and-entry)
8234 ;; Push button starting at MARKER.
8235 (save-excursion
8236 (let* ((marker (car marker-and-entry))
8237 (entry (cadr marker-and-entry))
8238 (regexp (car entry))
8239 (inhibit-point-motion-hooks t))
8240 (goto-char marker)
8241 ;; This is obviously true, or something bad is happening :)
8242 ;; But we need it to have the match-data
8243 (when (looking-at (or (if (symbolp regexp)
8244 (symbol-value regexp)
8245 regexp)))
8246 (let ((fun (nth 3 entry))
8247 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8248 (get-char-property marker 'gnus-button-url))
8249 (mapcar (lambda (group)
8250 (let ((string (match-string group)))
8251 (set-text-properties
8252 0 (length string) nil string)
8253 string))
8254 (nthcdr 4 entry)))))
8256 (cond
8257 ((fboundp fun)
8258 (apply fun args))
8259 ((and (boundp fun)
8260 (fboundp (symbol-value fun)))
8261 (apply (symbol-value fun) args))
8263 (gnus-message 1 "You must define `%S' to use this button"
8264 (cons fun args)))))))))
8266 (defun gnus-parse-news-url (url)
8267 (let (scheme server port group message-id articles)
8268 (with-temp-buffer
8269 (insert url)
8270 (goto-char (point-min))
8271 (when (looking-at "\\([A-Za-z]+\\):")
8272 (setq scheme (match-string 1))
8273 (goto-char (match-end 0)))
8274 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8275 (setq server (match-string 1))
8276 (setq port (if (stringp (match-string 3))
8277 (string-to-number (match-string 3))
8278 (match-string 3)))
8279 (goto-char (match-end 0)))
8281 (cond
8282 ((looking-at "\\(.*@.*\\)")
8283 (setq message-id (match-string 1)))
8284 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8285 (setq group (match-string 1)
8286 articles (split-string (match-string 2) "-")))
8287 ((looking-at "\\([^/]+\\)/?")
8288 (setq group (match-string 1)))
8290 (error "Unknown news URL syntax"))))
8291 (list scheme server port group message-id articles)))
8293 (defvar nntp-port-number)
8295 (defun gnus-button-handle-news (url)
8296 "Fetch a news URL."
8297 (destructuring-bind (_scheme server port group message-id _articles)
8298 (gnus-parse-news-url url)
8299 (cond
8300 (message-id
8301 (with-current-buffer gnus-summary-buffer
8302 (if server
8303 (let ((gnus-refer-article-method
8304 (nconc (list (list 'nntp server))
8305 gnus-refer-article-method))
8306 (nntp-port-number (or port "nntp")))
8307 (gnus-message 7 "Fetching %s with %s"
8308 message-id gnus-refer-article-method)
8309 (gnus-summary-refer-article message-id))
8310 (gnus-summary-refer-article message-id))))
8311 (group
8312 (gnus-button-fetch-group url)))))
8314 (defun gnus-button-patch (library line)
8315 "Visit an Emacs Lisp library LIBRARY on line LINE."
8316 (interactive)
8317 (let ((file (locate-library (file-name-nondirectory library))))
8318 (unless file
8319 (error "Couldn't find library %s" library))
8320 (find-file file)
8321 (goto-char (point-min))
8322 (forward-line (1- (string-to-number line)))))
8324 (defun gnus-button-handle-man (url)
8325 "Fetch a man page."
8326 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8327 (when (eq gnus-button-man-handler 'woman)
8328 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8329 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8330 (funcall gnus-button-man-handler url))
8332 (defun gnus-button-handle-info-url (url)
8333 "Fetch an info URL."
8334 (setq url (mm-subst-char-in-string ?+ ?\ url))
8335 (cond
8336 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8337 (gnus-info-find-node
8338 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8339 "Gnus")
8340 ")" (gnus-url-unhex-string (match-string 2 url)))))
8341 ((string-match "([^)\"]+)[^\"]+" url)
8342 (setq url
8343 (gnus-replace-in-string
8344 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8345 (gnus-info-find-node url))
8346 (t (error "Can't parse %s" url))))
8348 (defun gnus-button-handle-info-url-gnome (url)
8349 "Fetch GNOME style info URL."
8350 (setq url (mm-subst-char-in-string ?_ ?\ url))
8351 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8352 (gnus-info-find-node
8353 (concat "("
8354 (gnus-url-unhex-string
8355 (match-string 1 url))
8357 (or (gnus-url-unhex-string
8358 (match-string 2 url))
8359 "Top")))
8360 (error "Can't parse %s" url)))
8362 (defun gnus-button-handle-info-url-kde (url)
8363 "Fetch KDE style info URL."
8364 (gnus-info-find-node (gnus-url-unhex-string url)))
8366 ;; (info) will autoload info.el
8367 (declare-function Info-menu "info" (menu-item &optional fork))
8368 (declare-function Info-index-next "info" (num))
8370 (defun gnus-button-handle-info-keystrokes (url)
8371 "Call `info' when pushing the corresponding URL button."
8372 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8373 (let (node indx comma)
8374 (if (string-match
8375 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8376 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8377 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8378 "\\(?:[ \t\n,]*\\)\\)?")
8379 url)
8380 (setq node (match-string 2 url)
8381 indx (match-string 3 url))
8382 (error "Can't parse %s" url))
8383 (info)
8384 (Info-directory)
8385 (Info-menu node)
8386 (when (> (length indx) 0)
8387 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8388 "\\([ \t\n,]*\\)")
8389 indx)
8390 (setq comma (match-string 2 indx))
8391 (setq indx (match-string 1 indx))
8392 (Info-index indx)
8393 (when comma
8394 (dotimes (i (with-temp-buffer
8395 (insert comma)
8396 ;; Note: the XEmacs version of `how-many' takes
8397 ;; no optional argument.
8398 (goto-char (point-min))
8399 (how-many ",")))
8400 (Info-index-next 1)))
8401 nil)))
8403 (autoload 'pgg-snarf-keys-region "pgg")
8404 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8405 (declare-function pgg-display-output-buffer "pgg" (start end status))
8407 (defun gnus-button-openpgp (url)
8408 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8409 (with-temp-buffer
8410 (mm-url-insert-file-contents-external url)
8411 (pgg-snarf-keys-region (point-min) (point-max))
8412 (pgg-display-output-buffer nil nil nil)))
8414 (defun gnus-button-message-id (message-id)
8415 "Fetch MESSAGE-ID."
8416 (with-current-buffer gnus-summary-buffer
8417 (gnus-summary-refer-article message-id)))
8419 (defun gnus-button-fetch-group (address &rest _ignore)
8420 "Fetch GROUP specified by ADDRESS."
8421 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8422 address)
8423 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8424 ;; for nntp:// and news://
8425 (setq address (match-string 3 address)))
8426 (if (not (string-match "[:/]" address))
8427 ;; This is just a simple group url.
8428 (gnus-group-read-ephemeral-group address gnus-select-method)
8429 (if (not
8430 (string-match
8431 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8432 address))
8433 (error "Can't parse %s" address)
8434 (gnus-group-read-ephemeral-group
8435 (match-string 4 address)
8436 `(nntp ,(match-string 1 address)
8437 (nntp-address ,(match-string 1 address))
8438 (nntp-port-number ,(if (match-end 3)
8439 (match-string 3 address)
8440 "nntp")))
8441 nil nil nil
8442 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8444 (defun gnus-url-parse-query-string (query &optional downcase)
8445 (let (retval pairs cur key val)
8446 (setq pairs (split-string query "&"))
8447 (while pairs
8448 (setq cur (car pairs)
8449 pairs (cdr pairs))
8450 (if (not (string-match "=" cur))
8451 nil ; Grace
8452 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8453 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8454 (if downcase
8455 (setq key (downcase key)))
8456 (setq cur (assoc key retval))
8457 (if cur
8458 (setcdr cur (cons val (cdr cur)))
8459 (setq retval (cons (list key val) retval)))))
8460 retval))
8462 (defun gnus-url-mailto (url)
8463 ;; Send mail to someone
8464 (setq url (replace-regexp-in-string "\n" " " url))
8465 (when (string-match "mailto:/*\\(.*\\)" url)
8466 (setq url (substring url (match-beginning 1) nil)))
8467 (let* ((args (gnus-url-parse-query-string
8468 (if (string-match "^\\?" url)
8469 (substring url 1)
8470 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8471 (concat "to=" (match-string 1 url) "&"
8472 (match-string 2 url))
8473 (concat "to=" url)))))
8474 (subject (cdr-safe (assoc "subject" args)))
8475 func)
8476 (gnus-msg-mail)
8477 (while args
8478 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8479 (if (fboundp func)
8480 (funcall func)
8481 (message-position-on-field (caar args)))
8482 (insert (gnus-replace-in-string
8483 (mapconcat 'identity (reverse (cdar args)) ", ")
8484 "\r\n" "\n" t))
8485 (setq args (cdr args)))
8486 (if subject
8487 (message-goto-body)
8488 (message-goto-subject))))
8490 (defun gnus-button-embedded-url (address)
8491 "Activate ADDRESS with `browse-url'."
8492 (browse-url (gnus-strip-whitespace address)))
8494 ;;; Next/prev buttons in the article buffer.
8496 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8497 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8499 (defvar gnus-prev-page-map
8500 (let ((map (make-sparse-keymap)))
8501 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8502 (define-key map "\r" 'gnus-button-prev-page)
8503 map))
8505 (defvar gnus-next-page-map
8506 (let ((map (make-sparse-keymap)))
8507 (define-key map gnus-mouse-2 'gnus-button-next-page)
8508 (define-key map "\r" 'gnus-button-next-page)
8509 map))
8511 (defun gnus-insert-prev-page-button ()
8512 (let ((b (point)) e
8513 (inhibit-read-only t))
8514 (gnus-eval-format
8515 gnus-prev-page-line-format nil
8516 `(keymap ,gnus-prev-page-map
8517 gnus-prev t
8518 gnus-callback gnus-article-button-prev-page
8519 article-type annotation))
8520 (setq e (if (bolp)
8521 ;; Exclude a newline.
8522 (1- (point))
8523 (point)))
8524 (when gnus-article-button-face
8525 (overlay-put (make-overlay b e nil t)
8526 'face gnus-article-button-face))
8527 (widget-convert-button
8528 'link b e
8529 :action 'gnus-button-prev-page
8530 :button-keymap gnus-prev-page-map)))
8532 (defun gnus-button-next-page (&optional _args _more-args)
8533 "Go to the next page."
8534 (interactive)
8535 (let ((win (selected-window)))
8536 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8537 (gnus-article-next-page)
8538 (select-window win)))
8540 (defun gnus-button-prev-page (&optional _args _more-args)
8541 "Go to the prev page."
8542 (interactive)
8543 (let ((win (selected-window)))
8544 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8545 (gnus-article-prev-page)
8546 (select-window win)))
8548 (defun gnus-insert-next-page-button ()
8549 (let ((b (point)) e
8550 (inhibit-read-only t))
8551 (gnus-eval-format gnus-next-page-line-format nil
8552 `(keymap ,gnus-next-page-map
8553 gnus-next t
8554 gnus-callback gnus-article-button-next-page
8555 article-type annotation))
8556 (setq e (if (bolp)
8557 ;; Exclude a newline.
8558 (1- (point))
8559 (point)))
8560 (when gnus-article-button-face
8561 (overlay-put (make-overlay b e nil t)
8562 'face gnus-article-button-face))
8563 (widget-convert-button
8564 'link b e
8565 :action 'gnus-button-next-page
8566 :button-keymap gnus-next-page-map)))
8568 (defun gnus-article-button-next-page (_arg)
8569 "Go to the next page."
8570 (interactive "P")
8571 (let ((win (selected-window)))
8572 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8573 (gnus-article-next-page)
8574 (select-window win)))
8576 (defun gnus-article-button-prev-page (_arg)
8577 "Go to the prev page."
8578 (interactive "P")
8579 (let ((win (selected-window)))
8580 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8581 (gnus-article-prev-page)
8582 (select-window win)))
8584 (defvar gnus-decode-header-methods
8585 '(mail-decode-encoded-word-region)
8586 "List of methods used to decode headers.
8588 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8589 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8590 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8591 whose names match REGEXP.
8593 For example:
8594 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8595 mail-decode-encoded-word-region
8596 (\"chinese\" . rfc1843-decode-region))
8599 (defvar gnus-decode-header-methods-cache nil)
8601 (defun gnus-multi-decode-header (start end)
8602 "Apply the functions from `gnus-encoded-word-methods' that match."
8603 (unless (and gnus-decode-header-methods-cache
8604 (eq gnus-newsgroup-name
8605 (car gnus-decode-header-methods-cache)))
8606 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8607 (dolist (x gnus-decode-header-methods)
8608 (if (symbolp x)
8609 (nconc gnus-decode-header-methods-cache (list x))
8610 (if (and gnus-newsgroup-name
8611 (string-match (car x) gnus-newsgroup-name))
8612 (nconc gnus-decode-header-methods-cache
8613 (list (cdr x)))))))
8614 (let ((xlist gnus-decode-header-methods-cache))
8615 (pop xlist)
8616 (save-restriction
8617 (narrow-to-region start end)
8618 (while xlist
8619 (funcall (pop xlist) (point-min) (point-max))))))
8622 ;;; Treatment top-level handling.
8625 (defvar gnus-inhibit-article-treatments nil)
8627 ;; Dynamic variables.
8628 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8629 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8630 (defvar gnus-treat-type)
8631 (defvar gnus-treat-condition)
8632 (defvar gnus-treat-length)
8634 (defun gnus-treat-article (condition
8635 &optional part-num total type)
8636 (let ((gnus-treat-condition condition)
8637 (part-number part-num)
8638 (total-parts total)
8639 (gnus-treat-type type)
8640 (gnus-treat-length (- (point-max) (point-min)))
8641 (alist gnus-treatment-function-alist)
8642 (article-goto-body-goes-to-point-min-p t)
8643 (treated-type
8644 (or (not type)
8645 (catch 'found
8646 (let ((list gnus-article-treat-types))
8647 (while list
8648 (when (string-match (pop list) type)
8649 (throw 'found t)))))))
8650 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8651 val)
8652 (gnus-run-hooks 'gnus-part-display-hook)
8653 (dolist (elem alist)
8654 (setq val
8655 (save-excursion
8656 (when (gnus-buffer-live-p gnus-summary-buffer)
8657 (set-buffer gnus-summary-buffer))
8658 (symbol-value (car elem))))
8659 (when (and (or (consp val)
8660 treated-type)
8661 (or (not gnus-inhibit-article-treatments)
8662 (eq gnus-treat-condition 'head))
8663 (gnus-treat-predicate val)
8664 (or (not (get (car elem) 'highlight))
8665 highlightp))
8666 (save-restriction
8667 (funcall (cadr elem)))))))
8669 (defun gnus-treat-predicate (val)
8670 (cond
8671 ((null val)
8672 nil)
8673 (gnus-treat-condition
8674 (eq gnus-treat-condition val))
8675 ((and (listp val)
8676 (stringp (car val)))
8677 (apply 'gnus-or (mapcar `(lambda (s)
8678 (string-match s ,(or gnus-newsgroup-name "")))
8679 val)))
8680 ((listp val)
8681 (let ((pred (pop val)))
8682 (cond
8683 ((eq pred 'or)
8684 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8685 ((eq pred 'and)
8686 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8687 ((eq pred 'not)
8688 (not (gnus-treat-predicate (car val))))
8689 ((eq pred 'typep)
8690 (equal (car val) gnus-treat-type))
8691 ((functionp pred)
8692 (funcall pred))
8694 (error "%S is not a valid predicate" pred)))))
8695 ((eq val t)
8697 ((eq val 'head)
8698 nil)
8699 ((eq val 'first)
8700 (eq part-number 1))
8701 ((eq val 'last)
8702 (eq part-number total-parts))
8703 ((numberp val)
8704 (< gnus-treat-length val))
8706 (error "%S is not a valid value" val))))
8708 (defun gnus-article-encrypt-body (protocol &optional n)
8709 "Encrypt the article body."
8710 (interactive
8711 (list
8712 (or gnus-article-encrypt-protocol
8713 (gnus-completing-read "Encrypt protocol"
8714 (mapcar 'car gnus-article-encrypt-protocol-alist)
8716 current-prefix-arg))
8717 ;; User might hit `K E' instead of `K e', so prompt once.
8718 (when (and gnus-article-encrypt-protocol
8719 gnus-novice-user)
8720 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8721 (error "Encrypt aborted")))
8722 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8723 (unless func
8724 (error "Can't find the encrypt protocol %s" protocol))
8725 (if (member gnus-newsgroup-name '("nndraft:delayed"
8726 "nndraft:drafts"
8727 "nndraft:queue"))
8728 (error "Can't encrypt the article in group %s"
8729 gnus-newsgroup-name))
8730 (gnus-summary-iterate n
8731 (with-current-buffer gnus-summary-buffer
8732 (let ((mail-parse-charset gnus-newsgroup-charset)
8733 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8734 (summary-buffer gnus-summary-buffer)
8735 references point)
8736 (gnus-set-global-variables)
8737 (when (gnus-group-read-only-p)
8738 (error "The current newsgroup does not support article encrypt"))
8739 (gnus-summary-show-article t)
8740 (setq references
8741 (or (mail-header-references gnus-current-headers) ""))
8742 (set-buffer gnus-article-buffer)
8743 (let* ((inhibit-read-only t)
8744 (headers
8745 (mapcar (lambda (field)
8746 (and (save-restriction
8747 (message-narrow-to-head)
8748 (goto-char (point-min))
8749 (search-forward field nil t))
8750 (prog2
8751 (message-narrow-to-field)
8752 (buffer-string)
8753 (delete-region (point-min) (point-max))
8754 (widen))))
8755 '("Content-Type:" "Content-Transfer-Encoding:"
8756 "Content-Disposition:"))))
8757 (message-narrow-to-head)
8758 (message-remove-header "MIME-Version")
8759 (goto-char (point-max))
8760 (setq point (point))
8761 (insert (apply 'concat headers))
8762 (widen)
8763 (narrow-to-region point (point-max))
8764 (let ((message-options message-options))
8765 (message-options-set 'message-sender user-mail-address)
8766 (message-options-set 'message-recipients user-mail-address)
8767 (message-options-set 'message-sign-encrypt 'not)
8768 (funcall func))
8769 (goto-char (point-min))
8770 (insert "MIME-Version: 1.0\n")
8771 (widen)
8772 (gnus-summary-edit-article-done
8773 references nil summary-buffer t))
8774 (when gnus-keep-backlog
8775 (gnus-backlog-remove-article
8776 (car gnus-article-current) (cdr gnus-article-current)))
8777 (gnus-flush-original-article-buffer)
8778 (when gnus-use-cache
8779 (gnus-cache-update-article
8780 (car gnus-article-current) (cdr gnus-article-current))))))))
8782 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8783 "The following specs can be used:
8784 %t The security MIME type
8785 %i Additional info
8786 %d Details
8787 %D Details if button is pressed")
8789 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8790 "The following specs can be used:
8791 %t The security MIME type
8792 %i Additional info
8793 %d Details
8794 %D Details if button is pressed")
8796 (defvar gnus-mime-security-button-line-format-alist
8797 '((?t gnus-tmp-type ?s)
8798 (?i gnus-tmp-info ?s)
8799 (?d gnus-tmp-details ?s)
8800 (?D gnus-tmp-pressed-details ?s)))
8802 (defvar gnus-mime-security-button-commands
8803 '((gnus-article-press-button "\r" "Show Detail")
8804 (undefined "v")
8805 (undefined "t")
8806 (undefined "C")
8807 (gnus-mime-security-save-part "o" "Save...")
8808 (undefined "\C-o")
8809 (undefined "r")
8810 (undefined "d")
8811 (undefined "c")
8812 (undefined "i")
8813 (undefined "E")
8814 (undefined "e")
8815 (undefined "p")
8816 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8817 (undefined ".")))
8819 (defvar gnus-mime-security-button-map
8820 (let ((map (make-sparse-keymap)))
8821 (define-key map gnus-mouse-2 'gnus-article-push-button)
8822 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8823 (dolist (c gnus-mime-security-button-commands)
8824 (define-key map (cadr c) (car c)))
8825 map))
8827 (easy-menu-define
8828 gnus-mime-security-button-menu gnus-mime-security-button-map
8829 "Security button menu."
8830 `("Security Part"
8831 ,@(delq nil
8832 (mapcar (lambda (c)
8833 (unless (eq (car c) 'undefined)
8834 (vector (caddr c) (car c) :active t)))
8835 gnus-mime-security-button-commands))))
8837 (defun gnus-mime-security-button-menu (event prefix)
8838 "Construct a context-sensitive menu of security commands."
8839 (interactive "e\nP")
8840 (save-window-excursion
8841 (let ((pos (event-start event)))
8842 (select-window (posn-window pos))
8843 (goto-char (posn-point pos))
8844 (gnus-article-check-buffer)
8845 (popup-menu gnus-mime-security-button-menu nil prefix))))
8847 (defvar gnus-mime-security-details-buffer nil)
8849 (defvar gnus-mime-security-button-pressed nil)
8851 (defvar gnus-mime-security-show-details-inline t
8852 "If non-nil, show details in the article buffer.")
8854 (defun gnus-mime-security-verify-or-decrypt (handle)
8855 (mm-remove-parts (cdr handle))
8856 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8857 point (inhibit-read-only t))
8858 (if region
8859 (goto-char (car region)))
8860 (setq point (point))
8861 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8862 (let* ((mm-verify-option 'known)
8863 (mm-decrypt-option 'known)
8864 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8865 (unless (eq nparts (cdr handle))
8866 (mm-destroy-parts (cdr handle))
8867 (setcdr handle nparts))))
8868 (gnus-mime-display-security handle)
8869 (when region
8870 (delete-region (point) (cdr region))
8871 (set-marker (car region) nil)
8872 (set-marker (cdr region) nil))
8873 (goto-char point)))
8875 (defun gnus-mime-security-show-details (handle)
8876 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8877 (if (not details)
8878 (gnus-message 5 "No details.")
8879 (if gnus-mime-security-show-details-inline
8880 (let ((gnus-mime-security-button-pressed
8881 (not (get-text-property (point) 'gnus-mime-details)))
8882 (gnus-mime-security-button-line-format
8883 (get-text-property (point) 'gnus-line-format))
8884 (inhibit-read-only t))
8885 (forward-char -1)
8886 (while (eq (get-text-property (point) 'gnus-line-format)
8887 gnus-mime-security-button-line-format)
8888 (forward-char -1))
8889 (forward-char)
8890 (save-restriction
8891 (narrow-to-region (point) (point))
8892 (gnus-insert-mime-security-button handle))
8893 (delete-region (point)
8894 (or (text-property-not-all
8895 (point) (point-max)
8896 'gnus-line-format
8897 gnus-mime-security-button-line-format)
8898 (point-max))))
8899 ;; Not inlined.
8900 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8901 (with-current-buffer gnus-mime-security-details-buffer
8902 (erase-buffer)
8904 (setq gnus-mime-security-details-buffer
8905 (gnus-get-buffer-create "*MIME Security Details*")))
8906 (with-current-buffer gnus-mime-security-details-buffer
8907 (insert details)
8908 (goto-char (point-min)))
8909 (pop-to-buffer gnus-mime-security-details-buffer)))))
8911 (defun gnus-mime-security-press-button (handle)
8912 (save-excursion
8913 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8914 (gnus-mime-security-show-details handle)
8915 (gnus-mime-security-verify-or-decrypt handle))))
8917 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8918 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8919 (gnus-tmp-type
8920 (concat
8921 (or (nth 2 (assoc protocol mm-verify-function-alist))
8922 (nth 2 (assoc protocol mm-decrypt-function-alist))
8923 "Unknown")
8924 (if (equal (car handle) "multipart/signed")
8925 " Signed" " Encrypted")
8926 " Part"))
8927 (gnus-tmp-info
8928 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8929 "Undecided"))
8930 (gnus-tmp-details
8931 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8932 gnus-tmp-pressed-details
8933 b e)
8934 (setq gnus-tmp-details
8935 (if gnus-tmp-details
8936 (concat "\n" gnus-tmp-details)
8937 ""))
8938 (setq gnus-tmp-pressed-details
8939 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8940 (unless (bolp)
8941 (insert "\n"))
8942 (setq b (point))
8943 (gnus-eval-format
8944 gnus-mime-security-button-line-format
8945 gnus-mime-security-button-line-format-alist
8946 `(keymap ,gnus-mime-security-button-map
8947 gnus-callback gnus-mime-security-press-button
8948 gnus-line-format ,gnus-mime-security-button-line-format
8949 gnus-mime-details ,gnus-mime-security-button-pressed
8950 article-type annotation
8951 gnus-data ,handle))
8952 (setq e (if (bolp)
8953 ;; Exclude a newline.
8954 (1- (point))
8955 (point)))
8956 (when gnus-article-button-face
8957 (overlay-put (make-overlay b e nil t)
8958 'face gnus-article-button-face))
8959 (widget-convert-button
8960 'link b e
8961 :mime-handle handle
8962 :action 'gnus-widget-press-button
8963 :button-keymap gnus-mime-security-button-map
8964 :help-echo
8965 (lambda (_widget)
8966 ;; Needed to properly clear the message due to a bug in
8967 ;; wid-edit (XEmacs only).
8968 (when (boundp 'help-echo-owns-message)
8969 (setq help-echo-owns-message t))
8970 (format
8971 "%S: show detail; %S: more options"
8972 (aref gnus-mouse-2 0)
8973 (aref gnus-down-mouse-3 0))))))
8975 (defun gnus-mime-display-security (handle)
8976 (save-restriction
8977 (narrow-to-region (point) (point))
8978 (unless (gnus-unbuttonized-mime-type-p (car handle))
8979 (gnus-insert-mime-security-button handle))
8980 (gnus-mime-display-part (cadr handle))
8981 (unless (bolp)
8982 (insert "\n"))
8983 (unless (gnus-unbuttonized-mime-type-p (car handle))
8984 (let ((gnus-mime-security-button-line-format
8985 gnus-mime-security-button-end-line-format))
8986 (gnus-insert-mime-security-button handle)))
8987 (mm-set-handle-multipart-parameter
8988 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8989 (goto-char (point-max))))
8991 (defun gnus-mime-security-run-function (function)
8992 "Run FUNCTION with the security part under point."
8993 (gnus-article-check-buffer)
8994 (let ((data (get-text-property (point) 'gnus-data))
8995 buffer handle)
8996 (when (and (stringp (car-safe data))
8997 (setq buffer (mm-handle-multipart-original-buffer data))
8998 (setq handle (cadr data)))
8999 (if (bufferp (mm-handle-buffer handle))
9000 (progn
9001 (setq handle (cons buffer (copy-sequence (cdr handle))))
9002 (mm-handle-set-undisplayer handle nil))
9003 (setq handle (mm-make-handle
9004 buffer
9005 (mm-handle-multipart-ctl-parameter handle 'protocol)
9006 nil nil nil nil nil nil)))
9007 (funcall function handle))))
9009 (defun gnus-mime-security-save-part ()
9010 "Save the security part under point."
9011 (interactive)
9012 (gnus-mime-security-run-function 'mm-save-part))
9014 (defun gnus-mime-security-pipe-part ()
9015 "Pipe the security part under point to a process."
9016 (interactive)
9017 (gnus-mime-security-run-function 'mm-pipe-part))
9019 (gnus-ems-redefine)
9021 (provide 'gnus-art)
9023 (run-hooks 'gnus-art-load-hook)
9025 ;;; gnus-art.el ends here