1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2011 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/>.
27 ;; For Emacs <22.2 and XEmacs.
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (defvar w3m-minor-mode-map)
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
57 (defgroup gnus-article nil
59 :link '(custom-manual "(gnus)Article Buffer")
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
78 (defgroup gnus-article-signature nil
80 :link '(custom-manual "(gnus)Article Signature")
83 (defgroup gnus-article-headers nil
85 :link '(custom-manual "(gnus)Hiding Headers")
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
98 (defgroup gnus-article-saving nil
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice regexp
168 :group 'gnus-article-hiding)
170 (defcustom gnus-visible-headers
171 "^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:"
172 "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
180 (widget-editable-list-match widget value)))
182 (const :tag "Use gnus-ignored-headers" nil)
184 :group 'gnus-article-hiding)
186 (defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189 "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
210 :type '(set (const :tag "Headers with no content." empty)
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
217 (const :tag "Date less than four days old." date)
218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
219 (const :tag "Multiple To and/or Cc headers." many-to))
220 :group 'gnus-article-hiding)
222 (defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text. Boring text is controlled by
227 `gnus-article-boring-faces'."
230 :group 'gnus-article-hiding)
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234 This can also be a list of regexps. In that case, it will be checked
235 from head to tail looking for a separator. Searches will be done from
236 the end of the buffer."
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
239 (repeat :tag "List of regexp" regexp))
240 :group 'gnus-article-signature)
242 (defcustom gnus-signature-limit nil
243 "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number. If it is a floating point number, no signature may be
246 longer (in lines) than that number. If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer. If it is a string, it will be used as a
249 regexp. If it matches, the text in question is not a signature.
251 This can also be a list of the above values."
252 :type '(choice (const nil)
256 (regexp :value ".*"))
257 :group 'gnus-article-signature)
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
262 :group 'gnus-article-hiding)
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
272 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
273 ; uncompface; } | icontopbm | ee -")
274 (if (gnus-image-type-available-p 'pbm)
275 'gnus-display-x-face-in-from
277 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
278 ; uncompface; } | icontopbm | display -"))
279 "*String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
308 '(choice :tag "Banner"
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
313 (const :tag "None" nil))
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
340 (const :tag "None" nil))))
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
372 (defcustom gnus-emphasis-alist
374 '(("\\*" "\\*" bold nil 2)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "*Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
410 :format "%[Customizing Style%]\n%v"
412 (group :tag "Default"
413 :value ("" 0 0 default)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
420 (if (not (eq (nth 2 value) 'default))
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
431 :value (("_" . "_") nil default)
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
452 :group 'gnus-article-emphasis
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
496 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
497 "Format for display of Date headers in article bodies.
498 See `format-time-string' for the possible values.
500 The variable can also be function, which should return a complete Date
501 header. The function is called with one argument, the time, which can
502 be fed to `format-time-string'."
503 :type '(choice string function)
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
507 (defcustom gnus-save-all-headers t
508 "*If non-nil, don't remove any headers before saving.
509 This will be overridden by the `:headers' property that the symbol of
510 the saver function, which is specified by `gnus-default-article-saver',
512 :group 'gnus-article-saving
515 (defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517 If it is nil, no prompting will be done, and the articles will be
518 saved to the default files. If this variable is `always', each and
519 every article that is saved will be preceded by a prompt, even when
520 saving large batches of articles. If this variable is neither nil not
521 `always', there the user will be prompted once for a file name for
522 each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
526 (sexp :tag "once" :format "%t\n" :value t)))
528 (defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531 If that variable is nil, however, all headers that match this regexp
532 will be kept while the rest will be deleted before saving. This and
533 `gnus-save-all-headers' will be overridden by the `:headers' property
534 that the symbol of the saver function, which is specified by
535 `gnus-default-article-saver', might have."
536 :group 'gnus-article-saving
539 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
540 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
541 "A function to save articles in your favorite format.
542 The function will be called by way of the `gnus-summary-save-article'
543 command, and friends such as `gnus-summary-save-article-rmail'.
545 Gnus provides the following functions:
547 * gnus-summary-save-in-rmail (Rmail format)
548 * gnus-summary-save-in-mail (Unix mail format)
549 * gnus-summary-save-in-folder (MH folder)
550 * gnus-summary-save-in-file (article format)
551 * gnus-summary-save-body-in-file (article body)
552 * gnus-summary-save-in-vm (use VM's folder format)
553 * gnus-summary-write-to-file (article format -- overwrite)
554 * gnus-summary-write-body-to-file (article body -- overwrite)
555 * gnus-summary-save-in-pipe (article format)
557 The symbol of each function may have the following properties:
560 The value non-nil means save decoded articles. This is meaningful
561 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
562 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
563 `gnus-summary-save-in-pipe'.
566 The value specifies an alternative function which appends, not
567 overwrites, articles to a file. This implies that when saving many
568 articles at a time, `gnus-prompt-before-saving' is bound to t and all
569 articles are saved in a single file. This is meaningful only with
570 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
573 The value specifies the symbol of a variable of which the value
574 specifies headers to be saved. If it is omitted,
575 `gnus-save-all-headers' and `gnus-saved-headers' control what
576 headers should be saved."
577 :group 'gnus-article-saving
578 :type '(radio (function-item gnus-summary-save-in-rmail)
579 (function-item gnus-summary-save-in-mail)
580 (function-item gnus-summary-save-in-folder)
581 (function-item gnus-summary-save-in-file)
582 (function-item gnus-summary-save-body-in-file)
583 (function-item gnus-summary-save-in-vm)
584 (function-item gnus-summary-write-to-file)
585 (function-item gnus-summary-write-body-to-file)
586 (function-item gnus-summary-save-in-pipe)
589 (defcustom gnus-article-save-coding-system
590 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
591 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
592 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
593 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
594 "Coding system used to save decoded articles to a file.
596 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
597 which can safely encode any characters in text. This is used by the
600 * gnus-summary-save-article-file
601 * gnus-summary-save-article-body-file
602 * gnus-summary-write-article-file
603 * gnus-summary-write-article-body-file
605 and the functions to which you may set `gnus-default-article-saver':
607 * gnus-summary-save-in-file
608 * gnus-summary-save-body-in-file
609 * gnus-summary-write-to-file
610 * gnus-summary-write-body-to-file
612 Those commands and functions save just text displayed in the article
613 buffer to a file if the value of this variable is non-nil. Note that
614 buttonized MIME parts will be lost in a saved file in that case.
615 Otherwise, raw articles will be saved."
616 :group 'gnus-article-saving
618 :format "%{%t%}:\n %[Value Menu%] %v"
619 (const :tag "Save raw articles" nil)
622 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
623 '((const :tag "UTF-8" utf-8)
624 (const :tag "iso-2022-7bit" iso-2022-7bit)
625 (const :tag "Emacs internal" emacs-mule)
626 (const :tag "escape-quoted" escape-quoted))))
627 (symbol :tag "Coding system")))
629 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
630 "A function generating a file name to save articles in Rmail format.
631 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
632 :group 'gnus-article-saving
635 (defcustom gnus-mail-save-name 'gnus-plain-save-name
636 "A function generating a file name to save articles in Unix mail format.
637 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
638 :group 'gnus-article-saving
641 (defcustom gnus-folder-save-name 'gnus-folder-save-name
642 "A function generating a file name to save articles in MH folder.
643 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
644 :group 'gnus-article-saving
647 (defcustom gnus-file-save-name 'gnus-numeric-save-name
648 "A function generating a file name to save articles in article format.
649 The function is called with NEWSGROUP, HEADERS, and optional
651 :group 'gnus-article-saving
654 (defcustom gnus-split-methods
655 '((gnus-article-archive-name)
656 (gnus-article-nndoc-name))
657 "*Variable used to suggest where articles are to be saved.
658 For instance, if you would like to save articles related to Gnus in
659 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
660 you could set this variable to something like:
662 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
663 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
665 This variable is an alist where the key is the match and the
666 value is a list of possible files to save in if the match is
669 If the match is a string, it is used as a regexp match on the
670 article. If the match is a symbol, that symbol will be funcalled
671 from the buffer of the article to be saved with the newsgroup as the
672 parameter. If it is a list, it will be evaled in the same buffer.
674 If this form or function returns a string, this string will be used as a
675 possible file name; and if it returns a non-nil list, that list will be
676 used as possible file names."
677 :group 'gnus-article-saving
678 :type '(repeat (choice (list :value (fun) function)
679 (cons :value ("" "") regexp (repeat string))
682 (defcustom gnus-page-delimiter "^\^L"
683 "*Regexp describing what to use as article page delimiters.
684 The default value is \"^\^L\", which is a form linefeed at the
685 beginning of a line."
687 :group 'gnus-article-various)
689 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
690 "*The format specification for the article mode line.
691 See `gnus-summary-mode-line-format' for a closer description.
693 The following additional specs are available:
695 %w The article washing status.
696 %m The number of MIME parts in the article."
699 :group 'gnus-article-various)
701 (defcustom gnus-article-mode-hook nil
702 "*A hook for Gnus article mode."
704 :group 'gnus-article-various)
706 (when (featurep 'xemacs)
707 ;; Extracted from gnus-xmas-define in order to preserve user settings
708 (when (fboundp 'turn-off-scroll-in-place)
709 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
710 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
711 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
713 (defcustom gnus-article-menu-hook nil
714 "*Hook run after the creation of the article mode menu."
716 :group 'gnus-article-various)
718 (defcustom gnus-article-prepare-hook nil
719 "*A hook called after an article has been prepared in the article buffer."
721 :group 'gnus-article-various)
723 (defcustom gnus-copy-article-ignored-headers nil
724 "List of headers to be removed when copying an article.
725 Each element is a regular expression."
726 :version "23.1" ;; No Gnus
727 :type '(repeat regexp)
728 :group 'gnus-article-various)
730 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
731 "Gnus 5.10 (Emacs 22.1)")
734 '((t (:weight bold)))
735 "Face used for highlighting a button in the article buffer."
736 :group 'gnus-article-buttons)
738 (defcustom gnus-article-button-face 'gnus-button
739 "Face used for highlighting buttons in the article buffer.
741 An article button is a piece of text that you can activate by pressing
742 `RET' or `mouse-2' above it."
744 :group 'gnus-article-buttons)
746 (defcustom gnus-article-mouse-face 'highlight
747 "Face used for mouse highlighting in the article buffer.
749 Article buttons will be displayed in this face when the cursor is
752 :group 'gnus-article-buttons)
754 (defcustom gnus-signature-face 'gnus-signature
755 "Face used for highlighting a signature in the article buffer.
756 Obsolete; use the face `gnus-signature' for customizations instead."
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
761 (defface gnus-signature
764 "Face used for highlighting a signature in the article buffer."
765 :group 'gnus-article-highlight
766 :group 'gnus-article-signature)
767 ;; backward-compatibility alias
768 (put 'gnus-signature-face 'face-alias 'gnus-signature)
769 (put 'gnus-signature-face 'obsolete-face "22.1")
771 (defface gnus-header-from
774 (:foreground "PaleGreen1"))
777 (:foreground "red3"))
780 "Face used for displaying from headers."
781 :group 'gnus-article-headers
782 :group 'gnus-article-highlight)
783 ;; backward-compatibility alias
784 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
785 (put 'gnus-header-from-face 'obsolete-face "22.1")
787 (defface gnus-header-subject
790 (:foreground "SeaGreen1"))
793 (:foreground "red4"))
795 (:bold t :italic t)))
796 "Face used for displaying subject headers."
797 :group 'gnus-article-headers
798 :group 'gnus-article-highlight)
799 ;; backward-compatibility alias
800 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
801 (put 'gnus-header-subject-face 'obsolete-face "22.1")
803 (defface gnus-header-newsgroups
806 (:foreground "yellow" :italic t))
809 (:foreground "MidnightBlue" :italic t))
812 "Face used for displaying newsgroups headers.
813 In the default setup this face is only used for crossposted
815 :group 'gnus-article-headers
816 :group 'gnus-article-highlight)
817 ;; backward-compatibility alias
818 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
819 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
821 (defface gnus-header-name
824 (:foreground "SpringGreen2"))
827 (:foreground "maroon"))
830 "Face used for displaying header names."
831 :group 'gnus-article-headers
832 :group 'gnus-article-highlight)
833 ;; backward-compatibility alias
834 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
835 (put 'gnus-header-name-face 'obsolete-face "22.1")
837 (defface gnus-header-content
840 (:foreground "SpringGreen1" :italic t))
843 (:foreground "indianred4" :italic t))
845 (:italic t))) "Face used for displaying header content."
846 :group 'gnus-article-headers
847 :group 'gnus-article-highlight)
848 ;; backward-compatibility alias
849 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
850 (put 'gnus-header-content-face 'obsolete-face "22.1")
852 (defcustom gnus-header-face-alist
853 '(("From" nil gnus-header-from)
854 ("Subject" nil gnus-header-subject)
855 ("Newsgroups:.*," nil gnus-header-newsgroups)
856 ("" gnus-header-name gnus-header-content))
857 "*Controls highlighting of article headers.
859 An alist of the form (HEADER NAME CONTENT).
861 HEADER is a regular expression which should match the name of a
862 header and NAME and CONTENT are either face names or nil.
864 The name of each header field will be displayed using the face
865 specified by the first element in the list where HEADER matches
866 the header name and NAME is non-nil. Similarly, the content will
867 be displayed by the first non-nil matching CONTENT face."
868 :group 'gnus-article-headers
869 :group 'gnus-article-highlight
870 :type '(repeat (list (regexp :tag "Header")
872 (item :tag "skip" nil)
873 (face :value default))
874 (choice :tag "Content"
875 (item :tag "skip" nil)
876 (face :value default)))))
878 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
879 '((xface . (:face gnus-x-face)))
880 '((pbm . (:face gnus-x-face))
882 "Alist of image types and properties applied to Face and X-Face images.
885 ;; Specify the altitude of Face images in the From header.
886 \(setq gnus-face-properties-alist
887 '((pbm . (:face gnus-x-face :ascent 80))
888 (png . (:ascent 80))))
890 ;; Show Face images as pressed buttons.
891 \(setq gnus-face-properties-alist
892 '((pbm . (:face gnus-x-face :relief -2))
893 (png . (:relief -2))))
895 See the manual for the valid properties for various image types.
896 Currently, `pbm' is used for X-Face images and `png' is used for Face
897 images in Emacs. Only the `:face' property is effective on the `xface'
898 image type in XEmacs if it is built with the libcompface library."
899 :version "23.1" ;; No Gnus
900 :group 'gnus-article-headers
901 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
903 (defcustom gnus-article-decode-hook
904 '(article-decode-charset article-decode-encoded-words
905 article-decode-group-name article-decode-idna-rhs)
906 "*Hook run to decode charsets in articles."
907 :group 'gnus-article-headers
910 (defcustom gnus-display-mime-function 'gnus-display-mime
911 "Function to display MIME articles."
912 :group 'gnus-article-mime
915 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
916 "Function used to decode headers.")
918 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
919 "Function used to decode addresses.")
921 (defvar gnus-article-dumbquotes-map
941 "Table for MS-to-Latin1 translation.")
943 (defcustom gnus-ignored-mime-types nil
944 "List of MIME types that should be ignored by Gnus."
946 :group 'gnus-article-mime
947 :type '(repeat regexp))
949 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
950 "List of MIME types that should not be given buttons when rendered inline.
951 See also `gnus-buttonized-mime-types' which may override this variable.
952 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
954 :group 'gnus-article-mime
955 :type '(repeat regexp))
957 (defcustom gnus-buttonized-mime-types nil
958 "List of MIME types that should be given buttons when rendered inline.
959 If set, this variable overrides `gnus-unbuttonized-mime-types'.
960 To see e.g. security buttons you could set this to
961 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
962 this list to display radio buttons that allow you to choose one of two
963 media types those mails include. See also `mm-discouraged-alternatives'.
964 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
966 :group 'gnus-article-mime
967 :type '(repeat regexp))
969 (defcustom gnus-inhibit-mime-unbuttonizing nil
970 "If non-nil, all MIME parts get buttons.
971 When nil (the default value), then some MIME parts do not get buttons,
972 as described by the variables `gnus-buttonized-mime-types' and
973 `gnus-unbuttonized-mime-types'."
975 :group 'gnus-article-mime
978 (defcustom gnus-body-boundary-delimiter "_"
979 "String used to delimit header and body.
980 This variable is used by `gnus-article-treat-body-boundary' which can
981 be controlled by `gnus-treat-body-boundary'."
983 :group 'gnus-article-various
984 :type '(choice (item :tag "None" :value nil)
987 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
989 "Defines the location of the faces database.
990 For information on obtaining this database of pretty pictures, please
991 see http://www.cs.indiana.edu/picons/ftp/index.html"
993 :type '(repeat directory)
994 :link '(url-link :tag "download"
995 "http://www.cs.indiana.edu/picons/ftp/index.html")
996 :link '(custom-manual "(gnus)Picons")
999 (defun gnus-picons-installed-p ()
1000 "Say whether picons are installed on your machine."
1001 (let ((installed nil))
1002 (dolist (database gnus-picon-databases)
1003 (when (file-exists-p database)
1004 (setq installed t)))
1007 (defcustom gnus-article-mime-part-function nil
1008 "Function called with a MIME handle as the argument.
1009 This is meant for people who want to do something automatic based
1010 on parts -- for instance, adding Vcard info to a database."
1011 :group 'gnus-article-mime
1012 :type '(choice (const nil)
1015 (defcustom gnus-mime-multipart-functions nil
1016 "An alist of MIME types to functions to display them."
1018 :group 'gnus-article-mime
1019 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1021 (defcustom gnus-article-date-headers '(combined-lapsed)
1022 "A list of Date header formats to display.
1023 Valid formats are `ut' (universal time), `local' (local time
1024 zone), `english' (readable English), `lapsed' (elapsed time),
1025 `combined-lapsed' (both the original date and the elapsed time),
1026 `original' (the original date header), `iso8601' (ISO8601
1027 format), and `user-defined' (a user-defined format defined by the
1028 `gnus-article-time-format' variable).
1030 You have as many date headers as you want in the article buffer.
1031 Some of these headers are updated automatically. See
1032 `gnus-article-update-date-headers' for details."
1034 :group 'gnus-article-headers
1036 (item :tag "Universal time (UT)" :value 'ut)
1037 (item :tag "Local time zone" :value 'local)
1038 (item :tag "Readable English" :value 'english)
1039 (item :tag "Elapsed time" :value 'lapsed)
1040 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1041 (item :tag "Original date header" :value 'original)
1042 (item :tag "ISO8601 format" :value 'iso8601)
1043 (item :tag "User-defined" :value 'user-defined)))
1045 (defcustom gnus-article-update-date-headers nil
1046 "A number that says how often to update the date header (in seconds).
1047 If nil, don't update it at all."
1049 :group 'gnus-article-headers
1051 (item :tag "Don't update" :value nil)
1054 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1055 "Function called with a MIME handle as the argument.
1056 This is meant for people who want to view first matched part.
1057 For `undisplayed-alternative' (default), the first undisplayed
1058 part or alternative part is used. For `undisplayed', the first
1059 undisplayed part is used. For a function, the first part which
1060 the function return t is used. For nil, the first part is
1063 :group 'gnus-article-mime
1065 (item :tag "first" :value nil)
1066 (item :tag "undisplayed" :value undisplayed)
1067 (item :tag "undisplayed or alternative"
1068 :value undisplayed-alternative)
1071 (defcustom gnus-mime-action-alist
1072 '(("save to file" . gnus-mime-save-part)
1073 ("save and strip" . gnus-mime-save-part-and-strip)
1074 ("replace with file" . gnus-mime-replace-part)
1075 ("delete part" . gnus-mime-delete-part)
1076 ("display as text" . gnus-mime-inline-part)
1077 ("view the part" . gnus-mime-view-part)
1078 ("pipe to command" . gnus-mime-pipe-part)
1079 ("toggle display" . gnus-article-press-button)
1080 ("toggle display" . gnus-article-view-part-as-charset)
1081 ("view as type" . gnus-mime-view-part-as-type)
1082 ("view internally" . gnus-mime-view-part-internally)
1083 ("view externally" . gnus-mime-view-part-externally))
1084 "An alist of actions that run on the MIME attachment."
1085 :group 'gnus-article-mime
1086 :type '(repeat (cons (string :tag "name")
1089 (defcustom gnus-auto-select-part 1
1090 "Advance to next MIME part when deleting or stripping parts.
1092 When 0, point will be placed on the same part as before. When
1093 positive (negative), move point forward (backwards) this many
1094 parts. When nil, redisplay article."
1095 :version "23.1" ;; No Gnus
1096 :group 'gnus-article-mime
1097 :type '(choice (const nil :tag "Redisplay article.")
1098 (const 1 :tag "Next part.")
1099 (const 0 :tag "Current part.")
1103 ;;; The treatment variables
1106 (defvar gnus-part-display-hook nil
1107 "Hook called on parts that are to receive treatment.")
1109 (defvar gnus-article-treat-custom
1110 '(choice (const :tag "Off" nil)
1112 (const :tag "Header" head)
1113 (const :tag "First" first)
1114 (const :tag "Last" last)
1115 (integer :tag "Less")
1116 (repeat :tag "Groups" regexp)
1117 (sexp :tag "Predicate")))
1119 (defvar gnus-article-treat-head-custom
1120 '(choice (const :tag "Off" nil)
1121 (const :tag "Header" head)))
1123 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1127 (defvar gnus-inhibit-treatment nil
1128 "Whether to inhibit treatment.")
1130 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1131 "Highlight the signature.
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate. See Info node `(gnus)Customizing Articles'."
1134 :group 'gnus-article-treat
1135 :link '(custom-manual "(gnus)Customizing Articles")
1136 :type gnus-article-treat-custom)
1137 (put 'gnus-treat-highlight-signature 'highlight t)
1139 (defcustom gnus-treat-buttonize 100000
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1143 :group 'gnus-article-treat
1144 :link '(custom-manual "(gnus)Customizing Articles")
1145 :type gnus-article-treat-custom)
1146 (put 'gnus-treat-buttonize 'highlight t)
1148 (defcustom gnus-treat-buttonize-head 'head
1149 "Add buttons to the head.
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate. See Info node `(gnus)Customizing Articles'."
1152 :group 'gnus-article-treat
1153 :link '(custom-manual "(gnus)Customizing Articles")
1154 :type gnus-article-treat-head-custom)
1155 (put 'gnus-treat-buttonize-head 'highlight t)
1157 (defcustom gnus-treat-date 'head
1158 "Display dates according to the `gnus-article-date-headers' variable.
1159 Valid values are nil, t, `head', `first', `last', an integer or a
1160 predicate. See Info node `(gnus)Customizing Articles'."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-emphasize 50000
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-custom)
1173 (put 'gnus-treat-emphasize 'highlight t)
1175 (defcustom gnus-treat-strip-cr nil
1176 "Remove carriage returns.
1177 Valid values are nil, t, `head', `first', `last', an integer or a
1178 predicate. See Info node `(gnus)Customizing Articles'."
1180 :group 'gnus-article-treat
1181 :link '(custom-manual "(gnus)Customizing Articles")
1182 :type gnus-article-treat-custom)
1184 (defcustom gnus-treat-unsplit-urls nil
1185 "Remove newlines from within URLs.
1186 Valid values are nil, t, `head', `first', `last', an integer or a
1187 predicate. See Info node `(gnus)Customizing Articles'."
1189 :group 'gnus-article-treat
1190 :link '(custom-manual "(gnus)Customizing Articles")
1191 :type gnus-article-treat-custom)
1193 (defcustom gnus-treat-leading-whitespace nil
1194 "Remove leading whitespace in headers.
1195 Valid values are nil, t, `head', `first', `last', an integer or a
1196 predicate. See Info node `(gnus)Customizing Articles'."
1198 :group 'gnus-article-treat
1199 :link '(custom-manual "(gnus)Customizing Articles")
1200 :type gnus-article-treat-custom)
1202 (defcustom gnus-treat-hide-headers 'head
1204 Valid values are nil, t, `head', `first', `last', an integer or a
1205 predicate. See Info node `(gnus)Customizing Articles'."
1206 :group 'gnus-article-treat
1207 :link '(custom-manual "(gnus)Customizing Articles")
1208 :type gnus-article-treat-head-custom)
1210 (defcustom gnus-treat-hide-boring-headers nil
1211 "Hide boring headers.
1212 Valid values are nil, t, `head', `first', `last', an integer or a
1213 predicate. See Info node `(gnus)Customizing Articles'."
1214 :group 'gnus-article-treat
1215 :link '(custom-manual "(gnus)Customizing Articles")
1216 :type gnus-article-treat-head-custom)
1218 (defcustom gnus-treat-hide-signature nil
1219 "Hide the signature.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-fill-article nil
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate. See Info node `(gnus)Customizing Articles'."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1234 (defcustom gnus-treat-hide-citation nil
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'.
1239 See `gnus-article-highlight-citation' for variables used to
1240 control what it hides."
1241 :group 'gnus-article-treat
1242 :link '(custom-manual "(gnus)Customizing Articles")
1243 :type gnus-article-treat-custom)
1245 (defcustom gnus-treat-hide-citation-maybe nil
1246 "Hide cited text according to certain conditions.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'.
1250 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1251 how to control what it hides."
1252 :group 'gnus-article-treat
1253 :link '(custom-manual "(gnus)Customizing Articles")
1254 :type gnus-article-treat-custom)
1256 (defcustom gnus-treat-strip-list-identifiers 'head
1257 "Strip list identifiers from `gnus-list-identifiers`.
1258 Valid values are nil, t, `head', `first', `last', an integer or a
1259 predicate. See Info node `(gnus)Customizing Articles'."
1261 :group 'gnus-article-treat
1262 :link '(custom-manual "(gnus)Customizing Articles")
1263 :type gnus-article-treat-custom)
1265 (gnus-define-group-parameter
1268 "Alist of regexps and correspondent identifiers."
1269 :variable-group gnus-article-washing
1271 '(choice :tag "Identifier"
1273 (symbol :tag "Item in `gnus-list-identifiers'" none)
1275 (const :tag "None" nil))
1277 "If non-nil, specify how to remove `identifiers' from articles' subject.
1279 Any symbol is used to look up a regular expression to match the
1280 banner in `gnus-list-identifiers'. A string is used as a regular
1281 expression to match the identifier directly.")
1283 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1284 "Gnus 5.10 (Emacs 22.1)")
1286 (defcustom gnus-treat-strip-pem nil
1287 "Strip PEM signatures.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-custom)
1294 (defcustom gnus-treat-strip-banner t
1295 "Strip banners from articles.
1296 The banner to be stripped is specified in the `banner' group parameter.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-custom)
1303 (defcustom gnus-treat-highlight-headers 'head
1304 "Highlight the headers.
1305 Valid values are nil, t, `head', `first', `last', an integer or a
1306 predicate. See Info node `(gnus)Customizing Articles'."
1307 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :type gnus-article-treat-head-custom)
1310 (put 'gnus-treat-highlight-headers 'highlight t)
1312 (defcustom gnus-treat-highlight-citation t
1313 "Highlight cited text.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1316 :group 'gnus-article-treat
1317 :link '(custom-manual "(gnus)Customizing Articles")
1318 :type gnus-article-treat-custom)
1319 (put 'gnus-treat-highlight-citation 'highlight t)
1321 (defcustom gnus-treat-strip-headers-in-body t
1322 "Strip the X-No-Archive header line from the beginning of the body.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'."
1326 :group 'gnus-article-treat
1327 :link '(custom-manual "(gnus)Customizing Articles")
1328 :type gnus-article-treat-custom)
1330 (defcustom gnus-treat-strip-trailing-blank-lines nil
1331 "Strip trailing blank lines.
1332 Valid values are nil, t, `head', `first', `last', an integer or a
1333 predicate. See Info node `(gnus)Customizing Articles'.
1335 When set to t, it also strips trailing blanks in all MIME parts.
1336 Consider to use `last' instead."
1337 :group 'gnus-article-treat
1338 :link '(custom-manual "(gnus)Customizing Articles")
1339 :type gnus-article-treat-custom)
1341 (defcustom gnus-treat-strip-leading-blank-lines nil
1342 "Strip leading blank lines.
1343 Valid values are nil, t, `head', `first', `last', an integer or a
1344 predicate. See Info node `(gnus)Customizing Articles'.
1346 When set to t, it also strips trailing blanks in all MIME parts."
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1351 (defcustom gnus-treat-strip-multiple-blank-lines nil
1352 "Strip multiple blank lines.
1353 Valid values are nil, t, `head', `first', `last', an integer or a
1354 predicate. See Info node `(gnus)Customizing Articles'."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1359 (defcustom gnus-treat-unfold-headers 'head
1360 "Unfold folded header lines.
1361 Valid values are nil, t, `head', `first', `last', an integer or a
1362 predicate. See Info node `(gnus)Customizing Articles'."
1364 :group 'gnus-article-treat
1365 :link '(custom-manual "(gnus)Customizing Articles")
1366 :type gnus-article-treat-custom)
1368 (defcustom gnus-article-unfold-long-headers nil
1369 "If non-nil, allow unfolding headers even if the header is long.
1370 If it is a regexp, only long headers matching this regexp are unfolded.
1371 If it is t, all long headers are unfolded.
1373 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1374 :version "23.1" ;; No Gnus
1375 :group 'gnus-article-treat
1376 :type '(choice (const nil)
1377 (const :tag "all" t)
1380 (defcustom gnus-treat-fold-headers nil
1382 Valid values are nil, t, `head', `first', `last', an integer or a
1383 predicate. See Info node `(gnus)Customizing Articles'."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-fold-newsgroups 'head
1390 "Fold the Newsgroups and Followup-To headers.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1398 (defcustom gnus-treat-overstrike t
1399 "Treat overstrike highlighting.
1400 Valid values are nil, t, `head', `first', `last', an integer or a
1401 predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1405 (put 'gnus-treat-overstrike 'highlight t)
1407 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1408 "Treat ANSI SGR control sequences.
1409 Valid values are nil, t, `head', `first', `last', an integer or a
1410 predicate. See Info node `(gnus)Customizing Articles'."
1411 :group 'gnus-article-treat
1412 :link '(custom-manual "(gnus)Customizing Articles")
1413 :type gnus-article-treat-custom)
1415 (make-obsolete-variable 'gnus-treat-display-xface
1416 'gnus-treat-display-x-face "Emacs 22.1")
1418 (defcustom gnus-treat-display-x-face
1419 (and (not noninteractive)
1420 (gnus-image-type-available-p 'xbm)
1421 (if (featurep 'xemacs)
1424 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1425 (executable-find "icontopbm"))
1426 ;; shell-command-to-string may signal an error, e.g. if
1427 ;; shell-file-name is not found.
1430 "Display X-Face headers.
1431 Valid values are nil and `head'.
1432 See Info node `(gnus)Customizing Articles' and Info node
1433 `(gnus)X-Face' for details."
1434 :group 'gnus-article-treat
1436 :link '(custom-manual "(gnus)Customizing Articles")
1437 :link '(custom-manual "(gnus)X-Face")
1438 :type gnus-article-treat-head-custom
1439 :set (lambda (symbol value)
1442 (cond ((or (boundp symbol) (get symbol 'saved-value))
1444 ((boundp 'gnus-treat-display-xface)
1446 ** gnus-treat-display-xface is an obsolete variable;\
1447 use gnus-treat-display-x-face instead")
1448 (default-value 'gnus-treat-display-xface))
1449 ((get 'gnus-treat-display-xface 'saved-value)
1451 ** gnus-treat-display-xface is an obsolete variable;\
1452 use gnus-treat-display-x-face instead")
1453 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1456 (put 'gnus-treat-display-x-face 'highlight t)
1458 (defcustom gnus-treat-display-face
1459 (and (not noninteractive)
1460 (gnus-image-type-available-p 'png)
1462 "Display Face headers.
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles' and Info
1465 node `(gnus)Face' for details."
1466 :group 'gnus-article-treat
1468 :link '(custom-manual "(gnus)Customizing Articles")
1469 :link '(custom-manual "(gnus)X-Face")
1470 :type gnus-article-treat-head-custom)
1471 (put 'gnus-treat-display-face 'highlight t)
1473 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1475 Valid values are nil, t, `head', `first', `last', an integer or a
1476 predicate. See Info node `(gnus)Customizing Articles' and Info
1477 node `(gnus)Smileys' for details."
1478 :group 'gnus-article-treat
1480 :link '(custom-manual "(gnus)Customizing Articles")
1481 :link '(custom-manual "(gnus)Smileys")
1482 :type gnus-article-treat-custom)
1483 (put 'gnus-treat-display-smileys 'highlight t)
1485 (defcustom gnus-treat-from-picon
1486 (if (and (gnus-image-type-available-p 'xpm)
1487 (gnus-picons-installed-p))
1489 "Display picons in the From header.
1490 Valid values are nil, t, `head', `first', `last', an integer or a
1491 predicate. See Info node `(gnus)Customizing Articles' and Info
1492 node `(gnus)Picons' for details."
1494 :group 'gnus-article-treat
1496 :link '(custom-manual "(gnus)Customizing Articles")
1497 :link '(custom-manual "(gnus)Picons")
1498 :type gnus-article-treat-head-custom)
1499 (put 'gnus-treat-from-picon 'highlight t)
1501 (defcustom gnus-treat-mail-picon
1502 (if (and (gnus-image-type-available-p 'xpm)
1503 (gnus-picons-installed-p))
1505 "Display picons in To and Cc headers.
1506 Valid values are nil, t, `head', `first', `last', an integer or a
1507 predicate. See Info node `(gnus)Customizing Articles' and Info
1508 node `(gnus)Picons' for details."
1510 :group 'gnus-article-treat
1512 :link '(custom-manual "(gnus)Customizing Articles")
1513 :link '(custom-manual "(gnus)Picons")
1514 :type gnus-article-treat-head-custom)
1515 (put 'gnus-treat-mail-picon 'highlight t)
1517 (defcustom gnus-treat-newsgroups-picon
1518 (if (and (gnus-image-type-available-p 'xpm)
1519 (gnus-picons-installed-p))
1521 "Display picons in the Newsgroups and Followup-To headers.
1522 Valid values are nil, t, `head', `first', `last', an integer or a
1523 predicate. See Info node `(gnus)Customizing Articles' and Info
1524 node `(gnus)Picons' for details."
1526 :group 'gnus-article-treat
1528 :link '(custom-manual "(gnus)Customizing Articles")
1529 :link '(custom-manual "(gnus)Picons")
1530 :type gnus-article-treat-head-custom)
1531 (put 'gnus-treat-newsgroups-picon 'highlight t)
1533 (defcustom gnus-treat-from-gravatar nil
1534 "Display gravatars in the From header.
1535 Valid values are nil, t, `head', `first', `last', an integer or a
1536 predicate. See Info node `(gnus)Customizing Articles' and Info
1537 node `(gnus)Gravatars' for details."
1539 :group 'gnus-article-treat
1540 :group 'gnus-gravatar
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :link '(custom-manual "(gnus)Gravatars")
1543 :type gnus-article-treat-head-custom)
1544 (put 'gnus-treat-from-gravatar 'highlight t)
1546 (defcustom gnus-treat-mail-gravatar nil
1547 "Display gravatars in To and Cc headers.
1548 Valid values are nil, t, `head', `first', `last', an integer or a
1549 predicate. See Info node `(gnus)Customizing Articles' and Info
1550 node `(gnus)Gravatars' for details."
1552 :group 'gnus-article-treat
1553 :group 'gnus-gravatar
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :link '(custom-manual "(gnus)Gravatars")
1556 :type gnus-article-treat-head-custom)
1557 (put 'gnus-treat-mail-gravatar 'highlight t)
1559 (defcustom gnus-treat-body-boundary
1560 (if (or gnus-treat-newsgroups-picon
1561 gnus-treat-mail-picon
1562 gnus-treat-from-picon
1563 gnus-treat-from-gravatar
1564 gnus-treat-mail-gravatar)
1565 ;; If there's much decoration, the user might prefer a boundary.
1568 "Draw a boundary at the end of the headers.
1569 Valid values are nil and `head'.
1570 See Info node `(gnus)Customizing Articles' for details."
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-head-custom)
1576 (defcustom gnus-treat-capitalize-sentences nil
1577 "Capitalize sentence-starting words.
1578 Valid values are nil, t, `head', `first', `last', an integer or a
1579 predicate. See Info node `(gnus)Customizing Articles'."
1581 :group 'gnus-article-treat
1582 :link '(custom-manual "(gnus)Customizing Articles")
1583 :type gnus-article-treat-custom)
1585 (defcustom gnus-treat-wash-html nil
1587 Valid values are nil, t, `head', `first', `last', an integer or a
1588 predicate. See Info node `(gnus)Customizing Articles'."
1590 :group 'gnus-article-treat
1591 :link '(custom-manual "(gnus)Customizing Articles")
1592 :type gnus-article-treat-custom)
1594 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1596 Valid values are nil, t, `head', `first', `last', an integer or a
1597 predicate. See Info node `(gnus)Customizing Articles'."
1599 :group 'gnus-article-treat
1600 :link '(custom-manual "(gnus)Customizing Articles")
1601 :type gnus-article-treat-custom)
1603 (defcustom gnus-treat-x-pgp-sig nil
1605 To automatically treat X-PGP-Sig, set it to head.
1606 Valid values are nil, t, `head', `first', `last', an integer or a
1607 predicate. See Info node `(gnus)Customizing Articles'."
1609 :group 'gnus-article-treat
1610 :group 'mime-security
1611 :link '(custom-manual "(gnus)Customizing Articles")
1612 :type gnus-article-treat-custom)
1614 (defvar gnus-article-encrypt-protocol-alist
1615 '(("PGP" . mml2015-self-encrypt)))
1617 ;; Set to nil if more than one protocol added to
1618 ;; gnus-article-encrypt-protocol-alist.
1619 (defcustom gnus-article-encrypt-protocol "PGP"
1620 "The protocol used for encrypt articles.
1621 It is a string, such as \"PGP\". If nil, ask user."
1624 :group 'mime-security)
1626 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1627 (mm-coding-system-p 'utf-8)
1628 (executable-find idna-program))
1629 "Whether IDNA decoding of headers is used when viewing messages.
1630 This requires GNU Libidn, and by default only enabled if it is found."
1632 :group 'gnus-article-headers
1635 (defcustom gnus-article-over-scroll nil
1636 "If non-nil, allow scrolling the article buffer even when there no more text."
1638 :group 'gnus-article
1641 (defcustom gnus-inhibit-images nil
1642 "Non-nil means inhibit displaying of images inline in the article body."
1644 :group 'gnus-article
1647 (defcustom gnus-blocked-images 'gnus-block-private-groups
1648 "Images that have URLs matching this regexp will be blocked.
1649 This can also be a function to be evaluated. If so, it will be
1650 called with the group name as the parameter, and should return a
1656 ;;; Internal variables
1658 (defvar gnus-english-month-names
1659 '("January" "February" "March" "April" "May" "June" "July" "August"
1660 "September" "October" "November" "December"))
1662 (defvar article-goto-body-goes-to-point-min-p nil)
1663 (defvar gnus-article-wash-types nil)
1664 (defvar gnus-article-emphasis-alist nil)
1665 (defvar gnus-article-image-alist nil)
1667 (defvar gnus-article-mime-handle-alist-1 nil)
1668 (defvar gnus-treatment-function-alist
1669 '((gnus-treat-strip-cr gnus-article-remove-cr)
1670 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1671 (gnus-treat-strip-banner gnus-article-strip-banner)
1672 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1673 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1674 (gnus-treat-buttonize gnus-article-add-buttons)
1675 (gnus-treat-fill-article gnus-article-fill-cited-article)
1676 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1677 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1678 (gnus-treat-display-x-face gnus-article-display-x-face)
1679 (gnus-treat-display-face gnus-article-display-face)
1680 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1681 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1682 (gnus-treat-hide-signature gnus-article-hide-signature)
1683 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1684 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1685 (gnus-treat-from-picon gnus-treat-from-picon)
1686 (gnus-treat-mail-picon gnus-treat-mail-picon)
1687 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1688 (gnus-treat-strip-pem gnus-article-hide-pem)
1689 (gnus-treat-date gnus-article-treat-date)
1690 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1691 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1692 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1693 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1694 (gnus-treat-strip-trailing-blank-lines
1695 gnus-article-remove-trailing-blank-lines)
1696 (gnus-treat-strip-leading-blank-lines
1697 gnus-article-strip-leading-blank-lines)
1698 (gnus-treat-strip-multiple-blank-lines
1699 gnus-article-strip-multiple-blank-lines)
1700 (gnus-treat-overstrike gnus-article-treat-overstrike)
1701 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1702 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1703 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1704 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1705 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1706 (gnus-treat-display-smileys gnus-treat-smiley)
1707 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1708 (gnus-treat-wash-html gnus-article-wash-html)
1709 (gnus-treat-emphasize gnus-article-emphasize)
1710 (gnus-treat-hide-citation gnus-article-hide-citation)
1711 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1712 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1713 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1715 (defvar gnus-article-mime-handle-alist nil)
1716 (defvar article-lapsed-timer nil)
1717 (defvar gnus-article-current-summary nil)
1719 (defvar gnus-article-mode-syntax-table
1720 (let ((table (copy-syntax-table text-mode-syntax-table)))
1721 ;; This causes the citation match run O(2^n).
1722 ;; (modify-syntax-entry ?- "w" table)
1723 (modify-syntax-entry ?> ")<" table)
1724 (modify-syntax-entry ?< "(>" table)
1725 ;; make M-. in article buffers work for `foo' strings
1726 (modify-syntax-entry ?' " " table)
1727 (modify-syntax-entry ?` " " table)
1729 "Syntax table used in article mode buffers.
1730 Initialized from `text-mode-syntax-table.")
1732 (defvar gnus-save-article-buffer nil)
1734 (defvar gnus-number-of-articles-to-be-saved nil)
1736 (defvar gnus-inhibit-hiding nil)
1738 (defvar gnus-article-edit-mode nil)
1740 ;;; Macros for dealing with the article buffer.
1742 (defmacro gnus-with-article-headers (&rest forms)
1743 `(with-current-buffer gnus-article-buffer
1745 (let ((inhibit-read-only t)
1746 (inhibit-point-motion-hooks t)
1747 (case-fold-search t))
1748 (article-narrow-to-head)
1751 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1752 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1754 (defmacro gnus-with-article-buffer (&rest forms)
1755 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1756 (with-current-buffer gnus-article-buffer
1757 (let ((inhibit-read-only t))
1760 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1761 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1763 (defun gnus-article-goto-header (header)
1764 "Go to HEADER, which is a regular expression."
1765 (re-search-forward (concat "^\\(" header "\\):") nil t))
1767 (defsubst gnus-article-hide-text (b e props)
1768 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1769 (gnus-add-text-properties-when 'article-type nil b e props)
1770 (when (memq 'intangible props)
1772 (max (1- b) (point-min))
1773 b 'intangible (cddr (memq 'intangible props)))))
1775 (defsubst gnus-article-unhide-text (b e)
1776 "Remove hidden text properties from region between B and E."
1777 (remove-text-properties b e gnus-hidden-properties)
1778 (when (memq 'intangible gnus-hidden-properties)
1779 (put-text-property (max (1- b) (point-min))
1780 b 'intangible nil)))
1782 (defun gnus-article-hide-text-type (b e type)
1783 "Hide text of TYPE between B and E."
1784 (gnus-add-wash-type type)
1785 (gnus-article-hide-text
1786 b e (cons 'article-type (cons type gnus-hidden-properties))))
1788 (defun gnus-article-unhide-text-type (b e type)
1789 "Unhide text of TYPE between B and E."
1790 (gnus-delete-wash-type type)
1791 (remove-text-properties
1792 b e (cons 'article-type (cons type gnus-hidden-properties)))
1793 (when (memq 'intangible gnus-hidden-properties)
1794 (put-text-property (max (1- b) (point-min))
1795 b 'intangible nil)))
1797 (defun gnus-article-hide-text-of-type (type)
1798 "Hide text of TYPE in the current buffer."
1800 (let ((b (point-min))
1802 (while (setq b (text-property-any b e 'article-type type))
1803 (add-text-properties b (incf b) gnus-hidden-properties)))))
1805 (defun gnus-article-delete-text-of-type (type)
1806 "Delete text of TYPE in the current buffer."
1808 (let ((b (point-min)))
1809 (if (eq type 'multipart)
1810 ;; Remove MIME buttons associated with multipart/alternative parts.
1813 (while (if (get-text-property (point) 'gnus-part)
1815 (when (setq b (next-single-property-change (point)
1820 (skip-chars-forward "\n")
1821 (when (eq (get-text-property b 'article-type) 'multipart)
1822 (delete-region b (point)))))
1823 (while (setq b (text-property-any b (point-max) 'article-type type))
1825 b (or (text-property-not-all b (point-max) 'article-type type)
1828 (defun gnus-article-delete-invisible-text ()
1829 "Delete all invisible text in the current buffer."
1831 (let ((b (point-min)))
1832 (while (setq b (text-property-any b (point-max) 'invisible t))
1834 b (or (text-property-not-all b (point-max) 'invisible t)
1837 (defun gnus-article-text-type-exists-p (type)
1838 "Say whether any text of type TYPE exists in the buffer."
1839 (text-property-any (point-min) (point-max) 'article-type type))
1841 (defsubst gnus-article-header-rank ()
1842 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1843 (let ((list gnus-sorted-header-list)
1846 (if (looking-at (car list))
1848 (setq list (cdr list))
1852 (defun article-hide-headers (&optional arg delete)
1853 "Hide unwanted headers and possibly sort them as well."
1855 ;; This function might be inhibited.
1856 (unless gnus-inhibit-hiding
1857 (let ((inhibit-read-only t)
1858 (case-fold-search t)
1859 (max (1+ (length gnus-sorted-header-list)))
1860 (inhibit-point-motion-hooks t)
1861 (cur (current-buffer))
1862 ignored visible beg)
1864 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1865 ;; group parameters, so we should go to the summary buffer.
1868 (progn (set-buffer gnus-summary-buffer) t)
1870 (setq ignored (when (not gnus-visible-headers)
1871 (cond ((stringp gnus-ignored-headers)
1872 gnus-ignored-headers)
1873 ((listp gnus-ignored-headers)
1874 (mapconcat 'identity
1875 gnus-ignored-headers
1877 visible (cond ((stringp gnus-visible-headers)
1878 gnus-visible-headers)
1879 ((and gnus-visible-headers
1880 (listp gnus-visible-headers))
1881 (mapconcat 'identity
1882 gnus-visible-headers
1886 ;; First we narrow to just the headers.
1887 (article-narrow-to-head)
1888 ;; Hide any "From " lines at the beginning of (mail) articles.
1889 (while (looking-at "From ")
1892 (delete-region (point-min) (point)))
1893 ;; Then treat the rest of the header lines.
1894 ;; Then we use the two regular expressions
1895 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1896 ;; select which header lines is to remain visible in the
1898 (while (re-search-forward "^[^ \t:]*:" nil t)
1900 ;; Mark the rank of the header.
1902 (point) (1+ (point)) 'message-rank
1903 (if (or (and visible (looking-at visible))
1905 (not (looking-at ignored))))
1906 (gnus-article-header-rank)
1909 (message-sort-headers-1)
1910 (when (setq beg (text-property-any
1911 (point-min) (point-max) 'message-rank (+ 2 max)))
1912 ;; We delete the unwanted headers.
1913 (gnus-add-wash-type 'headers)
1914 (add-text-properties (point-min) (+ 5 (point-min))
1915 '(article-type headers dummy-invisible t))
1916 (delete-region beg (point-max))))))))
1918 (defun article-hide-boring-headers (&optional arg)
1919 "Toggle hiding of headers that aren't very interesting.
1920 If given a negative prefix, always show; if given a positive prefix,
1922 (interactive (gnus-article-hidden-arg))
1923 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1924 (not gnus-show-all-headers))
1927 (let ((inhibit-read-only t)
1928 (inhibit-point-motion-hooks t))
1929 (article-narrow-to-head)
1930 (dolist (elem gnus-boring-article-headers)
1931 (goto-char (point-min))
1933 ;; Hide empty headers.
1935 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1937 (gnus-article-hide-text-type
1941 (if (re-search-forward "^[^ \t]" nil t)
1945 ;; Hide boring Newsgroups header.
1946 ((eq elem 'newsgroups)
1947 (when (gnus-string-equal
1948 (gnus-fetch-field "newsgroups")
1949 (gnus-group-real-name
1950 (if (boundp 'gnus-newsgroup-name)
1953 (gnus-article-hide-header "newsgroups")))
1954 ((eq elem 'to-address)
1955 (let ((to (message-fetch-field "to"))
1957 (gnus-parameter-to-address
1958 (if (boundp 'gnus-newsgroup-name)
1959 gnus-newsgroup-name ""))))
1960 (when (and to to-address
1963 ;; only one address in To
1964 (nth 1 (mail-extract-address-components to))
1966 (gnus-article-hide-header "to"))))
1968 (let ((to (message-fetch-field "to"))
1970 (gnus-parameter-to-list
1971 (if (boundp 'gnus-newsgroup-name)
1972 gnus-newsgroup-name ""))))
1973 (when (and to to-list
1976 ;; only one address in To
1977 (nth 1 (mail-extract-address-components to))
1979 (gnus-article-hide-header "to"))))
1981 (let ((cc (message-fetch-field "cc"))
1983 (gnus-parameter-to-list
1984 (if (boundp 'gnus-newsgroup-name)
1985 gnus-newsgroup-name ""))))
1986 (when (and cc to-list
1989 ;; only one address in CC
1990 (nth 1 (mail-extract-address-components cc))
1992 (gnus-article-hide-header "cc"))))
1993 ((eq elem 'followup-to)
1994 (when (gnus-string-equal
1995 (message-fetch-field "followup-to")
1996 (message-fetch-field "newsgroups"))
1997 (gnus-article-hide-header "followup-to")))
1998 ((eq elem 'reply-to)
1999 (if (gnus-group-find-parameter
2000 gnus-newsgroup-name 'broken-reply-to)
2001 (gnus-article-hide-header "reply-to")
2002 (let ((from (message-fetch-field "from"))
2003 (reply-to (message-fetch-field "reply-to")))
2010 (lambda (x) (downcase (cadr x)))
2011 (mail-extract-address-components from t))
2014 (lambda (x) (downcase (cadr x)))
2015 (mail-extract-address-components reply-to t))
2017 (gnus-article-hide-header "reply-to")))))
2019 (let ((date (with-current-buffer gnus-original-article-buffer
2020 ;; If date in `gnus-article-buffer' is localized
2021 ;; (`gnus-treat-date-user-defined'),
2022 ;; `days-between' might fail.
2023 (message-fetch-field "date"))))
2025 (< (days-between (current-time-string) date)
2027 (gnus-article-hide-header "date"))))
2029 (let ((to (message-fetch-field "to"))
2030 (cc (message-fetch-field "cc")))
2031 (when (> (length to) 1024)
2032 (gnus-article-hide-header "to"))
2033 (when (> (length cc) 1024)
2034 (gnus-article-hide-header "cc"))))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^to:" nil t)
2040 (setq to-count (1+ to-count)))
2041 (when (> to-count 1)
2042 (while (> to-count 0)
2043 (goto-char (point-min))
2045 (re-search-forward "^to:" nil nil to-count)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "to"))
2049 (setq to-count (1- to-count))))
2050 (goto-char (point-min))
2051 (while (re-search-forward "^cc:" nil t)
2052 (setq cc-count (1+ cc-count)))
2053 (when (> cc-count 1)
2054 (while (> cc-count 0)
2055 (goto-char (point-min))
2057 (re-search-forward "^cc:" nil nil cc-count)
2059 (narrow-to-region (point) (point-max))
2060 (gnus-article-hide-header "cc"))
2061 (setq cc-count (1- cc-count)))))))))))))
2063 (defun gnus-article-hide-header (header)
2065 (goto-char (point-min))
2066 (when (re-search-forward (concat "^" header ":") nil t)
2067 (gnus-article-hide-text-type
2071 (if (re-search-forward "^[^ \t]" nil t)
2076 (defvar gnus-article-normalized-header-length 40
2077 "Length of normalized headers.")
2079 (defun article-normalize-headers ()
2080 "Make all header lines 40 characters long."
2082 (let ((inhibit-read-only t)
2086 (article-narrow-to-head)
2089 ((< (setq column (- (point-at-eol) (point)))
2090 gnus-article-normalized-header-length)
2092 (insert (make-string
2093 (- gnus-article-normalized-header-length column)
2095 ((> column gnus-article-normalized-header-length)
2096 (gnus-put-text-property
2098 (forward-char gnus-article-normalized-header-length)
2105 (forward-line 1))))))
2107 (defun article-treat-dumbquotes ()
2108 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2109 Note that this function guesses whether a character is a sm*rtq**t* or
2110 not, so it should only be used interactively.
2112 Sm*rtq**t*s are M****s***'s unilateral extension to the
2113 iso-8859-1 character map in an attempt to provide more quoting
2114 characters. If you see something like \\222 or \\264 where
2115 you're expecting some kind of apostrophe or quotation mark, then
2118 (article-translate-strings gnus-article-dumbquotes-map))
2120 (defvar org-entities)
2122 (defun article-treat-non-ascii ()
2123 "Translate many Unicode characters into their ASCII equivalents."
2125 (require 'org-entities)
2126 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2127 (dolist (elem org-entities)
2128 (when (and (listp elem)
2129 (= (length (nth 6 elem)) 1))
2130 (if (featurep 'xemacs)
2131 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2132 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2134 (when (article-goto-body)
2135 (let ((inhibit-read-only t)
2138 (if (not (setq replace (if (featurep 'xemacs)
2139 (get-char-table (following-char) table)
2140 (aref table (following-char)))))
2143 (setq props (text-properties-at (point)))
2145 (add-text-properties (point) (progn (insert replace) (point))
2147 (insert replace)))))))))
2149 (defun article-translate-characters (from to)
2150 "Translate all characters in the body of the article according to FROM and TO.
2151 FROM is a string of characters to translate from; to is a string of
2152 characters to translate to."
2154 (when (article-goto-body)
2155 (let ((inhibit-read-only t)
2156 (x (make-string 225 ?x))
2158 (while (< (incf i) (length x))
2161 (while (< i (length from))
2162 (aset x (aref from i) (aref to i))
2164 (translate-region (point) (point-max) x)))))
2166 (defun article-translate-strings (map)
2167 "Translate all string in the body of the article according to MAP.
2168 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2170 (when (article-goto-body)
2171 (let ((inhibit-read-only t))
2173 (let ((from (car elem))
2177 (while (search-forward from nil t)
2180 (if (eq (following-char) from)
2184 (forward-char 1)))))))))))
2186 (defun article-treat-overstrike ()
2187 "Translate overstrikes into bold text."
2190 (when (article-goto-body)
2191 (let ((inhibit-read-only t))
2192 (while (search-forward "\b" nil t)
2193 (let ((next (char-after))
2194 (previous (char-after (- (point) 2))))
2195 ;; We do the boldification/underlining by hiding the
2196 ;; overstrikes and putting the proper text property
2200 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2201 (put-text-property (point) (1+ (point)) 'face 'bold))
2203 (gnus-article-hide-text-type
2204 (1- (point)) (1+ (point)) 'overstrike)
2206 (- (point) 2) (1- (point)) 'face 'underline))
2208 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2210 (point) (1+ (point)) 'face 'underline)))))))))
2212 (defun article-treat-ansi-sequences ()
2213 "Translate ANSI SGR control sequences into overlays or extents."
2216 (when (article-goto-body)
2217 (let ((inhibit-read-only t))
2218 (ansi-color-apply-on-region (point) (point-max))))))
2220 (defun gnus-article-treat-unfold-headers ()
2221 "Unfold folded message headers.
2222 Only the headers that fit into the current window width will be
2225 (gnus-with-article-headers
2229 (mail-header-narrow-to-field)
2230 (let* ((header (buffer-string))
2232 (or (equal gnus-article-unfold-long-headers t)
2233 (and (stringp gnus-article-unfold-long-headers)
2234 (string-match gnus-article-unfold-long-headers header)))))
2237 (goto-char (point-min))
2238 (while (re-search-forward "\n[\t ]" nil t)
2239 (replace-match " " t t)))
2240 (setq length (- (point-max) (point-min) 1))
2241 (when (or unfoldable
2242 (< length (window-width)))
2243 (while (re-search-forward "\n[\t ]" nil t)
2244 (replace-match " " t t))))
2245 (goto-char (point-max)))))))
2247 (defun gnus-article-treat-fold-headers ()
2248 "Fold message headers."
2250 (gnus-with-article-headers
2253 (mail-header-narrow-to-field)
2254 (mail-header-fold-field)
2255 (goto-char (point-max))))))
2257 (defun gnus-treat-smiley ()
2258 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2260 (gnus-with-article-buffer
2261 (if (memq 'smiley gnus-article-wash-types)
2262 (gnus-delete-images 'smiley)
2264 (let ((images (smiley-region (point) (point-max))))
2266 (gnus-add-wash-type 'smiley)
2267 (dolist (image images)
2268 (gnus-add-image 'smiley image)))))))
2270 (defun gnus-article-remove-images ()
2271 "Remove all images from the article buffer."
2273 (gnus-with-article-buffer
2276 (dolist (elem gnus-article-image-alist)
2277 (gnus-delete-images (car elem))))))
2279 (autoload 'w3m-toggle-inline-images "w3m")
2281 (defun gnus-article-show-images ()
2282 "Show any images that are in the HTML-rendered article buffer.
2283 This only works if the article in question is HTML."
2285 (gnus-with-article-buffer
2288 (if (eq mm-text-html-renderer 'w3m)
2289 (let ((mm-inline-text-html-with-images nil))
2290 (w3m-toggle-inline-images))
2291 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2293 (destructuring-bind (start end function) region
2294 (funcall function (get-text-property start 'image-url)
2297 (defun gnus-article-treat-fold-newsgroups ()
2298 "Unfold folded message headers.
2299 Only the headers that fit into the current window width will be
2302 (gnus-with-article-headers
2303 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2305 (mail-header-narrow-to-field)
2306 (while (re-search-forward ", *" nil t)
2307 (replace-match ", " t t))
2308 (mail-header-fold-field)
2309 (goto-char (point-max))))))
2311 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2312 "Value of `truncate-lines' in Gnus Article buffer.
2313 Valid values are nil, t, `head', `first', `last', an integer or a
2314 predicate. See Info node `(gnus)Customizing Articles'."
2315 :version "23.1" ;; No Gnus
2316 :group 'gnus-article
2317 ;; :link '(custom-manual "(gnus)Customizing Articles")
2320 (defun gnus-article-toggle-truncate-lines (&optional arg)
2321 "Toggle whether to fold or truncate long lines in article the buffer.
2322 If ARG is non-nil and not a number, toggle
2323 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2324 long lines if and only if arg is positive."
2327 ((and (numberp arg) (> arg 0))
2328 (setq gnus-article-truncate-lines t))
2330 (setq gnus-article-truncate-lines nil))
2332 (setq gnus-article-truncate-lines
2333 (not gnus-article-truncate-lines))))
2334 (gnus-with-article-buffer
2336 ((and (numberp arg) (> arg 0))
2337 (setq truncate-lines nil))
2339 (setq truncate-lines t)))
2340 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2341 ;; `toggle-truncate-lines' needs an argument.
2342 (toggle-truncate-lines)))
2344 (defun gnus-article-treat-body-boundary ()
2345 "Place a boundary line at the end of the headers."
2347 (when (and gnus-body-boundary-delimiter
2348 (> (length gnus-body-boundary-delimiter) 0))
2349 (gnus-with-article-headers
2350 (goto-char (point-max))
2351 (let ((start (point)))
2352 (insert "X-Boundary: ")
2353 (gnus-add-text-properties start (point) '(invisible t intangible t))
2354 (insert (let (str (max (window-width)))
2355 (if (featurep 'xemacs)
2356 (setq max (1- max)))
2357 (while (>= max (length str))
2358 (setq str (concat str gnus-body-boundary-delimiter)))
2359 (substring str 0 max))
2361 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2363 (defun article-fill-long-lines ()
2364 "Fill lines that are wider than the window width."
2367 (let ((inhibit-read-only t)
2368 (width (window-width (get-buffer-window (current-buffer)))))
2371 (let ((adaptive-fill-mode nil)) ;Why? -sm
2374 (when (>= (current-column) (min fill-column width))
2375 (narrow-to-region (min (1+ (point)) (point-max))
2377 (let ((goback (point-marker)))
2378 (fill-paragraph nil)
2379 (goto-char (marker-position goback)))
2381 (forward-line 1)))))))
2383 (defun article-capitalize-sentences ()
2384 "Capitalize the first word in each sentence."
2387 (let ((inhibit-read-only t)
2388 (paragraph-start "^[\n\^L]"))
2392 (forward-sentence)))))
2394 (defun article-remove-cr ()
2395 "Remove trailing CRs and then translate remaining CRs into LFs."
2398 (let ((inhibit-read-only t))
2399 (goto-char (point-min))
2400 (while (re-search-forward "\r+$" nil t)
2401 (replace-match "" t t))
2402 (goto-char (point-min))
2403 (while (search-forward "\r" nil t)
2404 (replace-match "\n" t t)))))
2406 (defun article-remove-trailing-blank-lines ()
2407 "Remove all trailing blank lines from the article."
2410 (let ((inhibit-read-only t))
2411 (goto-char (point-max))
2415 (while (and (not (bobp))
2416 (looking-at "^[ \t]*$")
2417 (not (gnus-annotation-in-region-p
2418 (point) (point-at-eol))))
2423 (defvar gnus-face-properties-alist)
2425 (defun article-display-face (&optional force)
2426 "Display any Face headers in the header."
2427 (interactive (list 'force))
2428 (let ((wash-face-p buffer-read-only))
2429 (gnus-with-article-headers
2430 ;; When displaying parts, this function can be called several times on
2431 ;; the same article, without any intended toggle semantic (as typing `W
2432 ;; D d' would have). So face deletion must occur only when we come from
2433 ;; an interactive command, that is when the *Article* buffer is
2435 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2436 (gnus-delete-images 'face)
2437 (let ((from (message-fetch-field "from"))
2439 (save-current-buffer
2440 (when (and wash-face-p
2441 (gnus-buffer-live-p gnus-original-article-buffer)
2442 (not (re-search-forward "^Face:[\t ]*" nil t)))
2443 (set-buffer gnus-original-article-buffer))
2445 (mail-narrow-to-head)
2447 ;; Check whether this face is censored.
2448 (not (and gnus-article-x-face-too-ugly
2450 (setq from (message-fetch-field "from")))
2451 (string-match gnus-article-x-face-too-ugly
2453 (while (gnus-article-goto-header "Face")
2454 (push (mail-header-field-value) faces)))))
2456 (goto-char (point-min))
2458 (unless (setq from (gnus-article-goto-header "from"))
2461 (insert " [no `from' set]\n"))
2463 (when (setq png (gnus-convert-face-to-png (pop faces)))
2465 (apply 'gnus-create-image png 'png t
2466 (cdr (assq 'png gnus-face-properties-alist))))
2468 (gnus-add-wash-type 'face)
2469 (gnus-add-image 'face image)
2470 (gnus-put-image image nil 'face))))))))))
2472 (defun article-display-x-face (&optional force)
2473 "Look for an X-Face header and display it if present."
2474 (interactive (list 'force))
2475 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2476 (gnus-with-article-headers
2477 ;; Delete the old process, if any.
2478 (when (process-status "article-x-face")
2479 (delete-process "article-x-face"))
2480 ;; See the comment in `article-display-face'.
2481 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2482 ;; We have already displayed X-Faces, so we remove them
2484 (gnus-delete-images 'xface)
2486 (let ((from (message-fetch-field "from"))
2488 (save-current-buffer
2489 (when (and wash-face-p
2490 (gnus-buffer-live-p gnus-original-article-buffer)
2491 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2492 ;; If type `W f', use gnus-original-article-buffer,
2493 ;; otherwise use the current buffer because displaying
2494 ;; RFC822 parts calls this function too.
2495 (set-buffer gnus-original-article-buffer))
2497 (mail-narrow-to-head)
2498 (and gnus-article-x-face-command
2500 ;; Check whether this face is censored.
2501 (not (and gnus-article-x-face-too-ugly
2503 (setq from (message-fetch-field "from")))
2504 (string-match gnus-article-x-face-too-ugly
2506 (while (gnus-article-goto-header "X-Face")
2507 (push (mail-header-field-value) x-faces)))))
2509 ;; We display the face.
2510 (cond ((functionp gnus-article-x-face-command)
2511 ;; The command is a lisp function, so we call it.
2512 (mapc gnus-article-x-face-command x-faces))
2513 ((stringp gnus-article-x-face-command)
2514 ;; The command is a string, so we interpret the command
2515 ;; as a, well, command, and fork it off.
2516 (let ((process-connection-type nil))
2517 (gnus-set-process-query-on-exit-flag
2519 "article-x-face" nil shell-file-name
2520 shell-command-switch gnus-article-x-face-command)
2522 ;; Sending multiple EOFs to xv doesn't work,
2523 ;; so we only do a single external face.
2525 (insert (car x-faces))
2526 (process-send-region "article-x-face"
2527 (point-min) (point-max)))
2528 (process-send-eof "article-x-face")))
2530 (error "`%s' set to `%s' is not a function"
2531 gnus-article-x-face-command
2532 'gnus-article-x-face-command)))))))))
2534 (defun article-decode-mime-words ()
2535 "Decode all MIME-encoded words in the article."
2537 (gnus-with-article-buffer
2538 (let ((inhibit-point-motion-hooks t)
2539 (mail-parse-charset gnus-newsgroup-charset)
2540 (mail-parse-ignored-charsets
2541 (with-current-buffer gnus-summary-buffer
2542 gnus-newsgroup-ignored-charsets)))
2543 (mail-decode-encoded-word-region (point-min) (point-max)))))
2545 (defun article-decode-charset (&optional prompt)
2546 "Decode charset-encoded text in the article.
2547 If PROMPT (the prefix), prompt for a coding system to use."
2549 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2550 (inhibit-read-only t)
2551 (mail-parse-charset gnus-newsgroup-charset)
2552 (mail-parse-ignored-charsets
2553 (save-excursion (condition-case nil
2554 (set-buffer gnus-summary-buffer)
2556 gnus-newsgroup-ignored-charsets))
2557 ct cte ctl charset format)
2560 (article-narrow-to-head)
2561 (setq ct (message-fetch-field "Content-Type" t)
2562 cte (message-fetch-field "Content-Transfer-Encoding" t)
2563 ctl (and ct (mail-header-parse-content-type ct))
2566 (mm-read-coding-system "Charset to decode: "))
2568 (mail-content-type-get ctl 'charset)))
2569 format (and ctl (mail-content-type-get ctl 'format)))
2571 (setq cte (mail-header-strip cte)))
2572 (if (and ctl (not (string-match "/" (car ctl))))
2574 (goto-char (point-max)))
2577 (narrow-to-region (point) (point-max))
2578 (when (and (eq mail-parse-charset 'gnus-decoded)
2579 (eq (mm-body-7-or-8) '8bit))
2580 ;; The text code could have been decoded.
2581 (setq charset mail-parse-charset))
2582 (when (and (or (not ctl)
2583 (equal (car ctl) "text/plain"))
2584 (not format)) ;; article with format will decode later.
2586 charset (and cte (intern (downcase
2587 (gnus-strip-whitespace cte))))
2590 (defun article-decode-encoded-words ()
2591 "Remove encoded-word encoding from headers."
2592 (let ((inhibit-point-motion-hooks t)
2593 (mail-parse-charset gnus-newsgroup-charset)
2594 (mail-parse-ignored-charsets
2595 (save-excursion (condition-case nil
2596 (set-buffer gnus-summary-buffer)
2598 gnus-newsgroup-ignored-charsets))
2599 (inhibit-read-only t)
2601 (goto-char (point-min))
2602 (when (search-forward "\n\n" nil 'move)
2609 (memq (char-after) '(?\t ? )))))
2610 (setq start (point))
2612 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2613 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2614 (funcall gnus-decode-address-function start end)
2615 (funcall gnus-decode-header-function start end))
2616 (goto-char (setq end start)))))
2618 (defun article-decode-group-name ()
2619 "Decode group names in Newsgroups, Followup-To and Xref headers."
2620 (let ((inhibit-point-motion-hooks t)
2621 (inhibit-read-only t)
2622 (method (gnus-find-method-for-group gnus-newsgroup-name))
2624 (when (and (or gnus-group-name-charset-method-alist
2625 gnus-group-name-charset-group-alist)
2626 (gnus-buffer-live-p gnus-original-article-buffer))
2628 (article-narrow-to-head)
2629 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2630 (with-current-buffer gnus-original-article-buffer
2631 (goto-char (point-min)))
2632 (setq regexp (concat "^" header
2633 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2634 (while (re-search-forward regexp nil t)
2635 (replace-match (save-match-data
2636 (gnus-decode-newsgroups
2637 ;; XXX how to use data in article buffer?
2638 (with-current-buffer gnus-original-article-buffer
2639 (re-search-forward regexp nil t)
2641 gnus-newsgroup-name method))
2643 (goto-char (point-min)))))))
2645 (autoload 'idna-to-unicode "idna")
2647 (defun article-decode-idna-rhs ()
2648 "Decode IDNA strings in RHS in various headers in current buffer.
2649 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2650 Mail-Reply-To: and Mail-Followup-To:."
2653 (let ((inhibit-point-motion-hooks t)
2654 (inhibit-read-only t))
2655 (article-narrow-to-head)
2656 (goto-char (point-min))
2657 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2659 (when (save-match-data
2660 (and (setq ace (match-string 1))
2662 (and (re-search-backward "^[^ \t]" nil t)
2663 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2664 (setq unicode (idna-to-unicode ace))))
2665 (unless (string= ace unicode)
2666 (replace-match unicode nil nil nil 1)))))))))
2668 (defun article-de-quoted-unreadable (&optional force read-charset)
2669 "Translate a quoted-printable-encoded article.
2670 If FORCE, decode the article whether it is marked as quoted-printable
2672 If READ-CHARSET, ask for a coding system."
2673 (interactive (list 'force current-prefix-arg))
2675 (let ((inhibit-read-only t) type charset)
2676 (if (gnus-buffer-live-p gnus-original-article-buffer)
2677 (with-current-buffer gnus-original-article-buffer
2679 (gnus-fetch-field "content-transfer-encoding"))
2680 (let* ((ct (gnus-fetch-field "content-type"))
2681 (ctl (and ct (mail-header-parse-content-type ct))))
2682 (setq charset (and ctl
2683 (mail-content-type-get ctl 'charset)))
2684 (if (stringp charset)
2685 (setq charset (intern (downcase charset)))))))
2687 (setq charset (mm-read-coding-system "Charset: " charset)))
2689 (setq charset gnus-newsgroup-charset))
2691 (and type (let ((case-fold-search t))
2692 (string-match "quoted-printable" type))))
2694 (quoted-printable-decode-region
2695 (point) (point-max) (mm-charset-to-coding-system charset))))))
2697 (defun article-de-base64-unreadable (&optional force read-charset)
2698 "Translate a base64 article.
2699 If FORCE, decode the article whether it is marked as base64 not.
2700 If READ-CHARSET, ask for a coding system."
2701 (interactive (list 'force current-prefix-arg))
2703 (let ((inhibit-read-only t) type charset)
2704 (if (gnus-buffer-live-p gnus-original-article-buffer)
2705 (with-current-buffer gnus-original-article-buffer
2707 (gnus-fetch-field "content-transfer-encoding"))
2708 (let* ((ct (gnus-fetch-field "content-type"))
2709 (ctl (and ct (mail-header-parse-content-type ct))))
2710 (setq charset (and ctl
2711 (mail-content-type-get ctl 'charset)))
2712 (if (stringp charset)
2713 (setq charset (intern (downcase charset)))))))
2715 (setq charset (mm-read-coding-system "Charset: " charset)))
2717 (setq charset gnus-newsgroup-charset))
2719 (and type (let ((case-fold-search t))
2720 (string-match "base64" type))))
2723 (narrow-to-region (point) (point-max))
2724 (base64-decode-region (point-min) (point-max))
2725 (mm-decode-coding-region
2726 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2731 (defun article-decode-HZ ()
2732 "Translate a HZ-encoded article."
2736 (let ((inhibit-read-only t))
2737 (rfc1843-decode-region (point-min) (point-max)))))
2739 (defun article-unsplit-urls ()
2740 "Remove the newlines that some other mailers insert into URLs."
2743 (let ((inhibit-read-only t))
2744 (goto-char (point-min))
2745 (while (re-search-forward
2746 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2747 (replace-match "\\1\\3" t)))
2748 (when (interactive-p)
2749 (gnus-treat-article nil))))
2751 (defun article-wash-html ()
2752 "Format an HTML article."
2755 (buffer-read-only nil))
2756 (when (gnus-buffer-live-p gnus-original-article-buffer)
2757 (setq handles (mm-dissect-buffer t t)))
2759 (delete-region (point) (point-max))
2760 (mm-inline-text-html handles)))
2762 (defvar gnus-article-browse-html-temp-list nil
2763 "List of temporary files created by `gnus-article-browse-html-parts'.
2764 Internal variable.")
2766 (defcustom gnus-article-browse-delete-temp 'ask
2767 "What to do with temporary files from `gnus-article-browse-html-parts'.
2768 If nil, don't delete temporary files. If it is t, delete them on
2769 exit from the summary buffer. If it is the symbol `file', query
2770 on each file, if it is `ask' ask once when exiting from the
2772 :group 'gnus-article
2773 :version "23.1" ;; No Gnus
2774 :type '(choice (const :tag "Don't delete" nil)
2775 (const :tag "Don't ask" t)
2776 (const :tag "Ask" ask)
2777 (const :tag "Ask for each file" file)))
2779 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2781 (defun gnus-article-browse-delete-temp-files (&optional how)
2782 "Delete temp-files created by `gnus-article-browse-html-parts'."
2783 (when (and gnus-article-browse-html-temp-list
2785 (or how (setq how gnus-article-browse-delete-temp))
2787 (let ((files (length gnus-article-browse-html-temp-list)))
2788 (gnus-y-or-n-p (format
2789 "Delete all %s temporary HTML file%s? "
2791 (if (> files 1) "s" ""))))
2793 (dolist (file gnus-article-browse-html-temp-list)
2794 (cond ((file-directory-p file)
2795 (when (or (not (eq how 'file))
2798 "Delete temporary HTML file(s) in directory `%s'? "
2799 (file-name-as-directory file))))
2800 (gnus-delete-directory file)))
2801 ((file-exists-p file)
2802 (when (or (not (eq how 'file))
2804 (format "Delete temporary HTML file `%s'? " file)))
2805 (delete-file file)))))
2806 ;; Also remove file from the list when not deleted or if file doesn't
2808 (setq gnus-article-browse-html-temp-list nil))
2809 gnus-article-browse-html-temp-list)
2811 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2812 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2817 (dolist (handle handles)
2819 ((not (listp handle)))
2820 ((equal (mm-handle-media-supertype handle) "multipart")
2821 (when (setq file (gnus-article-browse-html-save-cid-content
2822 cid handle directory))
2823 (throw 'found file)))
2824 ((equal (concat "<" cid ">") (mm-handle-id handle))
2827 (or (mm-handle-filename handle)
2829 (make-temp-name "cid")
2830 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2832 (mm-save-part-to-file handle file)
2833 (throw 'found file))))))))
2835 (defun gnus-article-browse-html-parts (list &optional header)
2836 "View all \"text/html\" parts from LIST.
2837 Recurse into multiparts. The optional HEADER that should be a decoded
2838 message header will be added to the bodies of the \"text/html\" parts."
2839 ;; Internal function used by `gnus-article-browse-html-article'.
2840 (let (type file charset content cid-dir tmp-file showed)
2841 ;; Find and show the html-parts.
2842 (dolist (handle list)
2843 ;; If HTML, show it:
2844 (cond ((not (listp handle)))
2845 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2846 (and (equal (car type) "message/external-body")
2848 (setq file (mm-handle-filename handle)))
2849 (or (mm-handle-cache handle)
2850 (condition-case code
2851 (progn (mm-extern-cache-contents handle) t)
2853 (gnus-message 3 "%s" (error-message-string code))
2854 (when (>= gnus-verbose 3) (sit-for 2))
2857 (setq handle (mm-handle-cache handle)
2858 type (mm-handle-type handle))
2859 (equal (car type) "text/html"))))
2860 (setq charset (mail-content-type-get type 'charset)
2861 content (mm-get-part handle))
2863 (if (eq charset 'gnus-decoded)
2864 (mm-enable-multibyte)
2865 (mm-disable-multibyte))
2867 ;; resolve cid contents
2868 (let ((case-fold-search t)
2870 (goto-char (point-min))
2871 (while (re-search-forward "\
2872 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2875 (setq cid-dir (mm-make-temp-file "cid" t))
2876 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2879 (when (setq cid-file
2880 (gnus-article-browse-html-save-cid-content
2882 (with-current-buffer gnus-article-buffer
2883 gnus-article-mime-handles)
2885 (when (eq system-type 'cygwin)
2887 (concat "/" (substring
2888 (with-output-to-string
2889 (call-process "cygpath" nil
2893 (replace-match (concat "file://" cid-file)
2895 (unless content (setq content (buffer-string))))
2896 (when (or charset header (not file))
2897 (setq tmp-file (mm-make-temp-file
2898 ;; Do we need to care for 8.3 filenames?
2899 "mm-" nil ".html")))
2900 ;; Add a meta html tag to specify charset and a header.
2903 (let (title eheader body hcharset coding force-charset)
2905 (mm-enable-multibyte)
2906 (setq case-fold-search t)
2907 (insert header "\n")
2908 (setq title (message-fetch-field "subject"))
2909 (goto-char (point-min))
2910 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2911 (replace-match (cond ((match-beginning 1) "<")
2912 ((match-beginning 2) ">")
2914 (goto-char (point-min))
2916 (goto-char (point-max))
2917 (insert "</pre>\n<hr>\n")
2918 ;; We have to examine charset one by one since
2919 ;; charset specified in parts might be different.
2920 (if (eq charset 'gnus-decoded)
2921 (setq charset 'utf-8
2922 eheader (mm-encode-coding-string (buffer-string)
2925 (mm-encode-coding-string title charset))
2926 body (mm-encode-coding-string content charset)
2928 (setq hcharset (mm-find-mime-charset-region (point-min)
2930 (cond ((= (length hcharset) 1)
2931 (setq hcharset (car hcharset)
2932 coding (mm-charset-to-coding-system
2934 ((> (length hcharset) 1)
2935 (setq hcharset 'utf-8
2941 (mm-charset-to-coding-system charset))
2942 (if (eq coding body)
2943 (setq eheader (mm-encode-coding-string
2944 (buffer-string) coding)
2946 (mm-encode-coding-string
2949 (setq charset 'utf-8
2950 eheader (mm-encode-coding-string
2951 (buffer-string) charset)
2953 (mm-encode-coding-string
2955 body (mm-encode-coding-string
2956 (mm-decode-coding-string
2960 (setq charset hcharset
2961 eheader (mm-encode-coding-string
2962 (buffer-string) coding)
2964 (mm-encode-coding-string
2967 (setq eheader (mm-string-as-unibyte (buffer-string))
2970 (mm-disable-multibyte)
2973 (mm-add-meta-html-tag handle charset force-charset))
2975 (goto-char (point-min))
2976 (unless (search-forward "<title>" nil t)
2977 (re-search-forward "<head>\\s-*" nil t)
2978 (insert "<title>" title "</title>\n")))
2979 (goto-char (point-min))
2980 (or (re-search-forward
2981 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2983 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2985 (mm-write-region (point-min) (point-max)
2986 tmp-file nil nil nil 'binary t))))
2988 (mm-with-unibyte-buffer
2989 (insert (if (eq charset 'gnus-decoded)
2990 (mm-encode-coding-string content
2991 (setq charset 'utf-8))
2993 (if (or (mm-add-meta-html-tag handle charset)
2995 (mm-write-region (point-min) (point-max)
2996 tmp-file nil nil nil 'binary t)
2997 (setq tmp-file nil))))
2999 (mm-save-part-to-file handle tmp-file)))
3001 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3002 (add-hook 'gnus-summary-prepare-exit-hook
3003 'gnus-article-browse-delete-temp-files)
3004 (add-hook 'gnus-exit-gnus-hook
3006 (gnus-article-browse-delete-temp-files t)))
3007 ;; FIXME: Warn if there's an <img> tag?
3008 (browse-url-of-file (or tmp-file (expand-file-name file)))
3010 ;; If multipart, recurse
3011 ((equal (mm-handle-media-supertype handle) "multipart")
3012 (when (gnus-article-browse-html-parts handle header)
3014 ((equal (mm-handle-media-type handle) "message/rfc822")
3015 (mm-with-multibyte-buffer
3016 (mm-insert-part handle)
3017 (setq handle (mm-dissect-buffer t t))
3018 (when (and (bufferp (car handle))
3019 (stringp (car (mm-handle-type handle))))
3020 (setq handle (list handle)))
3022 (article-decode-encoded-words)
3023 (let ((gnus-visible-headers
3024 (or (get 'gnus-visible-headers 'standard-value)
3025 gnus-visible-headers)))
3026 (article-hide-headers))
3027 (goto-char (point-min))
3028 (search-forward "\n\n" nil 'move)
3029 (skip-chars-backward "\t\n ")
3030 (setq header (buffer-substring (point-min) (point)))))
3032 (gnus-article-browse-html-parts handle header)
3033 (mm-destroy-parts handle))
3037 (defun gnus-article-browse-html-article (&optional arg)
3038 "View \"text/html\" parts of the current article with a WWW browser.
3039 Inline images embedded in a message using the cid scheme, as they are
3040 generally considered to be safe, will be processed properly.
3041 The message header is added to the beginning of every html part unless
3042 the prefix argument ARG is given.
3044 Warning: Spammers use links to images (using the http scheme) in HTML
3045 articles to verify whether you have read the message. As
3046 `gnus-article-browse-html-article' passes the HTML content to the
3047 browser without eliminating these \"web bugs\" you should only
3048 use it for mails from trusted senders.
3050 If you always want to display HTML parts in the browser, set
3051 `mm-text-html-renderer' to nil.
3053 This command creates temporary files to pass HTML contents including
3054 images if any to the browser, and deletes them when exiting the group
3056 ;; Cf. `mm-w3m-safe-url-regexp'
3059 (gnus-summary-show-article)
3060 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3061 gnus-visible-headers))
3062 ;; As we insert a <hr>, there's no need for the body boundary.
3063 (gnus-treat-body-boundary nil))
3064 (gnus-summary-show-article)))
3065 (with-current-buffer gnus-article-buffer
3066 (let ((header (unless arg
3069 (buffer-substring-no-properties
3070 (goto-char (point-min))
3071 (if (search-forward "\n\n" nil t)
3073 (goto-char (point-max))
3074 (skip-chars-backward "\t\n ")
3077 (set-buffer gnus-original-article-buffer)
3078 (setq parts (mm-dissect-buffer t t))
3079 ;; If singlepart, enforce a list.
3080 (when (and (bufferp (car parts))
3081 (stringp (car (mm-handle-type parts))))
3082 (setq parts (list parts)))
3084 (unless (gnus-article-browse-html-parts parts header)
3085 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3086 (mm-destroy-parts parts)
3088 (gnus-summary-show-article)))))
3090 (defun article-hide-list-identifiers ()
3091 "Remove list identifies from the Subject header.
3092 The `gnus-list-identifiers' variable specifies what to do."
3094 (let ((inhibit-point-motion-hooks t)
3095 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3096 (inhibit-read-only t))
3100 (article-narrow-to-head)
3101 (goto-char (point-min))
3102 (while (re-search-forward
3103 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3105 (delete-region (match-beginning 2) (match-end 0))
3106 (beginning-of-line))
3107 (when (re-search-forward
3108 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3109 (delete-region (match-beginning 1) (match-end 1))))))))
3111 (defun article-hide-pem (&optional arg)
3112 "Toggle hiding of any PEM headers and signatures in the current article.
3113 If given a negative prefix, always show; if given a positive prefix,
3115 (interactive (gnus-article-hidden-arg))
3116 (unless (gnus-article-check-hidden-text 'pem arg)
3118 (let ((inhibit-read-only t) end)
3119 (goto-char (point-min))
3120 ;; Hide the horrendously ugly "header".
3121 (when (and (search-forward
3122 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3124 (setq end (1+ (match-beginning 0))))
3125 (gnus-add-wash-type 'pem)
3126 (gnus-article-hide-text-type
3128 (if (search-forward "\n\n" nil t)
3132 ;; Hide the trailer as well
3133 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3135 (gnus-article-hide-text-type
3136 (match-beginning 0) (match-end 0) 'pem)))))))
3138 (defun article-strip-banner ()
3139 "Strip the banners specified by the `banner' group parameter and by
3140 `gnus-article-address-banner-alist'."
3144 (let ((inhibit-point-motion-hooks t))
3145 (when (gnus-parameter-banner gnus-newsgroup-name)
3146 (article-really-strip-banner
3147 (gnus-parameter-banner gnus-newsgroup-name)))
3148 (when gnus-article-address-banner-alist
3149 ;; Note that the From header is decoded here, so it is
3150 ;; required that the *-extract-address-components function
3151 ;; supports non-ASCII text.
3152 (let ((from (save-restriction
3154 (article-narrow-to-head)
3155 (mail-fetch-field "from"))))
3158 (cadr (funcall gnus-extract-address-components
3161 (dolist (pair gnus-article-address-banner-alist)
3162 (when (string-match (car pair) from)
3164 (article-really-strip-banner (cdr pair)))))))))))))
3166 (defun article-really-strip-banner (banner)
3167 "Strip the banner specified by the argument."
3170 (let ((inhibit-point-motion-hooks t)
3171 (gnus-signature-limit nil)
3172 (inhibit-read-only t))
3175 ((eq banner 'signature)
3176 (when (gnus-article-narrow-to-signature)
3179 (delete-region (point) (point-max))))
3181 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3182 (while (re-search-forward banner nil t)
3183 (delete-region (match-beginning 0) (match-end 0)))))
3185 (while (re-search-forward banner nil t)
3186 (delete-region (match-beginning 0) (match-end 0)))))))))
3188 (defun article-babel ()
3189 "Translate article using an online translation service."
3192 (gnus-with-article-buffer
3193 (when (article-goto-body)
3194 (let* ((start (point))
3196 (orig (buffer-substring start end))
3197 (trans (babel-as-string orig)))
3199 (narrow-to-region start end)
3200 (delete-region start end)
3203 (defun article-hide-signature (&optional arg)
3204 "Hide the signature in the current article.
3205 If given a negative prefix, always show; if given a positive prefix,
3207 (interactive (gnus-article-hidden-arg))
3208 (unless (gnus-article-check-hidden-text 'signature arg)
3211 (let ((inhibit-read-only t))
3212 (when (gnus-article-narrow-to-signature)
3213 (gnus-article-hide-text-type
3214 (point-min) (point-max) 'signature))))))
3215 (gnus-set-mode-line 'article))
3217 (defun article-strip-headers-in-body ()
3218 "Strip offensive headers from bodies."
3222 (let ((case-fold-search t))
3223 (when (looking-at "x-no-archive:")
3224 (gnus-delete-line)))))
3226 (defun article-strip-leading-blank-lines ()
3227 "Remove all blank lines from the beginning of the article."
3230 (let ((inhibit-point-motion-hooks t)
3231 (inhibit-read-only t))
3232 (when (article-goto-body)
3233 (while (and (not (eobp))
3234 (looking-at "[ \t]*$"))
3235 (gnus-delete-line))))))
3237 (defun article-narrow-to-head ()
3238 "Narrow the buffer to the head of the message.
3239 Point is left at the beginning of the narrowed-to region."
3241 (goto-char (point-min))
3242 (if (search-forward "\n\n" nil 1)
3245 (goto-char (point-min)))
3247 (defun article-goto-body ()
3248 "Place point at the start of the body."
3249 (goto-char (point-min))
3251 ;; This variable is only bound when dealing with separate
3253 (article-goto-body-goes-to-point-min-p
3255 ((search-forward "\n\n" nil t)
3258 (goto-char (point-max))
3261 (defun article-strip-multiple-blank-lines ()
3262 "Replace consecutive blank lines with one empty line."
3265 (let ((inhibit-point-motion-hooks t)
3266 (inhibit-read-only t))
3267 ;; First make all blank lines empty.
3269 (while (re-search-forward "^[ \t]+$" nil t)
3270 (unless (gnus-annotation-in-region-p
3271 (match-beginning 0) (match-end 0))
3272 (replace-match "" nil t)))
3273 ;; Then replace multiple empty lines with a single empty line.
3275 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3276 (unless (gnus-annotation-in-region-p
3277 (match-beginning 0) (match-end 0))
3278 (delete-region (match-beginning 1) (match-end 1)))))))
3280 (defun article-strip-leading-space ()
3281 "Remove all white space from the beginning of the lines in the article."
3284 (let ((inhibit-point-motion-hooks t)
3285 (inhibit-read-only t))
3287 (while (re-search-forward "^[ \t]+" nil t)
3288 (replace-match "" t t)))))
3290 (defun article-strip-trailing-space ()
3291 "Remove all white space from the end of the lines in the article."
3294 (let ((inhibit-point-motion-hooks t)
3295 (inhibit-read-only t))
3297 (while (re-search-forward "[ \t]+$" nil t)
3298 (replace-match "" t t)))))
3300 (defun article-strip-blank-lines ()
3301 "Strip leading, trailing and multiple blank lines."
3303 (article-strip-leading-blank-lines)
3304 (article-remove-trailing-blank-lines)
3305 (article-strip-multiple-blank-lines))
3307 (defun article-strip-all-blank-lines ()
3308 "Strip all blank lines."
3311 (let ((inhibit-point-motion-hooks t)
3312 (inhibit-read-only t))
3314 (while (re-search-forward "^[ \t]*\n" nil t)
3315 (replace-match "" t t)))))
3317 (defun gnus-article-narrow-to-signature ()
3318 "Narrow to the signature; return t if a signature is found, else nil."
3319 (let ((inhibit-point-motion-hooks t))
3320 (when (gnus-article-search-signature)
3322 ;; Check whether we have some limits to what we consider
3323 ;; to be a signature.
3324 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3325 (list gnus-signature-limit)))
3327 (while (setq limit (pop limits))
3328 (if (or (and (integerp limit)
3329 (< (- (point-max) (point)) limit))
3331 (< (count-lines (point) (point-max)) limit))
3332 (and (functionp limit)
3334 (and (stringp limit)
3335 (not (re-search-forward limit nil t))))
3336 () ; This limit did not succeed.
3340 (narrow-to-region (point) (point-max))
3343 (defun gnus-article-search-signature ()
3344 "Search the current buffer for the signature separator.
3345 Put point at the beginning of the signature separator."
3346 (let ((cur (point)))
3347 (goto-char (point-max))
3348 (if (if (stringp gnus-signature-separator)
3349 (re-search-backward gnus-signature-separator nil t)
3350 (let ((seps gnus-signature-separator))
3352 (not (re-search-backward (car seps) nil t)))
3359 (defun gnus-article-hidden-arg ()
3360 "Return the current prefix arg as a number, or 0 if no prefix."
3361 (list (if current-prefix-arg
3362 (prefix-numeric-value current-prefix-arg)
3365 (defun gnus-article-check-hidden-text (type arg)
3366 "Return nil if hiding is necessary.
3367 Arg can be nil or a number. nil and positive means hide, negative
3368 means show, 0 means toggle."
3371 (let ((hide (gnus-article-hidden-text-p type)))
3377 (gnus-article-show-hidden-text type)
3380 (if (eq hide 'hidden)
3382 (gnus-article-show-hidden-text type)
3386 (defun gnus-article-hidden-text-p (type)
3387 "Say whether the current buffer contains hidden text of type TYPE."
3388 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3390 (not (get-text-property pos 'invisible))
3391 (not (get-text-property pos 'dummy-invisible)))
3393 (text-property-any (1+ pos) (point-max) 'article-type type)))
3398 (defun gnus-article-show-hidden-text (type &optional dummy)
3399 "Show all hidden text of type TYPE.
3400 Originally it is hide instead of DUMMY."
3401 (let ((inhibit-read-only t)
3402 (inhibit-point-motion-hooks t))
3403 (gnus-remove-text-properties-when
3405 (point-min) (point-max)
3406 (cons 'article-type (cons type
3407 gnus-hidden-properties)))
3408 (gnus-delete-wash-type type)))
3410 (defconst article-time-units
3411 `((year . ,(* 365.25 24 60 60))
3412 (week . ,(* 7 24 60 60))
3413 (day . ,(* 24 60 60))
3417 "Mapping from time units to seconds.")
3419 (defun gnus-article-forward-header ()
3420 "Move point to the start of the next header.
3421 If the current header is a continuation header, this can be several
3426 (if (looking-at "[ \t]+[^ \t]")
3430 (defun article-treat-date ()
3431 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3432 (with-current-buffer gnus-summary-buffer
3433 gnus-article-date-headers)
3434 gnus-article-date-headers)
3437 (defun article-date-ut (&optional type highlight date-position)
3438 "Convert DATE date to TYPE in the current article.
3439 The default type is `ut'. See `gnus-article-date-headers' for
3441 (interactive (list 'ut t))
3442 (let* ((case-fold-search t)
3443 (inhibit-read-only t)
3444 (inhibit-point-motion-hooks t)
3446 (visible-date (mail-fetch-field "Date"))
3447 pos date bface eface)
3449 (goto-char (point-min))
3450 (when (re-search-forward "^Date:" nil t)
3451 (setq bface (get-text-property (point-at-bol) 'face)
3452 eface (get-text-property (1- (point-at-eol)) 'face)))
3453 ;; Delete any old Date headers.
3456 (goto-char date-position)
3457 (setq date (get-text-property (point) 'original-date))
3458 (delete-region (point)
3460 (gnus-article-forward-header)
3462 (article-transform-date date type bface eface))
3465 (goto-char (point-min))
3466 (while (or (get-text-property (setq pos (point)) 'original-date)
3467 (and (setq pos (next-single-property-change
3468 (point) 'original-date))
3470 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3471 (1+ (match-beginning 0))
3473 (goto-char (point-min))
3474 (while (re-search-forward "^Date:" nil t)
3475 (setq date (get-text-property (match-beginning 0) 'original-date))
3476 (delete-region (point-at-bol) (progn
3477 (gnus-article-forward-header)
3479 (when (and (not date)
3481 (setq date visible-date))
3483 (article-transform-date date type bface eface))
3484 (goto-char (point-max))
3487 (defun article-transform-date (date type bface eface)
3488 (dolist (this-type (cond
3495 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3498 (put-text-property (point) (1+ (point))
3499 'original-date date)
3500 (put-text-property (point) (1+ (point))
3501 'gnus-date-type this-type)
3503 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3504 (put-text-property (match-beginning 1) (1+ (match-end 1))
3506 (put-text-property (match-beginning 2) (match-end 2)
3510 (defun article-make-date-line (date type)
3511 "Return a DATE line of TYPE."
3512 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3514 (error "Unknown conversion type: %s" type))
3516 (let ((time (ignore-errors (date-to-time date))))
3518 ;; Convert to the local timezone.
3520 (concat "Date: " (message-make-date time)))
3521 ;; Convert to Universal Time.
3526 (let* ((e (parse-time-string date))
3527 (tm (apply 'encode-time e))
3529 (ls (- (cadr tm) (car (current-time-zone time)))))
3530 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3531 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3535 ;; Get the original date from the article.
3536 ((eq type 'original)
3537 (concat "Date: " (if (string-match "\n+$" date)
3538 (substring date 0 (match-beginning 0))
3540 ;; Let the user define the format.
3541 ((eq type 'user-defined)
3542 (let ((format (or (condition-case nil
3543 (with-current-buffer gnus-summary-buffer
3544 gnus-article-time-format)
3546 gnus-article-time-format)))
3547 (if (functionp format)
3548 (funcall format time)
3549 (concat "Date: " (format-time-string format time)))))
3552 (let ((tz (car (current-time-zone time))))
3555 (format-time-string "%Y%m%dT%H%M%S" time)
3556 (format "%s%02d%02d"
3557 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3558 (/ (% (abs tz) 3600) 60)))))
3559 ;; Do a lapsed format.
3561 (concat "Date: " (article-lapsed-string time)))
3562 ;; A combined date/lapsed format.
3563 ((eq type 'combined-lapsed)
3564 (let ((date-string (article-make-date-line date 'original))
3570 (concat " (" (article-lapsed-string time segments) ")"))
3571 (> (+ (length date-string)
3572 (length lapsed-string))
3575 (setq segments (1- segments)))
3577 (concat date-string lapsed-string)
3579 ;; Display the date in proper English
3581 (let ((dtime (decode-time time)))
3584 (number-to-string (nth 3 dtime))
3585 (let ((digit (% (nth 3 dtime) 10)))
3587 ((memq (nth 3 dtime) '(11 12 13)) "th")
3593 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3595 (number-to-string (nth 5 dtime))
3597 (format "%02d" (nth 2 dtime))
3599 (format "%02d" (nth 1 dtime)))))))
3601 (format "Date: %s (from Gnus)" date))))
3603 (defun article-lapsed-string (time &optional max-segments)
3604 ;; If the date is seriously mangled, the timezone functions are
3605 ;; liable to bug out, so we ignore all errors.
3606 (let* ((now (current-time))
3607 (real-time (subtract-time now time))
3608 (real-sec (and real-time
3609 (+ (* (float (car real-time)) 65536)
3611 (sec (and real-time (abs real-sec)))
3614 (unless max-segments
3615 (setq max-segments (length article-time-units)))
3623 ;; This is a bit convoluted, but basically we go
3624 ;; through the time units for years, weeks, etc,
3625 ;; and divide things to see whether that results
3626 ;; in positive answers.
3629 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3630 (>= segments max-segments))
3631 ;; The (remaining) seconds are too few to
3632 ;; be divided into this time unit.
3634 ;; It's big enough, so we output it.
3635 (setq sec (- sec (* num (cdr unit))))
3637 (concat (if prev ", " "") (int-to-string
3639 " " (symbol-name (car unit))
3640 (if (> num 1) "s" ""))
3642 segments (1+ segments)))))
3643 article-time-units "")
3644 ;; If dates are odd, then it might appear like the
3645 ;; article was sent in the future.
3648 " in the future"))))))
3650 (defun article-date-local (&optional highlight)
3651 "Convert the current article date to the local timezone."
3652 (interactive (list t))
3653 (article-date-ut 'local highlight))
3655 (defun article-date-english (&optional highlight)
3656 "Convert the current article date to something that is proper English."
3657 (interactive (list t))
3658 (article-date-ut 'english highlight))
3660 (defun article-date-original (&optional highlight)
3661 "Convert the current article date to what it was originally.
3662 This is only useful if you have used some other date conversion
3663 function and want to see what the date was before converting."
3664 (interactive (list t))
3665 (article-date-ut 'original highlight))
3667 (defun article-date-lapsed (&optional highlight)
3668 "Convert the current article date to time lapsed since it was sent."
3669 (interactive (list t))
3670 (article-date-ut 'lapsed highlight))
3672 (defun article-date-combined-lapsed (&optional highlight)
3673 "Convert the current article date to time lapsed since it was sent."
3674 (interactive (list t))
3675 (article-date-ut 'combined-lapsed highlight))
3677 (defun article-update-date-lapsed ()
3678 "Function to be run from a timer to update the lapsed time line."
3680 (let ((buffer (current-buffer)))
3684 (set-buffer (window-buffer w))
3685 (when (eq major-mode 'gnus-article-mode)
3686 (let ((old-line (count-lines (point-min) (point)))
3687 (old-column (- (point) (line-beginning-position)))
3689 (window-start (get-buffer-window (current-buffer)))))
3690 (goto-char (point-min))
3691 (while (re-search-forward "^Date:" nil t)
3692 (let ((type (get-text-property (match-beginning 0)
3694 (when (memq type '(lapsed combined-lapsed user-format))
3695 (when (and window-start
3696 (not (= window-start
3700 (setq window-start nil))
3702 (article-date-ut type t (match-beginning 0)))
3705 (set-window-start (get-buffer-window (current-buffer))
3707 (goto-char (point-min))
3708 (when (> old-column 0)
3709 (setq old-line (1- old-line)))
3710 (forward-line old-line)
3712 (when (> (current-column) old-column)
3714 (forward-char old-column)))))
3716 (set-buffer buffer))))
3718 (defun gnus-start-date-timer (&optional n)
3719 "Start a timer to update the Date headers in the article buffers.
3720 The numerical prefix says how frequently (in seconds) the function
3725 (gnus-stop-date-timer)
3726 (setq article-lapsed-timer
3727 (run-at-time 1 n 'article-update-date-lapsed)))
3729 (defun gnus-stop-date-timer ()
3730 "Stop the Date timer."
3732 (when article-lapsed-timer
3733 (nnheader-cancel-timer article-lapsed-timer)
3734 (setq article-lapsed-timer nil)))
3736 (defun article-date-user (&optional highlight)
3737 "Convert the current article date to the user-defined format.
3738 This format is defined by the `gnus-article-time-format' variable."
3739 (interactive (list t))
3740 (article-date-ut 'user highlight))
3742 (defun article-date-iso8601 (&optional highlight)
3743 "Convert the current article date to ISO8601."
3744 (interactive (list t))
3745 (article-date-ut 'iso8601 highlight))
3747 (defmacro gnus-article-save-original-date (&rest forms)
3748 "Save the original date as a text property and evaluate FORMS."
3749 `(let* ((case-fold-search t)
3751 (goto-char (point-min))
3752 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3755 (date (when (and start
3756 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3758 (buffer-substring-no-properties start
3759 (match-beginning 0)))))
3760 (goto-char (point-max))
3761 (skip-chars-backward "\n")
3762 (put-text-property (point-min) (point) 'original-date date)
3764 (goto-char (point-max))
3765 (skip-chars-backward "\n")
3766 (put-text-property (point-min) (point) 'original-date date)))
3768 ;; (defun article-show-all ()
3769 ;; "Show all hidden text in the article buffer."
3772 ;; (let ((inhibit-read-only t))
3773 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3775 (defun article-remove-leading-whitespace ()
3776 "Remove excessive whitespace from all headers."
3780 (let ((inhibit-read-only t))
3781 (article-narrow-to-head)
3782 (goto-char (point-min))
3783 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3784 (delete-region (match-beginning 1) (match-end 1)))))))
3786 (defun article-emphasize (&optional arg)
3787 "Emphasize text according to `gnus-emphasis-alist'."
3788 (interactive (gnus-article-hidden-arg))
3789 (unless (gnus-article-check-hidden-text 'emphasis arg)
3793 (with-current-buffer gnus-summary-buffer
3794 gnus-article-emphasis-alist)
3796 gnus-emphasis-alist))
3797 (inhibit-read-only t)
3798 (props (append '(article-type emphasis)
3799 gnus-hidden-properties))
3800 regexp elem beg invisible visible face)
3803 (while (setq elem (pop alist))
3805 (setq regexp (car elem)
3806 invisible (nth 1 elem)
3807 visible (nth 2 elem)
3809 (while (re-search-forward regexp nil t)
3810 (when (and (match-beginning visible) (match-beginning invisible))
3811 (gnus-article-hide-text
3812 (match-beginning invisible) (match-end invisible) props)
3813 (gnus-article-unhide-text-type
3814 (match-beginning visible) (match-end visible) 'emphasis)
3815 (gnus-put-overlay-excluding-newlines
3816 (match-beginning visible) (match-end visible) 'face face)
3817 (gnus-add-wash-type 'emphasis)
3818 (goto-char (match-end invisible)))))))))
3820 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3821 "Setup newsgroup emphasis alist."
3822 (unless gnus-article-emphasis-alist
3823 (let ((name (and gnus-newsgroup-name
3824 (gnus-group-real-name gnus-newsgroup-name))))
3825 (make-local-variable 'gnus-article-emphasis-alist)
3826 (setq gnus-article-emphasis-alist
3828 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3829 (while (setq elem (pop alist))
3830 (when (and name (string-match (car elem) name))
3832 highlight (copy-sequence (cdr elem)))))
3834 (copy-sequence highlight-words)
3835 (if gnus-newsgroup-name
3836 (copy-sequence (gnus-group-find-parameter
3837 gnus-newsgroup-name 'highlight-words t)))
3838 gnus-emphasis-alist)))))
3840 (defvar gnus-summary-article-menu)
3841 (defvar gnus-summary-post-menu)
3843 ;;; Saving functions.
3845 (defun gnus-article-save (save-buffer file &optional num)
3846 "Save the currently selected article."
3847 (when (or (get gnus-default-article-saver :headers)
3848 (not gnus-save-all-headers))
3849 ;; Remove headers according to `gnus-saved-headers' or the value
3850 ;; of the `:headers' property that the saver function might have.
3851 (let ((gnus-visible-headers
3852 (or (symbol-value (get gnus-default-article-saver :headers))
3853 gnus-saved-headers gnus-visible-headers))
3854 ;; Ignore group parameter. See `article-hide-headers'.
3855 (gnus-summary-buffer nil))
3856 (with-current-buffer save-buffer
3857 (article-hide-headers 1 t))))
3858 (save-window-excursion
3859 (if (not gnus-default-article-saver)
3860 (error "No default saver is defined")
3861 ;; !!! Magic! The saving functions all save
3862 ;; `gnus-save-article-buffer' (or so they think), but we
3863 ;; bind that variable to our save-buffer.
3864 (set-buffer gnus-article-buffer)
3865 (let* ((gnus-save-article-buffer save-buffer)
3868 ((not gnus-prompt-before-saving) 'default)
3869 ((eq gnus-prompt-before-saving 'always) nil)
3871 (gnus-number-of-articles-to-be-saved
3872 (when (eq gnus-prompt-before-saving t)
3874 (set-buffer gnus-article-current-summary)
3875 (funcall gnus-default-article-saver filename)))))
3877 (defun gnus-read-save-file-name (prompt &optional filename
3878 function group headers variable
3881 (funcall function group headers (symbol-value variable)))
3886 ((eq filename 'default)
3892 (when (symbol-value dir-var)
3893 (setq default-name (expand-file-name
3894 (file-name-nondirectory default-name)
3895 (symbol-value dir-var))))
3896 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3899 (if (and gnus-number-of-articles-to-be-saved
3900 (> gnus-number-of-articles-to-be-saved 1))
3901 (format "these %d articles"
3902 gnus-number-of-articles-to-be-saved)
3905 ;; Let the split methods have their say.
3907 ;; No split name was found.
3910 (concat prompt " (default "
3911 (file-name-nondirectory default-name) "): ")
3912 (file-name-directory default-name)
3914 ;; A single group name is returned.
3915 ((stringp split-name)
3917 (funcall function split-name headers
3918 (symbol-value variable)))
3920 (concat prompt " (default "
3921 (file-name-nondirectory default-name) "): ")
3922 (file-name-directory default-name)
3924 ;; A single split name was found
3925 ((= 1 (length split-name))
3926 (let* ((name (expand-file-name
3928 gnus-article-save-directory))
3929 (dir (cond ((file-directory-p name)
3930 (file-name-as-directory name))
3931 ((file-exists-p name) name)
3932 (t gnus-article-save-directory))))
3934 (concat prompt " (default " name "): ")
3936 ;; A list of splits was found.
3938 (setq split-name (nreverse split-name))
3940 (let ((file-name-history
3941 (nconc split-name file-name-history)))
3945 (concat prompt " (`M-p' for defaults): ")
3946 gnus-article-save-directory
3948 gnus-article-save-directory)))
3949 (car (push result file-name-history)))))))
3950 ;; Create the directory.
3951 (gnus-make-directory (file-name-directory file))
3952 ;; If we have read a directory, we append the default file name.
3953 (when (file-directory-p file)
3954 (setq file (expand-file-name (file-name-nondirectory
3956 (file-name-as-directory file))))
3957 ;; Possibly translate some characters.
3958 (nnheader-translate-file-chars file))))))
3959 (gnus-make-directory (file-name-directory result))
3961 (set variable result))
3963 (set dir-var (file-name-directory result)))
3966 (defun gnus-article-archive-name (group)
3967 "Return the first instance of an \"Archive-name\" in the current buffer."
3968 (let ((case-fold-search t))
3969 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3970 (nnheader-concat gnus-article-save-directory
3971 (match-string 1)))))
3973 (defun gnus-article-nndoc-name (group)
3974 "If GROUP is an nndoc group, return the name of the parent group."
3975 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3976 (gnus-group-get-parameter group 'save-article-group)))
3978 (defun gnus-summary-save-in-rmail (&optional filename)
3979 "Append this article to Rmail file.
3980 Optional argument FILENAME specifies file name.
3981 Directory to save to is default to `gnus-article-save-directory'."
3982 (setq filename (gnus-read-save-file-name
3983 "Save %s in rmail file" filename
3984 gnus-rmail-save-name gnus-newsgroup-name
3985 gnus-current-headers 'gnus-newsgroup-last-rmail))
3986 (with-current-buffer gnus-save-article-buffer
3990 ;; Note that unlike gnus-summary-save-in-mail, there is no
3991 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3993 (gnus-output-to-rmail filename))))
3996 (defun gnus-summary-save-in-mail (&optional filename)
3997 "Append this article to Unix mail file.
3998 Optional argument FILENAME specifies file name.
3999 Directory to save to is default to `gnus-article-save-directory'."
4000 (setq filename (gnus-read-save-file-name
4001 "Save %s in Unix mail file" filename
4002 gnus-mail-save-name gnus-newsgroup-name
4003 gnus-current-headers 'gnus-newsgroup-last-mail))
4004 (with-current-buffer gnus-save-article-buffer
4008 (if (and (file-readable-p filename)
4009 (file-regular-p filename)
4010 (mail-file-babyl-p filename))
4011 (gnus-output-to-rmail filename)
4012 (gnus-output-to-mail filename)))))
4015 (put 'gnus-summary-save-in-file :decode t)
4016 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4017 (defun gnus-summary-save-in-file (&optional filename overwrite)
4018 "Append this article to file.
4019 Optional argument FILENAME specifies file name.
4020 Directory to save to is default to `gnus-article-save-directory'."
4021 (setq filename (gnus-read-save-file-name
4022 "Save %s in file" filename
4023 gnus-file-save-name gnus-newsgroup-name
4024 gnus-current-headers 'gnus-newsgroup-last-file))
4025 (with-current-buffer gnus-save-article-buffer
4029 (when (and overwrite
4030 (file-exists-p filename))
4031 (delete-file filename))
4032 (gnus-output-to-file filename))))
4035 (put 'gnus-summary-write-to-file :decode t)
4036 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4037 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4038 (defun gnus-summary-write-to-file (&optional filename)
4039 "Write this article to a file, overwriting it if the file exists.
4040 Optional argument FILENAME specifies file name.
4041 The directory to save in defaults to `gnus-article-save-directory'."
4042 (setq filename (gnus-read-save-file-name
4043 "Save %s in file" filename
4044 gnus-file-save-name gnus-newsgroup-name
4045 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4046 (gnus-summary-save-in-file filename t))
4048 (put 'gnus-summary-save-body-in-file :decode t)
4049 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4050 "Append this article body to a file.
4051 Optional argument FILENAME specifies file name.
4052 The directory to save in defaults to `gnus-article-save-directory'."
4053 (setq filename (gnus-read-save-file-name
4054 "Save %s body in file" filename
4055 gnus-file-save-name gnus-newsgroup-name
4056 gnus-current-headers 'gnus-newsgroup-last-file))
4057 (with-current-buffer gnus-save-article-buffer
4061 (when (article-goto-body)
4062 (narrow-to-region (point) (point-max)))
4063 (when (and overwrite
4064 (file-exists-p filename))
4065 (delete-file filename))
4066 (gnus-output-to-file filename))))
4069 (put 'gnus-summary-write-body-to-file :decode t)
4070 (put 'gnus-summary-write-body-to-file
4071 :function 'gnus-summary-save-body-in-file)
4072 (defun gnus-summary-write-body-to-file (&optional filename)
4073 "Write this article body to a file, overwriting it if the file exists.
4074 Optional argument FILENAME specifies file name.
4075 The directory to save in defaults to `gnus-article-save-directory'."
4076 (setq filename (gnus-read-save-file-name
4077 "Save %s body in file" filename
4078 gnus-file-save-name gnus-newsgroup-name
4079 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4080 (gnus-summary-save-body-in-file filename t))
4082 (put 'gnus-summary-save-in-pipe :decode t)
4083 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4084 (defun gnus-summary-save-in-pipe (&optional command raw)
4085 "Pipe this article to subprocess COMMAND.
4086 Valid values for COMMAND include:
4088 The executable command name and possibly arguments.
4090 You will be prompted for the command in the minibuffer.
4091 the symbol `default'
4092 It will be replaced with the command which the variable
4093 `gnus-summary-pipe-output-default-command' holds or the command
4094 last used for saving.
4095 Non-nil value for RAW overrides `:decode' and `:headers' properties
4096 and the raw article including all headers will be piped."
4097 (let ((article (gnus-summary-article-number))
4099 (get 'gnus-summary-save-in-pipe :decode)))
4100 save-buffer default)
4102 (if (vectorp (gnus-summary-article-header article))
4103 (save-current-buffer
4104 (gnus-summary-select-article decode decode nil article)
4105 (insert-buffer-substring
4109 gnus-original-article-buffer)
4111 (nnheader-set-temp-buffer " *Gnus Save*"))))
4112 ;; Remove unwanted headers.
4113 (when (and (not raw)
4114 (or (get 'gnus-summary-save-in-pipe :headers)
4115 (not gnus-save-all-headers)))
4116 (let ((gnus-visible-headers
4117 (or (symbol-value (get 'gnus-summary-save-in-pipe
4119 gnus-saved-headers gnus-visible-headers))
4120 (gnus-summary-buffer nil))
4121 (article-hide-headers 1 t))))
4122 (error "%d is not a real article" article))
4123 (error "No article to pipe"))
4124 (setq default (or gnus-summary-pipe-output-default-command
4125 gnus-last-shell-command))
4126 (unless (stringp command)
4128 (if (and (eq command 'default) default)
4130 (gnus-read-shell-command "Shell command on this article: "
4132 (when (string-equal command "")
4134 (setq command default)
4135 (error "A command is required")))
4136 (with-current-buffer save-buffer
4139 (shell-command-on-region (point-min) (point-max) command nil)))
4140 (gnus-kill-buffer save-buffer))
4141 (setq gnus-summary-pipe-output-default-command command))
4143 (defun gnus-summary-pipe-to-muttprint (&optional command)
4144 "Pipe this article to muttprint."
4145 (unless (stringp command)
4146 (setq command (read-string
4147 "Print using command: " gnus-summary-muttprint-program
4148 nil gnus-summary-muttprint-program)))
4149 (let ((gnus-summary-pipe-output-default-command
4150 gnus-summary-pipe-output-default-command))
4151 (gnus-summary-save-in-pipe command))
4152 (setq gnus-summary-muttprint-program command))
4154 ;;; Article file names when saving.
4156 (defun gnus-capitalize-newsgroup (newsgroup)
4157 "Capitalize NEWSGROUP name."
4158 (when (not (zerop (length newsgroup)))
4159 (concat (char-to-string (upcase (aref newsgroup 0)))
4160 (substring newsgroup 1))))
4162 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4163 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4164 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4165 Otherwise, it is like ~/News/news/group/num."
4168 (concat (if (gnus-use-long-file-name 'not-save)
4169 (gnus-capitalize-newsgroup newsgroup)
4170 (gnus-newsgroup-directory-form newsgroup))
4171 "/" (int-to-string (mail-header-number headers)))
4172 gnus-article-save-directory)))
4174 (string-equal (file-name-directory default)
4175 (file-name-directory last-file))
4176 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4178 (or last-file default))))
4180 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4181 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4182 If variable `gnus-use-long-file-name' is non-nil, it is
4183 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4186 (concat (if (gnus-use-long-file-name 'not-save)
4188 (gnus-newsgroup-directory-form newsgroup))
4189 "/" (int-to-string (mail-header-number headers)))
4190 gnus-article-save-directory)))
4192 (string-equal (file-name-directory default)
4193 (file-name-directory last-file))
4194 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4196 (or last-file default))))
4198 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4199 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4200 If variable `gnus-use-long-file-name' is non-nil, it is
4201 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4204 (if (gnus-use-long-file-name 'not-save)
4207 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4209 gnus-article-save-directory)))
4211 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4212 "Generate file name from sender."
4213 (let ((from (mail-header-from headers)))
4215 (if (and from (string-match "\\([^ <]+\\)@" from))
4216 (match-string 1 from)
4218 gnus-article-save-directory)))
4220 (defun article-verify-x-pgp-sig ()
4222 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4224 (if (gnus-buffer-live-p gnus-original-article-buffer)
4225 (let ((sig (with-current-buffer gnus-original-article-buffer
4226 (gnus-fetch-field "X-PGP-Sig")))
4230 (mml2015-clear-verify-function))
4232 (insert-buffer-substring gnus-original-article-buffer)
4233 (setq items (split-string sig))
4234 (message-narrow-to-head)
4235 (let ((inhibit-point-motion-hooks t)
4236 (case-fold-search t))
4237 ;; Don't verify multiple headers.
4238 (setq headers (mapconcat (lambda (header)
4240 (mail-fetch-field header)
4242 (split-string (nth 1 items) ",") "")))
4243 (delete-region (point-min) (point-max))
4244 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4245 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4250 (if (looking-at "^-")
4253 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4254 (insert "Version: " (car items) "\n\n")
4255 (insert (mapconcat 'identity (cddr items) "\n"))
4256 (insert "\n-----END PGP SIGNATURE-----\n")
4257 (let ((mm-security-handle (list (format "multipart/signed"))))
4258 (mml2015-clean-buffer)
4259 (let ((coding-system-for-write (or gnus-newsgroup-charset
4261 (funcall (mml2015-clear-verify-function)))
4263 (or (mm-handle-multipart-ctl-parameter
4264 mm-security-handle 'gnus-details)
4265 (mm-handle-multipart-ctl-parameter
4266 mm-security-handle 'gnus-info)))))
4268 (let ((inhibit-read-only t) bface eface)
4270 (message-narrow-to-head)
4271 (goto-char (point-max))
4273 (setq bface (get-text-property (point-at-bol) 'face)
4274 eface (get-text-property (1- (point-at-eol)) 'face))
4275 (message-remove-header "X-Gnus-PGP-Verify")
4276 (if (re-search-forward "^X-PGP-Sig:" nil t)
4278 (goto-char (point-max)))
4279 (narrow-to-region (point) (point))
4280 (insert "X-Gnus-PGP-Verify: " info "\n")
4281 (goto-char (point-min))
4284 (if (not (looking-at "^[ \t]"))
4288 (goto-char (point-min))
4289 (when (looking-at "\\([^:]+\\): *")
4290 (put-text-property (match-beginning 1) (1+ (match-end 1))
4292 (put-text-property (match-end 0) (point-max)
4293 'face eface)))))))))
4295 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4297 (defun article-verify-cancel-lock ()
4298 "Verify Cancel-Lock header."
4300 (if (gnus-buffer-live-p gnus-original-article-buffer)
4301 (canlock-verify gnus-original-article-buffer)))
4308 (setq afunc (car func)
4311 gfunc (intern (format "gnus-%s" func))))
4313 (when (fboundp afunc)
4314 `(lambda (&optional interactive &rest args)
4315 ,(documentation afunc t)
4316 (interactive (list t))
4317 (with-current-buffer gnus-article-buffer
4319 (call-interactively ',afunc)
4320 (apply ',afunc args))))))))
4321 '(article-hide-headers
4322 article-verify-x-pgp-sig
4323 article-verify-cancel-lock
4324 article-hide-boring-headers
4325 article-treat-overstrike
4326 article-treat-ansi-sequences
4327 article-fill-long-lines
4328 article-capitalize-sentences
4330 article-remove-leading-whitespace
4331 article-display-x-face
4332 article-display-face
4333 article-de-quoted-unreadable
4334 article-de-base64-unreadable
4337 article-unsplit-urls
4338 article-hide-list-identifiers
4339 article-strip-banner
4342 article-hide-signature
4343 article-strip-headers-in-body
4344 article-remove-trailing-blank-lines
4345 article-strip-leading-blank-lines
4346 article-strip-multiple-blank-lines
4347 article-strip-leading-space
4348 article-strip-trailing-space
4349 article-strip-blank-lines
4350 article-strip-all-blank-lines
4352 article-date-english
4353 article-date-iso8601
4354 article-date-original
4357 article-decode-mime-words
4358 article-decode-charset
4359 article-decode-encoded-words
4362 article-date-combined-lapsed
4364 article-treat-dumbquotes
4365 article-treat-non-ascii
4366 article-normalize-headers
4367 ;;(article-show-all . gnus-article-show-all-headers)
4371 ;;; Gnus article mode
4374 (put 'gnus-article-mode 'mode-class 'special)
4376 (set-keymap-parent gnus-article-mode-map widget-keymap)
4378 (gnus-define-keys gnus-article-mode-map
4379 " " gnus-article-goto-next-page
4380 "\177" gnus-article-goto-prev-page
4381 [delete] gnus-article-goto-prev-page
4382 [backspace] gnus-article-goto-prev-page
4383 "\C-c^" gnus-article-refer-article
4384 "h" gnus-article-show-summary
4385 "s" gnus-article-show-summary
4386 "\C-c\C-m" gnus-article-mail
4387 "?" gnus-article-describe-briefly
4388 "<" beginning-of-buffer
4390 "\C-c\C-i" gnus-info-find-node
4392 "R" gnus-article-reply-with-original
4393 "F" gnus-article-followup-with-original
4394 "\C-hk" gnus-article-describe-key
4395 "\C-hc" gnus-article-describe-key-briefly
4396 "\C-hb" gnus-article-describe-bindings
4398 "e" gnus-article-read-summary-keys
4399 "\C-d" gnus-article-read-summary-keys
4400 "\M-*" gnus-article-read-summary-keys
4401 "\M-#" gnus-article-read-summary-keys
4402 "\M-^" gnus-article-read-summary-keys
4403 "\M-g" gnus-article-read-summary-keys)
4405 (substitute-key-definition
4406 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4408 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4409 "W" gnus-article-wide-reply-with-original)
4410 (if (featurep 'xemacs)
4411 (set-keymap-default-binding gnus-article-send-map
4412 'gnus-article-read-summary-send-keys)
4413 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4415 (defun gnus-article-make-menu-bar ()
4416 (unless (boundp 'gnus-article-commands-menu)
4417 (gnus-summary-make-menu-bar))
4418 (unless (boundp 'gnus-article-article-menu)
4420 gnus-article-article-menu gnus-article-mode-map ""
4422 ["Scroll forwards" gnus-article-goto-next-page t]
4423 ["Scroll backwards" gnus-article-goto-prev-page t]
4424 ["Show summary" gnus-article-show-summary t]
4425 ["Fetch Message-ID at point" gnus-article-refer-article t]
4426 ["Mail to address at point" gnus-article-mail t]
4427 ["Send a bug report" gnus-bug t]))
4430 gnus-article-treatment-menu gnus-article-mode-map ""
4431 ;; Fixme: this should use :active (and maybe :visible).
4433 ["Hide headers" gnus-article-hide-headers t]
4434 ["Hide signature" gnus-article-hide-signature t]
4435 ["Hide citation" gnus-article-hide-citation t]
4436 ["Treat overstrike" gnus-article-treat-overstrike t]
4437 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4438 ["Remove carriage return" gnus-article-remove-cr t]
4439 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4440 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4441 ["Remove base64" gnus-article-de-base64-unreadable t]
4442 ["Treat html" gnus-article-wash-html t]
4443 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4444 ["Decode HZ" gnus-article-decode-HZ t]))
4446 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4448 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4450 (gnus-run-hooks 'gnus-article-menu-hook)))
4452 (defvar bookmark-make-record-function)
4453 (defvar shr-put-image-function)
4455 (defun gnus-article-mode ()
4456 "Major mode for displaying an article.
4458 All normal editing commands are switched off.
4460 The following commands are available in addition to all summary mode
4462 \\<gnus-article-mode-map>
4463 \\[gnus-article-next-page]\t Scroll the article one page forwards
4464 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4465 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4466 \\[gnus-article-show-summary]\t Display the summary buffer
4467 \\[gnus-article-mail]\t Send a reply to the address near point
4468 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4469 \\[gnus-info-find-node]\t Go to the Gnus info node"
4471 (kill-all-local-variables)
4472 (gnus-simplify-mode-line)
4473 (setq mode-name "Article")
4474 (setq major-mode 'gnus-article-mode)
4475 (make-local-variable 'minor-mode-alist)
4476 (use-local-map gnus-article-mode-map)
4477 (when (gnus-visual-p 'article-menu 'menu)
4478 (gnus-article-make-menu-bar)
4479 (when gnus-summary-tool-bar-map
4480 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4481 (gnus-update-format-specifications nil 'article-mode)
4482 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4483 (set (make-local-variable 'gnus-page-broken) nil)
4484 (make-local-variable 'gnus-article-current-summary)
4485 (make-local-variable 'gnus-article-mime-handles)
4486 (make-local-variable 'gnus-article-decoded-p)
4487 (make-local-variable 'gnus-article-mime-handle-alist)
4488 (make-local-variable 'gnus-article-wash-types)
4489 (make-local-variable 'gnus-article-image-alist)
4490 (make-local-variable 'gnus-article-charset)
4491 (make-local-variable 'gnus-article-ignored-charsets)
4492 (set (make-local-variable 'bookmark-make-record-function)
4493 'gnus-summary-bookmark-make-record)
4494 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4496 (set (make-local-variable 'nobreak-char-display) nil)
4497 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4498 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4499 (setq cursor-in-non-selected-windows nil)
4500 (gnus-set-default-directory)
4501 (buffer-disable-undo)
4502 (setq buffer-read-only t
4503 show-trailing-whitespace nil)
4504 (set-syntax-table gnus-article-mode-syntax-table)
4505 (mm-enable-multibyte)
4506 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4508 (defun gnus-article-setup-buffer ()
4509 "Initialize the article buffer."
4510 (let* ((name (if gnus-single-article-buffer "*Article*"
4512 (gnus-group-decoded-name gnus-newsgroup-name)
4515 (progn (string-match "\\*Article" name)
4516 (concat " *Original Article"
4517 (substring name (match-end 0))))))
4518 (setq gnus-article-buffer name)
4519 (setq gnus-original-article-buffer original)
4520 (setq gnus-article-mime-handle-alist nil)
4521 (with-current-buffer gnus-summary-buffer
4522 ;; This might be a variable local to the summary buffer.
4523 (unless gnus-single-article-buffer
4524 (setq gnus-article-buffer name)
4525 (setq gnus-original-article-buffer original)
4526 (gnus-set-global-variables)))
4527 (gnus-article-setup-highlight-words)
4528 ;; Init original article buffer.
4529 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4530 (mm-enable-multibyte)
4531 (setq major-mode 'gnus-original-article-mode)
4532 (make-local-variable 'gnus-original-article))
4533 (if (and (get-buffer name)
4534 (with-current-buffer name
4535 (if gnus-article-edit-mode
4536 (if (y-or-n-p "Article mode edit in progress; discard? ")
4538 (set-buffer-modified-p nil)
4539 (gnus-kill-buffer name)
4542 (error "Action aborted"))
4544 (with-current-buffer name
4545 (set (make-local-variable 'gnus-article-edit-mode) nil)
4546 (gnus-article-stop-animations)
4547 (when gnus-article-mime-handles
4548 (mm-destroy-parts gnus-article-mime-handles)
4549 (setq gnus-article-mime-handles nil))
4550 ;; Set it to nil in article-buffer!
4551 (setq gnus-article-mime-handle-alist nil)
4552 (buffer-disable-undo)
4553 (setq buffer-read-only t)
4554 (unless (eq major-mode 'gnus-article-mode)
4555 (gnus-article-mode))
4556 (setq truncate-lines gnus-article-truncate-lines)
4558 (with-current-buffer (gnus-get-buffer-create name)
4560 (setq truncate-lines gnus-article-truncate-lines)
4561 (make-local-variable 'gnus-summary-buffer)
4562 (setq gnus-summary-buffer
4563 (gnus-summary-buffer-name gnus-newsgroup-name))
4564 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4565 (when article-lapsed-timer
4566 (gnus-stop-date-timer))
4567 (when gnus-article-update-date-headers
4568 (gnus-start-date-timer gnus-article-update-date-headers))
4569 (current-buffer)))))
4571 (defun gnus-article-stop-animations ()
4572 (dolist (timer (and (boundp 'timer-list)
4574 (when (eq (elt timer 5) 'image-animate-timeout)
4575 (cancel-timer timer))))
4577 ;; Set article window start at LINE, where LINE is the number of lines
4578 ;; from the head of the article.
4579 (defun gnus-article-set-window-start (&optional line)
4580 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4581 (when article-window
4584 (with-current-buffer gnus-article-buffer
4585 (goto-char (point-min))
4588 (gnus-message 6 "Moved to bookmark")
4589 (search-forward "\n\n" nil t)
4593 (defun gnus-article-prepare (article &optional all-headers header)
4594 "Prepare ARTICLE in article mode buffer.
4595 ARTICLE should either be an article number or a Message-ID.
4596 If ARTICLE is an id, HEADER should be the article headers.
4597 If ALL-HEADERS is non-nil, no headers are hidden."
4599 ;; Make sure we start in a summary buffer.
4600 (unless (eq major-mode 'gnus-summary-mode)
4601 (set-buffer gnus-summary-buffer))
4602 (setq gnus-summary-buffer (current-buffer))
4603 (let* ((gnus-article (if header (mail-header-number header) article))
4604 (summary-buffer (current-buffer))
4605 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4606 (group gnus-newsgroup-name)
4609 (gnus-article-setup-buffer)
4610 (set-buffer gnus-article-buffer)
4611 ;; Deactivate active regions.
4612 (when (and (boundp 'transient-mark-mode)
4613 transient-mark-mode)
4614 (setq mark-active nil))
4615 (if (not (setq result (let ((inhibit-read-only t))
4616 (gnus-request-article-this-buffer
4618 ;; There is no such article.
4620 (when (and (numberp article)
4621 (not (memq article gnus-newsgroup-sparse)))
4622 (setq gnus-article-current
4623 (cons gnus-newsgroup-name article))
4624 (set-buffer gnus-summary-buffer)
4625 (setq gnus-current-article article)
4626 (if (and (memq article gnus-newsgroup-undownloaded)
4627 (not (gnus-online (gnus-find-method-for-group
4628 gnus-newsgroup-name))))
4630 (gnus-summary-set-agent-mark article)
4631 (message "Message marked for downloading"))
4632 (gnus-summary-mark-article article gnus-canceled-mark)
4633 (unless (memq article gnus-newsgroup-sparse)
4634 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4635 (if (or (eq result 'pseudo)
4636 (eq result 'nneething))
4638 (with-current-buffer summary-buffer
4639 (push article gnus-newsgroup-history)
4640 (setq gnus-last-article gnus-current-article
4641 gnus-current-article 0
4642 gnus-current-headers nil
4643 gnus-article-current nil)
4644 (if (eq result 'nneething)
4645 (gnus-configure-windows 'summary)
4646 (gnus-configure-windows 'article))
4647 (gnus-set-global-variables))
4648 (let ((gnus-article-mime-handle-alist-1
4649 gnus-article-mime-handle-alist))
4650 (gnus-set-mode-line 'article)))
4651 ;; The result from the `request' was an actual article -
4652 ;; or at least some text that is now displayed in the
4654 (when (and (numberp article)
4655 (not (eq article gnus-current-article)))
4656 ;; Seems like a new article has been selected.
4657 ;; `gnus-current-article' must be an article number.
4658 (with-current-buffer summary-buffer
4659 (push article gnus-newsgroup-history)
4660 (setq gnus-last-article gnus-current-article
4661 gnus-current-article article
4662 gnus-current-headers
4663 (gnus-summary-article-header gnus-current-article)
4664 gnus-article-current
4665 (cons gnus-newsgroup-name gnus-current-article))
4666 (unless (vectorp gnus-current-headers)
4667 (setq gnus-current-headers nil))
4668 (gnus-summary-goto-subject gnus-current-article)
4669 (when (gnus-summary-show-thread)
4670 ;; If the summary buffer really was folded, the
4671 ;; previous goto may not actually have gone to
4672 ;; the right article, but the thread root instead.
4674 (gnus-summary-goto-subject gnus-current-article))
4675 (gnus-run-hooks 'gnus-mark-article-hook)
4676 (gnus-set-mode-line 'summary)
4677 (when (gnus-visual-p 'article-highlight 'highlight)
4678 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4679 ;; Set the global newsgroup variables here.
4680 (gnus-set-global-variables)
4681 (setq gnus-have-all-headers
4682 (or all-headers gnus-show-all-headers))))
4684 (gnus-configure-windows 'article))
4685 (when (or (numberp article)
4687 (gnus-article-prepare-display)
4689 (goto-char (point-min))
4690 (when gnus-break-pages
4691 (gnus-narrow-to-page)))
4692 (let ((gnus-article-mime-handle-alist-1
4693 gnus-article-mime-handle-alist))
4694 (gnus-set-mode-line 'article))
4698 (set-window-point (get-buffer-window (current-buffer)) (point))
4699 (gnus-configure-windows 'article)
4700 (gnus-run-hooks 'gnus-article-prepare-hook)
4704 (defun gnus-article-prepare-display ()
4705 "Make the current buffer look like a nice article."
4706 ;; Hooks for getting information from the article.
4707 ;; This hook must be called before being narrowed.
4708 (let ((gnus-article-buffer (current-buffer))
4710 (inhibit-read-only t))
4711 (unless (eq major-mode 'gnus-article-mode)
4712 (gnus-article-mode))
4713 (setq buffer-read-only nil
4714 gnus-article-wash-types nil
4715 gnus-article-image-alist nil)
4716 (gnus-run-hooks 'gnus-tmp-internal-hook)
4717 (when gnus-display-mime-function
4718 (funcall gnus-display-mime-function))))
4721 ;;; Gnus Sticky Article Mode
4724 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4725 "Mode for sticky articles."
4726 ;; Release bindings that won't work.
4727 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4728 gnus-sticky-article-mode-map)
4729 (substitute-key-definition 'gnus-article-refer-article 'undefined
4730 gnus-sticky-article-mode-map)
4731 (dolist (k '("e" "h" "s" "F" "R"))
4732 (define-key gnus-sticky-article-mode-map k nil))
4733 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4734 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4735 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4736 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4738 (defun gnus-sticky-article (arg)
4739 "Make the current article sticky.
4740 If a prefix ARG is given, ask for a name for this sticky article buffer."
4742 (gnus-summary-show-thread)
4743 (gnus-summary-select-article nil nil 'pseudo)
4744 (let (new-art-buf-name)
4745 (gnus-eval-in-buffer-window gnus-article-buffer
4746 (setq new-art-buf-name
4750 (read-from-minibuffer "Sticky article buffer name: ")
4751 (gnus-with-article-headers
4752 (gnus-article-goto-header "subject")
4753 (setq new-art-buf-name
4754 (buffer-substring-no-properties
4755 (line-beginning-position) (line-end-position)))
4756 (goto-char (point-min))
4757 (gnus-article-goto-header "from")
4758 (setq new-art-buf-name
4760 new-art-buf-name ", "
4761 (buffer-substring-no-properties
4762 (line-beginning-position) (line-end-position))))
4763 (goto-char (point-min))
4764 (gnus-article-goto-header "date")
4765 (setq new-art-buf-name
4767 new-art-buf-name ", "
4768 (buffer-substring-no-properties
4769 (line-beginning-position) (line-end-position))))))
4771 (if (and (gnus-buffer-live-p new-art-buf-name)
4772 (with-current-buffer new-art-buf-name
4773 (eq major-mode 'gnus-sticky-article-mode)))
4774 (switch-to-buffer new-art-buf-name)
4775 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4776 (gnus-sticky-article-mode))
4777 (setq gnus-article-buffer new-art-buf-name))
4778 (gnus-summary-recenter)
4779 (gnus-summary-position-point))
4781 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4782 "Kill the given sticky article BUFFER.
4783 If none is given, assume the current buffer and kill it if it has
4784 `gnus-sticky-article-mode'."
4787 (setq buffer (current-buffer)))
4788 (with-current-buffer buffer
4789 (when (eq major-mode 'gnus-sticky-article-mode)
4790 (gnus-kill-buffer buffer))))
4792 (defun gnus-kill-sticky-article-buffers (arg)
4793 "Kill all sticky article buffers.
4794 If a prefix ARG is given, ask for confirmation."
4796 (dolist (buf (gnus-buffers))
4797 (with-current-buffer buf
4798 (when (eq major-mode 'gnus-sticky-article-mode)
4800 (gnus-kill-buffer buf)
4801 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4802 (gnus-kill-buffer buf)))))))
4805 ;;; Gnus MIME viewing functions
4808 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4809 "Format of the MIME buttons.
4811 Valid specifiers include:
4813 %T MIME type, along with additional info
4814 %n The `name' parameter
4815 %d The description, if any
4816 %l The length of the encoded part
4817 %p The part identifier number
4818 %e Dots if the part isn't displayed
4820 General format specifiers can also be used. See Info node
4821 `(gnus)Formatting Variables'.")
4823 (defvar gnus-mime-button-line-format-alist
4824 '((?t gnus-tmp-type ?s)
4825 (?T gnus-tmp-type-long ?s)
4826 (?n gnus-tmp-name ?s)
4827 (?d gnus-tmp-description ?s)
4829 (?l gnus-tmp-length ?d)
4830 (?e gnus-tmp-dots ?s)))
4832 (defvar gnus-mime-button-commands
4833 '((gnus-article-press-button "\r" "Toggle Display")
4834 (gnus-mime-view-part "v" "View Interactively...")
4835 (gnus-mime-view-part-as-type "t" "View As Type...")
4836 (gnus-mime-view-part-as-charset "C" "View As charset...")
4837 (gnus-mime-save-part "o" "Save...")
4838 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4839 (gnus-mime-replace-part "r" "Replace part")
4840 (gnus-mime-delete-part "d" "Delete part")
4841 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4842 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4843 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4844 (gnus-mime-view-part-externally "e" "View Externally")
4845 (gnus-mime-print-part "p" "Print")
4846 (gnus-mime-pipe-part "|" "Pipe To Command...")
4847 (gnus-mime-action-on-part "." "Take action on the part...")))
4849 (defun gnus-article-mime-part-status ()
4850 (if gnus-article-mime-handle-alist-1
4851 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4853 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4856 (defvar gnus-mime-button-map
4857 (let ((map (make-sparse-keymap)))
4858 (define-key map gnus-mouse-2 'gnus-article-push-button)
4859 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4860 (dolist (c gnus-mime-button-commands)
4861 (define-key map (cadr c) (car c)))
4865 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4867 ,@(mapcar (lambda (c)
4868 (vector (caddr c) (car c) :active t))
4869 gnus-mime-button-commands)))
4871 (defvar gnus-url-button-commands
4872 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4874 (defvar gnus-url-button-map
4875 (let ((map (make-sparse-keymap)))
4876 (dolist (c gnus-url-button-commands)
4877 (define-key map (cadr c) (car c)))
4881 gnus-url-button-menu gnus-url-button-map "URL button menu."
4883 ,@(mapcar (lambda (c)
4884 (vector (caddr c) (car c) :active t))
4885 gnus-url-button-commands)))
4887 (defmacro gnus-bind-safe-url-regexp (&rest body)
4888 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4889 `(let ((mm-w3m-safe-url-regexp
4890 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4892 gnus-article-current-summary))
4893 (with-current-buffer gnus-article-current-summary
4894 gnus-newsgroup-name)
4895 gnus-newsgroup-name)))
4896 (if (cond ((not group)
4897 ;; Maybe we're in a mml-preview buffer
4898 ;; and no group is selected.
4900 ((stringp gnus-safe-html-newsgroups)
4901 (string-match gnus-safe-html-newsgroups group))
4902 ((consp gnus-safe-html-newsgroups)
4903 (member group gnus-safe-html-newsgroups)))
4905 mm-w3m-safe-url-regexp))))
4908 (defun gnus-mime-button-menu (event prefix)
4909 "Construct a context-sensitive menu of MIME commands."
4910 (interactive "e\nP")
4911 (save-window-excursion
4912 (let ((pos (event-start event)))
4913 (select-window (posn-window pos))
4914 (goto-char (posn-point pos))
4915 (gnus-article-check-buffer)
4916 (popup-menu gnus-mime-button-menu nil prefix))))
4918 (defun gnus-mime-view-all-parts (&optional handles)
4919 "View all the MIME parts."
4921 (with-current-buffer gnus-article-buffer
4922 (let ((handles (or handles gnus-article-mime-handles))
4923 (mail-parse-charset gnus-newsgroup-charset)
4924 (mail-parse-ignored-charsets
4925 (with-current-buffer gnus-summary-buffer
4926 gnus-newsgroup-ignored-charsets)))
4928 (mm-remove-parts handles)
4929 (goto-char (point-min))
4930 (or (search-forward "\n\n") (goto-char (point-max)))
4931 (let ((inhibit-read-only t))
4932 (delete-region (point) (point-max))
4933 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4935 (defun gnus-article-jump-to-part (n)
4936 "Jump to MIME part N."
4938 (let ((parts (with-current-buffer gnus-article-buffer
4939 (length gnus-article-mime-handle-alist))))
4941 (error "No such part"))
4942 (pop-to-buffer gnus-article-buffer)
4944 (setq n (if (= parts 1)
4946 (read-number (format "Jump to part (1..%s): " parts)))))
4947 (unless (and (integerp n) (<= n parts) (>= n 1))
4950 (gnus-message 7 "Invalid part `%s', using %s instead."
4953 (gnus-message 9 "Jumping to part %s." n)
4954 (cond ((>= gnus-auto-select-part 1)
4955 (while (and (<= n parts)
4956 (not (gnus-article-goto-part n)))
4958 ((< gnus-auto-select-part 0)
4959 (while (and (>= n 1)
4960 (not (gnus-article-goto-part n)))
4963 (gnus-article-goto-part n)))))
4965 (defvar gnus-mime-buttonized-part-id nil
4966 "ID of a mime part that should be buttonized.
4967 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4970 (defsubst gnus-article-edit-part (handles &optional current-id)
4971 "Edit an article in order to delete a mime part.
4972 This function is exclusively used by `gnus-mime-save-part-and-strip'
4973 and `gnus-mime-delete-part', and not provided at run-time normally."
4974 (gnus-article-edit-article
4976 (buffer-disable-undo)
4978 (let ((mail-parse-charset (or gnus-article-charset
4979 ',gnus-newsgroup-charset))
4980 (mail-parse-ignored-charsets
4981 (or gnus-article-ignored-charsets
4982 ',gnus-newsgroup-ignored-charsets))
4983 (mbl mml-buffer-list))
4984 (setq mml-buffer-list nil)
4985 (insert-buffer-substring gnus-original-article-buffer)
4986 (mime-to-mml ',handles)
4987 (setq gnus-article-mime-handles nil)
4988 (let ((mbl1 mml-buffer-list))
4989 (setq mml-buffer-list mbl)
4990 (set (make-local-variable 'mml-buffer-list) mbl1))
4991 (gnus-make-local-hook 'kill-buffer-hook)
4992 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4993 `(lambda (no-highlight)
4994 (let ((mail-parse-charset (or gnus-article-charset
4995 ',gnus-newsgroup-charset))
4996 (message-options message-options)
4997 (message-options-set-recipient)
4998 (mail-parse-ignored-charsets
4999 (or gnus-article-ignored-charsets
5000 ',gnus-newsgroup-ignored-charsets)))
5002 (mml-destroy-buffers)
5003 (remove-hook 'kill-buffer-hook
5004 'mml-destroy-buffers t)
5005 (kill-local-variable 'mml-buffer-list))
5006 (gnus-summary-edit-article-done
5007 ,(or (mail-header-references gnus-current-headers) "")
5008 ,(gnus-group-read-only-p)
5009 ,gnus-summary-buffer no-highlight))
5011 ;; Force buttonizing this part.
5012 (let ((gnus-mime-buttonized-part-id current-id))
5013 (gnus-article-edit-done))
5014 (gnus-configure-windows 'article)
5015 (when (and current-id (integerp gnus-auto-select-part))
5016 (gnus-article-jump-to-part
5017 (min (max (+ current-id gnus-auto-select-part) 1)
5018 (with-current-buffer gnus-article-buffer
5019 (length gnus-article-mime-handle-alist)))))))
5021 (defun gnus-mime-replace-part (file)
5022 "Replace MIME part under point with an external body."
5023 ;; Useful if file has already been saved to disk
5026 (read-file-name "Replace MIME part with file: "
5027 (or mm-default-directory default-directory)
5029 (gnus-mime-save-part-and-strip file))
5031 (defun gnus-mime-save-part-and-strip (&optional file)
5032 "Save the MIME part under point then replace it with an external body.
5033 If FILE is given, use it for the external part."
5035 (gnus-article-check-buffer)
5036 (when (gnus-group-read-only-p)
5037 (error "The current group does not support deleting of parts"))
5038 (when (mm-complicated-handles gnus-article-mime-handles)
5040 The current article has a complicated MIME structure, giving up..."))
5041 (let* ((data (get-text-property (point) 'gnus-data))
5042 (id (get-text-property (point) 'gnus-part))
5044 (handles gnus-article-mime-handles))
5047 (and data (mm-save-part data "Delete MIME part and save to: "))))
5049 (with-current-buffer (mm-handle-buffer data)
5051 (insert "Content-Type: " (mm-handle-media-type data))
5052 (mml-insert-parameter-string (cdr (mm-handle-type data))
5054 ;; Add a filename for the sake of saving the part again.
5055 (mml-insert-parameter
5056 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5058 (insert "Content-ID: " (message-make-message-id) "\n")
5059 (insert "Content-Transfer-Encoding: binary\n")
5062 (cdr (mm-make-handle nil
5063 `("message/external-body"
5064 (access-type . "LOCAL-FILE")
5066 ;; (set-buffer gnus-summary-buffer)
5067 (gnus-article-edit-part handles id))))
5069 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5070 ;; parts...>') but with stripping would be nice.
5072 (defun gnus-mime-delete-part ()
5073 "Delete the MIME part under point.
5074 Replace it with some information about the removed part."
5076 (gnus-article-check-buffer)
5077 (when (gnus-group-read-only-p)
5078 (error "The current group does not support deleting of parts"))
5079 (when (mm-complicated-handles gnus-article-mime-handles)
5081 The current article has a complicated MIME structure, giving up..."))
5082 (when (or gnus-expert-user
5083 (gnus-yes-or-no-p "\
5084 Deleting parts may malfunction or destroy the article; continue? "))
5085 (let* ((data (get-text-property (point) 'gnus-data))
5086 (id (get-text-property (point) 'gnus-part))
5087 (handles gnus-article-mime-handles)
5089 (let ((desc (mm-handle-description data)))
5091 (mail-decode-encoded-word-string desc))))
5092 (filename (or (mm-handle-filename data) "(none)"))
5093 (type (mm-handle-media-type data)))
5095 (error "No MIME part under point"))
5096 (with-current-buffer (mm-handle-buffer data)
5097 (let ((bsize (buffer-size)))
5102 "| The following attachment has been deleted:\n"
5104 "| Type: " type "\n"
5105 "| Filename: " filename "\n"
5106 "| Size (encoded): " (format "%s byte%s\n"
5107 bsize (if (= bsize 1)
5111 (concat "| Description: " description "\n"))
5114 (cdr (mm-make-handle
5115 nil `("text/plain" (charset . gnus-decoded)) nil nil
5117 (format "Deleted attachment (%s bytes)" bsize))))))
5118 ;; (set-buffer gnus-summary-buffer)
5119 (gnus-article-edit-part handles id))))
5121 (defun gnus-mime-save-part ()
5122 "Save the MIME part under point."
5124 (gnus-article-check-buffer)
5125 (let ((data (get-text-property (point) 'gnus-data)))
5127 (mm-save-part data))))
5129 (defun gnus-mime-pipe-part (&optional cmd)
5130 "Pipe the MIME part under point to a process.
5131 Use CMD as the process."
5133 (gnus-article-check-buffer)
5134 (let ((data (get-text-property (point) 'gnus-data)))
5136 (mm-pipe-part data cmd))))
5138 (defun gnus-mime-view-part ()
5139 "Interactively choose a viewing method for the MIME part under point."
5141 (gnus-article-check-buffer)
5142 (let ((data (get-text-property (point) 'gnus-data)))
5144 (setq gnus-article-mime-handles
5146 gnus-article-mime-handles (setq data (copy-sequence data))))
5147 (mm-interactively-view-part data))))
5149 (defun gnus-mime-view-part-as-type-internal ()
5150 (gnus-article-check-buffer)
5151 (let* ((handle (get-text-property (point) 'gnus-data))
5153 ;; Content-Type: foo/bar; name=...
5154 (mail-content-type-get (mm-handle-type handle) 'name)
5155 ;; Content-Disposition: attachment; filename=...
5156 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5157 (def-type (and name (mm-default-file-encoding name))))
5158 (or (and def-type (cons def-type 0))
5160 (equal (mm-handle-media-supertype handle) "text")
5161 '("text/plain" . 0))
5162 '("application/octet-stream" . 0))))
5164 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5165 "Choose a MIME media type, and view the part as such.
5166 If non-nil, PRED is a predicate to use during completion to limit the
5167 available media-types."
5171 (let ((default (gnus-mime-view-part-as-type-internal)))
5172 (gnus-completing-read
5175 (gnus-remove-if-not pred (mailcap-mime-types))
5176 (mailcap-mime-types))
5179 (gnus-article-check-buffer)
5180 (let ((handle (get-text-property (point) 'gnus-data)))
5182 (when (equal (mm-handle-media-type handle) "message/external-body")
5183 (unless (mm-handle-cache handle)
5184 (mm-extern-cache-contents handle))
5185 (setq handle (mm-handle-cache handle)))
5187 (mm-make-handle (mm-handle-buffer handle)
5188 (cons mime-type (cdr (mm-handle-type handle)))
5189 (mm-handle-encoding handle)
5190 (mm-handle-undisplayer handle)
5191 (mm-handle-disposition handle)
5192 (mm-handle-description handle)
5194 (mm-handle-id handle)))
5195 (setq gnus-article-mime-handles
5196 (mm-merge-handles gnus-article-mime-handles handle))
5197 (when (mm-handle-displayed-p handle)
5198 (mm-remove-part handle))
5199 (gnus-mm-display-part handle))))
5201 (defun gnus-mime-copy-part (&optional handle arg)
5202 "Put the MIME part under point into a new buffer.
5203 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5205 (interactive (list nil current-prefix-arg))
5206 (gnus-article-check-buffer)
5208 (setq handle (get-text-property (point) 'gnus-data)))
5210 (let ((filename (mm-handle-filename handle))
5211 contents dont-decode charset coding-system)
5212 (mm-with-unibyte-buffer
5213 (mm-insert-part handle)
5214 (setq contents (or (condition-case nil
5215 (mm-decompress-buffer filename nil 'sig)
5217 (setq dont-decode t)
5220 (setq filename (cond (filename (file-name-nondirectory filename))
5221 (dont-decode "*raw data*")
5226 (unless (setq charset (mail-content-type-get
5227 (mm-handle-type handle) 'charset))
5228 (unless (setq coding-system (mm-with-unibyte-buffer
5230 (mm-find-buffer-file-coding-system)))
5231 (setq charset gnus-newsgroup-charset))))
5233 (setq charset (or (cdr (assq arg
5234 gnus-summary-show-article-charset-alist))
5235 (mm-read-coding-system "Charset: ")))))
5236 (switch-to-buffer (generate-new-buffer filename))
5237 (if (or coding-system
5239 (setq coding-system (mm-charset-to-coding-system charset))
5240 (not (eq coding-system 'ascii))))
5242 (mm-enable-multibyte)
5243 (insert (mm-decode-coding-string contents coding-system))
5244 (setq buffer-file-coding-system
5245 (if (boundp 'last-coding-system-used)
5246 (symbol-value 'last-coding-system-used)
5248 (mm-disable-multibyte)
5250 (setq buffer-file-coding-system mm-binary-coding-system))
5251 ;; We do it this way to make `normal-mode' set the appropriate mode.
5254 (setq buffer-file-name (expand-file-name filename))
5256 (setq buffer-file-name nil))
5257 (goto-char (point-min)))))
5259 (defun gnus-mime-print-part (&optional handle filename)
5260 "Print the MIME part under point."
5261 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5262 (gnus-article-check-buffer)
5263 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5264 (contents (and handle (mm-get-part handle)))
5265 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5266 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5271 (mm-save-part-to-file handle file)
5272 (call-process shell-file-name nil
5273 (generate-new-buffer " *mm*")
5275 shell-command-switch
5277 printer file (mm-handle-type handle))))
5281 (gnus-print-buffer))
5282 (ps-despool filename)))))
5284 (defun gnus-mime-inline-part (&optional handle arg)
5285 "Insert the MIME part under point into the current buffer.
5286 Compressed files like .gz and .bz2 are decompressed."
5287 (interactive (list nil current-prefix-arg))
5288 (gnus-article-check-buffer)
5290 (setq handle (get-text-property (point) 'gnus-data)))
5293 (inhibit-read-only t)
5294 contents charset coding-system)
5295 (if (and (not arg) (mm-handle-undisplayer handle))
5296 (mm-remove-part handle)
5297 (mm-with-unibyte-buffer
5298 (mm-insert-part handle)
5300 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5304 (unless (setq charset (mail-content-type-get
5305 (mm-handle-type handle) 'charset))
5306 (unless (setq coding-system
5307 (mm-with-unibyte-buffer
5309 (mm-find-buffer-file-coding-system)))
5310 (setq charset gnus-newsgroup-charset))))
5312 (if (mm-handle-undisplayer handle)
5313 (mm-remove-part handle))
5316 gnus-summary-show-article-charset-alist))
5317 (mm-read-coding-system "Charset: "))))
5319 (if (mm-handle-undisplayer handle)
5320 (mm-remove-part handle))))
5322 (mm-display-inline handle)
5325 (defun gnus-mime-set-charset-parameters (handle charset)
5326 "Set CHARSET to parameters in HANDLE.
5327 CHARSET may either be a string or a symbol."
5328 (unless (stringp charset)
5329 (setq charset (symbol-name charset)))
5330 (if (stringp (car handle))
5331 (dolist (h (cdr handle))
5332 (gnus-mime-set-charset-parameters h charset))
5333 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5334 "message/external-body")
5336 (unless (mm-handle-cache handle)
5337 (mm-extern-cache-contents handle))
5338 (mm-handle-cache handle))
5340 (param (assq 'charset (cdr type))))
5342 (setcdr param charset)
5343 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5345 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5346 "Insert the MIME part under point into the current buffer using the
5348 (interactive (list nil current-prefix-arg))
5349 (gnus-article-check-buffer)
5350 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5351 (fun (get-text-property (point) 'gnus-callback))
5352 (gnus-newsgroup-ignored-charsets 'gnus-all)
5353 charset form preferred parts)
5360 gnus-summary-show-article-charset-alist))
5361 (mm-read-coding-system "Charset: "))))
5362 (if (mm-handle-undisplayer handle)
5363 (mm-remove-part handle)))
5364 (gnus-mime-set-charset-parameters handle charset)
5365 (when (and (consp (setq form (cdr-safe fun)))
5366 (setq form (ignore-errors
5367 (assq 'gnus-mime-display-alternative form)))
5368 (setq preferred (caddr form))
5370 (when (eq (car preferred) 'quote)
5371 (setq preferred (cadr preferred)))
5372 (not (equal preferred
5373 (get-text-property (point) 'gnus-data))))
5374 (setq parts (get-text-property (point) 'gnus-part))
5375 (setq parts (cdr (assq parts
5376 gnus-article-mime-handle-alist)))
5377 (equal (mm-handle-media-type parts) "multipart/alternative")
5378 (setq parts (reverse (cdr parts))))
5380 (list 'quote (or (cadr (member preferred parts))
5382 (funcall fun handle)))))
5384 (defun gnus-mime-view-part-externally (&optional handle)
5385 "View the MIME part under point with an external viewer."
5387 (gnus-article-check-buffer)
5388 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5389 (mm-user-display-methods nil)
5390 (mm-inlined-types nil)
5391 (mail-parse-charset gnus-newsgroup-charset)
5392 (mail-parse-ignored-charsets
5393 (with-current-buffer gnus-summary-buffer
5394 gnus-newsgroup-ignored-charsets))
5395 (type (mm-handle-media-type handle))
5396 (method (mailcap-mime-info type))
5397 (mm-enable-external t))
5398 (if (not (stringp method))
5399 (gnus-mime-view-part-as-type
5400 nil (lambda (type) (stringp (mailcap-mime-info type))))
5402 (mm-display-part handle nil t)))))
5404 (defun gnus-mime-view-part-internally (&optional handle)
5405 "View the MIME part under point with an internal viewer.
5406 If no internal viewer is available, use an external viewer."
5408 (gnus-article-check-buffer)
5409 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5410 (mm-inlined-types '(".*"))
5411 (mm-inline-large-images t)
5412 (mail-parse-charset gnus-newsgroup-charset)
5413 (mail-parse-ignored-charsets
5414 (with-current-buffer gnus-summary-buffer
5415 gnus-newsgroup-ignored-charsets))
5416 (inhibit-read-only t))
5417 (if (not (mm-inlinable-p handle))
5418 (gnus-mime-view-part-as-type
5419 nil (lambda (type) (mm-inlinable-p handle type)))
5421 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5423 (defun gnus-mime-action-on-part (&optional action)
5424 "Do something with the MIME attachment at \(point\)."
5426 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5427 (gnus-article-check-buffer)
5428 (let ((action-pair (assoc action gnus-mime-action-alist)))
5430 (funcall (cdr action-pair)))))
5432 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5433 "Call FUNCTION on MIME part N.
5434 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5435 If INTERACTIVE, call FUNCTION interactively."
5437 ;; Check whether the article is displayed.
5438 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5439 (setq window (get-buffer-window gnus-article-buffer t))
5440 (frame-visible-p (setq frame (window-frame window))))
5441 (error "No article is displayed"))
5442 (with-current-buffer gnus-article-buffer
5443 ;; Check whether the article displays the right contents.
5444 (unless (with-current-buffer gnus-summary-buffer
5445 (eq gnus-current-article (gnus-summary-article-number)))
5446 (error "You should select the right article first"))
5448 (setq n (prefix-numeric-value n))
5450 (setq n (or (get-text-property pt 'gnus-part)
5452 (get-text-property (1- pt) 'gnus-part))
5453 (get-text-property (prog2
5459 (or (and (setq pt (previous-single-property-change
5462 (next-single-property-change (point) 'gnus-part)
5466 ;; Check whether the specified part exists.
5467 (when (> n (length gnus-article-mime-handle-alist))
5468 (error "No such part")))
5471 ;; To select the window is needed so that the cursor
5472 ;; might be visible on the MIME button.
5473 (select-window (prog1
5475 (setq window (selected-window))
5476 ;; Article may be displayed in the other frame.
5477 (gnus-select-frame-set-input-focus
5480 (setq frame (selected-frame))))))
5481 (when (gnus-article-goto-part n)
5482 ;; We point the cursor and the arrow at the MIME button
5483 ;; when the `function' prompt the user for something.
5484 (unless (and (pos-visible-in-window-p)
5485 (> (count-lines (point) (window-end))
5486 (/ (1- (window-height)) 3)))
5487 (recenter (/ (1- (window-height)) 3)))
5488 (let ((cursor-in-non-selected-windows t)
5489 (overlay-arrow-string "=>")
5490 (overlay-arrow-position (point-marker)))
5493 ((and no-handle interactive)
5494 (call-interactively function))
5499 function (get-text-property (point) 'gnus-data)))
5502 (get-text-property (point) 'gnus-data))))
5503 (set-marker overlay-arrow-position nil)
5504 (unless gnus-auto-select-part
5505 (gnus-select-frame-set-input-focus frame)
5506 (select-window window))))
5508 (if gnus-inhibit-mime-unbuttonizing
5509 ;; This is the default though the program shouldn't reach here.
5510 (error "No such part")
5511 ;; The part which doesn't have the MIME button is selected.
5512 ;; So, we display all the buttons and redo it.
5513 (let ((gnus-inhibit-mime-unbuttonizing t))
5514 (gnus-summary-show-article)
5515 (gnus-article-part-wrapper n function no-handle))))))
5517 (defun gnus-article-pipe-part (n)
5518 "Pipe MIME part N, which is the numerical prefix."
5520 (gnus-article-part-wrapper n 'mm-pipe-part))
5522 (defun gnus-article-save-part (n)
5523 "Save MIME part N, which is the numerical prefix."
5525 (gnus-article-part-wrapper n 'mm-save-part))
5527 (defun gnus-article-interactively-view-part (n)
5528 "View MIME part N interactively, which is the numerical prefix."
5530 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5532 (defun gnus-article-copy-part (n)
5533 "Copy MIME part N, which is the numerical prefix."
5535 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5537 (defun gnus-article-view-part-as-charset (n)
5538 "View MIME part N using a specified charset.
5539 N is the numerical prefix."
5541 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5543 (defun gnus-article-view-part-externally (n)
5544 "View MIME part N externally, which is the numerical prefix."
5546 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5548 (defun gnus-article-inline-part (n)
5549 "Inline MIME part N, which is the numerical prefix."
5551 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5553 (defun gnus-article-save-part-and-strip (n)
5554 "Save MIME part N and replace it with an external body.
5555 N is the numerical prefix."
5557 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5559 (defun gnus-article-replace-part (n)
5560 "Replace MIME part N with an external body.
5561 N is the numerical prefix."
5563 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5565 (defun gnus-article-delete-part (n)
5566 "Delete MIME part N and add some information about the removed part.
5567 N is the numerical prefix."
5569 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5571 (defun gnus-article-view-part-as-type (n)
5572 "Choose a MIME media type, and view part N as such.
5573 N is the numerical prefix."
5575 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5577 (defun gnus-article-mime-match-handle-first (condition)
5580 (dolist (ihandle gnus-article-mime-handle-alist)
5582 ((functionp condition)
5583 (funcall condition (cdr ihandle)))
5584 ((eq condition 'undisplayed)
5585 (not (or (mm-handle-undisplayer (cdr ihandle))
5586 (equal (mm-handle-media-type (cdr ihandle))
5587 "multipart/alternative"))))
5588 ((eq condition 'undisplayed-alternative)
5589 (not (mm-handle-undisplayer (cdr ihandle))))
5591 (gnus-article-goto-part (car ihandle))
5592 (or (not n) (< (car ihandle) n)))
5593 (setq n (car ihandle))))
5597 (defun gnus-article-view-part (&optional n)
5598 "View MIME part N, which is the numerical prefix.
5599 If the part is already shown, hide the part. If N is nil, view
5602 (with-current-buffer gnus-article-buffer
5603 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5604 gnus-article-mime-match-handle-function)))
5605 (when (> n (length gnus-article-mime-handle-alist))
5606 (error "No such part"))
5607 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5608 (when (gnus-article-goto-part n)
5609 (if (equal (car handle) "multipart/alternative")
5610 (gnus-article-press-button)
5611 (when (eq (gnus-mm-display-part handle) 'internal)
5612 (gnus-set-window-start)))))))
5614 (defsubst gnus-article-mime-total-parts ()
5615 (if (bufferp (car gnus-article-mime-handles))
5617 (1- (length gnus-article-mime-handles))))
5619 (defun gnus-mm-display-part (handle)
5620 "Display HANDLE and fix MIME button."
5621 (let ((id (get-text-property (point) 'gnus-part))
5623 (inhibit-read-only t))
5626 (let ((window (selected-window))
5627 (mail-parse-charset gnus-newsgroup-charset)
5628 (mail-parse-ignored-charsets
5629 (if (gnus-buffer-live-p gnus-summary-buffer)
5630 (with-current-buffer gnus-summary-buffer
5631 gnus-newsgroup-ignored-charsets)
5635 (let ((win (gnus-get-buffer-window (current-buffer) t))
5638 (select-window win))
5641 (if (mm-handle-displayed-p handle)
5642 ;; This will remove the part.
5643 (mm-display-part handle)
5645 (narrow-to-region (point)
5646 (if (eobp) (point) (1+ (point))))
5647 (gnus-bind-safe-url-regexp (mm-display-part handle))
5648 ;; We narrow to the part itself and
5649 ;; then call the treatment functions.
5650 (goto-char (point-min))
5652 (narrow-to-region (point) (point-max))
5655 (gnus-article-mime-total-parts)
5656 (mm-handle-media-type handle)))))
5657 (if (window-live-p window)
5658 (select-window window)))))
5661 (gnus-insert-mime-button
5662 handle id (list (mm-handle-displayed-p handle)))
5663 (goto-char point))))
5665 (defun gnus-article-goto-part (n)
5666 "Go to MIME part N."
5667 (when gnus-break-pages
5670 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5671 part handle end next handles)
5674 (if (setq handle (get-text-property start 'gnus-data))
5676 ;; Go to the displayed subpart, assuming this is
5677 ;; multipart/alternative.
5680 (while (and (not handle)
5683 (setq next (text-property-not-all part end
5686 handle (get-text-property part 'gnus-data))
5687 (push (cons handle part) handles)
5688 (unless (mm-handle-displayed-p handle)
5690 part (text-property-any part end 'gnus-data nil))))
5692 ;; No subpart is displayed, so we find preferred one.
5694 (cdr (assq (mm-preferred-alternative
5695 (nreverse (mapcar 'car handles)))
5698 (goto-char (1+ part))
5700 (when gnus-break-pages
5701 (gnus-narrow-to-page))))
5703 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5704 (let ((gnus-tmp-name
5705 (or (mm-handle-filename handle)
5706 (mail-content-type-get (mm-handle-type handle) 'url)
5708 (gnus-tmp-type (mm-handle-media-type handle))
5709 (gnus-tmp-description (or (mm-handle-description handle) ""))
5711 (if (if displayed (car displayed)
5712 (mm-handle-displayed-p handle))
5714 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5716 gnus-tmp-type-long b e)
5717 (when (string-match ".*/" gnus-tmp-name)
5718 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5719 (setq gnus-tmp-type-long (concat gnus-tmp-type
5720 (and (not (equal gnus-tmp-name ""))
5721 (concat "; " gnus-tmp-name))))
5722 (unless (equal gnus-tmp-description "")
5723 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5728 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5729 `(keymap ,gnus-mime-button-map
5730 gnus-callback gnus-mm-display-part
5731 gnus-part ,gnus-tmp-id
5732 article-type annotation
5736 ;; Exclude a newline.
5739 (when gnus-article-button-face
5740 (gnus-overlay-put (gnus-make-overlay b e nil t)
5741 'face gnus-article-button-face))
5742 (widget-convert-button
5745 :action 'gnus-widget-press-button
5746 :button-keymap gnus-mime-button-map
5749 ;; Needed to properly clear the message due to a bug in
5750 ;; wid-edit (XEmacs only).
5751 (if (boundp 'help-echo-owns-message)
5752 (setq help-echo-owns-message t))
5754 "%S: %s the MIME part; %S: more options"
5755 (aref gnus-mouse-2 0)
5756 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5758 (aref gnus-down-mouse-3 0))))))
5760 (defun gnus-widget-press-button (elems el)
5761 (goto-char (widget-get elems :from))
5762 (gnus-article-press-button))
5764 (defvar gnus-displaying-mime nil)
5766 (defun gnus-display-mime (&optional ihandles)
5767 "Display the MIME parts."
5769 (save-selected-window
5770 (let ((window (get-buffer-window gnus-article-buffer))
5773 (select-window window)
5774 ;; We have to do this since selecting the window
5775 ;; may change the point. So we set the window point.
5776 (set-window-point window point)))
5777 (let ((handles ihandles)
5778 (inhibit-read-only t)
5781 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5782 (when gnus-article-emulate-mime
5783 (mm-uu-dissect-text-parts handles)))
5784 (gnus-article-emulate-mime
5785 (setq handles (mm-uu-dissect))))
5786 (when (and (not ihandles)
5787 (not gnus-displaying-mime))
5788 ;; Top-level call; we clean up.
5789 (when gnus-article-mime-handles
5790 (mm-destroy-parts gnus-article-mime-handles)
5791 (setq gnus-article-mime-handle-alist nil));; A trick.
5792 (setq gnus-article-mime-handles handles)
5793 ;; We allow users to glean info from the handles.
5794 (when gnus-article-mime-part-function
5795 (gnus-mime-part-function handles)))
5797 (or (not (stringp (car handles)))
5800 (when (and (not ihandles)
5801 (not gnus-displaying-mime))
5802 ;; Clean up for mime parts.
5804 (delete-region (point) (point-max)))
5805 (let ((gnus-displaying-mime t))
5806 (gnus-mime-display-part handles)))
5809 (narrow-to-region (point) (point-max))
5810 (gnus-treat-article nil 1 1 "text/plain")
5813 ;; Highlight the headers.
5817 (narrow-to-region (point-min) (point))
5818 (gnus-article-save-original-date
5819 (gnus-treat-article 'head)))))))
5820 ;; Cope with broken MIME messages.
5821 (goto-char (point-max))
5825 (defcustom gnus-mime-display-multipart-as-mixed nil
5826 "Display \"multipart\" parts as \"multipart/mixed\".
5828 If t, it overrides nil values of
5829 `gnus-mime-display-multipart-alternative-as-mixed' and
5830 `gnus-mime-display-multipart-related-as-mixed'."
5831 :group 'gnus-article-mime
5834 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5835 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5837 :group 'gnus-article-mime
5840 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5841 "Display \"multipart/related\" parts as \"multipart/mixed\".
5843 If displaying \"text/html\" is discouraged \(see
5844 `mm-discouraged-alternatives'\) images or other material inside a
5845 \"multipart/related\" part might be overlooked when this variable is nil."
5847 :group 'gnus-article-mime
5850 (defun gnus-mime-display-part (handle)
5852 ;; Maybe a broken MIME message.
5855 ((not (stringp (car handle)))
5856 (gnus-mime-display-single handle))
5857 ;; User-defined multipart
5858 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5859 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5861 ;; multipart/alternative
5862 ((and (equal (car handle) "multipart/alternative")
5863 (not (or gnus-mime-display-multipart-as-mixed
5864 gnus-mime-display-multipart-alternative-as-mixed)))
5865 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5866 (push (cons id handle) gnus-article-mime-handle-alist)
5867 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5868 ;; multipart/related
5869 ((and (equal (car handle) "multipart/related")
5870 (not (or gnus-mime-display-multipart-as-mixed
5871 gnus-mime-display-multipart-related-as-mixed)))
5872 ;;;!!!We should find the start part, but we just default
5873 ;;;!!!to the first part.
5874 ;;(gnus-mime-display-part (cadr handle))
5875 ;;;!!! Most multipart/related is an HTML message plus images.
5876 ;;;!!! Unfortunately we are unable to let W3 display those
5877 ;;;!!! included images, so we just display it as a mixed multipart.
5878 ;;(gnus-mime-display-mixed (cdr handle))
5879 ;;;!!! No, w3 can display everything just fine.
5880 (gnus-mime-display-part (cadr handle)))
5881 ((equal (car handle) "multipart/signed")
5882 (gnus-add-wash-type 'signed)
5883 (gnus-mime-display-security handle))
5884 ((equal (car handle) "multipart/encrypted")
5885 (gnus-add-wash-type 'encrypted)
5886 (gnus-mime-display-security handle))
5887 ;; Other multiparts are handled like multipart/mixed.
5889 (gnus-mime-display-mixed (cdr handle)))))
5891 (defun gnus-mime-part-function (handles)
5892 (if (stringp (car handles))
5893 (mapcar 'gnus-mime-part-function (cdr handles))
5894 (funcall gnus-article-mime-part-function handles)))
5896 (defun gnus-mime-display-mixed (handles)
5897 (mapcar 'gnus-mime-display-part handles))
5899 (defun gnus-mime-display-single (handle)
5900 (let ((type (mm-handle-media-type handle))
5901 (ignored gnus-ignored-mime-types)
5908 (when (string-match (pop ignored) type)
5909 (throw 'ignored nil)))
5910 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5911 (with-current-buffer gnus-summary-buffer
5912 gnus-inhibit-images)
5913 gnus-inhibit-images)
5914 (string-match "\\`image/" type)))
5915 (setq not-attachment
5916 (and (not (mm-inline-override-p handle))
5917 (or (not (mm-handle-disposition handle))
5918 (equal (car (mm-handle-disposition handle))
5920 (mm-attachment-override-p handle))))
5921 (mm-automatic-display-p handle)
5923 (mm-inlinable-p handle)
5924 (mm-inlined-p handle))
5925 (mm-automatic-external-display-p type)))
5927 (when (equal (mm-handle-media-supertype handle) "text")
5929 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5931 (push (cons id handle) gnus-article-mime-handle-alist)
5933 (equal (mm-handle-media-supertype handle) "message"))
5936 (cond ((not (bolp)) 2)
5937 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5939 (when (or (not display)
5940 (not (gnus-unbuttonized-mime-type-p type))
5941 (eq id gnus-mime-buttonized-part-id))
5942 (gnus-insert-mime-button
5943 handle id (list (or display (and not-attachment text))))
5944 (gnus-article-insert-newline)
5945 ;; Remember modify the number of forward lines.
5953 (let ((mail-parse-charset gnus-newsgroup-charset)
5954 (mail-parse-ignored-charsets
5955 (save-excursion (condition-case ()
5956 (set-buffer gnus-summary-buffer)
5958 gnus-newsgroup-ignored-charsets)))
5959 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5960 (goto-char (point-max)))
5961 ((and text not-attachment)
5965 (gnus-article-insert-newline)
5966 (mm-display-inline handle)
5967 (goto-char (point-max))))
5971 (narrow-to-region beg (point))
5972 (if (eq handle gnus-article-mime-handles)
5973 ;; The format=flowed case.
5974 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5975 ;; Don't count signature parts that are never displayed.
5976 ;; The part number should be re-calculated supposing this
5977 ;; might be a message/rfc822 part.
5979 (dolist (part gnus-article-mime-handles)
5980 (unless (or (stringp part)
5981 (equal (car (mm-handle-type part))
5982 "application/pgp-signature"))
5983 (push part handles)))
5985 nil (length (memq handle handles)) (length handles)
5986 (mm-handle-media-type handle)))))))))))
5988 (defun gnus-unbuttonized-mime-type-p (type)
5989 "Say whether TYPE is to be unbuttonized."
5990 (unless gnus-inhibit-mime-unbuttonizing
5992 (let ((types gnus-unbuttonized-mime-types))
5994 (when (string-match (pop types) type)
5995 (throw 'found t)))))
5997 (let ((types gnus-buttonized-mime-types))
5999 (when (string-match (pop types) type)
6000 (throw 'found t)))))))))
6002 (defun gnus-article-insert-newline ()
6003 "Insert a newline, but mark it as undeletable."
6004 (gnus-put-text-property
6005 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6007 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6008 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6011 handle (inhibit-read-only t) from props begend not-pref)
6012 (save-window-excursion
6015 (narrow-to-region (car ibegend)
6018 (goto-char (car ibegend))
6021 (delete-region (point-min) (point-max))
6022 (mm-remove-parts handles))
6023 (setq begend (list (point-marker)))
6025 (unless (setq not-pref (cadr (member preferred ihandles)))
6026 (setq not-pref (car ihandles)))
6029 (not (gnus-unbuttonized-mime-type-p
6030 "multipart/alternative")))
6031 (gnus-add-text-properties
6034 (insert (format "%d. " id))
6038 (unless ,(not ibegend)
6039 (setq gnus-article-mime-handle-alist
6040 ',gnus-article-mime-handle-alist))
6041 (gnus-mime-display-alternative
6042 ',ihandles ',not-pref ',begend ,id))
6043 keymap ,gnus-mime-button-map
6044 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6045 face ,gnus-article-button-face
6047 article-type multipart
6049 (widget-convert-button 'link from (point)
6050 :action 'gnus-widget-press-button
6051 :button-keymap gnus-widget-button-keymap)
6053 (while (setq handle (pop handles))
6054 (gnus-add-text-properties
6057 (insert (format "(%c) %-18s"
6058 (if (equal handle preferred) ?* ? )
6059 (mm-handle-media-type handle)))
6063 (unless ,(not ibegend)
6064 (setq gnus-article-mime-handle-alist
6065 ',gnus-article-mime-handle-alist))
6066 (gnus-mime-display-alternative
6067 ',ihandles ',handle ',begend ,id))
6068 keymap ,gnus-mime-button-map
6069 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6070 face ,gnus-article-button-face
6074 (widget-convert-button 'link from (point)
6075 :action 'gnus-widget-press-button
6076 :button-keymap gnus-widget-button-keymap)
6080 (if (stringp (car preferred))
6081 (gnus-display-mime preferred)
6082 (let ((mail-parse-charset gnus-newsgroup-charset)
6083 (mail-parse-ignored-charsets
6084 (with-current-buffer gnus-summary-buffer
6085 gnus-newsgroup-ignored-charsets)))
6086 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6090 (narrow-to-region (car begend) (point-max))
6092 nil (length gnus-article-mime-handle-alist)
6093 (gnus-article-mime-total-parts)
6094 (mm-handle-media-type preferred))))))
6095 (goto-char (point-max))
6096 (setcdr begend (point-marker)))))
6098 (goto-char point))))
6100 (defconst gnus-article-wash-status-strings
6101 (let ((alist '((cite "c" "Possible hidden citation text"
6102 " " "All citation text visible")
6103 (headers "h" "Hidden headers"
6104 " " "All headers visible.")
6105 (pgp "p" "Encrypted or signed message status hidden"
6106 " " "No hidden encryption nor digital signature status")
6107 (signature "s" "Signature has been hidden"
6108 " " "Signature is visible")
6109 (overstrike "o" "Overstrike (^H) characters applied"
6110 " " "No overstrike characters applied")
6111 (emphasis "e" "/*_Emphasis_*/ characters applied"
6112 " " "No /*_emphasis_*/ characters applied")))
6114 (dolist (entry alist result)
6115 (let ((key (nth 0 entry))
6116 (on (copy-sequence (nth 1 entry)))
6117 (on-help (nth 2 entry))
6118 (off (copy-sequence (nth 3 entry)))
6119 (off-help (nth 4 entry)))
6120 (put-text-property 0 1 'help-echo on-help on)
6121 (put-text-property 0 1 'help-echo off-help off)
6122 (push (list key on off) result))))
6123 "Alist of strings describing wash status in the mode line.
6124 Each entry has the form (KEY ON OF), where the KEY is a symbol
6125 representing the particular washing function, ON is the string to use
6126 in the article mode line when the washing function is active, and OFF
6127 is the string to use when it is inactive.")
6129 (defun gnus-article-wash-status-entry (key value)
6130 (let ((entry (assoc key gnus-article-wash-status-strings)))
6131 (if value (nth 1 entry) (nth 2 entry))))
6133 (defun gnus-article-wash-status ()
6134 "Return a string which display status of article washing."
6135 (with-current-buffer gnus-article-buffer
6136 (let ((cite (memq 'cite gnus-article-wash-types))
6137 (headers (memq 'headers gnus-article-wash-types))
6138 (boring (memq 'boring-headers gnus-article-wash-types))
6139 (pgp (memq 'pgp gnus-article-wash-types))
6140 (pem (memq 'pem gnus-article-wash-types))
6141 (signed (memq 'signed gnus-article-wash-types))
6142 (encrypted (memq 'encrypted gnus-article-wash-types))
6143 (signature (memq 'signature gnus-article-wash-types))
6144 (overstrike (memq 'overstrike gnus-article-wash-types))
6145 (emphasis (memq 'emphasis gnus-article-wash-types)))
6147 (gnus-article-wash-status-entry 'cite cite)
6148 (gnus-article-wash-status-entry 'headers (or headers boring))
6149 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6150 (gnus-article-wash-status-entry 'signature signature)
6151 (gnus-article-wash-status-entry 'overstrike overstrike)
6152 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6154 (defun gnus-add-wash-type (type)
6155 "Add a washing of TYPE to the current status."
6156 (add-to-list 'gnus-article-wash-types type))
6158 (defun gnus-delete-wash-type (type)
6159 "Add a washing of TYPE to the current status."
6160 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6162 (defun gnus-add-image (category image)
6163 "Add IMAGE of CATEGORY to the list of displayed images."
6164 (let ((entry (assq category gnus-article-image-alist)))
6166 (setq entry (list category))
6167 (push entry gnus-article-image-alist))
6168 (nconc entry (list image))))
6170 (defun gnus-delete-images (category)
6171 "Delete all images in CATEGORY."
6172 (let ((entry (assq category gnus-article-image-alist)))
6173 (dolist (image (cdr entry))
6174 (gnus-remove-image image category))
6175 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6176 (gnus-delete-wash-type category)))
6178 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6180 (defun gnus-article-maybe-hide-headers ()
6181 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6182 Provided for backwards compatibility."
6183 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6184 (not (with-current-buffer gnus-summary-buffer
6185 gnus-have-all-headers)))
6186 (not gnus-inhibit-hiding))
6187 (gnus-article-hide-headers)))
6189 (declare-function shr-put-image "shr" (data alt))
6191 (defun gnus-shr-put-image (data alt)
6192 "Put image DATA with a string ALT. Enable image to be deleted."
6193 (let ((image (shr-put-image data (propertize (or alt "*")
6194 'gnus-image-category 'shr))))
6196 (gnus-add-image 'shr image))))
6200 (defun gnus-output-to-file (file-name)
6201 "Append the current article to a file named FILE-NAME.
6202 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6203 text and used as the value of the coding cookie which is added to the
6204 top of a file. Otherwise, this function saves a raw article without
6206 (let* ((artbuf (current-buffer))
6207 (file-name-coding-system nnmail-pathname-coding-system)
6208 (coding gnus-article-save-coding-system)
6209 (coding-system-for-read (if coding
6210 nil ;; Rely on the coding cookie.
6211 mm-text-coding-system))
6212 (coding-system-for-write (or coding
6213 mm-text-coding-system-for-write
6214 mm-text-coding-system))
6215 (exists (file-exists-p file-name)))
6218 (insert-file-contents file-name)
6219 (goto-char (point-min))
6220 ;; Remove the existing coding cookie.
6221 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6222 (delete-region (match-beginning 0) (match-end 0))))
6223 (goto-char (point-max))
6224 (insert-buffer-substring artbuf)
6225 ;; Append newline at end of the buffer as separator, and then
6227 (goto-char (point-max))
6230 ;; If the coding system is not suitable to encode the text,
6231 ;; ask a user for a proper one.
6232 (when (fboundp 'select-safe-coding-system)
6233 (setq coding (coding-system-base
6234 (save-window-excursion
6235 (select-safe-coding-system (point-min) (point-max)
6237 (setq coding-system-for-write
6238 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6240 (goto-char (point-min))
6241 ;; Add the coding cookie.
6242 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6243 coding-system-for-write)))
6246 (write-region (point-min) (point-max) file-name nil 'no-message)
6247 (message "Appended to %s" file-name))
6248 (write-region (point-min) (point-max) file-name))))
6251 (defun gnus-narrow-to-page (&optional arg)
6252 "Narrow the article buffer to a page.
6253 If given a numerical ARG, move forward ARG pages."
6255 (setq arg (if arg (prefix-numeric-value arg) 0))
6256 (with-current-buffer gnus-article-buffer
6258 ;; Remove any old next/prev buttons.
6259 (when (gnus-visual-p 'page-marker)
6260 (let ((inhibit-read-only t))
6261 (gnus-remove-text-with-property 'gnus-prev)
6262 (gnus-remove-text-with-property 'gnus-next)))
6264 (when (save-excursion
6266 (if (re-search-backward page-delimiter nil 'move (abs arg))
6268 (setq nd (match-beginning 0)
6270 (when (re-search-backward page-delimiter nil t)
6271 (setq st (match-end 0))))
6272 (when (re-search-forward page-delimiter nil t)
6273 (setq nd (match-beginning 0)
6276 (if (re-search-forward page-delimiter nil 'move arg)
6278 (setq st (match-end 0)
6280 (when (re-search-forward page-delimiter nil t)
6281 (setq nd (match-beginning 0))))
6282 (when (re-search-backward page-delimiter nil t)
6283 (setq st (match-end 0)
6286 (when (re-search-backward page-delimiter nil t)
6287 (goto-char (setq st (match-end 0))))
6288 (when (re-search-forward page-delimiter nil t)
6289 (setq nd (match-beginning 0)))
6291 (setq gnus-page-broken t)
6292 (when pt (goto-char pt))
6293 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6294 (when (gnus-visual-p 'page-marker)
6298 (gnus-insert-next-page-button))
6301 (gnus-insert-prev-page-button))))))))
6303 ;; Article mode commands
6305 (defun gnus-article-goto-next-page ()
6306 "Show the next page of the article."
6308 (when (gnus-article-next-page)
6309 (goto-char (point-min))
6310 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6313 (defun gnus-article-goto-prev-page ()
6314 "Show the previous page of the article."
6316 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6317 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6318 (gnus-article-prev-page nil)))
6320 ;; This is cleaner but currently breaks `gnus-pick-mode':
6322 ;; (defun gnus-article-goto-next-page ()
6323 ;; "Show the next page of the article."
6325 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6326 ;; (gnus-summary-next-page)))
6328 ;; (defun gnus-article-goto-prev-page ()
6329 ;; "Show the next page of the article."
6331 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6332 ;; (gnus-summary-prev-page)))
6334 (defun gnus-article-next-page (&optional lines)
6335 "Show the next page of the current article.
6336 If end of article, return non-nil. Otherwise return nil.
6337 Argument LINES specifies lines to be scrolled up."
6339 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6340 (if (and (not (and gnus-article-over-scroll
6341 (> (count-lines (window-start) (point-max))
6342 (if (featurep 'xemacs)
6343 (or lines (1- (window-height)))
6344 (+ (or lines (1- (window-height))) scroll-margin)))))
6347 (and (pos-visible-in-window-p) ;Not continuation line.
6348 (>= (point) (point-max)))))
6349 ;; Nothing in this page.
6350 (if (or (not gnus-page-broken)
6355 (eobp)))) ;Real end-of-buffer?
6357 (when gnus-article-over-scroll
6358 (gnus-article-next-page-1 lines))
6360 (gnus-narrow-to-page 1) ;Go to next page.
6362 ;; More in this page.
6363 (gnus-article-next-page-1 lines)
6366 (defun gnus-article-beginning-of-window ()
6367 "Move point to the beginning of the window.
6368 In Emacs, the point is placed at the line number which `scroll-margin'
6370 (if (featurep 'xemacs)
6371 (move-to-window-line 0)
6372 ;; There is an obscure bug in Emacs that makes it impossible to
6373 ;; scroll past big pictures in the article buffer. Try to fix
6374 ;; this by adding a sanity check by counting the lines visible.
6375 (when (> (count-lines (window-start) (window-end)) 30)
6376 (move-to-window-line
6377 (min (max 0 scroll-margin)
6378 (max 1 (- (window-height)
6379 (if mode-line-format 1 0)
6380 (if header-line-format 1 0)
6383 (defun gnus-article-next-page-1 (lines)
6385 (let ((scroll-in-place nil)
6386 (auto-window-vscroll nil))
6389 ;; Long lines may cause an end-of-buffer error.
6390 (goto-char (point-max))))
6391 (gnus-article-beginning-of-window))
6393 (defun gnus-article-prev-page (&optional lines)
6394 "Show previous page of current article.
6395 Argument LINES specifies lines to be scrolled down."
6397 (move-to-window-line 0)
6398 (if (and gnus-page-broken
6400 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6402 (gnus-narrow-to-page -1) ;Go to previous page.
6403 (goto-char (point-max))
6404 (recenter (if gnus-article-over-scroll
6406 (max (if (featurep 'xemacs)
6408 (+ lines scroll-margin))
6410 (- (window-height) 2))
6414 (let ((scroll-in-place nil))
6415 (scroll-down lines))
6416 (beginning-of-buffer
6417 (goto-char (point-min))))
6418 (gnus-article-beginning-of-window))))
6420 (defun gnus-article-only-boring-p ()
6421 "Decide whether there is only boring text remaining in the article.
6422 Something \"interesting\" is a word of at least two letters that does
6423 not have a face in `gnus-article-boring-faces'."
6424 (when (and gnus-article-skip-boring
6425 (boundp 'gnus-article-boring-faces)
6426 (symbol-value 'gnus-article-boring-faces))
6428 (let ((inhibit-point-motion-hooks t))
6430 (while (re-search-forward "\\b\\w\\w" nil t)
6432 (when (not (gnus-intersection
6433 (gnus-faces-at (point))
6434 (symbol-value 'gnus-article-boring-faces)))
6435 (throw 'only-boring nil)))
6436 (throw 'only-boring t))))))
6438 (defun gnus-article-refer-article ()
6439 "Read article specified by message-id around point."
6442 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6443 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6444 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6445 (let ((msg-id (concat "<" (match-string 0) ">")))
6446 (set-buffer gnus-summary-buffer)
6447 (gnus-summary-refer-article msg-id))
6448 (error "No references around point"))))
6450 (defun gnus-article-show-summary ()
6451 "Reconfigure windows to show summary buffer."
6453 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6454 (error "There is no summary buffer for this article buffer")
6455 (gnus-article-set-globals)
6456 (gnus-configure-windows 'article)
6457 (gnus-summary-goto-subject gnus-current-article)
6458 (gnus-summary-position-point)))
6460 (defun gnus-article-describe-briefly ()
6461 "Describe article mode commands briefly."
6463 (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")))
6465 (defun gnus-article-check-buffer ()
6466 "Beep if not in an article buffer."
6467 (unless (equal major-mode 'gnus-article-mode)
6468 (error "Command invoked outside of a Gnus article buffer")))
6470 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6471 "Read a summary buffer key sequence and execute it from the article buffer."
6473 (gnus-article-check-buffer)
6475 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6476 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6477 "=" "^" "\M-^" "|"))
6479 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6480 "An" "Ap" [?A (meta return)] [?A delete]))
6484 '("n" "Gn" "p" "Gp"))
6486 (with-current-buffer gnus-article-current-summary
6487 (let (gnus-pick-mode)
6488 (setq unread-command-events (nconc unread-command-events
6489 (list (or key last-command-event)))
6490 keys (if (featurep 'xemacs)
6491 (events-to-keys (read-key-sequence nil t))
6492 (read-key-sequence nil t)))))
6497 ((eq (aref keys (1- (length keys))) ?\C-h)
6498 (gnus-article-describe-bindings (substring keys 0 -1)))
6499 ((or (member keys nosaves)
6500 (member keys nosave-but-article)
6501 (member keys nosave-in-article))
6503 (save-window-excursion
6504 (pop-to-buffer gnus-article-current-summary)
6505 ;; We disable the pick minor mode commands.
6506 (let (gnus-pick-mode)
6507 (setq func (key-binding keys t))))
6511 (unless (member keys nosave-in-article)
6512 (set-buffer gnus-article-current-summary))
6513 (when (get func 'disabled)
6514 (error "Function %s disabled" func))
6515 (call-interactively func)
6516 (setq new-sum-point (point)))
6517 (when (member keys nosave-but-article)
6518 (pop-to-buffer gnus-article-buffer))))
6520 ;; These commands should restore window configuration.
6521 (let ((obuf (current-buffer))
6522 (owin (current-window-configuration))
6523 win func in-buffer selected new-sum-start new-sum-hscroll err)
6524 (cond (not-restore-window
6525 (pop-to-buffer gnus-article-current-summary)
6526 (setq win (selected-window)))
6527 ((setq win (get-buffer-window gnus-article-current-summary))
6528 (select-window win))
6530 (let ((summary-buffer gnus-article-current-summary))
6531 (gnus-configure-windows 'article)
6532 (unless (setq win (get-buffer-window summary-buffer 'visible))
6533 (let ((gnus-buffer-configuration
6534 '((article ((vertical 1.0
6535 (summary 0.25 point)
6537 (gnus-configure-windows 'article))
6538 (setq win (get-buffer-window summary-buffer 'visible)))
6539 (gnus-select-frame-set-input-focus (window-frame win))
6540 (select-window win))))
6541 (setq in-buffer (current-buffer))
6542 ;; We disable the pick minor mode commands.
6543 (setq func (let (gnus-pick-mode)
6544 (key-binding keys t)))
6545 (when (get func 'disabled)
6546 (error "Function %s disabled" func))
6549 (condition-case code
6551 (call-interactively func)
6557 (when (eq win (selected-window))
6558 (setq new-sum-point (point)
6559 new-sum-start (window-start win)
6560 new-sum-hscroll (window-hscroll win)))
6561 (when (or (eq in-buffer (current-buffer))
6562 (when (eq obuf (current-buffer))
6563 (set-buffer in-buffer)
6565 (setq selected (gnus-summary-select-article))
6567 (unless not-restore-window
6568 (set-window-configuration owin))
6569 (when (and (eq selected 'old)
6571 (set-window-start (get-buffer-window (current-buffer))
6573 (set-window-point (get-buffer-window (current-buffer))
6574 (if (article-goto-body)
6577 (when (and (not not-restore-window)
6580 (with-current-buffer (window-buffer win)
6581 (eq major-mode 'gnus-summary-mode)))
6582 (set-window-point win new-sum-point)
6583 (set-window-start win new-sum-start)
6584 (set-window-hscroll win new-sum-hscroll))))
6585 (set-window-configuration owin)
6587 (signal (car err) (cdr err))
6590 (defun gnus-article-read-summary-send-keys ()
6592 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6593 (gnus-article-read-summary-keys)))
6595 (defun gnus-article-describe-key (key)
6596 "Display documentation of the function invoked by KEY.
6597 KEY is a string or a vector."
6598 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6599 (read-key-sequence "Describe key: "))))
6600 (gnus-article-check-buffer)
6601 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6602 gnus-article-read-summary-send-keys))
6603 (with-current-buffer gnus-article-current-summary
6604 (setq unread-command-events
6605 (if (featurep 'xemacs)
6607 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6608 (list 'meta (- x 128))
6611 (let ((cursor-in-echo-area t)
6613 (describe-key (read-key-sequence nil t))))
6614 (describe-key key)))
6616 (defun gnus-article-describe-key-briefly (key &optional insert)
6617 "Display documentation of the function invoked by KEY.
6618 KEY is a string or a vector."
6619 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6620 (read-key-sequence "Describe key: "))
6621 current-prefix-arg))
6622 (gnus-article-check-buffer)
6623 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6624 gnus-article-read-summary-send-keys))
6625 (with-current-buffer gnus-article-current-summary
6626 (setq unread-command-events
6627 (if (featurep 'xemacs)
6629 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6630 (list 'meta (- x 128))
6633 (let ((cursor-in-echo-area t)
6635 (describe-key-briefly (read-key-sequence nil t) insert)))
6636 (describe-key-briefly key insert)))
6638 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6639 (defvar gnus-agent-summary-mode)
6640 (defvar gnus-draft-mode)
6641 ;; Calling help-buffer will autoload help-mode.
6642 (defvar help-xref-stack-item)
6643 ;; Emacs 22 doesn't load it in the batch mode.
6645 (autoload 'help-buffer "help-mode"))
6647 (defun gnus-article-describe-bindings (&optional prefix)
6648 "Show a list of all defined keys, and their definitions.
6649 The optional argument PREFIX, if non-nil, should be a key sequence;
6650 then we display only bindings that start with that prefix."
6652 (gnus-article-check-buffer)
6653 (let ((keymap (copy-keymap gnus-article-mode-map))
6654 (map (copy-keymap gnus-article-send-map))
6655 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6657 (define-key keymap "S" map)
6658 (define-key map [t] nil)
6659 (with-current-buffer gnus-article-current-summary
6662 (if (setq parent (keymap-parent gnus-article-mode-map))
6664 (setq parent (copy-keymap parent))
6665 (set-keymap-parent parent (current-local-map)))
6666 (current-local-map)))
6667 (set-keymap-parent map (key-binding "S"))
6668 (let (key def gnus-pick-mode)
6670 (setq key (pop sumkeys))
6671 (cond ((and (vectorp key) (= (length key) 1)
6672 (consp (setq def (aref key 0)))
6673 (numberp (car def)) (numberp (cdr def)))
6674 (when (< (max (car def) (cdr def)) 128)
6678 (nreverse (gnus-uncompress-range def)))
6680 ((setq def (key-binding key))
6681 (unless (eq def 'undefined)
6682 (define-key keymap key def))))))
6683 (when (boundp 'gnus-agent-summary-mode)
6684 (setq agent gnus-agent-summary-mode))
6685 (when (boundp 'gnus-draft-mode)
6686 (setq draft gnus-draft-mode)))
6688 (use-local-map keymap)
6689 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6690 (set (make-local-variable 'gnus-draft-mode) draft)
6691 (describe-bindings prefix))
6692 (let ((item `((lambda (prefix)
6693 (with-current-buffer ,(current-buffer)
6694 (gnus-article-describe-bindings prefix)))
6696 (with-current-buffer (let (help-xref-following) (help-buffer))
6697 (setq help-xref-stack-item item)))))
6699 (defun gnus-article-reply-with-original (&optional wide)
6700 "Start composing a reply mail to the current message.
6701 The text in the region will be yanked. If the region isn't active,
6702 the entire article will be yanked."
6704 (let ((article (cdr gnus-article-current))
6706 (if (not (gnus-region-active-p))
6707 (with-current-buffer gnus-summary-buffer
6708 (gnus-summary-reply (list (list article)) wide))
6709 (setq contents (buffer-substring (point) (mark t)))
6710 ;; Deactivate active regions.
6711 (when (and (boundp 'transient-mark-mode)
6712 transient-mark-mode)
6713 (setq mark-active nil))
6714 (with-current-buffer gnus-summary-buffer
6716 (list (list article contents)) wide)))))
6718 (defun gnus-article-wide-reply-with-original ()
6719 "Start composing a wide reply mail to the current message.
6720 The text in the region will be yanked. If the region isn't active,
6721 the entire article will be yanked."
6723 (gnus-article-reply-with-original t))
6725 (defun gnus-article-followup-with-original ()
6726 "Compose a followup to the current article.
6727 The text in the region will be yanked. If the region isn't active,
6728 the entire article will be yanked."
6730 (let ((article (cdr gnus-article-current))
6732 (if (not (gnus-region-active-p))
6733 (with-current-buffer gnus-summary-buffer
6734 (gnus-summary-followup (list (list article))))
6735 (setq contents (buffer-substring (point) (mark t)))
6736 ;; Deactivate active regions.
6737 (when (and (boundp 'transient-mark-mode)
6738 transient-mark-mode)
6739 (setq mark-active nil))
6740 (with-current-buffer gnus-summary-buffer
6741 (gnus-summary-followup
6742 (list (list article contents)))))))
6744 (defun gnus-article-hide (&optional arg force)
6745 "Hide all the gruft in the current article.
6746 This means that signatures, cited text and (some) headers will be
6748 If given a prefix, show the hidden text instead."
6749 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6750 (gnus-article-hide-headers arg)
6751 (gnus-article-hide-list-identifiers arg)
6752 (gnus-article-hide-citation-maybe arg force)
6753 (gnus-article-hide-signature arg))
6755 (defun gnus-article-maybe-highlight ()
6756 "Do some article highlighting if article highlighting is requested."
6757 (when (gnus-visual-p 'article-highlight 'highlight)
6758 (gnus-article-highlight-some)))
6760 (defun gnus-check-group-server ()
6761 ;; Make sure the connection to the server is alive.
6762 (unless (gnus-server-opened
6763 (gnus-find-method-for-group gnus-newsgroup-name))
6764 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6765 (gnus-request-group gnus-newsgroup-name t)))
6768 (autoload 'nneething-get-file-name "nneething"))
6770 (defun gnus-request-article-this-buffer (article group)
6771 "Get an article and insert it into this buffer."
6772 (let (do-update-line sparse-header)
6776 (gnus-kill-all-overlays)
6777 (setq group (or group gnus-newsgroup-name))
6779 ;; Using `gnus-request-article' directly will insert the article into
6780 ;; `nntp-server-buffer' - so we'll save some time by not having to
6781 ;; copy it from the server buffer into the article buffer.
6783 ;; We only request an article by message-id when we do not have the
6784 ;; headers for it, so we'll have to get those.
6785 (when (stringp article)
6786 (gnus-read-header article))
6788 ;; If the article number is negative, that means that this article
6789 ;; doesn't belong in this newsgroup (possibly), so we find its
6790 ;; message-id and request it by id instead of number.
6791 (when (and (numberp article)
6793 (get-buffer gnus-summary-buffer)
6794 (gnus-buffer-exists-p gnus-summary-buffer))
6795 (with-current-buffer gnus-summary-buffer
6796 (let ((header (gnus-summary-article-header article)))
6799 ((memq article gnus-newsgroup-sparse)
6800 ;; This is a sparse gap article.
6801 (setq do-update-line article)
6802 (setq article (mail-header-id header))
6803 (setq sparse-header (gnus-read-header article))
6804 (setq gnus-newsgroup-sparse
6805 (delq article gnus-newsgroup-sparse)))
6807 ;; It's a real article.
6808 (setq article (mail-header-id header)))
6810 ;; It is an extracted pseudo-article.
6811 (setq article 'pseudo)
6812 (gnus-request-pseudo-article header))))
6814 (let ((method (gnus-find-method-for-group
6815 gnus-newsgroup-name)))
6816 (when (and (eq (car method) 'nneething)
6818 (let ((dir (nneething-get-file-name
6819 (mail-header-id header))))
6820 (when (and (stringp dir)
6821 (file-directory-p dir))
6822 (setq article 'nneething)
6823 (gnus-group-enter-directory dir))))))))
6826 ;; Refuse to select canceled articles.
6827 ((and (numberp article)
6829 (get-buffer gnus-summary-buffer)
6830 (gnus-buffer-exists-p gnus-summary-buffer)
6831 (eq (cdr (with-current-buffer gnus-summary-buffer
6832 (assq article gnus-newsgroup-reads)))
6833 gnus-canceled-mark))
6835 ;; We first check `gnus-original-article-buffer'.
6836 ((and (get-buffer gnus-original-article-buffer)
6838 (with-current-buffer gnus-original-article-buffer
6839 (and (equal (car gnus-original-article) group)
6840 (eq (cdr gnus-original-article) article))))
6841 ;; `insert-buffer-substring' would incorrectly use the
6842 ;; equivalent of string-make-multibyte which amount to decoding
6843 ;; with locale-coding-system, causing failure of
6844 ;; subsequent decoding.
6845 (insert (mm-string-to-multibyte
6846 (with-current-buffer gnus-original-article-buffer
6847 (buffer-substring (point-min) (point-max)))))
6849 ;; Check the backlog.
6850 ((and gnus-keep-backlog
6851 (gnus-backlog-request-article group article (current-buffer)))
6853 ;; Check asynchronous pre-fetch.
6854 ((gnus-async-request-fetched-article group article (current-buffer))
6855 (gnus-async-prefetch-next group article gnus-summary-buffer)
6856 (when (and (numberp article) gnus-keep-backlog)
6857 (gnus-backlog-enter-article group article (current-buffer)))
6860 ((and gnus-use-cache
6862 (gnus-cache-request-article article group))
6864 ;; Check the agent cache.
6865 ((gnus-agent-request-article article group)
6867 ;; Get the article and put into the article buffer.
6868 ((or (stringp article)
6870 (let ((gnus-override-method gnus-override-method)
6871 (methods (and (stringp article)
6872 (with-current-buffer gnus-summary-buffer
6873 (gnus-refer-article-methods))))
6874 (backend (car (gnus-find-method-for-group
6875 gnus-newsgroup-name)))
6877 (inhibit-read-only t))
6878 (when (and (null gnus-override-method)
6880 (setq gnus-override-method (pop methods)))
6883 (gnus-kill-all-overlays)
6884 (let ((gnus-newsgroup-name group))
6885 (gnus-check-group-server))
6887 ((gnus-request-article article group (current-buffer))
6888 (when (numberp article)
6889 (gnus-async-prefetch-next group article
6890 gnus-summary-buffer)
6891 (when gnus-keep-backlog
6892 (gnus-backlog-enter-article
6893 group article (current-buffer)))
6894 (when (and gnus-agent
6895 (gnus-agent-group-covered-p group))
6896 (gnus-agent-store-article article group)))
6897 (setq result 'article))
6899 (setq gnus-override-method (pop methods)))
6900 ((not (string-match "^400 "
6901 (nnheader-get-report backend)))
6902 ;; If we get 400 server disconnect, reconnect and
6903 ;; retry; otherwise, assume the article has expired.
6904 (setq result 'done))))
6905 (and (eq result 'article) 'article)))
6909 ;; Associate this article with the current summary buffer.
6910 (setq gnus-article-current-summary gnus-summary-buffer)
6912 ;; Take the article from the original article buffer
6913 ;; and place it in the buffer it's supposed to be in.
6914 (when (and (get-buffer gnus-article-buffer)
6915 (equal (buffer-name (current-buffer))
6916 (buffer-name (get-buffer gnus-article-buffer))))
6918 (if (get-buffer gnus-original-article-buffer)
6919 (set-buffer gnus-original-article-buffer)
6920 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6921 (buffer-disable-undo)
6922 (setq major-mode 'gnus-original-article-mode)
6923 (setq buffer-read-only t))
6924 (let ((inhibit-read-only t))
6926 (insert-buffer-substring gnus-article-buffer))
6927 (setq gnus-original-article (cons group article)))
6930 (run-hooks 'gnus-article-decode-hook)
6931 ;; Mark article as decoded or not.
6932 (setq gnus-article-decoded-p gnus-article-decode-hook))
6934 ;; Update sparse articles.
6935 (when (and do-update-line
6936 (or (numberp article)
6938 (let ((buf (current-buffer)))
6939 (set-buffer gnus-summary-buffer)
6940 (gnus-summary-update-article do-update-line sparse-header)
6941 (gnus-summary-goto-subject do-update-line nil t)
6942 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6944 (set-buffer buf))))))
6946 (defun gnus-block-private-groups (group)
6947 (if (gnus-news-group-p group)
6948 ;; Block nothing in news groups.
6950 ;; Block everything anywhere else.
6953 (defun gnus-blocked-images ()
6954 (if (functionp gnus-blocked-images)
6955 (funcall gnus-blocked-images gnus-newsgroup-name)
6956 gnus-blocked-images))
6962 (defcustom gnus-article-edit-mode-hook nil
6963 "Hook run in article edit mode buffers."
6964 :group 'gnus-article-various
6967 (defvar gnus-article-edit-done-function nil)
6969 (defvar gnus-article-edit-mode-map nil)
6971 ;; Should we be using derived.el for this?
6972 (unless gnus-article-edit-mode-map
6973 (setq gnus-article-edit-mode-map (make-keymap))
6974 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6976 (gnus-define-keys gnus-article-edit-mode-map
6977 "\C-c?" describe-mode
6978 "\C-c\C-c" gnus-article-edit-done
6979 "\C-c\C-k" gnus-article-edit-exit
6980 "\C-c\C-f\C-t" message-goto-to
6981 "\C-c\C-f\C-o" message-goto-from
6982 "\C-c\C-f\C-b" message-goto-bcc
6983 ;;"\C-c\C-f\C-w" message-goto-fcc
6984 "\C-c\C-f\C-c" message-goto-cc
6985 "\C-c\C-f\C-s" message-goto-subject
6986 "\C-c\C-f\C-r" message-goto-reply-to
6987 "\C-c\C-f\C-n" message-goto-newsgroups
6988 "\C-c\C-f\C-d" message-goto-distribution
6989 "\C-c\C-f\C-f" message-goto-followup-to
6990 "\C-c\C-f\C-m" message-goto-mail-followup-to
6991 "\C-c\C-f\C-k" message-goto-keywords
6992 "\C-c\C-f\C-u" message-goto-summary
6993 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6994 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6995 "\C-c\C-b" message-goto-body
6996 "\C-c\C-i" message-goto-signature
6998 "\C-c\C-t" message-insert-to
6999 "\C-c\C-n" message-insert-newsgroups
7000 "\C-c\C-o" message-sort-headers
7001 "\C-c\C-e" message-elide-region
7002 "\C-c\C-v" message-delete-not-region
7003 "\C-c\C-z" message-kill-to-signature
7004 "\M-\r" message-newline-and-reformat
7005 "\C-c\C-a" mml-attach-file
7006 "\C-a" message-beginning-of-line
7008 "\M-;" comment-region)
7010 (gnus-define-keys (gnus-article-edit-wash-map
7011 "\C-c\C-w" gnus-article-edit-mode-map)
7012 "f" gnus-article-edit-full-stops))
7015 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7017 ["Fetch To" message-insert-to t]
7018 ["Fetch Newsgroups" message-insert-newsgroups t]
7020 ["To" message-goto-to t]
7021 ["From" message-goto-from t]
7022 ["Subject" message-goto-subject t]
7023 ["Cc" message-goto-cc t]
7024 ["Reply-To" message-goto-reply-to t]
7025 ["Summary" message-goto-summary t]
7026 ["Keywords" message-goto-keywords t]
7027 ["Newsgroups" message-goto-newsgroups t]
7028 ["Followup-To" message-goto-followup-to t]
7029 ["Mail-Followup-To" message-goto-mail-followup-to t]
7030 ["Distribution" message-goto-distribution t]
7031 ["Body" message-goto-body t]
7032 ["Signature" message-goto-signature t]))
7034 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7035 "Major mode for editing articles.
7036 This is an extended text-mode.
7038 \\{gnus-article-edit-mode-map}"
7039 (make-local-variable 'gnus-article-edit-done-function)
7040 (make-local-variable 'gnus-prev-winconf)
7041 (set (make-local-variable 'font-lock-defaults)
7042 '(message-font-lock-keywords t))
7043 (set (make-local-variable 'mail-header-separator) "")
7044 (set (make-local-variable 'gnus-article-edit-mode) t)
7045 (easy-menu-add message-mode-field-menu message-mode-map)
7047 (setq buffer-read-only nil)
7048 (buffer-enable-undo)
7051 (defun gnus-article-edit (&optional force)
7052 "Edit the current article.
7053 This will have permanent effect only in mail groups.
7054 If FORCE is non-nil, allow editing of articles even in read-only
7057 (when (and (not force)
7058 (gnus-group-read-only-p))
7059 (error "The current newsgroup does not support article editing"))
7060 (gnus-article-date-original)
7061 (gnus-article-edit-article
7063 `(lambda (no-highlight)
7065 (gnus-summary-edit-article-done
7066 ,(or (mail-header-references gnus-current-headers) "")
7067 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7069 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7070 "Start editing the contents of the current article buffer."
7071 (let ((winconf (current-window-configuration)))
7072 (set-buffer gnus-article-buffer)
7073 (let ((message-auto-save-directory
7074 ;; Don't associate the article buffer with a draft file.
7076 (gnus-article-edit-mode))
7077 (funcall start-func)
7078 (set-buffer-modified-p nil)
7079 (gnus-configure-windows 'edit-article)
7080 (setq gnus-article-edit-done-function exit-func)
7081 (setq gnus-prev-winconf winconf)
7083 (gnus-message 6 "C-c C-c to end edits"))))
7085 (defun gnus-article-edit-done (&optional arg)
7086 "Update the article edits and exit."
7088 (let ((func gnus-article-edit-done-function)
7089 (buf (current-buffer))
7090 (start (window-start))
7092 (winconf gnus-prev-winconf))
7093 (widen) ;; Widen it in case that users narrowed the buffer.
7096 ;; The cache and backlog have to be flushed somewhat.
7097 (when gnus-keep-backlog
7098 (gnus-backlog-remove-article
7099 (car gnus-article-current) (cdr gnus-article-current)))
7100 ;; Flush original article as well.
7101 (gnus-flush-original-article-buffer)
7102 (when gnus-use-cache
7103 (gnus-cache-update-article
7104 (car gnus-article-current) (cdr gnus-article-current)))
7105 ;; We remove all text props from the article buffer.
7106 (kill-all-local-variables)
7107 (set-text-properties (point-min) (point-max) nil)
7109 (set-window-configuration winconf)
7111 (set-window-start (get-buffer-window buf) start)
7112 (set-window-point (get-buffer-window buf) (point)))
7113 (gnus-summary-show-article))
7115 (defun gnus-flush-original-article-buffer ()
7116 (when (get-buffer gnus-original-article-buffer)
7117 (with-current-buffer gnus-original-article-buffer
7118 (setq gnus-original-article nil))))
7120 (defun gnus-article-edit-exit ()
7121 "Exit the article editing without updating."
7123 (when (or (not (buffer-modified-p))
7124 (yes-or-no-p "Article modified; kill anyway? "))
7125 (let ((curbuf (current-buffer))
7127 (window-start (window-start)))
7129 (if (gnus-buffer-live-p gnus-original-article-buffer)
7130 (insert-buffer-substring gnus-original-article-buffer))
7131 (let ((winconf gnus-prev-winconf))
7132 (kill-all-local-variables)
7134 (set-window-configuration winconf)
7135 ;; Tippy-toe some to make sure that point remains where it was.
7136 (save-current-buffer
7138 (set-window-start (get-buffer-window (current-buffer)) window-start)
7140 (gnus-summary-show-article)))
7142 (defun gnus-article-edit-full-stops ()
7143 "Interactively repair spacing at end of sentences."
7146 (goto-char (point-min))
7147 (search-forward-regexp "^$" nil t)
7148 (let ((case-fold-search nil))
7149 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7152 ;;; Article highlights
7155 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7157 ;;; Internal Variables:
7159 (defcustom gnus-button-url-regexp
7161 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7162 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7163 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7164 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7165 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7169 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7170 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7171 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7173 "[" chars punct "]+" "[" chars "]"
7175 (concat ;; XEmacs 21.4 doesn't support POSIX.
7176 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7177 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7179 "Regular expression that matches URLs."
7180 :group 'gnus-article-buttons
7183 (defcustom gnus-button-valid-fqdn-regexp
7184 message-valid-fqdn-regexp
7185 "Regular expression that matches a valid FQDN."
7187 :group 'gnus-article-buttons
7190 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7191 (defcustom gnus-button-valid-localpart-regexp
7192 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7193 "Regular expression that matches a localpart of mail addresses or MIDs."
7195 :group 'gnus-article-buttons
7198 (defcustom gnus-button-man-handler 'manual-entry
7199 "Function to use for displaying man pages.
7200 The function must take at least one argument with a string naming the
7203 :type '(choice (function-item :tag "Man" manual-entry)
7204 (function-item :tag "Woman" woman)
7205 (function :tag "Other"))
7206 :group 'gnus-article-buttons)
7208 (defcustom gnus-button-mid-or-mail-regexp
7209 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7210 gnus-button-valid-fqdn-regexp
7212 "Regular expression that matches a message ID or a mail address."
7214 :group 'gnus-article-buttons
7217 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7218 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7219 Strings like this can be either a message ID or a mail address. If it is one
7220 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7221 message ID or a mail address, respectively. If this variable is set to the
7222 symbol `ask', always query the user what do do. If it is a function, this
7223 function will be called with the string as its only argument. The function
7224 must return `mid', `mail', `invalid' or `ask'."
7226 :group 'gnus-article-buttons
7227 :type '(choice (function-item :tag "Heuristic function"
7228 gnus-button-mid-or-mail-heuristic)
7233 (defcustom gnus-button-mid-or-mail-heuristic-alist
7234 '((-10.0 . ".+\\$.+@")
7237 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7238 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7239 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7240 (-1.0 . "^[^a-z]+@")
7242 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7243 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7244 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7245 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7248 (-1.0 . "^[0-9][0-9]")
7250 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7251 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7252 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7253 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7255 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7256 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7259 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7261 ;; compensation for TDMA dated mail addresses:
7262 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7264 (-20.0 . "\\.fsf@") ;; Gnus
7267 (-20.0 . "^alpine\\.")
7268 (-20.0 . "_-_") ;; Subject change in thread
7270 (-20.0 . "\\.ln@") ;; leafnode
7271 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7272 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7274 ;; (5.0 . "") ;; $local_part_len <= 7
7275 (10.0 . "^[^0-9]+@")
7276 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7277 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7280 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7282 (0.5 . "^[A-Z][a-z]")
7283 (0.5 . "^[A-Z][a-z][a-z]")
7284 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7285 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7286 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7288 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7289 address. The REGEXP is processed with `case-fold-search' set to nil."
7291 :group 'gnus-article-buttons
7292 :type '(repeat (cons (number :tag "Rate")
7293 (regexp :tag "Regexp"))))
7295 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7296 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7297 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7298 address, `ask' if unsure and `invalid' if the string is invalid."
7299 (let ((case-fold-search nil)
7300 (list gnus-button-mid-or-mail-heuristic-alist)
7301 (result 0) rate regexp lpartlen elem)
7303 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7304 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7305 ;; Certain special cases...
7308 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7309 "^[0-9]+\\.[0-9]+@compuserve\\|"
7310 "@public\\.gmane\\.org")
7312 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7313 (setq result 'mail))
7314 (when (string-match "@.*@\\| " mid-or-mail)
7315 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7316 (setq result 'invalid))
7317 ;; Nothing more to do, if result is not a number here...
7318 (when (numberp result)
7320 (setq elem (car list)
7324 (when (string-match regexp mid-or-mail)
7325 (setq result (+ result rate))
7327 9 "`%s' matched `%s', rate `%s', result `%s'."
7328 mid-or-mail regexp rate result)))
7329 (when (<= lpartlen 7)
7330 (setq result (+ result 5.0))
7331 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7332 mid-or-mail result))
7333 (when (>= lpartlen 12)
7334 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7336 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7337 ;; Long local part should contain realname if e-mail address,
7338 ;; too many digits: message-id.
7339 ;; $score -= 5.0 + 0.1 * $local_part_len;
7340 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7341 (setq result (+ result rate))
7343 9 "Many digits in `%s', rate `%s', result `%s'."
7344 mid-or-mail rate result))
7345 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7347 ;; Too few vowels [^aeiouy]{4,}.*\@
7348 (setq result (+ result -5.0))
7350 9 "Few vowels in `%s', rate `%s', result `%s'."
7351 mid-or-mail -5.0 result))
7353 (setq result (+ result 5.0))
7355 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7356 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7357 ;; Maybe we should make this a customizable alist: (condition . 'result)
7359 ((symbolp result) result)
7360 ;; Now convert number into proper results:
7361 ((< result -10.0) 'mid)
7362 ((> result 10.0) 'mail)
7365 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7366 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7367 (url-mid (concat "news" ":" mid-or-mail))
7368 (url-mailto (concat "mailto" ":" mid-or-mail)))
7369 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7370 (when (fboundp pref)
7372 ;; get rid of surrounding angles...
7374 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7375 (if (or (eq 'mid guessed) (eq 'mail guessed))
7379 (save-window-excursion
7380 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7383 (cond ((eq pref 'mid)
7384 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7385 (gnus-button-handle-news url-mid))
7387 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7388 (gnus-url-mailto url-mailto))
7389 (t (gnus-message 3 "Invalid string.")))))
7391 (defun gnus-button-handle-custom (fun arg)
7392 "Call function FUN on argument ARG.
7393 Both FUN and ARG are supposed to be strings. ARG will be passed
7394 as a symbol to FUN."
7395 (funcall (intern fun)
7396 (if (string-match "^customize-apropos" fun)
7400 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7402 (defun gnus-button-handle-describe-function (url)
7403 "Call `describe-function' when pushing the corresponding URL button."
7406 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7408 (defun gnus-button-handle-describe-variable (url)
7409 "Call `describe-variable' when pushing the corresponding URL button."
7412 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7414 (defun gnus-button-handle-symbol (url)
7415 "Display help on variable or function.
7416 Calls `describe-variable' or `describe-function'."
7417 (let ((sym (intern url)))
7419 ((fboundp sym) (describe-function sym))
7420 ((boundp sym) (describe-variable sym))
7421 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7423 (defun gnus-button-handle-describe-key (url)
7424 "Call `describe-key' when pushing the corresponding URL button."
7426 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7427 (keys (ignore-errors (eval `(kbd ,key-string)))))
7430 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7432 (defun gnus-button-handle-apropos (url)
7433 "Call `apropos' when pushing the corresponding URL button."
7434 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7436 (defun gnus-button-handle-apropos-command (url)
7437 "Call `apropos' when pushing the corresponding URL button."
7439 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7441 (defun gnus-button-handle-apropos-variable (url)
7442 "Call `apropos' when pushing the corresponding URL button."
7444 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7445 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7447 (defun gnus-button-handle-apropos-documentation (url)
7448 "Call `apropos' when pushing the corresponding URL button."
7450 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7451 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7453 (defun gnus-button-handle-library (url)
7454 "Call `locate-library' when pushing the corresponding URL button."
7455 (gnus-message 9 "url=`%s'" url)
7456 (let* ((lib (locate-library url))
7457 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7459 (gnus-message 1 "Cannot locale library `%s'." url)
7460 (find-file-read-only file))))
7462 (defcustom gnus-button-man-level 5
7463 "*Integer that says how many man-related buttons Gnus will show.
7464 The higher the number, the more buttons will appear and the more false
7465 positives are possible. Note that you can set this variable local to
7466 specific groups. Setting it higher in Unix groups is probably a good idea.
7467 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7468 how to set variables in specific groups."
7470 :group 'gnus-article-buttons
7471 :link '(custom-manual "(gnus)Group Parameters")
7474 (defcustom gnus-button-emacs-level 5
7475 "*Integer that says how many emacs-related buttons Gnus will show.
7476 The higher the number, the more buttons will appear and the more false
7477 positives are possible. Note that you can set this variable local to
7478 specific groups. Setting it higher in Emacs or Gnus related groups is
7479 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7480 `gnus-parameters' on how to set variables in specific groups."
7482 :group 'gnus-article-buttons
7483 :link '(custom-manual "(gnus)Group Parameters")
7486 (defcustom gnus-button-message-level 5
7487 "*Integer that says how many buttons for news or mail messages will appear.
7488 The higher the number, the more buttons will appear and the more false
7489 positives are possible."
7490 ;; mail addresses, MIDs, URLs for news, ...
7492 :group 'gnus-article-buttons
7495 (defcustom gnus-button-browse-level 5
7496 "*Integer that says how many buttons for browsing will appear.
7497 The higher the number, the more buttons will appear and the more false
7498 positives are possible."
7499 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7501 :group 'gnus-article-buttons
7504 (defcustom gnus-button-alist
7505 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7506 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7507 ((concat "\\b\\(nntp\\|news\\):\\("
7508 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7509 0 t gnus-button-handle-news 2)
7510 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7511 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7512 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7513 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7514 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7515 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7516 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7517 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7518 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7519 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7520 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7521 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7522 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7523 ;; RFC 2368 (The mailto URL scheme)
7524 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7525 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7526 ("\\bmailto:\\([^ \n\t]+\\)"
7527 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7528 ;; Info Konqueror style <info:/foo/bar baz>.
7529 ;; Must come before " Gnus home-grown style".
7530 ("\\binfo://?\\([^'\">\n\t]+\\)"
7531 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7532 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7533 ("\\binfo://\\([^'\">\n\t ]+\\)"
7534 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7535 ;; Info GNOME style <info:foo#bar_baz>
7536 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7537 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7538 ;; Info KDE style <info:(foo)bar baz>
7539 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7540 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7541 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7542 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7543 ("\\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,]*\\)\\)?"
7544 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7545 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7547 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7548 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7549 ;; Emacs help commands
7550 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7551 ;; regexp doesn't match arguments containing ` '.
7552 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7553 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7554 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7555 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7556 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7557 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7558 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7559 ;; The following entries may lead to many false positives so don't enable
7560 ;; them by default (use a high button level).
7561 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7562 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7563 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7564 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7565 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7566 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7567 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7568 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7569 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7570 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7571 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7572 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7573 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7574 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7575 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7576 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7577 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7578 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7579 ;; Unlike the other regexps we really have to require quoting
7580 ;; here to determine where it ends.
7581 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7582 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7583 ("<URL: *\\([^\n<>]*\\)>"
7584 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7585 ;; RFC 2396 (2.4.3., delims) ...
7586 ("\"URL: *\\([^\n\"]*\\)\""
7587 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7589 (gnus-button-url-regexp
7590 0 (>= gnus-button-browse-level 0) browse-url 0)
7592 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7593 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7594 gnus-button-handle-man 1)
7595 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7596 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7597 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7598 gnus-button-handle-man 1)
7599 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7600 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7601 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7602 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7603 ;; Recognizing patches to .el files. This is somewhat obscure,
7604 ;; but considering the percentage of Gnus users who hack Emacs
7606 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7607 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7608 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7609 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7610 ;; MID or mail: To avoid too many false positives we don't try to catch
7611 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7612 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7613 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7614 ;; so that non-ambiguous entries (see above) match first.
7615 (gnus-button-mid-or-mail-regexp
7616 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7617 "*Alist of regexps matching buttons in article bodies.
7619 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7620 REGEXP: is the string (case insensitive) matching text around the button (can
7621 also be Lisp expression evaluating to a string),
7622 BUTTON: is the number of the regexp grouping actually matching the button,
7623 FORM: is a Lisp expression which must eval to true for the button to
7625 CALLBACK: is the function to call when the user push this button, and each
7626 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7628 CALLBACK can also be a variable, in that case the value of that
7629 variable it the real callback function."
7630 :group 'gnus-article-buttons
7631 :type '(repeat (list (choice regexp variable sexp)
7632 (integer :tag "Button")
7634 (function :tag "Callback")
7637 (integer :tag "Regexp group")))))
7638 (put 'gnus-button-alist 'risky-local-variable t)
7640 (defcustom gnus-header-button-alist
7641 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7642 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7643 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7644 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7645 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7646 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7647 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7648 0 (>= gnus-button-browse-level 0) browse-url 0)
7649 ("^Subject:" gnus-button-url-regexp
7650 0 (>= gnus-button-browse-level 0) browse-url 0)
7651 ("^[^:]+:" gnus-button-url-regexp
7652 0 (>= gnus-button-browse-level 0) browse-url 0)
7653 ("^OpenPGP:.*url=" gnus-button-url-regexp
7654 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7655 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7656 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7657 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7658 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7659 "*Alist of headers and regexps to match buttons in article heads.
7661 This alist is very similar to `gnus-button-alist', except that each
7662 alist has an additional HEADER element first in each entry:
7664 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7666 HEADER is a regexp to match a header. For a fuller explanation, see
7667 `gnus-button-alist'."
7668 :group 'gnus-article-buttons
7669 :group 'gnus-article-headers
7670 :type '(repeat (list (regexp :tag "Header")
7671 (choice regexp variable)
7672 (integer :tag "Button")
7674 (function :tag "Callback")
7677 (integer :tag "Regexp group")))))
7678 (put 'gnus-header-button-alist 'risky-local-variable t)
7682 (defun gnus-article-push-button (event)
7683 "Check text under the mouse pointer for a callback function.
7684 If the text under the mouse pointer has a `gnus-callback' property,
7685 call it with the value of the `gnus-data' text property."
7687 (set-buffer (window-buffer (posn-window (event-start event))))
7688 (let* ((pos (posn-point (event-start event)))
7689 (data (get-text-property pos 'gnus-data))
7690 (fun (get-text-property pos 'gnus-callback)))
7693 (funcall fun data))))
7695 (defun gnus-article-press-button ()
7696 "Check text at point for a callback function.
7697 If the text at point has a `gnus-callback' property,
7698 call it with the value of the `gnus-data' text property."
7700 (let ((data (get-text-property (point) 'gnus-data))
7701 (fun (get-text-property (point) 'gnus-callback)))
7703 (funcall fun data))))
7705 (defun gnus-article-highlight (&optional force)
7706 "Highlight current article.
7707 This function calls `gnus-article-highlight-headers',
7708 `gnus-article-highlight-citation',
7709 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7710 do the highlighting. See the documentation for those functions."
7711 (interactive (list 'force))
7712 (gnus-article-highlight-headers)
7713 (gnus-article-highlight-citation force)
7714 (gnus-article-highlight-signature)
7715 (gnus-article-add-buttons)
7716 (gnus-article-add-buttons-to-head))
7718 (defun gnus-article-highlight-some (&optional force)
7719 "Highlight current article.
7720 This function calls `gnus-article-highlight-headers',
7721 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7722 do the highlighting. See the documentation for those functions."
7723 (interactive (list 'force))
7724 (gnus-article-highlight-headers)
7725 (gnus-article-highlight-signature)
7726 (gnus-article-add-buttons))
7728 (defun gnus-article-highlight-headers ()
7729 "Highlight article headers as specified by `gnus-header-face-alist'."
7731 (gnus-with-article-headers
7732 (let (regexp header-face field-face from hpoints fpoints)
7733 (dolist (entry gnus-header-face-alist)
7734 (goto-char (point-min))
7735 (setq regexp (concat "^\\("
7736 (if (string-equal "" (nth 0 entry))
7740 header-face (nth 1 entry)
7741 field-face (nth 2 entry))
7742 (while (and (re-search-forward regexp nil t)
7746 (unless (search-forward ":" nil t)
7748 (when (and header-face
7749 (not (memq (point) hpoints)))
7750 (push (point) hpoints)
7751 (gnus-put-text-property from (point) 'face header-face))
7752 (when (and field-face
7753 (not (memq (setq from (point)) fpoints)))
7755 (if (re-search-forward "^[^ \t]" nil t)
7757 (goto-char (point-max)))
7758 (gnus-put-text-property from (point) 'face field-face)))))))
7760 (defun gnus-article-highlight-signature ()
7761 "Highlight the signature in an article.
7762 It does this by highlighting everything after
7763 `gnus-signature-separator' using the face `gnus-signature'."
7765 (gnus-with-article-buffer
7766 (let ((inhibit-point-motion-hooks t))
7768 (when (and gnus-signature-face
7769 (gnus-article-narrow-to-signature))
7770 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7771 'face gnus-signature-face)
7773 (gnus-article-search-signature)
7774 (let ((start (match-beginning 0))
7775 (end (set-marker (make-marker) (1+ (match-end 0)))))
7776 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7779 (defun gnus-button-in-region-p (b e prop)
7780 "Say whether PROP exists in the region."
7781 (text-property-not-all b e prop nil))
7783 (defun gnus-article-add-buttons ()
7784 "Find external references in the article and make buttons of them.
7785 \"External references\" are things like Message-IDs and URLs, as
7786 specified by `gnus-button-alist'."
7788 (gnus-with-article-buffer
7789 (let ((inhibit-point-motion-hooks t)
7790 (case-fold-search t)
7791 (alist gnus-button-alist)
7793 ;; We skip the headers.
7796 (while (setq entry (pop alist))
7797 (setq regexp (eval (car entry)))
7799 (while (re-search-forward regexp nil t)
7800 (let ((start (match-beginning (nth 1 entry)))
7801 (end (match-end (nth 1 entry)))
7802 (from (match-beginning 0)))
7803 (when (and (eval (nth 2 entry))
7804 (not (gnus-button-in-region-p
7805 start end 'gnus-callback)))
7806 ;; That optional form returned non-nil, so we add the
7808 (setq from (set-marker (make-marker) from))
7809 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7810 (gnus-article-extend-url-button from start end))
7811 (gnus-article-add-button start end
7812 'gnus-button-push (list from entry))
7813 (gnus-put-text-property
7815 'gnus-string (buffer-substring-no-properties
7818 (defun gnus-article-extend-url-button (beg start end)
7819 "Extend url button if url is folded into two or more lines.
7820 Return non-nil if button is extended. BEG is a marker that points to
7821 the beginning position of a text containing url. START and END are
7822 the endpoints of a url button before it is extended. The concatenated
7823 url is put as the `gnus-button-url' overlay property on the button."
7824 (let ((opoint (point))
7825 (points (list start end))
7830 (not (looking-at "[\t ]*[\">]")))
7834 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7835 (buffer-substring (point-at-bol) start)))
7837 (setq url (list (buffer-substring start end))
7838 delim (if (match-beginning 1) ">" "\""))
7840 (setq regexp (concat
7841 (when (and (looking-at
7842 message-cite-prefix-regexp)
7843 (< (match-end 0) start))
7844 (regexp-quote (match-string 0)))
7846 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7850 (and (looking-at regexp)
7853 (push (or (match-string 2)
7856 (push (setq end (or (match-end 2)
7859 (push (or (match-beginning 2)
7860 (match-beginning 1))
7862 (match-beginning 2)))
7863 (let (gnus-article-mouse-face widget-mouse-face)
7865 (gnus-article-add-button (pop points) (pop points)
7866 'gnus-button-push beg)))
7867 (let ((overlay (gnus-make-overlay start end)))
7868 (gnus-overlay-put overlay 'evaporate t)
7869 (gnus-overlay-put overlay 'gnus-button-url
7870 (list (mapconcat 'identity (nreverse url) "")))
7871 (when gnus-article-mouse-face
7872 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7874 (goto-char opoint))))
7876 ;; Add buttons to the head of an article.
7877 (defun gnus-article-add-buttons-to-head ()
7878 "Add buttons to the head of the article."
7880 (gnus-with-article-headers
7882 (dolist (entry gnus-header-button-alist)
7883 ;; Each alist entry.
7884 (goto-char (point-min))
7885 (while (re-search-forward (car entry) nil t)
7886 ;; Each header matching the entry.
7887 (setq beg (match-beginning 0))
7888 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7889 (match-beginning 0))
7892 (while (re-search-forward (eval (nth 1 entry)) end t)
7893 ;; Each match within a header.
7894 (let* ((entry (cdr entry))
7895 (start (match-beginning (nth 1 entry)))
7896 (end (match-end (nth 1 entry)))
7897 (form (nth 2 entry)))
7898 (goto-char (match-end 0))
7900 (gnus-article-add-button
7901 start end (nth 3 entry)
7902 (buffer-substring (match-beginning (nth 4 entry))
7903 (match-end (nth 4 entry)))))))
7904 (goto-char end))))))
7906 ;;; External functions:
7908 (defun gnus-article-add-button (from to fun &optional data text)
7909 "Create a button between FROM and TO with callback FUN and data DATA."
7910 (when gnus-article-button-face
7911 (gnus-overlay-put (gnus-make-overlay from to nil t)
7912 'face gnus-article-button-face))
7913 (gnus-add-text-properties
7915 (nconc (and gnus-article-mouse-face
7916 (list gnus-mouse-face-prop gnus-article-mouse-face))
7917 (list 'gnus-callback fun)
7918 (and data (list 'gnus-data data))))
7919 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7920 :help-echo (or text "Follow the link")
7921 :keymap gnus-url-button-map
7922 :button-keymap gnus-widget-button-keymap))
7924 (defun gnus-article-copy-string ()
7925 "Copy the string in the button to the kill ring."
7927 (gnus-article-check-buffer)
7928 (let ((data (get-text-property (point) 'gnus-string)))
7932 (copy-region-as-kill (point-min) (point-max))
7933 (message "Copied %s" data)))))
7935 ;;; Internal functions:
7937 (defun gnus-article-set-globals ()
7938 (with-current-buffer gnus-summary-buffer
7939 (gnus-set-global-variables)))
7941 (defun gnus-signature-toggle (end)
7942 (gnus-with-article-buffer
7943 (let ((inhibit-point-motion-hooks t))
7944 (if (text-property-any end (point-max) 'article-type 'signature)
7946 (gnus-delete-wash-type 'signature)
7947 (gnus-remove-text-properties-when
7948 'article-type 'signature end (point-max)
7949 (cons 'article-type (cons 'signature
7950 gnus-hidden-properties))))
7951 (gnus-add-wash-type 'signature)
7952 (gnus-add-text-properties-when
7953 'article-type nil end (point-max)
7954 (cons 'article-type (cons 'signature
7955 gnus-hidden-properties)))))
7956 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7957 (gnus-set-mode-line 'article))))
7959 (defun gnus-button-push (marker-and-entry)
7960 ;; Push button starting at MARKER.
7962 (let* ((marker (car marker-and-entry))
7963 (entry (cadr marker-and-entry))
7964 (regexp (car entry))
7965 (inhibit-point-motion-hooks t))
7967 ;; This is obviously true, or something bad is happening :)
7968 ;; But we need it to have the match-data
7969 (when (looking-at (or (if (symbolp regexp)
7970 (symbol-value regexp)
7972 (let ((fun (nth 3 entry))
7973 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7974 (get-char-property marker 'gnus-button-url))
7975 (mapcar (lambda (group)
7976 (let ((string (match-string group)))
7977 (set-text-properties
7978 0 (length string) nil string)
7980 (nthcdr 4 entry)))))
7986 (fboundp (symbol-value fun)))
7987 (apply (symbol-value fun) args))
7989 (gnus-message 1 "You must define `%S' to use this button"
7990 (cons fun args)))))))))
7992 (defun gnus-parse-news-url (url)
7993 (let (scheme server port group message-id articles)
7996 (goto-char (point-min))
7997 (when (looking-at "\\([A-Za-z]+\\):")
7998 (setq scheme (match-string 1))
7999 (goto-char (match-end 0)))
8000 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8001 (setq server (match-string 1))
8002 (setq port (if (stringp (match-string 3))
8003 (string-to-number (match-string 3))
8005 (goto-char (match-end 0)))
8008 ((looking-at "\\(.*@.*\\)")
8009 (setq message-id (match-string 1)))
8010 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8011 (setq group (match-string 1)
8012 articles (split-string (match-string 2) "-")))
8013 ((looking-at "\\([^/]+\\)/?")
8014 (setq group (match-string 1)))
8016 (error "Unknown news URL syntax"))))
8017 (list scheme server port group message-id articles)))
8019 (defun gnus-button-handle-news (url)
8021 (destructuring-bind (scheme server port group message-id articles)
8022 (gnus-parse-news-url url)
8025 (with-current-buffer gnus-summary-buffer
8027 (let ((gnus-refer-article-method
8028 (nconc (list (list 'nntp server))
8029 gnus-refer-article-method))
8030 (nntp-port-number (or port "nntp")))
8031 (gnus-message 7 "Fetching %s with %s"
8032 message-id gnus-refer-article-method)
8033 (gnus-summary-refer-article message-id))
8034 (gnus-summary-refer-article message-id))))
8036 (gnus-button-fetch-group url)))))
8038 (defun gnus-button-patch (library line)
8039 "Visit an Emacs Lisp library LIBRARY on line LINE."
8041 (let ((file (locate-library (file-name-nondirectory library))))
8043 (error "Couldn't find library %s" library))
8045 (goto-char (point-min))
8046 (forward-line (1- (string-to-number line)))))
8048 (defun gnus-button-handle-man (url)
8050 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8051 (when (eq gnus-button-man-handler 'woman)
8052 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8053 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8054 (funcall gnus-button-man-handler url))
8056 (defun gnus-button-handle-info-url (url)
8057 "Fetch an info URL."
8058 (setq url (mm-subst-char-in-string ?+ ?\ url))
8060 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8061 (gnus-info-find-node
8062 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8064 ")" (gnus-url-unhex-string (match-string 2 url)))))
8065 ((string-match "([^)\"]+)[^\"]+" url)
8067 (gnus-replace-in-string
8068 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8069 (gnus-info-find-node url))
8070 (t (error "Can't parse %s" url))))
8072 (defun gnus-button-handle-info-url-gnome (url)
8073 "Fetch GNOME style info URL."
8074 (setq url (mm-subst-char-in-string ?_ ?\ url))
8075 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8076 (gnus-info-find-node
8078 (gnus-url-unhex-string
8079 (match-string 1 url))
8081 (or (gnus-url-unhex-string
8082 (match-string 2 url))
8084 (error "Can't parse %s" url)))
8086 (defun gnus-button-handle-info-url-kde (url)
8087 "Fetch KDE style info URL."
8088 (gnus-info-find-node (gnus-url-unhex-string url)))
8090 ;; (info) will autoload info.el
8091 (declare-function Info-menu "info" (menu-item &optional fork))
8092 (declare-function Info-index-next "info" (num))
8094 (defun gnus-button-handle-info-keystrokes (url)
8095 "Call `info' when pushing the corresponding URL button."
8096 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8097 (let (node indx comma)
8099 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8100 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8101 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8102 "\\(?:[ \t\n,]*\\)\\)?")
8104 (setq node (match-string 2 url)
8105 indx (match-string 3 url))
8106 (error "Can't parse %s" url))
8110 (when (> (length indx) 0)
8111 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8114 (setq comma (match-string 2 indx))
8115 (setq indx (match-string 1 indx))
8118 (dotimes (i (with-temp-buffer
8120 ;; Note: the XEmacs version of `how-many' takes
8121 ;; no optional argument.
8122 (goto-char (point-min))
8124 (Info-index-next 1)))
8127 (autoload 'pgg-snarf-keys-region "pgg")
8128 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8129 (declare-function pgg-display-output-buffer "pgg" (start end status))
8131 (defun gnus-button-openpgp (url)
8132 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8134 (mm-url-insert-file-contents-external url)
8135 (pgg-snarf-keys-region (point-min) (point-max))
8136 (pgg-display-output-buffer nil nil nil)))
8138 (defun gnus-button-message-id (message-id)
8140 (with-current-buffer gnus-summary-buffer
8141 (gnus-summary-refer-article message-id)))
8143 (defun gnus-button-fetch-group (address &rest ignore)
8144 "Fetch GROUP specified by ADDRESS."
8145 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8147 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8148 ;; for nntp:// and news://
8149 (setq address (match-string 3 address)))
8150 (if (not (string-match "[:/]" address))
8151 ;; This is just a simple group url.
8152 (gnus-group-read-ephemeral-group address gnus-select-method)
8155 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8157 (error "Can't parse %s" address)
8158 (gnus-group-read-ephemeral-group
8159 (match-string 4 address)
8160 `(nntp ,(match-string 1 address)
8161 (nntp-address ,(match-string 1 address))
8162 (nntp-port-number ,(if (match-end 3)
8163 (match-string 3 address)
8166 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8168 (defun gnus-url-parse-query-string (query &optional downcase)
8169 (let (retval pairs cur key val)
8170 (setq pairs (split-string query "&"))
8172 (setq cur (car pairs)
8174 (if (not (string-match "=" cur))
8176 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8177 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8179 (setq key (downcase key)))
8180 (setq cur (assoc key retval))
8182 (setcdr cur (cons val (cdr cur)))
8183 (setq retval (cons (list key val) retval)))))
8186 (defun gnus-url-mailto (url)
8187 ;; Send mail to someone
8188 (setq url (replace-regexp-in-string "\n" " " url))
8189 (when (string-match "mailto:/*\\(.*\\)" url)
8190 (setq url (substring url (match-beginning 1) nil)))
8191 (let (to args subject func)
8192 (setq args (gnus-url-parse-query-string
8193 (if (string-match "^\\?" url)
8195 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8196 (concat "to=" (match-string 1 url) "&"
8197 (match-string 2 url))
8198 (concat "to=" url))))
8199 subject (cdr-safe (assoc "subject" args)))
8202 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8205 (message-position-on-field (caar args)))
8206 (insert (gnus-replace-in-string
8207 (mapconcat 'identity (reverse (cdar args)) ", ")
8209 (setq args (cdr args)))
8212 (message-goto-subject))))
8214 (defun gnus-button-embedded-url (address)
8215 "Activate ADDRESS with `browse-url'."
8216 (browse-url (gnus-strip-whitespace address)))
8218 ;;; Next/prev buttons in the article buffer.
8220 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8221 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8223 (defvar gnus-prev-page-map
8224 (let ((map (make-sparse-keymap)))
8225 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8226 (define-key map "\r" 'gnus-button-prev-page)
8229 (defvar gnus-next-page-map
8230 (let ((map (make-sparse-keymap)))
8231 (define-key map gnus-mouse-2 'gnus-button-next-page)
8232 (define-key map "\r" 'gnus-button-next-page)
8235 (defun gnus-insert-prev-page-button ()
8237 (inhibit-read-only t))
8239 gnus-prev-page-line-format nil
8240 `(keymap ,gnus-prev-page-map
8242 gnus-callback gnus-article-button-prev-page
8243 article-type annotation))
8245 ;; Exclude a newline.
8248 (when gnus-article-button-face
8249 (gnus-overlay-put (gnus-make-overlay b e nil t)
8250 'face gnus-article-button-face))
8251 (widget-convert-button
8253 :action 'gnus-button-prev-page
8254 :button-keymap gnus-prev-page-map)))
8256 (defun gnus-button-next-page (&optional args more-args)
8257 "Go to the next page."
8259 (let ((win (selected-window)))
8260 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8261 (gnus-article-next-page)
8262 (select-window win)))
8264 (defun gnus-button-prev-page (&optional args more-args)
8265 "Go to the prev page."
8267 (let ((win (selected-window)))
8268 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8269 (gnus-article-prev-page)
8270 (select-window win)))
8272 (defun gnus-insert-next-page-button ()
8274 (inhibit-read-only t))
8275 (gnus-eval-format gnus-next-page-line-format nil
8276 `(keymap ,gnus-next-page-map
8278 gnus-callback gnus-article-button-next-page
8279 article-type annotation))
8281 ;; Exclude a newline.
8284 (when gnus-article-button-face
8285 (gnus-overlay-put (gnus-make-overlay b e nil t)
8286 'face gnus-article-button-face))
8287 (widget-convert-button
8289 :action 'gnus-button-next-page
8290 :button-keymap gnus-next-page-map)))
8292 (defun gnus-article-button-next-page (arg)
8293 "Go to the next page."
8295 (let ((win (selected-window)))
8296 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8297 (gnus-article-next-page)
8298 (select-window win)))
8300 (defun gnus-article-button-prev-page (arg)
8301 "Go to the prev page."
8303 (let ((win (selected-window)))
8304 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8305 (gnus-article-prev-page)
8306 (select-window win)))
8308 (defvar gnus-decode-header-methods
8309 '(mail-decode-encoded-word-region)
8310 "List of methods used to decode headers.
8312 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8313 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8314 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8315 whose names match REGEXP.
8318 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8319 mail-decode-encoded-word-region
8320 (\"chinese\" . rfc1843-decode-region))
8323 (defvar gnus-decode-header-methods-cache nil)
8325 (defun gnus-multi-decode-header (start end)
8326 "Apply the functions from `gnus-encoded-word-methods' that match."
8327 (unless (and gnus-decode-header-methods-cache
8328 (eq gnus-newsgroup-name
8329 (car gnus-decode-header-methods-cache)))
8330 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8331 (dolist (x gnus-decode-header-methods)
8333 (nconc gnus-decode-header-methods-cache (list x))
8334 (if (and gnus-newsgroup-name
8335 (string-match (car x) gnus-newsgroup-name))
8336 (nconc gnus-decode-header-methods-cache
8338 (let ((xlist gnus-decode-header-methods-cache))
8341 (narrow-to-region start end)
8343 (funcall (pop xlist) (point-min) (point-max))))))
8346 ;;; Treatment top-level handling.
8349 (defvar gnus-inhibit-article-treatments nil)
8351 (defun gnus-treat-article (gnus-treat-condition
8352 &optional part-number total-parts gnus-treat-type)
8353 (let ((gnus-treat-length (- (point-max) (point-min)))
8354 (alist gnus-treatment-function-alist)
8355 (article-goto-body-goes-to-point-min-p t)
8357 (or (not gnus-treat-type)
8359 (let ((list gnus-article-treat-types))
8361 (when (string-match (pop list) gnus-treat-type)
8362 (throw 'found t)))))))
8363 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8365 (gnus-run-hooks 'gnus-part-display-hook)
8366 (dolist (elem alist)
8369 (when (gnus-buffer-live-p gnus-summary-buffer)
8370 (set-buffer gnus-summary-buffer))
8371 (symbol-value (car elem))))
8372 (when (and (or (consp val)
8374 (or (not gnus-inhibit-article-treatments)
8375 (eq gnus-treat-condition 'head))
8376 (gnus-treat-predicate val)
8377 (or (not (get (car elem) 'highlight))
8380 (funcall (cadr elem)))))))
8382 ;; Dynamic variables.
8383 (defvar part-number)
8384 (defvar total-parts)
8385 (defvar gnus-treat-type)
8386 (defvar gnus-treat-condition)
8387 (defvar gnus-treat-length)
8389 (defun gnus-treat-predicate (val)
8393 (gnus-treat-condition
8394 (eq gnus-treat-condition val))
8396 (stringp (car val)))
8397 (apply 'gnus-or (mapcar `(lambda (s)
8398 (string-match s ,(or gnus-newsgroup-name "")))
8401 (let ((pred (pop val)))
8404 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8406 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8408 (not (gnus-treat-predicate (car val))))
8410 (equal (car val) gnus-treat-type))
8412 (error "%S is not a valid predicate" pred)))))
8420 (eq part-number total-parts))
8422 (< gnus-treat-length val))
8424 (error "%S is not a valid value" val))))
8426 (defun gnus-article-encrypt-body (protocol &optional n)
8427 "Encrypt the article body."
8430 (or gnus-article-encrypt-protocol
8431 (gnus-completing-read "Encrypt protocol"
8432 (mapcar 'car gnus-article-encrypt-protocol-alist)
8434 current-prefix-arg))
8435 ;; User might hit `K E' instead of `K e', so prompt once.
8436 (when (and gnus-article-encrypt-protocol
8438 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8439 (error "Encrypt aborted")))
8440 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8442 (error "Can't find the encrypt protocol %s" protocol))
8443 (if (member gnus-newsgroup-name '("nndraft:delayed"
8446 (error "Can't encrypt the article in group %s"
8447 gnus-newsgroup-name))
8448 (gnus-summary-iterate n
8449 (with-current-buffer gnus-summary-buffer
8450 (let ((mail-parse-charset gnus-newsgroup-charset)
8451 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8452 (summary-buffer gnus-summary-buffer)
8454 (gnus-set-global-variables)
8455 (when (gnus-group-read-only-p)
8456 (error "The current newsgroup does not support article encrypt"))
8457 (gnus-summary-show-article t)
8459 (or (mail-header-references gnus-current-headers) ""))
8460 (set-buffer gnus-article-buffer)
8461 (let* ((inhibit-read-only t)
8463 (mapcar (lambda (field)
8464 (and (save-restriction
8465 (message-narrow-to-head)
8466 (goto-char (point-min))
8467 (search-forward field nil t))
8469 (message-narrow-to-field)
8471 (delete-region (point-min) (point-max))
8473 '("Content-Type:" "Content-Transfer-Encoding:"
8474 "Content-Disposition:"))))
8475 (message-narrow-to-head)
8476 (message-remove-header "MIME-Version")
8477 (goto-char (point-max))
8478 (setq point (point))
8479 (insert (apply 'concat headers))
8481 (narrow-to-region point (point-max))
8482 (let ((message-options message-options))
8483 (message-options-set 'message-sender user-mail-address)
8484 (message-options-set 'message-recipients user-mail-address)
8485 (message-options-set 'message-sign-encrypt 'not)
8487 (goto-char (point-min))
8488 (insert "MIME-Version: 1.0\n")
8490 (gnus-summary-edit-article-done
8491 references nil summary-buffer t))
8492 (when gnus-keep-backlog
8493 (gnus-backlog-remove-article
8494 (car gnus-article-current) (cdr gnus-article-current)))
8495 (gnus-flush-original-article-buffer)
8496 (when gnus-use-cache
8497 (gnus-cache-update-article
8498 (car gnus-article-current) (cdr gnus-article-current))))))))
8500 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8501 "The following specs can be used:
8502 %t The security MIME type
8505 %D Details if button is pressed")
8507 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8508 "The following specs can be used:
8509 %t The security MIME type
8512 %D Details if button is pressed")
8514 (defvar gnus-mime-security-button-line-format-alist
8515 '((?t gnus-tmp-type ?s)
8516 (?i gnus-tmp-info ?s)
8517 (?d gnus-tmp-details ?s)
8518 (?D gnus-tmp-pressed-details ?s)))
8520 (defvar gnus-mime-security-button-commands
8521 '((gnus-article-press-button "\r" "Show Detail")
8525 (gnus-mime-security-save-part "o" "Save...")
8534 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8537 (defvar gnus-mime-security-button-map
8538 (let ((map (make-sparse-keymap)))
8539 (define-key map gnus-mouse-2 'gnus-article-push-button)
8540 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8541 (dolist (c gnus-mime-security-button-commands)
8542 (define-key map (cadr c) (car c)))
8546 gnus-mime-security-button-menu gnus-mime-security-button-map
8547 "Security button menu."
8551 (unless (eq (car c) 'undefined)
8552 (vector (caddr c) (car c) :active t)))
8553 gnus-mime-security-button-commands))))
8555 (defun gnus-mime-security-button-menu (event prefix)
8556 "Construct a context-sensitive menu of security commands."
8557 (interactive "e\nP")
8558 (save-window-excursion
8559 (let ((pos (event-start event)))
8560 (select-window (posn-window pos))
8561 (goto-char (posn-point pos))
8562 (gnus-article-check-buffer)
8563 (popup-menu gnus-mime-security-button-menu nil prefix))))
8565 (defvar gnus-mime-security-details-buffer nil)
8567 (defvar gnus-mime-security-button-pressed nil)
8569 (defvar gnus-mime-security-show-details-inline t
8570 "If non-nil, show details in the article buffer.")
8572 (defun gnus-mime-security-verify-or-decrypt (handle)
8573 (mm-remove-parts (cdr handle))
8574 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8575 point (inhibit-read-only t))
8577 (goto-char (car region)))
8578 (setq point (point))
8579 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8580 (let* ((mm-verify-option 'known)
8581 (mm-decrypt-option 'known)
8582 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8583 (unless (eq nparts (cdr handle))
8584 (mm-destroy-parts (cdr handle))
8585 (setcdr handle nparts))))
8586 (gnus-mime-display-security handle)
8588 (delete-region (point) (cdr region))
8589 (set-marker (car region) nil)
8590 (set-marker (cdr region) nil))
8593 (defun gnus-mime-security-show-details (handle)
8594 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8596 (gnus-message 5 "No details.")
8597 (if gnus-mime-security-show-details-inline
8598 (let ((gnus-mime-security-button-pressed
8599 (not (get-text-property (point) 'gnus-mime-details)))
8600 (gnus-mime-security-button-line-format
8601 (get-text-property (point) 'gnus-line-format))
8602 (inhibit-read-only t))
8604 (while (eq (get-text-property (point) 'gnus-line-format)
8605 gnus-mime-security-button-line-format)
8609 (narrow-to-region (point) (point))
8610 (gnus-insert-mime-security-button handle))
8611 (delete-region (point)
8612 (or (text-property-not-all
8615 gnus-mime-security-button-line-format)
8618 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8619 (with-current-buffer gnus-mime-security-details-buffer
8622 (setq gnus-mime-security-details-buffer
8623 (gnus-get-buffer-create "*MIME Security Details*")))
8624 (with-current-buffer gnus-mime-security-details-buffer
8626 (goto-char (point-min)))
8627 (pop-to-buffer gnus-mime-security-details-buffer)))))
8629 (defun gnus-mime-security-press-button (handle)
8631 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8632 (gnus-mime-security-show-details handle)
8633 (gnus-mime-security-verify-or-decrypt handle))))
8635 (defun gnus-insert-mime-security-button (handle &optional displayed)
8636 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8639 (or (nth 2 (assoc protocol mm-verify-function-alist))
8640 (nth 2 (assoc protocol mm-decrypt-function-alist))
8642 (if (equal (car handle) "multipart/signed")
8643 " Signed" " Encrypted")
8646 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8649 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8650 gnus-tmp-pressed-details
8652 (setq gnus-tmp-details
8653 (if gnus-tmp-details
8654 (concat "\n" gnus-tmp-details)
8656 (setq gnus-tmp-pressed-details
8657 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8662 gnus-mime-security-button-line-format
8663 gnus-mime-security-button-line-format-alist
8664 `(keymap ,gnus-mime-security-button-map
8665 gnus-callback gnus-mime-security-press-button
8666 gnus-line-format ,gnus-mime-security-button-line-format
8667 gnus-mime-details ,gnus-mime-security-button-pressed
8668 article-type annotation
8671 ;; Exclude a newline.
8674 (when gnus-article-button-face
8675 (gnus-overlay-put (gnus-make-overlay b e nil t)
8676 'face gnus-article-button-face))
8677 (widget-convert-button
8680 :action 'gnus-widget-press-button
8681 :button-keymap gnus-mime-security-button-map
8684 ;; Needed to properly clear the message due to a bug in
8685 ;; wid-edit (XEmacs only).
8686 (when (boundp 'help-echo-owns-message)
8687 (setq help-echo-owns-message t))
8689 "%S: show detail; %S: more options"
8690 (aref gnus-mouse-2 0)
8691 (aref gnus-down-mouse-3 0))))))
8693 (defun gnus-mime-display-security (handle)
8695 (narrow-to-region (point) (point))
8696 (unless (gnus-unbuttonized-mime-type-p (car handle))
8697 (gnus-insert-mime-security-button handle))
8698 (gnus-mime-display-part (cadr handle))
8701 (unless (gnus-unbuttonized-mime-type-p (car handle))
8702 (let ((gnus-mime-security-button-line-format
8703 gnus-mime-security-button-end-line-format))
8704 (gnus-insert-mime-security-button handle)))
8705 (mm-set-handle-multipart-parameter
8707 (cons (set-marker (make-marker) (point-min))
8708 (set-marker (make-marker) (point-max))))
8709 (goto-char (point-max))))
8711 (defun gnus-mime-security-run-function (function)
8712 "Run FUNCTION with the security part under point."
8713 (gnus-article-check-buffer)
8714 (let ((data (get-text-property (point) 'gnus-data))
8716 (when (and (stringp (car-safe data))
8717 (setq buffer (mm-handle-multipart-original-buffer data))
8718 (setq handle (cadr data)))
8719 (if (bufferp (mm-handle-buffer handle))
8721 (setq handle (cons buffer (copy-sequence (cdr handle))))
8722 (mm-handle-set-undisplayer handle nil))
8723 (setq handle (mm-make-handle
8725 (mm-handle-multipart-ctl-parameter handle 'protocol)
8726 nil nil nil nil nil nil)))
8727 (funcall function handle))))
8729 (defun gnus-mime-security-save-part ()
8730 "Save the security part under point."
8732 (gnus-mime-security-run-function 'mm-save-part))
8734 (defun gnus-mime-security-pipe-part ()
8735 "Pipe the security part under point to a process."
8737 (gnus-mime-security-run-function 'mm-pipe-part))
8743 (run-hooks 'gnus-art-load-hook)
8745 ;;; gnus-art.el ends here