1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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)
47 (autoload 'gnus-msg-mail "gnus-msg" nil t)
48 (autoload 'gnus-button-mailto "gnus-msg")
49 (autoload 'gnus-button-reply "gnus-msg" nil t)
50 (autoload 'parse-time-string "parse-time" nil nil)
51 (autoload 'ansi-color-apply-on-region "ansi-color")
52 (autoload 'mm-url-insert-file-contents-external "mm-url")
53 (autoload 'mm-extern-cache-contents "mm-extern")
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 '(invisible t intangible t)
258 "Property list to use for hiding text."
260 :group 'gnus-article-hiding)
262 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
263 ;; frames in a session.
264 (defcustom gnus-article-x-face-command
265 (if (featurep 'xemacs)
266 (if (or (gnus-image-type-available-p 'xface)
267 (gnus-image-type-available-p 'pbm))
268 'gnus-display-x-face-in-from
270 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
271 ; uncompface; } | icontopbm | ee -")
272 (if (gnus-image-type-available-p 'pbm)
273 'gnus-display-x-face-in-from
275 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
276 ; uncompface; } | icontopbm | display -"))
277 "*String or function to be executed to display an X-Face header.
278 If it is a string, the command will be executed in a sub-shell
279 asynchronously. The compressed face will be piped to this command."
280 :type `(choice string
281 (function-item gnus-display-x-face-in-from)
285 :group 'gnus-article-washing)
287 (defcustom gnus-article-x-face-too-ugly nil
288 "Regexp matching posters whose face shouldn't be shown automatically."
289 :type '(choice regexp (const nil))
290 :group 'gnus-article-washing)
292 (defcustom gnus-article-banner-alist nil
293 "Banner alist for stripping.
295 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
297 :type '(repeat (cons symbol regexp))
298 :group 'gnus-article-washing)
300 (gnus-define-group-parameter
303 "Alist of regexps (to match group names) and banner."
304 :variable-group gnus-article-washing
306 '(choice :tag "Banner"
308 (const :tag "Remove signature" signature)
309 (symbol :tag "Item in `gnus-article-banner-alist'" none)
311 (const :tag "None" nil))
313 "If non-nil, specify how to remove `banners' from articles.
315 Symbol `signature' means to remove signatures delimited by
316 `gnus-signature-separator'. Any other symbol is used to look up a
317 regular expression to match the banner in `gnus-article-banner-alist'.
318 A string is used as a regular expression to match the banner
321 (defcustom gnus-article-address-banner-alist nil
322 "Alist of mail addresses and banners.
323 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
324 to match a mail address in the From: header, BANNER is one of a symbol
325 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
326 If ADDRESS matches author's mail address, it will remove things like
327 advertisements. For example:
329 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 (regexp :tag "Address")
334 (choice :tag "Banner" :value nil
335 (const :tag "Remove signature" signature)
336 (symbol :tag "Item in `gnus-article-banner-alist'" none)
338 (const :tag "None" nil))))
340 :group 'gnus-article-washing)
342 (defmacro gnus-emphasis-custom-with-format (&rest body)
344 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
345 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 (defun gnus-emphasis-custom-value-to-external (value)
349 (gnus-emphasis-custom-with-format
350 (if (consp (car value))
351 (list (format format (car (car value)) (cdr (car value)))
353 (if (nth 1 value) 2 3)
357 (defun gnus-emphasis-custom-value-to-internal (value)
358 (gnus-emphasis-custom-with-format
359 (let ((regexp (concat "\\`"
360 (format (regexp-quote format)
361 "\\([^()]+\\)" "\\([^()]+\\)")
364 (if (string-match regexp (setq pattern (car value)))
365 (list (cons (match-string 1 pattern) (match-string 2 pattern))
370 (defcustom gnus-emphasis-alist
372 '(("\\*" "\\*" bold nil 2)
375 ("_/" "/_" underline-italic)
376 ("_\\*" "\\*_" underline-bold)
377 ("\\*/" "/\\*" bold-italic)
378 ("_\\*/" "/\\*_" underline-bold-italic))))
380 (gnus-emphasis-custom-with-format
381 (mapcar (lambda (spec)
382 (list (format format (car spec) (cadr spec))
385 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
387 '(;; I've never seen anyone use this strikethru convention whereas I've
388 ;; several times seen it triggered by normal text. --Stef
389 ;; Miles suggests that this form is sometimes used but for italics,
390 ;; so maybe we should map it to `italic'.
391 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
392 ;; 2 3 gnus-emphasis-strikethru)
393 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
394 2 3 gnus-emphasis-underline))))
395 "*Alist that says how to fontify certain phrases.
396 Each item looks like this:
398 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
400 The first element is a regular expression to be matched. The second
401 is a number that says what regular expression grouping used to find
402 the entire emphasized word. The third is a number that says what
403 regexp grouping should be displayed and highlighted. The fourth
404 is the face used for highlighting."
408 :format "%[Customizing Style%]\n%v"
410 (group :tag "Default"
411 :value ("" 0 0 default)
414 (let ((value (widget-get
415 (cadr (widget-get (widget-get widget :parent)
418 (if (not (eq (nth 2 value) 'default))
422 (gnus-emphasis-custom-value-to-external value))))
423 (widget-group-value-create widget))
425 (integer :format "Match group: %v")
426 (integer :format "Emphasize group: %v")
429 :value (("_" . "_") nil default)
431 (regexp :format "Start regexp: %v")
432 (regexp :format "End regexp: %v"))
433 (boolean :format "Show start and end patterns: %[%v%]\n"
434 :on " On " :off " Off ")
436 :get (lambda (symbol)
437 (mapcar 'gnus-emphasis-custom-value-to-internal
438 (default-value symbol)))
439 :set (lambda (symbol value)
440 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
442 :group 'gnus-article-emphasis)
444 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
445 "A regexp to describe whitespace which should not be emphasized.
446 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
447 The former avoids underlining of leading and trailing whitespace,
448 and the latter avoids underlining any whitespace at all."
450 :group 'gnus-article-emphasis
453 (defface gnus-emphasis-bold '((t (:bold t)))
454 "Face used for displaying strong emphasized text (*word*)."
455 :group 'gnus-article-emphasis)
457 (defface gnus-emphasis-italic '((t (:italic t)))
458 "Face used for displaying italic emphasized text (/word/)."
459 :group 'gnus-article-emphasis)
461 (defface gnus-emphasis-underline '((t (:underline t)))
462 "Face used for displaying underlined emphasized text (_word_)."
463 :group 'gnus-article-emphasis)
465 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
466 "Face used for displaying underlined bold emphasized text (_*word*_)."
467 :group 'gnus-article-emphasis)
469 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
470 "Face used for displaying underlined italic emphasized text (_/word/_)."
471 :group 'gnus-article-emphasis)
473 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
474 "Face used for displaying bold italic emphasized text (/*word*/)."
475 :group 'gnus-article-emphasis)
477 (defface gnus-emphasis-underline-bold-italic
478 '((t (:bold t :italic t :underline t)))
479 "Face used for displaying underlined bold italic emphasized text.
480 Example: (_/*word*/_)."
481 :group 'gnus-article-emphasis)
483 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
484 '((t (:strikethru t)))
485 '((t (:strike-through t))))
486 "Face used for displaying strike-through text (-word-)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-highlight-words
490 '((t (:background "black" :foreground "yellow")))
491 "Face used for displaying highlighted words."
492 :group 'gnus-article-emphasis)
494 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
495 "Format for display of Date headers in article bodies.
496 See `format-time-string' for the possible values.
498 The variable can also be function, which should return a complete Date
499 header. The function is called with one argument, the time, which can
500 be fed to `format-time-string'."
501 :type '(choice string function)
502 :link '(custom-manual "(gnus)Article Date")
503 :group 'gnus-article-washing)
505 (defcustom gnus-save-all-headers t
506 "*If non-nil, don't remove any headers before saving.
507 This will be overridden by the `:headers' property that the symbol of
508 the saver function, which is specified by `gnus-default-article-saver',
510 :group 'gnus-article-saving
513 (defcustom gnus-prompt-before-saving 'always
514 "*This variable says how much prompting is to be done when saving articles.
515 If it is nil, no prompting will be done, and the articles will be
516 saved to the default files. If this variable is `always', each and
517 every article that is saved will be preceded by a prompt, even when
518 saving large batches of articles. If this variable is neither nil not
519 `always', there the user will be prompted once for a file name for
520 each invocation of the saving commands."
521 :group 'gnus-article-saving
522 :type '(choice (item always)
523 (item :tag "never" nil)
524 (sexp :tag "once" :format "%t\n" :value t)))
526 (defcustom gnus-saved-headers gnus-visible-headers
527 "Headers to keep if `gnus-save-all-headers' is nil.
528 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
529 If that variable is nil, however, all headers that match this regexp
530 will be kept while the rest will be deleted before saving. This and
531 `gnus-save-all-headers' will be overridden by the `:headers' property
532 that the symbol of the saver function, which is specified by
533 `gnus-default-article-saver', might have."
534 :group 'gnus-article-saving
537 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
538 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
539 "A function to save articles in your favorite format.
540 The function will be called by way of the `gnus-summary-save-article'
541 command, and friends such as `gnus-summary-save-article-rmail'.
543 Gnus provides the following functions:
545 * gnus-summary-save-in-rmail (Rmail format)
546 * gnus-summary-save-in-mail (Unix mail format)
547 * gnus-summary-save-in-folder (MH folder)
548 * gnus-summary-save-in-file (article format)
549 * gnus-summary-save-body-in-file (article body)
550 * gnus-summary-save-in-vm (use VM's folder format)
551 * gnus-summary-write-to-file (article format -- overwrite)
552 * gnus-summary-write-body-to-file (article body -- overwrite)
553 * gnus-summary-save-in-pipe (article format)
555 The symbol of each function may have the following properties:
558 The value non-nil means save decoded articles. This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
561 `gnus-summary-save-in-pipe'.
564 The value specifies an alternative function which appends, not
565 overwrites, articles to a file. This implies that when saving many
566 articles at a time, `gnus-prompt-before-saving' is bound to t and all
567 articles are saved in a single file. This is meaningful only with
568 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
571 The value specifies the symbol of a variable of which the value
572 specifies headers to be saved. If it is omitted,
573 `gnus-save-all-headers' and `gnus-saved-headers' control what
574 headers should be saved."
575 :group 'gnus-article-saving
576 :type '(radio (function-item gnus-summary-save-in-rmail)
577 (function-item gnus-summary-save-in-mail)
578 (function-item gnus-summary-save-in-folder)
579 (function-item gnus-summary-save-in-file)
580 (function-item gnus-summary-save-body-in-file)
581 (function-item gnus-summary-save-in-vm)
582 (function-item gnus-summary-write-to-file)
583 (function-item gnus-summary-write-body-to-file)
584 (function-item gnus-summary-save-in-pipe)
587 (defcustom gnus-article-save-coding-system
588 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
589 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
590 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
591 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
592 "Coding system used to save decoded articles to a file.
594 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
595 which can safely encode any characters in text. This is used by the
598 * gnus-summary-save-article-file
599 * gnus-summary-save-article-body-file
600 * gnus-summary-write-article-file
601 * gnus-summary-write-article-body-file
603 and the functions to which you may set `gnus-default-article-saver':
605 * gnus-summary-save-in-file
606 * gnus-summary-save-body-in-file
607 * gnus-summary-write-to-file
608 * gnus-summary-write-body-to-file
610 Those commands and functions save just text displayed in the article
611 buffer to a file if the value of this variable is non-nil. Note that
612 buttonized MIME parts will be lost in a saved file in that case.
613 Otherwise, raw articles will be saved."
614 :group 'gnus-article-saving
616 :format "%{%t%}:\n %[Value Menu%] %v"
617 (const :tag "Save raw articles" nil)
620 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
621 '((const :tag "UTF-8" utf-8)
622 (const :tag "iso-2022-7bit" iso-2022-7bit)
623 (const :tag "Emacs internal" emacs-mule)
624 (const :tag "escape-quoted" escape-quoted))))
625 (symbol :tag "Coding system")))
627 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
628 "A function generating a file name to save articles in Rmail format.
629 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
630 :group 'gnus-article-saving
633 (defcustom gnus-mail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Unix mail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
639 (defcustom gnus-folder-save-name 'gnus-folder-save-name
640 "A function generating a file name to save articles in MH folder.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
642 :group 'gnus-article-saving
645 (defcustom gnus-file-save-name 'gnus-numeric-save-name
646 "A function generating a file name to save articles in article format.
647 The function is called with NEWSGROUP, HEADERS, and optional
649 :group 'gnus-article-saving
652 (defcustom gnus-split-methods
653 '((gnus-article-archive-name)
654 (gnus-article-nndoc-name))
655 "*Variable used to suggest where articles are to be saved.
656 For instance, if you would like to save articles related to Gnus in
657 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
658 you could set this variable to something like:
660 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
661 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
663 This variable is an alist where the key is the match and the
664 value is a list of possible files to save in if the match is
667 If the match is a string, it is used as a regexp match on the
668 article. If the match is a symbol, that symbol will be funcalled
669 from the buffer of the article to be saved with the newsgroup as the
670 parameter. If it is a list, it will be evalled in the same buffer.
672 If this form or function returns a string, this string will be used as a
673 possible file name; and if it returns a non-nil list, that list will be
674 used as possible file names."
675 :group 'gnus-article-saving
676 :type '(repeat (choice (list :value (fun) function)
677 (cons :value ("" "") regexp (repeat string))
680 (defcustom gnus-page-delimiter "^\^L"
681 "*Regexp describing what to use as article page delimiters.
682 The default value is \"^\^L\", which is a form linefeed at the
683 beginning of a line."
685 :group 'gnus-article-various)
687 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
688 "*The format specification for the article mode line.
689 See `gnus-summary-mode-line-format' for a closer description.
691 The following additional specs are available:
693 %w The article washing status.
694 %m The number of MIME parts in the article."
697 :group 'gnus-article-various)
699 (defcustom gnus-article-mode-hook nil
700 "*A hook for Gnus article mode."
702 :group 'gnus-article-various)
704 (when (featurep 'xemacs)
705 ;; Extracted from gnus-xmas-define in order to preserve user settings
706 (when (fboundp 'turn-off-scroll-in-place)
707 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
708 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
709 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
711 (defcustom gnus-article-menu-hook nil
712 "*Hook run after the creation of the article mode menu."
714 :group 'gnus-article-various)
716 (defcustom gnus-article-prepare-hook nil
717 "*A hook called after an article has been prepared in the article buffer."
719 :group 'gnus-article-various)
721 (defcustom gnus-copy-article-ignored-headers nil
722 "List of headers to be removed when copying an article.
723 Each element is a regular expression."
724 :version "23.1" ;; No Gnus
725 :type '(repeat regexp)
726 :group 'gnus-article-various)
728 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
729 "Gnus 5.10 (Emacs 22.1)")
732 '((t (:weight bold)))
733 "Face used for highlighting a button in the article buffer."
734 :group 'gnus-article-buttons)
736 (defcustom gnus-article-button-face 'gnus-button
737 "Face used for highlighting buttons in the article buffer.
739 An article button is a piece of text that you can activate by pressing
740 `RET' or `mouse-2' above it."
742 :group 'gnus-article-buttons)
744 (defcustom gnus-article-mouse-face 'highlight
745 "Face used for mouse highlighting in the article buffer.
747 Article buttons will be displayed in this face when the cursor is
750 :group 'gnus-article-buttons)
752 (defcustom gnus-signature-face 'gnus-signature
753 "Face used for highlighting a signature in the article buffer.
754 Obsolete; use the face `gnus-signature' for customizations instead."
756 :group 'gnus-article-highlight
757 :group 'gnus-article-signature)
759 (defface gnus-signature
762 "Face used for highlighting a signature in the article buffer."
763 :group 'gnus-article-highlight
764 :group 'gnus-article-signature)
765 ;; backward-compatibility alias
766 (put 'gnus-signature-face 'face-alias 'gnus-signature)
767 (put 'gnus-signature-face 'obsolete-face "22.1")
769 (defface gnus-header-from
772 (:foreground "PaleGreen1"))
775 (:foreground "red3"))
778 "Face used for displaying from headers."
779 :group 'gnus-article-headers
780 :group 'gnus-article-highlight)
781 ;; backward-compatibility alias
782 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
783 (put 'gnus-header-from-face 'obsolete-face "22.1")
785 (defface gnus-header-subject
788 (:foreground "SeaGreen1"))
791 (:foreground "red4"))
793 (:bold t :italic t)))
794 "Face used for displaying subject headers."
795 :group 'gnus-article-headers
796 :group 'gnus-article-highlight)
797 ;; backward-compatibility alias
798 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
799 (put 'gnus-header-subject-face 'obsolete-face "22.1")
801 (defface gnus-header-newsgroups
804 (:foreground "yellow" :italic t))
807 (:foreground "MidnightBlue" :italic t))
810 "Face used for displaying newsgroups headers.
811 In the default setup this face is only used for crossposted
813 :group 'gnus-article-headers
814 :group 'gnus-article-highlight)
815 ;; backward-compatibility alias
816 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
817 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
819 (defface gnus-header-name
822 (:foreground "SpringGreen2"))
825 (:foreground "maroon"))
828 "Face used for displaying header names."
829 :group 'gnus-article-headers
830 :group 'gnus-article-highlight)
831 ;; backward-compatibility alias
832 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
833 (put 'gnus-header-name-face 'obsolete-face "22.1")
835 (defface gnus-header-content
838 (:foreground "SpringGreen1" :italic t))
841 (:foreground "indianred4" :italic t))
843 (:italic t))) "Face used for displaying header content."
844 :group 'gnus-article-headers
845 :group 'gnus-article-highlight)
846 ;; backward-compatibility alias
847 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
848 (put 'gnus-header-content-face 'obsolete-face "22.1")
850 (defcustom gnus-header-face-alist
851 '(("From" nil gnus-header-from)
852 ("Subject" nil gnus-header-subject)
853 ("Newsgroups:.*," nil gnus-header-newsgroups)
854 ("" gnus-header-name gnus-header-content))
855 "*Controls highlighting of article headers.
857 An alist of the form (HEADER NAME CONTENT).
859 HEADER is a regular expression which should match the name of a
860 header and NAME and CONTENT are either face names or nil.
862 The name of each header field will be displayed using the face
863 specified by the first element in the list where HEADER matches
864 the header name and NAME is non-nil. Similarly, the content will
865 be displayed by the first non-nil matching CONTENT face."
866 :group 'gnus-article-headers
867 :group 'gnus-article-highlight
868 :type '(repeat (list (regexp :tag "Header")
870 (item :tag "skip" nil)
871 (face :value default))
872 (choice :tag "Content"
873 (item :tag "skip" nil)
874 (face :value default)))))
876 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
877 '((xface . (:face gnus-x-face)))
878 '((pbm . (:face gnus-x-face))
880 "Alist of image types and properties applied to Face and X-Face images.
883 ;; Specify the altitude of Face images in the From header.
884 \(setq gnus-face-properties-alist
885 '((pbm . (:face gnus-x-face :ascent 80))
886 (png . (:ascent 80))))
888 ;; Show Face images as pressed buttons.
889 \(setq gnus-face-properties-alist
890 '((pbm . (:face gnus-x-face :relief -2))
891 (png . (:relief -2))))
893 See the manual for the valid properties for various image types.
894 Currently, `pbm' is used for X-Face images and `png' is used for Face
895 images in Emacs. Only the `:face' property is effective on the `xface'
896 image type in XEmacs if it is built with the libcompface library."
897 :version "23.1" ;; No Gnus
898 :group 'gnus-article-headers
899 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
901 (defcustom gnus-article-decode-hook
902 '(article-decode-charset article-decode-encoded-words
903 article-decode-group-name article-decode-idna-rhs)
904 "*Hook run to decode charsets in articles."
905 :group 'gnus-article-headers
908 (defcustom gnus-display-mime-function 'gnus-display-mime
909 "Function to display MIME articles."
910 :group 'gnus-article-mime
913 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
914 "Function used to decode headers.")
916 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
917 "Function used to decode addresses.")
919 (defvar gnus-article-dumbquotes-map
939 "Table for MS-to-Latin1 translation.")
941 (defcustom gnus-ignored-mime-types nil
942 "List of MIME types that should be ignored by Gnus."
944 :group 'gnus-article-mime
945 :type '(repeat regexp))
947 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
948 "List of MIME types that should not be given buttons when rendered inline.
949 See also `gnus-buttonized-mime-types' which may override this variable.
950 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
952 :group 'gnus-article-mime
953 :type '(repeat regexp))
955 (defcustom gnus-buttonized-mime-types nil
956 "List of MIME types that should be given buttons when rendered inline.
957 If set, this variable overrides `gnus-unbuttonized-mime-types'.
958 To see e.g. security buttons you could set this to
959 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
960 this list to display radio buttons that allow you to choose one of two
961 media types those mails include. See also `mm-discouraged-alternatives'.
962 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
964 :group 'gnus-article-mime
965 :type '(repeat regexp))
967 (defcustom gnus-inhibit-mime-unbuttonizing nil
968 "If non-nil, all MIME parts get buttons.
969 When nil (the default value), then some MIME parts do not get buttons,
970 as described by the variables `gnus-buttonized-mime-types' and
971 `gnus-unbuttonized-mime-types'."
973 :group 'gnus-article-mime
976 (defcustom gnus-body-boundary-delimiter "_"
977 "String used to delimit header and body.
978 This variable is used by `gnus-article-treat-body-boundary' which can
979 be controlled by `gnus-treat-body-boundary'."
981 :group 'gnus-article-various
982 :type '(choice (item :tag "None" :value nil)
985 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
987 "Defines the location of the faces database.
988 For information on obtaining this database of pretty pictures, please
989 see http://www.cs.indiana.edu/picons/ftp/index.html"
991 :type '(repeat directory)
992 :link '(url-link :tag "download"
993 "http://www.cs.indiana.edu/picons/ftp/index.html")
994 :link '(custom-manual "(gnus)Picons")
997 (defun gnus-picons-installed-p ()
998 "Say whether picons are installed on your machine."
999 (let ((installed nil))
1000 (dolist (database gnus-picon-databases)
1001 (when (file-exists-p database)
1002 (setq installed t)))
1005 (defcustom gnus-article-mime-part-function nil
1006 "Function called with a MIME handle as the argument.
1007 This is meant for people who want to do something automatic based
1008 on parts -- for instance, adding Vcard info to a database."
1009 :group 'gnus-article-mime
1010 :type '(choice (const nil)
1013 (defcustom gnus-mime-multipart-functions nil
1014 "An alist of MIME types to functions to display them."
1016 :group 'gnus-article-mime
1017 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1019 (defcustom gnus-article-date-headers '(combined-lapsed)
1020 "A list of Date header formats to display.
1021 Valid formats are `ut' (universal time), `local' (local time
1022 zone), `english' (readable English), `lapsed' (elapsed time),
1023 `combined-lapsed' (both the original date and the elapsed time),
1024 `original' (the original date header), `iso8601' (ISO8601
1025 format), and `user-defined' (a user-defined format defined by the
1026 `gnus-article-time-format' variable).
1028 You have as many date headers as you want in the article buffer.
1029 Some of these headers are updated automatically. See
1030 `gnus-article-update-date-headers' for details."
1032 :group 'gnus-article-headers
1034 (const :tag "Universal time (UT)" ut)
1035 (const :tag "Local time zone" local)
1036 (const :tag "Readable English" english)
1037 (const :tag "Elapsed time" lapsed)
1038 (const :tag "Original and elapsed time" combined-lapsed)
1039 (const :tag "Original date header" original)
1040 (const :tag "ISO8601 format" iso8601)
1041 (const :tag "User-defined" user-defined)))
1043 (defcustom gnus-article-update-date-headers nil
1044 "A number that says how often to update the date header (in seconds).
1045 If nil, don't update it at all."
1047 :group 'gnus-article-headers
1049 (item :tag "Don't update" :value nil)
1052 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1053 "Function called with a MIME handle as the argument.
1054 This is meant for people who want to view first matched part.
1055 For `undisplayed-alternative' (default), the first undisplayed
1056 part or alternative part is used. For `undisplayed', the first
1057 undisplayed part is used. For a function, the first part which
1058 the function return t is used. For nil, the first part is
1061 :group 'gnus-article-mime
1063 (item :tag "first" :value nil)
1064 (item :tag "undisplayed" :value undisplayed)
1065 (item :tag "undisplayed or alternative"
1066 :value undisplayed-alternative)
1069 (defcustom gnus-mime-action-alist
1070 '(("save to file" . gnus-mime-save-part)
1071 ("save and strip" . gnus-mime-save-part-and-strip)
1072 ("replace with file" . gnus-mime-replace-part)
1073 ("delete part" . gnus-mime-delete-part)
1074 ("display as text" . gnus-mime-inline-part)
1075 ("view the part" . gnus-mime-view-part)
1076 ("pipe to command" . gnus-mime-pipe-part)
1077 ("toggle display" . gnus-article-press-button)
1078 ("toggle display" . gnus-article-view-part-as-charset)
1079 ("view as type" . gnus-mime-view-part-as-type)
1080 ("view internally" . gnus-mime-view-part-internally)
1081 ("view externally" . gnus-mime-view-part-externally))
1082 "An alist of actions that run on the MIME attachment."
1083 :group 'gnus-article-mime
1084 :type '(repeat (cons (string :tag "name")
1087 (defcustom gnus-auto-select-part 1
1088 "Advance to next MIME part when deleting or stripping parts.
1090 When 0, point will be placed on the same part as before. When
1091 positive (negative), move point forward (backwards) this many
1092 parts. When nil, redisplay article."
1093 :version "23.1" ;; No Gnus
1094 :group 'gnus-article-mime
1095 :type '(choice (const nil :tag "Redisplay article.")
1096 (const 1 :tag "Next part.")
1097 (const 0 :tag "Current part.")
1101 ;;; The treatment variables
1104 (defvar gnus-part-display-hook nil
1105 "Hook called on parts that are to receive treatment.")
1107 (defvar gnus-article-treat-custom
1108 '(choice (const :tag "Off" nil)
1110 (const :tag "Header" head)
1111 (const :tag "First" first)
1112 (const :tag "Last" last)
1113 (integer :tag "Less")
1114 (repeat :tag "Groups" regexp)
1115 (sexp :tag "Predicate")))
1117 (defvar gnus-article-treat-head-custom
1118 '(choice (const :tag "Off" nil)
1119 (const :tag "Header" head)))
1121 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1122 "text/x-patch" "text/html")
1123 "Part types eligible for treatment.")
1125 (defvar gnus-inhibit-treatment nil
1126 "Whether to inhibit treatment.")
1128 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1129 "Highlight the signature.
1130 Valid values are nil, t, `head', `first', `last', an integer or a
1131 predicate. See Info node `(gnus)Customizing Articles'."
1132 :group 'gnus-article-treat
1133 :link '(custom-manual "(gnus)Customizing Articles")
1134 :type gnus-article-treat-custom)
1135 (put 'gnus-treat-highlight-signature 'highlight t)
1137 (defcustom gnus-treat-buttonize 100000
1139 Valid values are nil, t, `head', `first', `last', an integer or a
1140 predicate. See Info node `(gnus)Customizing Articles'."
1141 :group 'gnus-article-treat
1142 :link '(custom-manual "(gnus)Customizing Articles")
1143 :type gnus-article-treat-custom)
1144 (put 'gnus-treat-buttonize 'highlight t)
1146 (defcustom gnus-treat-buttonize-head 'head
1147 "Add buttons to the head.
1148 Valid values are nil, t, `head', `first', `last', an integer or a
1149 predicate. See Info node `(gnus)Customizing Articles'."
1150 :group 'gnus-article-treat
1151 :link '(custom-manual "(gnus)Customizing Articles")
1152 :type gnus-article-treat-head-custom)
1153 (put 'gnus-treat-buttonize-head 'highlight t)
1155 (defcustom gnus-treat-date 'head
1156 "Display dates according to the `gnus-article-date-headers' variable.
1157 Valid values are nil, t, `head', `first', `last', an integer or a
1158 predicate. See Info node `(gnus)Customizing Articles'."
1160 :group 'gnus-article-treat
1161 :link '(custom-manual "(gnus)Customizing Articles")
1162 :type gnus-article-treat-head-custom)
1164 (defcustom gnus-treat-emphasize 50000
1166 Valid values are nil, t, `head', `first', `last', an integer or a
1167 predicate. See Info node `(gnus)Customizing Articles'."
1168 :group 'gnus-article-treat
1169 :link '(custom-manual "(gnus)Customizing Articles")
1170 :type gnus-article-treat-custom)
1171 (put 'gnus-treat-emphasize 'highlight t)
1173 (defcustom gnus-treat-strip-cr nil
1174 "Remove carriage returns.
1175 Valid values are nil, t, `head', `first', `last', an integer or a
1176 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1182 (defcustom gnus-treat-unsplit-urls nil
1183 "Remove newlines from within URLs.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1187 :group 'gnus-article-treat
1188 :link '(custom-manual "(gnus)Customizing Articles")
1189 :type gnus-article-treat-custom)
1191 (defcustom gnus-treat-leading-whitespace nil
1192 "Remove leading whitespace in headers.
1193 Valid values are nil, t, `head', `first', `last', an integer or a
1194 predicate. See Info node `(gnus)Customizing Articles'."
1196 :group 'gnus-article-treat
1197 :link '(custom-manual "(gnus)Customizing Articles")
1198 :type gnus-article-treat-custom)
1200 (defcustom gnus-treat-hide-headers 'head
1202 Valid values are nil, t, `head', `first', `last', an integer or a
1203 predicate. See Info node `(gnus)Customizing Articles'."
1204 :group 'gnus-article-treat
1205 :link '(custom-manual "(gnus)Customizing Articles")
1206 :type gnus-article-treat-head-custom)
1208 (defcustom gnus-treat-hide-boring-headers nil
1209 "Hide boring headers.
1210 Valid values are nil, t, `head', `first', `last', an integer or a
1211 predicate. See Info node `(gnus)Customizing Articles'."
1212 :group 'gnus-article-treat
1213 :link '(custom-manual "(gnus)Customizing Articles")
1214 :type gnus-article-treat-head-custom)
1216 (defcustom gnus-treat-hide-signature nil
1217 "Hide the signature.
1218 Valid values are nil, t, `head', `first', `last', an integer or a
1219 predicate. See Info node `(gnus)Customizing Articles'."
1220 :group 'gnus-article-treat
1221 :link '(custom-manual "(gnus)Customizing Articles")
1222 :type gnus-article-treat-custom)
1224 (defcustom gnus-treat-fill-article nil
1226 Valid values are nil, t, `head', `first', `last', an integer or a
1227 predicate. See Info node `(gnus)Customizing Articles'."
1228 :group 'gnus-article-treat
1229 :link '(custom-manual "(gnus)Customizing Articles")
1230 :type gnus-article-treat-custom)
1232 (defcustom gnus-treat-hide-citation nil
1234 Valid values are nil, t, `head', `first', `last', an integer or a
1235 predicate. See Info node `(gnus)Customizing Articles'.
1237 See `gnus-article-highlight-citation' for variables used to
1238 control what it hides."
1239 :group 'gnus-article-treat
1240 :link '(custom-manual "(gnus)Customizing Articles")
1241 :type gnus-article-treat-custom)
1243 (defcustom gnus-treat-hide-citation-maybe nil
1244 "Hide cited text according to certain conditions.
1245 Valid values are nil, t, `head', `first', `last', an integer or a
1246 predicate. See Info node `(gnus)Customizing Articles'.
1248 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1249 how to control what it hides."
1250 :group 'gnus-article-treat
1251 :link '(custom-manual "(gnus)Customizing Articles")
1252 :type gnus-article-treat-custom)
1254 (defcustom gnus-treat-strip-list-identifiers 'head
1255 "Strip list identifiers from `gnus-list-identifiers`.
1256 Valid values are nil, t, `head', `first', `last', an integer or a
1257 predicate. See Info node `(gnus)Customizing Articles'."
1259 :group 'gnus-article-treat
1260 :link '(custom-manual "(gnus)Customizing Articles")
1261 :type gnus-article-treat-custom)
1263 (gnus-define-group-parameter
1266 "Alist of regexps and correspondent identifiers."
1267 :variable-group gnus-article-washing
1269 '(choice :tag "Identifier"
1271 (symbol :tag "Item in `gnus-list-identifiers'" none)
1273 (const :tag "None" nil))
1275 "If non-nil, specify how to remove `identifiers' from articles' subject.
1277 Any symbol is used to look up a regular expression to match the
1278 banner in `gnus-list-identifiers'. A string is used as a regular
1279 expression to match the identifier directly.")
1281 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1282 "Gnus 5.10 (Emacs 22.1)")
1284 (defcustom gnus-treat-strip-pem nil
1285 "Strip PEM signatures.
1286 Valid values are nil, t, `head', `first', `last', an integer or a
1287 predicate. See Info node `(gnus)Customizing Articles'."
1288 :group 'gnus-article-treat
1289 :link '(custom-manual "(gnus)Customizing Articles")
1290 :type gnus-article-treat-custom)
1292 (defcustom gnus-treat-strip-banner t
1293 "Strip banners from articles.
1294 The banner to be stripped is specified in the `banner' group parameter.
1295 Valid values are nil, t, `head', `first', `last', an integer or a
1296 predicate. See Info node `(gnus)Customizing Articles'."
1297 :group 'gnus-article-treat
1298 :link '(custom-manual "(gnus)Customizing Articles")
1299 :type gnus-article-treat-custom)
1301 (defcustom gnus-treat-highlight-headers 'head
1302 "Highlight the headers.
1303 Valid values are nil, t, `head', `first', `last', an integer or a
1304 predicate. See Info node `(gnus)Customizing Articles'."
1305 :group 'gnus-article-treat
1306 :link '(custom-manual "(gnus)Customizing Articles")
1307 :type gnus-article-treat-head-custom)
1308 (put 'gnus-treat-highlight-headers 'highlight t)
1310 (defcustom gnus-treat-highlight-citation t
1311 "Highlight cited text.
1312 Valid values are nil, t, `head', `first', `last', an integer or a
1313 predicate. See Info node `(gnus)Customizing Articles'."
1314 :group 'gnus-article-treat
1315 :link '(custom-manual "(gnus)Customizing Articles")
1316 :type gnus-article-treat-custom)
1317 (put 'gnus-treat-highlight-citation 'highlight t)
1319 (defcustom gnus-treat-strip-headers-in-body t
1320 "Strip the X-No-Archive header line from the beginning of the body.
1321 Valid values are nil, t, `head', `first', `last', an integer or a
1322 predicate. See Info node `(gnus)Customizing Articles'."
1324 :group 'gnus-article-treat
1325 :link '(custom-manual "(gnus)Customizing Articles")
1326 :type gnus-article-treat-custom)
1328 (defcustom gnus-treat-strip-trailing-blank-lines nil
1329 "Strip trailing blank lines.
1330 Valid values are nil, t, `head', `first', `last', an integer or a
1331 predicate. See Info node `(gnus)Customizing Articles'.
1333 When set to t, it also strips trailing blanks in all MIME parts.
1334 Consider to use `last' instead."
1335 :group 'gnus-article-treat
1336 :link '(custom-manual "(gnus)Customizing Articles")
1337 :type gnus-article-treat-custom)
1339 (defcustom gnus-treat-strip-leading-blank-lines nil
1340 "Strip leading blank lines.
1341 Valid values are nil, t, `head', `first', `last', an integer or a
1342 predicate. See Info node `(gnus)Customizing Articles'.
1344 When set to t, it also strips trailing blanks in all MIME parts."
1345 :group 'gnus-article-treat
1346 :link '(custom-manual "(gnus)Customizing Articles")
1347 :type gnus-article-treat-custom)
1349 (defcustom gnus-treat-strip-multiple-blank-lines nil
1350 "Strip multiple blank lines.
1351 Valid values are nil, t, `head', `first', `last', an integer or a
1352 predicate. See Info node `(gnus)Customizing Articles'."
1353 :group 'gnus-article-treat
1354 :link '(custom-manual "(gnus)Customizing Articles")
1355 :type gnus-article-treat-custom)
1357 (defcustom gnus-treat-unfold-headers 'head
1358 "Unfold folded header lines.
1359 Valid values are nil, t, `head', `first', `last', an integer or a
1360 predicate. See Info node `(gnus)Customizing Articles'."
1362 :group 'gnus-article-treat
1363 :link '(custom-manual "(gnus)Customizing Articles")
1364 :type gnus-article-treat-custom)
1366 (defcustom gnus-article-unfold-long-headers nil
1367 "If non-nil, allow unfolding headers even if the header is long.
1368 If it is a regexp, only long headers matching this regexp are unfolded.
1369 If it is t, all long headers are unfolded.
1371 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1372 :version "23.1" ;; No Gnus
1373 :group 'gnus-article-treat
1374 :type '(choice (const nil)
1375 (const :tag "all" t)
1378 (defcustom gnus-treat-fold-headers nil
1380 Valid values are nil, t, `head', `first', `last', an integer or a
1381 predicate. See Info node `(gnus)Customizing Articles'."
1383 :group 'gnus-article-treat
1384 :link '(custom-manual "(gnus)Customizing Articles")
1385 :type gnus-article-treat-custom)
1387 (defcustom gnus-treat-fold-newsgroups 'head
1388 "Fold the Newsgroups and Followup-To headers.
1389 Valid values are nil, t, `head', `first', `last', an integer or a
1390 predicate. See Info node `(gnus)Customizing Articles'."
1392 :group 'gnus-article-treat
1393 :link '(custom-manual "(gnus)Customizing Articles")
1394 :type gnus-article-treat-custom)
1396 (defcustom gnus-treat-overstrike t
1397 "Treat overstrike highlighting.
1398 Valid values are nil, t, `head', `first', `last', an integer or a
1399 predicate. See Info node `(gnus)Customizing Articles'."
1400 :group 'gnus-article-treat
1401 :link '(custom-manual "(gnus)Customizing Articles")
1402 :type gnus-article-treat-custom)
1403 (put 'gnus-treat-overstrike 'highlight t)
1405 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1406 "Treat ANSI SGR control sequences.
1407 Valid values are nil, t, `head', `first', `last', an integer or a
1408 predicate. See Info node `(gnus)Customizing Articles'."
1409 :group 'gnus-article-treat
1410 :link '(custom-manual "(gnus)Customizing Articles")
1411 :type gnus-article-treat-custom)
1413 (make-obsolete-variable 'gnus-treat-display-xface
1414 'gnus-treat-display-x-face "Emacs 22.1")
1416 (defcustom gnus-treat-display-x-face
1417 (and (not noninteractive)
1418 (gnus-image-type-available-p 'xbm)
1419 (if (featurep 'xemacs)
1422 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1423 (executable-find "icontopbm"))
1424 ;; shell-command-to-string may signal an error, e.g. if
1425 ;; shell-file-name is not found.
1428 "Display X-Face headers.
1429 Valid values are nil and `head'.
1430 See Info node `(gnus)Customizing Articles' and Info node
1431 `(gnus)X-Face' for details."
1432 :group 'gnus-article-treat
1434 :link '(custom-manual "(gnus)Customizing Articles")
1435 :link '(custom-manual "(gnus)X-Face")
1436 :type gnus-article-treat-head-custom
1437 :set (lambda (symbol value)
1440 (cond ((or (boundp symbol) (get symbol 'saved-value))
1442 ((boundp 'gnus-treat-display-xface)
1444 ** gnus-treat-display-xface is an obsolete variable;\
1445 use gnus-treat-display-x-face instead")
1446 (default-value 'gnus-treat-display-xface))
1447 ((get 'gnus-treat-display-xface 'saved-value)
1449 ** gnus-treat-display-xface is an obsolete variable;\
1450 use gnus-treat-display-x-face instead")
1451 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1454 (put 'gnus-treat-display-x-face 'highlight t)
1456 (defcustom gnus-treat-display-face
1457 (and (not noninteractive)
1458 (gnus-image-type-available-p 'png)
1460 "Display Face headers.
1461 Valid values are nil, t, `head', `first', `last', an integer or a
1462 predicate. See Info node `(gnus)Customizing Articles' and Info
1463 node `(gnus)Face' for details."
1464 :group 'gnus-article-treat
1466 :link '(custom-manual "(gnus)Customizing Articles")
1467 :link '(custom-manual "(gnus)X-Face")
1468 :type gnus-article-treat-head-custom)
1469 (put 'gnus-treat-display-face 'highlight t)
1471 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1473 Valid values are nil, t, `head', `first', `last', an integer or a
1474 predicate. See Info node `(gnus)Customizing Articles' and Info
1475 node `(gnus)Smileys' for details."
1476 :group 'gnus-article-treat
1478 :link '(custom-manual "(gnus)Customizing Articles")
1479 :link '(custom-manual "(gnus)Smileys")
1480 :type gnus-article-treat-custom)
1481 (put 'gnus-treat-display-smileys 'highlight t)
1483 (defcustom gnus-treat-from-picon
1484 (if (and (gnus-image-type-available-p 'xpm)
1485 (gnus-picons-installed-p))
1487 "Display picons in the From header.
1488 Valid values are nil, t, `head', `first', `last', an integer or a
1489 predicate. See Info node `(gnus)Customizing Articles' and Info
1490 node `(gnus)Picons' for details."
1492 :group 'gnus-article-treat
1494 :link '(custom-manual "(gnus)Customizing Articles")
1495 :link '(custom-manual "(gnus)Picons")
1496 :type gnus-article-treat-head-custom)
1497 (put 'gnus-treat-from-picon 'highlight t)
1499 (defcustom gnus-treat-mail-picon
1500 (if (and (gnus-image-type-available-p 'xpm)
1501 (gnus-picons-installed-p))
1503 "Display picons in To and Cc headers.
1504 Valid values are nil, t, `head', `first', `last', an integer or a
1505 predicate. See Info node `(gnus)Customizing Articles' and Info
1506 node `(gnus)Picons' for details."
1508 :group 'gnus-article-treat
1510 :link '(custom-manual "(gnus)Customizing Articles")
1511 :link '(custom-manual "(gnus)Picons")
1512 :type gnus-article-treat-head-custom)
1513 (put 'gnus-treat-mail-picon 'highlight t)
1515 (defcustom gnus-treat-newsgroups-picon
1516 (if (and (gnus-image-type-available-p 'xpm)
1517 (gnus-picons-installed-p))
1519 "Display picons in the Newsgroups and Followup-To headers.
1520 Valid values are nil, t, `head', `first', `last', an integer or a
1521 predicate. See Info node `(gnus)Customizing Articles' and Info
1522 node `(gnus)Picons' for details."
1524 :group 'gnus-article-treat
1526 :link '(custom-manual "(gnus)Customizing Articles")
1527 :link '(custom-manual "(gnus)Picons")
1528 :type gnus-article-treat-head-custom)
1529 (put 'gnus-treat-newsgroups-picon 'highlight t)
1531 (defcustom gnus-treat-from-gravatar nil
1532 "Display gravatars in the From header.
1533 Valid values are nil, t, `head', `first', `last', an integer or a
1534 predicate. See Info node `(gnus)Customizing Articles' and Info
1535 node `(gnus)Gravatars' for details."
1537 :group 'gnus-article-treat
1538 :group 'gnus-gravatar
1539 :link '(custom-manual "(gnus)Customizing Articles")
1540 :link '(custom-manual "(gnus)Gravatars")
1541 :type gnus-article-treat-head-custom)
1542 (put 'gnus-treat-from-gravatar 'highlight t)
1544 (defcustom gnus-treat-mail-gravatar nil
1545 "Display gravatars in To and Cc headers.
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate. See Info node `(gnus)Customizing Articles' and Info
1548 node `(gnus)Gravatars' for details."
1550 :group 'gnus-article-treat
1551 :group 'gnus-gravatar
1552 :link '(custom-manual "(gnus)Customizing Articles")
1553 :link '(custom-manual "(gnus)Gravatars")
1554 :type gnus-article-treat-head-custom)
1555 (put 'gnus-treat-mail-gravatar 'highlight t)
1557 (defcustom gnus-treat-body-boundary
1558 (if (or gnus-treat-newsgroups-picon
1559 gnus-treat-mail-picon
1560 gnus-treat-from-picon
1561 gnus-treat-from-gravatar
1562 gnus-treat-mail-gravatar)
1563 ;; If there's much decoration, the user might prefer a boundary.
1566 "Draw a boundary at the end of the headers.
1567 Valid values are nil and `head'.
1568 See Info node `(gnus)Customizing Articles' for details."
1570 :group 'gnus-article-treat
1571 :link '(custom-manual "(gnus)Customizing Articles")
1572 :type gnus-article-treat-head-custom)
1574 (defcustom gnus-treat-capitalize-sentences nil
1575 "Capitalize sentence-starting words.
1576 Valid values are nil, t, `head', `first', `last', an integer or a
1577 predicate. See Info node `(gnus)Customizing Articles'."
1579 :group 'gnus-article-treat
1580 :link '(custom-manual "(gnus)Customizing Articles")
1581 :type gnus-article-treat-custom)
1583 (defcustom gnus-treat-wash-html nil
1585 Valid values are nil, t, `head', `first', `last', an integer or a
1586 predicate. See Info node `(gnus)Customizing Articles'."
1588 :group 'gnus-article-treat
1589 :link '(custom-manual "(gnus)Customizing Articles")
1590 :type gnus-article-treat-custom)
1592 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1594 Valid values are nil, t, `head', `first', `last', an integer or a
1595 predicate. See Info node `(gnus)Customizing Articles'."
1597 :group 'gnus-article-treat
1598 :link '(custom-manual "(gnus)Customizing Articles")
1599 :type gnus-article-treat-custom)
1601 (defcustom gnus-treat-x-pgp-sig nil
1603 To automatically treat X-PGP-Sig, set it to head.
1604 Valid values are nil, t, `head', `first', `last', an integer or a
1605 predicate. See Info node `(gnus)Customizing Articles'."
1607 :group 'gnus-article-treat
1608 :group 'mime-security
1609 :link '(custom-manual "(gnus)Customizing Articles")
1610 :type gnus-article-treat-custom)
1612 (defvar gnus-article-encrypt-protocol-alist
1613 '(("PGP" . mml2015-self-encrypt)))
1615 ;; Set to nil if more than one protocol added to
1616 ;; gnus-article-encrypt-protocol-alist.
1617 (defcustom gnus-article-encrypt-protocol "PGP"
1618 "The protocol used for encrypt articles.
1619 It is a string, such as \"PGP\". If nil, ask user."
1622 :group 'mime-security)
1624 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1625 (mm-coding-system-p 'utf-8)
1626 (executable-find idna-program))
1627 "Whether IDNA decoding of headers is used when viewing messages.
1628 This requires GNU Libidn, and by default only enabled if it is found."
1630 :group 'gnus-article-headers
1633 (defcustom gnus-article-over-scroll nil
1634 "If non-nil, allow scrolling the article buffer even when there no more text."
1636 :group 'gnus-article
1639 (defcustom gnus-inhibit-images nil
1640 "Non-nil means inhibit displaying of images inline in the article body."
1642 :group 'gnus-article
1645 (defcustom gnus-blocked-images 'gnus-block-private-groups
1646 "Images that have URLs matching this regexp will be blocked.
1647 This can also be a function to be evaluated. If so, it will be
1648 called with the group name as the parameter, and should return a
1652 :type '(choice regexp function))
1654 ;;; Internal variables
1656 (defvar gnus-english-month-names
1657 '("January" "February" "March" "April" "May" "June" "July" "August"
1658 "September" "October" "November" "December"))
1660 (defvar article-goto-body-goes-to-point-min-p nil)
1661 (defvar gnus-article-wash-types nil)
1662 (defvar gnus-article-emphasis-alist nil)
1663 (defvar gnus-article-image-alist nil)
1665 (defvar gnus-article-mime-handle-alist-1 nil)
1666 (defvar gnus-treatment-function-alist
1667 '((gnus-treat-strip-cr gnus-article-remove-cr)
1668 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1669 (gnus-treat-strip-banner gnus-article-strip-banner)
1670 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1671 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1672 (gnus-treat-buttonize gnus-article-add-buttons)
1673 (gnus-treat-fill-article gnus-article-fill-cited-article)
1674 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1675 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1676 (gnus-treat-display-x-face gnus-article-display-x-face)
1677 (gnus-treat-display-face gnus-article-display-face)
1678 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1679 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1680 (gnus-treat-hide-signature gnus-article-hide-signature)
1681 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1682 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1683 (gnus-treat-from-picon gnus-treat-from-picon)
1684 (gnus-treat-mail-picon gnus-treat-mail-picon)
1685 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1686 (gnus-treat-strip-pem gnus-article-hide-pem)
1687 (gnus-treat-date gnus-article-treat-date)
1688 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1689 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1690 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1691 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1692 (gnus-treat-strip-trailing-blank-lines
1693 gnus-article-remove-trailing-blank-lines)
1694 (gnus-treat-strip-leading-blank-lines
1695 gnus-article-strip-leading-blank-lines)
1696 (gnus-treat-strip-multiple-blank-lines
1697 gnus-article-strip-multiple-blank-lines)
1698 (gnus-treat-overstrike gnus-article-treat-overstrike)
1699 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1700 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1701 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1702 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1703 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1704 (gnus-treat-display-smileys gnus-treat-smiley)
1705 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1706 (gnus-treat-wash-html gnus-article-wash-html)
1707 (gnus-treat-emphasize gnus-article-emphasize)
1708 (gnus-treat-hide-citation gnus-article-hide-citation)
1709 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1710 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1711 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1713 (defvar gnus-article-mime-handle-alist nil)
1714 (defvar article-lapsed-timer nil)
1715 (defvar gnus-article-current-summary nil)
1717 (defvar gnus-article-mode-syntax-table
1718 (let ((table (copy-syntax-table text-mode-syntax-table)))
1719 ;; This causes the citation match run O(2^n).
1720 ;; (modify-syntax-entry ?- "w" table)
1721 (modify-syntax-entry ?> ")<" table)
1722 (modify-syntax-entry ?< "(>" table)
1723 ;; make M-. in article buffers work for `foo' strings
1724 (modify-syntax-entry ?' " " table)
1725 (modify-syntax-entry ?` " " table)
1727 "Syntax table used in article mode buffers.
1728 Initialized from `text-mode-syntax-table.")
1730 (defvar gnus-save-article-buffer nil)
1732 (defvar gnus-number-of-articles-to-be-saved nil)
1734 (defvar gnus-inhibit-hiding nil)
1736 (defvar gnus-article-edit-mode nil)
1738 ;;; Macros for dealing with the article buffer.
1740 (defmacro gnus-with-article-headers (&rest forms)
1741 `(with-current-buffer gnus-article-buffer
1743 (let ((inhibit-read-only t)
1744 (inhibit-point-motion-hooks t)
1745 (case-fold-search t))
1746 (article-narrow-to-head)
1749 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1750 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1752 (defmacro gnus-with-article-buffer (&rest forms)
1753 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1754 (with-current-buffer gnus-article-buffer
1755 (let ((inhibit-read-only t))
1758 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1759 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1761 (defun gnus-article-goto-header (header)
1762 "Go to HEADER, which is a regular expression."
1763 (re-search-forward (concat "^\\(" header "\\):") nil t))
1765 (defsubst gnus-article-hide-text (b e props)
1766 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1767 (gnus-add-text-properties-when 'article-type nil b e props)
1768 (when (memq 'intangible props)
1770 (max (1- b) (point-min))
1771 b 'intangible (cddr (memq 'intangible props)))))
1773 (defsubst gnus-article-unhide-text (b e)
1774 "Remove hidden text properties from region between B and E."
1775 (remove-text-properties b e gnus-hidden-properties)
1776 (when (memq 'intangible gnus-hidden-properties)
1777 (put-text-property (max (1- b) (point-min))
1778 b 'intangible nil)))
1780 (defun gnus-article-hide-text-type (b e type)
1781 "Hide text of TYPE between B and E."
1782 (gnus-add-wash-type type)
1783 (gnus-article-hide-text
1784 b e (cons 'article-type (cons type gnus-hidden-properties))))
1786 (defun gnus-article-unhide-text-type (b e type)
1787 "Unhide text of TYPE between B and E."
1788 (gnus-delete-wash-type type)
1789 (remove-text-properties
1790 b e (cons 'article-type (cons type gnus-hidden-properties)))
1791 (when (memq 'intangible gnus-hidden-properties)
1792 (put-text-property (max (1- b) (point-min))
1793 b 'intangible nil)))
1795 (defun gnus-article-delete-text-of-type (type)
1796 "Delete text of TYPE in the current buffer."
1798 (let ((b (point-min)))
1799 (if (eq type 'multipart)
1800 ;; Remove MIME buttons associated with multipart/alternative parts.
1803 (while (if (get-text-property (point) 'gnus-part)
1805 (when (setq b (next-single-property-change (point)
1810 (skip-chars-forward "\n")
1811 (when (eq (get-text-property b 'article-type) 'multipart)
1812 (delete-region b (point)))))
1813 (while (setq b (text-property-any b (point-max) 'article-type type))
1815 b (or (text-property-not-all b (point-max) 'article-type type)
1818 (defun gnus-article-delete-invisible-text ()
1819 "Delete all invisible text in the current buffer."
1821 (let ((b (point-min)))
1822 (while (setq b (text-property-any b (point-max) 'invisible t))
1824 b (or (text-property-not-all b (point-max) 'invisible t)
1827 (defsubst gnus-article-header-rank ()
1828 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1829 (let ((list gnus-sorted-header-list)
1832 (if (looking-at (car list))
1834 (setq list (cdr list))
1838 (defun article-hide-headers (&optional arg delete)
1839 "Hide unwanted headers and possibly sort them as well."
1841 ;; This function might be inhibited.
1842 (unless gnus-inhibit-hiding
1843 (let ((inhibit-read-only t)
1844 (case-fold-search t)
1845 (max (1+ (length gnus-sorted-header-list)))
1846 (inhibit-point-motion-hooks t)
1847 (cur (current-buffer))
1848 ignored visible beg)
1850 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1851 ;; group parameters, so we should go to the summary buffer.
1854 (progn (set-buffer gnus-summary-buffer) t)
1856 (setq ignored (when (not gnus-visible-headers)
1857 (cond ((stringp gnus-ignored-headers)
1858 gnus-ignored-headers)
1859 ((listp gnus-ignored-headers)
1860 (mapconcat 'identity
1861 gnus-ignored-headers
1863 visible (cond ((stringp gnus-visible-headers)
1864 gnus-visible-headers)
1865 ((and gnus-visible-headers
1866 (listp gnus-visible-headers))
1867 (mapconcat 'identity
1868 gnus-visible-headers
1872 ;; First we narrow to just the headers.
1873 (article-narrow-to-head)
1874 ;; Hide any "From " lines at the beginning of (mail) articles.
1875 (while (looking-at "From ")
1878 (delete-region (point-min) (point)))
1879 ;; Then treat the rest of the header lines.
1880 ;; Then we use the two regular expressions
1881 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1882 ;; select which header lines is to remain visible in the
1884 (while (re-search-forward "^[^ \t:]*:" nil t)
1886 ;; Mark the rank of the header.
1888 (point) (1+ (point)) 'message-rank
1889 (if (or (and visible (looking-at visible))
1891 (not (looking-at ignored))))
1892 (gnus-article-header-rank)
1895 (message-sort-headers-1)
1896 (when (setq beg (text-property-any
1897 (point-min) (point-max) 'message-rank (+ 2 max)))
1898 ;; We delete the unwanted headers.
1899 (gnus-add-wash-type 'headers)
1900 (add-text-properties (point-min) (+ 5 (point-min))
1901 '(article-type headers dummy-invisible t))
1902 (delete-region beg (point-max))))))))
1904 (defun article-hide-boring-headers (&optional arg)
1905 "Toggle hiding of headers that aren't very interesting.
1906 If given a negative prefix, always show; if given a positive prefix,
1908 (interactive (gnus-article-hidden-arg))
1909 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1910 (not gnus-show-all-headers))
1913 (let ((inhibit-read-only t)
1914 (inhibit-point-motion-hooks t))
1915 (article-narrow-to-head)
1916 (dolist (elem gnus-boring-article-headers)
1917 (goto-char (point-min))
1919 ;; Hide empty headers.
1921 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1923 (gnus-article-hide-text-type
1927 (if (re-search-forward "^[^ \t]" nil t)
1931 ;; Hide boring Newsgroups header.
1932 ((eq elem 'newsgroups)
1933 (when (gnus-string-equal
1934 (gnus-fetch-field "newsgroups")
1935 (gnus-group-real-name
1936 (if (boundp 'gnus-newsgroup-name)
1939 (gnus-article-hide-header "newsgroups")))
1940 ((eq elem 'to-address)
1941 (let ((to (message-fetch-field "to"))
1943 (gnus-parameter-to-address
1944 (if (boundp 'gnus-newsgroup-name)
1945 gnus-newsgroup-name ""))))
1946 (when (and to to-address
1949 ;; only one address in To
1950 (nth 1 (mail-extract-address-components to))
1952 (gnus-article-hide-header "to"))))
1954 (let ((to (message-fetch-field "to"))
1956 (gnus-parameter-to-list
1957 (if (boundp 'gnus-newsgroup-name)
1958 gnus-newsgroup-name ""))))
1959 (when (and to to-list
1962 ;; only one address in To
1963 (nth 1 (mail-extract-address-components to))
1965 (gnus-article-hide-header "to"))))
1967 (let ((cc (message-fetch-field "cc"))
1969 (gnus-parameter-to-list
1970 (if (boundp 'gnus-newsgroup-name)
1971 gnus-newsgroup-name ""))))
1972 (when (and cc to-list
1975 ;; only one address in CC
1976 (nth 1 (mail-extract-address-components cc))
1978 (gnus-article-hide-header "cc"))))
1979 ((eq elem 'followup-to)
1980 (when (gnus-string-equal
1981 (message-fetch-field "followup-to")
1982 (message-fetch-field "newsgroups"))
1983 (gnus-article-hide-header "followup-to")))
1984 ((eq elem 'reply-to)
1985 (if (gnus-group-find-parameter
1986 gnus-newsgroup-name 'broken-reply-to)
1987 (gnus-article-hide-header "reply-to")
1988 (let ((from (message-fetch-field "from"))
1989 (reply-to (message-fetch-field "reply-to")))
1996 (lambda (x) (downcase (cadr x)))
1997 (mail-extract-address-components from t))
2000 (lambda (x) (downcase (cadr x)))
2001 (mail-extract-address-components reply-to t))
2003 (gnus-article-hide-header "reply-to")))))
2005 (let ((date (with-current-buffer gnus-original-article-buffer
2006 ;; If date in `gnus-article-buffer' is localized
2007 ;; (`gnus-treat-date-user-defined'),
2008 ;; `days-between' might fail.
2009 (message-fetch-field "date"))))
2011 (< (days-between (current-time-string) date)
2013 (gnus-article-hide-header "date"))))
2015 (let ((to (message-fetch-field "to"))
2016 (cc (message-fetch-field "cc")))
2017 (when (> (length to) 1024)
2018 (gnus-article-hide-header "to"))
2019 (when (> (length cc) 1024)
2020 (gnus-article-hide-header "cc"))))
2024 (goto-char (point-min))
2025 (while (re-search-forward "^to:" nil t)
2026 (setq to-count (1+ to-count)))
2027 (when (> to-count 1)
2028 (while (> to-count 0)
2029 (goto-char (point-min))
2031 (re-search-forward "^to:" nil nil to-count)
2033 (narrow-to-region (point) (point-max))
2034 (gnus-article-hide-header "to"))
2035 (setq to-count (1- to-count))))
2036 (goto-char (point-min))
2037 (while (re-search-forward "^cc:" nil t)
2038 (setq cc-count (1+ cc-count)))
2039 (when (> cc-count 1)
2040 (while (> cc-count 0)
2041 (goto-char (point-min))
2043 (re-search-forward "^cc:" nil nil cc-count)
2045 (narrow-to-region (point) (point-max))
2046 (gnus-article-hide-header "cc"))
2047 (setq cc-count (1- cc-count)))))))))))))
2049 (defun gnus-article-hide-header (header)
2051 (goto-char (point-min))
2052 (when (re-search-forward (concat "^" header ":") nil t)
2053 (gnus-article-hide-text-type
2057 (if (re-search-forward "^[^ \t]" nil t)
2062 (defvar gnus-article-normalized-header-length 40
2063 "Length of normalized headers.")
2065 (defun article-normalize-headers ()
2066 "Make all header lines 40 characters long."
2068 (let ((inhibit-read-only t)
2072 (article-narrow-to-head)
2075 ((< (setq column (- (point-at-eol) (point)))
2076 gnus-article-normalized-header-length)
2078 (insert (make-string
2079 (- gnus-article-normalized-header-length column)
2081 ((> column gnus-article-normalized-header-length)
2082 (gnus-put-text-property
2084 (forward-char gnus-article-normalized-header-length)
2091 (forward-line 1))))))
2093 (defun article-treat-dumbquotes ()
2094 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2095 Note that this function guesses whether a character is a sm*rtq**t* or
2096 not, so it should only be used interactively.
2098 Sm*rtq**t*s are M****s***'s unilateral extension to the
2099 iso-8859-1 character map in an attempt to provide more quoting
2100 characters. If you see something like \\222 or \\264 where
2101 you're expecting some kind of apostrophe or quotation mark, then
2104 (article-translate-strings gnus-article-dumbquotes-map))
2106 (defvar org-entities)
2108 (defun article-treat-non-ascii ()
2109 "Translate many Unicode characters into their ASCII equivalents."
2111 (require 'org-entities)
2112 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2113 (dolist (elem org-entities)
2114 (when (and (listp elem)
2115 (= (length (nth 6 elem)) 1))
2116 (if (featurep 'xemacs)
2117 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2118 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2120 (when (article-goto-body)
2121 (let ((inhibit-read-only t)
2124 (if (not (setq replace (if (featurep 'xemacs)
2125 (get-char-table (following-char) table)
2126 (aref table (following-char)))))
2129 (setq props (text-properties-at (point)))
2131 (add-text-properties (point) (progn (insert replace) (point))
2133 (insert replace)))))))))
2135 (defun article-translate-strings (map)
2136 "Translate all string in the body of the article according to MAP.
2137 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2139 (when (article-goto-body)
2140 (let ((inhibit-read-only t))
2142 (let ((from (car elem))
2146 (while (search-forward from nil t)
2149 (if (eq (following-char) from)
2153 (forward-char 1)))))))))))
2155 (defun article-treat-overstrike ()
2156 "Translate overstrikes into bold text."
2159 (when (article-goto-body)
2160 (let ((inhibit-read-only t))
2161 (while (search-forward "\b" nil t)
2162 (let ((next (char-after))
2163 (previous (char-after (- (point) 2))))
2164 ;; We do the boldification/underlining by hiding the
2165 ;; overstrikes and putting the proper text property
2169 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2170 (put-text-property (point) (1+ (point)) 'face 'bold))
2172 (gnus-article-hide-text-type
2173 (1- (point)) (1+ (point)) 'overstrike)
2175 (- (point) 2) (1- (point)) 'face 'underline))
2177 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2179 (point) (1+ (point)) 'face 'underline)))))))))
2181 (defun article-treat-ansi-sequences ()
2182 "Translate ANSI SGR control sequences into overlays or extents."
2185 (when (article-goto-body)
2186 (let ((inhibit-read-only t))
2187 (ansi-color-apply-on-region (point) (point-max))))))
2189 (defun gnus-article-treat-unfold-headers ()
2190 "Unfold folded message headers.
2191 Only the headers that fit into the current window width will be
2194 (gnus-with-article-headers
2198 (mail-header-narrow-to-field)
2199 (let* ((header (buffer-string))
2201 (or (equal gnus-article-unfold-long-headers t)
2202 (and (stringp gnus-article-unfold-long-headers)
2203 (string-match gnus-article-unfold-long-headers
2207 (goto-char (point-min))
2208 (while (re-search-forward "\n[\t ]" nil t)
2209 (replace-match " " t t)))
2210 (setq length (- (point-max) (point-min) 1))
2211 (when (or unfoldable
2212 (< length (window-width)))
2213 (while (re-search-forward "\n[\t ]" nil t)
2214 (replace-match " " t t))))
2215 (goto-char (point-max)))))))
2217 (defun gnus-article-treat-fold-headers ()
2218 "Fold message headers."
2220 (gnus-with-article-headers
2223 (mail-header-narrow-to-field)
2224 (mail-header-fold-field)
2225 (goto-char (point-max))))))
2227 (defun gnus-treat-smiley ()
2228 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2230 (gnus-with-article-buffer
2231 (if (memq 'smiley gnus-article-wash-types)
2232 (gnus-delete-images 'smiley)
2234 (let ((images (smiley-region (point) (point-max))))
2236 (gnus-add-wash-type 'smiley)
2237 (dolist (image images)
2238 (gnus-add-image 'smiley image)))))))
2240 (defun gnus-article-remove-images ()
2241 "Remove all images from the article buffer."
2243 (gnus-with-article-buffer
2246 (dolist (elem gnus-article-image-alist)
2247 (gnus-delete-images (car elem))))))
2249 (autoload 'w3m-toggle-inline-images "w3m")
2251 (defun gnus-article-show-images ()
2252 "Show any images that are in the HTML-rendered article buffer.
2253 This only works if the article in question is HTML."
2255 (gnus-with-article-buffer
2258 (if (eq mm-text-html-renderer 'w3m)
2259 (let ((mm-inline-text-html-with-images nil))
2260 (w3m-toggle-inline-images))
2261 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2263 (destructuring-bind (start end function) region
2264 (funcall function (get-text-property start 'image-url)
2267 (defun gnus-article-treat-fold-newsgroups ()
2268 "Unfold folded message headers.
2269 Only the headers that fit into the current window width will be
2272 (gnus-with-article-headers
2273 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2275 (mail-header-narrow-to-field)
2276 (while (re-search-forward ", *" nil t)
2277 (replace-match ", " t t))
2278 (mail-header-fold-field)
2279 (goto-char (point-max))))))
2281 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2282 "Value of `truncate-lines' in Gnus Article buffer.
2283 Valid values are nil, t, `head', `first', `last', an integer or a
2284 predicate. See Info node `(gnus)Customizing Articles'."
2285 :version "23.1" ;; No Gnus
2286 :group 'gnus-article
2287 ;; :link '(custom-manual "(gnus)Customizing Articles")
2290 (defun gnus-article-toggle-truncate-lines (&optional arg)
2291 "Toggle whether to fold or truncate long lines in article the buffer.
2292 If ARG is non-nil and not a number, toggle
2293 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2294 long lines if and only if arg is positive."
2297 ((and (numberp arg) (> arg 0))
2298 (setq gnus-article-truncate-lines t))
2300 (setq gnus-article-truncate-lines nil))
2302 (setq gnus-article-truncate-lines
2303 (not gnus-article-truncate-lines))))
2304 (gnus-with-article-buffer
2306 ((and (numberp arg) (> arg 0))
2307 (setq truncate-lines nil))
2309 (setq truncate-lines t)))
2310 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2311 ;; `toggle-truncate-lines' needs an argument.
2312 (toggle-truncate-lines)))
2314 (defun gnus-article-treat-body-boundary ()
2315 "Place a boundary line at the end of the headers."
2317 (when (and gnus-body-boundary-delimiter
2318 (> (length gnus-body-boundary-delimiter) 0))
2319 (gnus-with-article-headers
2320 (goto-char (point-max))
2321 (let ((start (point)))
2322 (insert "X-Boundary: ")
2323 (gnus-add-text-properties start (point) '(invisible t intangible t))
2324 (insert (let (str (max (window-width)))
2325 (if (featurep 'xemacs)
2326 (setq max (1- max)))
2327 (while (>= max (length str))
2328 (setq str (concat str gnus-body-boundary-delimiter)))
2329 (substring str 0 max))
2331 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2333 (defun article-fill-long-lines ()
2334 "Fill lines that are wider than the window width."
2337 (let ((inhibit-read-only t)
2338 (width (window-width (get-buffer-window (current-buffer)))))
2341 (let ((adaptive-fill-mode nil)) ;Why? -sm
2344 (when (>= (current-column) (min fill-column width))
2345 (narrow-to-region (min (1+ (point)) (point-max))
2347 (let ((goback (point-marker)))
2348 (fill-paragraph nil)
2349 (goto-char (marker-position goback)))
2351 (forward-line 1)))))))
2353 (defun article-capitalize-sentences ()
2354 "Capitalize the first word in each sentence."
2357 (let ((inhibit-read-only t)
2358 (paragraph-start "^[\n\^L]"))
2362 (forward-sentence)))))
2364 (defun article-remove-cr ()
2365 "Remove trailing CRs and then translate remaining CRs into LFs."
2368 (let ((inhibit-read-only t))
2369 (goto-char (point-min))
2370 (while (re-search-forward "\r+$" nil t)
2371 (replace-match "" t t))
2372 (goto-char (point-min))
2373 (while (search-forward "\r" nil t)
2374 (replace-match "\n" t t)))))
2376 (defun article-remove-trailing-blank-lines ()
2377 "Remove all trailing blank lines from the article."
2380 (let ((inhibit-read-only t))
2381 (goto-char (point-max))
2385 (while (and (not (bobp))
2386 (looking-at "^[ \t]*$")
2387 (not (gnus-annotation-in-region-p
2388 (point) (point-at-eol))))
2393 (defvar gnus-face-properties-alist)
2395 (defun article-display-face (&optional force)
2396 "Display any Face headers in the header."
2397 (interactive (list 'force))
2398 (let ((wash-face-p buffer-read-only))
2399 (gnus-with-article-headers
2400 ;; When displaying parts, this function can be called several times on
2401 ;; the same article, without any intended toggle semantic (as typing `W
2402 ;; D d' would have). So face deletion must occur only when we come from
2403 ;; an interactive command, that is when the *Article* buffer is
2405 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2406 (gnus-delete-images 'face)
2407 (let ((from (message-fetch-field "from"))
2409 (save-current-buffer
2410 (when (and wash-face-p
2411 (gnus-buffer-live-p gnus-original-article-buffer)
2412 (not (re-search-forward "^Face:[\t ]*" nil t)))
2413 (set-buffer gnus-original-article-buffer))
2415 (mail-narrow-to-head)
2417 ;; Check whether this face is censored.
2418 (not (and gnus-article-x-face-too-ugly
2420 (setq from (message-fetch-field "from")))
2421 (string-match gnus-article-x-face-too-ugly
2423 (while (gnus-article-goto-header "Face")
2424 (push (mail-header-field-value) faces)))))
2426 (goto-char (point-min))
2428 (unless (setq from (gnus-article-goto-header "from"))
2431 (insert " [no `from' set]\n"))
2433 (when (setq png (gnus-convert-face-to-png (pop faces)))
2435 (apply 'gnus-create-image png 'png t
2436 (cdr (assq 'png gnus-face-properties-alist))))
2439 (gnus-add-wash-type 'face)
2440 (gnus-add-image 'face image)
2441 (gnus-put-image image nil 'face)))))))))))
2443 (defun article-display-x-face (&optional force)
2444 "Look for an X-Face header and display it if present."
2445 (interactive (list 'force))
2446 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2447 (gnus-with-article-headers
2448 ;; Delete the old process, if any.
2449 (when (process-status "article-x-face")
2450 (delete-process "article-x-face"))
2451 ;; See the comment in `article-display-face'.
2452 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2453 ;; We have already displayed X-Faces, so we remove them
2455 (gnus-delete-images 'xface)
2457 (let ((from (message-fetch-field "from"))
2459 (save-current-buffer
2460 (when (and wash-face-p
2461 (gnus-buffer-live-p gnus-original-article-buffer)
2462 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2463 ;; If type `W f', use gnus-original-article-buffer,
2464 ;; otherwise use the current buffer because displaying
2465 ;; RFC822 parts calls this function too.
2466 (set-buffer gnus-original-article-buffer))
2468 (mail-narrow-to-head)
2469 (and gnus-article-x-face-command
2471 ;; Check whether this face is censored.
2472 (not (and gnus-article-x-face-too-ugly
2474 (setq from (message-fetch-field "from")))
2475 (string-match gnus-article-x-face-too-ugly
2477 (while (gnus-article-goto-header "X-Face")
2478 (push (mail-header-field-value) x-faces)))))
2480 ;; We display the face.
2481 (cond ((functionp gnus-article-x-face-command)
2482 ;; The command is a lisp function, so we call it.
2483 (mapc gnus-article-x-face-command x-faces))
2484 ((stringp gnus-article-x-face-command)
2485 ;; The command is a string, so we interpret the command
2486 ;; as a, well, command, and fork it off.
2487 (let ((process-connection-type nil))
2488 (gnus-set-process-query-on-exit-flag
2490 "article-x-face" nil shell-file-name
2491 shell-command-switch gnus-article-x-face-command)
2493 ;; Sending multiple EOFs to xv doesn't work,
2494 ;; so we only do a single external face.
2496 (insert (car x-faces))
2497 (process-send-region "article-x-face"
2498 (point-min) (point-max)))
2499 (process-send-eof "article-x-face")))
2501 (error "`%s' set to `%s' is not a function"
2502 gnus-article-x-face-command
2503 'gnus-article-x-face-command)))))))))
2505 (defun article-decode-mime-words ()
2506 "Decode all MIME-encoded words in the article."
2508 (gnus-with-article-buffer
2509 (let ((inhibit-point-motion-hooks t)
2510 (mail-parse-charset gnus-newsgroup-charset)
2511 (mail-parse-ignored-charsets
2512 (with-current-buffer gnus-summary-buffer
2513 gnus-newsgroup-ignored-charsets)))
2514 (mail-decode-encoded-word-region (point-min) (point-max)))))
2516 (defun article-decode-charset (&optional prompt)
2517 "Decode charset-encoded text in the article.
2518 If PROMPT (the prefix), prompt for a coding system to use."
2520 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2521 (inhibit-read-only t)
2522 (mail-parse-charset gnus-newsgroup-charset)
2523 (mail-parse-ignored-charsets
2524 (save-excursion (condition-case nil
2525 (set-buffer gnus-summary-buffer)
2527 gnus-newsgroup-ignored-charsets))
2528 ct cte ctl charset format)
2531 (article-narrow-to-head)
2532 (setq ct (message-fetch-field "Content-Type" t)
2533 cte (message-fetch-field "Content-Transfer-Encoding" t)
2534 ctl (and ct (mail-header-parse-content-type ct))
2537 (mm-read-coding-system "Charset to decode: "))
2539 (mail-content-type-get ctl 'charset)))
2540 format (and ctl (mail-content-type-get ctl 'format)))
2542 (setq cte (mail-header-strip cte)))
2543 (if (and ctl (not (string-match "/" (car ctl))))
2545 (goto-char (point-max)))
2548 (narrow-to-region (point) (point-max))
2549 (when (and (eq mail-parse-charset 'gnus-decoded)
2550 (eq (mm-body-7-or-8) '8bit))
2551 ;; The text code could have been decoded.
2552 (setq charset mail-parse-charset))
2553 (when (and (or (not ctl)
2554 (equal (car ctl) "text/plain"))
2555 (not format)) ;; article with format will decode later.
2557 charset (and cte (intern (downcase
2558 (gnus-strip-whitespace cte))))
2561 (defun article-decode-encoded-words ()
2562 "Remove encoded-word encoding from headers."
2563 (let ((inhibit-point-motion-hooks t)
2564 (mail-parse-charset gnus-newsgroup-charset)
2565 (mail-parse-ignored-charsets
2566 (save-excursion (condition-case nil
2567 (set-buffer gnus-summary-buffer)
2569 gnus-newsgroup-ignored-charsets))
2570 (inhibit-read-only t)
2572 (goto-char (point-min))
2573 (when (search-forward "\n\n" nil 'move)
2580 (memq (char-after) '(?\t ? )))))
2581 (setq start (point))
2583 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2584 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2585 (funcall gnus-decode-address-function start end)
2586 (funcall gnus-decode-header-function start end))
2587 (goto-char (setq end start)))))
2589 (defun article-decode-group-name ()
2590 "Decode group names in Newsgroups, Followup-To and Xref headers."
2591 (let ((inhibit-point-motion-hooks t)
2592 (inhibit-read-only t)
2593 (method (gnus-find-method-for-group gnus-newsgroup-name))
2595 (when (and (or gnus-group-name-charset-method-alist
2596 gnus-group-name-charset-group-alist)
2597 (gnus-buffer-live-p gnus-original-article-buffer))
2599 (article-narrow-to-head)
2600 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2601 (with-current-buffer gnus-original-article-buffer
2602 (goto-char (point-min)))
2603 (setq regexp (concat "^" header
2604 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2605 (while (re-search-forward regexp nil t)
2606 (replace-match (save-match-data
2607 (gnus-decode-newsgroups
2608 ;; XXX how to use data in article buffer?
2609 (with-current-buffer gnus-original-article-buffer
2610 (re-search-forward regexp nil t)
2612 gnus-newsgroup-name method))
2614 (goto-char (point-min)))))))
2616 (autoload 'idna-to-unicode "idna")
2618 (defun article-decode-idna-rhs ()
2619 "Decode IDNA strings in RHS in various headers in current buffer.
2620 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2621 Mail-Reply-To: and Mail-Followup-To:."
2624 (let ((inhibit-point-motion-hooks t)
2625 (inhibit-read-only t))
2626 (article-narrow-to-head)
2627 (goto-char (point-min))
2628 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2630 (when (save-match-data
2631 (and (setq ace (match-string 1))
2633 (and (re-search-backward "^[^ \t]" nil t)
2634 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2635 (setq unicode (idna-to-unicode ace))))
2636 (unless (string= ace unicode)
2637 (replace-match unicode nil nil nil 1)))))))))
2639 (defun article-de-quoted-unreadable (&optional force read-charset)
2640 "Translate a quoted-printable-encoded article.
2641 If FORCE, decode the article whether it is marked as quoted-printable
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 (mm-read-coding-system "Charset: " charset)))
2660 (setq charset gnus-newsgroup-charset))
2662 (and type (let ((case-fold-search t))
2663 (string-match "quoted-printable" type))))
2665 (quoted-printable-decode-region
2666 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2668 (defun article-de-base64-unreadable (&optional force read-charset)
2669 "Translate a base64 article.
2670 If FORCE, decode the article whether it is marked as base64 not.
2671 If READ-CHARSET, ask for a coding system."
2672 (interactive (list 'force current-prefix-arg))
2674 (let ((inhibit-read-only t) type charset)
2675 (if (gnus-buffer-live-p gnus-original-article-buffer)
2676 (with-current-buffer gnus-original-article-buffer
2678 (gnus-fetch-field "content-transfer-encoding"))
2679 (let* ((ct (gnus-fetch-field "content-type"))
2680 (ctl (and ct (mail-header-parse-content-type ct))))
2681 (setq charset (and ctl
2682 (mail-content-type-get ctl 'charset)))
2683 (if (stringp charset)
2684 (setq charset (intern (downcase charset)))))))
2686 (setq charset (mm-read-coding-system "Charset: " charset)))
2688 (setq charset gnus-newsgroup-charset))
2690 (and type (let ((case-fold-search t))
2691 (string-match "base64" type))))
2694 (narrow-to-region (point) (point-max))
2695 (base64-decode-region (point-min) (point-max))
2696 (mm-decode-coding-region
2697 (point-min) (point-max)
2698 (mm-charset-to-coding-system charset nil t)))))))
2703 (defun article-decode-HZ ()
2704 "Translate a HZ-encoded article."
2708 (let ((inhibit-read-only t))
2709 (rfc1843-decode-region (point-min) (point-max)))))
2711 (defun article-unsplit-urls ()
2712 "Remove the newlines that some other mailers insert into URLs."
2715 (let ((inhibit-read-only t))
2716 (goto-char (point-min))
2717 (while (re-search-forward
2718 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2719 (replace-match "\\1\\3" t)))
2720 (when (gmm-called-interactively-p 'any)
2721 (gnus-treat-article nil))))
2723 (defun article-wash-html ()
2724 "Format an HTML article."
2727 (buffer-read-only nil))
2728 (when (gnus-buffer-live-p gnus-original-article-buffer)
2729 (with-current-buffer gnus-original-article-buffer
2730 (setq handles (mm-dissect-buffer t t))))
2732 (delete-region (point) (point-max))
2733 (mm-enable-multibyte)
2734 (mm-inline-text-html handles)))
2736 (defvar gnus-article-browse-html-temp-list nil
2737 "List of temporary files created by `gnus-article-browse-html-parts'.
2738 Internal variable.")
2740 (defcustom gnus-article-browse-delete-temp 'ask
2741 "What to do with temporary files from `gnus-article-browse-html-parts'.
2742 If nil, don't delete temporary files. If it is t, delete them on
2743 exit from the summary buffer. If it is the symbol `file', query
2744 on each file, if it is `ask' ask once when exiting from the
2746 :group 'gnus-article
2747 :version "23.1" ;; No Gnus
2748 :type '(choice (const :tag "Don't delete" nil)
2749 (const :tag "Don't ask" t)
2750 (const :tag "Ask" ask)
2751 (const :tag "Ask for each file" file)))
2753 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2755 (defun gnus-article-browse-delete-temp-files (&optional how)
2756 "Delete temp-files created by `gnus-article-browse-html-parts'."
2757 (when (and gnus-article-browse-html-temp-list
2759 (or how (setq how gnus-article-browse-delete-temp))
2761 (let ((files (length gnus-article-browse-html-temp-list)))
2764 "Delete the temporary HTML file? "
2765 (format "Delete all %s temporary HTML files? "
2767 (setq gnus-article-browse-html-temp-list nil)))
2769 (dolist (file gnus-article-browse-html-temp-list)
2770 (cond ((file-directory-p file)
2771 (when (or (not (eq how 'file))
2774 "Delete temporary HTML file(s) in directory `%s'? "
2775 (file-name-as-directory file))))
2776 (gnus-delete-directory file)))
2777 ((file-exists-p file)
2778 (when (or (not (eq how 'file))
2780 (format "Delete temporary HTML file `%s'? " file)))
2781 (delete-file file)))))
2782 ;; Also remove file from the list when not deleted or if file doesn't
2784 (setq gnus-article-browse-html-temp-list nil))
2785 gnus-article-browse-html-temp-list)
2787 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2788 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2793 (dolist (handle handles)
2795 ((not (listp handle)))
2796 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2798 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2799 ((equal (mm-handle-media-supertype handle) "multipart")
2800 (when (setq file (gnus-article-browse-html-save-cid-content
2801 cid handle directory))
2802 (throw 'found file)))
2803 ((equal (concat "<" cid ">") (mm-handle-id handle))
2806 (or (mm-handle-filename handle)
2808 (make-temp-name "cid")
2809 (car (rassoc (car (mm-handle-type handle))
2810 mailcap-mime-extensions))))
2812 (mm-save-part-to-file handle file)
2813 (throw 'found file))))))))
2815 (defun gnus-article-browse-html-parts (list &optional header)
2816 "View all \"text/html\" parts from LIST.
2817 Recurse into multiparts. The optional HEADER that should be a decoded
2818 message header will be added to the bodies of the \"text/html\" parts."
2819 ;; Internal function used by `gnus-article-browse-html-article'.
2820 (let (type file charset content cid-dir tmp-file showed)
2821 ;; Find and show the html-parts.
2822 (dolist (handle list)
2823 ;; If HTML, show it:
2824 (cond ((not (listp handle)))
2825 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2826 (and (equal (car type) "message/external-body")
2828 (setq file (mm-handle-filename handle)))
2829 (or (mm-handle-cache handle)
2830 (condition-case code
2831 (progn (mm-extern-cache-contents handle) t)
2833 (gnus-message 3 "%s" (error-message-string code))
2834 (when (>= gnus-verbose 3) (sit-for 2))
2837 (setq handle (mm-handle-cache handle)
2838 type (mm-handle-type handle))
2839 (equal (car type) "text/html"))))
2840 (setq charset (mail-content-type-get type 'charset)
2841 content (mm-get-part handle))
2843 (if (eq charset 'gnus-decoded)
2844 (mm-enable-multibyte)
2845 (mm-disable-multibyte))
2847 ;; resolve cid contents
2848 (let ((case-fold-search t)
2850 (goto-char (point-min))
2851 (while (re-search-forward "\
2852 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2855 (setq cid-dir (mm-make-temp-file "cid" t))
2856 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2859 (when (setq cid-file
2860 (gnus-article-browse-html-save-cid-content
2862 (with-current-buffer gnus-article-buffer
2863 gnus-article-mime-handles)
2865 (when (eq system-type 'cygwin)
2867 (concat "/" (substring
2868 (with-output-to-string
2869 (call-process "cygpath" nil
2873 (replace-match (concat "file://" cid-file)
2875 (unless content (setq content (buffer-string))))
2876 (when (or charset header (not file))
2877 (setq tmp-file (mm-make-temp-file
2878 ;; Do we need to care for 8.3 filenames?
2879 "mm-" nil ".html")))
2880 ;; Add a meta html tag to specify charset and a header.
2883 (let (title eheader body hcharset coding)
2885 (mm-enable-multibyte)
2886 (setq case-fold-search t)
2887 (insert header "\n")
2888 (setq title (message-fetch-field "subject"))
2889 (goto-char (point-min))
2890 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2892 (replace-match (cond ((match-beginning 1) "<")
2893 ((match-beginning 2) ">")
2894 ((match-beginning 3) "&")
2896 (goto-char (point-min))
2897 (while (re-search-forward "^[\t ]+" nil t)
2900 (delete-region (match-beginning 0)
2903 (goto-char (point-min))
2904 (insert "<div align=\"left\">\n")
2905 (goto-char (point-max))
2906 (insert "</div>\n<hr>\n")
2907 ;; We have to examine charset one by one since
2908 ;; charset specified in parts might be different.
2909 (if (eq charset 'gnus-decoded)
2910 (setq charset 'utf-8
2911 eheader (mm-encode-coding-string (buffer-string)
2914 (mm-encode-coding-string title charset))
2915 body (mm-encode-coding-string content charset))
2916 (setq hcharset (mm-find-mime-charset-region (point-min)
2918 (cond ((= (length hcharset) 1)
2919 (setq hcharset (car hcharset)
2920 coding (mm-charset-to-coding-system
2922 ((> (length hcharset) 1)
2923 (setq hcharset 'utf-8
2929 (mm-charset-to-coding-system charset
2931 (if (eq coding body)
2932 (setq eheader (mm-encode-coding-string
2933 (buffer-string) coding)
2935 (mm-encode-coding-string
2938 (setq charset 'utf-8
2939 eheader (mm-encode-coding-string
2940 (buffer-string) charset)
2942 (mm-encode-coding-string
2944 body (mm-encode-coding-string
2945 (mm-decode-coding-string
2948 (setq charset hcharset
2949 eheader (mm-encode-coding-string
2950 (buffer-string) coding)
2952 (mm-encode-coding-string
2955 (setq eheader (mm-string-as-unibyte (buffer-string))
2958 (mm-disable-multibyte)
2961 (mm-add-meta-html-tag handle charset t))
2963 (goto-char (point-min))
2964 (unless (search-forward "<title>" nil t)
2965 (re-search-forward "<head>\\s-*" nil t)
2966 (insert "<title>" title "</title>\n")))
2967 (goto-char (point-min))
2968 (or (re-search-forward
2969 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2971 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2973 (mm-write-region (point-min) (point-max)
2974 tmp-file nil nil nil 'binary t))))
2976 (mm-with-unibyte-buffer
2977 (insert (if (eq charset 'gnus-decoded)
2978 (mm-encode-coding-string content
2979 (setq charset 'utf-8))
2981 (if (or (mm-add-meta-html-tag handle charset)
2983 (mm-write-region (point-min) (point-max)
2984 tmp-file nil nil nil 'binary t)
2985 (setq tmp-file nil))))
2987 (mm-save-part-to-file handle tmp-file)))
2989 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2990 (add-hook 'gnus-summary-prepare-exit-hook
2991 'gnus-article-browse-delete-temp-files)
2992 (add-hook 'gnus-exit-gnus-hook
2994 (gnus-article-browse-delete-temp-files t)))
2995 ;; FIXME: Warn if there's an <img> tag?
2996 (browse-url-of-file (or tmp-file (expand-file-name file)))
2998 ;; If multipart, recurse
2999 ((equal (mm-handle-media-supertype handle) "multipart")
3000 (when (gnus-article-browse-html-parts handle header)
3002 ((equal (mm-handle-media-type handle) "message/rfc822")
3003 (mm-with-multibyte-buffer
3004 (mm-insert-part handle)
3005 (setq handle (mm-dissect-buffer t t))
3006 (when (and (bufferp (car handle))
3007 (stringp (car (mm-handle-type handle))))
3008 (setq handle (list handle)))
3010 (article-decode-encoded-words)
3011 (let ((gnus-visible-headers
3012 (or (get 'gnus-visible-headers 'standard-value)
3013 gnus-visible-headers)))
3014 (article-hide-headers))
3015 (goto-char (point-min))
3016 (search-forward "\n\n" nil 'move)
3017 (skip-chars-backward "\t\n ")
3018 (setq header (buffer-substring (point-min) (point)))))
3020 (gnus-article-browse-html-parts handle header)
3021 (mm-destroy-parts handle))
3025 (defun gnus-article-browse-html-article (&optional arg)
3026 "View \"text/html\" parts of the current article with a WWW browser.
3027 Inline images embedded in a message using the cid scheme, as they are
3028 generally considered to be safe, will be processed properly.
3029 The message header is added to the beginning of every html part unless
3030 the prefix argument ARG is given.
3032 Warning: Spammers use links to images (using the http scheme) in HTML
3033 articles to verify whether you have read the message. As
3034 `gnus-article-browse-html-article' passes the HTML content to the
3035 browser without eliminating these \"web bugs\" you should only
3036 use it for mails from trusted senders.
3038 If you always want to display HTML parts in the browser, set
3039 `mm-text-html-renderer' to nil.
3041 This command creates temporary files to pass HTML contents including
3042 images if any to the browser, and deletes them when exiting the group
3044 ;; Cf. `mm-w3m-safe-url-regexp'
3047 (gnus-summary-show-article)
3048 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3049 gnus-visible-headers))
3050 ;; As we insert a <hr>, there's no need for the body boundary.
3051 (gnus-treat-body-boundary nil))
3052 (gnus-summary-show-article)))
3053 (with-current-buffer gnus-article-buffer
3054 (let ((header (unless arg
3057 (buffer-substring-no-properties
3058 (goto-char (point-min))
3059 (if (search-forward "\n\n" nil t)
3061 (goto-char (point-max))
3062 (skip-chars-backward "\t\n ")
3065 (set-buffer gnus-original-article-buffer)
3066 (setq parts (mm-dissect-buffer t t))
3067 ;; If singlepart, enforce a list.
3068 (when (and (bufferp (car parts))
3069 (stringp (car (mm-handle-type parts))))
3070 (setq parts (list parts)))
3072 (unless (gnus-article-browse-html-parts parts header)
3073 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3074 (mm-destroy-parts parts)
3076 (gnus-summary-show-article)))))
3078 (defun article-hide-list-identifiers ()
3079 "Remove list identifies from the Subject header.
3080 The `gnus-list-identifiers' variable specifies what to do."
3082 (let ((inhibit-point-motion-hooks t)
3083 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3084 (inhibit-read-only t))
3088 (article-narrow-to-head)
3089 (goto-char (point-min))
3090 (while (re-search-forward
3091 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3093 (delete-region (match-beginning 2) (match-end 0))
3094 (beginning-of-line))
3095 (when (re-search-forward
3096 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3097 (delete-region (match-beginning 1) (match-end 1))))))))
3099 (defun article-hide-pem (&optional arg)
3100 "Toggle hiding of any PEM headers and signatures in the current article.
3101 If given a negative prefix, always show; if given a positive prefix,
3103 (interactive (gnus-article-hidden-arg))
3104 (unless (gnus-article-check-hidden-text 'pem arg)
3106 (let ((inhibit-read-only t) end)
3107 (goto-char (point-min))
3108 ;; Hide the horrendously ugly "header".
3109 (when (and (search-forward
3110 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3112 (setq end (1+ (match-beginning 0))))
3113 (gnus-add-wash-type 'pem)
3114 (gnus-article-hide-text-type
3116 (if (search-forward "\n\n" nil t)
3120 ;; Hide the trailer as well
3121 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3123 (gnus-article-hide-text-type
3124 (match-beginning 0) (match-end 0) 'pem)))))))
3126 (defun article-strip-banner ()
3127 "Strip the banners specified by the `banner' group parameter and by
3128 `gnus-article-address-banner-alist'."
3132 (let ((inhibit-point-motion-hooks t))
3133 (when (gnus-parameter-banner gnus-newsgroup-name)
3134 (article-really-strip-banner
3135 (gnus-parameter-banner gnus-newsgroup-name)))
3136 (when gnus-article-address-banner-alist
3137 ;; Note that the From header is decoded here, so it is
3138 ;; required that the *-extract-address-components function
3139 ;; supports non-ASCII text.
3140 (let ((from (save-restriction
3142 (article-narrow-to-head)
3143 (mail-fetch-field "from"))))
3146 (cadr (funcall gnus-extract-address-components
3149 (dolist (pair gnus-article-address-banner-alist)
3150 (when (string-match (car pair) from)
3152 (article-really-strip-banner (cdr pair)))))))))))))
3154 (defun article-really-strip-banner (banner)
3155 "Strip the banner specified by the argument."
3158 (let ((inhibit-point-motion-hooks t)
3159 (gnus-signature-limit nil)
3160 (inhibit-read-only t))
3163 ((eq banner 'signature)
3164 (when (gnus-article-narrow-to-signature)
3167 (delete-region (point) (point-max))))
3169 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3170 (while (re-search-forward banner nil t)
3171 (delete-region (match-beginning 0) (match-end 0)))))
3173 (while (re-search-forward banner nil t)
3174 (delete-region (match-beginning 0) (match-end 0)))))))))
3176 (defun article-babel ()
3177 "Translate article using an online translation service."
3180 (gnus-with-article-buffer
3181 (when (article-goto-body)
3182 (let* ((start (point))
3184 (orig (buffer-substring start end))
3185 (trans (babel-as-string orig)))
3187 (narrow-to-region start end)
3188 (delete-region start end)
3191 (defun article-hide-signature (&optional arg)
3192 "Hide the signature in the current article.
3193 If given a negative prefix, always show; if given a positive prefix,
3195 (interactive (gnus-article-hidden-arg))
3196 (unless (gnus-article-check-hidden-text 'signature arg)
3199 (let ((inhibit-read-only t))
3200 (when (gnus-article-narrow-to-signature)
3201 (gnus-article-hide-text-type
3202 (point-min) (point-max) 'signature))))))
3203 (gnus-set-mode-line 'article))
3205 (defun article-strip-headers-in-body ()
3206 "Strip offensive headers from bodies."
3210 (let ((case-fold-search t))
3211 (when (looking-at "x-no-archive:")
3212 (gnus-delete-line)))))
3214 (defun article-strip-leading-blank-lines ()
3215 "Remove all blank lines from the beginning of the article."
3218 (let ((inhibit-point-motion-hooks t)
3219 (inhibit-read-only t))
3220 (when (article-goto-body)
3221 (while (and (not (eobp))
3222 (looking-at "[ \t]*$"))
3223 (gnus-delete-line))))))
3225 (defun article-narrow-to-head ()
3226 "Narrow the buffer to the head of the message.
3227 Point is left at the beginning of the narrowed-to region."
3229 (goto-char (point-min))
3231 ;; Absolutely no headers displayed.
3235 ((search-forward "\n\n" nil 1)
3237 ;; Nothing but headers.
3240 (goto-char (point-min)))
3242 (defun article-goto-body ()
3243 "Place point at the start of the body."
3244 (goto-char (point-min))
3246 ;; This variable is only bound when dealing with separate
3248 (article-goto-body-goes-to-point-min-p
3250 ((search-forward "\n\n" nil t)
3253 (goto-char (point-max))
3256 (defun article-strip-multiple-blank-lines ()
3257 "Replace consecutive blank lines with one empty line."
3260 (let ((inhibit-point-motion-hooks t)
3261 (inhibit-read-only t))
3262 ;; First make all blank lines empty.
3264 (while (re-search-forward "^[ \t]+$" nil t)
3265 (unless (gnus-annotation-in-region-p
3266 (match-beginning 0) (match-end 0))
3267 (replace-match "" nil t)))
3268 ;; Then replace multiple empty lines with a single empty line.
3270 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3271 (unless (gnus-annotation-in-region-p
3272 (match-beginning 0) (match-end 0))
3273 (delete-region (match-beginning 1) (match-end 1)))))))
3275 (defun article-strip-leading-space ()
3276 "Remove all white space from the beginning of the lines in the article."
3279 (let ((inhibit-point-motion-hooks t)
3280 (inhibit-read-only t))
3282 (while (re-search-forward "^[ \t]+" nil t)
3283 (replace-match "" t t)))))
3285 (defun article-strip-trailing-space ()
3286 "Remove all white space from the end of the lines in the article."
3289 (let ((inhibit-point-motion-hooks t)
3290 (inhibit-read-only t))
3292 (while (re-search-forward "[ \t]+$" nil t)
3293 (replace-match "" t t)))))
3295 (defun article-strip-blank-lines ()
3296 "Strip leading, trailing and multiple blank lines."
3298 (article-strip-leading-blank-lines)
3299 (article-remove-trailing-blank-lines)
3300 (article-strip-multiple-blank-lines))
3302 (defun article-strip-all-blank-lines ()
3303 "Strip all blank lines."
3306 (let ((inhibit-point-motion-hooks t)
3307 (inhibit-read-only t))
3309 (while (re-search-forward "^[ \t]*\n" nil t)
3310 (replace-match "" t t)))))
3312 (defun gnus-article-narrow-to-signature ()
3313 "Narrow to the signature; return t if a signature is found, else nil."
3314 (let ((inhibit-point-motion-hooks t))
3315 (when (gnus-article-search-signature)
3317 ;; Check whether we have some limits to what we consider
3318 ;; to be a signature.
3319 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3320 (list gnus-signature-limit)))
3322 (while (setq limit (pop limits))
3323 (if (or (and (integerp limit)
3324 (< (- (point-max) (point)) limit))
3326 (< (count-lines (point) (point-max)) limit))
3327 (and (functionp limit)
3329 (and (stringp limit)
3330 (not (re-search-forward limit nil t))))
3331 () ; This limit did not succeed.
3335 (narrow-to-region (point) (point-max))
3338 (defun gnus-article-search-signature ()
3339 "Search the current buffer for the signature separator.
3340 Put point at the beginning of the signature separator."
3341 (let ((cur (point)))
3342 (goto-char (point-max))
3343 (if (if (stringp gnus-signature-separator)
3344 (re-search-backward gnus-signature-separator nil t)
3345 (let ((seps gnus-signature-separator))
3347 (not (re-search-backward (car seps) nil t)))
3354 (defun gnus-article-hidden-arg ()
3355 "Return the current prefix arg as a number, or 0 if no prefix."
3356 (list (if current-prefix-arg
3357 (prefix-numeric-value current-prefix-arg)
3360 (defun gnus-article-check-hidden-text (type arg)
3361 "Return nil if hiding is necessary.
3362 Arg can be nil or a number. nil and positive means hide, negative
3363 means show, 0 means toggle."
3366 (let ((hide (gnus-article-hidden-text-p type)))
3372 (gnus-article-show-hidden-text type)
3375 (if (eq hide 'hidden)
3377 (gnus-article-show-hidden-text type)
3381 (defun gnus-article-hidden-text-p (type)
3382 "Say whether the current buffer contains hidden text of type TYPE."
3383 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3385 (not (get-text-property pos 'invisible))
3386 (not (get-text-property pos 'dummy-invisible)))
3388 (text-property-any (1+ pos) (point-max) 'article-type type)))
3393 (defun gnus-article-show-hidden-text (type &optional dummy)
3394 "Show all hidden text of type TYPE.
3395 Originally it is hide instead of DUMMY."
3396 (let ((inhibit-read-only t)
3397 (inhibit-point-motion-hooks t))
3398 (gnus-remove-text-properties-when
3400 (point-min) (point-max)
3401 (cons 'article-type (cons type
3402 gnus-hidden-properties)))
3403 (gnus-delete-wash-type type)))
3405 (defconst article-time-units
3406 `((year . ,(* 365.25 24 60 60))
3407 (week . ,(* 7 24 60 60))
3408 (day . ,(* 24 60 60))
3412 "Mapping from time units to seconds.")
3414 (defun gnus-article-forward-header ()
3415 "Move point to the start of the next header.
3416 If the current header is a continuation header, this can be several
3421 (if (looking-at "[ \t]+[^ \t]")
3425 (defun article-treat-date ()
3426 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3427 (with-current-buffer gnus-summary-buffer
3428 gnus-article-date-headers)
3429 gnus-article-date-headers)
3432 (defun article-date-ut (&optional type highlight date-position)
3433 "Convert DATE date to TYPE in the current article.
3434 The default type is `ut'. See `gnus-article-date-headers' for
3436 (interactive (list 'ut t))
3437 (let* ((case-fold-search t)
3438 (inhibit-read-only t)
3439 (inhibit-point-motion-hooks t)
3441 (visible-date (mail-fetch-field "Date"))
3442 pos date bface eface)
3446 (goto-char date-position)
3447 (setq date (get-text-property (point) 'original-date))
3448 (when (looking-at "[^:]+:[\t ]*")
3449 (setq bface (get-text-property (match-beginning 0) 'face)
3450 eface (get-text-property (match-end 0) 'face)))
3451 (delete-region (point)
3453 (gnus-article-forward-header)
3455 (article-transform-date date type bface eface))
3458 (goto-char (point-min))
3459 (while (or (get-text-property (setq pos (point)) 'original-date)
3460 (and (setq pos (next-single-property-change
3461 (point) 'original-date))
3463 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3464 (1+ (match-beginning 0))
3466 (while (setq pos (text-property-not-all pos (point-max)
3467 'gnus-date-type nil))
3468 (setq date (get-text-property pos 'original-date))
3470 (when (looking-at "[^:]+:[\t ]*")
3471 (setq bface (get-text-property (match-beginning 0) 'face)
3472 eface (get-text-property (match-end 0) 'face)))
3473 (delete-region pos (or (text-property-any pos (point-max)
3474 'gnus-date-type nil)
3476 (unless date ;; the 1st time
3477 (goto-char (point-min))
3478 (while (re-search-forward "^Date:[\t ]*" nil t)
3479 (setq date (get-text-property (match-beginning 0)
3481 bface (get-text-property (match-beginning 0) 'face)
3482 eface (get-text-property (match-end 0) 'face))
3483 (delete-region (point-at-bol) (progn
3484 (gnus-article-forward-header)
3486 (when (and (not date)
3488 (setq date visible-date))
3490 (article-transform-date date type bface eface))
3491 (goto-char (point-max))
3494 (defun article-transform-date (date type bface eface)
3495 (dolist (this-type (cond
3505 (add-text-properties
3508 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3510 (list 'original-date date 'gnus-date-type this-type))))
3513 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3514 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3515 (when (match-beginning 2)
3516 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3517 (while (and (zerop (forward-line 1))
3518 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3519 (when (match-beginning 1)
3520 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3522 (defun article-make-date-line (date type)
3523 "Return a DATE line of TYPE."
3524 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3526 (error "Unknown conversion type: %s" type))
3528 (let ((time (ignore-errors (date-to-time date))))
3530 ;; Convert to the local timezone.
3532 (concat "Date: " (message-make-date time)))
3533 ;; Convert to Universal Time.
3538 (let* ((e (parse-time-string date))
3539 (tm (apply 'encode-time e))
3541 (ls (- (cadr tm) (car (current-time-zone time)))))
3542 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3543 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3547 ;; Get the original date from the article.
3548 ((eq type 'original)
3549 (concat "Date: " (if (string-match "\n+$" date)
3550 (substring date 0 (match-beginning 0))
3552 ;; Let the user define the format.
3553 ((eq type 'user-defined)
3554 (let ((format (or (condition-case nil
3555 (with-current-buffer gnus-summary-buffer
3556 gnus-article-time-format)
3558 gnus-article-time-format)))
3559 (if (functionp format)
3560 (funcall format time)
3561 (concat "Date: " (format-time-string format time)))))
3564 (let ((tz (car (current-time-zone time))))
3567 (format-time-string "%Y%m%dT%H%M%S" time)
3568 (format "%s%02d%02d"
3569 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3570 (/ (% (abs tz) 3600) 60)))))
3571 ;; Do a lapsed format.
3573 (concat "Date: " (article-lapsed-string time)))
3574 ;; A combined date/lapsed format.
3575 ((eq type 'combined-lapsed)
3576 (let ((date-string (article-make-date-line date 'original))
3582 (concat " (" (article-lapsed-string time segments) ")"))
3583 (> (+ (length date-string)
3584 (length lapsed-string))
3587 (setq segments (1- segments)))
3589 (concat date-string lapsed-string)
3591 ;; Display the date in proper English
3593 (let ((dtime (decode-time time)))
3596 (number-to-string (nth 3 dtime))
3597 (let ((digit (% (nth 3 dtime) 10)))
3599 ((memq (nth 3 dtime) '(11 12 13)) "th")
3605 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3607 (number-to-string (nth 5 dtime))
3609 (format "%02d" (nth 2 dtime))
3611 (format "%02d" (nth 1 dtime)))))))
3613 (format "Date: %s (from Gnus)" date))))
3615 (defun article-lapsed-string (time &optional max-segments)
3616 ;; If the date is seriously mangled, the timezone functions are
3617 ;; liable to bug out, so we ignore all errors.
3618 (let* ((now (current-time))
3619 (real-time (subtract-time now time))
3620 (real-sec (and real-time
3621 (+ (* (float (car real-time)) 65536)
3623 (sec (and real-time (abs real-sec)))
3626 (unless max-segments
3627 (setq max-segments (length article-time-units)))
3635 ;; This is a bit convoluted, but basically we go
3636 ;; through the time units for years, weeks, etc,
3637 ;; and divide things to see whether that results
3638 ;; in positive answers.
3641 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3642 (>= segments max-segments))
3643 ;; The (remaining) seconds are too few to
3644 ;; be divided into this time unit.
3646 ;; It's big enough, so we output it.
3647 (setq sec (- sec (* num (cdr unit))))
3649 (concat (if prev ", " "") (int-to-string
3651 " " (symbol-name (car unit))
3652 (if (> num 1) "s" ""))
3654 segments (1+ segments)))))
3655 article-time-units "")
3656 ;; If dates are odd, then it might appear like the
3657 ;; article was sent in the future.
3660 " in the future"))))))
3662 (defun article-date-local (&optional highlight)
3663 "Convert the current article date to the local timezone."
3664 (interactive (list t))
3665 (article-date-ut 'local highlight))
3667 (defun article-date-english (&optional highlight)
3668 "Convert the current article date to something that is proper English."
3669 (interactive (list t))
3670 (article-date-ut 'english highlight))
3672 (defun article-date-original (&optional highlight)
3673 "Convert the current article date to what it was originally.
3674 This is only useful if you have used some other date conversion
3675 function and want to see what the date was before converting."
3676 (interactive (list t))
3677 (article-date-ut 'original highlight))
3679 (defun article-date-lapsed (&optional highlight)
3680 "Convert the current article date to time lapsed since it was sent."
3681 (interactive (list t))
3682 (article-date-ut 'lapsed highlight))
3684 (defun article-date-combined-lapsed (&optional highlight)
3685 "Convert the current article date to time lapsed since it was sent."
3686 (interactive (list t))
3687 (article-date-ut 'combined-lapsed highlight))
3689 (defun article-update-date-lapsed ()
3690 "Function to be run from a timer to update the lapsed time line."
3692 (let ((buffer (current-buffer)))
3696 (set-buffer (window-buffer w))
3697 (when (derived-mode-p 'gnus-article-mode)
3698 (let ((old-line (count-lines (point-min) (point)))
3699 (old-column (- (point) (line-beginning-position)))
3700 (window-start (window-start w))
3703 (while (setq pos (text-property-not-all pos (point-max)
3704 'gnus-date-type nil))
3705 (setq next (or (next-single-property-change pos
3708 (setq type (get-text-property pos 'gnus-date-type))
3709 (when (memq type '(lapsed combined-lapsed user-defined))
3710 (article-date-ut type t pos)
3711 (setq end (or (next-single-property-change pos
3715 (if (/= window-start next)
3716 (setq window-start nil)
3717 (set-window-start w end)))
3720 (goto-char (point-min))
3721 (when (> old-column 0)
3722 (setq old-line (1- old-line)))
3723 (forward-line old-line)
3725 (when (> (current-column) old-column)
3727 (forward-char old-column)))))
3729 (set-buffer buffer))))
3731 (defun gnus-start-date-timer (&optional n)
3732 "Start a timer to update the Date headers in the article buffers.
3733 The numerical prefix says how frequently (in seconds) the function
3738 (gnus-stop-date-timer)
3739 (setq article-lapsed-timer
3740 (run-at-time 1 n 'article-update-date-lapsed)))
3742 (defun gnus-stop-date-timer ()
3743 "Stop the Date timer."
3745 (when article-lapsed-timer
3746 (nnheader-cancel-timer article-lapsed-timer)
3747 (setq article-lapsed-timer nil)))
3749 (defun article-date-user (&optional highlight)
3750 "Convert the current article date to the user-defined format.
3751 This format is defined by the `gnus-article-time-format' variable."
3752 (interactive (list t))
3753 (article-date-ut 'user highlight))
3755 (defun article-date-iso8601 (&optional highlight)
3756 "Convert the current article date to ISO8601."
3757 (interactive (list t))
3758 (article-date-ut 'iso8601 highlight))
3760 (defmacro gnus-article-save-original-date (&rest forms)
3761 "Save the original date as a text property and evaluate FORMS."
3762 `(let* ((case-fold-search t)
3764 (goto-char (point-min))
3765 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3768 (date (when (and start
3769 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3771 (buffer-substring-no-properties start
3772 (match-beginning 0)))))
3773 (goto-char (point-max))
3774 (skip-chars-backward "\n")
3775 (put-text-property (point-min) (point) 'original-date date)
3777 (goto-char (point-max))
3778 (skip-chars-backward "\n")
3779 (put-text-property (point-min) (point) 'original-date date)))
3781 ;; (defun article-show-all ()
3782 ;; "Show all hidden text in the article buffer."
3785 ;; (let ((inhibit-read-only t))
3786 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3788 (defun article-remove-leading-whitespace ()
3789 "Remove excessive whitespace from all headers."
3793 (let ((inhibit-read-only t))
3794 (article-narrow-to-head)
3795 (goto-char (point-min))
3796 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3797 (delete-region (match-beginning 1) (match-end 1)))))))
3799 (defun article-emphasize (&optional arg)
3800 "Emphasize text according to `gnus-emphasis-alist'."
3801 (interactive (gnus-article-hidden-arg))
3802 (unless (gnus-article-check-hidden-text 'emphasis arg)
3806 (with-current-buffer gnus-summary-buffer
3807 gnus-article-emphasis-alist)
3809 gnus-emphasis-alist))
3810 (inhibit-read-only t)
3811 (props (append '(article-type emphasis)
3812 gnus-hidden-properties))
3813 regexp elem beg invisible visible face)
3816 (while (setq elem (pop alist))
3818 (setq regexp (car elem)
3819 invisible (nth 1 elem)
3820 visible (nth 2 elem)
3822 (while (re-search-forward regexp nil t)
3823 (when (and (match-beginning visible) (match-beginning invisible))
3824 (gnus-article-hide-text
3825 (match-beginning invisible) (match-end invisible) props)
3826 (gnus-article-unhide-text-type
3827 (match-beginning visible) (match-end visible) 'emphasis)
3828 (gnus-put-overlay-excluding-newlines
3829 (match-beginning visible) (match-end visible) 'face face)
3830 (gnus-add-wash-type 'emphasis)
3831 (goto-char (match-end invisible)))))))))
3833 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3834 "Setup newsgroup emphasis alist."
3835 (unless gnus-article-emphasis-alist
3836 (let ((name (and gnus-newsgroup-name
3837 (gnus-group-real-name gnus-newsgroup-name))))
3838 (make-local-variable 'gnus-article-emphasis-alist)
3839 (setq gnus-article-emphasis-alist
3841 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3842 (while (setq elem (pop alist))
3843 (when (and name (string-match (car elem) name))
3845 highlight (copy-sequence (cdr elem)))))
3847 (copy-sequence highlight-words)
3848 (if gnus-newsgroup-name
3849 (copy-sequence (gnus-group-find-parameter
3850 gnus-newsgroup-name 'highlight-words t)))
3851 gnus-emphasis-alist)))))
3853 (defvar gnus-summary-article-menu)
3854 (defvar gnus-summary-post-menu)
3856 ;;; Saving functions.
3858 (defun gnus-article-save (save-buffer file &optional num)
3859 "Save the currently selected article."
3860 (when (or (get gnus-default-article-saver :headers)
3861 (not gnus-save-all-headers))
3862 ;; Remove headers according to `gnus-saved-headers' or the value
3863 ;; of the `:headers' property that the saver function might have.
3864 (let ((gnus-visible-headers
3865 (or (symbol-value (get gnus-default-article-saver :headers))
3866 gnus-saved-headers gnus-visible-headers))
3867 ;; Ignore group parameter. See `article-hide-headers'.
3868 (gnus-summary-buffer nil))
3869 (with-current-buffer save-buffer
3870 (article-hide-headers 1 t))))
3871 (save-window-excursion
3872 (if (not gnus-default-article-saver)
3873 (error "No default saver is defined")
3874 ;; !!! Magic! The saving functions all save
3875 ;; `gnus-save-article-buffer' (or so they think), but we
3876 ;; bind that variable to our save-buffer.
3877 (set-buffer gnus-article-buffer)
3878 (let* ((gnus-save-article-buffer save-buffer)
3881 ((not gnus-prompt-before-saving) 'default)
3882 ((eq gnus-prompt-before-saving 'always) nil)
3884 (gnus-number-of-articles-to-be-saved
3885 (when (eq gnus-prompt-before-saving t)
3887 (set-buffer gnus-article-current-summary)
3888 (funcall gnus-default-article-saver filename)))))
3890 (defun gnus-read-save-file-name (prompt &optional filename
3891 function group headers variable
3894 (funcall function group headers (symbol-value variable)))
3899 ((eq filename 'default)
3905 (when (symbol-value dir-var)
3906 (setq default-name (expand-file-name
3907 (file-name-nondirectory default-name)
3908 (symbol-value dir-var))))
3909 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3912 (if (and gnus-number-of-articles-to-be-saved
3913 (> gnus-number-of-articles-to-be-saved 1))
3914 (format "these %d articles"
3915 gnus-number-of-articles-to-be-saved)
3918 ;; Let the split methods have their say.
3920 ;; No split name was found.
3923 (concat prompt " (default "
3924 (file-name-nondirectory default-name) "): ")
3925 (file-name-directory default-name)
3927 ;; A single group name is returned.
3928 ((stringp split-name)
3930 (funcall function split-name headers
3931 (symbol-value variable)))
3933 (concat prompt " (default "
3934 (file-name-nondirectory default-name) "): ")
3935 (file-name-directory default-name)
3937 ;; A single split name was found
3938 ((= 1 (length split-name))
3939 (let* ((name (expand-file-name
3941 gnus-article-save-directory))
3942 (dir (cond ((file-directory-p name)
3943 (file-name-as-directory name))
3944 ((file-exists-p name) name)
3945 (t gnus-article-save-directory))))
3947 (concat prompt " (default " name "): ")
3949 ;; A list of splits was found.
3951 (setq split-name (nreverse split-name))
3953 (let ((file-name-history
3954 (nconc split-name file-name-history)))
3958 (concat prompt " (`M-p' for defaults): ")
3959 gnus-article-save-directory
3961 gnus-article-save-directory)))
3962 (car (push result file-name-history)))))))
3963 ;; Create the directory.
3964 (gnus-make-directory (file-name-directory file))
3965 ;; If we have read a directory, we append the default file name.
3966 (when (file-directory-p file)
3967 (setq file (expand-file-name (file-name-nondirectory
3969 (file-name-as-directory file))))
3970 ;; Possibly translate some characters.
3971 (nnheader-translate-file-chars file))))))
3972 (gnus-make-directory (file-name-directory result))
3974 (set variable result))
3976 (set dir-var (file-name-directory result)))
3979 (defun gnus-article-archive-name (group)
3980 "Return the first instance of an \"Archive-name\" in the current buffer."
3981 (let ((case-fold-search t))
3982 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3983 (nnheader-concat gnus-article-save-directory
3984 (match-string 1)))))
3986 (defun gnus-article-nndoc-name (group)
3987 "If GROUP is an nndoc group, return the name of the parent group."
3988 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3989 (gnus-group-get-parameter group 'save-article-group)))
3991 (defun gnus-summary-save-in-rmail (&optional filename)
3992 "Append this article to Rmail file.
3993 Optional argument FILENAME specifies file name.
3994 Directory to save to is default to `gnus-article-save-directory'."
3995 (setq filename (gnus-read-save-file-name
3996 "Save %s in rmail file" filename
3997 gnus-rmail-save-name gnus-newsgroup-name
3998 gnus-current-headers 'gnus-newsgroup-last-rmail))
3999 (with-current-buffer gnus-save-article-buffer
4003 ;; Note that unlike gnus-summary-save-in-mail, there is no
4004 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4006 (gnus-output-to-rmail filename))))
4009 (defun gnus-summary-save-in-mail (&optional filename)
4010 "Append this article to Unix mail file.
4011 Optional argument FILENAME specifies file name.
4012 Directory to save to is default to `gnus-article-save-directory'."
4013 (setq filename (gnus-read-save-file-name
4014 "Save %s in Unix mail file" filename
4015 gnus-mail-save-name gnus-newsgroup-name
4016 gnus-current-headers 'gnus-newsgroup-last-mail))
4017 (with-current-buffer gnus-save-article-buffer
4021 (if (and (file-readable-p filename)
4022 (file-regular-p filename)
4023 (mail-file-babyl-p filename))
4024 (gnus-output-to-rmail filename)
4025 (gnus-output-to-mail filename)))))
4028 (put 'gnus-summary-save-in-file :decode t)
4029 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4030 (defun gnus-summary-save-in-file (&optional filename overwrite)
4031 "Append this article to file.
4032 Optional argument FILENAME specifies file name.
4033 Directory to save to is default to `gnus-article-save-directory'."
4034 (setq filename (gnus-read-save-file-name
4035 "Save %s in file" filename
4036 gnus-file-save-name gnus-newsgroup-name
4037 gnus-current-headers 'gnus-newsgroup-last-file))
4038 (with-current-buffer gnus-save-article-buffer
4042 (when (and overwrite
4043 (file-exists-p filename))
4044 (delete-file filename))
4045 (gnus-output-to-file filename))))
4048 (put 'gnus-summary-write-to-file :decode t)
4049 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4050 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4051 (defun gnus-summary-write-to-file (&optional filename)
4052 "Write this article to a file, overwriting it if the file exists.
4053 Optional argument FILENAME specifies file name.
4054 The directory to save in defaults to `gnus-article-save-directory'."
4055 (setq filename (gnus-read-save-file-name
4056 "Save %s in file" filename
4057 gnus-file-save-name gnus-newsgroup-name
4058 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4059 (gnus-summary-save-in-file filename t))
4061 (put 'gnus-summary-save-body-in-file :decode t)
4062 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4063 "Append this article body to a file.
4064 Optional argument FILENAME specifies file name.
4065 The directory to save in defaults to `gnus-article-save-directory'."
4066 (setq filename (gnus-read-save-file-name
4067 "Save %s body in file" filename
4068 gnus-file-save-name gnus-newsgroup-name
4069 gnus-current-headers 'gnus-newsgroup-last-file))
4070 (with-current-buffer gnus-save-article-buffer
4074 (when (article-goto-body)
4075 (narrow-to-region (point) (point-max)))
4076 (when (and overwrite
4077 (file-exists-p filename))
4078 (delete-file filename))
4079 (gnus-output-to-file filename))))
4082 (put 'gnus-summary-write-body-to-file :decode t)
4083 (put 'gnus-summary-write-body-to-file
4084 :function 'gnus-summary-save-body-in-file)
4085 (defun gnus-summary-write-body-to-file (&optional filename)
4086 "Write this article body to a file, overwriting it if the file exists.
4087 Optional argument FILENAME specifies file name.
4088 The directory to save in defaults to `gnus-article-save-directory'."
4089 (setq filename (gnus-read-save-file-name
4090 "Save %s body in file" filename
4091 gnus-file-save-name gnus-newsgroup-name
4092 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4093 (gnus-summary-save-body-in-file filename t))
4095 (put 'gnus-summary-save-in-pipe :decode t)
4096 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4097 (defun gnus-summary-save-in-pipe (&optional command raw)
4098 "Pipe this article to subprocess COMMAND.
4099 Valid values for COMMAND include:
4101 The executable command name and possibly arguments.
4103 You will be prompted for the command in the minibuffer.
4104 the symbol `default'
4105 It will be replaced with the command which the variable
4106 `gnus-summary-pipe-output-default-command' holds or the command
4107 last used for saving.
4108 Non-nil value for RAW overrides `:decode' and `:headers' properties
4109 and the raw article including all headers will be piped."
4110 (let ((article (gnus-summary-article-number))
4112 (get 'gnus-summary-save-in-pipe :decode)))
4113 save-buffer default)
4115 (if (vectorp (gnus-summary-article-header article))
4116 (save-current-buffer
4117 (gnus-summary-select-article decode decode nil article)
4118 (insert-buffer-substring
4122 gnus-original-article-buffer)
4124 (nnheader-set-temp-buffer " *Gnus Save*"))))
4125 ;; Remove unwanted headers.
4126 (when (and (not raw)
4127 (or (get 'gnus-summary-save-in-pipe :headers)
4128 (not gnus-save-all-headers)))
4129 (let ((gnus-visible-headers
4130 (or (symbol-value (get 'gnus-summary-save-in-pipe
4132 gnus-saved-headers gnus-visible-headers))
4133 (gnus-summary-buffer nil))
4134 (article-hide-headers 1 t))))
4135 (error "%d is not a real article" article))
4136 (error "No article to pipe"))
4137 (setq default (or gnus-summary-pipe-output-default-command
4138 gnus-last-shell-command))
4139 (unless (stringp command)
4141 (if (and (eq command 'default) default)
4143 (gnus-read-shell-command "Shell command on this article: "
4145 (when (string-equal command "")
4147 (setq command default)
4148 (error "A command is required")))
4149 (with-current-buffer save-buffer
4152 (shell-command-on-region (point-min) (point-max) command nil)))
4153 (gnus-kill-buffer save-buffer))
4154 (setq gnus-summary-pipe-output-default-command command))
4156 (defun gnus-summary-pipe-to-muttprint (&optional command)
4157 "Pipe this article to muttprint."
4158 (unless (stringp command)
4159 (setq command (read-string
4160 "Print using command: " gnus-summary-muttprint-program
4161 nil gnus-summary-muttprint-program)))
4162 (let ((gnus-summary-pipe-output-default-command
4163 gnus-summary-pipe-output-default-command))
4164 (gnus-summary-save-in-pipe command))
4165 (setq gnus-summary-muttprint-program command))
4167 ;;; Article file names when saving.
4169 (defun gnus-capitalize-newsgroup (newsgroup)
4170 "Capitalize NEWSGROUP name."
4171 (when (not (zerop (length newsgroup)))
4172 (concat (char-to-string (upcase (aref newsgroup 0)))
4173 (substring newsgroup 1))))
4175 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4176 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4177 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4178 Otherwise, it is like ~/News/news/group/num."
4181 (concat (if (gnus-use-long-file-name 'not-save)
4182 (gnus-capitalize-newsgroup newsgroup)
4183 (gnus-newsgroup-directory-form newsgroup))
4184 "/" (int-to-string (mail-header-number headers)))
4185 gnus-article-save-directory)))
4187 (string-equal (file-name-directory default)
4188 (file-name-directory last-file))
4189 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4191 (or last-file default))))
4193 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4194 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4195 If variable `gnus-use-long-file-name' is non-nil, it is
4196 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4199 (concat (if (gnus-use-long-file-name 'not-save)
4201 (gnus-newsgroup-directory-form newsgroup))
4202 "/" (int-to-string (mail-header-number headers)))
4203 gnus-article-save-directory)))
4205 (string-equal (file-name-directory default)
4206 (file-name-directory last-file))
4207 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4209 (or last-file default))))
4211 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4212 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4213 If variable `gnus-use-long-file-name' is non-nil, it is
4214 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4217 (if (gnus-use-long-file-name 'not-save)
4220 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4222 gnus-article-save-directory)))
4224 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4225 "Generate file name from sender."
4226 (let ((from (mail-header-from headers)))
4228 (if (and from (string-match "\\([^ <]+\\)@" from))
4229 (match-string 1 from)
4231 gnus-article-save-directory)))
4233 (defun article-verify-x-pgp-sig ()
4235 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4237 (if (gnus-buffer-live-p gnus-original-article-buffer)
4238 (let ((sig (with-current-buffer gnus-original-article-buffer
4239 (gnus-fetch-field "X-PGP-Sig")))
4243 (mml2015-clear-verify-function))
4245 (insert-buffer-substring gnus-original-article-buffer)
4246 (setq items (split-string sig))
4247 (message-narrow-to-head)
4248 (let ((inhibit-point-motion-hooks t)
4249 (case-fold-search t))
4250 ;; Don't verify multiple headers.
4251 (setq headers (mapconcat (lambda (header)
4253 (mail-fetch-field header)
4255 (split-string (nth 1 items) ",") "")))
4256 (delete-region (point-min) (point-max))
4257 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4258 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4263 (if (looking-at "^-")
4266 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4267 (insert "Version: " (car items) "\n\n")
4268 (insert (mapconcat 'identity (cddr items) "\n"))
4269 (insert "\n-----END PGP SIGNATURE-----\n")
4270 (let ((mm-security-handle (list (format "multipart/signed"))))
4271 (mml2015-clean-buffer)
4272 (let ((coding-system-for-write (or gnus-newsgroup-charset
4274 (funcall (mml2015-clear-verify-function)))
4276 (or (mm-handle-multipart-ctl-parameter
4277 mm-security-handle 'gnus-details)
4278 (mm-handle-multipart-ctl-parameter
4279 mm-security-handle 'gnus-info)))))
4281 (let ((inhibit-read-only t) bface eface)
4283 (message-narrow-to-head)
4284 (goto-char (point-max))
4286 (setq bface (get-text-property (point-at-bol) 'face)
4287 eface (get-text-property (1- (point-at-eol)) 'face))
4288 (message-remove-header "X-Gnus-PGP-Verify")
4289 (if (re-search-forward "^X-PGP-Sig:" nil t)
4291 (goto-char (point-max)))
4292 (narrow-to-region (point) (point))
4293 (insert "X-Gnus-PGP-Verify: " info "\n")
4294 (goto-char (point-min))
4297 (if (not (looking-at "^[ \t]"))
4301 (goto-char (point-min))
4302 (when (looking-at "\\([^:]+\\): *")
4303 (put-text-property (match-beginning 1) (1+ (match-end 1))
4305 (put-text-property (match-end 0) (point-max)
4306 'face eface)))))))))
4308 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4310 (defun article-verify-cancel-lock ()
4311 "Verify Cancel-Lock header."
4313 (if (gnus-buffer-live-p gnus-original-article-buffer)
4314 (canlock-verify gnus-original-article-buffer)))
4321 (setq afunc (car func)
4324 gfunc (intern (format "gnus-%s" func))))
4326 (when (fboundp afunc)
4327 `(lambda (&optional interactive &rest args)
4328 ,(documentation afunc t)
4329 (interactive (list t))
4330 (with-current-buffer gnus-article-buffer
4332 (call-interactively ',afunc)
4333 (apply ',afunc args))))))))
4334 '(article-hide-headers
4335 article-verify-x-pgp-sig
4336 article-verify-cancel-lock
4337 article-hide-boring-headers
4338 article-treat-overstrike
4339 article-treat-ansi-sequences
4340 article-fill-long-lines
4341 article-capitalize-sentences
4343 article-remove-leading-whitespace
4344 article-display-x-face
4345 article-display-face
4346 article-de-quoted-unreadable
4347 article-de-base64-unreadable
4350 article-unsplit-urls
4351 article-hide-list-identifiers
4352 article-strip-banner
4355 article-hide-signature
4356 article-strip-headers-in-body
4357 article-remove-trailing-blank-lines
4358 article-strip-leading-blank-lines
4359 article-strip-multiple-blank-lines
4360 article-strip-leading-space
4361 article-strip-trailing-space
4362 article-strip-blank-lines
4363 article-strip-all-blank-lines
4365 article-date-english
4366 article-date-iso8601
4367 article-date-original
4370 article-decode-mime-words
4371 article-decode-charset
4372 article-decode-encoded-words
4375 article-date-combined-lapsed
4377 article-treat-dumbquotes
4378 article-treat-non-ascii
4379 article-normalize-headers
4380 ;;(article-show-all . gnus-article-show-all-headers)
4384 ;;; Gnus article mode
4387 (put 'gnus-article-mode 'mode-class 'special)
4389 (set-keymap-parent gnus-article-mode-map widget-keymap)
4391 (gnus-define-keys gnus-article-mode-map
4392 " " gnus-article-goto-next-page
4393 [?\S-\ ] gnus-article-goto-prev-page
4394 "\177" gnus-article-goto-prev-page
4395 [delete] gnus-article-goto-prev-page
4396 "\C-c^" gnus-article-refer-article
4397 "h" gnus-article-show-summary
4398 "s" gnus-article-show-summary
4399 "\C-c\C-m" gnus-article-mail
4400 "?" gnus-article-describe-briefly
4401 "<" beginning-of-buffer
4403 "\C-c\C-i" gnus-info-find-node
4405 "R" gnus-article-reply-with-original
4406 "F" gnus-article-followup-with-original
4407 "\C-hk" gnus-article-describe-key
4408 "\C-hc" gnus-article-describe-key-briefly
4409 "\C-hb" gnus-article-describe-bindings
4411 "e" gnus-article-read-summary-keys
4412 "\C-d" gnus-article-read-summary-keys
4413 "\M-*" gnus-article-read-summary-keys
4414 "\M-#" gnus-article-read-summary-keys
4415 "\M-^" gnus-article-read-summary-keys
4416 "\M-g" gnus-article-read-summary-keys)
4418 (substitute-key-definition
4419 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4421 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4422 "W" gnus-article-wide-reply-with-original)
4423 (if (featurep 'xemacs)
4424 (set-keymap-default-binding gnus-article-send-map
4425 'gnus-article-read-summary-send-keys)
4426 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4428 (defun gnus-article-make-menu-bar ()
4429 (unless (boundp 'gnus-article-commands-menu)
4430 (gnus-summary-make-menu-bar))
4431 (unless (boundp 'gnus-article-article-menu)
4433 gnus-article-article-menu gnus-article-mode-map ""
4435 ["Scroll forwards" gnus-article-goto-next-page t]
4436 ["Scroll backwards" gnus-article-goto-prev-page t]
4437 ["Show summary" gnus-article-show-summary t]
4438 ["Fetch Message-ID at point" gnus-article-refer-article t]
4439 ["Mail to address at point" gnus-article-mail t]
4440 ["Send a bug report" gnus-bug t]))
4443 gnus-article-treatment-menu gnus-article-mode-map ""
4444 ;; Fixme: this should use :active (and maybe :visible).
4446 ["Hide headers" gnus-article-hide-headers t]
4447 ["Hide signature" gnus-article-hide-signature t]
4448 ["Hide citation" gnus-article-hide-citation t]
4449 ["Treat overstrike" gnus-article-treat-overstrike t]
4450 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4451 ["Remove carriage return" gnus-article-remove-cr t]
4452 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4453 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4454 ["Remove base64" gnus-article-de-base64-unreadable t]
4455 ["Treat html" gnus-article-wash-html t]
4456 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4457 ["Decode HZ" gnus-article-decode-HZ t]))
4459 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4461 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4463 (gnus-run-hooks 'gnus-article-menu-hook)))
4465 (defvar bookmark-make-record-function)
4466 (defvar shr-put-image-function)
4468 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4469 "Major mode for displaying an article.
4471 All normal editing commands are switched off.
4473 The following commands are available in addition to all summary mode
4475 \\<gnus-article-mode-map>
4476 \\[gnus-article-next-page]\t Scroll the article one page forwards
4477 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4478 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4479 \\[gnus-article-show-summary]\t Display the summary buffer
4480 \\[gnus-article-mail]\t Send a reply to the address near point
4481 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4482 \\[gnus-info-find-node]\t Go to the Gnus info node"
4483 (gnus-simplify-mode-line)
4484 (make-local-variable 'minor-mode-alist)
4485 (when (gnus-visual-p 'article-menu 'menu)
4486 (gnus-article-make-menu-bar)
4487 (when gnus-summary-tool-bar-map
4488 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4489 (gnus-update-format-specifications nil 'article-mode)
4490 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4491 (set (make-local-variable 'gnus-page-broken) nil)
4492 (make-local-variable 'gnus-article-current-summary)
4493 (make-local-variable 'gnus-article-mime-handles)
4494 (make-local-variable 'gnus-article-decoded-p)
4495 (make-local-variable 'gnus-article-mime-handle-alist)
4496 (make-local-variable 'gnus-article-wash-types)
4497 (make-local-variable 'gnus-article-image-alist)
4498 (make-local-variable 'gnus-article-charset)
4499 (make-local-variable 'gnus-article-ignored-charsets)
4500 (set (make-local-variable 'bookmark-make-record-function)
4501 'gnus-summary-bookmark-make-record)
4502 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4504 (set (make-local-variable 'nobreak-char-display) nil)
4505 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4506 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4507 (setq cursor-in-non-selected-windows nil)
4508 (gnus-set-default-directory)
4509 (buffer-disable-undo)
4510 (setq buffer-read-only t
4511 show-trailing-whitespace nil)
4512 (mm-enable-multibyte))
4514 (defun gnus-article-setup-buffer ()
4515 "Initialize the article buffer."
4516 (let* ((name (if gnus-single-article-buffer "*Article*"
4518 (gnus-group-decoded-name gnus-newsgroup-name)
4521 (progn (string-match "\\*Article" name)
4522 (concat " *Original Article"
4523 (substring name (match-end 0))))))
4524 (setq gnus-article-buffer name)
4525 (setq gnus-original-article-buffer original)
4526 (setq gnus-article-mime-handle-alist nil)
4527 (with-current-buffer gnus-summary-buffer
4528 ;; This might be a variable local to the summary buffer.
4529 (unless gnus-single-article-buffer
4530 (setq gnus-article-buffer name)
4531 (setq gnus-original-article-buffer original)
4532 (gnus-set-global-variables)))
4533 (gnus-article-setup-highlight-words)
4534 ;; Init original article buffer.
4535 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4536 (mm-enable-multibyte)
4537 (setq major-mode 'gnus-original-article-mode)
4538 (make-local-variable 'gnus-original-article))
4539 (if (and (get-buffer name)
4540 (with-current-buffer name
4541 (if gnus-article-edit-mode
4542 (if (y-or-n-p "Article mode edit in progress; discard? ")
4544 (set-buffer-modified-p nil)
4545 (gnus-kill-buffer name)
4548 (error "Action aborted"))
4550 (let ((summary gnus-summary-buffer))
4551 (with-current-buffer name
4552 (set (make-local-variable 'gnus-article-edit-mode) nil)
4553 (gnus-article-stop-animations)
4554 (when gnus-article-mime-handles
4555 (mm-destroy-parts gnus-article-mime-handles)
4556 (setq gnus-article-mime-handles nil))
4557 ;; Set it to nil in article-buffer!
4558 (setq gnus-article-mime-handle-alist nil)
4559 (buffer-disable-undo)
4560 (setq buffer-read-only t)
4561 (unless (derived-mode-p 'gnus-article-mode)
4562 (gnus-article-mode))
4563 (set (make-local-variable 'gnus-summary-buffer) summary)
4564 (setq truncate-lines gnus-article-truncate-lines)
4566 (let ((summary gnus-summary-buffer))
4567 (with-current-buffer (gnus-get-buffer-create name)
4569 (setq truncate-lines gnus-article-truncate-lines)
4570 (set (make-local-variable 'gnus-summary-buffer) summary)
4571 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4572 (when article-lapsed-timer
4573 (gnus-stop-date-timer))
4574 (when gnus-article-update-date-headers
4575 (gnus-start-date-timer gnus-article-update-date-headers))
4576 (current-buffer))))))
4578 (defun gnus-article-stop-animations ()
4579 (dolist (timer (and (boundp 'timer-list)
4581 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4582 (cancel-timer timer))))
4584 (defun gnus-stop-downloads ()
4585 (when (boundp 'url-queue)
4586 (set (intern "url-queue" obarray) nil)))
4588 ;; Set article window start at LINE, where LINE is the number of lines
4589 ;; from the head of the article.
4590 (defun gnus-article-set-window-start (&optional line)
4591 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4592 (when article-window
4595 (with-current-buffer gnus-article-buffer
4596 (goto-char (point-min))
4599 (gnus-message 6 "Moved to bookmark")
4600 (search-forward "\n\n" nil t)
4604 (defun gnus-article-prepare (article &optional all-headers header)
4605 "Prepare ARTICLE in article mode buffer.
4606 ARTICLE should either be an article number or a Message-ID.
4607 If ARTICLE is an id, HEADER should be the article headers.
4608 If ALL-HEADERS is non-nil, no headers are hidden."
4610 ;; Make sure we start in a summary buffer.
4611 (unless (derived-mode-p 'gnus-summary-mode)
4612 (set-buffer gnus-summary-buffer))
4613 (setq gnus-summary-buffer (current-buffer))
4614 (let* ((gnus-article (if header (mail-header-number header) article))
4615 (summary-buffer (current-buffer))
4616 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4617 (group gnus-newsgroup-name)
4620 (gnus-article-setup-buffer)
4621 (set-buffer gnus-article-buffer)
4622 ;; Deactivate active regions.
4623 (when (and (boundp 'transient-mark-mode)
4624 transient-mark-mode)
4625 (setq mark-active nil))
4626 (if (not (setq result (let ((inhibit-read-only t))
4627 (gnus-request-article-this-buffer
4629 ;; There is no such article.
4631 (when (and (numberp article)
4632 (not (memq article gnus-newsgroup-sparse)))
4633 (setq gnus-article-current
4634 (cons gnus-newsgroup-name article))
4635 (set-buffer gnus-summary-buffer)
4636 (setq gnus-current-article article)
4637 (if (and (memq article gnus-newsgroup-undownloaded)
4638 (not (gnus-online (gnus-find-method-for-group
4639 gnus-newsgroup-name))))
4641 (gnus-summary-set-agent-mark article)
4642 (message "Message marked for downloading"))
4643 (gnus-summary-mark-article article gnus-canceled-mark)
4644 (unless (memq article gnus-newsgroup-sparse)
4645 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4646 (if (or (eq result 'pseudo)
4647 (eq result 'nneething))
4649 (with-current-buffer summary-buffer
4650 (push article gnus-newsgroup-history)
4651 (setq gnus-last-article gnus-current-article
4652 gnus-current-article 0
4653 gnus-current-headers nil
4654 gnus-article-current nil)
4655 (if (eq result 'nneething)
4656 (gnus-configure-windows 'summary)
4657 (gnus-configure-windows 'article))
4658 (gnus-set-global-variables))
4659 (let ((gnus-article-mime-handle-alist-1
4660 gnus-article-mime-handle-alist))
4661 (gnus-set-mode-line 'article)))
4662 ;; The result from the `request' was an actual article -
4663 ;; or at least some text that is now displayed in the
4665 (when (and (numberp article)
4666 (not (eq article gnus-current-article)))
4667 ;; Seems like a new article has been selected.
4668 ;; `gnus-current-article' must be an article number.
4669 (with-current-buffer summary-buffer
4670 (push article gnus-newsgroup-history)
4671 (setq gnus-last-article gnus-current-article
4672 gnus-current-article article
4673 gnus-current-headers
4674 (gnus-summary-article-header gnus-current-article)
4675 gnus-article-current
4676 (cons gnus-newsgroup-name gnus-current-article))
4677 (unless (vectorp gnus-current-headers)
4678 (setq gnus-current-headers nil))
4679 (gnus-summary-goto-subject gnus-current-article)
4680 (when (gnus-summary-show-thread)
4681 ;; If the summary buffer really was folded, the
4682 ;; previous goto may not actually have gone to
4683 ;; the right article, but the thread root instead.
4685 (gnus-summary-goto-subject gnus-current-article))
4686 (gnus-run-hooks 'gnus-mark-article-hook)
4687 (gnus-set-mode-line 'summary)
4688 (when (gnus-visual-p 'article-highlight 'highlight)
4689 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4690 ;; Set the global newsgroup variables here.
4691 (gnus-set-global-variables)
4692 (setq gnus-have-all-headers
4693 (or all-headers gnus-show-all-headers))))
4695 (gnus-configure-windows 'article))
4696 (when (or (numberp article)
4698 (gnus-article-prepare-display)
4700 (goto-char (point-min))
4701 (when gnus-break-pages
4702 (gnus-narrow-to-page)))
4703 (let ((gnus-article-mime-handle-alist-1
4704 gnus-article-mime-handle-alist))
4705 (gnus-set-mode-line 'article))
4709 (set-window-point (get-buffer-window (current-buffer)) (point))
4710 (gnus-configure-windows 'article)
4711 (gnus-run-hooks 'gnus-article-prepare-hook)
4715 (defun gnus-article-prepare-display ()
4716 "Make the current buffer look like a nice article."
4717 ;; Hooks for getting information from the article.
4718 ;; This hook must be called before being narrowed.
4719 (let ((gnus-article-buffer (current-buffer))
4721 (inhibit-read-only t))
4722 (unless (derived-mode-p 'gnus-article-mode)
4723 (gnus-article-mode))
4724 (setq buffer-read-only nil
4725 gnus-article-wash-types nil
4726 gnus-article-image-alist nil)
4727 (gnus-run-hooks 'gnus-tmp-internal-hook)
4728 (when gnus-display-mime-function
4729 (funcall gnus-display-mime-function))
4730 ;; Add attachment buttons to the header.
4731 (when gnus-mime-display-attachment-buttons-in-header
4732 (gnus-mime-buttonize-attachments-in-header))))
4735 ;;; Gnus Sticky Article Mode
4738 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4739 "Mode for sticky articles."
4740 ;; Release bindings that won't work.
4741 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4742 gnus-sticky-article-mode-map)
4743 (substitute-key-definition 'gnus-article-refer-article 'undefined
4744 gnus-sticky-article-mode-map)
4745 (dolist (k '("e" "h" "s" "F" "R"))
4746 (define-key gnus-sticky-article-mode-map k nil))
4747 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4748 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4749 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4750 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4752 (defun gnus-sticky-article (arg)
4753 "Make the current article sticky.
4754 If a prefix ARG is given, ask for a name for this sticky article buffer."
4756 (gnus-summary-show-thread)
4757 (gnus-summary-select-article nil nil 'pseudo)
4758 (let (new-art-buf-name)
4759 (gnus-eval-in-buffer-window gnus-article-buffer
4760 (setq new-art-buf-name
4764 (read-from-minibuffer "Sticky article buffer name: ")
4765 (gnus-with-article-headers
4766 (gnus-article-goto-header "subject")
4767 (setq new-art-buf-name
4768 (buffer-substring-no-properties
4769 (line-beginning-position) (line-end-position)))
4770 (goto-char (point-min))
4771 (gnus-article-goto-header "from")
4772 (setq new-art-buf-name
4774 new-art-buf-name ", "
4775 (buffer-substring-no-properties
4776 (line-beginning-position) (line-end-position))))
4777 (goto-char (point-min))
4778 (gnus-article-goto-header "date")
4779 (setq new-art-buf-name
4781 new-art-buf-name ", "
4782 (buffer-substring-no-properties
4783 (line-beginning-position) (line-end-position))))))
4785 (if (and (gnus-buffer-live-p new-art-buf-name)
4786 (with-current-buffer new-art-buf-name
4787 (derived-mode-p 'gnus-sticky-article-mode)))
4788 (switch-to-buffer new-art-buf-name)
4789 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4790 (gnus-sticky-article-mode))
4791 (setq gnus-article-buffer new-art-buf-name))
4792 (gnus-summary-recenter)
4793 (gnus-summary-position-point))
4795 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4796 "Kill the given sticky article BUFFER.
4797 If none is given, assume the current buffer and kill it if it has
4798 `gnus-sticky-article-mode'."
4801 (setq buffer (current-buffer)))
4802 (with-current-buffer buffer
4803 (when (derived-mode-p 'gnus-sticky-article-mode)
4804 (gnus-kill-buffer buffer))))
4806 (defun gnus-kill-sticky-article-buffers (arg)
4807 "Kill all sticky article buffers.
4808 If a prefix ARG is given, ask for confirmation."
4810 (dolist (buf (gnus-buffers))
4811 (with-current-buffer buf
4812 (when (derived-mode-p 'gnus-sticky-article-mode)
4814 (gnus-kill-buffer buf)
4815 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4816 (gnus-kill-buffer buf)))))))
4819 ;;; Gnus MIME viewing functions
4822 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4823 "Format of the MIME buttons.
4825 Valid specifiers include:
4827 %T MIME type, along with additional info
4828 %n The `name' parameter
4829 %d The description, if any
4830 %l The length of the encoded part
4831 %p The part identifier number
4832 %e Dots if the part isn't displayed
4834 General format specifiers can also be used. See Info node
4835 `(gnus)Formatting Variables'.")
4837 (defvar gnus-mime-button-line-format-alist
4838 '((?t gnus-tmp-type ?s)
4839 (?T gnus-tmp-type-long ?s)
4840 (?n gnus-tmp-name ?s)
4841 (?d gnus-tmp-description ?s)
4843 (?l gnus-tmp-length ?d)
4844 (?e gnus-tmp-dots ?s)))
4846 (defvar gnus-mime-button-commands
4847 '((gnus-article-press-button "\r" "Toggle Display")
4848 (gnus-mime-view-part "v" "View Interactively...")
4849 (gnus-mime-view-part-as-type "t" "View As Type...")
4850 (gnus-mime-view-part-as-charset "C" "View As charset...")
4851 (gnus-mime-save-part "o" "Save...")
4852 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4853 (gnus-mime-replace-part "r" "Replace part")
4854 (gnus-mime-delete-part "d" "Delete part")
4855 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4856 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4857 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4858 (gnus-mime-view-part-externally "e" "View Externally")
4859 (gnus-mime-print-part "p" "Print")
4860 (gnus-mime-pipe-part "|" "Pipe To Command...")
4861 (gnus-mime-action-on-part "." "Take action on the part...")))
4863 (defun gnus-article-mime-part-status ()
4864 (if gnus-article-mime-handle-alist-1
4865 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4867 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4870 (defvar gnus-mime-button-map
4871 (let ((map (make-sparse-keymap)))
4872 (define-key map gnus-mouse-2 'gnus-article-push-button)
4873 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4874 (dolist (c gnus-mime-button-commands)
4875 (define-key map (cadr c) (car c)))
4879 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4881 ,@(mapcar (lambda (c)
4882 (vector (caddr c) (car c) :active t))
4883 gnus-mime-button-commands)))
4885 (defvar gnus-url-button-commands
4886 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4888 (defvar gnus-url-button-map
4889 (let ((map (make-sparse-keymap)))
4890 (dolist (c gnus-url-button-commands)
4891 (define-key map (cadr c) (car c)))
4895 gnus-url-button-menu gnus-url-button-map "URL button menu."
4897 ,@(mapcar (lambda (c)
4898 (vector (caddr c) (car c) :active t))
4899 gnus-url-button-commands)))
4901 (defmacro gnus-bind-safe-url-regexp (&rest body)
4902 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4903 `(let ((mm-w3m-safe-url-regexp
4904 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4906 gnus-article-current-summary))
4907 (with-current-buffer gnus-article-current-summary
4908 gnus-newsgroup-name)
4909 gnus-newsgroup-name)))
4910 (if (cond ((not group)
4911 ;; Maybe we're in a mml-preview buffer
4912 ;; and no group is selected.
4914 ((stringp gnus-safe-html-newsgroups)
4915 (string-match gnus-safe-html-newsgroups group))
4916 ((consp gnus-safe-html-newsgroups)
4917 (member group gnus-safe-html-newsgroups)))
4919 mm-w3m-safe-url-regexp))))
4922 (defun gnus-mime-button-menu (event prefix)
4923 "Construct a context-sensitive menu of MIME commands."
4924 (interactive "e\nP")
4925 (save-window-excursion
4926 (let ((pos (event-start event)))
4927 (select-window (posn-window pos))
4928 (goto-char (posn-point pos))
4929 (gnus-article-check-buffer)
4930 (popup-menu gnus-mime-button-menu nil prefix))))
4932 (defun gnus-mime-view-all-parts (&optional handles)
4933 "View all the MIME parts."
4935 (with-current-buffer gnus-article-buffer
4936 (let ((handles (or handles gnus-article-mime-handles))
4937 (mail-parse-charset gnus-newsgroup-charset)
4938 (mail-parse-ignored-charsets
4939 (with-current-buffer gnus-summary-buffer
4940 gnus-newsgroup-ignored-charsets)))
4942 (mm-remove-parts handles)
4943 (goto-char (point-min))
4944 (or (search-forward "\n\n") (goto-char (point-max)))
4945 (let ((inhibit-read-only t))
4946 (delete-region (point) (point-max))
4947 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4949 (defun gnus-article-jump-to-part (n)
4950 "Jump to MIME part N."
4952 (let ((parts (with-current-buffer gnus-article-buffer
4953 (length gnus-article-mime-handle-alist))))
4955 (error "No such part"))
4956 (pop-to-buffer gnus-article-buffer)
4958 (setq n (if (= parts 1)
4960 (read-number (format "Jump to part (1..%s): " parts)))))
4961 (unless (and (integerp n) (<= n parts) (>= n 1))
4964 (gnus-message 7 "Invalid part `%s', using %s instead."
4967 (gnus-message 9 "Jumping to part %s." n)
4968 (cond ((>= gnus-auto-select-part 1)
4969 (while (and (<= n parts)
4970 (not (gnus-article-goto-part n)))
4972 ((< gnus-auto-select-part 0)
4973 (while (and (>= n 1)
4974 (not (gnus-article-goto-part n)))
4977 (gnus-article-goto-part n)))))
4979 (defvar gnus-mime-buttonized-part-id nil
4980 "ID of a mime part that should be buttonized.
4981 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4984 (defsubst gnus-article-edit-part (handles &optional current-id)
4985 "Edit an article in order to delete a mime part.
4986 This function is exclusively used by `gnus-mime-save-part-and-strip'
4987 and `gnus-mime-delete-part', and not provided at run-time normally."
4988 (gnus-article-edit-article
4990 (buffer-disable-undo)
4991 (let ((mail-parse-charset (or gnus-article-charset
4992 ',gnus-newsgroup-charset))
4993 (mail-parse-ignored-charsets
4994 (or gnus-article-ignored-charsets
4995 ',gnus-newsgroup-ignored-charsets))
4996 (mbl mml-buffer-list))
4997 (setq mml-buffer-list nil)
4998 ;; A new text must be inserted before deleting existing ones
4999 ;; at the end so as not to move existing markers of which
5000 ;; the insertion type is t.
5004 (goto-char (point-max))
5005 (insert-buffer-substring gnus-original-article-buffer)))
5006 (mime-to-mml ',handles)
5007 (setq gnus-article-mime-handles nil)
5008 (let ((mbl1 mml-buffer-list))
5009 (setq mml-buffer-list mbl)
5010 (set (make-local-variable 'mml-buffer-list) mbl1))
5011 (gnus-make-local-hook 'kill-buffer-hook)
5012 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5013 `(lambda (no-highlight)
5014 (let ((mail-parse-charset (or gnus-article-charset
5015 ',gnus-newsgroup-charset))
5016 (message-options message-options)
5017 (message-options-set-recipient)
5018 (mail-parse-ignored-charsets
5019 (or gnus-article-ignored-charsets
5020 ',gnus-newsgroup-ignored-charsets)))
5022 (mml-destroy-buffers)
5023 (remove-hook 'kill-buffer-hook
5024 'mml-destroy-buffers t)
5025 (kill-local-variable 'mml-buffer-list))
5026 (gnus-summary-edit-article-done
5027 ,(or (mail-header-references gnus-current-headers) "")
5028 ,(gnus-group-read-only-p)
5029 ,gnus-summary-buffer no-highlight))
5031 ;; Force buttonizing this part.
5032 (let ((gnus-mime-buttonized-part-id current-id))
5033 (gnus-article-edit-done))
5034 (gnus-configure-windows 'article)
5035 (when (and current-id (integerp gnus-auto-select-part))
5036 (gnus-article-jump-to-part
5037 (min (max (+ current-id gnus-auto-select-part) 1)
5038 (with-current-buffer gnus-article-buffer
5039 (length gnus-article-mime-handle-alist)))))))
5041 (defun gnus-mime-replace-part (file)
5042 "Replace MIME part under point with an external body."
5043 ;; Useful if file has already been saved to disk
5046 (read-file-name "Replace MIME part with file: "
5047 (or mm-default-directory default-directory)
5049 (gnus-mime-save-part-and-strip file))
5051 (defun gnus-mime-save-part-and-strip (&optional file)
5052 "Save the MIME part under point then replace it with an external body.
5053 If FILE is given, use it for the external part."
5055 (gnus-article-check-buffer)
5056 (when (gnus-group-read-only-p)
5057 (error "The current group does not support deleting of parts"))
5058 (when (mm-complicated-handles gnus-article-mime-handles)
5060 The current article has a complicated MIME structure, giving up..."))
5061 (let* ((data (get-text-property (point) 'gnus-data))
5062 (id (get-text-property (point) 'gnus-part))
5064 (handles gnus-article-mime-handles))
5067 (and data (mm-save-part data "Delete MIME part and save to: "))))
5069 (with-current-buffer (mm-handle-buffer data)
5071 (insert "Content-Type: " (mm-handle-media-type data))
5072 (mml-insert-parameter-string (cdr (mm-handle-type data))
5074 ;; Add a filename for the sake of saving the part again.
5075 (mml-insert-parameter
5076 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5078 (insert "Content-ID: " (message-make-message-id) "\n")
5079 (insert "Content-Transfer-Encoding: binary\n")
5082 (cdr (mm-make-handle nil
5083 `("message/external-body"
5084 (access-type . "LOCAL-FILE")
5086 ;; (set-buffer gnus-summary-buffer)
5087 (gnus-article-edit-part handles id))))
5089 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5090 ;; parts...>') but with stripping would be nice.
5092 (defun gnus-mime-delete-part ()
5093 "Delete the MIME part under point.
5094 Replace it with some information about the removed part."
5096 (gnus-article-check-buffer)
5097 (when (gnus-group-read-only-p)
5098 (error "The current group does not support deleting of parts"))
5099 (when (mm-complicated-handles gnus-article-mime-handles)
5101 The current article has a complicated MIME structure, giving up..."))
5102 (when (or gnus-expert-user
5103 (gnus-yes-or-no-p "\
5104 Deleting parts may malfunction or destroy the article; continue? "))
5105 (let* ((data (get-text-property (point) 'gnus-data))
5106 (id (get-text-property (point) 'gnus-part))
5107 (handles gnus-article-mime-handles)
5109 (let ((desc (mm-handle-description data)))
5111 (mail-decode-encoded-word-string desc))))
5112 (filename (or (mm-handle-filename data) "(none)"))
5113 (type (mm-handle-media-type data)))
5115 (error "No MIME part under point"))
5116 (with-current-buffer (mm-handle-buffer data)
5117 (let ((bsize (buffer-size)))
5122 "| The following attachment has been deleted:\n"
5124 "| Type: " type "\n"
5125 "| Filename: " filename "\n"
5126 "| Size (encoded): " (format "%s byte%s\n"
5127 bsize (if (= bsize 1)
5131 (concat "| Description: " description "\n"))
5134 (cdr (mm-make-handle
5135 nil `("text/plain" (charset . gnus-decoded)) nil nil
5137 (format "Deleted attachment (%s bytes)" bsize))))))
5138 ;; (set-buffer gnus-summary-buffer)
5139 (gnus-article-edit-part handles id))))
5141 (defun gnus-mime-save-part ()
5142 "Save the MIME part under point."
5144 (gnus-article-check-buffer)
5145 (let ((data (get-text-property (point) 'gnus-data)))
5147 (mm-save-part data))))
5149 (defun gnus-mime-pipe-part (&optional cmd)
5150 "Pipe the MIME part under point to a process.
5151 Use CMD as the process."
5153 (gnus-article-check-buffer)
5154 (let ((data (get-text-property (point) 'gnus-data)))
5156 (mm-pipe-part data cmd))))
5158 (defun gnus-mime-view-part ()
5159 "Interactively choose a viewing method for the MIME part under point."
5161 (gnus-article-check-buffer)
5162 (let ((data (get-text-property (point) 'gnus-data)))
5164 (setq gnus-article-mime-handles
5166 gnus-article-mime-handles (setq data (copy-sequence data))))
5167 (mm-interactively-view-part data))))
5169 (defun gnus-mime-view-part-as-type-internal ()
5170 (gnus-article-check-buffer)
5171 (let* ((handle (get-text-property (point) 'gnus-data))
5173 ;; Content-Type: foo/bar; name=...
5174 (mail-content-type-get (mm-handle-type handle) 'name)
5175 ;; Content-Disposition: attachment; filename=...
5176 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5177 (def-type (and name (mm-default-file-encoding name))))
5178 (or (and def-type (cons def-type 0))
5180 (equal (mm-handle-media-supertype handle) "text")
5181 '("text/plain" . 0))
5182 '("application/octet-stream" . 0))))
5184 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5185 "Choose a MIME media type, and view the part as such.
5186 If non-nil, PRED is a predicate to use during completion to limit the
5187 available media-types."
5191 (let ((default (gnus-mime-view-part-as-type-internal)))
5192 (gnus-completing-read
5195 (gnus-remove-if-not pred (mailcap-mime-types))
5196 (mailcap-mime-types))
5199 (gnus-article-check-buffer)
5200 (let ((handle (get-text-property (point) 'gnus-data)))
5202 (when (equal (mm-handle-media-type handle) "message/external-body")
5203 (unless (mm-handle-cache handle)
5204 (mm-extern-cache-contents handle))
5205 (setq handle (mm-handle-cache handle)))
5207 (mm-make-handle (mm-handle-buffer handle)
5208 (cons mime-type (cdr (mm-handle-type handle)))
5209 (mm-handle-encoding handle)
5210 (mm-handle-undisplayer handle)
5211 (mm-handle-disposition handle)
5212 (mm-handle-description handle)
5214 (mm-handle-id handle)))
5215 (setq gnus-article-mime-handles
5216 (mm-merge-handles gnus-article-mime-handles handle))
5217 (when (mm-handle-displayed-p handle)
5218 (mm-remove-part handle))
5219 (gnus-mm-display-part handle))))
5221 (defun gnus-mime-copy-part (&optional handle arg)
5222 "Put the MIME part under point into a new buffer.
5223 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5225 (interactive (list nil current-prefix-arg))
5226 (gnus-article-check-buffer)
5228 (setq handle (get-text-property (point) 'gnus-data)))
5230 (let ((filename (mm-handle-filename handle))
5231 contents dont-decode charset coding-system)
5232 (mm-with-unibyte-buffer
5233 (mm-insert-part handle)
5234 (setq contents (or (condition-case nil
5235 (mm-decompress-buffer filename nil 'sig)
5237 (setq dont-decode t)
5240 (setq filename (cond (filename (file-name-nondirectory filename))
5241 (dont-decode "*raw data*")
5246 (unless (setq charset (mail-content-type-get
5247 (mm-handle-type handle) 'charset))
5248 (unless (setq coding-system (mm-with-unibyte-buffer
5250 (mm-find-buffer-file-coding-system)))
5251 (setq charset gnus-newsgroup-charset))))
5253 (setq charset (or (cdr (assq arg
5254 gnus-summary-show-article-charset-alist))
5255 (mm-read-coding-system "Charset: ")))))
5256 (switch-to-buffer (generate-new-buffer filename))
5257 (if (or coding-system
5259 (setq coding-system (mm-charset-to-coding-system
5261 (not (eq coding-system 'ascii))))
5263 (mm-enable-multibyte)
5264 (insert (mm-decode-coding-string contents coding-system))
5265 (setq buffer-file-coding-system
5266 (if (boundp 'last-coding-system-used)
5267 (symbol-value 'last-coding-system-used)
5269 (mm-disable-multibyte)
5271 (setq buffer-file-coding-system mm-binary-coding-system))
5272 ;; We do it this way to make `normal-mode' set the appropriate mode.
5275 (setq buffer-file-name (expand-file-name filename))
5277 (setq buffer-file-name nil))
5278 (goto-char (point-min)))))
5280 (defun gnus-mime-print-part (&optional handle filename)
5281 "Print the MIME part under point."
5282 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5283 (gnus-article-check-buffer)
5284 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5285 (contents (and handle (mm-get-part handle)))
5286 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5287 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5292 (mm-save-part-to-file handle file)
5293 (call-process shell-file-name nil
5294 (generate-new-buffer " *mm*")
5296 shell-command-switch
5298 printer file (mm-handle-type handle))))
5302 (gnus-print-buffer))
5303 (ps-despool filename)))))
5305 (defun gnus-mime-inline-part (&optional handle arg)
5306 "Insert the MIME part under point into the current buffer.
5307 Compressed files like .gz and .bz2 are decompressed."
5308 (interactive (list nil current-prefix-arg))
5309 (gnus-article-check-buffer)
5310 (let* ((inhibit-read-only t)
5312 (btn ;; position where the MIME button exists
5314 (if (eq handle (get-text-property b 'gnus-data))
5317 (or (text-property-any (point) (point-max) 'gnus-data handle)
5318 (text-property-any (point-min) (point) 'gnus-data handle)))
5319 (setq handle (get-text-property b 'gnus-data))
5321 start contents charset coding-system)
5325 (setq start (next-single-property-change btn 'gnus-data
5327 btn (previous-single-property-change start
5330 (if (and (not arg) (mm-handle-undisplayer handle))
5331 (mm-remove-part handle)
5332 (mm-with-unibyte-buffer
5333 (mm-insert-part handle)
5335 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5339 (unless (setq charset (mail-content-type-get
5340 (mm-handle-type handle) 'charset))
5341 (unless (setq coding-system
5342 (mm-with-unibyte-buffer
5344 (mm-find-buffer-file-coding-system)))
5345 (setq charset gnus-newsgroup-charset))))
5347 (if (mm-handle-undisplayer handle)
5348 (mm-remove-part handle))
5351 gnus-summary-show-article-charset-alist))
5352 (mm-read-coding-system "Charset: "))))
5353 ((mm-handle-undisplayer handle)
5354 (mm-remove-part handle)))
5357 ;; This is a header button.
5359 (mm-display-inline handle))
5360 ;; Toggle the button appearance between `[button]...' and `[button]'.
5362 (let ((displayed-p (mm-handle-displayed-p handle)))
5363 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5365 (if (featurep 'emacs)
5368 (next-single-property-change (point) 'gnus-data nil (point-max)))
5369 (let* ((end (next-single-property-change (point) 'gnus-data))
5370 (annots (annotations-at (or end (point-max)))))
5371 (delete-region (point)
5373 (if annots (1+ end) end)
5375 (dolist (annot annots)
5376 (set-extent-endpoints annot (point) (point)))))
5377 (setq start (point))
5378 (if (search-backward "\n\n" nil t)
5381 (unless (or displayed-p (eolp))
5382 ;; Add extra newline.
5383 (insert (propertize (buffer-substring (1- start) start)
5384 'gnus-undeletable t))))
5385 ;; We're in the article header.
5387 (dolist (ovl (gnus-overlays-in btn (point)))
5388 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5389 (gnus-overlay-put ovl 'face nil))
5391 (message-narrow-to-field)
5392 (let ((gnus-treatment-function-alist
5393 '((gnus-treat-highlight-headers
5394 gnus-article-highlight-headers))))
5395 (gnus-treat-article 'head)))))
5398 (defun gnus-mime-set-charset-parameters (handle charset)
5399 "Set CHARSET to parameters in HANDLE.
5400 CHARSET may either be a string or a symbol."
5401 (unless (stringp charset)
5402 (setq charset (symbol-name charset)))
5403 (if (stringp (car handle))
5404 (dolist (h (cdr handle))
5405 (gnus-mime-set-charset-parameters h charset))
5406 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5407 "message/external-body")
5409 (unless (mm-handle-cache handle)
5410 (mm-extern-cache-contents handle))
5411 (mm-handle-cache handle))
5413 (param (assq 'charset (cdr type))))
5415 (setcdr param charset)
5416 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5418 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5419 "Insert the MIME part under point into the current buffer using the
5421 (interactive (list nil current-prefix-arg))
5422 (gnus-article-check-buffer)
5423 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5424 (fun (get-text-property (point) 'gnus-callback))
5425 (gnus-newsgroup-ignored-charsets 'gnus-all)
5426 charset form preferred parts)
5433 gnus-summary-show-article-charset-alist))
5434 (mm-read-coding-system "Charset: "))))
5435 (if (mm-handle-undisplayer handle)
5436 (mm-remove-part handle)))
5437 (gnus-mime-set-charset-parameters handle charset)
5438 (when (and (consp (setq form (cdr-safe fun)))
5439 (setq form (ignore-errors
5440 (assq 'gnus-mime-display-alternative form)))
5441 (setq preferred (caddr form))
5443 (when (eq (car preferred) 'quote)
5444 (setq preferred (cadr preferred)))
5445 (not (equal preferred
5446 (get-text-property (point) 'gnus-data))))
5447 (setq parts (get-text-property (point) 'gnus-part))
5448 (setq parts (cdr (assq parts
5449 gnus-article-mime-handle-alist)))
5450 (equal (mm-handle-media-type parts) "multipart/alternative")
5451 (setq parts (reverse (cdr parts))))
5453 (list 'quote (or (cadr (member preferred parts))
5455 (funcall fun handle)))))
5457 (defun gnus-mime-view-part-externally (&optional handle)
5458 "View the MIME part under point with an external viewer."
5460 (gnus-article-check-buffer)
5461 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5462 (mm-user-display-methods nil)
5463 (mm-inlined-types nil)
5464 (mail-parse-charset gnus-newsgroup-charset)
5465 (mail-parse-ignored-charsets
5466 (with-current-buffer gnus-summary-buffer
5467 gnus-newsgroup-ignored-charsets))
5468 (type (mm-handle-media-type handle))
5469 (method (mailcap-mime-info type))
5470 (mm-enable-external t))
5471 (if (not (stringp method))
5472 (gnus-mime-view-part-as-type
5473 nil (lambda (type) (stringp (mailcap-mime-info type))))
5475 (mm-display-part handle nil t)))))
5477 (defun gnus-mime-view-part-internally (&optional handle)
5478 "View the MIME part under point with an internal viewer.
5479 If no internal viewer is available, use an external viewer."
5481 (gnus-article-check-buffer)
5482 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5483 (mm-inlined-types '(".*"))
5484 (mm-inline-large-images t)
5485 (mail-parse-charset gnus-newsgroup-charset)
5486 (mail-parse-ignored-charsets
5487 (with-current-buffer gnus-summary-buffer
5488 gnus-newsgroup-ignored-charsets))
5489 (inhibit-read-only t))
5490 (if (not (mm-inlinable-p handle))
5491 (gnus-mime-view-part-as-type
5492 nil (lambda (type) (mm-inlinable-p handle type)))
5494 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5496 (defun gnus-mime-action-on-part (&optional action)
5497 "Do something with the MIME attachment at \(point\)."
5499 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5500 (gnus-article-check-buffer)
5501 (let ((action-pair (assoc action gnus-mime-action-alist)))
5503 (funcall (cdr action-pair)))))
5505 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5506 "Call FUNCTION on MIME part N.
5507 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5508 If INTERACTIVE, call FUNCTION interactively."
5510 ;; Check whether the article is displayed.
5511 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5512 (setq window (get-buffer-window gnus-article-buffer t))
5513 (frame-visible-p (setq frame (window-frame window))))
5514 (error "No article is displayed"))
5515 (with-current-buffer gnus-article-buffer
5516 ;; Check whether the article displays the right contents.
5517 (unless (with-current-buffer gnus-summary-buffer
5518 (eq gnus-current-article (gnus-summary-article-number)))
5519 (error "You should select the right article first"))
5521 (setq n (prefix-numeric-value n))
5523 (setq n (or (get-text-property pt 'gnus-part)
5525 (get-text-property (1- pt) 'gnus-part))
5526 (get-text-property (prog2
5532 (or (and (setq pt (previous-single-property-change
5535 (next-single-property-change (point) 'gnus-part)
5539 ;; Check whether the specified part exists.
5540 (when (> n (length gnus-article-mime-handle-alist))
5541 (error "No such part")))
5544 ;; To select the window is needed so that the cursor
5545 ;; might be visible on the MIME button.
5546 (select-window (prog1
5548 (setq window (selected-window))
5549 ;; Article may be displayed in the other frame.
5550 (gnus-select-frame-set-input-focus
5553 (setq frame (selected-frame))))))
5554 (when (gnus-article-goto-part n)
5555 ;; We point the cursor and the arrow at the MIME button
5556 ;; when the `function' prompt the user for something.
5557 (unless (and (pos-visible-in-window-p)
5558 (> (count-lines (point) (window-end))
5559 (/ (1- (window-height)) 3)))
5560 (recenter (/ (1- (window-height)) 3)))
5561 (let ((cursor-in-non-selected-windows t)
5562 (overlay-arrow-string "=>")
5563 (overlay-arrow-position (point-marker)))
5566 ((and no-handle interactive)
5567 (call-interactively function))
5572 function (get-text-property (point) 'gnus-data)))
5575 (get-text-property (point) 'gnus-data))))
5576 (set-marker overlay-arrow-position nil)
5577 (unless gnus-auto-select-part
5578 (gnus-select-frame-set-input-focus frame)
5579 (select-window window))))
5581 (if gnus-inhibit-mime-unbuttonizing
5582 ;; This is the default though the program shouldn't reach here.
5583 (error "No such part")
5584 ;; The part which doesn't have the MIME button is selected.
5585 ;; So, we display all the buttons and redo it.
5586 (let ((gnus-inhibit-mime-unbuttonizing t))
5587 (gnus-summary-show-article)
5588 (gnus-article-part-wrapper n function no-handle))))))
5590 (defun gnus-article-pipe-part (n)
5591 "Pipe MIME part N, which is the numerical prefix."
5593 (gnus-article-part-wrapper n 'mm-pipe-part))
5595 (defun gnus-article-save-part (n)
5596 "Save MIME part N, which is the numerical prefix."
5598 (gnus-article-part-wrapper n 'mm-save-part))
5600 (defun gnus-article-interactively-view-part (n)
5601 "View MIME part N interactively, which is the numerical prefix."
5603 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5605 (defun gnus-article-copy-part (n)
5606 "Copy MIME part N, which is the numerical prefix."
5608 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5610 (defun gnus-article-view-part-as-charset (n)
5611 "View MIME part N using a specified charset.
5612 N is the numerical prefix."
5614 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5616 (defun gnus-article-view-part-externally (n)
5617 "View MIME part N externally, which is the numerical prefix."
5619 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5621 (defun gnus-article-inline-part (n)
5622 "Inline MIME part N, which is the numerical prefix."
5624 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5626 (defun gnus-article-save-part-and-strip (n)
5627 "Save MIME part N and replace it with an external body.
5628 N is the numerical prefix."
5630 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5632 (defun gnus-article-replace-part (n)
5633 "Replace MIME part N with an external body.
5634 N is the numerical prefix."
5636 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5638 (defun gnus-article-delete-part (n)
5639 "Delete MIME part N and add some information about the removed part.
5640 N is the numerical prefix."
5642 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5644 (defun gnus-article-view-part-as-type (n)
5645 "Choose a MIME media type, and view part N as such.
5646 N is the numerical prefix."
5648 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5650 (defun gnus-article-mime-match-handle-first (condition)
5653 (dolist (ihandle gnus-article-mime-handle-alist)
5655 ((functionp condition)
5656 (funcall condition (cdr ihandle)))
5657 ((eq condition 'undisplayed)
5658 (not (or (mm-handle-undisplayer (cdr ihandle))
5659 (equal (mm-handle-media-type (cdr ihandle))
5660 "multipart/alternative"))))
5661 ((eq condition 'undisplayed-alternative)
5662 (not (mm-handle-undisplayer (cdr ihandle))))
5664 (gnus-article-goto-part (car ihandle))
5665 (or (not n) (< (car ihandle) n)))
5666 (setq n (car ihandle))))
5670 (defun gnus-article-view-part (&optional n)
5671 "View MIME part N, which is the numerical prefix.
5672 If the part is already shown, hide the part. If N is nil, view
5675 (with-current-buffer gnus-article-buffer
5676 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5677 gnus-article-mime-match-handle-function)))
5678 (when (> n (length gnus-article-mime-handle-alist))
5679 (error "No such part"))
5680 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5681 (when (gnus-article-goto-part n)
5682 (if (equal (car handle) "multipart/alternative")
5684 (beginning-of-line) ;; Make it toggle subparts
5685 (gnus-article-press-button))
5686 (when (eq (gnus-mm-display-part handle) 'internal)
5687 (gnus-set-window-start)))))))
5689 (defsubst gnus-article-mime-total-parts ()
5690 (if (bufferp (car gnus-article-mime-handles))
5692 (1- (length gnus-article-mime-handles))))
5694 (defun gnus-mm-display-part (handle)
5695 "Display HANDLE and fix MIME button."
5696 (let ((id (get-text-property (point) 'gnus-part))
5698 (inhibit-read-only t)
5699 (window (selected-window))
5700 (mail-parse-charset gnus-newsgroup-charset)
5701 (mail-parse-ignored-charsets
5702 (if (gnus-buffer-live-p gnus-summary-buffer)
5703 (with-current-buffer gnus-summary-buffer
5704 gnus-newsgroup-ignored-charsets)
5709 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5713 (setq start (next-single-property-change point 'gnus-data
5715 point (previous-single-property-change start 'gnus-data))
5716 (if (mm-handle-displayed-p handle)
5717 ;; This will remove the part.
5718 (setq retval (mm-display-part handle))
5719 (let ((part (or (and (mm-inlinable-p handle)
5720 (mm-inlined-p handle)
5723 (gnus-bind-safe-url-regexp
5724 (setq retval (mm-display-part handle)))
5725 (unless (zerop (buffer-size))
5726 (buffer-string))))))
5729 ;; This is a header button.
5731 (cond ((stringp part)
5733 (narrow-to-region (point)
5736 (unless (bolp) (insert "\n"))
5738 (gnus-treat-article nil id
5739 (gnus-article-mime-total-parts)
5740 (mm-handle-media-type handle))
5741 (mm-handle-set-undisplayer
5744 (let ((inhibit-read-only t))
5745 (delete-region ,(copy-marker (point-min) t)
5746 ,(point-max-marker)))))))
5748 (mm-display-inline handle))))))
5750 ;; Toggle the button appearance between `[button]...' and `[button]'.
5751 (let ((displayed-p (mm-handle-displayed-p handle)))
5752 (gnus-insert-mime-button handle id (list displayed-p))
5753 (if (featurep 'emacs)
5756 (next-single-property-change (point) 'gnus-data nil (point-max)))
5757 (let* ((end (next-single-property-change (point) 'gnus-data))
5758 (annots (annotations-at (or end (point-max)))))
5759 (delete-region (point)
5761 (if annots (1+ end) end)
5763 (dolist (annot annots)
5764 (set-extent-endpoints annot (point) (point)))))
5765 (setq start (point))
5766 (if (search-backward "\n\n" nil t)
5769 (unless (or displayed-p (eolp))
5770 ;; Add extra newline.
5771 (insert (propertize (buffer-substring (1- start) start)
5772 'gnus-undeletable t))))
5773 ;; We're in the article header.
5775 (dolist (ovl (gnus-overlays-in point (point)))
5776 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5777 (gnus-overlay-put ovl 'face nil))
5779 (message-narrow-to-field)
5780 (let ((gnus-treatment-function-alist
5781 '((gnus-treat-highlight-headers
5782 gnus-article-highlight-headers))))
5783 (gnus-treat-article 'head)))))
5785 (if (window-live-p window)
5786 (select-window window)))
5789 (defun gnus-article-goto-part (n)
5790 "Go to MIME part N."
5791 (when gnus-break-pages
5795 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5796 ;; There may be header buttons.
5797 (text-property-any (point-min) (point) 'gnus-part n)))
5798 part handle end next handles)
5801 (if (setq handle (get-text-property start 'gnus-data))
5803 ;; Go to the displayed subpart, assuming this is
5804 ;; multipart/alternative.
5807 (while (and (not handle)
5810 (setq next (text-property-not-all part end
5813 handle (get-text-property part 'gnus-data))
5814 (push (cons handle part) handles)
5815 (unless (mm-handle-displayed-p handle)
5817 part (text-property-any part end 'gnus-data nil))))
5819 ;; No subpart is displayed, so we find preferred one.
5821 (cdr (assq (mm-preferred-alternative
5822 (nreverse (mapcar 'car handles)))
5825 (goto-char (1+ part))
5827 (when gnus-break-pages
5828 (gnus-narrow-to-page))))
5830 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5831 (let ((gnus-tmp-name
5832 (or (mm-handle-filename handle)
5833 (mail-content-type-get (mm-handle-type handle) 'url)
5835 (gnus-tmp-type (mm-handle-media-type handle))
5836 (gnus-tmp-description (or (mm-handle-description handle) ""))
5838 (if (if displayed (car displayed)
5839 (mm-handle-displayed-p handle))
5841 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5843 gnus-tmp-type-long b e)
5844 (when (string-match ".*/" gnus-tmp-name)
5845 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5846 (setq gnus-tmp-type-long (concat gnus-tmp-type
5847 (and (not (equal gnus-tmp-name ""))
5848 (concat "; " gnus-tmp-name))))
5849 (unless (equal gnus-tmp-description "")
5850 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5853 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5854 `(keymap ,gnus-mime-button-map
5855 gnus-callback gnus-mm-display-part
5856 gnus-part ,gnus-tmp-id
5857 article-type annotation
5861 ;; Exclude a newline.
5864 (when gnus-article-button-face
5865 (gnus-overlay-put (gnus-make-overlay b e nil t)
5866 'face gnus-article-button-face))
5867 (widget-convert-button
5870 :action 'gnus-widget-press-button
5871 :button-keymap gnus-mime-button-map
5874 ;; Needed to properly clear the message due to a bug in
5875 ;; wid-edit (XEmacs only).
5876 (if (boundp 'help-echo-owns-message)
5877 (setq help-echo-owns-message t))
5879 "%S: %s the MIME part; %S: more options"
5880 (aref gnus-mouse-2 0)
5881 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5883 (aref gnus-down-mouse-3 0))))))
5885 (defun gnus-widget-press-button (elems el)
5886 (goto-char (widget-get elems :from))
5887 (gnus-article-press-button))
5889 (defvar gnus-displaying-mime nil)
5891 (defun gnus-display-mime (&optional ihandles)
5892 "Display the MIME parts."
5894 (save-selected-window
5895 (let ((window (get-buffer-window gnus-article-buffer))
5898 (select-window window)
5899 ;; We have to do this since selecting the window
5900 ;; may change the point. So we set the window point.
5901 (set-window-point window point)))
5902 (let ((handles ihandles)
5903 (inhibit-read-only t)
5906 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5907 (when gnus-article-emulate-mime
5908 (mm-uu-dissect-text-parts handles)))
5909 (gnus-article-emulate-mime
5910 (setq handles (mm-uu-dissect))))
5911 (when (and (not ihandles)
5912 (not gnus-displaying-mime))
5913 ;; Top-level call; we clean up.
5914 (when gnus-article-mime-handles
5915 (mm-destroy-parts gnus-article-mime-handles)
5916 (setq gnus-article-mime-handle-alist nil));; A trick.
5917 (setq gnus-article-mime-handles handles)
5918 ;; We allow users to glean info from the handles.
5919 (when gnus-article-mime-part-function
5920 (gnus-mime-part-function handles)))
5922 (or (not (stringp (car handles)))
5925 (when (and (not ihandles)
5926 (not gnus-displaying-mime))
5927 ;; Clean up for mime parts.
5929 (delete-region (point) (point-max)))
5930 (let ((gnus-displaying-mime t))
5931 (gnus-mime-display-part handles)))
5934 (narrow-to-region (point) (point-max))
5935 (gnus-treat-article nil 1 1 "text/plain")
5938 ;; Highlight the headers.
5942 (narrow-to-region (point-min) (point))
5943 (gnus-article-save-original-date
5944 (gnus-treat-article 'head)))))))
5945 ;; Cope with broken MIME messages.
5946 (goto-char (point-max))
5950 (defcustom gnus-mime-display-multipart-as-mixed nil
5951 "Display \"multipart\" parts as \"multipart/mixed\".
5953 If t, it overrides nil values of
5954 `gnus-mime-display-multipart-alternative-as-mixed' and
5955 `gnus-mime-display-multipart-related-as-mixed'."
5956 :group 'gnus-article-mime
5959 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5960 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5962 :group 'gnus-article-mime
5965 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5966 "Display \"multipart/related\" parts as \"multipart/mixed\".
5968 If displaying \"text/html\" is discouraged \(see
5969 `mm-discouraged-alternatives'\) images or other material inside a
5970 \"multipart/related\" part might be overlooked when this variable is nil."
5972 :group 'gnus-article-mime
5975 (defcustom gnus-mime-display-attachment-buttons-in-header t
5976 "Add attachment buttons in the end of the header of an article.
5977 Since MIME attachments tend to be put at the end of an article, we may
5978 overlook them if there is a huge body. This option offers you a copy
5979 of all non-inlinable MIME parts as buttons shown in front of an article.
5980 If nil, don't show those extra buttons."
5982 :group 'gnus-article-mime
5985 (defun gnus-mime-display-part (handle)
5987 ;; Maybe a broken MIME message.
5990 ((not (stringp (car handle)))
5991 (gnus-mime-display-single handle))
5992 ;; User-defined multipart
5993 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5994 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5996 ;; multipart/alternative
5997 ((and (equal (car handle) "multipart/alternative")
5998 (not (or gnus-mime-display-multipart-as-mixed
5999 gnus-mime-display-multipart-alternative-as-mixed)))
6000 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6001 (push (cons id handle) gnus-article-mime-handle-alist)
6002 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6003 ;; multipart/related
6004 ((and (equal (car handle) "multipart/related")
6005 (not (or gnus-mime-display-multipart-as-mixed
6006 gnus-mime-display-multipart-related-as-mixed)))
6007 (gnus-mime-display-part (cadr handle)))
6008 ((equal (car handle) "multipart/signed")
6009 (gnus-add-wash-type 'signed)
6010 (gnus-mime-display-security handle))
6011 ((equal (car handle) "multipart/encrypted")
6012 (gnus-add-wash-type 'encrypted)
6013 (gnus-mime-display-security handle))
6014 ;; Other multiparts are handled like multipart/mixed.
6016 (gnus-mime-display-mixed (cdr handle)))))
6018 (defun gnus-mime-part-function (handles)
6019 (if (stringp (car handles))
6020 (mapcar 'gnus-mime-part-function (cdr handles))
6021 (funcall gnus-article-mime-part-function handles)))
6023 (defun gnus-mime-display-mixed (handles)
6024 (mapcar 'gnus-mime-display-part handles))
6026 (defun gnus-mime-display-single (handle)
6027 (let ((type (mm-handle-media-type handle))
6028 (ignored gnus-ignored-mime-types)
6034 (when (string-match (pop ignored) type)
6035 (throw 'ignored nil)))
6036 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6037 (with-current-buffer gnus-summary-buffer
6038 gnus-inhibit-images)
6039 gnus-inhibit-images)
6040 (string-match "\\`image/" type)))
6041 (setq not-attachment
6042 (and (not (mm-inline-override-p handle))
6043 (or (not (mm-handle-disposition handle))
6044 (equal (car (mm-handle-disposition handle))
6046 (mm-attachment-override-p handle))))
6047 (mm-automatic-display-p handle)
6049 (mm-inlinable-p handle)
6050 (mm-inlined-p handle))
6051 (mm-automatic-external-display-p type)))
6053 (when (equal (mm-handle-media-supertype handle) "text")
6055 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6058 (setq id (1+ (length gnus-article-mime-handle-alist)))
6059 (push (cons id handle) gnus-article-mime-handle-alist))
6061 (equal (mm-handle-media-supertype handle) "message"))
6064 (cond ((not (bolp)) 2)
6065 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6067 (when (or (not display)
6068 (not (gnus-unbuttonized-mime-type-p type))
6069 (eq id gnus-mime-buttonized-part-id))
6070 (gnus-insert-mime-button
6071 handle id (list (or display (and not-attachment text)))))
6075 (let ((mail-parse-charset gnus-newsgroup-charset)
6076 (mail-parse-ignored-charsets
6077 (save-excursion (condition-case ()
6078 (set-buffer gnus-summary-buffer)
6080 gnus-newsgroup-ignored-charsets)))
6081 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6082 ((and text not-attachment)
6083 (mm-display-inline handle)))
6084 (goto-char (point-max))
6085 (if (string-match "\\`image/" type)
6086 (gnus-article-insert-newline)
6088 (= (skip-chars-backward "\n") -1)
6090 (gnus-article-insert-newline)
6091 (put-text-property (point) (point-max) 'gnus-undeletable t))
6092 (goto-char (point-max)))
6096 (narrow-to-region beg (point))
6097 (if (eq handle gnus-article-mime-handles)
6098 ;; The format=flowed case.
6099 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6100 ;; Don't count signature parts that are never displayed.
6101 ;; The part number should be re-calculated supposing this
6102 ;; might be a message/rfc822 part.
6104 (dolist (part gnus-article-mime-handles)
6105 (unless (or (stringp part)
6106 (equal (car (mm-handle-type part))
6107 "application/pgp-signature"))
6108 (push part handles)))
6110 nil (length (memq handle handles)) (length handles)
6111 (mm-handle-media-type handle)))))))))))
6113 (defun gnus-unbuttonized-mime-type-p (type)
6114 "Say whether TYPE is to be unbuttonized."
6115 (unless gnus-inhibit-mime-unbuttonizing
6117 (let ((types gnus-unbuttonized-mime-types))
6119 (when (string-match (pop types) type)
6120 (throw 'found t)))))
6122 (let ((types gnus-buttonized-mime-types))
6124 (when (string-match (pop types) type)
6125 (throw 'found t)))))))))
6127 (defun gnus-article-insert-newline ()
6128 "Insert a newline, but mark it as undeletable."
6129 (gnus-put-text-property
6130 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6132 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6133 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6136 handle (inhibit-read-only t) from props begend not-pref)
6137 (save-window-excursion
6140 (narrow-to-region (car ibegend)
6143 (goto-char (car ibegend))
6146 (delete-region (point-min) (point-max))
6147 (mm-remove-parts handles))
6148 (setq begend (list (point-marker)))
6150 (unless (setq not-pref (cadr (member preferred ihandles)))
6151 (setq not-pref (car ihandles)))
6154 (not (gnus-unbuttonized-mime-type-p
6155 "multipart/alternative")))
6156 (gnus-add-text-properties
6159 (insert (format "%d. " id))
6163 (unless ,(not ibegend)
6164 (setq gnus-article-mime-handle-alist
6165 ',gnus-article-mime-handle-alist))
6166 (gnus-mime-display-alternative
6167 ',ihandles ',not-pref ',begend ,id))
6168 keymap ,gnus-mime-button-map
6169 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6170 face ,gnus-article-button-face
6172 article-type multipart
6174 (widget-convert-button 'link from (point)
6175 :action 'gnus-widget-press-button
6176 :button-keymap gnus-widget-button-keymap)
6178 (while (setq handle (pop handles))
6179 (gnus-add-text-properties
6182 (insert (format "(%c) %-18s"
6183 (if (equal handle preferred) ?* ? )
6184 (mm-handle-media-type handle)))
6188 (unless ,(not ibegend)
6189 (setq gnus-article-mime-handle-alist
6190 ',gnus-article-mime-handle-alist))
6191 (gnus-mime-display-alternative
6192 ',ihandles ',handle ',begend ,id))
6193 keymap ,gnus-mime-button-map
6194 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6195 face ,gnus-article-button-face
6199 (widget-convert-button 'link from (point)
6200 :action 'gnus-widget-press-button
6201 :button-keymap gnus-widget-button-keymap)
6205 (if (stringp (car preferred))
6206 (gnus-display-mime preferred)
6207 (let ((mail-parse-charset gnus-newsgroup-charset)
6208 (mail-parse-ignored-charsets
6209 (with-current-buffer gnus-summary-buffer
6210 gnus-newsgroup-ignored-charsets)))
6211 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6215 (narrow-to-region (car begend) (point-max))
6217 nil (length gnus-article-mime-handle-alist)
6218 (gnus-article-mime-total-parts)
6219 (mm-handle-media-type preferred))))))
6220 (goto-char (point-max))
6221 (setcdr begend (point-marker)))))
6224 ;; Redraw attachment buttons in the header.
6225 (when gnus-mime-display-attachment-buttons-in-header
6226 (gnus-mime-buttonize-attachments-in-header)))
6228 (defconst gnus-article-wash-status-strings
6229 (let ((alist '((cite "c" "Possible hidden citation text"
6230 " " "All citation text visible")
6231 (headers "h" "Hidden headers"
6232 " " "All headers visible.")
6233 (pgp "p" "Encrypted or signed message status hidden"
6234 " " "No hidden encryption nor digital signature status")
6235 (signature "s" "Signature has been hidden"
6236 " " "Signature is visible")
6237 (overstrike "o" "Overstrike (^H) characters applied"
6238 " " "No overstrike characters applied")
6239 (emphasis "e" "/*_Emphasis_*/ characters applied"
6240 " " "No /*_emphasis_*/ characters applied")))
6242 (dolist (entry alist result)
6243 (let ((key (nth 0 entry))
6244 (on (copy-sequence (nth 1 entry)))
6245 (on-help (nth 2 entry))
6246 (off (copy-sequence (nth 3 entry)))
6247 (off-help (nth 4 entry)))
6248 (put-text-property 0 1 'help-echo on-help on)
6249 (put-text-property 0 1 'help-echo off-help off)
6250 (push (list key on off) result))))
6251 "Alist of strings describing wash status in the mode line.
6252 Each entry has the form (KEY ON OF), where the KEY is a symbol
6253 representing the particular washing function, ON is the string to use
6254 in the article mode line when the washing function is active, and OFF
6255 is the string to use when it is inactive.")
6257 (defun gnus-article-wash-status-entry (key value)
6258 (let ((entry (assoc key gnus-article-wash-status-strings)))
6259 (if value (nth 1 entry) (nth 2 entry))))
6261 (defun gnus-article-wash-status ()
6262 "Return a string which display status of article washing."
6263 (with-current-buffer gnus-article-buffer
6264 (let ((cite (memq 'cite gnus-article-wash-types))
6265 (headers (memq 'headers gnus-article-wash-types))
6266 (boring (memq 'boring-headers gnus-article-wash-types))
6267 (pgp (memq 'pgp gnus-article-wash-types))
6268 (pem (memq 'pem gnus-article-wash-types))
6269 (signed (memq 'signed gnus-article-wash-types))
6270 (encrypted (memq 'encrypted gnus-article-wash-types))
6271 (signature (memq 'signature gnus-article-wash-types))
6272 (overstrike (memq 'overstrike gnus-article-wash-types))
6273 (emphasis (memq 'emphasis gnus-article-wash-types)))
6275 (gnus-article-wash-status-entry 'cite cite)
6276 (gnus-article-wash-status-entry 'headers (or headers boring))
6277 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6278 (gnus-article-wash-status-entry 'signature signature)
6279 (gnus-article-wash-status-entry 'overstrike overstrike)
6280 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6282 (defun gnus-add-wash-type (type)
6283 "Add a washing of TYPE to the current status."
6284 (add-to-list 'gnus-article-wash-types type))
6286 (defun gnus-delete-wash-type (type)
6287 "Add a washing of TYPE to the current status."
6288 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6290 (defun gnus-add-image (category image)
6291 "Add IMAGE of CATEGORY to the list of displayed images."
6292 (let ((entry (assq category gnus-article-image-alist)))
6294 (setq entry (list category))
6295 (push entry gnus-article-image-alist))
6296 (nconc entry (list image))))
6298 (defun gnus-delete-images (category)
6299 "Delete all images in CATEGORY."
6300 (let ((entry (assq category gnus-article-image-alist)))
6301 (dolist (image (cdr entry))
6302 (gnus-remove-image image category))
6303 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6304 (gnus-delete-wash-type category)))
6306 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6308 (defun gnus-article-maybe-hide-headers ()
6309 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6310 Provided for backwards compatibility."
6311 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6312 (not (with-current-buffer gnus-summary-buffer
6313 gnus-have-all-headers)))
6314 (not gnus-inhibit-hiding))
6315 (gnus-article-hide-headers)))
6317 (declare-function shr-put-image "shr" (data alt &optional flags))
6319 (defun gnus-shr-put-image (data alt &optional flags)
6320 "Put image DATA with a string ALT. Enable image to be deleted."
6321 (let ((image (if flags
6322 (shr-put-image data (propertize (or alt "*")
6323 'gnus-image-category 'shr)
6325 ;; Old `shr-put-image' doesn't take the optional `flags'
6327 (shr-put-image data (propertize (or alt "*")
6328 'gnus-image-category 'shr)))))
6330 (gnus-add-image 'shr image))))
6332 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6333 "Show attachments as buttons in the end of the header of an article.
6334 This function toggles the display when called interactively. Note that
6335 buttons to be added to the header are only the ones that aren't inlined
6336 in the body. Use `gnus-header-face-alist' to highlight buttons."
6337 (interactive (list t))
6338 (gnus-with-article-buffer
6340 ;; Function that returns a flattened version of
6341 ;; `gnus-article-mime-handle-alist'.
6343 (&optional alist id all)
6345 (let ((i 1) newid flat)
6346 (dolist (handle alist flat)
6347 (setq newid (append id (list i))
6349 (if (stringp (car handle))
6350 (setq flat (nconc flat (flattened-alist (cdr handle)
6352 (delq (rassq handle all) all)
6353 (setq flat (nconc flat (list (cons newid handle)))))))
6354 (let ((flat (list nil)))
6355 ;; Assume that elements of `gnus-article-mime-handle-alist'
6356 ;; are in the decreasing order, but unnumbered subsidiaries
6357 ;; in each element are in the increasing order.
6358 (dolist (handle (reverse gnus-article-mime-handle-alist))
6359 (if (stringp (cadr handle))
6360 (setq flat (nconc flat (flattened-alist (cddr handle)
6363 (delq (rassq (cdr handle) flat) flat)
6364 (setq flat (nconc flat (list (cons (list (car handle))
6366 (setq flat (cdr flat))
6367 (mapc (lambda (handle)
6369 ;; This is a hidden (i.e. unnumbered) handle.
6372 (1+ (caar gnus-article-mime-handle-alist)))
6373 (push handle gnus-article-mime-handle-alist))
6374 (setcar handle (caar handle))))
6377 (let ((case-fold-search t) buttons handle type st)
6381 (article-narrow-to-head)
6382 ;; Header buttons exist?
6383 (while (and (not buttons)
6384 (re-search-forward "^attachments?:[\n ]+" nil t))
6385 (when (get-char-property (match-end 0)
6386 'gnus-button-attachment-extra)
6387 (setq buttons (match-beginning 0))))
6390 ;; Delete header buttons.
6391 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6394 (unless (and interactive buttons)
6397 (dolist (button (flattened-alist))
6398 (setq handle (cdr button)
6399 type (mm-handle-media-type handle))
6400 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6401 (with-current-buffer gnus-summary-buffer
6402 gnus-inhibit-images)
6403 gnus-inhibit-images)
6404 (string-match "\\`image/" type))
6405 (mm-inline-override-p handle)
6406 (and (mm-handle-disposition handle)
6407 (not (equal (car (mm-handle-disposition handle))
6409 (not (mm-attachment-override-p handle)))
6410 (not (mm-automatic-display-p handle))
6411 (not (or (and (mm-inlinable-p handle)
6412 (mm-inlined-p handle))
6413 (mm-automatic-external-display-p type))))
6414 (push button buttons)))
6416 ;; Add header buttons.
6419 (narrow-to-region (point) (point))
6420 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6421 (dolist (button (nreverse buttons))
6424 (mm-handle-set-undisplayer
6425 (setq handle (copy-sequence (cdr button))) nil)
6426 (gnus-insert-mime-button handle (car button))
6427 (skip-chars-backward "\t\n ")
6428 (delete-region (point) (point-max))
6429 (when (> (current-column) (window-width))
6434 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6435 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6436 (gnus-overlay-put ovl 'face nil))
6437 (let ((gnus-treatment-function-alist
6438 '((gnus-treat-highlight-headers
6439 gnus-article-highlight-headers))))
6440 (gnus-treat-article 'head))))))))))
6444 (defun gnus-output-to-file (file-name)
6445 "Append the current article to a file named FILE-NAME.
6446 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6447 text and used as the value of the coding cookie which is added to the
6448 top of a file. Otherwise, this function saves a raw article without
6450 (let* ((artbuf (current-buffer))
6451 (file-name-coding-system nnmail-pathname-coding-system)
6452 (coding gnus-article-save-coding-system)
6453 (coding-system-for-read (if coding
6454 nil ;; Rely on the coding cookie.
6455 mm-text-coding-system))
6456 (coding-system-for-write (or coding
6457 mm-text-coding-system-for-write
6458 mm-text-coding-system))
6459 (exists (file-exists-p file-name)))
6462 (insert-file-contents file-name)
6463 (goto-char (point-min))
6464 ;; Remove the existing coding cookie.
6465 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6466 (delete-region (match-beginning 0) (match-end 0))))
6467 (goto-char (point-max))
6468 (insert-buffer-substring artbuf)
6469 ;; Append newline at end of the buffer as separator, and then
6471 (goto-char (point-max))
6474 ;; If the coding system is not suitable to encode the text,
6475 ;; ask a user for a proper one.
6476 (when (fboundp 'select-safe-coding-system)
6477 (setq coding (coding-system-base
6478 (save-window-excursion
6479 (select-safe-coding-system (point-min) (point-max)
6481 (setq coding-system-for-write
6482 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6484 (goto-char (point-min))
6485 ;; Add the coding cookie.
6486 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6487 coding-system-for-write)))
6490 (write-region (point-min) (point-max) file-name nil 'no-message)
6491 (message "Appended to %s" file-name))
6492 (write-region (point-min) (point-max) file-name))))
6495 (defun gnus-narrow-to-page (&optional arg)
6496 "Narrow the article buffer to a page.
6497 If given a numerical ARG, move forward ARG pages."
6499 (setq arg (if arg (prefix-numeric-value arg) 0))
6500 (with-current-buffer gnus-article-buffer
6502 ;; Remove any old next/prev buttons.
6503 (when (gnus-visual-p 'page-marker)
6504 (let ((inhibit-read-only t))
6505 (gnus-remove-text-with-property 'gnus-prev)
6506 (gnus-remove-text-with-property 'gnus-next)))
6508 (when (save-excursion
6510 (if (re-search-backward page-delimiter nil 'move (abs arg))
6512 (setq nd (match-beginning 0)
6514 (when (re-search-backward page-delimiter nil t)
6515 (setq st (match-end 0))))
6516 (when (re-search-forward page-delimiter nil t)
6517 (setq nd (match-beginning 0)
6520 (if (re-search-forward page-delimiter nil 'move arg)
6522 (setq st (match-end 0)
6524 (when (re-search-forward page-delimiter nil t)
6525 (setq nd (match-beginning 0))))
6526 (when (re-search-backward page-delimiter nil t)
6527 (setq st (match-end 0)
6530 (when (re-search-backward page-delimiter nil t)
6531 (goto-char (setq st (match-end 0))))
6532 (when (re-search-forward page-delimiter nil t)
6533 (setq nd (match-beginning 0)))
6535 (setq gnus-page-broken t)
6536 (when pt (goto-char pt))
6537 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6538 (when (gnus-visual-p 'page-marker)
6542 (gnus-insert-next-page-button))
6545 (gnus-insert-prev-page-button))))))))
6547 ;; Article mode commands
6549 (defun gnus-article-goto-next-page ()
6550 "Show the next page of the article."
6552 (when (gnus-article-next-page)
6553 (goto-char (point-min))
6554 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6557 (defun gnus-article-goto-prev-page ()
6558 "Show the previous page of the article."
6560 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6561 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6562 (gnus-article-prev-page nil)))
6564 ;; This is cleaner but currently breaks `gnus-pick-mode':
6566 ;; (defun gnus-article-goto-next-page ()
6567 ;; "Show the next page of the article."
6569 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6570 ;; (gnus-summary-next-page)))
6572 ;; (defun gnus-article-goto-prev-page ()
6573 ;; "Show the next page of the article."
6575 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6576 ;; (gnus-summary-prev-page)))
6578 (defun gnus-article-next-page (&optional lines)
6579 "Show the next page of the current article.
6580 If end of article, return non-nil. Otherwise return nil.
6581 Argument LINES specifies lines to be scrolled up."
6583 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6584 (if (and (not (and gnus-article-over-scroll
6585 (> (count-lines (window-start) (point-max))
6586 (if (featurep 'xemacs)
6587 (or lines (1- (window-height)))
6588 (+ (or lines (1- (window-height))) scroll-margin)))))
6591 (and (pos-visible-in-window-p) ;Not continuation line.
6592 (>= (point) (point-max)))))
6593 ;; Nothing in this page.
6594 (if (or (not gnus-page-broken)
6599 (eobp)))) ;Real end-of-buffer?
6601 (when gnus-article-over-scroll
6602 (gnus-article-next-page-1 lines))
6604 (gnus-narrow-to-page 1) ;Go to next page.
6606 ;; More in this page.
6607 (gnus-article-next-page-1 lines)
6610 (defun gnus-article-beginning-of-window ()
6611 "Move point to the beginning of the window.
6612 In Emacs, the point is placed at the line number which `scroll-margin'
6614 (if (featurep 'xemacs)
6615 (move-to-window-line 0)
6616 ;; There is an obscure bug in Emacs that makes it impossible to
6617 ;; scroll past big pictures in the article buffer. Try to fix
6618 ;; this by adding a sanity check by counting the lines visible.
6619 (when (> (count-lines (window-start) (window-end)) 30)
6620 (move-to-window-line
6621 (min (max 0 scroll-margin)
6622 (max 1 (- (window-height)
6623 (if mode-line-format 1 0)
6624 (if header-line-format 1 0)
6627 (defun gnus-article-next-page-1 (lines)
6629 (let ((scroll-in-place nil)
6630 (auto-window-vscroll nil))
6633 ;; Long lines may cause an end-of-buffer error.
6634 (goto-char (point-max))))
6635 (gnus-article-beginning-of-window))
6637 (defun gnus-article-prev-page (&optional lines)
6638 "Show previous page of current article.
6639 Argument LINES specifies lines to be scrolled down."
6641 (move-to-window-line 0)
6642 (if (and gnus-page-broken
6644 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6646 (gnus-narrow-to-page -1) ;Go to previous page.
6647 (goto-char (point-max))
6648 (recenter (if gnus-article-over-scroll
6650 (max (if (featurep 'xemacs)
6652 (+ lines scroll-margin))
6654 (- (window-height) 2))
6658 (let ((scroll-in-place nil))
6659 (scroll-down lines))
6660 (beginning-of-buffer
6661 (goto-char (point-min))))
6662 (gnus-article-beginning-of-window))))
6664 (defun gnus-article-only-boring-p ()
6665 "Decide whether there is only boring text remaining in the article.
6666 Something \"interesting\" is a word of at least two letters that does
6667 not have a face in `gnus-article-boring-faces'."
6668 (when (and gnus-article-skip-boring
6669 (boundp 'gnus-article-boring-faces)
6670 (symbol-value 'gnus-article-boring-faces))
6672 (let ((inhibit-point-motion-hooks t))
6674 (while (re-search-forward "\\b\\w\\w" nil t)
6676 (when (not (gnus-intersection
6677 (gnus-faces-at (point))
6678 (symbol-value 'gnus-article-boring-faces)))
6679 (throw 'only-boring nil)))
6680 (throw 'only-boring t))))))
6682 (defun gnus-article-refer-article ()
6683 "Read article specified by message-id around point."
6686 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6687 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6688 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6689 (let ((msg-id (concat "<" (match-string 0) ">")))
6690 (set-buffer gnus-summary-buffer)
6691 (gnus-summary-refer-article msg-id))
6692 (error "No references around point"))))
6694 (defun gnus-article-show-summary ()
6695 "Reconfigure windows to show summary buffer."
6697 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6698 (error "There is no summary buffer for this article buffer")
6699 (gnus-article-set-globals)
6700 (gnus-configure-windows 'article)
6701 (gnus-summary-goto-subject gnus-current-article)
6702 (gnus-summary-position-point)))
6704 (defun gnus-article-describe-briefly ()
6705 "Describe article mode commands briefly."
6707 (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")))
6709 (defun gnus-article-check-buffer ()
6710 "Beep if not in an article buffer."
6711 (unless (derived-mode-p 'gnus-article-mode)
6712 (error "Command invoked outside of a Gnus article buffer")))
6714 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6715 "Read a summary buffer key sequence and execute it from the article buffer."
6717 (gnus-article-check-buffer)
6719 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6720 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6721 "=" "^" "\M-^" "|"))
6723 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6724 "An" "Ap" [?A (meta return)] [?A delete]))
6728 '("n" "Gn" "p" "Gp"))
6730 (with-current-buffer gnus-article-current-summary
6731 (let (gnus-pick-mode)
6732 (setq unread-command-events (nconc unread-command-events
6733 (list (or key last-command-event)))
6734 keys (if (featurep 'xemacs)
6735 (events-to-keys (read-key-sequence nil t))
6736 (read-key-sequence nil t)))))
6741 ((eq (aref keys (1- (length keys))) ?\C-h)
6742 (gnus-article-describe-bindings (substring keys 0 -1)))
6743 ((or (member keys nosaves)
6744 (member keys nosave-but-article)
6745 (member keys nosave-in-article))
6747 (save-window-excursion
6748 (pop-to-buffer gnus-article-current-summary)
6749 ;; We disable the pick minor mode commands.
6750 (let (gnus-pick-mode)
6751 (setq func (key-binding keys t))))
6755 (unless (member keys nosave-in-article)
6756 (set-buffer gnus-article-current-summary))
6757 (when (and (symbolp func)
6758 (get func 'disabled))
6759 (error "Function %s disabled" func))
6760 (call-interactively func)
6761 (setq new-sum-point (point)))
6762 (when (member keys nosave-but-article)
6763 (pop-to-buffer gnus-article-buffer))))
6765 ;; These commands should restore window configuration.
6766 (let ((obuf (current-buffer))
6767 (owin (current-window-configuration))
6768 win func in-buffer selected new-sum-start new-sum-hscroll err)
6769 (cond (not-restore-window
6770 (pop-to-buffer gnus-article-current-summary)
6771 (setq win (selected-window)))
6772 ((setq win (get-buffer-window gnus-article-current-summary))
6773 (select-window win))
6775 (let ((summary-buffer gnus-article-current-summary))
6776 (gnus-configure-windows 'article)
6777 (unless (setq win (get-buffer-window summary-buffer 'visible))
6778 (let ((gnus-buffer-configuration
6779 '((article ((vertical 1.0
6780 (summary 0.25 point)
6782 (gnus-configure-windows 'article))
6783 (setq win (get-buffer-window summary-buffer 'visible)))
6784 (gnus-select-frame-set-input-focus (window-frame win))
6785 (select-window win))))
6786 (setq in-buffer (current-buffer))
6787 ;; We disable the pick minor mode commands.
6788 (setq func (let (gnus-pick-mode)
6789 (key-binding keys t)))
6790 (when (get func 'disabled)
6791 (error "Function %s disabled" func))
6794 (condition-case code
6796 (call-interactively func)
6802 (when (eq win (selected-window))
6803 (setq new-sum-point (point)
6804 new-sum-start (window-start win)
6805 new-sum-hscroll (window-hscroll win)))
6806 (when (or (eq in-buffer (current-buffer))
6807 (when (eq obuf (current-buffer))
6808 (set-buffer in-buffer)
6810 (setq selected (ignore-errors (gnus-summary-select-article)))
6812 (unless not-restore-window
6813 (set-window-configuration owin))
6814 (when (and (eq selected 'old)
6816 (set-window-start (get-buffer-window (current-buffer))
6818 (set-window-point (get-buffer-window (current-buffer))
6819 (if (article-goto-body)
6822 (when (and (not not-restore-window)
6825 (with-current-buffer (window-buffer win)
6826 (derived-mode-p 'gnus-summary-mode)))
6827 (set-window-point win new-sum-point)
6828 (set-window-start win new-sum-start)
6829 (set-window-hscroll win new-sum-hscroll))))
6830 (set-window-configuration owin)
6832 (signal (car err) (cdr err))
6835 (defun gnus-article-read-summary-send-keys ()
6837 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6838 (gnus-article-read-summary-keys)))
6840 (defun gnus-article-describe-key (key)
6841 "Display documentation of the function invoked by KEY.
6842 KEY is a string or a vector."
6843 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6844 (read-key-sequence "Describe key: "))))
6845 (gnus-article-check-buffer)
6846 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6847 gnus-article-read-summary-send-keys))
6848 (with-current-buffer gnus-article-current-summary
6849 (setq unread-command-events
6850 (if (featurep 'xemacs)
6852 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6853 (list 'meta (- x 128))
6856 (let ((cursor-in-echo-area t)
6858 (describe-key (read-key-sequence nil t))))
6859 (describe-key key)))
6861 (defun gnus-article-describe-key-briefly (key &optional insert)
6862 "Display documentation of the function invoked by KEY.
6863 KEY is a string or a vector."
6864 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6865 (read-key-sequence "Describe key: "))
6866 current-prefix-arg))
6867 (gnus-article-check-buffer)
6868 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6869 gnus-article-read-summary-send-keys))
6870 (with-current-buffer gnus-article-current-summary
6871 (setq unread-command-events
6872 (if (featurep 'xemacs)
6874 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6875 (list 'meta (- x 128))
6878 (let ((cursor-in-echo-area t)
6880 (describe-key-briefly (read-key-sequence nil t) insert)))
6881 (describe-key-briefly key insert)))
6883 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6884 (defvar gnus-agent-summary-mode)
6885 (defvar gnus-draft-mode)
6886 (defvar help-xref-stack-item)
6888 (defun gnus-article-describe-bindings (&optional prefix)
6889 "Show a list of all defined keys, and their definitions.
6890 The optional argument PREFIX, if non-nil, should be a key sequence;
6891 then we display only bindings that start with that prefix."
6893 (gnus-article-check-buffer)
6894 (let ((keymap (copy-keymap gnus-article-mode-map))
6895 (map (copy-keymap gnus-article-send-map))
6896 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6898 (define-key keymap "S" map)
6899 (define-key map [t] nil)
6900 (with-current-buffer gnus-article-current-summary
6903 (if (setq parent (keymap-parent gnus-article-mode-map))
6905 (setq parent (copy-keymap parent))
6906 (set-keymap-parent parent (current-local-map)))
6907 (current-local-map)))
6908 (set-keymap-parent map (key-binding "S"))
6909 (let (key def gnus-pick-mode)
6911 (setq key (pop sumkeys))
6912 (cond ((and (vectorp key) (= (length key) 1)
6913 (consp (setq def (aref key 0)))
6914 (numberp (car def)) (numberp (cdr def)))
6915 (when (< (max (car def) (cdr def)) 128)
6919 (nreverse (gnus-uncompress-range def)))
6921 ((setq def (key-binding key))
6922 (unless (eq def 'undefined)
6923 (define-key keymap key def))))))
6924 (when (boundp 'gnus-agent-summary-mode)
6925 (setq agent gnus-agent-summary-mode))
6926 (when (boundp 'gnus-draft-mode)
6927 (setq draft gnus-draft-mode)))
6929 (use-local-map keymap)
6930 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6931 (set (make-local-variable 'gnus-draft-mode) draft)
6932 (describe-bindings prefix))
6933 (let ((item `((lambda (prefix)
6934 (with-current-buffer ,(current-buffer)
6935 (gnus-article-describe-bindings prefix)))
6937 ;; Loading `help-mode' here is necessary if `describe-bindings'
6938 ;; is replaced with something, e.g. `helm-descbinds'.
6939 (require 'help-mode)
6940 (with-current-buffer (let (help-xref-following) (help-buffer))
6941 (setq help-xref-stack-item item)))))
6943 (defun gnus-article-reply-with-original (&optional wide)
6944 "Start composing a reply mail to the current message.
6945 The text in the region will be yanked. If the region isn't active,
6946 the entire article will be yanked."
6948 (let ((article (cdr gnus-article-current))
6950 (if (not (gnus-region-active-p))
6951 (with-current-buffer gnus-summary-buffer
6952 (gnus-summary-reply (list (list article)) wide))
6953 (setq contents (buffer-substring (point) (mark t)))
6954 ;; Deactivate active regions.
6955 (when (and (boundp 'transient-mark-mode)
6956 transient-mark-mode)
6957 (setq mark-active nil))
6958 (with-current-buffer gnus-summary-buffer
6960 (list (list article contents)) wide)))))
6962 (defun gnus-article-wide-reply-with-original ()
6963 "Start composing a wide reply mail to the current message.
6964 The text in the region will be yanked. If the region isn't active,
6965 the entire article will be yanked."
6967 (gnus-article-reply-with-original t))
6969 (defun gnus-article-followup-with-original ()
6970 "Compose a followup to the current article.
6971 The text in the region will be yanked. If the region isn't active,
6972 the entire article will be yanked."
6974 (let ((article (cdr gnus-article-current))
6976 (if (not (gnus-region-active-p))
6977 (with-current-buffer gnus-summary-buffer
6978 (gnus-summary-followup (list (list article))))
6979 (setq contents (buffer-substring (point) (mark t)))
6980 ;; Deactivate active regions.
6981 (when (and (boundp 'transient-mark-mode)
6982 transient-mark-mode)
6983 (setq mark-active nil))
6984 (with-current-buffer gnus-summary-buffer
6985 (gnus-summary-followup
6986 (list (list article contents)))))))
6988 (defun gnus-article-hide (&optional arg force)
6989 "Hide all the gruft in the current article.
6990 This means that signatures, cited text and (some) headers will be
6992 If given a prefix, show the hidden text instead."
6993 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6994 (gnus-article-hide-headers arg)
6995 (gnus-article-hide-list-identifiers arg)
6996 (gnus-article-hide-citation-maybe arg force)
6997 (gnus-article-hide-signature arg))
6999 (defun gnus-check-group-server ()
7000 ;; Make sure the connection to the server is alive.
7001 (unless (gnus-server-opened
7002 (gnus-find-method-for-group gnus-newsgroup-name))
7003 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7004 (gnus-request-group gnus-newsgroup-name t)))
7007 (autoload 'nneething-get-file-name "nneething"))
7009 (defun gnus-request-article-this-buffer (article group)
7010 "Get an article and insert it into this buffer."
7011 (let (do-update-line sparse-header)
7015 (gnus-kill-all-overlays)
7016 (setq group (or group gnus-newsgroup-name))
7018 ;; Using `gnus-request-article' directly will insert the article into
7019 ;; `nntp-server-buffer' - so we'll save some time by not having to
7020 ;; copy it from the server buffer into the article buffer.
7022 ;; We only request an article by message-id when we do not have the
7023 ;; headers for it, so we'll have to get those.
7024 (when (stringp article)
7025 (gnus-read-header article))
7027 ;; If the article number is negative, that means that this article
7028 ;; doesn't belong in this newsgroup (possibly), so we find its
7029 ;; message-id and request it by id instead of number.
7030 (when (and (numberp article)
7032 (get-buffer gnus-summary-buffer)
7033 (gnus-buffer-exists-p gnus-summary-buffer))
7034 (with-current-buffer gnus-summary-buffer
7035 (let ((header (gnus-summary-article-header article)))
7038 ((memq article gnus-newsgroup-sparse)
7039 ;; This is a sparse gap article.
7040 (setq do-update-line article)
7041 (setq article (mail-header-id header))
7042 (setq sparse-header (gnus-read-header article))
7043 (setq gnus-newsgroup-sparse
7044 (delq article gnus-newsgroup-sparse)))
7046 ;; It's a real article.
7047 (setq article (mail-header-id header)))
7049 ;; It is an extracted pseudo-article.
7050 (setq article 'pseudo)
7051 (gnus-request-pseudo-article header))))
7053 (let ((method (gnus-find-method-for-group
7054 gnus-newsgroup-name)))
7055 (when (and (eq (car method) 'nneething)
7057 (let ((dir (nneething-get-file-name
7058 (mail-header-id header))))
7059 (when (and (stringp dir)
7060 (file-directory-p dir))
7061 (setq article 'nneething)
7062 (gnus-group-enter-directory dir))))))))
7065 ;; Refuse to select canceled articles.
7066 ((and (numberp article)
7068 (get-buffer gnus-summary-buffer)
7069 (gnus-buffer-exists-p gnus-summary-buffer)
7070 (eq (cdr (with-current-buffer gnus-summary-buffer
7071 (assq article gnus-newsgroup-reads)))
7072 gnus-canceled-mark))
7074 ;; We first check `gnus-original-article-buffer'.
7075 ((and (get-buffer gnus-original-article-buffer)
7077 (with-current-buffer gnus-original-article-buffer
7078 (and (equal (car gnus-original-article) group)
7079 (eq (cdr gnus-original-article) article))))
7080 ;; `insert-buffer-substring' would incorrectly use the
7081 ;; equivalent of string-make-multibyte which amount to decoding
7082 ;; with locale-coding-system, causing failure of
7083 ;; subsequent decoding.
7084 (insert (mm-string-to-multibyte
7085 (with-current-buffer gnus-original-article-buffer
7086 (buffer-substring (point-min) (point-max)))))
7088 ;; Check the backlog.
7089 ((and gnus-keep-backlog
7090 (gnus-backlog-request-article group article (current-buffer)))
7092 ;; Check asynchronous pre-fetch.
7093 ((gnus-async-request-fetched-article group article (current-buffer))
7094 (gnus-async-prefetch-next group article gnus-summary-buffer)
7095 (when (and (numberp article) gnus-keep-backlog)
7096 (gnus-backlog-enter-article group article (current-buffer)))
7099 ((and gnus-use-cache
7101 (gnus-cache-request-article article group))
7103 ;; Check the agent cache.
7104 ((gnus-agent-request-article article group)
7106 ;; Get the article and put into the article buffer.
7107 ((or (stringp article)
7109 (let ((gnus-override-method gnus-override-method)
7110 (methods (and (stringp article)
7111 (with-current-buffer gnus-summary-buffer
7112 (gnus-refer-article-methods))))
7113 (backend (car (gnus-find-method-for-group
7114 gnus-newsgroup-name)))
7116 (inhibit-read-only t))
7117 (when (and (null gnus-override-method)
7119 (setq gnus-override-method (pop methods)))
7122 (gnus-kill-all-overlays)
7123 (let ((gnus-newsgroup-name group))
7124 (gnus-check-group-server))
7126 ((gnus-request-article article group (current-buffer))
7127 (when (numberp article)
7128 (gnus-async-prefetch-next group article
7129 gnus-summary-buffer)
7130 (when gnus-keep-backlog
7131 (gnus-backlog-enter-article
7132 group article (current-buffer)))
7133 (when (and gnus-agent
7134 (gnus-agent-group-covered-p group))
7135 (gnus-agent-store-article article group)))
7136 (setq result 'article))
7138 (setq gnus-override-method (pop methods)))
7139 ((not (string-match "^400 "
7140 (nnheader-get-report backend)))
7141 ;; If we get 400 server disconnect, reconnect and
7142 ;; retry; otherwise, assume the article has expired.
7143 (setq result 'done))))
7144 (and (eq result 'article) 'article)))
7148 ;; Associate this article with the current summary buffer.
7149 (setq gnus-article-current-summary gnus-summary-buffer)
7151 ;; Take the article from the original article buffer
7152 ;; and place it in the buffer it's supposed to be in.
7153 (when (and (get-buffer gnus-article-buffer)
7154 (equal (buffer-name (current-buffer))
7155 (buffer-name (get-buffer gnus-article-buffer))))
7157 (if (get-buffer gnus-original-article-buffer)
7158 (set-buffer gnus-original-article-buffer)
7159 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7160 (buffer-disable-undo)
7161 (setq major-mode 'gnus-original-article-mode)
7162 (setq buffer-read-only t))
7163 (let ((inhibit-read-only t))
7165 (insert-buffer-substring gnus-article-buffer))
7166 (setq gnus-original-article (cons group article)))
7169 (run-hooks 'gnus-article-decode-hook)
7170 ;; Mark article as decoded or not.
7171 (setq gnus-article-decoded-p gnus-article-decode-hook))
7173 ;; Update sparse articles.
7174 (when (and do-update-line
7175 (or (numberp article)
7177 (let ((buf (current-buffer)))
7178 (set-buffer gnus-summary-buffer)
7179 (gnus-summary-update-article do-update-line sparse-header)
7180 (gnus-summary-goto-subject do-update-line nil t)
7181 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7183 (set-buffer buf))))))
7185 (defun gnus-block-private-groups (group)
7186 (if (or (gnus-news-group-p group)
7187 (gnus-member-of-valid 'global group))
7188 ;; Block nothing in news groups.
7190 ;; Block everything anywhere else.
7193 (defun gnus-blocked-images ()
7194 (if (functionp gnus-blocked-images)
7195 (funcall gnus-blocked-images gnus-newsgroup-name)
7196 gnus-blocked-images))
7202 (defcustom gnus-article-edit-mode-hook nil
7203 "Hook run in article edit mode buffers."
7204 :group 'gnus-article-various
7207 (defvar gnus-article-edit-done-function nil)
7209 (defvar gnus-article-edit-mode-map nil)
7211 ;; Should we be using derived.el for this?
7212 (unless gnus-article-edit-mode-map
7213 (setq gnus-article-edit-mode-map (make-keymap))
7214 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7216 (gnus-define-keys gnus-article-edit-mode-map
7217 "\C-c?" describe-mode
7218 "\C-c\C-c" gnus-article-edit-done
7219 "\C-c\C-k" gnus-article-edit-exit
7220 "\C-c\C-f\C-t" message-goto-to
7221 "\C-c\C-f\C-o" message-goto-from
7222 "\C-c\C-f\C-b" message-goto-bcc
7223 ;;"\C-c\C-f\C-w" message-goto-fcc
7224 "\C-c\C-f\C-c" message-goto-cc
7225 "\C-c\C-f\C-s" message-goto-subject
7226 "\C-c\C-f\C-r" message-goto-reply-to
7227 "\C-c\C-f\C-n" message-goto-newsgroups
7228 "\C-c\C-f\C-d" message-goto-distribution
7229 "\C-c\C-f\C-f" message-goto-followup-to
7230 "\C-c\C-f\C-m" message-goto-mail-followup-to
7231 "\C-c\C-f\C-k" message-goto-keywords
7232 "\C-c\C-f\C-u" message-goto-summary
7233 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7234 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7235 "\C-c\C-b" message-goto-body
7236 "\C-c\C-i" message-goto-signature
7238 "\C-c\C-t" message-insert-to
7239 "\C-c\C-n" message-insert-newsgroups
7240 "\C-c\C-o" message-sort-headers
7241 "\C-c\C-e" message-elide-region
7242 "\C-c\C-v" message-delete-not-region
7243 "\C-c\C-z" message-kill-to-signature
7244 "\M-\r" message-newline-and-reformat
7245 "\C-c\C-a" mml-attach-file
7246 "\C-a" message-beginning-of-line
7248 "\M-;" comment-region)
7250 (gnus-define-keys (gnus-article-edit-wash-map
7251 "\C-c\C-w" gnus-article-edit-mode-map)
7252 "f" gnus-article-edit-full-stops))
7255 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7257 ["Fetch To" message-insert-to t]
7258 ["Fetch Newsgroups" message-insert-newsgroups t]
7260 ["To" message-goto-to t]
7261 ["From" message-goto-from t]
7262 ["Subject" message-goto-subject t]
7263 ["Cc" message-goto-cc t]
7264 ["Reply-To" message-goto-reply-to t]
7265 ["Summary" message-goto-summary t]
7266 ["Keywords" message-goto-keywords t]
7267 ["Newsgroups" message-goto-newsgroups t]
7268 ["Followup-To" message-goto-followup-to t]
7269 ["Mail-Followup-To" message-goto-mail-followup-to t]
7270 ["Distribution" message-goto-distribution t]
7271 ["Body" message-goto-body t]
7272 ["Signature" message-goto-signature t]))
7274 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7275 "Major mode for editing articles.
7276 This is an extended text-mode.
7278 \\{gnus-article-edit-mode-map}"
7279 (make-local-variable 'gnus-article-edit-done-function)
7280 (make-local-variable 'gnus-prev-winconf)
7281 (set (make-local-variable 'font-lock-defaults)
7282 '(message-font-lock-keywords t))
7283 (set (make-local-variable 'mail-header-separator) "")
7284 (set (make-local-variable 'gnus-article-edit-mode) t)
7285 (easy-menu-add message-mode-field-menu message-mode-map)
7287 (setq buffer-read-only nil)
7288 (buffer-enable-undo)
7291 (defun gnus-article-edit (&optional force)
7292 "Edit the current article.
7293 This will have permanent effect only in mail groups.
7294 If FORCE is non-nil, allow editing of articles even in read-only
7297 (when (and (not force)
7298 (gnus-group-read-only-p))
7299 (error "The current newsgroup does not support article editing"))
7300 (gnus-article-date-original)
7301 (gnus-article-edit-article
7303 `(lambda (no-highlight)
7305 (gnus-summary-edit-article-done
7306 ,(or (mail-header-references gnus-current-headers) "")
7307 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7309 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7310 "Start editing the contents of the current article buffer."
7311 (let ((winconf (current-window-configuration)))
7312 (set-buffer gnus-article-buffer)
7313 (let ((message-auto-save-directory
7314 ;; Don't associate the article buffer with a draft file.
7316 (gnus-article-edit-mode))
7317 (funcall start-func)
7318 (set-buffer-modified-p nil)
7319 (gnus-configure-windows 'edit-article)
7320 (setq gnus-article-edit-done-function exit-func)
7321 (setq gnus-prev-winconf winconf)
7323 (gnus-message 6 "C-c C-c to end edits"))))
7325 (defun gnus-article-edit-done (&optional arg)
7326 "Update the article edits and exit."
7328 (let ((func gnus-article-edit-done-function)
7329 (buf (current-buffer))
7330 (start (window-start))
7332 (winconf gnus-prev-winconf))
7333 (widen) ;; Widen it in case that users narrowed the buffer.
7336 ;; The cache and backlog have to be flushed somewhat.
7337 (when gnus-keep-backlog
7338 (gnus-backlog-remove-article
7339 (car gnus-article-current) (cdr gnus-article-current)))
7340 ;; Flush original article as well.
7341 (gnus-flush-original-article-buffer)
7342 (when gnus-use-cache
7343 (gnus-cache-update-article
7344 (car gnus-article-current) (cdr gnus-article-current)))
7345 ;; We remove all text props from the article buffer.
7346 (kill-all-local-variables)
7347 (set-text-properties (point-min) (point-max) nil)
7349 (set-window-configuration winconf)
7351 (set-window-start (get-buffer-window buf) start)
7352 (set-window-point (get-buffer-window buf) (point)))
7353 (gnus-summary-show-article))
7355 (defun gnus-flush-original-article-buffer ()
7356 (when (get-buffer gnus-original-article-buffer)
7357 (with-current-buffer gnus-original-article-buffer
7358 (setq gnus-original-article nil))))
7360 (defun gnus-article-edit-exit ()
7361 "Exit the article editing without updating."
7363 (when (or (not (buffer-modified-p))
7364 (yes-or-no-p "Article modified; kill anyway? "))
7365 (let ((curbuf (current-buffer))
7367 (window-start (window-start)))
7369 (if (gnus-buffer-live-p gnus-original-article-buffer)
7370 (insert-buffer-substring gnus-original-article-buffer))
7371 (let ((winconf gnus-prev-winconf))
7372 (kill-all-local-variables)
7374 (set-window-configuration winconf)
7375 ;; Tippy-toe some to make sure that point remains where it was.
7376 (save-current-buffer
7378 (set-window-start (get-buffer-window (current-buffer)) window-start)
7380 (gnus-summary-show-article)))
7382 (defun gnus-article-edit-full-stops ()
7383 "Interactively repair spacing at end of sentences."
7386 (goto-char (point-min))
7387 (search-forward-regexp "^$" nil t)
7388 (let ((case-fold-search nil))
7389 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7392 ;;; Article highlights
7395 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7397 ;;; Internal Variables:
7399 (defcustom gnus-button-url-regexp
7401 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7402 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7403 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7404 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7405 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7409 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7410 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7411 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7412 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7414 "[" chars punct "]+" "[" chars "]"
7416 (concat ;; XEmacs 21.4 doesn't support POSIX.
7417 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7418 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7420 "Regular expression that matches URLs."
7422 :group 'gnus-article-buttons
7425 (defcustom gnus-button-valid-fqdn-regexp
7426 message-valid-fqdn-regexp
7427 "Regular expression that matches a valid FQDN."
7429 :group 'gnus-article-buttons
7432 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7433 (defcustom gnus-button-valid-localpart-regexp
7434 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7435 "Regular expression that matches a localpart of mail addresses or MIDs."
7437 :group 'gnus-article-buttons
7440 (defcustom gnus-button-man-handler 'manual-entry
7441 "Function to use for displaying man pages.
7442 The function must take at least one argument with a string naming the
7445 :type '(choice (function-item :tag "Man" manual-entry)
7446 (function-item :tag "Woman" woman)
7447 (function :tag "Other"))
7448 :group 'gnus-article-buttons)
7450 (defcustom gnus-button-mid-or-mail-regexp
7451 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7452 gnus-button-valid-fqdn-regexp
7454 "Regular expression that matches a message ID or a mail address."
7456 :group 'gnus-article-buttons
7459 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7460 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7461 Strings like this can be either a message ID or a mail address. If it is one
7462 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7463 message ID or a mail address, respectively. If this variable is set to the
7464 symbol `ask', always query the user what do do. If it is a function, this
7465 function will be called with the string as its only argument. The function
7466 must return `mid', `mail', `invalid' or `ask'."
7468 :group 'gnus-article-buttons
7469 :type '(choice (function-item :tag "Heuristic function"
7470 gnus-button-mid-or-mail-heuristic)
7475 (defcustom gnus-button-mid-or-mail-heuristic-alist
7476 '((-10.0 . ".+\\$.+@")
7479 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7480 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7481 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7482 (-1.0 . "^[^a-z]+@")
7484 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7485 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7486 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7487 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7490 (-1.0 . "^[0-9][0-9]")
7492 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7493 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7494 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7495 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7497 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7498 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7501 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7503 ;; compensation for TDMA dated mail addresses:
7504 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7506 (-20.0 . "\\.fsf@") ;; Gnus
7509 (-20.0 . "^alpine\\.")
7510 (-20.0 . "_-_") ;; Subject change in thread
7512 (-20.0 . "\\.ln@") ;; leafnode
7513 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7514 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7516 ;; (5.0 . "") ;; $local_part_len <= 7
7517 (10.0 . "^[^0-9]+@")
7518 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7519 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7522 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7524 (0.5 . "^[A-Z][a-z]")
7525 (0.5 . "^[A-Z][a-z][a-z]")
7526 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7527 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7528 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7530 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7531 address. The REGEXP is processed with `case-fold-search' set to nil."
7533 :group 'gnus-article-buttons
7534 :type '(repeat (cons (number :tag "Rate")
7535 (regexp :tag "Regexp"))))
7537 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7538 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7539 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7540 address, `ask' if unsure and `invalid' if the string is invalid."
7541 (let ((case-fold-search nil)
7542 (list gnus-button-mid-or-mail-heuristic-alist)
7543 (result 0) rate regexp lpartlen elem)
7545 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7546 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7547 ;; Certain special cases...
7550 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7551 "^[0-9]+\\.[0-9]+@compuserve\\|"
7552 "@public\\.gmane\\.org")
7554 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7555 (setq result 'mail))
7556 (when (string-match "@.*@\\| " mid-or-mail)
7557 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7558 (setq result 'invalid))
7559 ;; Nothing more to do, if result is not a number here...
7560 (when (numberp result)
7562 (setq elem (car list)
7566 (when (string-match regexp mid-or-mail)
7567 (setq result (+ result rate))
7569 9 "`%s' matched `%s', rate `%s', result `%s'."
7570 mid-or-mail regexp rate result)))
7571 (when (<= lpartlen 7)
7572 (setq result (+ result 5.0))
7573 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7574 mid-or-mail result))
7575 (when (>= lpartlen 12)
7576 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7578 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7579 ;; Long local part should contain realname if e-mail address,
7580 ;; too many digits: message-id.
7581 ;; $score -= 5.0 + 0.1 * $local_part_len;
7582 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7583 (setq result (+ result rate))
7585 9 "Many digits in `%s', rate `%s', result `%s'."
7586 mid-or-mail rate result))
7587 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7589 ;; Too few vowels [^aeiouy]{4,}.*\@
7590 (setq result (+ result -5.0))
7592 9 "Few vowels in `%s', rate `%s', result `%s'."
7593 mid-or-mail -5.0 result))
7595 (setq result (+ result 5.0))
7597 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7598 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7599 ;; Maybe we should make this a customizable alist: (condition . 'result)
7601 ((symbolp result) result)
7602 ;; Now convert number into proper results:
7603 ((< result -10.0) 'mid)
7604 ((> result 10.0) 'mail)
7607 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7608 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7609 (url-mid (concat "news" ":" mid-or-mail))
7610 (url-mailto (concat "mailto" ":" mid-or-mail)))
7611 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7612 (when (fboundp pref)
7614 ;; get rid of surrounding angles...
7616 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7617 (if (or (eq 'mid guessed) (eq 'mail guessed))
7621 (save-window-excursion
7622 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7625 (cond ((eq pref 'mid)
7626 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7627 (gnus-button-handle-news url-mid))
7629 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7630 (gnus-url-mailto url-mailto))
7631 (t (gnus-message 3 "Invalid string.")))))
7633 (defun gnus-button-handle-custom (fun arg)
7634 "Call function FUN on argument ARG.
7635 Both FUN and ARG are supposed to be strings. ARG will be passed
7636 as a symbol to FUN."
7637 (funcall (intern fun)
7638 (if (string-match "^customize-apropos" fun)
7642 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7644 (defun gnus-button-handle-describe-function (url)
7645 "Call `describe-function' when pushing the corresponding URL button."
7648 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7650 (defun gnus-button-handle-describe-variable (url)
7651 "Call `describe-variable' when pushing the corresponding URL button."
7654 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7656 (defun gnus-button-handle-symbol (url)
7657 "Display help on variable or function.
7658 Calls `describe-variable' or `describe-function'."
7659 (let ((sym (intern url)))
7661 ((fboundp sym) (describe-function sym))
7662 ((boundp sym) (describe-variable sym))
7663 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7665 (defun gnus-button-handle-describe-key (url)
7666 "Call `describe-key' when pushing the corresponding URL button."
7668 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7669 (keys (ignore-errors (eval `(kbd ,key-string)))))
7672 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7674 (defun gnus-button-handle-apropos (url)
7675 "Call `apropos' when pushing the corresponding URL button."
7676 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7678 (defun gnus-button-handle-apropos-command (url)
7679 "Call `apropos' when pushing the corresponding URL button."
7681 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7683 (defun gnus-button-handle-apropos-variable (url)
7684 "Call `apropos' when pushing the corresponding URL button."
7686 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7687 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7689 (defun gnus-button-handle-apropos-documentation (url)
7690 "Call `apropos' when pushing the corresponding URL button."
7692 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7693 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7695 (defun gnus-button-handle-library (url)
7696 "Call `locate-library' when pushing the corresponding URL button."
7697 (gnus-message 9 "url=`%s'" url)
7698 (let* ((lib (locate-library url))
7699 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7701 (gnus-message 1 "Cannot locale library `%s'." url)
7702 (find-file-read-only file))))
7704 (defcustom gnus-button-man-level 5
7705 "*Integer that says how many man-related buttons Gnus will show.
7706 The higher the number, the more buttons will appear and the more false
7707 positives are possible. Note that you can set this variable local to
7708 specific groups. Setting it higher in Unix groups is probably a good idea.
7709 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7710 how to set variables in specific groups."
7712 :group 'gnus-article-buttons
7713 :link '(custom-manual "(gnus)Group Parameters")
7716 (defcustom gnus-button-emacs-level 5
7717 "*Integer that says how many emacs-related buttons Gnus will show.
7718 The higher the number, the more buttons will appear and the more false
7719 positives are possible. Note that you can set this variable local to
7720 specific groups. Setting it higher in Emacs or Gnus related groups is
7721 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7722 `gnus-parameters' on how to set variables in specific groups."
7724 :group 'gnus-article-buttons
7725 :link '(custom-manual "(gnus)Group Parameters")
7728 (defcustom gnus-button-message-level 5
7729 "*Integer that says how many buttons for news or mail messages will appear.
7730 The higher the number, the more buttons will appear and the more false
7731 positives are possible."
7732 ;; mail addresses, MIDs, URLs for news, ...
7734 :group 'gnus-article-buttons
7737 (defcustom gnus-button-browse-level 5
7738 "*Integer that says how many buttons for browsing will appear.
7739 The higher the number, the more buttons will appear and the more false
7740 positives are possible."
7741 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7743 :group 'gnus-article-buttons
7746 (defcustom gnus-button-alist
7747 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7748 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7749 ((concat "\\b\\(nntp\\|news\\):\\("
7750 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7751 0 t gnus-button-handle-news 2)
7752 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7753 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7754 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7755 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7756 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7757 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7758 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7759 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7760 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7761 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7762 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7763 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7764 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7765 ;; RFC 2368 (The mailto URL scheme)
7766 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7767 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7768 ("\\bmailto:\\([^ \n\t]+\\)"
7769 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7770 ;; Info Konqueror style <info:/foo/bar baz>.
7771 ;; Must come before " Gnus home-grown style".
7772 ("\\binfo://?\\([^'\">\n\t]+\\)"
7773 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7774 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7775 ("\\binfo://\\([^'\">\n\t ]+\\)"
7776 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7777 ;; Info GNOME style <info:foo#bar_baz>
7778 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7779 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7780 ;; Info KDE style <info:(foo)bar baz>
7781 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7782 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7783 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7784 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7785 ("\\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,]*\\)\\)?"
7786 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7787 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7789 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7790 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7791 ;; Emacs help commands
7792 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7793 ;; regexp doesn't match arguments containing ` '.
7794 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7795 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7796 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7797 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7798 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7799 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7800 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7801 ;; The following entries may lead to many false positives so don't enable
7802 ;; them by default (use a high button level).
7803 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7804 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7805 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7806 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7807 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7808 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7809 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7810 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7811 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7812 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7813 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7814 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7815 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7816 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7817 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7818 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7819 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7820 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7821 ;; Unlike the other regexps we really have to require quoting
7822 ;; here to determine where it ends.
7823 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7824 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7825 ("<URL: *\\([^\n<>]*\\)>"
7826 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7827 ;; RFC 2396 (2.4.3., delims) ...
7828 ("\"URL: *\\([^\n\"]*\\)\""
7829 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7831 (gnus-button-url-regexp
7832 0 (>= gnus-button-browse-level 0) browse-url 0)
7834 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7835 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7836 gnus-button-handle-man 1)
7837 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7838 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7839 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7840 gnus-button-handle-man 1)
7841 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7842 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7843 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7844 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7845 ;; Recognizing patches to .el files. This is somewhat obscure,
7846 ;; but considering the percentage of Gnus users who hack Emacs
7848 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7849 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7850 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7851 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7852 ;; MID or mail: To avoid too many false positives we don't try to catch
7853 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7854 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7855 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7856 ;; so that non-ambiguous entries (see above) match first.
7857 (gnus-button-mid-or-mail-regexp
7858 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7859 "*Alist of regexps matching buttons in article bodies.
7861 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7862 REGEXP: is the string (case insensitive) matching text around the button (can
7863 also be Lisp expression evaluating to a string),
7864 BUTTON: is the number of the regexp grouping actually matching the button,
7865 FORM: is a Lisp expression which must eval to true for the button to
7867 CALLBACK: is the function to call when the user push this button, and each
7868 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7870 CALLBACK can also be a variable, in that case the value of that
7871 variable it the real callback function."
7872 :group 'gnus-article-buttons
7873 :type '(repeat (list (choice regexp variable sexp)
7874 (integer :tag "Button")
7876 (function :tag "Callback")
7879 (integer :tag "Regexp group")))))
7880 (put 'gnus-button-alist 'risky-local-variable t)
7882 (defcustom gnus-header-button-alist
7883 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7884 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7885 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7886 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7887 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7888 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7889 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7890 0 (>= gnus-button-browse-level 0) browse-url 0)
7891 ("^Subject:" gnus-button-url-regexp
7892 0 (>= gnus-button-browse-level 0) browse-url 0)
7893 ("^[^:]+:" gnus-button-url-regexp
7894 0 (>= gnus-button-browse-level 0) browse-url 0)
7895 ("^OpenPGP:.*url=" gnus-button-url-regexp
7896 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7897 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7898 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7899 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7900 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7901 "*Alist of headers and regexps to match buttons in article heads.
7903 This alist is very similar to `gnus-button-alist', except that each
7904 alist has an additional HEADER element first in each entry:
7906 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7908 HEADER is a regexp to match a header. For a fuller explanation, see
7909 `gnus-button-alist'."
7910 :group 'gnus-article-buttons
7911 :group 'gnus-article-headers
7912 :type '(repeat (list (regexp :tag "Header")
7913 (choice regexp variable)
7914 (integer :tag "Button")
7916 (function :tag "Callback")
7919 (integer :tag "Regexp group")))))
7920 (put 'gnus-header-button-alist 'risky-local-variable t)
7924 (defun gnus-article-push-button (event)
7925 "Check text under the mouse pointer for a callback function.
7926 If the text under the mouse pointer has a `gnus-callback' property,
7927 call it with the value of the `gnus-data' text property."
7929 (set-buffer (window-buffer (posn-window (event-start event))))
7930 (let* ((pos (posn-point (event-start event)))
7931 (data (get-text-property pos 'gnus-data))
7932 (fun (get-text-property pos 'gnus-callback)))
7935 (funcall fun data))))
7937 (defun gnus-article-press-button ()
7938 "Check text at point for a callback function.
7939 If the text at point has a `gnus-callback' property,
7940 call it with the value of the `gnus-data' text property."
7942 (let ((data (get-text-property (point) 'gnus-data))
7943 (fun (get-text-property (point) 'gnus-callback)))
7945 (funcall fun data))))
7947 (defun gnus-article-highlight (&optional force)
7948 "Highlight current article.
7949 This function calls `gnus-article-highlight-headers',
7950 `gnus-article-highlight-citation',
7951 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7952 do the highlighting. See the documentation for those functions."
7953 (interactive (list 'force))
7954 (gnus-article-highlight-headers)
7955 (gnus-article-highlight-citation force)
7956 (gnus-article-highlight-signature)
7957 (gnus-article-add-buttons)
7958 (gnus-article-add-buttons-to-head))
7960 (defun gnus-article-highlight-some (&optional force)
7961 "Highlight current article.
7962 This function calls `gnus-article-highlight-headers',
7963 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7964 do the highlighting. See the documentation for those functions."
7965 (interactive (list 'force))
7966 (gnus-article-highlight-headers)
7967 (gnus-article-highlight-signature)
7968 (gnus-article-add-buttons))
7970 (defun gnus-article-highlight-headers ()
7971 "Highlight article headers as specified by `gnus-header-face-alist'."
7973 (gnus-with-article-headers
7974 (let (regexp header-face field-face from hpoints fpoints)
7975 (dolist (entry gnus-header-face-alist)
7976 (goto-char (point-min))
7977 (setq regexp (concat "^\\("
7978 (if (string-equal "" (nth 0 entry))
7982 header-face (nth 1 entry)
7983 field-face (nth 2 entry))
7984 (while (and (re-search-forward regexp nil t)
7988 (unless (search-forward ":" nil t)
7990 (when (and header-face
7991 (not (memq (point) hpoints)))
7992 (push (point) hpoints)
7993 (gnus-put-text-property from (point) 'face header-face))
7994 (when (and field-face
7995 (not (memq (setq from (point)) fpoints)))
7997 (if (re-search-forward "^[^ \t]" nil t)
7999 (goto-char (point-max)))
8000 (gnus-put-text-property from (point) 'face field-face)))))))
8002 (defun gnus-article-highlight-signature ()
8003 "Highlight the signature in an article.
8004 It does this by highlighting everything after
8005 `gnus-signature-separator' using the face `gnus-signature'."
8007 (gnus-with-article-buffer
8008 (let ((inhibit-point-motion-hooks t))
8010 (when (and gnus-signature-face
8011 (gnus-article-narrow-to-signature))
8012 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8013 'face gnus-signature-face)
8015 (gnus-article-search-signature)
8016 (let ((start (match-beginning 0))
8017 (end (set-marker (make-marker) (1+ (match-end 0)))))
8018 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8021 (defun gnus-button-in-region-p (b e prop)
8022 "Say whether PROP exists in the region."
8023 (text-property-not-all b e prop nil))
8025 (defun gnus-article-add-buttons ()
8026 "Find external references in the article and make buttons of them.
8027 \"External references\" are things like Message-IDs and URLs, as
8028 specified by `gnus-button-alist'."
8030 (gnus-with-article-buffer
8031 (let ((inhibit-point-motion-hooks t)
8032 (case-fold-search t)
8033 (alist gnus-button-alist)
8035 ;; We skip the headers.
8038 (while (setq entry (pop alist))
8039 (setq regexp (eval (car entry)))
8041 (while (re-search-forward regexp nil t)
8042 (let ((start (match-beginning (nth 1 entry)))
8043 (end (match-end (nth 1 entry)))
8044 (from (match-beginning 0)))
8045 (when (and (eval (nth 2 entry))
8046 (not (gnus-button-in-region-p
8047 start end 'gnus-callback)))
8048 ;; That optional form returned non-nil, so we add the
8050 (setq from (set-marker (make-marker) from))
8051 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8052 (gnus-article-extend-url-button from start end))
8053 (gnus-article-add-button start end
8054 'gnus-button-push (list from entry))
8055 (gnus-put-text-property
8057 'gnus-string (buffer-substring-no-properties
8060 (defun gnus-article-extend-url-button (beg start end)
8061 "Extend url button if url is folded into two or more lines.
8062 Return non-nil if button is extended. BEG is a marker that points to
8063 the beginning position of a text containing url. START and END are
8064 the endpoints of a url button before it is extended. The concatenated
8065 url is put as the `gnus-button-url' overlay property on the button."
8066 (let ((opoint (point))
8067 (points (list start end))
8072 (not (looking-at "[\t ]*[\">]")))
8076 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8077 (buffer-substring (point-at-bol) start)))
8079 (setq url (list (buffer-substring start end))
8080 delim (if (match-beginning 1) ">" "\""))
8082 (setq regexp (concat
8083 (when (and (looking-at
8084 message-cite-prefix-regexp)
8085 (< (match-end 0) start))
8086 (regexp-quote (match-string 0)))
8088 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8092 (and (looking-at regexp)
8095 (push (or (match-string 2)
8098 (push (setq end (or (match-end 2)
8101 (push (or (match-beginning 2)
8102 (match-beginning 1))
8104 (match-beginning 2)))
8105 (let (gnus-article-mouse-face widget-mouse-face)
8107 (gnus-article-add-button (pop points) (pop points)
8109 (list beg (assq 'gnus-button-url-regexp
8110 gnus-button-alist)))))
8111 (let ((overlay (gnus-make-overlay start end)))
8112 (gnus-overlay-put overlay 'evaporate t)
8113 (gnus-overlay-put overlay 'gnus-button-url
8114 (list (mapconcat 'identity (nreverse url) "")))
8115 (when gnus-article-mouse-face
8116 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8118 (goto-char opoint))))
8120 ;; Add buttons to the head of an article.
8121 (defun gnus-article-add-buttons-to-head ()
8122 "Add buttons to the head of the article."
8124 (gnus-with-article-headers
8126 (dolist (entry gnus-header-button-alist)
8127 ;; Each alist entry.
8128 (goto-char (point-min))
8129 (while (re-search-forward (car entry) nil t)
8130 ;; Each header matching the entry.
8131 (setq beg (match-beginning 0))
8132 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8133 (match-beginning 0))
8136 (while (re-search-forward (eval (nth 1 entry)) end t)
8137 ;; Each match within a header.
8138 (let* ((entry (cdr entry))
8139 (start (match-beginning (nth 1 entry)))
8140 (end (match-end (nth 1 entry)))
8141 (form (nth 2 entry)))
8142 (goto-char (match-end 0))
8144 (gnus-article-add-button
8145 start end (nth 3 entry)
8146 (buffer-substring (match-beginning (nth 4 entry))
8147 (match-end (nth 4 entry)))))))
8148 (goto-char end))))))
8150 ;;; External functions:
8152 (defun gnus-article-add-button (from to fun &optional data text)
8153 "Create a button between FROM and TO with callback FUN and data DATA."
8154 (when gnus-article-button-face
8155 (gnus-overlay-put (gnus-make-overlay from to nil t)
8156 'face gnus-article-button-face))
8157 (gnus-add-text-properties
8159 (nconc (and gnus-article-mouse-face
8160 (list gnus-mouse-face-prop gnus-article-mouse-face))
8161 (list 'gnus-callback fun)
8162 (and data (list 'gnus-data data))))
8163 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8164 :help-echo (or text "Follow the link")
8165 :keymap gnus-url-button-map
8166 :button-keymap gnus-widget-button-keymap))
8168 (defun gnus-article-copy-string ()
8169 "Copy the string in the button to the kill ring."
8171 (gnus-article-check-buffer)
8172 (let ((data (get-text-property (point) 'gnus-string)))
8176 (copy-region-as-kill (point-min) (point-max))
8177 (message "Copied %s" data)))))
8179 ;;; Internal functions:
8181 (defun gnus-article-set-globals ()
8182 (with-current-buffer gnus-summary-buffer
8183 (gnus-set-global-variables)))
8185 (defun gnus-signature-toggle (end)
8186 (gnus-with-article-buffer
8187 (let ((inhibit-point-motion-hooks t))
8188 (if (text-property-any end (point-max) 'article-type 'signature)
8190 (gnus-delete-wash-type 'signature)
8191 (gnus-remove-text-properties-when
8192 'article-type 'signature end (point-max)
8193 (cons 'article-type (cons 'signature
8194 gnus-hidden-properties))))
8195 (gnus-add-wash-type 'signature)
8196 (gnus-add-text-properties-when
8197 'article-type nil end (point-max)
8198 (cons 'article-type (cons 'signature
8199 gnus-hidden-properties)))))
8200 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8201 (gnus-set-mode-line 'article))))
8203 (defun gnus-button-push (marker-and-entry)
8204 ;; Push button starting at MARKER.
8206 (let* ((marker (car marker-and-entry))
8207 (entry (cadr marker-and-entry))
8208 (regexp (car entry))
8209 (inhibit-point-motion-hooks t))
8211 ;; This is obviously true, or something bad is happening :)
8212 ;; But we need it to have the match-data
8213 (when (looking-at (or (if (symbolp regexp)
8214 (symbol-value regexp)
8216 (let ((fun (nth 3 entry))
8217 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8218 (get-char-property marker 'gnus-button-url))
8219 (mapcar (lambda (group)
8220 (let ((string (match-string group)))
8221 (set-text-properties
8222 0 (length string) nil string)
8224 (nthcdr 4 entry)))))
8230 (fboundp (symbol-value fun)))
8231 (apply (symbol-value fun) args))
8233 (gnus-message 1 "You must define `%S' to use this button"
8234 (cons fun args)))))))))
8236 (defun gnus-parse-news-url (url)
8237 (let (scheme server port group message-id articles)
8240 (goto-char (point-min))
8241 (when (looking-at "\\([A-Za-z]+\\):")
8242 (setq scheme (match-string 1))
8243 (goto-char (match-end 0)))
8244 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8245 (setq server (match-string 1))
8246 (setq port (if (stringp (match-string 3))
8247 (string-to-number (match-string 3))
8249 (goto-char (match-end 0)))
8252 ((looking-at "\\(.*@.*\\)")
8253 (setq message-id (match-string 1)))
8254 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8255 (setq group (match-string 1)
8256 articles (split-string (match-string 2) "-")))
8257 ((looking-at "\\([^/]+\\)/?")
8258 (setq group (match-string 1)))
8260 (error "Unknown news URL syntax"))))
8261 (list scheme server port group message-id articles)))
8263 (defun gnus-button-handle-news (url)
8265 (destructuring-bind (scheme server port group message-id articles)
8266 (gnus-parse-news-url url)
8269 (with-current-buffer gnus-summary-buffer
8271 (let ((gnus-refer-article-method
8272 (nconc (list (list 'nntp server))
8273 gnus-refer-article-method))
8274 (nntp-port-number (or port "nntp")))
8275 (gnus-message 7 "Fetching %s with %s"
8276 message-id gnus-refer-article-method)
8277 (gnus-summary-refer-article message-id))
8278 (gnus-summary-refer-article message-id))))
8280 (gnus-button-fetch-group url)))))
8282 (defun gnus-button-patch (library line)
8283 "Visit an Emacs Lisp library LIBRARY on line LINE."
8285 (let ((file (locate-library (file-name-nondirectory library))))
8287 (error "Couldn't find library %s" library))
8289 (goto-char (point-min))
8290 (forward-line (1- (string-to-number line)))))
8292 (defun gnus-button-handle-man (url)
8294 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8295 (when (eq gnus-button-man-handler 'woman)
8296 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8297 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8298 (funcall gnus-button-man-handler url))
8300 (defun gnus-button-handle-info-url (url)
8301 "Fetch an info URL."
8302 (setq url (mm-subst-char-in-string ?+ ?\ url))
8304 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8305 (gnus-info-find-node
8306 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8308 ")" (gnus-url-unhex-string (match-string 2 url)))))
8309 ((string-match "([^)\"]+)[^\"]+" url)
8311 (gnus-replace-in-string
8312 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8313 (gnus-info-find-node url))
8314 (t (error "Can't parse %s" url))))
8316 (defun gnus-button-handle-info-url-gnome (url)
8317 "Fetch GNOME style info URL."
8318 (setq url (mm-subst-char-in-string ?_ ?\ url))
8319 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8320 (gnus-info-find-node
8322 (gnus-url-unhex-string
8323 (match-string 1 url))
8325 (or (gnus-url-unhex-string
8326 (match-string 2 url))
8328 (error "Can't parse %s" url)))
8330 (defun gnus-button-handle-info-url-kde (url)
8331 "Fetch KDE style info URL."
8332 (gnus-info-find-node (gnus-url-unhex-string url)))
8334 ;; (info) will autoload info.el
8335 (declare-function Info-menu "info" (menu-item &optional fork))
8336 (declare-function Info-index-next "info" (num))
8338 (defun gnus-button-handle-info-keystrokes (url)
8339 "Call `info' when pushing the corresponding URL button."
8340 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8341 (let (node indx comma)
8343 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8344 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8345 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8346 "\\(?:[ \t\n,]*\\)\\)?")
8348 (setq node (match-string 2 url)
8349 indx (match-string 3 url))
8350 (error "Can't parse %s" url))
8354 (when (> (length indx) 0)
8355 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8358 (setq comma (match-string 2 indx))
8359 (setq indx (match-string 1 indx))
8362 (dotimes (i (with-temp-buffer
8364 ;; Note: the XEmacs version of `how-many' takes
8365 ;; no optional argument.
8366 (goto-char (point-min))
8368 (Info-index-next 1)))
8371 (autoload 'pgg-snarf-keys-region "pgg")
8372 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8373 (declare-function pgg-display-output-buffer "pgg" (start end status))
8375 (defun gnus-button-openpgp (url)
8376 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8378 (mm-url-insert-file-contents-external url)
8379 (pgg-snarf-keys-region (point-min) (point-max))
8380 (pgg-display-output-buffer nil nil nil)))
8382 (defun gnus-button-message-id (message-id)
8384 (with-current-buffer gnus-summary-buffer
8385 (gnus-summary-refer-article message-id)))
8387 (defun gnus-button-fetch-group (address &rest ignore)
8388 "Fetch GROUP specified by ADDRESS."
8389 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8391 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8392 ;; for nntp:// and news://
8393 (setq address (match-string 3 address)))
8394 (if (not (string-match "[:/]" address))
8395 ;; This is just a simple group url.
8396 (gnus-group-read-ephemeral-group address gnus-select-method)
8399 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8401 (error "Can't parse %s" address)
8402 (gnus-group-read-ephemeral-group
8403 (match-string 4 address)
8404 `(nntp ,(match-string 1 address)
8405 (nntp-address ,(match-string 1 address))
8406 (nntp-port-number ,(if (match-end 3)
8407 (match-string 3 address)
8410 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8412 (defun gnus-url-parse-query-string (query &optional downcase)
8413 (let (retval pairs cur key val)
8414 (setq pairs (split-string query "&"))
8416 (setq cur (car pairs)
8418 (if (not (string-match "=" cur))
8420 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8421 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8423 (setq key (downcase key)))
8424 (setq cur (assoc key retval))
8426 (setcdr cur (cons val (cdr cur)))
8427 (setq retval (cons (list key val) retval)))))
8430 (defun gnus-url-mailto (url)
8431 ;; Send mail to someone
8432 (setq url (replace-regexp-in-string "\n" " " url))
8433 (when (string-match "mailto:/*\\(.*\\)" url)
8434 (setq url (substring url (match-beginning 1) nil)))
8435 (let (to args subject func)
8436 (setq args (gnus-url-parse-query-string
8437 (if (string-match "^\\?" url)
8439 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8440 (concat "to=" (match-string 1 url) "&"
8441 (match-string 2 url))
8442 (concat "to=" url))))
8443 subject (cdr-safe (assoc "subject" args)))
8446 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8449 (message-position-on-field (caar args)))
8450 (insert (gnus-replace-in-string
8451 (mapconcat 'identity (reverse (cdar args)) ", ")
8453 (setq args (cdr args)))
8456 (message-goto-subject))))
8458 (defun gnus-button-embedded-url (address)
8459 "Activate ADDRESS with `browse-url'."
8460 (browse-url (gnus-strip-whitespace address)))
8462 ;;; Next/prev buttons in the article buffer.
8464 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8465 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8467 (defvar gnus-prev-page-map
8468 (let ((map (make-sparse-keymap)))
8469 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8470 (define-key map "\r" 'gnus-button-prev-page)
8473 (defvar gnus-next-page-map
8474 (let ((map (make-sparse-keymap)))
8475 (define-key map gnus-mouse-2 'gnus-button-next-page)
8476 (define-key map "\r" 'gnus-button-next-page)
8479 (defun gnus-insert-prev-page-button ()
8481 (inhibit-read-only t))
8483 gnus-prev-page-line-format nil
8484 `(keymap ,gnus-prev-page-map
8486 gnus-callback gnus-article-button-prev-page
8487 article-type annotation))
8489 ;; Exclude a newline.
8492 (when gnus-article-button-face
8493 (gnus-overlay-put (gnus-make-overlay b e nil t)
8494 'face gnus-article-button-face))
8495 (widget-convert-button
8497 :action 'gnus-button-prev-page
8498 :button-keymap gnus-prev-page-map)))
8500 (defun gnus-button-next-page (&optional args more-args)
8501 "Go to the next page."
8503 (let ((win (selected-window)))
8504 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8505 (gnus-article-next-page)
8506 (select-window win)))
8508 (defun gnus-button-prev-page (&optional args more-args)
8509 "Go to the prev page."
8511 (let ((win (selected-window)))
8512 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8513 (gnus-article-prev-page)
8514 (select-window win)))
8516 (defun gnus-insert-next-page-button ()
8518 (inhibit-read-only t))
8519 (gnus-eval-format gnus-next-page-line-format nil
8520 `(keymap ,gnus-next-page-map
8522 gnus-callback gnus-article-button-next-page
8523 article-type annotation))
8525 ;; Exclude a newline.
8528 (when gnus-article-button-face
8529 (gnus-overlay-put (gnus-make-overlay b e nil t)
8530 'face gnus-article-button-face))
8531 (widget-convert-button
8533 :action 'gnus-button-next-page
8534 :button-keymap gnus-next-page-map)))
8536 (defun gnus-article-button-next-page (arg)
8537 "Go to the next page."
8539 (let ((win (selected-window)))
8540 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8541 (gnus-article-next-page)
8542 (select-window win)))
8544 (defun gnus-article-button-prev-page (arg)
8545 "Go to the prev page."
8547 (let ((win (selected-window)))
8548 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8549 (gnus-article-prev-page)
8550 (select-window win)))
8552 (defvar gnus-decode-header-methods
8553 '(mail-decode-encoded-word-region)
8554 "List of methods used to decode headers.
8556 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8557 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8558 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8559 whose names match REGEXP.
8562 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8563 mail-decode-encoded-word-region
8564 (\"chinese\" . rfc1843-decode-region))
8567 (defvar gnus-decode-header-methods-cache nil)
8569 (defun gnus-multi-decode-header (start end)
8570 "Apply the functions from `gnus-encoded-word-methods' that match."
8571 (unless (and gnus-decode-header-methods-cache
8572 (eq gnus-newsgroup-name
8573 (car gnus-decode-header-methods-cache)))
8574 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8575 (dolist (x gnus-decode-header-methods)
8577 (nconc gnus-decode-header-methods-cache (list x))
8578 (if (and gnus-newsgroup-name
8579 (string-match (car x) gnus-newsgroup-name))
8580 (nconc gnus-decode-header-methods-cache
8582 (let ((xlist gnus-decode-header-methods-cache))
8585 (narrow-to-region start end)
8587 (funcall (pop xlist) (point-min) (point-max))))))
8590 ;;; Treatment top-level handling.
8593 (defvar gnus-inhibit-article-treatments nil)
8595 (defun gnus-treat-article (gnus-treat-condition
8596 &optional part-number total-parts gnus-treat-type)
8597 (let ((gnus-treat-length (- (point-max) (point-min)))
8598 (alist gnus-treatment-function-alist)
8599 (article-goto-body-goes-to-point-min-p t)
8601 (or (not gnus-treat-type)
8603 (let ((list gnus-article-treat-types))
8605 (when (string-match (pop list) gnus-treat-type)
8606 (throw 'found t)))))))
8607 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8609 (gnus-run-hooks 'gnus-part-display-hook)
8610 (dolist (elem alist)
8613 (when (gnus-buffer-live-p gnus-summary-buffer)
8614 (set-buffer gnus-summary-buffer))
8615 (symbol-value (car elem))))
8616 (when (and (or (consp val)
8618 (or (not gnus-inhibit-article-treatments)
8619 (eq gnus-treat-condition 'head))
8620 (gnus-treat-predicate val)
8621 (or (not (get (car elem) 'highlight))
8624 (funcall (cadr elem)))))))
8626 ;; Dynamic variables.
8627 (defvar part-number)
8628 (defvar total-parts)
8629 (defvar gnus-treat-type)
8630 (defvar gnus-treat-condition)
8631 (defvar gnus-treat-length)
8633 (defun gnus-treat-predicate (val)
8637 (gnus-treat-condition
8638 (eq gnus-treat-condition val))
8640 (stringp (car val)))
8641 (apply 'gnus-or (mapcar `(lambda (s)
8642 (string-match s ,(or gnus-newsgroup-name "")))
8645 (let ((pred (pop val)))
8648 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8650 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8652 (not (gnus-treat-predicate (car val))))
8654 (equal (car val) gnus-treat-type))
8658 (error "%S is not a valid predicate" pred)))))
8666 (eq part-number total-parts))
8668 (< gnus-treat-length val))
8670 (error "%S is not a valid value" val))))
8672 (defun gnus-article-encrypt-body (protocol &optional n)
8673 "Encrypt the article body."
8676 (or gnus-article-encrypt-protocol
8677 (gnus-completing-read "Encrypt protocol"
8678 (mapcar 'car gnus-article-encrypt-protocol-alist)
8680 current-prefix-arg))
8681 ;; User might hit `K E' instead of `K e', so prompt once.
8682 (when (and gnus-article-encrypt-protocol
8684 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8685 (error "Encrypt aborted")))
8686 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8688 (error "Can't find the encrypt protocol %s" protocol))
8689 (if (member gnus-newsgroup-name '("nndraft:delayed"
8692 (error "Can't encrypt the article in group %s"
8693 gnus-newsgroup-name))
8694 (gnus-summary-iterate n
8695 (with-current-buffer gnus-summary-buffer
8696 (let ((mail-parse-charset gnus-newsgroup-charset)
8697 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8698 (summary-buffer gnus-summary-buffer)
8700 (gnus-set-global-variables)
8701 (when (gnus-group-read-only-p)
8702 (error "The current newsgroup does not support article encrypt"))
8703 (gnus-summary-show-article t)
8705 (or (mail-header-references gnus-current-headers) ""))
8706 (set-buffer gnus-article-buffer)
8707 (let* ((inhibit-read-only t)
8709 (mapcar (lambda (field)
8710 (and (save-restriction
8711 (message-narrow-to-head)
8712 (goto-char (point-min))
8713 (search-forward field nil t))
8715 (message-narrow-to-field)
8717 (delete-region (point-min) (point-max))
8719 '("Content-Type:" "Content-Transfer-Encoding:"
8720 "Content-Disposition:"))))
8721 (message-narrow-to-head)
8722 (message-remove-header "MIME-Version")
8723 (goto-char (point-max))
8724 (setq point (point))
8725 (insert (apply 'concat headers))
8727 (narrow-to-region point (point-max))
8728 (let ((message-options message-options))
8729 (message-options-set 'message-sender user-mail-address)
8730 (message-options-set 'message-recipients user-mail-address)
8731 (message-options-set 'message-sign-encrypt 'not)
8733 (goto-char (point-min))
8734 (insert "MIME-Version: 1.0\n")
8736 (gnus-summary-edit-article-done
8737 references nil summary-buffer t))
8738 (when gnus-keep-backlog
8739 (gnus-backlog-remove-article
8740 (car gnus-article-current) (cdr gnus-article-current)))
8741 (gnus-flush-original-article-buffer)
8742 (when gnus-use-cache
8743 (gnus-cache-update-article
8744 (car gnus-article-current) (cdr gnus-article-current))))))))
8746 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8747 "The following specs can be used:
8748 %t The security MIME type
8751 %D Details if button is pressed")
8753 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8754 "The following specs can be used:
8755 %t The security MIME type
8758 %D Details if button is pressed")
8760 (defvar gnus-mime-security-button-line-format-alist
8761 '((?t gnus-tmp-type ?s)
8762 (?i gnus-tmp-info ?s)
8763 (?d gnus-tmp-details ?s)
8764 (?D gnus-tmp-pressed-details ?s)))
8766 (defvar gnus-mime-security-button-commands
8767 '((gnus-article-press-button "\r" "Show Detail")
8771 (gnus-mime-security-save-part "o" "Save...")
8780 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8783 (defvar gnus-mime-security-button-map
8784 (let ((map (make-sparse-keymap)))
8785 (define-key map gnus-mouse-2 'gnus-article-push-button)
8786 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8787 (dolist (c gnus-mime-security-button-commands)
8788 (define-key map (cadr c) (car c)))
8792 gnus-mime-security-button-menu gnus-mime-security-button-map
8793 "Security button menu."
8797 (unless (eq (car c) 'undefined)
8798 (vector (caddr c) (car c) :active t)))
8799 gnus-mime-security-button-commands))))
8801 (defun gnus-mime-security-button-menu (event prefix)
8802 "Construct a context-sensitive menu of security commands."
8803 (interactive "e\nP")
8804 (save-window-excursion
8805 (let ((pos (event-start event)))
8806 (select-window (posn-window pos))
8807 (goto-char (posn-point pos))
8808 (gnus-article-check-buffer)
8809 (popup-menu gnus-mime-security-button-menu nil prefix))))
8811 (defvar gnus-mime-security-details-buffer nil)
8813 (defvar gnus-mime-security-button-pressed nil)
8815 (defvar gnus-mime-security-show-details-inline t
8816 "If non-nil, show details in the article buffer.")
8818 (defun gnus-mime-security-verify-or-decrypt (handle)
8819 (mm-remove-parts (cdr handle))
8820 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8821 point (inhibit-read-only t))
8823 (goto-char (car region)))
8824 (setq point (point))
8825 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8826 (let* ((mm-verify-option 'known)
8827 (mm-decrypt-option 'known)
8828 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8829 (unless (eq nparts (cdr handle))
8830 (mm-destroy-parts (cdr handle))
8831 (setcdr handle nparts))))
8832 (gnus-mime-display-security handle)
8834 (delete-region (point) (cdr region))
8835 (set-marker (car region) nil)
8836 (set-marker (cdr region) nil))
8839 (defun gnus-mime-security-show-details (handle)
8840 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8842 (gnus-message 5 "No details.")
8843 (if gnus-mime-security-show-details-inline
8844 (let ((gnus-mime-security-button-pressed
8845 (not (get-text-property (point) 'gnus-mime-details)))
8846 (gnus-mime-security-button-line-format
8847 (get-text-property (point) 'gnus-line-format))
8848 (inhibit-read-only t))
8850 (while (eq (get-text-property (point) 'gnus-line-format)
8851 gnus-mime-security-button-line-format)
8855 (narrow-to-region (point) (point))
8856 (gnus-insert-mime-security-button handle))
8857 (delete-region (point)
8858 (or (text-property-not-all
8861 gnus-mime-security-button-line-format)
8864 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8865 (with-current-buffer gnus-mime-security-details-buffer
8868 (setq gnus-mime-security-details-buffer
8869 (gnus-get-buffer-create "*MIME Security Details*")))
8870 (with-current-buffer gnus-mime-security-details-buffer
8872 (goto-char (point-min)))
8873 (pop-to-buffer gnus-mime-security-details-buffer)))))
8875 (defun gnus-mime-security-press-button (handle)
8877 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8878 (gnus-mime-security-show-details handle)
8879 (gnus-mime-security-verify-or-decrypt handle))))
8881 (defun gnus-insert-mime-security-button (handle &optional displayed)
8882 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8885 (or (nth 2 (assoc protocol mm-verify-function-alist))
8886 (nth 2 (assoc protocol mm-decrypt-function-alist))
8888 (if (equal (car handle) "multipart/signed")
8889 " Signed" " Encrypted")
8892 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8895 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8896 gnus-tmp-pressed-details
8898 (setq gnus-tmp-details
8899 (if gnus-tmp-details
8900 (concat "\n" gnus-tmp-details)
8902 (setq gnus-tmp-pressed-details
8903 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8908 gnus-mime-security-button-line-format
8909 gnus-mime-security-button-line-format-alist
8910 `(keymap ,gnus-mime-security-button-map
8911 gnus-callback gnus-mime-security-press-button
8912 gnus-line-format ,gnus-mime-security-button-line-format
8913 gnus-mime-details ,gnus-mime-security-button-pressed
8914 article-type annotation
8917 ;; Exclude a newline.
8920 (when gnus-article-button-face
8921 (gnus-overlay-put (gnus-make-overlay b e nil t)
8922 'face gnus-article-button-face))
8923 (widget-convert-button
8926 :action 'gnus-widget-press-button
8927 :button-keymap gnus-mime-security-button-map
8930 ;; Needed to properly clear the message due to a bug in
8931 ;; wid-edit (XEmacs only).
8932 (when (boundp 'help-echo-owns-message)
8933 (setq help-echo-owns-message t))
8935 "%S: show detail; %S: more options"
8936 (aref gnus-mouse-2 0)
8937 (aref gnus-down-mouse-3 0))))))
8939 (defun gnus-mime-display-security (handle)
8941 (narrow-to-region (point) (point))
8942 (unless (gnus-unbuttonized-mime-type-p (car handle))
8943 (gnus-insert-mime-security-button handle))
8944 (gnus-mime-display-part (cadr handle))
8947 (unless (gnus-unbuttonized-mime-type-p (car handle))
8948 (let ((gnus-mime-security-button-line-format
8949 gnus-mime-security-button-end-line-format))
8950 (gnus-insert-mime-security-button handle)))
8951 (mm-set-handle-multipart-parameter
8952 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8953 (goto-char (point-max))))
8955 (defun gnus-mime-security-run-function (function)
8956 "Run FUNCTION with the security part under point."
8957 (gnus-article-check-buffer)
8958 (let ((data (get-text-property (point) 'gnus-data))
8960 (when (and (stringp (car-safe data))
8961 (setq buffer (mm-handle-multipart-original-buffer data))
8962 (setq handle (cadr data)))
8963 (if (bufferp (mm-handle-buffer handle))
8965 (setq handle (cons buffer (copy-sequence (cdr handle))))
8966 (mm-handle-set-undisplayer handle nil))
8967 (setq handle (mm-make-handle
8969 (mm-handle-multipart-ctl-parameter handle 'protocol)
8970 nil nil nil nil nil nil)))
8971 (funcall function handle))))
8973 (defun gnus-mime-security-save-part ()
8974 "Save the security part under point."
8976 (gnus-mime-security-run-function 'mm-save-part))
8978 (defun gnus-mime-security-pipe-part ()
8979 "Pipe the security part under point to a process."
8981 (gnus-mime-security-run-function 'mm-pipe-part))
8987 (run-hooks 'gnus-art-load-hook)
8989 ;;; gnus-art.el ends here