1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (defvar w3m-minor-mode-map)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
53 (autoload 'url-expand-file-name "url-expand")
55 (defgroup gnus-article nil
57 :link '(custom-manual "(gnus)Article Buffer")
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
76 (defgroup gnus-article-signature nil
78 :link '(custom-manual "(gnus)Article Signature")
81 (defgroup gnus-article-headers nil
83 :link '(custom-manual "(gnus)Hiding Headers")
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
96 (defgroup gnus-article-saving nil
98 :link '(custom-manual "(gnus)Saving Articles")
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
116 (defcustom gnus-ignored-headers
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
166 :group 'gnus-article-hiding)
168 (defcustom gnus-visible-headers
169 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
178 (widget-editable-list-match widget value)))
180 (const :tag "Use gnus-ignored-headers" nil)
182 :group 'gnus-article-hiding)
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
198 `empty' Headers with no content.
199 `newsgroups' Newsgroup identical to Gnus group.
200 `to-address' To identical to To-address.
201 `to-list' To identical to To-list.
202 `cc-list' CC identical to To-list.
203 `followup-to' Followup-to identical to Newsgroups.
204 `reply-to' Reply-to identical to From.
205 `date' Date less than four days old.
206 `long-to' To and/or Cc longer than 1024 characters.
207 `many-to' Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
228 :group 'gnus-article-hiding)
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
249 This can also be a list of the above values."
250 :type '(choice (const nil)
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
257 (defcustom gnus-hidden-properties
258 ;; We use to have `intangible' here as well, but Emacs's command loop moves
259 ;; point out of invisible text anyway, so `intangible' is clearly not
260 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
262 "Property list to use for hiding text."
264 :group 'gnus-article-hiding)
266 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
267 ;; frames in a session.
268 (defcustom gnus-article-x-face-command
269 (if (gnus-image-type-available-p 'pbm)
270 'gnus-display-x-face-in-from
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | display -")
274 "*String or function to be executed to display an X-Face header.
275 If it is a string, the command will be executed in a sub-shell
276 asynchronously. The compressed face will be piped to this command."
277 :type `(choice string
278 (function-item gnus-display-x-face-in-from)
282 :group 'gnus-article-washing)
284 (defcustom gnus-article-x-face-too-ugly nil
285 "Regexp matching posters whose face shouldn't be shown automatically."
286 :type '(choice regexp (const nil))
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-banner-alist nil
290 "Banner alist for stripping.
292 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
294 :type '(repeat (cons symbol regexp))
295 :group 'gnus-article-washing)
297 (gnus-define-group-parameter
300 "Alist of regexps (to match group names) and banner."
301 :variable-group gnus-article-washing
303 '(choice :tag "Banner"
305 (const :tag "Remove signature" signature)
306 (symbol :tag "Item in `gnus-article-banner-alist'" none)
308 (const :tag "None" nil))
310 "If non-nil, specify how to remove `banners' from articles.
312 Symbol `signature' means to remove signatures delimited by
313 `gnus-signature-separator'. Any other symbol is used to look up a
314 regular expression to match the banner in `gnus-article-banner-alist'.
315 A string is used as a regular expression to match the banner
318 (defcustom gnus-article-address-banner-alist nil
319 "Alist of mail addresses and banners.
320 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
321 to match a mail address in the From: header, BANNER is one of a symbol
322 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
323 If ADDRESS matches author's mail address, it will remove things like
324 advertisements. For example:
326 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
330 (regexp :tag "Address")
331 (choice :tag "Banner" :value nil
332 (const :tag "Remove signature" signature)
333 (symbol :tag "Item in `gnus-article-banner-alist'" none)
335 (const :tag "None" nil))))
337 :group 'gnus-article-washing)
339 (defmacro gnus-emphasis-custom-with-format (&rest body)
341 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
342 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
345 (defun gnus-emphasis-custom-value-to-external (value)
346 (gnus-emphasis-custom-with-format
347 (if (consp (car value))
348 (list (format format (car (car value)) (cdr (car value)))
350 (if (nth 1 value) 2 3)
354 (defun gnus-emphasis-custom-value-to-internal (value)
355 (gnus-emphasis-custom-with-format
356 (let ((regexp (concat "\\`"
357 (format (regexp-quote format)
358 "\\([^()]+\\)" "\\([^()]+\\)")
361 (if (string-match regexp (setq pattern (car value)))
362 (list (cons (match-string 1 pattern) (match-string 2 pattern))
367 (defcustom gnus-emphasis-alist
369 '(("\\*" "\\*" bold nil 2)
372 ("_/" "/_" underline-italic)
373 ("_\\*" "\\*_" underline-bold)
374 ("\\*/" "/\\*" bold-italic)
375 ("_\\*/" "/\\*_" underline-bold-italic))))
377 (gnus-emphasis-custom-with-format
378 (mapcar (lambda (spec)
379 (list (format format (car spec) (cadr spec))
382 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
384 '(;; I've never seen anyone use this strikethru convention whereas I've
385 ;; several times seen it triggered by normal text. --Stef
386 ;; Miles suggests that this form is sometimes used but for italics,
387 ;; so maybe we should map it to `italic'.
388 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
389 ;; 2 3 gnus-emphasis-strikethru)
390 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
391 2 3 gnus-emphasis-underline))))
392 "*Alist that says how to fontify certain phrases.
393 Each item looks like this:
395 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
397 The first element is a regular expression to be matched. The second
398 is a number that says what regular expression grouping used to find
399 the entire emphasized word. The third is a number that says what
400 regexp grouping should be displayed and highlighted. The fourth
401 is the face used for highlighting."
405 :format "%[Customizing Style%]\n%v"
407 (group :tag "Default"
408 :value ("" 0 0 default)
411 (let ((value (widget-get
412 (cadr (widget-get (widget-get widget :parent)
415 (if (not (eq (nth 2 value) 'default))
419 (gnus-emphasis-custom-value-to-external value))))
420 (widget-group-value-create widget))
422 (integer :format "Match group: %v")
423 (integer :format "Emphasize group: %v")
426 :value (("_" . "_") nil default)
428 (regexp :format "Start regexp: %v")
429 (regexp :format "End regexp: %v"))
430 (boolean :format "Show start and end patterns: %[%v%]\n"
431 :on " On " :off " Off ")
433 :get (lambda (symbol)
434 (mapcar 'gnus-emphasis-custom-value-to-internal
435 (default-value symbol)))
436 :set (lambda (symbol value)
437 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
439 :group 'gnus-article-emphasis)
441 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
442 "A regexp to describe whitespace which should not be emphasized.
443 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
444 The former avoids underlining of leading and trailing whitespace,
445 and the latter avoids underlining any whitespace at all."
447 :group 'gnus-article-emphasis
450 (defface gnus-emphasis-bold '((t (:bold t)))
451 "Face used for displaying strong emphasized text (*word*)."
452 :group 'gnus-article-emphasis)
454 (defface gnus-emphasis-italic '((t (:italic t)))
455 "Face used for displaying italic emphasized text (/word/)."
456 :group 'gnus-article-emphasis)
458 (defface gnus-emphasis-underline '((t (:underline t)))
459 "Face used for displaying underlined emphasized text (_word_)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
463 "Face used for displaying underlined bold emphasized text (_*word*_)."
464 :group 'gnus-article-emphasis)
466 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
467 "Face used for displaying underlined italic emphasized text (_/word/_)."
468 :group 'gnus-article-emphasis)
470 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
471 "Face used for displaying bold italic emphasized text (/*word*/)."
472 :group 'gnus-article-emphasis)
474 (defface gnus-emphasis-underline-bold-italic
475 '((t (:bold t :italic t :underline t)))
476 "Face used for displaying underlined bold italic emphasized text.
477 Example: (_/*word*/_)."
478 :group 'gnus-article-emphasis)
480 (defface gnus-emphasis-strikethru '((t (:strike-through t)))
481 "Face used for displaying strike-through text (-word-)."
482 :group 'gnus-article-emphasis)
484 (defface gnus-emphasis-highlight-words
485 '((t (:background "black" :foreground "yellow")))
486 "Face used for displaying highlighted words."
487 :group 'gnus-article-emphasis)
489 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
490 "Format for display of Date headers in article bodies.
491 See `format-time-string' for the possible values.
493 The variable can also be function, which should return a complete Date
494 header. The function is called with one argument, the time, which can
495 be fed to `format-time-string'."
496 :type '(choice string function)
497 :link '(custom-manual "(gnus)Article Date")
498 :group 'gnus-article-washing)
500 (defcustom gnus-save-all-headers t
501 "*If non-nil, don't remove any headers before saving.
502 This will be overridden by the `:headers' property that the symbol of
503 the saver function, which is specified by `gnus-default-article-saver',
505 :group 'gnus-article-saving
508 (defcustom gnus-prompt-before-saving 'always
509 "*This variable says how much prompting is to be done when saving articles.
510 If it is nil, no prompting will be done, and the articles will be
511 saved to the default files. If this variable is `always', each and
512 every article that is saved will be preceded by a prompt, even when
513 saving large batches of articles. If this variable is neither nil not
514 `always', there the user will be prompted once for a file name for
515 each invocation of the saving commands."
516 :group 'gnus-article-saving
517 :type '(choice (item always)
518 (item :tag "never" nil)
519 (sexp :tag "once" :format "%t\n" :value t)))
521 (defcustom gnus-saved-headers gnus-visible-headers
522 "Headers to keep if `gnus-save-all-headers' is nil.
523 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
524 If that variable is nil, however, all headers that match this regexp
525 will be kept while the rest will be deleted before saving. This and
526 `gnus-save-all-headers' will be overridden by the `:headers' property
527 that the symbol of the saver function, which is specified by
528 `gnus-default-article-saver', might have."
529 :group 'gnus-article-saving
532 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
533 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
534 "A function to save articles in your favorite format.
535 The function will be called by way of the `gnus-summary-save-article'
536 command, and friends such as `gnus-summary-save-article-rmail'.
538 Gnus provides the following functions:
540 * gnus-summary-save-in-rmail (Rmail format)
541 * gnus-summary-save-in-mail (Unix mail format)
542 * gnus-summary-save-in-folder (MH folder)
543 * gnus-summary-save-in-file (article format)
544 * gnus-summary-save-body-in-file (article body)
545 * gnus-summary-save-in-vm (use VM's folder format)
546 * gnus-summary-write-to-file (article format -- overwrite)
547 * gnus-summary-write-body-to-file (article body -- overwrite)
548 * gnus-summary-save-in-pipe (article format)
550 The symbol of each function may have the following properties:
553 The value non-nil means save decoded articles. This is meaningful
554 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
555 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
556 `gnus-summary-save-in-pipe'.
559 The value specifies an alternative function which appends, not
560 overwrites, articles to a file. This implies that when saving many
561 articles at a time, `gnus-prompt-before-saving' is bound to t and all
562 articles are saved in a single file. This is meaningful only with
563 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
566 The value specifies the symbol of a variable of which the value
567 specifies headers to be saved. If it is omitted,
568 `gnus-save-all-headers' and `gnus-saved-headers' control what
569 headers should be saved."
570 :group 'gnus-article-saving
571 :type '(radio (function-item gnus-summary-save-in-rmail)
572 (function-item gnus-summary-save-in-mail)
573 (function-item gnus-summary-save-in-folder)
574 (function-item gnus-summary-save-in-file)
575 (function-item gnus-summary-save-body-in-file)
576 (function-item gnus-summary-save-in-vm)
577 (function-item gnus-summary-write-to-file)
578 (function-item gnus-summary-write-body-to-file)
579 (function-item gnus-summary-save-in-pipe)
582 (defcustom gnus-article-save-coding-system
583 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
584 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
585 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
586 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
587 "Coding system used to save decoded articles to a file.
589 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
590 which can safely encode any characters in text. This is used by the
593 * gnus-summary-save-article-file
594 * gnus-summary-save-article-body-file
595 * gnus-summary-write-article-file
596 * gnus-summary-write-article-body-file
598 and the functions to which you may set `gnus-default-article-saver':
600 * gnus-summary-save-in-file
601 * gnus-summary-save-body-in-file
602 * gnus-summary-write-to-file
603 * gnus-summary-write-body-to-file
605 Those commands and functions save just text displayed in the article
606 buffer to a file if the value of this variable is non-nil. Note that
607 buttonized MIME parts will be lost in a saved file in that case.
608 Otherwise, raw articles will be saved."
609 :group 'gnus-article-saving
611 :format "%{%t%}:\n %[Value Menu%] %v"
612 (const :tag "Save raw articles" nil)
615 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
616 '((const :tag "UTF-8" utf-8)
617 (const :tag "iso-2022-7bit" iso-2022-7bit)
618 (const :tag "Emacs internal" emacs-mule)
619 (const :tag "escape-quoted" escape-quoted))))
620 (symbol :tag "Coding system")))
622 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
623 "A function generating a file name to save articles in Rmail format.
624 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
625 :group 'gnus-article-saving
628 (defcustom gnus-mail-save-name 'gnus-plain-save-name
629 "A function generating a file name to save articles in Unix mail format.
630 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
631 :group 'gnus-article-saving
634 (defcustom gnus-folder-save-name 'gnus-folder-save-name
635 "A function generating a file name to save articles in MH folder.
636 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
637 :group 'gnus-article-saving
640 (defcustom gnus-file-save-name 'gnus-numeric-save-name
641 "A function generating a file name to save articles in article format.
642 The function is called with NEWSGROUP, HEADERS, and optional
644 :group 'gnus-article-saving
647 (defcustom gnus-split-methods
648 '((gnus-article-archive-name)
649 (gnus-article-nndoc-name))
650 "*Variable used to suggest where articles are to be saved.
651 For instance, if you would like to save articles related to Gnus in
652 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
653 you could set this variable to something like:
655 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
656 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
658 This variable is an alist where the key is the match and the
659 value is a list of possible files to save in if the match is
662 If the match is a string, it is used as a regexp match on the
663 article. If the match is a symbol, that symbol will be funcalled
664 from the buffer of the article to be saved with the newsgroup as the
665 parameter. If it is a list, it will be evalled in the same buffer.
667 If this form or function returns a string, this string will be used as a
668 possible file name; and if it returns a non-nil list, that list will be
669 used as possible file names."
670 :group 'gnus-article-saving
671 :type '(repeat (choice (list :value (fun) function)
672 (cons :value ("" "") regexp (repeat string))
675 (defcustom gnus-page-delimiter "^\^L"
676 "*Regexp describing what to use as article page delimiters.
677 The default value is \"^\^L\", which is a form linefeed at the
678 beginning of a line."
680 :group 'gnus-article-various)
682 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
683 "*The format specification for the article mode line.
684 See `gnus-summary-mode-line-format' for a closer description.
686 The following additional specs are available:
688 %w The article washing status.
689 %m The number of MIME parts in the article."
692 :group 'gnus-article-various)
694 (defcustom gnus-article-mode-hook nil
695 "*A hook for Gnus article mode."
697 :group 'gnus-article-various)
699 (defcustom gnus-article-menu-hook nil
700 "*Hook run after the creation of the article mode menu."
702 :group 'gnus-article-various)
704 (defcustom gnus-article-prepare-hook nil
705 "*A hook called after an article has been prepared in the article buffer."
707 :group 'gnus-article-various)
709 (defcustom gnus-copy-article-ignored-headers nil
710 "List of headers to be removed when copying an article.
711 Each element is a regular expression."
712 :version "23.1" ;; No Gnus
713 :type '(repeat regexp)
714 :group 'gnus-article-various)
716 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
717 "Gnus 5.10 (Emacs 22.1)")
720 '((t (:weight bold)))
721 "Face used for highlighting a button in the article buffer."
722 :group 'gnus-article-buttons)
724 (defcustom gnus-article-button-face 'gnus-button
725 "Face used for highlighting buttons in the article buffer.
727 An article button is a piece of text that you can activate by pressing
728 `RET' or `mouse-2' above it."
730 :group 'gnus-article-buttons)
732 (defcustom gnus-article-mouse-face 'highlight
733 "Face used for mouse highlighting in the article buffer.
735 Article buttons will be displayed in this face when the cursor is
738 :group 'gnus-article-buttons)
740 (defcustom gnus-signature-face 'gnus-signature
741 "Face used for highlighting a signature in the article buffer.
742 Obsolete; use the face `gnus-signature' for customizations instead."
744 :group 'gnus-article-highlight
745 :group 'gnus-article-signature)
747 (defface gnus-signature
750 "Face used for highlighting a signature in the article buffer."
751 :group 'gnus-article-highlight
752 :group 'gnus-article-signature)
753 ;; backward-compatibility alias
754 (put 'gnus-signature-face 'face-alias 'gnus-signature)
755 (put 'gnus-signature-face 'obsolete-face "22.1")
757 (defface gnus-header-from
760 (:foreground "PaleGreen1"))
763 (:foreground "red3"))
766 "Face used for displaying from headers."
767 :group 'gnus-article-headers
768 :group 'gnus-article-highlight)
769 ;; backward-compatibility alias
770 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
771 (put 'gnus-header-from-face 'obsolete-face "22.1")
773 (defface gnus-header-subject
776 (:foreground "SeaGreen1"))
779 (:foreground "red4"))
781 (:bold t :italic t)))
782 "Face used for displaying subject headers."
783 :group 'gnus-article-headers
784 :group 'gnus-article-highlight)
785 ;; backward-compatibility alias
786 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
787 (put 'gnus-header-subject-face 'obsolete-face "22.1")
789 (defface gnus-header-newsgroups
792 (:foreground "yellow" :italic t))
795 (:foreground "MidnightBlue" :italic t))
798 "Face used for displaying newsgroups headers.
799 In the default setup this face is only used for crossposted
801 :group 'gnus-article-headers
802 :group 'gnus-article-highlight)
803 ;; backward-compatibility alias
804 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
805 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
807 (defface gnus-header-name
810 (:foreground "SpringGreen2"))
813 (:foreground "maroon"))
816 "Face used for displaying header names."
817 :group 'gnus-article-headers
818 :group 'gnus-article-highlight)
819 ;; backward-compatibility alias
820 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
821 (put 'gnus-header-name-face 'obsolete-face "22.1")
823 (defface gnus-header-content
826 (:foreground "SpringGreen1" :italic t))
829 (:foreground "indianred4" :italic t))
831 (:italic t))) "Face used for displaying header content."
832 :group 'gnus-article-headers
833 :group 'gnus-article-highlight)
834 ;; backward-compatibility alias
835 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
836 (put 'gnus-header-content-face 'obsolete-face "22.1")
838 (defcustom gnus-header-face-alist
839 '(("From" nil gnus-header-from)
840 ("Subject" nil gnus-header-subject)
841 ("Newsgroups:.*," nil gnus-header-newsgroups)
842 ("" gnus-header-name gnus-header-content))
843 "*Controls highlighting of article headers.
845 An alist of the form (HEADER NAME CONTENT).
847 HEADER is a regular expression which should match the name of a
848 header and NAME and CONTENT are either face names or nil.
850 The name of each header field will be displayed using the face
851 specified by the first element in the list where HEADER matches
852 the header name and NAME is non-nil. Similarly, the content will
853 be displayed by the first non-nil matching CONTENT face."
854 :group 'gnus-article-headers
855 :group 'gnus-article-highlight
856 :type '(repeat (list (regexp :tag "Header")
858 (item :tag "skip" nil)
859 (face :value default))
860 (choice :tag "Content"
861 (item :tag "skip" nil)
862 (face :value default)))))
864 (defcustom gnus-face-properties-alist '((pbm . (:face gnus-x-face))
866 "Alist of image types and properties applied to Face and X-Face images.
869 ;; Specify the altitude of Face images in the From header.
870 \(setq gnus-face-properties-alist
871 \\='((pbm . (:face gnus-x-face :ascent 80))
872 (png . (:ascent 80))))
874 ;; Show Face images as pressed buttons.
875 \(setq gnus-face-properties-alist
876 \\='((pbm . (:face gnus-x-face :relief -2))
877 (png . (:relief -2))))
879 See the manual for the valid properties for various image types.
880 Currently, `pbm' is used for X-Face images and `png' is used for Face
882 :version "23.1" ;; No Gnus
883 :group 'gnus-article-headers
884 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
886 (defcustom gnus-article-decode-hook
887 '(article-decode-charset article-decode-encoded-words
888 article-decode-group-name article-decode-idna-rhs)
889 "*Hook run to decode charsets in articles."
890 :group 'gnus-article-headers
893 (defcustom gnus-display-mime-function 'gnus-display-mime
894 "Function to display MIME articles."
895 :group 'gnus-article-mime
898 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
899 "Function used to decode headers.")
901 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
902 "Function used to decode addresses.")
904 (defvar gnus-article-dumbquotes-map
924 "Table for MS-to-Latin1 translation.")
926 (defcustom gnus-ignored-mime-types nil
927 "List of MIME types that should be ignored by Gnus."
929 :group 'gnus-article-mime
930 :type '(repeat regexp))
932 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
933 "List of MIME types that should not be given buttons when rendered inline.
934 See also `gnus-buttonized-mime-types' which may override this variable.
935 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
937 :group 'gnus-article-mime
938 :type '(repeat regexp))
940 (defcustom gnus-buttonized-mime-types nil
941 "List of MIME types that should be given buttons when rendered inline.
942 If set, this variable overrides `gnus-unbuttonized-mime-types'.
943 To see e.g. security buttons you could set this to
944 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
945 this list to display radio buttons that allow you to choose one of two
946 media types those mails include. See also `mm-discouraged-alternatives'.
947 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
949 :group 'gnus-article-mime
950 :type '(repeat regexp))
952 (defcustom gnus-inhibit-mime-unbuttonizing nil
953 "If non-nil, all MIME parts get buttons.
954 When nil (the default value), then some MIME parts do not get buttons,
955 as described by the variables `gnus-buttonized-mime-types' and
956 `gnus-unbuttonized-mime-types'."
958 :group 'gnus-article-mime
961 (defcustom gnus-body-boundary-delimiter "_"
962 "String used to delimit header and body.
963 This variable is used by `gnus-article-treat-body-boundary' which can
964 be controlled by `gnus-treat-body-boundary'."
966 :group 'gnus-article-various
967 :type '(choice (item :tag "None" :value nil)
970 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
972 "Defines the location of the faces database.
973 For information on obtaining this database of pretty pictures, please
974 see http://www.cs.indiana.edu/picons/ftp/index.html"
976 :type '(repeat directory)
977 :link '(url-link :tag "download"
978 "http://www.cs.indiana.edu/picons/ftp/index.html")
979 :link '(custom-manual "(gnus)Picons")
982 (defun gnus-picons-installed-p ()
983 "Say whether picons are installed on your machine."
984 (let ((installed nil))
985 (dolist (database gnus-picon-databases)
986 (when (file-exists-p database)
990 (defcustom gnus-article-mime-part-function nil
991 "Function called with a MIME handle as the argument.
992 This is meant for people who want to do something automatic based
993 on parts -- for instance, adding Vcard info to a database."
994 :group 'gnus-article-mime
995 :type '(choice (const nil)
998 (defcustom gnus-mime-multipart-functions nil
999 "An alist of MIME types to functions to display them."
1001 :group 'gnus-article-mime
1002 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1004 (defcustom gnus-article-date-headers '(combined-lapsed)
1005 "A list of Date header formats to display.
1006 Valid formats are `ut' (universal time), `local' (local time
1007 zone), `english' (readable English), `lapsed' (elapsed time),
1008 `combined-lapsed' (both the original date and the elapsed time),
1009 `original' (the original date header), `iso8601' (ISO8601
1010 format), and `user-defined' (a user-defined format defined by the
1011 `gnus-article-time-format' variable).
1013 You have as many date headers as you want in the article buffer.
1014 Some of these headers are updated automatically. See
1015 `gnus-article-update-date-headers' for details."
1017 :group 'gnus-article-headers
1019 (const :tag "Universal time (UT)" ut)
1020 (const :tag "Local time zone" local)
1021 (const :tag "Readable English" english)
1022 (const :tag "Elapsed time" lapsed)
1023 (const :tag "Original and elapsed time" combined-lapsed)
1024 (const :tag "Original date header" original)
1025 (const :tag "ISO8601 format" iso8601)
1026 (const :tag "User-defined" user-defined)))
1028 (defcustom gnus-article-update-date-headers nil
1029 "A number that says how often to update the date header (in seconds).
1030 If nil, don't update it at all."
1032 :group 'gnus-article-headers
1034 (item :tag "Don't update" :value nil)
1037 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1038 "Function called with a MIME handle as the argument.
1039 This is meant for people who want to view first matched part.
1040 For `undisplayed-alternative' (default), the first undisplayed
1041 part or alternative part is used. For `undisplayed', the first
1042 undisplayed part is used. For a function, the first part which
1043 the function return t is used. For nil, the first part is
1046 :group 'gnus-article-mime
1048 (item :tag "first" :value nil)
1049 (item :tag "undisplayed" :value undisplayed)
1050 (item :tag "undisplayed or alternative"
1051 :value undisplayed-alternative)
1054 (defcustom gnus-mime-action-alist
1055 '(("save to file" . gnus-mime-save-part)
1056 ("save and strip" . gnus-mime-save-part-and-strip)
1057 ("replace with file" . gnus-mime-replace-part)
1058 ("delete part" . gnus-mime-delete-part)
1059 ("display as text" . gnus-mime-inline-part)
1060 ("view the part" . gnus-mime-view-part)
1061 ("pipe to command" . gnus-mime-pipe-part)
1062 ("toggle display" . gnus-article-press-button)
1063 ("toggle display" . gnus-article-view-part-as-charset)
1064 ("view as type" . gnus-mime-view-part-as-type)
1065 ("view internally" . gnus-mime-view-part-internally)
1066 ("view externally" . gnus-mime-view-part-externally))
1067 "An alist of actions that run on the MIME attachment."
1068 :group 'gnus-article-mime
1069 :type '(repeat (cons (string :tag "name")
1072 (defcustom gnus-auto-select-part 1
1073 "Advance to next MIME part when deleting or stripping parts.
1075 When 0, point will be placed on the same part as before. When
1076 positive (negative), move point forward (backwards) this many
1077 parts. When nil, redisplay article."
1078 :version "23.1" ;; No Gnus
1079 :group 'gnus-article-mime
1080 :type '(choice (const nil :tag "Redisplay article.")
1081 (const 1 :tag "Next part.")
1082 (const 0 :tag "Current part.")
1086 ;;; The treatment variables
1089 (defvar gnus-part-display-hook nil
1090 "Hook called on parts that are to receive treatment.")
1092 (defvar gnus-article-treat-custom
1093 '(choice (const :tag "Off" nil)
1095 (const :tag "Header" head)
1096 (const :tag "First" first)
1097 (const :tag "Last" last)
1098 (integer :tag "Less")
1099 (repeat :tag "Groups" regexp)
1100 (sexp :tag "Predicate")))
1102 (defvar gnus-article-treat-head-custom
1103 '(choice (const :tag "Off" nil)
1104 (const :tag "Header" head)))
1106 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1107 "text/x-patch" "text/html")
1108 "Part types eligible for treatment.")
1110 (defvar gnus-inhibit-treatment nil
1111 "Whether to inhibit treatment.")
1113 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1114 "Highlight the signature.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate. See Info node `(gnus)Customizing Articles'."
1117 :group 'gnus-article-treat
1118 :link '(custom-manual "(gnus)Customizing Articles")
1119 :type gnus-article-treat-custom)
1120 (put 'gnus-treat-highlight-signature 'highlight t)
1122 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate. See Info node `(gnus)Customizing Articles'."
1126 :group 'gnus-article-treat
1127 :link '(custom-manual "(gnus)Customizing Articles")
1128 :type gnus-article-treat-custom)
1129 (put 'gnus-treat-buttonize 'highlight t)
1131 (defcustom gnus-treat-buttonize-head 'head
1132 "Add buttons to the head.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1135 :group 'gnus-article-treat
1136 :link '(custom-manual "(gnus)Customizing Articles")
1137 :type gnus-article-treat-head-custom)
1138 (put 'gnus-treat-buttonize-head 'highlight t)
1140 (defcustom gnus-treat-date 'head
1141 "Display dates according to the `gnus-article-date-headers' variable.
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-head-custom)
1149 (defcustom gnus-treat-emphasize 50000
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate. See Info node `(gnus)Customizing Articles'."
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-custom)
1156 (put 'gnus-treat-emphasize 'highlight t)
1158 (defcustom gnus-treat-strip-cr nil
1159 "Remove carriage returns.
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1163 :group 'gnus-article-treat
1164 :link '(custom-manual "(gnus)Customizing Articles")
1165 :type gnus-article-treat-custom)
1167 (defcustom gnus-treat-unsplit-urls nil
1168 "Remove newlines from within URLs.
1169 Valid values are nil, t, `head', `first', `last', an integer or a
1170 predicate. See Info node `(gnus)Customizing Articles'."
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-custom)
1176 (defcustom gnus-treat-leading-whitespace nil
1177 "Remove leading whitespace in headers.
1178 Valid values are nil, t, `head', `first', `last', an integer or a
1179 predicate. See Info node `(gnus)Customizing Articles'."
1181 :group 'gnus-article-treat
1182 :link '(custom-manual "(gnus)Customizing Articles")
1183 :type gnus-article-treat-custom)
1185 (defcustom gnus-treat-hide-headers 'head
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-boring-headers nil
1194 "Hide boring headers.
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-head-custom)
1201 (defcustom gnus-treat-hide-signature nil
1202 "Hide the signature.
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-fill-article nil
1211 Valid values are nil, t, `head', `first', `last', an integer or a
1212 predicate. See Info node `(gnus)Customizing Articles'."
1213 :group 'gnus-article-treat
1214 :link '(custom-manual "(gnus)Customizing Articles")
1215 :type gnus-article-treat-custom)
1217 (defcustom gnus-treat-hide-citation nil
1219 Valid values are nil, t, `head', `first', `last', an integer or a
1220 predicate. See Info node `(gnus)Customizing Articles'.
1222 See `gnus-article-highlight-citation' for variables used to
1223 control what it hides."
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1228 (defcustom gnus-treat-hide-citation-maybe nil
1229 "Hide cited text according to certain conditions.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'.
1233 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1234 how to control what it hides."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1239 (defcustom gnus-treat-strip-list-identifiers 'head
1240 "Strip list identifiers from `gnus-list-identifiers'.
1241 Valid values are nil, t, `head', `first', `last', an integer or a
1242 predicate. See Info node `(gnus)Customizing Articles'."
1244 :group 'gnus-article-treat
1245 :link '(custom-manual "(gnus)Customizing Articles")
1246 :type gnus-article-treat-custom)
1248 (gnus-define-group-parameter
1251 "Alist of regexps and correspondent identifiers."
1252 :variable-group gnus-article-washing
1254 '(choice :tag "Identifier"
1256 (symbol :tag "Item in `gnus-list-identifiers'" none)
1258 (const :tag "None" nil))
1260 "If non-nil, specify how to remove `identifiers' from articles' subject.
1262 Any symbol is used to look up a regular expression to match the
1263 banner in `gnus-list-identifiers'. A string is used as a regular
1264 expression to match the identifier directly.")
1266 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1267 "Gnus 5.10 (Emacs 22.1)")
1269 (defcustom gnus-treat-strip-pem nil
1270 "Strip PEM signatures.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1273 :group 'gnus-article-treat
1274 :link '(custom-manual "(gnus)Customizing Articles")
1275 :type gnus-article-treat-custom)
1277 (defcustom gnus-treat-strip-banner t
1278 "Strip banners from articles.
1279 The banner to be stripped is specified in the `banner' group parameter.
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-custom)
1286 (defcustom gnus-treat-highlight-headers 'head
1287 "Highlight the headers.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-head-custom)
1293 (put 'gnus-treat-highlight-headers 'highlight t)
1295 (defcustom gnus-treat-highlight-citation t
1296 "Highlight cited text.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-custom)
1302 (put 'gnus-treat-highlight-citation 'highlight t)
1304 (defcustom gnus-treat-strip-headers-in-body t
1305 "Strip the X-No-Archive header line from the beginning of the body.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate. See Info node `(gnus)Customizing Articles'."
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-custom)
1313 (defcustom gnus-treat-strip-trailing-blank-lines nil
1314 "Strip trailing blank lines.
1315 Valid values are nil, t, `head', `first', `last', an integer or a
1316 predicate. See Info node `(gnus)Customizing Articles'.
1318 When set to t, it also strips trailing blanks in all MIME parts.
1319 Consider to use `last' instead."
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1324 (defcustom gnus-treat-strip-leading-blank-lines nil
1325 "Strip leading blank lines.
1326 Valid values are nil, t, `head', `first', `last', an integer or a
1327 predicate. See Info node `(gnus)Customizing Articles'.
1329 When set to t, it also strips trailing blanks in all MIME parts."
1330 :group 'gnus-article-treat
1331 :link '(custom-manual "(gnus)Customizing Articles")
1332 :type gnus-article-treat-custom)
1334 (defcustom gnus-treat-strip-multiple-blank-lines nil
1335 "Strip multiple blank lines.
1336 Valid values are nil, t, `head', `first', `last', an integer or a
1337 predicate. See Info node `(gnus)Customizing Articles'."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1342 (defcustom gnus-treat-unfold-headers 'head
1343 "Unfold folded header lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'."
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1351 (defcustom gnus-article-unfold-long-headers nil
1352 "If non-nil, allow unfolding headers even if the header is long.
1353 If it is a regexp, only long headers matching this regexp are unfolded.
1354 If it is t, all long headers are unfolded.
1356 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1357 :version "23.1" ;; No Gnus
1358 :group 'gnus-article-treat
1359 :type '(choice (const nil)
1360 (const :tag "all" t)
1363 (defcustom gnus-treat-fold-headers nil
1365 Valid values are nil, t, `head', `first', `last', an integer or a
1366 predicate. See Info node `(gnus)Customizing Articles'."
1368 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :type gnus-article-treat-custom)
1372 (defcustom gnus-treat-fold-newsgroups 'head
1373 "Fold the Newsgroups and Followup-To headers.
1374 Valid values are nil, t, `head', `first', `last', an integer or a
1375 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)
1381 (defcustom gnus-treat-overstrike t
1382 "Treat overstrike highlighting.
1383 Valid values are nil, t, `head', `first', `last', an integer or a
1384 predicate. See Info node `(gnus)Customizing Articles'."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1388 (put 'gnus-treat-overstrike 'highlight t)
1390 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1391 "Treat ANSI SGR control sequences.
1392 Valid values are nil, t, `head', `first', `last', an integer or a
1393 predicate. See Info node `(gnus)Customizing Articles'."
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1398 (make-obsolete-variable 'gnus-treat-display-xface
1399 'gnus-treat-display-x-face "Emacs 22.1")
1401 (defcustom gnus-treat-display-x-face
1402 (and (not noninteractive)
1403 (gnus-image-type-available-p 'xbm)
1405 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1406 (executable-find "icontopbm"))
1407 ;; shell-command-to-string may signal an error, e.g. if
1408 ;; shell-file-name is not found.
1411 "Display X-Face headers.
1412 Valid values are nil and `head'.
1413 See Info node `(gnus)Customizing Articles' and Info node
1414 `(gnus)X-Face' for details."
1415 :group 'gnus-article-treat
1417 :link '(custom-manual "(gnus)Customizing Articles")
1418 :link '(custom-manual "(gnus)X-Face")
1419 :type gnus-article-treat-head-custom
1420 :set (lambda (symbol value)
1423 (cond ((or (boundp symbol) (get symbol 'saved-value))
1425 ((boundp 'gnus-treat-display-xface)
1427 ** gnus-treat-display-xface is an obsolete variable;\
1428 use gnus-treat-display-x-face instead")
1429 (default-value 'gnus-treat-display-xface))
1430 ((get 'gnus-treat-display-xface 'saved-value)
1432 ** gnus-treat-display-xface is an obsolete variable;\
1433 use gnus-treat-display-x-face instead")
1434 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1437 (put 'gnus-treat-display-x-face 'highlight t)
1439 (defcustom gnus-treat-display-face
1440 (and (not noninteractive)
1441 (gnus-image-type-available-p 'png)
1443 "Display Face headers.
1444 Valid values are nil, t, `head', `first', `last', an integer or a
1445 predicate. See Info node `(gnus)Customizing Articles' and Info
1446 node `(gnus)Face' for details."
1447 :group 'gnus-article-treat
1449 :link '(custom-manual "(gnus)Customizing Articles")
1450 :link '(custom-manual "(gnus)X-Face")
1451 :type gnus-article-treat-head-custom)
1452 (put 'gnus-treat-display-face 'highlight t)
1454 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1456 Valid values are nil, t, `head', `first', `last', an integer or a
1457 predicate. See Info node `(gnus)Customizing Articles' and Info
1458 node `(gnus)Smileys' for details."
1459 :group 'gnus-article-treat
1461 :link '(custom-manual "(gnus)Customizing Articles")
1462 :link '(custom-manual "(gnus)Smileys")
1463 :type gnus-article-treat-custom)
1464 (put 'gnus-treat-display-smileys 'highlight t)
1466 (defcustom gnus-treat-from-picon
1467 (if (and (gnus-image-type-available-p 'xpm)
1468 (gnus-picons-installed-p))
1470 "Display picons in the From header.
1471 Valid values are nil, t, `head', `first', `last', an integer or a
1472 predicate. See Info node `(gnus)Customizing Articles' and Info
1473 node `(gnus)Picons' for details."
1475 :group 'gnus-article-treat
1477 :link '(custom-manual "(gnus)Customizing Articles")
1478 :link '(custom-manual "(gnus)Picons")
1479 :type gnus-article-treat-head-custom)
1480 (put 'gnus-treat-from-picon 'highlight t)
1482 (defcustom gnus-treat-mail-picon
1483 (if (and (gnus-image-type-available-p 'xpm)
1484 (gnus-picons-installed-p))
1486 "Display picons in To and Cc headers.
1487 Valid values are nil, t, `head', `first', `last', an integer or a
1488 predicate. See Info node `(gnus)Customizing Articles' and Info
1489 node `(gnus)Picons' for details."
1491 :group 'gnus-article-treat
1493 :link '(custom-manual "(gnus)Customizing Articles")
1494 :link '(custom-manual "(gnus)Picons")
1495 :type gnus-article-treat-head-custom)
1496 (put 'gnus-treat-mail-picon 'highlight t)
1498 (defcustom gnus-treat-newsgroups-picon
1499 (if (and (gnus-image-type-available-p 'xpm)
1500 (gnus-picons-installed-p))
1502 "Display picons in the Newsgroups and Followup-To headers.
1503 Valid values are nil, t, `head', `first', `last', an integer or a
1504 predicate. See Info node `(gnus)Customizing Articles' and Info
1505 node `(gnus)Picons' for details."
1507 :group 'gnus-article-treat
1509 :link '(custom-manual "(gnus)Customizing Articles")
1510 :link '(custom-manual "(gnus)Picons")
1511 :type gnus-article-treat-head-custom)
1512 (put 'gnus-treat-newsgroups-picon 'highlight t)
1514 (defcustom gnus-treat-from-gravatar nil
1515 "Display gravatars in the From header.
1516 Valid values are nil, t, `head', `first', `last', an integer or a
1517 predicate. See Info node `(gnus)Customizing Articles' and Info
1518 node `(gnus)Gravatars' for details."
1520 :group 'gnus-article-treat
1521 :group 'gnus-gravatar
1522 :link '(custom-manual "(gnus)Customizing Articles")
1523 :link '(custom-manual "(gnus)Gravatars")
1524 :type gnus-article-treat-head-custom)
1525 (put 'gnus-treat-from-gravatar 'highlight t)
1527 (defcustom gnus-treat-mail-gravatar nil
1528 "Display gravatars in To and Cc headers.
1529 Valid values are nil, t, `head', `first', `last', an integer or a
1530 predicate. See Info node `(gnus)Customizing Articles' and Info
1531 node `(gnus)Gravatars' for details."
1533 :group 'gnus-article-treat
1534 :group 'gnus-gravatar
1535 :link '(custom-manual "(gnus)Customizing Articles")
1536 :link '(custom-manual "(gnus)Gravatars")
1537 :type gnus-article-treat-head-custom)
1538 (put 'gnus-treat-mail-gravatar 'highlight t)
1540 (defcustom gnus-treat-body-boundary
1541 (if (or gnus-treat-newsgroups-picon
1542 gnus-treat-mail-picon
1543 gnus-treat-from-picon
1544 gnus-treat-from-gravatar
1545 gnus-treat-mail-gravatar)
1546 ;; If there's much decoration, the user might prefer a boundary.
1549 "Draw a boundary at the end of the headers.
1550 Valid values are nil and `head'.
1551 See Info node `(gnus)Customizing Articles' for details."
1553 :group 'gnus-article-treat
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :type gnus-article-treat-head-custom)
1557 (defcustom gnus-treat-capitalize-sentences nil
1558 "Capitalize sentence-starting words.
1559 Valid values are nil, t, `head', `first', `last', an integer or a
1560 predicate. See Info node `(gnus)Customizing Articles'."
1562 :group 'gnus-article-treat
1563 :link '(custom-manual "(gnus)Customizing Articles")
1564 :type gnus-article-treat-custom)
1566 (defcustom gnus-treat-wash-html nil
1568 Valid values are nil, t, `head', `first', `last', an integer or a
1569 predicate. See Info node `(gnus)Customizing Articles'."
1571 :group 'gnus-article-treat
1572 :link '(custom-manual "(gnus)Customizing Articles")
1573 :type gnus-article-treat-custom)
1575 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1577 Valid values are nil, t, `head', `first', `last', an integer or a
1578 predicate. See Info node `(gnus)Customizing Articles'."
1580 :group 'gnus-article-treat
1581 :link '(custom-manual "(gnus)Customizing Articles")
1582 :type gnus-article-treat-custom)
1584 (defcustom gnus-treat-x-pgp-sig nil
1586 To automatically treat X-PGP-Sig, set it to head.
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1590 :group 'gnus-article-treat
1591 :group 'mime-security
1592 :link '(custom-manual "(gnus)Customizing Articles")
1593 :type gnus-article-treat-custom)
1595 (defvar gnus-article-encrypt-protocol-alist
1596 '(("PGP" . mml2015-self-encrypt)))
1598 ;; Set to nil if more than one protocol added to
1599 ;; gnus-article-encrypt-protocol-alist.
1600 (defcustom gnus-article-encrypt-protocol "PGP"
1601 "The protocol used for encrypt articles.
1602 It is a string, such as \"PGP\". If nil, ask user."
1605 :group 'mime-security)
1607 (defvar idna-program)
1609 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1613 (invalid-operation))
1615 (executable-find idna-program))
1616 "Whether IDNA decoding of headers is used when viewing messages.
1617 This requires GNU Libidn, and by default only enabled if it is found."
1619 :group 'gnus-article-headers
1622 (defcustom gnus-article-over-scroll nil
1623 "If non-nil, allow scrolling the article buffer even when there no more text."
1625 :group 'gnus-article
1628 (defcustom gnus-inhibit-images nil
1629 "Non-nil means inhibit displaying of images inline in the article body."
1631 :group 'gnus-article
1634 (defcustom gnus-blocked-images 'gnus-block-private-groups
1635 "Images that have URLs matching this regexp will be blocked.
1636 This can also be a function to be evaluated. If so, it will be
1637 called with the group name as the parameter, and should return a
1641 :type '(choice (const :tag "Allow all" nil)
1642 (regexp :tag "Regular expression")
1643 (function :tag "Use a function")))
1645 ;;; Internal variables
1647 (defvar gnus-english-month-names
1648 '("January" "February" "March" "April" "May" "June" "July" "August"
1649 "September" "October" "November" "December"))
1651 (defvar article-goto-body-goes-to-point-min-p nil)
1652 (defvar gnus-article-wash-types nil)
1653 (defvar gnus-article-emphasis-alist nil)
1654 (defvar gnus-article-image-alist nil)
1656 (defvar gnus-article-mime-handle-alist-1 nil)
1657 (defvar gnus-treatment-function-alist
1658 '((gnus-treat-strip-cr gnus-article-remove-cr)
1659 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1660 (gnus-treat-strip-banner gnus-article-strip-banner)
1661 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1662 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1663 (gnus-treat-buttonize gnus-article-add-buttons)
1664 (gnus-treat-fill-article gnus-article-fill-cited-article)
1665 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1666 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1667 (gnus-treat-display-x-face gnus-article-display-x-face)
1668 (gnus-treat-display-face gnus-article-display-face)
1669 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1670 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1671 (gnus-treat-hide-signature gnus-article-hide-signature)
1672 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1673 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1674 (gnus-treat-from-picon gnus-treat-from-picon)
1675 (gnus-treat-mail-picon gnus-treat-mail-picon)
1676 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1677 (gnus-treat-strip-pem gnus-article-hide-pem)
1678 (gnus-treat-date gnus-article-treat-date)
1679 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1680 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1681 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1682 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1683 (gnus-treat-strip-trailing-blank-lines
1684 gnus-article-remove-trailing-blank-lines)
1685 (gnus-treat-strip-leading-blank-lines
1686 gnus-article-strip-leading-blank-lines)
1687 (gnus-treat-strip-multiple-blank-lines
1688 gnus-article-strip-multiple-blank-lines)
1689 (gnus-treat-overstrike gnus-article-treat-overstrike)
1690 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1691 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1692 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1693 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1694 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1695 (gnus-treat-display-smileys gnus-treat-smiley)
1696 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1697 (gnus-treat-wash-html gnus-article-wash-html)
1698 (gnus-treat-emphasize gnus-article-emphasize)
1699 (gnus-treat-hide-citation gnus-article-hide-citation)
1700 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1701 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1702 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1704 (defvar gnus-article-mime-handle-alist nil)
1705 (defvar article-lapsed-timer nil)
1706 (defvar gnus-article-current-summary nil)
1708 (defvar gnus-article-mode-syntax-table
1709 (let ((table (copy-syntax-table text-mode-syntax-table)))
1710 ;; This causes the citation match run O(2^n).
1711 ;; (modify-syntax-entry ?- "w" table)
1712 (modify-syntax-entry ?> ")<" table)
1713 (modify-syntax-entry ?< "(>" table)
1714 ;; make M-. in article buffers work for `foo' strings
1715 (modify-syntax-entry ?' " " table)
1716 (modify-syntax-entry ?` " " 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
1734 (let ((inhibit-read-only t)
1735 (inhibit-point-motion-hooks t)
1736 (case-fold-search t))
1737 (article-narrow-to-head)
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))
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."
1779 (let ((b (point-min)))
1780 (if (eq type 'multipart)
1781 ;; Remove MIME buttons associated with multipart/alternative parts.
1784 (while (if (get-text-property (point) 'gnus-part)
1786 (when (setq b (next-single-property-change (point)
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))
1796 b (or (text-property-not-all b (point-max) 'article-type type)
1799 (defun gnus-article-delete-invisible-text ()
1800 "Delete all invisible text in the current buffer."
1802 (let ((b (point-min)))
1803 (while (setq b (text-property-any b (point-max) 'invisible t))
1805 b (or (text-property-not-all b (point-max) 'invisible t)
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)
1813 (if (looking-at (car list))
1815 (setq list (cdr list))
1819 (defun article-hide-headers (&optional _arg _delete)
1820 "Hide unwanted headers and possibly sort them as well."
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)
1831 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1832 ;; group parameters, so we should go to the summary buffer.
1835 (progn (set-buffer gnus-summary-buffer) t)
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
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
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 ")
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
1865 (while (re-search-forward "^[^ \t:]*:" nil t)
1867 ;; Mark the rank of the header.
1869 (point) (1+ (point)) 'message-rank
1870 (if (or (and visible (looking-at visible))
1872 (not (looking-at ignored))))
1873 (gnus-article-header-rank)
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,
1889 (interactive (gnus-article-hidden-arg))
1890 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1891 (not gnus-show-all-headers))
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))
1900 ;; Hide empty headers.
1902 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1904 (gnus-article-hide-text-type
1908 (if (re-search-forward "^[^ \t]" nil t)
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)
1920 (gnus-article-hide-header "newsgroups")))
1921 ((eq elem 'to-address)
1922 (let ((to (message-fetch-field "to"))
1924 (gnus-parameter-to-address
1925 (if (boundp 'gnus-newsgroup-name)
1926 gnus-newsgroup-name ""))))
1927 (when (and to to-address
1930 ;; only one address in To
1931 (nth 1 (mail-extract-address-components to))
1933 (gnus-article-hide-header "to"))))
1935 (let ((to (message-fetch-field "to"))
1937 (gnus-parameter-to-list
1938 (if (boundp 'gnus-newsgroup-name)
1939 gnus-newsgroup-name ""))))
1940 (when (and to to-list
1943 ;; only one address in To
1944 (nth 1 (mail-extract-address-components to))
1946 (gnus-article-hide-header "to"))))
1948 (let ((cc (message-fetch-field "cc"))
1950 (gnus-parameter-to-list
1951 (if (boundp 'gnus-newsgroup-name)
1952 gnus-newsgroup-name ""))))
1953 (when (and cc to-list
1956 ;; only one address in CC
1957 (nth 1 (mail-extract-address-components cc))
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")))
1977 (lambda (x) (downcase (cadr x)))
1978 (mail-extract-address-components from t))
1981 (lambda (x) (downcase (cadr x)))
1982 (mail-extract-address-components reply-to t))
1984 (gnus-article-hide-header "reply-to")))))
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"))))
1992 (< (days-between (current-time-string) date)
1994 (gnus-article-hide-header "date"))))
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"))))
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))
2012 (re-search-forward "^to:" nil nil to-count)
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))
2024 (re-search-forward "^cc:" nil nil cc-count)
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)
2032 (goto-char (point-min))
2033 (when (re-search-forward (concat "^" header ":") nil t)
2034 (gnus-article-hide-text-type
2038 (if (re-search-forward "^[^ \t]" nil t)
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."
2049 (let ((inhibit-read-only t)
2053 (article-narrow-to-head)
2056 ((< (setq column (- (point-at-eol) (point)))
2057 gnus-article-normalized-header-length)
2059 (insert (make-string
2060 (- gnus-article-normalized-header-length column)
2062 ((> column gnus-article-normalized-header-length)
2065 (forward-char gnus-article-normalized-header-length)
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
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."
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))))
2099 (when (article-goto-body)
2100 (let ((inhibit-read-only t)
2103 (if (not (setq replace (aref table (following-char))))
2106 (setq props (text-properties-at (point)))
2108 (add-text-properties (point) (progn (insert replace) (point))
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\")."
2116 (when (article-goto-body)
2117 (let ((inhibit-read-only t))
2119 (let ((from (car elem))
2123 (while (search-forward from nil t)
2126 (if (eq (following-char) from)
2130 (forward-char 1)))))))))))
2132 (defun article-treat-overstrike ()
2133 "Translate overstrikes into bold text."
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
2146 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2147 (put-text-property (point) (1+ (point)) 'face 'bold))
2149 (gnus-article-hide-text-type
2150 (1- (point)) (1+ (point)) 'overstrike)
2152 (- (point) 2) (1- (point)) 'face 'underline))
2154 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2156 (point) (1+ (point)) 'face 'underline)))))))))
2158 (defun article-treat-ansi-sequences ()
2159 "Translate ANSI SGR control sequences into overlays or extents."
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
2171 (gnus-with-article-headers
2175 (mail-header-narrow-to-field)
2176 (let* ((header (buffer-string))
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
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."
2197 (gnus-with-article-headers
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."
2207 (gnus-with-article-buffer
2208 (if (memq 'smiley gnus-article-wash-types)
2209 (gnus-delete-images 'smiley)
2211 (let ((images (smiley-region (point) (point-max))))
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."
2220 (gnus-with-article-buffer
2223 (dolist (elem gnus-article-image-alist)
2224 (gnus-delete-images (car elem))))))
2226 (autoload '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."
2232 (gnus-with-article-buffer
2235 (if (eq mm-text-html-renderer 'w3m)
2236 (w3m-toggle-inline-images)
2237 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2239 (destructuring-bind (start end function) region
2240 (funcall function (get-text-property start 'image-url)
2243 (defun gnus-article-treat-fold-newsgroups ()
2244 "Unfold folded message headers.
2245 Only the headers that fit into the current window width will be
2248 (gnus-with-article-headers
2249 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2251 (mail-header-narrow-to-field)
2252 (while (re-search-forward ", *" nil t)
2253 (replace-match ", " t t))
2254 (mail-header-fold-field)
2255 (goto-char (point-max))))))
2257 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2258 "Value of `truncate-lines' in Gnus Article buffer.
2259 Valid values are nil, t, `head', `first', `last', an integer or a
2260 predicate. See Info node `(gnus)Customizing Articles'."
2261 :version "23.1" ;; No Gnus
2262 :group 'gnus-article
2263 ;; :link '(custom-manual "(gnus)Customizing Articles")
2266 (defun gnus-article-toggle-truncate-lines (&optional arg)
2267 "Toggle whether to fold or truncate long lines in article the buffer.
2268 If ARG is non-nil and not a number, toggle
2269 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2270 long lines if and only if arg is positive."
2273 ((and (numberp arg) (> arg 0))
2274 (setq gnus-article-truncate-lines t))
2276 (setq gnus-article-truncate-lines nil))
2278 (setq gnus-article-truncate-lines
2279 (not gnus-article-truncate-lines))))
2280 (gnus-with-article-buffer
2282 ((and (numberp arg) (> arg 0))
2283 (setq truncate-lines nil))
2285 (setq truncate-lines t)))
2286 (toggle-truncate-lines)))
2288 (defun gnus-article-treat-body-boundary ()
2289 "Place a boundary line at the end of the headers."
2291 (when (and gnus-body-boundary-delimiter
2292 (> (length gnus-body-boundary-delimiter) 0))
2293 (gnus-with-article-headers
2294 (goto-char (point-max))
2295 (let ((start (point)))
2296 (insert "X-Boundary: ")
2297 (add-text-properties start (point) gnus-hidden-properties)
2298 (insert (let (str (max (window-width)))
2299 (while (>= max (length str))
2300 (setq str (concat str gnus-body-boundary-delimiter)))
2301 (substring str 0 max))
2303 (put-text-property start (point) 'gnus-decoration 'header)))))
2305 (defun article-fill-long-lines ()
2306 "Fill lines that are wider than the window width."
2309 (let ((inhibit-read-only t)
2310 (width (window-width (get-buffer-window (current-buffer)))))
2313 (let ((adaptive-fill-mode nil)) ;Why? -sm
2316 (when (>= (current-column) (min fill-column width))
2317 (narrow-to-region (min (1+ (point)) (point-max))
2319 (let ((goback (point-marker)))
2320 (fill-paragraph nil)
2321 (goto-char (marker-position goback)))
2323 (forward-line 1)))))))
2325 (defun article-capitalize-sentences ()
2326 "Capitalize the first word in each sentence."
2329 (let ((inhibit-read-only t)
2330 (paragraph-start "^[\n\^L]"))
2334 (forward-sentence)))))
2336 (defun article-remove-cr ()
2337 "Remove trailing CRs and then translate remaining CRs into LFs."
2340 (let ((inhibit-read-only t))
2341 (goto-char (point-min))
2342 (while (re-search-forward "\r+$" nil t)
2343 (replace-match "" t t))
2344 (goto-char (point-min))
2345 (while (search-forward "\r" nil t)
2346 (replace-match "\n" t t)))))
2348 (defun article-remove-trailing-blank-lines ()
2349 "Remove all trailing blank lines from the article."
2352 (let ((inhibit-read-only t))
2353 (goto-char (point-max))
2357 (while (and (not (bobp))
2358 (looking-at "^[ \t]*$")
2359 (not (gnus-annotation-in-region-p
2360 (point) (point-at-eol))))
2365 (defvar gnus-face-properties-alist)
2367 (defun article-display-face (&optional force)
2368 "Display any Face headers in the header."
2369 (interactive (list 'force))
2370 (let ((wash-face-p buffer-read-only))
2371 (gnus-with-article-headers
2372 ;; When displaying parts, this function can be called several times on
2373 ;; the same article, without any intended toggle semantic (as typing `W
2374 ;; D d' would have). So face deletion must occur only when we come from
2375 ;; an interactive command, that is when the *Article* buffer is
2377 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2378 (gnus-delete-images 'face)
2379 (let ((from (message-fetch-field "from"))
2381 (save-current-buffer
2382 (when (and wash-face-p
2383 (gnus-buffer-live-p gnus-original-article-buffer)
2384 (not (re-search-forward "^Face:[\t ]*" nil t)))
2385 (set-buffer gnus-original-article-buffer))
2387 (mail-narrow-to-head)
2389 ;; Check whether this face is censored.
2390 (not (and gnus-article-x-face-too-ugly
2392 (setq from (message-fetch-field "from")))
2393 (string-match gnus-article-x-face-too-ugly
2395 (while (gnus-article-goto-header "Face")
2396 (push (mail-header-field-value) faces)))))
2398 (goto-char (point-min))
2400 (unless (setq from (gnus-article-goto-header "from"))
2403 (insert " [no 'from' set]\n"))
2405 (when (setq png (gnus-convert-face-to-png (pop faces)))
2407 (apply 'gnus-create-image png 'png t
2408 (cdr (assq 'png gnus-face-properties-alist))))
2411 (gnus-add-wash-type 'face)
2412 (gnus-add-image 'face image)
2413 (gnus-put-image image nil 'face)))))))))))
2415 (defun article-display-x-face (&optional force)
2416 "Look for an X-Face header and display it if present."
2417 (interactive (list 'force))
2418 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2419 (gnus-with-article-headers
2420 ;; Delete the old process, if any.
2421 (when (process-status "article-x-face")
2422 (delete-process "article-x-face"))
2423 ;; See the comment in `article-display-face'.
2424 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2425 ;; We have already displayed X-Faces, so we remove them
2427 (gnus-delete-images 'xface)
2429 (let ((from (message-fetch-field "from"))
2431 (save-current-buffer
2432 (when (and wash-face-p
2433 (gnus-buffer-live-p gnus-original-article-buffer)
2434 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2435 ;; If type `W f', use gnus-original-article-buffer,
2436 ;; otherwise use the current buffer because displaying
2437 ;; RFC822 parts calls this function too.
2438 (set-buffer gnus-original-article-buffer))
2440 (mail-narrow-to-head)
2441 (and gnus-article-x-face-command
2443 ;; Check whether this face is censored.
2444 (not (and gnus-article-x-face-too-ugly
2446 (setq from (message-fetch-field "from")))
2447 (string-match gnus-article-x-face-too-ugly
2449 (while (gnus-article-goto-header "X-Face")
2450 (push (mail-header-field-value) x-faces)))))
2452 ;; We display the face.
2453 (cond ((functionp gnus-article-x-face-command)
2454 ;; The command is a lisp function, so we call it.
2455 (mapc gnus-article-x-face-command x-faces))
2456 ((stringp gnus-article-x-face-command)
2457 ;; The command is a string, so we interpret the command
2458 ;; as a, well, command, and fork it off.
2459 (let ((process-connection-type nil))
2460 (set-process-query-on-exit-flag
2462 "article-x-face" nil shell-file-name
2463 shell-command-switch gnus-article-x-face-command)
2465 ;; Sending multiple EOFs to xv doesn't work,
2466 ;; so we only do a single external face.
2468 (insert (car x-faces))
2469 (process-send-region "article-x-face"
2470 (point-min) (point-max)))
2471 (process-send-eof "article-x-face")))
2473 (error "`%s' set to `%s' is not a function"
2474 gnus-article-x-face-command
2475 'gnus-article-x-face-command)))))))))
2477 (defun article-decode-mime-words ()
2478 "Decode all MIME-encoded words in the article."
2480 (gnus-with-article-buffer
2481 (let ((inhibit-point-motion-hooks t)
2482 (mail-parse-charset gnus-newsgroup-charset)
2483 (mail-parse-ignored-charsets
2484 (with-current-buffer gnus-summary-buffer
2485 gnus-newsgroup-ignored-charsets)))
2486 (mail-decode-encoded-word-region (point-min) (point-max)))))
2488 (defun article-decode-charset (&optional prompt)
2489 "Decode charset-encoded text in the article.
2490 If PROMPT (the prefix), prompt for a coding system to use."
2492 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2493 (inhibit-read-only t)
2494 (mail-parse-charset gnus-newsgroup-charset)
2495 (mail-parse-ignored-charsets
2496 (save-excursion (condition-case nil
2497 (set-buffer gnus-summary-buffer)
2499 gnus-newsgroup-ignored-charsets))
2500 ct cte ctl charset format)
2503 (article-narrow-to-head)
2504 (setq ct (message-fetch-field "Content-Type" t)
2505 cte (message-fetch-field "Content-Transfer-Encoding" t)
2506 ctl (and ct (mail-header-parse-content-type ct))
2509 (read-coding-system "Charset to decode: "))
2511 (mail-content-type-get ctl 'charset)))
2512 format (and ctl (mail-content-type-get ctl 'format)))
2514 (setq cte (mail-header-strip cte)))
2515 (if (and ctl (not (string-match "/" (car ctl))))
2517 (goto-char (point-max)))
2520 (narrow-to-region (point) (point-max))
2521 (when (and (eq mail-parse-charset 'gnus-decoded)
2522 (eq (mm-body-7-or-8) '8bit))
2523 ;; The text code could have been decoded.
2524 (setq charset mail-parse-charset))
2525 (when (and (or (not ctl)
2526 (equal (car ctl) "text/plain"))
2527 (not format)) ;; article with format will decode later.
2529 charset (and cte (intern (downcase
2530 (gnus-strip-whitespace cte))))
2533 (defun article-decode-encoded-words ()
2534 "Remove encoded-word encoding from headers."
2535 (let ((inhibit-point-motion-hooks t)
2536 (mail-parse-charset gnus-newsgroup-charset)
2537 (mail-parse-ignored-charsets
2538 (save-excursion (condition-case nil
2539 (set-buffer gnus-summary-buffer)
2541 gnus-newsgroup-ignored-charsets))
2542 (inhibit-read-only t)
2544 (goto-char (point-min))
2545 (when (search-forward "\n\n" nil 'move)
2552 (memq (char-after) '(?\t ? )))))
2553 (setq start (point))
2555 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2556 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2557 (funcall gnus-decode-address-function start end)
2558 (funcall gnus-decode-header-function start end))
2559 (goto-char (setq end start)))))
2561 (defun article-decode-group-name ()
2562 "Decode group names in Newsgroups, Followup-To and Xref headers."
2563 (let ((inhibit-point-motion-hooks t)
2564 (inhibit-read-only t)
2565 (method (gnus-find-method-for-group gnus-newsgroup-name))
2567 (when (and (or gnus-group-name-charset-method-alist
2568 gnus-group-name-charset-group-alist)
2569 (gnus-buffer-live-p gnus-original-article-buffer))
2571 (article-narrow-to-head)
2572 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2573 (with-current-buffer gnus-original-article-buffer
2574 (goto-char (point-min)))
2575 (setq regexp (concat "^" header
2576 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2577 (while (re-search-forward regexp nil t)
2578 (replace-match (save-match-data
2579 (gnus-decode-newsgroups
2580 ;; XXX how to use data in article buffer?
2581 (with-current-buffer gnus-original-article-buffer
2582 (re-search-forward regexp nil t)
2584 gnus-newsgroup-name method))
2586 (goto-char (point-min)))))))
2588 (autoload 'idna-to-unicode "idna")
2590 (defun article-decode-idna-rhs ()
2591 "Decode IDNA strings in RHS in various headers in current buffer.
2592 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2593 Mail-Reply-To: and Mail-Followup-To:."
2596 (let ((inhibit-point-motion-hooks t)
2597 (inhibit-read-only t))
2598 (article-narrow-to-head)
2599 (goto-char (point-min))
2600 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2602 (when (save-match-data
2603 (and (setq ace (match-string 1))
2605 (and (re-search-backward "^[^ \t]" nil t)
2606 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2607 (setq unicode (idna-to-unicode ace))))
2608 (unless (string= ace unicode)
2609 (replace-match unicode nil nil nil 1)))))))))
2611 (defun article-de-quoted-unreadable (&optional force read-charset)
2612 "Translate a quoted-printable-encoded article.
2613 If FORCE, decode the article whether it is marked as quoted-printable
2615 If READ-CHARSET, ask for a coding system."
2616 (interactive (list 'force current-prefix-arg))
2618 (let ((inhibit-read-only t) type charset)
2619 (if (gnus-buffer-live-p gnus-original-article-buffer)
2620 (with-current-buffer gnus-original-article-buffer
2622 (gnus-fetch-field "content-transfer-encoding"))
2623 (let* ((ct (gnus-fetch-field "content-type"))
2624 (ctl (and ct (mail-header-parse-content-type ct))))
2625 (setq charset (and ctl
2626 (mail-content-type-get ctl 'charset)))
2627 (if (stringp charset)
2628 (setq charset (intern (downcase charset)))))))
2630 (setq charset (read-coding-system "Charset: " charset)))
2632 (setq charset gnus-newsgroup-charset))
2634 (and type (let ((case-fold-search t))
2635 (string-match "quoted-printable" type))))
2637 (quoted-printable-decode-region
2638 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2640 (defun article-de-base64-unreadable (&optional force read-charset)
2641 "Translate a base64 article.
2642 If FORCE, decode the article whether it is marked as base64 not.
2643 If READ-CHARSET, ask for a coding system."
2644 (interactive (list 'force current-prefix-arg))
2646 (let ((inhibit-read-only t) type charset)
2647 (if (gnus-buffer-live-p gnus-original-article-buffer)
2648 (with-current-buffer gnus-original-article-buffer
2650 (gnus-fetch-field "content-transfer-encoding"))
2651 (let* ((ct (gnus-fetch-field "content-type"))
2652 (ctl (and ct (mail-header-parse-content-type ct))))
2653 (setq charset (and ctl
2654 (mail-content-type-get ctl 'charset)))
2655 (if (stringp charset)
2656 (setq charset (intern (downcase charset)))))))
2658 (setq charset (read-coding-system "Charset: " charset)))
2660 (setq charset gnus-newsgroup-charset))
2662 (and type (let ((case-fold-search t))
2663 (string-match "base64" type))))
2666 (narrow-to-region (point) (point-max))
2667 (base64-decode-region (point-min) (point-max))
2668 (decode-coding-region
2669 (point-min) (point-max)
2670 (mm-charset-to-coding-system charset nil t)))))))
2672 (declare-function rfc1843-decode-region "rfc1843" (from to))
2674 (defun article-decode-HZ ()
2675 "Translate a HZ-encoded article."
2679 (let ((inhibit-read-only t))
2680 (rfc1843-decode-region (point-min) (point-max)))))
2682 (defun article-unsplit-urls ()
2683 "Remove the newlines that some other mailers insert into URLs."
2686 (let ((inhibit-read-only t))
2687 (goto-char (point-min))
2688 (while (re-search-forward
2689 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2690 (replace-match "\\1\\3" t)))
2691 (when (called-interactively-p 'any)
2692 (gnus-treat-article nil))))
2694 (defun article-wash-html ()
2695 "Format an HTML article."
2698 (buffer-read-only nil))
2699 (when (gnus-buffer-live-p gnus-original-article-buffer)
2700 (with-current-buffer gnus-original-article-buffer
2701 (setq handles (mm-dissect-buffer t t))))
2703 (delete-region (point) (point-max))
2704 (mm-enable-multibyte)
2705 (mm-inline-text-html handles)))
2707 (defvar gnus-article-browse-html-temp-list nil
2708 "List of temporary files created by `gnus-article-browse-html-parts'.
2709 Internal variable.")
2711 (defcustom gnus-article-browse-delete-temp 'ask
2712 "What to do with temporary files from `gnus-article-browse-html-parts'.
2713 If nil, don't delete temporary files. If it is t, delete them on
2714 exit from the summary buffer. If it is the symbol `file', query
2715 on each file, if it is `ask' ask once when exiting from the
2717 :group 'gnus-article
2718 :version "23.1" ;; No Gnus
2719 :type '(choice (const :tag "Don't delete" nil)
2720 (const :tag "Don't ask" t)
2721 (const :tag "Ask" ask)
2722 (const :tag "Ask for each file" file)))
2724 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2726 (defun gnus-article-browse-delete-temp-files (&optional how)
2727 "Delete temp-files created by `gnus-article-browse-html-parts'."
2728 (when (and gnus-article-browse-html-temp-list
2730 (or how (setq how gnus-article-browse-delete-temp))
2732 (let ((files (length gnus-article-browse-html-temp-list)))
2735 "Delete the temporary HTML file? "
2736 (format "Delete all %s temporary HTML files? "
2738 (setq gnus-article-browse-html-temp-list nil)))
2740 (dolist (file gnus-article-browse-html-temp-list)
2741 (cond ((file-directory-p file)
2742 (when (or (not (eq how 'file))
2745 "Delete temporary HTML file(s) in directory `%s'? "
2746 (file-name-as-directory file))))
2747 (gnus-delete-directory file)))
2748 ((file-exists-p file)
2749 (when (or (not (eq how 'file))
2751 (format "Delete temporary HTML file `%s'? " file)))
2752 (delete-file file)))))
2753 ;; Also remove file from the list when not deleted or if file doesn't
2755 (setq gnus-article-browse-html-temp-list nil))
2756 gnus-article-browse-html-temp-list)
2758 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2759 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2760 Return file name relative to the parent of DIRECTORY."
2764 (dolist (handle handles)
2766 ((not (listp handle)))
2767 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2769 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2770 ((equal (mm-handle-media-supertype handle) "multipart")
2771 (when (setq file (gnus-article-browse-html-save-cid-content
2772 cid handle directory))
2773 (throw 'found file)))
2774 ((equal (concat "<" cid ">") (mm-handle-id handle))
2775 (setq file (or (mm-handle-filename handle)
2777 (make-temp-name "cid")
2778 (car (rassoc (car (mm-handle-type handle))
2779 mailcap-mime-extensions))))
2780 afile (expand-file-name file directory))
2781 (mm-save-part-to-file handle afile)
2782 (throw 'found (concat (file-name-nondirectory
2783 (directory-file-name directory))
2786 (defun gnus-article-browse-html-parts (list &optional header)
2787 "View all \"text/html\" parts from LIST.
2788 Recurse into multiparts. The optional HEADER that should be a decoded
2789 message header will be added to the bodies of the \"text/html\" parts."
2790 ;; Internal function used by `gnus-article-browse-html-article'.
2791 (let (type file charset content cid-dir tmp-file showed)
2792 ;; Find and show the html-parts.
2793 (dolist (handle list)
2794 ;; If HTML, show it:
2795 (cond ((not (listp handle)))
2796 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2797 (and (equal (car type) "message/external-body")
2799 (setq file (mm-handle-filename handle)))
2800 (or (mm-handle-cache handle)
2801 (condition-case code
2802 (progn (mm-extern-cache-contents handle) t)
2804 (gnus-message 3 "%s" (error-message-string code))
2805 (when (>= gnus-verbose 3) (sit-for 2))
2808 (setq handle (mm-handle-cache handle)
2809 type (mm-handle-type handle))
2810 (equal (car type) "text/html"))))
2811 (setq charset (mail-content-type-get type 'charset)
2812 content (mm-get-part handle))
2814 (if (eq charset 'gnus-decoded)
2815 (mm-enable-multibyte)
2816 (mm-disable-multibyte))
2818 ;; resolve cid contents
2819 (let ((case-fold-search t)
2820 st base regexp cid-file)
2821 (goto-char (point-min))
2822 (when (and (re-search-forward "<head[\t\n >]" nil t)
2824 (setq st (match-end 0))
2825 (re-search-forward "</head[\t\n >]" nil t))
2826 (re-search-backward "<base\
2827 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2828 (setq base (match-string 1))
2829 (replace-match "<!--\\&-->")
2831 (dolist (tag '(("a" . "href") ("form" . "action")
2833 (setq regexp (concat "<" (car tag)
2834 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2835 (cdr tag) "=\"\\([^\"]+\\)"))
2836 (while (re-search-forward regexp nil t)
2840 (url-expand-file-name (match-string 1)
2842 (error (match-string 1)))
2843 (delete-region (match-beginning 1)
2846 (while (re-search-forward "\
2847 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2850 (setq cid-dir (make-temp-file "cid" t))
2851 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2854 (when (setq cid-file
2855 (gnus-article-browse-html-save-cid-content
2857 (with-current-buffer gnus-article-buffer
2858 gnus-article-mime-handles)
2860 (replace-match cid-file nil nil nil 1))))
2861 (unless content (setq content (buffer-string))))
2862 (when (or charset header (not file))
2863 (setq tmp-file (make-temp-file
2864 ;; Do we need to care for 8.3 filenames?
2865 "mm-" nil ".html")))
2866 ;; Add a meta html tag to specify charset and a header.
2869 (let (title eheader body hcharset coding)
2871 (mm-enable-multibyte)
2872 (setq case-fold-search t)
2873 (insert header "\n")
2874 (setq title (message-fetch-field "subject"))
2875 (goto-char (point-min))
2876 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2878 (replace-match (cond ((match-beginning 1) "<")
2879 ((match-beginning 2) ">")
2880 ((match-beginning 3) "&")
2882 (goto-char (point-min))
2883 (while (re-search-forward "^[\t ]+" nil t)
2886 (delete-region (match-beginning 0)
2889 (goto-char (point-min))
2890 (insert "<div align=\"left\">\n")
2891 (goto-char (point-max))
2892 (insert "</div>\n<hr>\n")
2893 ;; We have to examine charset one by one since
2894 ;; charset specified in parts might be different.
2895 (if (eq charset 'gnus-decoded)
2896 (setq charset 'utf-8
2897 eheader (encode-coding-string (buffer-string)
2900 (encode-coding-string title charset))
2901 body (encode-coding-string content charset))
2902 (setq hcharset (mm-find-mime-charset-region (point-min)
2904 (cond ((= (length hcharset) 1)
2905 (setq hcharset (car hcharset)
2906 coding (mm-charset-to-coding-system
2908 ((> (length hcharset) 1)
2909 (setq hcharset 'utf-8
2915 (mm-charset-to-coding-system charset
2917 (if (eq coding body)
2918 (setq eheader (encode-coding-string
2919 (buffer-string) coding)
2921 (encode-coding-string
2924 (setq charset 'utf-8
2925 eheader (encode-coding-string
2926 (buffer-string) charset)
2928 (encode-coding-string
2930 body (encode-coding-string
2931 (decode-coding-string
2934 (setq charset hcharset
2935 eheader (encode-coding-string
2936 (buffer-string) coding)
2938 (encode-coding-string
2941 (setq eheader (string-as-unibyte (buffer-string))
2944 (mm-disable-multibyte)
2947 (mm-add-meta-html-tag handle charset t))
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)
2957 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2959 (mm-write-region (point-min) (point-max)
2960 tmp-file nil nil nil 'binary t))))
2962 (mm-with-unibyte-buffer
2963 (insert (if (eq charset 'gnus-decoded)
2964 (encode-coding-string content
2965 (setq charset 'utf-8))
2967 (if (or (mm-add-meta-html-tag handle charset)
2969 (mm-write-region (point-min) (point-max)
2970 tmp-file nil nil nil 'binary t)
2971 (setq tmp-file nil))))
2973 (mm-save-part-to-file handle 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
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)))
2984 ;; If multipart, recurse
2985 ((equal (mm-handle-media-supertype handle) "multipart")
2986 (when (gnus-article-browse-html-parts handle header)
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)))
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)))))
3006 (gnus-article-browse-html-parts handle header)
3007 (mm-destroy-parts handle))
3011 (defun gnus-article-browse-html-article (&optional arg)
3012 "View \"text/html\" parts of the current article with a WWW browser.
3013 Inline images embedded in a message using the cid scheme, as they are
3014 generally considered to be safe, will be processed properly.
3015 The message header is added to the beginning of every html part unless
3016 the prefix argument ARG is given.
3018 Warning: Spammers use links to images (using the http scheme) in HTML
3019 articles to verify whether you have read the message. As
3020 `gnus-article-browse-html-article' passes the HTML content to the
3021 browser without eliminating these \"web bugs\" you should only
3022 use it for mails from trusted senders.
3024 If you always want to display HTML parts in the browser, set
3025 `mm-text-html-renderer' to nil.
3027 This command creates temporary files to pass HTML contents including
3028 images if any to the browser, and deletes them when exiting the group
3030 ;; Cf. `mm-w3m-safe-url-regexp'
3033 (gnus-summary-show-article)
3034 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3035 gnus-visible-headers))
3036 ;; As we insert a <hr>, there's no need for the body boundary.
3037 (gnus-treat-body-boundary nil))
3038 (gnus-summary-show-article)))
3039 (with-current-buffer gnus-article-buffer
3040 (let ((header (unless arg
3043 (buffer-substring-no-properties
3044 (goto-char (point-min))
3045 (if (search-forward "\n\n" nil t)
3047 (goto-char (point-max))
3048 (skip-chars-backward "\t\n ")
3051 (set-buffer gnus-original-article-buffer)
3052 (setq parts (mm-dissect-buffer t t))
3053 ;; If singlepart, enforce a list.
3054 (when (and (bufferp (car parts))
3055 (stringp (car (mm-handle-type parts))))
3056 (setq parts (list parts)))
3058 (unless (gnus-article-browse-html-parts parts header)
3059 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3060 (mm-destroy-parts parts)
3062 (gnus-summary-show-article)))))
3064 (defun article-hide-list-identifiers ()
3065 "Remove list identifiers from the Subject header.
3066 The `gnus-list-identifiers' variable specifies what to do."
3068 (let ((inhibit-point-motion-hooks t)
3069 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3070 (inhibit-read-only t))
3074 (article-narrow-to-head)
3075 (goto-char (point-min))
3076 (while (re-search-forward
3077 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3079 (delete-region (match-beginning 2) (match-end 0))
3080 (beginning-of-line))
3081 (when (re-search-forward
3082 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3083 (delete-region (match-beginning 1) (match-end 1))))))))
3085 (defun article-hide-pem (&optional arg)
3086 "Toggle hiding of any PEM headers and signatures in the current article.
3087 If given a negative prefix, always show; if given a positive prefix,
3089 (interactive (gnus-article-hidden-arg))
3090 (unless (gnus-article-check-hidden-text 'pem arg)
3092 (let ((inhibit-read-only t) end)
3093 (goto-char (point-min))
3094 ;; Hide the horrendously ugly "header".
3095 (when (and (search-forward
3096 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3098 (setq end (1+ (match-beginning 0))))
3099 (gnus-add-wash-type 'pem)
3100 (gnus-article-hide-text-type
3102 (if (search-forward "\n\n" nil t)
3106 ;; Hide the trailer as well
3107 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3109 (gnus-article-hide-text-type
3110 (match-beginning 0) (match-end 0) 'pem)))))))
3112 (defun article-strip-banner ()
3113 "Strip the banners specified by the `banner' group parameter and by
3114 `gnus-article-address-banner-alist'."
3118 (let ((inhibit-point-motion-hooks t))
3119 (when (gnus-parameter-banner gnus-newsgroup-name)
3120 (article-really-strip-banner
3121 (gnus-parameter-banner gnus-newsgroup-name)))
3122 (when gnus-article-address-banner-alist
3123 ;; Note that the From header is decoded here, so it is
3124 ;; required that the *-extract-address-components function
3125 ;; supports non-ASCII text.
3126 (let ((from (save-restriction
3128 (article-narrow-to-head)
3129 (mail-fetch-field "from"))))
3132 (cadr (funcall gnus-extract-address-components
3135 (dolist (pair gnus-article-address-banner-alist)
3136 (when (string-match (car pair) from)
3138 (article-really-strip-banner (cdr pair)))))))))))))
3140 (defun article-really-strip-banner (banner)
3141 "Strip the banner specified by the argument."
3144 (let ((inhibit-point-motion-hooks t)
3145 (gnus-signature-limit nil)
3146 (inhibit-read-only t))
3149 ((eq banner 'signature)
3150 (when (gnus-article-narrow-to-signature)
3153 (delete-region (point) (point-max))))
3155 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3156 (while (re-search-forward banner nil t)
3157 (delete-region (match-beginning 0) (match-end 0)))))
3159 (while (re-search-forward banner nil t)
3160 (delete-region (match-beginning 0) (match-end 0)))))))))
3162 (defun article-babel ()
3163 "Translate article using an online translation service."
3166 (gnus-with-article-buffer
3167 (when (article-goto-body)
3168 (let* ((start (point))
3170 (orig (buffer-substring start end))
3171 (trans (babel-as-string orig)))
3173 (narrow-to-region start end)
3174 (delete-region start end)
3177 (defun article-hide-signature (&optional arg)
3178 "Hide the signature in the current article.
3179 If given a negative prefix, always show; if given a positive prefix,
3181 (interactive (gnus-article-hidden-arg))
3182 (unless (gnus-article-check-hidden-text 'signature arg)
3185 (let ((inhibit-read-only t))
3186 (when (gnus-article-narrow-to-signature)
3187 (gnus-article-hide-text-type
3188 (point-min) (point-max) 'signature))))))
3189 (gnus-set-mode-line 'article))
3191 (defun article-strip-headers-in-body ()
3192 "Strip offensive headers from bodies."
3196 (let ((case-fold-search t))
3197 (when (looking-at "x-no-archive:")
3198 (gnus-delete-line)))))
3200 (defun article-strip-leading-blank-lines ()
3201 "Remove all blank lines from the beginning of the article."
3204 (let ((inhibit-point-motion-hooks t)
3205 (inhibit-read-only t))
3206 (when (article-goto-body)
3207 (while (and (not (eobp))
3208 (looking-at "[ \t]*$"))
3209 (gnus-delete-line))))))
3211 (defun article-narrow-to-head ()
3212 "Narrow the buffer to the head of the message.
3213 Point is left at the beginning of the narrowed-to region."
3215 (goto-char (point-min))
3217 ;; Absolutely no headers displayed.
3221 ((search-forward "\n\n" nil 1)
3223 ;; Nothing but headers.
3226 (goto-char (point-min)))
3228 (defun article-goto-body ()
3229 "Place point at the start of the body."
3230 (goto-char (point-min))
3232 ;; This variable is only bound when dealing with separate
3234 (article-goto-body-goes-to-point-min-p
3236 ((search-forward "\n\n" nil t)
3239 (goto-char (point-max))
3242 (defun article-strip-multiple-blank-lines ()
3243 "Replace consecutive blank lines with one empty line."
3246 (let ((inhibit-point-motion-hooks t)
3247 (inhibit-read-only t))
3248 ;; First make all blank lines empty.
3250 (while (re-search-forward "^[ \t]+$" nil t)
3251 (unless (gnus-annotation-in-region-p
3252 (match-beginning 0) (match-end 0))
3253 (replace-match "" nil t)))
3254 ;; Then replace multiple empty lines with a single empty line.
3256 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3257 (unless (gnus-annotation-in-region-p
3258 (match-beginning 0) (match-end 0))
3259 (delete-region (match-beginning 1) (match-end 1)))))))
3261 (defun article-strip-leading-space ()
3262 "Remove all white space from the beginning of the lines in the article."
3265 (let ((inhibit-point-motion-hooks t)
3266 (inhibit-read-only t))
3268 (while (re-search-forward "^[ \t]+" nil t)
3269 (replace-match "" t t)))))
3271 (defun article-strip-trailing-space ()
3272 "Remove all white space from the end of the lines in the article."
3275 (let ((inhibit-point-motion-hooks t)
3276 (inhibit-read-only t))
3278 (while (re-search-forward "[ \t]+$" nil t)
3279 (replace-match "" t t)))))
3281 (defun article-strip-blank-lines ()
3282 "Strip leading, trailing and multiple blank lines."
3284 (article-strip-leading-blank-lines)
3285 (article-remove-trailing-blank-lines)
3286 (article-strip-multiple-blank-lines))
3288 (defun article-strip-all-blank-lines ()
3289 "Strip all blank lines."
3292 (let ((inhibit-point-motion-hooks t)
3293 (inhibit-read-only t))
3295 (while (re-search-forward "^[ \t]*\n" nil t)
3296 (replace-match "" t t)))))
3298 (defun gnus-article-narrow-to-signature ()
3299 "Narrow to the signature; return t if a signature is found, else nil."
3300 (let ((inhibit-point-motion-hooks t))
3301 (when (gnus-article-search-signature)
3303 ;; Check whether we have some limits to what we consider
3304 ;; to be a signature.
3305 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3306 (list gnus-signature-limit)))
3308 (while (setq limit (pop limits))
3309 (if (or (and (integerp limit)
3310 (< (- (point-max) (point)) limit))
3312 (< (count-lines (point) (point-max)) limit))
3313 (and (functionp limit)
3315 (and (stringp limit)
3316 (not (re-search-forward limit nil t))))
3317 () ; This limit did not succeed.
3321 (narrow-to-region (point) (point-max))
3324 (defun gnus-article-search-signature ()
3325 "Search the current buffer for the signature separator.
3326 Put point at the beginning of the signature separator."
3327 (let ((cur (point)))
3328 (goto-char (point-max))
3329 (if (if (stringp gnus-signature-separator)
3330 (re-search-backward gnus-signature-separator nil t)
3331 (let ((seps gnus-signature-separator))
3333 (not (re-search-backward (car seps) nil t)))
3340 (defun gnus-article-hidden-arg ()
3341 "Return the current prefix arg as a number, or 0 if no prefix."
3342 (list (if current-prefix-arg
3343 (prefix-numeric-value current-prefix-arg)
3346 (defun gnus-article-check-hidden-text (type arg)
3347 "Return nil if hiding is necessary.
3348 Arg can be nil or a number. nil and positive means hide, negative
3349 means show, 0 means toggle."
3352 (let ((hide (gnus-article-hidden-text-p type)))
3358 (gnus-article-show-hidden-text type)
3361 (if (eq hide 'hidden)
3363 (gnus-article-show-hidden-text type)
3367 (defun gnus-article-hidden-text-p (type)
3368 "Say whether the current buffer contains hidden text of type TYPE."
3369 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3371 (not (get-text-property pos 'invisible))
3372 (not (get-text-property pos 'dummy-invisible)))
3374 (text-property-any (1+ pos) (point-max) 'article-type type)))
3379 (defun gnus-article-show-hidden-text (type &optional _dummy)
3380 "Show all hidden text of type TYPE.
3381 Originally it is hide instead of DUMMY."
3382 (let ((inhibit-read-only t)
3383 (inhibit-point-motion-hooks t))
3384 (gnus-remove-text-properties-when
3386 (point-min) (point-max)
3387 (cons 'article-type (cons type
3388 gnus-hidden-properties)))
3389 (gnus-delete-wash-type type)))
3391 (defconst article-time-units
3392 `((year . ,(* 365.25 24 60 60))
3393 (week . ,(* 7 24 60 60))
3394 (day . ,(* 24 60 60))
3398 "Mapping from time units to seconds.")
3400 (defun gnus-article-forward-header ()
3401 "Move point to the start of the next header.
3402 If the current header is a continuation header, this can be several
3407 (if (looking-at "[ \t]+[^ \t]")
3411 (defun article-treat-date ()
3412 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3413 (with-current-buffer gnus-summary-buffer
3414 gnus-article-date-headers)
3415 gnus-article-date-headers)
3418 (defun article-date-ut (&optional type _highlight date-position)
3419 "Convert DATE date to TYPE in the current article.
3420 The default type is `ut'. See `gnus-article-date-headers' for
3422 (interactive (list 'ut t))
3423 (let* ((case-fold-search t)
3424 (inhibit-read-only t)
3425 (inhibit-point-motion-hooks t)
3426 (visible-date (mail-fetch-field "Date"))
3427 pos date bface eface)
3431 (goto-char date-position)
3432 (setq date (get-text-property (point) 'original-date))
3433 (when (looking-at "[^:]+:[\t ]*")
3434 (setq bface (get-text-property (match-beginning 0) 'face)
3435 eface (get-text-property (match-end 0) 'face)))
3436 (delete-region (point)
3438 (gnus-article-forward-header)
3440 (article-transform-date date type bface eface))
3443 (goto-char (point-min))
3444 (while (or (get-text-property (setq pos (point)) 'original-date)
3445 (and (setq pos (next-single-property-change
3446 (point) 'original-date))
3448 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3449 (1+ (match-beginning 0))
3451 (while (setq pos (text-property-not-all pos (point-max)
3452 'gnus-date-type nil))
3453 (setq date (get-text-property pos 'original-date))
3455 (when (looking-at "[^:]+:[\t ]*")
3456 (setq bface (get-text-property (match-beginning 0) 'face)
3457 eface (get-text-property (match-end 0) 'face)))
3458 (delete-region pos (or (text-property-any pos (point-max)
3459 'gnus-date-type nil)
3461 (unless date ;; the 1st time
3462 (goto-char (point-min))
3463 (while (re-search-forward "^Date:[\t ]*" nil t)
3464 (setq date (get-text-property (match-beginning 0)
3466 bface (get-text-property (match-beginning 0) 'face)
3467 eface (get-text-property (match-end 0) 'face))
3468 (delete-region (point-at-bol) (progn
3469 (gnus-article-forward-header)
3471 (when (and (not date)
3473 (setq date visible-date))
3475 (article-transform-date date type bface eface))
3476 (goto-char (point-max))
3479 (defun article-transform-date (date type bface eface)
3480 (dolist (this-type (cond
3490 (add-text-properties
3493 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3495 (list 'original-date date 'gnus-date-type this-type))))
3498 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3499 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3500 (when (match-beginning 2)
3501 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3502 (while (and (zerop (forward-line 1))
3503 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3504 (when (match-beginning 1)
3505 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3507 (defun article-make-date-line (date type)
3508 "Return a DATE line of TYPE."
3509 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3511 (error "Unknown conversion type: %s" type))
3513 (let ((time (ignore-errors (date-to-time date))))
3515 ;; Convert to the local timezone.
3517 (concat "Date: " (message-make-date time)))
3518 ;; Convert to Universal Time.
3523 (let* ((e (parse-time-string date))
3524 (tm (apply 'encode-time e))
3526 (ls (- (cadr tm) (car (current-time-zone time)))))
3527 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3528 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3532 ;; Get the original date from the article.
3533 ((eq type 'original)
3534 (concat "Date: " (if (string-match "\n+$" date)
3535 (substring date 0 (match-beginning 0))
3537 ;; Let the user define the format.
3538 ((eq type 'user-defined)
3539 (let ((format (or (condition-case nil
3540 (with-current-buffer gnus-summary-buffer
3541 gnus-article-time-format)
3543 gnus-article-time-format)))
3544 (if (functionp format)
3545 (funcall format time)
3546 (concat "Date: " (format-time-string format time)))))
3549 (let ((tz (car (current-time-zone time))))
3552 (format-time-string "%Y%m%dT%H%M%S" time)
3553 (format "%s%02d%02d"
3554 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3555 (/ (% (abs tz) 3600) 60)))))
3556 ;; Do a lapsed format.
3558 (concat "Date: " (article-lapsed-string time)))
3559 ;; A combined date/lapsed format.
3560 ((eq type 'combined-lapsed)
3561 (let ((date-string (article-make-date-line date 'original))
3567 (concat " (" (article-lapsed-string time segments) ")"))
3568 (> (+ (length date-string)
3569 (length lapsed-string))
3572 (setq segments (1- segments)))
3574 (concat date-string lapsed-string)
3576 ;; Display the date in proper English
3578 (let ((dtime (decode-time time)))
3581 (number-to-string (nth 3 dtime))
3582 (let ((digit (% (nth 3 dtime) 10)))
3584 ((memq (nth 3 dtime) '(11 12 13)) "th")
3590 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3592 (number-to-string (nth 5 dtime))
3594 (format "%02d" (nth 2 dtime))
3596 (format "%02d" (nth 1 dtime)))))))
3598 (format "Date: %s (from Gnus)" date))))
3600 (defun article-lapsed-string (time &optional max-segments)
3601 ;; If the date is seriously mangled, the timezone functions are
3602 ;; liable to bug out, so we ignore all errors.
3603 (let* ((now (current-time))
3604 (real-time (subtract-time now time))
3605 (real-sec (and real-time
3606 (+ (* (float (car real-time)) 65536)
3608 (sec (and real-time (abs real-sec)))
3611 (unless max-segments
3612 (setq max-segments (length article-time-units)))
3620 ;; This is a bit convoluted, but basically we go
3621 ;; through the time units for years, weeks, etc,
3622 ;; and divide things to see whether that results
3623 ;; in positive answers.
3626 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3627 (>= segments max-segments))
3628 ;; The (remaining) seconds are too few to
3629 ;; be divided into this time unit.
3631 ;; It's big enough, so we output it.
3632 (setq sec (- sec (* num (cdr unit))))
3634 (concat (if prev ", " "") (int-to-string
3636 " " (symbol-name (car unit))
3637 (if (> num 1) "s" ""))
3639 segments (1+ segments)))))
3640 article-time-units "")
3641 ;; If dates are odd, then it might appear like the
3642 ;; article was sent in the future.
3645 " in the future"))))))
3647 (defun article-date-local (&optional highlight)
3648 "Convert the current article date to the local timezone."
3649 (interactive (list t))
3650 (article-date-ut 'local highlight))
3652 (defun article-date-english (&optional highlight)
3653 "Convert the current article date to something that is proper English."
3654 (interactive (list t))
3655 (article-date-ut 'english highlight))
3657 (defun article-date-original (&optional highlight)
3658 "Convert the current article date to what it was originally.
3659 This is only useful if you have used some other date conversion
3660 function and want to see what the date was before converting."
3661 (interactive (list t))
3662 (article-date-ut 'original highlight))
3664 (defun article-date-lapsed (&optional highlight)
3665 "Convert the current article date to time lapsed since it was sent."
3666 (interactive (list t))
3667 (article-date-ut 'lapsed highlight))
3669 (defun article-date-combined-lapsed (&optional highlight)
3670 "Convert the current article date to time lapsed since it was sent."
3671 (interactive (list t))
3672 (article-date-ut 'combined-lapsed highlight))
3674 (defun article-update-date-lapsed ()
3675 "Function to be run from a timer to update the lapsed time line."
3677 (let ((buffer (current-buffer)))
3681 (set-buffer (window-buffer w))
3682 (when (derived-mode-p 'gnus-article-mode)
3683 (let ((old-line (count-lines (point-min) (point)))
3684 (old-column (- (point) (line-beginning-position)))
3685 (window-start (window-start w))
3688 (while (setq pos (text-property-not-all pos (point-max)
3689 'gnus-date-type nil))
3690 (setq next (or (next-single-property-change pos
3693 (setq type (get-text-property pos 'gnus-date-type))
3694 (when (memq type '(lapsed combined-lapsed user-defined))
3695 (article-date-ut type t pos)
3696 (setq end (or (next-single-property-change pos
3700 (if (/= window-start next)
3701 (setq window-start nil)
3702 (set-window-start w end)))
3705 (goto-char (point-min))
3706 (when (> old-column 0)
3707 (setq old-line (1- old-line)))
3708 (forward-line old-line)
3710 (when (> (current-column) old-column)
3712 (forward-char old-column)))))
3714 (set-buffer buffer))))
3716 (defun gnus-start-date-timer (&optional n)
3717 "Start a timer to update the Date headers in the article buffers.
3718 The numerical prefix says how frequently (in seconds) the function
3723 (gnus-stop-date-timer)
3724 (setq article-lapsed-timer
3725 (run-at-time 1 n 'article-update-date-lapsed)))
3727 (defun gnus-stop-date-timer ()
3728 "Stop the Date timer."
3730 (when article-lapsed-timer
3731 (nnheader-cancel-timer article-lapsed-timer)
3732 (setq article-lapsed-timer nil)))
3734 (defun article-date-user (&optional highlight)
3735 "Convert the current article date to the user-defined format.
3736 This format is defined by the `gnus-article-time-format' variable."
3737 (interactive (list t))
3738 (article-date-ut 'user highlight))
3740 (defun article-date-iso8601 (&optional highlight)
3741 "Convert the current article date to ISO8601."
3742 (interactive (list t))
3743 (article-date-ut 'iso8601 highlight))
3745 (defmacro gnus-article-save-original-date (&rest forms)
3746 "Save the original date as a text property and evaluate FORMS."
3747 `(let* ((case-fold-search t)
3749 (goto-char (point-min))
3750 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3753 (date (when (and start
3754 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3756 (buffer-substring-no-properties start
3757 (match-beginning 0)))))
3758 (goto-char (point-max))
3759 (skip-chars-backward "\n")
3760 (put-text-property (point-min) (point) 'original-date date)
3762 (goto-char (point-max))
3763 (skip-chars-backward "\n")
3764 (put-text-property (point-min) (point) 'original-date date)))
3766 ;; (defun article-show-all ()
3767 ;; "Show all hidden text in the article buffer."
3770 ;; (let ((inhibit-read-only t))
3771 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3773 (defun article-remove-leading-whitespace ()
3774 "Remove excessive whitespace from all headers."
3778 (let ((inhibit-read-only t))
3779 (article-narrow-to-head)
3780 (goto-char (point-min))
3781 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3782 (delete-region (match-beginning 1) (match-end 1)))))))
3784 (defun article-emphasize (&optional arg)
3785 "Emphasize text according to `gnus-emphasis-alist'."
3786 (interactive (gnus-article-hidden-arg))
3787 (unless (gnus-article-check-hidden-text 'emphasis arg)
3791 (with-current-buffer gnus-summary-buffer
3792 gnus-article-emphasis-alist)
3794 gnus-emphasis-alist))
3795 (inhibit-read-only t)
3796 (props (append '(article-type emphasis)
3797 gnus-hidden-properties))
3798 regexp elem beg invisible visible face)
3801 (while (setq elem (pop alist))
3803 (setq regexp (car elem)
3804 invisible (nth 1 elem)
3805 visible (nth 2 elem)
3807 (while (re-search-forward regexp nil t)
3808 (when (and (match-beginning visible) (match-beginning invisible))
3809 (gnus-article-hide-text
3810 (match-beginning invisible) (match-end invisible) props)
3811 (gnus-article-unhide-text-type
3812 (match-beginning visible) (match-end visible) 'emphasis)
3813 (gnus-put-overlay-excluding-newlines
3814 (match-beginning visible) (match-end visible) 'face face)
3815 (gnus-add-wash-type 'emphasis)
3816 (goto-char (match-end invisible)))))))))
3818 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3819 "Setup newsgroup emphasis alist."
3820 (unless gnus-article-emphasis-alist
3821 (let ((name (and gnus-newsgroup-name
3822 (gnus-group-real-name gnus-newsgroup-name))))
3823 (make-local-variable 'gnus-article-emphasis-alist)
3824 (setq gnus-article-emphasis-alist
3826 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3827 (while (setq elem (pop alist))
3828 (when (and name (string-match (car elem) name))
3830 highlight (copy-sequence (cdr elem)))))
3832 (copy-sequence highlight-words)
3833 (if gnus-newsgroup-name
3834 (copy-sequence (gnus-group-find-parameter
3835 gnus-newsgroup-name 'highlight-words t)))
3836 gnus-emphasis-alist)))))
3838 (defvar gnus-summary-article-menu)
3839 (defvar gnus-summary-post-menu)
3841 ;;; Saving functions.
3843 (defun gnus-article-save (save-buffer file &optional num)
3844 "Save the currently selected article."
3845 (when (or (get gnus-default-article-saver :headers)
3846 (not gnus-save-all-headers))
3847 ;; Remove headers according to `gnus-saved-headers' or the value
3848 ;; of the `:headers' property that the saver function might have.
3849 (let ((gnus-visible-headers
3850 (or (symbol-value (get gnus-default-article-saver :headers))
3851 gnus-saved-headers gnus-visible-headers))
3852 ;; Ignore group parameter. See `article-hide-headers'.
3853 (gnus-summary-buffer nil))
3854 (with-current-buffer save-buffer
3855 (article-hide-headers 1 t))))
3856 (save-window-excursion
3857 (if (not gnus-default-article-saver)
3858 (error "No default saver is defined")
3859 ;; !!! Magic! The saving functions all save
3860 ;; `gnus-save-article-buffer' (or so they think), but we
3861 ;; bind that variable to our save-buffer.
3862 (set-buffer gnus-article-buffer)
3863 (let* ((gnus-save-article-buffer save-buffer)
3866 ((not gnus-prompt-before-saving) 'default)
3867 ((eq gnus-prompt-before-saving 'always) nil)
3869 (gnus-number-of-articles-to-be-saved
3870 (when (eq gnus-prompt-before-saving t)
3872 (set-buffer gnus-article-current-summary)
3873 (funcall gnus-default-article-saver filename)))))
3875 (defun gnus-read-save-file-name (prompt &optional filename
3876 function group headers variable
3879 (funcall function group headers (symbol-value variable)))
3884 ((eq filename 'default)
3890 (when (symbol-value dir-var)
3891 (setq default-name (expand-file-name
3892 (file-name-nondirectory default-name)
3893 (symbol-value dir-var))))
3894 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3897 (if (and gnus-number-of-articles-to-be-saved
3898 (> gnus-number-of-articles-to-be-saved 1))
3899 (format "these %d articles"
3900 gnus-number-of-articles-to-be-saved)
3903 ;; Let the split methods have their say.
3905 ;; No split name was found.
3908 (concat prompt " (default "
3909 (file-name-nondirectory default-name) "): ")
3910 (file-name-directory default-name)
3912 ;; A single group name is returned.
3913 ((stringp split-name)
3915 (funcall function split-name headers
3916 (symbol-value variable)))
3918 (concat prompt " (default "
3919 (file-name-nondirectory default-name) "): ")
3920 (file-name-directory default-name)
3922 ;; A single split name was found
3923 ((= 1 (length split-name))
3924 (let* ((name (expand-file-name
3926 gnus-article-save-directory))
3927 (dir (cond ((file-directory-p name)
3928 (file-name-as-directory name))
3929 ((file-exists-p name) name)
3930 (t gnus-article-save-directory))))
3932 (concat prompt " (default " name "): ")
3934 ;; A list of splits was found.
3936 (setq split-name (nreverse split-name))
3938 (let ((file-name-history
3939 (nconc split-name file-name-history)))
3943 (concat prompt " (`M-p' for defaults): ")
3944 gnus-article-save-directory
3946 gnus-article-save-directory)))
3947 (car (push result file-name-history)))))))
3948 ;; Create the directory.
3949 (gnus-make-directory (file-name-directory file))
3950 ;; If we have read a directory, we append the default file name.
3951 (when (file-directory-p file)
3952 (setq file (expand-file-name (file-name-nondirectory
3954 (file-name-as-directory file))))
3955 ;; Possibly translate some characters.
3956 (nnheader-translate-file-chars file))))))
3957 (gnus-make-directory (file-name-directory result))
3959 (set variable result))
3961 (set dir-var (file-name-directory result)))
3964 (defun gnus-article-archive-name (_group)
3965 "Return the first instance of an \"Archive-name\" in the current buffer."
3966 (let ((case-fold-search t))
3967 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3968 (nnheader-concat gnus-article-save-directory
3969 (match-string 1)))))
3971 (defun gnus-article-nndoc-name (group)
3972 "If GROUP is an nndoc group, return the name of the parent group."
3973 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3974 (gnus-group-get-parameter group 'save-article-group)))
3976 (defun gnus-summary-save-in-rmail (&optional filename)
3977 "Append this article to Rmail file.
3978 Optional argument FILENAME specifies file name.
3979 Directory to save to is default to `gnus-article-save-directory'."
3980 (setq filename (gnus-read-save-file-name
3981 "Save %s in rmail file" filename
3982 gnus-rmail-save-name gnus-newsgroup-name
3983 gnus-current-headers 'gnus-newsgroup-last-rmail))
3984 (with-current-buffer gnus-save-article-buffer
3988 ;; Note that unlike gnus-summary-save-in-mail, there is no
3989 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3991 (gnus-output-to-rmail filename))))
3994 (defun gnus-summary-save-in-mail (&optional filename)
3995 "Append this article to Unix mail file.
3996 Optional argument FILENAME specifies file name.
3997 Directory to save to is default to `gnus-article-save-directory'."
3998 (setq filename (gnus-read-save-file-name
3999 "Save %s in Unix mail file" filename
4000 gnus-mail-save-name gnus-newsgroup-name
4001 gnus-current-headers 'gnus-newsgroup-last-mail))
4002 (with-current-buffer gnus-save-article-buffer
4006 (if (and (file-readable-p filename)
4007 (file-regular-p filename)
4008 (mail-file-babyl-p filename))
4009 (gnus-output-to-rmail filename)
4010 (gnus-output-to-mail filename)))))
4013 (put 'gnus-summary-save-in-file :decode t)
4014 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4015 (defun gnus-summary-save-in-file (&optional filename overwrite)
4016 "Append this article to file.
4017 Optional argument FILENAME specifies file name.
4018 Directory to save to is default to `gnus-article-save-directory'."
4019 (setq filename (gnus-read-save-file-name
4020 "Save %s in file" filename
4021 gnus-file-save-name gnus-newsgroup-name
4022 gnus-current-headers 'gnus-newsgroup-last-file))
4023 (with-current-buffer gnus-save-article-buffer
4027 (when (and overwrite
4028 (file-exists-p filename))
4029 (delete-file filename))
4030 (gnus-output-to-file filename))))
4033 (put 'gnus-summary-write-to-file :decode t)
4034 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4035 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4036 (defun gnus-summary-write-to-file (&optional filename)
4037 "Write this article to a file, overwriting it if the file exists.
4038 Optional argument FILENAME specifies file name.
4039 The directory to save in defaults to `gnus-article-save-directory'."
4040 (setq filename (gnus-read-save-file-name
4041 "Save %s in file" filename
4042 gnus-file-save-name gnus-newsgroup-name
4043 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4044 (gnus-summary-save-in-file filename t))
4046 (put 'gnus-summary-save-body-in-file :decode t)
4047 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4048 "Append this article body to a file.
4049 Optional argument FILENAME specifies file name.
4050 The directory to save in defaults to `gnus-article-save-directory'."
4051 (setq filename (gnus-read-save-file-name
4052 "Save %s body in file" filename
4053 gnus-file-save-name gnus-newsgroup-name
4054 gnus-current-headers 'gnus-newsgroup-last-file))
4055 (with-current-buffer gnus-save-article-buffer
4059 (when (article-goto-body)
4060 (narrow-to-region (point) (point-max)))
4061 (when (and overwrite
4062 (file-exists-p filename))
4063 (delete-file filename))
4064 (gnus-output-to-file filename))))
4067 (put 'gnus-summary-write-body-to-file :decode t)
4068 (put 'gnus-summary-write-body-to-file
4069 :function 'gnus-summary-save-body-in-file)
4070 (defun gnus-summary-write-body-to-file (&optional filename)
4071 "Write this article body to a file, overwriting it if the file exists.
4072 Optional argument FILENAME specifies file name.
4073 The directory to save in defaults to `gnus-article-save-directory'."
4074 (setq filename (gnus-read-save-file-name
4075 "Save %s body in file" filename
4076 gnus-file-save-name gnus-newsgroup-name
4077 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4078 (gnus-summary-save-body-in-file filename t))
4080 (put 'gnus-summary-save-in-pipe :decode t)
4081 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4082 (defun gnus-summary-save-in-pipe (&optional command raw)
4083 "Pipe this article to subprocess COMMAND.
4084 Valid values for COMMAND include:
4086 The executable command name and possibly arguments.
4088 You will be prompted for the command in the minibuffer.
4089 the symbol `default'
4090 It will be replaced with the command which the variable
4091 `gnus-summary-pipe-output-default-command' holds or the command
4092 last used for saving.
4093 Non-nil value for RAW overrides `:decode' and `:headers' properties
4094 and the raw article including all headers will be piped."
4095 (let ((article (gnus-summary-article-number))
4097 (get 'gnus-summary-save-in-pipe :decode)))
4098 save-buffer default)
4100 (if (vectorp (gnus-summary-article-header article))
4101 (save-current-buffer
4102 (gnus-summary-select-article decode decode nil article)
4103 (insert-buffer-substring
4107 gnus-original-article-buffer)
4109 (nnheader-set-temp-buffer " *Gnus Save*"))))
4110 ;; Remove unwanted headers.
4111 (when (and (not raw)
4112 (or (get 'gnus-summary-save-in-pipe :headers)
4113 (not gnus-save-all-headers)))
4114 (let ((gnus-visible-headers
4115 (or (symbol-value (get 'gnus-summary-save-in-pipe
4117 gnus-saved-headers gnus-visible-headers))
4118 (gnus-summary-buffer nil))
4119 (article-hide-headers 1 t))))
4120 (error "%d is not a real article" article))
4121 (error "No article to pipe"))
4122 (setq default (or gnus-summary-pipe-output-default-command
4123 gnus-last-shell-command))
4124 (unless (stringp command)
4126 (if (and (eq command 'default) default)
4128 (read-shell-command "Shell command on this article: " default))))
4129 (when (string-equal command "")
4131 (setq command default)
4132 (error "A command is required")))
4133 (with-current-buffer save-buffer
4136 (shell-command-on-region (point-min) (point-max) command nil)))
4137 (gnus-kill-buffer save-buffer))
4138 (setq gnus-summary-pipe-output-default-command command))
4140 (defun gnus-summary-pipe-to-muttprint (&optional command)
4141 "Pipe this article to muttprint."
4142 (unless (stringp command)
4143 (setq command (read-string
4144 "Print using command: " gnus-summary-muttprint-program
4145 nil gnus-summary-muttprint-program)))
4146 (let ((gnus-summary-pipe-output-default-command
4147 gnus-summary-pipe-output-default-command))
4148 (gnus-summary-save-in-pipe command))
4149 (setq gnus-summary-muttprint-program command))
4151 ;;; Article file names when saving.
4153 (defun gnus-capitalize-newsgroup (newsgroup)
4154 "Capitalize NEWSGROUP name."
4155 (when (not (zerop (length newsgroup)))
4156 (concat (char-to-string (upcase (aref newsgroup 0)))
4157 (substring newsgroup 1))))
4159 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4160 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4161 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4162 Otherwise, it is like ~/News/news/group/num."
4165 (concat (if (gnus-use-long-file-name 'not-save)
4166 (gnus-capitalize-newsgroup newsgroup)
4167 (gnus-newsgroup-directory-form newsgroup))
4168 "/" (int-to-string (mail-header-number headers)))
4169 gnus-article-save-directory)))
4171 (string-equal (file-name-directory default)
4172 (file-name-directory last-file))
4173 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4175 (or last-file default))))
4177 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4178 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4179 If variable `gnus-use-long-file-name' is non-nil, it is
4180 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4183 (concat (if (gnus-use-long-file-name 'not-save)
4185 (gnus-newsgroup-directory-form newsgroup))
4186 "/" (int-to-string (mail-header-number headers)))
4187 gnus-article-save-directory)))
4189 (string-equal (file-name-directory default)
4190 (file-name-directory last-file))
4191 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4193 (or last-file default))))
4195 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4196 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4197 If variable `gnus-use-long-file-name' is non-nil, it is
4198 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4201 (if (gnus-use-long-file-name 'not-save)
4204 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4206 gnus-article-save-directory)))
4208 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4209 "Generate file name from sender."
4210 (let ((from (mail-header-from headers)))
4212 (if (and from (string-match "\\([^ <]+\\)@" from))
4213 (match-string 1 from)
4215 gnus-article-save-directory)))
4217 (defun article-verify-x-pgp-sig ()
4219 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4221 (if (gnus-buffer-live-p gnus-original-article-buffer)
4222 (let ((sig (with-current-buffer gnus-original-article-buffer
4223 (gnus-fetch-field "X-PGP-Sig")))
4227 (mml2015-clear-verify-function))
4229 (insert-buffer-substring gnus-original-article-buffer)
4230 (setq items (split-string sig))
4231 (message-narrow-to-head)
4232 (let ((inhibit-point-motion-hooks t)
4233 (case-fold-search t))
4234 ;; Don't verify multiple headers.
4235 (setq headers (mapconcat (lambda (header)
4237 (mail-fetch-field header)
4239 (split-string (nth 1 items) ",") "")))
4240 (delete-region (point-min) (point-max))
4241 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4242 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4247 (if (looking-at "^-")
4250 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4251 (insert "Version: " (car items) "\n\n")
4252 (insert (mapconcat 'identity (cddr items) "\n"))
4253 (insert "\n-----END PGP SIGNATURE-----\n")
4254 (let ((mm-security-handle (list (format "multipart/signed"))))
4255 (mml2015-clean-buffer)
4256 (let ((coding-system-for-write (or gnus-newsgroup-charset
4258 (funcall (mml2015-clear-verify-function)))
4260 (or (mm-handle-multipart-ctl-parameter
4261 mm-security-handle 'gnus-details)
4262 (mm-handle-multipart-ctl-parameter
4263 mm-security-handle 'gnus-info)))))
4265 (let ((inhibit-read-only t) bface eface)
4267 (message-narrow-to-head)
4268 (goto-char (point-max))
4270 (setq bface (get-text-property (point-at-bol) 'face)
4271 eface (get-text-property (1- (point-at-eol)) 'face))
4272 (message-remove-header "X-Gnus-PGP-Verify")
4273 (if (re-search-forward "^X-PGP-Sig:" nil t)
4275 (goto-char (point-max)))
4276 (narrow-to-region (point) (point))
4277 (insert "X-Gnus-PGP-Verify: " info "\n")
4278 (goto-char (point-min))
4281 (if (not (looking-at "^[ \t]"))
4285 (goto-char (point-min))
4286 (when (looking-at "\\([^:]+\\): *")
4287 (put-text-property (match-beginning 1) (1+ (match-end 1))
4289 (put-text-property (match-end 0) (point-max)
4290 'face eface)))))))))
4292 (defun article-verify-cancel-lock ()
4293 "Verify Cancel-Lock header."
4295 (if (gnus-buffer-live-p gnus-original-article-buffer)
4296 (canlock-verify gnus-original-article-buffer)))
4303 (setq afunc (car func)
4306 gfunc (intern (format "gnus-%s" func))))
4308 (when (fboundp afunc)
4309 `(lambda (&optional interactive &rest args)
4310 ,(documentation afunc t)
4311 (interactive (list t))
4312 (with-current-buffer gnus-article-buffer
4314 (call-interactively ',afunc)
4315 (apply ',afunc args))))))))
4316 '(article-hide-headers
4317 article-verify-x-pgp-sig
4318 article-verify-cancel-lock
4319 article-hide-boring-headers
4320 article-treat-overstrike
4321 article-treat-ansi-sequences
4322 article-fill-long-lines
4323 article-capitalize-sentences
4325 article-remove-leading-whitespace
4326 article-display-x-face
4327 article-display-face
4328 article-de-quoted-unreadable
4329 article-de-base64-unreadable
4332 article-unsplit-urls
4333 article-hide-list-identifiers
4334 article-strip-banner
4337 article-hide-signature
4338 article-strip-headers-in-body
4339 article-remove-trailing-blank-lines
4340 article-strip-leading-blank-lines
4341 article-strip-multiple-blank-lines
4342 article-strip-leading-space
4343 article-strip-trailing-space
4344 article-strip-blank-lines
4345 article-strip-all-blank-lines
4347 article-date-english
4348 article-date-iso8601
4349 article-date-original
4352 article-decode-mime-words
4353 article-decode-charset
4354 article-decode-encoded-words
4357 article-date-combined-lapsed
4359 article-treat-dumbquotes
4360 article-treat-non-ascii
4361 article-normalize-headers
4362 ;;(article-show-all . gnus-article-show-all-headers)
4366 ;;; Gnus article mode
4369 (put 'gnus-article-mode 'mode-class 'special)
4371 (set-keymap-parent gnus-article-mode-map widget-keymap)
4373 (gnus-define-keys gnus-article-mode-map
4374 " " gnus-article-goto-next-page
4375 [?\S-\ ] gnus-article-goto-prev-page
4376 "\177" gnus-article-goto-prev-page
4377 [delete] gnus-article-goto-prev-page
4378 "\C-c^" gnus-article-refer-article
4379 "h" gnus-article-show-summary
4380 "s" gnus-article-show-summary
4381 "\C-c\C-m" gnus-article-mail
4382 "?" gnus-article-describe-briefly
4383 "<" beginning-of-buffer
4385 "\C-c\C-i" gnus-info-find-node
4387 "R" gnus-article-reply-with-original
4388 "F" gnus-article-followup-with-original
4389 "\C-hk" gnus-article-describe-key
4390 "\C-hc" gnus-article-describe-key-briefly
4391 "\C-hb" gnus-article-describe-bindings
4393 "e" gnus-article-read-summary-keys
4394 "\C-d" gnus-article-read-summary-keys
4395 "\M-*" gnus-article-read-summary-keys
4396 "\M-#" gnus-article-read-summary-keys
4397 "\M-^" gnus-article-read-summary-keys
4398 "\M-g" gnus-article-read-summary-keys)
4400 (substitute-key-definition
4401 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4403 (defvar gnus-article-send-map)
4404 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4405 "W" gnus-article-wide-reply-with-original
4406 [t] 'gnus-article-read-summary-send-keys)
4408 (defun gnus-article-make-menu-bar ()
4409 (unless (boundp 'gnus-article-commands-menu)
4410 (gnus-summary-make-menu-bar))
4411 (unless (boundp 'gnus-article-article-menu)
4413 gnus-article-article-menu gnus-article-mode-map ""
4415 ["Scroll forwards" gnus-article-goto-next-page t]
4416 ["Scroll backwards" gnus-article-goto-prev-page t]
4417 ["Show summary" gnus-article-show-summary t]
4418 ["Fetch Message-ID at point" gnus-article-refer-article t]
4419 ["Mail to address at point" gnus-article-mail t]
4420 ["Send a bug report" gnus-bug t]))
4423 gnus-article-treatment-menu gnus-article-mode-map ""
4424 ;; Fixme: this should use :active (and maybe :visible).
4426 ["Hide headers" gnus-article-hide-headers t]
4427 ["Hide signature" gnus-article-hide-signature t]
4428 ["Hide citation" gnus-article-hide-citation t]
4429 ["Treat overstrike" gnus-article-treat-overstrike t]
4430 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4431 ["Remove carriage return" gnus-article-remove-cr t]
4432 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4433 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4434 ["Remove base64" gnus-article-de-base64-unreadable t]
4435 ["Treat html" gnus-article-wash-html t]
4436 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4437 ["Decode HZ" gnus-article-decode-HZ t]))
4439 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4441 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4443 (gnus-run-hooks 'gnus-article-menu-hook)))
4445 (defvar bookmark-make-record-function)
4446 (defvar shr-put-image-function)
4448 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4449 "Major mode for displaying an article.
4451 All normal editing commands are switched off.
4453 The following commands are available in addition to all summary mode
4455 \\<gnus-article-mode-map>
4456 \\[gnus-article-next-page]\t Scroll the article one page forwards
4457 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4458 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4459 \\[gnus-article-show-summary]\t Display the summary buffer
4460 \\[gnus-article-mail]\t Send a reply to the address near point
4461 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4462 \\[gnus-info-find-node]\t Go to the Gnus info node"
4463 (gnus-simplify-mode-line)
4464 (make-local-variable 'minor-mode-alist)
4465 (when (gnus-visual-p 'article-menu 'menu)
4466 (gnus-article-make-menu-bar)
4467 (when gnus-summary-tool-bar-map
4468 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4469 (gnus-update-format-specifications nil 'article-mode)
4470 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4471 (set (make-local-variable 'gnus-page-broken) nil)
4472 (make-local-variable 'gnus-article-current-summary)
4473 (make-local-variable 'gnus-article-mime-handles)
4474 (make-local-variable 'gnus-article-decoded-p)
4475 (make-local-variable 'gnus-article-mime-handle-alist)
4476 (make-local-variable 'gnus-article-wash-types)
4477 (make-local-variable 'gnus-article-image-alist)
4478 (make-local-variable 'gnus-article-charset)
4479 (make-local-variable 'gnus-article-ignored-charsets)
4480 (set (make-local-variable 'bookmark-make-record-function)
4481 'gnus-summary-bookmark-make-record)
4482 ;; Prevent Emacs from displaying non-break space with
4483 ;; `nobreak-space' face.
4484 (set (make-local-variable 'nobreak-char-display) nil)
4485 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4486 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4487 (setq cursor-in-non-selected-windows nil)
4488 (gnus-set-default-directory)
4489 (buffer-disable-undo)
4490 (setq buffer-read-only t
4491 show-trailing-whitespace nil)
4492 (mm-enable-multibyte))
4494 (defun gnus-article-setup-buffer ()
4495 "Initialize the article buffer."
4496 (let* ((name (if gnus-single-article-buffer "*Article*"
4498 (gnus-group-decoded-name gnus-newsgroup-name)
4501 (progn (string-match "\\*Article" name)
4502 (concat " *Original Article"
4503 (substring name (match-end 0))))))
4504 (setq gnus-article-buffer name)
4505 (setq gnus-original-article-buffer original)
4506 (setq gnus-article-mime-handle-alist nil)
4507 (with-current-buffer gnus-summary-buffer
4508 ;; This might be a variable local to the summary buffer.
4509 (unless gnus-single-article-buffer
4510 (setq gnus-article-buffer name)
4511 (setq gnus-original-article-buffer original)
4512 (gnus-set-global-variables)))
4513 (gnus-article-setup-highlight-words)
4514 ;; Init original article buffer.
4515 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4516 (mm-enable-multibyte)
4517 (setq major-mode 'gnus-original-article-mode)
4518 (make-local-variable 'gnus-original-article))
4519 (if (and (get-buffer name)
4520 (with-current-buffer name
4521 (if gnus-article-edit-mode
4522 (if (y-or-n-p "Article mode edit in progress; discard? ")
4524 (set-buffer-modified-p nil)
4525 (gnus-kill-buffer name)
4528 (error "Action aborted"))
4530 (let ((summary gnus-summary-buffer))
4531 (with-current-buffer name
4532 (set (make-local-variable 'gnus-article-edit-mode) nil)
4533 (gnus-article-stop-animations)
4534 (when gnus-article-mime-handles
4535 (mm-destroy-parts gnus-article-mime-handles)
4536 (setq gnus-article-mime-handles nil))
4537 ;; Set it to nil in article-buffer!
4538 (setq gnus-article-mime-handle-alist nil)
4539 (buffer-disable-undo)
4540 (setq buffer-read-only t)
4541 (unless (derived-mode-p 'gnus-article-mode)
4542 (gnus-article-mode))
4543 (set (make-local-variable 'gnus-summary-buffer) summary)
4544 (setq truncate-lines gnus-article-truncate-lines)
4546 (let ((summary gnus-summary-buffer))
4547 (with-current-buffer (gnus-get-buffer-create name)
4549 (setq truncate-lines gnus-article-truncate-lines)
4550 (set (make-local-variable 'gnus-summary-buffer) summary)
4551 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4552 (when article-lapsed-timer
4553 (gnus-stop-date-timer))
4554 (when gnus-article-update-date-headers
4555 (gnus-start-date-timer gnus-article-update-date-headers))
4556 (current-buffer))))))
4558 (defun gnus-article-stop-animations ()
4559 (dolist (timer (and (boundp 'timer-list)
4561 (when (eq (timer--function timer) 'image-animate-timeout)
4562 (cancel-timer timer))))
4564 (defun gnus-stop-downloads ()
4565 (when (boundp 'url-queue)
4566 (set (intern "url-queue" obarray) nil)))
4568 ;; Set article window start at LINE, where LINE is the number of lines
4569 ;; from the head of the article.
4570 (defun gnus-article-set-window-start (&optional line)
4571 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4572 (when article-window
4575 (with-current-buffer gnus-article-buffer
4576 (goto-char (point-min))
4579 (gnus-message 6 "Moved to bookmark")
4580 (search-forward "\n\n" nil t)
4584 (defvar gnus-tmp-internal-hook)
4586 (defun gnus-article-prepare (article &optional all-headers _header)
4587 "Prepare ARTICLE in article mode buffer.
4588 ARTICLE should either be an article number or a Message-ID.
4589 If ARTICLE is an id, HEADER should be the article headers.
4590 If ALL-HEADERS is non-nil, no headers are hidden."
4591 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4592 ;; Make sure we start in a summary buffer.
4593 (unless (derived-mode-p 'gnus-summary-mode)
4594 (set-buffer gnus-summary-buffer))
4595 (setq gnus-summary-buffer (current-buffer))
4596 (let* ((summary-buffer (current-buffer))
4597 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4598 (group gnus-newsgroup-name)
4601 (gnus-article-setup-buffer)
4602 (set-buffer gnus-article-buffer)
4603 ;; Deactivate active regions.
4604 (when transient-mark-mode
4605 (setq mark-active nil))
4606 (if (not (setq result (let ((inhibit-read-only t))
4607 (gnus-request-article-this-buffer
4609 ;; There is no such article.
4611 (when (and (numberp article)
4612 (not (memq article gnus-newsgroup-sparse)))
4613 (setq gnus-article-current
4614 (cons gnus-newsgroup-name article))
4615 (set-buffer gnus-summary-buffer)
4616 (setq gnus-current-article article)
4617 (if (and (memq article gnus-newsgroup-undownloaded)
4618 (not (gnus-online (gnus-find-method-for-group
4619 gnus-newsgroup-name))))
4621 (gnus-summary-set-agent-mark article)
4622 (message "Message marked for downloading"))
4623 (gnus-summary-mark-article article gnus-canceled-mark)
4624 (unless (memq article gnus-newsgroup-sparse)
4625 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4626 (if (or (eq result 'pseudo)
4627 (eq result 'nneething))
4629 (with-current-buffer summary-buffer
4630 (push article gnus-newsgroup-history)
4631 (setq gnus-last-article gnus-current-article
4632 gnus-current-article 0
4633 gnus-current-headers nil
4634 gnus-article-current nil)
4635 (if (eq result 'nneething)
4636 (gnus-configure-windows 'summary)
4637 (gnus-configure-windows 'article))
4638 (gnus-set-global-variables))
4639 (let ((gnus-article-mime-handle-alist-1
4640 gnus-article-mime-handle-alist))
4641 (gnus-set-mode-line 'article)))
4642 ;; The result from the `request' was an actual article -
4643 ;; or at least some text that is now displayed in the
4645 (when (and (numberp article)
4646 (not (eq article gnus-current-article)))
4647 ;; Seems like a new article has been selected.
4648 ;; `gnus-current-article' must be an article number.
4649 (with-current-buffer summary-buffer
4650 (push article gnus-newsgroup-history)
4651 (setq gnus-last-article gnus-current-article
4652 gnus-current-article article
4653 gnus-current-headers
4654 (gnus-summary-article-header gnus-current-article)
4655 gnus-article-current
4656 (cons gnus-newsgroup-name gnus-current-article))
4657 (unless (vectorp gnus-current-headers)
4658 (setq gnus-current-headers nil))
4659 (gnus-summary-goto-subject gnus-current-article)
4660 (when (gnus-summary-show-thread)
4661 ;; If the summary buffer really was folded, the
4662 ;; previous goto may not actually have gone to
4663 ;; the right article, but the thread root instead.
4665 (gnus-summary-goto-subject gnus-current-article))
4666 (gnus-run-hooks 'gnus-mark-article-hook)
4667 (gnus-set-mode-line 'summary)
4668 (when (gnus-visual-p 'article-highlight 'highlight)
4669 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4670 ;; Set the global newsgroup variables here.
4671 (gnus-set-global-variables)
4672 (setq gnus-have-all-headers
4673 (or all-headers gnus-show-all-headers))))
4675 (gnus-configure-windows 'article))
4676 (when (or (numberp article)
4678 (gnus-article-prepare-display)
4680 (goto-char (point-min))
4681 (when gnus-break-pages
4682 (gnus-narrow-to-page)))
4683 (let ((gnus-article-mime-handle-alist-1
4684 gnus-article-mime-handle-alist))
4685 (gnus-set-mode-line 'article))
4689 (set-window-point (get-buffer-window (current-buffer)) (point))
4690 (gnus-configure-windows 'article)
4691 (gnus-run-hooks 'gnus-article-prepare-hook)
4694 (defvar gnus-mime-display-attachment-buttons-in-header)
4697 (defun gnus-article-prepare-display ()
4698 "Make the current buffer look like a nice article."
4699 ;; Hooks for getting information from the article.
4700 ;; This hook must be called before being narrowed.
4701 (let ((gnus-article-buffer (current-buffer))
4703 (inhibit-read-only t))
4704 (unless (derived-mode-p 'gnus-article-mode)
4705 (gnus-article-mode))
4706 (setq buffer-read-only nil
4707 gnus-article-wash-types nil
4708 gnus-article-image-alist nil)
4709 (gnus-run-hooks 'gnus-tmp-internal-hook)
4710 (when gnus-display-mime-function
4711 (funcall gnus-display-mime-function))
4712 ;; Add attachment buttons to the header.
4713 (when gnus-mime-display-attachment-buttons-in-header
4714 (gnus-mime-buttonize-attachments-in-header))))
4717 ;;; Gnus Sticky Article Mode
4720 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4721 "Mode for sticky articles."
4722 ;; Release bindings that won't work.
4723 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4724 gnus-sticky-article-mode-map)
4725 (substitute-key-definition 'gnus-article-refer-article 'undefined
4726 gnus-sticky-article-mode-map)
4727 (dolist (k '("e" "h" "s" "F" "R"))
4728 (define-key gnus-sticky-article-mode-map k nil))
4729 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4730 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4731 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4732 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4734 (defun gnus-sticky-article (arg)
4735 "Make the current article sticky.
4736 If a prefix ARG is given, ask for a name for this sticky article buffer."
4738 (gnus-summary-show-thread)
4739 (gnus-summary-select-article nil nil 'pseudo)
4740 (let (new-art-buf-name)
4741 (gnus-eval-in-buffer-window gnus-article-buffer
4742 (setq new-art-buf-name
4746 (read-from-minibuffer "Sticky article buffer name: ")
4747 (gnus-with-article-headers
4748 (gnus-article-goto-header "subject")
4749 (setq new-art-buf-name
4750 (buffer-substring-no-properties
4751 (line-beginning-position) (line-end-position)))
4752 (goto-char (point-min))
4753 (gnus-article-goto-header "from")
4754 (setq new-art-buf-name
4756 new-art-buf-name ", "
4757 (buffer-substring-no-properties
4758 (line-beginning-position) (line-end-position))))
4759 (goto-char (point-min))
4760 (gnus-article-goto-header "date")
4761 (setq new-art-buf-name
4763 new-art-buf-name ", "
4764 (buffer-substring-no-properties
4765 (line-beginning-position) (line-end-position))))))
4767 (if (and (gnus-buffer-live-p new-art-buf-name)
4768 (with-current-buffer new-art-buf-name
4769 (derived-mode-p 'gnus-sticky-article-mode)))
4770 (switch-to-buffer new-art-buf-name)
4771 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4772 (gnus-sticky-article-mode))
4773 (setq gnus-article-buffer new-art-buf-name))
4774 (gnus-summary-recenter)
4775 (gnus-summary-position-point))
4777 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4778 "Kill the given sticky article BUFFER.
4779 If none is given, assume the current buffer and kill it if it has
4780 `gnus-sticky-article-mode'."
4783 (setq buffer (current-buffer)))
4784 (with-current-buffer buffer
4785 (when (derived-mode-p 'gnus-sticky-article-mode)
4786 (gnus-kill-buffer buffer))))
4788 (defun gnus-kill-sticky-article-buffers (arg)
4789 "Kill all sticky article buffers.
4790 If a prefix ARG is given, ask for confirmation."
4792 (dolist (buf (gnus-buffers))
4793 (with-current-buffer buf
4794 (when (derived-mode-p 'gnus-sticky-article-mode)
4796 (gnus-kill-buffer buf)
4797 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4798 (gnus-kill-buffer buf)))))))
4801 ;;; Gnus MIME viewing functions
4804 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4805 "Format of the MIME buttons.
4807 Valid specifiers include:
4809 %T MIME type, along with additional info
4810 %n The `name' parameter
4811 %d The description, if any
4812 %l The length of the encoded part
4813 %p The part identifier number
4814 %e Dots if the part isn't displayed
4816 General format specifiers can also be used. See Info node
4817 `(gnus)Formatting Variables'.")
4819 (defvar gnus-tmp-type)
4820 (defvar gnus-tmp-type-long)
4821 (defvar gnus-tmp-name)
4822 (defvar gnus-tmp-description)
4823 (defvar gnus-tmp-id)
4824 (defvar gnus-tmp-length)
4825 (defvar gnus-tmp-dots)
4826 (defvar gnus-tmp-info)
4827 (defvar gnus-tmp-pressed-details)
4829 (defvar gnus-mime-button-line-format-alist
4830 '((?t gnus-tmp-type ?s)
4831 (?T gnus-tmp-type-long ?s)
4832 (?n gnus-tmp-name ?s)
4833 (?d gnus-tmp-description ?s)
4835 (?l gnus-tmp-length ?d)
4836 (?e gnus-tmp-dots ?s)))
4838 (defvar gnus-mime-button-commands
4839 '((gnus-article-press-button "\r" "Toggle Display")
4840 (gnus-mime-view-part "v" "View Interactively...")
4841 (gnus-mime-view-part-as-type "t" "View As Type...")
4842 (gnus-mime-view-part-as-charset "C" "View As charset...")
4843 (gnus-mime-save-part "o" "Save...")
4844 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4845 (gnus-mime-replace-part "r" "Replace part")
4846 (gnus-mime-delete-part "d" "Delete part")
4847 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4848 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4849 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4850 (gnus-mime-view-part-externally "e" "View Externally")
4851 (gnus-mime-print-part "p" "Print")
4852 (gnus-mime-pipe-part "|" "Pipe To Command...")
4853 (gnus-mime-action-on-part "." "Take action on the part...")))
4855 (defun gnus-article-mime-part-status ()
4856 (if gnus-article-mime-handle-alist-1
4857 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4859 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4862 (defvar gnus-mime-button-map
4863 (let ((map (make-sparse-keymap)))
4864 (define-key map [mouse-2] 'gnus-article-push-button)
4865 (define-key map [down-mouse-3] 'gnus-mime-button-menu)
4866 (dolist (c gnus-mime-button-commands)
4867 (define-key map (cadr c) (car c)))
4871 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4873 ,@(mapcar (lambda (c)
4874 (vector (caddr c) (car c) :active t))
4875 gnus-mime-button-commands)))
4877 (defvar gnus-url-button-commands
4878 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4880 (defvar gnus-url-button-map
4881 (let ((map (make-sparse-keymap)))
4882 (dolist (c gnus-url-button-commands)
4883 (define-key map (cadr c) (car c)))
4887 gnus-url-button-menu gnus-url-button-map "URL button menu."
4889 ,@(mapcar (lambda (c)
4890 (vector (caddr c) (car c) :active t))
4891 gnus-url-button-commands)))
4893 (defmacro gnus-bind-mm-vars (&rest body)
4894 "Bind some mm-* variables and execute BODY."
4895 `(let (mm-html-inhibit-images
4896 mm-html-blocked-images
4897 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4898 (with-current-buffer
4899 (cond ((derived-mode-p 'gnus-article-mode)
4900 (if (gnus-buffer-live-p gnus-article-current-summary)
4901 gnus-article-current-summary
4902 ;; Maybe we're in a mml-preview buffer
4903 ;; and no group is selected.
4905 ((gnus-buffer-live-p gnus-summary-buffer)
4906 gnus-summary-buffer)
4907 (t (current-buffer)))
4908 (setq mm-html-inhibit-images gnus-inhibit-images
4909 mm-html-blocked-images (gnus-blocked-images))
4910 (when (or (not gnus-newsgroup-name)
4911 (and (stringp gnus-safe-html-newsgroups)
4912 (string-match gnus-safe-html-newsgroups
4913 gnus-newsgroup-name))
4914 (and (consp gnus-safe-html-newsgroups)
4915 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4916 (setq mm-w3m-safe-url-regexp nil)))
4919 (defun gnus-mime-button-menu (event prefix)
4920 "Construct a context-sensitive menu of MIME commands."
4921 (interactive "e\nP")
4922 (save-window-excursion
4923 (let ((pos (event-start event)))
4924 (select-window (posn-window pos))
4925 (goto-char (posn-point pos))
4926 (gnus-article-check-buffer)
4927 (popup-menu gnus-mime-button-menu nil prefix))))
4929 (defun gnus-mime-view-all-parts (&optional handles)
4930 "View all the MIME parts."
4932 (with-current-buffer gnus-article-buffer
4933 (let ((handles (or handles gnus-article-mime-handles))
4934 (mail-parse-charset gnus-newsgroup-charset)
4935 (mail-parse-ignored-charsets
4936 (with-current-buffer gnus-summary-buffer
4937 gnus-newsgroup-ignored-charsets)))
4939 (mm-remove-parts handles)
4940 (goto-char (point-min))
4941 (or (search-forward "\n\n") (goto-char (point-max)))
4942 (let ((inhibit-read-only t))
4943 (delete-region (point) (point-max))
4944 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4946 (defun gnus-article-jump-to-part (n)
4947 "Jump to MIME part N."
4949 (let ((parts (with-current-buffer gnus-article-buffer
4950 (length gnus-article-mime-handle-alist))))
4952 (error "No such part"))
4953 (pop-to-buffer gnus-article-buffer)
4955 (setq n (if (= parts 1)
4957 (read-number (format "Jump to part (1..%s): " parts)))))
4958 (unless (and (integerp n) (<= n parts) (>= n 1))
4961 (gnus-message 7 "Invalid part `%s', using %s instead."
4964 (gnus-message 9 "Jumping to part %s." n)
4965 (cond ((>= gnus-auto-select-part 1)
4966 (while (and (<= n parts)
4967 (not (gnus-article-goto-part n)))
4969 ((< gnus-auto-select-part 0)
4970 (while (and (>= n 1)
4971 (not (gnus-article-goto-part n)))
4974 (gnus-article-goto-part n)))))
4976 (defvar gnus-mime-buttonized-part-id nil
4977 "ID of a mime part that should be buttonized.
4978 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4981 (defsubst gnus-article-edit-part (handles &optional current-id)
4982 "Edit an article in order to delete a mime part.
4983 This function is exclusively used by `gnus-mime-save-part-and-strip'
4984 and `gnus-mime-delete-part', and not provided at run-time normally."
4985 (gnus-article-edit-article
4987 (buffer-disable-undo)
4988 (let ((mail-parse-charset (or gnus-article-charset
4989 ',gnus-newsgroup-charset))
4990 (mail-parse-ignored-charsets
4991 (or gnus-article-ignored-charsets
4992 ',gnus-newsgroup-ignored-charsets))
4993 (mbl mml-buffer-list))
4994 (setq mml-buffer-list nil)
4995 ;; A new text must be inserted before deleting existing ones
4996 ;; at the end so as not to move existing markers of which
4997 ;; the insertion type is t.
5001 (goto-char (point-max))
5002 (insert-buffer-substring gnus-original-article-buffer)))
5003 (mime-to-mml ',handles)
5004 (setq gnus-article-mime-handles nil)
5005 (let ((mbl1 mml-buffer-list))
5006 (setq mml-buffer-list mbl)
5007 (set (make-local-variable 'mml-buffer-list) mbl1))
5008 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5009 `(lambda (no-highlight)
5010 (let ((mail-parse-charset (or gnus-article-charset
5011 ',gnus-newsgroup-charset))
5012 (message-options message-options)
5013 (message-options-set-recipient)
5014 (mail-parse-ignored-charsets
5015 (or gnus-article-ignored-charsets
5016 ',gnus-newsgroup-ignored-charsets)))
5018 (mml-destroy-buffers)
5019 (remove-hook 'kill-buffer-hook
5020 'mml-destroy-buffers t)
5021 (kill-local-variable 'mml-buffer-list))
5022 (gnus-summary-edit-article-done
5023 ,(or (mail-header-references gnus-current-headers) "")
5024 ,(gnus-group-read-only-p)
5025 ,gnus-summary-buffer no-highlight))
5027 ;; Force buttonizing this part.
5028 (let ((gnus-mime-buttonized-part-id current-id))
5029 (gnus-article-edit-done))
5030 (gnus-configure-windows 'article)
5032 (when (and current-id (integerp gnus-auto-select-part))
5033 (gnus-article-jump-to-part
5034 (min (max (+ current-id gnus-auto-select-part) 1)
5035 (with-current-buffer gnus-article-buffer
5036 (length gnus-article-mime-handle-alist)))))))
5038 (defun gnus-mime-replace-part (file)
5039 "Replace MIME part under point with an external body."
5040 ;; Useful if file has already been saved to disk
5043 (read-file-name "Replace MIME part with file: "
5044 (or mm-default-directory default-directory)
5046 (gnus-mime-save-part-and-strip file))
5048 (defun gnus-mime-save-part-and-strip (&optional file)
5049 "Save the MIME part under point then replace it with an external body.
5050 If FILE is given, use it for the external part."
5052 (gnus-article-check-buffer)
5053 (when (gnus-group-read-only-p)
5054 (error "The current group does not support deleting of parts"))
5055 (when (mm-complicated-handles gnus-article-mime-handles)
5057 The current article has a complicated MIME structure, giving up..."))
5058 (let* ((data (get-text-property (point) 'gnus-data))
5059 (id (get-text-property (point) 'gnus-part))
5060 (handles gnus-article-mime-handles))
5063 (and data (mm-save-part data "Delete MIME part and save to: "))))
5065 (with-current-buffer (mm-handle-buffer data)
5067 (insert "Content-Type: " (mm-handle-media-type data))
5068 (mml-insert-parameter-string (cdr (mm-handle-type data))
5070 ;; Add a filename for the sake of saving the part again.
5071 (mml-insert-parameter
5072 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5074 (insert "Content-ID: " (message-make-message-id) "\n")
5075 (insert "Content-Transfer-Encoding: binary\n")
5078 (cdr (mm-make-handle nil
5079 `("message/external-body"
5080 (access-type . "LOCAL-FILE")
5082 ;; (set-buffer gnus-summary-buffer)
5083 (gnus-article-edit-part handles id))))
5085 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5086 ;; parts...>') but with stripping would be nice.
5088 (defun gnus-mime-delete-part ()
5089 "Delete the MIME part under point.
5090 Replace it with some information about the removed part."
5092 (gnus-article-check-buffer)
5093 (when (gnus-group-read-only-p)
5094 (error "The current group does not support deleting of parts"))
5095 (when (mm-complicated-handles gnus-article-mime-handles)
5097 The current article has a complicated MIME structure, giving up..."))
5098 (when (or gnus-expert-user
5099 (gnus-yes-or-no-p "\
5100 Deleting parts may malfunction or destroy the article; continue? "))
5101 (let* ((data (get-text-property (point) 'gnus-data))
5102 (id (get-text-property (point) 'gnus-part))
5103 (handles gnus-article-mime-handles)
5105 (let ((desc (mm-handle-description data)))
5107 (mail-decode-encoded-word-string desc))))
5108 (filename (or (mm-handle-filename data) "(none)"))
5109 (type (mm-handle-media-type data)))
5111 (error "No MIME part under point"))
5112 (with-current-buffer (mm-handle-buffer data)
5113 (let ((bsize (buffer-size)))
5118 "| The following attachment has been deleted:\n"
5120 "| Type: " type "\n"
5121 "| Filename: " filename "\n"
5122 "| Size (encoded): " (format "%s byte%s\n"
5123 bsize (if (= bsize 1)
5127 (concat "| Description: " description "\n"))
5130 (cdr (mm-make-handle
5131 nil `("text/plain" (charset . gnus-decoded)) nil nil
5133 (format "Deleted attachment (%s bytes)" bsize))))))
5134 ;; (set-buffer gnus-summary-buffer)
5135 (gnus-article-edit-part handles id))))
5137 (defun gnus-mime-save-part ()
5138 "Save the MIME part under point."
5140 (gnus-article-check-buffer)
5141 (let ((data (get-text-property (point) 'gnus-data)))
5143 (mm-save-part data))))
5145 (defun gnus-mime-pipe-part (&optional cmd)
5146 "Pipe the MIME part under point to a process.
5147 Use CMD as the process."
5149 (gnus-article-check-buffer)
5150 (let ((data (get-text-property (point) 'gnus-data)))
5152 (mm-pipe-part data cmd))))
5154 (defun gnus-mime-view-part ()
5155 "Interactively choose a viewing method for the MIME part under point."
5157 (gnus-article-check-buffer)
5158 (let ((data (get-text-property (point) 'gnus-data)))
5160 (setq gnus-article-mime-handles
5162 gnus-article-mime-handles (setq data (copy-sequence data))))
5163 (mm-interactively-view-part data))))
5165 (defun gnus-mime-view-part-as-type-internal ()
5166 (gnus-article-check-buffer)
5167 (let* ((handle (get-text-property (point) 'gnus-data))
5169 ;; Content-Type: foo/bar; name=...
5170 (mail-content-type-get (mm-handle-type handle) 'name)
5171 ;; Content-Disposition: attachment; filename=...
5172 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5173 (def-type (and name (mm-default-file-encoding name))))
5174 (or (and def-type (cons def-type 0))
5176 (equal (mm-handle-media-supertype handle) "text")
5177 '("text/plain" . 0))
5178 '("application/octet-stream" . 0))))
5180 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5181 "Choose a MIME media type, and view the part as such.
5182 If non-nil, PRED is a predicate to use during completion to limit the
5183 available media-types."
5187 (let ((default (gnus-mime-view-part-as-type-internal)))
5188 (gnus-completing-read
5191 (gnus-remove-if-not pred (mailcap-mime-types))
5192 (mailcap-mime-types))
5195 (gnus-article-check-buffer)
5196 (let ((handle (get-text-property (point) 'gnus-data)))
5198 (when (equal (mm-handle-media-type handle) "message/external-body")
5199 (unless (mm-handle-cache handle)
5200 (mm-extern-cache-contents handle))
5201 (setq handle (mm-handle-cache handle)))
5203 (mm-make-handle (mm-handle-buffer handle)
5204 (cons mime-type (cdr (mm-handle-type handle)))
5205 (mm-handle-encoding handle)
5206 (mm-handle-undisplayer handle)
5207 (mm-handle-disposition handle)
5208 (mm-handle-description handle)
5210 (mm-handle-id handle)))
5211 (setq gnus-article-mime-handles
5212 (mm-merge-handles gnus-article-mime-handles handle))
5213 (when (mm-handle-displayed-p handle)
5214 (mm-remove-part handle))
5215 (gnus-mm-display-part handle))))
5217 (defun gnus-mime-copy-part (&optional handle arg)
5218 "Put the MIME part under point into a new buffer.
5219 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5221 (interactive (list nil current-prefix-arg))
5222 (gnus-article-check-buffer)
5224 (setq handle (get-text-property (point) 'gnus-data)))
5226 (let ((filename (mm-handle-filename handle))
5227 contents dont-decode charset coding-system)
5228 (mm-with-unibyte-buffer
5229 (mm-insert-part handle)
5230 (setq contents (or (condition-case nil
5231 (mm-decompress-buffer filename nil 'sig)
5233 (setq dont-decode t)
5236 (setq filename (cond (filename (file-name-nondirectory filename))
5237 (dont-decode "*raw data*")
5242 (unless (setq charset (mail-content-type-get
5243 (mm-handle-type handle) 'charset))
5244 (unless (setq coding-system (mm-with-unibyte-buffer
5246 (mm-find-buffer-file-coding-system)))
5247 (setq charset gnus-newsgroup-charset))))
5249 (setq charset (or (cdr (assq arg
5250 gnus-summary-show-article-charset-alist))
5251 (read-coding-system "Charset: ")))))
5252 (switch-to-buffer (generate-new-buffer filename))
5253 (if (or coding-system
5255 (setq coding-system (mm-charset-to-coding-system
5257 (not (eq coding-system 'ascii))))
5259 (mm-enable-multibyte)
5260 (insert (decode-coding-string contents coding-system))
5261 (setq buffer-file-coding-system last-coding-system-used))
5262 (mm-disable-multibyte)
5264 (setq buffer-file-coding-system mm-binary-coding-system))
5265 ;; We do it this way to make `normal-mode' set the appropriate mode.
5268 (setq buffer-file-name (expand-file-name filename))
5270 (setq buffer-file-name nil))
5271 (goto-char (point-min)))))
5273 (defun gnus-mime-print-part (&optional handle filename)
5274 "Print the MIME part under point."
5275 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5276 (gnus-article-check-buffer)
5277 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5278 (contents (and handle (mm-get-part handle)))
5279 (file (make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5280 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5285 (mm-save-part-to-file handle file)
5286 (call-process shell-file-name nil
5287 (generate-new-buffer " *mm*")
5289 shell-command-switch
5291 printer file (mm-handle-type handle))))
5295 (gnus-print-buffer))
5296 (ps-despool filename)))))
5298 (defun gnus-mime-inline-part (&optional handle arg)
5299 "Insert the MIME part under point into the current buffer.
5300 Compressed files like .gz and .bz2 are decompressed."
5301 (interactive (list nil current-prefix-arg))
5302 (gnus-article-check-buffer)
5303 (let* ((inhibit-read-only t)
5305 (btn ;; position where the MIME button exists
5307 (if (eq handle (get-text-property b 'gnus-data))
5310 (or (text-property-any (point) (point-max) 'gnus-data handle)
5311 (text-property-any (point-min) (point) 'gnus-data handle)))
5312 (setq handle (get-text-property b 'gnus-data))
5318 (setq start (next-single-property-change btn 'gnus-data
5320 btn (previous-single-property-change start
5323 (if (and (not arg) (mm-handle-undisplayer handle))
5325 (setq b (copy-marker b)
5326 btn (copy-marker btn))
5327 (mm-remove-part handle))
5331 (if (mm-handle-undisplayer handle)
5332 (mm-remove-part handle)))
5333 ((mm-handle-undisplayer handle)
5334 (mm-remove-part handle)))
5337 ;; This is a header button.
5339 (mm-display-inline handle))
5340 ;; Toggle the button appearance between `[button]...' and `[button]'.
5342 (setq btn (prog1 (marker-position btn)
5343 (set-marker btn nil))))
5345 (let ((displayed-p (mm-handle-displayed-p handle)))
5346 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5350 (next-single-property-change (point) 'gnus-data nil (point-max)))
5351 (setq start (point))
5352 (if (search-backward "\n\n" nil t)
5355 (unless (or displayed-p (eolp))
5356 ;; Add extra newline.
5357 (insert (propertize (buffer-substring (1- start) start)
5358 'gnus-undeletable t))))
5359 ;; We're in the article header.
5361 (dolist (ovl (overlays-in btn (point)))
5362 (overlay-put ovl 'gnus-button-attachment-extra t)
5363 (overlay-put ovl 'face nil))
5365 (message-narrow-to-field)
5366 (let ((gnus-treatment-function-alist
5367 '((gnus-treat-highlight-headers
5368 gnus-article-highlight-headers))))
5369 (gnus-treat-article 'head)))))
5371 (setq b (prog1 (marker-position b)
5372 (set-marker b nil))))
5375 (defun gnus-mime-set-charset-parameters (handle charset)
5376 "Set CHARSET to parameters in HANDLE.
5377 CHARSET may either be a string or a symbol."
5378 (unless (stringp charset)
5379 (setq charset (symbol-name charset)))
5380 (if (stringp (car handle))
5381 (dolist (h (cdr handle))
5382 (gnus-mime-set-charset-parameters h charset))
5383 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5384 "message/external-body")
5386 (unless (mm-handle-cache handle)
5387 (mm-extern-cache-contents handle))
5388 (mm-handle-cache handle))
5390 (param (assq 'charset (cdr type))))
5392 (setcdr param charset)
5393 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5395 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5396 "Insert the MIME part under point into the current buffer using the
5398 (interactive (list nil current-prefix-arg))
5399 (gnus-article-check-buffer)
5400 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5401 (fun (get-text-property (point) 'gnus-callback))
5402 (gnus-newsgroup-ignored-charsets 'gnus-all)
5403 charset form preferred parts)
5410 gnus-summary-show-article-charset-alist))
5411 (read-coding-system "Charset: "))))
5412 (if (mm-handle-undisplayer handle)
5413 (mm-remove-part handle)))
5414 (gnus-mime-set-charset-parameters handle charset)
5415 (when (and (consp (setq form (cdr-safe fun)))
5416 (setq form (ignore-errors
5417 (assq 'gnus-mime-display-alternative form)))
5418 (setq preferred (caddr form))
5420 (when (eq (car preferred) 'quote)
5421 (setq preferred (cadr preferred)))
5422 (not (equal preferred
5423 (get-text-property (point) 'gnus-data))))
5424 (setq parts (get-text-property (point) 'gnus-part))
5425 (setq parts (cdr (assq parts
5426 gnus-article-mime-handle-alist)))
5427 (equal (mm-handle-media-type parts) "multipart/alternative")
5428 (setq parts (reverse (cdr parts))))
5430 (list 'quote (or (cadr (member preferred parts))
5432 (funcall fun handle)))))
5434 (defun gnus-mime-view-part-externally (&optional handle)
5435 "View the MIME part under point with an external viewer."
5437 (gnus-article-check-buffer)
5438 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5439 (mm-inlined-types nil)
5440 (mail-parse-charset gnus-newsgroup-charset)
5441 (mail-parse-ignored-charsets
5442 (with-current-buffer gnus-summary-buffer
5443 gnus-newsgroup-ignored-charsets))
5444 (type (mm-handle-media-type handle))
5445 (method (mailcap-mime-info type))
5446 (mm-enable-external t))
5447 (if (not (stringp method))
5448 (gnus-mime-view-part-as-type
5449 nil (lambda (type) (stringp (mailcap-mime-info type))))
5451 (mm-display-part handle nil t)))))
5453 (defun gnus-mime-view-part-internally (&optional handle)
5454 "View the MIME part under point with an internal viewer.
5455 If no internal viewer is available, use an external viewer."
5457 (gnus-article-check-buffer)
5458 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5459 (mm-inlined-types '(".*"))
5460 (mm-inline-large-images t)
5461 (mail-parse-charset gnus-newsgroup-charset)
5462 (mail-parse-ignored-charsets
5463 (with-current-buffer gnus-summary-buffer
5464 gnus-newsgroup-ignored-charsets))
5465 (inhibit-read-only t))
5466 (if (not (mm-inlinable-p handle))
5467 (gnus-mime-view-part-as-type
5468 nil (lambda (type) (mm-inlinable-p handle type)))
5470 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5472 (defun gnus-mime-action-on-part (&optional action)
5473 "Do something with the MIME attachment at (point)."
5475 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5476 (gnus-article-check-buffer)
5477 (let ((action-pair (assoc action gnus-mime-action-alist)))
5479 (funcall (cdr action-pair)))))
5481 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5482 "Call FUNCTION on MIME part N.
5483 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5484 If INTERACTIVE, call FUNCTION interactively."
5486 ;; Check whether the article is displayed.
5487 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5488 (setq window (get-buffer-window gnus-article-buffer t))
5489 (frame-visible-p (setq frame (window-frame window))))
5490 (error "No article is displayed"))
5491 (with-current-buffer gnus-article-buffer
5492 ;; Check whether the article displays the right contents.
5493 (unless (with-current-buffer gnus-summary-buffer
5494 (eq gnus-current-article (gnus-summary-article-number)))
5495 (error "You should select the right article first"))
5497 (setq n (prefix-numeric-value n))
5499 (setq n (or (get-text-property pt 'gnus-part)
5501 (get-text-property (1- pt) 'gnus-part))
5502 (get-text-property (prog2
5508 (or (and (setq pt (previous-single-property-change
5511 (next-single-property-change (point) 'gnus-part)
5515 ;; Check whether the specified part exists.
5516 (when (> n (length gnus-article-mime-handle-alist))
5517 (error "No such part")))
5520 ;; To select the window is needed so that the cursor
5521 ;; might be visible on the MIME button.
5522 (select-window (prog1
5524 (setq window (selected-window))
5525 ;; Article may be displayed in the other frame.
5526 (select-frame-set-input-focus
5529 (setq frame (selected-frame))))))
5530 (when (gnus-article-goto-part n)
5531 ;; We point the cursor and the arrow at the MIME button
5532 ;; when the `function' prompt the user for something.
5533 (unless (and (pos-visible-in-window-p)
5534 (> (count-lines (point) (window-end))
5535 (/ (1- (window-height)) 3)))
5536 (recenter (/ (1- (window-height)) 3)))
5537 (let ((cursor-in-non-selected-windows t)
5538 (overlay-arrow-string "=>")
5539 (overlay-arrow-position (point-marker)))
5542 ((and no-handle interactive)
5543 (call-interactively function))
5548 function (get-text-property (point) 'gnus-data)))
5551 (get-text-property (point) 'gnus-data))))
5552 (set-marker overlay-arrow-position nil)
5553 (unless gnus-auto-select-part
5554 (select-frame-set-input-focus frame)
5555 (select-window window))))
5557 (if gnus-inhibit-mime-unbuttonizing
5558 ;; This is the default though the program shouldn't reach here.
5559 (error "No such part")
5560 ;; The part which doesn't have the MIME button is selected.
5561 ;; So, we display all the buttons and redo it.
5562 (let ((gnus-inhibit-mime-unbuttonizing t))
5563 (gnus-summary-show-article)
5564 (gnus-article-part-wrapper n function no-handle))))))
5566 (defun gnus-article-pipe-part (n)
5567 "Pipe MIME part N, which is the numerical prefix."
5569 (gnus-article-part-wrapper n 'mm-pipe-part))
5571 (defun gnus-article-save-part (n)
5572 "Save MIME part N, which is the numerical prefix."
5574 (gnus-article-part-wrapper n 'mm-save-part))
5576 (defun gnus-article-interactively-view-part (n)
5577 "View MIME part N interactively, which is the numerical prefix."
5579 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5581 (defun gnus-article-copy-part (n)
5582 "Copy MIME part N, which is the numerical prefix."
5584 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5586 (defun gnus-article-view-part-as-charset (n)
5587 "View MIME part N using a specified charset.
5588 N is the numerical prefix."
5590 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5592 (defun gnus-article-view-part-externally (n)
5593 "View MIME part N externally, which is the numerical prefix."
5595 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5597 (defun gnus-article-inline-part (n)
5598 "Inline MIME part N, which is the numerical prefix."
5600 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5602 (defun gnus-article-save-part-and-strip (n)
5603 "Save MIME part N and replace it with an external body.
5604 N is the numerical prefix."
5606 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5608 (defun gnus-article-replace-part (n)
5609 "Replace MIME part N with an external body.
5610 N is the numerical prefix."
5612 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5614 (defun gnus-article-delete-part (n)
5615 "Delete MIME part N and add some information about the removed part.
5616 N is the numerical prefix."
5618 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5620 (defun gnus-article-view-part-as-type (n)
5621 "Choose a MIME media type, and view part N as such.
5622 N is the numerical prefix."
5624 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5626 (defun gnus-article-mime-match-handle-first (condition)
5629 (dolist (ihandle gnus-article-mime-handle-alist)
5631 ((functionp condition)
5632 (funcall condition (cdr ihandle)))
5633 ((eq condition 'undisplayed)
5634 (not (or (mm-handle-undisplayer (cdr ihandle))
5635 (equal (mm-handle-media-type (cdr ihandle))
5636 "multipart/alternative"))))
5637 ((eq condition 'undisplayed-alternative)
5638 (not (mm-handle-undisplayer (cdr ihandle))))
5640 (gnus-article-goto-part (car ihandle))
5641 (or (not n) (< (car ihandle) n)))
5642 (setq n (car ihandle))))
5646 (defun gnus-article-view-part (&optional n)
5647 "View MIME part N, which is the numerical prefix.
5648 If the part is already shown, hide the part. If N is nil, view
5651 (with-current-buffer gnus-article-buffer
5652 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5653 gnus-article-mime-match-handle-function)))
5654 (when (> n (length gnus-article-mime-handle-alist))
5655 (error "No such part"))
5656 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5657 (when (gnus-article-goto-part n)
5658 (if (equal (car handle) "multipart/alternative")
5660 (beginning-of-line) ;; Make it toggle subparts
5661 (gnus-article-press-button))
5662 (when (eq (gnus-mm-display-part handle) 'internal)
5663 (gnus-set-window-start)))))))
5665 (defsubst gnus-article-mime-total-parts ()
5666 (if (bufferp (car gnus-article-mime-handles))
5668 (1- (length gnus-article-mime-handles))))
5670 (defun gnus-mm-display-part (handle)
5671 "Display HANDLE and fix MIME button."
5672 (let ((id (get-text-property (point) 'gnus-part))
5674 (inhibit-read-only t)
5675 (window (selected-window))
5676 (mail-parse-charset gnus-newsgroup-charset)
5677 (mail-parse-ignored-charsets
5678 (if (gnus-buffer-live-p gnus-summary-buffer)
5679 (with-current-buffer gnus-summary-buffer
5680 gnus-newsgroup-ignored-charsets)
5685 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5689 (setq start (next-single-property-change point 'gnus-data
5691 point (previous-single-property-change start 'gnus-data))
5692 (if (mm-handle-displayed-p handle)
5693 ;; This will remove the part.
5694 (setq point (copy-marker point)
5695 retval (mm-display-part handle))
5696 (let ((part (or (and (mm-inlinable-p handle)
5697 (mm-inlined-p handle)
5701 (setq retval (mm-display-part handle)))
5702 (unless (zerop (buffer-size))
5703 (buffer-string))))))
5706 ;; This is a header button.
5708 (cond ((stringp part)
5710 (narrow-to-region (point)
5713 (unless (bolp) (insert "\n"))
5715 (gnus-treat-article nil id
5716 (gnus-article-mime-total-parts)
5717 (mm-handle-media-type handle))
5718 (mm-handle-set-undisplayer
5721 (let ((inhibit-read-only t))
5722 (delete-region ,(copy-marker (point-min) t)
5723 ,(point-max-marker)))))))
5725 (mm-display-inline handle))))))
5726 (when (markerp point)
5727 (setq point (prog1 (marker-position point)
5728 (set-marker point nil))))
5730 ;; Toggle the button appearance between `[button]...' and `[button]'.
5731 (let ((displayed-p (mm-handle-displayed-p handle)))
5732 (gnus-insert-mime-button handle id (list displayed-p))
5735 (next-single-property-change (point) 'gnus-data nil (point-max)))
5736 (setq start (point))
5737 (if (search-backward "\n\n" nil t)
5740 (unless (or displayed-p (eolp))
5741 ;; Add extra newline.
5742 (insert (propertize (buffer-substring (1- start) start)
5743 'gnus-undeletable t))))
5744 ;; We're in the article header.
5746 (dolist (ovl (overlays-in point (point)))
5747 (overlay-put ovl 'gnus-button-attachment-extra t)
5748 (overlay-put ovl 'face nil))
5750 (message-narrow-to-field)
5751 (let ((gnus-treatment-function-alist
5752 '((gnus-treat-highlight-headers
5753 gnus-article-highlight-headers))))
5754 (gnus-treat-article 'head)))))
5756 (if (window-live-p window)
5757 (select-window window)))
5760 (defun gnus-article-goto-part (n)
5761 "Go to MIME part N."
5762 (when gnus-break-pages
5766 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5767 ;; There may be header buttons.
5768 (text-property-any (point-min) (point) 'gnus-part n)))
5769 part handle end next handles)
5772 (if (setq handle (get-text-property start 'gnus-data))
5774 ;; Go to the displayed subpart, assuming this is
5775 ;; multipart/alternative.
5778 (while (and (not handle)
5781 (setq next (text-property-not-all part end
5784 handle (get-text-property part 'gnus-data))
5785 (push (cons handle part) handles)
5786 (unless (mm-handle-displayed-p handle)
5788 part (text-property-any part end 'gnus-data nil))))
5790 ;; No subpart is displayed, so we find preferred one.
5792 (cdr (assq (mm-preferred-alternative
5793 (nreverse (mapcar 'car handles)))
5796 (goto-char (1+ part))
5798 (when gnus-break-pages
5799 (gnus-narrow-to-page))))
5801 (defun gnus-insert-mime-button (handle id &optional displayed)
5802 (let ((gnus-tmp-name
5803 (or (mm-handle-filename handle)
5804 (mail-content-type-get (mm-handle-type handle) 'url)
5807 (gnus-tmp-type (mm-handle-media-type handle))
5808 (gnus-tmp-description (or (mm-handle-description handle) ""))
5810 (if (if displayed (car displayed)
5811 (mm-handle-displayed-p handle))
5813 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5815 gnus-tmp-type-long b e)
5816 (when (string-match ".*/" gnus-tmp-name)
5817 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5818 (setq gnus-tmp-type-long (concat gnus-tmp-type
5819 (and (not (equal gnus-tmp-name ""))
5820 (concat "; " gnus-tmp-name))))
5821 (unless (equal gnus-tmp-description "")
5822 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5825 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5826 `(keymap ,gnus-mime-button-map
5827 gnus-callback gnus-mm-display-part
5828 gnus-part ,gnus-tmp-id
5829 article-type annotation
5833 ;; Exclude a newline.
5836 (when gnus-article-button-face
5837 (overlay-put (make-overlay b e nil t)
5838 'face gnus-article-button-face))
5839 (widget-convert-button
5842 :action 'gnus-widget-press-button
5843 :button-keymap gnus-mime-button-map
5847 "%S: %s the MIME part; %S: more options"
5849 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5853 (defun gnus-widget-press-button (elems _el)
5854 (goto-char (widget-get elems :from))
5855 (gnus-article-press-button))
5857 (defvar gnus-displaying-mime nil)
5859 (defun gnus-display-mime (&optional ihandles)
5860 "Display the MIME parts."
5862 (save-selected-window
5863 (let ((window (get-buffer-window gnus-article-buffer))
5866 (select-window window)
5867 ;; We have to do this since selecting the window
5868 ;; may change the point. So we set the window point.
5869 (set-window-point window point)))
5870 (let ((handles ihandles)
5871 (inhibit-read-only t))
5873 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5874 (when gnus-article-emulate-mime
5875 (mm-uu-dissect-text-parts handles)))
5876 (gnus-article-emulate-mime
5877 (setq handles (mm-uu-dissect))))
5878 (when (and (not ihandles)
5879 (not gnus-displaying-mime))
5880 ;; Top-level call; we clean up.
5881 (when gnus-article-mime-handles
5882 (mm-destroy-parts gnus-article-mime-handles)
5883 (setq gnus-article-mime-handle-alist nil));; A trick.
5884 (setq gnus-article-mime-handles handles)
5885 ;; We allow users to glean info from the handles.
5886 (when gnus-article-mime-part-function
5887 (gnus-mime-part-function handles)))
5889 (or (not (stringp (car handles)))
5892 (when (and (not ihandles)
5893 (not gnus-displaying-mime))
5894 ;; Clean up for mime parts.
5896 (delete-region (point) (point-max)))
5897 (let ((gnus-displaying-mime t))
5898 (gnus-mime-display-part handles)))
5901 (narrow-to-region (point) (point-max))
5902 (gnus-treat-article nil 1 1 "text/plain")
5905 ;; Highlight the headers.
5909 (narrow-to-region (point-min) (point))
5910 (gnus-article-save-original-date
5911 (gnus-treat-article 'head)))))))
5912 ;; Cope with broken MIME messages.
5913 (goto-char (point-max))
5917 (defcustom gnus-mime-display-multipart-as-mixed nil
5918 "Display \"multipart\" parts as \"multipart/mixed\".
5920 If t, it overrides nil values of
5921 `gnus-mime-display-multipart-alternative-as-mixed' and
5922 `gnus-mime-display-multipart-related-as-mixed'."
5923 :group 'gnus-article-mime
5926 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5927 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5929 :group 'gnus-article-mime
5932 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5933 "Display \"multipart/related\" parts as \"multipart/mixed\".
5935 If displaying \"text/html\" is discouraged \(see
5936 `mm-discouraged-alternatives') images or other material inside a
5937 \"multipart/related\" part might be overlooked when this variable is nil."
5939 :group 'gnus-article-mime
5942 (defcustom gnus-mime-display-attachment-buttons-in-header t
5943 "Add attachment buttons in the end of the header of an article.
5944 Since MIME attachments tend to be put at the end of an article, we may
5945 overlook them if there is a huge body. This option offers you a copy
5946 of all non-inlinable MIME parts as buttons shown in front of an article.
5947 If nil, don't show those extra buttons."
5949 :group 'gnus-article-mime
5952 (defun gnus-mime-display-part (handle)
5954 ;; Maybe a broken MIME message.
5957 ((not (stringp (car handle)))
5958 (gnus-mime-display-single handle))
5959 ;; User-defined multipart
5960 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5961 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5963 ;; multipart/alternative
5964 ((and (equal (car handle) "multipart/alternative")
5965 (not (or gnus-mime-display-multipart-as-mixed
5966 gnus-mime-display-multipart-alternative-as-mixed)))
5967 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5968 (push (cons id handle) gnus-article-mime-handle-alist)
5969 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5970 ;; multipart/related
5971 ((and (equal (car handle) "multipart/related")
5972 (not (or gnus-mime-display-multipart-as-mixed
5973 gnus-mime-display-multipart-related-as-mixed)))
5974 (gnus-mime-display-part (cadr handle)))
5975 ((equal (car handle) "multipart/signed")
5976 (gnus-add-wash-type 'signed)
5977 (gnus-mime-display-security handle))
5978 ((equal (car handle) "multipart/encrypted")
5979 (gnus-add-wash-type 'encrypted)
5980 (gnus-mime-display-security handle))
5981 ;; Other multiparts are handled like multipart/mixed.
5983 (gnus-mime-display-mixed (cdr handle)))))
5985 (defun gnus-mime-part-function (handles)
5986 (if (stringp (car handles))
5987 (mapcar 'gnus-mime-part-function (cdr handles))
5988 (funcall gnus-article-mime-part-function handles)))
5990 (defun gnus-mime-display-mixed (handles)
5991 (mapcar 'gnus-mime-display-part handles))
5993 (defun gnus-mime-display-single (handle)
5994 (let ((type (mm-handle-media-type handle))
5995 (ignored gnus-ignored-mime-types)
6001 (when (string-match (pop ignored) type)
6002 (throw 'ignored nil)))
6003 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6004 (with-current-buffer gnus-summary-buffer
6005 gnus-inhibit-images)
6006 gnus-inhibit-images)
6007 (string-match "\\`image/" type)))
6008 (setq not-attachment
6009 (and (not (mm-inline-override-p handle))
6010 (or (not (mm-handle-disposition handle))
6011 (equal (car (mm-handle-disposition handle))
6013 (mm-attachment-override-p handle))))
6014 (mm-automatic-display-p handle)
6016 (mm-inlinable-p handle)
6017 (mm-inlined-p handle))
6018 (mm-automatic-external-display-p type)))
6020 (when (equal (mm-handle-media-supertype handle) "text")
6022 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6025 (setq id (1+ (length gnus-article-mime-handle-alist)))
6026 (push (cons id handle) gnus-article-mime-handle-alist))
6028 (equal (mm-handle-media-supertype handle) "message"))
6031 (cond ((not (bolp)) 2)
6032 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6034 (when (or (not display)
6035 (not (gnus-unbuttonized-mime-type-p type))
6036 (eq id gnus-mime-buttonized-part-id))
6037 (gnus-insert-mime-button
6038 handle id (list (or display (and not-attachment text)))))
6042 (let ((mail-parse-charset gnus-newsgroup-charset)
6043 (mail-parse-ignored-charsets
6044 (save-excursion (condition-case ()
6045 (set-buffer gnus-summary-buffer)
6047 gnus-newsgroup-ignored-charsets)))
6048 (gnus-bind-mm-vars (mm-display-part handle t))))
6049 ((and text not-attachment)
6050 (mm-display-inline handle)))
6051 (goto-char (point-max))
6052 (if (string-match "\\`image/" type)
6053 (gnus-article-insert-newline)
6055 (= (skip-chars-backward "\n") -1)
6056 (unless (eobp) (forward-char 1)))
6057 (gnus-article-insert-newline)
6058 (put-text-property (point) (point-max) 'gnus-undeletable t))
6059 (goto-char (point-max)))
6063 (narrow-to-region beg (point))
6064 (if (eq handle gnus-article-mime-handles)
6065 ;; The format=flowed case.
6066 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6067 ;; Don't count signature parts that are never displayed.
6068 ;; The part number should be re-calculated supposing this
6069 ;; might be a message/rfc822 part.
6071 (dolist (part gnus-article-mime-handles)
6072 (unless (or (stringp part)
6073 (equal (car (mm-handle-type part))
6074 "application/pgp-signature"))
6075 (push part handles)))
6077 nil (length (memq handle handles)) (length handles)
6078 (mm-handle-media-type handle)))))))))))
6080 (defun gnus-unbuttonized-mime-type-p (type)
6081 "Say whether TYPE is to be unbuttonized."
6082 (unless gnus-inhibit-mime-unbuttonizing
6084 (let ((types gnus-unbuttonized-mime-types))
6086 (when (string-match (pop types) type)
6087 (throw 'found t)))))
6089 (let ((types gnus-buttonized-mime-types))
6091 (when (string-match (pop types) type)
6092 (throw 'found t)))))))))
6094 (defun gnus-article-insert-newline ()
6095 "Insert a newline, but mark it as undeletable."
6096 (put-text-property (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6098 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6099 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6102 handle (inhibit-read-only t) from begend not-pref)
6103 (save-window-excursion
6106 (narrow-to-region (car ibegend)
6109 (goto-char (car ibegend))
6112 (delete-region (point-min) (point-max))
6113 (mm-remove-parts handles))
6114 (setq begend (list (point-marker)))
6116 (unless (setq not-pref (cadr (member preferred ihandles)))
6117 (setq not-pref (car ihandles)))
6120 (not (gnus-unbuttonized-mime-type-p
6121 "multipart/alternative")))
6122 (add-text-properties
6125 (insert (format "%d. " id))
6129 (unless ,(not ibegend)
6130 (setq gnus-article-mime-handle-alist
6131 ',gnus-article-mime-handle-alist))
6132 (gnus-mime-display-alternative
6133 ',ihandles ',not-pref ',begend ,id))
6134 keymap ,gnus-mime-button-map
6135 mouse-face ,gnus-article-mouse-face
6136 face ,gnus-article-button-face
6138 article-type multipart
6140 (widget-convert-button 'link from (point)
6141 :action 'gnus-widget-press-button)
6143 (while (setq handle (pop handles))
6144 (add-text-properties
6147 (insert (format "(%c) %-18s"
6148 (if (equal handle preferred) ?* ? )
6149 (mm-handle-media-type handle)))
6153 (unless ,(not ibegend)
6154 (setq gnus-article-mime-handle-alist
6155 ',gnus-article-mime-handle-alist))
6156 (gnus-mime-display-alternative
6157 ',ihandles ',handle ',begend ,id))
6158 keymap ,gnus-mime-button-map
6159 mouse-face ,gnus-article-mouse-face
6160 face ,gnus-article-button-face
6164 (widget-convert-button 'link from (point)
6165 :action 'gnus-widget-press-button)
6169 (if (stringp (car preferred))
6170 (gnus-display-mime preferred)
6171 (let ((mail-parse-charset gnus-newsgroup-charset)
6172 (mail-parse-ignored-charsets
6173 (with-current-buffer gnus-summary-buffer
6174 gnus-newsgroup-ignored-charsets)))
6175 (gnus-bind-mm-vars (mm-display-part preferred))
6179 (narrow-to-region (car begend) (point-max))
6181 nil (length gnus-article-mime-handle-alist)
6182 (gnus-article-mime-total-parts)
6183 (mm-handle-media-type preferred))))))
6184 (goto-char (point-max))
6185 (setcdr begend (point-marker)))))
6188 ;; Redraw attachment buttons in the header.
6189 (when gnus-mime-display-attachment-buttons-in-header
6190 (gnus-mime-buttonize-attachments-in-header)))
6192 (defconst gnus-article-wash-status-strings
6193 (let ((alist '((cite "c" "Possible hidden citation text"
6194 " " "All citation text visible")
6195 (headers "h" "Hidden headers"
6196 " " "All headers visible.")
6197 (pgp "p" "Encrypted or signed message status hidden"
6198 " " "No hidden encryption nor digital signature status")
6199 (signature "s" "Signature has been hidden"
6200 " " "Signature is visible")
6201 (overstrike "o" "Overstrike (^H) characters applied"
6202 " " "No overstrike characters applied")
6203 (emphasis "e" "/*_Emphasis_*/ characters applied"
6204 " " "No /*_emphasis_*/ characters applied")))
6206 (dolist (entry alist result)
6207 (let ((key (nth 0 entry))
6208 (on (copy-sequence (nth 1 entry)))
6209 (on-help (nth 2 entry))
6210 (off (copy-sequence (nth 3 entry)))
6211 (off-help (nth 4 entry)))
6212 (put-text-property 0 1 'help-echo on-help on)
6213 (put-text-property 0 1 'help-echo off-help off)
6214 (push (list key on off) result))))
6215 "Alist of strings describing wash status in the mode line.
6216 Each entry has the form (KEY ON OF), where the KEY is a symbol
6217 representing the particular washing function, ON is the string to use
6218 in the article mode line when the washing function is active, and OFF
6219 is the string to use when it is inactive.")
6221 (defun gnus-article-wash-status-entry (key value)
6222 (let ((entry (assoc key gnus-article-wash-status-strings)))
6223 (if value (nth 1 entry) (nth 2 entry))))
6225 (defun gnus-article-wash-status ()
6226 "Return a string which display status of article washing."
6227 (with-current-buffer gnus-article-buffer
6228 (let ((cite (memq 'cite gnus-article-wash-types))
6229 (headers (memq 'headers gnus-article-wash-types))
6230 (boring (memq 'boring-headers gnus-article-wash-types))
6231 (pgp (memq 'pgp gnus-article-wash-types))
6232 (pem (memq 'pem gnus-article-wash-types))
6233 (signed (memq 'signed gnus-article-wash-types))
6234 (encrypted (memq 'encrypted gnus-article-wash-types))
6235 (signature (memq 'signature gnus-article-wash-types))
6236 (overstrike (memq 'overstrike gnus-article-wash-types))
6237 (emphasis (memq 'emphasis gnus-article-wash-types)))
6239 (gnus-article-wash-status-entry 'cite cite)
6240 (gnus-article-wash-status-entry 'headers (or headers boring))
6241 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6242 (gnus-article-wash-status-entry 'signature signature)
6243 (gnus-article-wash-status-entry 'overstrike overstrike)
6244 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6246 (defun gnus-add-wash-type (type)
6247 "Add a washing of TYPE to the current status."
6248 (add-to-list 'gnus-article-wash-types type))
6250 (defun gnus-delete-wash-type (type)
6251 "Add a washing of TYPE to the current status."
6252 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6254 (defun gnus-add-image (category image)
6255 "Add IMAGE of CATEGORY to the list of displayed images."
6256 (let ((entry (assq category gnus-article-image-alist)))
6258 (setq entry (list category))
6259 (push entry gnus-article-image-alist))
6260 (nconc entry (list image))))
6262 (defun gnus-delete-images (category)
6263 "Delete all images in CATEGORY."
6264 (let ((entry (assq category gnus-article-image-alist)))
6265 (dolist (image (cdr entry))
6266 (gnus-remove-image image category))
6267 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6268 (gnus-delete-wash-type category)))
6270 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6272 (defun gnus-article-maybe-hide-headers ()
6273 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6274 Provided for backwards compatibility."
6275 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6276 (not (with-current-buffer gnus-summary-buffer
6277 gnus-have-all-headers)))
6278 (not gnus-inhibit-hiding))
6279 (article-hide-headers)))
6281 (declare-function shr-put-image "shr" (data alt &optional flags))
6283 (defun gnus-shr-put-image (data alt &optional flags)
6284 "Put image DATA with a string ALT. Enable image to be deleted."
6285 (let ((image (if flags
6286 (shr-put-image data (propertize (or alt "*")
6287 'gnus-image-category 'shr)
6289 ;; Old `shr-put-image' doesn't take the optional `flags'
6291 (shr-put-image data (propertize (or alt "*")
6292 'gnus-image-category 'shr)))))
6294 (gnus-add-image 'shr image))))
6296 (defun gnus-article-mime-handles (&optional alist id all)
6298 (let ((i 1) newid flat)
6299 (dolist (handle alist flat)
6300 (setq newid (append id (list i))
6302 (if (stringp (car handle))
6303 (setq flat (nconc flat (gnus-article-mime-handles
6304 (cdr handle) newid all)))
6305 (delq (rassq handle all) all)
6306 (setq flat (nconc flat (list (cons newid handle)))))))
6307 (let ((flat (list nil)))
6308 ;; Assume that elements of `gnus-article-mime-handle-alist'
6309 ;; are in the decreasing order, but unnumbered subsidiaries
6310 ;; in each element are in the increasing order.
6311 (dolist (handle (reverse gnus-article-mime-handle-alist))
6312 (if (stringp (cadr handle))
6313 (setq flat (nconc flat (gnus-article-mime-handles
6314 (cddr handle) (list (car handle)) flat)))
6315 (delq (rassq (cdr handle) flat) flat)
6316 (setq flat (nconc flat (list (cons (list (car handle))
6318 (setq flat (cdr flat))
6319 (mapc (lambda (handle)
6321 ;; This is a hidden (i.e. unnumbered) handle.
6324 (1+ (caar gnus-article-mime-handle-alist)))
6325 (push handle gnus-article-mime-handle-alist))
6326 (setcar handle (caar handle))))
6330 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6331 "Show attachments as buttons in the end of the header of an article.
6332 This function toggles the display when called interactively. Note that
6333 buttons to be added to the header are only the ones that aren't inlined
6334 in the body. Use `gnus-header-face-alist' to highlight buttons."
6335 (interactive (list t))
6336 (gnus-with-article-buffer
6337 (let ((case-fold-search t) buttons handle type st)
6341 (article-narrow-to-head)
6342 ;; Header buttons exist?
6343 (while (and (not buttons)
6344 (re-search-forward "^attachments?:[\n ]+" nil t))
6345 (when (get-char-property (match-end 0)
6346 'gnus-button-attachment-extra)
6347 (setq buttons (match-beginning 0))))
6350 ;; Delete header buttons.
6351 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6354 (unless (and interactive buttons)
6357 (dolist (button (gnus-article-mime-handles))
6358 (setq handle (cdr button)
6359 type (mm-handle-media-type handle))
6360 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6361 (with-current-buffer gnus-summary-buffer
6362 gnus-inhibit-images)
6363 gnus-inhibit-images)
6364 (string-match "\\`image/" type))
6365 (mm-inline-override-p handle)
6366 (and (mm-handle-disposition handle)
6367 (not (equal (car (mm-handle-disposition handle))
6369 (not (mm-attachment-override-p handle)))
6370 (not (mm-automatic-display-p handle))
6371 (not (or (and (mm-inlinable-p handle)
6372 (mm-inlined-p handle))
6373 (mm-automatic-external-display-p type))))
6374 (push button buttons)))
6376 ;; Add header buttons.
6379 (narrow-to-region (point) (point))
6380 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6381 (dolist (button (nreverse buttons))
6384 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6385 (gnus-insert-mime-button handle (car button))
6386 (skip-chars-backward "\t\n ")
6387 (delete-region (point) (point-max))
6388 (when (> (current-column) (window-width))
6393 (dolist (ovl (overlays-in (point-min) (point)))
6394 (overlay-put ovl 'gnus-button-attachment-extra t)
6395 (overlay-put ovl 'face nil))
6396 (let ((gnus-treatment-function-alist
6397 '((gnus-treat-highlight-headers
6398 gnus-article-highlight-headers))))
6399 (gnus-treat-article 'head)))))))))
6403 (defun gnus-output-to-file (file-name)
6404 "Append the current article to a file named FILE-NAME.
6405 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6406 text and used as the value of the coding cookie which is added to the
6407 top of a file. Otherwise, this function saves a raw article without
6409 (let* ((artbuf (current-buffer))
6410 (file-name-coding-system nnmail-pathname-coding-system)
6411 (coding gnus-article-save-coding-system)
6412 (coding-system-for-read (if coding
6413 nil ;; Rely on the coding cookie.
6414 mm-text-coding-system))
6415 (coding-system-for-write (or coding
6416 mm-text-coding-system-for-write
6417 mm-text-coding-system))
6418 (exists (file-exists-p file-name)))
6421 (insert-file-contents file-name)
6422 (goto-char (point-min))
6423 ;; Remove the existing coding cookie.
6424 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6425 (delete-region (match-beginning 0) (match-end 0))))
6426 (goto-char (point-max))
6427 (insert-buffer-substring artbuf)
6428 ;; Append newline at end of the buffer as separator, and then
6430 (goto-char (point-max))
6433 ;; If the coding system is not suitable to encode the text,
6434 ;; ask a user for a proper one.
6435 (setq coding (coding-system-base
6436 (save-window-excursion
6437 (select-safe-coding-system (point-min) (point-max)
6439 (setq coding-system-for-write
6440 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6442 (goto-char (point-min))
6443 ;; Add the coding cookie.
6444 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6445 coding-system-for-write)))
6448 (write-region (point-min) (point-max) file-name nil 'no-message)
6449 (message "Appended to %s" file-name))
6450 (write-region (point-min) (point-max) file-name))))
6453 (defun gnus-narrow-to-page (&optional arg)
6454 "Narrow the article buffer to a page.
6455 If given a numerical ARG, move forward ARG pages."
6457 (setq arg (if arg (prefix-numeric-value arg) 0))
6458 (with-current-buffer gnus-article-buffer
6460 ;; Remove any old next/prev buttons.
6461 (when (gnus-visual-p 'page-marker)
6462 (let ((inhibit-read-only t))
6463 (gnus-remove-text-with-property 'gnus-prev)
6464 (gnus-remove-text-with-property 'gnus-next)))
6466 (when (save-excursion
6468 (if (re-search-backward page-delimiter nil 'move (abs arg))
6470 (setq nd (match-beginning 0)
6472 (when (re-search-backward page-delimiter nil t)
6473 (setq st (match-end 0))))
6474 (when (re-search-forward page-delimiter nil t)
6475 (setq nd (match-beginning 0)
6478 (if (re-search-forward page-delimiter nil 'move arg)
6480 (setq st (match-end 0)
6482 (when (re-search-forward page-delimiter nil t)
6483 (setq nd (match-beginning 0))))
6484 (when (re-search-backward page-delimiter nil t)
6485 (setq st (match-end 0)
6488 (when (re-search-backward page-delimiter nil t)
6489 (goto-char (setq st (match-end 0))))
6490 (when (re-search-forward page-delimiter nil t)
6491 (setq nd (match-beginning 0)))
6493 (setq gnus-page-broken t)
6494 (when pt (goto-char pt))
6495 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6496 (when (gnus-visual-p 'page-marker)
6500 (gnus-insert-next-page-button))
6503 (gnus-insert-prev-page-button))))))))
6505 ;; Article mode commands
6507 (defun gnus-article-goto-next-page ()
6508 "Show the next page of the article."
6510 (when (gnus-article-next-page)
6511 (goto-char (point-min))
6512 (gnus-article-read-summary-keys nil ?n)))
6515 (defun gnus-article-goto-prev-page ()
6516 "Show the previous page of the article."
6518 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6519 (gnus-article-read-summary-keys nil ?p)
6520 (gnus-article-prev-page nil)))
6522 ;; This is cleaner but currently breaks `gnus-pick-mode':
6524 ;; (defun gnus-article-goto-next-page ()
6525 ;; "Show the next page of the article."
6527 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6528 ;; (gnus-summary-next-page)))
6530 ;; (defun gnus-article-goto-prev-page ()
6531 ;; "Show the next page of the article."
6533 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6534 ;; (gnus-summary-prev-page)))
6536 (defun gnus-article-next-page (&optional lines)
6537 "Show the next page of the current article.
6538 If end of article, return non-nil. Otherwise return nil.
6539 Argument LINES specifies lines to be scrolled up."
6541 (move-to-window-line (- -1 scroll-margin))
6542 (if (and (not (and gnus-article-over-scroll
6543 (> (count-lines (window-start) (point-max))
6544 (+ (or lines (1- (window-height))) scroll-margin))))
6547 (and (pos-visible-in-window-p) ;Not continuation line.
6548 (>= (point) (point-max)))))
6549 ;; Nothing in this page.
6550 (if (or (not gnus-page-broken)
6555 (eobp)))) ;Real end-of-buffer?
6557 (when gnus-article-over-scroll
6558 (gnus-article-next-page-1 lines))
6560 (gnus-narrow-to-page 1) ;Go to next page.
6562 ;; More in this page.
6563 (gnus-article-next-page-1 lines)
6566 (defun gnus-article-beginning-of-window ()
6567 "Move point to the beginning of the window.
6568 The point is placed at the line number which `scroll-margin'
6570 ;; There is an obscure bug in Emacs that makes it impossible to
6571 ;; scroll past big pictures in the article buffer. Try to fix
6572 ;; this by adding a sanity check by counting the lines visible.
6573 (when (> (count-lines (window-start) (window-end)) 30)
6574 (move-to-window-line
6575 (min (max 0 scroll-margin)
6576 (max 1 (- (window-height)
6577 (if mode-line-format 1 0)
6578 (if header-line-format 1 0)
6581 (defvar scroll-in-place)
6583 (defun gnus-article-next-page-1 (lines)
6585 (let ((scroll-in-place nil)
6586 (auto-window-vscroll nil))
6589 ;; Long lines may cause an end-of-buffer error.
6590 (goto-char (point-max))))
6591 (gnus-article-beginning-of-window))
6593 (defun gnus-article-prev-page (&optional lines)
6594 "Show previous page of current article.
6595 Argument LINES specifies lines to be scrolled down."
6597 (move-to-window-line 0)
6598 (if (and gnus-page-broken
6600 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6602 (gnus-narrow-to-page -1) ;Go to previous page.
6603 (goto-char (point-max))
6604 (recenter (if gnus-article-over-scroll
6606 (max (+ lines scroll-margin) 3)
6607 (- (window-height) 2))
6611 (let ((scroll-in-place nil))
6612 (scroll-down lines))
6613 (beginning-of-buffer
6614 (goto-char (point-min))))
6615 (gnus-article-beginning-of-window))))
6617 (defun gnus-article-only-boring-p ()
6618 "Decide whether there is only boring text remaining in the article.
6619 Something \"interesting\" is a word of at least two letters that does
6620 not have a face in `gnus-article-boring-faces'."
6621 (when (and gnus-article-skip-boring
6622 (boundp 'gnus-article-boring-faces)
6623 (symbol-value 'gnus-article-boring-faces))
6625 (let ((inhibit-point-motion-hooks t))
6627 (while (re-search-forward "\\b\\w\\w" nil t)
6629 (when (not (gnus-intersection
6630 (gnus-faces-at (point))
6631 (symbol-value 'gnus-article-boring-faces)))
6632 (throw 'only-boring nil)))
6633 (throw 'only-boring t))))))
6635 (defun gnus-article-refer-article ()
6636 "Read article specified by message-id around point."
6639 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6640 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6641 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6642 (let ((msg-id (concat "<" (match-string 0) ">")))
6643 (set-buffer gnus-summary-buffer)
6644 (gnus-summary-refer-article msg-id))
6645 (error "No references around point"))))
6647 (defun gnus-article-show-summary ()
6648 "Reconfigure windows to show summary buffer."
6650 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6651 (error "There is no summary buffer for this article buffer")
6652 (gnus-article-set-globals)
6653 (gnus-configure-windows 'article)
6654 (gnus-summary-goto-subject gnus-current-article)
6655 (gnus-summary-position-point)))
6657 (defun gnus-article-describe-briefly ()
6658 "Describe article mode commands briefly."
6660 (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")))
6662 (defun gnus-article-check-buffer ()
6663 "Beep if not in an article buffer."
6664 (unless (derived-mode-p 'gnus-article-mode)
6665 (error "Command invoked outside of a Gnus article buffer")))
6667 (defvar gnus-pick-mode)
6669 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6670 "Read a summary buffer key sequence and execute it from the article buffer."
6672 (gnus-article-check-buffer)
6674 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6675 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6676 "=" "^" "\M-^" "|"))
6678 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6679 "An" "Ap" [?A (meta return)] [?A delete]))
6683 (with-current-buffer gnus-article-current-summary
6684 (let (gnus-pick-mode)
6685 (setq unread-command-events (nconc unread-command-events
6686 (list (or key last-command-event)))
6687 keys (read-key-sequence nil t))))
6692 ((eq (aref keys (1- (length keys))) ?\C-h)
6693 (gnus-article-describe-bindings (substring keys 0 -1)))
6694 ((or (member keys nosaves)
6695 (member keys nosave-but-article)
6696 (member keys nosave-in-article))
6698 (save-window-excursion
6699 (pop-to-buffer gnus-article-current-summary)
6700 ;; We disable the pick minor mode commands.
6701 (let (gnus-pick-mode)
6702 (setq func (key-binding keys t))))
6706 (unless (member keys nosave-in-article)
6707 (set-buffer gnus-article-current-summary))
6708 (when (and (symbolp func)
6709 (get func 'disabled))
6710 (error "Function %s disabled" func))
6711 (call-interactively func)
6712 (setq new-sum-point (point)))
6713 (when (member keys nosave-but-article)
6714 (pop-to-buffer gnus-article-buffer))))
6716 ;; These commands should restore window configuration.
6717 (let ((obuf (current-buffer))
6718 (owin (current-window-configuration))
6719 win func in-buffer selected new-sum-start new-sum-hscroll err)
6720 (cond (not-restore-window
6721 (pop-to-buffer gnus-article-current-summary)
6722 (setq win (selected-window)))
6723 ((setq win (get-buffer-window gnus-article-current-summary))
6724 (select-window win))
6726 (let ((summary-buffer gnus-article-current-summary))
6727 (gnus-configure-windows 'article)
6728 (unless (setq win (get-buffer-window summary-buffer 'visible))
6729 (let ((gnus-buffer-configuration
6730 '((article ((vertical 1.0
6731 (summary 0.25 point)
6733 (gnus-configure-windows 'article))
6734 (setq win (get-buffer-window summary-buffer 'visible)))
6735 (select-frame-set-input-focus (window-frame win))
6736 (select-window win))))
6737 (setq in-buffer (current-buffer))
6738 ;; We disable the pick minor mode commands.
6739 (setq func (let (gnus-pick-mode)
6740 (key-binding keys t)))
6741 (when (get func 'disabled)
6742 (error "Function %s disabled" func))
6745 (condition-case code
6747 (call-interactively func)
6753 (when (eq win (selected-window))
6754 (setq new-sum-point (point)
6755 new-sum-start (window-start win)
6756 new-sum-hscroll (window-hscroll win)))
6757 (when (or (eq in-buffer (current-buffer))
6758 (when (eq obuf (current-buffer))
6759 (set-buffer in-buffer)
6761 (setq selected (ignore-errors (gnus-summary-select-article)))
6763 (unless not-restore-window
6764 (set-window-configuration owin))
6765 (when (and (eq selected 'old)
6767 (set-window-start (get-buffer-window (current-buffer))
6769 (set-window-point (get-buffer-window (current-buffer))
6770 (if (article-goto-body)
6773 (when (and (not not-restore-window)
6776 (with-current-buffer (window-buffer win)
6777 (derived-mode-p 'gnus-summary-mode)))
6778 (set-window-point win new-sum-point)
6779 (set-window-start win new-sum-start)
6780 (set-window-hscroll win new-sum-hscroll))))
6781 (set-window-configuration owin)
6783 (signal (car err) (cdr err))
6786 (defun gnus-article-read-summary-send-keys ()
6788 (let ((unread-command-events (list ?S)))
6789 (gnus-article-read-summary-keys)))
6791 (defun gnus-article-describe-key (key)
6792 "Display documentation of the function invoked by KEY.
6793 KEY is a string or a vector."
6794 (interactive (list (let ((cursor-in-echo-area t))
6795 (read-key-sequence "Describe key: "))))
6796 (gnus-article-check-buffer)
6797 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6798 gnus-article-read-summary-send-keys))
6799 (with-current-buffer gnus-article-current-summary
6800 (setq unread-command-events
6802 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6803 (list 'meta (- x 128))
6806 unread-command-events))
6807 (let ((cursor-in-echo-area t)
6809 (describe-key (read-key-sequence nil t))))
6810 (describe-key key)))
6812 (defun gnus-article-describe-key-briefly (key &optional insert)
6813 "Display documentation of the function invoked by KEY.
6814 KEY is a string or a vector."
6815 (interactive (list (let ((cursor-in-echo-area t))
6816 (read-key-sequence "Describe key: "))
6817 current-prefix-arg))
6818 (gnus-article-check-buffer)
6819 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6820 gnus-article-read-summary-send-keys))
6821 (with-current-buffer gnus-article-current-summary
6822 (setq unread-command-events
6824 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6825 (list 'meta (- x 128))
6828 unread-command-events))
6829 (let ((cursor-in-echo-area t)
6831 (describe-key-briefly (read-key-sequence nil t) insert)))
6832 (describe-key-briefly key insert)))
6834 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6835 (defvar gnus-agent-summary-mode)
6836 (defvar gnus-draft-mode)
6837 (defvar help-xref-stack-item)
6838 (defvar help-xref-following)
6840 (defun gnus-article-describe-bindings (&optional prefix)
6841 "Show a list of all defined keys, and their definitions.
6842 The optional argument PREFIX, if non-nil, should be a key sequence;
6843 then we display only bindings that start with that prefix."
6845 (gnus-article-check-buffer)
6846 (let ((keymap (copy-keymap gnus-article-mode-map))
6847 (map (copy-keymap gnus-article-send-map))
6848 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6850 (define-key keymap "S" map)
6851 (define-key map [t] nil)
6852 (with-current-buffer gnus-article-current-summary
6855 (if (setq parent (keymap-parent gnus-article-mode-map))
6857 (setq parent (copy-keymap parent))
6858 (set-keymap-parent parent (current-local-map)))
6859 (current-local-map)))
6860 (set-keymap-parent map (key-binding "S"))
6861 (let (key def gnus-pick-mode)
6863 (setq key (pop sumkeys))
6864 (cond ((and (vectorp key) (= (length key) 1)
6865 (consp (setq def (aref key 0)))
6866 (numberp (car def)) (numberp (cdr def)))
6867 (when (< (max (car def) (cdr def)) 128)
6871 (nreverse (gnus-uncompress-range def)))
6873 ((setq def (key-binding key))
6874 (unless (eq def 'undefined)
6875 (define-key keymap key def))))))
6876 (when (boundp 'gnus-agent-summary-mode)
6877 (setq agent gnus-agent-summary-mode))
6878 (when (boundp 'gnus-draft-mode)
6879 (setq draft gnus-draft-mode)))
6881 (use-local-map keymap)
6882 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6883 (set (make-local-variable 'gnus-draft-mode) draft)
6884 (describe-bindings prefix))
6885 (let ((item `((lambda (prefix)
6886 (with-current-buffer ,(current-buffer)
6887 (gnus-article-describe-bindings prefix)))
6889 ;; Loading `help-mode' here is necessary if `describe-bindings'
6890 ;; is replaced with something, e.g. `helm-descbinds'.
6891 (require 'help-mode)
6892 (with-current-buffer (let (help-xref-following) (help-buffer))
6893 (setq help-xref-stack-item item)))))
6895 (defun gnus-article-reply-with-original (&optional wide)
6896 "Start composing a reply mail to the current message.
6897 The text in the region will be yanked. If the region isn't active,
6898 the entire article will be yanked."
6900 (let ((article (cdr gnus-article-current))
6902 (if (not (and transient-mark-mode mark-active))
6903 (with-current-buffer gnus-summary-buffer
6904 (gnus-summary-reply (list (list article)) wide))
6905 (setq contents (buffer-substring (point) (mark t)))
6906 ;; Deactivate active regions.
6907 (when transient-mark-mode
6908 (setq mark-active nil))
6909 (with-current-buffer gnus-summary-buffer
6911 (list (list article contents)) wide)))))
6913 (defun gnus-article-wide-reply-with-original ()
6914 "Start composing a wide reply mail to the current message.
6915 The text in the region will be yanked. If the region isn't active,
6916 the entire article will be yanked."
6918 (gnus-article-reply-with-original t))
6920 (defun gnus-article-followup-with-original ()
6921 "Compose a followup to the current article.
6922 The text in the region will be yanked. If the region isn't active,
6923 the entire article will be yanked."
6925 (let ((article (cdr gnus-article-current))
6927 (if (not (and transient-mark-mode mark-active))
6928 (with-current-buffer gnus-summary-buffer
6929 (gnus-summary-followup (list (list article))))
6930 (setq contents (buffer-substring (point) (mark t)))
6931 ;; Deactivate active regions.
6932 (when transient-mark-mode
6933 (setq mark-active nil))
6934 (with-current-buffer gnus-summary-buffer
6935 (gnus-summary-followup
6936 (list (list article contents)))))))
6938 (defun gnus-article-hide (&optional arg force)
6939 "Hide all the gruft in the current article.
6940 This means that signatures, cited text and (some) headers will be
6942 If given a prefix, show the hidden text instead."
6943 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6944 (gnus-with-article-buffer
6945 (article-hide-headers arg)
6946 (article-hide-list-identifiers)
6947 (gnus-article-hide-citation-maybe arg force)
6948 (article-hide-signature arg)))
6950 (defun gnus-check-group-server ()
6951 ;; Make sure the connection to the server is alive.
6952 (unless (gnus-server-opened
6953 (gnus-find-method-for-group gnus-newsgroup-name))
6954 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6955 (gnus-request-group gnus-newsgroup-name t)))
6957 (declare-function nneething-get-file-name "nneething" (id))
6959 (defun gnus-request-article-this-buffer (article group)
6960 "Get an article and insert it into this buffer."
6961 (let (do-update-line sparse-header)
6965 (gnus-kill-all-overlays)
6966 (setq group (or group gnus-newsgroup-name))
6968 ;; Using `gnus-request-article' directly will insert the article into
6969 ;; `nntp-server-buffer' - so we'll save some time by not having to
6970 ;; copy it from the server buffer into the article buffer.
6972 ;; We only request an article by message-id when we do not have the
6973 ;; headers for it, so we'll have to get those.
6974 (when (stringp article)
6975 (gnus-read-header article))
6977 ;; If the article number is negative, that means that this article
6978 ;; doesn't belong in this newsgroup (possibly), so we find its
6979 ;; message-id and request it by id instead of number.
6980 (when (and (numberp article)
6982 (get-buffer gnus-summary-buffer)
6983 (gnus-buffer-exists-p gnus-summary-buffer))
6984 (with-current-buffer gnus-summary-buffer
6985 (let ((header (gnus-summary-article-header article)))
6988 ((memq article gnus-newsgroup-sparse)
6989 ;; This is a sparse gap article.
6990 (setq do-update-line article)
6991 (setq article (mail-header-id header))
6992 (setq sparse-header (gnus-read-header article))
6993 (setq gnus-newsgroup-sparse
6994 (delq article gnus-newsgroup-sparse)))
6996 ;; It's a real article.
6997 (setq article (mail-header-id header)))
6999 ;; It is an extracted pseudo-article.
7000 (setq article 'pseudo)
7001 (gnus-request-pseudo-article header))))
7003 (let ((method (gnus-find-method-for-group
7004 gnus-newsgroup-name)))
7005 (when (and (eq (car method) 'nneething)
7007 (let ((dir (nneething-get-file-name
7008 (mail-header-id header))))
7009 (when (and (stringp dir)
7010 (file-directory-p dir))
7011 (setq article 'nneething)
7012 (gnus-group-enter-directory dir))))))))
7015 ;; Refuse to select canceled articles.
7016 ((and (numberp article)
7018 (get-buffer gnus-summary-buffer)
7019 (gnus-buffer-exists-p gnus-summary-buffer)
7020 (eq (cdr (with-current-buffer gnus-summary-buffer
7021 (assq article gnus-newsgroup-reads)))
7022 gnus-canceled-mark))
7024 ;; We first check `gnus-original-article-buffer'.
7025 ((and (get-buffer gnus-original-article-buffer)
7027 (with-current-buffer gnus-original-article-buffer
7028 (and (equal (car gnus-original-article) group)
7029 (eq (cdr gnus-original-article) article))))
7030 ;; `insert-buffer-substring' would incorrectly use the
7031 ;; equivalent of string-make-multibyte which amount to decoding
7032 ;; with locale-coding-system, causing failure of
7033 ;; subsequent decoding.
7034 (insert (string-to-multibyte
7035 (with-current-buffer gnus-original-article-buffer
7036 (buffer-substring (point-min) (point-max)))))
7038 ;; Check the backlog.
7039 ((and gnus-keep-backlog
7040 (gnus-backlog-request-article group article (current-buffer)))
7042 ;; Check asynchronous pre-fetch.
7043 ((gnus-async-request-fetched-article group article (current-buffer))
7044 (gnus-async-prefetch-next group article gnus-summary-buffer)
7045 (when (and (numberp article) gnus-keep-backlog)
7046 (gnus-backlog-enter-article group article (current-buffer)))
7049 ((and gnus-use-cache
7051 (gnus-cache-request-article article group))
7053 ;; Check the agent cache.
7054 ((gnus-agent-request-article article group)
7056 ;; Get the article and put into the article buffer.
7057 ((or (stringp article)
7059 (let ((gnus-override-method gnus-override-method)
7060 (methods (and (stringp article)
7061 (with-current-buffer gnus-summary-buffer
7062 (gnus-refer-article-methods))))
7063 (backend (car (gnus-find-method-for-group
7064 gnus-newsgroup-name)))
7066 (inhibit-read-only t))
7067 (when (and (null gnus-override-method)
7069 (setq gnus-override-method (pop methods)))
7072 (gnus-kill-all-overlays)
7073 (let ((gnus-newsgroup-name group))
7074 (gnus-check-group-server))
7076 ((gnus-request-article article group (current-buffer))
7077 (when (numberp article)
7078 (gnus-async-prefetch-next group article
7079 gnus-summary-buffer)
7080 (when gnus-keep-backlog
7081 (gnus-backlog-enter-article
7082 group article (current-buffer)))
7083 (when (and gnus-agent
7084 (gnus-agent-group-covered-p group))
7085 (gnus-agent-store-article article group)))
7086 (setq result 'article))
7088 (setq gnus-override-method (pop methods)))
7089 ((not (string-match "^400 "
7090 (nnheader-get-report backend)))
7091 ;; If we get 400 server disconnect, reconnect and
7092 ;; retry; otherwise, assume the article has expired.
7093 (setq result 'done))))
7094 (and (eq result 'article) 'article)))
7098 ;; Associate this article with the current summary buffer.
7099 (setq gnus-article-current-summary gnus-summary-buffer)
7101 ;; Take the article from the original article buffer
7102 ;; and place it in the buffer it's supposed to be in.
7103 (when (and (get-buffer gnus-article-buffer)
7104 (equal (buffer-name (current-buffer))
7105 (buffer-name (get-buffer gnus-article-buffer))))
7107 (if (get-buffer gnus-original-article-buffer)
7108 (set-buffer gnus-original-article-buffer)
7109 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7110 (buffer-disable-undo)
7111 (setq major-mode 'gnus-original-article-mode)
7112 (setq buffer-read-only t))
7113 (let ((inhibit-read-only t))
7115 (insert-buffer-substring gnus-article-buffer))
7116 (setq gnus-original-article (cons group article)))
7119 (run-hooks 'gnus-article-decode-hook)
7120 ;; Mark article as decoded or not.
7121 (setq gnus-article-decoded-p gnus-article-decode-hook))
7123 ;; Update sparse articles.
7124 (when (and do-update-line
7125 (or (numberp article)
7127 (let ((buf (current-buffer)))
7128 (set-buffer gnus-summary-buffer)
7129 (gnus-summary-update-article do-update-line sparse-header)
7130 (gnus-summary-goto-subject do-update-line nil t)
7131 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7133 (set-buffer buf))))))
7135 (defun gnus-block-private-groups (group)
7136 "Allows images in newsgroups to be shown, blocks images in all
7138 (if (or (gnus-news-group-p group)
7139 (gnus-member-of-valid 'global group))
7140 ;; Block nothing in news groups.
7142 ;; Block everything anywhere else.
7145 (defun gnus-blocked-images ()
7146 (if (functionp gnus-blocked-images)
7147 (funcall gnus-blocked-images gnus-newsgroup-name)
7148 gnus-blocked-images))
7154 (defcustom gnus-article-edit-mode-hook nil
7155 "Hook run in article edit mode buffers."
7156 :group 'gnus-article-various
7159 (defvar gnus-article-edit-done-function nil)
7161 (defvar gnus-article-edit-mode-map nil)
7163 ;; Should we be using derived.el for this?
7164 (unless gnus-article-edit-mode-map
7165 (setq gnus-article-edit-mode-map (make-keymap))
7166 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7168 (gnus-define-keys gnus-article-edit-mode-map
7169 "\C-c?" describe-mode
7170 "\C-c\C-c" gnus-article-edit-done
7171 "\C-c\C-k" gnus-article-edit-exit
7172 "\C-c\C-f\C-t" message-goto-to
7173 "\C-c\C-f\C-o" message-goto-from
7174 "\C-c\C-f\C-b" message-goto-bcc
7175 ;;"\C-c\C-f\C-w" message-goto-fcc
7176 "\C-c\C-f\C-c" message-goto-cc
7177 "\C-c\C-f\C-s" message-goto-subject
7178 "\C-c\C-f\C-r" message-goto-reply-to
7179 "\C-c\C-f\C-n" message-goto-newsgroups
7180 "\C-c\C-f\C-d" message-goto-distribution
7181 "\C-c\C-f\C-f" message-goto-followup-to
7182 "\C-c\C-f\C-m" message-goto-mail-followup-to
7183 "\C-c\C-f\C-k" message-goto-keywords
7184 "\C-c\C-f\C-u" message-goto-summary
7185 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7186 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7187 "\C-c\C-b" message-goto-body
7188 "\C-c\C-i" message-goto-signature
7190 "\C-c\C-t" message-insert-to
7191 "\C-c\C-n" message-insert-newsgroups
7192 "\C-c\C-o" message-sort-headers
7193 "\C-c\C-e" message-elide-region
7194 "\C-c\C-v" message-delete-not-region
7195 "\C-c\C-z" message-kill-to-signature
7196 "\M-\r" message-newline-and-reformat
7197 "\C-c\C-a" mml-attach-file
7198 "\C-a" message-beginning-of-line
7200 "\M-;" comment-region)
7202 (gnus-define-keys (gnus-article-edit-wash-map
7203 "\C-c\C-w" gnus-article-edit-mode-map)
7204 "f" gnus-article-edit-full-stops))
7207 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7209 ["Fetch To" message-insert-to t]
7210 ["Fetch Newsgroups" message-insert-newsgroups t]
7212 ["To" message-goto-to t]
7213 ["From" message-goto-from t]
7214 ["Subject" message-goto-subject t]
7215 ["Cc" message-goto-cc t]
7216 ["Reply-To" message-goto-reply-to t]
7217 ["Summary" message-goto-summary t]
7218 ["Keywords" message-goto-keywords t]
7219 ["Newsgroups" message-goto-newsgroups t]
7220 ["Followup-To" message-goto-followup-to t]
7221 ["Mail-Followup-To" message-goto-mail-followup-to t]
7222 ["Distribution" message-goto-distribution t]
7223 ["Body" message-goto-body t]
7224 ["Signature" message-goto-signature t]))
7226 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7227 "Major mode for editing articles.
7228 This is an extended text-mode.
7230 \\{gnus-article-edit-mode-map}"
7231 (make-local-variable 'gnus-article-edit-done-function)
7232 (make-local-variable 'gnus-prev-winconf)
7233 (set (make-local-variable 'font-lock-defaults)
7234 '(message-font-lock-keywords t))
7235 (set (make-local-variable 'mail-header-separator) "")
7236 (set (make-local-variable 'gnus-article-edit-mode) t)
7237 (easy-menu-add message-mode-field-menu message-mode-map)
7239 (setq buffer-read-only nil)
7240 (buffer-enable-undo)
7243 (defun gnus-article-edit (&optional force)
7244 "Edit the current article.
7245 This will have permanent effect only in mail groups.
7246 If FORCE is non-nil, allow editing of articles even in read-only
7249 (when (and (not force)
7250 (gnus-group-read-only-p))
7251 (error "The current newsgroup does not support article editing"))
7252 (gnus-with-article-buffer
7253 (article-date-original))
7254 (gnus-article-edit-article
7256 `(lambda (no-highlight)
7258 (gnus-summary-edit-article-done
7259 ,(or (mail-header-references gnus-current-headers) "")
7260 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7262 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7263 "Start editing the contents of the current article buffer."
7264 (let ((winconf (current-window-configuration)))
7265 (set-buffer gnus-article-buffer)
7266 (let ((message-auto-save-directory
7267 ;; Don't associate the article buffer with a draft file.
7269 (gnus-article-edit-mode))
7270 (funcall start-func)
7271 (set-buffer-modified-p nil)
7272 (gnus-configure-windows 'edit-article)
7273 (setq gnus-article-edit-done-function exit-func)
7274 (setq gnus-prev-winconf winconf)
7276 (gnus-message 6 "C-c C-c to end edits"))))
7278 (defun gnus-article-edit-done (&optional arg)
7279 "Update the article edits and exit."
7281 (let ((func gnus-article-edit-done-function)
7282 (buf (current-buffer))
7283 (start (window-start))
7284 (winconf gnus-prev-winconf))
7285 (widen) ;; Widen it in case that users narrowed the buffer.
7288 ;; The cache and backlog have to be flushed somewhat.
7289 (when gnus-keep-backlog
7290 (gnus-backlog-remove-article
7291 (car gnus-article-current) (cdr gnus-article-current)))
7292 ;; Flush original article as well.
7293 (gnus-flush-original-article-buffer)
7294 (when gnus-use-cache
7295 (gnus-cache-update-article
7296 (car gnus-article-current) (cdr gnus-article-current)))
7297 ;; We remove all text props from the article buffer.
7298 (kill-all-local-variables)
7299 (set-text-properties (point-min) (point-max) nil)
7301 (set-window-configuration winconf)
7303 (set-window-start (get-buffer-window buf) start)
7304 (set-window-point (get-buffer-window buf) (point)))
7305 (gnus-summary-show-article))
7307 (defun gnus-flush-original-article-buffer ()
7308 (when (get-buffer gnus-original-article-buffer)
7309 (with-current-buffer gnus-original-article-buffer
7310 (setq gnus-original-article nil))))
7312 (defun gnus-article-edit-exit ()
7313 "Exit the article editing without updating."
7315 (when (or (not (buffer-modified-p))
7316 (yes-or-no-p "Article modified; kill anyway? "))
7317 (let ((curbuf (current-buffer))
7319 (window-start (window-start)))
7321 (if (gnus-buffer-live-p gnus-original-article-buffer)
7322 (insert-buffer-substring gnus-original-article-buffer))
7323 (let ((winconf gnus-prev-winconf))
7324 (kill-all-local-variables)
7326 (set-window-configuration winconf)
7327 ;; Tippy-toe some to make sure that point remains where it was.
7328 (save-current-buffer
7330 (set-window-start (get-buffer-window (current-buffer)) window-start)
7332 (gnus-summary-show-article)))
7334 (defun gnus-article-edit-full-stops ()
7335 "Interactively repair spacing at end of sentences."
7338 (goto-char (point-min))
7339 (search-forward-regexp "^$" nil t)
7340 (let ((case-fold-search nil))
7341 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7344 ;;; Article highlights
7347 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7349 ;;; Internal Variables:
7351 (defcustom gnus-button-url-regexp
7353 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7354 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7355 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7356 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7360 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7361 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7362 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7363 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7365 "[" chars punct "]+" "[" chars "]"
7368 "Regular expression that matches URLs."
7370 :group 'gnus-article-buttons
7373 (defcustom gnus-button-valid-fqdn-regexp "\\([-A-Za-z0-9]+\\.\\)+[A-Za-z]+"
7374 "Regular expression that matches a valid FQDN."
7376 :group 'gnus-article-buttons
7379 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7380 (defcustom gnus-button-valid-localpart-regexp
7381 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7382 "Regular expression that matches a localpart of mail addresses or MIDs."
7384 :group 'gnus-article-buttons
7387 (defcustom gnus-button-man-handler 'manual-entry
7388 "Function to use for displaying man pages.
7389 The function must take at least one argument with a string naming the
7392 :type '(choice (function-item :tag "Man" manual-entry)
7393 (function-item :tag "Woman" woman)
7394 (function :tag "Other"))
7395 :group 'gnus-article-buttons)
7397 (defcustom gnus-button-mid-or-mail-regexp
7398 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7399 gnus-button-valid-fqdn-regexp
7401 "Regular expression that matches a message ID or a mail address."
7403 :group 'gnus-article-buttons
7406 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7407 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7408 Strings like this can be either a message ID or a mail address. If it is one
7409 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7410 message ID or a mail address, respectively. If this variable is set to the
7411 symbol `ask', always query the user what do do. If it is a function, this
7412 function will be called with the string as its only argument. The function
7413 must return `mid', `mail', `invalid' or `ask'."
7415 :group 'gnus-article-buttons
7416 :type '(choice (function-item :tag "Heuristic function"
7417 gnus-button-mid-or-mail-heuristic)
7422 (defcustom gnus-button-mid-or-mail-heuristic-alist
7423 '((-10.0 . ".+\\$.+@")
7426 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7427 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7428 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7429 (-1.0 . "^[^a-z]+@")
7431 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7432 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7433 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7434 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7437 (-1.0 . "^[0-9][0-9]")
7439 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7440 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7441 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7442 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7444 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7445 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7448 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7450 ;; compensation for TDMA dated mail addresses:
7451 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7453 (-20.0 . "\\.fsf@") ;; Gnus
7456 (-20.0 . "^alpine\\.")
7457 (-20.0 . "_-_") ;; Subject change in thread
7459 (-20.0 . "\\.ln@") ;; leafnode
7460 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7461 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7463 ;; (5.0 . "") ;; $local_part_len <= 7
7464 (10.0 . "^[^0-9]+@")
7465 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7466 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7469 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7471 (0.5 . "^[A-Z][a-z]")
7472 (0.5 . "^[A-Z][a-z][a-z]")
7473 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7474 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7475 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7477 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7478 address. The REGEXP is processed with `case-fold-search' set to nil."
7480 :group 'gnus-article-buttons
7481 :type '(repeat (cons (number :tag "Rate")
7482 (regexp :tag "Regexp"))))
7484 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7485 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7486 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7487 address, `ask' if unsure and `invalid' if the string is invalid."
7488 (let ((case-fold-search nil)
7489 (list gnus-button-mid-or-mail-heuristic-alist)
7490 (result 0) rate regexp lpartlen elem)
7492 (length (replace-regexp-in-string "^\\(.*\\)@.*$" "\\1" mid-or-mail)))
7493 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7494 ;; Certain special cases...
7497 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7498 "^[0-9]+\\.[0-9]+@compuserve\\|"
7499 "@public\\.gmane\\.org")
7501 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7502 (setq result 'mail))
7503 (when (string-match "@.*@\\| " mid-or-mail)
7504 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7505 (setq result 'invalid))
7506 ;; Nothing more to do, if result is not a number here...
7507 (when (numberp result)
7509 (setq elem (car list)
7513 (when (string-match regexp mid-or-mail)
7514 (setq result (+ result rate))
7516 9 "`%s' matched `%s', rate `%s', result `%s'."
7517 mid-or-mail regexp rate result)))
7518 (when (<= lpartlen 7)
7519 (setq result (+ result 5.0))
7520 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7521 mid-or-mail result))
7522 (when (>= lpartlen 12)
7523 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7525 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7526 ;; Long local part should contain realname if e-mail address,
7527 ;; too many digits: message-id.
7528 ;; $score -= 5.0 + 0.1 * $local_part_len;
7529 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7530 (setq result (+ result rate))
7532 9 "Many digits in `%s', rate `%s', result `%s'."
7533 mid-or-mail rate result))
7534 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7536 ;; Too few vowels [^aeiouy]{4,}.*@
7537 (setq result (+ result -5.0))
7539 9 "Few vowels in `%s', rate `%s', result `%s'."
7540 mid-or-mail -5.0 result))
7542 (setq result (+ result 5.0))
7544 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7545 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7546 ;; Maybe we should make this a customizable alist: (condition . 'result)
7548 ((symbolp result) result)
7549 ;; Now convert number into proper results:
7550 ((< result -10.0) 'mid)
7551 ((> result 10.0) 'mail)
7554 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7555 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7556 (url-mid (concat "news" ":" mid-or-mail))
7557 (url-mailto (concat "mailto" ":" mid-or-mail)))
7558 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7559 (when (fboundp pref)
7561 ;; get rid of surrounding angles...
7563 (replace-regexp-in-string "^<\\|>$" "" mid-or-mail)))
7564 (if (or (eq 'mid guessed) (eq 'mail guessed))
7568 (save-window-excursion
7569 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7572 (cond ((eq pref 'mid)
7573 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7574 (gnus-button-handle-news url-mid))
7576 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7577 (gnus-url-mailto url-mailto))
7578 (t (gnus-message 3 "Invalid string.")))))
7580 (defun gnus-button-handle-custom (fun arg)
7581 "Call function FUN on argument ARG.
7582 Both FUN and ARG are supposed to be strings. ARG will be passed
7583 as a symbol to FUN."
7584 (funcall (intern fun)
7585 (if (string-match "^customize-apropos" fun)
7589 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7591 (defun gnus-button-handle-describe-function (url)
7592 "Call `describe-function' when pushing the corresponding URL button."
7595 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7597 (defun gnus-button-handle-describe-variable (url)
7598 "Call `describe-variable' when pushing the corresponding URL button."
7601 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))))
7603 (defun gnus-button-handle-symbol (url)
7604 "Display help on variable or function.
7605 Calls `describe-variable' or `describe-function'."
7606 (let ((sym (intern url)))
7608 ((fboundp sym) (describe-function sym))
7609 ((boundp sym) (describe-variable sym))
7610 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7612 (defun gnus-button-handle-describe-key (url)
7613 "Call `describe-key' when pushing the corresponding URL button."
7615 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url))
7616 (keys (ignore-errors (eval `(kbd ,key-string)))))
7619 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7621 (defun gnus-button-handle-apropos (url)
7622 "Call `apropos' when pushing the corresponding URL button."
7623 (apropos (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7625 (defun gnus-button-handle-apropos-command (url)
7626 "Call `apropos' when pushing the corresponding URL button."
7628 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7630 (defun gnus-button-handle-apropos-variable (url)
7631 "Call `apropos' when pushing the corresponding URL button."
7633 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7635 (defun gnus-button-handle-apropos-documentation (url)
7636 "Call `apropos' when pushing the corresponding URL button."
7637 (apropos-documentation
7638 (replace-regexp-in-string gnus-button-handle-describe-prefix "" url)))
7640 (defun gnus-button-handle-library (url)
7641 "Call `locate-library' when pushing the corresponding URL button."
7642 (gnus-message 9 "url=`%s'" url)
7643 (let* ((lib (locate-library url))
7644 (file (replace-regexp-in-string "\\.elc" ".el" (or lib ""))))
7646 (gnus-message 1 "Cannot locale library `%s'." url)
7647 (find-file-read-only file))))
7649 (defcustom gnus-button-man-level 5
7650 "*Integer that says how many man-related buttons Gnus will show.
7651 The higher the number, the more buttons will appear and the more false
7652 positives are possible. Note that you can set this variable local to
7653 specific groups. Setting it higher in Unix groups is probably a good idea.
7654 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7655 how to set variables in specific groups."
7657 :group 'gnus-article-buttons
7658 :link '(custom-manual "(gnus)Group Parameters")
7661 (defcustom gnus-button-emacs-level 5
7662 "*Integer that says how many emacs-related buttons Gnus will show.
7663 The higher the number, the more buttons will appear and the more false
7664 positives are possible. Note that you can set this variable local to
7665 specific groups. Setting it higher in Emacs or Gnus related groups is
7666 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7667 `gnus-parameters' on how to set variables in specific groups."
7669 :group 'gnus-article-buttons
7670 :link '(custom-manual "(gnus)Group Parameters")
7673 (defcustom gnus-button-message-level 5
7674 "*Integer that says how many buttons for news or mail messages will appear.
7675 The higher the number, the more buttons will appear and the more false
7676 positives are possible."
7677 ;; mail addresses, MIDs, URLs for news, ...
7679 :group 'gnus-article-buttons
7682 (defcustom gnus-button-browse-level 5
7683 "*Integer that says how many buttons for browsing will appear.
7684 The higher the number, the more buttons will appear and the more false
7685 positives are possible."
7686 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7688 :group 'gnus-article-buttons
7691 (defcustom gnus-button-alist
7692 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7693 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7694 ((concat "\\b\\(nntp\\|news\\):\\("
7695 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7696 0 t gnus-button-handle-news 2)
7697 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7698 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7699 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7700 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7701 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7702 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7703 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7704 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7705 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7706 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7707 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7708 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7709 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7710 ;; RFC 2368 (The mailto URL scheme)
7711 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7712 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7713 ("\\bmailto:\\([^ \n\t]+\\)"
7714 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7715 ;; Info Konqueror style <info:/foo/bar baz>.
7716 ;; Must come before " Gnus home-grown style".
7717 ("\\binfo://?\\([^'\">\n\t]+\\)"
7718 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7719 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7720 ("\\binfo://\\([^'\">\n\t ]+\\)"
7721 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7722 ;; Info GNOME style <info:foo#bar_baz>
7723 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7724 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7725 ;; Info KDE style <info:(foo)bar baz>
7726 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7727 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7728 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7729 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7730 ("\\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,]*\\)\\)?"
7731 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7732 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7734 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7735 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7736 ;; Emacs help commands
7737 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7738 ;; regexp doesn't match arguments containing ` '.
7739 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7740 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7741 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7742 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7743 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7744 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7745 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7746 ;; The following entries may lead to many false positives so don't enable
7747 ;; them by default (use a high button level).
7748 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7749 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7750 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7751 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7752 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7753 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7754 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7755 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7756 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7757 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7758 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7759 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7760 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7761 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7762 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7763 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7764 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7765 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7766 ;; Unlike the other regexps we really have to require quoting
7767 ;; here to determine where it ends.
7768 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7769 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7770 ("<URL: *\\([^\n<>]*\\)>"
7771 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7772 ;; RFC 2396 (2.4.3., delims) ...
7773 ("\"URL: *\\([^\n\"]*\\)\""
7774 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7776 (gnus-button-url-regexp
7777 0 (>= gnus-button-browse-level 0) browse-url 0)
7779 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7780 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7781 gnus-button-handle-man 1)
7782 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7783 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7784 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7785 gnus-button-handle-man 1)
7786 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7787 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7788 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7789 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7790 ;; Recognizing patches to .el files. This is somewhat obscure,
7791 ;; but considering the percentage of Gnus users who hack Emacs
7793 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7794 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7795 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7796 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7797 ;; MID or mail: To avoid too many false positives we don't try to catch
7798 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7799 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7800 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7801 ;; so that non-ambiguous entries (see above) match first.
7802 (gnus-button-mid-or-mail-regexp
7803 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7804 "*Alist of regexps matching buttons in article bodies.
7806 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7807 REGEXP: is the string (case insensitive) matching text around the button (can
7808 also be Lisp expression evaluating to a string),
7809 BUTTON: is the number of the regexp grouping actually matching the button,
7810 FORM: is a Lisp expression which must eval to true for the button to
7812 CALLBACK: is the function to call when the user push this button, and each
7813 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7815 CALLBACK can also be a variable, in that case the value of that
7816 variable it the real callback function."
7817 :group 'gnus-article-buttons
7818 :type '(repeat (list (choice regexp variable sexp)
7819 (integer :tag "Button")
7821 (function :tag "Callback")
7824 (integer :tag "Regexp group")))))
7825 (put 'gnus-button-alist 'risky-local-variable t)
7827 (defcustom gnus-header-button-alist
7828 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7829 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7830 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7831 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7832 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7833 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7834 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7835 0 (>= gnus-button-browse-level 0) browse-url 0)
7836 ("^Subject:" gnus-button-url-regexp
7837 0 (>= gnus-button-browse-level 0) browse-url 0)
7838 ("^[^:]+:" gnus-button-url-regexp
7839 0 (>= gnus-button-browse-level 0) browse-url 0)
7840 ("^OpenPGP:.*url=" gnus-button-url-regexp
7841 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7842 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7843 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7844 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7845 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7846 "*Alist of headers and regexps to match buttons in article heads.
7848 This alist is very similar to `gnus-button-alist', except that each
7849 alist has an additional HEADER element first in each entry:
7851 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7853 HEADER is a regexp to match a header. For a fuller explanation, see
7854 `gnus-button-alist'."
7855 :group 'gnus-article-buttons
7856 :group 'gnus-article-headers
7857 :type '(repeat (list (regexp :tag "Header")
7858 (choice regexp variable)
7859 (integer :tag "Button")
7861 (function :tag "Callback")
7864 (integer :tag "Regexp group")))))
7865 (put 'gnus-header-button-alist 'risky-local-variable t)
7869 (defun gnus-article-push-button (event)
7870 "Check text under the mouse pointer for a callback function.
7871 If the text under the mouse pointer has a `gnus-callback' property,
7872 call it with the value of the `gnus-data' text property."
7874 (set-buffer (window-buffer (posn-window (event-start event))))
7875 (let* ((pos (posn-point (event-start event)))
7876 (data (get-text-property pos 'gnus-data))
7877 (fun (get-text-property pos 'gnus-callback)))
7880 (funcall fun data))))
7882 (defun gnus-article-press-button ()
7883 "Check text at point for a callback function.
7884 If the text at point has a `gnus-callback' property,
7885 call it with the value of the `gnus-data' text property."
7887 (let ((data (get-text-property (point) 'gnus-data))
7888 (fun (get-text-property (point) 'gnus-callback)))
7890 (funcall fun data))))
7892 (defun gnus-article-highlight (&optional force)
7893 "Highlight current article.
7894 This function calls `gnus-article-highlight-headers',
7895 `gnus-article-highlight-citation',
7896 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7897 do the highlighting. See the documentation for those functions."
7898 (interactive (list 'force))
7899 (gnus-article-highlight-headers)
7900 (gnus-article-highlight-citation force)
7901 (gnus-article-highlight-signature)
7902 (gnus-article-add-buttons)
7903 (gnus-article-add-buttons-to-head))
7905 (defun gnus-article-highlight-some (&optional _force)
7906 "Highlight current article.
7907 This function calls `gnus-article-highlight-headers',
7908 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7909 do the highlighting. See the documentation for those functions."
7910 (interactive (list 'force))
7911 (gnus-article-highlight-headers)
7912 (gnus-article-highlight-signature)
7913 (gnus-article-add-buttons))
7915 (defun gnus-article-highlight-headers ()
7916 "Highlight article headers as specified by `gnus-header-face-alist'."
7918 (gnus-with-article-headers
7919 (let (regexp header-face field-face from hpoints fpoints)
7920 (dolist (entry gnus-header-face-alist)
7921 (goto-char (point-min))
7922 (setq regexp (concat "^\\("
7923 (if (string-equal "" (nth 0 entry))
7927 header-face (nth 1 entry)
7928 field-face (nth 2 entry))
7929 (while (and (re-search-forward regexp nil t)
7933 (unless (search-forward ":" nil t)
7935 (when (and header-face
7936 (not (memq (point) hpoints)))
7937 (push (point) hpoints)
7938 (put-text-property from (point) 'face header-face))
7939 (when (and field-face
7940 (not (memq (setq from (point)) fpoints)))
7942 (if (re-search-forward "^[^ \t]" nil t)
7944 (goto-char (point-max)))
7945 (put-text-property from (point) 'face field-face)))))))
7947 (defun gnus-article-highlight-signature ()
7948 "Highlight the signature in an article.
7949 It does this by highlighting everything after
7950 `gnus-signature-separator' using the face `gnus-signature'."
7952 (gnus-with-article-buffer
7953 (let ((inhibit-point-motion-hooks t))
7955 (when (and gnus-signature-face
7956 (gnus-article-narrow-to-signature))
7957 (overlay-put (make-overlay (point-min) (point-max) nil t)
7958 'face gnus-signature-face)
7960 (gnus-article-search-signature)
7961 (let ((start (match-beginning 0))
7962 (end (set-marker (make-marker) (1+ (match-end 0)))))
7963 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7966 (defun gnus-button-in-region-p (b e prop)
7967 "Say whether PROP exists in the region."
7968 (text-property-not-all b e prop nil))
7970 (defun gnus-article-add-buttons ()
7971 "Find external references in the article and make buttons of them.
7972 \"External references\" are things like Message-IDs and URLs, as
7973 specified by `gnus-button-alist'."
7975 (gnus-with-article-buffer
7976 (let ((inhibit-point-motion-hooks t)
7977 (case-fold-search t)
7978 (alist gnus-button-alist)
7980 ;; We skip the headers.
7983 (while (setq entry (pop alist))
7984 (setq regexp (eval (car entry)))
7986 (while (re-search-forward regexp nil t)
7987 (let ((start (match-beginning (nth 1 entry)))
7988 (end (match-end (nth 1 entry)))
7989 (from (match-beginning 0)))
7990 (when (and (eval (nth 2 entry))
7991 (not (gnus-button-in-region-p
7992 start end 'gnus-callback)))
7993 ;; That optional form returned non-nil, so we add the
7995 (setq from (set-marker (make-marker) from))
7996 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7997 (gnus-article-extend-url-button from start end))
7998 (gnus-article-add-button start end
7999 'gnus-button-push (list from entry))
8002 'gnus-string (buffer-substring-no-properties
8005 (defun gnus-article-extend-url-button (beg start end)
8006 "Extend url button if url is folded into two or more lines.
8007 Return non-nil if button is extended. BEG is a marker that points to
8008 the beginning position of a text containing url. START and END are
8009 the endpoints of a url button before it is extended. The concatenated
8010 url is put as the `gnus-button-url' overlay property on the button."
8011 (let ((opoint (point))
8012 (points (list start end))
8017 (not (looking-at "[\t ]*[\">]")))
8021 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8022 (buffer-substring (point-at-bol) start)))
8024 (setq url (list (buffer-substring start end))
8025 delim (if (match-beginning 1) ">" "\""))
8027 (setq regexp (concat
8028 (when (and (looking-at
8029 message-cite-prefix-regexp)
8030 (< (match-end 0) start))
8031 (regexp-quote (match-string 0)))
8033 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8037 (and (looking-at regexp)
8040 (push (or (match-string 2)
8043 (push (setq end (or (match-end 2)
8046 (push (or (match-beginning 2)
8047 (match-beginning 1))
8049 (match-beginning 2)))
8050 (let (gnus-article-mouse-face widget-mouse-face)
8052 (gnus-article-add-button (pop points) (pop points)
8054 (list beg (assq 'gnus-button-url-regexp
8055 gnus-button-alist)))))
8056 (let ((overlay (make-overlay start end)))
8057 (overlay-put overlay 'evaporate t)
8058 (overlay-put overlay 'gnus-button-url
8059 (list (mapconcat 'identity (nreverse url) "")))
8060 (when gnus-article-mouse-face
8061 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8063 (goto-char opoint))))
8065 ;; Add buttons to the head of an article.
8066 (defun gnus-article-add-buttons-to-head ()
8067 "Add buttons to the head of the article."
8069 (gnus-with-article-headers
8071 (dolist (entry gnus-header-button-alist)
8072 ;; Each alist entry.
8073 (goto-char (point-min))
8074 (while (re-search-forward (car entry) nil t)
8075 ;; Each header matching the entry.
8076 (setq beg (match-beginning 0))
8077 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8078 (match-beginning 0))
8081 (while (re-search-forward (eval (nth 1 entry)) end t)
8082 ;; Each match within a header.
8083 (let* ((entry (cdr entry))
8084 (start (match-beginning (nth 1 entry)))
8085 (end (match-end (nth 1 entry)))
8086 (form (nth 2 entry)))
8087 (goto-char (match-end 0))
8089 (gnus-article-add-button
8090 start end (nth 3 entry)
8091 (buffer-substring (match-beginning (nth 4 entry))
8092 (match-end (nth 4 entry)))))))
8093 (goto-char end))))))
8095 ;;; External functions:
8097 (defun gnus-article-add-button (from to fun &optional data text)
8098 "Create a button between FROM and TO with callback FUN and data DATA."
8099 (when gnus-article-button-face
8100 (overlay-put (make-overlay from to nil t)
8101 'face gnus-article-button-face))
8102 (add-text-properties
8104 (nconc (and gnus-article-mouse-face
8105 (list 'mouse-face gnus-article-mouse-face))
8106 (list 'gnus-callback fun)
8107 (and data (list 'gnus-data data))))
8108 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8109 :help-echo (or text "Follow the link")
8110 :keymap gnus-url-button-map))
8112 (defun gnus-article-copy-string ()
8113 "Copy the string in the button to the kill ring."
8115 (gnus-article-check-buffer)
8116 (let ((data (get-text-property (point) 'gnus-string)))
8120 (copy-region-as-kill (point-min) (point-max))
8121 (message "Copied %s" data)))))
8123 ;;; Internal functions:
8125 (defun gnus-article-set-globals ()
8126 (with-current-buffer gnus-summary-buffer
8127 (gnus-set-global-variables)))
8129 (defun gnus-signature-toggle (end)
8130 (gnus-with-article-buffer
8131 (let ((inhibit-point-motion-hooks t))
8132 (if (text-property-any end (point-max) 'article-type 'signature)
8134 (gnus-delete-wash-type 'signature)
8135 (gnus-remove-text-properties-when
8136 'article-type 'signature end (point-max)
8137 (cons 'article-type (cons 'signature
8138 gnus-hidden-properties))))
8139 (gnus-add-wash-type 'signature)
8140 (gnus-add-text-properties-when
8141 'article-type nil end (point-max)
8142 (cons 'article-type (cons 'signature
8143 gnus-hidden-properties)))))
8144 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8145 (gnus-set-mode-line 'article))))
8147 (defun gnus-button-push (marker-and-entry)
8148 ;; Push button starting at MARKER.
8150 (let* ((marker (car marker-and-entry))
8151 (entry (cadr marker-and-entry))
8152 (regexp (car entry))
8153 (inhibit-point-motion-hooks t))
8155 ;; This is obviously true, or something bad is happening :)
8156 ;; But we need it to have the match-data
8157 (when (looking-at (or (if (symbolp regexp)
8158 (symbol-value regexp)
8160 (let ((fun (nth 3 entry))
8161 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8162 (get-char-property marker 'gnus-button-url))
8163 (mapcar (lambda (group)
8164 (let ((string (match-string group)))
8165 (set-text-properties
8166 0 (length string) nil string)
8168 (nthcdr 4 entry)))))
8174 (fboundp (symbol-value fun)))
8175 (apply (symbol-value fun) args))
8177 (gnus-message 1 "You must define `%S' to use this button"
8178 (cons fun args)))))))))
8180 (defun gnus-parse-news-url (url)
8181 (let (scheme server port group message-id articles)
8184 (goto-char (point-min))
8185 (when (looking-at "\\([A-Za-z]+\\):")
8186 (setq scheme (match-string 1))
8187 (goto-char (match-end 0)))
8188 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8189 (setq server (match-string 1))
8190 (setq port (if (stringp (match-string 3))
8191 (string-to-number (match-string 3))
8193 (goto-char (match-end 0)))
8196 ((looking-at "\\(.*@.*\\)")
8197 (setq message-id (match-string 1)))
8198 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8199 (setq group (match-string 1)
8200 articles (split-string (match-string 2) "-")))
8201 ((looking-at "\\([^/]+\\)/?")
8202 (setq group (match-string 1)))
8204 (error "Unknown news URL syntax"))))
8205 (list scheme server port group message-id articles)))
8207 (defvar nntp-port-number)
8209 (defun gnus-button-handle-news (url)
8211 (destructuring-bind (_scheme server port group message-id _articles)
8212 (gnus-parse-news-url url)
8215 (with-current-buffer gnus-summary-buffer
8217 (let ((gnus-refer-article-method
8218 (nconc (list (list 'nntp server))
8219 gnus-refer-article-method))
8220 (nntp-port-number (or port "nntp")))
8221 (gnus-message 7 "Fetching %s with %s"
8222 message-id gnus-refer-article-method)
8223 (gnus-summary-refer-article message-id))
8224 (gnus-summary-refer-article message-id))))
8226 (gnus-button-fetch-group url)))))
8228 (defun gnus-button-patch (library line)
8229 "Visit an Emacs Lisp library LIBRARY on line LINE."
8231 (let ((file (locate-library (file-name-nondirectory library))))
8233 (error "Couldn't find library %s" library))
8235 (goto-char (point-min))
8236 (forward-line (1- (string-to-number line)))))
8238 (defun gnus-button-handle-man (url)
8240 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8241 (when (eq gnus-button-man-handler 'woman)
8242 (setq url (replace-regexp-in-string "([1-9][X1a-z]*).*\\'" "" url)))
8243 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8244 (funcall gnus-button-man-handler url))
8246 (defun gnus-button-handle-info-url (url)
8247 "Fetch an info URL."
8248 (setq url (subst-char-in-string ?+ ?\ url))
8250 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8251 (gnus-info-find-node
8252 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8254 ")" (gnus-url-unhex-string (match-string 2 url)))))
8255 ((string-match "([^)\"]+)[^\"]+" url)
8257 (replace-regexp-in-string
8258 "\"" "" (replace-regexp-in-string "[\n\t ]+" " " url)))
8259 (gnus-info-find-node url))
8260 (t (error "Can't parse %s" url))))
8262 (defun gnus-button-handle-info-url-gnome (url)
8263 "Fetch GNOME style info URL."
8264 (setq url (subst-char-in-string ?_ ?\ url))
8265 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8266 (gnus-info-find-node
8268 (gnus-url-unhex-string
8269 (match-string 1 url))
8271 (or (gnus-url-unhex-string
8272 (match-string 2 url))
8274 (error "Can't parse %s" url)))
8276 (defun gnus-button-handle-info-url-kde (url)
8277 "Fetch KDE style info URL."
8278 (gnus-info-find-node (gnus-url-unhex-string url)))
8280 ;; (info) will autoload info.el
8281 (declare-function Info-menu "info" (menu-item &optional fork))
8282 (declare-function Info-index-next "info" (num))
8284 (defun gnus-button-handle-info-keystrokes (url)
8285 "Call `info' when pushing the corresponding URL button."
8286 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8287 (let (node indx comma)
8289 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8290 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8291 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8292 "\\(?:[ \t\n,]*\\)\\)?")
8294 (setq node (match-string 2 url)
8295 indx (match-string 3 url))
8296 (error "Can't parse %s" url))
8300 (when (> (length indx) 0)
8301 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8304 (setq comma (match-string 2 indx))
8305 (setq indx (match-string 1 indx))
8308 (dotimes (i (with-temp-buffer
8310 ;; Note: the XEmacs version of `how-many' takes
8311 ;; no optional argument.
8312 (goto-char (point-min))
8314 (Info-index-next 1)))
8317 (autoload 'pgg-snarf-keys-region "pgg")
8318 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8319 (declare-function pgg-display-output-buffer "pgg" (start end status))
8321 (defun gnus-button-openpgp (url)
8322 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8324 (mm-url-insert-file-contents-external url)
8325 (pgg-snarf-keys-region (point-min) (point-max))
8326 (pgg-display-output-buffer nil nil nil)))
8328 (defun gnus-button-message-id (message-id)
8330 (with-current-buffer gnus-summary-buffer
8331 (gnus-summary-refer-article message-id)))
8333 (defun gnus-button-fetch-group (address &rest _ignore)
8334 "Fetch GROUP specified by ADDRESS."
8335 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8337 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8338 ;; for nntp:// and news://
8339 (setq address (match-string 3 address)))
8340 (if (not (string-match "[:/]" address))
8341 ;; This is just a simple group url.
8342 (gnus-group-read-ephemeral-group address gnus-select-method)
8345 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8347 (error "Can't parse %s" address)
8348 (gnus-group-read-ephemeral-group
8349 (match-string 4 address)
8350 `(nntp ,(match-string 1 address)
8351 (nntp-address ,(match-string 1 address))
8352 (nntp-port-number ,(if (match-end 3)
8353 (match-string 3 address)
8356 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8358 (defun gnus-url-parse-query-string (query &optional downcase)
8359 (let (retval pairs cur key val)
8360 (setq pairs (split-string query "&"))
8362 (setq cur (car pairs)
8364 (if (not (string-match "=" cur))
8366 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8367 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8369 (setq key (downcase key)))
8370 (setq cur (assoc key retval))
8372 (setcdr cur (cons val (cdr cur)))
8373 (setq retval (cons (list key val) retval)))))
8376 (defun gnus-url-mailto (url)
8377 ;; Send mail to someone
8378 (setq url (replace-regexp-in-string "\n" " " url))
8379 (when (string-match "mailto:/*\\(.*\\)" url)
8380 (setq url (substring url (match-beginning 1) nil)))
8381 (let* ((args (gnus-url-parse-query-string
8382 (if (string-match "^\\?" url)
8384 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8385 (concat "to=" (match-string 1 url) "&"
8386 (match-string 2 url))
8387 (concat "to=" url)))))
8388 (subject (cdr-safe (assoc "subject" args)))
8392 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8395 (message-position-on-field (caar args)))
8396 (insert (replace-regexp-in-string
8398 (mapconcat 'identity (reverse (cdar args)) ", ") nil t))
8399 (setq args (cdr args)))
8402 (message-goto-subject))))
8404 (defun gnus-button-embedded-url (address)
8405 "Activate ADDRESS with `browse-url'."
8406 (browse-url (gnus-strip-whitespace address)))
8408 ;;; Next/prev buttons in the article buffer.
8410 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8411 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8413 (defvar gnus-prev-page-map
8414 (let ((map (make-sparse-keymap)))
8415 (define-key map [mouse-2] 'gnus-button-prev-page)
8416 (define-key map "\r" 'gnus-button-prev-page)
8419 (defvar gnus-next-page-map
8420 (let ((map (make-sparse-keymap)))
8421 (define-key map [mouse-2] 'gnus-button-next-page)
8422 (define-key map "\r" 'gnus-button-next-page)
8425 (defun gnus-insert-prev-page-button ()
8427 (inhibit-read-only t))
8429 gnus-prev-page-line-format nil
8430 `(keymap ,gnus-prev-page-map
8432 gnus-callback gnus-article-button-prev-page
8433 article-type annotation))
8435 ;; Exclude a newline.
8438 (when gnus-article-button-face
8439 (overlay-put (make-overlay b e nil t)
8440 'face gnus-article-button-face))
8441 (widget-convert-button
8443 :action 'gnus-button-prev-page
8444 :button-keymap gnus-prev-page-map)))
8446 (defun gnus-button-next-page (&optional _args _more-args)
8447 "Go to the next page."
8449 (let ((win (selected-window)))
8450 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8451 (gnus-article-next-page)
8452 (select-window win)))
8454 (defun gnus-button-prev-page (&optional _args _more-args)
8455 "Go to the prev page."
8457 (let ((win (selected-window)))
8458 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8459 (gnus-article-prev-page)
8460 (select-window win)))
8462 (defun gnus-insert-next-page-button ()
8464 (inhibit-read-only t))
8465 (gnus-eval-format gnus-next-page-line-format nil
8466 `(keymap ,gnus-next-page-map
8468 gnus-callback gnus-article-button-next-page
8469 article-type annotation))
8471 ;; Exclude a newline.
8474 (when gnus-article-button-face
8475 (overlay-put (make-overlay b e nil t)
8476 'face gnus-article-button-face))
8477 (widget-convert-button
8479 :action 'gnus-button-next-page
8480 :button-keymap gnus-next-page-map)))
8482 (defun gnus-article-button-next-page (_arg)
8483 "Go to the next page."
8485 (let ((win (selected-window)))
8486 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8487 (gnus-article-next-page)
8488 (select-window win)))
8490 (defun gnus-article-button-prev-page (_arg)
8491 "Go to the prev page."
8493 (let ((win (selected-window)))
8494 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8495 (gnus-article-prev-page)
8496 (select-window win)))
8498 (defvar gnus-decode-header-methods
8499 '(mail-decode-encoded-word-region)
8500 "List of methods used to decode headers.
8502 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8503 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8504 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8505 whose names match REGEXP.
8508 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8509 mail-decode-encoded-word-region
8510 (\"chinese\" . rfc1843-decode-region))
8513 (defvar gnus-decode-header-methods-cache nil)
8515 (defun gnus-multi-decode-header (start end)
8516 "Apply the functions from `gnus-encoded-word-methods' that match."
8517 (unless (and gnus-decode-header-methods-cache
8518 (eq gnus-newsgroup-name
8519 (car gnus-decode-header-methods-cache)))
8520 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8521 (dolist (x gnus-decode-header-methods)
8523 (nconc gnus-decode-header-methods-cache (list x))
8524 (if (and gnus-newsgroup-name
8525 (string-match (car x) gnus-newsgroup-name))
8526 (nconc gnus-decode-header-methods-cache
8528 (let ((xlist gnus-decode-header-methods-cache))
8531 (narrow-to-region start end)
8533 (funcall (pop xlist) (point-min) (point-max))))))
8536 ;;; Treatment top-level handling.
8539 (defvar gnus-inhibit-article-treatments nil)
8541 ;; Dynamic variables.
8542 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8543 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8544 (defvar gnus-treat-type)
8545 (defvar gnus-treat-condition)
8546 (defvar gnus-treat-length)
8548 (defun gnus-treat-article (condition
8549 &optional part-num total type)
8550 (let ((gnus-treat-condition condition)
8551 (part-number part-num)
8553 (gnus-treat-type type)
8554 (gnus-treat-length (- (point-max) (point-min)))
8555 (alist gnus-treatment-function-alist)
8556 (article-goto-body-goes-to-point-min-p t)
8560 (let ((list gnus-article-treat-types))
8562 (when (string-match (pop list) type)
8563 (throw 'found t)))))))
8564 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8566 (gnus-run-hooks 'gnus-part-display-hook)
8567 (dolist (elem alist)
8570 (when (gnus-buffer-live-p gnus-summary-buffer)
8571 (set-buffer gnus-summary-buffer))
8572 (symbol-value (car elem))))
8573 (when (and (or (consp val)
8575 (or (not gnus-inhibit-article-treatments)
8576 (eq gnus-treat-condition 'head))
8577 (gnus-treat-predicate val)
8578 (or (not (get (car elem) 'highlight))
8581 (funcall (cadr elem)))))))
8583 (defun gnus-treat-predicate (val)
8587 (gnus-treat-condition
8588 (eq gnus-treat-condition val))
8590 (stringp (car val)))
8591 (apply 'gnus-or (mapcar `(lambda (s)
8592 (string-match s ,(or gnus-newsgroup-name "")))
8595 (let ((pred (pop val)))
8598 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8600 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8602 (not (gnus-treat-predicate (car val))))
8604 (equal (car val) gnus-treat-type))
8608 (error "%S is not a valid predicate" pred)))))
8616 (eq part-number total-parts))
8618 (< gnus-treat-length val))
8620 (error "%S is not a valid value" val))))
8622 (defun gnus-article-encrypt-body (protocol &optional n)
8623 "Encrypt the article body."
8626 (or gnus-article-encrypt-protocol
8627 (gnus-completing-read "Encrypt protocol"
8628 (mapcar 'car gnus-article-encrypt-protocol-alist)
8630 current-prefix-arg))
8631 ;; User might hit `K E' instead of `K e', so prompt once.
8632 (when (and gnus-article-encrypt-protocol
8634 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8635 (error "Encrypt aborted")))
8636 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8638 (error "Can't find the encrypt protocol %s" protocol))
8639 (if (member gnus-newsgroup-name '("nndraft:delayed"
8642 (error "Can't encrypt the article in group %s"
8643 gnus-newsgroup-name))
8644 (gnus-summary-iterate n
8645 (with-current-buffer gnus-summary-buffer
8646 (let ((mail-parse-charset gnus-newsgroup-charset)
8647 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8648 (summary-buffer gnus-summary-buffer)
8650 (gnus-set-global-variables)
8651 (when (gnus-group-read-only-p)
8652 (error "The current newsgroup does not support article encrypt"))
8653 (gnus-summary-show-article t)
8655 (or (mail-header-references gnus-current-headers) ""))
8656 (set-buffer gnus-article-buffer)
8657 (let* ((inhibit-read-only t)
8659 (mapcar (lambda (field)
8660 (and (save-restriction
8661 (message-narrow-to-head)
8662 (goto-char (point-min))
8663 (search-forward field nil t))
8665 (message-narrow-to-field)
8667 (delete-region (point-min) (point-max))
8669 '("Content-Type:" "Content-Transfer-Encoding:"
8670 "Content-Disposition:"))))
8671 (message-narrow-to-head)
8672 (message-remove-header "MIME-Version")
8673 (goto-char (point-max))
8674 (setq point (point))
8675 (insert (apply 'concat headers))
8677 (narrow-to-region point (point-max))
8678 (let ((message-options message-options))
8679 (message-options-set 'message-sender user-mail-address)
8680 (message-options-set 'message-recipients user-mail-address)
8681 (message-options-set 'message-sign-encrypt 'not)
8683 (goto-char (point-min))
8684 (insert "MIME-Version: 1.0\n")
8686 (gnus-summary-edit-article-done
8687 references nil summary-buffer t))
8688 (when gnus-keep-backlog
8689 (gnus-backlog-remove-article
8690 (car gnus-article-current) (cdr gnus-article-current)))
8691 (gnus-flush-original-article-buffer)
8692 (when gnus-use-cache
8693 (gnus-cache-update-article
8694 (car gnus-article-current) (cdr gnus-article-current))))))))
8696 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8697 "The following specs can be used:
8698 %t The security MIME type
8701 %D Details if button is pressed")
8703 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8704 "The following specs can be used:
8705 %t The security MIME type
8708 %D Details if button is pressed")
8710 (defvar gnus-mime-security-button-line-format-alist
8711 '((?t gnus-tmp-type ?s)
8712 (?i gnus-tmp-info ?s)
8713 (?d gnus-tmp-details ?s)
8714 (?D gnus-tmp-pressed-details ?s)))
8716 (defvar gnus-mime-security-button-commands
8717 '((gnus-article-press-button "\r" "Show Detail")
8721 (gnus-mime-security-save-part "o" "Save...")
8730 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8733 (defvar gnus-mime-security-button-map
8734 (let ((map (make-sparse-keymap)))
8735 (define-key map [mouse-2] 'gnus-article-push-button)
8736 (define-key map [down-mouse-3] 'gnus-mime-security-button-menu)
8737 (dolist (c gnus-mime-security-button-commands)
8738 (define-key map (cadr c) (car c)))
8742 gnus-mime-security-button-menu gnus-mime-security-button-map
8743 "Security button menu."
8747 (unless (eq (car c) 'undefined)
8748 (vector (caddr c) (car c) :active t)))
8749 gnus-mime-security-button-commands))))
8751 (defun gnus-mime-security-button-menu (event prefix)
8752 "Construct a context-sensitive menu of security commands."
8753 (interactive "e\nP")
8754 (save-window-excursion
8755 (let ((pos (event-start event)))
8756 (select-window (posn-window pos))
8757 (goto-char (posn-point pos))
8758 (gnus-article-check-buffer)
8759 (popup-menu gnus-mime-security-button-menu nil prefix))))
8761 (defvar gnus-mime-security-details-buffer nil)
8763 (defvar gnus-mime-security-button-pressed nil)
8765 (defvar gnus-mime-security-show-details-inline t
8766 "If non-nil, show details in the article buffer.")
8768 (defun gnus-mime-security-verify-or-decrypt (handle)
8769 (mm-remove-parts (cdr handle))
8770 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8771 point (inhibit-read-only t))
8773 (goto-char (car region)))
8774 (setq point (point))
8775 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8776 (let* ((mm-verify-option 'known)
8777 (mm-decrypt-option 'known)
8778 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8779 (unless (eq nparts (cdr handle))
8780 (mm-destroy-parts (cdr handle))
8781 (setcdr handle nparts))))
8782 (gnus-mime-display-security handle)
8784 (delete-region (point) (cdr region))
8785 (set-marker (car region) nil)
8786 (set-marker (cdr region) nil))
8789 (defun gnus-mime-security-show-details (handle)
8790 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8792 (gnus-message 5 "No details.")
8793 (if gnus-mime-security-show-details-inline
8794 (let ((gnus-mime-security-button-pressed
8795 (not (get-text-property (point) 'gnus-mime-details)))
8796 (gnus-mime-security-button-line-format
8797 (get-text-property (point) 'gnus-line-format))
8798 (inhibit-read-only t))
8800 (while (eq (get-text-property (point) 'gnus-line-format)
8801 gnus-mime-security-button-line-format)
8805 (narrow-to-region (point) (point))
8806 (gnus-insert-mime-security-button handle))
8807 (delete-region (point)
8808 (or (text-property-not-all
8811 gnus-mime-security-button-line-format)
8814 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8815 (with-current-buffer gnus-mime-security-details-buffer
8818 (setq gnus-mime-security-details-buffer
8819 (gnus-get-buffer-create "*MIME Security Details*")))
8820 (with-current-buffer gnus-mime-security-details-buffer
8822 (goto-char (point-min)))
8823 (pop-to-buffer gnus-mime-security-details-buffer)))))
8825 (defun gnus-mime-security-press-button (handle)
8827 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8828 (gnus-mime-security-show-details handle)
8829 (gnus-mime-security-verify-or-decrypt handle))))
8831 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8832 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8835 (or (nth 2 (assoc protocol mm-verify-function-alist))
8836 (nth 2 (assoc protocol mm-decrypt-function-alist))
8838 (if (equal (car handle) "multipart/signed")
8839 " Signed" " Encrypted")
8842 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8845 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8846 gnus-tmp-pressed-details
8848 (setq gnus-tmp-details
8849 (if gnus-tmp-details
8850 (concat "\n" gnus-tmp-details)
8852 (setq gnus-tmp-pressed-details
8853 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8858 gnus-mime-security-button-line-format
8859 gnus-mime-security-button-line-format-alist
8860 `(keymap ,gnus-mime-security-button-map
8861 gnus-callback gnus-mime-security-press-button
8862 gnus-line-format ,gnus-mime-security-button-line-format
8863 gnus-mime-details ,gnus-mime-security-button-pressed
8864 article-type annotation
8867 ;; Exclude a newline.
8870 (when gnus-article-button-face
8871 (overlay-put (make-overlay b e nil t)
8872 'face gnus-article-button-face))
8873 (widget-convert-button
8876 :action 'gnus-widget-press-button
8877 :button-keymap gnus-mime-security-button-map
8881 "%S: show detail; %S: more options"
8885 (defun gnus-mime-display-security (handle)
8887 (narrow-to-region (point) (point))
8888 (unless (gnus-unbuttonized-mime-type-p (car handle))
8889 (gnus-insert-mime-security-button handle))
8890 (gnus-mime-display-part (cadr handle))
8893 (unless (gnus-unbuttonized-mime-type-p (car handle))
8894 (let ((gnus-mime-security-button-line-format
8895 gnus-mime-security-button-end-line-format))
8896 (gnus-insert-mime-security-button handle)))
8897 (mm-set-handle-multipart-parameter
8898 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8899 (goto-char (point-max))))
8901 (defun gnus-mime-security-run-function (function)
8902 "Run FUNCTION with the security part under point."
8903 (gnus-article-check-buffer)
8904 (let ((data (get-text-property (point) 'gnus-data))
8906 (when (and (stringp (car-safe data))
8907 (setq buffer (mm-handle-multipart-original-buffer data))
8908 (setq handle (cadr data)))
8909 (if (bufferp (mm-handle-buffer handle))
8911 (setq handle (cons buffer (copy-sequence (cdr handle))))
8912 (mm-handle-set-undisplayer handle nil))
8913 (setq handle (mm-make-handle
8915 (mm-handle-multipart-ctl-parameter handle 'protocol)
8916 nil nil nil nil nil nil)))
8917 (funcall function handle))))
8919 (defun gnus-mime-security-save-part ()
8920 "Save the security part under point."
8922 (gnus-mime-security-run-function 'mm-save-part))
8924 (defun gnus-mime-security-pipe-part ()
8925 "Pipe the security part under point to a process."
8927 (gnus-mime-security-run-function 'mm-pipe-part))
8931 (run-hooks 'gnus-art-load-hook)
8933 ;;; gnus-art.el ends here