Merge branch 'master' into comment-cache
[emacs.git] / lisp / gnus / gnus-art.el
bloba4ff840f75545690dd709f9bff44071993480faa
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2017 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 (repeat (choice (const nil)
256 (integer :value 200)
257 (number :value 4.0)
258 function
259 (regexp :value ".*"))))
260 :group 'gnus-article-signature)
262 (defcustom gnus-hidden-properties
263 ;; We use to have `intangible' here as well, but Emacs's command loop moves
264 ;; point out of invisible text anyway, so `intangible' is clearly not
265 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
266 '(invisible t)
267 "Property list to use for hiding text."
268 :type 'plist
269 :group 'gnus-article-hiding)
271 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
272 ;; frames in a session.
273 (defcustom gnus-article-x-face-command
274 (if (gnus-image-type-available-p 'pbm)
275 'gnus-display-x-face-in-from
276 "{ echo \
277 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
278 ; uncompface; } | icontopbm | display -")
279 "String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
284 function)
285 :version "21.1"
286 :group 'gnus-picon
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
296 For example,
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
298 :version "21.1"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
303 banner
304 :variable-document
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
307 :parameter-type
308 '(choice :tag "Banner"
309 :value nil
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
312 regexp
313 (const :tag "None" nil))
314 :parameter-document
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
321 directly.")
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 :type '(repeat
334 (cons
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
339 regexp
340 (const :tag "None" nil))))
341 :version "22.1"
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
345 `(let ((format "\
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 ,@body))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
356 (nth 2 value))
357 value)))
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
364 "\\'"))
365 pattern)
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
368 (= (nth 2 value) 2)
369 (nth 3 value))
370 value))))
372 (defcustom gnus-emphasis-alist
373 (let ((types
374 '(("\\*" "\\*" bold nil 2)
375 ("_" "_" underline)
376 ("/" "/" italic)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
381 (nconc
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
385 (or (nth 3 spec) 2)
386 (or (nth 4 spec) 3)
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
388 types))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
407 :type
408 '(repeat
409 (menu-choice
410 :format "%[Customizing Style%]\n%v"
411 :indent 2
412 (group :tag "Default"
413 :value ("" 0 0 default)
414 :value-create
415 (lambda (widget)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
418 :args))
419 :value)))
420 (if (not (eq (nth 2 value) 'default))
421 (widget-put
422 widget
423 :value
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
426 regexp
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
429 face)
430 (group :tag "Simple"
431 :value (("_" . "_") nil default)
432 (cons :format "%v"
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
437 face)))
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
443 value)))
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
451 :version "21.1"
452 :group 'gnus-article-emphasis
453 :type 'regexp)
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru '((t (:strike-through t)))
486 "Face used for displaying strike-through text (-word-)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-highlight-words
490 '((t (:background "black" :foreground "yellow")))
491 "Face used for displaying highlighted words."
492 :group 'gnus-article-emphasis)
494 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
495 "Format for display of Date headers in article bodies.
496 See `format-time-string' for the possible values.
498 The variable can also be function, which should return a complete Date
499 header. The function is called with one argument, the time, which can
500 be fed to `format-time-string'."
501 :type '(choice string function)
502 :link '(custom-manual "(gnus)Article Date")
503 :group 'gnus-article-washing)
505 (defcustom gnus-save-all-headers t
506 "If non-nil, don't remove any headers before saving.
507 This will be overridden by the `:headers' property that the symbol of
508 the saver function, which is specified by `gnus-default-article-saver',
509 might have."
510 :group 'gnus-article-saving
511 :type 'boolean)
513 (defcustom gnus-prompt-before-saving 'always
514 "This variable says how much prompting is to be done when saving articles.
515 If it is nil, no prompting will be done, and the articles will be
516 saved to the default files. If this variable is `always', each and
517 every article that is saved will be preceded by a prompt, even when
518 saving large batches of articles. If this variable is neither nil not
519 `always', there the user will be prompted once for a file name for
520 each invocation of the saving commands."
521 :group 'gnus-article-saving
522 :type '(choice (item always)
523 (item :tag "never" nil)
524 (sexp :tag "once" :format "%t\n" :value t)))
526 (defcustom gnus-article-show-cursor nil
527 "If non-nil, show the cursor in the Article buffer even when not selected."
528 :version "25.1"
529 :group 'gnus-article
530 :type 'bool)
532 (defcustom gnus-saved-headers gnus-visible-headers
533 "Headers to keep if `gnus-save-all-headers' is nil.
534 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
535 If that variable is nil, however, all headers that match this regexp
536 will be kept while the rest will be deleted before saving. This and
537 `gnus-save-all-headers' will be overridden by the `:headers' property
538 that the symbol of the saver function, which is specified by
539 `gnus-default-article-saver', might have."
540 :group 'gnus-article-saving
541 :type 'regexp)
543 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
544 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
545 "A function to save articles in your favorite format.
546 The function will be called by way of the `gnus-summary-save-article'
547 command, and friends such as `gnus-summary-save-article-rmail'.
549 Gnus provides the following functions:
551 * gnus-summary-save-in-rmail (Rmail format)
552 * gnus-summary-save-in-mail (Unix mail format)
553 * gnus-summary-save-in-folder (MH folder)
554 * gnus-summary-save-in-file (article format)
555 * gnus-summary-save-body-in-file (article body)
556 * gnus-summary-save-in-vm (use VM's folder format)
557 * gnus-summary-write-to-file (article format -- overwrite)
558 * gnus-summary-write-body-to-file (article body -- overwrite)
559 * gnus-summary-save-in-pipe (article format)
561 The symbol of each function may have the following properties:
563 * :decode
564 The value non-nil means save decoded articles. This is meaningful
565 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
566 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
567 `gnus-summary-save-in-pipe'.
569 * :function
570 The value specifies an alternative function which appends, not
571 overwrites, articles to a file. This implies that when saving many
572 articles at a time, `gnus-prompt-before-saving' is bound to t and all
573 articles are saved in a single file. This is meaningful only with
574 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
576 * :headers
577 The value specifies the symbol of a variable of which the value
578 specifies headers to be saved. If it is omitted,
579 `gnus-save-all-headers' and `gnus-saved-headers' control what
580 headers should be saved."
581 :group 'gnus-article-saving
582 :type '(radio (function-item gnus-summary-save-in-rmail)
583 (function-item gnus-summary-save-in-mail)
584 (function-item gnus-summary-save-in-folder)
585 (function-item gnus-summary-save-in-file)
586 (function-item gnus-summary-save-body-in-file)
587 (function-item gnus-summary-save-in-vm)
588 (function-item gnus-summary-write-to-file)
589 (function-item gnus-summary-write-body-to-file)
590 (function-item gnus-summary-save-in-pipe)
591 (function)))
593 (defcustom gnus-article-save-coding-system
594 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
595 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
596 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
597 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
598 "Coding system used to save decoded articles to a file.
600 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
601 which can safely encode any characters in text. This is used by the
602 commands including:
604 * gnus-summary-save-article-file
605 * gnus-summary-save-article-body-file
606 * gnus-summary-write-article-file
607 * gnus-summary-write-article-body-file
609 and the functions to which you may set `gnus-default-article-saver':
611 * gnus-summary-save-in-file
612 * gnus-summary-save-body-in-file
613 * gnus-summary-write-to-file
614 * gnus-summary-write-body-to-file
616 Those commands and functions save just text displayed in the article
617 buffer to a file if the value of this variable is non-nil. Note that
618 buttonized MIME parts will be lost in a saved file in that case.
619 Otherwise, raw articles will be saved."
620 :group 'gnus-article-saving
621 :type `(choice
622 :format "%{%t%}:\n %[Value Menu%] %v"
623 (const :tag "Save raw articles" nil)
624 ,@(delq nil
625 (mapcar
626 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
627 '((const :tag "UTF-8" utf-8)
628 (const :tag "iso-2022-7bit" iso-2022-7bit)
629 (const :tag "Emacs internal" emacs-mule)
630 (const :tag "escape-quoted" escape-quoted))))
631 (symbol :tag "Coding system")))
633 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Rmail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
637 :type 'function)
639 (defcustom gnus-mail-save-name 'gnus-plain-save-name
640 "A function generating a file name to save articles in Unix mail format.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
642 :group 'gnus-article-saving
643 :type 'function)
645 (defcustom gnus-folder-save-name 'gnus-folder-save-name
646 "A function generating a file name to save articles in MH folder.
647 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
648 :group 'gnus-article-saving
649 :type 'function)
651 (defcustom gnus-file-save-name 'gnus-numeric-save-name
652 "A function generating a file name to save articles in article format.
653 The function is called with NEWSGROUP, HEADERS, and optional
654 LAST-FILE."
655 :group 'gnus-article-saving
656 :type 'function)
658 (defcustom gnus-split-methods
659 '((gnus-article-archive-name)
660 (gnus-article-nndoc-name))
661 "Variable used to suggest where articles are to be saved.
662 For instance, if you would like to save articles related to Gnus in
663 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
664 you could set this variable to something like:
666 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
667 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
669 This variable is an alist where the key is the match and the
670 value is a list of possible files to save in if the match is
671 non-nil.
673 If the match is a string, it is used as a regexp match on the
674 article. If the match is a symbol, that symbol will be funcalled
675 from the buffer of the article to be saved with the newsgroup as the
676 parameter. If it is a list, it will be evalled in the same buffer.
678 If this form or function returns a string, this string will be used as a
679 possible file name; and if it returns a non-nil list, that list will be
680 used as possible file names."
681 :group 'gnus-article-saving
682 :type '(repeat (choice (list :value (fun) function)
683 (cons :value ("" "") regexp (repeat string))
684 (sexp :value nil))))
686 (defcustom gnus-page-delimiter "^\^L"
687 "Regexp describing what to use as article page delimiters.
688 The default value is \"^\^L\", which is a form linefeed at the
689 beginning of a line."
690 :type 'regexp
691 :group 'gnus-article-various)
693 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
694 "The format specification for the article mode line.
695 See `gnus-summary-mode-line-format' for a closer description.
697 The following additional specs are available:
699 %w The article washing status.
700 %m The number of MIME parts in the article."
701 :version "24.1"
702 :type 'string
703 :group 'gnus-article-various)
705 (defcustom gnus-article-mode-hook nil
706 "A hook for Gnus article mode."
707 :type 'hook
708 :group 'gnus-article-various)
710 (defcustom gnus-article-menu-hook nil
711 "Hook run after the creation of the article mode menu."
712 :type 'hook
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "A hook called after an article has been prepared in the article buffer."
717 :type 'hook
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
730 (defface gnus-button
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
740 :type 'face
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
747 above them."
748 :type 'face
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
754 :type 'face
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
759 '((t
760 (:italic t)))
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
769 '((((class color)
770 (background dark))
771 (:foreground "PaleGreen1"))
772 (((class color)
773 (background light))
774 (:foreground "red3"))
776 (:italic t)))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
785 '((((class color)
786 (background dark))
787 (:foreground "SeaGreen1"))
788 (((class color)
789 (background light))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
801 '((((class color)
802 (background dark))
803 (:foreground "yellow" :italic t))
804 (((class color)
805 (background light))
806 (:foreground "MidnightBlue" :italic t))
808 (:italic t)))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
811 articles."
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen2"))
822 (((class color)
823 (background light))
824 (:foreground "maroon"))
826 (:bold t)))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
835 '((((class color)
836 (background dark))
837 (:foreground "SpringGreen1" :italic t))
838 (((class color)
839 (background light))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
868 (choice :tag "Name"
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist '((pbm . (:face gnus-x-face))
876 (png . nil))
877 "Alist of image types and properties applied to Face and X-Face images.
878 Here are examples:
880 ;; Specify the altitude of Face images in the From header.
881 \(setq gnus-face-properties-alist
882 \\='((pbm . (:face gnus-x-face :ascent 80))
883 (png . (:ascent 80))))
885 ;; Show Face images as pressed buttons.
886 \(setq gnus-face-properties-alist
887 \\='((pbm . (:face gnus-x-face :relief -2))
888 (png . (:relief -2))))
890 See the manual for the valid properties for various image types.
891 Currently, `pbm' is used for X-Face images and `png' is used for Face
892 images in Emacs."
893 :version "23.1" ;; No Gnus
894 :group 'gnus-article-headers
895 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
897 (defcustom gnus-article-decode-hook
898 '(article-decode-charset article-decode-encoded-words
899 article-decode-group-name article-decode-idna-rhs)
900 "Hook run to decode charsets in articles."
901 :group 'gnus-article-headers
902 :type 'hook)
904 (defcustom gnus-display-mime-function 'gnus-display-mime
905 "Function to display MIME articles."
906 :group 'gnus-article-mime
907 :type 'function)
909 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
910 "Function used to decode headers.")
912 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
913 "Function used to decode addresses.")
915 (defvar gnus-article-dumbquotes-map
916 '((?\200 "EUR")
917 (?\202 ",")
918 (?\203 "f")
919 (?\204 ",,")
920 (?\205 "...")
921 (?\213 "<")
922 (?\214 "OE")
923 (?\221 "`")
924 (?\222 "'")
925 (?\223 "``")
926 (?\224 "\"")
927 (?\225 "*")
928 (?\226 "-")
929 (?\227 "--")
930 (?\230 "~")
931 (?\231 "(TM)")
932 (?\233 ">")
933 (?\234 "oe")
934 (?\264 "'"))
935 "Table for MS-to-Latin1 translation.")
937 (defcustom gnus-ignored-mime-types nil
938 "List of MIME types that should be ignored by Gnus."
939 :version "21.1"
940 :group 'gnus-article-mime
941 :type '(repeat regexp))
943 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
944 "List of MIME types that should not be given buttons when rendered inline.
945 See also `gnus-buttonized-mime-types' which may override this variable.
946 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
947 :version "21.1"
948 :group 'gnus-article-mime
949 :type '(repeat regexp))
951 (defcustom gnus-buttonized-mime-types nil
952 "List of MIME types that should be given buttons when rendered inline.
953 If set, this variable overrides `gnus-unbuttonized-mime-types'.
954 To see e.g. security buttons you could set this to
955 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
956 this list to display radio buttons that allow you to choose one of two
957 media types those mails include. See also `mm-discouraged-alternatives'.
958 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
959 :version "22.1"
960 :group 'gnus-article-mime
961 :type '(repeat regexp))
963 (defcustom gnus-inhibit-mime-unbuttonizing nil
964 "If non-nil, all MIME parts get buttons.
965 When nil (the default value), then some MIME parts do not get buttons,
966 as described by the variables `gnus-buttonized-mime-types' and
967 `gnus-unbuttonized-mime-types'."
968 :version "22.1"
969 :group 'gnus-article-mime
970 :type 'boolean)
972 (defcustom gnus-body-boundary-delimiter "_"
973 "String used to delimit header and body.
974 This variable is used by `gnus-article-treat-body-boundary' which can
975 be controlled by `gnus-treat-body-boundary'."
976 :version "22.1"
977 :group 'gnus-article-various
978 :type '(choice (item :tag "None" :value nil)
979 string))
981 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
982 "/usr/share/picons")
983 "Defines the location of the faces database.
984 For information on obtaining this database of pretty pictures, please
985 see http://www.cs.indiana.edu/picons/ftp/index.html"
986 :version "22.1"
987 :type '(repeat directory)
988 :link '(url-link :tag "download"
989 "http://www.cs.indiana.edu/picons/ftp/index.html")
990 :link '(custom-manual "(gnus)Picons")
991 :group 'gnus-picon)
993 (defun gnus-picons-installed-p ()
994 "Say whether picons are installed on your machine."
995 (let ((installed nil))
996 (dolist (database gnus-picon-databases)
997 (when (file-exists-p database)
998 (setq installed t)))
999 installed))
1001 (defcustom gnus-article-mime-part-function nil
1002 "Function called with a MIME handle as the argument.
1003 This is meant for people who want to do something automatic based
1004 on parts -- for instance, adding Vcard info to a database."
1005 :group 'gnus-article-mime
1006 :type '(choice (const nil)
1007 function))
1009 (defcustom gnus-mime-multipart-functions nil
1010 "An alist of MIME types to functions to display them."
1011 :version "21.1"
1012 :group 'gnus-article-mime
1013 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1015 (defcustom gnus-article-date-headers '(combined-lapsed)
1016 "A list of Date header formats to display.
1017 Valid formats are `ut' (Universal Time), `local' (local time
1018 zone), `english' (readable English), `lapsed' (elapsed time),
1019 `combined-lapsed' (both the original date and the elapsed time),
1020 `original' (the original date header), `iso8601' (ISO8601
1021 format), and `user-defined' (a user-defined format defined by the
1022 `gnus-article-time-format' variable).
1024 You have as many date headers as you want in the article buffer.
1025 Some of these headers are updated automatically. See
1026 `gnus-article-update-date-headers' for details."
1027 :version "24.1"
1028 :group 'gnus-article-headers
1029 :type '(set
1030 (const :tag "Universal time (UT)" ut)
1031 (const :tag "Local time zone" local)
1032 (const :tag "Readable English" english)
1033 (const :tag "Elapsed time" lapsed)
1034 (const :tag "Original and elapsed time" combined-lapsed)
1035 (const :tag "Original date header" original)
1036 (const :tag "ISO8601 format" iso8601)
1037 (const :tag "User-defined" user-defined)))
1039 (defcustom gnus-article-update-date-headers nil
1040 "A number that says how often to update the date header (in seconds).
1041 If nil, don't update it at all."
1042 :version "24.1"
1043 :group 'gnus-article-headers
1044 :type '(choice
1045 (item :tag "Don't update" :value nil)
1046 integer))
1048 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1049 "Function called with a MIME handle as the argument.
1050 This is meant for people who want to view first matched part.
1051 For `undisplayed-alternative' (default), the first undisplayed
1052 part or alternative part is used. For `undisplayed', the first
1053 undisplayed part is used. For a function, the first part which
1054 the function return t is used. For nil, the first part is
1055 used."
1056 :version "21.1"
1057 :group 'gnus-article-mime
1058 :type '(choice
1059 (item :tag "first" :value nil)
1060 (item :tag "undisplayed" :value undisplayed)
1061 (item :tag "undisplayed or alternative"
1062 :value undisplayed-alternative)
1063 (function)))
1065 (defcustom gnus-mime-action-alist
1066 '(("save to file" . gnus-mime-save-part)
1067 ("save and strip" . gnus-mime-save-part-and-strip)
1068 ("replace with file" . gnus-mime-replace-part)
1069 ("delete part" . gnus-mime-delete-part)
1070 ("display as text" . gnus-mime-inline-part)
1071 ("view the part" . gnus-mime-view-part)
1072 ("pipe to command" . gnus-mime-pipe-part)
1073 ("toggle display" . gnus-article-press-button)
1074 ("toggle display" . gnus-article-view-part-as-charset)
1075 ("view as type" . gnus-mime-view-part-as-type)
1076 ("view internally" . gnus-mime-view-part-internally)
1077 ("view externally" . gnus-mime-view-part-externally))
1078 "An alist of actions that run on the MIME attachment."
1079 :group 'gnus-article-mime
1080 :type '(repeat (cons (string :tag "name")
1081 (function))))
1083 (defcustom gnus-auto-select-part 1
1084 "Advance to next MIME part when deleting or stripping parts.
1086 When 0, point will be placed on the same part as before. When
1087 positive (negative), move point forward (backwards) this many
1088 parts. When nil, redisplay article."
1089 :version "23.1" ;; No Gnus
1090 :group 'gnus-article-mime
1091 :type '(choice (const nil :tag "Redisplay article.")
1092 (const 1 :tag "Next part.")
1093 (const 0 :tag "Current part.")
1094 integer))
1097 ;;; The treatment variables
1100 (defvar gnus-part-display-hook nil
1101 "Hook called on parts that are to receive treatment.")
1103 (defvar gnus-article-treat-custom
1104 '(choice (const :tag "Off" nil)
1105 (const :tag "On" t)
1106 (const :tag "Header" head)
1107 (const :tag "First" first)
1108 (const :tag "Last" last)
1109 (integer :tag "Less")
1110 (repeat :tag "Groups" regexp)
1111 (sexp :tag "Predicate")))
1113 (defvar gnus-article-treat-head-custom
1114 '(choice (const :tag "Off" nil)
1115 (const :tag "Header" head)))
1117 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1118 "text/x-patch" "text/html")
1119 "Part types eligible for treatment.")
1121 (defvar gnus-inhibit-treatment nil
1122 "Whether to inhibit treatment.")
1124 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1125 "Highlight the signature.
1126 Valid values are nil, t, `head', `first', `last', an integer or a
1127 predicate. See Info node `(gnus)Customizing Articles'."
1128 :group 'gnus-article-treat
1129 :link '(custom-manual "(gnus)Customizing Articles")
1130 :type gnus-article-treat-custom)
1131 (put 'gnus-treat-highlight-signature 'highlight t)
1133 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1134 "Add buttons.
1135 Valid values are nil, t, `head', `first', `last', an integer or a
1136 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1140 (put 'gnus-treat-buttonize 'highlight t)
1142 (defcustom gnus-treat-buttonize-head 'head
1143 "Add buttons to the head.
1144 Valid values are nil, t, `head', `first', `last', an integer or a
1145 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-head-custom)
1149 (put 'gnus-treat-buttonize-head 'highlight t)
1151 (defcustom gnus-treat-date 'head
1152 "Display dates according to the `gnus-article-date-headers' variable.
1153 Valid values are nil, t, `head', `first', `last', an integer or a
1154 predicate. See Info node `(gnus)Customizing Articles'."
1155 :version "24.1"
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-head-custom)
1160 (defcustom gnus-treat-emphasize 50000
1161 "Emphasize text.
1162 Valid values are nil, t, `head', `first', `last', an integer or a
1163 predicate. See Info node `(gnus)Customizing Articles'."
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-custom)
1167 (put 'gnus-treat-emphasize 'highlight t)
1169 (defcustom gnus-treat-strip-cr nil
1170 "Remove carriage returns.
1171 Valid values are nil, t, `head', `first', `last', an integer or a
1172 predicate. See Info node `(gnus)Customizing Articles'."
1173 :version "22.1"
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1178 (defcustom gnus-treat-unsplit-urls nil
1179 "Remove newlines from within URLs.
1180 Valid values are nil, t, `head', `first', `last', an integer or a
1181 predicate. See Info node `(gnus)Customizing Articles'."
1182 :version "22.1"
1183 :group 'gnus-article-treat
1184 :link '(custom-manual "(gnus)Customizing Articles")
1185 :type gnus-article-treat-custom)
1187 (defcustom gnus-treat-leading-whitespace nil
1188 "Remove leading whitespace in headers.
1189 Valid values are nil, t, `head', `first', `last', an integer or a
1190 predicate. See Info node `(gnus)Customizing Articles'."
1191 :version "22.1"
1192 :group 'gnus-article-treat
1193 :link '(custom-manual "(gnus)Customizing Articles")
1194 :type gnus-article-treat-custom)
1196 (defcustom gnus-treat-hide-headers 'head
1197 "Hide headers.
1198 Valid values are nil, t, `head', `first', `last', an integer or a
1199 predicate. See Info node `(gnus)Customizing Articles'."
1200 :group 'gnus-article-treat
1201 :link '(custom-manual "(gnus)Customizing Articles")
1202 :type gnus-article-treat-head-custom)
1204 (defcustom gnus-treat-hide-boring-headers nil
1205 "Hide boring 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-signature nil
1213 "Hide the signature.
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-custom)
1220 (defcustom gnus-treat-fill-article nil
1221 "Fill the article.
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-hide-citation nil
1229 "Hide cited text.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'.
1233 See `gnus-article-highlight-citation' for variables used to
1234 control what it hides."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1239 (defcustom gnus-treat-hide-citation-maybe nil
1240 "Hide cited text according to certain conditions.
1241 Valid values are nil, t, `head', `first', `last', an integer or a
1242 predicate. See Info node `(gnus)Customizing Articles'.
1244 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1245 how to control what it hides."
1246 :group 'gnus-article-treat
1247 :link '(custom-manual "(gnus)Customizing Articles")
1248 :type gnus-article-treat-custom)
1250 (defcustom gnus-treat-strip-list-identifiers 'head
1251 "Strip list identifiers from `gnus-list-identifiers'.
1252 Valid values are nil, t, `head', `first', `last', an integer or a
1253 predicate. See Info node `(gnus)Customizing Articles'."
1254 :version "21.1"
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1259 (gnus-define-group-parameter
1260 list-identifier
1261 :variable-document
1262 "Alist of regexps and correspondent identifiers."
1263 :variable-group gnus-article-washing
1264 :parameter-type
1265 '(choice :tag "Identifier"
1266 :value nil
1267 (symbol :tag "Item in `gnus-list-identifiers'" none)
1268 regexp
1269 (const :tag "None" nil))
1270 :parameter-document
1271 "If non-nil, specify how to remove `identifiers' from articles' subject.
1273 Any symbol is used to look up a regular expression to match the
1274 banner in `gnus-list-identifiers'. A string is used as a regular
1275 expression to match the identifier directly.")
1277 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1278 "Gnus 5.10 (Emacs 22.1)")
1280 (defcustom gnus-treat-strip-pem nil
1281 "Strip PEM signatures.
1282 Valid values are nil, t, `head', `first', `last', an integer or a
1283 predicate. See Info node `(gnus)Customizing Articles'."
1284 :group 'gnus-article-treat
1285 :link '(custom-manual "(gnus)Customizing Articles")
1286 :type gnus-article-treat-custom)
1288 (defcustom gnus-treat-strip-banner t
1289 "Strip banners from articles.
1290 The banner to be stripped is specified in the `banner' group parameter.
1291 Valid values are nil, t, `head', `first', `last', an integer or a
1292 predicate. See Info node `(gnus)Customizing Articles'."
1293 :group 'gnus-article-treat
1294 :link '(custom-manual "(gnus)Customizing Articles")
1295 :type gnus-article-treat-custom)
1297 (defcustom gnus-treat-highlight-headers 'head
1298 "Highlight the headers.
1299 Valid values are nil, t, `head', `first', `last', an integer or a
1300 predicate. See Info node `(gnus)Customizing Articles'."
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-head-custom)
1304 (put 'gnus-treat-highlight-headers 'highlight t)
1306 (defcustom gnus-treat-highlight-citation t
1307 "Highlight cited text.
1308 Valid values are nil, t, `head', `first', `last', an integer or a
1309 predicate. See Info node `(gnus)Customizing Articles'."
1310 :group 'gnus-article-treat
1311 :link '(custom-manual "(gnus)Customizing Articles")
1312 :type gnus-article-treat-custom)
1313 (put 'gnus-treat-highlight-citation 'highlight t)
1315 (defcustom gnus-treat-strip-headers-in-body t
1316 "Strip the X-No-Archive header line from the beginning of the body.
1317 Valid values are nil, t, `head', `first', `last', an integer or a
1318 predicate. See Info node `(gnus)Customizing Articles'."
1319 :version "21.1"
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1324 (defcustom gnus-treat-strip-trailing-blank-lines nil
1325 "Strip trailing blank lines.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'.
1329 When set to t, it also strips trailing blanks in all MIME parts.
1330 Consider to use `last' instead."
1331 :group 'gnus-article-treat
1332 :link '(custom-manual "(gnus)Customizing Articles")
1333 :type gnus-article-treat-custom)
1335 (defcustom gnus-treat-strip-leading-blank-lines nil
1336 "Strip leading blank lines.
1337 Valid values are nil, t, `head', `first', `last', an integer or a
1338 predicate. See Info node `(gnus)Customizing Articles'.
1340 When set to t, it also strips trailing blanks in all MIME parts."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-multiple-blank-lines nil
1346 "Strip multiple blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'."
1349 :group 'gnus-article-treat
1350 :link '(custom-manual "(gnus)Customizing Articles")
1351 :type gnus-article-treat-custom)
1353 (defcustom gnus-treat-unfold-headers 'head
1354 "Unfold folded header lines.
1355 Valid values are nil, t, `head', `first', `last', an integer or a
1356 predicate. See Info node `(gnus)Customizing Articles'."
1357 :version "22.1"
1358 :group 'gnus-article-treat
1359 :link '(custom-manual "(gnus)Customizing Articles")
1360 :type gnus-article-treat-custom)
1362 (defcustom gnus-article-unfold-long-headers nil
1363 "If non-nil, allow unfolding headers even if the header is long.
1364 If it is a regexp, only long headers matching this regexp are unfolded.
1365 If it is t, all long headers are unfolded.
1367 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1368 :version "23.1" ;; No Gnus
1369 :group 'gnus-article-treat
1370 :type '(choice (const nil)
1371 (const :tag "all" t)
1372 (regexp)))
1374 (defcustom gnus-treat-fold-headers nil
1375 "Fold headers.
1376 Valid values are nil, t, `head', `first', `last', an integer or a
1377 predicate. See Info node `(gnus)Customizing Articles'."
1378 :version "22.1"
1379 :group 'gnus-article-treat
1380 :link '(custom-manual "(gnus)Customizing Articles")
1381 :type gnus-article-treat-custom)
1383 (defcustom gnus-treat-fold-newsgroups 'head
1384 "Fold the Newsgroups and Followup-To headers.
1385 Valid values are nil, t, `head', `first', `last', an integer or a
1386 predicate. See Info node `(gnus)Customizing Articles'."
1387 :version "22.1"
1388 :group 'gnus-article-treat
1389 :link '(custom-manual "(gnus)Customizing Articles")
1390 :type gnus-article-treat-custom)
1392 (defcustom gnus-treat-overstrike t
1393 "Treat overstrike highlighting.
1394 Valid values are nil, t, `head', `first', `last', an integer or a
1395 predicate. See Info node `(gnus)Customizing Articles'."
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1399 (put 'gnus-treat-overstrike 'highlight t)
1401 (defcustom gnus-treat-ansi-sequences t
1402 "Treat ANSI SGR control sequences.
1403 Valid values are nil, t, `head', `first', `last', an integer or a
1404 predicate. See Info node `(gnus)Customizing Articles'."
1405 :group 'gnus-article-treat
1406 :link '(custom-manual "(gnus)Customizing Articles")
1407 :type gnus-article-treat-custom)
1409 (make-obsolete-variable 'gnus-treat-display-xface
1410 'gnus-treat-display-x-face "Emacs 22.1")
1412 (defcustom gnus-treat-display-x-face
1413 (and (not noninteractive)
1414 (gnus-image-type-available-p 'xbm)
1415 (condition-case nil
1416 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1417 (executable-find "icontopbm"))
1418 ;; shell-command-to-string may signal an error, e.g. if
1419 ;; shell-file-name is not found.
1420 (error nil))
1421 'head)
1422 "Display X-Face headers.
1423 Valid values are nil and `head'.
1424 See Info node `(gnus)Customizing Articles' and Info node
1425 `(gnus)X-Face' for details."
1426 :group 'gnus-article-treat
1427 :version "21.1"
1428 :link '(custom-manual "(gnus)Customizing Articles")
1429 :link '(custom-manual "(gnus)X-Face")
1430 :type gnus-article-treat-head-custom
1431 :set (lambda (symbol value)
1432 (set-default
1433 symbol
1434 (cond ((or (boundp symbol) (get symbol 'saved-value))
1435 value)
1436 ((boundp 'gnus-treat-display-xface)
1437 (message "\
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (default-value 'gnus-treat-display-xface))
1441 ((get 'gnus-treat-display-xface 'saved-value)
1442 (message "\
1443 ** gnus-treat-display-xface is an obsolete variable;\
1444 use gnus-treat-display-x-face instead")
1445 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1447 value)))))
1448 (put 'gnus-treat-display-x-face 'highlight t)
1450 (defcustom gnus-treat-display-face
1451 (and (not noninteractive)
1452 (gnus-image-type-available-p 'png)
1453 'head)
1454 "Display Face headers.
1455 Valid values are nil, t, `head', `first', `last', an integer or a
1456 predicate. See Info node `(gnus)Customizing Articles' and Info
1457 node `(gnus)Face' for details."
1458 :group 'gnus-article-treat
1459 :version "22.1"
1460 :link '(custom-manual "(gnus)Customizing Articles")
1461 :link '(custom-manual "(gnus)X-Face")
1462 :type gnus-article-treat-head-custom)
1463 (put 'gnus-treat-display-face 'highlight t)
1465 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1466 "Display smileys.
1467 Valid values are nil, t, `head', `first', `last', an integer or a
1468 predicate. See Info node `(gnus)Customizing Articles' and Info
1469 node `(gnus)Smileys' for details."
1470 :group 'gnus-article-treat
1471 :version "21.1"
1472 :link '(custom-manual "(gnus)Customizing Articles")
1473 :link '(custom-manual "(gnus)Smileys")
1474 :type gnus-article-treat-custom)
1475 (put 'gnus-treat-display-smileys 'highlight t)
1477 (defcustom gnus-treat-from-picon
1478 (if (and (gnus-image-type-available-p 'xpm)
1479 (gnus-picons-installed-p))
1480 'head nil)
1481 "Display picons in the From header.
1482 Valid values are nil, t, `head', `first', `last', an integer or a
1483 predicate. See Info node `(gnus)Customizing Articles' and Info
1484 node `(gnus)Picons' for details."
1485 :version "22.1"
1486 :group 'gnus-article-treat
1487 :group 'gnus-picon
1488 :link '(custom-manual "(gnus)Customizing Articles")
1489 :link '(custom-manual "(gnus)Picons")
1490 :type gnus-article-treat-head-custom)
1491 (put 'gnus-treat-from-picon 'highlight t)
1493 (defcustom gnus-treat-mail-picon
1494 (if (and (gnus-image-type-available-p 'xpm)
1495 (gnus-picons-installed-p))
1496 'head nil)
1497 "Display picons in To and Cc headers.
1498 Valid values are nil, t, `head', `first', `last', an integer or a
1499 predicate. See Info node `(gnus)Customizing Articles' and Info
1500 node `(gnus)Picons' for details."
1501 :version "22.1"
1502 :group 'gnus-article-treat
1503 :group 'gnus-picon
1504 :link '(custom-manual "(gnus)Customizing Articles")
1505 :link '(custom-manual "(gnus)Picons")
1506 :type gnus-article-treat-head-custom)
1507 (put 'gnus-treat-mail-picon 'highlight t)
1509 (defcustom gnus-treat-newsgroups-picon
1510 (if (and (gnus-image-type-available-p 'xpm)
1511 (gnus-picons-installed-p))
1512 'head nil)
1513 "Display picons in the Newsgroups and Followup-To headers.
1514 Valid values are nil, t, `head', `first', `last', an integer or a
1515 predicate. See Info node `(gnus)Customizing Articles' and Info
1516 node `(gnus)Picons' for details."
1517 :version "22.1"
1518 :group 'gnus-article-treat
1519 :group 'gnus-picon
1520 :link '(custom-manual "(gnus)Customizing Articles")
1521 :link '(custom-manual "(gnus)Picons")
1522 :type gnus-article-treat-head-custom)
1523 (put 'gnus-treat-newsgroups-picon 'highlight t)
1525 (defcustom gnus-treat-from-gravatar nil
1526 "Display gravatars in the From header.
1527 Valid values are nil, t, `head', `first', `last', an integer or a
1528 predicate. See Info node `(gnus)Customizing Articles' and Info
1529 node `(gnus)Gravatars' for details."
1530 :version "24.1"
1531 :group 'gnus-article-treat
1532 :group 'gnus-gravatar
1533 :link '(custom-manual "(gnus)Customizing Articles")
1534 :link '(custom-manual "(gnus)Gravatars")
1535 :type gnus-article-treat-head-custom)
1536 (put 'gnus-treat-from-gravatar 'highlight t)
1538 (defcustom gnus-treat-mail-gravatar nil
1539 "Display gravatars in To and Cc headers.
1540 Valid values are nil, t, `head', `first', `last', an integer or a
1541 predicate. See Info node `(gnus)Customizing Articles' and Info
1542 node `(gnus)Gravatars' for details."
1543 :version "24.1"
1544 :group 'gnus-article-treat
1545 :group 'gnus-gravatar
1546 :link '(custom-manual "(gnus)Customizing Articles")
1547 :link '(custom-manual "(gnus)Gravatars")
1548 :type gnus-article-treat-head-custom)
1549 (put 'gnus-treat-mail-gravatar 'highlight t)
1551 (defcustom gnus-treat-body-boundary
1552 (if (or gnus-treat-newsgroups-picon
1553 gnus-treat-mail-picon
1554 gnus-treat-from-picon
1555 gnus-treat-from-gravatar
1556 gnus-treat-mail-gravatar)
1557 ;; If there's much decoration, the user might prefer a boundary.
1558 'head
1559 nil)
1560 "Draw a boundary at the end of the headers.
1561 Valid values are nil and `head'.
1562 See Info node `(gnus)Customizing Articles' for details."
1563 :version "22.1"
1564 :group 'gnus-article-treat
1565 :link '(custom-manual "(gnus)Customizing Articles")
1566 :type gnus-article-treat-head-custom)
1568 (defcustom gnus-treat-capitalize-sentences nil
1569 "Capitalize sentence-starting words.
1570 Valid values are nil, t, `head', `first', `last', an integer or a
1571 predicate. See Info node `(gnus)Customizing Articles'."
1572 :version "21.1"
1573 :group 'gnus-article-treat
1574 :link '(custom-manual "(gnus)Customizing Articles")
1575 :type gnus-article-treat-custom)
1577 (defcustom gnus-treat-wash-html nil
1578 "Format as HTML.
1579 Valid values are nil, t, `head', `first', `last', an integer or a
1580 predicate. See Info node `(gnus)Customizing Articles'."
1581 :version "22.1"
1582 :group 'gnus-article-treat
1583 :link '(custom-manual "(gnus)Customizing Articles")
1584 :type gnus-article-treat-custom)
1586 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1587 "Fill long lines.
1588 Valid values are nil, t, `head', `first', `last', an integer or a
1589 predicate. See Info node `(gnus)Customizing Articles'."
1590 :version "24.1"
1591 :group 'gnus-article-treat
1592 :link '(custom-manual "(gnus)Customizing Articles")
1593 :type gnus-article-treat-custom)
1595 (defcustom gnus-treat-x-pgp-sig nil
1596 "Verify X-PGP-Sig.
1597 To automatically treat X-PGP-Sig, set it to head.
1598 Valid values are nil, t, `head', `first', `last', an integer or a
1599 predicate. See Info node `(gnus)Customizing Articles'."
1600 :version "22.1"
1601 :group 'gnus-article-treat
1602 :group 'mime-security
1603 :link '(custom-manual "(gnus)Customizing Articles")
1604 :type gnus-article-treat-custom)
1606 (defvar gnus-article-encrypt-protocol-alist
1607 '(("PGP" . mml2015-self-encrypt)))
1609 ;; Set to nil if more than one protocol added to
1610 ;; gnus-article-encrypt-protocol-alist.
1611 (defcustom gnus-article-encrypt-protocol "PGP"
1612 "The protocol used for encrypt articles.
1613 It is a string, such as \"PGP\". If nil, ask user."
1614 :version "22.1"
1615 :type 'string
1616 :group 'mime-security)
1618 (defcustom gnus-use-idna t
1619 "Whether IDNA decoding of headers is used when viewing messages."
1620 :version "26.1"
1621 :group 'gnus-article-headers
1622 :type 'boolean)
1624 (defcustom gnus-article-over-scroll nil
1625 "If non-nil, allow scrolling the article buffer even when there no more text."
1626 :version "22.1"
1627 :group 'gnus-article
1628 :type 'boolean)
1630 (defcustom gnus-inhibit-images nil
1631 "Non-nil means inhibit displaying of images inline in the article body."
1632 :version "24.1"
1633 :group 'gnus-article
1634 :type 'boolean)
1636 (defcustom gnus-blocked-images 'gnus-block-private-groups
1637 "Images that have URLs matching this regexp will be blocked.
1638 This can also be a function to be evaluated. If so, it will be
1639 called with the group name as the parameter, and should return a
1640 regexp."
1641 :version "24.1"
1642 :group 'gnus-art
1643 :type '(choice (const :tag "Allow all" nil)
1644 (regexp :tag "Regular expression")
1645 (function :tag "Use a function")))
1647 ;;; Internal variables
1649 (defvar gnus-english-month-names
1650 '("January" "February" "March" "April" "May" "June" "July" "August"
1651 "September" "October" "November" "December"))
1653 (defvar article-goto-body-goes-to-point-min-p nil)
1654 (defvar gnus-article-wash-types nil)
1655 (defvar gnus-article-emphasis-alist nil)
1656 (defvar gnus-article-image-alist nil)
1658 (defvar gnus-article-mime-handle-alist-1 nil)
1659 (defvar gnus-treatment-function-alist
1660 '((gnus-treat-strip-cr gnus-article-remove-cr)
1661 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1662 (gnus-treat-strip-banner gnus-article-strip-banner)
1663 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1664 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1665 (gnus-treat-buttonize gnus-article-add-buttons)
1666 (gnus-treat-fill-article gnus-article-fill-cited-article)
1667 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1668 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1669 (gnus-treat-display-x-face gnus-article-display-x-face)
1670 (gnus-treat-display-face gnus-article-display-face)
1671 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1672 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1673 (gnus-treat-hide-signature gnus-article-hide-signature)
1674 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1675 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1676 (gnus-treat-from-picon gnus-treat-from-picon)
1677 (gnus-treat-mail-picon gnus-treat-mail-picon)
1678 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1679 (gnus-treat-strip-pem gnus-article-hide-pem)
1680 (gnus-treat-date gnus-article-treat-date)
1681 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1682 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1683 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1684 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1685 (gnus-treat-strip-trailing-blank-lines
1686 gnus-article-remove-trailing-blank-lines)
1687 (gnus-treat-strip-leading-blank-lines
1688 gnus-article-strip-leading-blank-lines)
1689 (gnus-treat-strip-multiple-blank-lines
1690 gnus-article-strip-multiple-blank-lines)
1691 (gnus-treat-overstrike gnus-article-treat-overstrike)
1692 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1693 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1694 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1695 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1696 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1697 (gnus-treat-display-smileys gnus-treat-smiley)
1698 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1699 (gnus-treat-wash-html gnus-article-wash-html)
1700 (gnus-treat-emphasize gnus-article-emphasize)
1701 (gnus-treat-hide-citation gnus-article-hide-citation)
1702 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1703 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1704 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1706 (defvar gnus-article-mime-handle-alist nil)
1707 (defvar article-lapsed-timer nil)
1708 (defvar gnus-article-current-summary nil)
1710 (defvar gnus-article-mode-syntax-table
1711 (let ((table (copy-syntax-table text-mode-syntax-table)))
1712 ;; This causes the citation match run O(2^n).
1713 ;; (modify-syntax-entry ?- "w" table)
1714 (modify-syntax-entry ?> ")<" table)
1715 (modify-syntax-entry ?< "(>" table)
1716 ;; make M-. in article buffers work for `foo' strings,
1717 ;; and still allow C-s C-w to yank ' to the search ring
1718 (modify-syntax-entry ?' "'" table)
1719 (modify-syntax-entry ?` "'" table)
1720 table)
1721 "Syntax table used in article mode buffers.
1722 Initialized from `text-mode-syntax-table'.")
1724 (defvar gnus-save-article-buffer nil)
1726 (defvar gnus-number-of-articles-to-be-saved nil)
1728 (defvar gnus-inhibit-hiding nil)
1730 (defvar gnus-article-edit-mode nil)
1732 ;;; Macros for dealing with the article buffer.
1734 (defmacro gnus-with-article-headers (&rest forms)
1735 `(with-current-buffer gnus-article-buffer
1736 (save-restriction
1737 (let ((inhibit-read-only t)
1738 (inhibit-point-motion-hooks t)
1739 (case-fold-search t))
1740 (article-narrow-to-head)
1741 ,@forms))))
1743 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1744 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1746 (defmacro gnus-with-article-buffer (&rest forms)
1747 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1748 (with-current-buffer gnus-article-buffer
1749 (let ((inhibit-read-only t))
1750 ,@forms))))
1752 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1753 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1755 (defun gnus-article-goto-header (header)
1756 "Go to HEADER, which is a regular expression."
1757 (re-search-forward (concat "^\\(" header "\\):") nil t))
1759 (defsubst gnus-article-hide-text (b e props)
1760 "Set text PROPS on the B to E region."
1761 (gnus-add-text-properties-when 'article-type nil b e props))
1763 (defsubst gnus-article-unhide-text (b e)
1764 "Remove hidden text properties from region between B and E."
1765 (remove-text-properties b e gnus-hidden-properties))
1767 (defun gnus-article-hide-text-type (b e type)
1768 "Hide text of TYPE between B and E."
1769 (gnus-add-wash-type type)
1770 (gnus-article-hide-text
1771 b e (cons 'article-type (cons type gnus-hidden-properties))))
1773 (defun gnus-article-unhide-text-type (b e type)
1774 "Unhide text of TYPE between B and E."
1775 (gnus-delete-wash-type type)
1776 (remove-text-properties
1777 b e (cons 'article-type (cons type gnus-hidden-properties))))
1779 (defun gnus-article-delete-text-of-type (type)
1780 "Delete text of TYPE in the current buffer."
1781 (save-excursion
1782 (let ((b (point-min)))
1783 (if (eq type 'multipart)
1784 ;; Remove MIME buttons associated with multipart/alternative parts.
1785 (progn
1786 (goto-char b)
1787 (while (if (get-text-property (point) 'gnus-part)
1788 (setq b (point))
1789 (when (setq b (next-single-property-change (point)
1790 'gnus-part))
1791 (goto-char b)
1793 (end-of-line)
1794 (skip-chars-forward "\n")
1795 (when (eq (get-text-property b 'article-type) 'multipart)
1796 (delete-region b (point)))))
1797 (while (setq b (text-property-any b (point-max) 'article-type type))
1798 (delete-region
1799 b (or (text-property-not-all b (point-max) 'article-type type)
1800 (point-max))))))))
1802 (defun gnus-article-delete-invisible-text ()
1803 "Delete all invisible text in the current buffer."
1804 (save-excursion
1805 (let ((b (point-min)))
1806 (while (setq b (text-property-any b (point-max) 'invisible t))
1807 (delete-region
1808 b (or (text-property-not-all b (point-max) 'invisible t)
1809 (point-max)))))))
1811 (defsubst gnus-article-header-rank ()
1812 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1813 (let ((list gnus-sorted-header-list)
1814 (i 1))
1815 (while list
1816 (if (looking-at (car list))
1817 (setq list nil)
1818 (setq list (cdr list))
1819 (incf i)))
1822 (defun article-hide-headers (&optional _arg _delete)
1823 "Hide unwanted headers and possibly sort them as well."
1824 (interactive)
1825 ;; This function might be inhibited.
1826 (unless gnus-inhibit-hiding
1827 (let ((inhibit-read-only t)
1828 (case-fold-search t)
1829 (max (1+ (length gnus-sorted-header-list)))
1830 (inhibit-point-motion-hooks t)
1831 (cur (current-buffer))
1832 ignored visible beg)
1833 (save-excursion
1834 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1835 ;; group parameters, so we should go to the summary buffer.
1836 (when (prog1
1837 (condition-case nil
1838 (progn (set-buffer gnus-summary-buffer) t)
1839 (error nil))
1840 (setq ignored (when (not gnus-visible-headers)
1841 (cond ((stringp gnus-ignored-headers)
1842 gnus-ignored-headers)
1843 ((listp gnus-ignored-headers)
1844 (mapconcat 'identity
1845 gnus-ignored-headers
1846 "\\|"))))
1847 visible (cond ((stringp gnus-visible-headers)
1848 gnus-visible-headers)
1849 ((and gnus-visible-headers
1850 (listp gnus-visible-headers))
1851 (mapconcat 'identity
1852 gnus-visible-headers
1853 "\\|")))))
1854 (set-buffer cur))
1855 (save-restriction
1856 ;; First we narrow to just the headers.
1857 (article-narrow-to-head)
1858 ;; Hide any "From " lines at the beginning of (mail) articles.
1859 (while (looking-at "From ")
1860 (forward-line 1))
1861 (unless (bobp)
1862 (delete-region (point-min) (point)))
1863 ;; Then treat the rest of the header lines.
1864 ;; Then we use the two regular expressions
1865 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1866 ;; select which header lines is to remain visible in the
1867 ;; article buffer.
1868 (while (re-search-forward "^[^ \t:]*:" nil t)
1869 (beginning-of-line)
1870 ;; Mark the rank of the header.
1871 (put-text-property
1872 (point) (1+ (point)) 'message-rank
1873 (if (or (and visible (looking-at visible))
1874 (and ignored
1875 (not (looking-at ignored))))
1876 (gnus-article-header-rank)
1877 (+ 2 max)))
1878 (forward-line 1))
1879 (message-sort-headers-1)
1880 (when (setq beg (text-property-any
1881 (point-min) (point-max) 'message-rank (+ 2 max)))
1882 ;; We delete the unwanted headers.
1883 (gnus-add-wash-type 'headers)
1884 (add-text-properties (point-min) (+ 5 (point-min))
1885 '(article-type headers dummy-invisible t))
1886 (delete-region beg (point-max))))))))
1888 (defun article-hide-boring-headers (&optional arg)
1889 "Toggle hiding of headers that aren't very interesting.
1890 If given a negative prefix, always show; if given a positive prefix,
1891 always hide."
1892 (interactive (gnus-article-hidden-arg))
1893 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1894 (not gnus-show-all-headers))
1895 (save-excursion
1896 (save-restriction
1897 (let ((inhibit-read-only t)
1898 (inhibit-point-motion-hooks t))
1899 (article-narrow-to-head)
1900 (dolist (elem gnus-boring-article-headers)
1901 (goto-char (point-min))
1902 (cond
1903 ;; Hide empty headers.
1904 ((eq elem 'empty)
1905 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1906 (forward-line -1)
1907 (gnus-article-hide-text-type
1908 (point-at-bol)
1909 (progn
1910 (end-of-line)
1911 (if (re-search-forward "^[^ \t]" nil t)
1912 (match-beginning 0)
1913 (point-max)))
1914 'boring-headers)))
1915 ;; Hide boring Newsgroups header.
1916 ((eq elem 'newsgroups)
1917 (when (gnus-string-equal
1918 (gnus-fetch-field "newsgroups")
1919 (gnus-group-real-name
1920 (if (boundp 'gnus-newsgroup-name)
1921 gnus-newsgroup-name
1922 "")))
1923 (gnus-article-hide-header "newsgroups")))
1924 ((eq elem 'to-address)
1925 (let ((to (message-fetch-field "to"))
1926 (to-address
1927 (gnus-parameter-to-address
1928 (if (boundp 'gnus-newsgroup-name)
1929 gnus-newsgroup-name ""))))
1930 (when (and to to-address
1931 (ignore-errors
1932 (gnus-string-equal
1933 ;; only one address in To
1934 (nth 1 (mail-extract-address-components to))
1935 to-address)))
1936 (gnus-article-hide-header "to"))))
1937 ((eq elem 'to-list)
1938 (let ((to (message-fetch-field "to"))
1939 (to-list
1940 (gnus-parameter-to-list
1941 (if (boundp 'gnus-newsgroup-name)
1942 gnus-newsgroup-name ""))))
1943 (when (and to to-list
1944 (ignore-errors
1945 (gnus-string-equal
1946 ;; only one address in To
1947 (nth 1 (mail-extract-address-components to))
1948 to-list)))
1949 (gnus-article-hide-header "to"))))
1950 ((eq elem 'cc-list)
1951 (let ((cc (message-fetch-field "cc"))
1952 (to-list
1953 (gnus-parameter-to-list
1954 (if (boundp 'gnus-newsgroup-name)
1955 gnus-newsgroup-name ""))))
1956 (when (and cc to-list
1957 (ignore-errors
1958 (gnus-string-equal
1959 ;; only one address in CC
1960 (nth 1 (mail-extract-address-components cc))
1961 to-list)))
1962 (gnus-article-hide-header "cc"))))
1963 ((eq elem 'followup-to)
1964 (when (gnus-string-equal
1965 (message-fetch-field "followup-to")
1966 (message-fetch-field "newsgroups"))
1967 (gnus-article-hide-header "followup-to")))
1968 ((eq elem 'reply-to)
1969 (if (gnus-group-find-parameter
1970 gnus-newsgroup-name 'broken-reply-to)
1971 (gnus-article-hide-header "reply-to")
1972 (let ((from (message-fetch-field "from"))
1973 (reply-to (message-fetch-field "reply-to")))
1974 (when
1975 (and
1976 from reply-to
1977 (ignore-errors
1978 (equal
1979 (sort (mapcar
1980 (lambda (x) (downcase (cadr x)))
1981 (mail-extract-address-components from t))
1982 'string<)
1983 (sort (mapcar
1984 (lambda (x) (downcase (cadr x)))
1985 (mail-extract-address-components reply-to t))
1986 'string<))))
1987 (gnus-article-hide-header "reply-to")))))
1988 ((eq elem 'date)
1989 (let ((date (with-current-buffer gnus-original-article-buffer
1990 ;; If date in `gnus-article-buffer' is localized
1991 ;; (`gnus-treat-date-user-defined'),
1992 ;; `days-between' might fail.
1993 (message-fetch-field "date"))))
1994 (when (and date
1995 (< (days-between (current-time-string) date)
1997 (gnus-article-hide-header "date"))))
1998 ((eq elem 'long-to)
1999 (let ((to (message-fetch-field "to"))
2000 (cc (message-fetch-field "cc")))
2001 (when (> (length to) 1024)
2002 (gnus-article-hide-header "to"))
2003 (when (> (length cc) 1024)
2004 (gnus-article-hide-header "cc"))))
2005 ((eq elem 'many-to)
2006 (let ((to-count 0)
2007 (cc-count 0))
2008 (goto-char (point-min))
2009 (while (re-search-forward "^to:" nil t)
2010 (setq to-count (1+ to-count)))
2011 (when (> to-count 1)
2012 (while (> to-count 0)
2013 (goto-char (point-min))
2014 (save-restriction
2015 (re-search-forward "^to:" nil nil to-count)
2016 (forward-line -1)
2017 (narrow-to-region (point) (point-max))
2018 (gnus-article-hide-header "to"))
2019 (setq to-count (1- to-count))))
2020 (goto-char (point-min))
2021 (while (re-search-forward "^cc:" nil t)
2022 (setq cc-count (1+ cc-count)))
2023 (when (> cc-count 1)
2024 (while (> cc-count 0)
2025 (goto-char (point-min))
2026 (save-restriction
2027 (re-search-forward "^cc:" nil nil cc-count)
2028 (forward-line -1)
2029 (narrow-to-region (point) (point-max))
2030 (gnus-article-hide-header "cc"))
2031 (setq cc-count (1- cc-count)))))))))))))
2033 (defun gnus-article-hide-header (header)
2034 (save-excursion
2035 (goto-char (point-min))
2036 (when (re-search-forward (concat "^" header ":") nil t)
2037 (gnus-article-hide-text-type
2038 (point-at-bol)
2039 (progn
2040 (end-of-line)
2041 (if (re-search-forward "^[^ \t]" nil t)
2042 (match-beginning 0)
2043 (point-max)))
2044 'boring-headers))))
2046 (defvar gnus-article-normalized-header-length 40
2047 "Length of normalized headers.")
2049 (defun article-normalize-headers ()
2050 "Make all header lines 40 characters long."
2051 (interactive)
2052 (let ((inhibit-read-only t)
2053 column)
2054 (save-excursion
2055 (save-restriction
2056 (article-narrow-to-head)
2057 (while (not (eobp))
2058 (cond
2059 ((< (setq column (- (point-at-eol) (point)))
2060 gnus-article-normalized-header-length)
2061 (end-of-line)
2062 (insert (make-string
2063 (- gnus-article-normalized-header-length column)
2064 ? )))
2065 ((> column gnus-article-normalized-header-length)
2066 (put-text-property
2067 (progn
2068 (forward-char gnus-article-normalized-header-length)
2069 (point))
2070 (point-at-eol)
2071 'invisible t))
2073 ;; Do nothing.
2075 (forward-line 1))))))
2077 (defun article-treat-dumbquotes ()
2078 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2079 Note that this function guesses whether a character is a sm*rtq**t* or
2080 not, so it should only be used interactively.
2082 Sm*rtq**t*s are M****s***'s unilateral extension to the
2083 iso-8859-1 character map in an attempt to provide more quoting
2084 characters. If you see something like \\222 or \\264 where
2085 you're expecting some kind of apostrophe or quotation mark, then
2086 try this wash."
2087 (interactive)
2088 (article-translate-strings gnus-article-dumbquotes-map))
2090 (defvar org-entities)
2092 (defun article-treat-non-ascii ()
2093 "Translate many Unicode characters into their ASCII equivalents."
2094 (interactive)
2095 (require 'org-entities)
2096 (let ((table (make-char-table nil)))
2097 (dolist (elem org-entities)
2098 (when (and (listp elem)
2099 (= (length (nth 6 elem)) 1))
2100 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem))))
2101 (save-excursion
2102 (when (article-goto-body)
2103 (let ((inhibit-read-only t)
2104 replace props)
2105 (while (not (eobp))
2106 (if (not (setq replace (aref table (following-char))))
2107 (forward-char 1)
2108 (if (prog1
2109 (setq props (text-properties-at (point)))
2110 (delete-char 1))
2111 (add-text-properties (point) (progn (insert replace) (point))
2112 props)
2113 (insert replace)))))))))
2115 (defun article-translate-strings (map)
2116 "Translate all string in the body of the article according to MAP.
2117 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2118 (save-excursion
2119 (when (article-goto-body)
2120 (let ((inhibit-read-only t))
2121 (dolist (elem map)
2122 (let ((from (car elem))
2123 (to (cadr elem)))
2124 (save-excursion
2125 (if (stringp from)
2126 (while (search-forward from nil t)
2127 (replace-match to))
2128 (while (not (eobp))
2129 (if (eq (following-char) from)
2130 (progn
2131 (delete-char 1)
2132 (insert to))
2133 (forward-char 1)))))))))))
2135 (defun article-treat-overstrike ()
2136 "Translate overstrikes into bold text."
2137 (interactive)
2138 (save-excursion
2139 (when (article-goto-body)
2140 (let ((inhibit-read-only t))
2141 (while (search-forward "\b" nil t)
2142 (let ((next (char-after))
2143 (previous (char-after (- (point) 2))))
2144 ;; We do the boldification/underlining by hiding the
2145 ;; overstrikes and putting the proper text property
2146 ;; on the letters.
2147 (cond
2148 ((eq next previous)
2149 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2150 (put-text-property (point) (1+ (point)) 'face 'bold))
2151 ((eq next ?_)
2152 (gnus-article-hide-text-type
2153 (1- (point)) (1+ (point)) 'overstrike)
2154 (put-text-property
2155 (- (point) 2) (1- (point)) 'face 'underline))
2156 ((eq previous ?_)
2157 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2158 (put-text-property
2159 (point) (1+ (point)) 'face 'underline)))))))))
2161 (defun article-treat-ansi-sequences ()
2162 "Translate ANSI SGR control sequences into overlays or extents."
2163 (interactive)
2164 (save-excursion
2165 (when (article-goto-body)
2166 (let ((inhibit-read-only t))
2167 (ansi-color-apply-on-region (point) (point-max))))))
2169 (defun gnus-article-treat-unfold-headers ()
2170 "Unfold folded message headers.
2171 Only the headers that fit into the current window width will be
2172 unfolded."
2173 (interactive)
2174 (gnus-with-article-headers
2175 (let (length)
2176 (while (not (eobp))
2177 (save-restriction
2178 (mail-header-narrow-to-field)
2179 (let* ((header (buffer-string))
2180 (unfoldable
2181 (or (equal gnus-article-unfold-long-headers t)
2182 (and (stringp gnus-article-unfold-long-headers)
2183 (string-match gnus-article-unfold-long-headers
2184 header)))))
2185 (with-temp-buffer
2186 (insert header)
2187 (goto-char (point-min))
2188 (while (re-search-forward "\n[\t ]" nil t)
2189 (replace-match " " t t)))
2190 (setq length (- (point-max) (point-min) 1))
2191 (when (or unfoldable
2192 (< length (window-width)))
2193 (while (re-search-forward "\n[\t ]" nil t)
2194 (replace-match " " t t))))
2195 (goto-char (point-max)))))))
2197 (defun gnus-article-treat-fold-headers ()
2198 "Fold message headers."
2199 (interactive)
2200 (gnus-with-article-headers
2201 (while (not (eobp))
2202 (save-restriction
2203 (mail-header-narrow-to-field)
2204 (mail-header-fold-field)
2205 (goto-char (point-max))))))
2207 (defun gnus-treat-smiley ()
2208 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2209 (interactive)
2210 (gnus-with-article-buffer
2211 (if (memq 'smiley gnus-article-wash-types)
2212 (gnus-delete-images 'smiley)
2213 (article-goto-body)
2214 (let ((images (smiley-region (point) (point-max))))
2215 (when images
2216 (gnus-add-wash-type 'smiley)
2217 (dolist (image images)
2218 (gnus-add-image 'smiley image)))))))
2220 (defun gnus-article-remove-images ()
2221 "Remove all images from the article buffer."
2222 (interactive)
2223 (gnus-with-article-buffer
2224 (save-restriction
2225 (widen)
2226 (dolist (elem gnus-article-image-alist)
2227 (gnus-delete-images (car elem))))))
2229 (autoload 'w3m-toggle-inline-images "w3m")
2231 (defun gnus-article-show-images ()
2232 "Show any images that are in the HTML-rendered article buffer.
2233 This only works if the article in question is HTML."
2234 (interactive)
2235 (gnus-with-article-buffer
2236 (save-restriction
2237 (widen)
2238 (if (eq mm-text-html-renderer 'w3m)
2239 (w3m-toggle-inline-images)
2240 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2241 'image-displayer))
2242 (destructuring-bind (start end function) region
2243 (funcall function (get-text-property start 'image-url)
2244 start end)))))))
2246 (defun gnus-article-treat-fold-newsgroups ()
2247 "Unfold folded message headers.
2248 Only the headers that fit into the current window width will be
2249 unfolded."
2250 (interactive)
2251 (gnus-with-article-headers
2252 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2253 (save-restriction
2254 (mail-header-narrow-to-field)
2255 (while (re-search-forward ", *" nil t)
2256 (replace-match ", " t t))
2257 (mail-header-fold-field)
2258 (goto-char (point-max))))))
2260 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2261 "Value of `truncate-lines' in Gnus Article buffer.
2262 Valid values are nil, t, `head', `first', `last', an integer or a
2263 predicate. See Info node `(gnus)Customizing Articles'."
2264 :version "23.1" ;; No Gnus
2265 :group 'gnus-article
2266 ;; :link '(custom-manual "(gnus)Customizing Articles")
2267 :type 'boolean)
2269 (defun gnus-article-toggle-truncate-lines (&optional arg)
2270 "Toggle whether to fold or truncate long lines in article the buffer.
2271 If ARG is non-nil and not a number, toggle
2272 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2273 long lines if and only if arg is positive."
2274 (interactive "P")
2275 (cond
2276 ((and (numberp arg) (> arg 0))
2277 (setq gnus-article-truncate-lines t))
2278 ((numberp arg)
2279 (setq gnus-article-truncate-lines nil))
2280 (arg
2281 (setq gnus-article-truncate-lines
2282 (not gnus-article-truncate-lines))))
2283 (gnus-with-article-buffer
2284 (cond
2285 ((and (numberp arg) (> arg 0))
2286 (setq truncate-lines nil))
2287 ((numberp arg)
2288 (setq truncate-lines t)))
2289 (toggle-truncate-lines)))
2291 (defun gnus-article-treat-body-boundary ()
2292 "Place a boundary line at the end of the headers."
2293 (interactive)
2294 (when (and gnus-body-boundary-delimiter
2295 (> (length gnus-body-boundary-delimiter) 0))
2296 (gnus-with-article-headers
2297 (goto-char (point-max))
2298 (let ((start (point)))
2299 (insert "X-Boundary: ")
2300 (add-text-properties start (point) gnus-hidden-properties)
2301 (insert (let (str (max (window-width)))
2302 (while (>= max (length str))
2303 (setq str (concat str gnus-body-boundary-delimiter)))
2304 (substring str 0 max))
2305 "\n")
2306 (put-text-property start (point) 'gnus-decoration 'header)))))
2308 (defun article-fill-long-lines ()
2309 "Fill lines that are wider than the window width."
2310 (interactive)
2311 (save-excursion
2312 (let ((inhibit-read-only t)
2313 (width (window-width (get-buffer-window (current-buffer)))))
2314 (save-restriction
2315 (article-goto-body)
2316 (let ((adaptive-fill-mode nil)) ;Why? -sm
2317 (while (not (eobp))
2318 (end-of-line)
2319 (when (>= (current-column) (min fill-column width))
2320 (narrow-to-region (min (1+ (point)) (point-max))
2321 (point-at-bol))
2322 (let ((goback (point-marker)))
2323 (fill-paragraph nil)
2324 (goto-char (marker-position goback)))
2325 (widen))
2326 (forward-line 1)))))))
2328 (defun article-capitalize-sentences ()
2329 "Capitalize the first word in each sentence."
2330 (interactive)
2331 (save-excursion
2332 (let ((inhibit-read-only t)
2333 (paragraph-start "^[\n\^L]"))
2334 (article-goto-body)
2335 (while (not (eobp))
2336 (capitalize-word 1)
2337 (forward-sentence)))))
2339 (defun article-remove-cr ()
2340 "Remove trailing CRs and then translate remaining CRs into LFs."
2341 (interactive)
2342 (save-excursion
2343 (let ((inhibit-read-only t))
2344 (goto-char (point-min))
2345 (while (re-search-forward "\r+$" nil t)
2346 (replace-match "" t t))
2347 (goto-char (point-min))
2348 (while (search-forward "\r" nil t)
2349 (replace-match "\n" t t)))))
2351 (defun article-remove-trailing-blank-lines ()
2352 "Remove all trailing blank lines from the article."
2353 (interactive)
2354 (save-excursion
2355 (let ((inhibit-read-only t))
2356 (goto-char (point-max))
2357 (delete-region
2358 (point)
2359 (progn
2360 (while (and (not (bobp))
2361 (looking-at "^[ \t]*$")
2362 (not (gnus-annotation-in-region-p
2363 (point) (point-at-eol))))
2364 (forward-line -1))
2365 (forward-line 1)
2366 (point))))))
2368 (defvar gnus-face-properties-alist)
2370 (defun article-display-face (&optional force)
2371 "Display any Face headers in the header."
2372 (interactive (list 'force))
2373 (let ((wash-face-p buffer-read-only))
2374 (gnus-with-article-headers
2375 ;; When displaying parts, this function can be called several times on
2376 ;; the same article, without any intended toggle semantic (as typing `W
2377 ;; D d' would have). So face deletion must occur only when we come from
2378 ;; an interactive command, that is when the *Article* buffer is
2379 ;; read-only.
2380 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2381 (gnus-delete-images 'face)
2382 (let ((from (message-fetch-field "from"))
2383 faces)
2384 (save-current-buffer
2385 (when (and wash-face-p
2386 (gnus-buffer-live-p gnus-original-article-buffer)
2387 (not (re-search-forward "^Face:[\t ]*" nil t)))
2388 (set-buffer gnus-original-article-buffer))
2389 (save-restriction
2390 (mail-narrow-to-head)
2391 (when (or force
2392 ;; Check whether this face is censored.
2393 (not (and gnus-article-x-face-too-ugly
2394 (or from
2395 (setq from (message-fetch-field "from")))
2396 (string-match gnus-article-x-face-too-ugly
2397 from))))
2398 (while (gnus-article-goto-header "Face")
2399 (push (mail-header-field-value) faces)))))
2400 (when faces
2401 (goto-char (point-min))
2402 (let (png image)
2403 (unless (setq from (gnus-article-goto-header "from"))
2404 (insert "From:")
2405 (setq from (point))
2406 (insert " [no 'from' set]\n"))
2407 (while faces
2408 (when (setq png (gnus-convert-face-to-png (pop faces)))
2409 (setq image
2410 (apply 'gnus-create-image png 'png t
2411 (cdr (assq 'png gnus-face-properties-alist))))
2412 (goto-char from)
2413 (when image
2414 (gnus-add-wash-type 'face)
2415 (gnus-add-image 'face image)
2416 (gnus-put-image image nil 'face)))))))))))
2418 (defun article-display-x-face (&optional force)
2419 "Look for an X-Face header and display it if present."
2420 (interactive (list 'force))
2421 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2422 (gnus-with-article-headers
2423 ;; Delete the old process, if any.
2424 (when (process-status "article-x-face")
2425 (delete-process "article-x-face"))
2426 ;; See the comment in `article-display-face'.
2427 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2428 ;; We have already displayed X-Faces, so we remove them
2429 ;; instead.
2430 (gnus-delete-images 'xface)
2431 ;; Display X-Faces.
2432 (let ((from (message-fetch-field "from"))
2433 x-faces)
2434 (save-current-buffer
2435 (when (and wash-face-p
2436 (gnus-buffer-live-p gnus-original-article-buffer)
2437 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2438 ;; If type `W f', use gnus-original-article-buffer,
2439 ;; otherwise use the current buffer because displaying
2440 ;; RFC822 parts calls this function too.
2441 (set-buffer gnus-original-article-buffer))
2442 (save-restriction
2443 (mail-narrow-to-head)
2444 (and gnus-article-x-face-command
2445 (or force
2446 ;; Check whether this face is censored.
2447 (not (and gnus-article-x-face-too-ugly
2448 (or from
2449 (setq from (message-fetch-field "from")))
2450 (string-match gnus-article-x-face-too-ugly
2451 from))))
2452 (while (gnus-article-goto-header "X-Face")
2453 (push (mail-header-field-value) x-faces)))))
2454 (when x-faces
2455 ;; We display the face.
2456 (cond ((functionp gnus-article-x-face-command)
2457 ;; The command is a lisp function, so we call it.
2458 (mapc gnus-article-x-face-command x-faces))
2459 ((stringp gnus-article-x-face-command)
2460 ;; The command is a string, so we interpret the command
2461 ;; as a, well, command, and fork it off.
2462 (let ((process-connection-type nil))
2463 (set-process-query-on-exit-flag
2464 (start-process
2465 "article-x-face" nil shell-file-name
2466 shell-command-switch gnus-article-x-face-command)
2467 nil)
2468 ;; Sending multiple EOFs to xv doesn't work,
2469 ;; so we only do a single external face.
2470 (with-temp-buffer
2471 (insert (car x-faces))
2472 (process-send-region "article-x-face"
2473 (point-min) (point-max)))
2474 (process-send-eof "article-x-face")))
2476 (error "`%s' set to `%s' is not a function"
2477 gnus-article-x-face-command
2478 'gnus-article-x-face-command)))))))))
2480 (defun article-decode-mime-words ()
2481 "Decode all MIME-encoded words in the article."
2482 (interactive)
2483 (gnus-with-article-buffer
2484 (let ((inhibit-point-motion-hooks t)
2485 (mail-parse-charset gnus-newsgroup-charset)
2486 (mail-parse-ignored-charsets
2487 (with-current-buffer gnus-summary-buffer
2488 gnus-newsgroup-ignored-charsets)))
2489 (mail-decode-encoded-word-region (point-min) (point-max)))))
2491 (defun article-decode-charset (&optional prompt)
2492 "Decode charset-encoded text in the article.
2493 If PROMPT (the prefix), prompt for a coding system to use."
2494 (interactive "P")
2495 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2496 (inhibit-read-only t)
2497 (mail-parse-charset gnus-newsgroup-charset)
2498 (mail-parse-ignored-charsets
2499 (save-excursion (condition-case nil
2500 (set-buffer gnus-summary-buffer)
2501 (error))
2502 gnus-newsgroup-ignored-charsets))
2503 ct cte ctl charset format)
2504 (save-excursion
2505 (save-restriction
2506 (article-narrow-to-head)
2507 (setq ct (message-fetch-field "Content-Type" t)
2508 cte (message-fetch-field "Content-Transfer-Encoding" t)
2509 ctl (and ct (mail-header-parse-content-type ct))
2510 charset (cond
2511 (prompt
2512 (read-coding-system "Charset to decode: "))
2513 (ctl
2514 (mail-content-type-get ctl 'charset)))
2515 format (and ctl (mail-content-type-get ctl 'format)))
2516 (when cte
2517 (setq cte (mail-header-strip-cte cte)))
2518 (if (and ctl (not (string-match "/" (car ctl))))
2519 (setq ctl nil))
2520 (goto-char (point-max)))
2521 (forward-line 1)
2522 (save-restriction
2523 (narrow-to-region (point) (point-max))
2524 (when (and (eq mail-parse-charset 'gnus-decoded)
2525 (eq (mm-body-7-or-8) '8bit))
2526 ;; The text code could have been decoded.
2527 (setq charset mail-parse-charset))
2528 (when (and (or (not ctl)
2529 (equal (car ctl) "text/plain"))
2530 (not format)) ;; article with format will decode later.
2531 (mm-decode-body
2532 charset (and cte (intern (downcase cte)))
2533 (car ctl)))))))
2535 (defun article-decode-encoded-words ()
2536 "Remove encoded-word encoding from headers."
2537 (let ((inhibit-point-motion-hooks t)
2538 (mail-parse-charset gnus-newsgroup-charset)
2539 (mail-parse-ignored-charsets
2540 (save-excursion (condition-case nil
2541 (set-buffer gnus-summary-buffer)
2542 (error))
2543 gnus-newsgroup-ignored-charsets))
2544 (inhibit-read-only t)
2545 end start)
2546 (goto-char (point-min))
2547 (when (search-forward "\n\n" nil 'move)
2548 (forward-line -1))
2549 (setq end (point))
2550 (while (not (bobp))
2551 (while (progn
2552 (forward-line -1)
2553 (and (not (bobp))
2554 (memq (char-after) '(?\t ? )))))
2555 (setq start (point))
2556 (if (looking-at "\
2557 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2558 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2559 (funcall gnus-decode-address-function start end)
2560 (funcall gnus-decode-header-function start end))
2561 (goto-char (setq end start)))))
2563 (defun article-decode-group-name ()
2564 "Decode group names in Newsgroups, Followup-To and Xref headers."
2565 (let ((inhibit-point-motion-hooks t)
2566 (inhibit-read-only t)
2567 (method (gnus-find-method-for-group gnus-newsgroup-name))
2568 regexp)
2569 (when (and (or gnus-group-name-charset-method-alist
2570 gnus-group-name-charset-group-alist)
2571 (gnus-buffer-live-p gnus-original-article-buffer))
2572 (save-restriction
2573 (article-narrow-to-head)
2574 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2575 (with-current-buffer gnus-original-article-buffer
2576 (goto-char (point-min)))
2577 (setq regexp (concat "^" header
2578 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2579 (while (re-search-forward regexp nil t)
2580 (replace-match (save-match-data
2581 (gnus-decode-newsgroups
2582 ;; XXX how to use data in article buffer?
2583 (with-current-buffer gnus-original-article-buffer
2584 (re-search-forward regexp nil t)
2585 (match-string 1))
2586 gnus-newsgroup-name method))
2587 t t nil 1))
2588 (goto-char (point-min)))))))
2590 (defun article-decode-idna-rhs ()
2591 "Decode IDNA strings in RHS in various headers in current buffer.
2592 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2593 Mail-Reply-To: and Mail-Followup-To:."
2594 (when gnus-use-idna
2595 (save-restriction
2596 (let ((inhibit-point-motion-hooks t)
2597 (inhibit-read-only t))
2598 (article-narrow-to-head)
2599 (goto-char (point-min))
2600 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2601 (let (ace unicode)
2602 (when (save-match-data
2603 (and (setq ace (match-string 1))
2604 (save-excursion
2605 (and (re-search-backward "^[^ \t]" nil t)
2606 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2607 (setq unicode (puny-decode-domain ace))))
2608 (unless (string= ace unicode)
2609 (replace-match unicode nil nil nil 1)))))))))
2611 (defun article-de-quoted-unreadable (&optional force read-charset)
2612 "Translate a quoted-printable-encoded article.
2613 If FORCE, decode the article whether it is marked as quoted-printable
2614 or not.
2615 If READ-CHARSET, ask for a coding system."
2616 (interactive (list 'force current-prefix-arg))
2617 (save-excursion
2618 (let ((inhibit-read-only t) type charset)
2619 (if (gnus-buffer-live-p gnus-original-article-buffer)
2620 (with-current-buffer gnus-original-article-buffer
2621 (setq type
2622 (gnus-fetch-field "content-transfer-encoding"))
2623 (let* ((ct (gnus-fetch-field "content-type"))
2624 (ctl (and ct (mail-header-parse-content-type ct))))
2625 (setq charset (and ctl
2626 (mail-content-type-get ctl 'charset)))
2627 (if (stringp charset)
2628 (setq charset (intern (downcase charset)))))))
2629 (if read-charset
2630 (setq charset (read-coding-system "Charset: " charset)))
2631 (unless charset
2632 (setq charset gnus-newsgroup-charset))
2633 (when (or force
2634 (and type (let ((case-fold-search t))
2635 (string-match "quoted-printable" type))))
2636 (article-goto-body)
2637 (quoted-printable-decode-region
2638 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2640 (defun article-de-base64-unreadable (&optional force read-charset)
2641 "Translate a base64 article.
2642 If FORCE, decode the article whether it is marked as base64 not.
2643 If READ-CHARSET, ask for a coding system."
2644 (interactive (list 'force current-prefix-arg))
2645 (save-excursion
2646 (let ((inhibit-read-only t) type charset)
2647 (if (gnus-buffer-live-p gnus-original-article-buffer)
2648 (with-current-buffer gnus-original-article-buffer
2649 (setq type
2650 (gnus-fetch-field "content-transfer-encoding"))
2651 (let* ((ct (gnus-fetch-field "content-type"))
2652 (ctl (and ct (mail-header-parse-content-type ct))))
2653 (setq charset (and ctl
2654 (mail-content-type-get ctl 'charset)))
2655 (if (stringp charset)
2656 (setq charset (intern (downcase charset)))))))
2657 (if read-charset
2658 (setq charset (read-coding-system "Charset: " charset)))
2659 (unless charset
2660 (setq charset gnus-newsgroup-charset))
2661 (when (or force
2662 (and type (let ((case-fold-search t))
2663 (string-match "base64" type))))
2664 (article-goto-body)
2665 (save-restriction
2666 (narrow-to-region (point) (point-max))
2667 (base64-decode-region (point-min) (point-max))
2668 (decode-coding-region
2669 (point-min) (point-max)
2670 (mm-charset-to-coding-system charset nil t)))))))
2672 (declare-function rfc1843-decode-region "rfc1843" (from to))
2674 (defun article-decode-HZ ()
2675 "Translate a HZ-encoded article."
2676 (interactive)
2677 (require 'rfc1843)
2678 (save-excursion
2679 (let ((inhibit-read-only t))
2680 (rfc1843-decode-region (point-min) (point-max)))))
2682 (defun article-unsplit-urls ()
2683 "Remove the newlines that some other mailers insert into URLs."
2684 (interactive)
2685 (save-excursion
2686 (let ((inhibit-read-only t))
2687 (goto-char (point-min))
2688 (while (re-search-forward
2689 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2690 (replace-match "\\1\\3" t)))
2691 (when (called-interactively-p 'any)
2692 (gnus-treat-article nil))))
2694 (defun article-wash-html ()
2695 "Format an HTML article."
2696 (interactive)
2697 (let ((handles nil)
2698 (buffer-read-only nil))
2699 (when (gnus-buffer-live-p gnus-original-article-buffer)
2700 (with-current-buffer gnus-original-article-buffer
2701 (setq handles (mm-dissect-buffer t t))))
2702 (article-goto-body)
2703 (delete-region (point) (point-max))
2704 (mm-enable-multibyte)
2705 (mm-inline-text-html handles)))
2707 (defvar gnus-article-browse-html-temp-list nil
2708 "List of temporary files created by `gnus-article-browse-html-parts'.
2709 Internal variable.")
2711 (defcustom gnus-article-browse-delete-temp 'ask
2712 "What to do with temporary files from `gnus-article-browse-html-parts'.
2713 If nil, don't delete temporary files. If it is t, delete them on
2714 exit from the summary buffer. If it is the symbol `file', query
2715 on each file, if it is `ask' ask once when exiting from the
2716 summary buffer."
2717 :group 'gnus-article
2718 :version "23.1" ;; No Gnus
2719 :type '(choice (const :tag "Don't delete" nil)
2720 (const :tag "Don't ask" t)
2721 (const :tag "Ask" ask)
2722 (const :tag "Ask for each file" file)))
2724 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2726 (defun gnus-article-browse-delete-temp-files (&optional how)
2727 "Delete temp-files created by `gnus-article-browse-html-parts'."
2728 (when (and gnus-article-browse-html-temp-list
2729 (progn
2730 (or how (setq how gnus-article-browse-delete-temp))
2731 (if (eq how 'ask)
2732 (let ((files (length gnus-article-browse-html-temp-list)))
2733 (or (gnus-y-or-n-p
2734 (if (= files 1)
2735 "Delete the temporary HTML file? "
2736 (format "Delete all %s temporary HTML files? "
2737 files)))
2738 (setq gnus-article-browse-html-temp-list nil)))
2739 how)))
2740 (dolist (file gnus-article-browse-html-temp-list)
2741 (cond ((file-directory-p file)
2742 (when (or (not (eq how 'file))
2743 (gnus-y-or-n-p
2744 (format-message
2745 "Delete temporary HTML file(s) in directory `%s'? "
2746 (file-name-as-directory file))))
2747 (gnus-delete-directory file)))
2748 ((file-exists-p file)
2749 (when (or (not (eq how 'file))
2750 (gnus-y-or-n-p
2751 (format "Delete temporary HTML file `%s'? " file)))
2752 (delete-file file)))))
2753 ;; Also remove file from the list when not deleted or if file doesn't
2754 ;; exist anymore.
2755 (setq gnus-article-browse-html-temp-list nil))
2756 gnus-article-browse-html-temp-list)
2758 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2759 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2760 Return file name relative to the parent of DIRECTORY."
2761 (save-match-data
2762 (let (file afile)
2763 (catch 'found
2764 (dolist (handle handles)
2765 (cond
2766 ((not (listp handle)))
2767 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2768 ;; may create.
2769 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2770 ((equal (mm-handle-media-supertype handle) "multipart")
2771 (when (setq file (gnus-article-browse-html-save-cid-content
2772 cid handle directory))
2773 (throw 'found file)))
2774 ((equal (concat "<" cid ">") (mm-handle-id handle))
2775 (setq file (or (mm-handle-filename handle)
2776 (concat
2777 (make-temp-name "cid")
2778 (car (rassoc (car (mm-handle-type handle))
2779 mailcap-mime-extensions))))
2780 afile (expand-file-name file directory))
2781 (mm-save-part-to-file handle afile)
2782 (throw 'found (concat (file-name-nondirectory
2783 (directory-file-name directory))
2784 "/" file)))))))))
2786 (defun gnus-article-browse-html-parts (list &optional header)
2787 "View all \"text/html\" parts from LIST.
2788 Recurse into multiparts. The optional HEADER that should be a decoded
2789 message header will be added to the bodies of the \"text/html\" parts."
2790 ;; Internal function used by `gnus-article-browse-html-article'.
2791 (let (type file charset content cid-dir tmp-file showed)
2792 ;; Find and show the html-parts.
2793 (dolist (handle list)
2794 ;; If HTML, show it:
2795 (cond ((not (listp handle)))
2796 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2797 (and (equal (car type) "message/external-body")
2798 (or header
2799 (setq file (mm-handle-filename handle)))
2800 (or (mm-handle-cache handle)
2801 (condition-case code
2802 (progn (mm-extern-cache-contents handle) t)
2803 (error
2804 (gnus-message 3 "%s" (error-message-string code))
2805 (when (>= gnus-verbose 3) (sit-for 2))
2806 nil)))
2807 (progn
2808 (setq handle (mm-handle-cache handle)
2809 type (mm-handle-type handle))
2810 (equal (car type) "text/html"))))
2811 (setq charset (mail-content-type-get type 'charset)
2812 content (mm-get-part handle))
2813 (with-temp-buffer
2814 (if (eq charset 'gnus-decoded)
2815 (mm-enable-multibyte)
2816 (mm-disable-multibyte))
2817 (insert content)
2818 ;; resolve cid contents
2819 (let ((case-fold-search t)
2820 st base regexp cid-file)
2821 (goto-char (point-min))
2822 (when (and (re-search-forward "<head[\t\n >]" nil t)
2823 (progn
2824 (setq st (match-end 0))
2825 (re-search-forward "</head[\t\n >]" nil t))
2826 (re-search-backward "<base\
2827 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2828 (setq base (match-string 1))
2829 (replace-match "<!--\\&-->")
2830 (setq st (point))
2831 (dolist (tag '(("a" . "href") ("form" . "action")
2832 ("img" . "src")))
2833 (setq regexp (concat "<" (car tag)
2834 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2835 (cdr tag) "=\"\\([^\"]+\\)"))
2836 (while (re-search-forward regexp nil t)
2837 (insert (prog1
2838 (condition-case nil
2839 (save-match-data
2840 (url-expand-file-name (match-string 1)
2841 base))
2842 (error (match-string 1)))
2843 (delete-region (match-beginning 1)
2844 (match-end 1)))))
2845 (goto-char st)))
2846 (while (re-search-forward "\
2847 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2848 nil t)
2849 (unless cid-dir
2850 (setq cid-dir (make-temp-file "cid" t))
2851 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2852 (setq file nil
2853 content nil)
2854 (when (setq cid-file
2855 (gnus-article-browse-html-save-cid-content
2856 (match-string 2)
2857 (with-current-buffer gnus-article-buffer
2858 gnus-article-mime-handles)
2859 cid-dir))
2860 (replace-match cid-file nil nil nil 1))))
2861 (unless content (setq content (buffer-string))))
2862 (when (or charset header (not file))
2863 (setq tmp-file (make-temp-file
2864 ;; Do we need to care for 8.3 filenames?
2865 "mm-" nil ".html")))
2866 ;; Add a meta html tag to specify charset and a header.
2867 (cond
2868 (header
2869 (let (title eheader body hcharset coding)
2870 (with-temp-buffer
2871 (mm-enable-multibyte)
2872 (setq case-fold-search t)
2873 (insert header "\n")
2874 (setq title (message-fetch-field "subject"))
2875 (goto-char (point-min))
2876 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2877 nil t)
2878 (replace-match (cond ((match-beginning 1) "&lt;")
2879 ((match-beginning 2) "&gt;")
2880 ((match-beginning 3) "&amp;")
2881 (t "<br>\n"))))
2882 (goto-char (point-min))
2883 (while (re-search-forward "^[\t ]+" nil t)
2884 (dotimes (i (prog1
2885 (current-column)
2886 (delete-region (match-beginning 0)
2887 (match-end 0))))
2888 (insert "&nbsp;")))
2889 (goto-char (point-min))
2890 (insert "<div align=\"left\">\n")
2891 (goto-char (point-max))
2892 (insert "</div>\n<hr>\n")
2893 ;; We have to examine charset one by one since
2894 ;; charset specified in parts might be different.
2895 (if (eq charset 'gnus-decoded)
2896 (setq charset 'utf-8
2897 eheader (encode-coding-string (buffer-string)
2898 charset)
2899 title (when title
2900 (encode-coding-string title charset))
2901 body (encode-coding-string content charset))
2902 (setq hcharset (mm-find-mime-charset-region (point-min)
2903 (point-max)))
2904 (cond ((= (length hcharset) 1)
2905 (setq hcharset (car hcharset)
2906 coding (mm-charset-to-coding-system
2907 hcharset nil t)))
2908 ((> (length hcharset) 1)
2909 (setq hcharset 'utf-8
2910 coding hcharset)))
2911 (if coding
2912 (if charset
2913 (progn
2914 (setq body
2915 (mm-charset-to-coding-system charset
2916 nil t))
2917 (if (eq coding body)
2918 (setq eheader (encode-coding-string
2919 (buffer-string) coding)
2920 title (when title
2921 (encode-coding-string
2922 title coding))
2923 body content)
2924 (setq charset 'utf-8
2925 eheader (encode-coding-string
2926 (buffer-string) charset)
2927 title (when title
2928 (encode-coding-string
2929 title charset))
2930 body (encode-coding-string
2931 (decode-coding-string
2932 content body)
2933 charset))))
2934 (setq charset hcharset
2935 eheader (encode-coding-string
2936 (buffer-string) coding)
2937 title (when title
2938 (encode-coding-string
2939 title coding))
2940 body content))
2941 (setq eheader (string-as-unibyte (buffer-string))
2942 body content)))
2943 (erase-buffer)
2944 (mm-disable-multibyte)
2945 (insert body)
2946 (when charset
2947 (mm-add-meta-html-tag handle charset t))
2948 (when title
2949 (goto-char (point-min))
2950 (unless (search-forward "<title>" nil t)
2951 (re-search-forward "<head>\\s-*" nil t)
2952 (insert "<title>" title "</title>\n")))
2953 (goto-char (point-min))
2954 (or (re-search-forward
2955 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2956 (re-search-forward
2957 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2958 (insert eheader)
2959 (mm-write-region (point-min) (point-max)
2960 tmp-file nil nil nil 'binary t))))
2961 (charset
2962 (mm-with-unibyte-buffer
2963 (insert (if (eq charset 'gnus-decoded)
2964 (encode-coding-string content
2965 (setq charset 'utf-8))
2966 content))
2967 (if (or (mm-add-meta-html-tag handle charset)
2968 (not file))
2969 (mm-write-region (point-min) (point-max)
2970 tmp-file nil nil nil 'binary t)
2971 (setq tmp-file nil))))
2972 (tmp-file
2973 (mm-save-part-to-file handle tmp-file)))
2974 (when tmp-file
2975 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2976 (add-hook 'gnus-summary-prepare-exit-hook
2977 'gnus-article-browse-delete-temp-files)
2978 (add-hook 'gnus-exit-gnus-hook
2979 (lambda ()
2980 (gnus-article-browse-delete-temp-files t)))
2981 ;; FIXME: Warn if there's an <img> tag?
2982 (browse-url-of-file (or tmp-file (expand-file-name file)))
2983 (setq showed t))
2984 ;; If multipart, recurse
2985 ((equal (mm-handle-media-supertype handle) "multipart")
2986 (when (gnus-article-browse-html-parts handle header)
2987 (setq showed t)))
2988 ((equal (mm-handle-media-type handle) "message/rfc822")
2989 (mm-with-multibyte-buffer
2990 (mm-insert-part handle)
2991 (setq handle (mm-dissect-buffer t t))
2992 (when (and (bufferp (car handle))
2993 (stringp (car (mm-handle-type handle))))
2994 (setq handle (list handle)))
2995 (when header
2996 (article-decode-encoded-words)
2997 (let ((gnus-visible-headers
2998 (or (get 'gnus-visible-headers 'standard-value)
2999 gnus-visible-headers)))
3000 (article-hide-headers))
3001 (goto-char (point-min))
3002 (search-forward "\n\n" nil 'move)
3003 (skip-chars-backward "\t\n ")
3004 (setq header (buffer-substring (point-min) (point)))))
3005 (when (prog1
3006 (gnus-article-browse-html-parts handle header)
3007 (mm-destroy-parts handle))
3008 (setq showed t)))))
3009 showed))
3011 (defun gnus-article-browse-html-article (&optional arg)
3012 "View \"text/html\" parts of the current article with a WWW browser.
3013 Inline images embedded in a message using the cid scheme, as they are
3014 generally considered to be safe, will be processed properly.
3015 The message header is added to the beginning of every html part unless
3016 the prefix argument ARG is given.
3018 Warning: Spammers use links to images (using the http scheme) in HTML
3019 articles to verify whether you have read the message. As
3020 `gnus-article-browse-html-article' passes the HTML content to the
3021 browser without eliminating these \"web bugs\" you should only
3022 use it for mails from trusted senders.
3024 If you always want to display HTML parts in the browser, set
3025 `mm-text-html-renderer' to nil.
3027 This command creates temporary files to pass HTML contents including
3028 images if any to the browser, and deletes them when exiting the group
3029 \(if you want)."
3030 ;; Cf. `mm-w3m-safe-url-regexp'
3031 (interactive "P")
3032 (if arg
3033 (gnus-summary-show-article)
3034 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3035 gnus-visible-headers))
3036 ;; As we insert a <hr>, there's no need for the body boundary.
3037 (gnus-treat-body-boundary nil))
3038 (gnus-summary-show-article)))
3039 (with-current-buffer gnus-article-buffer
3040 (let ((header (unless arg
3041 (save-restriction
3042 (widen)
3043 (buffer-substring-no-properties
3044 (goto-char (point-min))
3045 (if (search-forward "\n\n" nil t)
3046 (match-beginning 0)
3047 (goto-char (point-max))
3048 (skip-chars-backward "\t\n ")
3049 (point))))))
3050 parts)
3051 (set-buffer gnus-original-article-buffer)
3052 (setq parts (mm-dissect-buffer t t))
3053 ;; If singlepart, enforce a list.
3054 (when (and (bufferp (car parts))
3055 (stringp (car (mm-handle-type parts))))
3056 (setq parts (list parts)))
3057 ;; Process the list
3058 (unless (gnus-article-browse-html-parts parts header)
3059 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3060 (mm-destroy-parts parts)
3061 (unless arg
3062 (gnus-summary-show-article)))))
3064 (defun article-hide-list-identifiers ()
3065 "Remove list identifiers from the Subject header.
3066 The `gnus-list-identifiers' variable specifies what to do."
3067 (interactive)
3068 (let ((inhibit-point-motion-hooks t)
3069 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3070 (inhibit-read-only t))
3071 (when regexp
3072 (save-excursion
3073 (save-restriction
3074 (article-narrow-to-head)
3075 (goto-char (point-min))
3076 (while (re-search-forward
3077 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3078 nil t)
3079 (delete-region (match-beginning 2) (match-end 0))
3080 (beginning-of-line))
3081 (when (re-search-forward
3082 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3083 (delete-region (match-beginning 1) (match-end 1))))))))
3085 (defun article-hide-pem (&optional arg)
3086 "Toggle hiding of any PEM headers and signatures in the current article.
3087 If given a negative prefix, always show; if given a positive prefix,
3088 always hide."
3089 (interactive (gnus-article-hidden-arg))
3090 (unless (gnus-article-check-hidden-text 'pem arg)
3091 (save-excursion
3092 (let ((inhibit-read-only t) end)
3093 (goto-char (point-min))
3094 ;; Hide the horrendously ugly "header".
3095 (when (and (search-forward
3096 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3097 nil t)
3098 (setq end (1+ (match-beginning 0))))
3099 (gnus-add-wash-type 'pem)
3100 (gnus-article-hide-text-type
3102 (if (search-forward "\n\n" nil t)
3103 (match-end 0)
3104 (point-max))
3105 'pem)
3106 ;; Hide the trailer as well
3107 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3108 nil t)
3109 (gnus-article-hide-text-type
3110 (match-beginning 0) (match-end 0) 'pem)))))))
3112 (defun article-strip-banner ()
3113 "Strip the banners specified by the `banner' group parameter and by
3114 `gnus-article-address-banner-alist'."
3115 (interactive)
3116 (save-excursion
3117 (save-restriction
3118 (let ((inhibit-point-motion-hooks t))
3119 (when (gnus-parameter-banner gnus-newsgroup-name)
3120 (article-really-strip-banner
3121 (gnus-parameter-banner gnus-newsgroup-name)))
3122 (when gnus-article-address-banner-alist
3123 ;; Note that the From header is decoded here, so it is
3124 ;; required that the *-extract-address-components function
3125 ;; supports non-ASCII text.
3126 (let ((from (save-restriction
3127 (widen)
3128 (article-narrow-to-head)
3129 (mail-fetch-field "from"))))
3130 (when (and from
3131 (setq from
3132 (cadr (funcall gnus-extract-address-components
3133 from))))
3134 (catch 'found
3135 (dolist (pair gnus-article-address-banner-alist)
3136 (when (string-match (car pair) from)
3137 (throw 'found
3138 (article-really-strip-banner (cdr pair)))))))))))))
3140 (defun article-really-strip-banner (banner)
3141 "Strip the banner specified by the argument."
3142 (save-excursion
3143 (save-restriction
3144 (let ((inhibit-point-motion-hooks t)
3145 (gnus-signature-limit nil)
3146 (inhibit-read-only t))
3147 (article-goto-body)
3148 (cond
3149 ((eq banner 'signature)
3150 (when (gnus-article-narrow-to-signature)
3151 (widen)
3152 (forward-line -1)
3153 (delete-region (point) (point-max))))
3154 ((symbolp banner)
3155 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3156 (while (re-search-forward banner nil t)
3157 (delete-region (match-beginning 0) (match-end 0)))))
3158 ((stringp banner)
3159 (while (re-search-forward banner nil t)
3160 (delete-region (match-beginning 0) (match-end 0)))))))))
3162 (defun article-babel ()
3163 "Translate article using an online translation service."
3164 (interactive)
3165 (require 'babel)
3166 (gnus-with-article-buffer
3167 (when (article-goto-body)
3168 (let* ((start (point))
3169 (end (point-max))
3170 (orig (buffer-substring start end))
3171 (trans (babel-as-string orig)))
3172 (save-restriction
3173 (narrow-to-region start end)
3174 (delete-region start end)
3175 (insert trans))))))
3177 (defun article-hide-signature (&optional arg)
3178 "Hide the signature in the current article.
3179 If given a negative prefix, always show; if given a positive prefix,
3180 always hide."
3181 (interactive (gnus-article-hidden-arg))
3182 (unless (gnus-article-check-hidden-text 'signature arg)
3183 (save-excursion
3184 (save-restriction
3185 (let ((inhibit-read-only t))
3186 (when (gnus-article-narrow-to-signature)
3187 (gnus-article-hide-text-type
3188 (point-min) (point-max) 'signature))))))
3189 (gnus-set-mode-line 'article))
3191 (defun article-strip-headers-in-body ()
3192 "Strip offensive headers from bodies."
3193 (interactive)
3194 (save-excursion
3195 (article-goto-body)
3196 (let ((case-fold-search t))
3197 (when (looking-at "x-no-archive:")
3198 (gnus-delete-line)))))
3200 (defun article-strip-leading-blank-lines ()
3201 "Remove all blank lines from the beginning of the article."
3202 (interactive)
3203 (save-excursion
3204 (let ((inhibit-point-motion-hooks t)
3205 (inhibit-read-only t))
3206 (when (article-goto-body)
3207 (while (and (not (eobp))
3208 (looking-at "[ \t]*$"))
3209 (gnus-delete-line))))))
3211 (defun article-narrow-to-head ()
3212 "Narrow the buffer to the head of the message.
3213 Point is left at the beginning of the narrowed-to region."
3214 (narrow-to-region
3215 (goto-char (point-min))
3216 (cond
3217 ;; Absolutely no headers displayed.
3218 ((looking-at "\n")
3219 (point))
3220 ;; Normal headers.
3221 ((search-forward "\n\n" nil 1)
3222 (1- (point)))
3223 ;; Nothing but headers.
3225 (point-max))))
3226 (goto-char (point-min)))
3228 (defun article-goto-body ()
3229 "Place point at the start of the body."
3230 (goto-char (point-min))
3231 (cond
3232 ;; This variable is only bound when dealing with separate
3233 ;; MIME body parts.
3234 (article-goto-body-goes-to-point-min-p
3236 ((search-forward "\n\n" nil t)
3239 (goto-char (point-max))
3240 nil)))
3242 (defun article-strip-multiple-blank-lines ()
3243 "Replace consecutive blank lines with one empty line."
3244 (interactive)
3245 (save-excursion
3246 (let ((inhibit-point-motion-hooks t)
3247 (inhibit-read-only t))
3248 ;; First make all blank lines empty.
3249 (article-goto-body)
3250 (while (re-search-forward "^[ \t]+$" nil t)
3251 (unless (gnus-annotation-in-region-p
3252 (match-beginning 0) (match-end 0))
3253 (replace-match "" nil t)))
3254 ;; Then replace multiple empty lines with a single empty line.
3255 (article-goto-body)
3256 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3257 (unless (gnus-annotation-in-region-p
3258 (match-beginning 0) (match-end 0))
3259 (delete-region (match-beginning 1) (match-end 1)))))))
3261 (defun article-strip-leading-space ()
3262 "Remove all white space from the beginning of the lines in the article."
3263 (interactive)
3264 (save-excursion
3265 (let ((inhibit-point-motion-hooks t)
3266 (inhibit-read-only t))
3267 (article-goto-body)
3268 (while (re-search-forward "^[ \t]+" nil t)
3269 (replace-match "" t t)))))
3271 (defun article-strip-trailing-space ()
3272 "Remove all white space from the end of the lines in the article."
3273 (interactive)
3274 (save-excursion
3275 (let ((inhibit-point-motion-hooks t)
3276 (inhibit-read-only t))
3277 (article-goto-body)
3278 (while (re-search-forward "[ \t]+$" nil t)
3279 (replace-match "" t t)))))
3281 (defun article-strip-blank-lines ()
3282 "Strip leading, trailing and multiple blank lines."
3283 (interactive)
3284 (article-strip-leading-blank-lines)
3285 (article-remove-trailing-blank-lines)
3286 (article-strip-multiple-blank-lines))
3288 (defun article-strip-all-blank-lines ()
3289 "Strip all blank lines."
3290 (interactive)
3291 (save-excursion
3292 (let ((inhibit-point-motion-hooks t)
3293 (inhibit-read-only t))
3294 (article-goto-body)
3295 (while (re-search-forward "^[ \t]*\n" nil t)
3296 (replace-match "" t t)))))
3298 (defun gnus-article-narrow-to-signature ()
3299 "Narrow to the signature; return t if a signature is found, else nil."
3300 (let ((inhibit-point-motion-hooks t))
3301 (when (gnus-article-search-signature)
3302 (forward-line 1)
3303 ;; Check whether we have some limits to what we consider
3304 ;; to be a signature.
3305 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3306 (list gnus-signature-limit)))
3307 limit limited)
3308 (while (setq limit (pop limits))
3309 (if (or (and (integerp limit)
3310 (< (- (point-max) (point)) limit))
3311 (and (floatp limit)
3312 (< (count-lines (point) (point-max)) limit))
3313 (and (functionp limit)
3314 (funcall limit))
3315 (and (stringp limit)
3316 (not (re-search-forward limit nil t))))
3317 () ; This limit did not succeed.
3318 (setq limited t
3319 limits nil)))
3320 (unless limited
3321 (narrow-to-region (point) (point-max))
3322 t)))))
3324 (defun gnus-article-search-signature ()
3325 "Search the current buffer for the signature separator.
3326 Put point at the beginning of the signature separator."
3327 (let ((cur (point)))
3328 (goto-char (point-max))
3329 (if (if (stringp gnus-signature-separator)
3330 (re-search-backward gnus-signature-separator nil t)
3331 (let ((seps gnus-signature-separator))
3332 (while (and seps
3333 (not (re-search-backward (car seps) nil t)))
3334 (pop seps))
3335 seps))
3337 (goto-char cur)
3338 nil)))
3340 (defun gnus-article-hidden-arg ()
3341 "Return the current prefix arg as a number, or 0 if no prefix."
3342 (list (if current-prefix-arg
3343 (prefix-numeric-value current-prefix-arg)
3344 0)))
3346 (defun gnus-article-check-hidden-text (type arg)
3347 "Return nil if hiding is necessary.
3348 Arg can be nil or a number. nil and positive means hide, negative
3349 means show, 0 means toggle."
3350 (save-excursion
3351 (save-restriction
3352 (let ((hide (gnus-article-hidden-text-p type)))
3353 (cond
3354 ((or (null arg)
3355 (> arg 0))
3356 nil)
3357 ((< arg 0)
3358 (gnus-article-show-hidden-text type)
3361 (if (eq hide 'hidden)
3362 (progn
3363 (gnus-article-show-hidden-text type)
3365 nil)))))))
3367 (defun gnus-article-hidden-text-p (type)
3368 "Say whether the current buffer contains hidden text of type TYPE."
3369 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3370 (while (and pos
3371 (not (get-text-property pos 'invisible))
3372 (not (get-text-property pos 'dummy-invisible)))
3373 (setq pos
3374 (text-property-any (1+ pos) (point-max) 'article-type type)))
3375 (if pos
3376 'hidden
3377 nil)))
3379 (defun gnus-article-show-hidden-text (type &optional _dummy)
3380 "Show all hidden text of type TYPE.
3381 Originally it is hide instead of DUMMY."
3382 (let ((inhibit-read-only t)
3383 (inhibit-point-motion-hooks t))
3384 (gnus-remove-text-properties-when
3385 'article-type type
3386 (point-min) (point-max)
3387 (cons 'article-type (cons type
3388 gnus-hidden-properties)))
3389 (gnus-delete-wash-type type)))
3391 (defconst article-time-units
3392 `((year . ,(* 365.25 24 60 60))
3393 (week . ,(* 7 24 60 60))
3394 (day . ,(* 24 60 60))
3395 (hour . ,(* 60 60))
3396 (minute . 60)
3397 (second . 1))
3398 "Mapping from time units to seconds.")
3400 (defun gnus-article-forward-header ()
3401 "Move point to the start of the next header.
3402 If the current header is a continuation header, this can be several
3403 lines forward."
3404 (let ((ended nil))
3405 (while (not ended)
3406 (forward-line 1)
3407 (if (looking-at "[ \t]+[^ \t]")
3408 (forward-line 1)
3409 (setq ended t)))))
3411 (defun article-treat-date ()
3412 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3413 (with-current-buffer gnus-summary-buffer
3414 gnus-article-date-headers)
3415 gnus-article-date-headers)
3418 (defun article-date-ut (&optional type _highlight date-position)
3419 "Convert DATE date to TYPE in the current article.
3420 The default type is `ut'. See `gnus-article-date-headers' for
3421 possible values."
3422 (interactive (list 'ut t))
3423 (let* ((case-fold-search t)
3424 (inhibit-read-only t)
3425 (inhibit-point-motion-hooks t)
3426 (visible-date (mail-fetch-field "Date"))
3427 pos date bface eface)
3428 (save-excursion
3429 (if date-position
3430 (progn
3431 (goto-char date-position)
3432 (setq date (get-text-property (point) 'original-date))
3433 (when (looking-at "[^:]+:[\t ]*")
3434 (setq bface (get-text-property (match-beginning 0) 'face)
3435 eface (get-text-property (match-end 0) 'face)))
3436 (delete-region (point)
3437 (progn
3438 (gnus-article-forward-header)
3439 (point)))
3440 (article-transform-date date type bface eface))
3441 (save-restriction
3442 (widen)
3443 (goto-char (point-min))
3444 (while (or (get-text-property (setq pos (point)) 'original-date)
3445 (and (setq pos (next-single-property-change
3446 (point) 'original-date))
3447 (goto-char pos)))
3448 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3449 (1+ (match-beginning 0))
3450 (point-max)))
3451 (while (setq pos (text-property-not-all pos (point-max)
3452 'gnus-date-type nil))
3453 (setq date (get-text-property pos 'original-date))
3454 (goto-char pos)
3455 (when (looking-at "[^:]+:[\t ]*")
3456 (setq bface (get-text-property (match-beginning 0) 'face)
3457 eface (get-text-property (match-end 0) 'face)))
3458 (delete-region pos (or (text-property-any pos (point-max)
3459 'gnus-date-type nil)
3460 (point-max))))
3461 (unless date ;; the 1st time
3462 (goto-char (point-min))
3463 (while (re-search-forward "^Date:[\t ]*" nil t)
3464 (setq date (get-text-property (match-beginning 0)
3465 'original-date)
3466 bface (get-text-property (match-beginning 0) 'face)
3467 eface (get-text-property (match-end 0) 'face))
3468 (delete-region (point-at-bol) (progn
3469 (gnus-article-forward-header)
3470 (point)))))
3471 (when (and (not date)
3472 visible-date)
3473 (setq date visible-date))
3474 (when date
3475 (article-transform-date date type bface eface))
3476 (goto-char (point-max))
3477 (widen)))))))
3479 (defun article-transform-date (date type bface eface)
3480 (dolist (this-type (cond
3481 ((null type)
3482 (list 'ut))
3483 ((atom type)
3484 (list type))
3486 type)))
3487 (goto-char
3488 (prog1
3489 (point)
3490 (add-text-properties
3491 (point)
3492 (progn
3493 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3494 (point))
3495 (list 'original-date date 'gnus-date-type this-type))))
3496 ;; Do highlighting.
3497 (when (looking-at
3498 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3499 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3500 (when (match-beginning 2)
3501 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3502 (while (and (zerop (forward-line 1))
3503 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3504 (when (match-beginning 1)
3505 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3507 (defun article-make-date-line (date type)
3508 "Return a DATE line of TYPE."
3509 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3510 combined-lapsed))
3511 (error "Unknown conversion type: %s" type))
3512 (condition-case ()
3513 (let ((time (ignore-errors (date-to-time date))))
3514 (cond
3515 ;; Convert to the local timezone.
3516 ((eq type 'local)
3517 (concat "Date: " (message-make-date time)))
3518 ;; Convert to Universal Time.
3519 ((eq type 'ut)
3520 (concat "Date: "
3521 (substring
3522 (message-make-date
3523 (let* ((e (parse-time-string date))
3524 (tm (apply 'encode-time e))
3525 (ms (car tm))
3526 (ls (- (cadr tm) (car (current-time-zone time)))))
3527 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3528 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3529 (t (list ms ls)))))
3530 0 -5)
3531 "UT"))
3532 ;; Get the original date from the article.
3533 ((eq type 'original)
3534 (concat "Date: " (if (string-match "\n+$" date)
3535 (substring date 0 (match-beginning 0))
3536 date)))
3537 ;; Let the user define the format.
3538 ((eq type 'user-defined)
3539 (let ((format (or (condition-case nil
3540 (with-current-buffer gnus-summary-buffer
3541 gnus-article-time-format)
3542 (error nil))
3543 gnus-article-time-format)))
3544 (if (functionp format)
3545 (funcall format time)
3546 (concat "Date: " (format-time-string format time)))))
3547 ;; ISO 8601.
3548 ((eq type 'iso8601)
3549 (let ((tz (car (current-time-zone time))))
3550 (concat
3551 "Date: "
3552 (format-time-string "%Y%m%dT%H%M%S" time)
3553 (format "%s%02d%02d"
3554 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3555 (/ (% (abs tz) 3600) 60)))))
3556 ;; Do a lapsed format.
3557 ((eq type 'lapsed)
3558 (concat "Date: " (article-lapsed-string time)))
3559 ;; A combined date/lapsed format.
3560 ((eq type 'combined-lapsed)
3561 (let ((date-string (article-make-date-line date 'original))
3562 (segments 3)
3563 lapsed-string)
3564 (while (and
3565 time
3566 (setq lapsed-string
3567 (concat " (" (article-lapsed-string time segments) ")"))
3568 (> (+ (length date-string)
3569 (length lapsed-string))
3570 (+ fill-column 6))
3571 (> segments 0))
3572 (setq segments (1- segments)))
3573 (if (> segments 0)
3574 (concat date-string lapsed-string)
3575 date-string)))
3576 ;; Display the date in proper English
3577 ((eq type 'english)
3578 (let ((dtime (decode-time time)))
3579 (concat
3580 "Date: the "
3581 (number-to-string (nth 3 dtime))
3582 (let ((digit (% (nth 3 dtime) 10)))
3583 (cond
3584 ((memq (nth 3 dtime) '(11 12 13)) "th")
3585 ((= digit 1) "st")
3586 ((= digit 2) "nd")
3587 ((= digit 3) "rd")
3588 (t "th")))
3589 " of "
3590 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3592 (number-to-string (nth 5 dtime))
3593 " at "
3594 (format "%02d" (nth 2 dtime))
3596 (format "%02d" (nth 1 dtime)))))))
3597 (foo
3598 (format "Date: %s (from Gnus)" date))))
3600 (defun article-lapsed-string (time &optional max-segments)
3601 ;; If the date is seriously mangled, the timezone functions are
3602 ;; liable to bug out, so we ignore all errors.
3603 (let* ((now (current-time))
3604 (real-time (time-subtract now time))
3605 (real-sec (and real-time
3606 (+ (* (float (car real-time)) 65536)
3607 (cadr real-time))))
3608 (sec (and real-time (abs real-sec)))
3609 (segments 0)
3610 num prev)
3611 (unless max-segments
3612 (setq max-segments (length article-time-units)))
3613 (cond
3614 ((null real-time)
3615 "Unknown")
3616 ((zerop sec)
3617 "Now")
3619 (concat
3620 ;; This is a bit convoluted, but basically we go
3621 ;; through the time units for years, weeks, etc,
3622 ;; and divide things to see whether that results
3623 ;; in positive answers.
3624 (mapconcat
3625 (lambda (unit)
3626 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3627 (>= segments max-segments))
3628 ;; The (remaining) seconds are too few to
3629 ;; be divided into this time unit.
3631 ;; It's big enough, so we output it.
3632 (setq sec (- sec (* num (cdr unit))))
3633 (prog1
3634 (concat (if prev ", " "") (int-to-string
3635 (floor num))
3636 " " (symbol-name (car unit))
3637 (if (> num 1) "s" ""))
3638 (setq prev t
3639 segments (1+ segments)))))
3640 article-time-units "")
3641 ;; If dates are odd, then it might appear like the
3642 ;; article was sent in the future.
3643 (if (> real-sec 0)
3644 " ago"
3645 " in the future"))))))
3647 (defun article-date-local (&optional highlight)
3648 "Convert the current article date to the local timezone."
3649 (interactive (list t))
3650 (article-date-ut 'local highlight))
3652 (defun article-date-english (&optional highlight)
3653 "Convert the current article date to something that is proper English."
3654 (interactive (list t))
3655 (article-date-ut 'english highlight))
3657 (defun article-date-original (&optional highlight)
3658 "Convert the current article date to what it was originally.
3659 This is only useful if you have used some other date conversion
3660 function and want to see what the date was before converting."
3661 (interactive (list t))
3662 (article-date-ut 'original highlight))
3664 (defun article-date-lapsed (&optional highlight)
3665 "Convert the current article date to time lapsed since it was sent."
3666 (interactive (list t))
3667 (article-date-ut 'lapsed highlight))
3669 (defun article-date-combined-lapsed (&optional highlight)
3670 "Convert the current article date to time lapsed since it was sent."
3671 (interactive (list t))
3672 (article-date-ut 'combined-lapsed highlight))
3674 (defun article-update-date-lapsed ()
3675 "Function to be run from a timer to update the lapsed time line."
3676 (save-match-data
3677 (let ((buffer (current-buffer)))
3678 (ignore-errors
3679 (walk-windows
3680 (lambda (w)
3681 (set-buffer (window-buffer w))
3682 (when (derived-mode-p 'gnus-article-mode)
3683 (let ((old-line (count-lines (point-min) (point)))
3684 (old-column (- (point) (line-beginning-position)))
3685 (window-start (window-start w))
3686 (pos (point-min))
3687 type next end)
3688 (while (setq pos (text-property-not-all pos (point-max)
3689 'gnus-date-type nil))
3690 (setq next (or (next-single-property-change pos
3691 'gnus-date-type)
3692 (point-max)))
3693 (setq type (get-text-property pos 'gnus-date-type))
3694 (when (memq type '(lapsed combined-lapsed user-defined))
3695 (article-date-ut type t pos)
3696 (setq end (or (next-single-property-change pos
3697 'gnus-date-type)
3698 (point-max)))
3699 (when window-start
3700 (if (/= window-start next)
3701 (setq window-start nil)
3702 (set-window-start w end)))
3703 (setq next end))
3704 (setq pos next))
3705 (goto-char (point-min))
3706 (when (> old-column 0)
3707 (setq old-line (1- old-line)))
3708 (forward-line old-line)
3709 (end-of-line)
3710 (when (> (current-column) old-column)
3711 (beginning-of-line)
3712 (forward-char old-column)))))
3713 nil 'visible))
3714 (set-buffer buffer))))
3716 (defun gnus-start-date-timer (&optional n)
3717 "Start a timer to update the Date headers in the article buffers.
3718 The numerical prefix says how frequently (in seconds) the function
3719 is to run."
3720 (interactive "p")
3721 (unless n
3722 (setq n 1))
3723 (gnus-stop-date-timer)
3724 (setq article-lapsed-timer
3725 (run-at-time 1 n 'article-update-date-lapsed)))
3727 (defun gnus-stop-date-timer ()
3728 "Stop the Date timer."
3729 (interactive)
3730 (when article-lapsed-timer
3731 (nnheader-cancel-timer article-lapsed-timer)
3732 (setq article-lapsed-timer nil)))
3734 (defun article-date-user (&optional highlight)
3735 "Convert the current article date to the user-defined format.
3736 This format is defined by the `gnus-article-time-format' variable."
3737 (interactive (list t))
3738 (article-date-ut 'user highlight))
3740 (defun article-date-iso8601 (&optional highlight)
3741 "Convert the current article date to ISO8601."
3742 (interactive (list t))
3743 (article-date-ut 'iso8601 highlight))
3745 (defmacro gnus-article-save-original-date (&rest forms)
3746 "Save the original date as a text property and evaluate FORMS."
3747 `(let* ((case-fold-search t)
3748 (start (progn
3749 (goto-char (point-min))
3750 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3751 (not (bolp)))
3752 (match-end 0))))
3753 (date (when (and start
3754 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3755 nil t))
3756 (buffer-substring-no-properties start
3757 (match-beginning 0)))))
3758 (goto-char (point-max))
3759 (skip-chars-backward "\n")
3760 (put-text-property (point-min) (point) 'original-date date)
3761 ,@forms
3762 (goto-char (point-max))
3763 (skip-chars-backward "\n")
3764 (put-text-property (point-min) (point) 'original-date date)))
3766 ;; (defun article-show-all ()
3767 ;; "Show all hidden text in the article buffer."
3768 ;; (interactive)
3769 ;; (save-excursion
3770 ;; (let ((inhibit-read-only t))
3771 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3773 (defun article-remove-leading-whitespace ()
3774 "Remove excessive whitespace from all headers."
3775 (interactive)
3776 (save-excursion
3777 (save-restriction
3778 (let ((inhibit-read-only t))
3779 (article-narrow-to-head)
3780 (goto-char (point-min))
3781 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3782 (delete-region (match-beginning 1) (match-end 1)))))))
3784 (defun article-emphasize (&optional arg)
3785 "Emphasize text according to `gnus-emphasis-alist'."
3786 (interactive (gnus-article-hidden-arg))
3787 (unless (gnus-article-check-hidden-text 'emphasis arg)
3788 (save-excursion
3789 (let ((alist (or
3790 (condition-case nil
3791 (with-current-buffer gnus-summary-buffer
3792 gnus-article-emphasis-alist)
3793 (error))
3794 gnus-emphasis-alist))
3795 (inhibit-read-only t)
3796 (props (append '(article-type emphasis)
3797 gnus-hidden-properties))
3798 regexp elem beg invisible visible face)
3799 (article-goto-body)
3800 (setq beg (point))
3801 (while (setq elem (pop alist))
3802 (goto-char beg)
3803 (setq regexp (car elem)
3804 invisible (nth 1 elem)
3805 visible (nth 2 elem)
3806 face (nth 3 elem))
3807 (while (re-search-forward regexp nil t)
3808 (when (and (match-beginning visible) (match-beginning invisible))
3809 (gnus-article-hide-text
3810 (match-beginning invisible) (match-end invisible) props)
3811 (gnus-article-unhide-text-type
3812 (match-beginning visible) (match-end visible) 'emphasis)
3813 (gnus-put-overlay-excluding-newlines
3814 (match-beginning visible) (match-end visible) 'face face)
3815 (gnus-add-wash-type 'emphasis)
3816 (goto-char (match-end invisible)))))))))
3818 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3819 "Setup newsgroup emphasis alist."
3820 (unless gnus-article-emphasis-alist
3821 (let ((name (and gnus-newsgroup-name
3822 (gnus-group-real-name gnus-newsgroup-name))))
3823 (make-local-variable 'gnus-article-emphasis-alist)
3824 (setq gnus-article-emphasis-alist
3825 (nconc
3826 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3827 (while (setq elem (pop alist))
3828 (when (and name (string-match (car elem) name))
3829 (setq alist nil
3830 highlight (copy-sequence (cdr elem)))))
3831 highlight)
3832 (copy-sequence highlight-words)
3833 (if gnus-newsgroup-name
3834 (copy-sequence (gnus-group-find-parameter
3835 gnus-newsgroup-name 'highlight-words t)))
3836 gnus-emphasis-alist)))))
3838 (defvar gnus-summary-article-menu)
3839 (defvar gnus-summary-post-menu)
3841 ;;; Saving functions.
3843 (defun gnus-article-save (save-buffer file &optional num)
3844 "Save the currently selected article."
3845 (when (or (get gnus-default-article-saver :headers)
3846 (not gnus-save-all-headers))
3847 ;; Remove headers according to `gnus-saved-headers' or the value
3848 ;; of the `:headers' property that the saver function might have.
3849 (let ((gnus-visible-headers
3850 (or (symbol-value (get gnus-default-article-saver :headers))
3851 gnus-saved-headers gnus-visible-headers))
3852 ;; Ignore group parameter. See `article-hide-headers'.
3853 (gnus-summary-buffer nil))
3854 (with-current-buffer save-buffer
3855 (article-hide-headers 1 t))))
3856 (save-window-excursion
3857 (if (not gnus-default-article-saver)
3858 (error "No default saver is defined")
3859 ;; !!! Magic! The saving functions all save
3860 ;; `gnus-save-article-buffer' (or so they think), but we
3861 ;; bind that variable to our save-buffer.
3862 (set-buffer gnus-article-buffer)
3863 (let* ((gnus-save-article-buffer save-buffer)
3864 (filename
3865 (cond
3866 ((not gnus-prompt-before-saving) 'default)
3867 ((eq gnus-prompt-before-saving 'always) nil)
3868 (t file)))
3869 (gnus-number-of-articles-to-be-saved
3870 (when (eq gnus-prompt-before-saving t)
3871 num))) ; Magic
3872 (set-buffer gnus-article-current-summary)
3873 (funcall gnus-default-article-saver filename)))))
3875 (defun gnus-read-save-file-name (prompt &optional filename
3876 function group headers variable
3877 dir-var)
3878 (let ((default-name
3879 (funcall function group headers (symbol-value variable)))
3880 result)
3881 (setq result
3882 (expand-file-name
3883 (cond
3884 ((eq filename 'default)
3885 default-name)
3886 ((eq filename t)
3887 default-name)
3888 (filename filename)
3890 (when (symbol-value dir-var)
3891 (setq default-name (expand-file-name
3892 (file-name-nondirectory default-name)
3893 (symbol-value dir-var))))
3894 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3895 (prompt
3896 (format prompt
3897 (if (and gnus-number-of-articles-to-be-saved
3898 (> gnus-number-of-articles-to-be-saved 1))
3899 (format "these %d articles"
3900 gnus-number-of-articles-to-be-saved)
3901 "this article")))
3902 (file
3903 ;; Let the split methods have their say.
3904 (cond
3905 ;; No split name was found.
3906 ((null split-name)
3907 (read-file-name
3908 (concat prompt " (default "
3909 (file-name-nondirectory default-name) "): ")
3910 (file-name-directory default-name)
3911 default-name))
3912 ;; A single group name is returned.
3913 ((stringp split-name)
3914 (setq default-name
3915 (funcall function split-name headers
3916 (symbol-value variable)))
3917 (read-file-name
3918 (concat prompt " (default "
3919 (file-name-nondirectory default-name) "): ")
3920 (file-name-directory default-name)
3921 default-name))
3922 ;; A single split name was found
3923 ((= 1 (length split-name))
3924 (let* ((name (expand-file-name
3925 (car split-name)
3926 gnus-article-save-directory))
3927 (dir (cond ((file-directory-p name)
3928 (file-name-as-directory name))
3929 ((file-exists-p name) name)
3930 (t gnus-article-save-directory))))
3931 (read-file-name
3932 (concat prompt " (default " name "): ")
3933 dir name)))
3934 ;; A list of splits was found.
3936 (setq split-name (nreverse split-name))
3937 (let (result)
3938 (let ((file-name-history
3939 (nconc split-name file-name-history)))
3940 (setq result
3941 (expand-file-name
3942 (read-file-name
3943 (concat prompt " (`M-p' for defaults): ")
3944 gnus-article-save-directory
3945 (car split-name))
3946 gnus-article-save-directory)))
3947 (car (push result file-name-history)))))))
3948 ;; Create the directory.
3949 (gnus-make-directory (file-name-directory file))
3950 ;; If we have read a directory, we append the default file name.
3951 (when (file-directory-p file)
3952 (setq file (expand-file-name (file-name-nondirectory
3953 default-name)
3954 (file-name-as-directory file))))
3955 ;; Possibly translate some characters.
3956 (nnheader-translate-file-chars file))))))
3957 (gnus-make-directory (file-name-directory result))
3958 (when variable
3959 (set variable result))
3960 (when dir-var
3961 (set dir-var (file-name-directory result)))
3962 result))
3964 (defun gnus-article-archive-name (_group)
3965 "Return the first instance of an \"Archive-name\" in the current buffer."
3966 (let ((case-fold-search t))
3967 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3968 (nnheader-concat gnus-article-save-directory
3969 (match-string 1)))))
3971 (defun gnus-article-nndoc-name (group)
3972 "If GROUP is an nndoc group, return the name of the parent group."
3973 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3974 (gnus-group-get-parameter group 'save-article-group)))
3976 (defun gnus-summary-save-in-rmail (&optional filename)
3977 "Append this article to Rmail file.
3978 Optional argument FILENAME specifies file name.
3979 Directory to save to is default to `gnus-article-save-directory'."
3980 (setq filename (gnus-read-save-file-name
3981 "Save %s in rmail file" filename
3982 gnus-rmail-save-name gnus-newsgroup-name
3983 gnus-current-headers 'gnus-newsgroup-last-rmail))
3984 (with-current-buffer gnus-save-article-buffer
3985 (save-excursion
3986 (save-restriction
3987 (widen)
3988 ;; Note that unlike gnus-summary-save-in-mail, there is no
3989 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3990 ;; not use Babyl.
3991 (gnus-output-to-rmail filename))))
3992 filename)
3994 (defun gnus-summary-save-in-mail (&optional filename)
3995 "Append this article to Unix mail file.
3996 Optional argument FILENAME specifies file name.
3997 Directory to save to is default to `gnus-article-save-directory'."
3998 (setq filename (gnus-read-save-file-name
3999 "Save %s in Unix mail file" filename
4000 gnus-mail-save-name gnus-newsgroup-name
4001 gnus-current-headers 'gnus-newsgroup-last-mail))
4002 (with-current-buffer gnus-save-article-buffer
4003 (save-excursion
4004 (save-restriction
4005 (widen)
4006 (if (and (file-readable-p filename)
4007 (file-regular-p filename)
4008 (mail-file-babyl-p filename))
4009 (gnus-output-to-rmail filename)
4010 (gnus-output-to-mail filename)))))
4011 filename)
4013 (put 'gnus-summary-save-in-file :decode t)
4014 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4015 (defun gnus-summary-save-in-file (&optional filename overwrite)
4016 "Append this article to file.
4017 Optional argument FILENAME specifies file name.
4018 Directory to save to is default to `gnus-article-save-directory'."
4019 (setq filename (gnus-read-save-file-name
4020 "Save %s in file" filename
4021 gnus-file-save-name gnus-newsgroup-name
4022 gnus-current-headers 'gnus-newsgroup-last-file))
4023 (with-current-buffer gnus-save-article-buffer
4024 (save-excursion
4025 (save-restriction
4026 (widen)
4027 (when (and overwrite
4028 (file-exists-p filename))
4029 (delete-file filename))
4030 (gnus-output-to-file filename))))
4031 filename)
4033 (put 'gnus-summary-write-to-file :decode t)
4034 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4035 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4036 (defun gnus-summary-write-to-file (&optional filename)
4037 "Write this article to a file, overwriting it if the file exists.
4038 Optional argument FILENAME specifies file name.
4039 The directory to save in defaults to `gnus-article-save-directory'."
4040 (setq filename (gnus-read-save-file-name
4041 "Save %s in file" filename
4042 gnus-file-save-name gnus-newsgroup-name
4043 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4044 (gnus-summary-save-in-file filename t))
4046 (put 'gnus-summary-save-body-in-file :decode t)
4047 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4048 "Append this article body to a file.
4049 Optional argument FILENAME specifies file name.
4050 The directory to save in defaults to `gnus-article-save-directory'."
4051 (setq filename (gnus-read-save-file-name
4052 "Save %s body in file" filename
4053 gnus-file-save-name gnus-newsgroup-name
4054 gnus-current-headers 'gnus-newsgroup-last-file))
4055 (with-current-buffer gnus-save-article-buffer
4056 (save-excursion
4057 (save-restriction
4058 (widen)
4059 (when (article-goto-body)
4060 (narrow-to-region (point) (point-max)))
4061 (when (and overwrite
4062 (file-exists-p filename))
4063 (delete-file filename))
4064 (gnus-output-to-file filename))))
4065 filename)
4067 (put 'gnus-summary-write-body-to-file :decode t)
4068 (put 'gnus-summary-write-body-to-file
4069 :function 'gnus-summary-save-body-in-file)
4070 (defun gnus-summary-write-body-to-file (&optional filename)
4071 "Write this article body to a file, overwriting it if the file exists.
4072 Optional argument FILENAME specifies file name.
4073 The directory to save in defaults to `gnus-article-save-directory'."
4074 (setq filename (gnus-read-save-file-name
4075 "Save %s body in file" filename
4076 gnus-file-save-name gnus-newsgroup-name
4077 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4078 (gnus-summary-save-body-in-file filename t))
4080 (put 'gnus-summary-save-in-pipe :decode t)
4081 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4082 (defun gnus-summary-save-in-pipe (&optional command raw)
4083 "Pipe this article to subprocess COMMAND.
4084 Valid values for COMMAND include:
4085 a string
4086 The executable command name and possibly arguments.
4088 You will be prompted for the command in the minibuffer.
4089 the symbol `default'
4090 It will be replaced with the command which the variable
4091 `gnus-summary-pipe-output-default-command' holds or the command
4092 last used for saving.
4093 Non-nil value for RAW overrides `:decode' and `:headers' properties
4094 and the raw article including all headers will be piped."
4095 (let ((article (gnus-summary-article-number))
4096 (decode (unless raw
4097 (get 'gnus-summary-save-in-pipe :decode)))
4098 save-buffer default)
4099 (if article
4100 (if (vectorp (gnus-summary-article-header article))
4101 (save-current-buffer
4102 (gnus-summary-select-article decode decode nil article)
4103 (insert-buffer-substring
4104 (prog1
4105 (if decode
4106 gnus-article-buffer
4107 gnus-original-article-buffer)
4108 (setq save-buffer
4109 (nnheader-set-temp-buffer " *Gnus Save*"))))
4110 ;; Remove unwanted headers.
4111 (when (and (not raw)
4112 (or (get 'gnus-summary-save-in-pipe :headers)
4113 (not gnus-save-all-headers)))
4114 (let ((gnus-visible-headers
4115 (or (symbol-value (get 'gnus-summary-save-in-pipe
4116 :headers))
4117 gnus-saved-headers gnus-visible-headers))
4118 (gnus-summary-buffer nil))
4119 (article-hide-headers 1 t))))
4120 (error "%d is not a real article" article))
4121 (error "No article to pipe"))
4122 (setq default (or gnus-summary-pipe-output-default-command
4123 gnus-last-shell-command))
4124 (unless (stringp command)
4125 (setq command
4126 (if (and (eq command 'default) default)
4127 default
4128 (read-shell-command "Shell command on this article: " default))))
4129 (when (string-equal command "")
4130 (if default
4131 (setq command default)
4132 (error "A command is required")))
4133 (with-current-buffer save-buffer
4134 (save-restriction
4135 (widen)
4136 (shell-command-on-region (point-min) (point-max) command nil)))
4137 (gnus-kill-buffer save-buffer))
4138 (setq gnus-summary-pipe-output-default-command command))
4140 (defun gnus-summary-pipe-to-muttprint (&optional command)
4141 "Pipe this article to muttprint."
4142 (unless (stringp command)
4143 (setq command (read-string
4144 "Print using command: " gnus-summary-muttprint-program
4145 nil gnus-summary-muttprint-program)))
4146 (let ((gnus-summary-pipe-output-default-command
4147 gnus-summary-pipe-output-default-command))
4148 (gnus-summary-save-in-pipe command))
4149 (setq gnus-summary-muttprint-program command))
4151 ;;; Article file names when saving.
4153 (defun gnus-capitalize-newsgroup (newsgroup)
4154 "Capitalize NEWSGROUP name."
4155 (when (not (zerop (length newsgroup)))
4156 (concat (char-to-string (upcase (aref newsgroup 0)))
4157 (substring newsgroup 1))))
4159 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4160 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4161 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4162 Otherwise, it is like ~/News/news/group/num."
4163 (let ((default
4164 (expand-file-name
4165 (concat (if (gnus-use-long-file-name 'not-save)
4166 (gnus-capitalize-newsgroup newsgroup)
4167 (gnus-newsgroup-directory-form newsgroup))
4168 "/" (int-to-string (mail-header-number headers)))
4169 gnus-article-save-directory)))
4170 (if (and last-file
4171 (string-equal (file-name-directory default)
4172 (file-name-directory last-file))
4173 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4174 default
4175 (or last-file default))))
4177 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4178 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4179 If variable `gnus-use-long-file-name' is non-nil, it is
4180 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4181 (let ((default
4182 (expand-file-name
4183 (concat (if (gnus-use-long-file-name 'not-save)
4184 newsgroup
4185 (gnus-newsgroup-directory-form newsgroup))
4186 "/" (int-to-string (mail-header-number headers)))
4187 gnus-article-save-directory)))
4188 (if (and last-file
4189 (string-equal (file-name-directory default)
4190 (file-name-directory last-file))
4191 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4192 default
4193 (or last-file default))))
4195 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4196 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4197 If variable `gnus-use-long-file-name' is non-nil, it is
4198 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4199 (or last-file
4200 (expand-file-name
4201 (if (gnus-use-long-file-name 'not-save)
4202 newsgroup
4203 (file-relative-name
4204 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4205 default-directory))
4206 gnus-article-save-directory)))
4208 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4209 "Generate file name from sender."
4210 (let ((from (mail-header-from headers)))
4211 (expand-file-name
4212 (if (and from (string-match "\\([^ <]+\\)@" from))
4213 (match-string 1 from)
4214 "nobody")
4215 gnus-article-save-directory)))
4217 (defun article-verify-x-pgp-sig ()
4218 "Verify X-PGP-Sig."
4219 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4220 (interactive)
4221 (if (gnus-buffer-live-p gnus-original-article-buffer)
4222 (let ((sig (with-current-buffer gnus-original-article-buffer
4223 (gnus-fetch-field "X-PGP-Sig")))
4224 items info headers)
4225 (when (and sig
4226 mml2015-use
4227 (mml2015-clear-verify-function))
4228 (with-temp-buffer
4229 (insert-buffer-substring gnus-original-article-buffer)
4230 (setq items (split-string sig))
4231 (message-narrow-to-head)
4232 (let ((inhibit-point-motion-hooks t)
4233 (case-fold-search t))
4234 ;; Don't verify multiple headers.
4235 (setq headers (mapconcat (lambda (header)
4236 (concat header ": "
4237 (mail-fetch-field header)
4238 "\n"))
4239 (split-string (nth 1 items) ",") "")))
4240 (delete-region (point-min) (point-max))
4241 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4242 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4243 (insert headers)
4244 (widen)
4245 (forward-line)
4246 (while (not (eobp))
4247 (if (looking-at "^-")
4248 (insert "- "))
4249 (forward-line))
4250 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4251 (insert "Version: " (car items) "\n\n")
4252 (insert (mapconcat 'identity (cddr items) "\n"))
4253 (insert "\n-----END PGP SIGNATURE-----\n")
4254 (let ((mm-security-handle (list (format "multipart/signed"))))
4255 (mml2015-clean-buffer)
4256 (let ((coding-system-for-write (or gnus-newsgroup-charset
4257 'iso-8859-1)))
4258 (funcall (mml2015-clear-verify-function)))
4259 (setq info
4260 (or (mm-handle-multipart-ctl-parameter
4261 mm-security-handle 'gnus-details)
4262 (mm-handle-multipart-ctl-parameter
4263 mm-security-handle 'gnus-info)))))
4264 (when info
4265 (let ((inhibit-read-only t) bface eface)
4266 (save-restriction
4267 (message-narrow-to-head)
4268 (goto-char (point-max))
4269 (forward-line -1)
4270 (setq bface (get-text-property (point-at-bol) 'face)
4271 eface (get-text-property (1- (point-at-eol)) 'face))
4272 (message-remove-header "X-Gnus-PGP-Verify")
4273 (if (re-search-forward "^X-PGP-Sig:" nil t)
4274 (forward-line)
4275 (goto-char (point-max)))
4276 (narrow-to-region (point) (point))
4277 (insert "X-Gnus-PGP-Verify: " info "\n")
4278 (goto-char (point-min))
4279 (forward-line)
4280 (while (not (eobp))
4281 (if (not (looking-at "^[ \t]"))
4282 (insert " "))
4283 (forward-line))
4284 ;; Do highlighting.
4285 (goto-char (point-min))
4286 (when (looking-at "\\([^:]+\\): *")
4287 (put-text-property (match-beginning 1) (1+ (match-end 1))
4288 'face bface)
4289 (put-text-property (match-end 0) (point-max)
4290 'face eface)))))))))
4292 (defun article-verify-cancel-lock ()
4293 "Verify Cancel-Lock header."
4294 (interactive)
4295 (if (gnus-buffer-live-p gnus-original-article-buffer)
4296 (canlock-verify gnus-original-article-buffer)))
4298 (eval-and-compile
4299 (mapc
4300 (lambda (func)
4301 (let (afunc gfunc)
4302 (if (consp func)
4303 (setq afunc (car func)
4304 gfunc (cdr func))
4305 (setq afunc func
4306 gfunc (intern (format "gnus-%s" func))))
4307 (defalias gfunc
4308 (when (fboundp afunc)
4309 `(lambda (&optional interactive &rest args)
4310 ,(documentation afunc t)
4311 (interactive (list t))
4312 (with-current-buffer gnus-article-buffer
4313 (if interactive
4314 (call-interactively ',afunc)
4315 (apply ',afunc args))))))))
4316 '(article-hide-headers
4317 article-verify-x-pgp-sig
4318 article-verify-cancel-lock
4319 article-hide-boring-headers
4320 article-treat-overstrike
4321 article-treat-ansi-sequences
4322 article-fill-long-lines
4323 article-capitalize-sentences
4324 article-remove-cr
4325 article-remove-leading-whitespace
4326 article-display-x-face
4327 article-display-face
4328 article-de-quoted-unreadable
4329 article-de-base64-unreadable
4330 article-decode-HZ
4331 article-wash-html
4332 article-unsplit-urls
4333 article-hide-list-identifiers
4334 article-strip-banner
4335 article-babel
4336 article-hide-pem
4337 article-hide-signature
4338 article-strip-headers-in-body
4339 article-remove-trailing-blank-lines
4340 article-strip-leading-blank-lines
4341 article-strip-multiple-blank-lines
4342 article-strip-leading-space
4343 article-strip-trailing-space
4344 article-strip-blank-lines
4345 article-strip-all-blank-lines
4346 article-date-local
4347 article-date-english
4348 article-date-iso8601
4349 article-date-original
4350 article-treat-date
4351 article-date-ut
4352 article-decode-mime-words
4353 article-decode-charset
4354 article-decode-encoded-words
4355 article-date-user
4356 article-date-lapsed
4357 article-date-combined-lapsed
4358 article-emphasize
4359 article-treat-dumbquotes
4360 article-treat-non-ascii
4361 article-normalize-headers
4362 ;;(article-show-all . gnus-article-show-all-headers)
4366 ;;; Gnus article mode
4369 (put 'gnus-article-mode 'mode-class 'special)
4371 (set-keymap-parent gnus-article-mode-map widget-keymap)
4373 (gnus-define-keys gnus-article-mode-map
4374 " " gnus-article-goto-next-page
4375 [?\S-\ ] gnus-article-goto-prev-page
4376 "\177" gnus-article-goto-prev-page
4377 [delete] gnus-article-goto-prev-page
4378 "\C-c^" gnus-article-refer-article
4379 "h" gnus-article-show-summary
4380 "s" gnus-article-show-summary
4381 "\C-c\C-m" gnus-article-mail
4382 "?" gnus-article-describe-briefly
4383 "<" beginning-of-buffer
4384 ">" end-of-buffer
4385 "\C-c\C-i" gnus-info-find-node
4386 "\C-c\C-b" gnus-bug
4387 "R" gnus-article-reply-with-original
4388 "F" gnus-article-followup-with-original
4389 "\C-hk" gnus-article-describe-key
4390 "\C-hc" gnus-article-describe-key-briefly
4391 "\C-hb" gnus-article-describe-bindings
4393 "e" gnus-article-read-summary-keys
4394 "\C-d" gnus-article-read-summary-keys
4395 "\M-*" gnus-article-read-summary-keys
4396 "\M-#" gnus-article-read-summary-keys
4397 "\M-^" gnus-article-read-summary-keys
4398 "\M-g" gnus-article-read-summary-keys)
4400 (substitute-key-definition
4401 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4403 (defvar gnus-article-send-map)
4404 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4405 "W" gnus-article-wide-reply-with-original
4406 [t] gnus-article-read-summary-send-keys)
4408 (defun gnus-article-make-menu-bar ()
4409 (unless (boundp 'gnus-article-commands-menu)
4410 (gnus-summary-make-menu-bar))
4411 (unless (boundp 'gnus-article-article-menu)
4412 (easy-menu-define
4413 gnus-article-article-menu gnus-article-mode-map ""
4414 '("Article"
4415 ["Scroll forwards" gnus-article-goto-next-page t]
4416 ["Scroll backwards" gnus-article-goto-prev-page t]
4417 ["Show summary" gnus-article-show-summary t]
4418 ["Fetch Message-ID at point" gnus-article-refer-article t]
4419 ["Mail to address at point" gnus-article-mail t]
4420 ["Send a bug report" gnus-bug t]))
4422 (easy-menu-define
4423 gnus-article-treatment-menu gnus-article-mode-map ""
4424 ;; Fixme: this should use :active (and maybe :visible).
4425 '("Treatment"
4426 ["Hide headers" gnus-article-hide-headers t]
4427 ["Hide signature" gnus-article-hide-signature t]
4428 ["Hide citation" gnus-article-hide-citation t]
4429 ["Treat overstrike" gnus-article-treat-overstrike t]
4430 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4431 ["Remove carriage return" gnus-article-remove-cr t]
4432 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4433 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4434 ["Remove base64" gnus-article-de-base64-unreadable t]
4435 ["Treat html" gnus-article-wash-html t]
4436 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4437 ["Decode HZ" gnus-article-decode-HZ t]))
4439 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4441 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4443 (gnus-run-hooks 'gnus-article-menu-hook)))
4445 (defvar bookmark-make-record-function)
4446 (defvar shr-put-image-function)
4448 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4449 "Major mode for displaying an article.
4451 All normal editing commands are switched off.
4453 The following commands are available in addition to all summary mode
4454 commands:
4455 \\<gnus-article-mode-map>
4456 \\[gnus-article-next-page]\t Scroll the article one page forwards
4457 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4458 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4459 \\[gnus-article-show-summary]\t Display the summary buffer
4460 \\[gnus-article-mail]\t Send a reply to the address near point
4461 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4462 \\[gnus-info-find-node]\t Go to the Gnus info node"
4463 (gnus-simplify-mode-line)
4464 (make-local-variable 'minor-mode-alist)
4465 (when (gnus-visual-p 'article-menu 'menu)
4466 (gnus-article-make-menu-bar)
4467 (when gnus-summary-tool-bar-map
4468 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4469 (gnus-update-format-specifications nil 'article-mode)
4470 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4471 (set (make-local-variable 'gnus-page-broken) nil)
4472 (make-local-variable 'gnus-article-current-summary)
4473 (make-local-variable 'gnus-article-mime-handles)
4474 (make-local-variable 'gnus-article-decoded-p)
4475 (make-local-variable 'gnus-article-mime-handle-alist)
4476 (make-local-variable 'gnus-article-wash-types)
4477 (make-local-variable 'gnus-article-image-alist)
4478 (make-local-variable 'gnus-article-charset)
4479 (make-local-variable 'gnus-article-ignored-charsets)
4480 (set (make-local-variable 'bookmark-make-record-function)
4481 'gnus-summary-bookmark-make-record)
4482 ;; Prevent Emacs from displaying non-break space with
4483 ;; `nobreak-space' face.
4484 (set (make-local-variable 'nobreak-char-display) nil)
4485 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4486 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4487 (unless gnus-article-show-cursor
4488 (setq cursor-in-non-selected-windows nil))
4489 (gnus-set-default-directory)
4490 (buffer-disable-undo)
4491 (setq buffer-read-only t
4492 show-trailing-whitespace nil)
4493 (mm-enable-multibyte))
4495 (defun gnus-article-setup-buffer ()
4496 "Initialize the article buffer."
4497 (let* ((name (if gnus-single-article-buffer "*Article*"
4498 (concat "*Article "
4499 (gnus-group-decoded-name gnus-newsgroup-name)
4500 "*")))
4501 (original
4502 (progn (string-match "\\*Article" name)
4503 (concat " *Original Article"
4504 (substring name (match-end 0))))))
4505 (setq gnus-article-buffer name)
4506 (setq gnus-original-article-buffer original)
4507 (setq gnus-article-mime-handle-alist nil)
4508 (with-current-buffer gnus-summary-buffer
4509 ;; This might be a variable local to the summary buffer.
4510 (unless gnus-single-article-buffer
4511 (setq gnus-article-buffer name)
4512 (setq gnus-original-article-buffer original)
4513 (gnus-set-global-variables)))
4514 (gnus-article-setup-highlight-words)
4515 ;; Init original article buffer.
4516 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4517 (mm-enable-multibyte)
4518 (setq major-mode 'gnus-original-article-mode)
4519 (make-local-variable 'gnus-original-article))
4520 (if (and (get-buffer name)
4521 (with-current-buffer name
4522 (if gnus-article-edit-mode
4523 (if (y-or-n-p "Article mode edit in progress; discard? ")
4524 (progn
4525 (set-buffer-modified-p nil)
4526 (gnus-kill-buffer name)
4527 (message "")
4528 nil)
4529 (error "Action aborted"))
4530 t)))
4531 (let ((summary gnus-summary-buffer))
4532 (with-current-buffer name
4533 (set (make-local-variable 'gnus-article-edit-mode) nil)
4534 (gnus-article-stop-animations)
4535 (when gnus-article-mime-handles
4536 (mm-destroy-parts gnus-article-mime-handles)
4537 (setq gnus-article-mime-handles nil))
4538 ;; Set it to nil in article-buffer!
4539 (setq gnus-article-mime-handle-alist nil)
4540 (buffer-disable-undo)
4541 (setq buffer-read-only t)
4542 (unless (derived-mode-p 'gnus-article-mode)
4543 (gnus-article-mode))
4544 (set (make-local-variable 'gnus-summary-buffer) summary)
4545 (setq truncate-lines gnus-article-truncate-lines)
4546 (current-buffer)))
4547 (let ((summary gnus-summary-buffer))
4548 (with-current-buffer (gnus-get-buffer-create name)
4549 (gnus-article-mode)
4550 (setq truncate-lines gnus-article-truncate-lines)
4551 (set (make-local-variable 'gnus-summary-buffer) summary)
4552 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4553 (when article-lapsed-timer
4554 (gnus-stop-date-timer))
4555 (when gnus-article-update-date-headers
4556 (gnus-start-date-timer gnus-article-update-date-headers))
4557 (current-buffer))))))
4559 (defun gnus-article-stop-animations ()
4560 (dolist (timer (and (boundp 'timer-list)
4561 timer-list))
4562 (when (eq (timer--function timer) 'image-animate-timeout)
4563 (cancel-timer timer))))
4565 (defun gnus-stop-downloads ()
4566 (when (boundp 'url-queue)
4567 (set (intern "url-queue" obarray) nil)))
4569 ;; Set article window start at LINE, where LINE is the number of lines
4570 ;; from the head of the article.
4571 (defun gnus-article-set-window-start (&optional line)
4572 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4573 (when article-window
4574 (set-window-start
4575 article-window
4576 (with-current-buffer gnus-article-buffer
4577 (goto-char (point-min))
4578 (if (not line)
4579 (point-min)
4580 (gnus-message 6 "Moved to bookmark")
4581 (search-forward "\n\n" nil t)
4582 (forward-line line)
4583 (point)))))))
4585 (defvar gnus-tmp-internal-hook)
4587 (defun gnus-article-prepare (article &optional all-headers _header)
4588 "Prepare ARTICLE in article mode buffer.
4589 ARTICLE should either be an article number or a Message-ID.
4590 If ARTICLE is an id, HEADER should be the article headers.
4591 If ALL-HEADERS is non-nil, no headers are hidden."
4592 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4593 ;; Make sure we start in a summary buffer.
4594 (unless (derived-mode-p 'gnus-summary-mode)
4595 (set-buffer gnus-summary-buffer))
4596 (setq gnus-summary-buffer (current-buffer))
4597 (let* ((summary-buffer (current-buffer))
4598 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4599 (group gnus-newsgroup-name)
4600 result)
4601 (save-excursion
4602 (gnus-article-setup-buffer)
4603 (set-buffer gnus-article-buffer)
4604 ;; Deactivate active regions.
4605 (when transient-mark-mode
4606 (setq mark-active nil))
4607 (if (not (setq result (let ((inhibit-read-only t))
4608 (gnus-request-article-this-buffer
4609 article group))))
4610 ;; There is no such article.
4611 (save-excursion
4612 (when (and (numberp article)
4613 (not (memq article gnus-newsgroup-sparse)))
4614 (setq gnus-article-current
4615 (cons gnus-newsgroup-name article))
4616 (set-buffer gnus-summary-buffer)
4617 (setq gnus-current-article article)
4618 (if (and (memq article gnus-newsgroup-undownloaded)
4619 (not (gnus-online (gnus-find-method-for-group
4620 gnus-newsgroup-name))))
4621 (progn
4622 (gnus-summary-set-agent-mark article)
4623 (message "Message marked for downloading"))
4624 (gnus-summary-mark-article article gnus-canceled-mark)
4625 (unless (memq article gnus-newsgroup-sparse)
4626 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4627 (if (or (eq result 'pseudo)
4628 (eq result 'nneething))
4629 (progn
4630 (with-current-buffer summary-buffer
4631 (push article gnus-newsgroup-history)
4632 (setq gnus-last-article gnus-current-article
4633 gnus-current-article 0
4634 gnus-current-headers nil
4635 gnus-article-current nil)
4636 (if (eq result 'nneething)
4637 (gnus-configure-windows 'summary)
4638 (gnus-configure-windows 'article))
4639 (gnus-set-global-variables))
4640 (let ((gnus-article-mime-handle-alist-1
4641 gnus-article-mime-handle-alist))
4642 (gnus-set-mode-line 'article)))
4643 ;; The result from the `request' was an actual article -
4644 ;; or at least some text that is now displayed in the
4645 ;; article buffer.
4646 (when (and (numberp article)
4647 (not (eq article gnus-current-article)))
4648 ;; Seems like a new article has been selected.
4649 ;; `gnus-current-article' must be an article number.
4650 (with-current-buffer summary-buffer
4651 (push article gnus-newsgroup-history)
4652 (setq gnus-last-article gnus-current-article
4653 gnus-current-article article
4654 gnus-current-headers
4655 (gnus-summary-article-header gnus-current-article)
4656 gnus-article-current
4657 (cons gnus-newsgroup-name gnus-current-article))
4658 (unless (vectorp gnus-current-headers)
4659 (setq gnus-current-headers nil))
4660 (gnus-summary-goto-subject gnus-current-article)
4661 (when (gnus-summary-show-thread)
4662 ;; If the summary buffer really was folded, the
4663 ;; previous goto may not actually have gone to
4664 ;; the right article, but the thread root instead.
4665 ;; So we go again.
4666 (gnus-summary-goto-subject gnus-current-article))
4667 (gnus-run-hooks 'gnus-mark-article-hook)
4668 (gnus-set-mode-line 'summary)
4669 (when (gnus-visual-p 'article-highlight 'highlight)
4670 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4671 ;; Set the global newsgroup variables here.
4672 (gnus-set-global-variables)
4673 (setq gnus-have-all-headers
4674 (or all-headers gnus-show-all-headers))))
4675 (save-excursion
4676 (gnus-configure-windows 'article))
4677 (when (or (numberp article)
4678 (stringp article))
4679 (gnus-article-prepare-display)
4680 ;; Do page break.
4681 (goto-char (point-min))
4682 (when gnus-break-pages
4683 (gnus-narrow-to-page)))
4684 (let ((gnus-article-mime-handle-alist-1
4685 gnus-article-mime-handle-alist))
4686 (gnus-set-mode-line 'article))
4687 (article-goto-body)
4688 (unless (bobp)
4689 (forward-line -1))
4690 (set-window-point (get-buffer-window (current-buffer)) (point))
4691 (gnus-configure-windows 'article)
4692 (gnus-run-hooks 'gnus-article-prepare-hook)
4693 t))))))
4695 (defvar gnus-mime-display-attachment-buttons-in-header)
4697 ;;;###autoload
4698 (defun gnus-article-prepare-display ()
4699 "Make the current buffer look like a nice article."
4700 ;; Hooks for getting information from the article.
4701 ;; This hook must be called before being narrowed.
4702 (let ((gnus-article-buffer (current-buffer))
4703 buffer-read-only
4704 (inhibit-read-only t))
4705 (unless (derived-mode-p 'gnus-article-mode)
4706 (gnus-article-mode))
4707 (setq buffer-read-only nil
4708 gnus-article-wash-types nil
4709 gnus-article-image-alist nil)
4710 (gnus-run-hooks 'gnus-tmp-internal-hook)
4711 (when gnus-display-mime-function
4712 (funcall gnus-display-mime-function))
4713 ;; Add attachment buttons to the header.
4714 (when gnus-mime-display-attachment-buttons-in-header
4715 (gnus-mime-buttonize-attachments-in-header))))
4718 ;;; Gnus Sticky Article Mode
4721 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4722 "Mode for sticky articles."
4723 ;; Release bindings that won't work.
4724 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4725 gnus-sticky-article-mode-map)
4726 (substitute-key-definition 'gnus-article-refer-article 'undefined
4727 gnus-sticky-article-mode-map)
4728 (dolist (k '("e" "h" "s" "F" "R"))
4729 (define-key gnus-sticky-article-mode-map k nil))
4730 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4731 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4732 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4733 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4735 (defun gnus-sticky-article (arg)
4736 "Make the current article sticky.
4737 If a prefix ARG is given, ask for a name for this sticky article buffer."
4738 (interactive "P")
4739 (gnus-summary-show-thread)
4740 (gnus-summary-select-article nil nil 'pseudo)
4741 (let (new-art-buf-name)
4742 (gnus-eval-in-buffer-window gnus-article-buffer
4743 (setq new-art-buf-name
4744 (concat
4745 "*Sticky Article: "
4746 (if arg
4747 (read-from-minibuffer "Sticky article buffer name: ")
4748 (gnus-with-article-headers
4749 (gnus-article-goto-header "subject")
4750 (setq new-art-buf-name
4751 (buffer-substring-no-properties
4752 (line-beginning-position) (line-end-position)))
4753 (goto-char (point-min))
4754 (gnus-article-goto-header "from")
4755 (setq new-art-buf-name
4756 (concat
4757 new-art-buf-name ", "
4758 (buffer-substring-no-properties
4759 (line-beginning-position) (line-end-position))))
4760 (goto-char (point-min))
4761 (gnus-article-goto-header "date")
4762 (setq new-art-buf-name
4763 (concat
4764 new-art-buf-name ", "
4765 (buffer-substring-no-properties
4766 (line-beginning-position) (line-end-position))))))
4767 "*"))
4768 (if (and (gnus-buffer-live-p new-art-buf-name)
4769 (with-current-buffer new-art-buf-name
4770 (derived-mode-p 'gnus-sticky-article-mode)))
4771 (switch-to-buffer new-art-buf-name)
4772 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4773 (gnus-sticky-article-mode))
4774 (setq gnus-article-buffer new-art-buf-name))
4775 (gnus-summary-recenter)
4776 (gnus-summary-position-point))
4778 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4779 "Kill the given sticky article BUFFER.
4780 If none is given, assume the current buffer and kill it if it has
4781 `gnus-sticky-article-mode'."
4782 (interactive)
4783 (unless buffer
4784 (setq buffer (current-buffer)))
4785 (with-current-buffer buffer
4786 (when (derived-mode-p 'gnus-sticky-article-mode)
4787 (gnus-kill-buffer buffer))))
4789 (defun gnus-kill-sticky-article-buffers (arg)
4790 "Kill all sticky article buffers.
4791 If a prefix ARG is given, ask for confirmation."
4792 (interactive "P")
4793 (dolist (buf (gnus-buffers))
4794 (with-current-buffer buf
4795 (when (derived-mode-p 'gnus-sticky-article-mode)
4796 (if (not arg)
4797 (gnus-kill-buffer buf)
4798 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4799 (gnus-kill-buffer buf)))))))
4802 ;;; Gnus MIME viewing functions
4805 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4806 "Format of the MIME buttons.
4808 Valid specifiers include:
4809 %t The MIME type
4810 %T MIME type, along with additional info
4811 %n The `name' parameter
4812 %d The description, if any
4813 %l The length of the encoded part
4814 %p The part identifier number
4815 %e Dots if the part isn't displayed
4817 General format specifiers can also be used. See Info node
4818 `(gnus)Formatting Variables'.")
4820 (defvar gnus-tmp-type)
4821 (defvar gnus-tmp-type-long)
4822 (defvar gnus-tmp-name)
4823 (defvar gnus-tmp-description)
4824 (defvar gnus-tmp-id)
4825 (defvar gnus-tmp-length)
4826 (defvar gnus-tmp-dots)
4827 (defvar gnus-tmp-info)
4828 (defvar gnus-tmp-pressed-details)
4830 (defvar gnus-mime-button-line-format-alist
4831 '((?t gnus-tmp-type ?s)
4832 (?T gnus-tmp-type-long ?s)
4833 (?n gnus-tmp-name ?s)
4834 (?d gnus-tmp-description ?s)
4835 (?p gnus-tmp-id ?s)
4836 (?l gnus-tmp-length ?d)
4837 (?e gnus-tmp-dots ?s)))
4839 (defvar gnus-mime-button-commands
4840 '((gnus-article-press-button "\r" "Toggle Display")
4841 (gnus-mime-view-part "v" "View Interactively...")
4842 (gnus-mime-view-part-as-type "t" "View As Type...")
4843 (gnus-mime-view-part-as-charset "C" "View As charset...")
4844 (gnus-mime-save-part "o" "Save...")
4845 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4846 (gnus-mime-replace-part "r" "Replace part")
4847 (gnus-mime-delete-part "d" "Delete part")
4848 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4849 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4850 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4851 (gnus-mime-view-part-externally "e" "View Externally")
4852 (gnus-mime-print-part "p" "Print")
4853 (gnus-mime-pipe-part "|" "Pipe To Command...")
4854 (gnus-mime-action-on-part "." "Take action on the part...")))
4856 (defun gnus-article-mime-part-status ()
4857 (if gnus-article-mime-handle-alist-1
4858 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4859 " (1 part)"
4860 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4861 ""))
4863 (defvar gnus-mime-button-map
4864 (let ((map (make-sparse-keymap)))
4865 (define-key map [mouse-2] 'gnus-article-push-button)
4866 (define-key map [down-mouse-3] 'gnus-mime-button-menu)
4867 (dolist (c gnus-mime-button-commands)
4868 (define-key map (cadr c) (car c)))
4869 map))
4871 (easy-menu-define
4872 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4873 `("MIME Part"
4874 ,@(mapcar (lambda (c)
4875 (vector (caddr c) (car c) :active t))
4876 gnus-mime-button-commands)))
4878 (defvar gnus-url-button-commands
4879 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4881 (defvar gnus-url-button-map
4882 (let ((map (make-sparse-keymap)))
4883 (dolist (c gnus-url-button-commands)
4884 (define-key map (cadr c) (car c)))
4885 map))
4887 (easy-menu-define
4888 gnus-url-button-menu gnus-url-button-map "URL button menu."
4889 `("Url Button"
4890 ,@(mapcar (lambda (c)
4891 (vector (caddr c) (car c) :active t))
4892 gnus-url-button-commands)))
4894 (defmacro gnus-bind-mm-vars (&rest body)
4895 "Bind some mm-* variables and execute BODY."
4896 `(let (mm-html-inhibit-images
4897 mm-html-blocked-images
4898 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4899 (with-current-buffer
4900 (cond ((derived-mode-p 'gnus-article-mode)
4901 (if (gnus-buffer-live-p gnus-article-current-summary)
4902 gnus-article-current-summary
4903 ;; Maybe we're in a mml-preview buffer
4904 ;; and no group is selected.
4905 (current-buffer)))
4906 ((gnus-buffer-live-p gnus-summary-buffer)
4907 gnus-summary-buffer)
4908 (t (current-buffer)))
4909 (setq mm-html-inhibit-images gnus-inhibit-images
4910 mm-html-blocked-images (gnus-blocked-images))
4911 (when (or (not gnus-newsgroup-name)
4912 (and (stringp gnus-safe-html-newsgroups)
4913 (string-match gnus-safe-html-newsgroups
4914 gnus-newsgroup-name))
4915 (and (consp gnus-safe-html-newsgroups)
4916 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4917 (setq mm-w3m-safe-url-regexp nil)))
4918 ,@body))
4920 (defun gnus-mime-button-menu (event prefix)
4921 "Construct a context-sensitive menu of MIME commands."
4922 (interactive "e\nP")
4923 (save-window-excursion
4924 (let ((pos (event-start event)))
4925 (select-window (posn-window pos))
4926 (goto-char (posn-point pos))
4927 (gnus-article-check-buffer)
4928 (popup-menu gnus-mime-button-menu nil prefix))))
4930 (defun gnus-mime-view-all-parts (&optional handles)
4931 "View all the MIME parts."
4932 (interactive)
4933 (with-current-buffer gnus-article-buffer
4934 (let ((handles (or handles gnus-article-mime-handles))
4935 (mail-parse-charset gnus-newsgroup-charset)
4936 (mail-parse-ignored-charsets
4937 (with-current-buffer gnus-summary-buffer
4938 gnus-newsgroup-ignored-charsets)))
4939 (when handles
4940 (mm-remove-parts handles)
4941 (goto-char (point-min))
4942 (or (search-forward "\n\n") (goto-char (point-max)))
4943 (let ((inhibit-read-only t))
4944 (delete-region (point) (point-max))
4945 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4947 (defun gnus-article-jump-to-part (n)
4948 "Jump to MIME part N."
4949 (interactive "P")
4950 (let ((parts (with-current-buffer gnus-article-buffer
4951 (length gnus-article-mime-handle-alist))))
4952 (when (zerop parts)
4953 (error "No such part"))
4954 (pop-to-buffer gnus-article-buffer)
4955 (or n
4956 (setq n (if (= parts 1)
4958 (read-number (format "Jump to part (1..%s): " parts)))))
4959 (unless (and (integerp n) (<= n parts) (>= n 1))
4960 (setq n
4961 (progn
4962 (gnus-message 7 "Invalid part `%s', using %s instead."
4963 n parts)
4964 parts)))
4965 (gnus-message 9 "Jumping to part %s." n)
4966 (cond ((>= gnus-auto-select-part 1)
4967 (while (and (<= n parts)
4968 (not (gnus-article-goto-part n)))
4969 (setq n (1+ n))))
4970 ((< gnus-auto-select-part 0)
4971 (while (and (>= n 1)
4972 (not (gnus-article-goto-part n)))
4973 (setq n (1- n))))
4975 (gnus-article-goto-part n)))))
4977 (defvar gnus-mime-buttonized-part-id nil
4978 "ID of a mime part that should be buttonized.
4979 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4981 (eval-when-compile
4982 (defsubst gnus-article-edit-part (handles &optional current-id)
4983 "Edit an article in order to delete a mime part.
4984 This function is exclusively used by `gnus-mime-save-part-and-strip'
4985 and `gnus-mime-delete-part', and not provided at run-time normally."
4986 (gnus-article-edit-article
4987 `(lambda ()
4988 (buffer-disable-undo)
4989 (let ((mail-parse-charset (or gnus-article-charset
4990 ',gnus-newsgroup-charset))
4991 (mail-parse-ignored-charsets
4992 (or gnus-article-ignored-charsets
4993 ',gnus-newsgroup-ignored-charsets))
4994 (mbl mml-buffer-list))
4995 (setq mml-buffer-list nil)
4996 ;; A new text must be inserted before deleting existing ones
4997 ;; at the end so as not to move existing markers of which
4998 ;; the insertion type is t.
4999 (delete-region
5000 (point-min)
5001 (prog1
5002 (goto-char (point-max))
5003 (insert-buffer-substring gnus-original-article-buffer)))
5004 (mime-to-mml ',handles)
5005 (setq gnus-article-mime-handles nil)
5006 (let ((mbl1 mml-buffer-list))
5007 (setq mml-buffer-list mbl)
5008 (set (make-local-variable 'mml-buffer-list) mbl1))
5009 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5010 `(lambda (no-highlight)
5011 (let ((mail-parse-charset (or gnus-article-charset
5012 ',gnus-newsgroup-charset))
5013 (message-options message-options)
5014 (message-options-set-recipient)
5015 (mail-parse-ignored-charsets
5016 (or gnus-article-ignored-charsets
5017 ',gnus-newsgroup-ignored-charsets)))
5018 (mml-to-mime)
5019 (mml-destroy-buffers)
5020 (remove-hook 'kill-buffer-hook
5021 'mml-destroy-buffers t)
5022 (kill-local-variable 'mml-buffer-list))
5023 (gnus-summary-edit-article-done
5024 ,(or (mail-header-references gnus-current-headers) "")
5025 ,(gnus-group-read-only-p)
5026 ,gnus-summary-buffer no-highlight))
5028 ;; Force buttonizing this part.
5029 (let ((gnus-mime-buttonized-part-id current-id))
5030 (gnus-article-edit-done))
5031 (gnus-configure-windows 'article)
5032 (sit-for 0)
5033 (when (and current-id (integerp gnus-auto-select-part))
5034 (gnus-article-jump-to-part
5035 (min (max (+ current-id gnus-auto-select-part) 1)
5036 (with-current-buffer gnus-article-buffer
5037 (length gnus-article-mime-handle-alist)))))))
5039 (defun gnus-mime-replace-part (file)
5040 "Replace MIME part under point with an external body."
5041 ;; Useful if file has already been saved to disk
5042 (interactive
5043 (list
5044 (read-file-name "Replace MIME part with file: "
5045 (or mm-default-directory default-directory)
5046 nil nil)))
5047 (gnus-mime-save-part-and-strip file))
5049 (defun gnus-mime-save-part-and-strip (&optional file)
5050 "Save the MIME part under point then replace it with an external body.
5051 If FILE is given, use it for the external part."
5052 (interactive)
5053 (gnus-article-check-buffer)
5054 (when (gnus-group-read-only-p)
5055 (error "The current group does not support deleting of parts"))
5056 (when (mm-complicated-handles gnus-article-mime-handles)
5057 (error "\
5058 The current article has a complicated MIME structure, giving up..."))
5059 (let* ((data (get-text-property (point) 'gnus-data))
5060 (id (get-text-property (point) 'gnus-part))
5061 (handles gnus-article-mime-handles))
5062 (unless file
5063 (setq file
5064 (and data (mm-save-part data "Delete MIME part and save to: "))))
5065 (when file
5066 (with-current-buffer (mm-handle-buffer data)
5067 (erase-buffer)
5068 (insert "Content-Type: " (mm-handle-media-type data))
5069 (mml-insert-parameter-string (cdr (mm-handle-type data))
5070 '(charset))
5071 ;; Add a filename for the sake of saving the part again.
5072 (mml-insert-parameter
5073 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5074 (insert "\n")
5075 (insert "Content-ID: " (message-make-message-id) "\n")
5076 (insert "Content-Transfer-Encoding: binary\n")
5077 (insert "\n"))
5078 (setcdr data
5079 (cdr (mm-make-handle nil
5080 `("message/external-body"
5081 (access-type . "LOCAL-FILE")
5082 (name . ,file)))))
5083 ;; (set-buffer gnus-summary-buffer)
5084 (gnus-article-edit-part handles id))))
5086 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5087 ;; parts...>') but with stripping would be nice.
5089 (defun gnus-mime-delete-part ()
5090 "Delete the MIME part under point.
5091 Replace it with some information about the removed part."
5092 (interactive)
5093 (gnus-article-check-buffer)
5094 (when (gnus-group-read-only-p)
5095 (error "The current group does not support deleting of parts"))
5096 (when (mm-complicated-handles gnus-article-mime-handles)
5097 (error "\
5098 The current article has a complicated MIME structure, giving up..."))
5099 (when (or gnus-expert-user
5100 (gnus-yes-or-no-p "\
5101 Deleting parts may malfunction or destroy the article; continue? "))
5102 (let* ((data (get-text-property (point) 'gnus-data))
5103 (id (get-text-property (point) 'gnus-part))
5104 (handles gnus-article-mime-handles)
5105 (description
5106 (let ((desc (mm-handle-description data)))
5107 (when desc
5108 (mail-decode-encoded-word-string desc))))
5109 (filename (or (mm-handle-filename data) "(none)"))
5110 (type (mm-handle-media-type data)))
5111 (unless data
5112 (error "No MIME part under point"))
5113 (with-current-buffer (mm-handle-buffer data)
5114 (let ((bsize (buffer-size)))
5115 (erase-buffer)
5116 (insert
5117 (concat
5118 ",----\n"
5119 "| The following attachment has been deleted:\n"
5120 "|\n"
5121 "| Type: " type "\n"
5122 "| Filename: " filename "\n"
5123 "| Size (encoded): " (format "%s byte%s\n"
5124 bsize (if (= bsize 1)
5126 "s"))
5127 (when description
5128 (concat "| Description: " description "\n"))
5129 "`----\n"))
5130 (setcdr data
5131 (cdr (mm-make-handle
5132 nil `("text/plain" (charset . gnus-decoded)) nil nil
5133 (list "attachment")
5134 (format "Deleted attachment (%s bytes)" bsize))))))
5135 ;; (set-buffer gnus-summary-buffer)
5136 (gnus-article-edit-part handles id))))
5138 (defun gnus-mime-save-part ()
5139 "Save the MIME part under point."
5140 (interactive)
5141 (gnus-article-check-buffer)
5142 (let ((data (get-text-property (point) 'gnus-data)))
5143 (when data
5144 (mm-save-part data))))
5146 (defun gnus-mime-pipe-part (&optional cmd)
5147 "Pipe the MIME part under point to a process.
5148 Use CMD as the process."
5149 (interactive)
5150 (gnus-article-check-buffer)
5151 (let ((data (get-text-property (point) 'gnus-data)))
5152 (when data
5153 (mm-pipe-part data cmd))))
5155 (defun gnus-mime-view-part ()
5156 "Interactively choose a viewing method for the MIME part under point."
5157 (interactive)
5158 (gnus-article-check-buffer)
5159 (let ((data (get-text-property (point) 'gnus-data)))
5160 (when data
5161 (setq gnus-article-mime-handles
5162 (mm-merge-handles
5163 gnus-article-mime-handles (setq data (copy-sequence data))))
5164 (mm-interactively-view-part data))))
5166 (defun gnus-mime-view-part-as-type-internal ()
5167 (gnus-article-check-buffer)
5168 (let* ((handle (get-text-property (point) 'gnus-data))
5169 (name (or
5170 ;; Content-Type: foo/bar; name=...
5171 (mail-content-type-get (mm-handle-type handle) 'name)
5172 ;; Content-Disposition: attachment; filename=...
5173 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5174 (def-type (and name (mm-default-file-encoding name))))
5175 (or (and def-type (cons def-type 0))
5176 (and handle
5177 (equal (mm-handle-media-supertype handle) "text")
5178 '("text/plain" . 0))
5179 '("application/octet-stream" . 0))))
5181 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5182 "Choose a MIME media type, and view the part as such.
5183 If non-nil, PRED is a predicate to use during completion to limit the
5184 available media-types."
5185 (interactive)
5186 (unless mime-type
5187 (setq mime-type
5188 (let ((default (gnus-mime-view-part-as-type-internal)))
5189 (gnus-completing-read
5190 "View as MIME type"
5191 (if pred
5192 (gnus-remove-if-not pred (mailcap-mime-types))
5193 (mailcap-mime-types))
5194 nil nil nil
5195 (car default)))))
5196 (gnus-article-check-buffer)
5197 (let ((handle (get-text-property (point) 'gnus-data)))
5198 (when handle
5199 (when (equal (mm-handle-media-type handle) "message/external-body")
5200 (unless (mm-handle-cache handle)
5201 (mm-extern-cache-contents handle))
5202 (setq handle (mm-handle-cache handle)))
5203 (setq handle
5204 (mm-make-handle (mm-handle-buffer handle)
5205 (cons mime-type (cdr (mm-handle-type handle)))
5206 (mm-handle-encoding handle)
5207 (mm-handle-undisplayer handle)
5208 (mm-handle-disposition handle)
5209 (mm-handle-description handle)
5211 (mm-handle-id handle)))
5212 (setq gnus-article-mime-handles
5213 (mm-merge-handles gnus-article-mime-handles handle))
5214 (when (mm-handle-displayed-p handle)
5215 (mm-remove-part handle))
5216 (gnus-mm-display-part handle))))
5218 (defun gnus-mime-copy-part (&optional handle arg)
5219 "Put the MIME part under point into a new buffer.
5220 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5221 are decompressed."
5222 (interactive (list nil current-prefix-arg))
5223 (gnus-article-check-buffer)
5224 (unless handle
5225 (setq handle (get-text-property (point) 'gnus-data)))
5226 (when handle
5227 (let ((filename (mm-handle-filename handle))
5228 contents dont-decode charset coding-system)
5229 (mm-with-unibyte-buffer
5230 (mm-insert-part handle)
5231 (setq contents (or (condition-case nil
5232 (mm-decompress-buffer filename nil 'sig)
5233 (error
5234 (setq dont-decode t)
5235 nil))
5236 (buffer-string))))
5237 (setq filename (cond (filename (file-name-nondirectory filename))
5238 (dont-decode "*raw data*")
5239 (t "*decoded*")))
5240 (cond
5241 (dont-decode)
5242 ((not arg)
5243 (unless (setq charset (mail-content-type-get
5244 (mm-handle-type handle) 'charset))
5245 (unless (setq coding-system (mm-with-unibyte-buffer
5246 (insert contents)
5247 (mm-find-buffer-file-coding-system)))
5248 (setq charset gnus-newsgroup-charset))))
5249 ((numberp arg)
5250 (setq charset (or (cdr (assq arg
5251 gnus-summary-show-article-charset-alist))
5252 (read-coding-system "Charset: ")))))
5253 (switch-to-buffer (generate-new-buffer filename))
5254 (if (or coding-system
5255 (and charset
5256 (setq coding-system (mm-charset-to-coding-system
5257 charset nil t))
5258 (not (eq coding-system 'ascii))))
5259 (progn
5260 (mm-enable-multibyte)
5261 (insert (decode-coding-string contents coding-system))
5262 (setq buffer-file-coding-system last-coding-system-used))
5263 (mm-disable-multibyte)
5264 (insert contents)
5265 (setq buffer-file-coding-system mm-binary-coding-system))
5266 ;; We do it this way to make `normal-mode' set the appropriate mode.
5267 (unwind-protect
5268 (progn
5269 (setq buffer-file-name (expand-file-name filename))
5270 (normal-mode))
5271 (setq buffer-file-name nil))
5272 (goto-char (point-min)))))
5274 (defun gnus-mime-print-part (&optional handle filename)
5275 "Print the MIME part under point."
5276 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5277 (gnus-article-check-buffer)
5278 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5279 (contents (and handle (mm-get-part handle)))
5280 (file (make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5281 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5282 (when contents
5283 (if printer
5284 (unwind-protect
5285 (progn
5286 (mm-save-part-to-file handle file)
5287 (call-process shell-file-name nil
5288 (generate-new-buffer " *mm*")
5290 shell-command-switch
5291 (mm-mailcap-command
5292 printer file (mm-handle-type handle))))
5293 (delete-file file))
5294 (with-temp-buffer
5295 (insert contents)
5296 (gnus-print-buffer))
5297 (ps-despool filename)))))
5299 (defun gnus-mime-inline-part (&optional handle arg)
5300 "Insert the MIME part under point into the current buffer.
5301 Compressed files like .gz and .bz2 are decompressed."
5302 (interactive (list nil current-prefix-arg))
5303 (gnus-article-check-buffer)
5304 (let* ((inhibit-read-only t)
5305 (b (point))
5306 (btn ;; position where the MIME button exists
5307 (if handle
5308 (if (eq handle (get-text-property b 'gnus-data))
5310 (article-goto-body)
5311 (or (text-property-any (point) (point-max) 'gnus-data handle)
5312 (text-property-any (point-min) (point) 'gnus-data handle)))
5313 (setq handle (get-text-property b 'gnus-data))
5315 start)
5316 (when handle
5317 (when (= b (prog1
5319 (setq start (next-single-property-change btn 'gnus-data
5320 nil (point-max))
5321 btn (previous-single-property-change start
5322 'gnus-data))))
5323 (setq b btn))
5324 (if (and (not arg) (mm-handle-undisplayer handle))
5325 (progn
5326 (setq b (copy-marker b)
5327 btn (copy-marker btn))
5328 (mm-remove-part handle))
5329 (cond
5330 ((not arg) nil)
5331 ((numberp arg)
5332 (if (mm-handle-undisplayer handle)
5333 (mm-remove-part handle)))
5334 ((mm-handle-undisplayer handle)
5335 (mm-remove-part handle)))
5336 (goto-char start)
5337 (unless (bolp)
5338 ;; This is a header button.
5339 (forward-line 1))
5340 (mm-display-inline handle))
5341 ;; Toggle the button appearance between `[button]...' and `[button]'.
5342 (when (markerp btn)
5343 (setq btn (prog1 (marker-position btn)
5344 (set-marker btn nil))))
5345 (goto-char btn)
5346 (let ((displayed-p (mm-handle-displayed-p handle)))
5347 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5348 (list displayed-p))
5349 (delete-region
5350 (point)
5351 (next-single-property-change (point) 'gnus-data nil (point-max)))
5352 (setq start (point))
5353 (if (search-backward "\n\n" nil t)
5354 (progn
5355 (goto-char start)
5356 (unless (or displayed-p (eolp))
5357 ;; Add extra newline.
5358 (insert (propertize (buffer-substring (1- start) start)
5359 'gnus-undeletable t))))
5360 ;; We're in the article header.
5361 (delete-char -1)
5362 (dolist (ovl (overlays-in btn (point)))
5363 (overlay-put ovl 'gnus-button-attachment-extra t)
5364 (overlay-put ovl 'face nil))
5365 (save-restriction
5366 (message-narrow-to-field)
5367 (let ((gnus-treatment-function-alist
5368 '((gnus-treat-highlight-headers
5369 gnus-article-highlight-headers))))
5370 (gnus-treat-article 'head)))))
5371 (when (markerp b)
5372 (setq b (prog1 (marker-position b)
5373 (set-marker b nil))))
5374 (goto-char b))))
5376 (defun gnus-mime-set-charset-parameters (handle charset)
5377 "Set CHARSET to parameters in HANDLE.
5378 CHARSET may either be a string or a symbol."
5379 (unless (stringp charset)
5380 (setq charset (symbol-name charset)))
5381 (if (stringp (car handle))
5382 (dolist (h (cdr handle))
5383 (gnus-mime-set-charset-parameters h charset))
5384 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5385 "message/external-body")
5386 (progn
5387 (unless (mm-handle-cache handle)
5388 (mm-extern-cache-contents handle))
5389 (mm-handle-cache handle))
5390 handle)))
5391 (param (assq 'charset (cdr type))))
5392 (if param
5393 (setcdr param charset)
5394 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5396 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5397 "Insert the MIME part under point into the current buffer using the
5398 specified charset."
5399 (interactive (list nil current-prefix-arg))
5400 (gnus-article-check-buffer)
5401 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5402 (fun (get-text-property (point) 'gnus-callback))
5403 (gnus-newsgroup-ignored-charsets 'gnus-all)
5404 charset form preferred parts)
5405 (when handle
5406 (when (prog1
5407 (and fun
5408 (setq charset
5409 (or (cdr (assq
5411 gnus-summary-show-article-charset-alist))
5412 (read-coding-system "Charset: "))))
5413 (if (mm-handle-undisplayer handle)
5414 (mm-remove-part handle)))
5415 (gnus-mime-set-charset-parameters handle charset)
5416 (when (and (consp (setq form (cdr-safe fun)))
5417 (setq form (ignore-errors
5418 (assq 'gnus-mime-display-alternative form)))
5419 (setq preferred (caddr form))
5420 (progn
5421 (when (eq (car preferred) 'quote)
5422 (setq preferred (cadr preferred)))
5423 (not (equal preferred
5424 (get-text-property (point) 'gnus-data))))
5425 (setq parts (get-text-property (point) 'gnus-part))
5426 (setq parts (cdr (assq parts
5427 gnus-article-mime-handle-alist)))
5428 (equal (mm-handle-media-type parts) "multipart/alternative")
5429 (setq parts (reverse (cdr parts))))
5430 (setcar (cddr form)
5431 (list 'quote (or (cadr (member preferred parts))
5432 (car parts)))))
5433 (funcall fun handle)))))
5435 (defun gnus-mime-view-part-externally (&optional handle)
5436 "View the MIME part under point with an external viewer."
5437 (interactive)
5438 (gnus-article-check-buffer)
5439 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5440 (mm-inlined-types nil)
5441 (mail-parse-charset gnus-newsgroup-charset)
5442 (mail-parse-ignored-charsets
5443 (with-current-buffer gnus-summary-buffer
5444 gnus-newsgroup-ignored-charsets))
5445 (type (mm-handle-media-type handle))
5446 (method (mailcap-mime-info type))
5447 (mm-enable-external t))
5448 (if (not (stringp method))
5449 (gnus-mime-view-part-as-type
5450 nil (lambda (type) (stringp (mailcap-mime-info type))))
5451 (when handle
5452 (mm-display-part handle nil t)))))
5454 (defun gnus-mime-view-part-internally (&optional handle)
5455 "View the MIME part under point with an internal viewer.
5456 If no internal viewer is available, use an external viewer."
5457 (interactive)
5458 (gnus-article-check-buffer)
5459 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5460 (mm-inlined-types '(".*"))
5461 (mm-inline-large-images t)
5462 (mail-parse-charset gnus-newsgroup-charset)
5463 (mail-parse-ignored-charsets
5464 (with-current-buffer gnus-summary-buffer
5465 gnus-newsgroup-ignored-charsets))
5466 (inhibit-read-only t))
5467 (if (not (mm-inlinable-p handle))
5468 (gnus-mime-view-part-as-type
5469 nil (lambda (type) (mm-inlinable-p handle type)))
5470 (when handle
5471 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5473 (defun gnus-mime-action-on-part (&optional action)
5474 "Do something with the MIME attachment at (point)."
5475 (interactive
5476 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5477 (gnus-article-check-buffer)
5478 (let ((action-pair (assoc action gnus-mime-action-alist)))
5479 (if action-pair
5480 (funcall (cdr action-pair)))))
5482 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5483 "Call FUNCTION on MIME part N.
5484 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5485 If INTERACTIVE, call FUNCTION interactively."
5486 (let (window frame)
5487 ;; Check whether the article is displayed.
5488 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5489 (setq window (get-buffer-window gnus-article-buffer t))
5490 (frame-visible-p (setq frame (window-frame window))))
5491 (error "No article is displayed"))
5492 (with-current-buffer gnus-article-buffer
5493 ;; Check whether the article displays the right contents.
5494 (unless (with-current-buffer gnus-summary-buffer
5495 (eq gnus-current-article (gnus-summary-article-number)))
5496 (error "You should select the right article first"))
5497 (if n
5498 (setq n (prefix-numeric-value n))
5499 (let ((pt (point)))
5500 (setq n (or (get-text-property pt 'gnus-part)
5501 (and (not (bobp))
5502 (get-text-property (1- pt) 'gnus-part))
5503 (get-text-property (prog2
5504 (forward-line 1)
5505 (point)
5506 (goto-char pt))
5507 'gnus-part)
5508 (get-text-property
5509 (or (and (setq pt (previous-single-property-change
5510 pt 'gnus-part))
5511 (1- pt))
5512 (next-single-property-change (point) 'gnus-part)
5513 (point))
5514 'gnus-part)
5515 1))))
5516 ;; Check whether the specified part exists.
5517 (when (> n (length gnus-article-mime-handle-alist))
5518 (error "No such part")))
5519 (unless
5520 (progn
5521 ;; To select the window is needed so that the cursor
5522 ;; might be visible on the MIME button.
5523 (select-window (prog1
5524 window
5525 (setq window (selected-window))
5526 ;; Article may be displayed in the other frame.
5527 (select-frame-set-input-focus
5528 (prog1
5529 frame
5530 (setq frame (selected-frame))))))
5531 (when (gnus-article-goto-part n)
5532 ;; We point the cursor and the arrow at the MIME button
5533 ;; when the `function' prompt the user for something.
5534 (unless (and (pos-visible-in-window-p)
5535 (> (count-lines (point) (window-end))
5536 (/ (1- (window-height)) 3)))
5537 (recenter (/ (1- (window-height)) 3)))
5538 (let ((cursor-in-non-selected-windows t)
5539 (overlay-arrow-string "=>")
5540 (overlay-arrow-position (point-marker)))
5541 (unwind-protect
5542 (cond
5543 ((and no-handle interactive)
5544 (call-interactively function))
5545 (no-handle
5546 (funcall function))
5547 (interactive
5548 (call-interactively
5549 function (get-text-property (point) 'gnus-data)))
5551 (funcall function
5552 (get-text-property (point) 'gnus-data))))
5553 (set-marker overlay-arrow-position nil)
5554 (unless gnus-auto-select-part
5555 (select-frame-set-input-focus frame)
5556 (select-window window))))
5558 (if gnus-inhibit-mime-unbuttonizing
5559 ;; This is the default though the program shouldn't reach here.
5560 (error "No such part")
5561 ;; The part which doesn't have the MIME button is selected.
5562 ;; So, we display all the buttons and redo it.
5563 (let ((gnus-inhibit-mime-unbuttonizing t))
5564 (gnus-summary-show-article)
5565 (gnus-article-part-wrapper n function no-handle))))))
5567 (defun gnus-article-pipe-part (n)
5568 "Pipe MIME part N, which is the numerical prefix."
5569 (interactive "P")
5570 (gnus-article-part-wrapper n 'mm-pipe-part))
5572 (defun gnus-article-save-part (n)
5573 "Save MIME part N, which is the numerical prefix."
5574 (interactive "P")
5575 (gnus-article-part-wrapper n 'mm-save-part))
5577 (defun gnus-article-interactively-view-part (n)
5578 "View MIME part N interactively, which is the numerical prefix."
5579 (interactive "P")
5580 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5582 (defun gnus-article-copy-part (n)
5583 "Copy MIME part N, which is the numerical prefix."
5584 (interactive "P")
5585 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5587 (defun gnus-article-view-part-as-charset (n)
5588 "View MIME part N using a specified charset.
5589 N is the numerical prefix."
5590 (interactive "P")
5591 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5593 (defun gnus-article-view-part-externally (n)
5594 "View MIME part N externally, which is the numerical prefix."
5595 (interactive "P")
5596 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5598 (defun gnus-article-inline-part (n)
5599 "Inline MIME part N, which is the numerical prefix."
5600 (interactive "P")
5601 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5603 (defun gnus-article-save-part-and-strip (n)
5604 "Save MIME part N and replace it with an external body.
5605 N is the numerical prefix."
5606 (interactive "P")
5607 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5609 (defun gnus-article-replace-part (n)
5610 "Replace MIME part N with an external body.
5611 N is the numerical prefix."
5612 (interactive "P")
5613 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5615 (defun gnus-article-delete-part (n)
5616 "Delete MIME part N and add some information about the removed part.
5617 N is the numerical prefix."
5618 (interactive "P")
5619 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5621 (defun gnus-article-view-part-as-type (n)
5622 "Choose a MIME media type, and view part N as such.
5623 N is the numerical prefix."
5624 (interactive "P")
5625 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5627 (defun gnus-article-mime-match-handle-first (condition)
5628 (if condition
5629 (let (n)
5630 (dolist (ihandle gnus-article-mime-handle-alist)
5631 (if (and (cond
5632 ((functionp condition)
5633 (funcall condition (cdr ihandle)))
5634 ((eq condition 'undisplayed)
5635 (not (or (mm-handle-undisplayer (cdr ihandle))
5636 (equal (mm-handle-media-type (cdr ihandle))
5637 "multipart/alternative"))))
5638 ((eq condition 'undisplayed-alternative)
5639 (not (mm-handle-undisplayer (cdr ihandle))))
5640 (t t))
5641 (gnus-article-goto-part (car ihandle))
5642 (or (not n) (< (car ihandle) n)))
5643 (setq n (car ihandle))))
5644 (or n 1))
5647 (defun gnus-article-view-part (&optional n)
5648 "View MIME part N, which is the numerical prefix.
5649 If the part is already shown, hide the part. If N is nil, view
5650 all parts."
5651 (interactive "P")
5652 (with-current-buffer gnus-article-buffer
5653 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5654 gnus-article-mime-match-handle-function)))
5655 (when (> n (length gnus-article-mime-handle-alist))
5656 (error "No such part"))
5657 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5658 (when (gnus-article-goto-part n)
5659 (if (equal (car handle) "multipart/alternative")
5660 (progn
5661 (beginning-of-line) ;; Make it toggle subparts
5662 (gnus-article-press-button))
5663 (when (eq (gnus-mm-display-part handle) 'internal)
5664 (gnus-set-window-start)))))))
5666 (defsubst gnus-article-mime-total-parts ()
5667 (if (bufferp (car gnus-article-mime-handles))
5668 1 ;; single part
5669 (1- (length gnus-article-mime-handles))))
5671 (defun gnus-mm-display-part (handle)
5672 "Display HANDLE and fix MIME button."
5673 (let ((id (get-text-property (point) 'gnus-part))
5674 (point (point))
5675 (inhibit-read-only t)
5676 (window (selected-window))
5677 (mail-parse-charset gnus-newsgroup-charset)
5678 (mail-parse-ignored-charsets
5679 (if (gnus-buffer-live-p gnus-summary-buffer)
5680 (with-current-buffer gnus-summary-buffer
5681 gnus-newsgroup-ignored-charsets)
5682 nil))
5683 start retval)
5684 (unwind-protect
5685 (progn
5686 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5687 (when win
5688 (select-window win)
5689 (goto-char point)))
5690 (setq start (next-single-property-change point 'gnus-data
5691 nil (point-max))
5692 point (previous-single-property-change start 'gnus-data))
5693 (if (mm-handle-displayed-p handle)
5694 ;; This will remove the part.
5695 (setq point (copy-marker point)
5696 retval (mm-display-part handle))
5697 (let ((part (or (and (mm-inlinable-p handle)
5698 (mm-inlined-p handle)
5700 (with-temp-buffer
5701 (gnus-bind-mm-vars
5702 (setq retval (mm-display-part handle)))
5703 (unless (zerop (buffer-size))
5704 (buffer-string))))))
5705 (goto-char start)
5706 (unless (bolp)
5707 ;; This is a header button.
5708 (forward-line 1))
5709 (cond ((stringp part)
5710 (save-restriction
5711 (narrow-to-region (point)
5712 (progn
5713 (insert part)
5714 (unless (bolp) (insert "\n"))
5715 (point)))
5716 (gnus-treat-article nil id
5717 (gnus-article-mime-total-parts)
5718 (mm-handle-media-type handle))
5719 (mm-handle-set-undisplayer
5720 handle
5721 `(lambda ()
5722 (let ((inhibit-read-only t))
5723 (delete-region ,(copy-marker (point-min) t)
5724 ,(point-max-marker)))))))
5725 (part
5726 (mm-display-inline handle))))))
5727 (when (markerp point)
5728 (setq point (prog1 (marker-position point)
5729 (set-marker point nil))))
5730 (goto-char point)
5731 ;; Toggle the button appearance between `[button]...' and `[button]'.
5732 (let ((displayed-p (mm-handle-displayed-p handle)))
5733 (gnus-insert-mime-button handle id (list displayed-p))
5734 (delete-region
5735 (point)
5736 (next-single-property-change (point) 'gnus-data nil (point-max)))
5737 (setq start (point))
5738 (if (search-backward "\n\n" nil t)
5739 (progn
5740 (goto-char start)
5741 (unless (or displayed-p (eolp))
5742 ;; Add extra newline.
5743 (insert (propertize (buffer-substring (1- start) start)
5744 'gnus-undeletable t))))
5745 ;; We're in the article header.
5746 (delete-char -1)
5747 (dolist (ovl (overlays-in point (point)))
5748 (overlay-put ovl 'gnus-button-attachment-extra t)
5749 (overlay-put ovl 'face nil))
5750 (save-restriction
5751 (message-narrow-to-field)
5752 (let ((gnus-treatment-function-alist
5753 '((gnus-treat-highlight-headers
5754 gnus-article-highlight-headers))))
5755 (gnus-treat-article 'head)))))
5756 (goto-char point)
5757 (if (window-live-p window)
5758 (select-window window)))
5759 retval))
5761 (defun gnus-article-goto-part (n)
5762 "Go to MIME part N."
5763 (when gnus-break-pages
5764 (widen))
5765 (article-goto-body)
5766 (prog1
5767 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5768 ;; There may be header buttons.
5769 (text-property-any (point-min) (point) 'gnus-part n)))
5770 part handle end next handles)
5771 (when start
5772 (goto-char start)
5773 (if (setq handle (get-text-property start 'gnus-data))
5774 start
5775 ;; Go to the displayed subpart, assuming this is
5776 ;; multipart/alternative.
5777 (setq part start
5778 end (point-at-eol))
5779 (while (and (not handle)
5780 part
5781 (< part end)
5782 (setq next (text-property-not-all part end
5783 'gnus-data nil)))
5784 (setq part next
5785 handle (get-text-property part 'gnus-data))
5786 (push (cons handle part) handles)
5787 (unless (mm-handle-displayed-p handle)
5788 (setq handle nil
5789 part (text-property-any part end 'gnus-data nil))))
5790 (unless handle
5791 ;; No subpart is displayed, so we find preferred one.
5792 (setq part
5793 (cdr (assq (mm-preferred-alternative
5794 (nreverse (mapcar 'car handles)))
5795 handles))))
5796 (if part
5797 (goto-char (1+ part))
5798 start))))
5799 (when gnus-break-pages
5800 (gnus-narrow-to-page))))
5802 (defun gnus-insert-mime-button (handle id &optional displayed)
5803 (let ((gnus-tmp-name
5804 (or (mm-handle-filename handle)
5805 (mail-content-type-get (mm-handle-type handle) 'url)
5806 ""))
5807 (gnus-tmp-id id)
5808 (gnus-tmp-type (mm-handle-media-type handle))
5809 (gnus-tmp-description (or (mm-handle-description handle) ""))
5810 (gnus-tmp-dots
5811 (if (if displayed (car displayed)
5812 (mm-handle-displayed-p handle))
5813 "" "..."))
5814 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5815 (buffer-size)))
5816 gnus-tmp-type-long b e)
5817 (when (string-match ".*/" gnus-tmp-name)
5818 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5819 (setq gnus-tmp-type-long (concat gnus-tmp-type
5820 (and (not (equal gnus-tmp-name ""))
5821 (concat "; " gnus-tmp-name))))
5822 (unless (equal gnus-tmp-description "")
5823 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5824 (setq b (point))
5825 (gnus-eval-format
5826 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5827 `(keymap ,gnus-mime-button-map
5828 gnus-callback gnus-mm-display-part
5829 gnus-part ,gnus-tmp-id
5830 article-type annotation
5831 gnus-data ,handle
5832 rear-nonsticky t))
5833 (setq e (if (bolp)
5834 ;; Exclude a newline.
5835 (1- (point))
5836 (point)))
5837 (when gnus-article-button-face
5838 (overlay-put (make-overlay b e nil t)
5839 'face gnus-article-button-face))
5840 (widget-convert-button
5841 'link b e
5842 :mime-handle handle
5843 :action 'gnus-widget-press-button
5844 :button-keymap gnus-mime-button-map
5845 :help-echo
5846 (lambda (widget)
5847 (format
5848 "%S: %s the MIME part; %S: more options"
5849 'mouse-2
5850 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5851 "hide" "show")
5852 'down-mouse-3)))))
5854 (defun gnus-widget-press-button (elems _el)
5855 (goto-char (widget-get elems :from))
5856 (gnus-article-press-button))
5858 (defvar gnus-displaying-mime nil)
5860 (defun gnus-display-mime (&optional ihandles)
5861 "Display the MIME parts."
5862 (save-excursion
5863 (save-selected-window
5864 (let ((window (get-buffer-window gnus-article-buffer))
5865 (point (point)))
5866 (when window
5867 (select-window window)
5868 ;; We have to do this since selecting the window
5869 ;; may change the point. So we set the window point.
5870 (set-window-point window point)))
5871 (let ((handles ihandles)
5872 (inhibit-read-only t))
5873 (cond (handles)
5874 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5875 (when gnus-article-emulate-mime
5876 (mm-uu-dissect-text-parts handles)))
5877 (gnus-article-emulate-mime
5878 (setq handles (mm-uu-dissect))))
5879 (when (and (not ihandles)
5880 (not gnus-displaying-mime))
5881 ;; Top-level call; we clean up.
5882 (when gnus-article-mime-handles
5883 (mm-destroy-parts gnus-article-mime-handles)
5884 (setq gnus-article-mime-handle-alist nil));; A trick.
5885 (setq gnus-article-mime-handles handles)
5886 ;; We allow users to glean info from the handles.
5887 (when gnus-article-mime-part-function
5888 (gnus-mime-part-function handles)))
5889 (if (and handles
5890 (or (not (stringp (car handles)))
5891 (cdr handles)))
5892 (progn
5893 (when (and (not ihandles)
5894 (not gnus-displaying-mime))
5895 ;; Clean up for mime parts.
5896 (article-goto-body)
5897 (delete-region (point) (point-max)))
5898 (let ((gnus-displaying-mime t))
5899 (gnus-mime-display-part handles)))
5900 (save-restriction
5901 (article-goto-body)
5902 (narrow-to-region (point) (point-max))
5903 (gnus-treat-article nil 1 1 "text/plain")
5904 (widen)))
5905 (unless ihandles
5906 ;; Highlight the headers.
5907 (save-excursion
5908 (save-restriction
5909 (article-goto-body)
5910 (narrow-to-region (point-min) (point))
5911 (gnus-article-save-original-date
5912 (gnus-treat-article 'head)))))))
5913 ;; Cope with broken MIME messages.
5914 (goto-char (point-max))
5915 (unless (bolp)
5916 (insert "\n"))))
5918 (defcustom gnus-mime-display-multipart-as-mixed nil
5919 "Display \"multipart\" parts as \"multipart/mixed\".
5921 If t, it overrides nil values of
5922 `gnus-mime-display-multipart-alternative-as-mixed' and
5923 `gnus-mime-display-multipart-related-as-mixed'."
5924 :group 'gnus-article-mime
5925 :type 'boolean)
5927 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5928 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5929 :version "22.1"
5930 :group 'gnus-article-mime
5931 :type 'boolean)
5933 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5934 "Display \"multipart/related\" parts as \"multipart/mixed\".
5936 If displaying \"text/html\" is discouraged \(see
5937 `mm-discouraged-alternatives') images or other material inside a
5938 \"multipart/related\" part might be overlooked when this variable is nil."
5939 :version "22.1"
5940 :group 'gnus-article-mime
5941 :type 'boolean)
5943 (defcustom gnus-mime-display-attachment-buttons-in-header t
5944 "Add attachment buttons in the end of the header of an article.
5945 Since MIME attachments tend to be put at the end of an article, we may
5946 overlook them if there is a huge body. This option offers you a copy
5947 of all non-inlinable MIME parts as buttons shown in front of an article.
5948 If nil, don't show those extra buttons."
5949 :version "25.1"
5950 :group 'gnus-article-mime
5951 :type 'boolean)
5953 (defun gnus-mime-display-part (handle)
5954 (cond
5955 ;; Maybe a broken MIME message.
5956 ((null handle))
5957 ;; Single part.
5958 ((not (stringp (car handle)))
5959 (gnus-mime-display-single handle))
5960 ;; User-defined multipart
5961 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5962 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5963 handle))
5964 ;; multipart/alternative
5965 ((and (equal (car handle) "multipart/alternative")
5966 (not (or gnus-mime-display-multipart-as-mixed
5967 gnus-mime-display-multipart-alternative-as-mixed)))
5968 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5969 (push (cons id handle) gnus-article-mime-handle-alist)
5970 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5971 ;; multipart/related
5972 ((and (equal (car handle) "multipart/related")
5973 (not (or gnus-mime-display-multipart-as-mixed
5974 gnus-mime-display-multipart-related-as-mixed)))
5975 (gnus-mime-display-part (cadr handle)))
5976 ((equal (car handle) "multipart/signed")
5977 (gnus-add-wash-type 'signed)
5978 (gnus-mime-display-security handle))
5979 ((equal (car handle) "multipart/encrypted")
5980 (gnus-add-wash-type 'encrypted)
5981 (gnus-mime-display-security handle))
5982 ;; Other multiparts are handled like multipart/mixed.
5984 (gnus-mime-display-mixed (cdr handle)))))
5986 (defun gnus-mime-part-function (handles)
5987 (if (stringp (car handles))
5988 (mapcar 'gnus-mime-part-function (cdr handles))
5989 (funcall gnus-article-mime-part-function handles)))
5991 (defun gnus-mime-display-mixed (handles)
5992 (mapcar 'gnus-mime-display-part handles))
5994 (defun gnus-mime-display-single (handle)
5995 (let ((type (mm-handle-media-type handle))
5996 (ignored gnus-ignored-mime-types)
5997 (not-attachment t)
5998 display text)
5999 (catch 'ignored
6000 (progn
6001 (while ignored
6002 (when (string-match (pop ignored) type)
6003 (throw 'ignored nil)))
6004 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6005 (with-current-buffer gnus-summary-buffer
6006 gnus-inhibit-images)
6007 gnus-inhibit-images)
6008 (string-match "\\`image/" type)))
6009 (setq not-attachment
6010 (and (not (mm-inline-override-p handle))
6011 (or (not (mm-handle-disposition handle))
6012 (equal (car (mm-handle-disposition handle))
6013 "inline")
6014 (mm-attachment-override-p handle))))
6015 (mm-automatic-display-p handle)
6016 (or (and
6017 (mm-inlinable-p handle)
6018 (mm-inlined-p handle))
6019 (mm-automatic-external-display-p type)))
6020 (setq display t)
6021 (when (equal (mm-handle-media-supertype handle) "text")
6022 (setq text t)))
6023 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6024 beg)
6025 (unless id
6026 (setq id (1+ (length gnus-article-mime-handle-alist)))
6027 (push (cons id handle) gnus-article-mime-handle-alist))
6028 (when (and display
6029 (equal (mm-handle-media-supertype handle) "message"))
6030 (insert-char
6032 (cond ((not (bolp)) 2)
6033 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6034 (t 1))))
6035 (when (or (not display)
6036 (not (gnus-unbuttonized-mime-type-p type))
6037 (eq id gnus-mime-buttonized-part-id))
6038 (gnus-insert-mime-button
6039 handle id (list (or display (and not-attachment text)))))
6040 (setq beg (point))
6041 (cond
6042 (display
6043 (let ((mail-parse-charset gnus-newsgroup-charset)
6044 (mail-parse-ignored-charsets
6045 (save-excursion (condition-case ()
6046 (set-buffer gnus-summary-buffer)
6047 (error))
6048 gnus-newsgroup-ignored-charsets)))
6049 (gnus-bind-mm-vars (mm-display-part handle t))))
6050 ((and text not-attachment)
6051 (mm-display-inline handle)))
6052 (goto-char (point-max))
6053 (if (string-match "\\`image/" type)
6054 (gnus-article-insert-newline)
6055 (if (prog1
6056 (= (skip-chars-backward "\n") -1)
6057 (unless (eobp) (forward-char 1)))
6058 (gnus-article-insert-newline)
6059 (put-text-property (point) (point-max) 'gnus-undeletable t))
6060 (goto-char (point-max)))
6061 ;; Do highlighting.
6062 (save-excursion
6063 (save-restriction
6064 (narrow-to-region beg (point))
6065 (if (eq handle gnus-article-mime-handles)
6066 ;; The format=flowed case.
6067 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6068 ;; Don't count signature parts that are never displayed.
6069 ;; The part number should be re-calculated supposing this
6070 ;; might be a message/rfc822 part.
6071 (let (handles)
6072 (dolist (part gnus-article-mime-handles)
6073 (unless (or (stringp part)
6074 (equal (car (mm-handle-type part))
6075 "application/pgp-signature"))
6076 (push part handles)))
6077 (gnus-treat-article
6078 nil (length (memq handle handles)) (length handles)
6079 (mm-handle-media-type handle)))))))))))
6081 (defun gnus-unbuttonized-mime-type-p (type)
6082 "Say whether TYPE is to be unbuttonized."
6083 (unless gnus-inhibit-mime-unbuttonizing
6084 (when (catch 'found
6085 (let ((types gnus-unbuttonized-mime-types))
6086 (while types
6087 (when (string-match (pop types) type)
6088 (throw 'found t)))))
6089 (not (catch 'found
6090 (let ((types gnus-buttonized-mime-types))
6091 (while types
6092 (when (string-match (pop types) type)
6093 (throw 'found t)))))))))
6095 (defun gnus-article-insert-newline ()
6096 "Insert a newline, but mark it as undeletable."
6097 (put-text-property (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6099 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6100 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6101 (ihandles handles)
6102 (point (point))
6103 handle (inhibit-read-only t) from begend not-pref)
6104 (save-window-excursion
6105 (save-restriction
6106 (when ibegend
6107 (narrow-to-region (car ibegend)
6108 (or (cdr ibegend)
6109 (progn
6110 (goto-char (car ibegend))
6111 (forward-line 2)
6112 (point))))
6113 (delete-region (point-min) (point-max))
6114 (mm-remove-parts handles))
6115 (setq begend (list (point-marker)))
6116 ;; Do the toggle.
6117 (unless (setq not-pref (cadr (member preferred ihandles)))
6118 (setq not-pref (car ihandles)))
6119 (when (or ibegend
6120 (not preferred)
6121 (not (gnus-unbuttonized-mime-type-p
6122 "multipart/alternative")))
6123 (add-text-properties
6124 (setq from (point))
6125 (progn
6126 (insert (format "%d. " id))
6127 (point))
6128 `(gnus-callback
6129 (lambda (handles)
6130 (unless ,(not ibegend)
6131 (setq gnus-article-mime-handle-alist
6132 ',gnus-article-mime-handle-alist))
6133 (gnus-mime-display-alternative
6134 ',ihandles ',not-pref ',begend ,id))
6135 keymap ,gnus-mime-button-map
6136 mouse-face ,gnus-article-mouse-face
6137 face ,gnus-article-button-face
6138 gnus-part ,id
6139 article-type multipart
6140 rear-nonsticky t))
6141 (widget-convert-button 'link from (point)
6142 :action 'gnus-widget-press-button)
6143 ;; Do the handles
6144 (while (setq handle (pop handles))
6145 (add-text-properties
6146 (setq from (point))
6147 (progn
6148 (insert (format "(%c) %-18s"
6149 (if (equal handle preferred) ?* ? )
6150 (mm-handle-media-type handle)))
6151 (point))
6152 `(gnus-callback
6153 (lambda (handles)
6154 (unless ,(not ibegend)
6155 (setq gnus-article-mime-handle-alist
6156 ',gnus-article-mime-handle-alist))
6157 (gnus-mime-display-alternative
6158 ',ihandles ',handle ',begend ,id))
6159 keymap ,gnus-mime-button-map
6160 mouse-face ,gnus-article-mouse-face
6161 face ,gnus-article-button-face
6162 gnus-part ,id
6163 gnus-data ,handle
6164 rear-nonsticky t))
6165 (widget-convert-button 'link from (point)
6166 :action 'gnus-widget-press-button)
6167 (insert " "))
6168 (insert "\n\n"))
6169 (when preferred
6170 (if (stringp (car preferred))
6171 (gnus-display-mime preferred)
6172 (let ((mail-parse-charset gnus-newsgroup-charset)
6173 (mail-parse-ignored-charsets
6174 (with-current-buffer gnus-summary-buffer
6175 gnus-newsgroup-ignored-charsets)))
6176 (gnus-bind-mm-vars (mm-display-part preferred))
6177 ;; Do highlighting.
6178 (save-excursion
6179 (save-restriction
6180 (narrow-to-region (car begend) (point-max))
6181 (gnus-treat-article
6182 nil (length gnus-article-mime-handle-alist)
6183 (gnus-article-mime-total-parts)
6184 (mm-handle-media-type preferred))))))
6185 (goto-char (point-max))
6186 (setcdr begend (point-marker)))))
6187 (when ibegend
6188 (goto-char point)))
6189 ;; Redraw attachment buttons in the header.
6190 (when gnus-mime-display-attachment-buttons-in-header
6191 (gnus-mime-buttonize-attachments-in-header)))
6193 (defconst gnus-article-wash-status-strings
6194 (let ((alist '((cite "c" "Possible hidden citation text"
6195 " " "All citation text visible")
6196 (headers "h" "Hidden headers"
6197 " " "All headers visible.")
6198 (pgp "p" "Encrypted or signed message status hidden"
6199 " " "No hidden encryption nor digital signature status")
6200 (signature "s" "Signature has been hidden"
6201 " " "Signature is visible")
6202 (overstrike "o" "Overstrike (^H) characters applied"
6203 " " "No overstrike characters applied")
6204 (emphasis "e" "/*_Emphasis_*/ characters applied"
6205 " " "No /*_emphasis_*/ characters applied")))
6206 result)
6207 (dolist (entry alist result)
6208 (let ((key (nth 0 entry))
6209 (on (copy-sequence (nth 1 entry)))
6210 (on-help (nth 2 entry))
6211 (off (copy-sequence (nth 3 entry)))
6212 (off-help (nth 4 entry)))
6213 (put-text-property 0 1 'help-echo on-help on)
6214 (put-text-property 0 1 'help-echo off-help off)
6215 (push (list key on off) result))))
6216 "Alist of strings describing wash status in the mode line.
6217 Each entry has the form (KEY ON OF), where the KEY is a symbol
6218 representing the particular washing function, ON is the string to use
6219 in the article mode line when the washing function is active, and OFF
6220 is the string to use when it is inactive.")
6222 (defun gnus-article-wash-status-entry (key value)
6223 (let ((entry (assoc key gnus-article-wash-status-strings)))
6224 (if value (nth 1 entry) (nth 2 entry))))
6226 (defun gnus-article-wash-status ()
6227 "Return a string which display status of article washing."
6228 (with-current-buffer gnus-article-buffer
6229 (let ((cite (memq 'cite gnus-article-wash-types))
6230 (headers (memq 'headers gnus-article-wash-types))
6231 (boring (memq 'boring-headers gnus-article-wash-types))
6232 (pgp (memq 'pgp gnus-article-wash-types))
6233 (pem (memq 'pem gnus-article-wash-types))
6234 (signed (memq 'signed gnus-article-wash-types))
6235 (encrypted (memq 'encrypted gnus-article-wash-types))
6236 (signature (memq 'signature gnus-article-wash-types))
6237 (overstrike (memq 'overstrike gnus-article-wash-types))
6238 (emphasis (memq 'emphasis gnus-article-wash-types)))
6239 (concat
6240 (gnus-article-wash-status-entry 'cite cite)
6241 (gnus-article-wash-status-entry 'headers (or headers boring))
6242 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6243 (gnus-article-wash-status-entry 'signature signature)
6244 (gnus-article-wash-status-entry 'overstrike overstrike)
6245 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6247 (defun gnus-add-wash-type (type)
6248 "Add a washing of TYPE to the current status."
6249 (add-to-list 'gnus-article-wash-types type))
6251 (defun gnus-delete-wash-type (type)
6252 "Add a washing of TYPE to the current status."
6253 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6255 (defun gnus-add-image (category image)
6256 "Add IMAGE of CATEGORY to the list of displayed images."
6257 (let ((entry (assq category gnus-article-image-alist)))
6258 (unless entry
6259 (setq entry (list category))
6260 (push entry gnus-article-image-alist))
6261 (nconc entry (list image))))
6263 (defun gnus-delete-images (category)
6264 "Delete all images in CATEGORY."
6265 (let ((entry (assq category gnus-article-image-alist)))
6266 (dolist (image (cdr entry))
6267 (gnus-remove-image image category))
6268 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6269 (gnus-delete-wash-type category)))
6271 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6273 (defun gnus-article-maybe-hide-headers ()
6274 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6275 Provided for backwards compatibility."
6276 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6277 (not (with-current-buffer gnus-summary-buffer
6278 gnus-have-all-headers)))
6279 (not gnus-inhibit-hiding))
6280 (article-hide-headers)))
6282 (declare-function shr-put-image "shr" (data alt &optional flags))
6284 (defun gnus-shr-put-image (data alt &optional flags)
6285 "Put image DATA with a string ALT. Enable image to be deleted."
6286 (let ((image (if flags
6287 (shr-put-image data (propertize (or alt "*")
6288 'gnus-image-category 'shr)
6289 flags)
6290 ;; Old `shr-put-image' doesn't take the optional `flags'
6291 ;; argument.
6292 (shr-put-image data (propertize (or alt "*")
6293 'gnus-image-category 'shr)))))
6294 (when image
6295 (gnus-add-image 'shr image))))
6297 (defun gnus-article-mime-handles (&optional alist id all)
6298 (if alist
6299 (let ((i 1) newid flat)
6300 (dolist (handle alist flat)
6301 (setq newid (append id (list i))
6302 i (1+ i))
6303 (if (stringp (car handle))
6304 (setq flat (nconc flat (gnus-article-mime-handles
6305 (cdr handle) newid all)))
6306 (delq (rassq handle all) all)
6307 (setq flat (nconc flat (list (cons newid handle)))))))
6308 (let ((flat (list nil)))
6309 ;; Assume that elements of `gnus-article-mime-handle-alist'
6310 ;; are in the decreasing order, but unnumbered subsidiaries
6311 ;; in each element are in the increasing order.
6312 (dolist (handle (reverse gnus-article-mime-handle-alist))
6313 (if (stringp (cadr handle))
6314 (setq flat (nconc flat (gnus-article-mime-handles
6315 (cddr handle) (list (car handle)) flat)))
6316 (delq (rassq (cdr handle) flat) flat)
6317 (setq flat (nconc flat (list (cons (list (car handle))
6318 (cdr handle)))))))
6319 (setq flat (cdr flat))
6320 (mapc (lambda (handle)
6321 (if (cdar handle)
6322 ;; This is a hidden (i.e. unnumbered) handle.
6323 (progn
6324 (setcar handle
6325 (1+ (caar gnus-article-mime-handle-alist)))
6326 (push handle gnus-article-mime-handle-alist))
6327 (setcar handle (caar handle))))
6328 flat)
6329 flat)))
6331 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6332 "Show attachments as buttons in the end of the header of an article.
6333 This function toggles the display when called interactively. Note that
6334 buttons to be added to the header are only the ones that aren't inlined
6335 in the body. Use `gnus-header-face-alist' to highlight buttons."
6336 (interactive (list t))
6337 (gnus-with-article-buffer
6338 (let ((case-fold-search t) buttons handle type st)
6339 (save-excursion
6340 (save-restriction
6341 (widen)
6342 (article-narrow-to-head)
6343 ;; Header buttons exist?
6344 (while (and (not buttons)
6345 (re-search-forward "^attachments?:[\n ]+" nil t))
6346 (when (get-char-property (match-end 0)
6347 'gnus-button-attachment-extra)
6348 (setq buttons (match-beginning 0))))
6349 (widen)
6350 (when buttons
6351 ;; Delete header buttons.
6352 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6353 (match-beginning 0)
6354 (point-max))))
6355 (unless (and interactive buttons)
6356 ;; Find buttons.
6357 (setq buttons nil)
6358 (dolist (button (gnus-article-mime-handles))
6359 (setq handle (cdr button)
6360 type (mm-handle-media-type handle))
6361 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6362 (with-current-buffer gnus-summary-buffer
6363 gnus-inhibit-images)
6364 gnus-inhibit-images)
6365 (string-match "\\`image/" type))
6366 (mm-inline-override-p handle)
6367 (and (mm-handle-disposition handle)
6368 (not (equal (car (mm-handle-disposition handle))
6369 "inline"))
6370 (not (mm-attachment-override-p handle)))
6371 (not (mm-automatic-display-p handle))
6372 (not (or (and (mm-inlinable-p handle)
6373 (mm-inlined-p handle))
6374 (mm-automatic-external-display-p type))))
6375 (push button buttons)))
6376 (when buttons
6377 ;; Add header buttons.
6378 (article-goto-body)
6379 (forward-line -1)
6380 (narrow-to-region (point) (point))
6381 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6382 (dolist (button (nreverse buttons))
6383 (setq st (point))
6384 (insert " ")
6385 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6386 (gnus-insert-mime-button handle (car button))
6387 (skip-chars-backward "\t\n ")
6388 (delete-region (point) (point-max))
6389 (when (> (current-column) (window-width))
6390 (goto-char st)
6391 (insert "\n")
6392 (end-of-line)))
6393 (insert "\n")
6394 (dolist (ovl (overlays-in (point-min) (point)))
6395 (overlay-put ovl 'gnus-button-attachment-extra t)
6396 (overlay-put ovl 'face nil))
6397 (let ((gnus-treatment-function-alist
6398 '((gnus-treat-highlight-headers
6399 gnus-article-highlight-headers))))
6400 (gnus-treat-article 'head)))))))))
6402 ;;; Article savers.
6404 (defun gnus-output-to-file (file-name)
6405 "Append the current article to a file named FILE-NAME.
6406 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6407 text and used as the value of the coding cookie which is added to the
6408 top of a file. Otherwise, this function saves a raw article without
6409 the coding cookie."
6410 (let* ((artbuf (current-buffer))
6411 (file-name-coding-system nnmail-pathname-coding-system)
6412 (coding gnus-article-save-coding-system)
6413 (coding-system-for-read (if coding
6414 nil ;; Rely on the coding cookie.
6415 mm-text-coding-system))
6416 (coding-system-for-write (or coding
6417 mm-text-coding-system-for-write
6418 mm-text-coding-system))
6419 (exists (file-exists-p file-name)))
6420 (with-temp-buffer
6421 (when exists
6422 (insert-file-contents file-name)
6423 (goto-char (point-min))
6424 ;; Remove the existing coding cookie.
6425 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6426 (delete-region (match-beginning 0) (match-end 0))))
6427 (goto-char (point-max))
6428 (insert-buffer-substring artbuf)
6429 ;; Append newline at end of the buffer as separator, and then
6430 ;; save it to file.
6431 (goto-char (point-max))
6432 (insert "\n")
6433 (when coding
6434 ;; If the coding system is not suitable to encode the text,
6435 ;; ask a user for a proper one.
6436 (setq coding (coding-system-base
6437 (save-window-excursion
6438 (select-safe-coding-system (point-min) (point-max)
6439 coding))))
6440 (setq coding-system-for-write
6441 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6442 coding))
6443 (goto-char (point-min))
6444 ;; Add the coding cookie.
6445 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6446 coding-system-for-write)))
6447 (if exists
6448 (progn
6449 (write-region (point-min) (point-max) file-name nil 'no-message)
6450 (message "Appended to %s" file-name))
6451 (write-region (point-min) (point-max) file-name))))
6454 (defun gnus-narrow-to-page (&optional arg)
6455 "Narrow the article buffer to a page.
6456 If given a numerical ARG, move forward ARG pages."
6457 (interactive "P")
6458 (setq arg (if arg (prefix-numeric-value arg) 0))
6459 (with-current-buffer gnus-article-buffer
6460 (widen)
6461 ;; Remove any old next/prev buttons.
6462 (when (gnus-visual-p 'page-marker)
6463 (let ((inhibit-read-only t))
6464 (gnus-remove-text-with-property 'gnus-prev)
6465 (gnus-remove-text-with-property 'gnus-next)))
6466 (let (st nd pt)
6467 (when (save-excursion
6468 (cond ((< arg 0)
6469 (if (re-search-backward page-delimiter nil 'move (abs arg))
6470 (prog1
6471 (setq nd (match-beginning 0)
6472 pt nd)
6473 (when (re-search-backward page-delimiter nil t)
6474 (setq st (match-end 0))))
6475 (when (re-search-forward page-delimiter nil t)
6476 (setq nd (match-beginning 0)
6477 pt (point-min)))))
6478 ((> arg 0)
6479 (if (re-search-forward page-delimiter nil 'move arg)
6480 (prog1
6481 (setq st (match-end 0)
6482 pt st)
6483 (when (re-search-forward page-delimiter nil t)
6484 (setq nd (match-beginning 0))))
6485 (when (re-search-backward page-delimiter nil t)
6486 (setq st (match-end 0)
6487 pt (point-max)))))
6489 (when (re-search-backward page-delimiter nil t)
6490 (goto-char (setq st (match-end 0))))
6491 (when (re-search-forward page-delimiter nil t)
6492 (setq nd (match-beginning 0)))
6493 (or st nd))))
6494 (setq gnus-page-broken t)
6495 (when pt (goto-char pt))
6496 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6497 (when (gnus-visual-p 'page-marker)
6498 (save-excursion
6499 (when nd
6500 (goto-char nd)
6501 (gnus-insert-next-page-button))
6502 (when st
6503 (goto-char st)
6504 (gnus-insert-prev-page-button))))))))
6506 ;; Article mode commands
6508 (defun gnus-article-goto-next-page ()
6509 "Show the next page of the article."
6510 (interactive)
6511 (when (gnus-article-next-page)
6512 (goto-char (point-min))
6513 (gnus-article-read-summary-keys nil ?n)))
6516 (defun gnus-article-goto-prev-page ()
6517 "Show the previous page of the article."
6518 (interactive)
6519 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6520 (gnus-article-read-summary-keys nil ?p)
6521 (gnus-article-prev-page nil)))
6523 ;; This is cleaner but currently breaks `gnus-pick-mode':
6525 ;; (defun gnus-article-goto-next-page ()
6526 ;; "Show the next page of the article."
6527 ;; (interactive)
6528 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6529 ;; (gnus-summary-next-page)))
6531 ;; (defun gnus-article-goto-prev-page ()
6532 ;; "Show the next page of the article."
6533 ;; (interactive)
6534 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6535 ;; (gnus-summary-prev-page)))
6537 (defun gnus-article-next-page (&optional lines)
6538 "Show the next page of the current article.
6539 If end of article, return non-nil. Otherwise return nil.
6540 Argument LINES specifies lines to be scrolled up."
6541 (interactive "p")
6542 (move-to-window-line (- -1 scroll-margin))
6543 (if (and (not (and gnus-article-over-scroll
6544 (> (count-lines (window-start) (point-max))
6545 (+ (or lines (1- (window-height))) scroll-margin))))
6546 (save-excursion
6547 (end-of-line)
6548 (and (pos-visible-in-window-p) ;Not continuation line.
6549 (>= (point) (point-max)))))
6550 ;; Nothing in this page.
6551 (if (or (not gnus-page-broken)
6552 (save-excursion
6553 (save-restriction
6554 (widen)
6555 (forward-line)
6556 (eobp)))) ;Real end-of-buffer?
6557 (progn
6558 (when gnus-article-over-scroll
6559 (gnus-article-next-page-1 lines))
6560 t) ;Nothing more.
6561 (gnus-narrow-to-page 1) ;Go to next page.
6562 nil)
6563 ;; More in this page.
6564 (gnus-article-next-page-1 lines)
6565 nil))
6567 (defun gnus-article-beginning-of-window ()
6568 "Move point to the beginning of the window.
6569 The point is placed at the line number which `scroll-margin'
6570 specifies."
6571 ;; There is an obscure bug in Emacs that makes it impossible to
6572 ;; scroll past big pictures in the article buffer. Try to fix
6573 ;; this by adding a sanity check by counting the lines visible.
6574 (when (> (count-lines (window-start) (window-end)) 30)
6575 (move-to-window-line
6576 (min (max 0 scroll-margin)
6577 (max 1 (- (window-height)
6578 (if mode-line-format 1 0)
6579 (if header-line-format 1 0)
6580 2))))))
6582 (defvar scroll-in-place)
6584 (defun gnus-article-next-page-1 (lines)
6585 (condition-case ()
6586 (let ((scroll-in-place nil)
6587 (auto-window-vscroll nil))
6588 (scroll-up lines))
6589 (end-of-buffer
6590 ;; Long lines may cause an end-of-buffer error.
6591 (goto-char (point-max))))
6592 (gnus-article-beginning-of-window))
6594 (defun gnus-article-prev-page (&optional lines)
6595 "Show previous page of current article.
6596 Argument LINES specifies lines to be scrolled down."
6597 (interactive "p")
6598 (move-to-window-line 0)
6599 (if (and gnus-page-broken
6600 (bobp)
6601 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6602 (progn
6603 (gnus-narrow-to-page -1) ;Go to previous page.
6604 (goto-char (point-max))
6605 (recenter (if gnus-article-over-scroll
6606 (if lines
6607 (max (+ lines scroll-margin) 3)
6608 (- (window-height) 2))
6609 -1)))
6610 (prog1
6611 (condition-case ()
6612 (let ((scroll-in-place nil))
6613 (scroll-down lines))
6614 (beginning-of-buffer
6615 (goto-char (point-min))))
6616 (gnus-article-beginning-of-window))))
6618 (defun gnus-article-only-boring-p ()
6619 "Decide whether there is only boring text remaining in the article.
6620 Something \"interesting\" is a word of at least two letters that does
6621 not have a face in `gnus-article-boring-faces'."
6622 (when (and gnus-article-skip-boring
6623 (boundp 'gnus-article-boring-faces)
6624 (symbol-value 'gnus-article-boring-faces))
6625 (save-excursion
6626 (let ((inhibit-point-motion-hooks t))
6627 (catch 'only-boring
6628 (while (re-search-forward "\\b\\w\\w" nil t)
6629 (forward-char -1)
6630 (when (not (gnus-intersection
6631 (gnus-faces-at (point))
6632 (symbol-value 'gnus-article-boring-faces)))
6633 (throw 'only-boring nil)))
6634 (throw 'only-boring t))))))
6636 (defun gnus-article-refer-article ()
6637 "Read article specified by message-id around point."
6638 (interactive)
6639 (save-excursion
6640 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6641 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6642 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6643 (let ((msg-id (concat "<" (match-string 0) ">")))
6644 (set-buffer gnus-summary-buffer)
6645 (gnus-summary-refer-article msg-id))
6646 (error "No references around point"))))
6648 (defun gnus-article-show-summary ()
6649 "Reconfigure windows to show summary buffer."
6650 (interactive)
6651 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6652 (error "There is no summary buffer for this article buffer")
6653 (gnus-article-set-globals)
6654 (gnus-configure-windows 'article)
6655 (gnus-summary-goto-subject gnus-current-article)
6656 (gnus-summary-position-point)))
6658 (defun gnus-article-describe-briefly ()
6659 "Describe article mode commands briefly."
6660 (interactive)
6661 (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")))
6663 (defun gnus-article-check-buffer ()
6664 "Beep if not in an article buffer."
6665 (unless (derived-mode-p 'gnus-article-mode)
6666 (error "Command invoked outside of a Gnus article buffer")))
6668 (defvar gnus-pick-mode)
6670 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6671 "Read a summary buffer key sequence and execute it from the article buffer."
6672 (interactive "P")
6673 (gnus-article-check-buffer)
6674 (let ((nosaves
6675 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6676 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6677 "=" "^" "\M-^" "|"))
6678 (nosave-but-article
6679 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6680 "An" "Ap" [?A (meta return)] [?A delete]))
6681 (nosave-in-article
6682 '("AS" "\C-d"))
6683 keys new-sum-point)
6684 (with-current-buffer gnus-article-current-summary
6685 (let (gnus-pick-mode)
6686 (setq unread-command-events (nconc unread-command-events
6687 (list (or key last-command-event)))
6688 keys (read-key-sequence nil t))))
6690 (message "")
6692 (cond
6693 ((eq (aref keys (1- (length keys))) ?\C-h)
6694 (gnus-article-describe-bindings (substring keys 0 -1)))
6695 ((or (member keys nosaves)
6696 (member keys nosave-but-article)
6697 (member keys nosave-in-article))
6698 (let (func)
6699 (save-window-excursion
6700 (pop-to-buffer gnus-article-current-summary)
6701 ;; We disable the pick minor mode commands.
6702 (let (gnus-pick-mode)
6703 (setq func (key-binding keys t))))
6704 (if (or (not func)
6705 (numberp func))
6706 (ding)
6707 (unless (member keys nosave-in-article)
6708 (set-buffer gnus-article-current-summary))
6709 (when (and (symbolp func)
6710 (get func 'disabled))
6711 (error "Function %s disabled" func))
6712 (call-interactively func)
6713 (setq new-sum-point (point)))
6714 (when (member keys nosave-but-article)
6715 (pop-to-buffer gnus-article-buffer))))
6717 ;; These commands should restore window configuration.
6718 (let ((obuf (current-buffer))
6719 (owin (current-window-configuration))
6720 win func in-buffer selected new-sum-start new-sum-hscroll err)
6721 (cond (not-restore-window
6722 (pop-to-buffer gnus-article-current-summary)
6723 (setq win (selected-window)))
6724 ((setq win (get-buffer-window gnus-article-current-summary))
6725 (select-window win))
6727 (let ((summary-buffer gnus-article-current-summary))
6728 (gnus-configure-windows 'article)
6729 (unless (setq win (get-buffer-window summary-buffer 'visible))
6730 (let ((gnus-buffer-configuration
6731 '((article ((vertical 1.0
6732 (summary 0.25 point)
6733 (article 1.0)))))))
6734 (gnus-configure-windows 'article))
6735 (setq win (get-buffer-window summary-buffer 'visible)))
6736 (select-frame-set-input-focus (window-frame win))
6737 (select-window win))))
6738 (setq in-buffer (current-buffer))
6739 ;; We disable the pick minor mode commands.
6740 (setq func (let (gnus-pick-mode)
6741 (key-binding keys t)))
6742 (when (get func 'disabled)
6743 (error "Function %s disabled" func))
6744 (if (and func
6745 (functionp func)
6746 (condition-case code
6747 (progn
6748 (call-interactively func)
6750 (error
6751 (setq err code)
6752 nil)))
6753 (progn
6754 (when (eq win (selected-window))
6755 (setq new-sum-point (point)
6756 new-sum-start (window-start win)
6757 new-sum-hscroll (window-hscroll win)))
6758 (when (or (eq in-buffer (current-buffer))
6759 (when (eq obuf (current-buffer))
6760 (set-buffer in-buffer)
6762 (setq selected (ignore-errors (gnus-summary-select-article)))
6763 (set-buffer obuf)
6764 (unless not-restore-window
6765 (set-window-configuration owin))
6766 (when (and (eq selected 'old)
6767 new-sum-point)
6768 (set-window-start (get-buffer-window (current-buffer))
6770 (set-window-point (get-buffer-window (current-buffer))
6771 (if (article-goto-body)
6772 (1- (point))
6773 (point))))
6774 (when (and (not not-restore-window)
6775 new-sum-point
6776 (window-live-p win)
6777 (with-current-buffer (window-buffer win)
6778 (derived-mode-p 'gnus-summary-mode)))
6779 (set-window-point win new-sum-point)
6780 (set-window-start win new-sum-start)
6781 (set-window-hscroll win new-sum-hscroll))))
6782 (set-window-configuration owin)
6783 (if err
6784 (signal (car err) (cdr err))
6785 (ding))))))))
6787 (defun gnus-article-read-summary-send-keys ()
6788 (interactive)
6789 (let ((unread-command-events (list ?S)))
6790 (gnus-article-read-summary-keys)))
6792 (defun gnus-article-describe-key (key)
6793 "Display documentation of the function invoked by KEY.
6794 KEY is a string or a vector."
6795 (interactive (list (let ((cursor-in-echo-area t))
6796 (read-key-sequence "Describe key: "))))
6797 (gnus-article-check-buffer)
6798 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6799 gnus-article-read-summary-send-keys))
6800 (with-current-buffer gnus-article-current-summary
6801 (setq unread-command-events
6802 (nconc
6803 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6804 (list 'meta (- x 128))
6806 key)
6807 unread-command-events))
6808 (let ((cursor-in-echo-area t)
6809 gnus-pick-mode)
6810 (describe-key (read-key-sequence nil t))))
6811 (describe-key key)))
6813 (defun gnus-article-describe-key-briefly (key &optional insert)
6814 "Display documentation of the function invoked by KEY.
6815 KEY is a string or a vector."
6816 (interactive (list (let ((cursor-in-echo-area t))
6817 (read-key-sequence "Describe key: "))
6818 current-prefix-arg))
6819 (gnus-article-check-buffer)
6820 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6821 gnus-article-read-summary-send-keys))
6822 (with-current-buffer gnus-article-current-summary
6823 (setq unread-command-events
6824 (nconc
6825 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6826 (list 'meta (- x 128))
6828 key)
6829 unread-command-events))
6830 (let ((cursor-in-echo-area t)
6831 gnus-pick-mode)
6832 (describe-key-briefly (read-key-sequence nil t) insert)))
6833 (describe-key-briefly key insert)))
6835 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6836 (defvar gnus-agent-summary-mode)
6837 (defvar gnus-draft-mode)
6838 (defvar help-xref-stack-item)
6839 (defvar help-xref-following)
6841 (defun gnus-article-describe-bindings (&optional prefix)
6842 "Show a list of all defined keys, and their definitions.
6843 The optional argument PREFIX, if non-nil, should be a key sequence;
6844 then we display only bindings that start with that prefix."
6845 (interactive)
6846 (gnus-article-check-buffer)
6847 (let ((keymap (copy-keymap gnus-article-mode-map))
6848 (map (copy-keymap gnus-article-send-map))
6849 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6850 (summap (make-sparse-keymap))
6851 parent agent draft)
6852 (define-key keymap "S" map)
6853 (define-key map [t] nil)
6854 (define-key summap [t] 'undefined)
6855 (with-current-buffer gnus-article-current-summary
6856 (dolist (key sumkeys)
6857 (define-key summap key (key-binding key (current-local-map))))
6858 (set-keymap-parent
6859 keymap
6860 (if (setq parent (keymap-parent gnus-article-mode-map))
6861 (prog1
6862 (setq parent (copy-keymap parent))
6863 (set-keymap-parent parent summap))
6864 summap))
6865 (set-keymap-parent map (key-binding "S"))
6866 (let (key def gnus-pick-mode)
6867 (while sumkeys
6868 (setq key (pop sumkeys))
6869 (cond ((and (vectorp key) (= (length key) 1)
6870 (consp (setq def (aref key 0)))
6871 (numberp (car def)) (numberp (cdr def)))
6872 (when (< (max (car def) (cdr def)) 128)
6873 (setq sumkeys
6874 (append (mapcar
6875 #'vector
6876 (nreverse (gnus-uncompress-range def)))
6877 sumkeys))))
6878 ((setq def (key-binding key))
6879 (unless (eq def 'undefined)
6880 (define-key keymap key def))))))
6881 (when (boundp 'gnus-agent-summary-mode)
6882 (setq agent gnus-agent-summary-mode))
6883 (when (boundp 'gnus-draft-mode)
6884 (setq draft gnus-draft-mode)))
6885 (with-temp-buffer
6886 (use-local-map keymap)
6887 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6888 (set (make-local-variable 'gnus-draft-mode) draft)
6889 (describe-bindings prefix))
6890 (let ((item `((lambda (prefix)
6891 (with-current-buffer ,(current-buffer)
6892 (gnus-article-describe-bindings prefix)))
6893 ,prefix)))
6894 ;; Loading `help-mode' here is necessary if `describe-bindings'
6895 ;; is replaced with something, e.g. `helm-descbinds'.
6896 (require 'help-mode)
6897 (with-current-buffer (let (help-xref-following) (help-buffer))
6898 (setq help-xref-stack-item item)))))
6900 (defun gnus-article-reply-with-original (&optional wide)
6901 "Start composing a reply mail to the current message.
6902 The text in the region will be yanked. If the region isn't active,
6903 the entire article will be yanked."
6904 (interactive)
6905 (let ((article (cdr gnus-article-current))
6906 contents)
6907 (if (not (and transient-mark-mode mark-active))
6908 (with-current-buffer gnus-summary-buffer
6909 (gnus-summary-reply (list (list article)) wide))
6910 (setq contents (buffer-substring (point) (mark t)))
6911 ;; Deactivate active regions.
6912 (when transient-mark-mode
6913 (setq mark-active nil))
6914 (with-current-buffer gnus-summary-buffer
6915 (gnus-summary-reply
6916 (list (list article contents)) wide)))))
6918 (defun gnus-article-wide-reply-with-original ()
6919 "Start composing a wide reply mail to the current message.
6920 The text in the region will be yanked. If the region isn't active,
6921 the entire article will be yanked."
6922 (interactive)
6923 (gnus-article-reply-with-original t))
6925 (defun gnus-article-followup-with-original ()
6926 "Compose a followup to the current article.
6927 The text in the region will be yanked. If the region isn't active,
6928 the entire article will be yanked."
6929 (interactive)
6930 (let ((article (cdr gnus-article-current))
6931 contents)
6932 (if (not (and transient-mark-mode mark-active))
6933 (with-current-buffer gnus-summary-buffer
6934 (gnus-summary-followup (list (list article))))
6935 (setq contents (buffer-substring (point) (mark t)))
6936 ;; Deactivate active regions.
6937 (when transient-mark-mode
6938 (setq mark-active nil))
6939 (with-current-buffer gnus-summary-buffer
6940 (gnus-summary-followup
6941 (list (list article contents)))))))
6943 (defun gnus-article-hide (&optional arg force)
6944 "Hide all the gruft in the current article.
6945 This means that signatures, cited text and (some) headers will be
6946 hidden.
6947 If given a prefix, show the hidden text instead."
6948 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6949 (gnus-with-article-buffer
6950 (article-hide-headers arg)
6951 (article-hide-list-identifiers)
6952 (gnus-article-hide-citation-maybe arg force)
6953 (article-hide-signature arg)))
6955 (defun gnus-check-group-server ()
6956 ;; Make sure the connection to the server is alive.
6957 (unless (gnus-server-opened
6958 (gnus-find-method-for-group gnus-newsgroup-name))
6959 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6960 (gnus-request-group gnus-newsgroup-name t)))
6962 (declare-function nneething-get-file-name "nneething" (id))
6964 (defun gnus-request-article-this-buffer (article group)
6965 "Get an article and insert it into this buffer."
6966 (let (do-update-line sparse-header)
6967 (prog1
6968 (save-excursion
6969 (erase-buffer)
6970 (gnus-kill-all-overlays)
6971 (setq group (or group gnus-newsgroup-name))
6973 ;; Using `gnus-request-article' directly will insert the article into
6974 ;; `nntp-server-buffer' - so we'll save some time by not having to
6975 ;; copy it from the server buffer into the article buffer.
6977 ;; We only request an article by message-id when we do not have the
6978 ;; headers for it, so we'll have to get those.
6979 (when (stringp article)
6980 (gnus-read-header article))
6982 ;; If the article number is negative, that means that this article
6983 ;; doesn't belong in this newsgroup (possibly), so we find its
6984 ;; message-id and request it by id instead of number.
6985 (when (and (numberp article)
6986 gnus-summary-buffer
6987 (get-buffer gnus-summary-buffer)
6988 (gnus-buffer-exists-p gnus-summary-buffer))
6989 (with-current-buffer gnus-summary-buffer
6990 (let ((header (gnus-summary-article-header article)))
6991 (when (< article 0)
6992 (cond
6993 ((memq article gnus-newsgroup-sparse)
6994 ;; This is a sparse gap article.
6995 (setq do-update-line article)
6996 (setq article (mail-header-id header))
6997 (setq sparse-header (gnus-read-header article))
6998 (setq gnus-newsgroup-sparse
6999 (delq article gnus-newsgroup-sparse)))
7000 ((vectorp header)
7001 ;; It's a real article.
7002 (setq article (mail-header-id header)))
7004 ;; It is an extracted pseudo-article.
7005 (setq article 'pseudo)
7006 (gnus-request-pseudo-article header))))
7008 (let ((method (gnus-find-method-for-group
7009 gnus-newsgroup-name)))
7010 (when (and (eq (car method) 'nneething)
7011 (vectorp header))
7012 (let ((dir (nneething-get-file-name
7013 (mail-header-id header))))
7014 (when (and (stringp dir)
7015 (file-directory-p dir))
7016 (setq article 'nneething)
7017 (gnus-group-enter-directory dir))))))))
7019 (cond
7020 ;; Refuse to select canceled articles.
7021 ((and (numberp article)
7022 gnus-summary-buffer
7023 (get-buffer gnus-summary-buffer)
7024 (gnus-buffer-exists-p gnus-summary-buffer)
7025 (eq (cdr (with-current-buffer gnus-summary-buffer
7026 (assq article gnus-newsgroup-reads)))
7027 gnus-canceled-mark))
7028 nil)
7029 ;; We first check `gnus-original-article-buffer'.
7030 ((and (get-buffer gnus-original-article-buffer)
7031 (numberp article)
7032 (with-current-buffer gnus-original-article-buffer
7033 (and (equal (car gnus-original-article) group)
7034 (eq (cdr gnus-original-article) article))))
7035 ;; `insert-buffer-substring' would incorrectly use the
7036 ;; equivalent of string-make-multibyte which amount to decoding
7037 ;; with locale-coding-system, causing failure of
7038 ;; subsequent decoding.
7039 (insert (string-to-multibyte
7040 (with-current-buffer gnus-original-article-buffer
7041 (buffer-substring (point-min) (point-max)))))
7042 'article)
7043 ;; Check the backlog.
7044 ((and gnus-keep-backlog
7045 (gnus-backlog-request-article group article (current-buffer)))
7046 'article)
7047 ;; Check asynchronous pre-fetch.
7048 ((gnus-async-request-fetched-article group article (current-buffer))
7049 (gnus-async-prefetch-next group article gnus-summary-buffer)
7050 (when (and (numberp article) gnus-keep-backlog)
7051 (gnus-backlog-enter-article group article (current-buffer)))
7052 'article)
7053 ;; Check the cache.
7054 ((and gnus-use-cache
7055 (numberp article)
7056 (gnus-cache-request-article article group))
7057 'article)
7058 ;; Check the agent cache.
7059 ((gnus-agent-request-article article group)
7060 'article)
7061 ;; Get the article and put into the article buffer.
7062 ((or (stringp article)
7063 (numberp article))
7064 (let ((gnus-override-method gnus-override-method)
7065 (methods (and (stringp article)
7066 (with-current-buffer gnus-summary-buffer
7067 (gnus-refer-article-methods))))
7068 (backend (car (gnus-find-method-for-group
7069 gnus-newsgroup-name)))
7070 result
7071 (inhibit-read-only t))
7072 (when (and (null gnus-override-method)
7073 methods)
7074 (setq gnus-override-method (pop methods)))
7075 (while (not result)
7076 (erase-buffer)
7077 (gnus-kill-all-overlays)
7078 (let ((gnus-newsgroup-name group))
7079 (gnus-check-group-server))
7080 (cond
7081 ((gnus-request-article article group (current-buffer))
7082 (when (numberp article)
7083 (gnus-async-prefetch-next group article
7084 gnus-summary-buffer)
7085 (when gnus-keep-backlog
7086 (gnus-backlog-enter-article
7087 group article (current-buffer)))
7088 (when (and gnus-agent
7089 (gnus-agent-group-covered-p group))
7090 (gnus-agent-store-article article group)))
7091 (setq result 'article))
7092 (methods
7093 (setq gnus-override-method (pop methods)))
7094 ((not (string-match "^400 "
7095 (nnheader-get-report backend)))
7096 ;; If we get 400 server disconnect, reconnect and
7097 ;; retry; otherwise, assume the article has expired.
7098 (setq result 'done))))
7099 (and (eq result 'article) 'article)))
7100 ;; It was a pseudo.
7101 (t article)))
7103 ;; Associate this article with the current summary buffer.
7104 (setq gnus-article-current-summary gnus-summary-buffer)
7106 ;; Take the article from the original article buffer
7107 ;; and place it in the buffer it's supposed to be in.
7108 (when (and (get-buffer gnus-article-buffer)
7109 (equal (buffer-name (current-buffer))
7110 (buffer-name (get-buffer gnus-article-buffer))))
7111 (save-excursion
7112 (if (get-buffer gnus-original-article-buffer)
7113 (set-buffer gnus-original-article-buffer)
7114 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7115 (buffer-disable-undo)
7116 (setq major-mode 'gnus-original-article-mode)
7117 (setq buffer-read-only t))
7118 (let ((inhibit-read-only t))
7119 (erase-buffer)
7120 (insert-buffer-substring gnus-article-buffer))
7121 (setq gnus-original-article (cons group article)))
7123 ;; Decode charsets.
7124 (run-hooks 'gnus-article-decode-hook)
7125 ;; Mark article as decoded or not.
7126 (setq gnus-article-decoded-p gnus-article-decode-hook))
7128 ;; Update sparse articles.
7129 (when (and do-update-line
7130 (or (numberp article)
7131 (stringp article)))
7132 (let ((buf (current-buffer)))
7133 (set-buffer gnus-summary-buffer)
7134 (gnus-summary-update-article do-update-line sparse-header)
7135 (gnus-summary-goto-subject do-update-line nil t)
7136 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7137 (point))
7138 (set-buffer buf))))))
7140 (defun gnus-block-private-groups (group)
7141 "Allows images in newsgroups to be shown, blocks images in all
7142 other groups."
7143 (if (or (gnus-news-group-p group)
7144 (gnus-member-of-valid 'global group))
7145 ;; Block nothing in news groups.
7147 ;; Block everything anywhere else.
7148 "."))
7150 (defun gnus-blocked-images ()
7151 (if (functionp gnus-blocked-images)
7152 (funcall gnus-blocked-images gnus-newsgroup-name)
7153 gnus-blocked-images))
7156 ;;; Article editing
7159 (defcustom gnus-article-edit-mode-hook nil
7160 "Hook run in article edit mode buffers."
7161 :group 'gnus-article-various
7162 :type 'hook)
7164 (defvar gnus-article-edit-done-function nil)
7166 (defvar gnus-article-edit-mode-map nil)
7168 ;; Should we be using derived.el for this?
7169 (unless gnus-article-edit-mode-map
7170 (setq gnus-article-edit-mode-map (make-keymap))
7171 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7173 (gnus-define-keys gnus-article-edit-mode-map
7174 "\C-c?" describe-mode
7175 "\C-c\C-c" gnus-article-edit-done
7176 "\C-c\C-k" gnus-article-edit-exit
7177 "\C-c\C-f\C-t" message-goto-to
7178 "\C-c\C-f\C-o" message-goto-from
7179 "\C-c\C-f\C-b" message-goto-bcc
7180 ;;"\C-c\C-f\C-w" message-goto-fcc
7181 "\C-c\C-f\C-c" message-goto-cc
7182 "\C-c\C-f\C-s" message-goto-subject
7183 "\C-c\C-f\C-r" message-goto-reply-to
7184 "\C-c\C-f\C-n" message-goto-newsgroups
7185 "\C-c\C-f\C-d" message-goto-distribution
7186 "\C-c\C-f\C-f" message-goto-followup-to
7187 "\C-c\C-f\C-m" message-goto-mail-followup-to
7188 "\C-c\C-f\C-k" message-goto-keywords
7189 "\C-c\C-f\C-u" message-goto-summary
7190 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7191 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7192 "\C-c\C-b" message-goto-body
7193 "\C-c\C-i" message-goto-signature
7195 "\C-c\C-t" message-insert-to
7196 "\C-c\C-n" message-insert-newsgroups
7197 "\C-c\C-o" message-sort-headers
7198 "\C-c\C-e" message-elide-region
7199 "\C-c\C-v" message-delete-not-region
7200 "\C-c\C-z" message-kill-to-signature
7201 "\M-\r" message-newline-and-reformat
7202 "\C-c\C-a" mml-attach-file
7203 "\C-a" message-beginning-of-line
7204 "\t" message-tab
7205 "\M-;" comment-region)
7207 (gnus-define-keys (gnus-article-edit-wash-map
7208 "\C-c\C-w" gnus-article-edit-mode-map)
7209 "f" gnus-article-edit-full-stops))
7211 (easy-menu-define
7212 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7213 '("Field"
7214 ["Fetch To" message-insert-to t]
7215 ["Fetch Newsgroups" message-insert-newsgroups t]
7216 "----"
7217 ["To" message-goto-to t]
7218 ["From" message-goto-from t]
7219 ["Subject" message-goto-subject t]
7220 ["Cc" message-goto-cc t]
7221 ["Reply-To" message-goto-reply-to t]
7222 ["Summary" message-goto-summary t]
7223 ["Keywords" message-goto-keywords t]
7224 ["Newsgroups" message-goto-newsgroups t]
7225 ["Followup-To" message-goto-followup-to t]
7226 ["Mail-Followup-To" message-goto-mail-followup-to t]
7227 ["Distribution" message-goto-distribution t]
7228 ["Body" message-goto-body t]
7229 ["Signature" message-goto-signature t]))
7231 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7232 "Major mode for editing articles.
7233 This is an extended text-mode.
7235 \\{gnus-article-edit-mode-map}"
7236 (make-local-variable 'gnus-article-edit-done-function)
7237 (make-local-variable 'gnus-prev-winconf)
7238 (set (make-local-variable 'font-lock-defaults)
7239 '(message-font-lock-keywords t))
7240 (set (make-local-variable 'mail-header-separator) "")
7241 (set (make-local-variable 'gnus-article-edit-mode) t)
7242 (easy-menu-add message-mode-field-menu message-mode-map)
7243 (mml-mode)
7244 (setq buffer-read-only nil)
7245 (buffer-enable-undo)
7246 (widen))
7248 (defun gnus-article-edit (&optional force)
7249 "Edit the current article.
7250 This will have permanent effect only in mail groups.
7251 If FORCE is non-nil, allow editing of articles even in read-only
7252 groups."
7253 (interactive "P")
7254 (when (and (not force)
7255 (gnus-group-read-only-p))
7256 (error "The current newsgroup does not support article editing"))
7257 (gnus-with-article-buffer
7258 (article-date-original))
7259 (gnus-article-edit-article
7260 'ignore
7261 `(lambda (no-highlight)
7262 'ignore
7263 (gnus-summary-edit-article-done
7264 ,(or (mail-header-references gnus-current-headers) "")
7265 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7267 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7268 "Start editing the contents of the current article buffer."
7269 (let ((winconf (current-window-configuration)))
7270 (set-buffer gnus-article-buffer)
7271 (let ((message-auto-save-directory
7272 ;; Don't associate the article buffer with a draft file.
7273 nil))
7274 (gnus-article-edit-mode))
7275 (funcall start-func)
7276 (set-buffer-modified-p nil)
7277 (gnus-configure-windows 'edit-article)
7278 (setq gnus-article-edit-done-function exit-func)
7279 (setq gnus-prev-winconf winconf)
7280 (unless quiet
7281 (gnus-message 6 "C-c C-c to end edits"))))
7283 (defun gnus-article-edit-done (&optional arg)
7284 "Update the article edits and exit."
7285 (interactive "P")
7286 (let ((func gnus-article-edit-done-function)
7287 (buf (current-buffer))
7288 (start (window-start))
7289 (winconf gnus-prev-winconf))
7290 (widen) ;; Widen it in case that users narrowed the buffer.
7291 (funcall func arg)
7292 (set-buffer buf)
7293 ;; The cache and backlog have to be flushed somewhat.
7294 (when gnus-keep-backlog
7295 (gnus-backlog-remove-article
7296 (car gnus-article-current) (cdr gnus-article-current)))
7297 ;; Flush original article as well.
7298 (gnus-flush-original-article-buffer)
7299 (when gnus-use-cache
7300 (gnus-cache-update-article
7301 (car gnus-article-current) (cdr gnus-article-current)))
7302 ;; We remove all text props from the article buffer.
7303 (kill-all-local-variables)
7304 (set-text-properties (point-min) (point-max) nil)
7305 (gnus-article-mode)
7306 (set-window-configuration winconf)
7307 (set-buffer buf)
7308 (set-window-start (get-buffer-window buf) start)
7309 (set-window-point (get-buffer-window buf) (point)))
7310 (gnus-summary-show-article))
7312 (defun gnus-flush-original-article-buffer ()
7313 (when (get-buffer gnus-original-article-buffer)
7314 (with-current-buffer gnus-original-article-buffer
7315 (setq gnus-original-article nil))))
7317 (defun gnus-article-edit-exit ()
7318 "Exit the article editing without updating."
7319 (interactive)
7320 (when (or (not (buffer-modified-p))
7321 (yes-or-no-p "Article modified; kill anyway? "))
7322 (let ((curbuf (current-buffer))
7323 (p (point))
7324 (window-start (window-start)))
7325 (erase-buffer)
7326 (if (gnus-buffer-live-p gnus-original-article-buffer)
7327 (insert-buffer-substring gnus-original-article-buffer))
7328 (let ((winconf gnus-prev-winconf))
7329 (kill-all-local-variables)
7330 (gnus-article-mode)
7331 (set-window-configuration winconf)
7332 ;; Tippy-toe some to make sure that point remains where it was.
7333 (save-current-buffer
7334 (set-buffer curbuf)
7335 (set-window-start (get-buffer-window (current-buffer)) window-start)
7336 (goto-char p))))
7337 (gnus-summary-show-article)))
7339 (defun gnus-article-edit-full-stops ()
7340 "Interactively repair spacing at end of sentences."
7341 (interactive)
7342 (save-excursion
7343 (goto-char (point-min))
7344 (search-forward-regexp "^$" nil t)
7345 (let ((case-fold-search nil))
7346 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7349 ;;; Article highlights
7352 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7354 ;;; Internal Variables:
7356 (defcustom gnus-button-url-regexp
7357 (concat
7358 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7359 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7360 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7361 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7362 (punct "!?:;.,"))
7363 (concat
7364 "\\(?:"
7365 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7366 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7367 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7368 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7369 "\\|"
7370 "[" chars punct "]+" "[" chars "]"
7371 "\\)"))
7372 "\\)")
7373 "Regular expression that matches URLs."
7374 :version "24.4"
7375 :group 'gnus-article-buttons
7376 :type 'regexp)
7378 (defcustom gnus-button-valid-fqdn-regexp "\\([-A-Za-z0-9]+\\.\\)+[A-Za-z]+"
7379 "Regular expression that matches a valid FQDN."
7380 :version "26.1"
7381 :group 'gnus-article-buttons
7382 :type 'regexp)
7384 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7385 (defcustom gnus-button-valid-localpart-regexp
7386 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7387 "Regular expression that matches a localpart of mail addresses or MIDs."
7388 :version "22.1"
7389 :group 'gnus-article-buttons
7390 :type 'regexp)
7392 (defcustom gnus-button-man-handler 'manual-entry
7393 "Function to use for displaying man pages.
7394 The function must take at least one argument with a string naming the
7395 man page."
7396 :version "22.1"
7397 :type '(choice (function-item :tag "Man" manual-entry)
7398 (function-item :tag "Woman" woman)
7399 (function :tag "Other"))
7400 :group 'gnus-article-buttons)
7402 (defcustom gnus-button-mid-or-mail-regexp
7403 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7404 gnus-button-valid-fqdn-regexp
7405 ">?\\)\\b")
7406 "Regular expression that matches a message ID or a mail address."
7407 :version "22.1"
7408 :group 'gnus-article-buttons
7409 :type 'regexp)
7411 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7412 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7413 Strings like this can be either a message ID or a mail address. If it is one
7414 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7415 message ID or a mail address, respectively. If this variable is set to the
7416 symbol `ask', always query the user what do do. If it is a function, this
7417 function will be called with the string as its only argument. The function
7418 must return `mid', `mail', `invalid' or `ask'."
7419 :version "22.1"
7420 :group 'gnus-article-buttons
7421 :type '(choice (function-item :tag "Heuristic function"
7422 gnus-button-mid-or-mail-heuristic)
7423 (const ask)
7424 (const mid)
7425 (const mail)))
7427 (defcustom gnus-button-mid-or-mail-heuristic-alist
7428 '((-10.0 . ".+\\$.+@")
7429 (-10.0 . "#")
7430 (-10.0 . "\\*")
7431 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7432 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7433 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7434 (-1.0 . "^[^a-z]+@")
7436 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7437 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7438 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7439 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7441 (-2.0 . "^[0-9]")
7442 (-1.0 . "^[0-9][0-9]")
7444 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7445 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7446 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7447 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7449 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7450 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7451 ;; "[0-9]{8,}.*\@"
7452 (-3.0
7453 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7454 ;; "[0-9]{12,}.*\@"
7455 ;; compensation for TDMA dated mail addresses:
7456 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7458 (-20.0 . "\\.fsf@") ;; Gnus
7459 (-20.0 . "^slrn")
7460 (-20.0 . "^Pine")
7461 (-20.0 . "^alpine\\.")
7462 (-20.0 . "_-_") ;; Subject change in thread
7464 (-20.0 . "\\.ln@") ;; leafnode
7465 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7466 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7468 ;; (5.0 . "") ;; $local_part_len <= 7
7469 (10.0 . "^[^0-9]+@")
7470 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7471 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7472 (3.0 . "@stud")
7474 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7476 (0.5 . "^[A-Z][a-z]")
7477 (0.5 . "^[A-Z][a-z][a-z]")
7478 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7479 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7480 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7482 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7483 address. The REGEXP is processed with `case-fold-search' set to nil."
7484 :version "22.1"
7485 :group 'gnus-article-buttons
7486 :type '(repeat (cons (number :tag "Rate")
7487 (regexp :tag "Regexp"))))
7489 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7490 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7491 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7492 address, `ask' if unsure and `invalid' if the string is invalid."
7493 (let ((case-fold-search nil)
7494 (list gnus-button-mid-or-mail-heuristic-alist)
7495 (result 0) rate regexp lpartlen elem)
7496 (setq lpartlen
7497 (length (replace-regexp-in-string "^\\(.*\\)@.*$" "\\1" mid-or-mail)))
7498 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7499 ;; Certain special cases...
7500 (when (string-match
7501 (concat
7502 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7503 "^[0-9]+\\.[0-9]+@compuserve\\|"
7504 "@public\\.gmane\\.org")
7505 mid-or-mail)
7506 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7507 (setq result 'mail))
7508 (when (string-match "@.*@\\| " mid-or-mail)
7509 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7510 (setq result 'invalid))
7511 ;; Nothing more to do, if result is not a number here...
7512 (when (numberp result)
7513 (while list
7514 (setq elem (car list)
7515 rate (car elem)
7516 regexp (cdr elem)
7517 list (cdr list))
7518 (when (string-match regexp mid-or-mail)
7519 (setq result (+ result rate))
7520 (gnus-message
7521 9 "`%s' matched `%s', rate `%s', result `%s'."
7522 mid-or-mail regexp rate result)))
7523 (when (<= lpartlen 7)
7524 (setq result (+ result 5.0))
7525 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7526 mid-or-mail result))
7527 (when (>= lpartlen 12)
7528 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7529 (cond
7530 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7531 ;; Long local part should contain realname if e-mail address,
7532 ;; too many digits: message-id.
7533 ;; $score -= 5.0 + 0.1 * $local_part_len;
7534 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7535 (setq result (+ result rate))
7536 (gnus-message
7537 9 "Many digits in `%s', rate `%s', result `%s'."
7538 mid-or-mail rate result))
7539 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7540 mid-or-mail)
7541 ;; Too few vowels [^aeiouy]{4,}.*@
7542 (setq result (+ result -5.0))
7543 (gnus-message
7544 9 "Few vowels in `%s', rate `%s', result `%s'."
7545 mid-or-mail -5.0 result))
7547 (setq result (+ result 5.0))
7548 (gnus-message
7549 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7550 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7551 ;; Maybe we should make this a customizable alist: (condition . 'result)
7552 (cond
7553 ((symbolp result) result)
7554 ;; Now convert number into proper results:
7555 ((< result -10.0) 'mid)
7556 ((> result 10.0) 'mail)
7557 (t 'ask))))
7559 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7560 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7561 (url-mid (concat "news" ":" mid-or-mail))
7562 (url-mailto (concat "mailto" ":" mid-or-mail)))
7563 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7564 (when (fboundp pref)
7565 (setq guessed
7566 ;; get rid of surrounding angles...
7567 (funcall pref
7568 (replace-regexp-in-string "^<\\|>$" "" mid-or-mail)))
7569 (if (or (eq 'mid guessed) (eq 'mail guessed))
7570 (setq pref guessed)
7571 (setq pref 'ask)))
7572 (if (eq pref 'ask)
7573 (save-window-excursion
7574 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7575 (setq pref 'mail)
7576 (setq pref 'mid))))
7577 (cond ((eq pref 'mid)
7578 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7579 (gnus-button-handle-news url-mid))
7580 ((eq pref 'mail)
7581 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7582 (gnus-url-mailto url-mailto))
7583 (t (gnus-message 3 "Invalid string.")))))
7585 (defun gnus-button-handle-custom (fun arg)
7586 "Call function FUN on argument ARG.
7587 Both FUN and ARG are supposed to be strings. ARG will be passed
7588 as a symbol to FUN."
7589 (funcall (intern fun)
7590 (if (string-match "^customize-apropos" fun)
7592 (intern arg))))
7594 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7596 (defun gnus-button-handle-describe-function (url)
7597 "Call `describe-function' when pushing the corresponding URL button."
7598 (describe-function
7599 (intern
7600 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7602 (defun gnus-button-handle-describe-variable (url)
7603 "Call `describe-variable' when pushing the corresponding URL button."
7604 (describe-variable
7605 (intern
7606 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7608 (defun gnus-button-handle-symbol (url)
7609 "Display help on variable or function.
7610 Calls `describe-variable' or `describe-function'."
7611 (let ((sym (intern url)))
7612 (cond
7613 ((fboundp sym) (describe-function sym))
7614 ((boundp sym) (describe-variable sym))
7615 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7617 (defun gnus-button-handle-describe-key (url)
7618 "Call `describe-key' when pushing the corresponding URL button."
7619 (let* ((key-string
7620 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))
7621 (keys (ignore-errors (eval `(kbd ,key-string)))))
7622 (if keys
7623 (describe-key keys)
7624 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7626 (defun gnus-button-handle-apropos (url)
7627 "Call `apropos' when pushing the corresponding URL button."
7628 (apropos (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7630 (defun gnus-button-handle-apropos-command (url)
7631 "Call `apropos' when pushing the corresponding URL button."
7632 (apropos-command
7633 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7635 (defun gnus-button-handle-apropos-variable (url)
7636 "Call `apropos' when pushing the corresponding URL button."
7637 (apropos-variable
7638 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7640 (defun gnus-button-handle-apropos-documentation (url)
7641 "Call `apropos' when pushing the corresponding URL button."
7642 (apropos-documentation
7643 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7645 (defun gnus-button-handle-library (url)
7646 "Call `locate-library' when pushing the corresponding URL button."
7647 (gnus-message 9 "url=`%s'" url)
7648 (let* ((lib (locate-library url))
7649 (file (replace-regexp-in-string "\\.elc" ".el" (or lib ""))))
7650 (if (not lib)
7651 (gnus-message 1 "Cannot locate library `%s'." url)
7652 (find-file-read-only file))))
7654 (defcustom gnus-button-man-level 5
7655 "Integer that says how many man-related buttons Gnus will show.
7656 The higher the number, the more buttons will appear and the more false
7657 positives are possible. Note that you can set this variable local to
7658 specific groups. Setting it higher in Unix groups is probably a good idea.
7659 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7660 how to set variables in specific groups."
7661 :version "22.1"
7662 :group 'gnus-article-buttons
7663 :link '(custom-manual "(gnus)Group Parameters")
7664 :type 'integer)
7666 (defcustom gnus-button-emacs-level 5
7667 "Integer that says how many emacs-related buttons Gnus will show.
7668 The higher the number, the more buttons will appear and the more false
7669 positives are possible. Note that you can set this variable local to
7670 specific groups. Setting it higher in Emacs or Gnus related groups is
7671 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7672 `gnus-parameters' on how to set variables in specific groups."
7673 :version "22.1"
7674 :group 'gnus-article-buttons
7675 :link '(custom-manual "(gnus)Group Parameters")
7676 :type 'integer)
7678 (defcustom gnus-button-message-level 5
7679 "Integer that says how many buttons for news or mail messages will appear.
7680 The higher the number, the more buttons will appear and the more false
7681 positives are possible."
7682 ;; mail addresses, MIDs, URLs for news, ...
7683 :version "22.1"
7684 :group 'gnus-article-buttons
7685 :type 'integer)
7687 (defcustom gnus-button-browse-level 5
7688 "Integer that says how many buttons for browsing will appear.
7689 The higher the number, the more buttons will appear and the more false
7690 positives are possible."
7691 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7692 :version "22.1"
7693 :group 'gnus-article-buttons
7694 :type 'integer)
7696 (defcustom gnus-button-alist
7697 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7698 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7699 ((concat "\\b\\(nntp\\|news\\):\\("
7700 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7701 0 t gnus-button-handle-news 2)
7702 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7703 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7704 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7705 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7706 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7707 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7708 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7709 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7710 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7711 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7712 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7713 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7714 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7715 ;; RFC 2368 (The mailto URL scheme)
7716 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7717 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7718 ("\\bmailto:\\([^ \n\t]+\\)"
7719 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7720 ;; Info Konqueror style <info:/foo/bar baz>.
7721 ;; Must come before " Gnus home-grown style".
7722 ("\\binfo://?\\([^'\">\n\t]+\\)"
7723 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7724 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7725 ("\\binfo://\\([^'\">\n\t ]+\\)"
7726 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7727 ;; Info GNOME style <info:foo#bar_baz>
7728 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7729 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7730 ;; Info KDE style <info:(foo)bar baz>
7731 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7732 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7733 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7734 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7735 ("\\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,]*\\)\\)?"
7736 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7737 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7738 ;; This is custom
7739 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7740 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7741 ;; Emacs help commands
7742 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7743 ;; regexp doesn't match arguments containing ` '.
7744 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7745 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7746 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7747 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7748 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7749 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7750 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7751 ;; The following entries may lead to many false positives so don't enable
7752 ;; them by default (use a high button level).
7753 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7754 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7755 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7756 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7757 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7758 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7759 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7760 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7761 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7762 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7763 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7764 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7765 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7766 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7767 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7768 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7769 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7770 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7771 ;; Unlike the other regexps we really have to require quoting
7772 ;; here to determine where it ends.
7773 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7774 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7775 ("<URL: *\\([^\n<>]*\\)>"
7776 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7777 ;; RFC 2396 (2.4.3., delims) ...
7778 ("\"URL: *\\([^\n\"]*\\)\""
7779 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7780 ;; Raw URLs.
7781 (gnus-button-url-regexp
7782 0 (>= gnus-button-browse-level 0) browse-url 0)
7783 ;; man pages
7784 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7785 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7786 gnus-button-handle-man 1)
7787 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7788 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7789 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7790 gnus-button-handle-man 1)
7791 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7792 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7793 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7794 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7795 ;; Recognizing patches to .el files. This is somewhat obscure,
7796 ;; but considering the percentage of Gnus users who hack Emacs
7797 ;; Lisp files...
7798 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7799 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7800 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7801 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7802 ;; MID or mail: To avoid too many false positives we don't try to catch
7803 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7804 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7805 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7806 ;; so that non-ambiguous entries (see above) match first.
7807 (gnus-button-mid-or-mail-regexp
7808 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7809 "Alist of regexps matching buttons in article bodies.
7811 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7812 REGEXP: is the string (case insensitive) matching text around the button (can
7813 also be Lisp expression evaluating to a string),
7814 BUTTON: is the number of the regexp grouping actually matching the button,
7815 FORM: is a Lisp expression which must eval to true for the button to
7816 be added,
7817 CALLBACK: is the function to call when the user push this button, and each
7818 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7820 CALLBACK can also be a variable, in that case the value of that
7821 variable it the real callback function."
7822 :group 'gnus-article-buttons
7823 :type '(repeat (list (choice regexp variable sexp)
7824 (integer :tag "Button")
7825 (sexp :tag "Form")
7826 (function :tag "Callback")
7827 (repeat :tag "Par"
7828 :inline t
7829 (integer :tag "Regexp group")))))
7830 (put 'gnus-button-alist 'risky-local-variable t)
7832 (defcustom gnus-header-button-alist
7833 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7834 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7835 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7836 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7837 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7838 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7839 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7840 0 (>= gnus-button-browse-level 0) browse-url 0)
7841 ("^Subject:" gnus-button-url-regexp
7842 0 (>= gnus-button-browse-level 0) browse-url 0)
7843 ("^[^:]+:" gnus-button-url-regexp
7844 0 (>= gnus-button-browse-level 0) browse-url 0)
7845 ("^OpenPGP:.*url=" gnus-button-url-regexp
7846 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7847 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7848 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7849 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7850 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7851 "Alist of headers and regexps to match buttons in article heads.
7853 This alist is very similar to `gnus-button-alist', except that each
7854 alist has an additional HEADER element first in each entry:
7856 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7858 HEADER is a regexp to match a header. For a fuller explanation, see
7859 `gnus-button-alist'."
7860 :group 'gnus-article-buttons
7861 :group 'gnus-article-headers
7862 :type '(repeat (list (regexp :tag "Header")
7863 (choice regexp variable)
7864 (integer :tag "Button")
7865 (sexp :tag "Form")
7866 (function :tag "Callback")
7867 (repeat :tag "Par"
7868 :inline t
7869 (integer :tag "Regexp group")))))
7870 (put 'gnus-header-button-alist 'risky-local-variable t)
7872 ;;; Commands:
7874 (defun gnus-article-push-button (event)
7875 "Check text under the mouse pointer for a callback function.
7876 If the text under the mouse pointer has a `gnus-callback' property,
7877 call it with the value of the `gnus-data' text property."
7878 (interactive "e")
7879 (set-buffer (window-buffer (posn-window (event-start event))))
7880 (let* ((pos (posn-point (event-start event)))
7881 (data (get-text-property pos 'gnus-data))
7882 (fun (get-text-property pos 'gnus-callback)))
7883 (goto-char pos)
7884 (when fun
7885 (funcall fun data))))
7887 (defun gnus-article-press-button ()
7888 "Check text at point for a callback function.
7889 If the text at point has a `gnus-callback' property,
7890 call it with the value of the `gnus-data' text property."
7891 (interactive)
7892 (let ((data (get-text-property (point) 'gnus-data))
7893 (fun (get-text-property (point) 'gnus-callback)))
7894 (when fun
7895 (funcall fun data))))
7897 (defun gnus-article-highlight (&optional force)
7898 "Highlight current article.
7899 This function calls `gnus-article-highlight-headers',
7900 `gnus-article-highlight-citation',
7901 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7902 do the highlighting. See the documentation for those functions."
7903 (interactive (list 'force))
7904 (gnus-article-highlight-headers)
7905 (gnus-article-highlight-citation force)
7906 (gnus-article-highlight-signature)
7907 (gnus-article-add-buttons)
7908 (gnus-article-add-buttons-to-head))
7910 (defun gnus-article-highlight-some (&optional _force)
7911 "Highlight current article.
7912 This function calls `gnus-article-highlight-headers',
7913 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7914 do the highlighting. See the documentation for those functions."
7915 (interactive (list 'force))
7916 (gnus-article-highlight-headers)
7917 (gnus-article-highlight-signature)
7918 (gnus-article-add-buttons))
7920 (defun gnus-article-highlight-headers ()
7921 "Highlight article headers as specified by `gnus-header-face-alist'."
7922 (interactive)
7923 (gnus-with-article-headers
7924 (let (regexp header-face field-face from hpoints fpoints)
7925 (dolist (entry gnus-header-face-alist)
7926 (goto-char (point-min))
7927 (setq regexp (concat "^\\("
7928 (if (string-equal "" (nth 0 entry))
7929 "[^\t ]"
7930 (nth 0 entry))
7931 "\\)")
7932 header-face (nth 1 entry)
7933 field-face (nth 2 entry))
7934 (while (and (re-search-forward regexp nil t)
7935 (not (eobp)))
7936 (beginning-of-line)
7937 (setq from (point))
7938 (unless (search-forward ":" nil t)
7939 (forward-char 1))
7940 (when (and header-face
7941 (not (memq (point) hpoints)))
7942 (push (point) hpoints)
7943 (put-text-property from (point) 'face header-face))
7944 (when (and field-face
7945 (not (memq (setq from (point)) fpoints)))
7946 (push from fpoints)
7947 (if (re-search-forward "^[^ \t]" nil t)
7948 (forward-char -2)
7949 (goto-char (point-max)))
7950 (put-text-property from (point) 'face field-face)))))))
7952 (defun gnus-article-highlight-signature ()
7953 "Highlight the signature in an article.
7954 It does this by highlighting everything after
7955 `gnus-signature-separator' using the face `gnus-signature'."
7956 (interactive)
7957 (gnus-with-article-buffer
7958 (let ((inhibit-point-motion-hooks t))
7959 (save-restriction
7960 (when (and gnus-signature-face
7961 (gnus-article-narrow-to-signature))
7962 (overlay-put (make-overlay (point-min) (point-max) nil t)
7963 'face gnus-signature-face)
7964 (widen)
7965 (gnus-article-search-signature)
7966 (let ((start (match-beginning 0))
7967 (end (set-marker (make-marker) (1+ (match-end 0)))))
7968 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7969 end)))))))
7971 (defun gnus-button-in-region-p (b e prop)
7972 "Say whether PROP exists in the region."
7973 (text-property-not-all b e prop nil))
7975 (defun gnus-article-add-buttons ()
7976 "Find external references in the article and make buttons of them.
7977 \"External references\" are things like Message-IDs and URLs, as
7978 specified by `gnus-button-alist'."
7979 (interactive)
7980 (gnus-with-article-buffer
7981 (let ((inhibit-point-motion-hooks t)
7982 (case-fold-search t)
7983 (alist gnus-button-alist)
7984 beg entry regexp)
7985 ;; We skip the headers.
7986 (article-goto-body)
7987 (setq beg (point))
7988 (while (setq entry (pop alist))
7989 (setq regexp (eval (car entry)))
7990 (goto-char beg)
7991 (while (re-search-forward regexp nil t)
7992 (let ((start (match-beginning (nth 1 entry)))
7993 (end (match-end (nth 1 entry)))
7994 (from (match-beginning 0)))
7995 (when (and (eval (nth 2 entry))
7996 (not (gnus-button-in-region-p
7997 start end 'gnus-callback)))
7998 ;; That optional form returned non-nil, so we add the
7999 ;; button.
8000 (setq from (set-marker (make-marker) from))
8001 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8002 (gnus-article-extend-url-button from start end))
8003 (gnus-article-add-button start end
8004 'gnus-button-push (list from entry))
8005 (put-text-property
8006 start end
8007 'gnus-string (buffer-substring-no-properties
8008 start end))))))))))
8010 (defun gnus-article-extend-url-button (beg start end)
8011 "Extend url button if url is folded into two or more lines.
8012 Return non-nil if button is extended. BEG is a marker that points to
8013 the beginning position of a text containing url. START and END are
8014 the endpoints of a url button before it is extended. The concatenated
8015 url is put as the `gnus-button-url' overlay property on the button."
8016 (let ((opoint (point))
8017 (points (list start end))
8018 url delim regexp)
8019 (prog1
8020 (when (and (progn
8021 (goto-char end)
8022 (not (looking-at "[\t ]*[\">]")))
8023 (progn
8024 (goto-char start)
8025 (string-match
8026 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8027 (buffer-substring (point-at-bol) start)))
8028 (progn
8029 (setq url (list (buffer-substring start end))
8030 delim (if (match-beginning 1) ">" "\""))
8031 (beginning-of-line)
8032 (setq regexp (concat
8033 (when (and (looking-at
8034 message-cite-prefix-regexp)
8035 (< (match-end 0) start))
8036 (regexp-quote (match-string 0)))
8038 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8039 delim "\\)"))
8040 (while (progn
8041 (forward-line 1)
8042 (and (looking-at regexp)
8043 (prog1
8044 (match-beginning 1)
8045 (push (or (match-string 2)
8046 (match-string 1))
8047 url)
8048 (push (setq end (or (match-end 2)
8049 (match-end 1)))
8050 points)
8051 (push (or (match-beginning 2)
8052 (match-beginning 1))
8053 points)))))
8054 (match-beginning 2)))
8055 (let (gnus-article-mouse-face widget-mouse-face)
8056 (while points
8057 (gnus-article-add-button (pop points) (pop points)
8058 'gnus-button-push
8059 (list beg (assq 'gnus-button-url-regexp
8060 gnus-button-alist)))))
8061 (let ((overlay (make-overlay start end)))
8062 (overlay-put overlay 'evaporate t)
8063 (overlay-put overlay 'gnus-button-url
8064 (list (mapconcat 'identity (nreverse url) "")))
8065 (when gnus-article-mouse-face
8066 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8068 (goto-char opoint))))
8070 ;; Add buttons to the head of an article.
8071 (defun gnus-article-add-buttons-to-head ()
8072 "Add buttons to the head of the article."
8073 (interactive)
8074 (gnus-with-article-headers
8075 (let (beg end)
8076 (dolist (entry gnus-header-button-alist)
8077 ;; Each alist entry.
8078 (goto-char (point-min))
8079 (while (re-search-forward (car entry) nil t)
8080 ;; Each header matching the entry.
8081 (setq beg (match-beginning 0))
8082 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8083 (match-beginning 0))
8084 (point-max)))
8085 (goto-char beg)
8086 (while (re-search-forward (eval (nth 1 entry)) end t)
8087 ;; Each match within a header.
8088 (let* ((entry (cdr entry))
8089 (start (match-beginning (nth 1 entry)))
8090 (end (match-end (nth 1 entry)))
8091 (form (nth 2 entry)))
8092 (goto-char (match-end 0))
8093 (when (eval form)
8094 (gnus-article-add-button
8095 start end (nth 3 entry)
8096 (buffer-substring (match-beginning (nth 4 entry))
8097 (match-end (nth 4 entry)))))))
8098 (goto-char end))))))
8100 ;;; External functions:
8102 (defun gnus-article-add-button (from to fun &optional data text)
8103 "Create a button between FROM and TO with callback FUN and data DATA."
8104 (when gnus-article-button-face
8105 (overlay-put (make-overlay from to nil t)
8106 'face gnus-article-button-face))
8107 (add-text-properties
8108 from to
8109 (nconc (and gnus-article-mouse-face
8110 (list 'mouse-face gnus-article-mouse-face))
8111 (list 'gnus-callback fun)
8112 (and data (list 'gnus-data data))))
8113 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8114 :help-echo (or text "Follow the link")
8115 :keymap gnus-url-button-map))
8117 (defun gnus-article-copy-string ()
8118 "Copy the string in the button to the kill ring."
8119 (interactive)
8120 (gnus-article-check-buffer)
8121 (let ((data (get-text-property (point) 'gnus-string)))
8122 (when data
8123 (with-temp-buffer
8124 (insert data)
8125 (copy-region-as-kill (point-min) (point-max))
8126 (message "Copied %s" data)))))
8128 ;;; Internal functions:
8130 (defun gnus-article-set-globals ()
8131 (with-current-buffer gnus-summary-buffer
8132 (gnus-set-global-variables)))
8134 (defun gnus-signature-toggle (end)
8135 (gnus-with-article-buffer
8136 (let ((inhibit-point-motion-hooks t))
8137 (if (text-property-any end (point-max) 'article-type 'signature)
8138 (progn
8139 (gnus-delete-wash-type 'signature)
8140 (gnus-remove-text-properties-when
8141 'article-type 'signature end (point-max)
8142 (cons 'article-type (cons 'signature
8143 gnus-hidden-properties))))
8144 (gnus-add-wash-type 'signature)
8145 (gnus-add-text-properties-when
8146 'article-type nil end (point-max)
8147 (cons 'article-type (cons 'signature
8148 gnus-hidden-properties)))))
8149 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8150 (gnus-set-mode-line 'article))))
8152 (defun gnus-button-push (marker-and-entry)
8153 ;; Push button starting at MARKER.
8154 (save-excursion
8155 (let* ((marker (car marker-and-entry))
8156 (entry (cadr marker-and-entry))
8157 (regexp (car entry))
8158 (inhibit-point-motion-hooks t))
8159 (goto-char marker)
8160 ;; This is obviously true, or something bad is happening :)
8161 ;; But we need it to have the match-data
8162 (when (looking-at (or (if (symbolp regexp)
8163 (symbol-value regexp)
8164 regexp)))
8165 (let ((fun (nth 3 entry))
8166 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8167 (get-char-property marker 'gnus-button-url))
8168 (mapcar (lambda (group)
8169 (let ((string (match-string group)))
8170 (set-text-properties
8171 0 (length string) nil string)
8172 string))
8173 (nthcdr 4 entry)))))
8175 (cond
8176 ((fboundp fun)
8177 (apply fun args))
8178 ((and (boundp fun)
8179 (fboundp (symbol-value fun)))
8180 (apply (symbol-value fun) args))
8182 (gnus-message 1 "You must define `%S' to use this button"
8183 (cons fun args)))))))))
8185 (defun gnus-parse-news-url (url)
8186 (let (scheme server port group message-id articles)
8187 (with-temp-buffer
8188 (insert url)
8189 (goto-char (point-min))
8190 (when (looking-at "\\([A-Za-z]+\\):")
8191 (setq scheme (match-string 1))
8192 (goto-char (match-end 0)))
8193 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8194 (setq server (match-string 1))
8195 (setq port (if (stringp (match-string 3))
8196 (string-to-number (match-string 3))
8197 (match-string 3)))
8198 (goto-char (match-end 0)))
8200 (cond
8201 ((looking-at "\\(.*@.*\\)")
8202 (setq message-id (match-string 1)))
8203 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8204 (setq group (match-string 1)
8205 articles (split-string (match-string 2) "-")))
8206 ((looking-at "\\([^/]+\\)/?")
8207 (setq group (match-string 1)))
8209 (error "Unknown news URL syntax"))))
8210 (list scheme server port group message-id articles)))
8212 (defvar nntp-port-number)
8214 (defun gnus-button-handle-news (url)
8215 "Fetch a news URL."
8216 (destructuring-bind (_scheme server port group message-id _articles)
8217 (gnus-parse-news-url url)
8218 (cond
8219 (message-id
8220 (with-current-buffer gnus-summary-buffer
8221 (if server
8222 (let ((gnus-refer-article-method
8223 (nconc (list (list 'nntp server))
8224 gnus-refer-article-method))
8225 (nntp-port-number (or port "nntp")))
8226 (gnus-message 7 "Fetching %s with %s"
8227 message-id gnus-refer-article-method)
8228 (gnus-summary-refer-article message-id))
8229 (gnus-summary-refer-article message-id))))
8230 (group
8231 (gnus-button-fetch-group url)))))
8233 (defun gnus-button-patch (library line)
8234 "Visit an Emacs Lisp library LIBRARY on line LINE."
8235 (interactive)
8236 (let ((file (locate-library (file-name-nondirectory library))))
8237 (unless file
8238 (error "Couldn't find library %s" library))
8239 (find-file file)
8240 (goto-char (point-min))
8241 (forward-line (1- (string-to-number line)))))
8243 (defun gnus-button-handle-man (url)
8244 "Fetch a man page."
8245 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8246 (when (eq gnus-button-man-handler 'woman)
8247 (setq url (replace-regexp-in-string "([1-9][X1a-z]*).*\\'" "" url)))
8248 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8249 (funcall gnus-button-man-handler url))
8251 (defun gnus-button-handle-info-url (url)
8252 "Fetch an info URL."
8253 (setq url (subst-char-in-string ?+ ?\ url))
8254 (cond
8255 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8256 (gnus-info-find-node
8257 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8258 "Gnus")
8259 ")" (gnus-url-unhex-string (match-string 2 url)))))
8260 ((string-match "([^)\"]+)[^\"]+" url)
8261 (setq url
8262 (replace-regexp-in-string
8263 "\"" "" (replace-regexp-in-string "[\n\t ]+" " " url)))
8264 (gnus-info-find-node url))
8265 (t (error "Can't parse %s" url))))
8267 (defun gnus-button-handle-info-url-gnome (url)
8268 "Fetch GNOME style info URL."
8269 (setq url (subst-char-in-string ?_ ?\ url))
8270 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8271 (gnus-info-find-node
8272 (concat "("
8273 (gnus-url-unhex-string
8274 (match-string 1 url))
8276 (or (gnus-url-unhex-string
8277 (match-string 2 url))
8278 "Top")))
8279 (error "Can't parse %s" url)))
8281 (defun gnus-button-handle-info-url-kde (url)
8282 "Fetch KDE style info URL."
8283 (gnus-info-find-node (gnus-url-unhex-string url)))
8285 ;; (info) will autoload info.el
8286 (declare-function Info-menu "info" (menu-item &optional fork))
8287 (declare-function Info-index-next "info" (num))
8289 (defun gnus-button-handle-info-keystrokes (url)
8290 "Call `info' when pushing the corresponding URL button."
8291 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8292 (let (node indx comma)
8293 (if (string-match
8294 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8295 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8296 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8297 "\\(?:[ \t\n,]*\\)\\)?")
8298 url)
8299 (setq node (match-string 2 url)
8300 indx (match-string 3 url))
8301 (error "Can't parse %s" url))
8302 (info)
8303 (Info-directory)
8304 (Info-menu node)
8305 (when (> (length indx) 0)
8306 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8307 "\\([ \t\n,]*\\)")
8308 indx)
8309 (setq comma (match-string 2 indx))
8310 (setq indx (match-string 1 indx))
8311 (Info-index indx)
8312 (when comma
8313 (dotimes (i (with-temp-buffer
8314 (insert comma)
8315 ;; Note: the XEmacs version of `how-many' takes
8316 ;; no optional argument.
8317 (goto-char (point-min))
8318 (how-many ",")))
8319 (Info-index-next 1)))
8320 nil)))
8322 (autoload 'pgg-snarf-keys-region "pgg")
8323 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8324 (declare-function pgg-display-output-buffer "pgg" (start end status))
8326 (defun gnus-button-openpgp (url)
8327 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8328 (with-temp-buffer
8329 (mm-url-insert-file-contents-external url)
8330 (pgg-snarf-keys-region (point-min) (point-max))
8331 (pgg-display-output-buffer nil nil nil)))
8333 (defun gnus-button-message-id (message-id)
8334 "Fetch MESSAGE-ID."
8335 (with-current-buffer gnus-summary-buffer
8336 (gnus-summary-refer-article message-id)))
8338 (defun gnus-button-fetch-group (address &rest _ignore)
8339 "Fetch GROUP specified by ADDRESS."
8340 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8341 address)
8342 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8343 ;; for nntp:// and news://
8344 (setq address (match-string 3 address)))
8345 (if (not (string-match "[:/]" address))
8346 ;; This is just a simple group url.
8347 (gnus-group-read-ephemeral-group address gnus-select-method)
8348 (if (not
8349 (string-match
8350 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8351 address))
8352 (error "Can't parse %s" address)
8353 (gnus-group-read-ephemeral-group
8354 (match-string 4 address)
8355 `(nntp ,(match-string 1 address)
8356 (nntp-address ,(match-string 1 address))
8357 (nntp-port-number ,(if (match-end 3)
8358 (match-string 3 address)
8359 "nntp")))
8360 nil nil nil
8361 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8363 (defun gnus-url-parse-query-string (query &optional downcase)
8364 (let (retval pairs cur key val)
8365 (setq pairs (split-string query "&"))
8366 (while pairs
8367 (setq cur (car pairs)
8368 pairs (cdr pairs))
8369 (if (not (string-match "=" cur))
8370 nil ; Grace
8371 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8372 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8373 (if downcase
8374 (setq key (downcase key)))
8375 (setq cur (assoc key retval))
8376 (if cur
8377 (setcdr cur (cons val (cdr cur)))
8378 (setq retval (cons (list key val) retval)))))
8379 retval))
8381 (defun gnus-url-mailto (url)
8382 ;; Send mail to someone
8383 (setq url (replace-regexp-in-string "\n" " " url))
8384 (when (string-match "mailto:/*\\(.*\\)" url)
8385 (setq url (substring url (match-beginning 1) nil)))
8386 (let* ((args (gnus-url-parse-query-string
8387 (if (string-match "^\\?" url)
8388 (substring url 1)
8389 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8390 (concat "to=" (match-string 1 url) "&"
8391 (match-string 2 url))
8392 (concat "to=" url)))))
8393 (subject (cdr-safe (assoc "subject" args)))
8394 func)
8395 (gnus-msg-mail)
8396 (while args
8397 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8398 (if (fboundp func)
8399 (funcall func)
8400 (message-position-on-field (caar args)))
8401 (insert (replace-regexp-in-string
8402 "\r\n" "\n"
8403 (mapconcat 'identity (reverse (cdar args)) ", ") nil t))
8404 (setq args (cdr args)))
8405 (if subject
8406 (message-goto-body)
8407 (message-goto-subject))))
8409 (defun gnus-button-embedded-url (address)
8410 "Activate ADDRESS with `browse-url'."
8411 (browse-url (gnus-strip-whitespace address)))
8413 ;;; Next/prev buttons in the article buffer.
8415 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8416 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8418 (defvar gnus-prev-page-map
8419 (let ((map (make-sparse-keymap)))
8420 (define-key map [mouse-2] 'gnus-button-prev-page)
8421 (define-key map "\r" 'gnus-button-prev-page)
8422 map))
8424 (defvar gnus-next-page-map
8425 (let ((map (make-sparse-keymap)))
8426 (define-key map [mouse-2] 'gnus-button-next-page)
8427 (define-key map "\r" 'gnus-button-next-page)
8428 map))
8430 (defun gnus-insert-prev-page-button ()
8431 (let ((b (point)) e
8432 (inhibit-read-only t))
8433 (gnus-eval-format
8434 gnus-prev-page-line-format nil
8435 `(keymap ,gnus-prev-page-map
8436 gnus-prev t
8437 gnus-callback gnus-article-button-prev-page
8438 article-type annotation))
8439 (setq e (if (bolp)
8440 ;; Exclude a newline.
8441 (1- (point))
8442 (point)))
8443 (when gnus-article-button-face
8444 (overlay-put (make-overlay b e nil t)
8445 'face gnus-article-button-face))
8446 (widget-convert-button
8447 'link b e
8448 :action 'gnus-button-prev-page
8449 :button-keymap gnus-prev-page-map)))
8451 (defun gnus-button-next-page (&optional _args _more-args)
8452 "Go to the next page."
8453 (interactive)
8454 (let ((win (selected-window)))
8455 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8456 (gnus-article-next-page)
8457 (select-window win)))
8459 (defun gnus-button-prev-page (&optional _args _more-args)
8460 "Go to the prev page."
8461 (interactive)
8462 (let ((win (selected-window)))
8463 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8464 (gnus-article-prev-page)
8465 (select-window win)))
8467 (defun gnus-insert-next-page-button ()
8468 (let ((b (point)) e
8469 (inhibit-read-only t))
8470 (gnus-eval-format gnus-next-page-line-format nil
8471 `(keymap ,gnus-next-page-map
8472 gnus-next t
8473 gnus-callback gnus-article-button-next-page
8474 article-type annotation))
8475 (setq e (if (bolp)
8476 ;; Exclude a newline.
8477 (1- (point))
8478 (point)))
8479 (when gnus-article-button-face
8480 (overlay-put (make-overlay b e nil t)
8481 'face gnus-article-button-face))
8482 (widget-convert-button
8483 'link b e
8484 :action 'gnus-button-next-page
8485 :button-keymap gnus-next-page-map)))
8487 (defun gnus-article-button-next-page (_arg)
8488 "Go to the next page."
8489 (interactive "P")
8490 (let ((win (selected-window)))
8491 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8492 (gnus-article-next-page)
8493 (select-window win)))
8495 (defun gnus-article-button-prev-page (_arg)
8496 "Go to the prev page."
8497 (interactive "P")
8498 (let ((win (selected-window)))
8499 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8500 (gnus-article-prev-page)
8501 (select-window win)))
8503 (defvar gnus-decode-header-methods
8504 '(mail-decode-encoded-word-region)
8505 "List of methods used to decode headers.
8507 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8508 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8509 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8510 whose names match REGEXP.
8512 For example:
8513 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8514 mail-decode-encoded-word-region
8515 (\"chinese\" . rfc1843-decode-region))
8518 (defvar gnus-decode-header-methods-cache nil)
8520 (defun gnus-multi-decode-header (start end)
8521 "Apply the functions from `gnus-encoded-word-methods' that match."
8522 (unless (and gnus-decode-header-methods-cache
8523 (eq gnus-newsgroup-name
8524 (car gnus-decode-header-methods-cache)))
8525 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8526 (dolist (x gnus-decode-header-methods)
8527 (if (symbolp x)
8528 (nconc gnus-decode-header-methods-cache (list x))
8529 (if (and gnus-newsgroup-name
8530 (string-match (car x) gnus-newsgroup-name))
8531 (nconc gnus-decode-header-methods-cache
8532 (list (cdr x)))))))
8533 (let ((xlist gnus-decode-header-methods-cache))
8534 (pop xlist)
8535 (save-restriction
8536 (narrow-to-region start end)
8537 (while xlist
8538 (funcall (pop xlist) (point-min) (point-max))))))
8541 ;;; Treatment top-level handling.
8544 (defvar gnus-inhibit-article-treatments nil)
8546 ;; Dynamic variables.
8547 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8548 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8549 (defvar gnus-treat-type)
8550 (defvar gnus-treat-condition)
8551 (defvar gnus-treat-length)
8553 (defun gnus-treat-article (condition
8554 &optional part-num total type)
8555 (let ((gnus-treat-condition condition)
8556 (part-number part-num)
8557 (total-parts total)
8558 (gnus-treat-type type)
8559 (gnus-treat-length (- (point-max) (point-min)))
8560 (alist gnus-treatment-function-alist)
8561 (article-goto-body-goes-to-point-min-p t)
8562 (treated-type
8563 (or (not type)
8564 (catch 'found
8565 (let ((list gnus-article-treat-types))
8566 (while list
8567 (when (string-match (pop list) type)
8568 (throw 'found t)))))))
8569 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8570 val)
8571 (gnus-run-hooks 'gnus-part-display-hook)
8572 (dolist (elem alist)
8573 (setq val
8574 (save-excursion
8575 (when (gnus-buffer-live-p gnus-summary-buffer)
8576 (set-buffer gnus-summary-buffer))
8577 (symbol-value (car elem))))
8578 (when (and (or (consp val)
8579 treated-type)
8580 (or (not gnus-inhibit-article-treatments)
8581 (eq gnus-treat-condition 'head))
8582 (gnus-treat-predicate val)
8583 (or (not (get (car elem) 'highlight))
8584 highlightp))
8585 (save-restriction
8586 (funcall (cadr elem)))))))
8588 (defun gnus-treat-predicate (val)
8589 (cond
8590 ((null val)
8591 nil)
8592 (gnus-treat-condition
8593 (eq gnus-treat-condition val))
8594 ((and (listp val)
8595 (stringp (car val)))
8596 (apply 'gnus-or (mapcar `(lambda (s)
8597 (string-match s ,(or gnus-newsgroup-name "")))
8598 val)))
8599 ((listp val)
8600 (let ((pred (pop val)))
8601 (cond
8602 ((eq pred 'or)
8603 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8604 ((eq pred 'and)
8605 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8606 ((eq pred 'not)
8607 (not (gnus-treat-predicate (car val))))
8608 ((eq pred 'typep)
8609 (equal (car val) gnus-treat-type))
8610 ((functionp pred)
8611 (funcall pred))
8613 (error "%S is not a valid predicate" pred)))))
8614 ((eq val t)
8616 ((eq val 'head)
8617 nil)
8618 ((eq val 'first)
8619 (eq part-number 1))
8620 ((eq val 'last)
8621 (eq part-number total-parts))
8622 ((numberp val)
8623 (< gnus-treat-length val))
8625 (error "%S is not a valid value" val))))
8627 (defun gnus-article-encrypt-body (protocol &optional n)
8628 "Encrypt the article body."
8629 (interactive
8630 (list
8631 (or gnus-article-encrypt-protocol
8632 (gnus-completing-read "Encrypt protocol"
8633 (mapcar 'car gnus-article-encrypt-protocol-alist)
8635 current-prefix-arg))
8636 ;; User might hit `K E' instead of `K e', so prompt once.
8637 (when (and gnus-article-encrypt-protocol
8638 gnus-novice-user)
8639 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8640 (error "Encrypt aborted")))
8641 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8642 (unless func
8643 (error "Can't find the encrypt protocol %s" protocol))
8644 (if (member gnus-newsgroup-name '("nndraft:delayed"
8645 "nndraft:drafts"
8646 "nndraft:queue"))
8647 (error "Can't encrypt the article in group %s"
8648 gnus-newsgroup-name))
8649 (gnus-summary-iterate n
8650 (with-current-buffer gnus-summary-buffer
8651 (let ((mail-parse-charset gnus-newsgroup-charset)
8652 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8653 (summary-buffer gnus-summary-buffer)
8654 references point)
8655 (gnus-set-global-variables)
8656 (when (gnus-group-read-only-p)
8657 (error "The current newsgroup does not support article encrypt"))
8658 (gnus-summary-show-article t)
8659 (setq references
8660 (or (mail-header-references gnus-current-headers) ""))
8661 (set-buffer gnus-article-buffer)
8662 (let* ((inhibit-read-only t)
8663 (headers
8664 (mapcar (lambda (field)
8665 (and (save-restriction
8666 (message-narrow-to-head)
8667 (goto-char (point-min))
8668 (search-forward field nil t))
8669 (prog2
8670 (message-narrow-to-field)
8671 (buffer-string)
8672 (delete-region (point-min) (point-max))
8673 (widen))))
8674 '("Content-Type:" "Content-Transfer-Encoding:"
8675 "Content-Disposition:"))))
8676 (message-narrow-to-head)
8677 (message-remove-header "MIME-Version")
8678 (goto-char (point-max))
8679 (setq point (point))
8680 (insert (apply 'concat headers))
8681 (widen)
8682 (narrow-to-region point (point-max))
8683 (let ((message-options message-options))
8684 (message-options-set 'message-sender user-mail-address)
8685 (message-options-set 'message-recipients user-mail-address)
8686 (message-options-set 'message-sign-encrypt 'not)
8687 (funcall func))
8688 (goto-char (point-min))
8689 (insert "MIME-Version: 1.0\n")
8690 (widen)
8691 (gnus-summary-edit-article-done
8692 references nil summary-buffer t))
8693 (when gnus-keep-backlog
8694 (gnus-backlog-remove-article
8695 (car gnus-article-current) (cdr gnus-article-current)))
8696 (gnus-flush-original-article-buffer)
8697 (when gnus-use-cache
8698 (gnus-cache-update-article
8699 (car gnus-article-current) (cdr gnus-article-current))))))))
8701 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8702 "The following specs can be used:
8703 %t The security MIME type
8704 %i Additional info
8705 %d Details
8706 %D Details if button is pressed")
8708 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8709 "The following specs can be used:
8710 %t The security MIME type
8711 %i Additional info
8712 %d Details
8713 %D Details if button is pressed")
8715 (defvar gnus-mime-security-button-line-format-alist
8716 '((?t gnus-tmp-type ?s)
8717 (?i gnus-tmp-info ?s)
8718 (?d gnus-tmp-details ?s)
8719 (?D gnus-tmp-pressed-details ?s)))
8721 (defvar gnus-mime-security-button-commands
8722 '((gnus-article-press-button "\r" "Show Detail")
8723 (undefined "v")
8724 (undefined "t")
8725 (undefined "C")
8726 (gnus-mime-security-save-part "o" "Save...")
8727 (undefined "\C-o")
8728 (undefined "r")
8729 (undefined "d")
8730 (undefined "c")
8731 (undefined "i")
8732 (undefined "E")
8733 (undefined "e")
8734 (undefined "p")
8735 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8736 (undefined ".")))
8738 (defvar gnus-mime-security-button-map
8739 (let ((map (make-sparse-keymap)))
8740 (define-key map [mouse-2] 'gnus-article-push-button)
8741 (define-key map [down-mouse-3] 'gnus-mime-security-button-menu)
8742 (dolist (c gnus-mime-security-button-commands)
8743 (define-key map (cadr c) (car c)))
8744 map))
8746 (easy-menu-define
8747 gnus-mime-security-button-menu gnus-mime-security-button-map
8748 "Security button menu."
8749 `("Security Part"
8750 ,@(delq nil
8751 (mapcar (lambda (c)
8752 (unless (eq (car c) 'undefined)
8753 (vector (caddr c) (car c) :active t)))
8754 gnus-mime-security-button-commands))))
8756 (defun gnus-mime-security-button-menu (event prefix)
8757 "Construct a context-sensitive menu of security commands."
8758 (interactive "e\nP")
8759 (save-window-excursion
8760 (let ((pos (event-start event)))
8761 (select-window (posn-window pos))
8762 (goto-char (posn-point pos))
8763 (gnus-article-check-buffer)
8764 (popup-menu gnus-mime-security-button-menu nil prefix))))
8766 (defvar gnus-mime-security-details-buffer nil)
8768 (defvar gnus-mime-security-button-pressed nil)
8770 (defvar gnus-mime-security-show-details-inline t
8771 "If non-nil, show details in the article buffer.")
8773 (defun gnus-mime-security-verify-or-decrypt (handle)
8774 (mm-remove-parts (cdr handle))
8775 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8776 point (inhibit-read-only t))
8777 (if region
8778 (goto-char (car region)))
8779 (setq point (point))
8780 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8781 (let* ((mm-verify-option 'known)
8782 (mm-decrypt-option 'known)
8783 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8784 (unless (eq nparts (cdr handle))
8785 (mm-destroy-parts (cdr handle))
8786 (setcdr handle nparts))))
8787 (gnus-mime-display-security handle)
8788 (when region
8789 (delete-region (point) (cdr region))
8790 (set-marker (car region) nil)
8791 (set-marker (cdr region) nil))
8792 (goto-char point)))
8794 (defun gnus-mime-security-show-details (handle)
8795 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8796 (if (not details)
8797 (gnus-message 5 "No details.")
8798 (if gnus-mime-security-show-details-inline
8799 (let ((gnus-mime-security-button-pressed
8800 (not (get-text-property (point) 'gnus-mime-details)))
8801 (gnus-mime-security-button-line-format
8802 (get-text-property (point) 'gnus-line-format))
8803 (inhibit-read-only t))
8804 (forward-char -1)
8805 (while (eq (get-text-property (point) 'gnus-line-format)
8806 gnus-mime-security-button-line-format)
8807 (forward-char -1))
8808 (forward-char)
8809 (save-restriction
8810 (narrow-to-region (point) (point))
8811 (gnus-insert-mime-security-button handle))
8812 (delete-region (point)
8813 (or (text-property-not-all
8814 (point) (point-max)
8815 'gnus-line-format
8816 gnus-mime-security-button-line-format)
8817 (point-max))))
8818 ;; Not inlined.
8819 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8820 (with-current-buffer gnus-mime-security-details-buffer
8821 (erase-buffer)
8823 (setq gnus-mime-security-details-buffer
8824 (gnus-get-buffer-create "*MIME Security Details*")))
8825 (with-current-buffer gnus-mime-security-details-buffer
8826 (insert details)
8827 (goto-char (point-min)))
8828 (pop-to-buffer gnus-mime-security-details-buffer)))))
8830 (defun gnus-mime-security-press-button (handle)
8831 (save-excursion
8832 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8833 (gnus-mime-security-show-details handle)
8834 (gnus-mime-security-verify-or-decrypt handle))))
8836 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8837 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8838 (gnus-tmp-type
8839 (concat
8840 (or (nth 2 (assoc protocol mm-verify-function-alist))
8841 (nth 2 (assoc protocol mm-decrypt-function-alist))
8842 "Unknown")
8843 (if (equal (car handle) "multipart/signed")
8844 " Signed" " Encrypted")
8845 " Part"))
8846 (gnus-tmp-info
8847 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8848 "Undecided"))
8849 (gnus-tmp-details
8850 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8851 gnus-tmp-pressed-details
8852 b e)
8853 (setq gnus-tmp-details
8854 (if gnus-tmp-details
8855 (concat "\n" gnus-tmp-details)
8856 ""))
8857 (setq gnus-tmp-pressed-details
8858 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8859 (unless (bolp)
8860 (insert "\n"))
8861 (setq b (point))
8862 (gnus-eval-format
8863 gnus-mime-security-button-line-format
8864 gnus-mime-security-button-line-format-alist
8865 `(keymap ,gnus-mime-security-button-map
8866 gnus-callback gnus-mime-security-press-button
8867 gnus-line-format ,gnus-mime-security-button-line-format
8868 gnus-mime-details ,gnus-mime-security-button-pressed
8869 article-type annotation
8870 gnus-data ,handle))
8871 (setq e (if (bolp)
8872 ;; Exclude a newline.
8873 (1- (point))
8874 (point)))
8875 (when gnus-article-button-face
8876 (overlay-put (make-overlay b e nil t)
8877 'face gnus-article-button-face))
8878 (widget-convert-button
8879 'link b e
8880 :mime-handle handle
8881 :action 'gnus-widget-press-button
8882 :button-keymap gnus-mime-security-button-map
8883 :help-echo
8884 (lambda (_widget)
8885 (format
8886 "%S: show detail; %S: more options"
8887 'mouse-2
8888 'down-mouse-3)))))
8890 (defun gnus-mime-display-security (handle)
8891 (save-restriction
8892 (narrow-to-region (point) (point))
8893 (unless (gnus-unbuttonized-mime-type-p (car handle))
8894 (gnus-insert-mime-security-button handle))
8895 (gnus-mime-display-part (cadr handle))
8896 (unless (bolp)
8897 (insert "\n"))
8898 (unless (gnus-unbuttonized-mime-type-p (car handle))
8899 (let ((gnus-mime-security-button-line-format
8900 gnus-mime-security-button-end-line-format))
8901 (gnus-insert-mime-security-button handle)))
8902 (mm-set-handle-multipart-parameter
8903 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8904 (goto-char (point-max))))
8906 (defun gnus-mime-security-run-function (function)
8907 "Run FUNCTION with the security part under point."
8908 (gnus-article-check-buffer)
8909 (let ((data (get-text-property (point) 'gnus-data))
8910 buffer handle)
8911 (when (and (stringp (car-safe data))
8912 (setq buffer (mm-handle-multipart-original-buffer data))
8913 (setq handle (cadr data)))
8914 (if (bufferp (mm-handle-buffer handle))
8915 (progn
8916 (setq handle (cons buffer (copy-sequence (cdr handle))))
8917 (mm-handle-set-undisplayer handle nil))
8918 (setq handle (mm-make-handle
8919 buffer
8920 (mm-handle-multipart-ctl-parameter handle 'protocol)
8921 nil nil nil nil nil nil)))
8922 (funcall function handle))))
8924 (defun gnus-mime-security-save-part ()
8925 "Save the security part under point."
8926 (interactive)
8927 (gnus-mime-security-run-function 'mm-save-part))
8929 (defun gnus-mime-security-pipe-part ()
8930 "Pipe the security part under point to a process."
8931 (interactive)
8932 (gnus-mime-security-run-function 'mm-pipe-part))
8934 (provide 'gnus-art)
8936 (run-hooks 'gnus-art-load-hook)
8938 ;;; gnus-art.el ends here