Output alists with dotted pair notation in .dir-locals.el
[emacs.git] / lisp / gnus / gnus-art.el
blob1b0dde94551a45e54f7992675b24da954c5c059e
1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2018 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 <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile (require 'cl-lib))
28 (defvar tool-bar-map)
29 (defvar w3m-minor-mode-map)
31 (require 'gnus)
32 (require 'gnus-sum)
33 (require 'gnus-spec)
34 (require 'gnus-int)
35 (require 'gnus-win)
36 (require 'mm-bodies)
37 (require 'mail-parse)
38 (require 'mm-decode)
39 (require 'mm-view)
40 (require 'wid-edit)
41 (require 'mm-uu)
42 (require 'message)
43 (require 'mouse)
45 (autoload 'gnus-msg-mail "gnus-msg" nil t)
46 (autoload 'gnus-button-mailto "gnus-msg")
47 (autoload 'gnus-button-reply "gnus-msg" nil t)
48 (autoload 'parse-time-string "parse-time" nil nil)
49 (autoload 'ansi-color-apply-on-region "ansi-color")
50 (autoload 'mm-url-insert-file-contents-external "mm-url")
51 (autoload 'mm-extern-cache-contents "mm-extern")
52 (autoload 'url-expand-file-name "url-expand")
54 (defgroup gnus-article nil
55 "Article display."
56 :link '(custom-manual "(gnus)Article Buffer")
57 :group 'gnus)
59 (defgroup gnus-article-treat nil
60 "Treating article parts."
61 :link '(custom-manual "(gnus)Article Hiding")
62 :group 'gnus-article)
64 (defgroup gnus-article-hiding nil
65 "Hiding article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
67 :group 'gnus-article)
69 (defgroup gnus-article-highlight nil
70 "Article highlighting."
71 :link '(custom-manual "(gnus)Article Highlighting")
72 :group 'gnus-article
73 :group 'gnus-visual)
75 (defgroup gnus-article-signature nil
76 "Article signatures."
77 :link '(custom-manual "(gnus)Article Signature")
78 :group 'gnus-article)
80 (defgroup gnus-article-headers nil
81 "Article headers."
82 :link '(custom-manual "(gnus)Hiding Headers")
83 :group 'gnus-article)
85 (defgroup gnus-article-washing nil
86 "Special commands on articles."
87 :link '(custom-manual "(gnus)Article Washing")
88 :group 'gnus-article)
90 (defgroup gnus-article-emphasis nil
91 "Fontisizing articles."
92 :link '(custom-manual "(gnus)Article Fontisizing")
93 :group 'gnus-article)
95 (defgroup gnus-article-saving nil
96 "Saving articles."
97 :link '(custom-manual "(gnus)Saving Articles")
98 :group 'gnus-article)
100 (defgroup gnus-article-mime nil
101 "Worshiping the MIME wonder."
102 :link '(custom-manual "(gnus)Using MIME")
103 :group 'gnus-article)
105 (defgroup gnus-article-buttons nil
106 "Pushable buttons in the article buffer."
107 :link '(custom-manual "(gnus)Article Buttons")
108 :group 'gnus-article)
110 (defgroup gnus-article-various nil
111 "Other article options."
112 :link '(custom-manual "(gnus)Misc Article")
113 :group 'gnus-article)
115 (defcustom gnus-ignored-headers
116 (mapcar
117 (lambda (header)
118 (concat "^" header ":"))
119 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
120 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
121 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
122 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
123 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
124 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
125 "X-Attribution" "X-Originating-IP" "Delivered-To"
126 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
127 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
128 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
129 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
130 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
131 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
132 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
133 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
134 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
135 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
136 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
137 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
138 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
139 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
140 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
141 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
142 "List-[A-Za-z]+" "X-Listprocessor-Version"
143 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
144 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
145 "X-Received" "Content-length" "X-precedence"
146 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
147 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
148 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
149 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
150 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
151 "X-Content-length" "X-Posting-Agent" "Original-Received"
152 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
153 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
154 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
155 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
156 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
157 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
158 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
159 "Envelope-Sender" "Envelope-Recipients"))
160 "All headers that start with this regexp will be hidden.
161 This variable can also be a list of regexps of headers to be ignored.
162 If `gnus-visible-headers' is non-nil, this variable will be ignored."
163 :type '(choice regexp
164 (repeat regexp))
165 :group 'gnus-article-hiding)
167 (defcustom gnus-visible-headers
168 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
169 "All headers that do not match this regexp will be hidden.
170 This variable can also be a list of regexp of headers to remain visible.
171 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
172 :type '(choice
173 (repeat :value-to-internal (lambda (widget value)
174 (custom-split-regexp-maybe value))
175 :match (lambda (widget value)
176 (or (stringp value)
177 (widget-editable-list-match widget value)))
178 regexp)
179 (const :tag "Use gnus-ignored-headers" nil)
180 regexp)
181 :group 'gnus-article-hiding)
183 (defcustom gnus-sorted-header-list
184 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
185 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
186 "This variable is a list of regular expressions.
187 If it is non-nil, headers that match the regular expressions will
188 be placed first in the article buffer in the sequence specified by
189 this list."
190 :type '(repeat regexp)
191 :group 'gnus-article-hiding)
193 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
194 "Headers that are only to be displayed if they have interesting data.
195 Possible values in this list are:
197 `empty' Headers with no content.
198 `newsgroups' Newsgroup identical to Gnus group.
199 `to-address' To identical to To-address.
200 `to-list' To identical to To-list.
201 `cc-list' Cc identical to To-list.
202 `followup-to' Followup-To identical to Newsgroups.
203 `reply-to' Reply-To identical to From.
204 `date' Date less than four days old.
205 `long-to' To and/or Cc longer than 1024 characters.
206 `many-to' Multiple To and/or Cc."
207 :type '(set (const :tag "Headers with no content." empty)
208 (const :tag "Newsgroups identical to Gnus group." newsgroups)
209 (const :tag "To identical to To-address." to-address)
210 (const :tag "To identical to To-list." to-list)
211 (const :tag "Cc identical to To-list." cc-list)
212 (const :tag "Followup-To identical to Newsgroups." followup-to)
213 (const :tag "Reply-To identical to From." reply-to)
214 (const :tag "Date less than four days old." date)
215 (const :tag "To and/or Cc longer than 1024 characters." long-to)
216 (const :tag "Multiple To and/or Cc headers." many-to))
217 :group 'gnus-article-hiding)
219 (defcustom gnus-article-skip-boring nil
220 "Skip over text that is not worth reading.
221 By default, if you set this t, then Gnus will display citations and
222 signatures, but will never scroll down to show you a page consisting
223 only of boring text. Boring text is controlled by
224 `gnus-article-boring-faces'."
225 :version "22.1"
226 :type 'boolean
227 :group 'gnus-article-hiding)
229 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
230 "Regexp matching signature separator.
231 This can also be a list of regexps. In that case, it will be checked
232 from head to tail looking for a separator. Searches will be done from
233 the end of the buffer."
234 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
235 (regexp)
236 (repeat :tag "List of regexp" regexp))
237 :group 'gnus-article-signature)
239 (defcustom gnus-signature-limit nil
240 "Provide a limit to what is considered a signature.
241 If it is a number, no signature may not be longer (in characters) than
242 that number. If it is a floating point number, no signature may be
243 longer (in lines) than that number. If it is a function, the function
244 will be called without any parameters, and if it returns nil, there is
245 no signature in the buffer. If it is a string, it will be used as a
246 regexp. If it matches, the text in question is not a signature.
248 This can also be a list of the above values."
249 :type '(choice (const nil)
250 (integer :value 200)
251 (number :value 4.0)
252 function
253 (regexp :value ".*")
254 (repeat (choice (const nil)
255 (integer :value 200)
256 (number :value 4.0)
257 function
258 (regexp :value ".*"))))
259 :group 'gnus-article-signature)
261 (defcustom gnus-hidden-properties
262 ;; We use to have `intangible' here as well, but Emacs's command loop moves
263 ;; point out of invisible text anyway, so `intangible' is clearly not
264 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
265 '(invisible t)
266 "Property list to use for hiding text."
267 :type 'plist
268 :group 'gnus-article-hiding)
270 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
271 ;; frames in a session.
272 (defcustom gnus-article-x-face-command
273 (if (gnus-image-type-available-p 'pbm)
274 'gnus-display-x-face-in-from
275 "{ echo \
276 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
277 ; uncompface; } | icontopbm | display -")
278 "String or function to be executed to display an X-Face header.
279 If it is a string, the command will be executed in a sub-shell
280 asynchronously. The compressed face will be piped to this command."
281 :type `(choice string
282 (function-item gnus-display-x-face-in-from)
283 function)
284 :version "21.1"
285 :group 'gnus-picon
286 :group 'gnus-article-washing)
288 (defcustom gnus-article-x-face-too-ugly nil
289 "Regexp matching posters whose face shouldn't be shown automatically."
290 :type '(choice regexp (const nil))
291 :group 'gnus-article-washing)
293 (defcustom gnus-article-banner-alist nil
294 "Banner alist for stripping.
295 For example,
296 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
297 :version "21.1"
298 :type '(repeat (cons symbol regexp))
299 :group 'gnus-article-washing)
301 (gnus-define-group-parameter
302 banner
303 :variable-document
304 "Alist of regexps (to match group names) and banner."
305 :variable-group gnus-article-washing
306 :parameter-type
307 '(choice :tag "Banner"
308 :value nil
309 (const :tag "Remove signature" signature)
310 (symbol :tag "Item in `gnus-article-banner-alist'" none)
311 regexp
312 (const :tag "None" nil))
313 :parameter-document
314 "If non-nil, specify how to remove `banners' from articles.
316 Symbol `signature' means to remove signatures delimited by
317 `gnus-signature-separator'. Any other symbol is used to look up a
318 regular expression to match the banner in `gnus-article-banner-alist'.
319 A string is used as a regular expression to match the banner
320 directly.")
322 (defcustom gnus-article-address-banner-alist nil
323 "Alist of mail addresses and banners.
324 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
325 to match a mail address in the From: header, BANNER is one of a symbol
326 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
327 If ADDRESS matches author's mail address, it will remove things like
328 advertisements. For example:
330 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
332 :type '(repeat
333 (cons
334 (regexp :tag "Address")
335 (choice :tag "Banner" :value nil
336 (const :tag "Remove signature" signature)
337 (symbol :tag "Item in `gnus-article-banner-alist'" none)
338 regexp
339 (const :tag "None" nil))))
340 :version "22.1"
341 :group 'gnus-article-washing)
343 (defmacro gnus-emphasis-custom-with-format (&rest body)
344 `(let ((format "\
345 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
346 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
347 ,@body))
349 (defun gnus-emphasis-custom-value-to-external (value)
350 (gnus-emphasis-custom-with-format
351 (if (consp (car value))
352 (list (format format (car (car value)) (cdr (car value)))
354 (if (nth 1 value) 2 3)
355 (nth 2 value))
356 value)))
358 (defun gnus-emphasis-custom-value-to-internal (value)
359 (gnus-emphasis-custom-with-format
360 (let ((regexp (concat "\\`"
361 (format (regexp-quote format)
362 "\\([^()]+\\)" "\\([^()]+\\)")
363 "\\'"))
364 pattern)
365 (if (string-match regexp (setq pattern (car value)))
366 (list (cons (match-string 1 pattern) (match-string 2 pattern))
367 (= (nth 2 value) 2)
368 (nth 3 value))
369 value))))
371 (defcustom gnus-emphasis-alist
372 (let ((types
373 '(("\\*" "\\*" bold nil 2)
374 ("_" "_" underline)
375 ("/" "/" italic)
376 ("_/" "/_" underline-italic)
377 ("_\\*" "\\*_" underline-bold)
378 ("\\*/" "/\\*" bold-italic)
379 ("_\\*/" "/\\*_" underline-bold-italic))))
380 (nconc
381 (gnus-emphasis-custom-with-format
382 (mapcar (lambda (spec)
383 (list (format format (car spec) (cadr spec))
384 (or (nth 3 spec) 2)
385 (or (nth 4 spec) 3)
386 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
387 types))
388 '(;; I've never seen anyone use this strikethru convention whereas I've
389 ;; several times seen it triggered by normal text. --Stef
390 ;; Miles suggests that this form is sometimes used but for italics,
391 ;; so maybe we should map it to `italic'.
392 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
393 ;; 2 3 gnus-emphasis-strikethru)
394 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
395 2 3 gnus-emphasis-underline))))
396 "Alist that says how to fontify certain phrases.
397 Each item looks like this:
399 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
401 The first element is a regular expression to be matched. The second
402 is a number that says what regular expression grouping used to find
403 the entire emphasized word. The third is a number that says what
404 regexp grouping should be displayed and highlighted. The fourth
405 is the face used for highlighting."
406 :type
407 '(repeat
408 (menu-choice
409 :format "%[Customizing Style%]\n%v"
410 :indent 2
411 (group :tag "Default"
412 :value ("" 0 0 default)
413 :value-create
414 (lambda (widget)
415 (let ((value (widget-get
416 (cadr (widget-get (widget-get widget :parent)
417 :args))
418 :value)))
419 (if (not (eq (nth 2 value) 'default))
420 (widget-put
421 widget
422 :value
423 (gnus-emphasis-custom-value-to-external value))))
424 (widget-group-value-create widget))
425 regexp
426 (integer :format "Match group: %v")
427 (integer :format "Emphasize group: %v")
428 face)
429 (group :tag "Simple"
430 :value (("_" . "_") nil default)
431 (cons :format "%v"
432 (regexp :format "Start regexp: %v")
433 (regexp :format "End regexp: %v"))
434 (boolean :format "Show start and end patterns: %[%v%]\n"
435 :on " On " :off " Off ")
436 face)))
437 :get (lambda (symbol)
438 (mapcar 'gnus-emphasis-custom-value-to-internal
439 (default-value symbol)))
440 :set (lambda (symbol value)
441 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
442 value)))
443 :group 'gnus-article-emphasis)
445 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
446 "A regexp to describe whitespace which should not be emphasized.
447 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
448 The former avoids underlining of leading and trailing whitespace,
449 and the latter avoids underlining any whitespace at all."
450 :version "21.1"
451 :group 'gnus-article-emphasis
452 :type 'regexp)
454 (defface gnus-emphasis-bold '((t (:bold t)))
455 "Face used for displaying strong emphasized text (*word*)."
456 :group 'gnus-article-emphasis)
458 (defface gnus-emphasis-italic '((t (:italic t)))
459 "Face used for displaying italic emphasized text (/word/)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-underline '((t (:underline t)))
463 "Face used for displaying underlined emphasized text (_word_)."
464 :group 'gnus-article-emphasis)
466 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
467 "Face used for displaying underlined bold emphasized text (_*word*_)."
468 :group 'gnus-article-emphasis)
470 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
471 "Face used for displaying underlined italic emphasized text (_/word/_)."
472 :group 'gnus-article-emphasis)
474 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
475 "Face used for displaying bold italic emphasized text (/*word*/)."
476 :group 'gnus-article-emphasis)
478 (defface gnus-emphasis-underline-bold-italic
479 '((t (:bold t :italic t :underline t)))
480 "Face used for displaying underlined bold italic emphasized text.
481 Example: (_/*word*/_)."
482 :group 'gnus-article-emphasis)
484 (defface gnus-emphasis-strikethru '((t (:strike-through t)))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
508 might have."
509 :group 'gnus-article-saving
510 :type 'boolean)
512 (defcustom gnus-prompt-before-saving 'always
513 "This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-article-show-cursor nil
526 "If non-nil, show the cursor in the Article buffer even when not selected."
527 :version "25.1"
528 :group 'gnus-article
529 :type 'boolean)
531 (defcustom gnus-saved-headers gnus-visible-headers
532 "Headers to keep if `gnus-save-all-headers' is nil.
533 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
534 If that variable is nil, however, all headers that match this regexp
535 will be kept while the rest will be deleted before saving. This and
536 `gnus-save-all-headers' will be overridden by the `:headers' property
537 that the symbol of the saver function, which is specified by
538 `gnus-default-article-saver', might have."
539 :group 'gnus-article-saving
540 :type 'regexp)
542 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
543 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
544 "A function to save articles in your favorite format.
545 The function will be called by way of the `gnus-summary-save-article'
546 command, and friends such as `gnus-summary-save-article-rmail'.
548 Gnus provides the following functions:
550 * gnus-summary-save-in-rmail (Rmail format)
551 * gnus-summary-save-in-mail (Unix mail format)
552 * gnus-summary-save-in-folder (MH folder)
553 * gnus-summary-save-in-file (article format)
554 * gnus-summary-save-body-in-file (article body)
555 * gnus-summary-save-in-vm (use VM's folder format)
556 * gnus-summary-write-to-file (article format -- overwrite)
557 * gnus-summary-write-body-to-file (article body -- overwrite)
558 * gnus-summary-save-in-pipe (article format)
560 The symbol of each function may have the following properties:
562 * :decode
563 The value non-nil means save decoded articles. This is meaningful
564 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
565 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
566 `gnus-summary-save-in-pipe'.
568 * :function
569 The value specifies an alternative function which appends, not
570 overwrites, articles to a file. This implies that when saving many
571 articles at a time, `gnus-prompt-before-saving' is bound to t and all
572 articles are saved in a single file. This is meaningful only with
573 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
575 * :headers
576 The value specifies the symbol of a variable of which the value
577 specifies headers to be saved. If it is omitted,
578 `gnus-save-all-headers' and `gnus-saved-headers' control what
579 headers should be saved."
580 :group 'gnus-article-saving
581 :type '(radio (function-item gnus-summary-save-in-rmail)
582 (function-item gnus-summary-save-in-mail)
583 (function-item gnus-summary-save-in-folder)
584 (function-item gnus-summary-save-in-file)
585 (function-item gnus-summary-save-body-in-file)
586 (function-item gnus-summary-save-in-vm)
587 (function-item gnus-summary-write-to-file)
588 (function-item gnus-summary-write-body-to-file)
589 (function-item gnus-summary-save-in-pipe)
590 (function)))
592 (defcustom gnus-article-save-coding-system
593 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
594 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
595 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
596 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
597 "Coding system used to save decoded articles to a file.
599 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
600 which can safely encode any characters in text. This is used by the
601 commands including:
603 * gnus-summary-save-article-file
604 * gnus-summary-save-article-body-file
605 * gnus-summary-write-article-file
606 * gnus-summary-write-article-body-file
608 and the functions to which you may set `gnus-default-article-saver':
610 * gnus-summary-save-in-file
611 * gnus-summary-save-body-in-file
612 * gnus-summary-write-to-file
613 * gnus-summary-write-body-to-file
615 Those commands and functions save just text displayed in the article
616 buffer to a file if the value of this variable is non-nil. Note that
617 buttonized MIME parts will be lost in a saved file in that case.
618 Otherwise, raw articles will be saved."
619 :group 'gnus-article-saving
620 :type `(choice
621 :format "%{%t%}:\n %[Value Menu%] %v"
622 (const :tag "Save raw articles" nil)
623 ,@(delq nil
624 (mapcar
625 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
626 '((const :tag "UTF-8" utf-8)
627 (const :tag "iso-2022-7bit" iso-2022-7bit)
628 (const :tag "Emacs internal" emacs-mule)
629 (const :tag "escape-quoted" escape-quoted))))
630 (symbol :tag "Coding system")))
632 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Rmail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
636 :type 'function)
638 (defcustom gnus-mail-save-name 'gnus-plain-save-name
639 "A function generating a file name to save articles in Unix mail format.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
641 :group 'gnus-article-saving
642 :type 'function)
644 (defcustom gnus-folder-save-name 'gnus-folder-save-name
645 "A function generating a file name to save articles in MH folder.
646 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
647 :group 'gnus-article-saving
648 :type 'function)
650 (defcustom gnus-file-save-name 'gnus-numeric-save-name
651 "A function generating a file name to save articles in article format.
652 The function is called with NEWSGROUP, HEADERS, and optional
653 LAST-FILE."
654 :group 'gnus-article-saving
655 :type 'function)
657 (defcustom gnus-split-methods
658 '((gnus-article-archive-name)
659 (gnus-article-nndoc-name))
660 "Variable used to suggest where articles are to be saved.
661 For instance, if you would like to save articles related to Gnus in
662 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
663 you could set this variable to something like:
665 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
666 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
668 This variable is an alist where the key is the match and the
669 value is a list of possible files to save in if the match is
670 non-nil.
672 If the match is a string, it is used as a regexp match on the
673 article. If the match is a symbol, that symbol will be funcalled
674 from the buffer of the article to be saved with the newsgroup as the
675 parameter. If it is a list, it will be evalled in the same buffer.
677 If this form or function returns a string, this string will be used as a
678 possible file name; and if it returns a non-nil list, that list will be
679 used as possible file names."
680 :group 'gnus-article-saving
681 :type '(repeat (choice (list :value (fun) function)
682 (cons :value ("" "") regexp (repeat string))
683 (sexp :value nil))))
685 (defcustom gnus-page-delimiter "^\^L"
686 "Regexp describing what to use as article page delimiters.
687 The default value is \"^\^L\", which is a form linefeed at the
688 beginning of a line."
689 :type 'regexp
690 :group 'gnus-article-various)
692 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
693 "The format specification for the article mode line.
694 See `gnus-summary-mode-line-format' for a closer description.
696 The following additional specs are available:
698 %w The article washing status.
699 %m The number of MIME parts in the article."
700 :version "24.1"
701 :type 'string
702 :group 'gnus-article-various)
704 (defcustom gnus-article-mode-hook nil
705 "A hook for Gnus article mode."
706 :type 'hook
707 :group 'gnus-article-various)
709 (defcustom gnus-article-menu-hook nil
710 "Hook run after the creation of the article mode menu."
711 :type 'hook
712 :group 'gnus-article-various)
714 (defcustom gnus-article-prepare-hook nil
715 "A hook called after an article has been prepared in the article buffer."
716 :type 'hook
717 :group 'gnus-article-various)
719 (defcustom gnus-copy-article-ignored-headers nil
720 "List of headers to be removed when copying an article.
721 Each element is a regular expression."
722 :version "23.1" ;; No Gnus
723 :type '(repeat regexp)
724 :group 'gnus-article-various)
726 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
727 "Gnus 5.10 (Emacs 22.1)")
729 (defface gnus-button
730 '((t (:weight bold)))
731 "Face used for highlighting a button in the article buffer."
732 :group 'gnus-article-buttons)
734 (defcustom gnus-article-button-face 'gnus-button
735 "Face used for highlighting buttons in the article buffer.
737 An article button is a piece of text that you can activate by pressing
738 `RET' or `mouse-2' above it."
739 :type 'face
740 :group 'gnus-article-buttons)
742 (defcustom gnus-article-mouse-face 'highlight
743 "Face used for mouse highlighting in the article buffer.
745 Article buttons will be displayed in this face when the cursor is
746 above them."
747 :type 'face
748 :group 'gnus-article-buttons)
750 (defcustom gnus-signature-face 'gnus-signature
751 "Face used for highlighting a signature in the article buffer.
752 Obsolete; use the face `gnus-signature' for customizations instead."
753 :type 'face
754 :group 'gnus-article-highlight
755 :group 'gnus-article-signature)
757 (defface gnus-signature
758 '((t
759 (:italic t)))
760 "Face used for highlighting a signature in the article buffer."
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
764 (defface gnus-header-from
765 '((((class color)
766 (background dark))
767 (:foreground "PaleGreen1"))
768 (((class color)
769 (background light))
770 (:foreground "red3"))
772 (:italic t)))
773 "Face used for displaying from headers."
774 :group 'gnus-article-headers
775 :group 'gnus-article-highlight)
777 (defface gnus-header-subject
778 '((((class color)
779 (background dark))
780 (:foreground "SeaGreen1"))
781 (((class color)
782 (background light))
783 (:foreground "red4"))
785 (:bold t :italic t)))
786 "Face used for displaying subject headers."
787 :group 'gnus-article-headers
788 :group 'gnus-article-highlight)
790 (defface gnus-header-newsgroups
791 '((((class color)
792 (background dark))
793 (:foreground "yellow" :italic t))
794 (((class color)
795 (background light))
796 (:foreground "MidnightBlue" :italic t))
798 (:italic t)))
799 "Face used for displaying newsgroups headers.
800 In the default setup this face is only used for crossposted
801 articles."
802 :group 'gnus-article-headers
803 :group 'gnus-article-highlight)
805 (defface gnus-header-name
806 '((((class color)
807 (background dark))
808 (:foreground "SpringGreen2"))
809 (((class color)
810 (background light))
811 (:foreground "maroon"))
813 (:bold t)))
814 "Face used for displaying header names."
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
818 (defface gnus-header-content
819 '((((class color)
820 (background dark))
821 (:foreground "SpringGreen1" :italic t))
822 (((class color)
823 (background light))
824 (:foreground "indianred4" :italic t))
826 (:italic t))) "Face used for displaying header content."
827 :group 'gnus-article-headers
828 :group 'gnus-article-highlight)
830 (defcustom gnus-header-face-alist
831 '(("From" nil gnus-header-from)
832 ("Subject" nil gnus-header-subject)
833 ("Newsgroups:.*," nil gnus-header-newsgroups)
834 ("" gnus-header-name gnus-header-content))
835 "Controls highlighting of article headers.
837 An alist of the form (HEADER NAME CONTENT).
839 HEADER is a regular expression which should match the name of a
840 header and NAME and CONTENT are either face names or nil.
842 The name of each header field will be displayed using the face
843 specified by the first element in the list where HEADER matches
844 the header name and NAME is non-nil. Similarly, the content will
845 be displayed by the first non-nil matching CONTENT face."
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight
848 :type '(repeat (list (regexp :tag "Header")
849 (choice :tag "Name"
850 (item :tag "skip" nil)
851 (face :value default))
852 (choice :tag "Content"
853 (item :tag "skip" nil)
854 (face :value default)))))
856 (defcustom gnus-face-properties-alist '((pbm . (:face gnus-x-face))
857 (png . nil))
858 "Alist of image types and properties applied to Face and X-Face images.
859 Here are examples:
861 ;; Specify the altitude of Face images in the From header.
862 \(setq gnus-face-properties-alist
863 \\='((pbm . (:face gnus-x-face :ascent 80))
864 (png . (:ascent 80))))
866 ;; Show Face images as pressed buttons.
867 \(setq gnus-face-properties-alist
868 \\='((pbm . (:face gnus-x-face :relief -2))
869 (png . (:relief -2))))
871 See the manual for the valid properties for various image types.
872 Currently, `pbm' is used for X-Face images and `png' is used for Face
873 images in Emacs."
874 :version "23.1" ;; No Gnus
875 :group 'gnus-article-headers
876 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
878 (defcustom gnus-article-decode-hook
879 '(article-decode-charset article-decode-encoded-words
880 article-decode-group-name article-decode-idna-rhs)
881 "Hook run to decode charsets in articles."
882 :group 'gnus-article-headers
883 :type 'hook)
885 (defcustom gnus-display-mime-function 'gnus-display-mime
886 "Function to display MIME articles."
887 :group 'gnus-article-mime
888 :type 'function)
890 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
891 "Function used to decode headers.")
893 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
894 "Function used to decode addresses.")
896 (defvar gnus-article-dumbquotes-map
897 '((?\200 "EUR")
898 (?\202 ",")
899 (?\203 "f")
900 (?\204 ",,")
901 (?\205 "...")
902 (?\213 "<")
903 (?\214 "OE")
904 (?\221 "`")
905 (?\222 "'")
906 (?\223 "``")
907 (?\224 "\"")
908 (?\225 "*")
909 (?\226 "-")
910 (?\227 "--")
911 (?\230 "~")
912 (?\231 "(TM)")
913 (?\233 ">")
914 (?\234 "oe")
915 (?\264 "'"))
916 "Table for MS-to-Latin1 translation.")
918 (defcustom gnus-ignored-mime-types nil
919 "List of MIME types that should be ignored by Gnus."
920 :version "21.1"
921 :group 'gnus-article-mime
922 :type '(repeat regexp))
924 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
925 "List of MIME types that should not be given buttons when rendered inline.
926 See also `gnus-buttonized-mime-types' which may override this variable.
927 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
928 :version "21.1"
929 :group 'gnus-article-mime
930 :type '(repeat regexp))
932 (defcustom gnus-buttonized-mime-types nil
933 "List of MIME types that should be given buttons when rendered inline.
934 If set, this variable overrides `gnus-unbuttonized-mime-types'.
935 To see e.g. security buttons you could set this to
936 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
937 this list to display radio buttons that allow you to choose one of two
938 media types those mails include. See also `mm-discouraged-alternatives'.
939 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
940 :version "22.1"
941 :group 'gnus-article-mime
942 :type '(repeat regexp))
944 (defcustom gnus-inhibit-mime-unbuttonizing nil
945 "If non-nil, all MIME parts get buttons.
946 When nil (the default value), then some MIME parts do not get buttons,
947 as described by the variables `gnus-buttonized-mime-types' and
948 `gnus-unbuttonized-mime-types'."
949 :version "22.1"
950 :group 'gnus-article-mime
951 :type 'boolean)
953 (defcustom gnus-body-boundary-delimiter "_"
954 "String used to delimit header and body.
955 This variable is used by `gnus-article-treat-body-boundary' which can
956 be controlled by `gnus-treat-body-boundary'."
957 :version "22.1"
958 :group 'gnus-article-various
959 :type '(choice (item :tag "None" :value nil)
960 string))
962 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
963 "/usr/share/picons")
964 "Defines the location of the faces database.
965 For information on obtaining this database of pretty pictures, please
966 see http://www.cs.indiana.edu/picons/ftp/index.html"
967 :version "22.1"
968 :type '(repeat directory)
969 :link '(url-link :tag "download"
970 "http://www.cs.indiana.edu/picons/ftp/index.html")
971 :link '(custom-manual "(gnus)Picons")
972 :group 'gnus-picon)
974 (defun gnus-picons-installed-p ()
975 "Say whether picons are installed on your machine."
976 (let ((installed nil))
977 (dolist (database gnus-picon-databases)
978 (when (file-exists-p database)
979 (setq installed t)))
980 installed))
982 (defcustom gnus-article-mime-part-function nil
983 "Function called with a MIME handle as the argument.
984 This is meant for people who want to do something automatic based
985 on parts -- for instance, adding Vcard info to a database."
986 :group 'gnus-article-mime
987 :type '(choice (const nil)
988 function))
990 (defcustom gnus-mime-multipart-functions nil
991 "An alist of MIME types to functions to display them."
992 :version "21.1"
993 :group 'gnus-article-mime
994 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
996 (defcustom gnus-article-date-headers '(combined-lapsed)
997 "A list of Date header formats to display.
998 Valid formats are `ut' (Universal Time), `local' (local time
999 zone), `english' (readable English), `lapsed' (elapsed time),
1000 `combined-lapsed' (both the original date and the elapsed time),
1001 `original' (the original date header), `iso8601' (ISO8601
1002 format), and `user-defined' (a user-defined format defined by the
1003 `gnus-article-time-format' variable).
1005 You have as many date headers as you want in the article buffer.
1006 Some of these headers are updated automatically. See
1007 `gnus-article-update-date-headers' for details."
1008 :version "24.1"
1009 :group 'gnus-article-headers
1010 :type '(set
1011 (const :tag "Universal time (UT)" ut)
1012 (const :tag "Local time zone" local)
1013 (const :tag "Readable English" english)
1014 (const :tag "Elapsed time" lapsed)
1015 (const :tag "Original and elapsed time" combined-lapsed)
1016 (const :tag "Original date header" original)
1017 (const :tag "ISO8601 format" iso8601)
1018 (const :tag "User-defined" user-defined)))
1020 (defcustom gnus-article-update-date-headers nil
1021 "A number that says how often to update the date header (in seconds).
1022 If nil, don't update it at all."
1023 :version "24.1"
1024 :group 'gnus-article-headers
1025 :type '(choice
1026 (item :tag "Don't update" :value nil)
1027 integer))
1029 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1030 "Function called with a MIME handle as the argument.
1031 This is meant for people who want to view first matched part.
1032 For `undisplayed-alternative' (default), the first undisplayed
1033 part or alternative part is used. For `undisplayed', the first
1034 undisplayed part is used. For a function, the first part which
1035 the function return t is used. For nil, the first part is
1036 used."
1037 :version "21.1"
1038 :group 'gnus-article-mime
1039 :type '(choice
1040 (item :tag "first" :value nil)
1041 (item :tag "undisplayed" :value undisplayed)
1042 (item :tag "undisplayed or alternative"
1043 :value undisplayed-alternative)
1044 (function)))
1046 (defcustom gnus-mime-action-alist
1047 '(("save to file" . gnus-mime-save-part)
1048 ("save and strip" . gnus-mime-save-part-and-strip)
1049 ("replace with file" . gnus-mime-replace-part)
1050 ("delete part" . gnus-mime-delete-part)
1051 ("display as text" . gnus-mime-inline-part)
1052 ("view the part" . gnus-mime-view-part)
1053 ("pipe to command" . gnus-mime-pipe-part)
1054 ("toggle display" . gnus-article-press-button)
1055 ("toggle display" . gnus-article-view-part-as-charset)
1056 ("view as type" . gnus-mime-view-part-as-type)
1057 ("view internally" . gnus-mime-view-part-internally)
1058 ("view externally" . gnus-mime-view-part-externally))
1059 "An alist of actions that run on the MIME attachment."
1060 :group 'gnus-article-mime
1061 :type '(repeat (cons (string :tag "name")
1062 (function))))
1064 (defcustom gnus-auto-select-part 1
1065 "Advance to next MIME part when deleting or stripping parts.
1067 When 0, point will be placed on the same part as before. When
1068 positive (negative), move point forward (backwards) this many
1069 parts. When nil, redisplay article."
1070 :version "23.1" ;; No Gnus
1071 :group 'gnus-article-mime
1072 :type '(choice (const nil :tag "Redisplay article.")
1073 (const 1 :tag "Next part.")
1074 (const 0 :tag "Current part.")
1075 integer))
1078 ;;; The treatment variables
1081 (defvar gnus-part-display-hook nil
1082 "Hook called on parts that are to receive treatment.")
1084 (defvar gnus-article-treat-custom
1085 '(choice (const :tag "Off" nil)
1086 (const :tag "On" t)
1087 (const :tag "Header" head)
1088 (const :tag "First" first)
1089 (const :tag "Last" last)
1090 (integer :tag "Less")
1091 (repeat :tag "Groups" regexp)
1092 (sexp :tag "Predicate")))
1094 (defvar gnus-article-treat-head-custom
1095 '(choice (const :tag "Off" nil)
1096 (const :tag "Header" head)))
1098 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1099 "text/x-patch" "text/html")
1100 "Part types eligible for treatment.")
1102 (defvar gnus-inhibit-treatment nil
1103 "Whether to inhibit treatment.")
1105 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1106 "Highlight the signature.
1107 Valid values are nil, t, `head', `first', `last', an integer or a
1108 predicate. See Info node `(gnus)Customizing Articles'."
1109 :group 'gnus-article-treat
1110 :link '(custom-manual "(gnus)Customizing Articles")
1111 :type gnus-article-treat-custom)
1112 (put 'gnus-treat-highlight-signature 'highlight t)
1114 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1115 "Add buttons.
1116 Valid values are nil, t, `head', `first', `last', an integer or a
1117 predicate. See Info node `(gnus)Customizing Articles'."
1118 :group 'gnus-article-treat
1119 :link '(custom-manual "(gnus)Customizing Articles")
1120 :type gnus-article-treat-custom)
1121 (put 'gnus-treat-buttonize 'highlight t)
1123 (defcustom gnus-treat-buttonize-head 'head
1124 "Add buttons to the head.
1125 Valid values are nil, t, `head', `first', `last', an integer or a
1126 predicate. See Info node `(gnus)Customizing Articles'."
1127 :group 'gnus-article-treat
1128 :link '(custom-manual "(gnus)Customizing Articles")
1129 :type gnus-article-treat-head-custom)
1130 (put 'gnus-treat-buttonize-head 'highlight t)
1132 (defcustom gnus-treat-date 'head
1133 "Display dates according to the `gnus-article-date-headers' variable.
1134 Valid values are nil, t, `head', `first', `last', an integer or a
1135 predicate. See Info node `(gnus)Customizing Articles'."
1136 :version "24.1"
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-head-custom)
1141 (defcustom gnus-treat-emphasize 50000
1142 "Emphasize text.
1143 Valid values are nil, t, `head', `first', `last', an integer or a
1144 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1148 (put 'gnus-treat-emphasize 'highlight t)
1150 (defcustom gnus-treat-strip-cr nil
1151 "Remove carriage returns.
1152 Valid values are nil, t, `head', `first', `last', an integer or a
1153 predicate. See Info node `(gnus)Customizing Articles'."
1154 :version "22.1"
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-custom)
1159 (defcustom gnus-treat-unsplit-urls nil
1160 "Remove newlines from within URLs.
1161 Valid values are nil, t, `head', `first', `last', an integer or a
1162 predicate. See Info node `(gnus)Customizing Articles'."
1163 :version "22.1"
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-custom)
1168 (defcustom gnus-treat-leading-whitespace nil
1169 "Remove leading whitespace in headers.
1170 Valid values are nil, t, `head', `first', `last', an integer or a
1171 predicate. See Info node `(gnus)Customizing Articles'."
1172 :version "22.1"
1173 :group 'gnus-article-treat
1174 :link '(custom-manual "(gnus)Customizing Articles")
1175 :type gnus-article-treat-custom)
1177 (defcustom gnus-treat-hide-headers 'head
1178 "Hide headers.
1179 Valid values are nil, t, `head', `first', `last', an integer or a
1180 predicate. See Info node `(gnus)Customizing Articles'."
1181 :group 'gnus-article-treat
1182 :link '(custom-manual "(gnus)Customizing Articles")
1183 :type gnus-article-treat-head-custom)
1185 (defcustom gnus-treat-hide-boring-headers nil
1186 "Hide boring headers.
1187 Valid values are nil, t, `head', `first', `last', an integer or a
1188 predicate. See Info node `(gnus)Customizing Articles'."
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-head-custom)
1193 (defcustom gnus-treat-hide-signature nil
1194 "Hide the signature.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1197 :group 'gnus-article-treat
1198 :link '(custom-manual "(gnus)Customizing Articles")
1199 :type gnus-article-treat-custom)
1201 (defcustom gnus-treat-fill-article nil
1202 "Fill the article.
1203 Valid values are nil, t, `head', `first', `last', an integer or a
1204 predicate. See Info node `(gnus)Customizing Articles'."
1205 :group 'gnus-article-treat
1206 :link '(custom-manual "(gnus)Customizing Articles")
1207 :type gnus-article-treat-custom)
1209 (defcustom gnus-treat-hide-citation nil
1210 "Hide cited text.
1211 Valid values are nil, t, `head', `first', `last', an integer or a
1212 predicate. See Info node `(gnus)Customizing Articles'.
1214 See `gnus-article-highlight-citation' for variables used to
1215 control what it hides."
1216 :group 'gnus-article-treat
1217 :link '(custom-manual "(gnus)Customizing Articles")
1218 :type gnus-article-treat-custom)
1220 (defcustom gnus-treat-hide-citation-maybe nil
1221 "Hide cited text according to certain conditions.
1222 Valid values are nil, t, `head', `first', `last', an integer or a
1223 predicate. See Info node `(gnus)Customizing Articles'.
1225 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1226 how to control what it hides."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (defcustom gnus-treat-strip-list-identifiers 'head
1232 "Strip list identifiers from `gnus-list-identifiers'.
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'."
1235 :version "21.1"
1236 :group 'gnus-article-treat
1237 :link '(custom-manual "(gnus)Customizing Articles")
1238 :type gnus-article-treat-custom)
1240 (gnus-define-group-parameter
1241 list-identifier
1242 :variable-document
1243 "Alist of regexps and correspondent identifiers."
1244 :variable-group gnus-article-washing
1245 :parameter-type
1246 '(choice :tag "Identifier"
1247 :value nil
1248 (symbol :tag "Item in `gnus-list-identifiers'" none)
1249 regexp
1250 (const :tag "None" nil))
1251 :parameter-document
1252 "If non-nil, specify how to remove `identifiers' from articles' subject.
1254 Any symbol is used to look up a regular expression to match the
1255 banner in `gnus-list-identifiers'. A string is used as a regular
1256 expression to match the identifier directly.")
1258 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1259 "Gnus 5.10 (Emacs 22.1)")
1261 (defcustom gnus-treat-strip-pem nil
1262 "Strip PEM signatures.
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-custom)
1269 (defcustom gnus-treat-strip-banner t
1270 "Strip banners from articles.
1271 The banner to be stripped is specified in the `banner' group parameter.
1272 Valid values are nil, t, `head', `first', `last', an integer or a
1273 predicate. See Info node `(gnus)Customizing Articles'."
1274 :group 'gnus-article-treat
1275 :link '(custom-manual "(gnus)Customizing Articles")
1276 :type gnus-article-treat-custom)
1278 (defcustom gnus-treat-highlight-headers 'head
1279 "Highlight the headers.
1280 Valid values are nil, t, `head', `first', `last', an integer or a
1281 predicate. See Info node `(gnus)Customizing Articles'."
1282 :group 'gnus-article-treat
1283 :link '(custom-manual "(gnus)Customizing Articles")
1284 :type gnus-article-treat-head-custom)
1285 (put 'gnus-treat-highlight-headers 'highlight t)
1287 (defcustom gnus-treat-highlight-citation t
1288 "Highlight cited text.
1289 Valid values are nil, t, `head', `first', `last', an integer or a
1290 predicate. See Info node `(gnus)Customizing Articles'."
1291 :group 'gnus-article-treat
1292 :link '(custom-manual "(gnus)Customizing Articles")
1293 :type gnus-article-treat-custom)
1294 (put 'gnus-treat-highlight-citation 'highlight t)
1296 (defcustom gnus-treat-strip-headers-in-body t
1297 "Strip the X-No-Archive header line from the beginning of the body.
1298 Valid values are nil, t, `head', `first', `last', an integer or a
1299 predicate. See Info node `(gnus)Customizing Articles'."
1300 :version "21.1"
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-custom)
1305 (defcustom gnus-treat-strip-trailing-blank-lines nil
1306 "Strip trailing blank lines.
1307 Valid values are nil, t, `head', `first', `last', an integer or a
1308 predicate. See Info node `(gnus)Customizing Articles'.
1310 When set to t, it also strips trailing blanks in all MIME parts.
1311 Consider to use `last' instead."
1312 :group 'gnus-article-treat
1313 :link '(custom-manual "(gnus)Customizing Articles")
1314 :type gnus-article-treat-custom)
1316 (defcustom gnus-treat-strip-leading-blank-lines nil
1317 "Strip leading blank lines.
1318 Valid values are nil, t, `head', `first', `last', an integer or a
1319 predicate. See Info node `(gnus)Customizing Articles'.
1321 When set to t, it also strips trailing blanks in all MIME parts."
1322 :group 'gnus-article-treat
1323 :link '(custom-manual "(gnus)Customizing Articles")
1324 :type gnus-article-treat-custom)
1326 (defcustom gnus-treat-strip-multiple-blank-lines nil
1327 "Strip multiple blank lines.
1328 Valid values are nil, t, `head', `first', `last', an integer or a
1329 predicate. See Info node `(gnus)Customizing Articles'."
1330 :group 'gnus-article-treat
1331 :link '(custom-manual "(gnus)Customizing Articles")
1332 :type gnus-article-treat-custom)
1334 (defcustom gnus-treat-unfold-headers 'head
1335 "Unfold folded header lines.
1336 Valid values are nil, t, `head', `first', `last', an integer or a
1337 predicate. See Info node `(gnus)Customizing Articles'."
1338 :version "22.1"
1339 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :type gnus-article-treat-custom)
1343 (defcustom gnus-article-unfold-long-headers nil
1344 "If non-nil, allow unfolding headers even if the header is long.
1345 If it is a regexp, only long headers matching this regexp are unfolded.
1346 If it is t, all long headers are unfolded.
1348 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1349 :version "23.1" ;; No Gnus
1350 :group 'gnus-article-treat
1351 :type '(choice (const nil)
1352 (const :tag "all" t)
1353 (regexp)))
1355 (defcustom gnus-treat-fold-headers nil
1356 "Fold headers.
1357 Valid values are nil, t, `head', `first', `last', an integer or a
1358 predicate. See Info node `(gnus)Customizing Articles'."
1359 :version "22.1"
1360 :group 'gnus-article-treat
1361 :link '(custom-manual "(gnus)Customizing Articles")
1362 :type gnus-article-treat-custom)
1364 (defcustom gnus-treat-fold-newsgroups 'head
1365 "Fold the Newsgroups and Followup-To headers.
1366 Valid values are nil, t, `head', `first', `last', an integer or a
1367 predicate. See Info node `(gnus)Customizing Articles'."
1368 :version "22.1"
1369 :group 'gnus-article-treat
1370 :link '(custom-manual "(gnus)Customizing Articles")
1371 :type gnus-article-treat-custom)
1373 (defcustom gnus-treat-overstrike t
1374 "Treat overstrike highlighting.
1375 Valid values are nil, t, `head', `first', `last', an integer or a
1376 predicate. See Info node `(gnus)Customizing Articles'."
1377 :group 'gnus-article-treat
1378 :link '(custom-manual "(gnus)Customizing Articles")
1379 :type gnus-article-treat-custom)
1380 (put 'gnus-treat-overstrike 'highlight t)
1382 (defcustom gnus-treat-ansi-sequences t
1383 "Treat ANSI SGR control sequences.
1384 Valid values are nil, t, `head', `first', `last', an integer or a
1385 predicate. See Info node `(gnus)Customizing Articles'."
1386 :group 'gnus-article-treat
1387 :link '(custom-manual "(gnus)Customizing Articles")
1388 :type gnus-article-treat-custom)
1390 (make-obsolete-variable 'gnus-treat-display-xface
1391 'gnus-treat-display-x-face "Emacs 22.1")
1393 (defcustom gnus-treat-display-x-face
1394 (and (not noninteractive)
1395 (gnus-image-type-available-p 'xbm)
1396 (condition-case nil
1397 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1398 (executable-find "icontopbm"))
1399 ;; shell-command-to-string may signal an error, e.g. if
1400 ;; shell-file-name is not found.
1401 (error nil))
1402 'head)
1403 "Display X-Face headers.
1404 Valid values are nil and `head'.
1405 See Info node `(gnus)Customizing Articles' and Info node
1406 `(gnus)X-Face' for details."
1407 :group 'gnus-article-treat
1408 :version "21.1"
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :link '(custom-manual "(gnus)X-Face")
1411 :type gnus-article-treat-head-custom
1412 :set (lambda (symbol value)
1413 (set-default
1414 symbol
1415 (cond ((or (boundp symbol) (get symbol 'saved-value))
1416 value)
1417 ((boundp 'gnus-treat-display-xface)
1418 (message "\
1419 ** gnus-treat-display-xface is an obsolete variable;\
1420 use gnus-treat-display-x-face instead")
1421 (default-value 'gnus-treat-display-xface))
1422 ((get 'gnus-treat-display-xface 'saved-value)
1423 (message "\
1424 ** gnus-treat-display-xface is an obsolete variable;\
1425 use gnus-treat-display-x-face instead")
1426 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1428 value)))))
1429 (put 'gnus-treat-display-x-face 'highlight t)
1431 (defcustom gnus-treat-display-face
1432 (and (not noninteractive)
1433 (gnus-image-type-available-p 'png)
1434 'head)
1435 "Display Face headers.
1436 Valid values are nil, t, `head', `first', `last', an integer or a
1437 predicate. See Info node `(gnus)Customizing Articles' and Info
1438 node `(gnus)Face' for details."
1439 :group 'gnus-article-treat
1440 :version "22.1"
1441 :link '(custom-manual "(gnus)Customizing Articles")
1442 :link '(custom-manual "(gnus)X-Face")
1443 :type gnus-article-treat-head-custom)
1444 (put 'gnus-treat-display-face 'highlight t)
1446 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1447 "Display smileys.
1448 Valid values are nil, t, `head', `first', `last', an integer or a
1449 predicate. See Info node `(gnus)Customizing Articles' and Info
1450 node `(gnus)Smileys' for details."
1451 :group 'gnus-article-treat
1452 :version "21.1"
1453 :link '(custom-manual "(gnus)Customizing Articles")
1454 :link '(custom-manual "(gnus)Smileys")
1455 :type gnus-article-treat-custom)
1456 (put 'gnus-treat-display-smileys 'highlight t)
1458 (defcustom gnus-treat-from-picon
1459 (if (and (gnus-image-type-available-p 'xpm)
1460 (gnus-picons-installed-p))
1461 'head nil)
1462 "Display picons in the From header.
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles' and Info
1465 node `(gnus)Picons' for details."
1466 :version "22.1"
1467 :group 'gnus-article-treat
1468 :group 'gnus-picon
1469 :link '(custom-manual "(gnus)Customizing Articles")
1470 :link '(custom-manual "(gnus)Picons")
1471 :type gnus-article-treat-head-custom)
1472 (put 'gnus-treat-from-picon 'highlight t)
1474 (defcustom gnus-treat-mail-picon
1475 (if (and (gnus-image-type-available-p 'xpm)
1476 (gnus-picons-installed-p))
1477 'head nil)
1478 "Display picons in To and Cc headers.
1479 Valid values are nil, t, `head', `first', `last', an integer or a
1480 predicate. See Info node `(gnus)Customizing Articles' and Info
1481 node `(gnus)Picons' for details."
1482 :version "22.1"
1483 :group 'gnus-article-treat
1484 :group 'gnus-picon
1485 :link '(custom-manual "(gnus)Customizing Articles")
1486 :link '(custom-manual "(gnus)Picons")
1487 :type gnus-article-treat-head-custom)
1488 (put 'gnus-treat-mail-picon 'highlight t)
1490 (defcustom gnus-treat-newsgroups-picon
1491 (if (and (gnus-image-type-available-p 'xpm)
1492 (gnus-picons-installed-p))
1493 'head nil)
1494 "Display picons in the Newsgroups and Followup-To headers.
1495 Valid values are nil, t, `head', `first', `last', an integer or a
1496 predicate. See Info node `(gnus)Customizing Articles' and Info
1497 node `(gnus)Picons' for details."
1498 :version "22.1"
1499 :group 'gnus-article-treat
1500 :group 'gnus-picon
1501 :link '(custom-manual "(gnus)Customizing Articles")
1502 :link '(custom-manual "(gnus)Picons")
1503 :type gnus-article-treat-head-custom)
1504 (put 'gnus-treat-newsgroups-picon 'highlight t)
1506 (defcustom gnus-treat-from-gravatar nil
1507 "Display gravatars in the From header.
1508 Valid values are nil, t, `head', `first', `last', an integer or a
1509 predicate. See Info node `(gnus)Customizing Articles' and Info
1510 node `(gnus)Gravatars' for details."
1511 :version "24.1"
1512 :group 'gnus-article-treat
1513 :group 'gnus-gravatar
1514 :link '(custom-manual "(gnus)Customizing Articles")
1515 :link '(custom-manual "(gnus)Gravatars")
1516 :type gnus-article-treat-head-custom)
1517 (put 'gnus-treat-from-gravatar 'highlight t)
1519 (defcustom gnus-treat-mail-gravatar nil
1520 "Display gravatars in To and Cc headers.
1521 Valid values are nil, t, `head', `first', `last', an integer or a
1522 predicate. See Info node `(gnus)Customizing Articles' and Info
1523 node `(gnus)Gravatars' for details."
1524 :version "24.1"
1525 :group 'gnus-article-treat
1526 :group 'gnus-gravatar
1527 :link '(custom-manual "(gnus)Customizing Articles")
1528 :link '(custom-manual "(gnus)Gravatars")
1529 :type gnus-article-treat-head-custom)
1530 (put 'gnus-treat-mail-gravatar 'highlight t)
1532 (defcustom gnus-treat-body-boundary
1533 (if (or gnus-treat-newsgroups-picon
1534 gnus-treat-mail-picon
1535 gnus-treat-from-picon
1536 gnus-treat-from-gravatar
1537 gnus-treat-mail-gravatar)
1538 ;; If there's much decoration, the user might prefer a boundary.
1539 'head
1540 nil)
1541 "Draw a boundary at the end of the headers.
1542 Valid values are nil and `head'.
1543 See Info node `(gnus)Customizing Articles' for details."
1544 :version "22.1"
1545 :group 'gnus-article-treat
1546 :link '(custom-manual "(gnus)Customizing Articles")
1547 :type gnus-article-treat-head-custom)
1549 (defcustom gnus-treat-capitalize-sentences nil
1550 "Capitalize sentence-starting words.
1551 Valid values are nil, t, `head', `first', `last', an integer or a
1552 predicate. See Info node `(gnus)Customizing Articles'."
1553 :version "21.1"
1554 :group 'gnus-article-treat
1555 :link '(custom-manual "(gnus)Customizing Articles")
1556 :type gnus-article-treat-custom)
1558 (defcustom gnus-treat-wash-html nil
1559 "Format as HTML.
1560 Valid values are nil, t, `head', `first', `last', an integer or a
1561 predicate. See Info node `(gnus)Customizing Articles'."
1562 :version "22.1"
1563 :group 'gnus-article-treat
1564 :link '(custom-manual "(gnus)Customizing Articles")
1565 :type gnus-article-treat-custom)
1567 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1568 "Fill long lines.
1569 Valid values are nil, t, `head', `first', `last', an integer or a
1570 predicate. See Info node `(gnus)Customizing Articles'."
1571 :version "24.1"
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-custom)
1576 (defcustom gnus-treat-x-pgp-sig nil
1577 "Verify X-PGP-Sig.
1578 To automatically treat X-PGP-Sig, set it to head.
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 :group 'mime-security
1584 :link '(custom-manual "(gnus)Customizing Articles")
1585 :type gnus-article-treat-custom)
1587 (defvar gnus-article-encrypt-protocol-alist
1588 '(("PGP" . mml2015-self-encrypt)))
1590 ;; Set to nil if more than one protocol added to
1591 ;; gnus-article-encrypt-protocol-alist.
1592 (defcustom gnus-article-encrypt-protocol "PGP"
1593 "The protocol used for encrypt articles.
1594 It is a string, such as \"PGP\". If nil, ask user."
1595 :version "22.1"
1596 :type 'string
1597 :group 'mime-security)
1599 (defcustom gnus-use-idna t
1600 "Whether IDNA decoding of headers is used when viewing messages."
1601 :version "26.1"
1602 :group 'gnus-article-headers
1603 :type 'boolean)
1605 (defcustom gnus-article-over-scroll nil
1606 "If non-nil, allow scrolling the article buffer even when there no more text."
1607 :version "22.1"
1608 :group 'gnus-article
1609 :type 'boolean)
1611 (defcustom gnus-inhibit-images nil
1612 "Non-nil means inhibit displaying of images inline in the article body."
1613 :version "24.1"
1614 :group 'gnus-article
1615 :type 'boolean)
1617 (defcustom gnus-blocked-images 'gnus-block-private-groups
1618 "Images that have URLs matching this regexp will be blocked.
1619 Note that the main reason external images are included in HTML
1620 emails (these days) is to allow tracking whether you've read the
1621 email message or not. If you allow loading images in HTML
1622 emails, you give up privacy.
1624 The default value of this variable blocks loading external
1625 resources when reading email groups (and therefore stops
1626 tracking), but allows loading external resources when reading
1627 from NNTP newsgroups and the like.
1629 People controlling these external resources won't be able to tell
1630 that any one person in particular has read the message (since
1631 it's in a public venue, many people will end up loading that
1632 resource), but they'll be able to tell that somebody from your IP
1633 address has accessed the resource.
1635 This can also be a function to be evaluated. If so, it will be
1636 called with the group name as the parameter, and should return a
1637 regexp."
1638 :version "24.1"
1639 :group 'gnus-art
1640 :type '(choice (const :tag "Allow all" nil)
1641 (regexp :tag "Regular expression")
1642 (function :tag "Use a function")))
1644 ;;; Internal variables
1646 (defvar gnus-english-month-names
1647 '("January" "February" "March" "April" "May" "June" "July" "August"
1648 "September" "October" "November" "December"))
1650 (defvar article-goto-body-goes-to-point-min-p nil)
1651 (defvar gnus-article-wash-types nil)
1652 (defvar gnus-article-emphasis-alist nil)
1653 (defvar gnus-article-image-alist nil)
1655 (defvar gnus-article-mime-handle-alist-1 nil)
1656 (defvar gnus-treatment-function-alist
1657 '((gnus-treat-strip-cr gnus-article-remove-cr)
1658 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1659 (gnus-treat-strip-banner gnus-article-strip-banner)
1660 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1661 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1662 (gnus-treat-buttonize gnus-article-add-buttons)
1663 (gnus-treat-fill-article gnus-article-fill-cited-article)
1664 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1665 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1666 (gnus-treat-display-x-face gnus-article-display-x-face)
1667 (gnus-treat-display-face gnus-article-display-face)
1668 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1669 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1670 (gnus-treat-hide-signature gnus-article-hide-signature)
1671 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1672 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1673 (gnus-treat-from-picon gnus-treat-from-picon)
1674 (gnus-treat-mail-picon gnus-treat-mail-picon)
1675 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1676 (gnus-treat-strip-pem gnus-article-hide-pem)
1677 (gnus-treat-date gnus-article-treat-date)
1678 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1679 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1680 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1681 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1682 (gnus-treat-strip-trailing-blank-lines
1683 gnus-article-remove-trailing-blank-lines)
1684 (gnus-treat-strip-leading-blank-lines
1685 gnus-article-strip-leading-blank-lines)
1686 (gnus-treat-strip-multiple-blank-lines
1687 gnus-article-strip-multiple-blank-lines)
1688 (gnus-treat-overstrike gnus-article-treat-overstrike)
1689 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1690 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1691 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1692 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1693 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1694 (gnus-treat-display-smileys gnus-treat-smiley)
1695 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1696 (gnus-treat-wash-html gnus-article-wash-html)
1697 (gnus-treat-emphasize gnus-article-emphasize)
1698 (gnus-treat-hide-citation gnus-article-hide-citation)
1699 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1700 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1701 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1703 (defvar gnus-article-mime-handle-alist nil)
1704 (defvar article-lapsed-timer nil)
1705 (defvar gnus-article-current-summary nil)
1707 (defvar gnus-article-mode-syntax-table
1708 (let ((table (copy-syntax-table text-mode-syntax-table)))
1709 ;; This causes the citation match run O(2^n).
1710 ;; (modify-syntax-entry ?- "w" table)
1711 (modify-syntax-entry ?> ")<" table)
1712 (modify-syntax-entry ?< "(>" table)
1713 ;; make M-. in article buffers work for `foo' strings,
1714 ;; and still allow C-s C-w to yank ' to the search ring
1715 (modify-syntax-entry ?' "'" table)
1716 (modify-syntax-entry ?` "'" table)
1717 table)
1718 "Syntax table used in article mode buffers.
1719 Initialized from `text-mode-syntax-table'.")
1721 (defvar gnus-save-article-buffer nil)
1723 (defvar gnus-number-of-articles-to-be-saved nil)
1725 (defvar gnus-inhibit-hiding nil)
1727 (defvar gnus-article-edit-mode nil)
1729 ;;; Macros for dealing with the article buffer.
1731 (defmacro gnus-with-article-headers (&rest forms)
1732 `(with-current-buffer gnus-article-buffer
1733 (save-restriction
1734 (let ((inhibit-read-only t)
1735 (inhibit-point-motion-hooks t)
1736 (case-fold-search t))
1737 (article-narrow-to-head)
1738 ,@forms))))
1740 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1741 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1743 (defmacro gnus-with-article-buffer (&rest forms)
1744 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1745 (with-current-buffer gnus-article-buffer
1746 (let ((inhibit-read-only t))
1747 ,@forms))))
1749 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1750 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1752 (defun gnus-article-goto-header (header)
1753 "Go to HEADER, which is a regular expression."
1754 (re-search-forward (concat "^\\(" header "\\):") nil t))
1756 (defsubst gnus-article-hide-text (b e props)
1757 "Set text PROPS on the B to E region."
1758 (gnus-add-text-properties-when 'article-type nil b e props))
1760 (defsubst gnus-article-unhide-text (b e)
1761 "Remove hidden text properties from region between B and E."
1762 (remove-text-properties b e gnus-hidden-properties))
1764 (defun gnus-article-hide-text-type (b e type)
1765 "Hide text of TYPE between B and E."
1766 (gnus-add-wash-type type)
1767 (gnus-article-hide-text
1768 b e (cons 'article-type (cons type gnus-hidden-properties))))
1770 (defun gnus-article-unhide-text-type (b e type)
1771 "Unhide text of TYPE between B and E."
1772 (gnus-delete-wash-type type)
1773 (remove-text-properties
1774 b e (cons 'article-type (cons type gnus-hidden-properties))))
1776 (defun gnus-article-delete-text-of-type (type)
1777 "Delete text of TYPE in the current buffer."
1778 (save-excursion
1779 (let ((b (point-min)))
1780 (if (eq type 'multipart)
1781 ;; Remove MIME buttons associated with multipart/alternative parts.
1782 (progn
1783 (goto-char b)
1784 (while (if (get-text-property (point) 'gnus-part)
1785 (setq b (point))
1786 (when (setq b (next-single-property-change (point)
1787 'gnus-part))
1788 (goto-char b)
1790 (end-of-line)
1791 (skip-chars-forward "\n")
1792 (when (eq (get-text-property b 'article-type) 'multipart)
1793 (delete-region b (point)))))
1794 (while (setq b (text-property-any b (point-max) 'article-type type))
1795 (delete-region
1796 b (or (text-property-not-all b (point-max) 'article-type type)
1797 (point-max))))))))
1799 (defun gnus-article-delete-invisible-text ()
1800 "Delete all invisible text in the current buffer."
1801 (save-excursion
1802 (let ((b (point-min)))
1803 (while (setq b (text-property-any b (point-max) 'invisible t))
1804 (delete-region
1805 b (or (text-property-not-all b (point-max) 'invisible t)
1806 (point-max)))))))
1808 (defsubst gnus-article-header-rank ()
1809 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1810 (let ((list gnus-sorted-header-list)
1811 (i 1))
1812 (while list
1813 (if (looking-at (car list))
1814 (setq list nil)
1815 (setq list (cdr list))
1816 (cl-incf i)))
1819 (defun article-hide-headers (&optional _arg _delete)
1820 "Hide unwanted headers and possibly sort them as well."
1821 (interactive)
1822 ;; This function might be inhibited.
1823 (unless gnus-inhibit-hiding
1824 (let ((inhibit-read-only t)
1825 (case-fold-search t)
1826 (max (1+ (length gnus-sorted-header-list)))
1827 (inhibit-point-motion-hooks t)
1828 (cur (current-buffer))
1829 ignored visible beg)
1830 (save-excursion
1831 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1832 ;; group parameters, so we should go to the summary buffer.
1833 (when (prog1
1834 (condition-case nil
1835 (progn (set-buffer gnus-summary-buffer) t)
1836 (error nil))
1837 (setq ignored (when (not gnus-visible-headers)
1838 (cond ((stringp gnus-ignored-headers)
1839 gnus-ignored-headers)
1840 ((listp gnus-ignored-headers)
1841 (mapconcat 'identity
1842 gnus-ignored-headers
1843 "\\|"))))
1844 visible (cond ((stringp gnus-visible-headers)
1845 gnus-visible-headers)
1846 ((and gnus-visible-headers
1847 (listp gnus-visible-headers))
1848 (mapconcat 'identity
1849 gnus-visible-headers
1850 "\\|")))))
1851 (set-buffer cur))
1852 (save-restriction
1853 ;; First we narrow to just the headers.
1854 (article-narrow-to-head)
1855 ;; Hide any "From " lines at the beginning of (mail) articles.
1856 (while (looking-at "From ")
1857 (forward-line 1))
1858 (unless (bobp)
1859 (delete-region (point-min) (point)))
1860 ;; Then treat the rest of the header lines.
1861 ;; Then we use the two regular expressions
1862 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1863 ;; select which header lines is to remain visible in the
1864 ;; article buffer.
1865 (while (re-search-forward "^[^ \t:]*:" nil t)
1866 (beginning-of-line)
1867 ;; Mark the rank of the header.
1868 (put-text-property
1869 (point) (1+ (point)) 'message-rank
1870 (if (or (and visible (looking-at visible))
1871 (and ignored
1872 (not (looking-at ignored))))
1873 (gnus-article-header-rank)
1874 (+ 2 max)))
1875 (forward-line 1))
1876 (message-sort-headers-1)
1877 (when (setq beg (text-property-any
1878 (point-min) (point-max) 'message-rank (+ 2 max)))
1879 ;; We delete the unwanted headers.
1880 (gnus-add-wash-type 'headers)
1881 (add-text-properties (point-min) (+ 5 (point-min))
1882 '(article-type headers dummy-invisible t))
1883 (delete-region beg (point-max))))))))
1885 (defun article-hide-boring-headers (&optional arg)
1886 "Toggle hiding of headers that aren't very interesting.
1887 If given a negative prefix, always show; if given a positive prefix,
1888 always hide."
1889 (interactive (gnus-article-hidden-arg))
1890 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1891 (not gnus-show-all-headers))
1892 (save-excursion
1893 (save-restriction
1894 (let ((inhibit-read-only t)
1895 (inhibit-point-motion-hooks t))
1896 (article-narrow-to-head)
1897 (dolist (elem gnus-boring-article-headers)
1898 (goto-char (point-min))
1899 (cond
1900 ;; Hide empty headers.
1901 ((eq elem 'empty)
1902 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1903 (forward-line -1)
1904 (gnus-article-hide-text-type
1905 (point-at-bol)
1906 (progn
1907 (end-of-line)
1908 (if (re-search-forward "^[^ \t]" nil t)
1909 (match-beginning 0)
1910 (point-max)))
1911 'boring-headers)))
1912 ;; Hide boring Newsgroups header.
1913 ((eq elem 'newsgroups)
1914 (when (gnus-string-equal
1915 (gnus-fetch-field "newsgroups")
1916 (gnus-group-real-name
1917 (if (boundp 'gnus-newsgroup-name)
1918 gnus-newsgroup-name
1919 "")))
1920 (gnus-article-hide-header "newsgroups")))
1921 ((eq elem 'to-address)
1922 (let ((to (message-fetch-field "to"))
1923 (to-address
1924 (gnus-parameter-to-address
1925 (if (boundp 'gnus-newsgroup-name)
1926 gnus-newsgroup-name ""))))
1927 (when (and to to-address
1928 (ignore-errors
1929 (gnus-string-equal
1930 ;; only one address in To
1931 (nth 1 (mail-extract-address-components to))
1932 to-address)))
1933 (gnus-article-hide-header "to"))))
1934 ((eq elem 'to-list)
1935 (let ((to (message-fetch-field "to"))
1936 (to-list
1937 (gnus-parameter-to-list
1938 (if (boundp 'gnus-newsgroup-name)
1939 gnus-newsgroup-name ""))))
1940 (when (and to to-list
1941 (ignore-errors
1942 (gnus-string-equal
1943 ;; only one address in To
1944 (nth 1 (mail-extract-address-components to))
1945 to-list)))
1946 (gnus-article-hide-header "to"))))
1947 ((eq elem 'cc-list)
1948 (let ((cc (message-fetch-field "cc"))
1949 (to-list
1950 (gnus-parameter-to-list
1951 (if (boundp 'gnus-newsgroup-name)
1952 gnus-newsgroup-name ""))))
1953 (when (and cc to-list
1954 (ignore-errors
1955 (gnus-string-equal
1956 ;; only one address in Cc
1957 (nth 1 (mail-extract-address-components cc))
1958 to-list)))
1959 (gnus-article-hide-header "cc"))))
1960 ((eq elem 'followup-to)
1961 (when (gnus-string-equal
1962 (message-fetch-field "followup-to")
1963 (message-fetch-field "newsgroups"))
1964 (gnus-article-hide-header "followup-to")))
1965 ((eq elem 'reply-to)
1966 (if (gnus-group-find-parameter
1967 gnus-newsgroup-name 'broken-reply-to)
1968 (gnus-article-hide-header "reply-to")
1969 (let ((from (message-fetch-field "from"))
1970 (reply-to (message-fetch-field "reply-to")))
1971 (when
1972 (and
1973 from reply-to
1974 (ignore-errors
1975 (equal
1976 (sort (mapcar
1977 (lambda (x) (downcase (cadr x)))
1978 (mail-extract-address-components from t))
1979 'string<)
1980 (sort (mapcar
1981 (lambda (x) (downcase (cadr x)))
1982 (mail-extract-address-components reply-to t))
1983 'string<))))
1984 (gnus-article-hide-header "reply-to")))))
1985 ((eq elem 'date)
1986 (let ((date (with-current-buffer gnus-original-article-buffer
1987 ;; If date in `gnus-article-buffer' is localized
1988 ;; (`gnus-treat-date-user-defined'),
1989 ;; `days-between' might fail.
1990 (message-fetch-field "date"))))
1991 (when (and date
1992 (< (days-between (current-time-string) date)
1994 (gnus-article-hide-header "date"))))
1995 ((eq elem 'long-to)
1996 (let ((to (message-fetch-field "to"))
1997 (cc (message-fetch-field "cc")))
1998 (when (> (length to) 1024)
1999 (gnus-article-hide-header "to"))
2000 (when (> (length cc) 1024)
2001 (gnus-article-hide-header "cc"))))
2002 ((eq elem 'many-to)
2003 (let ((to-count 0)
2004 (cc-count 0))
2005 (goto-char (point-min))
2006 (while (re-search-forward "^to:" nil t)
2007 (setq to-count (1+ to-count)))
2008 (when (> to-count 1)
2009 (while (> to-count 0)
2010 (goto-char (point-min))
2011 (save-restriction
2012 (re-search-forward "^to:" nil nil to-count)
2013 (forward-line -1)
2014 (narrow-to-region (point) (point-max))
2015 (gnus-article-hide-header "to"))
2016 (setq to-count (1- to-count))))
2017 (goto-char (point-min))
2018 (while (re-search-forward "^cc:" nil t)
2019 (setq cc-count (1+ cc-count)))
2020 (when (> cc-count 1)
2021 (while (> cc-count 0)
2022 (goto-char (point-min))
2023 (save-restriction
2024 (re-search-forward "^cc:" nil nil cc-count)
2025 (forward-line -1)
2026 (narrow-to-region (point) (point-max))
2027 (gnus-article-hide-header "cc"))
2028 (setq cc-count (1- cc-count)))))))))))))
2030 (defun gnus-article-hide-header (header)
2031 (save-excursion
2032 (goto-char (point-min))
2033 (when (re-search-forward (concat "^" header ":") nil t)
2034 (gnus-article-hide-text-type
2035 (point-at-bol)
2036 (progn
2037 (end-of-line)
2038 (if (re-search-forward "^[^ \t]" nil t)
2039 (match-beginning 0)
2040 (point-max)))
2041 'boring-headers))))
2043 (defvar gnus-article-normalized-header-length 40
2044 "Length of normalized headers.")
2046 (defun article-normalize-headers ()
2047 "Make all header lines 40 characters long."
2048 (interactive)
2049 (let ((inhibit-read-only t)
2050 column)
2051 (save-excursion
2052 (save-restriction
2053 (article-narrow-to-head)
2054 (while (not (eobp))
2055 (cond
2056 ((< (setq column (- (point-at-eol) (point)))
2057 gnus-article-normalized-header-length)
2058 (end-of-line)
2059 (insert (make-string
2060 (- gnus-article-normalized-header-length column)
2061 ? )))
2062 ((> column gnus-article-normalized-header-length)
2063 (put-text-property
2064 (progn
2065 (forward-char gnus-article-normalized-header-length)
2066 (point))
2067 (point-at-eol)
2068 'invisible t))
2070 ;; Do nothing.
2072 (forward-line 1))))))
2074 (defun article-treat-dumbquotes ()
2075 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2076 Note that this function guesses whether a character is a sm*rtq**t* or
2077 not, so it should only be used interactively.
2079 Sm*rtq**t*s are M****s***'s unilateral extension to the
2080 iso-8859-1 character map in an attempt to provide more quoting
2081 characters. If you see something like \\222 or \\264 where
2082 you're expecting some kind of apostrophe or quotation mark, then
2083 try this wash."
2084 (interactive)
2085 (article-translate-strings gnus-article-dumbquotes-map))
2087 (defvar org-entities)
2089 (defun article-treat-non-ascii ()
2090 "Translate many Unicode characters into their ASCII equivalents."
2091 (interactive)
2092 (require 'org-entities)
2093 (let ((table (make-char-table nil)))
2094 (dolist (elem org-entities)
2095 (when (and (listp elem)
2096 (= (length (nth 6 elem)) 1))
2097 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem))))
2098 (save-excursion
2099 (when (article-goto-body)
2100 (let ((inhibit-read-only t)
2101 replace props)
2102 (while (not (eobp))
2103 (if (not (setq replace (aref table (following-char))))
2104 (forward-char 1)
2105 (if (prog1
2106 (setq props (text-properties-at (point)))
2107 (delete-char 1))
2108 (add-text-properties (point) (progn (insert replace) (point))
2109 props)
2110 (insert replace)))))))))
2112 (defun article-translate-strings (map)
2113 "Translate all string in the body of the article according to MAP.
2114 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2115 (save-excursion
2116 (when (article-goto-body)
2117 (let ((inhibit-read-only t))
2118 (dolist (elem map)
2119 (let ((from (car elem))
2120 (to (cadr elem)))
2121 (save-excursion
2122 (if (stringp from)
2123 (while (search-forward from nil t)
2124 (replace-match to))
2125 (while (not (eobp))
2126 (if (eq (following-char) from)
2127 (progn
2128 (delete-char 1)
2129 (insert to))
2130 (forward-char 1)))))))))))
2132 (defun article-treat-overstrike ()
2133 "Translate overstrikes into bold text."
2134 (interactive)
2135 (save-excursion
2136 (when (article-goto-body)
2137 (let ((inhibit-read-only t))
2138 (while (search-forward "\b" nil t)
2139 (let ((next (char-after))
2140 (previous (char-after (- (point) 2))))
2141 ;; We do the boldification/underlining by hiding the
2142 ;; overstrikes and putting the proper text property
2143 ;; on the letters.
2144 (cond
2145 ((eq next previous)
2146 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2147 (put-text-property (point) (1+ (point)) 'face 'bold))
2148 ((eq next ?_)
2149 (gnus-article-hide-text-type
2150 (1- (point)) (1+ (point)) 'overstrike)
2151 (put-text-property
2152 (- (point) 2) (1- (point)) 'face 'underline))
2153 ((eq previous ?_)
2154 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2155 (put-text-property
2156 (point) (1+ (point)) 'face 'underline)))))))))
2158 (defun article-treat-ansi-sequences ()
2159 "Translate ANSI SGR control sequences into overlays or extents."
2160 (interactive)
2161 (save-excursion
2162 (when (article-goto-body)
2163 (let ((inhibit-read-only t))
2164 (ansi-color-apply-on-region (point) (point-max))))))
2166 (defun gnus-article-treat-unfold-headers ()
2167 "Unfold folded message headers.
2168 Only the headers that fit into the current window width will be
2169 unfolded."
2170 (interactive)
2171 (gnus-with-article-headers
2172 (let (length)
2173 (while (not (eobp))
2174 (save-restriction
2175 (mail-header-narrow-to-field)
2176 (let* ((header (buffer-string))
2177 (unfoldable
2178 (or (equal gnus-article-unfold-long-headers t)
2179 (and (stringp gnus-article-unfold-long-headers)
2180 (string-match gnus-article-unfold-long-headers
2181 header)))))
2182 (with-temp-buffer
2183 (insert header)
2184 (goto-char (point-min))
2185 (while (re-search-forward "\n[\t ]" nil t)
2186 (replace-match " " t t)))
2187 (setq length (- (point-max) (point-min) 1))
2188 (when (or unfoldable
2189 (< length (window-width)))
2190 (while (re-search-forward "\n[\t ]" nil t)
2191 (replace-match " " t t))))
2192 (goto-char (point-max)))))))
2194 (defun gnus-article-treat-fold-headers ()
2195 "Fold message headers."
2196 (interactive)
2197 (gnus-with-article-headers
2198 (while (not (eobp))
2199 (save-restriction
2200 (mail-header-narrow-to-field)
2201 (mail-header-fold-field)
2202 (goto-char (point-max))))))
2204 (defun gnus-treat-smiley ()
2205 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2206 (interactive)
2207 (gnus-with-article-buffer
2208 (if (memq 'smiley gnus-article-wash-types)
2209 (gnus-delete-images 'smiley)
2210 (article-goto-body)
2211 (let ((images (smiley-region (point) (point-max))))
2212 (when images
2213 (gnus-add-wash-type 'smiley)
2214 (dolist (image images)
2215 (gnus-add-image 'smiley image)))))))
2217 (defun gnus-article-remove-images ()
2218 "Remove all images from the article buffer."
2219 (interactive)
2220 (gnus-with-article-buffer
2221 (save-restriction
2222 (widen)
2223 (dolist (elem gnus-article-image-alist)
2224 (gnus-delete-images (car elem))))))
2226 (declare-function w3m-toggle-inline-images "w3m")
2228 (defun gnus-article-show-images ()
2229 "Show any images that are in the HTML-rendered article buffer.
2230 This only works if the article in question is HTML."
2231 (interactive)
2232 (gnus-with-article-buffer
2233 (save-restriction
2234 (widen)
2235 (if (eq mm-text-html-renderer 'w3m)
2236 (progn
2237 (require 'w3m)
2238 (w3m-toggle-inline-images))
2239 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2240 'image-displayer))
2241 (cl-destructuring-bind (start end function) region
2242 (funcall function (get-text-property start 'image-url)
2243 start end)))))))
2245 (defun gnus-article-treat-fold-newsgroups ()
2246 "Unfold folded message headers.
2247 Only the headers that fit into the current window width will be
2248 unfolded."
2249 (interactive)
2250 (gnus-with-article-headers
2251 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2252 (save-restriction
2253 (mail-header-narrow-to-field)
2254 (while (re-search-forward ", *" nil t)
2255 (replace-match ", " t t))
2256 (mail-header-fold-field)
2257 (goto-char (point-max))))))
2259 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2260 "Value of `truncate-lines' in Gnus Article buffer.
2261 Valid values are nil, t, `head', `first', `last', an integer or a
2262 predicate. See Info node `(gnus)Customizing Articles'."
2263 :version "23.1" ;; No Gnus
2264 :group 'gnus-article
2265 ;; :link '(custom-manual "(gnus)Customizing Articles")
2266 :type 'boolean)
2268 (defun gnus-article-toggle-truncate-lines (&optional arg)
2269 "Toggle whether to fold or truncate long lines in article the buffer.
2270 If ARG is non-nil and not a number, toggle
2271 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2272 long lines if and only if arg is positive."
2273 (interactive "P")
2274 (cond
2275 ((and (numberp arg) (> arg 0))
2276 (setq gnus-article-truncate-lines t))
2277 ((numberp arg)
2278 (setq gnus-article-truncate-lines nil))
2279 (arg
2280 (setq gnus-article-truncate-lines
2281 (not gnus-article-truncate-lines))))
2282 (gnus-with-article-buffer
2283 (cond
2284 ((and (numberp arg) (> arg 0))
2285 (setq truncate-lines nil))
2286 ((numberp arg)
2287 (setq truncate-lines t)))
2288 (toggle-truncate-lines)))
2290 (defun gnus-article-treat-body-boundary ()
2291 "Place a boundary line at the end of the headers."
2292 (interactive)
2293 (when (and gnus-body-boundary-delimiter
2294 (> (length gnus-body-boundary-delimiter) 0))
2295 (gnus-with-article-headers
2296 (goto-char (point-max))
2297 (let ((start (point)))
2298 (insert "X-Boundary: ")
2299 (add-text-properties start (point) gnus-hidden-properties)
2300 (insert (let (str (max (window-width)))
2301 (while (>= max (length str))
2302 (setq str (concat str gnus-body-boundary-delimiter)))
2303 (substring str 0 max))
2304 "\n")
2305 (put-text-property start (point) 'gnus-decoration 'header)))))
2307 (defun article-fill-long-lines ()
2308 "Fill lines that are wider than the window width."
2309 (interactive)
2310 (save-excursion
2311 (let ((inhibit-read-only t)
2312 (width (window-width (get-buffer-window (current-buffer)))))
2313 (save-restriction
2314 (article-goto-body)
2315 (let ((adaptive-fill-mode nil)) ;Why? -sm
2316 (while (not (eobp))
2317 (end-of-line)
2318 (when (>= (current-column) (min fill-column width))
2319 (narrow-to-region (min (1+ (point)) (point-max))
2320 (point-at-bol))
2321 (let ((goback (point-marker)))
2322 (fill-paragraph nil)
2323 (goto-char (marker-position goback)))
2324 (widen))
2325 (forward-line 1)))))))
2327 (defun article-capitalize-sentences ()
2328 "Capitalize the first word in each sentence."
2329 (interactive)
2330 (save-excursion
2331 (let ((inhibit-read-only t)
2332 (paragraph-start "^[\n\^L]"))
2333 (article-goto-body)
2334 (while (not (eobp))
2335 (capitalize-word 1)
2336 (forward-sentence)))))
2338 (defun article-remove-cr ()
2339 "Remove trailing CRs and then translate remaining CRs into LFs."
2340 (interactive)
2341 (save-excursion
2342 (let ((inhibit-read-only t))
2343 (goto-char (point-min))
2344 (while (re-search-forward "\r+$" nil t)
2345 (replace-match "" t t))
2346 (goto-char (point-min))
2347 (while (search-forward "\r" nil t)
2348 (replace-match "\n" t t)))))
2350 (defun article-remove-trailing-blank-lines ()
2351 "Remove all trailing blank lines from the article."
2352 (interactive)
2353 (save-excursion
2354 (let ((inhibit-read-only t))
2355 (goto-char (point-max))
2356 (delete-region
2357 (point)
2358 (progn
2359 (while (and (not (bobp))
2360 (looking-at "^[ \t]*$")
2361 (not (gnus-annotation-in-region-p
2362 (point) (point-at-eol))))
2363 (forward-line -1))
2364 (forward-line 1)
2365 (point))))))
2367 (defvar gnus-face-properties-alist)
2369 (defun article-display-face (&optional force)
2370 "Display any Face headers in the header."
2371 (interactive (list 'force))
2372 (let ((wash-face-p buffer-read-only))
2373 (gnus-with-article-headers
2374 ;; When displaying parts, this function can be called several times on
2375 ;; the same article, without any intended toggle semantic (as typing `W
2376 ;; D d' would have). So face deletion must occur only when we come from
2377 ;; an interactive command, that is when the *Article* buffer is
2378 ;; read-only.
2379 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2380 (gnus-delete-images 'face)
2381 (let ((from (message-fetch-field "from"))
2382 faces)
2383 (save-current-buffer
2384 (when (and wash-face-p
2385 (gnus-buffer-live-p gnus-original-article-buffer)
2386 (not (re-search-forward "^Face:[\t ]*" nil t)))
2387 (set-buffer gnus-original-article-buffer))
2388 (save-restriction
2389 (mail-narrow-to-head)
2390 (when (or force
2391 ;; Check whether this face is censored.
2392 (not (and gnus-article-x-face-too-ugly
2393 (or from
2394 (setq from (message-fetch-field "from")))
2395 (string-match gnus-article-x-face-too-ugly
2396 from))))
2397 (while (gnus-article-goto-header "Face")
2398 (push (mail-header-field-value) faces)))))
2399 (when faces
2400 (goto-char (point-min))
2401 (let (png image)
2402 (unless (setq from (gnus-article-goto-header "from"))
2403 (insert "From:")
2404 (setq from (point))
2405 (insert " [no 'from' set]\n"))
2406 (while faces
2407 (when (setq png (gnus-convert-face-to-png (pop faces)))
2408 (setq image
2409 (apply 'gnus-create-image png 'png t
2410 (cdr (assq 'png gnus-face-properties-alist))))
2411 (goto-char from)
2412 (when image
2413 (gnus-add-wash-type 'face)
2414 (gnus-add-image 'face image)
2415 (gnus-put-image image nil 'face)))))))))))
2417 (defun article-display-x-face (&optional force)
2418 "Look for an X-Face header and display it if present."
2419 (interactive (list 'force))
2420 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2421 (gnus-with-article-headers
2422 ;; Delete the old process, if any.
2423 (when (process-status "article-x-face")
2424 (delete-process "article-x-face"))
2425 ;; See the comment in `article-display-face'.
2426 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2427 ;; We have already displayed X-Faces, so we remove them
2428 ;; instead.
2429 (gnus-delete-images 'xface)
2430 ;; Display X-Faces.
2431 (let ((from (message-fetch-field "from"))
2432 x-faces)
2433 (save-current-buffer
2434 (when (and wash-face-p
2435 (gnus-buffer-live-p gnus-original-article-buffer)
2436 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2437 ;; If type `W f', use gnus-original-article-buffer,
2438 ;; otherwise use the current buffer because displaying
2439 ;; RFC822 parts calls this function too.
2440 (set-buffer gnus-original-article-buffer))
2441 (save-restriction
2442 (mail-narrow-to-head)
2443 (and gnus-article-x-face-command
2444 (or force
2445 ;; Check whether this face is censored.
2446 (not (and gnus-article-x-face-too-ugly
2447 (or from
2448 (setq from (message-fetch-field "from")))
2449 (string-match gnus-article-x-face-too-ugly
2450 from))))
2451 (while (gnus-article-goto-header "X-Face")
2452 (push (mail-header-field-value) x-faces)))))
2453 (when x-faces
2454 ;; We display the face.
2455 (cond ((functionp gnus-article-x-face-command)
2456 ;; The command is a lisp function, so we call it.
2457 (mapc gnus-article-x-face-command x-faces))
2458 ((stringp gnus-article-x-face-command)
2459 ;; The command is a string, so we interpret the command
2460 ;; as a, well, command, and fork it off.
2461 (let ((process-connection-type nil))
2462 (set-process-query-on-exit-flag
2463 (start-process
2464 "article-x-face" nil shell-file-name
2465 shell-command-switch gnus-article-x-face-command)
2466 nil)
2467 ;; Sending multiple EOFs to xv doesn't work,
2468 ;; so we only do a single external face.
2469 (with-temp-buffer
2470 (insert (car x-faces))
2471 (process-send-region "article-x-face"
2472 (point-min) (point-max)))
2473 (process-send-eof "article-x-face")))
2475 (error "`%s' set to `%s' is not a function"
2476 gnus-article-x-face-command
2477 'gnus-article-x-face-command)))))))))
2479 (defun article-decode-mime-words ()
2480 "Decode all MIME-encoded words in the article."
2481 (interactive)
2482 (gnus-with-article-buffer
2483 (let ((inhibit-point-motion-hooks t)
2484 (mail-parse-charset gnus-newsgroup-charset)
2485 (mail-parse-ignored-charsets
2486 (with-current-buffer gnus-summary-buffer
2487 gnus-newsgroup-ignored-charsets)))
2488 (mail-decode-encoded-word-region (point-min) (point-max)))))
2490 (defun article-decode-charset (&optional prompt)
2491 "Decode charset-encoded text in the article.
2492 If PROMPT (the prefix), prompt for a coding system to use."
2493 (interactive "P")
2494 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2495 (inhibit-read-only t)
2496 (mail-parse-charset gnus-newsgroup-charset)
2497 (mail-parse-ignored-charsets
2498 (save-excursion (condition-case nil
2499 (set-buffer gnus-summary-buffer)
2500 (error))
2501 gnus-newsgroup-ignored-charsets))
2502 ct cte ctl charset format)
2503 (save-excursion
2504 (save-restriction
2505 (article-narrow-to-head)
2506 (setq ct (message-fetch-field "Content-Type" t)
2507 cte (message-fetch-field "Content-Transfer-Encoding" t)
2508 ctl (and ct (mail-header-parse-content-type ct))
2509 charset (cond
2510 (prompt
2511 (read-coding-system "Charset to decode: "))
2512 (ctl
2513 (mail-content-type-get ctl 'charset)))
2514 format (and ctl (mail-content-type-get ctl 'format)))
2515 (when cte
2516 (setq cte (mail-header-strip-cte cte)))
2517 (if (and ctl (not (string-match "/" (car ctl))))
2518 (setq ctl nil))
2519 (goto-char (point-max)))
2520 (forward-line 1)
2521 (save-restriction
2522 (narrow-to-region (point) (point-max))
2523 (when (and (eq mail-parse-charset 'gnus-decoded)
2524 (eq (mm-body-7-or-8) '8bit))
2525 ;; The text code could have been decoded.
2526 (setq charset mail-parse-charset))
2527 (when (and (or (not ctl)
2528 (equal (car ctl) "text/plain"))
2529 (not format)) ;; article with format will decode later.
2530 (mm-decode-body
2531 charset (and cte (intern (downcase cte)))
2532 (car ctl)))))))
2534 (defun article-decode-encoded-words ()
2535 "Remove encoded-word encoding from headers."
2536 (let ((inhibit-point-motion-hooks t)
2537 (mail-parse-charset gnus-newsgroup-charset)
2538 (mail-parse-ignored-charsets
2539 (save-excursion (condition-case nil
2540 (set-buffer gnus-summary-buffer)
2541 (error))
2542 gnus-newsgroup-ignored-charsets))
2543 (inhibit-read-only t)
2544 end start)
2545 (goto-char (point-min))
2546 (when (search-forward "\n\n" nil 'move)
2547 (forward-line -1))
2548 (setq end (point))
2549 (while (not (bobp))
2550 (while (progn
2551 (forward-line -1)
2552 (and (not (bobp))
2553 (memq (char-after) '(?\t ? )))))
2554 (setq start (point))
2555 (if (looking-at "\
2556 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2557 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2558 (funcall gnus-decode-address-function start end)
2559 (funcall gnus-decode-header-function start end))
2560 (goto-char (setq end start)))))
2562 (defun article-decode-group-name ()
2563 "Decode group names in Newsgroups, Followup-To and Xref headers."
2564 (let ((inhibit-point-motion-hooks t)
2565 (inhibit-read-only t)
2566 (method (gnus-find-method-for-group gnus-newsgroup-name))
2567 regexp)
2568 (when (and (or gnus-group-name-charset-method-alist
2569 gnus-group-name-charset-group-alist)
2570 (gnus-buffer-live-p gnus-original-article-buffer))
2571 (save-restriction
2572 (article-narrow-to-head)
2573 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2574 (with-current-buffer gnus-original-article-buffer
2575 (goto-char (point-min)))
2576 (setq regexp (concat "^" header
2577 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2578 (while (re-search-forward regexp nil t)
2579 (replace-match (save-match-data
2580 (gnus-decode-newsgroups
2581 ;; XXX how to use data in article buffer?
2582 (with-current-buffer gnus-original-article-buffer
2583 (re-search-forward regexp nil t)
2584 (match-string 1))
2585 gnus-newsgroup-name method))
2586 t t nil 1))
2587 (goto-char (point-min)))))))
2589 (defun article-decode-idna-rhs ()
2590 "Decode IDNA strings in RHS in various headers in current buffer.
2591 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2592 Mail-Reply-To: and Mail-Followup-To:."
2593 (when gnus-use-idna
2594 (save-restriction
2595 (let ((inhibit-point-motion-hooks t)
2596 (inhibit-read-only t))
2597 (article-narrow-to-head)
2598 (goto-char (point-min))
2599 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2600 (let (ace unicode)
2601 (when (save-match-data
2602 (and (setq ace (match-string 1))
2603 (save-excursion
2604 (and (re-search-backward "^[^ \t]" nil t)
2605 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2606 (setq unicode (puny-decode-domain ace))))
2607 (unless (string= ace unicode)
2608 (replace-match unicode nil nil nil 1)))))))))
2610 (defun article-de-quoted-unreadable (&optional force read-charset)
2611 "Translate a quoted-printable-encoded article.
2612 If FORCE, decode the article whether it is marked as quoted-printable
2613 or not.
2614 If READ-CHARSET, ask for a coding system."
2615 (interactive (list 'force current-prefix-arg))
2616 (save-excursion
2617 (let ((inhibit-read-only t) type charset)
2618 (if (gnus-buffer-live-p gnus-original-article-buffer)
2619 (with-current-buffer gnus-original-article-buffer
2620 (setq type
2621 (gnus-fetch-field "content-transfer-encoding"))
2622 (let* ((ct (gnus-fetch-field "content-type"))
2623 (ctl (and ct (mail-header-parse-content-type ct))))
2624 (setq charset (and ctl
2625 (mail-content-type-get ctl 'charset)))
2626 (if (stringp charset)
2627 (setq charset (intern (downcase charset)))))))
2628 (if read-charset
2629 (setq charset (read-coding-system "Charset: " charset)))
2630 (unless charset
2631 (setq charset gnus-newsgroup-charset))
2632 (when (or force
2633 (and type (let ((case-fold-search t))
2634 (string-match "quoted-printable" type))))
2635 (article-goto-body)
2636 (quoted-printable-decode-region
2637 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2639 (defun article-de-base64-unreadable (&optional force read-charset)
2640 "Translate a base64 article.
2641 If FORCE, decode the article whether it is marked as base64 not.
2642 If READ-CHARSET, ask for a coding system."
2643 (interactive (list 'force current-prefix-arg))
2644 (save-excursion
2645 (let ((inhibit-read-only t) type charset)
2646 (if (gnus-buffer-live-p gnus-original-article-buffer)
2647 (with-current-buffer gnus-original-article-buffer
2648 (setq type
2649 (gnus-fetch-field "content-transfer-encoding"))
2650 (let* ((ct (gnus-fetch-field "content-type"))
2651 (ctl (and ct (mail-header-parse-content-type ct))))
2652 (setq charset (and ctl
2653 (mail-content-type-get ctl 'charset)))
2654 (if (stringp charset)
2655 (setq charset (intern (downcase charset)))))))
2656 (if read-charset
2657 (setq charset (read-coding-system "Charset: " charset)))
2658 (unless charset
2659 (setq charset gnus-newsgroup-charset))
2660 (when (or force
2661 (and type (let ((case-fold-search t))
2662 (string-match "base64" type))))
2663 (article-goto-body)
2664 (save-restriction
2665 (narrow-to-region (point) (point-max))
2666 (base64-decode-region (point-min) (point-max))
2667 (decode-coding-region
2668 (point-min) (point-max)
2669 (mm-charset-to-coding-system charset nil t)))))))
2671 (declare-function rfc1843-decode-region "rfc1843" (from to))
2673 (defun article-decode-HZ ()
2674 "Translate a HZ-encoded article."
2675 (interactive)
2676 (require 'rfc1843)
2677 (save-excursion
2678 (let ((inhibit-read-only t))
2679 (rfc1843-decode-region (point-min) (point-max)))))
2681 (defun article-unsplit-urls ()
2682 "Remove the newlines that some other mailers insert into URLs."
2683 (interactive)
2684 (save-excursion
2685 (let ((inhibit-read-only t))
2686 (goto-char (point-min))
2687 (while (re-search-forward
2688 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2689 (replace-match "\\1\\3" t)))
2690 (when (called-interactively-p 'any)
2691 (gnus-treat-article nil))))
2693 (defun article-wash-html ()
2694 "Format an HTML article."
2695 (interactive)
2696 (let ((handles nil)
2697 (buffer-read-only nil))
2698 (when (gnus-buffer-live-p gnus-original-article-buffer)
2699 (with-current-buffer gnus-original-article-buffer
2700 (setq handles (mm-dissect-buffer t t))))
2701 (article-goto-body)
2702 (delete-region (point) (point-max))
2703 (mm-enable-multibyte)
2704 (mm-inline-text-html handles)))
2706 (defvar gnus-article-browse-html-temp-list nil
2707 "List of temporary files created by `gnus-article-browse-html-parts'.
2708 Internal variable.")
2710 (defcustom gnus-article-browse-delete-temp 'ask
2711 "What to do with temporary files from `gnus-article-browse-html-parts'.
2712 If nil, don't delete temporary files. If it is t, delete them on
2713 exit from the summary buffer. If it is the symbol `file', query
2714 on each file, if it is `ask' ask once when exiting from the
2715 summary buffer."
2716 :group 'gnus-article
2717 :version "23.1" ;; No Gnus
2718 :type '(choice (const :tag "Don't delete" nil)
2719 (const :tag "Don't ask" t)
2720 (const :tag "Ask" ask)
2721 (const :tag "Ask for each file" file)))
2723 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2725 (defun gnus-article-browse-delete-temp-files (&optional how)
2726 "Delete temp-files created by `gnus-article-browse-html-parts'."
2727 (when (and gnus-article-browse-html-temp-list
2728 (progn
2729 (or how (setq how gnus-article-browse-delete-temp))
2730 (if (eq how 'ask)
2731 (let ((files (length gnus-article-browse-html-temp-list)))
2732 (or (gnus-y-or-n-p
2733 (if (= files 1)
2734 "Delete the temporary HTML file? "
2735 (format "Delete all %s temporary HTML files? "
2736 files)))
2737 (setq gnus-article-browse-html-temp-list nil)))
2738 how)))
2739 (dolist (file gnus-article-browse-html-temp-list)
2740 (cond ((file-directory-p file)
2741 (when (or (not (eq how 'file))
2742 (gnus-y-or-n-p
2743 (format-message
2744 "Delete temporary HTML file(s) in directory `%s'? "
2745 (file-name-as-directory file))))
2746 (gnus-delete-directory file)))
2747 ((file-exists-p file)
2748 (when (or (not (eq how 'file))
2749 (gnus-y-or-n-p
2750 (format "Delete temporary HTML file `%s'? " file)))
2751 (delete-file file)))))
2752 ;; Also remove file from the list when not deleted or if file doesn't
2753 ;; exist anymore.
2754 (setq gnus-article-browse-html-temp-list nil))
2755 gnus-article-browse-html-temp-list)
2757 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2758 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2759 Return file name relative to the parent of DIRECTORY."
2760 (save-match-data
2761 (let (file afile)
2762 (catch 'found
2763 (dolist (handle handles)
2764 (cond
2765 ((not (listp handle)))
2766 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2767 ;; may create.
2768 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2769 ((equal (mm-handle-media-supertype handle) "multipart")
2770 (when (setq file (gnus-article-browse-html-save-cid-content
2771 cid handle directory))
2772 (throw 'found file)))
2773 ((equal (concat "<" cid ">") (mm-handle-id handle))
2774 (setq file (or (mm-handle-filename handle)
2775 (concat
2776 (make-temp-name "cid")
2777 (car (rassoc (car (mm-handle-type handle))
2778 mailcap-mime-extensions))))
2779 afile (expand-file-name file directory))
2780 (mm-save-part-to-file handle afile)
2781 (throw 'found (concat (file-name-nondirectory
2782 (directory-file-name directory))
2783 "/" file)))))))))
2785 (defun gnus-article-browse-html-parts (list &optional header)
2786 "View all \"text/html\" parts from LIST.
2787 Recurse into multiparts. The optional HEADER that should be a decoded
2788 message header will be added to the bodies of the \"text/html\" parts."
2789 ;; Internal function used by `gnus-article-browse-html-article'.
2790 (let (type file charset content cid-dir tmp-file showed)
2791 ;; Find and show the html-parts.
2792 (dolist (handle list)
2793 ;; If HTML, show it:
2794 (cond ((not (listp handle)))
2795 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2796 (and (equal (car type) "message/external-body")
2797 (or header
2798 (setq file (mm-handle-filename handle)))
2799 (or (mm-handle-cache handle)
2800 (condition-case code
2801 (progn (mm-extern-cache-contents handle) t)
2802 (error
2803 (gnus-message 3 "%s" (error-message-string code))
2804 (when (>= gnus-verbose 3) (sit-for 2))
2805 nil)))
2806 (progn
2807 (setq handle (mm-handle-cache handle)
2808 type (mm-handle-type handle))
2809 (equal (car type) "text/html"))))
2810 (setq charset (mail-content-type-get type 'charset)
2811 content (mm-get-part handle))
2812 (with-temp-buffer
2813 (if (eq charset 'gnus-decoded)
2814 (mm-enable-multibyte)
2815 (mm-disable-multibyte))
2816 (insert content)
2817 ;; resolve cid contents
2818 (let ((case-fold-search t)
2819 st base regexp cid-file)
2820 (goto-char (point-min))
2821 (when (and (re-search-forward "<head[\t\n >]" nil t)
2822 (progn
2823 (setq st (match-end 0))
2824 (re-search-forward "</head[\t\n >]" nil t))
2825 (re-search-backward "<base\
2826 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2827 (setq base (match-string 1))
2828 (replace-match "<!--\\&-->")
2829 (setq st (point))
2830 (dolist (tag '(("a" . "href") ("form" . "action")
2831 ("img" . "src")))
2832 (setq regexp (concat "<" (car tag)
2833 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2834 (cdr tag) "=\"\\([^\"]+\\)"))
2835 (while (re-search-forward regexp nil t)
2836 (insert (prog1
2837 (condition-case nil
2838 (save-match-data
2839 (url-expand-file-name (match-string 1)
2840 base))
2841 (error (match-string 1)))
2842 (delete-region (match-beginning 1)
2843 (match-end 1)))))
2844 (goto-char st)))
2845 (while (re-search-forward "\
2846 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2847 nil t)
2848 (unless cid-dir
2849 (setq cid-dir (make-temp-file "cid" t))
2850 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2851 (setq file nil
2852 content nil)
2853 (when (setq cid-file
2854 (gnus-article-browse-html-save-cid-content
2855 (match-string 2)
2856 (with-current-buffer gnus-article-buffer
2857 gnus-article-mime-handles)
2858 cid-dir))
2859 (replace-match cid-file nil nil nil 1))))
2860 (unless content (setq content (buffer-string))))
2861 (when (or charset header (not file))
2862 (setq tmp-file (make-temp-file
2863 ;; Do we need to care for 8.3 filenames?
2864 "mm-" nil ".html")))
2865 ;; Add a meta html tag to specify charset and a header.
2866 (cond
2867 (header
2868 (let (title eheader body hcharset coding)
2869 (with-temp-buffer
2870 (mm-enable-multibyte)
2871 (setq case-fold-search t)
2872 (insert header "\n")
2873 (setq title (message-fetch-field "subject"))
2874 (goto-char (point-min))
2875 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2876 nil t)
2877 (replace-match (cond ((match-beginning 1) "&lt;")
2878 ((match-beginning 2) "&gt;")
2879 ((match-beginning 3) "&amp;")
2880 (t "<br>\n"))))
2881 (goto-char (point-min))
2882 (while (re-search-forward "^[\t ]+" nil t)
2883 (dotimes (i (prog1
2884 (current-column)
2885 (delete-region (match-beginning 0)
2886 (match-end 0))))
2887 (insert "&nbsp;")))
2888 (goto-char (point-min))
2889 (insert "<div align=\"left\">\n")
2890 (goto-char (point-max))
2891 (insert "</div>\n<hr>\n")
2892 ;; We have to examine charset one by one since
2893 ;; charset specified in parts might be different.
2894 (if (eq charset 'gnus-decoded)
2895 (setq charset 'utf-8
2896 eheader (encode-coding-string (buffer-string)
2897 charset)
2898 title (when title
2899 (encode-coding-string title charset))
2900 body (encode-coding-string content charset))
2901 (setq hcharset (mm-find-mime-charset-region (point-min)
2902 (point-max)))
2903 (cond ((= (length hcharset) 1)
2904 (setq hcharset (car hcharset)
2905 coding (mm-charset-to-coding-system
2906 hcharset nil t)))
2907 ((> (length hcharset) 1)
2908 (setq hcharset 'utf-8
2909 coding hcharset)))
2910 (if coding
2911 (if charset
2912 (progn
2913 (setq body
2914 (mm-charset-to-coding-system charset
2915 nil t))
2916 (if (eq coding body)
2917 (setq eheader (encode-coding-string
2918 (buffer-string) coding)
2919 title (when title
2920 (encode-coding-string
2921 title coding))
2922 body content)
2923 (setq charset 'utf-8
2924 eheader (encode-coding-string
2925 (buffer-string) charset)
2926 title (when title
2927 (encode-coding-string
2928 title charset))
2929 body (encode-coding-string
2930 (decode-coding-string
2931 content body)
2932 charset))))
2933 (setq charset hcharset
2934 eheader (encode-coding-string
2935 (buffer-string) coding)
2936 title (when title
2937 (encode-coding-string
2938 title coding))
2939 body content))
2940 (setq eheader (encode-coding-string
2941 (buffer-string) 'utf-8)
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 This command creates temporary files to pass HTML contents including
3025 images if any to the browser, and deletes them when exiting the group
3026 \(if you want)."
3027 ;; Cf. `mm-w3m-safe-url-regexp'
3028 (interactive "P")
3029 (if arg
3030 (gnus-summary-show-article)
3031 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3032 gnus-visible-headers))
3033 ;; As we insert a <hr>, there's no need for the body boundary.
3034 (gnus-treat-body-boundary nil))
3035 (gnus-summary-show-article)))
3036 (with-current-buffer gnus-article-buffer
3037 (let ((header (unless arg
3038 (save-restriction
3039 (widen)
3040 (buffer-substring-no-properties
3041 (goto-char (point-min))
3042 (if (search-forward "\n\n" nil t)
3043 (match-beginning 0)
3044 (goto-char (point-max))
3045 (skip-chars-backward "\t\n ")
3046 (point))))))
3047 parts)
3048 (set-buffer gnus-original-article-buffer)
3049 (setq parts (mm-dissect-buffer t t))
3050 ;; If singlepart, enforce a list.
3051 (when (and (bufferp (car parts))
3052 (stringp (car (mm-handle-type parts))))
3053 (setq parts (list parts)))
3054 ;; Process the list
3055 (unless (gnus-article-browse-html-parts parts header)
3056 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3057 (mm-destroy-parts parts)
3058 (unless arg
3059 (gnus-summary-show-article)))))
3061 (defun article-hide-list-identifiers ()
3062 "Remove list identifiers from the Subject header.
3063 The `gnus-list-identifiers' variable specifies what to do."
3064 (interactive)
3065 (let ((inhibit-point-motion-hooks t)
3066 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3067 (inhibit-read-only t))
3068 (when regexp
3069 (save-excursion
3070 (save-restriction
3071 (article-narrow-to-head)
3072 (goto-char (point-min))
3073 (while (re-search-forward
3074 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3075 nil t)
3076 (delete-region (match-beginning 2) (match-end 0))
3077 (beginning-of-line))
3078 (when (re-search-forward
3079 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3080 (delete-region (match-beginning 1) (match-end 1))))))))
3082 (defun article-hide-pem (&optional arg)
3083 "Toggle hiding of any PEM headers and signatures in the current article.
3084 If given a negative prefix, always show; if given a positive prefix,
3085 always hide."
3086 (interactive (gnus-article-hidden-arg))
3087 (unless (gnus-article-check-hidden-text 'pem arg)
3088 (save-excursion
3089 (let ((inhibit-read-only t) end)
3090 (goto-char (point-min))
3091 ;; Hide the horrendously ugly "header".
3092 (when (and (search-forward
3093 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3094 nil t)
3095 (setq end (1+ (match-beginning 0))))
3096 (gnus-add-wash-type 'pem)
3097 (gnus-article-hide-text-type
3099 (if (search-forward "\n\n" nil t)
3100 (match-end 0)
3101 (point-max))
3102 'pem)
3103 ;; Hide the trailer as well
3104 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3105 nil t)
3106 (gnus-article-hide-text-type
3107 (match-beginning 0) (match-end 0) 'pem)))))))
3109 (defun article-strip-banner ()
3110 "Strip the banners specified by the `banner' group parameter and by
3111 `gnus-article-address-banner-alist'."
3112 (interactive)
3113 (save-excursion
3114 (save-restriction
3115 (let ((inhibit-point-motion-hooks t))
3116 (when (gnus-parameter-banner gnus-newsgroup-name)
3117 (article-really-strip-banner
3118 (gnus-parameter-banner gnus-newsgroup-name)))
3119 (when gnus-article-address-banner-alist
3120 ;; Note that the From header is decoded here, so it is
3121 ;; required that the *-extract-address-components function
3122 ;; supports non-ASCII text.
3123 (let ((from (save-restriction
3124 (widen)
3125 (article-narrow-to-head)
3126 (mail-fetch-field "from"))))
3127 (when (and from
3128 (setq from
3129 (cadr (funcall gnus-extract-address-components
3130 from))))
3131 (catch 'found
3132 (dolist (pair gnus-article-address-banner-alist)
3133 (when (string-match (car pair) from)
3134 (throw 'found
3135 (article-really-strip-banner (cdr pair)))))))))))))
3137 (defun article-really-strip-banner (banner)
3138 "Strip the banner specified by the argument."
3139 (save-excursion
3140 (save-restriction
3141 (let ((inhibit-point-motion-hooks t)
3142 (gnus-signature-limit nil)
3143 (inhibit-read-only t))
3144 (article-goto-body)
3145 (cond
3146 ((eq banner 'signature)
3147 (when (gnus-article-narrow-to-signature)
3148 (widen)
3149 (forward-line -1)
3150 (delete-region (point) (point-max))))
3151 ((symbolp banner)
3152 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3153 (while (re-search-forward banner nil t)
3154 (delete-region (match-beginning 0) (match-end 0)))))
3155 ((stringp banner)
3156 (while (re-search-forward banner nil t)
3157 (delete-region (match-beginning 0) (match-end 0)))))))))
3159 (defun article-babel ()
3160 "Translate article using an online translation service."
3161 (interactive)
3162 (require 'babel)
3163 (gnus-with-article-buffer
3164 (when (article-goto-body)
3165 (let* ((start (point))
3166 (end (point-max))
3167 (orig (buffer-substring start end))
3168 (trans (babel-as-string orig)))
3169 (save-restriction
3170 (narrow-to-region start end)
3171 (delete-region start end)
3172 (insert trans))))))
3174 (defun article-hide-signature (&optional arg)
3175 "Hide the signature in the current article.
3176 If given a negative prefix, always show; if given a positive prefix,
3177 always hide."
3178 (interactive (gnus-article-hidden-arg))
3179 (unless (gnus-article-check-hidden-text 'signature arg)
3180 (save-excursion
3181 (save-restriction
3182 (let ((inhibit-read-only t))
3183 (when (gnus-article-narrow-to-signature)
3184 (gnus-article-hide-text-type
3185 (point-min) (point-max) 'signature))))))
3186 (gnus-set-mode-line 'article))
3188 (defun article-strip-headers-in-body ()
3189 "Strip offensive headers from bodies."
3190 (interactive)
3191 (save-excursion
3192 (article-goto-body)
3193 (let ((case-fold-search t))
3194 (when (looking-at "x-no-archive:")
3195 (gnus-delete-line)))))
3197 (defun article-strip-leading-blank-lines ()
3198 "Remove all blank lines from the beginning of the article."
3199 (interactive)
3200 (save-excursion
3201 (let ((inhibit-point-motion-hooks t)
3202 (inhibit-read-only t))
3203 (when (article-goto-body)
3204 (while (and (not (eobp))
3205 (looking-at "[ \t]*$"))
3206 (gnus-delete-line))))))
3208 (defun article-narrow-to-head ()
3209 "Narrow the buffer to the head of the message.
3210 Point is left at the beginning of the narrowed-to region."
3211 (narrow-to-region
3212 (goto-char (point-min))
3213 (cond
3214 ;; Absolutely no headers displayed.
3215 ((looking-at "\n")
3216 (point))
3217 ;; Normal headers.
3218 ((search-forward "\n\n" nil 1)
3219 (1- (point)))
3220 ;; Nothing but headers.
3222 (point-max))))
3223 (goto-char (point-min)))
3225 (defun article-goto-body ()
3226 "Place point at the start of the body."
3227 (goto-char (point-min))
3228 (cond
3229 ;; This variable is only bound when dealing with separate
3230 ;; MIME body parts.
3231 (article-goto-body-goes-to-point-min-p
3233 ((search-forward "\n\n" nil t)
3236 (goto-char (point-max))
3237 nil)))
3239 (defun article-strip-multiple-blank-lines ()
3240 "Replace consecutive blank lines with one empty line."
3241 (interactive)
3242 (save-excursion
3243 (let ((inhibit-point-motion-hooks t)
3244 (inhibit-read-only t))
3245 ;; First make all blank lines empty.
3246 (article-goto-body)
3247 (while (re-search-forward "^[ \t]+$" nil t)
3248 (unless (gnus-annotation-in-region-p
3249 (match-beginning 0) (match-end 0))
3250 (replace-match "" nil t)))
3251 ;; Then replace multiple empty lines with a single empty line.
3252 (article-goto-body)
3253 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3254 (unless (gnus-annotation-in-region-p
3255 (match-beginning 0) (match-end 0))
3256 (delete-region (match-beginning 1) (match-end 1)))))))
3258 (defun article-strip-leading-space ()
3259 "Remove all white space from the beginning of the lines in the article."
3260 (interactive)
3261 (save-excursion
3262 (let ((inhibit-point-motion-hooks t)
3263 (inhibit-read-only t))
3264 (article-goto-body)
3265 (while (re-search-forward "^[ \t]+" nil t)
3266 (replace-match "" t t)))))
3268 (defun article-strip-trailing-space ()
3269 "Remove all white space from the end of the lines in the article."
3270 (interactive)
3271 (save-excursion
3272 (let ((inhibit-point-motion-hooks t)
3273 (inhibit-read-only t))
3274 (article-goto-body)
3275 (while (re-search-forward "[ \t]+$" nil t)
3276 (replace-match "" t t)))))
3278 (defun article-strip-blank-lines ()
3279 "Strip leading, trailing and multiple blank lines."
3280 (interactive)
3281 (article-strip-leading-blank-lines)
3282 (article-remove-trailing-blank-lines)
3283 (article-strip-multiple-blank-lines))
3285 (defun article-strip-all-blank-lines ()
3286 "Strip all blank lines."
3287 (interactive)
3288 (save-excursion
3289 (let ((inhibit-point-motion-hooks t)
3290 (inhibit-read-only t))
3291 (article-goto-body)
3292 (while (re-search-forward "^[ \t]*\n" nil t)
3293 (replace-match "" t t)))))
3295 (defun gnus-article-narrow-to-signature ()
3296 "Narrow to the signature; return t if a signature is found, else nil."
3297 (let ((inhibit-point-motion-hooks t))
3298 (when (gnus-article-search-signature)
3299 (forward-line 1)
3300 ;; Check whether we have some limits to what we consider
3301 ;; to be a signature.
3302 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3303 (list gnus-signature-limit)))
3304 limit limited)
3305 (while (setq limit (pop limits))
3306 (if (or (and (integerp limit)
3307 (< (- (point-max) (point)) limit))
3308 (and (floatp limit)
3309 (< (count-lines (point) (point-max)) limit))
3310 (and (functionp limit)
3311 (funcall limit))
3312 (and (stringp limit)
3313 (not (re-search-forward limit nil t))))
3314 () ; This limit did not succeed.
3315 (setq limited t
3316 limits nil)))
3317 (unless limited
3318 (narrow-to-region (point) (point-max))
3319 t)))))
3321 (defun gnus-article-search-signature ()
3322 "Search the current buffer for the signature separator.
3323 Put point at the beginning of the signature separator."
3324 (let ((cur (point)))
3325 (goto-char (point-max))
3326 (if (if (stringp gnus-signature-separator)
3327 (re-search-backward gnus-signature-separator nil t)
3328 (let ((seps gnus-signature-separator))
3329 (while (and seps
3330 (not (re-search-backward (car seps) nil t)))
3331 (pop seps))
3332 seps))
3334 (goto-char cur)
3335 nil)))
3337 (defun gnus-article-hidden-arg ()
3338 "Return the current prefix arg as a number, or 0 if no prefix."
3339 (list (if current-prefix-arg
3340 (prefix-numeric-value current-prefix-arg)
3341 0)))
3343 (defun gnus-article-check-hidden-text (type arg)
3344 "Return nil if hiding is necessary.
3345 Arg can be nil or a number. nil and positive means hide, negative
3346 means show, 0 means toggle."
3347 (save-excursion
3348 (save-restriction
3349 (let ((hide (gnus-article-hidden-text-p type)))
3350 (cond
3351 ((or (null arg)
3352 (> arg 0))
3353 nil)
3354 ((< arg 0)
3355 (gnus-article-show-hidden-text type)
3358 (if (eq hide 'hidden)
3359 (progn
3360 (gnus-article-show-hidden-text type)
3362 nil)))))))
3364 (defun gnus-article-hidden-text-p (type)
3365 "Say whether the current buffer contains hidden text of type TYPE."
3366 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3367 (while (and pos
3368 (not (get-text-property pos 'invisible))
3369 (not (get-text-property pos 'dummy-invisible)))
3370 (setq pos
3371 (text-property-any (1+ pos) (point-max) 'article-type type)))
3372 (if pos
3373 'hidden
3374 nil)))
3376 (defun gnus-article-show-hidden-text (type &optional _dummy)
3377 "Show all hidden text of type TYPE.
3378 Originally it is hide instead of DUMMY."
3379 (let ((inhibit-read-only t)
3380 (inhibit-point-motion-hooks t))
3381 (gnus-remove-text-properties-when
3382 'article-type type
3383 (point-min) (point-max)
3384 (cons 'article-type (cons type
3385 gnus-hidden-properties)))
3386 (gnus-delete-wash-type type)))
3388 (defconst article-time-units
3389 `((year . ,(* 365.25 24 60 60))
3390 (week . ,(* 7 24 60 60))
3391 (day . ,(* 24 60 60))
3392 (hour . ,(* 60 60))
3393 (minute . 60)
3394 (second . 1))
3395 "Mapping from time units to seconds.")
3397 (defun gnus-article-forward-header ()
3398 "Move point to the start of the next header.
3399 If the current header is a continuation header, this can be several
3400 lines forward."
3401 (let ((ended nil))
3402 (while (not ended)
3403 (forward-line 1)
3404 (if (looking-at "[ \t]+[^ \t]")
3405 (forward-line 1)
3406 (setq ended t)))))
3408 (defun article-treat-date ()
3409 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3410 (with-current-buffer gnus-summary-buffer
3411 gnus-article-date-headers)
3412 gnus-article-date-headers)
3415 (defun article-date-ut (&optional type _highlight date-position)
3416 "Convert DATE date to TYPE in the current article.
3417 The default type is `ut'. See `gnus-article-date-headers' for
3418 possible values."
3419 (interactive (list 'ut t))
3420 (let* ((case-fold-search t)
3421 (inhibit-read-only t)
3422 (inhibit-point-motion-hooks t)
3423 (visible-date (mail-fetch-field "Date"))
3424 pos date bface eface)
3425 (save-excursion
3426 (if date-position
3427 (progn
3428 (goto-char date-position)
3429 (setq date (get-text-property (point) 'original-date))
3430 (beginning-of-line)
3431 (when (looking-at "[^:]+:[\t ]*")
3432 (setq bface (get-text-property (match-beginning 0) 'face)
3433 eface (get-text-property (match-end 0) 'face)))
3434 (goto-char date-position)
3435 (delete-region
3436 (or (and (bolp) date-position)
3437 ;; There might be space(s) added for line unfolding.
3438 (and (get-text-property date-position 'gnus-date-type)
3439 (< (skip-chars-backward "\t ") 0)
3440 (text-property-any (point) date-position
3441 'gnus-date-type nil))
3442 date-position)
3443 (progn (gnus-article-forward-header) (point)))
3444 (article-transform-date date type bface eface))
3445 (save-restriction
3446 (widen)
3447 (goto-char (point-min))
3448 (while (or (get-text-property (setq pos (point)) 'original-date)
3449 (and (setq pos (next-single-property-change
3450 (point) 'original-date))
3451 (goto-char pos)))
3452 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3453 (1+ (match-beginning 0))
3454 (point-max)))
3455 (while (setq pos (text-property-not-all pos (point-max)
3456 'gnus-date-type nil))
3457 (setq date (get-text-property pos 'original-date))
3458 (goto-char pos)
3459 (when (looking-at "[^:]+:[\t ]*")
3460 (setq bface (get-text-property (match-beginning 0) 'face)
3461 eface (get-text-property (match-end 0) 'face)))
3462 ;; Note: a feature like `gnus-treat-unfold-headers' breaks
3463 ;; the continuity of text props of a multi-line Date header,
3464 ;; that a user-defined date format might create, by adding
3465 ;; spaces. So, don't rely on gnus-date-type or original-date
3466 ;; text prop in case of searching for the header boundary.
3467 (delete-region pos (progn
3468 (gnus-article-forward-header)
3469 (point))))
3470 (unless date ;; the 1st time
3471 (goto-char (point-min))
3472 (while (re-search-forward "^Date:[\t ]*" nil t)
3473 (setq date (get-text-property (match-beginning 0)
3474 'original-date)
3475 bface (get-text-property (match-beginning 0) 'face)
3476 eface (get-text-property (match-end 0) 'face))
3477 (delete-region (point-at-bol) (progn
3478 (gnus-article-forward-header)
3479 (point)))))
3480 (when (and (not date)
3481 visible-date)
3482 (setq date visible-date))
3483 (when date
3484 (article-transform-date date type bface eface))
3485 (goto-char (point-max))
3486 (widen)))))))
3488 (defun article-transform-date (date type bface eface)
3489 (let (begin date-line)
3490 (dolist (this-type (cond ((null type)
3491 (list 'ut))
3492 ((atom type)
3493 (list type))
3495 type)))
3496 (setq begin (point)
3497 date-line (article-make-date-line date (or this-type 'ut)))
3498 (if (and (eq this-type 'user-defined) (bolp)
3499 ;; Test if this is not a continuation.
3500 (not (get-text-property
3501 (prog2 (end-of-line 0) (point) (goto-char begin))
3502 'gnus-date-type)))
3503 (progn
3504 (string-match "\\`\\([^\t\n :]+:\\)?[\t ]*" date-line)
3505 (if (match-beginning 1)
3506 (insert date-line "\n")
3507 ;; This user-defined date seems to intend to be a continuation
3508 ;; line of a multi-line Date header like this:
3509 ;; Date: Thu, Jan 1 00:00:00 1970 +0000
3510 ;; (47 years, 5 months, 20 days ago)
3511 (insert "Date: " (substring date-line (match-end 0)) "\n")))
3512 (insert date-line "\n"))
3513 (add-text-properties begin (point) (list 'original-date date
3514 'gnus-date-type this-type))
3515 (goto-char begin)
3516 ;; Do highlighting.
3517 (beginning-of-line)
3518 (looking-at
3519 "\\([^\n:]+:\\)?[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3520 (when (and bface (match-beginning 1))
3521 (put-text-property (match-beginning 1) (match-end 1) 'face bface))
3522 (when (match-beginning 2)
3523 (when eface
3524 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3525 (while (and (zerop (forward-line 1))
3526 (looking-at
3527 "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3528 (when (and eface (match-beginning 1))
3529 (put-text-property (match-beginning 1) (match-end 1)
3530 'face eface)))))))
3532 (defun article-make-date-line (date type)
3533 "Return a DATE line of TYPE."
3534 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3535 combined-lapsed))
3536 (error "Unknown conversion type: %s" type))
3537 (condition-case ()
3538 (let ((time (ignore-errors (date-to-time date))))
3539 (cond
3540 ;; Convert to the local timezone.
3541 ((eq type 'local)
3542 (concat "Date: " (message-make-date time)))
3543 ;; Convert to Universal Time.
3544 ((eq type 'ut)
3545 (concat "Date: "
3546 (substring
3547 (message-make-date
3548 (let* ((e (parse-time-string date))
3549 (tm (apply 'encode-time e))
3550 (ms (car tm))
3551 (ls (- (cadr tm) (car (current-time-zone time)))))
3552 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3553 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3554 (t (list ms ls)))))
3555 0 -5)
3556 "UT"))
3557 ;; Get the original date from the article.
3558 ((eq type 'original)
3559 (concat "Date: " (if (string-match "\n+$" date)
3560 (substring date 0 (match-beginning 0))
3561 date)))
3562 ;; Let the user define the format.
3563 ((eq type 'user-defined)
3564 (let ((format (or (condition-case nil
3565 (with-current-buffer gnus-summary-buffer
3566 gnus-article-time-format)
3567 (error nil))
3568 gnus-article-time-format)))
3569 (if (functionp format)
3570 (funcall format time)
3571 (concat "Date: " (format-time-string format time)))))
3572 ;; ISO 8601.
3573 ((eq type 'iso8601)
3574 (let ((tz (car (current-time-zone time))))
3575 (concat
3576 "Date: "
3577 (format-time-string "%Y%m%dT%H%M%S" time)
3578 (format "%s%02d%02d"
3579 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3580 (/ (% (abs tz) 3600) 60)))))
3581 ;; Do a lapsed format.
3582 ((eq type 'lapsed)
3583 (concat "Date: " (article-lapsed-string time)))
3584 ;; A combined date/lapsed format.
3585 ((eq type 'combined-lapsed)
3586 (let ((date-string (article-make-date-line date 'original))
3587 (segments 3)
3588 lapsed-string)
3589 (while (and
3590 time
3591 (setq lapsed-string
3592 (concat " (" (article-lapsed-string time segments) ")"))
3593 (> (+ (length date-string)
3594 (length lapsed-string))
3595 (+ fill-column 6))
3596 (> segments 0))
3597 (setq segments (1- segments)))
3598 (if (> segments 0)
3599 (concat date-string lapsed-string)
3600 date-string)))
3601 ;; Display the date in proper English
3602 ((eq type 'english)
3603 (let ((dtime (decode-time time)))
3604 (concat
3605 "Date: the "
3606 (number-to-string (nth 3 dtime))
3607 (let ((digit (% (nth 3 dtime) 10)))
3608 (cond
3609 ((memq (nth 3 dtime) '(11 12 13)) "th")
3610 ((= digit 1) "st")
3611 ((= digit 2) "nd")
3612 ((= digit 3) "rd")
3613 (t "th")))
3614 " of "
3615 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3617 (number-to-string (nth 5 dtime))
3618 " at "
3619 (format "%02d" (nth 2 dtime))
3621 (format "%02d" (nth 1 dtime)))))))
3622 (foo
3623 (format "Date: %s (from Gnus)" date))))
3625 (defun article-lapsed-string (time &optional max-segments)
3626 ;; If the date is seriously mangled, the timezone functions are
3627 ;; liable to bug out, so we ignore all errors.
3628 (let* ((real-time (time-subtract nil time))
3629 (real-sec (and real-time
3630 (+ (* (float (car real-time)) 65536)
3631 (cadr real-time))))
3632 (sec (and real-time (abs real-sec)))
3633 (segments 0)
3634 num prev)
3635 (unless max-segments
3636 (setq max-segments (length article-time-units)))
3637 (cond
3638 ((null real-time)
3639 "Unknown")
3640 ((zerop sec)
3641 "Now")
3643 (concat
3644 ;; This is a bit convoluted, but basically we go
3645 ;; through the time units for years, weeks, etc,
3646 ;; and divide things to see whether that results
3647 ;; in positive answers.
3648 (mapconcat
3649 (lambda (unit)
3650 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3651 (>= segments max-segments))
3652 ;; The (remaining) seconds are too few to
3653 ;; be divided into this time unit.
3655 ;; It's big enough, so we output it.
3656 (setq sec (- sec (* num (cdr unit))))
3657 (prog1
3658 (concat (if prev ", " "") (int-to-string
3659 (floor num))
3660 " " (symbol-name (car unit))
3661 (if (> num 1) "s" ""))
3662 (setq prev t
3663 segments (1+ segments)))))
3664 article-time-units "")
3665 ;; If dates are odd, then it might appear like the
3666 ;; article was sent in the future.
3667 (if (> real-sec 0)
3668 " ago"
3669 " in the future"))))))
3671 (defun article-date-local (&optional highlight)
3672 "Convert the current article date to the local timezone."
3673 (interactive (list t))
3674 (article-date-ut 'local highlight))
3676 (defun article-date-english (&optional highlight)
3677 "Convert the current article date to something that is proper English."
3678 (interactive (list t))
3679 (article-date-ut 'english highlight))
3681 (defun article-date-original (&optional highlight)
3682 "Convert the current article date to what it was originally.
3683 This is only useful if you have used some other date conversion
3684 function and want to see what the date was before converting."
3685 (interactive (list t))
3686 (article-date-ut 'original highlight))
3688 (defun article-date-lapsed (&optional highlight)
3689 "Convert the current article date to time lapsed since it was sent."
3690 (interactive (list t))
3691 (article-date-ut 'lapsed highlight))
3693 (defun article-date-combined-lapsed (&optional highlight)
3694 "Convert the current article date to time lapsed since it was sent."
3695 (interactive (list t))
3696 (article-date-ut 'combined-lapsed highlight))
3698 (defun article-update-date-lapsed ()
3699 "Function to be run from a timer to update the lapsed time line."
3700 (save-match-data
3701 (let ((buffer (current-buffer)))
3702 (ignore-errors
3703 (walk-windows
3704 (lambda (w)
3705 (set-buffer (window-buffer w))
3706 (when (derived-mode-p 'gnus-article-mode)
3707 (let ((old-line (count-lines (point-min) (point)))
3708 (old-column (- (point) (line-beginning-position)))
3709 (window-start (window-start w))
3710 (pos (point-min))
3711 type next end)
3712 (while (setq pos (text-property-not-all pos (point-max)
3713 'gnus-date-type nil))
3714 (setq next (or (next-single-property-change pos
3715 'gnus-date-type)
3716 (point-max)))
3717 (setq type (get-text-property pos 'gnus-date-type))
3718 (when (memq type '(lapsed combined-lapsed user-defined))
3719 (article-date-ut type t pos)
3720 (setq end (or (next-single-property-change pos
3721 'gnus-date-type)
3722 (point-max)))
3723 (when window-start
3724 (if (/= window-start next)
3725 (setq window-start nil)
3726 (set-window-start w end)))
3727 (setq next end))
3728 (setq pos next))
3729 (goto-char (point-min))
3730 (when (> old-column 0)
3731 (setq old-line (1- old-line)))
3732 (forward-line old-line)
3733 (end-of-line)
3734 (when (> (current-column) old-column)
3735 (beginning-of-line)
3736 (forward-char old-column)))))
3737 nil 'visible))
3738 (set-buffer buffer))))
3740 (defun gnus-start-date-timer (&optional n)
3741 "Start a timer to update the Date headers in the article buffers.
3742 The numerical prefix says how frequently (in seconds) the function
3743 is to run."
3744 (interactive "p")
3745 (unless n
3746 (setq n 1))
3747 (gnus-stop-date-timer)
3748 (setq article-lapsed-timer
3749 (run-at-time 1 n 'article-update-date-lapsed)))
3751 (defun gnus-stop-date-timer ()
3752 "Stop the Date timer."
3753 (interactive)
3754 (when article-lapsed-timer
3755 (nnheader-cancel-timer article-lapsed-timer)
3756 (setq article-lapsed-timer nil)))
3758 (defun article-date-user (&optional highlight)
3759 "Convert the current article date to the user-defined format.
3760 This format is defined by the `gnus-article-time-format' variable."
3761 (interactive (list t))
3762 (article-date-ut 'user-defined highlight))
3764 (defun article-date-iso8601 (&optional highlight)
3765 "Convert the current article date to ISO8601."
3766 (interactive (list t))
3767 (article-date-ut 'iso8601 highlight))
3769 (defmacro gnus-article-save-original-date (&rest forms)
3770 "Save the original date as a text property and evaluate FORMS."
3771 `(let* ((case-fold-search t)
3772 (start (progn
3773 (goto-char (point-min))
3774 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3775 (not (bolp)))
3776 (match-end 0))))
3777 (date (when (and start
3778 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3779 nil t))
3780 (buffer-substring-no-properties start
3781 (match-beginning 0)))))
3782 (goto-char (point-max))
3783 (skip-chars-backward "\n")
3784 (put-text-property (point-min) (point) 'original-date date)
3785 ,@forms
3786 (goto-char (point-max))
3787 (skip-chars-backward "\n")
3788 (put-text-property (point-min) (point) 'original-date date)))
3790 ;; (defun article-show-all ()
3791 ;; "Show all hidden text in the article buffer."
3792 ;; (interactive)
3793 ;; (save-excursion
3794 ;; (let ((inhibit-read-only t))
3795 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3797 (defun article-remove-leading-whitespace ()
3798 "Remove excessive whitespace from all headers."
3799 (interactive)
3800 (save-excursion
3801 (save-restriction
3802 (let ((inhibit-read-only t))
3803 (article-narrow-to-head)
3804 (goto-char (point-min))
3805 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3806 (delete-region (match-beginning 1) (match-end 1)))))))
3808 (defun article-emphasize (&optional arg)
3809 "Emphasize text according to `gnus-emphasis-alist'."
3810 (interactive (gnus-article-hidden-arg))
3811 (unless (gnus-article-check-hidden-text 'emphasis arg)
3812 (save-excursion
3813 (let ((alist (or
3814 (condition-case nil
3815 (with-current-buffer gnus-summary-buffer
3816 gnus-article-emphasis-alist)
3817 (error))
3818 gnus-emphasis-alist))
3819 (inhibit-read-only t)
3820 (props (append '(article-type emphasis)
3821 gnus-hidden-properties))
3822 regexp elem beg invisible visible face)
3823 (article-goto-body)
3824 (setq beg (point))
3825 (while (setq elem (pop alist))
3826 (goto-char beg)
3827 (setq regexp (car elem)
3828 invisible (nth 1 elem)
3829 visible (nth 2 elem)
3830 face (nth 3 elem))
3831 (while (re-search-forward regexp nil t)
3832 (when (and (match-beginning visible) (match-beginning invisible))
3833 (gnus-article-hide-text
3834 (match-beginning invisible) (match-end invisible) props)
3835 (gnus-article-unhide-text-type
3836 (match-beginning visible) (match-end visible) 'emphasis)
3837 (gnus-put-overlay-excluding-newlines
3838 (match-beginning visible) (match-end visible) 'face face)
3839 (gnus-add-wash-type 'emphasis)
3840 (goto-char (match-end invisible)))))))))
3842 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3843 "Setup newsgroup emphasis alist."
3844 (unless gnus-article-emphasis-alist
3845 (let ((name (and gnus-newsgroup-name
3846 (gnus-group-real-name gnus-newsgroup-name))))
3847 (make-local-variable 'gnus-article-emphasis-alist)
3848 (setq gnus-article-emphasis-alist
3849 (nconc
3850 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3851 (while (setq elem (pop alist))
3852 (when (and name (string-match (car elem) name))
3853 (setq alist nil
3854 highlight (copy-sequence (cdr elem)))))
3855 highlight)
3856 (copy-sequence highlight-words)
3857 (if gnus-newsgroup-name
3858 (copy-sequence (gnus-group-find-parameter
3859 gnus-newsgroup-name 'highlight-words t)))
3860 gnus-emphasis-alist)))))
3862 (defvar gnus-summary-article-menu)
3863 (defvar gnus-summary-post-menu)
3865 ;;; Saving functions.
3867 (defun gnus-article-save (save-buffer file &optional num)
3868 "Save the currently selected article."
3869 (when (or (get gnus-default-article-saver :headers)
3870 (not gnus-save-all-headers))
3871 ;; Remove headers according to `gnus-saved-headers' or the value
3872 ;; of the `:headers' property that the saver function might have.
3873 (let ((gnus-visible-headers
3874 (or (symbol-value (get gnus-default-article-saver :headers))
3875 gnus-saved-headers gnus-visible-headers))
3876 ;; Ignore group parameter. See `article-hide-headers'.
3877 (gnus-summary-buffer nil))
3878 (with-current-buffer save-buffer
3879 (article-hide-headers 1 t))))
3880 (save-window-excursion
3881 (if (not gnus-default-article-saver)
3882 (error "No default saver is defined")
3883 ;; !!! Magic! The saving functions all save
3884 ;; `gnus-save-article-buffer' (or so they think), but we
3885 ;; bind that variable to our save-buffer.
3886 (set-buffer gnus-article-buffer)
3887 (let* ((gnus-save-article-buffer save-buffer)
3888 (filename
3889 (cond
3890 ((not gnus-prompt-before-saving) 'default)
3891 ((eq gnus-prompt-before-saving 'always) nil)
3892 (t file)))
3893 (gnus-number-of-articles-to-be-saved
3894 (when (eq gnus-prompt-before-saving t)
3895 num))) ; Magic
3896 (set-buffer gnus-article-current-summary)
3897 (funcall gnus-default-article-saver filename)))))
3899 (defun gnus-read-save-file-name (prompt &optional filename
3900 function group headers variable
3901 dir-var)
3902 (let ((default-name
3903 (funcall function group headers (symbol-value variable)))
3904 result)
3905 (setq result
3906 (expand-file-name
3907 (cond
3908 ((eq filename 'default)
3909 default-name)
3910 ((eq filename t)
3911 default-name)
3912 (filename filename)
3914 (when (symbol-value dir-var)
3915 (setq default-name (expand-file-name
3916 (file-name-nondirectory default-name)
3917 (symbol-value dir-var))))
3918 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3919 (prompt
3920 (format prompt
3921 (if (and gnus-number-of-articles-to-be-saved
3922 (> gnus-number-of-articles-to-be-saved 1))
3923 (format "these %d articles"
3924 gnus-number-of-articles-to-be-saved)
3925 "this article")))
3926 (file
3927 ;; Let the split methods have their say.
3928 (cond
3929 ;; No split name was found.
3930 ((null split-name)
3931 (read-file-name
3932 (concat prompt " (default "
3933 (file-name-nondirectory default-name) "): ")
3934 (file-name-directory default-name)
3935 default-name))
3936 ;; A single group name is returned.
3937 ((stringp split-name)
3938 (setq default-name
3939 (funcall function split-name headers
3940 (symbol-value variable)))
3941 (read-file-name
3942 (concat prompt " (default "
3943 (file-name-nondirectory default-name) "): ")
3944 (file-name-directory default-name)
3945 default-name))
3946 ;; A single split name was found
3947 ((= 1 (length split-name))
3948 (let* ((name (expand-file-name
3949 (car split-name)
3950 gnus-article-save-directory))
3951 (dir (cond ((file-directory-p name)
3952 (file-name-as-directory name))
3953 ((file-exists-p name) name)
3954 (t gnus-article-save-directory))))
3955 (read-file-name
3956 (concat prompt " (default " name "): ")
3957 dir name)))
3958 ;; A list of splits was found.
3960 (setq split-name (nreverse split-name))
3961 (let (result)
3962 (let ((file-name-history
3963 (nconc split-name file-name-history)))
3964 (setq result
3965 (expand-file-name
3966 (read-file-name
3967 (concat prompt " (`M-p' for defaults): ")
3968 gnus-article-save-directory
3969 (car split-name))
3970 gnus-article-save-directory)))
3971 (car (push result file-name-history)))))))
3972 ;; Create the directory.
3973 (gnus-make-directory (file-name-directory file))
3974 ;; If we have read a directory, we append the default file name.
3975 (when (file-directory-p file)
3976 (setq file (expand-file-name (file-name-nondirectory
3977 default-name)
3978 (file-name-as-directory file))))
3979 ;; Possibly translate some characters.
3980 (nnheader-translate-file-chars file))))))
3981 (gnus-make-directory (file-name-directory result))
3982 (when variable
3983 (set variable result))
3984 (when dir-var
3985 (set dir-var (file-name-directory result)))
3986 result))
3988 (defun gnus-article-archive-name (_group)
3989 "Return the first instance of an \"Archive-name\" in the current buffer."
3990 (let ((case-fold-search t))
3991 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3992 (nnheader-concat gnus-article-save-directory
3993 (match-string 1)))))
3995 (defun gnus-article-nndoc-name (group)
3996 "If GROUP is an nndoc group, return the name of the parent group."
3997 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3998 (gnus-group-get-parameter group 'save-article-group)))
4000 (defun gnus-summary-save-in-rmail (&optional filename)
4001 "Append this article to Rmail file.
4002 Optional argument FILENAME specifies file name.
4003 Directory to save to is default to `gnus-article-save-directory'."
4004 (setq filename (gnus-read-save-file-name
4005 "Save %s in rmail file" filename
4006 gnus-rmail-save-name gnus-newsgroup-name
4007 gnus-current-headers 'gnus-newsgroup-last-rmail))
4008 (with-current-buffer gnus-save-article-buffer
4009 (save-excursion
4010 (save-restriction
4011 (widen)
4012 ;; Note that unlike gnus-summary-save-in-mail, there is no
4013 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4014 ;; not use Babyl.
4015 (gnus-output-to-rmail filename))))
4016 filename)
4018 (defun gnus-summary-save-in-mail (&optional filename)
4019 "Append this article to Unix mail file.
4020 Optional argument FILENAME specifies file name.
4021 Directory to save to is default to `gnus-article-save-directory'."
4022 (setq filename (gnus-read-save-file-name
4023 "Save %s in Unix mail file" filename
4024 gnus-mail-save-name gnus-newsgroup-name
4025 gnus-current-headers 'gnus-newsgroup-last-mail))
4026 (with-current-buffer gnus-save-article-buffer
4027 (save-excursion
4028 (save-restriction
4029 (widen)
4030 (if (and (file-readable-p filename)
4031 (file-regular-p filename)
4032 (mail-file-babyl-p filename))
4033 (gnus-output-to-rmail filename)
4034 (gnus-output-to-mail filename)))))
4035 filename)
4037 (put 'gnus-summary-save-in-file :decode t)
4038 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4039 (defun gnus-summary-save-in-file (&optional filename overwrite)
4040 "Append this article to file.
4041 Optional argument FILENAME specifies file name.
4042 Directory to save to is default to `gnus-article-save-directory'."
4043 (setq filename (gnus-read-save-file-name
4044 "Save %s in file" filename
4045 gnus-file-save-name gnus-newsgroup-name
4046 gnus-current-headers 'gnus-newsgroup-last-file))
4047 (with-current-buffer gnus-save-article-buffer
4048 (save-excursion
4049 (save-restriction
4050 (widen)
4051 (when (and overwrite
4052 (file-exists-p filename))
4053 (delete-file filename))
4054 (gnus-output-to-file filename))))
4055 filename)
4057 (put 'gnus-summary-write-to-file :decode t)
4058 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4059 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4060 (defun gnus-summary-write-to-file (&optional filename)
4061 "Write this article to a file, overwriting it if the file exists.
4062 Optional argument FILENAME specifies file name.
4063 The directory to save in defaults to `gnus-article-save-directory'."
4064 (setq filename (gnus-read-save-file-name
4065 "Save %s in file" filename
4066 gnus-file-save-name gnus-newsgroup-name
4067 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4068 (gnus-summary-save-in-file filename t))
4070 (put 'gnus-summary-save-body-in-file :decode t)
4071 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4072 "Append this article body to a file.
4073 Optional argument FILENAME specifies file name.
4074 The directory to save in defaults to `gnus-article-save-directory'."
4075 (setq filename (gnus-read-save-file-name
4076 "Save %s body in file" filename
4077 gnus-file-save-name gnus-newsgroup-name
4078 gnus-current-headers 'gnus-newsgroup-last-file))
4079 (with-current-buffer gnus-save-article-buffer
4080 (save-excursion
4081 (save-restriction
4082 (widen)
4083 (when (article-goto-body)
4084 (narrow-to-region (point) (point-max)))
4085 (when (and overwrite
4086 (file-exists-p filename))
4087 (delete-file filename))
4088 (gnus-output-to-file filename))))
4089 filename)
4091 (put 'gnus-summary-write-body-to-file :decode t)
4092 (put 'gnus-summary-write-body-to-file
4093 :function 'gnus-summary-save-body-in-file)
4094 (defun gnus-summary-write-body-to-file (&optional filename)
4095 "Write this article body to a file, overwriting it if the file exists.
4096 Optional argument FILENAME specifies file name.
4097 The directory to save in defaults to `gnus-article-save-directory'."
4098 (setq filename (gnus-read-save-file-name
4099 "Save %s body in file" filename
4100 gnus-file-save-name gnus-newsgroup-name
4101 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4102 (gnus-summary-save-body-in-file filename t))
4104 (put 'gnus-summary-save-in-pipe :decode t)
4105 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4106 (defun gnus-summary-save-in-pipe (&optional command raw)
4107 "Pipe this article to subprocess COMMAND.
4108 Valid values for COMMAND include:
4109 a string
4110 The executable command name and possibly arguments.
4112 You will be prompted for the command in the minibuffer.
4113 the symbol `default'
4114 It will be replaced with the command which the variable
4115 `gnus-summary-pipe-output-default-command' holds or the command
4116 last used for saving.
4117 Non-nil value for RAW overrides `:decode' and `:headers' properties
4118 and the raw article including all headers will be piped."
4119 (let ((article (gnus-summary-article-number))
4120 (decode (unless raw
4121 (get 'gnus-summary-save-in-pipe :decode)))
4122 save-buffer default)
4123 (if article
4124 (if (vectorp (gnus-summary-article-header article))
4125 (save-current-buffer
4126 (gnus-summary-select-article decode decode nil article)
4127 (insert-buffer-substring
4128 (prog1
4129 (if decode
4130 gnus-article-buffer
4131 gnus-original-article-buffer)
4132 (setq save-buffer
4133 (nnheader-set-temp-buffer " *Gnus Save*"))))
4134 ;; Remove unwanted headers.
4135 (when (and (not raw)
4136 (or (get 'gnus-summary-save-in-pipe :headers)
4137 (not gnus-save-all-headers)))
4138 (let ((gnus-visible-headers
4139 (or (symbol-value (get 'gnus-summary-save-in-pipe
4140 :headers))
4141 gnus-saved-headers gnus-visible-headers))
4142 (gnus-summary-buffer nil))
4143 (article-hide-headers 1 t))))
4144 (error "%d is not a real article" article))
4145 (error "No article to pipe"))
4146 (setq default (or gnus-summary-pipe-output-default-command
4147 gnus-last-shell-command))
4148 (unless (stringp command)
4149 (setq command
4150 (if (and (eq command 'default) default)
4151 default
4152 (read-shell-command "Shell command on this article: " default))))
4153 (when (string-equal command "")
4154 (if default
4155 (setq command default)
4156 (error "A command is required")))
4157 (with-current-buffer save-buffer
4158 (save-restriction
4159 (widen)
4160 (shell-command-on-region (point-min) (point-max) command nil)))
4161 (gnus-kill-buffer save-buffer))
4162 (setq gnus-summary-pipe-output-default-command command))
4164 (defun gnus-summary-pipe-to-muttprint (&optional command)
4165 "Pipe this article to muttprint."
4166 (unless (stringp command)
4167 (setq command (read-string
4168 "Print using command: " gnus-summary-muttprint-program
4169 nil gnus-summary-muttprint-program)))
4170 (let ((gnus-summary-pipe-output-default-command
4171 gnus-summary-pipe-output-default-command))
4172 (gnus-summary-save-in-pipe command))
4173 (setq gnus-summary-muttprint-program command))
4175 ;;; Article file names when saving.
4177 (defun gnus-capitalize-newsgroup (newsgroup)
4178 "Capitalize NEWSGROUP name."
4179 (when (not (zerop (length newsgroup)))
4180 (concat (char-to-string (upcase (aref newsgroup 0)))
4181 (substring newsgroup 1))))
4183 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4184 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4185 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4186 Otherwise, it is like ~/News/news/group/num."
4187 (let ((default
4188 (expand-file-name
4189 (concat (if (gnus-use-long-file-name 'not-save)
4190 (gnus-capitalize-newsgroup newsgroup)
4191 (gnus-newsgroup-directory-form newsgroup))
4192 "/" (int-to-string (mail-header-number headers)))
4193 gnus-article-save-directory)))
4194 (if (and last-file
4195 (string-equal (file-name-directory default)
4196 (file-name-directory last-file))
4197 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4198 default
4199 (or last-file default))))
4201 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4202 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4203 If variable `gnus-use-long-file-name' is non-nil, it is
4204 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4205 (let ((default
4206 (expand-file-name
4207 (concat (if (gnus-use-long-file-name 'not-save)
4208 newsgroup
4209 (gnus-newsgroup-directory-form newsgroup))
4210 "/" (int-to-string (mail-header-number headers)))
4211 gnus-article-save-directory)))
4212 (if (and last-file
4213 (string-equal (file-name-directory default)
4214 (file-name-directory last-file))
4215 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4216 default
4217 (or last-file default))))
4219 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4220 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4221 If variable `gnus-use-long-file-name' is non-nil, it is
4222 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4223 (or last-file
4224 (expand-file-name
4225 (if (gnus-use-long-file-name 'not-save)
4226 newsgroup
4227 (file-relative-name
4228 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4229 default-directory))
4230 gnus-article-save-directory)))
4232 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4233 "Generate file name from sender."
4234 (let ((from (mail-header-from headers)))
4235 (expand-file-name
4236 (if (and from (string-match "\\([^ <]+\\)@" from))
4237 (match-string 1 from)
4238 "nobody")
4239 gnus-article-save-directory)))
4241 (defun article-verify-x-pgp-sig ()
4242 "Verify X-PGP-Sig."
4243 ;; <https://ftp.isc.org/pub/pgpcontrol/FORMAT>
4244 (interactive)
4245 (if (gnus-buffer-live-p gnus-original-article-buffer)
4246 (let ((sig (with-current-buffer gnus-original-article-buffer
4247 (gnus-fetch-field "X-PGP-Sig")))
4248 items info headers)
4249 (when (and sig
4250 mml2015-use
4251 (mml2015-clear-verify-function))
4252 (with-temp-buffer
4253 (insert-buffer-substring gnus-original-article-buffer)
4254 (setq items (split-string sig))
4255 (message-narrow-to-head)
4256 (let ((inhibit-point-motion-hooks t)
4257 (case-fold-search t))
4258 ;; Don't verify multiple headers.
4259 (setq headers (mapconcat (lambda (header)
4260 (concat header ": "
4261 (mail-fetch-field header)
4262 "\n"))
4263 (split-string (nth 1 items) ",") "")))
4264 (delete-region (point-min) (point-max))
4265 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4266 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4267 (insert headers)
4268 (widen)
4269 (forward-line)
4270 (while (not (eobp))
4271 (if (looking-at "^-")
4272 (insert "- "))
4273 (forward-line))
4274 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4275 (insert "Version: " (car items) "\n\n")
4276 (insert (mapconcat 'identity (cddr items) "\n"))
4277 (insert "\n-----END PGP SIGNATURE-----\n")
4278 (let ((mm-security-handle (list (format "multipart/signed"))))
4279 (mml2015-clean-buffer)
4280 (let ((coding-system-for-write (or gnus-newsgroup-charset
4281 'iso-8859-1)))
4282 (funcall (mml2015-clear-verify-function)))
4283 (setq info
4284 (or (mm-handle-multipart-ctl-parameter
4285 mm-security-handle 'gnus-details)
4286 (mm-handle-multipart-ctl-parameter
4287 mm-security-handle 'gnus-info)))))
4288 (when info
4289 (let ((inhibit-read-only t) bface eface)
4290 (save-restriction
4291 (message-narrow-to-head)
4292 (goto-char (point-max))
4293 (forward-line -1)
4294 (setq bface (get-text-property (point-at-bol) 'face)
4295 eface (get-text-property (1- (point-at-eol)) 'face))
4296 (message-remove-header "X-Gnus-PGP-Verify")
4297 (if (re-search-forward "^X-PGP-Sig:" nil t)
4298 (forward-line)
4299 (goto-char (point-max)))
4300 (narrow-to-region (point) (point))
4301 (insert "X-Gnus-PGP-Verify: " info "\n")
4302 (goto-char (point-min))
4303 (forward-line)
4304 (while (not (eobp))
4305 (if (not (looking-at "^[ \t]"))
4306 (insert " "))
4307 (forward-line))
4308 ;; Do highlighting.
4309 (goto-char (point-min))
4310 (when (looking-at "\\([^:]+\\): *")
4311 (put-text-property (match-beginning 1) (1+ (match-end 1))
4312 'face bface)
4313 (put-text-property (match-end 0) (point-max)
4314 'face eface)))))))))
4316 (defun article-verify-cancel-lock ()
4317 "Verify Cancel-Lock header."
4318 (interactive)
4319 (if (gnus-buffer-live-p gnus-original-article-buffer)
4320 (canlock-verify gnus-original-article-buffer)))
4322 (eval-and-compile
4323 (mapc
4324 (lambda (func)
4325 (let (afunc gfunc)
4326 (if (consp func)
4327 (setq afunc (car func)
4328 gfunc (cdr func))
4329 (setq afunc func
4330 gfunc (intern (format "gnus-%s" func))))
4331 (defalias gfunc
4332 (when (fboundp afunc)
4333 `(lambda (&optional interactive &rest args)
4334 ,(documentation afunc t)
4335 (interactive (list t))
4336 (with-current-buffer gnus-article-buffer
4337 (if interactive
4338 (call-interactively ',afunc)
4339 (apply ',afunc args))))))))
4340 '(article-hide-headers
4341 article-verify-x-pgp-sig
4342 article-verify-cancel-lock
4343 article-hide-boring-headers
4344 article-treat-overstrike
4345 article-treat-ansi-sequences
4346 article-fill-long-lines
4347 article-capitalize-sentences
4348 article-remove-cr
4349 article-remove-leading-whitespace
4350 article-display-x-face
4351 article-display-face
4352 article-de-quoted-unreadable
4353 article-de-base64-unreadable
4354 article-decode-HZ
4355 article-wash-html
4356 article-unsplit-urls
4357 article-hide-list-identifiers
4358 article-strip-banner
4359 article-babel
4360 article-hide-pem
4361 article-hide-signature
4362 article-strip-headers-in-body
4363 article-remove-trailing-blank-lines
4364 article-strip-leading-blank-lines
4365 article-strip-multiple-blank-lines
4366 article-strip-leading-space
4367 article-strip-trailing-space
4368 article-strip-blank-lines
4369 article-strip-all-blank-lines
4370 article-date-local
4371 article-date-english
4372 article-date-iso8601
4373 article-date-original
4374 article-treat-date
4375 article-date-ut
4376 article-decode-mime-words
4377 article-decode-charset
4378 article-decode-encoded-words
4379 article-date-user
4380 article-date-lapsed
4381 article-date-combined-lapsed
4382 article-emphasize
4383 article-treat-dumbquotes
4384 article-treat-non-ascii
4385 article-normalize-headers
4386 ;;(article-show-all . gnus-article-show-all-headers)
4390 ;;; Gnus article mode
4393 (put 'gnus-article-mode 'mode-class 'special)
4395 (set-keymap-parent gnus-article-mode-map widget-keymap)
4397 (gnus-define-keys gnus-article-mode-map
4398 " " gnus-article-goto-next-page
4399 [?\S-\ ] gnus-article-goto-prev-page
4400 "\177" gnus-article-goto-prev-page
4401 [delete] gnus-article-goto-prev-page
4402 "\C-c^" gnus-article-refer-article
4403 "h" gnus-article-show-summary
4404 "s" gnus-article-show-summary
4405 "\C-c\C-m" gnus-article-mail
4406 "?" gnus-article-describe-briefly
4407 "<" beginning-of-buffer
4408 ">" end-of-buffer
4409 "\C-c\C-i" gnus-info-find-node
4410 "\C-c\C-b" gnus-bug
4411 "R" gnus-article-reply-with-original
4412 "F" gnus-article-followup-with-original
4413 "\C-hk" gnus-article-describe-key
4414 "\C-hc" gnus-article-describe-key-briefly
4415 "\C-hb" gnus-article-describe-bindings
4417 "e" gnus-article-read-summary-keys
4418 "\C-d" gnus-article-read-summary-keys
4419 "\M-*" gnus-article-read-summary-keys
4420 "\M-#" gnus-article-read-summary-keys
4421 "\M-^" gnus-article-read-summary-keys
4422 "\M-g" gnus-article-read-summary-keys)
4424 (substitute-key-definition
4425 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4427 (defvar gnus-article-send-map)
4428 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4429 "W" gnus-article-wide-reply-with-original
4430 [t] gnus-article-read-summary-send-keys)
4432 (defun gnus-article-make-menu-bar ()
4433 (unless (boundp 'gnus-article-commands-menu)
4434 (gnus-summary-make-menu-bar))
4435 (unless (boundp 'gnus-article-article-menu)
4436 (easy-menu-define
4437 gnus-article-article-menu gnus-article-mode-map ""
4438 '("Article"
4439 ["Scroll forwards" gnus-article-goto-next-page t]
4440 ["Scroll backwards" gnus-article-goto-prev-page t]
4441 ["Show summary" gnus-article-show-summary t]
4442 ["Fetch Message-ID at point" gnus-article-refer-article t]
4443 ["Mail to address at point" gnus-article-mail t]
4444 ["Send a bug report" gnus-bug t]))
4446 (easy-menu-define
4447 gnus-article-treatment-menu gnus-article-mode-map ""
4448 ;; Fixme: this should use :active (and maybe :visible).
4449 '("Treatment"
4450 ["Hide headers" gnus-article-hide-headers t]
4451 ["Hide signature" gnus-article-hide-signature t]
4452 ["Hide citation" gnus-article-hide-citation t]
4453 ["Treat overstrike" gnus-article-treat-overstrike t]
4454 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4455 ["Remove carriage return" gnus-article-remove-cr t]
4456 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4457 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4458 ["Remove base64" gnus-article-de-base64-unreadable t]
4459 ["Treat html" gnus-article-wash-html t]
4460 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4461 ["Decode HZ" gnus-article-decode-HZ t]))
4463 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4465 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4467 (gnus-run-hooks 'gnus-article-menu-hook)))
4469 (defvar bookmark-make-record-function)
4470 (defvar shr-put-image-function)
4472 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4473 "Major mode for displaying an article.
4475 All normal editing commands are switched off.
4477 The following commands are available in addition to all summary mode
4478 commands:
4479 \\<gnus-article-mode-map>
4480 \\[gnus-article-next-page]\t Scroll the article one page forwards
4481 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4482 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4483 \\[gnus-article-show-summary]\t Display the summary buffer
4484 \\[gnus-article-mail]\t Send a reply to the address near point
4485 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4486 \\[gnus-info-find-node]\t Go to the Gnus info node"
4487 (gnus-simplify-mode-line)
4488 (make-local-variable 'minor-mode-alist)
4489 (when (gnus-visual-p 'article-menu 'menu)
4490 (gnus-article-make-menu-bar)
4491 (when gnus-summary-tool-bar-map
4492 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4493 (gnus-update-format-specifications nil 'article-mode)
4494 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4495 (set (make-local-variable 'gnus-page-broken) nil)
4496 (make-local-variable 'gnus-article-current-summary)
4497 (make-local-variable 'gnus-article-mime-handles)
4498 (make-local-variable 'gnus-article-decoded-p)
4499 (make-local-variable 'gnus-article-mime-handle-alist)
4500 (make-local-variable 'gnus-article-wash-types)
4501 (make-local-variable 'gnus-article-image-alist)
4502 (make-local-variable 'gnus-article-charset)
4503 (make-local-variable 'gnus-article-ignored-charsets)
4504 (set (make-local-variable 'bookmark-make-record-function)
4505 'gnus-summary-bookmark-make-record)
4506 ;; Prevent Emacs from displaying non-break space with
4507 ;; `nobreak-space' face.
4508 (set (make-local-variable 'nobreak-char-display) nil)
4509 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4510 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4511 (unless gnus-article-show-cursor
4512 (setq cursor-in-non-selected-windows nil))
4513 (gnus-set-default-directory)
4514 (buffer-disable-undo)
4515 (setq buffer-read-only t
4516 show-trailing-whitespace nil)
4517 (mm-enable-multibyte))
4519 (defun gnus-article-setup-buffer ()
4520 "Initialize the article buffer."
4521 (let* ((name (if gnus-single-article-buffer "*Article*"
4522 (concat "*Article "
4523 (gnus-group-decoded-name gnus-newsgroup-name)
4524 "*")))
4525 (original
4526 (progn (string-match "\\*Article" name)
4527 (concat " *Original Article"
4528 (substring name (match-end 0))))))
4529 (setq gnus-article-buffer name)
4530 (setq gnus-original-article-buffer original)
4531 (setq gnus-article-mime-handle-alist nil)
4532 (with-current-buffer gnus-summary-buffer
4533 ;; This might be a variable local to the summary buffer.
4534 (unless gnus-single-article-buffer
4535 (setq gnus-article-buffer name)
4536 (setq gnus-original-article-buffer original)
4537 (gnus-set-global-variables)))
4538 (gnus-article-setup-highlight-words)
4539 ;; Init original article buffer.
4540 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4541 (mm-enable-multibyte)
4542 (setq major-mode 'gnus-original-article-mode)
4543 (make-local-variable 'gnus-original-article))
4544 (if (and (get-buffer name)
4545 (with-current-buffer name
4546 (if gnus-article-edit-mode
4547 (if (y-or-n-p "Article mode edit in progress; discard? ")
4548 (progn
4549 (set-buffer-modified-p nil)
4550 (gnus-kill-buffer name)
4551 (message "")
4552 nil)
4553 (error "Action aborted"))
4554 t)))
4555 (let ((summary gnus-summary-buffer))
4556 (with-current-buffer name
4557 (set (make-local-variable 'gnus-article-edit-mode) nil)
4558 (gnus-article-stop-animations)
4559 (when gnus-article-mime-handles
4560 (mm-destroy-parts gnus-article-mime-handles)
4561 (setq gnus-article-mime-handles nil))
4562 ;; Set it to nil in article-buffer!
4563 (setq gnus-article-mime-handle-alist nil)
4564 (buffer-disable-undo)
4565 (setq buffer-read-only t)
4566 (unless (derived-mode-p 'gnus-article-mode)
4567 (gnus-article-mode))
4568 (set (make-local-variable 'gnus-summary-buffer) summary)
4569 (setq truncate-lines gnus-article-truncate-lines)
4570 (current-buffer)))
4571 (let ((summary gnus-summary-buffer))
4572 (with-current-buffer (gnus-get-buffer-create name)
4573 (gnus-article-mode)
4574 (setq truncate-lines gnus-article-truncate-lines)
4575 (set (make-local-variable 'gnus-summary-buffer) summary)
4576 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4577 (when article-lapsed-timer
4578 (gnus-stop-date-timer))
4579 (when gnus-article-update-date-headers
4580 (gnus-start-date-timer gnus-article-update-date-headers))
4581 (current-buffer))))))
4583 (defun gnus-article-stop-animations ()
4584 (dolist (timer (and (boundp 'timer-list)
4585 timer-list))
4586 (when (eq (timer--function timer) 'image-animate-timeout)
4587 (cancel-timer timer))))
4589 (defun gnus-stop-downloads ()
4590 (when (boundp 'url-queue)
4591 (set (intern "url-queue" obarray) nil)))
4593 ;; Set article window start at LINE, where LINE is the number of lines
4594 ;; from the head of the article.
4595 (defun gnus-article-set-window-start (&optional line)
4596 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4597 (when article-window
4598 (set-window-start
4599 article-window
4600 (with-current-buffer gnus-article-buffer
4601 (goto-char (point-min))
4602 (if (not line)
4603 (point-min)
4604 (gnus-message 6 "Moved to bookmark")
4605 (search-forward "\n\n" nil t)
4606 (forward-line line)
4607 (point)))))))
4609 (defvar gnus-tmp-internal-hook)
4611 (defun gnus-article-prepare (article &optional all-headers _header)
4612 "Prepare ARTICLE in article mode buffer.
4613 ARTICLE should either be an article number or a Message-ID.
4614 If ARTICLE is an id, HEADER should be the article headers.
4615 If ALL-HEADERS is non-nil, no headers are hidden."
4616 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4617 ;; Make sure we start in a summary buffer.
4618 (unless (derived-mode-p 'gnus-summary-mode)
4619 (set-buffer gnus-summary-buffer))
4620 (setq gnus-summary-buffer (current-buffer))
4621 (let* ((summary-buffer (current-buffer))
4622 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4623 (group gnus-newsgroup-name)
4624 result)
4625 (save-excursion
4626 (gnus-article-setup-buffer)
4627 (set-buffer gnus-article-buffer)
4628 ;; Deactivate active regions.
4629 (when transient-mark-mode
4630 (setq mark-active nil))
4631 (if (not (setq result (let ((inhibit-read-only t))
4632 (gnus-request-article-this-buffer
4633 article group))))
4634 ;; There is no such article.
4635 (save-excursion
4636 (when (and (numberp article)
4637 (not (memq article gnus-newsgroup-sparse)))
4638 (setq gnus-article-current
4639 (cons gnus-newsgroup-name article))
4640 (set-buffer gnus-summary-buffer)
4641 (setq gnus-current-article article)
4642 (if (and (memq article gnus-newsgroup-undownloaded)
4643 (not (gnus-online (gnus-find-method-for-group
4644 gnus-newsgroup-name))))
4645 (progn
4646 (gnus-summary-set-agent-mark article)
4647 (message "Message marked for downloading"))
4648 (gnus-summary-mark-article article gnus-canceled-mark)
4649 (unless (memq article gnus-newsgroup-sparse)
4650 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4651 (if (or (eq result 'pseudo)
4652 (eq result 'nneething))
4653 (progn
4654 (with-current-buffer summary-buffer
4655 (push article gnus-newsgroup-history)
4656 (setq gnus-last-article gnus-current-article
4657 gnus-current-article 0
4658 gnus-current-headers nil
4659 gnus-article-current nil)
4660 (if (eq result 'nneething)
4661 (gnus-configure-windows 'summary)
4662 (gnus-configure-windows 'article))
4663 (gnus-set-global-variables))
4664 (let ((gnus-article-mime-handle-alist-1
4665 gnus-article-mime-handle-alist))
4666 (gnus-set-mode-line 'article)))
4667 ;; The result from the `request' was an actual article -
4668 ;; or at least some text that is now displayed in the
4669 ;; article buffer.
4670 (when (and (numberp article)
4671 (not (eq article gnus-current-article)))
4672 ;; Seems like a new article has been selected.
4673 ;; `gnus-current-article' must be an article number.
4674 (with-current-buffer summary-buffer
4675 (push article gnus-newsgroup-history)
4676 (setq gnus-last-article gnus-current-article
4677 gnus-current-article article
4678 gnus-current-headers
4679 (gnus-summary-article-header gnus-current-article)
4680 gnus-article-current
4681 (cons gnus-newsgroup-name gnus-current-article))
4682 (unless (vectorp gnus-current-headers)
4683 (setq gnus-current-headers nil))
4684 (gnus-summary-goto-subject gnus-current-article)
4685 (when (gnus-summary-show-thread)
4686 ;; If the summary buffer really was folded, the
4687 ;; previous goto may not actually have gone to
4688 ;; the right article, but the thread root instead.
4689 ;; So we go again.
4690 (gnus-summary-goto-subject gnus-current-article))
4691 (gnus-run-hooks 'gnus-mark-article-hook)
4692 (gnus-set-mode-line 'summary)
4693 (when (gnus-visual-p 'article-highlight 'highlight)
4694 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4695 ;; Set the global newsgroup variables here.
4696 (gnus-set-global-variables)
4697 (setq gnus-have-all-headers
4698 (or all-headers gnus-show-all-headers))))
4699 (save-excursion
4700 (gnus-configure-windows 'article))
4701 (when (or (numberp article)
4702 (stringp article))
4703 (gnus-article-prepare-display)
4704 ;; Do page break.
4705 (goto-char (point-min))
4706 (when gnus-break-pages
4707 (gnus-narrow-to-page)))
4708 (let ((gnus-article-mime-handle-alist-1
4709 gnus-article-mime-handle-alist))
4710 (gnus-set-mode-line 'article))
4711 (article-goto-body)
4712 (unless (bobp)
4713 (forward-line -1))
4714 (set-window-point (get-buffer-window (current-buffer)) (point))
4715 (gnus-configure-windows 'article)
4716 ;; Make sure the article begins with the top of the header.
4717 (let ((window (get-buffer-window gnus-article-buffer)))
4718 (when window
4719 (with-current-buffer (window-buffer window)
4720 (set-window-point window (point-min)))))
4721 (gnus-run-hooks 'gnus-article-prepare-hook)
4722 t))))))
4724 (defvar gnus-mime-display-attachment-buttons-in-header)
4726 ;;;###autoload
4727 (defun gnus-article-prepare-display ()
4728 "Make the current buffer look like a nice article."
4729 ;; Hooks for getting information from the article.
4730 ;; This hook must be called before being narrowed.
4731 (let ((gnus-article-buffer (current-buffer))
4732 buffer-read-only
4733 (inhibit-read-only t))
4734 (unless (derived-mode-p 'gnus-article-mode)
4735 (gnus-article-mode))
4736 (setq buffer-read-only nil
4737 gnus-article-wash-types nil
4738 gnus-article-image-alist nil)
4739 (gnus-run-hooks 'gnus-tmp-internal-hook)
4740 (when gnus-display-mime-function
4741 (funcall gnus-display-mime-function))
4742 ;; Add attachment buttons to the header.
4743 (when gnus-mime-display-attachment-buttons-in-header
4744 (gnus-mime-buttonize-attachments-in-header))))
4747 ;;; Gnus Sticky Article Mode
4750 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4751 "Mode for sticky articles."
4752 ;; Release bindings that won't work.
4753 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4754 gnus-sticky-article-mode-map)
4755 (substitute-key-definition 'gnus-article-refer-article 'undefined
4756 gnus-sticky-article-mode-map)
4757 (dolist (k '("e" "h" "s" "F" "R"))
4758 (define-key gnus-sticky-article-mode-map k nil))
4759 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4760 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4761 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4762 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4764 (defun gnus-sticky-article (arg)
4765 "Make the current article sticky.
4766 If a prefix ARG is given, ask for a name for this sticky article buffer."
4767 (interactive "P")
4768 (gnus-summary-show-thread)
4769 (gnus-summary-select-article nil nil 'pseudo)
4770 (let (new-art-buf-name)
4771 (gnus-eval-in-buffer-window gnus-article-buffer
4772 (setq new-art-buf-name
4773 (concat
4774 "*Sticky Article: "
4775 (if arg
4776 (read-from-minibuffer "Sticky article buffer name: ")
4777 (gnus-with-article-headers
4778 (gnus-article-goto-header "subject")
4779 (setq new-art-buf-name
4780 (buffer-substring-no-properties
4781 (line-beginning-position) (line-end-position)))
4782 (goto-char (point-min))
4783 (gnus-article-goto-header "from")
4784 (setq new-art-buf-name
4785 (concat
4786 new-art-buf-name ", "
4787 (buffer-substring-no-properties
4788 (line-beginning-position) (line-end-position))))
4789 (goto-char (point-min))
4790 (gnus-article-goto-header "date")
4791 (setq new-art-buf-name
4792 (concat
4793 new-art-buf-name ", "
4794 (buffer-substring-no-properties
4795 (line-beginning-position) (line-end-position))))))
4796 "*"))
4797 (if (and (gnus-buffer-live-p new-art-buf-name)
4798 (with-current-buffer new-art-buf-name
4799 (derived-mode-p 'gnus-sticky-article-mode)))
4800 (switch-to-buffer new-art-buf-name)
4801 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4802 (gnus-sticky-article-mode))
4803 (setq gnus-article-buffer new-art-buf-name))
4804 (gnus-summary-recenter)
4805 (gnus-summary-position-point))
4807 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4808 "Kill the given sticky article BUFFER.
4809 If none is given, assume the current buffer and kill it if it has
4810 `gnus-sticky-article-mode'."
4811 (interactive)
4812 (unless buffer
4813 (setq buffer (current-buffer)))
4814 (with-current-buffer buffer
4815 (when (derived-mode-p 'gnus-sticky-article-mode)
4816 (gnus-kill-buffer buffer))))
4818 (defun gnus-kill-sticky-article-buffers (arg)
4819 "Kill all sticky article buffers.
4820 If a prefix ARG is given, ask for confirmation."
4821 (interactive "P")
4822 (dolist (buf (gnus-buffers))
4823 (with-current-buffer buf
4824 (when (derived-mode-p 'gnus-sticky-article-mode)
4825 (if (not arg)
4826 (gnus-kill-buffer buf)
4827 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4828 (gnus-kill-buffer buf)))))))
4831 ;;; Gnus MIME viewing functions
4834 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4835 "Format of the MIME buttons.
4837 Valid specifiers include:
4838 %t The MIME type
4839 %T MIME type, along with additional info
4840 %n The `name' parameter
4841 %d The description, if any
4842 %l The length of the encoded part
4843 %p The part identifier number
4844 %e Dots if the part isn't displayed
4846 General format specifiers can also be used. See Info node
4847 `(gnus)Formatting Variables'.")
4849 (defvar gnus-tmp-type)
4850 (defvar gnus-tmp-type-long)
4851 (defvar gnus-tmp-name)
4852 (defvar gnus-tmp-description)
4853 (defvar gnus-tmp-id)
4854 (defvar gnus-tmp-length)
4855 (defvar gnus-tmp-dots)
4856 (defvar gnus-tmp-info)
4857 (defvar gnus-tmp-pressed-details)
4859 (defvar gnus-mime-button-line-format-alist
4860 '((?t gnus-tmp-type ?s)
4861 (?T gnus-tmp-type-long ?s)
4862 (?n gnus-tmp-name ?s)
4863 (?d gnus-tmp-description ?s)
4864 (?p gnus-tmp-id ?s)
4865 (?l gnus-tmp-length ?d)
4866 (?e gnus-tmp-dots ?s)))
4868 (defvar gnus-mime-button-commands
4869 '((gnus-article-press-button "\r" "Toggle Display")
4870 (gnus-mime-view-part "v" "View Interactively...")
4871 (gnus-mime-view-part-as-type "t" "View As Type...")
4872 (gnus-mime-view-part-as-charset "C" "View As charset...")
4873 (gnus-mime-save-part "o" "Save...")
4874 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4875 (gnus-mime-replace-part "r" "Replace part")
4876 (gnus-mime-delete-part "d" "Delete part")
4877 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4878 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4879 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4880 (gnus-mime-view-part-externally "e" "View Externally")
4881 (gnus-mime-print-part "p" "Print")
4882 (gnus-mime-pipe-part "|" "Pipe To Command...")
4883 (gnus-mime-action-on-part "." "Take action on the part...")))
4885 (defun gnus-article-mime-part-status ()
4886 (if gnus-article-mime-handle-alist-1
4887 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4888 " (1 part)"
4889 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4890 ""))
4892 (defvar gnus-mime-button-map
4893 (let ((map (make-sparse-keymap)))
4894 (define-key map [mouse-2] 'gnus-article-push-button)
4895 (define-key map [down-mouse-3] 'gnus-mime-button-menu)
4896 (dolist (c gnus-mime-button-commands)
4897 (define-key map (cadr c) (car c)))
4898 map))
4900 (easy-menu-define
4901 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4902 `("MIME Part"
4903 ,@(mapcar (lambda (c)
4904 (vector (caddr c) (car c) :active t))
4905 gnus-mime-button-commands)))
4907 (defvar gnus-url-button-commands
4908 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4910 (defvar gnus-url-button-map
4911 (let ((map (make-sparse-keymap)))
4912 (dolist (c gnus-url-button-commands)
4913 (define-key map (cadr c) (car c)))
4914 map))
4916 (easy-menu-define
4917 gnus-url-button-menu gnus-url-button-map "URL button menu."
4918 `("Url Button"
4919 ,@(mapcar (lambda (c)
4920 (vector (caddr c) (car c) :active t))
4921 gnus-url-button-commands)))
4923 (defmacro gnus-bind-mm-vars (&rest body)
4924 "Bind some mm-* variables and execute BODY."
4925 `(let (mm-html-inhibit-images
4926 mm-html-blocked-images
4927 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4928 (with-current-buffer
4929 (cond ((derived-mode-p 'gnus-article-mode)
4930 (if (gnus-buffer-live-p gnus-article-current-summary)
4931 gnus-article-current-summary
4932 ;; Maybe we're in a mml-preview buffer
4933 ;; and no group is selected.
4934 (current-buffer)))
4935 ((gnus-buffer-live-p gnus-summary-buffer)
4936 gnus-summary-buffer)
4937 (t (current-buffer)))
4938 (setq mm-html-inhibit-images gnus-inhibit-images
4939 mm-html-blocked-images (gnus-blocked-images))
4940 (when (or (not gnus-newsgroup-name)
4941 (and (stringp gnus-safe-html-newsgroups)
4942 (string-match gnus-safe-html-newsgroups
4943 gnus-newsgroup-name))
4944 (and (consp gnus-safe-html-newsgroups)
4945 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4946 (setq mm-w3m-safe-url-regexp nil)))
4947 ,@body))
4949 (defun gnus-mime-button-menu (event prefix)
4950 "Construct a context-sensitive menu of MIME commands."
4951 (interactive "e\nP")
4952 (save-window-excursion
4953 (let ((pos (event-start event)))
4954 (select-window (posn-window pos))
4955 (goto-char (posn-point pos))
4956 (gnus-article-check-buffer)
4957 (popup-menu gnus-mime-button-menu nil prefix))))
4959 (defun gnus-mime-view-all-parts (&optional handles)
4960 "View all the MIME parts."
4961 (interactive)
4962 (with-current-buffer gnus-article-buffer
4963 (let ((handles (or handles gnus-article-mime-handles))
4964 (mail-parse-charset gnus-newsgroup-charset)
4965 (mail-parse-ignored-charsets
4966 (with-current-buffer gnus-summary-buffer
4967 gnus-newsgroup-ignored-charsets)))
4968 (when handles
4969 (mm-remove-parts handles)
4970 (goto-char (point-min))
4971 (or (search-forward "\n\n") (goto-char (point-max)))
4972 (let ((inhibit-read-only t))
4973 (delete-region (point) (point-max))
4974 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4976 (defun gnus-article-jump-to-part (n)
4977 "Jump to MIME part N."
4978 (interactive "P")
4979 (let ((parts (with-current-buffer gnus-article-buffer
4980 (length gnus-article-mime-handle-alist))))
4981 (when (zerop parts)
4982 (error "No such part"))
4983 (pop-to-buffer gnus-article-buffer)
4984 (or n
4985 (setq n (if (= parts 1)
4987 (read-number (format "Jump to part (1..%s): " parts)))))
4988 (unless (and (integerp n) (<= n parts) (>= n 1))
4989 (setq n
4990 (progn
4991 (gnus-message 7 "Invalid part `%s', using %s instead."
4992 n parts)
4993 parts)))
4994 (gnus-message 9 "Jumping to part %s." n)
4995 (cond ((>= gnus-auto-select-part 1)
4996 (while (and (<= n parts)
4997 (not (gnus-article-goto-part n)))
4998 (setq n (1+ n))))
4999 ((< gnus-auto-select-part 0)
5000 (while (and (>= n 1)
5001 (not (gnus-article-goto-part n)))
5002 (setq n (1- n))))
5004 (gnus-article-goto-part n)))))
5006 (defvar gnus-mime-buttonized-part-id nil
5007 "ID of a mime part that should be buttonized.
5008 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5010 (eval-when-compile
5011 (defsubst gnus-article-edit-part (handles &optional current-id)
5012 "Edit an article in order to delete a mime part.
5013 This function is exclusively used by `gnus-mime-save-part-and-strip'
5014 and `gnus-mime-delete-part', and not provided at run-time normally."
5015 (gnus-article-edit-article
5016 `(lambda ()
5017 (buffer-disable-undo)
5018 (let ((mail-parse-charset (or gnus-article-charset
5019 ',gnus-newsgroup-charset))
5020 (mail-parse-ignored-charsets
5021 (or gnus-article-ignored-charsets
5022 ',gnus-newsgroup-ignored-charsets))
5023 (mbl mml-buffer-list))
5024 (setq mml-buffer-list nil)
5025 ;; A new text must be inserted before deleting existing ones
5026 ;; at the end so as not to move existing markers of which
5027 ;; the insertion type is t.
5028 (delete-region
5029 (point-min)
5030 (prog1
5031 (goto-char (point-max))
5032 (insert-buffer-substring gnus-original-article-buffer)))
5033 (mime-to-mml ',handles)
5034 (setq gnus-article-mime-handles nil)
5035 (let ((mbl1 mml-buffer-list))
5036 (setq mml-buffer-list mbl)
5037 (set (make-local-variable 'mml-buffer-list) mbl1))
5038 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5039 `(lambda (no-highlight)
5040 (let ((mail-parse-charset (or gnus-article-charset
5041 ',gnus-newsgroup-charset))
5042 (message-options message-options)
5043 (message-options-set-recipient)
5044 (mail-parse-ignored-charsets
5045 (or gnus-article-ignored-charsets
5046 ',gnus-newsgroup-ignored-charsets)))
5047 (mml-to-mime)
5048 (mml-destroy-buffers)
5049 (remove-hook 'kill-buffer-hook
5050 'mml-destroy-buffers t)
5051 (kill-local-variable 'mml-buffer-list))
5052 (gnus-summary-edit-article-done
5053 ,(or (mail-header-references gnus-current-headers) "")
5054 ,(gnus-group-read-only-p)
5055 ,gnus-summary-buffer no-highlight))
5057 ;; Force buttonizing this part.
5058 (let ((gnus-mime-buttonized-part-id current-id))
5059 (gnus-article-edit-done))
5060 (gnus-configure-windows 'article)
5061 (sit-for 0)
5062 (let ((handles (with-current-buffer gnus-article-buffer
5063 gnus-article-mime-handle-alist)))
5064 ;; `handles' will be nil if there is the only one part
5065 ;; in the article and is deleted.
5066 (when (and handles current-id (integerp gnus-auto-select-part))
5067 (gnus-article-jump-to-part
5068 (min (max (+ current-id gnus-auto-select-part) 1)
5069 (length handles)))))))
5071 (defun gnus-mime-replace-part (file)
5072 "Replace MIME part under point with an external body."
5073 ;; Useful if file has already been saved to disk
5074 (interactive
5075 (list
5076 (read-file-name "Replace MIME part with file: "
5077 (or mm-default-directory default-directory)
5078 nil nil)))
5079 (gnus-mime-save-part-and-strip file))
5081 (defun gnus-mime-save-part-and-strip (&optional file)
5082 "Save the MIME part under point then replace it with an external body.
5083 If FILE is given, use it for the external part."
5084 (interactive)
5085 (gnus-article-check-buffer)
5086 (when (gnus-group-read-only-p)
5087 (error "The current group does not support deleting of parts"))
5088 (when (mm-complicated-handles gnus-article-mime-handles)
5089 (error "\
5090 The current article has a complicated MIME structure, giving up..."))
5091 (let* ((data (get-text-property (point) 'gnus-data))
5092 (id (get-text-property (point) 'gnus-part))
5093 (handles gnus-article-mime-handles))
5094 (unless file
5095 (setq file
5096 (and data (mm-save-part data "Delete MIME part and save to: "))))
5097 (when file
5098 (with-current-buffer (mm-handle-buffer data)
5099 (erase-buffer)
5100 (insert "Content-Type: " (mm-handle-media-type data))
5101 (mml-insert-parameter-string (cdr (mm-handle-type data))
5102 '(charset))
5103 ;; Add a filename for the sake of saving the part again.
5104 (mml-insert-parameter
5105 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5106 (insert "\n")
5107 (insert "Content-ID: " (message-make-message-id) "\n")
5108 (insert "Content-Transfer-Encoding: binary\n")
5109 (insert "\n"))
5110 (setcdr data
5111 (cdr (mm-make-handle nil
5112 `("message/external-body"
5113 (access-type . "LOCAL-FILE")
5114 (name . ,file)))))
5115 ;; (set-buffer gnus-summary-buffer)
5116 (gnus-article-edit-part handles id))))
5118 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5119 ;; parts...>') but with stripping would be nice.
5121 (defun gnus-mime-delete-part ()
5122 "Delete the MIME part under point.
5123 Replace it with some information about the removed part."
5124 (interactive)
5125 (gnus-article-check-buffer)
5126 (when (gnus-group-read-only-p)
5127 (error "The current group does not support deleting of parts"))
5128 (when (mm-complicated-handles gnus-article-mime-handles)
5129 (error "\
5130 The current article has a complicated MIME structure, giving up..."))
5131 (when (or gnus-expert-user
5132 (gnus-yes-or-no-p "\
5133 Deleting parts may malfunction or destroy the article; continue? "))
5134 (let* ((data (get-text-property (point) 'gnus-data))
5135 (id (get-text-property (point) 'gnus-part))
5136 (handles gnus-article-mime-handles)
5137 (description
5138 (let ((desc (mm-handle-description data)))
5139 (when desc
5140 (mail-decode-encoded-word-string desc))))
5141 (filename (or (mm-handle-filename data) "(none)"))
5142 (type (mm-handle-media-type data)))
5143 (unless data
5144 (error "No MIME part under point"))
5145 (with-current-buffer (mm-handle-buffer data)
5146 (let ((bsize (buffer-size)))
5147 (erase-buffer)
5148 (insert
5149 (concat
5150 ",----\n"
5151 "| The following attachment has been deleted:\n"
5152 "|\n"
5153 "| Type: " type "\n"
5154 "| Filename: " filename "\n"
5155 "| Size (encoded): " (format "%s byte%s\n"
5156 bsize (if (= bsize 1)
5158 "s"))
5159 (when description
5160 (concat "| Description: " description "\n"))
5161 "`----\n"))
5162 (setcdr data
5163 (cdr (mm-make-handle
5164 nil `("text/plain" (charset . gnus-decoded)) nil nil
5165 (list "attachment")
5166 (format "Deleted attachment (%s bytes)" bsize))))))
5167 ;; (set-buffer gnus-summary-buffer)
5168 (gnus-article-edit-part handles id))))
5170 (defun gnus-mime-save-part ()
5171 "Save the MIME part under point."
5172 (interactive)
5173 (gnus-article-check-buffer)
5174 (let ((data (get-text-property (point) 'gnus-data)))
5175 (when data
5176 (mm-save-part data))))
5178 (defun gnus-mime-pipe-part (&optional cmd)
5179 "Pipe the MIME part under point to a process.
5180 Use CMD as the process."
5181 (interactive)
5182 (gnus-article-check-buffer)
5183 (let ((data (get-text-property (point) 'gnus-data)))
5184 (when data
5185 (mm-pipe-part data cmd))))
5187 (defun gnus-mime-view-part ()
5188 "Interactively choose a viewing method for the MIME part under point."
5189 (interactive)
5190 (gnus-article-check-buffer)
5191 (let ((data (get-text-property (point) 'gnus-data)))
5192 (when data
5193 (setq gnus-article-mime-handles
5194 (mm-merge-handles
5195 gnus-article-mime-handles (setq data (copy-sequence data))))
5196 (mm-interactively-view-part data))))
5198 (defun gnus-mime-view-part-as-type-internal ()
5199 (gnus-article-check-buffer)
5200 (let* ((handle (get-text-property (point) 'gnus-data))
5201 (name (or
5202 ;; Content-Type: foo/bar; name=...
5203 (mail-content-type-get (mm-handle-type handle) 'name)
5204 ;; Content-Disposition: attachment; filename=...
5205 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5206 (def-type (and name (mm-default-file-encoding name))))
5207 (or (and def-type (cons def-type 0))
5208 (and handle
5209 (equal (mm-handle-media-supertype handle) "text")
5210 '("text/plain" . 0))
5211 '("application/octet-stream" . 0))))
5213 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5214 "Choose a MIME media type, and view the part as such.
5215 If non-nil, PRED is a predicate to use during completion to limit the
5216 available media-types."
5217 (interactive)
5218 (unless mime-type
5219 (setq mime-type
5220 (let ((default (gnus-mime-view-part-as-type-internal)))
5221 (gnus-completing-read
5222 "View as MIME type"
5223 (if pred
5224 (seq-filter pred (mailcap-mime-types))
5225 (mailcap-mime-types))
5226 nil nil nil
5227 (car default)))))
5228 (gnus-article-check-buffer)
5229 (let ((handle (get-text-property (point) 'gnus-data)))
5230 (when handle
5231 (when (equal (mm-handle-media-type handle) "message/external-body")
5232 (unless (mm-handle-cache handle)
5233 (mm-extern-cache-contents handle))
5234 (setq handle (mm-handle-cache handle)))
5235 (setq handle
5236 (mm-make-handle (mm-handle-buffer handle)
5237 (cons mime-type (cdr (mm-handle-type handle)))
5238 (mm-handle-encoding handle)
5239 (mm-handle-undisplayer handle)
5240 (mm-handle-disposition handle)
5241 (mm-handle-description handle)
5243 (mm-handle-id handle)))
5244 (setq gnus-article-mime-handles
5245 (mm-merge-handles gnus-article-mime-handles handle))
5246 (when (mm-handle-displayed-p handle)
5247 (mm-remove-part handle))
5248 (gnus-mm-display-part handle))))
5250 (defun gnus-mime-copy-part (&optional handle arg)
5251 "Put the MIME part under point into a new buffer.
5252 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5253 are decompressed."
5254 (interactive (list nil current-prefix-arg))
5255 (gnus-article-check-buffer)
5256 (unless handle
5257 (setq handle (get-text-property (point) 'gnus-data)))
5258 (when handle
5259 (let ((filename (mm-handle-filename handle))
5260 contents dont-decode charset coding-system)
5261 (mm-with-unibyte-buffer
5262 (mm-insert-part handle)
5263 (setq contents (or (condition-case nil
5264 (mm-decompress-buffer filename nil 'sig)
5265 (error
5266 (setq dont-decode t)
5267 nil))
5268 (buffer-string))))
5269 (setq filename (cond (filename (file-name-nondirectory filename))
5270 (dont-decode "*raw data*")
5271 (t "*decoded*")))
5272 (cond
5273 (dont-decode)
5274 ((not arg)
5275 (unless (setq charset (mail-content-type-get
5276 (mm-handle-type handle) 'charset))
5277 (unless (setq coding-system (mm-with-unibyte-buffer
5278 (insert contents)
5279 (mm-find-buffer-file-coding-system)))
5280 (setq charset gnus-newsgroup-charset))))
5281 ((numberp arg)
5282 (setq charset (or (cdr (assq arg
5283 gnus-summary-show-article-charset-alist))
5284 (read-coding-system "Charset: ")))))
5285 (switch-to-buffer (generate-new-buffer filename))
5286 (if (or coding-system
5287 (and charset
5288 (setq coding-system (mm-charset-to-coding-system
5289 charset nil t))
5290 (not (eq coding-system 'ascii))))
5291 (progn
5292 (mm-enable-multibyte)
5293 (insert (decode-coding-string contents coding-system))
5294 (setq buffer-file-coding-system last-coding-system-used))
5295 (mm-disable-multibyte)
5296 (insert contents)
5297 (setq buffer-file-coding-system mm-binary-coding-system))
5298 ;; We do it this way to make `normal-mode' set the appropriate mode.
5299 (unwind-protect
5300 (progn
5301 (setq buffer-file-name (expand-file-name filename))
5302 (normal-mode))
5303 (setq buffer-file-name nil))
5304 (goto-char (point-min)))))
5306 (defun gnus-mime-print-part (&optional handle filename)
5307 "Print the MIME part under point."
5308 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5309 (gnus-article-check-buffer)
5310 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5311 (contents (and handle (mm-get-part handle)))
5312 (file (make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5313 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5314 (when contents
5315 (if printer
5316 (unwind-protect
5317 (progn
5318 (mm-save-part-to-file handle file)
5319 (call-process shell-file-name nil
5320 (generate-new-buffer " *mm*")
5322 shell-command-switch
5323 (mm-mailcap-command
5324 printer file (mm-handle-type handle))))
5325 (delete-file file))
5326 (with-temp-buffer
5327 (insert contents)
5328 (gnus-print-buffer))
5329 (ps-despool filename)))))
5331 (defun gnus-mime-inline-part (&optional handle arg)
5332 "Insert the MIME part under point into the current buffer.
5333 Compressed files like .gz and .bz2 are decompressed."
5334 (interactive (list nil current-prefix-arg))
5335 (gnus-article-check-buffer)
5336 (let* ((inhibit-read-only t)
5337 (b (point))
5338 (btn ;; position where the MIME button exists
5339 (if handle
5340 (if (eq handle (get-text-property b 'gnus-data))
5342 (article-goto-body)
5343 (or (text-property-any (point) (point-max) 'gnus-data handle)
5344 (text-property-any (point-min) (point) 'gnus-data handle)))
5345 (setq handle (get-text-property b 'gnus-data))
5347 start)
5348 (when handle
5349 (when (= b (prog1
5351 (setq start (next-single-property-change btn 'gnus-data
5352 nil (point-max))
5353 btn (previous-single-property-change start
5354 'gnus-data))))
5355 (setq b btn))
5356 (if (and (not arg) (mm-handle-undisplayer handle))
5357 (progn
5358 (setq b (copy-marker b)
5359 btn (copy-marker btn))
5360 (mm-remove-part handle))
5361 (cond
5362 ((not arg) nil)
5363 ((numberp arg)
5364 (if (mm-handle-undisplayer handle)
5365 (mm-remove-part handle)))
5366 ((mm-handle-undisplayer handle)
5367 (mm-remove-part handle)))
5368 (goto-char start)
5369 (unless (bolp)
5370 ;; This is a header button.
5371 (forward-line 1))
5372 (mm-display-inline handle))
5373 ;; Toggle the button appearance between `[button]...' and `[button]'.
5374 (when (markerp btn)
5375 (setq btn (prog1 (marker-position btn)
5376 (set-marker btn nil))))
5377 (goto-char btn)
5378 (let ((displayed-p (mm-handle-displayed-p handle)))
5379 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5380 (list displayed-p))
5381 (delete-region
5382 (point)
5383 (next-single-property-change (point) 'gnus-data nil (point-max)))
5384 (setq start (point))
5385 (if (search-backward "\n\n" nil t)
5386 (progn
5387 (goto-char start)
5388 (unless (or displayed-p (eolp))
5389 ;; Add extra newline.
5390 (insert (propertize (buffer-substring (1- start) start)
5391 'gnus-undeletable t))))
5392 ;; We're in the article header.
5393 (delete-char -1)
5394 (dolist (ovl (overlays-in btn (point)))
5395 (overlay-put ovl 'gnus-button-attachment-extra t)
5396 (overlay-put ovl 'face nil))
5397 (save-restriction
5398 (message-narrow-to-field)
5399 (let ((gnus-treatment-function-alist
5400 '((gnus-treat-highlight-headers
5401 gnus-article-highlight-headers))))
5402 (gnus-treat-article 'head)))))
5403 (when (markerp b)
5404 (setq b (prog1 (marker-position b)
5405 (set-marker b nil))))
5406 (goto-char b))))
5408 (defun gnus-mime-set-charset-parameters (handle charset)
5409 "Set CHARSET to parameters in HANDLE.
5410 CHARSET may either be a string or a symbol."
5411 (unless (stringp charset)
5412 (setq charset (symbol-name charset)))
5413 (if (stringp (car handle))
5414 (dolist (h (cdr handle))
5415 (gnus-mime-set-charset-parameters h charset))
5416 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5417 "message/external-body")
5418 (progn
5419 (unless (mm-handle-cache handle)
5420 (mm-extern-cache-contents handle))
5421 (mm-handle-cache handle))
5422 handle)))
5423 (param (assq 'charset (cdr type))))
5424 (if param
5425 (setcdr param charset)
5426 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5428 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5429 "Insert the MIME part under point into the current buffer using the
5430 specified charset."
5431 (interactive (list nil current-prefix-arg))
5432 (gnus-article-check-buffer)
5433 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5434 (fun (get-text-property (point) 'gnus-callback))
5435 (gnus-newsgroup-ignored-charsets 'gnus-all)
5436 charset form preferred parts)
5437 (when handle
5438 (when (prog1
5439 (and fun
5440 (setq charset
5441 (or (cdr (assq
5443 gnus-summary-show-article-charset-alist))
5444 (read-coding-system "Charset: "))))
5445 (if (mm-handle-undisplayer handle)
5446 (mm-remove-part handle)))
5447 (gnus-mime-set-charset-parameters handle charset)
5448 (when (and (consp (setq form (cdr-safe fun)))
5449 (setq form (ignore-errors
5450 (assq 'gnus-mime-display-alternative form)))
5451 (setq preferred (caddr form))
5452 (progn
5453 (when (eq (car preferred) 'quote)
5454 (setq preferred (cadr preferred)))
5455 (not (equal preferred
5456 (get-text-property (point) 'gnus-data))))
5457 (setq parts (get-text-property (point) 'gnus-part))
5458 (setq parts (cdr (assq parts
5459 gnus-article-mime-handle-alist)))
5460 (equal (mm-handle-media-type parts) "multipart/alternative")
5461 (setq parts (reverse (cdr parts))))
5462 (setcar (cddr form)
5463 (list 'quote (or (cadr (member preferred parts))
5464 (car parts)))))
5465 (funcall fun handle)))))
5467 (defun gnus-mime-view-part-externally (&optional handle)
5468 "View the MIME part under point with an external viewer."
5469 (interactive)
5470 (gnus-article-check-buffer)
5471 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5472 (mm-inlined-types nil)
5473 (mail-parse-charset gnus-newsgroup-charset)
5474 (mail-parse-ignored-charsets
5475 (with-current-buffer gnus-summary-buffer
5476 gnus-newsgroup-ignored-charsets))
5477 (type (mm-handle-media-type handle))
5478 (method (mailcap-mime-info type))
5479 (mm-enable-external t))
5480 (if (not (stringp method))
5481 (gnus-mime-view-part-as-type
5482 nil (lambda (type) (stringp (mailcap-mime-info type))))
5483 (when handle
5484 (mm-display-part handle nil t)))))
5486 (defun gnus-mime-view-part-internally (&optional handle)
5487 "View the MIME part under point with an internal viewer.
5488 If no internal viewer is available, use an external viewer."
5489 (interactive)
5490 (gnus-article-check-buffer)
5491 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5492 (mm-inlined-types '(".*"))
5493 (mm-inline-large-images t)
5494 (mail-parse-charset gnus-newsgroup-charset)
5495 (mail-parse-ignored-charsets
5496 (with-current-buffer gnus-summary-buffer
5497 gnus-newsgroup-ignored-charsets))
5498 (inhibit-read-only t))
5499 (if (not (mm-inlinable-p handle))
5500 (gnus-mime-view-part-as-type
5501 nil (lambda (type) (mm-inlinable-p handle type)))
5502 (when handle
5503 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5505 (defun gnus-mime-action-on-part (&optional action)
5506 "Do something with the MIME attachment at (point)."
5507 (interactive
5508 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5509 (gnus-article-check-buffer)
5510 (let ((action-pair (assoc action gnus-mime-action-alist)))
5511 (if action-pair
5512 (funcall (cdr action-pair)))))
5514 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5515 "Call FUNCTION on MIME part N.
5516 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5517 If INTERACTIVE, call FUNCTION interactively."
5518 (let (window frame)
5519 ;; Check whether the article is displayed.
5520 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5521 (setq window (get-buffer-window gnus-article-buffer t))
5522 (frame-visible-p (setq frame (window-frame window))))
5523 (error "No article is displayed"))
5524 (with-current-buffer gnus-article-buffer
5525 ;; Check whether the article displays the right contents.
5526 (unless (with-current-buffer gnus-summary-buffer
5527 (eq gnus-current-article (gnus-summary-article-number)))
5528 (error "You should select the right article first"))
5529 (if n
5530 (setq n (prefix-numeric-value n))
5531 (let ((pt (point)))
5532 (setq n (or (get-text-property pt 'gnus-part)
5533 (and (not (bobp))
5534 (get-text-property (1- pt) 'gnus-part))
5535 (get-text-property (prog2
5536 (forward-line 1)
5537 (point)
5538 (goto-char pt))
5539 'gnus-part)
5540 (get-text-property
5541 (or (and (setq pt (previous-single-property-change
5542 pt 'gnus-part))
5543 (1- pt))
5544 (next-single-property-change (point) 'gnus-part)
5545 (point))
5546 'gnus-part)
5547 1))))
5548 ;; Check whether the specified part exists.
5549 (when (> n (length gnus-article-mime-handle-alist))
5550 (error "No such part")))
5551 (unless
5552 (progn
5553 ;; To select the window is needed so that the cursor
5554 ;; might be visible on the MIME button.
5555 (select-window (prog1
5556 window
5557 (setq window (selected-window))
5558 ;; Article may be displayed in the other frame.
5559 (select-frame-set-input-focus
5560 (prog1
5561 frame
5562 (setq frame (selected-frame))))))
5563 (when (gnus-article-goto-part n)
5564 ;; We point the cursor and the arrow at the MIME button
5565 ;; when the `function' prompt the user for something.
5566 (unless (and (pos-visible-in-window-p)
5567 (> (count-lines (point) (window-end))
5568 (/ (1- (window-height)) 3)))
5569 (recenter (/ (1- (window-height)) 3)))
5570 (let ((cursor-in-non-selected-windows t)
5571 (overlay-arrow-string "=>")
5572 (overlay-arrow-position (point-marker)))
5573 (unwind-protect
5574 (cond
5575 ((and no-handle interactive)
5576 (call-interactively function))
5577 (no-handle
5578 (funcall function))
5579 (interactive
5580 (call-interactively
5581 function (get-text-property (point) 'gnus-data)))
5583 (funcall function
5584 (get-text-property (point) 'gnus-data))))
5585 (set-marker overlay-arrow-position nil)
5586 (unless gnus-auto-select-part
5587 (select-frame-set-input-focus frame)
5588 (select-window window))))
5590 (if gnus-inhibit-mime-unbuttonizing
5591 ;; This is the default though the program shouldn't reach here.
5592 (error "No such part")
5593 ;; The part which doesn't have the MIME button is selected.
5594 ;; So, we display all the buttons and redo it.
5595 (let ((gnus-inhibit-mime-unbuttonizing t))
5596 (gnus-summary-show-article)
5597 (gnus-article-part-wrapper n function no-handle))))))
5599 (defun gnus-article-pipe-part (n)
5600 "Pipe MIME part N, which is the numerical prefix."
5601 (interactive "P")
5602 (gnus-article-part-wrapper n 'mm-pipe-part))
5604 (defun gnus-article-save-part (n)
5605 "Save MIME part N, which is the numerical prefix."
5606 (interactive "P")
5607 (gnus-article-part-wrapper n 'mm-save-part))
5609 (defun gnus-article-interactively-view-part (n)
5610 "View MIME part N interactively, which is the numerical prefix."
5611 (interactive "P")
5612 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5614 (defun gnus-article-copy-part (n)
5615 "Copy MIME part N, which is the numerical prefix."
5616 (interactive "P")
5617 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5619 (defun gnus-article-view-part-as-charset (n)
5620 "View MIME part N using a specified charset.
5621 N is the numerical prefix."
5622 (interactive "P")
5623 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5625 (defun gnus-article-view-part-externally (n)
5626 "View MIME part N externally, which is the numerical prefix."
5627 (interactive "P")
5628 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5630 (defun gnus-article-inline-part (n)
5631 "Inline MIME part N, which is the numerical prefix."
5632 (interactive "P")
5633 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5635 (defun gnus-article-save-part-and-strip (n)
5636 "Save MIME part N and replace it with an external body.
5637 N is the numerical prefix."
5638 (interactive "P")
5639 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5641 (defun gnus-article-replace-part (n)
5642 "Replace MIME part N with an external body.
5643 N is the numerical prefix."
5644 (interactive "P")
5645 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5647 (defun gnus-article-delete-part (n)
5648 "Delete MIME part N and add some information about the removed part.
5649 N is the numerical prefix."
5650 (interactive "P")
5651 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5653 (defun gnus-article-view-part-as-type (n)
5654 "Choose a MIME media type, and view part N as such.
5655 N is the numerical prefix."
5656 (interactive "P")
5657 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5659 (defun gnus-article-mime-match-handle-first (condition)
5660 (if condition
5661 (let (n)
5662 (dolist (ihandle gnus-article-mime-handle-alist)
5663 (if (and (cond
5664 ((functionp condition)
5665 (funcall condition (cdr ihandle)))
5666 ((eq condition 'undisplayed)
5667 (not (or (mm-handle-undisplayer (cdr ihandle))
5668 (equal (mm-handle-media-type (cdr ihandle))
5669 "multipart/alternative"))))
5670 ((eq condition 'undisplayed-alternative)
5671 (not (mm-handle-undisplayer (cdr ihandle))))
5672 (t t))
5673 (gnus-article-goto-part (car ihandle))
5674 (or (not n) (< (car ihandle) n)))
5675 (setq n (car ihandle))))
5676 (or n 1))
5679 (defun gnus-article-view-part (&optional n)
5680 "View MIME part N, which is the numerical prefix.
5681 If the part is already shown, hide the part. If N is nil, view
5682 all parts."
5683 (interactive "P")
5684 (with-current-buffer gnus-article-buffer
5685 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5686 gnus-article-mime-match-handle-function)))
5687 (when (> n (length gnus-article-mime-handle-alist))
5688 (error "No such part"))
5689 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5690 (when (gnus-article-goto-part n)
5691 (if (equal (car handle) "multipart/alternative")
5692 (progn
5693 (beginning-of-line) ;; Make it toggle subparts
5694 (gnus-article-press-button))
5695 (when (eq (gnus-mm-display-part handle) 'internal)
5696 (gnus-set-window-start)))))))
5698 (defsubst gnus-article-mime-total-parts ()
5699 (if (bufferp (car gnus-article-mime-handles))
5700 1 ;; single part
5701 (1- (length gnus-article-mime-handles))))
5703 (defun gnus-mm-display-part (handle)
5704 "Display HANDLE and fix MIME button."
5705 (let ((id (get-text-property (point) 'gnus-part))
5706 (point (point))
5707 (inhibit-read-only t)
5708 (window (selected-window))
5709 (mail-parse-charset gnus-newsgroup-charset)
5710 (mail-parse-ignored-charsets
5711 (if (gnus-buffer-live-p gnus-summary-buffer)
5712 (with-current-buffer gnus-summary-buffer
5713 gnus-newsgroup-ignored-charsets)
5714 nil))
5715 start retval)
5716 (unwind-protect
5717 (progn
5718 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5719 (when win
5720 (select-window win)
5721 (goto-char point)))
5722 (setq start (next-single-property-change point 'gnus-data
5723 nil (point-max))
5724 point (previous-single-property-change start 'gnus-data))
5725 (if (mm-handle-displayed-p handle)
5726 ;; This will remove the part.
5727 (setq point (copy-marker point)
5728 retval (mm-display-part handle))
5729 (let ((part (or (and (mm-inlinable-p handle)
5730 (mm-inlined-p handle)
5732 (with-temp-buffer
5733 (gnus-bind-mm-vars
5734 (setq retval (mm-display-part handle)))
5735 (unless (zerop (buffer-size))
5736 (buffer-string))))))
5737 (goto-char start)
5738 (unless (bolp)
5739 ;; This is a header button.
5740 (forward-line 1))
5741 (cond ((stringp part)
5742 (save-restriction
5743 (narrow-to-region (point)
5744 (progn
5745 (insert part)
5746 (unless (bolp) (insert "\n"))
5747 (point)))
5748 (gnus-treat-article nil id
5749 (gnus-article-mime-total-parts)
5750 (mm-handle-media-type handle))
5751 (mm-handle-set-undisplayer
5752 handle
5753 `(lambda ()
5754 (let ((inhibit-read-only t))
5755 (delete-region ,(copy-marker (point-min) t)
5756 ,(point-max-marker)))))))
5757 (part
5758 (mm-display-inline handle))))))
5759 (when (markerp point)
5760 (setq point (prog1 (marker-position point)
5761 (set-marker point nil))))
5762 (goto-char point)
5763 ;; Toggle the button appearance between `[button]...' and `[button]'.
5764 (let ((displayed-p (mm-handle-displayed-p handle)))
5765 (gnus-insert-mime-button handle id (list displayed-p))
5766 (delete-region
5767 (point)
5768 (next-single-property-change (point) 'gnus-data nil (point-max)))
5769 (setq start (point))
5770 (if (search-backward "\n\n" nil t)
5771 (progn
5772 (goto-char start)
5773 (unless (or displayed-p (eolp))
5774 ;; Add extra newline.
5775 (insert (propertize (buffer-substring (1- start) start)
5776 'gnus-undeletable t))))
5777 ;; We're in the article header.
5778 (delete-char -1)
5779 (dolist (ovl (overlays-in point (point)))
5780 (overlay-put ovl 'gnus-button-attachment-extra t)
5781 (overlay-put ovl 'face nil))
5782 (save-restriction
5783 (message-narrow-to-field)
5784 (let ((gnus-treatment-function-alist
5785 '((gnus-treat-highlight-headers
5786 gnus-article-highlight-headers))))
5787 (gnus-treat-article 'head)))))
5788 (goto-char point)
5789 (if (window-live-p window)
5790 (select-window window)))
5791 retval))
5793 (defun gnus-article-goto-part (n)
5794 "Go to MIME part N."
5795 (when gnus-break-pages
5796 (widen))
5797 (article-goto-body)
5798 (prog1
5799 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5800 ;; There may be header buttons.
5801 (text-property-any (point-min) (point) 'gnus-part n)))
5802 part handle end next handles)
5803 (when start
5804 (goto-char start)
5805 (if (setq handle (get-text-property start 'gnus-data))
5806 start
5807 ;; Go to the displayed subpart, assuming this is
5808 ;; multipart/alternative.
5809 (setq part start
5810 end (point-at-eol))
5811 (while (and (not handle)
5812 part
5813 (< part end)
5814 (setq next (text-property-not-all part end
5815 'gnus-data nil)))
5816 (setq part next
5817 handle (get-text-property part 'gnus-data))
5818 (push (cons handle part) handles)
5819 (unless (mm-handle-displayed-p handle)
5820 (setq handle nil
5821 part (text-property-any part end 'gnus-data nil))))
5822 (unless handle
5823 ;; No subpart is displayed, so we find preferred one.
5824 (setq part
5825 (cdr (assq (mm-preferred-alternative
5826 (nreverse (mapcar 'car handles)))
5827 handles))))
5828 (if part
5829 (goto-char (1+ part))
5830 start))))
5831 (when gnus-break-pages
5832 (gnus-narrow-to-page))))
5834 (defun gnus-insert-mime-button (handle id &optional displayed)
5835 (let ((gnus-tmp-name
5836 (or (mm-handle-filename handle)
5837 (mail-content-type-get (mm-handle-type handle) 'url)
5838 ""))
5839 (gnus-tmp-id id)
5840 (gnus-tmp-type (mm-handle-media-type handle))
5841 (gnus-tmp-description (or (mm-handle-description handle) ""))
5842 (gnus-tmp-dots
5843 (if (if displayed (car displayed)
5844 (mm-handle-displayed-p handle))
5845 "" "..."))
5846 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5847 (buffer-size)))
5848 gnus-tmp-type-long b e)
5849 (when (string-match ".*/" gnus-tmp-name)
5850 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5851 (setq gnus-tmp-type-long (concat gnus-tmp-type
5852 (and (not (equal gnus-tmp-name ""))
5853 (concat "; " gnus-tmp-name))))
5854 (unless (equal gnus-tmp-description "")
5855 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5856 (setq b (point))
5857 (gnus-eval-format
5858 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5859 `(keymap ,gnus-mime-button-map
5860 gnus-callback gnus-mm-display-part
5861 gnus-part ,gnus-tmp-id
5862 article-type annotation
5863 gnus-data ,handle
5864 rear-nonsticky t))
5865 (setq e (if (bolp)
5866 ;; Exclude a newline.
5867 (1- (point))
5868 (point)))
5869 (when gnus-article-button-face
5870 (overlay-put (make-overlay b e nil t)
5871 'face gnus-article-button-face))
5872 (widget-convert-button
5873 'link b e
5874 :mime-handle handle
5875 :action 'gnus-widget-press-button
5876 :button-keymap gnus-mime-button-map
5877 :help-echo
5878 (lambda (widget)
5879 (format
5880 "%S: %s the MIME part; %S: more options"
5881 'mouse-2
5882 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5883 "hide" "show")
5884 'down-mouse-3)))))
5886 (defun gnus-widget-press-button (elems _el)
5887 (goto-char (widget-get elems :from))
5888 (gnus-article-press-button))
5890 (defvar gnus-displaying-mime nil)
5892 (defun gnus-display-mime (&optional ihandles)
5893 "Display the MIME parts."
5894 (save-excursion
5895 (save-selected-window
5896 (let ((window (get-buffer-window gnus-article-buffer))
5897 (point (point)))
5898 (when window
5899 (select-window window)
5900 ;; We have to do this since selecting the window
5901 ;; may change the point. So we set the window point.
5902 (set-window-point window point)))
5903 (let ((handles ihandles)
5904 (inhibit-read-only t))
5905 (cond (handles)
5906 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5907 (when gnus-article-emulate-mime
5908 (mm-uu-dissect-text-parts handles)))
5909 (gnus-article-emulate-mime
5910 (setq handles (mm-uu-dissect))))
5911 (when (and (not ihandles)
5912 (not gnus-displaying-mime))
5913 ;; Top-level call; we clean up.
5914 (when gnus-article-mime-handles
5915 (mm-destroy-parts gnus-article-mime-handles)
5916 (setq gnus-article-mime-handle-alist nil));; A trick.
5917 (setq gnus-article-mime-handles handles)
5918 ;; We allow users to glean info from the handles.
5919 (when gnus-article-mime-part-function
5920 (gnus-mime-part-function handles)))
5921 (if (and handles
5922 (or (not (stringp (car handles)))
5923 (cdr handles)))
5924 (progn
5925 (when (and (not ihandles)
5926 (not gnus-displaying-mime))
5927 ;; Clean up for mime parts.
5928 (article-goto-body)
5929 (delete-region (point) (point-max)))
5930 (let ((gnus-displaying-mime t))
5931 (gnus-mime-display-part handles)))
5932 (save-restriction
5933 (article-goto-body)
5934 (narrow-to-region (point) (point-max))
5935 (gnus-treat-article nil 1 1 "text/plain")
5936 (widen)))
5937 (unless ihandles
5938 ;; Highlight the headers.
5939 (save-excursion
5940 (save-restriction
5941 (article-goto-body)
5942 (narrow-to-region (point-min) (point))
5943 (gnus-article-save-original-date
5944 (gnus-treat-article 'head)))))))
5945 ;; Cope with broken MIME messages.
5946 (goto-char (point-max))
5947 (unless (bolp)
5948 (insert "\n"))))
5950 (defcustom gnus-mime-display-multipart-as-mixed nil
5951 "Display \"multipart\" parts as \"multipart/mixed\".
5953 If t, it overrides nil values of
5954 `gnus-mime-display-multipart-alternative-as-mixed' and
5955 `gnus-mime-display-multipart-related-as-mixed'."
5956 :group 'gnus-article-mime
5957 :type 'boolean)
5959 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5960 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5961 :version "22.1"
5962 :group 'gnus-article-mime
5963 :type 'boolean)
5965 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5966 "Display \"multipart/related\" parts as \"multipart/mixed\".
5968 If displaying \"text/html\" is discouraged \(see
5969 `mm-discouraged-alternatives') images or other material inside a
5970 \"multipart/related\" part might be overlooked when this variable is nil."
5971 :version "22.1"
5972 :group 'gnus-article-mime
5973 :type 'boolean)
5975 (defcustom gnus-mime-display-attachment-buttons-in-header t
5976 "Add attachment buttons in the end of the header of an article.
5977 Since MIME attachments tend to be put at the end of an article, we may
5978 overlook them if there is a huge body. This option offers you a copy
5979 of all non-inlinable MIME parts as buttons shown in front of an article.
5980 If nil, don't show those extra buttons."
5981 :version "25.1"
5982 :group 'gnus-article-mime
5983 :type 'boolean)
5985 (defun gnus-mime-display-part (handle)
5986 (cond
5987 ;; Maybe a broken MIME message.
5988 ((null handle))
5989 ;; Single part.
5990 ((not (stringp (car handle)))
5991 (gnus-mime-display-single handle))
5992 ;; User-defined multipart
5993 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5994 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5995 handle))
5996 ;; multipart/alternative
5997 ((and (equal (car handle) "multipart/alternative")
5998 (not (or gnus-mime-display-multipart-as-mixed
5999 gnus-mime-display-multipart-alternative-as-mixed)))
6000 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6001 (push (cons id handle) gnus-article-mime-handle-alist)
6002 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6003 ;; multipart/related
6004 ((and (equal (car handle) "multipart/related")
6005 (not (or gnus-mime-display-multipart-as-mixed
6006 gnus-mime-display-multipart-related-as-mixed)))
6007 (gnus-mime-display-part (cadr handle)))
6008 ((equal (car handle) "multipart/signed")
6009 (gnus-add-wash-type 'signed)
6010 (gnus-mime-display-security handle))
6011 ((equal (car handle) "multipart/encrypted")
6012 (gnus-add-wash-type 'encrypted)
6013 (gnus-mime-display-security handle))
6014 ;; Other multiparts are handled like multipart/mixed.
6016 (gnus-mime-display-mixed (cdr handle)))))
6018 (defun gnus-mime-part-function (handles)
6019 (if (stringp (car handles))
6020 (mapcar 'gnus-mime-part-function (cdr handles))
6021 (funcall gnus-article-mime-part-function handles)))
6023 (defun gnus-mime-display-mixed (handles)
6024 (mapcar 'gnus-mime-display-part handles))
6026 (defun gnus-mime-display-single (handle)
6027 (let ((type (mm-handle-media-type handle))
6028 (ignored gnus-ignored-mime-types)
6029 (not-attachment t)
6030 display text)
6031 (catch 'ignored
6032 (progn
6033 (while ignored
6034 (when (string-match (pop ignored) type)
6035 (throw 'ignored nil)))
6036 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6037 (with-current-buffer gnus-summary-buffer
6038 gnus-inhibit-images)
6039 gnus-inhibit-images)
6040 (string-match "\\`image/" type)))
6041 (setq not-attachment
6042 (and (not (mm-inline-override-p handle))
6043 (or (not (mm-handle-disposition handle))
6044 (equal (car (mm-handle-disposition handle))
6045 "inline")
6046 (mm-attachment-override-p handle))))
6047 (mm-automatic-display-p handle)
6048 (or (and
6049 (mm-inlinable-p handle)
6050 (mm-inlined-p handle))
6051 (mm-automatic-external-display-p type)))
6052 (setq display t)
6053 (when (equal (mm-handle-media-supertype handle) "text")
6054 (setq text t)))
6055 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6056 beg)
6057 (unless id
6058 (setq id (1+ (length gnus-article-mime-handle-alist)))
6059 (push (cons id handle) gnus-article-mime-handle-alist))
6060 (when (and display
6061 (equal (mm-handle-media-supertype handle) "message"))
6062 (insert-char
6064 (cond ((not (bolp)) 2)
6065 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6066 (t 1))))
6067 (when (or (not display)
6068 (not (gnus-unbuttonized-mime-type-p type))
6069 (eq id gnus-mime-buttonized-part-id))
6070 (gnus-insert-mime-button
6071 handle id (list (or display (and not-attachment text)))))
6072 (setq beg (point))
6073 (cond
6074 (display
6075 (let ((mail-parse-charset gnus-newsgroup-charset)
6076 (mail-parse-ignored-charsets
6077 (save-excursion (condition-case ()
6078 (set-buffer gnus-summary-buffer)
6079 (error))
6080 gnus-newsgroup-ignored-charsets)))
6081 (gnus-bind-mm-vars (mm-display-part handle t))))
6082 ((and text not-attachment)
6083 (mm-display-inline handle)))
6084 (goto-char (point-max))
6085 (if (string-match "\\`image/" type)
6086 (gnus-article-insert-newline)
6087 (if (prog1
6088 (= (skip-chars-backward "\n") -1)
6089 (unless (eobp) (forward-char 1)))
6090 (gnus-article-insert-newline)
6091 (put-text-property (point) (point-max) 'gnus-undeletable t))
6092 (goto-char (point-max)))
6093 ;; Do highlighting.
6094 (save-excursion
6095 (save-restriction
6096 (narrow-to-region beg (point))
6097 (if (eq handle gnus-article-mime-handles)
6098 ;; The format=flowed case.
6099 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6100 ;; Don't count signature parts that are never displayed.
6101 ;; The part number should be re-calculated supposing this
6102 ;; might be a message/rfc822 part.
6103 (let (handles)
6104 (dolist (part gnus-article-mime-handles)
6105 (unless (or (stringp part)
6106 (equal (car (mm-handle-type part))
6107 "application/pgp-signature"))
6108 (push part handles)))
6109 (gnus-treat-article
6110 nil (length (memq handle handles)) (length handles)
6111 (mm-handle-media-type handle)))))))))))
6113 (defun gnus-unbuttonized-mime-type-p (type)
6114 "Say whether TYPE is to be unbuttonized."
6115 (unless gnus-inhibit-mime-unbuttonizing
6116 (when (catch 'found
6117 (let ((types gnus-unbuttonized-mime-types))
6118 (while types
6119 (when (string-match (pop types) type)
6120 (throw 'found t)))))
6121 (not (catch 'found
6122 (let ((types gnus-buttonized-mime-types))
6123 (while types
6124 (when (string-match (pop types) type)
6125 (throw 'found t)))))))))
6127 (defun gnus-article-insert-newline ()
6128 "Insert a newline, but mark it as undeletable."
6129 (put-text-property (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6131 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6132 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6133 (ihandles handles)
6134 (point (point))
6135 handle (inhibit-read-only t) from begend not-pref)
6136 (save-window-excursion
6137 (save-restriction
6138 (when ibegend
6139 (narrow-to-region (car ibegend)
6140 (or (cdr ibegend)
6141 (progn
6142 (goto-char (car ibegend))
6143 (forward-line 2)
6144 (point))))
6145 (delete-region (point-min) (point-max))
6146 (mm-remove-parts handles))
6147 (setq begend (list (point-marker)))
6148 ;; Do the toggle.
6149 (unless (setq not-pref (cadr (member preferred ihandles)))
6150 (setq not-pref (car ihandles)))
6151 (when (or ibegend
6152 (not preferred)
6153 (not (gnus-unbuttonized-mime-type-p
6154 "multipart/alternative")))
6155 (add-text-properties
6156 (setq from (point))
6157 (progn
6158 (insert (format "%d. " id))
6159 (point))
6160 `(gnus-callback
6161 (lambda (handles)
6162 (unless ,(not ibegend)
6163 (setq gnus-article-mime-handle-alist
6164 ',gnus-article-mime-handle-alist))
6165 (gnus-mime-display-alternative
6166 ',ihandles ',not-pref ',begend ,id))
6167 keymap ,gnus-mime-button-map
6168 mouse-face ,gnus-article-mouse-face
6169 face ,gnus-article-button-face
6170 gnus-part ,id
6171 article-type multipart
6172 rear-nonsticky t))
6173 (widget-convert-button 'link from (point)
6174 :action 'gnus-widget-press-button)
6175 ;; Do the handles
6176 (while (setq handle (pop handles))
6177 (add-text-properties
6178 (setq from (point))
6179 (progn
6180 (insert (format "(%c) %-18s"
6181 (if (equal handle preferred) ?* ? )
6182 (mm-handle-media-type handle)))
6183 (point))
6184 `(gnus-callback
6185 (lambda (handles)
6186 (unless ,(not ibegend)
6187 (setq gnus-article-mime-handle-alist
6188 ',gnus-article-mime-handle-alist))
6189 (gnus-mime-display-alternative
6190 ',ihandles ',handle ',begend ,id))
6191 keymap ,gnus-mime-button-map
6192 mouse-face ,gnus-article-mouse-face
6193 face ,gnus-article-button-face
6194 gnus-part ,id
6195 gnus-data ,handle
6196 rear-nonsticky t))
6197 (widget-convert-button 'link from (point)
6198 :action 'gnus-widget-press-button)
6199 (insert " "))
6200 (insert "\n\n"))
6201 (when preferred
6202 (if (stringp (car preferred))
6203 (gnus-display-mime preferred)
6204 (let ((mail-parse-charset gnus-newsgroup-charset)
6205 (mail-parse-ignored-charsets
6206 (with-current-buffer gnus-summary-buffer
6207 gnus-newsgroup-ignored-charsets)))
6208 (gnus-bind-mm-vars (mm-display-part preferred))
6209 ;; Do highlighting.
6210 (save-excursion
6211 (save-restriction
6212 (narrow-to-region (car begend) (point-max))
6213 (gnus-treat-article
6214 nil (length gnus-article-mime-handle-alist)
6215 (gnus-article-mime-total-parts)
6216 (mm-handle-media-type preferred))))))
6217 (goto-char (point-max))
6218 (setcdr begend (point-marker)))))
6219 (when ibegend
6220 (goto-char point)))
6221 ;; Redraw attachment buttons in the header.
6222 (when gnus-mime-display-attachment-buttons-in-header
6223 (gnus-mime-buttonize-attachments-in-header)))
6225 (defconst gnus-article-wash-status-strings
6226 (let ((alist '((cite "c" "Possible hidden citation text"
6227 " " "All citation text visible")
6228 (headers "h" "Hidden headers"
6229 " " "All headers visible.")
6230 (pgp "p" "Encrypted or signed message status hidden"
6231 " " "No hidden encryption nor digital signature status")
6232 (signature "s" "Signature has been hidden"
6233 " " "Signature is visible")
6234 (overstrike "o" "Overstrike (^H) characters applied"
6235 " " "No overstrike characters applied")
6236 (emphasis "e" "/*_Emphasis_*/ characters applied"
6237 " " "No /*_emphasis_*/ characters applied")))
6238 result)
6239 (dolist (entry alist result)
6240 (let ((key (nth 0 entry))
6241 (on (copy-sequence (nth 1 entry)))
6242 (on-help (nth 2 entry))
6243 (off (copy-sequence (nth 3 entry)))
6244 (off-help (nth 4 entry)))
6245 (put-text-property 0 1 'help-echo on-help on)
6246 (put-text-property 0 1 'help-echo off-help off)
6247 (push (list key on off) result))))
6248 "Alist of strings describing wash status in the mode line.
6249 Each entry has the form (KEY ON OF), where the KEY is a symbol
6250 representing the particular washing function, ON is the string to use
6251 in the article mode line when the washing function is active, and OFF
6252 is the string to use when it is inactive.")
6254 (defun gnus-article-wash-status-entry (key value)
6255 (let ((entry (assoc key gnus-article-wash-status-strings)))
6256 (if value (nth 1 entry) (nth 2 entry))))
6258 (defun gnus-article-wash-status ()
6259 "Return a string which display status of article washing."
6260 (with-current-buffer gnus-article-buffer
6261 (let ((cite (memq 'cite gnus-article-wash-types))
6262 (headers (memq 'headers gnus-article-wash-types))
6263 (boring (memq 'boring-headers gnus-article-wash-types))
6264 (pgp (memq 'pgp gnus-article-wash-types))
6265 (pem (memq 'pem gnus-article-wash-types))
6266 (signed (memq 'signed gnus-article-wash-types))
6267 (encrypted (memq 'encrypted gnus-article-wash-types))
6268 (signature (memq 'signature gnus-article-wash-types))
6269 (overstrike (memq 'overstrike gnus-article-wash-types))
6270 (emphasis (memq 'emphasis gnus-article-wash-types)))
6271 (concat
6272 (gnus-article-wash-status-entry 'cite cite)
6273 (gnus-article-wash-status-entry 'headers (or headers boring))
6274 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6275 (gnus-article-wash-status-entry 'signature signature)
6276 (gnus-article-wash-status-entry 'overstrike overstrike)
6277 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6279 (defun gnus-add-wash-type (type)
6280 "Add a washing of TYPE to the current status."
6281 (add-to-list 'gnus-article-wash-types type))
6283 (defun gnus-delete-wash-type (type)
6284 "Add a washing of TYPE to the current status."
6285 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6287 (defun gnus-add-image (category image)
6288 "Add IMAGE of CATEGORY to the list of displayed images."
6289 (let ((entry (assq category gnus-article-image-alist)))
6290 (unless entry
6291 (setq entry (list category))
6292 (push entry gnus-article-image-alist))
6293 (nconc entry (list image))))
6295 (defun gnus-delete-images (category)
6296 "Delete all images in CATEGORY."
6297 (let ((entry (assq category gnus-article-image-alist)))
6298 (dolist (image (cdr entry))
6299 (gnus-remove-image image category))
6300 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6301 (gnus-delete-wash-type category)))
6303 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6305 (defun gnus-article-maybe-hide-headers ()
6306 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6307 Provided for backwards compatibility."
6308 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6309 (not (with-current-buffer gnus-summary-buffer
6310 gnus-have-all-headers)))
6311 (not gnus-inhibit-hiding))
6312 (article-hide-headers)))
6314 (declare-function shr-put-image "shr" (data alt &optional flags))
6316 (defun gnus-shr-put-image (data alt &optional flags)
6317 "Put image DATA with a string ALT. Enable image to be deleted."
6318 (let ((image (if flags
6319 (shr-put-image data (propertize (or alt "*")
6320 'gnus-image-category 'shr)
6321 flags)
6322 ;; Old `shr-put-image' doesn't take the optional `flags'
6323 ;; argument.
6324 (shr-put-image data (propertize (or alt "*")
6325 'gnus-image-category 'shr)))))
6326 (when image
6327 (gnus-add-image 'shr image))))
6329 (defun gnus-article-mime-handles (&optional alist id all)
6330 (if alist
6331 (let ((i 1) newid flat)
6332 (dolist (handle alist flat)
6333 (setq newid (append id (list i))
6334 i (1+ i))
6335 (if (stringp (car handle))
6336 (setq flat (nconc flat (gnus-article-mime-handles
6337 (cdr handle) newid all)))
6338 (delq (rassq handle all) all)
6339 (setq flat (nconc flat (list (cons newid handle)))))))
6340 (let ((flat (list nil)))
6341 ;; Assume that elements of `gnus-article-mime-handle-alist'
6342 ;; are in the decreasing order, but unnumbered subsidiaries
6343 ;; in each element are in the increasing order.
6344 (dolist (handle (reverse gnus-article-mime-handle-alist))
6345 (if (stringp (cadr handle))
6346 (when (cddr handle)
6347 (setq flat (nconc flat (gnus-article-mime-handles
6348 (cddr handle) (list (car handle)) flat))))
6349 (delq (rassq (cdr handle) flat) flat)
6350 (setq flat (nconc flat (list (cons (list (car handle))
6351 (cdr handle)))))))
6352 (setq flat (cdr flat))
6353 (mapc (lambda (handle)
6354 (if (cdar handle)
6355 ;; This is a hidden (i.e. unnumbered) handle.
6356 (progn
6357 (setcar handle
6358 (1+ (caar gnus-article-mime-handle-alist)))
6359 (push handle gnus-article-mime-handle-alist))
6360 (setcar handle (caar handle))))
6361 flat)
6362 flat)))
6364 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6365 "Show attachments as buttons in the end of the header of an article.
6366 This function toggles the display when called interactively. Note that
6367 buttons to be added to the header are only the ones that aren't inlined
6368 in the body. Use `gnus-header-face-alist' to highlight buttons."
6369 (interactive (list t))
6370 (gnus-with-article-buffer
6371 (let ((case-fold-search t) buttons st)
6372 (save-excursion
6373 (save-restriction
6374 (widen)
6375 (article-narrow-to-head)
6376 ;; Header buttons exist?
6377 (while (and (not buttons)
6378 (re-search-forward "^attachments?:[\n ]+" nil t))
6379 (when (get-char-property (match-end 0)
6380 'gnus-button-attachment-extra)
6381 (setq buttons (match-beginning 0))))
6382 (widen)
6383 (when buttons
6384 ;; Delete header buttons.
6385 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6386 (match-beginning 0)
6387 (point-max))))
6388 (unless (and interactive buttons)
6389 ;; Find buttons.
6390 (setq buttons nil)
6391 (dolist (button (gnus-article-mime-handles))
6392 (unless (mm-handle-undisplayer (cdr button))
6393 (push button buttons)))
6394 (when buttons
6395 ;; Add header buttons.
6396 (article-goto-body)
6397 (forward-line -1)
6398 (narrow-to-region (point) (point))
6399 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6400 (dolist (button (nreverse buttons))
6401 (setq st (point))
6402 (insert " ")
6403 (gnus-insert-mime-button (cdr button) (car button))
6404 (skip-chars-backward "\t\n ")
6405 (delete-region (point) (point-max))
6406 (when (> (current-column) (window-width))
6407 (goto-char st)
6408 (insert "\n")
6409 (end-of-line)))
6410 (insert "\n")
6411 (dolist (ovl (overlays-in (point-min) (point)))
6412 (overlay-put ovl 'gnus-button-attachment-extra t)
6413 (overlay-put ovl 'face nil))
6414 (let ((gnus-treatment-function-alist
6415 '((gnus-treat-highlight-headers
6416 gnus-article-highlight-headers))))
6417 (gnus-treat-article 'head)))))))))
6419 ;;; Article savers.
6421 (defun gnus-output-to-file (file-name)
6422 "Append the current article to a file named FILE-NAME.
6423 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6424 text and used as the value of the coding cookie which is added to the
6425 top of a file. Otherwise, this function saves a raw article without
6426 the coding cookie."
6427 (let* ((artbuf (current-buffer))
6428 (file-name-coding-system nnmail-pathname-coding-system)
6429 (coding gnus-article-save-coding-system)
6430 (coding-system-for-read (if coding
6431 nil ;; Rely on the coding cookie.
6432 mm-text-coding-system))
6433 (coding-system-for-write (or coding
6434 mm-text-coding-system-for-write
6435 mm-text-coding-system))
6436 (exists (file-exists-p file-name)))
6437 (with-temp-buffer
6438 (when exists
6439 (insert-file-contents file-name)
6440 (goto-char (point-min))
6441 ;; Remove the existing coding cookie.
6442 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6443 (delete-region (match-beginning 0) (match-end 0))))
6444 (goto-char (point-max))
6445 (insert-buffer-substring artbuf)
6446 ;; Append newline at end of the buffer as separator, and then
6447 ;; save it to file.
6448 (goto-char (point-max))
6449 (insert "\n")
6450 (when coding
6451 ;; If the coding system is not suitable to encode the text,
6452 ;; ask a user for a proper one.
6453 (setq coding (coding-system-base
6454 (save-window-excursion
6455 (select-safe-coding-system (point-min) (point-max)
6456 coding))))
6457 (setq coding-system-for-write
6458 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6459 coding))
6460 (goto-char (point-min))
6461 ;; Add the coding cookie.
6462 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6463 coding-system-for-write)))
6464 (if exists
6465 (progn
6466 (write-region (point-min) (point-max) file-name nil 'no-message)
6467 (message "Appended to %s" file-name))
6468 (write-region (point-min) (point-max) file-name))))
6471 (defun gnus-narrow-to-page (&optional arg)
6472 "Narrow the article buffer to a page.
6473 If given a numerical ARG, move forward ARG pages."
6474 (interactive "P")
6475 (setq arg (if arg (prefix-numeric-value arg) 0))
6476 (with-current-buffer gnus-article-buffer
6477 (widen)
6478 ;; Remove any old next/prev buttons.
6479 (when (gnus-visual-p 'page-marker)
6480 (let ((inhibit-read-only t))
6481 (gnus-remove-text-with-property 'gnus-prev)
6482 (gnus-remove-text-with-property 'gnus-next)))
6483 (let (st nd pt)
6484 (when (save-excursion
6485 (cond ((< arg 0)
6486 (if (re-search-backward page-delimiter nil 'move (abs arg))
6487 (prog1
6488 (setq nd (match-beginning 0)
6489 pt nd)
6490 (when (re-search-backward page-delimiter nil t)
6491 (setq st (match-end 0))))
6492 (when (re-search-forward page-delimiter nil t)
6493 (setq nd (match-beginning 0)
6494 pt (point-min)))))
6495 ((> arg 0)
6496 (if (re-search-forward page-delimiter nil 'move arg)
6497 (prog1
6498 (setq st (match-end 0)
6499 pt st)
6500 (when (re-search-forward page-delimiter nil t)
6501 (setq nd (match-beginning 0))))
6502 (when (re-search-backward page-delimiter nil t)
6503 (setq st (match-end 0)
6504 pt (point-max)))))
6506 (when (re-search-backward page-delimiter nil t)
6507 (goto-char (setq st (match-end 0))))
6508 (when (re-search-forward page-delimiter nil t)
6509 (setq nd (match-beginning 0)))
6510 (or st nd))))
6511 (setq gnus-page-broken t)
6512 (when pt (goto-char pt))
6513 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6514 (when (gnus-visual-p 'page-marker)
6515 (save-excursion
6516 (when nd
6517 (goto-char nd)
6518 (gnus-insert-next-page-button))
6519 (when st
6520 (goto-char st)
6521 (gnus-insert-prev-page-button))))))))
6523 ;; Article mode commands
6525 (defun gnus-article-goto-next-page ()
6526 "Show the next page of the article."
6527 (interactive)
6528 (when (gnus-article-next-page)
6529 (goto-char (point-min))
6530 (gnus-article-read-summary-keys nil ?n)))
6533 (defun gnus-article-goto-prev-page ()
6534 "Show the previous page of the article."
6535 (interactive)
6536 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6537 (gnus-article-read-summary-keys nil ?p)
6538 (gnus-article-prev-page nil)))
6540 ;; This is cleaner but currently breaks `gnus-pick-mode':
6542 ;; (defun gnus-article-goto-next-page ()
6543 ;; "Show the next page of the article."
6544 ;; (interactive)
6545 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6546 ;; (gnus-summary-next-page)))
6548 ;; (defun gnus-article-goto-prev-page ()
6549 ;; "Show the next page of the article."
6550 ;; (interactive)
6551 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6552 ;; (gnus-summary-prev-page)))
6554 (defun gnus-article-next-page (&optional lines)
6555 "Show the next page of the current article.
6556 If end of article, return non-nil. Otherwise return nil.
6557 Argument LINES specifies lines to be scrolled up."
6558 (interactive "p")
6559 (move-to-window-line (- -1 scroll-margin))
6560 (if (and (not (and gnus-article-over-scroll
6561 (> (count-lines (window-start) (point-max))
6562 (+ (or lines (1- (window-height))) scroll-margin))))
6563 (save-excursion
6564 (end-of-line)
6565 (and (pos-visible-in-window-p) ;Not continuation line.
6566 (>= (point) (point-max)))))
6567 ;; Nothing in this page.
6568 (if (or (not gnus-page-broken)
6569 (save-excursion
6570 (save-restriction
6571 (widen)
6572 (forward-line)
6573 (eobp)))) ;Real end-of-buffer?
6574 (progn
6575 (when gnus-article-over-scroll
6576 (gnus-article-next-page-1 lines))
6577 t) ;Nothing more.
6578 (gnus-narrow-to-page 1) ;Go to next page.
6579 nil)
6580 ;; More in this page.
6581 (gnus-article-next-page-1 lines)
6582 nil))
6584 (defun gnus-article-beginning-of-window ()
6585 "Move point to the beginning of the window.
6586 The point is placed at the line number which `scroll-margin'
6587 specifies."
6588 ;; There is an obscure bug in Emacs that makes it impossible to
6589 ;; scroll past big pictures in the article buffer. Try to fix
6590 ;; this by adding a sanity check by counting the lines visible.
6591 (when (> (count-lines (window-start) (window-end)) 30)
6592 (move-to-window-line
6593 (min (max 0 scroll-margin)
6594 (max 1 (- (window-height)
6595 (if mode-line-format 1 0)
6596 (if header-line-format 1 0)
6597 2))))))
6599 (defvar scroll-in-place)
6601 (defun gnus-article-next-page-1 (lines)
6602 (condition-case ()
6603 (let ((scroll-in-place nil)
6604 (auto-window-vscroll nil))
6605 (scroll-up lines))
6606 (end-of-buffer
6607 ;; Long lines may cause an end-of-buffer error.
6608 (goto-char (point-max))))
6609 (gnus-article-beginning-of-window))
6611 (defun gnus-article-prev-page (&optional lines)
6612 "Show previous page of current article.
6613 Argument LINES specifies lines to be scrolled down."
6614 (interactive "p")
6615 (move-to-window-line 0)
6616 (if (and gnus-page-broken
6617 (bobp)
6618 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6619 (progn
6620 (gnus-narrow-to-page -1) ;Go to previous page.
6621 (goto-char (point-max))
6622 (recenter (if gnus-article-over-scroll
6623 (if lines
6624 (max (+ lines scroll-margin) 3)
6625 (- (window-height) 2))
6626 -1)))
6627 (prog1
6628 (condition-case ()
6629 (let ((scroll-in-place nil))
6630 (scroll-down lines))
6631 (beginning-of-buffer
6632 (goto-char (point-min))))
6633 (gnus-article-beginning-of-window))))
6635 (defun gnus-article-only-boring-p ()
6636 "Decide whether there is only boring text remaining in the article.
6637 Something \"interesting\" is a word of at least two letters that does
6638 not have a face in `gnus-article-boring-faces'."
6639 (when (and gnus-article-skip-boring
6640 (boundp 'gnus-article-boring-faces)
6641 (symbol-value 'gnus-article-boring-faces))
6642 (save-excursion
6643 (let ((inhibit-point-motion-hooks t))
6644 (catch 'only-boring
6645 (while (re-search-forward "\\b\\w\\w" nil t)
6646 (forward-char -1)
6647 (when (not (gnus-intersection
6648 (gnus-faces-at (point))
6649 (symbol-value 'gnus-article-boring-faces)))
6650 (throw 'only-boring nil)))
6651 (throw 'only-boring t))))))
6653 (defun gnus-article-refer-article ()
6654 "Read article specified by message-id around point."
6655 (interactive)
6656 (save-excursion
6657 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6658 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6659 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6660 (let ((msg-id (concat "<" (match-string 0) ">")))
6661 (set-buffer gnus-summary-buffer)
6662 (gnus-summary-refer-article msg-id))
6663 (error "No references around point"))))
6665 (defun gnus-article-show-summary ()
6666 "Reconfigure windows to show summary buffer."
6667 (interactive)
6668 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6669 (error "There is no summary buffer for this article buffer")
6670 (gnus-article-set-globals)
6671 (gnus-configure-windows 'article)
6672 (gnus-summary-goto-subject gnus-current-article)
6673 (gnus-summary-position-point)))
6675 (defun gnus-article-describe-briefly ()
6676 "Describe article mode commands briefly."
6677 (interactive)
6678 (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")))
6680 (defun gnus-article-check-buffer ()
6681 "Beep if not in an article buffer."
6682 (unless (derived-mode-p 'gnus-article-mode)
6683 (error "Command invoked outside of a Gnus article buffer")))
6685 (defvar gnus-pick-mode)
6687 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6688 "Read a summary buffer key sequence and execute it from the article buffer."
6689 (interactive "P")
6690 (gnus-article-check-buffer)
6691 (let ((nosaves
6692 '("q" "Q" "r" "\C-c\C-f" "m" "a" "f" "WDD" "WDW"
6693 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6694 "=" "^" "\M-^" "|"))
6695 (nosave-but-article
6696 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6697 "An" "Ap" [?A (meta return)] [?A delete]))
6698 (nosave-in-article
6699 '("AS" "\C-d"))
6700 keys new-sum-point)
6701 (with-current-buffer gnus-article-current-summary
6702 (let (gnus-pick-mode)
6703 (setq unread-command-events (nconc unread-command-events
6704 (list (or key last-command-event)))
6705 keys (read-key-sequence nil t))))
6707 (message "")
6709 (cond
6710 ((eq (aref keys (1- (length keys))) ?\C-h)
6711 (gnus-article-describe-bindings (substring keys 0 -1)))
6712 ((or (member keys nosaves)
6713 (member keys nosave-but-article)
6714 (member keys nosave-in-article))
6715 (let (func)
6716 (with-current-buffer gnus-article-current-summary
6717 ;; We disable the pick minor mode commands.
6718 (let (gnus-pick-mode)
6719 (setq func (key-binding keys t))))
6720 (if (or (not func)
6721 (numberp func))
6722 (ding)
6723 (unless (member keys nosave-in-article)
6724 (set-buffer gnus-article-current-summary))
6725 (when (and (symbolp func)
6726 (get func 'disabled))
6727 (error "Function %s disabled" func))
6728 (call-interactively func)
6729 (setq new-sum-point (point)))
6730 (when (member keys nosave-but-article)
6731 (pop-to-buffer gnus-article-buffer))))
6733 ;; These commands should restore window configuration.
6734 (let ((obuf (current-buffer))
6735 (owin (current-window-configuration))
6736 win func in-buffer selected new-sum-start new-sum-hscroll err)
6737 (cond (not-restore-window
6738 (pop-to-buffer gnus-article-current-summary)
6739 (setq win (selected-window)))
6740 ((setq win (get-buffer-window gnus-article-current-summary))
6741 (select-window win))
6743 (let ((summary-buffer gnus-article-current-summary))
6744 (gnus-configure-windows 'article)
6745 (unless (setq win (get-buffer-window summary-buffer 'visible))
6746 (let ((gnus-buffer-configuration
6747 '((article ((vertical 1.0
6748 (summary 0.25 point)
6749 (article 1.0)))))))
6750 (gnus-configure-windows 'article))
6751 (setq win (get-buffer-window summary-buffer 'visible)))
6752 (select-frame-set-input-focus (window-frame win))
6753 (select-window win))))
6754 (setq in-buffer (current-buffer))
6755 ;; We disable the pick minor mode commands.
6756 (setq func (let (gnus-pick-mode)
6757 (key-binding keys t)))
6758 (when (and (symbolp func)
6759 (get func 'disabled))
6760 (error "Function %s disabled" func))
6761 (if (and func
6762 (functionp func)
6763 (condition-case code
6764 (progn
6765 (call-interactively func)
6767 (error
6768 (setq err code)
6769 nil)))
6770 (progn
6771 (when (eq win (selected-window))
6772 (setq new-sum-point (point)
6773 new-sum-start (window-start win)
6774 new-sum-hscroll (window-hscroll win)))
6775 (when (or (eq in-buffer (current-buffer))
6776 (when (eq obuf (current-buffer))
6777 (set-buffer in-buffer)
6779 (setq selected (ignore-errors (gnus-summary-select-article)))
6780 (set-buffer obuf)
6781 (unless not-restore-window
6782 (set-window-configuration owin))
6783 (when (and (eq selected 'old)
6784 new-sum-point)
6785 (set-window-start (get-buffer-window (current-buffer))
6787 (set-window-point (get-buffer-window (current-buffer))
6788 (if (article-goto-body)
6789 (1- (point))
6790 (point))))
6791 (when (and (not not-restore-window)
6792 new-sum-point
6793 (window-live-p win)
6794 (with-current-buffer (window-buffer win)
6795 (derived-mode-p 'gnus-summary-mode)))
6796 (set-window-point win new-sum-point)
6797 (set-window-start win new-sum-start)
6798 (set-window-hscroll win new-sum-hscroll))))
6799 (set-window-configuration owin)
6800 (if err
6801 (signal (car err) (cdr err))
6802 (ding))))))))
6804 (defun gnus-article-read-summary-send-keys ()
6805 (interactive)
6806 (let ((unread-command-events (list ?S)))
6807 (gnus-article-read-summary-keys)))
6809 (defun gnus-article-describe-key (key)
6810 "Display documentation of the function invoked by KEY.
6811 KEY is a string or a vector."
6812 (interactive (list (let ((cursor-in-echo-area t))
6813 (read-key-sequence "Describe key: "))))
6814 (gnus-article-check-buffer)
6815 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6816 gnus-article-read-summary-send-keys))
6817 (with-current-buffer gnus-article-current-summary
6818 (setq unread-command-events
6819 (nconc
6820 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6821 (list 'meta (- x 128))
6823 key)
6824 unread-command-events))
6825 (let ((cursor-in-echo-area t)
6826 gnus-pick-mode)
6827 (describe-key (read-key-sequence nil t))))
6828 (describe-key key)))
6830 (defun gnus-article-describe-key-briefly (key &optional insert)
6831 "Display documentation of the function invoked by KEY.
6832 KEY is a string or a vector."
6833 (interactive (list (let ((cursor-in-echo-area t))
6834 (read-key-sequence "Describe key: "))
6835 current-prefix-arg))
6836 (gnus-article-check-buffer)
6837 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6838 gnus-article-read-summary-send-keys))
6839 (with-current-buffer gnus-article-current-summary
6840 (setq unread-command-events
6841 (nconc
6842 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6843 (list 'meta (- x 128))
6845 key)
6846 unread-command-events))
6847 (let ((cursor-in-echo-area t)
6848 gnus-pick-mode)
6849 (describe-key-briefly (read-key-sequence nil t) insert)))
6850 (describe-key-briefly key insert)))
6852 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6853 (defvar gnus-agent-summary-mode)
6854 (defvar gnus-draft-mode)
6855 (defvar help-xref-stack-item)
6856 (defvar help-xref-following)
6858 (defun gnus-article-describe-bindings (&optional prefix)
6859 "Show a list of all defined keys, and their definitions.
6860 The optional argument PREFIX, if non-nil, should be a key sequence;
6861 then we display only bindings that start with that prefix."
6862 (interactive)
6863 (gnus-article-check-buffer)
6864 (let ((keymap (copy-keymap gnus-article-mode-map))
6865 (map (copy-keymap gnus-article-send-map))
6866 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6867 (summap (make-sparse-keymap))
6868 parent agent draft)
6869 (define-key keymap "S" map)
6870 (define-key map [t] nil)
6871 (define-key summap [t] 'undefined)
6872 (with-current-buffer gnus-article-current-summary
6873 (dolist (key sumkeys)
6874 (define-key summap key (key-binding key (current-local-map))))
6875 (set-keymap-parent
6876 keymap
6877 (if (setq parent (keymap-parent gnus-article-mode-map))
6878 (prog1
6879 (setq parent (copy-keymap parent))
6880 (set-keymap-parent parent summap))
6881 summap))
6882 (set-keymap-parent map (key-binding "S"))
6883 (let (key def gnus-pick-mode)
6884 (while sumkeys
6885 (setq key (pop sumkeys))
6886 (cond ((and (vectorp key) (= (length key) 1)
6887 (consp (setq def (aref key 0)))
6888 (numberp (car def)) (numberp (cdr def)))
6889 (when (< (max (car def) (cdr def)) 128)
6890 (setq sumkeys
6891 (append (mapcar
6892 #'vector
6893 (nreverse (gnus-uncompress-range def)))
6894 sumkeys))))
6895 ((setq def (key-binding key))
6896 (unless (eq def 'undefined)
6897 (define-key keymap key def))))))
6898 (when (boundp 'gnus-agent-summary-mode)
6899 (setq agent gnus-agent-summary-mode))
6900 (when (boundp 'gnus-draft-mode)
6901 (setq draft gnus-draft-mode)))
6902 (with-temp-buffer
6903 (use-local-map keymap)
6904 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6905 (set (make-local-variable 'gnus-draft-mode) draft)
6906 (describe-bindings prefix))
6907 (let ((item `((lambda (prefix)
6908 (with-current-buffer ,(current-buffer)
6909 (gnus-article-describe-bindings prefix)))
6910 ,prefix)))
6911 ;; Loading `help-mode' here is necessary if `describe-bindings'
6912 ;; is replaced with something, e.g. `helm-descbinds'.
6913 (require 'help-mode)
6914 (with-current-buffer (let (help-xref-following) (help-buffer))
6915 (setq help-xref-stack-item item)))))
6917 (defun gnus-article-reply-with-original (&optional wide)
6918 "Start composing a reply mail to the current message.
6919 The text in the region will be yanked. If the region isn't active,
6920 the entire article will be yanked."
6921 (interactive)
6922 (let ((article (cdr gnus-article-current))
6923 contents)
6924 (if (not (and transient-mark-mode mark-active))
6925 (with-current-buffer gnus-summary-buffer
6926 (gnus-summary-reply (list (list article)) wide))
6927 (setq contents (buffer-substring (point) (mark t)))
6928 ;; Deactivate active regions.
6929 (when transient-mark-mode
6930 (setq mark-active nil))
6931 (with-current-buffer gnus-summary-buffer
6932 (gnus-summary-reply
6933 (list (list article contents)) wide)))))
6935 (defun gnus-article-wide-reply-with-original ()
6936 "Start composing a wide reply mail to the current message.
6937 The text in the region will be yanked. If the region isn't active,
6938 the entire article will be yanked."
6939 (interactive)
6940 (gnus-article-reply-with-original t))
6942 (defun gnus-article-followup-with-original ()
6943 "Compose a followup to the current article.
6944 The text in the region will be yanked. If the region isn't active,
6945 the entire article will be yanked."
6946 (interactive)
6947 (let ((article (cdr gnus-article-current))
6948 contents)
6949 (if (not (and transient-mark-mode mark-active))
6950 (with-current-buffer gnus-summary-buffer
6951 (gnus-summary-followup (list (list article))))
6952 (setq contents (buffer-substring (point) (mark t)))
6953 ;; Deactivate active regions.
6954 (when transient-mark-mode
6955 (setq mark-active nil))
6956 (with-current-buffer gnus-summary-buffer
6957 (gnus-summary-followup
6958 (list (list article contents)))))))
6960 (defun gnus-article-hide (&optional arg force)
6961 "Hide all the gruft in the current article.
6962 This means that signatures, cited text and (some) headers will be
6963 hidden.
6964 If given a prefix, show the hidden text instead."
6965 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6966 (gnus-with-article-buffer
6967 (article-hide-headers arg)
6968 (article-hide-list-identifiers)
6969 (gnus-article-hide-citation-maybe arg force)
6970 (article-hide-signature arg)))
6972 (defun gnus-check-group-server ()
6973 ;; Make sure the connection to the server is alive.
6974 (unless (gnus-server-opened
6975 (gnus-find-method-for-group gnus-newsgroup-name))
6976 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6977 (gnus-request-group gnus-newsgroup-name t)))
6979 (declare-function nneething-get-file-name "nneething" (id))
6981 (defun gnus-request-article-this-buffer (article group)
6982 "Get an article and insert it into this buffer."
6983 (let (do-update-line sparse-header)
6984 (prog1
6985 (save-excursion
6986 (erase-buffer)
6987 (gnus-kill-all-overlays)
6988 (setq bidi-paragraph-direction nil)
6989 (setq group (or group gnus-newsgroup-name))
6991 ;; Using `gnus-request-article' directly will insert the article into
6992 ;; `nntp-server-buffer' - so we'll save some time by not having to
6993 ;; copy it from the server buffer into the article buffer.
6995 ;; We only request an article by message-id when we do not have the
6996 ;; headers for it, so we'll have to get those.
6997 (when (stringp article)
6998 (gnus-read-header article))
7000 ;; If the article number is negative, that means that this article
7001 ;; doesn't belong in this newsgroup (possibly), so we find its
7002 ;; message-id and request it by id instead of number.
7003 (when (and (numberp article)
7004 gnus-summary-buffer
7005 (get-buffer gnus-summary-buffer)
7006 (gnus-buffer-exists-p gnus-summary-buffer))
7007 (with-current-buffer gnus-summary-buffer
7008 (let ((header (gnus-summary-article-header article)))
7009 (when (< article 0)
7010 (cond
7011 ((memq article gnus-newsgroup-sparse)
7012 ;; This is a sparse gap article.
7013 (setq do-update-line article)
7014 (setq gnus-newsgroup-sparse
7015 (delq article gnus-newsgroup-sparse))
7016 (setq article (mail-header-id header))
7017 (setq sparse-header (gnus-read-header article)))
7018 ((vectorp header)
7019 ;; It's a real article.
7020 (setq article (mail-header-id header)))
7022 ;; It is an extracted pseudo-article.
7023 (setq article 'pseudo)
7024 (gnus-request-pseudo-article header))))
7026 (let ((method (gnus-find-method-for-group
7027 gnus-newsgroup-name)))
7028 (when (and (eq (car method) 'nneething)
7029 (vectorp header))
7030 (let ((dir (nneething-get-file-name
7031 (mail-header-id header))))
7032 (when (and (stringp dir)
7033 (file-directory-p dir))
7034 (setq article 'nneething)
7035 (gnus-group-enter-directory dir))))))))
7037 (cond
7038 ;; Refuse to select canceled articles.
7039 ((and (numberp article)
7040 gnus-summary-buffer
7041 (get-buffer gnus-summary-buffer)
7042 (gnus-buffer-exists-p gnus-summary-buffer)
7043 (eq (cdr (with-current-buffer gnus-summary-buffer
7044 (assq article gnus-newsgroup-reads)))
7045 gnus-canceled-mark))
7046 nil)
7047 ;; We first check `gnus-original-article-buffer'.
7048 ((and (get-buffer gnus-original-article-buffer)
7049 (numberp article)
7050 (with-current-buffer gnus-original-article-buffer
7051 (and (equal (car gnus-original-article) group)
7052 (eq (cdr gnus-original-article) article))))
7053 ;; `insert-buffer-substring' would incorrectly use the
7054 ;; equivalent of string-make-multibyte which amount to decoding
7055 ;; with locale-coding-system, causing failure of
7056 ;; subsequent decoding.
7057 (insert (with-current-buffer gnus-original-article-buffer
7058 (buffer-substring (point-min) (point-max))))
7059 'article)
7060 ;; Check the backlog.
7061 ((and gnus-keep-backlog
7062 (gnus-backlog-request-article group article (current-buffer)))
7063 'article)
7064 ;; Check asynchronous pre-fetch.
7065 ((gnus-async-request-fetched-article group article (current-buffer))
7066 (gnus-async-prefetch-next group article gnus-summary-buffer)
7067 (when (and (numberp article) gnus-keep-backlog)
7068 (gnus-backlog-enter-article group article (current-buffer)))
7069 'article)
7070 ;; Check the cache.
7071 ((and gnus-use-cache
7072 (numberp article)
7073 (gnus-cache-request-article article group))
7074 'article)
7075 ;; Check the agent cache.
7076 ((gnus-agent-request-article article group)
7077 'article)
7078 ;; Get the article and put into the article buffer.
7079 ((or (stringp article)
7080 (numberp article))
7081 (let ((gnus-override-method gnus-override-method)
7082 (methods (and (stringp article)
7083 (with-current-buffer gnus-summary-buffer
7084 (gnus-refer-article-methods))))
7085 (backend (car (gnus-find-method-for-group
7086 gnus-newsgroup-name)))
7087 result
7088 (inhibit-read-only t))
7089 (when (and (null gnus-override-method)
7090 methods)
7091 (setq gnus-override-method (pop methods)))
7092 (while (not result)
7093 (erase-buffer)
7094 (gnus-kill-all-overlays)
7095 (setq bidi-paragraph-direction nil)
7096 (let ((gnus-newsgroup-name group))
7097 (gnus-check-group-server))
7098 (cond
7099 ((gnus-request-article article group (current-buffer))
7100 (when (numberp article)
7101 (gnus-async-prefetch-next group article
7102 gnus-summary-buffer)
7103 (when gnus-keep-backlog
7104 (gnus-backlog-enter-article
7105 group article (current-buffer)))
7106 (when (and gnus-agent
7107 (gnus-agent-group-covered-p group))
7108 (gnus-agent-store-article article group)))
7109 (setq result 'article))
7110 (methods
7111 (setq gnus-override-method (pop methods)))
7112 ((not (string-match "^400 "
7113 (nnheader-get-report backend)))
7114 ;; If we get 400 server disconnect, reconnect and
7115 ;; retry; otherwise, assume the article has expired.
7116 (setq result 'done))))
7117 (and (eq result 'article) 'article)))
7118 ;; It was a pseudo.
7119 (t article)))
7121 ;; Associate this article with the current summary buffer.
7122 (setq gnus-article-current-summary gnus-summary-buffer)
7124 ;; Take the article from the original article buffer
7125 ;; and place it in the buffer it's supposed to be in.
7126 (when (and (get-buffer gnus-article-buffer)
7127 (equal (buffer-name (current-buffer))
7128 (buffer-name (get-buffer gnus-article-buffer))))
7129 (save-excursion
7130 (if (get-buffer gnus-original-article-buffer)
7131 (set-buffer gnus-original-article-buffer)
7132 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7133 (buffer-disable-undo)
7134 (setq major-mode 'gnus-original-article-mode)
7135 (setq buffer-read-only t))
7136 (let ((inhibit-read-only t))
7137 (erase-buffer)
7138 (insert-buffer-substring gnus-article-buffer))
7139 (setq gnus-original-article (cons group article)))
7141 ;; Decode charsets.
7142 (run-hooks 'gnus-article-decode-hook)
7143 ;; Mark article as decoded or not.
7144 (setq gnus-article-decoded-p gnus-article-decode-hook))
7146 ;; Update sparse articles.
7147 (when (and do-update-line
7148 (or (numberp article)
7149 (stringp article)))
7150 (let ((buf (current-buffer)))
7151 (set-buffer gnus-summary-buffer)
7152 (gnus-summary-update-article do-update-line sparse-header)
7153 (gnus-summary-goto-subject do-update-line nil t)
7154 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7155 (point))
7156 (set-buffer buf))))))
7158 (defun gnus-block-private-groups (group)
7159 "Allows images in newsgroups to be shown, blocks images in all
7160 other groups."
7161 (if (or (gnus-news-group-p group)
7162 (gnus-member-of-valid 'global group))
7163 ;; Block nothing in news groups.
7165 ;; Block everything anywhere else.
7166 "."))
7168 (defun gnus-blocked-images ()
7169 (if (functionp gnus-blocked-images)
7170 (funcall gnus-blocked-images gnus-newsgroup-name)
7171 gnus-blocked-images))
7174 ;;; Article editing
7177 (defcustom gnus-article-edit-mode-hook nil
7178 "Hook run in article edit mode buffers."
7179 :group 'gnus-article-various
7180 :type 'hook)
7182 (defvar gnus-article-edit-done-function nil)
7184 (defvar gnus-article-edit-mode-map nil)
7186 ;; Should we be using derived.el for this?
7187 (unless gnus-article-edit-mode-map
7188 (setq gnus-article-edit-mode-map (make-keymap))
7189 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7191 (gnus-define-keys gnus-article-edit-mode-map
7192 "\C-c?" describe-mode
7193 "\C-c\C-c" gnus-article-edit-done
7194 "\C-c\C-k" gnus-article-edit-exit
7195 "\C-c\C-f\C-t" message-goto-to
7196 "\C-c\C-f\C-o" message-goto-from
7197 "\C-c\C-f\C-b" message-goto-bcc
7198 ;;"\C-c\C-f\C-w" message-goto-fcc
7199 "\C-c\C-f\C-c" message-goto-cc
7200 "\C-c\C-f\C-s" message-goto-subject
7201 "\C-c\C-f\C-r" message-goto-reply-to
7202 "\C-c\C-f\C-n" message-goto-newsgroups
7203 "\C-c\C-f\C-d" message-goto-distribution
7204 "\C-c\C-f\C-f" message-goto-followup-to
7205 "\C-c\C-f\C-m" message-goto-mail-followup-to
7206 "\C-c\C-f\C-k" message-goto-keywords
7207 "\C-c\C-f\C-u" message-goto-summary
7208 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7209 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7210 "\C-c\C-b" message-goto-body
7211 "\C-c\C-i" message-goto-signature
7213 "\C-c\C-t" message-insert-to
7214 "\C-c\C-n" message-insert-newsgroups
7215 "\C-c\C-o" message-sort-headers
7216 "\C-c\C-e" message-elide-region
7217 "\C-c\C-v" message-delete-not-region
7218 "\C-c\C-z" message-kill-to-signature
7219 "\M-\r" message-newline-and-reformat
7220 "\C-c\C-a" mml-attach-file
7221 "\C-a" message-beginning-of-line
7222 "\t" message-tab
7223 "\M-;" comment-region)
7225 (gnus-define-keys (gnus-article-edit-wash-map
7226 "\C-c\C-w" gnus-article-edit-mode-map)
7227 "f" gnus-article-edit-full-stops))
7229 (easy-menu-define
7230 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7231 '("Field"
7232 ["Fetch To" message-insert-to t]
7233 ["Fetch Newsgroups" message-insert-newsgroups t]
7234 "----"
7235 ["To" message-goto-to t]
7236 ["From" message-goto-from t]
7237 ["Subject" message-goto-subject t]
7238 ["Cc" message-goto-cc t]
7239 ["Reply-To" message-goto-reply-to t]
7240 ["Summary" message-goto-summary t]
7241 ["Keywords" message-goto-keywords t]
7242 ["Newsgroups" message-goto-newsgroups t]
7243 ["Followup-To" message-goto-followup-to t]
7244 ["Mail-Followup-To" message-goto-mail-followup-to t]
7245 ["Distribution" message-goto-distribution t]
7246 ["Body" message-goto-body t]
7247 ["Signature" message-goto-signature t]))
7249 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7250 "Major mode for editing articles.
7251 This is an extended text-mode.
7253 \\{gnus-article-edit-mode-map}"
7254 (make-local-variable 'gnus-article-edit-done-function)
7255 (make-local-variable 'gnus-prev-winconf)
7256 (set (make-local-variable 'font-lock-defaults)
7257 '(message-font-lock-keywords t))
7258 (set (make-local-variable 'mail-header-separator) "")
7259 (set (make-local-variable 'gnus-article-edit-mode) t)
7260 (easy-menu-add message-mode-field-menu message-mode-map)
7261 (mml-mode)
7262 (setq buffer-read-only nil)
7263 (buffer-enable-undo)
7264 (widen))
7266 (defun gnus-article-edit (&optional force)
7267 "Edit the current article.
7268 This will have permanent effect only in mail groups.
7269 If FORCE is non-nil, allow editing of articles even in read-only
7270 groups."
7271 (interactive "P")
7272 (when (and (not force)
7273 (gnus-group-read-only-p))
7274 (error "The current newsgroup does not support article editing"))
7275 (gnus-with-article-buffer
7276 (article-date-original))
7277 (gnus-article-edit-article
7278 'ignore
7279 `(lambda (no-highlight)
7280 'ignore
7281 (gnus-summary-edit-article-done
7282 ,(or (mail-header-references gnus-current-headers) "")
7283 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7285 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7286 "Start editing the contents of the current article buffer."
7287 (let ((winconf (current-window-configuration)))
7288 (set-buffer gnus-article-buffer)
7289 (let ((message-auto-save-directory
7290 ;; Don't associate the article buffer with a draft file.
7291 nil))
7292 (gnus-article-edit-mode))
7293 (funcall start-func)
7294 (set-buffer-modified-p nil)
7295 (gnus-configure-windows 'edit-article)
7296 (setq gnus-article-edit-done-function exit-func)
7297 (setq gnus-prev-winconf winconf)
7298 (unless quiet
7299 (gnus-message 6 "C-c C-c to end edits"))))
7301 (defun gnus-article-edit-done (&optional arg)
7302 "Update the article edits and exit."
7303 (interactive "P")
7304 (let ((func gnus-article-edit-done-function)
7305 (buf (current-buffer))
7306 (start (window-start))
7307 (winconf gnus-prev-winconf))
7308 (widen) ;; Widen it in case that users narrowed the buffer.
7309 (funcall func arg)
7310 (set-buffer buf)
7311 ;; The cache and backlog have to be flushed somewhat.
7312 (when gnus-keep-backlog
7313 (gnus-backlog-remove-article
7314 (car gnus-article-current) (cdr gnus-article-current)))
7315 ;; Flush original article as well.
7316 (gnus-flush-original-article-buffer)
7317 (when gnus-use-cache
7318 (gnus-cache-update-article
7319 (car gnus-article-current) (cdr gnus-article-current)))
7320 ;; We remove all text props from the article buffer.
7321 (kill-all-local-variables)
7322 (set-text-properties (point-min) (point-max) nil)
7323 (gnus-article-mode)
7324 (set-window-configuration winconf)
7325 (set-buffer buf)
7326 (set-window-start (get-buffer-window buf) start)
7327 (set-window-point (get-buffer-window buf) (point)))
7328 (gnus-summary-show-article))
7330 (defun gnus-flush-original-article-buffer ()
7331 (when (get-buffer gnus-original-article-buffer)
7332 (with-current-buffer gnus-original-article-buffer
7333 (setq gnus-original-article nil))))
7335 (defun gnus-article-edit-exit ()
7336 "Exit the article editing without updating."
7337 (interactive)
7338 (when (or (not (buffer-modified-p))
7339 (yes-or-no-p "Article modified; kill anyway? "))
7340 (let ((curbuf (current-buffer))
7341 (p (point))
7342 (window-start (window-start)))
7343 (erase-buffer)
7344 (if (gnus-buffer-live-p gnus-original-article-buffer)
7345 (insert-buffer-substring gnus-original-article-buffer))
7346 (let ((winconf gnus-prev-winconf))
7347 (kill-all-local-variables)
7348 (gnus-article-mode)
7349 (set-window-configuration winconf)
7350 ;; Tippy-toe some to make sure that point remains where it was.
7351 (save-current-buffer
7352 (set-buffer curbuf)
7353 (set-window-start (get-buffer-window (current-buffer)) window-start)
7354 (goto-char p))))
7355 (gnus-summary-show-article)))
7357 (defun gnus-article-edit-full-stops ()
7358 "Interactively repair spacing at end of sentences."
7359 (interactive)
7360 (save-excursion
7361 (goto-char (point-min))
7362 (search-forward-regexp "^$" nil t)
7363 (let ((case-fold-search nil))
7364 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7367 ;;; Article highlights
7370 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7372 ;;; Internal Variables:
7374 (defcustom gnus-button-url-regexp
7375 (concat
7376 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7377 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7378 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7379 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7380 (punct "!?:;.,"))
7381 (concat
7382 "\\(?:"
7383 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7384 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7385 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7386 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7387 "\\|"
7388 "[" chars punct "]+" "[" chars "]"
7389 "\\)"))
7390 "\\)")
7391 "Regular expression that matches URLs."
7392 :version "24.4"
7393 :group 'gnus-article-buttons
7394 :type 'regexp)
7396 (defcustom gnus-button-valid-fqdn-regexp "\\([-A-Za-z0-9]+\\.\\)+[A-Za-z]+"
7397 "Regular expression that matches a valid FQDN."
7398 :version "26.1"
7399 :group 'gnus-article-buttons
7400 :type 'regexp)
7402 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7403 (defcustom gnus-button-valid-localpart-regexp
7404 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7405 "Regular expression that matches a localpart of mail addresses or MIDs."
7406 :version "22.1"
7407 :group 'gnus-article-buttons
7408 :type 'regexp)
7410 (defcustom gnus-button-man-handler 'manual-entry
7411 "Function to use for displaying man pages.
7412 The function must take at least one argument with a string naming the
7413 man page."
7414 :version "22.1"
7415 :type '(choice (function-item :tag "Man" manual-entry)
7416 (function-item :tag "Woman" woman)
7417 (function :tag "Other"))
7418 :group 'gnus-article-buttons)
7420 (defcustom gnus-button-mid-or-mail-regexp
7421 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7422 gnus-button-valid-fqdn-regexp
7423 ">?\\)\\b")
7424 "Regular expression that matches a message ID or a mail address."
7425 :version "22.1"
7426 :group 'gnus-article-buttons
7427 :type 'regexp)
7429 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7430 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7431 Strings like this can be either a message ID or a mail address. If it is one
7432 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7433 message ID or a mail address, respectively. If this variable is set to the
7434 symbol `ask', always query the user what do do. If it is a function, this
7435 function will be called with the string as its only argument. The function
7436 must return `mid', `mail', `invalid' or `ask'."
7437 :version "22.1"
7438 :group 'gnus-article-buttons
7439 :type '(choice (function-item :tag "Heuristic function"
7440 gnus-button-mid-or-mail-heuristic)
7441 (const ask)
7442 (const mid)
7443 (const mail)))
7445 (defcustom gnus-button-mid-or-mail-heuristic-alist
7446 '((-10.0 . ".+\\$.+@")
7447 (-10.0 . "#")
7448 (-10.0 . "\\*")
7449 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7450 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7451 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7452 (-1.0 . "^[^a-z]+@")
7454 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7455 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7456 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7457 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7459 (-2.0 . "^[0-9]")
7460 (-1.0 . "^[0-9][0-9]")
7462 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7463 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7464 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7465 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7467 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7468 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7469 ;; "[0-9]{8,}.*\@"
7470 (-3.0
7471 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7472 ;; "[0-9]{12,}.*\@"
7473 ;; compensation for TDMA dated mail addresses:
7474 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7476 (-20.0 . "\\.fsf@") ;; Gnus
7477 (-20.0 . "^slrn")
7478 (-20.0 . "^Pine")
7479 (-20.0 . "^alpine\\.")
7480 (-20.0 . "_-_") ;; Subject change in thread
7482 (-20.0 . "\\.ln@") ;; leafnode
7483 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7484 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7486 ;; (5.0 . "") ;; $local_part_len <= 7
7487 (10.0 . "^[^0-9]+@")
7488 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7489 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7490 (3.0 . "@stud")
7492 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7494 (0.5 . "^[A-Z][a-z]")
7495 (0.5 . "^[A-Z][a-z][a-z]")
7496 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7497 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7498 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7500 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7501 address. The REGEXP is processed with `case-fold-search' set to nil."
7502 :version "22.1"
7503 :group 'gnus-article-buttons
7504 :type '(repeat (cons (number :tag "Rate")
7505 (regexp :tag "Regexp"))))
7507 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7508 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7509 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7510 address, `ask' if unsure and `invalid' if the string is invalid."
7511 (let ((case-fold-search nil)
7512 (list gnus-button-mid-or-mail-heuristic-alist)
7513 (result 0) rate regexp lpartlen elem)
7514 (setq lpartlen
7515 (length (replace-regexp-in-string "^\\(.*\\)@.*$" "\\1" mid-or-mail)))
7516 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7517 ;; Certain special cases...
7518 (when (string-match
7519 (concat
7520 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7521 "^[0-9]+\\.[0-9]+@compuserve\\|"
7522 "@public\\.gmane\\.org")
7523 mid-or-mail)
7524 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7525 (setq result 'mail))
7526 (when (string-match "@.*@\\| " mid-or-mail)
7527 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7528 (setq result 'invalid))
7529 ;; Nothing more to do, if result is not a number here...
7530 (when (numberp result)
7531 (while list
7532 (setq elem (car list)
7533 rate (car elem)
7534 regexp (cdr elem)
7535 list (cdr list))
7536 (when (string-match regexp mid-or-mail)
7537 (setq result (+ result rate))
7538 (gnus-message
7539 9 "`%s' matched `%s', rate `%s', result `%s'."
7540 mid-or-mail regexp rate result)))
7541 (when (<= lpartlen 7)
7542 (setq result (+ result 5.0))
7543 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7544 mid-or-mail result))
7545 (when (>= lpartlen 12)
7546 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7547 (cond
7548 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7549 ;; Long local part should contain realname if e-mail address,
7550 ;; too many digits: message-id.
7551 ;; $score -= 5.0 + 0.1 * $local_part_len;
7552 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7553 (setq result (+ result rate))
7554 (gnus-message
7555 9 "Many digits in `%s', rate `%s', result `%s'."
7556 mid-or-mail rate result))
7557 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7558 mid-or-mail)
7559 ;; Too few vowels [^aeiouy]{4,}.*@
7560 (setq result (+ result -5.0))
7561 (gnus-message
7562 9 "Few vowels in `%s', rate `%s', result `%s'."
7563 mid-or-mail -5.0 result))
7565 (setq result (+ result 5.0))
7566 (gnus-message
7567 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7568 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7569 ;; Maybe we should make this a customizable alist: (condition . 'result)
7570 (cond
7571 ((symbolp result) result)
7572 ;; Now convert number into proper results:
7573 ((< result -10.0) 'mid)
7574 ((> result 10.0) 'mail)
7575 (t 'ask))))
7577 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7578 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7579 (url-mid (concat "news" ":" mid-or-mail))
7580 (url-mailto (concat "mailto" ":" mid-or-mail)))
7581 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7582 (when (fboundp pref)
7583 (setq guessed
7584 ;; get rid of surrounding angles...
7585 (funcall pref
7586 (replace-regexp-in-string "^<\\|>$" "" mid-or-mail)))
7587 (if (or (eq 'mid guessed) (eq 'mail guessed))
7588 (setq pref guessed)
7589 (setq pref 'ask)))
7590 (if (eq pref 'ask)
7591 (save-window-excursion
7592 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7593 (setq pref 'mail)
7594 (setq pref 'mid))))
7595 (cond ((eq pref 'mid)
7596 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7597 (gnus-button-handle-news url-mid))
7598 ((eq pref 'mail)
7599 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7600 (gnus-url-mailto url-mailto))
7601 (t (gnus-message 3 "Invalid string.")))))
7603 (defun gnus-button-handle-custom (fun arg)
7604 "Call function FUN on argument ARG.
7605 Both FUN and ARG are supposed to be strings. ARG will be passed
7606 as a symbol to FUN."
7607 (funcall (intern fun)
7608 (if (string-match "^customize-apropos" fun)
7610 (intern arg))))
7612 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7614 (defun gnus-button-handle-describe-function (url)
7615 "Call `describe-function' when pushing the corresponding URL button."
7616 (describe-function
7617 (intern
7618 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7620 (defun gnus-button-handle-describe-variable (url)
7621 "Call `describe-variable' when pushing the corresponding URL button."
7622 (describe-variable
7623 (intern
7624 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7626 (defun gnus-button-handle-symbol (url)
7627 "Display help on variable or function.
7628 Calls `describe-variable' or `describe-function'."
7629 (let ((sym (intern url)))
7630 (cond
7631 ((fboundp sym) (describe-function sym))
7632 ((boundp sym) (describe-variable sym))
7633 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7635 (defun gnus-button-handle-describe-key (url)
7636 "Call `describe-key' when pushing the corresponding URL button."
7637 (let* ((key-string
7638 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))
7639 (keys (ignore-errors (eval `(kbd ,key-string)))))
7640 (if keys
7641 (describe-key keys)
7642 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7644 (defun gnus-button-handle-apropos (url)
7645 "Call `apropos' when pushing the corresponding URL button."
7646 (apropos (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7648 (defun gnus-button-handle-apropos-command (url)
7649 "Call `apropos' when pushing the corresponding URL button."
7650 (apropos-command
7651 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7653 (defun gnus-button-handle-apropos-variable (url)
7654 "Call `apropos' when pushing the corresponding URL button."
7655 (apropos-variable
7656 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7658 (defun gnus-button-handle-apropos-documentation (url)
7659 "Call `apropos' when pushing the corresponding URL button."
7660 (apropos-documentation
7661 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7663 (defun gnus-button-handle-library (url)
7664 "Call `locate-library' when pushing the corresponding URL button."
7665 (gnus-message 9 "url=`%s'" url)
7666 (let* ((lib (locate-library url))
7667 (file (replace-regexp-in-string "\\.elc" ".el" (or lib ""))))
7668 (if (not lib)
7669 (gnus-message 1 "Cannot locate library `%s'." url)
7670 (find-file-read-only file))))
7672 (defcustom gnus-button-man-level 5
7673 "Integer that says how many man-related buttons Gnus will show.
7674 The higher the number, the more buttons will appear and the more false
7675 positives are possible. Note that you can set this variable local to
7676 specific groups. Setting it higher in Unix groups is probably a good idea.
7677 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7678 how to set variables in specific groups."
7679 :version "22.1"
7680 :group 'gnus-article-buttons
7681 :link '(custom-manual "(gnus)Group Parameters")
7682 :type 'integer)
7684 (defcustom gnus-button-emacs-level 5
7685 "Integer that says how many emacs-related buttons Gnus will show.
7686 The higher the number, the more buttons will appear and the more false
7687 positives are possible. Note that you can set this variable local to
7688 specific groups. Setting it higher in Emacs or Gnus related groups is
7689 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7690 `gnus-parameters' on how to set variables in specific groups."
7691 :version "22.1"
7692 :group 'gnus-article-buttons
7693 :link '(custom-manual "(gnus)Group Parameters")
7694 :type 'integer)
7696 (defcustom gnus-button-message-level 5
7697 "Integer that says how many buttons for news or mail messages will appear.
7698 The higher the number, the more buttons will appear and the more false
7699 positives are possible."
7700 ;; mail addresses, MIDs, URLs for news, ...
7701 :version "22.1"
7702 :group 'gnus-article-buttons
7703 :type 'integer)
7705 (defcustom gnus-button-browse-level 5
7706 "Integer that says how many buttons for browsing will appear.
7707 The higher the number, the more buttons will appear and the more false
7708 positives are possible."
7709 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7710 :version "22.1"
7711 :group 'gnus-article-buttons
7712 :type 'integer)
7714 (defcustom gnus-button-alist
7715 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7716 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7717 ((concat "\\b\\(nntp\\|news\\):\\("
7718 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7719 0 t gnus-button-handle-news 2)
7720 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7721 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7722 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7723 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7724 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7725 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7726 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7727 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7728 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7729 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7730 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7731 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7732 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7733 ;; RFC 2368 (The mailto URL scheme)
7734 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7735 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7736 ("\\bmailto:\\([^ \n\t]+\\)"
7737 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7738 ;; Info Konqueror style <info:/foo/bar baz>.
7739 ;; Must come before " Gnus home-grown style".
7740 ("\\binfo://?\\([^'\">\n\t]+\\)"
7741 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7742 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7743 ("\\binfo://\\([^'\">\n\t ]+\\)"
7744 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7745 ;; Info GNOME style <info:foo#bar_baz>
7746 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7747 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7748 ;; Info KDE style <info:(foo)bar baz>
7749 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7750 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7751 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7752 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7753 ("\\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,]*\\)\\)?"
7754 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7755 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7756 ;; This is custom
7757 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7758 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7759 ;; Emacs help commands
7760 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7761 ;; regexp doesn't match arguments containing ` '.
7762 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7763 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7764 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7765 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7766 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7767 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7768 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7769 ;; The following entries may lead to many false positives so don't enable
7770 ;; them by default (use a high button level).
7771 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7772 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7773 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7774 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7775 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7776 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7777 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7778 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7779 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7780 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7781 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7782 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7783 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7784 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7785 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7786 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7787 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7788 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7789 ;; Unlike the other regexps we really have to require quoting
7790 ;; here to determine where it ends.
7791 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7792 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7793 ("<URL: *\\([^\n<>]*\\)>"
7794 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7795 ;; RFC 2396 (2.4.3., delims) ...
7796 ("\"URL: *\\([^\n\"]*\\)\""
7797 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7798 ;; Raw URLs.
7799 (gnus-button-url-regexp
7800 0 (>= gnus-button-browse-level 0) browse-url 0)
7801 ;; man pages
7802 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7803 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7804 gnus-button-handle-man 1)
7805 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7806 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7807 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7808 gnus-button-handle-man 1)
7809 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7810 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7811 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7812 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7813 ;; Recognizing patches to .el files. This is somewhat obscure,
7814 ;; but considering the percentage of Gnus users who hack Emacs
7815 ;; Lisp files...
7816 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7817 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7818 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7819 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7820 ;; MID or mail: To avoid too many false positives we don't try to catch
7821 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7822 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7823 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7824 ;; so that non-ambiguous entries (see above) match first.
7825 (gnus-button-mid-or-mail-regexp
7826 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7827 "Alist of regexps matching buttons in article bodies.
7829 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7830 REGEXP: is the string (case insensitive) matching text around the button (can
7831 also be Lisp expression evaluating to a string),
7832 BUTTON: is the number of the regexp grouping actually matching the button,
7833 FORM: is a Lisp expression which must eval to true for the button to
7834 be added,
7835 CALLBACK: is the function to call when the user push this button, and each
7836 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7838 CALLBACK can also be a variable, in that case the value of that
7839 variable it the real callback function."
7840 :group 'gnus-article-buttons
7841 :type '(repeat (list (choice regexp variable sexp)
7842 (integer :tag "Button")
7843 (sexp :tag "Form")
7844 (function :tag "Callback")
7845 (repeat :tag "Par"
7846 :inline t
7847 (integer :tag "Regexp group")))))
7848 (put 'gnus-button-alist 'risky-local-variable t)
7850 (defcustom gnus-header-button-alist
7851 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7852 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7853 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7854 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7855 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7856 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7857 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7858 0 (>= gnus-button-browse-level 0) browse-url 0)
7859 ("^Subject:" gnus-button-url-regexp
7860 0 (>= gnus-button-browse-level 0) browse-url 0)
7861 ("^[^:]+:" gnus-button-url-regexp
7862 0 (>= gnus-button-browse-level 0) browse-url 0)
7863 ("^OpenPGP:.*url=" gnus-button-url-regexp
7864 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7865 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7866 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7867 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7868 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7869 "Alist of headers and regexps to match buttons in article heads.
7871 This alist is very similar to `gnus-button-alist', except that each
7872 alist has an additional HEADER element first in each entry:
7874 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7876 HEADER is a regexp to match a header. For a fuller explanation, see
7877 `gnus-button-alist'."
7878 :group 'gnus-article-buttons
7879 :group 'gnus-article-headers
7880 :type '(repeat (list (regexp :tag "Header")
7881 (choice regexp variable)
7882 (integer :tag "Button")
7883 (sexp :tag "Form")
7884 (function :tag "Callback")
7885 (repeat :tag "Par"
7886 :inline t
7887 (integer :tag "Regexp group")))))
7888 (put 'gnus-header-button-alist 'risky-local-variable t)
7890 ;;; Commands:
7892 (defun gnus-article-push-button (event)
7893 "Check text under the mouse pointer for a callback function.
7894 If the text under the mouse pointer has a `gnus-callback' property,
7895 call it with the value of the `gnus-data' text property."
7896 (interactive "e")
7897 (set-buffer (window-buffer (posn-window (event-start event))))
7898 (let* ((pos (posn-point (event-start event)))
7899 (data (get-text-property pos 'gnus-data))
7900 (fun (get-text-property pos 'gnus-callback)))
7901 (goto-char pos)
7902 (when fun
7903 (funcall fun data))))
7905 (defun gnus-article-press-button ()
7906 "Check text at point for a callback function.
7907 If the text at point has a `gnus-callback' property,
7908 call it with the value of the `gnus-data' text property."
7909 (interactive)
7910 (let ((data (get-text-property (point) 'gnus-data))
7911 (fun (get-text-property (point) 'gnus-callback)))
7912 (when fun
7913 (funcall fun data))))
7915 (defun gnus-article-highlight (&optional force)
7916 "Highlight current article.
7917 This function calls `gnus-article-highlight-headers',
7918 `gnus-article-highlight-citation',
7919 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7920 do the highlighting. See the documentation for those functions."
7921 (interactive (list 'force))
7922 (gnus-article-highlight-headers)
7923 (gnus-article-highlight-citation force)
7924 (gnus-article-highlight-signature)
7925 (gnus-article-add-buttons)
7926 (gnus-article-add-buttons-to-head))
7928 (defun gnus-article-highlight-some (&optional _force)
7929 "Highlight current article.
7930 This function calls `gnus-article-highlight-headers',
7931 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7932 do the highlighting. See the documentation for those functions."
7933 (interactive (list 'force))
7934 (gnus-article-highlight-headers)
7935 (gnus-article-highlight-signature)
7936 (gnus-article-add-buttons))
7938 (defun gnus-article-highlight-headers ()
7939 "Highlight article headers as specified by `gnus-header-face-alist'."
7940 (interactive)
7941 (gnus-with-article-headers
7942 (let (regexp header-face field-face from hpoints fpoints)
7943 (dolist (entry gnus-header-face-alist)
7944 (goto-char (point-min))
7945 (setq regexp (concat "^\\("
7946 (if (string-equal "" (nth 0 entry))
7947 "[^\t ]"
7948 (nth 0 entry))
7949 "\\)")
7950 header-face (nth 1 entry)
7951 field-face (nth 2 entry))
7952 (while (and (re-search-forward regexp nil t)
7953 (not (eobp)))
7954 (beginning-of-line)
7955 (setq from (point))
7956 (unless (search-forward ":" nil t)
7957 (forward-char 1))
7958 (when (and header-face
7959 (not (memq (point) hpoints)))
7960 (push (point) hpoints)
7961 (put-text-property from (point) 'face header-face))
7962 (when (and field-face
7963 (not (memq (setq from (point)) fpoints)))
7964 (push from fpoints)
7965 (if (re-search-forward "^[^ \t]" nil t)
7966 (forward-char -2)
7967 (goto-char (point-max)))
7968 (put-text-property from (point) 'face field-face)))))))
7970 (defun gnus-article-highlight-signature ()
7971 "Highlight the signature in an article.
7972 It does this by highlighting everything after
7973 `gnus-signature-separator' using the face `gnus-signature'."
7974 (interactive)
7975 (gnus-with-article-buffer
7976 (let ((inhibit-point-motion-hooks t))
7977 (save-restriction
7978 (when (and gnus-signature-face
7979 (gnus-article-narrow-to-signature))
7980 (overlay-put (make-overlay (point-min) (point-max) nil t)
7981 'face gnus-signature-face)
7982 (widen)
7983 (gnus-article-search-signature)
7984 (let ((start (match-beginning 0))
7985 (end (set-marker (make-marker) (1+ (match-end 0)))))
7986 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7987 end)))))))
7989 (defun gnus-button-in-region-p (b e prop)
7990 "Say whether PROP exists in the region."
7991 (text-property-not-all b e prop nil))
7993 (defun gnus-article-add-buttons ()
7994 "Find external references in the article and make buttons of them.
7995 \"External references\" are things like Message-IDs and URLs, as
7996 specified by `gnus-button-alist'."
7997 (interactive)
7998 (gnus-with-article-buffer
7999 (let ((inhibit-point-motion-hooks t)
8000 (case-fold-search t)
8001 (alist gnus-button-alist)
8002 beg entry regexp)
8003 ;; We skip the headers.
8004 (article-goto-body)
8005 (setq beg (point))
8006 (while (setq entry (pop alist))
8007 (setq regexp (eval (car entry)))
8008 (goto-char beg)
8009 (while (re-search-forward regexp nil t)
8010 (let ((start (match-beginning (nth 1 entry)))
8011 (end (match-end (nth 1 entry)))
8012 (from (match-beginning 0)))
8013 (when (and (eval (nth 2 entry))
8014 (not (gnus-button-in-region-p
8015 start end 'gnus-callback)))
8016 ;; That optional form returned non-nil, so we add the
8017 ;; button.
8018 (setq from (set-marker (make-marker) from))
8019 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8020 (gnus-article-extend-url-button from start end))
8021 (gnus-article-add-button start end
8022 'gnus-button-push (list from entry))
8023 (put-text-property
8024 start end
8025 'gnus-string (buffer-substring-no-properties
8026 start end))))))))))
8028 (defun gnus-article-extend-url-button (beg start end)
8029 "Extend url button if url is folded into two or more lines.
8030 Return non-nil if button is extended. BEG is a marker that points to
8031 the beginning position of a text containing url. START and END are
8032 the endpoints of a url button before it is extended. The concatenated
8033 url is put as the `gnus-button-url' overlay property on the button."
8034 (let ((opoint (point))
8035 (points (list start end))
8036 url delim regexp)
8037 (prog1
8038 (when (and (progn
8039 (goto-char end)
8040 (not (looking-at "[\t ]*[\">]")))
8041 (progn
8042 (goto-char start)
8043 (string-match
8044 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8045 (buffer-substring (point-at-bol) start)))
8046 (progn
8047 (setq url (list (buffer-substring start end))
8048 delim (if (match-beginning 1) ">" "\""))
8049 (beginning-of-line)
8050 (setq regexp (concat
8051 (when (and (looking-at
8052 message-cite-prefix-regexp)
8053 (< (match-end 0) start))
8054 (regexp-quote (match-string 0)))
8056 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8057 delim "\\)"))
8058 (while (progn
8059 (forward-line 1)
8060 (and (looking-at regexp)
8061 (prog1
8062 (match-beginning 1)
8063 (push (or (match-string 2)
8064 (match-string 1))
8065 url)
8066 (push (setq end (or (match-end 2)
8067 (match-end 1)))
8068 points)
8069 (push (or (match-beginning 2)
8070 (match-beginning 1))
8071 points)))))
8072 (match-beginning 2)))
8073 (let (gnus-article-mouse-face widget-mouse-face)
8074 (while points
8075 (gnus-article-add-button (pop points) (pop points)
8076 'gnus-button-push
8077 (list beg (assq 'gnus-button-url-regexp
8078 gnus-button-alist)))))
8079 (let ((overlay (make-overlay start end)))
8080 (overlay-put overlay 'evaporate t)
8081 (overlay-put overlay 'gnus-button-url
8082 (list (mapconcat 'identity (nreverse url) "")))
8083 (when gnus-article-mouse-face
8084 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8086 (goto-char opoint))))
8088 ;; Add buttons to the head of an article.
8089 (defun gnus-article-add-buttons-to-head ()
8090 "Add buttons to the head of the article."
8091 (interactive)
8092 (gnus-with-article-headers
8093 (let (beg end)
8094 (dolist (entry gnus-header-button-alist)
8095 ;; Each alist entry.
8096 (goto-char (point-min))
8097 (while (re-search-forward (car entry) nil t)
8098 ;; Each header matching the entry.
8099 (setq beg (match-beginning 0))
8100 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8101 (match-beginning 0))
8102 (point-max)))
8103 (goto-char beg)
8104 (while (re-search-forward (eval (nth 1 entry)) end t)
8105 ;; Each match within a header.
8106 (let* ((entry (cdr entry))
8107 (start (match-beginning (nth 1 entry)))
8108 (end (match-end (nth 1 entry)))
8109 (form (nth 2 entry)))
8110 (goto-char (match-end 0))
8111 (when (eval form)
8112 (gnus-article-add-button
8113 start end (nth 3 entry)
8114 (buffer-substring (match-beginning (nth 4 entry))
8115 (match-end (nth 4 entry)))))))
8116 (goto-char end))))))
8118 ;;; External functions:
8120 (defun gnus-article-add-button (from to fun &optional data text)
8121 "Create a button between FROM and TO with callback FUN and data DATA."
8122 (when gnus-article-button-face
8123 (overlay-put (make-overlay from to nil t)
8124 'face gnus-article-button-face))
8125 (add-text-properties
8126 from to
8127 (nconc (and gnus-article-mouse-face
8128 (list 'mouse-face gnus-article-mouse-face))
8129 (list 'gnus-callback fun)
8130 (and data (list 'gnus-data data))))
8131 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8132 :help-echo (or text "Follow the link")
8133 :keymap gnus-url-button-map))
8135 (defun gnus-article-copy-string ()
8136 "Copy the string in the button to the kill ring."
8137 (interactive)
8138 (gnus-article-check-buffer)
8139 (let ((data (get-text-property (point) 'gnus-string)))
8140 (when data
8141 (with-temp-buffer
8142 (insert data)
8143 (copy-region-as-kill (point-min) (point-max))
8144 (message "Copied %s" data)))))
8146 ;;; Internal functions:
8148 (defun gnus-article-set-globals ()
8149 (with-current-buffer gnus-summary-buffer
8150 (gnus-set-global-variables)))
8152 (defun gnus-signature-toggle (end)
8153 (gnus-with-article-buffer
8154 (let ((inhibit-point-motion-hooks t))
8155 (if (text-property-any end (point-max) 'article-type 'signature)
8156 (progn
8157 (gnus-delete-wash-type 'signature)
8158 (gnus-remove-text-properties-when
8159 'article-type 'signature end (point-max)
8160 (cons 'article-type (cons 'signature
8161 gnus-hidden-properties))))
8162 (gnus-add-wash-type 'signature)
8163 (gnus-add-text-properties-when
8164 'article-type nil end (point-max)
8165 (cons 'article-type (cons 'signature
8166 gnus-hidden-properties)))))
8167 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8168 (gnus-set-mode-line 'article))))
8170 (defun gnus-button-push (marker-and-entry)
8171 ;; Push button starting at MARKER.
8172 (save-excursion
8173 (let* ((marker (car marker-and-entry))
8174 (entry (cadr marker-and-entry))
8175 (regexp (car entry))
8176 (inhibit-point-motion-hooks t))
8177 (goto-char marker)
8178 ;; This is obviously true, or something bad is happening :)
8179 ;; But we need it to have the match-data
8180 (when (looking-at (or (if (symbolp regexp)
8181 (symbol-value regexp)
8182 regexp)))
8183 (let ((fun (nth 3 entry))
8184 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8185 (get-char-property marker 'gnus-button-url))
8186 (mapcar (lambda (group)
8187 (let ((string (match-string group)))
8188 (set-text-properties
8189 0 (length string) nil string)
8190 string))
8191 (nthcdr 4 entry)))))
8193 (cond
8194 ((fboundp fun)
8195 (apply fun args))
8196 ((and (boundp fun)
8197 (fboundp (symbol-value fun)))
8198 (apply (symbol-value fun) args))
8200 (gnus-message 1 "You must define `%S' to use this button"
8201 (cons fun args)))))))))
8203 (defun gnus-parse-news-url (url)
8204 (let (scheme server port group message-id articles)
8205 (with-temp-buffer
8206 (insert url)
8207 (goto-char (point-min))
8208 (when (looking-at "\\([A-Za-z]+\\):")
8209 (setq scheme (match-string 1))
8210 (goto-char (match-end 0)))
8211 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8212 (setq server (match-string 1))
8213 (setq port (if (stringp (match-string 3))
8214 (string-to-number (match-string 3))
8215 (match-string 3)))
8216 (goto-char (match-end 0)))
8218 (cond
8219 ((looking-at "\\(.*@.*\\)")
8220 (setq message-id (match-string 1)))
8221 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8222 (setq group (match-string 1)
8223 articles (split-string (match-string 2) "-")))
8224 ((looking-at "\\([^/]+\\)/?")
8225 (setq group (match-string 1)))
8227 (error "Unknown news URL syntax"))))
8228 (list scheme server port group message-id articles)))
8230 (defvar nntp-port-number)
8232 (defun gnus-button-handle-news (url)
8233 "Fetch a news URL."
8234 (cl-destructuring-bind (_scheme server port group message-id _articles)
8235 (gnus-parse-news-url url)
8236 (cond
8237 (message-id
8238 (with-current-buffer gnus-summary-buffer
8239 (if server
8240 (let ((gnus-refer-article-method
8241 (nconc (list (list 'nntp server))
8242 gnus-refer-article-method))
8243 (nntp-port-number (or port "nntp")))
8244 (gnus-message 7 "Fetching %s with %s"
8245 message-id gnus-refer-article-method)
8246 (gnus-summary-refer-article message-id))
8247 (gnus-summary-refer-article message-id))))
8248 (group
8249 (gnus-button-fetch-group url)))))
8251 (defun gnus-button-patch (library line)
8252 "Visit an Emacs Lisp library LIBRARY on line LINE."
8253 (interactive)
8254 (let ((file (locate-library (file-name-nondirectory library))))
8255 (unless file
8256 (error "Couldn't find library %s" library))
8257 (find-file file)
8258 (goto-char (point-min))
8259 (forward-line (1- (string-to-number line)))))
8261 (defun gnus-button-handle-man (url)
8262 "Fetch a man page."
8263 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8264 (when (eq gnus-button-man-handler 'woman)
8265 (setq url (replace-regexp-in-string "([1-9][X1a-z]*).*\\'" "" url)))
8266 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8267 (funcall gnus-button-man-handler url))
8269 (defun gnus-button-handle-info-url (url)
8270 "Fetch an info URL."
8271 (setq url (subst-char-in-string ?+ ?\ url))
8272 (cond
8273 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8274 (gnus-info-find-node
8275 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8276 "Gnus")
8277 ")" (gnus-url-unhex-string (match-string 2 url)))))
8278 ((string-match "([^)\"]+)[^\"]+" url)
8279 (setq url
8280 (replace-regexp-in-string
8281 "\"" "" (replace-regexp-in-string "[\n\t ]+" " " url)))
8282 (gnus-info-find-node url))
8283 (t (error "Can't parse %s" url))))
8285 (defun gnus-button-handle-info-url-gnome (url)
8286 "Fetch GNOME style info URL."
8287 (setq url (subst-char-in-string ?_ ?\ url))
8288 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8289 (gnus-info-find-node
8290 (concat "("
8291 (gnus-url-unhex-string
8292 (match-string 1 url))
8294 (or (gnus-url-unhex-string
8295 (match-string 2 url))
8296 "Top")))
8297 (error "Can't parse %s" url)))
8299 (defun gnus-button-handle-info-url-kde (url)
8300 "Fetch KDE style info URL."
8301 (gnus-info-find-node (gnus-url-unhex-string url)))
8303 ;; (info) will autoload info.el
8304 (declare-function Info-menu "info" (menu-item &optional fork))
8305 (declare-function Info-index-next "info" (num))
8307 (defun gnus-button-handle-info-keystrokes (url)
8308 "Call `info' when pushing the corresponding URL button."
8309 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8310 (let (node indx comma)
8311 (if (string-match
8312 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8313 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8314 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8315 "\\(?:[ \t\n,]*\\)\\)?")
8316 url)
8317 (setq node (match-string 2 url)
8318 indx (match-string 3 url))
8319 (error "Can't parse %s" url))
8320 (info)
8321 (Info-directory)
8322 (Info-menu node)
8323 (when (> (length indx) 0)
8324 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8325 "\\([ \t\n,]*\\)")
8326 indx)
8327 (setq comma (match-string 2 indx))
8328 (setq indx (match-string 1 indx))
8329 (Info-index indx)
8330 (when comma
8331 (dotimes (i (with-temp-buffer
8332 (insert comma)
8333 ;; Note: the XEmacs version of `how-many' takes
8334 ;; no optional argument.
8335 (goto-char (point-min))
8336 (how-many ",")))
8337 (Info-index-next 1)))
8338 nil)))
8340 (autoload 'pgg-snarf-keys-region "pgg")
8341 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8342 (declare-function pgg-display-output-buffer "pgg" (start end status))
8344 (defun gnus-button-openpgp (url)
8345 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8346 (with-temp-buffer
8347 (mm-url-insert-file-contents-external url)
8348 (pgg-snarf-keys-region (point-min) (point-max))
8349 (pgg-display-output-buffer nil nil nil)))
8351 (defun gnus-button-message-id (message-id)
8352 "Fetch MESSAGE-ID."
8353 (with-current-buffer gnus-summary-buffer
8354 (gnus-summary-refer-article message-id)))
8356 (defun gnus-button-fetch-group (address &rest _ignore)
8357 "Fetch GROUP specified by ADDRESS."
8358 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8359 address)
8360 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8361 ;; for nntp:// and news://
8362 (setq address (match-string 3 address)))
8363 (if (not (string-match "[:/]" address))
8364 ;; This is just a simple group url.
8365 (gnus-group-read-ephemeral-group address gnus-select-method)
8366 (if (not
8367 (string-match
8368 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8369 address))
8370 (error "Can't parse %s" address)
8371 (gnus-group-read-ephemeral-group
8372 (match-string 4 address)
8373 `(nntp ,(match-string 1 address)
8374 (nntp-address ,(match-string 1 address))
8375 (nntp-port-number ,(if (match-end 3)
8376 (match-string 3 address)
8377 "nntp")))
8378 nil nil nil
8379 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8381 (defun gnus-url-parse-query-string (query &optional downcase)
8382 (let (retval pairs cur key val)
8383 (setq pairs (split-string query "&"))
8384 (while pairs
8385 (setq cur (car pairs)
8386 pairs (cdr pairs))
8387 (if (not (string-match "=" cur))
8388 nil ; Grace
8389 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8390 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8391 (if downcase
8392 (setq key (downcase key)))
8393 (setq cur (assoc key retval))
8394 (if cur
8395 (setcdr cur (cons val (cdr cur)))
8396 (setq retval (cons (list key val) retval)))))
8397 retval))
8399 (defun gnus-url-mailto (url)
8400 ;; Send mail to someone
8401 (setq url (replace-regexp-in-string "\n" " " url))
8402 (when (string-match "mailto:/*\\(.*\\)" url)
8403 (setq url (substring url (match-beginning 1) nil)))
8404 (let* ((args (gnus-url-parse-query-string
8405 (if (string-match "^\\?" url)
8406 (substring url 1)
8407 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8408 (concat "to=" (match-string 1 url) "&"
8409 (match-string 2 url))
8410 (concat "to=" url)))))
8411 (subject (cdr-safe (assoc "subject" args)))
8412 func)
8413 (gnus-msg-mail)
8414 (while args
8415 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8416 (if (fboundp func)
8417 (funcall func)
8418 (message-position-on-field (caar args)))
8419 (insert (replace-regexp-in-string
8420 "\r\n" "\n"
8421 (mapconcat 'identity (reverse (cdar args)) ", ") nil t))
8422 (setq args (cdr args)))
8423 (if subject
8424 (message-goto-body)
8425 (message-goto-subject))))
8427 (defun gnus-button-embedded-url (address)
8428 "Activate ADDRESS with `browse-url'."
8429 (browse-url (gnus-strip-whitespace address)))
8431 ;;; Next/prev buttons in the article buffer.
8433 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8434 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8436 (defvar gnus-prev-page-map
8437 (let ((map (make-sparse-keymap)))
8438 (define-key map [mouse-2] 'gnus-button-prev-page)
8439 (define-key map "\r" 'gnus-button-prev-page)
8440 map))
8442 (defvar gnus-next-page-map
8443 (let ((map (make-sparse-keymap)))
8444 (define-key map [mouse-2] 'gnus-button-next-page)
8445 (define-key map "\r" 'gnus-button-next-page)
8446 map))
8448 (defun gnus-insert-prev-page-button ()
8449 (let ((b (point)) e
8450 (inhibit-read-only t))
8451 (gnus-eval-format
8452 gnus-prev-page-line-format nil
8453 `(keymap ,gnus-prev-page-map
8454 gnus-prev t
8455 gnus-callback gnus-article-button-prev-page
8456 article-type annotation))
8457 (setq e (if (bolp)
8458 ;; Exclude a newline.
8459 (1- (point))
8460 (point)))
8461 (when gnus-article-button-face
8462 (overlay-put (make-overlay b e nil t)
8463 'face gnus-article-button-face))
8464 (widget-convert-button
8465 'link b e
8466 :action 'gnus-button-prev-page
8467 :button-keymap gnus-prev-page-map)))
8469 (defun gnus-button-next-page (&optional _args _more-args)
8470 "Go to the next page."
8471 (interactive)
8472 (let ((win (selected-window)))
8473 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8474 (gnus-article-next-page)
8475 (select-window win)))
8477 (defun gnus-button-prev-page (&optional _args _more-args)
8478 "Go to the prev page."
8479 (interactive)
8480 (let ((win (selected-window)))
8481 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8482 (gnus-article-prev-page)
8483 (select-window win)))
8485 (defun gnus-insert-next-page-button ()
8486 (let ((b (point)) e
8487 (inhibit-read-only t))
8488 (gnus-eval-format gnus-next-page-line-format nil
8489 `(keymap ,gnus-next-page-map
8490 gnus-next t
8491 gnus-callback gnus-article-button-next-page
8492 article-type annotation))
8493 (setq e (if (bolp)
8494 ;; Exclude a newline.
8495 (1- (point))
8496 (point)))
8497 (when gnus-article-button-face
8498 (overlay-put (make-overlay b e nil t)
8499 'face gnus-article-button-face))
8500 (widget-convert-button
8501 'link b e
8502 :action 'gnus-button-next-page
8503 :button-keymap gnus-next-page-map)))
8505 (defun gnus-article-button-next-page (_arg)
8506 "Go to the next page."
8507 (interactive "P")
8508 (let ((win (selected-window)))
8509 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8510 (gnus-article-next-page)
8511 (select-window win)))
8513 (defun gnus-article-button-prev-page (_arg)
8514 "Go to the prev page."
8515 (interactive "P")
8516 (let ((win (selected-window)))
8517 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8518 (gnus-article-prev-page)
8519 (select-window win)))
8521 (defvar gnus-decode-header-methods
8522 '(mail-decode-encoded-word-region)
8523 "List of methods used to decode headers.
8525 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8526 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8527 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8528 whose names match REGEXP.
8530 For example:
8531 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8532 mail-decode-encoded-word-region
8533 (\"chinese\" . rfc1843-decode-region))
8536 (defvar gnus-decode-header-methods-cache nil)
8538 (defun gnus-multi-decode-header (start end)
8539 "Apply the functions from `gnus-encoded-word-methods' that match."
8540 (unless (and gnus-decode-header-methods-cache
8541 (eq gnus-newsgroup-name
8542 (car gnus-decode-header-methods-cache)))
8543 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8544 (dolist (x gnus-decode-header-methods)
8545 (if (symbolp x)
8546 (nconc gnus-decode-header-methods-cache (list x))
8547 (if (and gnus-newsgroup-name
8548 (string-match (car x) gnus-newsgroup-name))
8549 (nconc gnus-decode-header-methods-cache
8550 (list (cdr x)))))))
8551 (let ((xlist gnus-decode-header-methods-cache))
8552 (pop xlist)
8553 (save-restriction
8554 (narrow-to-region start end)
8555 (while xlist
8556 (funcall (pop xlist) (point-min) (point-max))))))
8559 ;;; Treatment top-level handling.
8562 (defvar gnus-inhibit-article-treatments nil)
8564 ;; Dynamic variables.
8565 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8566 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8567 (defvar gnus-treat-type)
8568 (defvar gnus-treat-condition)
8569 (defvar gnus-treat-length)
8571 (defun gnus-treat-article (condition
8572 &optional part-num total type)
8573 (let ((gnus-treat-condition condition)
8574 (part-number part-num)
8575 (total-parts total)
8576 (gnus-treat-type type)
8577 (gnus-treat-length (- (point-max) (point-min)))
8578 (alist gnus-treatment-function-alist)
8579 (article-goto-body-goes-to-point-min-p t)
8580 (treated-type
8581 (or (not type)
8582 (catch 'found
8583 (let ((list gnus-article-treat-types))
8584 (while list
8585 (when (string-match (pop list) type)
8586 (throw 'found t)))))))
8587 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8588 val)
8589 (gnus-run-hooks 'gnus-part-display-hook)
8590 (dolist (elem alist)
8591 (setq val
8592 (save-excursion
8593 (when (gnus-buffer-live-p gnus-summary-buffer)
8594 (set-buffer gnus-summary-buffer))
8595 (symbol-value (car elem))))
8596 (when (and (or (consp val)
8597 treated-type)
8598 (or (not gnus-inhibit-article-treatments)
8599 (eq gnus-treat-condition 'head))
8600 (gnus-treat-predicate val)
8601 (or (not (get (car elem) 'highlight))
8602 highlightp))
8603 (save-restriction
8604 (funcall (cadr elem)))))))
8606 (defun gnus-treat-predicate (val)
8607 (cond
8608 ((null val)
8609 nil)
8610 (gnus-treat-condition
8611 (eq gnus-treat-condition val))
8612 ((and (listp val)
8613 (stringp (car val)))
8614 (apply 'gnus-or (mapcar `(lambda (s)
8615 (string-match s ,(or gnus-newsgroup-name "")))
8616 val)))
8617 ((listp val)
8618 (let ((pred (pop val)))
8619 (cond
8620 ((eq pred 'or)
8621 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8622 ((eq pred 'and)
8623 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8624 ((eq pred 'not)
8625 (not (gnus-treat-predicate (car val))))
8626 ((eq pred 'typep)
8627 (equal (car val) gnus-treat-type))
8628 ((functionp pred)
8629 (funcall pred))
8631 (error "%S is not a valid predicate" pred)))))
8632 ((eq val t)
8634 ((eq val 'head)
8635 nil)
8636 ((eq val 'first)
8637 (eq part-number 1))
8638 ((eq val 'last)
8639 (eq part-number total-parts))
8640 ((numberp val)
8641 (< gnus-treat-length val))
8643 (error "%S is not a valid value" val))))
8645 (defun gnus-article-encrypt-body (protocol &optional n)
8646 "Encrypt the article body."
8647 (interactive
8648 (list
8649 (or gnus-article-encrypt-protocol
8650 (gnus-completing-read "Encrypt protocol"
8651 (mapcar 'car gnus-article-encrypt-protocol-alist)
8653 current-prefix-arg))
8654 ;; User might hit `K E' instead of `K e', so prompt once.
8655 (when (and gnus-article-encrypt-protocol
8656 gnus-novice-user)
8657 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8658 (error "Encrypt aborted")))
8659 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8660 (unless func
8661 (error "Can't find the encrypt protocol %s" protocol))
8662 (if (member gnus-newsgroup-name '("nndraft:delayed"
8663 "nndraft:drafts"
8664 "nndraft:queue"))
8665 (error "Can't encrypt the article in group %s"
8666 gnus-newsgroup-name))
8667 (gnus-summary-iterate n
8668 (with-current-buffer gnus-summary-buffer
8669 (let ((mail-parse-charset gnus-newsgroup-charset)
8670 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8671 (summary-buffer gnus-summary-buffer)
8672 references point)
8673 (gnus-set-global-variables)
8674 (when (gnus-group-read-only-p)
8675 (error "The current newsgroup does not support article encrypt"))
8676 (gnus-summary-show-article t)
8677 (setq references
8678 (or (mail-header-references gnus-current-headers) ""))
8679 (set-buffer gnus-article-buffer)
8680 (let* ((inhibit-read-only t)
8681 (headers
8682 (mapcar (lambda (field)
8683 (and (save-restriction
8684 (message-narrow-to-head)
8685 (goto-char (point-min))
8686 (search-forward field nil t))
8687 (prog2
8688 (message-narrow-to-field)
8689 (buffer-string)
8690 (delete-region (point-min) (point-max))
8691 (widen))))
8692 '("Content-Type:" "Content-Transfer-Encoding:"
8693 "Content-Disposition:"))))
8694 (message-narrow-to-head)
8695 (message-remove-header "MIME-Version")
8696 (goto-char (point-max))
8697 (setq point (point))
8698 (insert (apply 'concat headers))
8699 (widen)
8700 (narrow-to-region point (point-max))
8701 (let ((message-options message-options))
8702 (message-options-set 'message-sender user-mail-address)
8703 (message-options-set 'message-recipients user-mail-address)
8704 (message-options-set 'message-sign-encrypt 'not)
8705 (funcall func))
8706 (goto-char (point-min))
8707 (insert "MIME-Version: 1.0\n")
8708 (widen)
8709 (gnus-summary-edit-article-done
8710 references nil summary-buffer t))
8711 (when gnus-keep-backlog
8712 (gnus-backlog-remove-article
8713 (car gnus-article-current) (cdr gnus-article-current)))
8714 (gnus-flush-original-article-buffer)
8715 (when gnus-use-cache
8716 (gnus-cache-update-article
8717 (car gnus-article-current) (cdr gnus-article-current))))))))
8719 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8720 "The following specs can be used:
8721 %t The security MIME type
8722 %i Additional info
8723 %d Details
8724 %D Details if button is pressed")
8726 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8727 "The following specs can be used:
8728 %t The security MIME type
8729 %i Additional info
8730 %d Details
8731 %D Details if button is pressed")
8733 (defvar gnus-mime-security-button-line-format-alist
8734 '((?t gnus-tmp-type ?s)
8735 (?i gnus-tmp-info ?s)
8736 (?d gnus-tmp-details ?s)
8737 (?D gnus-tmp-pressed-details ?s)))
8739 (defvar gnus-mime-security-button-commands
8740 '((gnus-article-press-button "\r" "Show Detail")
8741 (undefined "v")
8742 (undefined "t")
8743 (undefined "C")
8744 (gnus-mime-security-save-part "o" "Save...")
8745 (undefined "\C-o")
8746 (undefined "r")
8747 (undefined "d")
8748 (undefined "c")
8749 (undefined "i")
8750 (undefined "E")
8751 (undefined "e")
8752 (undefined "p")
8753 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8754 (undefined ".")))
8756 (defvar gnus-mime-security-button-map
8757 (let ((map (make-sparse-keymap)))
8758 (define-key map [mouse-2] 'gnus-article-push-button)
8759 (define-key map [down-mouse-3] 'gnus-mime-security-button-menu)
8760 (dolist (c gnus-mime-security-button-commands)
8761 (define-key map (cadr c) (car c)))
8762 map))
8764 (easy-menu-define
8765 gnus-mime-security-button-menu gnus-mime-security-button-map
8766 "Security button menu."
8767 `("Security Part"
8768 ,@(delq nil
8769 (mapcar (lambda (c)
8770 (unless (eq (car c) 'undefined)
8771 (vector (caddr c) (car c) :active t)))
8772 gnus-mime-security-button-commands))))
8774 (defun gnus-mime-security-button-menu (event prefix)
8775 "Construct a context-sensitive menu of security commands."
8776 (interactive "e\nP")
8777 (save-window-excursion
8778 (let ((pos (event-start event)))
8779 (select-window (posn-window pos))
8780 (goto-char (posn-point pos))
8781 (gnus-article-check-buffer)
8782 (popup-menu gnus-mime-security-button-menu nil prefix))))
8784 (defvar gnus-mime-security-details-buffer nil)
8786 (defvar gnus-mime-security-button-pressed nil)
8788 (defvar gnus-mime-security-show-details-inline t
8789 "If non-nil, show details in the article buffer.")
8791 (defun gnus-mime-security-verify-or-decrypt (handle)
8792 (mm-remove-parts (cdr handle))
8793 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8794 point (inhibit-read-only t))
8795 (if region
8796 (goto-char (car region)))
8797 (setq point (point))
8798 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8799 (let* ((mm-verify-option 'known)
8800 (mm-decrypt-option 'known)
8801 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8802 (unless (eq nparts (cdr handle))
8803 (mm-destroy-parts (cdr handle))
8804 (setcdr handle nparts))))
8805 (gnus-mime-display-security handle)
8806 (when region
8807 (delete-region (point) (cdr region))
8808 (set-marker (car region) nil)
8809 (set-marker (cdr region) nil))
8810 (goto-char point)))
8812 (defun gnus-mime-security-show-details (handle)
8813 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8814 (if (not details)
8815 (gnus-message 5 "No details.")
8816 (if gnus-mime-security-show-details-inline
8817 (let ((gnus-mime-security-button-pressed
8818 (not (get-text-property (point) 'gnus-mime-details)))
8819 (gnus-mime-security-button-line-format
8820 (get-text-property (point) 'gnus-line-format))
8821 (inhibit-read-only t))
8822 (forward-char -1)
8823 (while (eq (get-text-property (point) 'gnus-line-format)
8824 gnus-mime-security-button-line-format)
8825 (forward-char -1))
8826 (forward-char)
8827 (save-restriction
8828 (narrow-to-region (point) (point))
8829 (gnus-insert-mime-security-button handle))
8830 (delete-region (point)
8831 (or (text-property-not-all
8832 (point) (point-max)
8833 'gnus-line-format
8834 gnus-mime-security-button-line-format)
8835 (point-max))))
8836 ;; Not inlined.
8837 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8838 (with-current-buffer gnus-mime-security-details-buffer
8839 (erase-buffer)
8841 (setq gnus-mime-security-details-buffer
8842 (gnus-get-buffer-create "*MIME Security Details*")))
8843 (with-current-buffer gnus-mime-security-details-buffer
8844 (insert details)
8845 (goto-char (point-min)))
8846 (pop-to-buffer gnus-mime-security-details-buffer)))))
8848 (defun gnus-mime-security-press-button (handle)
8849 (save-excursion
8850 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8851 (gnus-mime-security-show-details handle)
8852 (gnus-mime-security-verify-or-decrypt handle))))
8854 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8855 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8856 (gnus-tmp-type
8857 (concat
8858 (or (nth 2 (assoc protocol mm-verify-function-alist))
8859 (nth 2 (assoc protocol mm-decrypt-function-alist))
8860 "Unknown")
8861 (if (equal (car handle) "multipart/signed")
8862 " Signed" " Encrypted")
8863 " Part"))
8864 (gnus-tmp-info
8865 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8866 "Undecided"))
8867 (gnus-tmp-details
8868 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8869 gnus-tmp-pressed-details
8870 b e)
8871 (setq gnus-tmp-details
8872 (if gnus-tmp-details
8873 (concat "\n" gnus-tmp-details)
8874 ""))
8875 (setq gnus-tmp-pressed-details
8876 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8877 (unless (bolp)
8878 (insert "\n"))
8879 (setq b (point))
8880 (gnus-eval-format
8881 gnus-mime-security-button-line-format
8882 gnus-mime-security-button-line-format-alist
8883 `(keymap ,gnus-mime-security-button-map
8884 gnus-callback gnus-mime-security-press-button
8885 gnus-line-format ,gnus-mime-security-button-line-format
8886 gnus-mime-details ,gnus-mime-security-button-pressed
8887 article-type annotation
8888 gnus-data ,handle))
8889 (setq e (if (bolp)
8890 ;; Exclude a newline.
8891 (1- (point))
8892 (point)))
8893 (when gnus-article-button-face
8894 (overlay-put (make-overlay b e nil t)
8895 'face gnus-article-button-face))
8896 (widget-convert-button
8897 'link b e
8898 :mime-handle handle
8899 :action 'gnus-widget-press-button
8900 :button-keymap gnus-mime-security-button-map
8901 :help-echo
8902 (lambda (_widget)
8903 (format
8904 "%S: show detail; %S: more options"
8905 'mouse-2
8906 'down-mouse-3)))))
8908 (defun gnus-mime-display-security (handle)
8909 (save-restriction
8910 (narrow-to-region (point) (point))
8911 (unless (gnus-unbuttonized-mime-type-p (car handle))
8912 (gnus-insert-mime-security-button handle))
8913 (gnus-mime-display-part (cadr handle))
8914 (unless (bolp)
8915 (insert "\n"))
8916 (unless (gnus-unbuttonized-mime-type-p (car handle))
8917 (let ((gnus-mime-security-button-line-format
8918 gnus-mime-security-button-end-line-format))
8919 (gnus-insert-mime-security-button handle)))
8920 (mm-set-handle-multipart-parameter
8921 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8922 (goto-char (point-max))))
8924 (defun gnus-mime-security-run-function (function)
8925 "Run FUNCTION with the security part under point."
8926 (gnus-article-check-buffer)
8927 (let ((data (get-text-property (point) 'gnus-data))
8928 buffer handle)
8929 (when (and (stringp (car-safe data))
8930 (setq buffer (mm-handle-multipart-original-buffer data))
8931 (setq handle (cadr data)))
8932 (if (bufferp (mm-handle-buffer handle))
8933 (progn
8934 (setq handle (cons buffer (copy-sequence (cdr handle))))
8935 (mm-handle-set-undisplayer handle nil))
8936 (setq handle (mm-make-handle
8937 buffer
8938 (mm-handle-multipart-ctl-parameter handle 'protocol)
8939 nil nil nil nil nil nil)))
8940 (funcall function handle))))
8942 (defun gnus-mime-security-save-part ()
8943 "Save the security part under point."
8944 (interactive)
8945 (gnus-mime-security-run-function 'mm-save-part))
8947 (defun gnus-mime-security-pipe-part ()
8948 "Pipe the security part under point to a process."
8949 (interactive)
8950 (gnus-mime-security-run-function 'mm-pipe-part))
8952 (provide 'gnus-art)
8954 (run-hooks 'gnus-art-load-hook)
8956 ;;; gnus-art.el ends here