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
271 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272 (if (gnus-image-type-available-p 'pbm)
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
284 :group 'gnus-article-washing)
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
299 (gnus-define-group-parameter
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
305 '(choice :tag "Banner"
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
310 (const :tag "None" nil))
312 "If non-nil, specify how to remove `banners' from articles.
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
337 (const :tag "None" nil))))
339 :group 'gnus-article-washing)
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
352 (if (nth 1 value) 2 3)
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
369 (defcustom gnus-emphasis-alist
371 '(("\\*" "\\*" bold nil 2)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
407 :format "%[Customizing Style%]\n%v"
409 (group :tag "Default"
410 :value ("" 0 0 default)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
417 (if (not (eq (nth 2 value) 'default))
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
428 :value (("_" . "_") nil default)
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
441 :group 'gnus-article-emphasis)
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
449 :group 'gnus-article-emphasis
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
509 :group 'gnus-article-saving
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favourite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
542 Gnus provides the following functions:
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
554 The symbol of each function may have the following properties:
557 The value non-nil means save decoded articles. This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function-item gnus-summary-save-in-pipe)
586 (defcustom gnus-article-save-coding-system
587 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591 "Coding system used to save decoded articles to a file.
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text. This is used by the
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
602 and the functions to which you may set `gnus-default-article-saver':
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil. Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613 :group 'gnus-article-saving
615 :format "%{%t%}:\n %[Value Menu%] %v"
616 (const :tag "Save raw articles" nil)
619 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620 '((const :tag "UTF-8" utf-8)
621 (const :tag "iso-2022-7bit" iso-2022-7bit)
622 (const :tag "Emacs internal" emacs-mule)
623 (const :tag "escape-quoted" escape-quoted))))
624 (symbol :tag "Coding system")))
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
648 :group 'gnus-article-saving
651 (defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
654 "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
666 If the match is a string, it is used as a regexp match on the
667 article. If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter. If it is a list, it will be evaled in the same buffer.
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674 :group 'gnus-article-saving
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
679 (defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
684 :group 'gnus-article-various)
686 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
687 "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
690 The following additional specs are available:
692 %w The article washing status.
693 %m The number of MIME parts in the article."
696 :group 'gnus-article-various)
698 (defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
701 :group 'gnus-article-various)
703 (when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
710 (defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "*A hook called after an article has been prepared in the article buffer."
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
771 (:foreground "PaleGreen1"))
774 (:foreground "red3"))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
787 (:foreground "SeaGreen1"))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
803 (:foreground "yellow" :italic t))
806 (:foreground "MidnightBlue" :italic t))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
821 (:foreground "SpringGreen2"))
824 (:foreground "maroon"))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
837 (:foreground "SpringGreen1" :italic t))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "*Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
879 "Alist of image types and properties applied to Face and X-Face images.
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs. Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896 :version "23.1" ;; No Gnus
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
900 (defcustom gnus-article-decode-hook
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
918 (defvar gnus-article-dumbquotes-map
938 "Table for MS-to-Latin1 translation.")
940 (defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947 "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
954 (defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include. See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
972 :group 'gnus-article-mime
975 (defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
986 "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
996 (defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1004 (defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
1009 :type '(choice (const nil)
1012 (defcustom gnus-mime-multipart-functions nil
1013 "An alist of MIME types to functions to display them."
1015 :group 'gnus-article-mime
1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1018 (defcustom gnus-article-date-headers '(combined-lapsed)
1019 "A list of Date header formats to display.
1020 Valid formats are `ut' (universal time), `local' (local time
1021 zone), `english' (readable English), `lapsed' (elapsed time),
1022 `combined-lapsed' (both the original date and the elapsed time),
1023 `original' (the original date header), `iso8601' (ISO8601
1024 format), and `user-defined' (a user-defined format defined by the
1025 `gnus-article-time-format' variable).
1027 You have as many date headers as you want in the article buffer.
1028 Some of these headers are updated automatically. See
1029 `gnus-article-update-date-headers' for details."
1031 :group 'gnus-article-headers
1033 (item :tag "Universal time (UT)" :value 'ut)
1034 (item :tag "Local time zone" :value 'local)
1035 (item :tag "Readable English" :value 'english)
1036 (item :tag "Elapsed time" :value 'lapsed)
1037 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1038 (item :tag "Original date header" :value 'original)
1039 (item :tag "ISO8601 format" :value 'iso8601)
1040 (item :tag "User-defined" :value 'user-defined)))
1042 (defcustom gnus-article-update-date-headers nil
1043 "A number that says how often to update the date header (in seconds).
1044 If nil, don't update it at all."
1046 :group 'gnus-article-headers
1048 (item :tag "Don't update" :value nil)
1051 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1052 "Function called with a MIME handle as the argument.
1053 This is meant for people who want to view first matched part.
1054 For `undisplayed-alternative' (default), the first undisplayed
1055 part or alternative part is used. For `undisplayed', the first
1056 undisplayed part is used. For a function, the first part which
1057 the function return t is used. For nil, the first part is
1060 :group 'gnus-article-mime
1062 (item :tag "first" :value nil)
1063 (item :tag "undisplayed" :value undisplayed)
1064 (item :tag "undisplayed or alternative"
1065 :value undisplayed-alternative)
1068 (defcustom gnus-mime-action-alist
1069 '(("save to file" . gnus-mime-save-part)
1070 ("save and strip" . gnus-mime-save-part-and-strip)
1071 ("replace with file" . gnus-mime-replace-part)
1072 ("delete part" . gnus-mime-delete-part)
1073 ("display as text" . gnus-mime-inline-part)
1074 ("view the part" . gnus-mime-view-part)
1075 ("pipe to command" . gnus-mime-pipe-part)
1076 ("toggle display" . gnus-article-press-button)
1077 ("toggle display" . gnus-article-view-part-as-charset)
1078 ("view as type" . gnus-mime-view-part-as-type)
1079 ("view internally" . gnus-mime-view-part-internally)
1080 ("view externally" . gnus-mime-view-part-externally))
1081 "An alist of actions that run on the MIME attachment."
1082 :group 'gnus-article-mime
1083 :type '(repeat (cons (string :tag "name")
1086 (defcustom gnus-auto-select-part 1
1087 "Advance to next MIME part when deleting or stripping parts.
1089 When 0, point will be placed on the same part as before. When
1090 positive (negative), move point forward (backwards) this many
1091 parts. When nil, redisplay article."
1092 :version "23.1" ;; No Gnus
1093 :group 'gnus-article-mime
1094 :type '(choice (const nil :tag "Redisplay article.")
1095 (const 1 :tag "Next part.")
1096 (const 0 :tag "Current part.")
1100 ;;; The treatment variables
1103 (defvar gnus-part-display-hook nil
1104 "Hook called on parts that are to receive treatment.")
1106 (defvar gnus-article-treat-custom
1107 '(choice (const :tag "Off" nil)
1109 (const :tag "Header" head)
1110 (const :tag "First" first)
1111 (const :tag "Last" last)
1112 (integer :tag "Less")
1113 (repeat :tag "Groups" regexp)
1114 (sexp :tag "Predicate")))
1116 (defvar gnus-article-treat-head-custom
1117 '(choice (const :tag "Off" nil)
1118 (const :tag "Header" head)))
1120 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1124 (defvar gnus-inhibit-treatment nil
1125 "Whether to inhibit treatment.")
1127 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1128 "Highlight the signature.
1129 Valid values are nil, t, `head', `first', `last', an integer or a
1130 predicate. See Info node `(gnus)Customizing Articles'."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-custom)
1134 (put 'gnus-treat-highlight-signature 'highlight t)
1136 (defcustom gnus-treat-buttonize 100000
1138 Valid values are nil, t, `head', `first', `last', an integer or a
1139 predicate. See Info node `(gnus)Customizing Articles'."
1140 :group 'gnus-article-treat
1141 :link '(custom-manual "(gnus)Customizing Articles")
1142 :type gnus-article-treat-custom)
1143 (put 'gnus-treat-buttonize 'highlight t)
1145 (defcustom gnus-treat-buttonize-head 'head
1146 "Add buttons to the head.
1147 Valid values are nil, t, `head', `first', `last', an integer or a
1148 predicate. See Info node `(gnus)Customizing Articles'."
1149 :group 'gnus-article-treat
1150 :link '(custom-manual "(gnus)Customizing Articles")
1151 :type gnus-article-treat-head-custom)
1152 (put 'gnus-treat-buttonize-head 'highlight t)
1154 (defcustom gnus-treat-date 'head
1155 "Display dates according to the `gnus-article-date-headers' variable.
1156 Valid values are nil, t, `head', `first', `last', an integer or a
1157 predicate. See Info node `(gnus)Customizing Articles'."
1159 :group 'gnus-article-treat
1160 :link '(custom-manual "(gnus)Customizing Articles")
1161 :type gnus-article-treat-head-custom)
1163 (defcustom gnus-treat-emphasize 50000
1165 Valid values are nil, t, `head', `first', `last', an integer or a
1166 predicate. See Info node `(gnus)Customizing Articles'."
1167 :group 'gnus-article-treat
1168 :link '(custom-manual "(gnus)Customizing Articles")
1169 :type gnus-article-treat-custom)
1170 (put 'gnus-treat-emphasize 'highlight t)
1172 (defcustom gnus-treat-strip-cr nil
1173 "Remove carriage returns.
1174 Valid values are nil, t, `head', `first', `last', an integer or a
1175 predicate. See Info node `(gnus)Customizing Articles'."
1177 :group 'gnus-article-treat
1178 :link '(custom-manual "(gnus)Customizing Articles")
1179 :type gnus-article-treat-custom)
1181 (defcustom gnus-treat-unsplit-urls nil
1182 "Remove newlines from within URLs.
1183 Valid values are nil, t, `head', `first', `last', an integer or a
1184 predicate. See Info node `(gnus)Customizing Articles'."
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-leading-whitespace nil
1191 "Remove leading whitespace in headers.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-hide-headers 'head
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-head-custom)
1207 (defcustom gnus-treat-hide-boring-headers nil
1208 "Hide boring headers.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-head-custom)
1215 (defcustom gnus-treat-hide-signature nil
1216 "Hide the signature.
1217 Valid values are nil, t, `head', `first', `last', an integer or a
1218 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1223 (defcustom gnus-treat-fill-article nil
1225 Valid values are nil, t, `head', `first', `last', an integer or a
1226 predicate. See Info node `(gnus)Customizing Articles'."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (defcustom gnus-treat-hide-citation nil
1233 Valid values are nil, t, `head', `first', `last', an integer or a
1234 predicate. See Info node `(gnus)Customizing Articles'."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1239 (defcustom gnus-treat-hide-citation-maybe nil
1241 Valid values are nil, t, `head', `first', `last', an integer or a
1242 predicate. See Info node `(gnus)Customizing Articles'."
1243 :group 'gnus-article-treat
1244 :link '(custom-manual "(gnus)Customizing Articles")
1245 :type gnus-article-treat-custom)
1247 (defcustom gnus-treat-strip-list-identifiers 'head
1248 "Strip list identifiers from `gnus-list-identifiers`.
1249 Valid values are nil, t, `head', `first', `last', an integer or a
1250 predicate. See Info node `(gnus)Customizing Articles'."
1252 :group 'gnus-article-treat
1253 :link '(custom-manual "(gnus)Customizing Articles")
1254 :type gnus-article-treat-custom)
1256 (gnus-define-group-parameter
1259 "Alist of regexps and correspondent identifiers."
1260 :variable-group gnus-article-washing
1262 '(choice :tag "Identifier"
1264 (symbol :tag "Item in `gnus-list-identifiers'" none)
1266 (const :tag "None" nil))
1268 "If non-nil, specify how to remove `identifiers' from articles' subject.
1270 Any symbol is used to look up a regular expression to match the
1271 banner in `gnus-list-identifiers'. A string is used as a regular
1272 expression to match the identifier directly.")
1274 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1275 "Gnus 5.10 (Emacs 22.1)")
1277 (defcustom gnus-treat-strip-pem nil
1278 "Strip PEM signatures.
1279 Valid values are nil, t, `head', `first', `last', an integer or a
1280 predicate. See Info node `(gnus)Customizing Articles'."
1281 :group 'gnus-article-treat
1282 :link '(custom-manual "(gnus)Customizing Articles")
1283 :type gnus-article-treat-custom)
1285 (defcustom gnus-treat-strip-banner t
1286 "Strip banners from articles.
1287 The banner to be stripped is specified in the `banner' group parameter.
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-highlight-headers 'head
1295 "Highlight the headers.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1298 :group 'gnus-article-treat
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :type gnus-article-treat-head-custom)
1301 (put 'gnus-treat-highlight-headers 'highlight t)
1303 (defcustom gnus-treat-highlight-citation t
1304 "Highlight cited text.
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-custom)
1310 (put 'gnus-treat-highlight-citation 'highlight t)
1312 (defcustom gnus-treat-strip-headers-in-body t
1313 "Strip the X-No-Archive header line from the beginning of the body.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1317 :group 'gnus-article-treat
1318 :link '(custom-manual "(gnus)Customizing Articles")
1319 :type gnus-article-treat-custom)
1321 (defcustom gnus-treat-strip-trailing-blank-lines nil
1322 "Strip trailing blank lines.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'.
1326 When set to t, it also strips trailing blanks in all MIME parts.
1327 Consider to use `last' instead."
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1332 (defcustom gnus-treat-strip-leading-blank-lines nil
1333 "Strip leading blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1337 When set to t, it also strips trailing blanks in all MIME parts."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1342 (defcustom gnus-treat-strip-multiple-blank-lines nil
1343 "Strip multiple blank lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'."
1346 :group 'gnus-article-treat
1347 :link '(custom-manual "(gnus)Customizing Articles")
1348 :type gnus-article-treat-custom)
1350 (defcustom gnus-treat-unfold-headers 'head
1351 "Unfold folded header lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 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-article-unfold-long-headers nil
1360 "If non-nil, allow unfolding headers even if the header is long.
1361 If it is a regexp, only long headers matching this regexp are unfolded.
1362 If it is t, all long headers are unfolded.
1364 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1365 :version "23.1" ;; No Gnus
1366 :group 'gnus-article-treat
1367 :type '(choice (const nil)
1368 (const :tag "all" t)
1371 (defcustom gnus-treat-fold-headers nil
1373 Valid values are nil, t, `head', `first', `last', an integer or a
1374 predicate. See Info node `(gnus)Customizing Articles'."
1376 :group 'gnus-article-treat
1377 :link '(custom-manual "(gnus)Customizing Articles")
1378 :type gnus-article-treat-custom)
1380 (defcustom gnus-treat-fold-newsgroups 'head
1381 "Fold the Newsgroups and Followup-To headers.
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-overstrike t
1390 "Treat overstrike highlighting.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
1395 :type gnus-article-treat-custom)
1396 (put 'gnus-treat-overstrike 'highlight t)
1398 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1399 "Treat ANSI SGR control sequences.
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)
1406 (make-obsolete-variable 'gnus-treat-display-xface
1407 'gnus-treat-display-x-face "Emacs 22.1")
1409 (defcustom gnus-treat-display-x-face
1410 (and (not noninteractive)
1411 (gnus-image-type-available-p 'xbm)
1412 (if (featurep 'xemacs)
1415 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1416 (executable-find "icontopbm"))
1417 ;; shell-command-to-string may signal an error, e.g. if
1418 ;; shell-file-name is not found.
1421 "Display X-Face headers.
1422 Valid values are nil and `head'.
1423 See Info node `(gnus)Customizing Articles' and Info node
1424 `(gnus)X-Face' for details."
1425 :group 'gnus-article-treat
1427 :link '(custom-manual "(gnus)Customizing Articles")
1428 :link '(custom-manual "(gnus)X-Face")
1429 :type gnus-article-treat-head-custom
1430 :set (lambda (symbol value)
1433 (cond ((or (boundp symbol) (get symbol 'saved-value))
1435 ((boundp 'gnus-treat-display-xface)
1437 ** gnus-treat-display-xface is an obsolete variable;\
1438 use gnus-treat-display-x-face instead")
1439 (default-value 'gnus-treat-display-xface))
1440 ((get 'gnus-treat-display-xface 'saved-value)
1442 ** gnus-treat-display-xface is an obsolete variable;\
1443 use gnus-treat-display-x-face instead")
1444 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1447 (put 'gnus-treat-display-x-face 'highlight t)
1449 (defcustom gnus-treat-display-face
1450 (and (not noninteractive)
1451 (gnus-image-type-available-p 'png)
1453 "Display Face headers.
1454 Valid values are nil, t, `head', `first', `last', an integer or a
1455 predicate. See Info node `(gnus)Customizing Articles' and Info
1456 node `(gnus)Face' for details."
1457 :group 'gnus-article-treat
1459 :link '(custom-manual "(gnus)Customizing Articles")
1460 :link '(custom-manual "(gnus)X-Face")
1461 :type gnus-article-treat-head-custom)
1462 (put 'gnus-treat-display-face 'highlight t)
1464 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1466 Valid values are nil, t, `head', `first', `last', an integer or a
1467 predicate. See Info node `(gnus)Customizing Articles' and Info
1468 node `(gnus)Smileys' for details."
1469 :group 'gnus-article-treat
1471 :link '(custom-manual "(gnus)Customizing Articles")
1472 :link '(custom-manual "(gnus)Smileys")
1473 :type gnus-article-treat-custom)
1474 (put 'gnus-treat-display-smileys 'highlight t)
1476 (defcustom gnus-treat-from-picon
1477 (if (and (gnus-image-type-available-p 'xpm)
1478 (gnus-picons-installed-p))
1480 "Display picons in the From header.
1481 Valid values are nil, t, `head', `first', `last', an integer or a
1482 predicate. See Info node `(gnus)Customizing Articles' and Info
1483 node `(gnus)Picons' for details."
1485 :group 'gnus-article-treat
1487 :link '(custom-manual "(gnus)Customizing Articles")
1488 :link '(custom-manual "(gnus)Picons")
1489 :type gnus-article-treat-head-custom)
1490 (put 'gnus-treat-from-picon 'highlight t)
1492 (defcustom gnus-treat-mail-picon
1493 (if (and (gnus-image-type-available-p 'xpm)
1494 (gnus-picons-installed-p))
1496 "Display picons in To and Cc headers.
1497 Valid values are nil, t, `head', `first', `last', an integer or a
1498 predicate. See Info node `(gnus)Customizing Articles' and Info
1499 node `(gnus)Picons' for details."
1501 :group 'gnus-article-treat
1503 :link '(custom-manual "(gnus)Customizing Articles")
1504 :link '(custom-manual "(gnus)Picons")
1505 :type gnus-article-treat-head-custom)
1506 (put 'gnus-treat-mail-picon 'highlight t)
1508 (defcustom gnus-treat-newsgroups-picon
1509 (if (and (gnus-image-type-available-p 'xpm)
1510 (gnus-picons-installed-p))
1512 "Display picons in the Newsgroups and Followup-To headers.
1513 Valid values are nil, t, `head', `first', `last', an integer or a
1514 predicate. See Info node `(gnus)Customizing Articles' and Info
1515 node `(gnus)Picons' for details."
1517 :group 'gnus-article-treat
1519 :link '(custom-manual "(gnus)Customizing Articles")
1520 :link '(custom-manual "(gnus)Picons")
1521 :type gnus-article-treat-head-custom)
1522 (put 'gnus-treat-newsgroups-picon 'highlight t)
1524 (defcustom gnus-treat-from-gravatar nil
1525 "Display gravatars in the From header.
1526 Valid values are nil, t, `head', `first', `last', an integer or a
1527 predicate. See Info node `(gnus)Customizing Articles' and Info
1528 node `(gnus)Gravatars' for details."
1530 :group 'gnus-article-treat
1531 :group 'gnus-gravatar
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :link '(custom-manual "(gnus)Gravatars")
1534 :type gnus-article-treat-head-custom)
1535 (put 'gnus-treat-from-gravatar 'highlight t)
1537 (defcustom gnus-treat-mail-gravatar nil
1538 "Display gravatars in To and Cc headers.
1539 Valid values are nil, t, `head', `first', `last', an integer or a
1540 predicate. See Info node `(gnus)Customizing Articles' and Info
1541 node `(gnus)Gravatars' for details."
1543 :group 'gnus-article-treat
1544 :group 'gnus-gravatar
1545 :link '(custom-manual "(gnus)Customizing Articles")
1546 :link '(custom-manual "(gnus)Gravatars")
1547 :type gnus-article-treat-head-custom)
1548 (put 'gnus-treat-mail-gravatar 'highlight t)
1550 (defcustom gnus-treat-body-boundary
1551 (if (or gnus-treat-newsgroups-picon
1552 gnus-treat-mail-picon
1553 gnus-treat-from-picon
1554 gnus-treat-from-gravatar
1555 gnus-treat-mail-gravatar)
1556 ;; If there's much decoration, the user might prefer a boundery.
1559 "Draw a boundary at the end of the headers.
1560 Valid values are nil and `head'.
1561 See Info node `(gnus)Customizing Articles' for details."
1563 :group 'gnus-article-treat
1564 :link '(custom-manual "(gnus)Customizing Articles")
1565 :type gnus-article-treat-head-custom)
1567 (defcustom gnus-treat-capitalize-sentences nil
1568 "Capitalize sentence-starting words.
1569 Valid values are nil, t, `head', `first', `last', an integer or a
1570 predicate. See Info node `(gnus)Customizing Articles'."
1572 :group 'gnus-article-treat
1573 :link '(custom-manual "(gnus)Customizing Articles")
1574 :type gnus-article-treat-custom)
1576 (defcustom gnus-treat-wash-html nil
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-fill-long-lines '(typep "text/plain")
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-x-pgp-sig nil
1596 To automatically treat X-PGP-Sig, set it to head.
1597 Valid values are nil, t, `head', `first', `last', an integer or a
1598 predicate. See Info node `(gnus)Customizing Articles'."
1600 :group 'gnus-article-treat
1601 :group 'mime-security
1602 :link '(custom-manual "(gnus)Customizing Articles")
1603 :type gnus-article-treat-custom)
1605 (defvar gnus-article-encrypt-protocol-alist
1606 '(("PGP" . mml2015-self-encrypt)))
1608 ;; Set to nil if more than one protocol added to
1609 ;; gnus-article-encrypt-protocol-alist.
1610 (defcustom gnus-article-encrypt-protocol "PGP"
1611 "The protocol used for encrypt articles.
1612 It is a string, such as \"PGP\". If nil, ask user."
1615 :group 'mime-security)
1617 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1618 (mm-coding-system-p 'utf-8)
1619 (executable-find idna-program))
1620 "Whether IDNA decoding of headers is used when viewing messages.
1621 This requires GNU Libidn, and by default only enabled if it is found."
1623 :group 'gnus-article-headers
1626 (defcustom gnus-article-over-scroll nil
1627 "If non-nil, allow scrolling the article buffer even when there no more text."
1629 :group 'gnus-article
1632 (defcustom gnus-inhibit-images nil
1633 "Non-nil means inhibit displaying of images inline in the article body."
1635 :group 'gnus-article
1638 (defcustom gnus-blocked-images 'gnus-block-private-groups
1639 "Images that have URLs matching this regexp will be blocked.
1640 This can also be a function to be evaluated. If so, it will be
1641 called with the group name as the parameter, and should return a
1647 ;;; Internal variables
1649 (defvar gnus-english-month-names
1650 '("January" "February" "March" "April" "May" "June" "July" "August"
1651 "September" "October" "November" "December"))
1653 (defvar article-goto-body-goes-to-point-min-p nil)
1654 (defvar gnus-article-wash-types nil)
1655 (defvar gnus-article-emphasis-alist nil)
1656 (defvar gnus-article-image-alist nil)
1658 (defvar gnus-article-mime-handle-alist-1 nil)
1659 (defvar gnus-treatment-function-alist
1660 '((gnus-treat-strip-cr gnus-article-remove-cr)
1661 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1662 (gnus-treat-strip-banner gnus-article-strip-banner)
1663 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1664 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1665 (gnus-treat-buttonize gnus-article-add-buttons)
1666 (gnus-treat-fill-article gnus-article-fill-cited-article)
1667 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1668 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1669 (gnus-treat-display-x-face gnus-article-display-x-face)
1670 (gnus-treat-display-face gnus-article-display-face)
1671 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1672 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1673 (gnus-treat-hide-signature gnus-article-hide-signature)
1674 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1675 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1676 (gnus-treat-from-picon gnus-treat-from-picon)
1677 (gnus-treat-mail-picon gnus-treat-mail-picon)
1678 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1679 (gnus-treat-strip-pem gnus-article-hide-pem)
1680 (gnus-treat-date gnus-article-treat-date)
1681 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1682 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1683 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1684 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1685 (gnus-treat-strip-trailing-blank-lines
1686 gnus-article-remove-trailing-blank-lines)
1687 (gnus-treat-strip-leading-blank-lines
1688 gnus-article-strip-leading-blank-lines)
1689 (gnus-treat-strip-multiple-blank-lines
1690 gnus-article-strip-multiple-blank-lines)
1691 (gnus-treat-overstrike gnus-article-treat-overstrike)
1692 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1693 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1694 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1695 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1696 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1697 (gnus-treat-display-smileys gnus-treat-smiley)
1698 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1699 (gnus-treat-wash-html gnus-article-wash-html)
1700 (gnus-treat-emphasize gnus-article-emphasize)
1701 (gnus-treat-hide-citation gnus-article-hide-citation)
1702 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1703 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1704 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1706 (defvar gnus-article-mime-handle-alist nil)
1707 (defvar article-lapsed-timer nil)
1708 (defvar gnus-article-current-summary nil)
1710 (defvar gnus-article-mode-syntax-table
1711 (let ((table (copy-syntax-table text-mode-syntax-table)))
1712 ;; This causes the citation match run O(2^n).
1713 ;; (modify-syntax-entry ?- "w" table)
1714 (modify-syntax-entry ?> ")<" table)
1715 (modify-syntax-entry ?< "(>" table)
1716 ;; make M-. in article buffers work for `foo' strings
1717 (modify-syntax-entry ?' " " table)
1718 (modify-syntax-entry ?` " " table)
1720 "Syntax table used in article mode buffers.
1721 Initialized from `text-mode-syntax-table.")
1723 (defvar gnus-save-article-buffer nil)
1725 (defvar gnus-number-of-articles-to-be-saved nil)
1727 (defvar gnus-inhibit-hiding nil)
1729 (defvar gnus-article-edit-mode nil)
1731 ;;; Macros for dealing with the article buffer.
1733 (defmacro gnus-with-article-headers (&rest forms)
1734 `(with-current-buffer gnus-article-buffer
1736 (let ((inhibit-read-only t)
1737 (inhibit-point-motion-hooks t)
1738 (case-fold-search t))
1739 (article-narrow-to-head)
1742 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1743 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1745 (defmacro gnus-with-article-buffer (&rest forms)
1746 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1747 (with-current-buffer gnus-article-buffer
1748 (let ((inhibit-read-only t))
1751 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1752 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1754 (defun gnus-article-goto-header (header)
1755 "Go to HEADER, which is a regular expression."
1756 (re-search-forward (concat "^\\(" header "\\):") nil t))
1758 (defsubst gnus-article-hide-text (b e props)
1759 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1760 (gnus-add-text-properties-when 'article-type nil b e props)
1761 (when (memq 'intangible props)
1763 (max (1- b) (point-min))
1764 b 'intangible (cddr (memq 'intangible props)))))
1766 (defsubst gnus-article-unhide-text (b e)
1767 "Remove hidden text properties from region between B and E."
1768 (remove-text-properties b e gnus-hidden-properties)
1769 (when (memq 'intangible gnus-hidden-properties)
1770 (put-text-property (max (1- b) (point-min))
1771 b 'intangible nil)))
1773 (defun gnus-article-hide-text-type (b e type)
1774 "Hide text of TYPE between B and E."
1775 (gnus-add-wash-type type)
1776 (gnus-article-hide-text
1777 b e (cons 'article-type (cons type gnus-hidden-properties))))
1779 (defun gnus-article-unhide-text-type (b e type)
1780 "Unhide text of TYPE between B and E."
1781 (gnus-delete-wash-type type)
1782 (remove-text-properties
1783 b e (cons 'article-type (cons type gnus-hidden-properties)))
1784 (when (memq 'intangible gnus-hidden-properties)
1785 (put-text-property (max (1- b) (point-min))
1786 b 'intangible nil)))
1788 (defun gnus-article-hide-text-of-type (type)
1789 "Hide text of TYPE in the current buffer."
1791 (let ((b (point-min))
1793 (while (setq b (text-property-any b e 'article-type type))
1794 (add-text-properties b (incf b) gnus-hidden-properties)))))
1796 (defun gnus-article-delete-text-of-type (type)
1797 "Delete text of TYPE in the current buffer."
1799 (let ((b (point-min)))
1800 (if (eq type 'multipart)
1801 ;; Remove MIME buttons associated with multipart/alternative parts.
1804 (while (if (get-text-property (point) 'gnus-part)
1806 (when (setq b (next-single-property-change (point)
1811 (skip-chars-forward "\n")
1812 (when (eq (get-text-property b 'article-type) 'multipart)
1813 (delete-region b (point)))))
1814 (while (setq b (text-property-any b (point-max) 'article-type type))
1816 b (or (text-property-not-all b (point-max) 'article-type type)
1819 (defun gnus-article-delete-invisible-text ()
1820 "Delete all invisible text in the current buffer."
1822 (let ((b (point-min)))
1823 (while (setq b (text-property-any b (point-max) 'invisible t))
1825 b (or (text-property-not-all b (point-max) 'invisible t)
1828 (defun gnus-article-text-type-exists-p (type)
1829 "Say whether any text of type TYPE exists in the buffer."
1830 (text-property-any (point-min) (point-max) 'article-type type))
1832 (defsubst gnus-article-header-rank ()
1833 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1834 (let ((list gnus-sorted-header-list)
1837 (if (looking-at (car list))
1839 (setq list (cdr list))
1843 (defun article-hide-headers (&optional arg delete)
1844 "Hide unwanted headers and possibly sort them as well."
1846 ;; This function might be inhibited.
1847 (unless gnus-inhibit-hiding
1848 (let ((inhibit-read-only t)
1849 (case-fold-search t)
1850 (max (1+ (length gnus-sorted-header-list)))
1851 (inhibit-point-motion-hooks t)
1852 (cur (current-buffer))
1853 ignored visible beg)
1855 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1856 ;; group parameters, so we should go to the summary buffer.
1859 (progn (set-buffer gnus-summary-buffer) t)
1861 (setq ignored (when (not gnus-visible-headers)
1862 (cond ((stringp gnus-ignored-headers)
1863 gnus-ignored-headers)
1864 ((listp gnus-ignored-headers)
1865 (mapconcat 'identity
1866 gnus-ignored-headers
1868 visible (cond ((stringp gnus-visible-headers)
1869 gnus-visible-headers)
1870 ((and gnus-visible-headers
1871 (listp gnus-visible-headers))
1872 (mapconcat 'identity
1873 gnus-visible-headers
1877 ;; First we narrow to just the headers.
1878 (article-narrow-to-head)
1879 ;; Hide any "From " lines at the beginning of (mail) articles.
1880 (while (looking-at "From ")
1883 (delete-region (point-min) (point)))
1884 ;; Then treat the rest of the header lines.
1885 ;; Then we use the two regular expressions
1886 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1887 ;; select which header lines is to remain visible in the
1889 (while (re-search-forward "^[^ \t:]*:" nil t)
1891 ;; Mark the rank of the header.
1893 (point) (1+ (point)) 'message-rank
1894 (if (or (and visible (looking-at visible))
1896 (not (looking-at ignored))))
1897 (gnus-article-header-rank)
1900 (message-sort-headers-1)
1901 (when (setq beg (text-property-any
1902 (point-min) (point-max) 'message-rank (+ 2 max)))
1903 ;; We delete the unwanted headers.
1904 (gnus-add-wash-type 'headers)
1905 (add-text-properties (point-min) (+ 5 (point-min))
1906 '(article-type headers dummy-invisible t))
1907 (delete-region beg (point-max))))))))
1909 (defun article-hide-boring-headers (&optional arg)
1910 "Toggle hiding of headers that aren't very interesting.
1911 If given a negative prefix, always show; if given a positive prefix,
1913 (interactive (gnus-article-hidden-arg))
1914 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1915 (not gnus-show-all-headers))
1918 (let ((inhibit-read-only t)
1919 (inhibit-point-motion-hooks t))
1920 (article-narrow-to-head)
1921 (dolist (elem gnus-boring-article-headers)
1922 (goto-char (point-min))
1924 ;; Hide empty headers.
1926 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1928 (gnus-article-hide-text-type
1932 (if (re-search-forward "^[^ \t]" nil t)
1936 ;; Hide boring Newsgroups header.
1937 ((eq elem 'newsgroups)
1938 (when (gnus-string-equal
1939 (gnus-fetch-field "newsgroups")
1940 (gnus-group-real-name
1941 (if (boundp 'gnus-newsgroup-name)
1944 (gnus-article-hide-header "newsgroups")))
1945 ((eq elem 'to-address)
1946 (let ((to (message-fetch-field "to"))
1948 (gnus-parameter-to-address
1949 (if (boundp 'gnus-newsgroup-name)
1950 gnus-newsgroup-name ""))))
1951 (when (and to to-address
1954 ;; only one address in To
1955 (nth 1 (mail-extract-address-components to))
1957 (gnus-article-hide-header "to"))))
1959 (let ((to (message-fetch-field "to"))
1961 (gnus-parameter-to-list
1962 (if (boundp 'gnus-newsgroup-name)
1963 gnus-newsgroup-name ""))))
1964 (when (and to to-list
1967 ;; only one address in To
1968 (nth 1 (mail-extract-address-components to))
1970 (gnus-article-hide-header "to"))))
1972 (let ((cc (message-fetch-field "cc"))
1974 (gnus-parameter-to-list
1975 (if (boundp 'gnus-newsgroup-name)
1976 gnus-newsgroup-name ""))))
1977 (when (and cc to-list
1980 ;; only one address in CC
1981 (nth 1 (mail-extract-address-components cc))
1983 (gnus-article-hide-header "cc"))))
1984 ((eq elem 'followup-to)
1985 (when (gnus-string-equal
1986 (message-fetch-field "followup-to")
1987 (message-fetch-field "newsgroups"))
1988 (gnus-article-hide-header "followup-to")))
1989 ((eq elem 'reply-to)
1990 (if (gnus-group-find-parameter
1991 gnus-newsgroup-name 'broken-reply-to)
1992 (gnus-article-hide-header "reply-to")
1993 (let ((from (message-fetch-field "from"))
1994 (reply-to (message-fetch-field "reply-to")))
2001 (lambda (x) (downcase (cadr x)))
2002 (mail-extract-address-components from t))
2005 (lambda (x) (downcase (cadr x)))
2006 (mail-extract-address-components reply-to t))
2008 (gnus-article-hide-header "reply-to")))))
2010 (let ((date (with-current-buffer gnus-original-article-buffer
2011 ;; If date in `gnus-article-buffer' is localized
2012 ;; (`gnus-treat-date-user-defined'),
2013 ;; `days-between' might fail.
2014 (message-fetch-field "date"))))
2016 (< (days-between (current-time-string) date)
2018 (gnus-article-hide-header "date"))))
2020 (let ((to (message-fetch-field "to"))
2021 (cc (message-fetch-field "cc")))
2022 (when (> (length to) 1024)
2023 (gnus-article-hide-header "to"))
2024 (when (> (length cc) 1024)
2025 (gnus-article-hide-header "cc"))))
2029 (goto-char (point-min))
2030 (while (re-search-forward "^to:" nil t)
2031 (setq to-count (1+ to-count)))
2032 (when (> to-count 1)
2033 (while (> to-count 0)
2034 (goto-char (point-min))
2036 (re-search-forward "^to:" nil nil to-count)
2038 (narrow-to-region (point) (point-max))
2039 (gnus-article-hide-header "to"))
2040 (setq to-count (1- to-count))))
2041 (goto-char (point-min))
2042 (while (re-search-forward "^cc:" nil t)
2043 (setq cc-count (1+ cc-count)))
2044 (when (> cc-count 1)
2045 (while (> cc-count 0)
2046 (goto-char (point-min))
2048 (re-search-forward "^cc:" nil nil cc-count)
2050 (narrow-to-region (point) (point-max))
2051 (gnus-article-hide-header "cc"))
2052 (setq cc-count (1- cc-count)))))))))))))
2054 (defun gnus-article-hide-header (header)
2056 (goto-char (point-min))
2057 (when (re-search-forward (concat "^" header ":") nil t)
2058 (gnus-article-hide-text-type
2062 (if (re-search-forward "^[^ \t]" nil t)
2067 (defvar gnus-article-normalized-header-length 40
2068 "Length of normalized headers.")
2070 (defun article-normalize-headers ()
2071 "Make all header lines 40 characters long."
2073 (let ((inhibit-read-only t)
2077 (article-narrow-to-head)
2080 ((< (setq column (- (point-at-eol) (point)))
2081 gnus-article-normalized-header-length)
2083 (insert (make-string
2084 (- gnus-article-normalized-header-length column)
2086 ((> column gnus-article-normalized-header-length)
2087 (gnus-put-text-property
2089 (forward-char gnus-article-normalized-header-length)
2096 (forward-line 1))))))
2098 (defun article-treat-dumbquotes ()
2099 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2100 Note that this function guesses whether a character is a sm*rtq**t* or
2101 not, so it should only be used interactively.
2103 Sm*rtq**t*s are M****s***'s unilateral extension to the
2104 iso-8859-1 character map in an attempt to provide more quoting
2105 characters. If you see something like \\222 or \\264 where
2106 you're expecting some kind of apostrophe or quotation mark, then
2109 (article-translate-strings gnus-article-dumbquotes-map))
2111 (defvar org-entities)
2113 (defun article-treat-non-ascii ()
2114 "Translate many Unicode characters into their ASCII equivalents."
2116 (require 'org-entities)
2117 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2118 (dolist (elem org-entities)
2119 (when (and (listp elem)
2120 (= (length (nth 6 elem)) 1))
2121 (if (featurep 'xemacs)
2122 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2123 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2125 (when (article-goto-body)
2126 (let ((inhibit-read-only t)
2129 (if (not (setq replace (if (featurep 'xemacs)
2130 (get-char-table (following-char) table)
2131 (aref table (following-char)))))
2134 (setq props (text-properties-at (point)))
2136 (add-text-properties (point) (progn (insert replace) (point))
2138 (insert replace)))))))))
2140 (defun article-translate-characters (from to)
2141 "Translate all characters in the body of the article according to FROM and TO.
2142 FROM is a string of characters to translate from; to is a string of
2143 characters to translate to."
2145 (when (article-goto-body)
2146 (let ((inhibit-read-only t)
2147 (x (make-string 225 ?x))
2149 (while (< (incf i) (length x))
2152 (while (< i (length from))
2153 (aset x (aref from i) (aref to i))
2155 (translate-region (point) (point-max) x)))))
2157 (defun article-translate-strings (map)
2158 "Translate all string in the body of the article according to MAP.
2159 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2164 (let ((from (car elem))
2168 (while (search-forward from nil t)
2171 (if (eq (following-char) from)
2175 (forward-char 1)))))))))))
2177 (defun article-treat-overstrike ()
2178 "Translate overstrikes into bold text."
2181 (when (article-goto-body)
2182 (let ((inhibit-read-only t))
2183 (while (search-forward "\b" nil t)
2184 (let ((next (char-after))
2185 (previous (char-after (- (point) 2))))
2186 ;; We do the boldification/underlining by hiding the
2187 ;; overstrikes and putting the proper text property
2191 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2192 (put-text-property (point) (1+ (point)) 'face 'bold))
2194 (gnus-article-hide-text-type
2195 (1- (point)) (1+ (point)) 'overstrike)
2197 (- (point) 2) (1- (point)) 'face 'underline))
2199 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2201 (point) (1+ (point)) 'face 'underline)))))))))
2203 (defun article-treat-ansi-sequences ()
2204 "Translate ANSI SGR control sequences into overlays or extents."
2207 (when (article-goto-body)
2208 (let ((inhibit-read-only t))
2209 (ansi-color-apply-on-region (point) (point-max))))))
2211 (defun gnus-article-treat-unfold-headers ()
2212 "Unfold folded message headers.
2213 Only the headers that fit into the current window width will be
2216 (gnus-with-article-headers
2220 (mail-header-narrow-to-field)
2221 (let* ((header (buffer-string))
2223 (or (equal gnus-article-unfold-long-headers t)
2224 (and (stringp gnus-article-unfold-long-headers)
2225 (string-match gnus-article-unfold-long-headers header)))))
2228 (goto-char (point-min))
2229 (while (re-search-forward "\n[\t ]" nil t)
2230 (replace-match " " t t)))
2231 (setq length (- (point-max) (point-min) 1))
2232 (when (or unfoldable
2233 (< length (window-width)))
2234 (while (re-search-forward "\n[\t ]" nil t)
2235 (replace-match " " t t))))
2236 (goto-char (point-max)))))))
2238 (defun gnus-article-treat-fold-headers ()
2239 "Fold message headers."
2241 (gnus-with-article-headers
2244 (mail-header-narrow-to-field)
2245 (mail-header-fold-field)
2246 (goto-char (point-max))))))
2248 (defun gnus-treat-smiley ()
2249 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2251 (gnus-with-article-buffer
2252 (if (memq 'smiley gnus-article-wash-types)
2253 (gnus-delete-images 'smiley)
2255 (let ((images (smiley-region (point) (point-max))))
2257 (gnus-add-wash-type 'smiley)
2258 (dolist (image images)
2259 (gnus-add-image 'smiley image)))))))
2261 (defun gnus-article-remove-images ()
2262 "Remove all images from the article buffer."
2264 (gnus-with-article-buffer
2267 (dolist (elem gnus-article-image-alist)
2268 (gnus-delete-images (car elem))))))
2270 (autoload 'w3m-toggle-inline-images "w3m")
2272 (defun gnus-article-show-images ()
2273 "Show any images that are in the HTML-rendered article buffer.
2274 This only works if the article in question is HTML."
2276 (gnus-with-article-buffer
2279 (if (eq mm-text-html-renderer 'w3m)
2280 (let ((mm-inline-text-html-with-images nil))
2281 (w3m-toggle-inline-images))
2282 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2284 (destructuring-bind (start end function) region
2285 (funcall function (get-text-property start 'image-url)
2288 (defun gnus-article-treat-fold-newsgroups ()
2289 "Unfold folded message headers.
2290 Only the headers that fit into the current window width will be
2293 (gnus-with-article-headers
2294 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2296 (mail-header-narrow-to-field)
2297 (while (re-search-forward ", *" nil t)
2298 (replace-match ", " t t))
2299 (mail-header-fold-field)
2300 (goto-char (point-max))))))
2302 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2303 "Value of `truncate-lines' in Gnus Article buffer.
2304 Valid values are nil, t, `head', `first', `last', an integer or a
2305 predicate. See Info node `(gnus)Customizing Articles'."
2306 :version "23.1" ;; No Gnus
2307 :group 'gnus-article
2308 ;; :link '(custom-manual "(gnus)Customizing Articles")
2311 (defun gnus-article-toggle-truncate-lines (&optional arg)
2312 "Toggle whether to fold or truncate long lines in article the buffer.
2313 If ARG is non-nil and not a number, toggle
2314 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2315 long lines if and only if arg is positive."
2318 ((and (numberp arg) (> arg 0))
2319 (setq gnus-article-truncate-lines t))
2321 (setq gnus-article-truncate-lines nil))
2323 (setq gnus-article-truncate-lines
2324 (not gnus-article-truncate-lines))))
2325 (gnus-with-article-buffer
2327 ((and (numberp arg) (> arg 0))
2328 (setq truncate-lines nil))
2330 (setq truncate-lines t)))
2331 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2332 ;; `toggle-truncate-lines' needs an argument.
2333 (toggle-truncate-lines)))
2335 (defun gnus-article-treat-body-boundary ()
2336 "Place a boundary line at the end of the headers."
2338 (when (and gnus-body-boundary-delimiter
2339 (> (length gnus-body-boundary-delimiter) 0))
2340 (gnus-with-article-headers
2341 (goto-char (point-max))
2342 (let ((start (point)))
2343 (insert "X-Boundary: ")
2344 (gnus-add-text-properties start (point) '(invisible t intangible t))
2345 (insert (let (str (max (window-width)))
2346 (if (featurep 'xemacs)
2347 (setq max (1- max)))
2348 (while (>= max (length str))
2349 (setq str (concat str gnus-body-boundary-delimiter)))
2350 (substring str 0 max))
2352 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2354 (defun article-fill-long-lines ()
2355 "Fill lines that are wider than the window width."
2358 (let ((inhibit-read-only t)
2359 (width (window-width (get-buffer-window (current-buffer)))))
2362 (let ((adaptive-fill-mode nil)) ;Why? -sm
2365 (when (>= (current-column) (min fill-column width))
2366 (narrow-to-region (min (1+ (point)) (point-max))
2368 (let ((goback (point-marker)))
2369 (fill-paragraph nil)
2370 (goto-char (marker-position goback)))
2372 (forward-line 1)))))))
2374 (defun article-capitalize-sentences ()
2375 "Capitalize the first word in each sentence."
2378 (let ((inhibit-read-only t)
2379 (paragraph-start "^[\n\^L]"))
2383 (forward-sentence)))))
2385 (defun article-remove-cr ()
2386 "Remove trailing CRs and then translate remaining CRs into LFs."
2389 (let ((inhibit-read-only t))
2390 (goto-char (point-min))
2391 (while (re-search-forward "\r+$" nil t)
2392 (replace-match "" t t))
2393 (goto-char (point-min))
2394 (while (search-forward "\r" nil t)
2395 (replace-match "\n" t t)))))
2397 (defun article-remove-trailing-blank-lines ()
2398 "Remove all trailing blank lines from the article."
2401 (let ((inhibit-read-only t))
2402 (goto-char (point-max))
2406 (while (and (not (bobp))
2407 (looking-at "^[ \t]*$")
2408 (not (gnus-annotation-in-region-p
2409 (point) (point-at-eol))))
2414 (defvar gnus-face-properties-alist)
2416 (defun article-display-face (&optional force)
2417 "Display any Face headers in the header."
2418 (interactive (list 'force))
2419 (let ((wash-face-p buffer-read-only))
2420 (gnus-with-article-headers
2421 ;; When displaying parts, this function can be called several times on
2422 ;; the same article, without any intended toggle semantic (as typing `W
2423 ;; D d' would have). So face deletion must occur only when we come from
2424 ;; an interactive command, that is when the *Article* buffer is
2426 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2427 (gnus-delete-images 'face)
2428 (let ((from (message-fetch-field "from"))
2430 (save-current-buffer
2431 (when (and wash-face-p
2432 (gnus-buffer-live-p gnus-original-article-buffer)
2433 (not (re-search-forward "^Face:[\t ]*" nil t)))
2434 (set-buffer gnus-original-article-buffer))
2436 (mail-narrow-to-head)
2438 ;; Check whether this face is censored.
2439 (not (and gnus-article-x-face-too-ugly
2441 (setq from (message-fetch-field "from")))
2442 (string-match gnus-article-x-face-too-ugly
2444 (while (gnus-article-goto-header "Face")
2445 (push (mail-header-field-value) faces)))))
2447 (goto-char (point-min))
2449 (unless (setq from (gnus-article-goto-header "from"))
2452 (insert " [no `from' set]\n"))
2454 (when (setq png (gnus-convert-face-to-png (pop faces)))
2456 (apply 'gnus-create-image png 'png t
2457 (cdr (assq 'png gnus-face-properties-alist))))
2459 (gnus-add-wash-type 'face)
2460 (gnus-add-image 'face image)
2461 (gnus-put-image image nil 'face))))))))))
2463 (defun article-display-x-face (&optional force)
2464 "Look for an X-Face header and display it if present."
2465 (interactive (list 'force))
2466 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2467 (gnus-with-article-headers
2468 ;; Delete the old process, if any.
2469 (when (process-status "article-x-face")
2470 (delete-process "article-x-face"))
2471 ;; See the comment in `article-display-face'.
2472 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2473 ;; We have already displayed X-Faces, so we remove them
2475 (gnus-delete-images 'xface)
2477 (let ((from (message-fetch-field "from"))
2479 (save-current-buffer
2480 (when (and wash-face-p
2481 (gnus-buffer-live-p gnus-original-article-buffer)
2482 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2483 ;; If type `W f', use gnus-original-article-buffer,
2484 ;; otherwise use the current buffer because displaying
2485 ;; RFC822 parts calls this function too.
2486 (set-buffer gnus-original-article-buffer))
2488 (mail-narrow-to-head)
2489 (and gnus-article-x-face-command
2491 ;; Check whether this face is censored.
2492 (not (and gnus-article-x-face-too-ugly
2494 (setq from (message-fetch-field "from")))
2495 (string-match gnus-article-x-face-too-ugly
2497 (while (gnus-article-goto-header "X-Face")
2498 (push (mail-header-field-value) x-faces)))))
2500 ;; We display the face.
2501 (cond ((functionp gnus-article-x-face-command)
2502 ;; The command is a lisp function, so we call it.
2503 (mapc gnus-article-x-face-command x-faces))
2504 ((stringp gnus-article-x-face-command)
2505 ;; The command is a string, so we interpret the command
2506 ;; as a, well, command, and fork it off.
2507 (let ((process-connection-type nil))
2508 (gnus-set-process-query-on-exit-flag
2510 "article-x-face" nil shell-file-name
2511 shell-command-switch gnus-article-x-face-command)
2513 ;; Sending multiple EOFs to xv doesn't work,
2514 ;; so we only do a single external face.
2516 (insert (car x-faces))
2517 (process-send-region "article-x-face"
2518 (point-min) (point-max)))
2519 (process-send-eof "article-x-face")))
2521 (error "`%s' set to `%s' is not a function"
2522 gnus-article-x-face-command
2523 'gnus-article-x-face-command)))))))))
2525 (defun article-decode-mime-words ()
2526 "Decode all MIME-encoded words in the article."
2528 (gnus-with-article-buffer
2529 (let ((inhibit-point-motion-hooks t)
2530 (mail-parse-charset gnus-newsgroup-charset)
2531 (mail-parse-ignored-charsets
2532 (with-current-buffer gnus-summary-buffer
2533 gnus-newsgroup-ignored-charsets)))
2534 (mail-decode-encoded-word-region (point-min) (point-max)))))
2536 (defun article-decode-charset (&optional prompt)
2537 "Decode charset-encoded text in the article.
2538 If PROMPT (the prefix), prompt for a coding system to use."
2540 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2541 (inhibit-read-only t)
2542 (mail-parse-charset gnus-newsgroup-charset)
2543 (mail-parse-ignored-charsets
2544 (save-excursion (condition-case nil
2545 (set-buffer gnus-summary-buffer)
2547 gnus-newsgroup-ignored-charsets))
2548 ct cte ctl charset format)
2551 (article-narrow-to-head)
2552 (setq ct (message-fetch-field "Content-Type" t)
2553 cte (message-fetch-field "Content-Transfer-Encoding" t)
2554 ctl (and ct (mail-header-parse-content-type ct))
2557 (mm-read-coding-system "Charset to decode: "))
2559 (mail-content-type-get ctl 'charset)))
2560 format (and ctl (mail-content-type-get ctl 'format)))
2562 (setq cte (mail-header-strip cte)))
2563 (if (and ctl (not (string-match "/" (car ctl))))
2565 (goto-char (point-max)))
2568 (narrow-to-region (point) (point-max))
2569 (when (and (eq mail-parse-charset 'gnus-decoded)
2570 (eq (mm-body-7-or-8) '8bit))
2571 ;; The text code could have been decoded.
2572 (setq charset mail-parse-charset))
2573 (when (and (or (not ctl)
2574 (equal (car ctl) "text/plain"))
2575 (not format)) ;; article with format will decode later.
2577 charset (and cte (intern (downcase
2578 (gnus-strip-whitespace cte))))
2581 (defun article-decode-encoded-words ()
2582 "Remove encoded-word encoding from headers."
2583 (let ((inhibit-point-motion-hooks t)
2584 (mail-parse-charset gnus-newsgroup-charset)
2585 (mail-parse-ignored-charsets
2586 (save-excursion (condition-case nil
2587 (set-buffer gnus-summary-buffer)
2589 gnus-newsgroup-ignored-charsets))
2590 (inhibit-read-only t)
2592 (goto-char (point-min))
2593 (when (search-forward "\n\n" nil 'move)
2600 (memq (char-after) '(?\t ? )))))
2601 (setq start (point))
2603 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2604 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2605 (funcall gnus-decode-address-function start end)
2606 (funcall gnus-decode-header-function start end))
2607 (goto-char (setq end start)))))
2609 (defun article-decode-group-name ()
2610 "Decode group names in Newsgroups, Followup-To and Xref headers."
2611 (let ((inhibit-point-motion-hooks t)
2612 (inhibit-read-only t)
2613 (method (gnus-find-method-for-group gnus-newsgroup-name))
2615 (when (and (or gnus-group-name-charset-method-alist
2616 gnus-group-name-charset-group-alist)
2617 (gnus-buffer-live-p gnus-original-article-buffer))
2619 (article-narrow-to-head)
2620 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2621 (with-current-buffer gnus-original-article-buffer
2622 (goto-char (point-min)))
2623 (setq regexp (concat "^" header
2624 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2625 (while (re-search-forward regexp nil t)
2626 (replace-match (save-match-data
2627 (gnus-decode-newsgroups
2628 ;; XXX how to use data in article buffer?
2629 (with-current-buffer gnus-original-article-buffer
2630 (re-search-forward regexp nil t)
2632 gnus-newsgroup-name method))
2634 (goto-char (point-min)))))))
2636 (autoload 'idna-to-unicode "idna")
2638 (defun article-decode-idna-rhs ()
2639 "Decode IDNA strings in RHS in various headers in current buffer.
2640 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2641 Mail-Reply-To: and Mail-Followup-To:."
2644 (let ((inhibit-point-motion-hooks t)
2645 (inhibit-read-only t))
2646 (article-narrow-to-head)
2647 (goto-char (point-min))
2648 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2650 (when (save-match-data
2651 (and (setq ace (match-string 1))
2653 (and (re-search-backward "^[^ \t]" nil t)
2654 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2655 (setq unicode (idna-to-unicode ace))))
2656 (unless (string= ace unicode)
2657 (replace-match unicode nil nil nil 1)))))))))
2659 (defun article-de-quoted-unreadable (&optional force read-charset)
2660 "Translate a quoted-printable-encoded article.
2661 If FORCE, decode the article whether it is marked as quoted-printable
2663 If READ-CHARSET, ask for a coding system."
2664 (interactive (list 'force current-prefix-arg))
2666 (let ((inhibit-read-only t) type charset)
2667 (if (gnus-buffer-live-p gnus-original-article-buffer)
2668 (with-current-buffer gnus-original-article-buffer
2670 (gnus-fetch-field "content-transfer-encoding"))
2671 (let* ((ct (gnus-fetch-field "content-type"))
2672 (ctl (and ct (mail-header-parse-content-type ct))))
2673 (setq charset (and ctl
2674 (mail-content-type-get ctl 'charset)))
2675 (if (stringp charset)
2676 (setq charset (intern (downcase charset)))))))
2678 (setq charset (mm-read-coding-system "Charset: " charset)))
2680 (setq charset gnus-newsgroup-charset))
2682 (and type (let ((case-fold-search t))
2683 (string-match "quoted-printable" type))))
2685 (quoted-printable-decode-region
2686 (point) (point-max) (mm-charset-to-coding-system charset))))))
2688 (defun article-de-base64-unreadable (&optional force read-charset)
2689 "Translate a base64 article.
2690 If FORCE, decode the article whether it is marked as base64 not.
2691 If READ-CHARSET, ask for a coding system."
2692 (interactive (list 'force current-prefix-arg))
2694 (let ((inhibit-read-only t) type charset)
2695 (if (gnus-buffer-live-p gnus-original-article-buffer)
2696 (with-current-buffer gnus-original-article-buffer
2698 (gnus-fetch-field "content-transfer-encoding"))
2699 (let* ((ct (gnus-fetch-field "content-type"))
2700 (ctl (and ct (mail-header-parse-content-type ct))))
2701 (setq charset (and ctl
2702 (mail-content-type-get ctl 'charset)))
2703 (if (stringp charset)
2704 (setq charset (intern (downcase charset)))))))
2706 (setq charset (mm-read-coding-system "Charset: " charset)))
2708 (setq charset gnus-newsgroup-charset))
2710 (and type (let ((case-fold-search t))
2711 (string-match "base64" type))))
2714 (narrow-to-region (point) (point-max))
2715 (base64-decode-region (point-min) (point-max))
2716 (mm-decode-coding-region
2717 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2722 (defun article-decode-HZ ()
2723 "Translate a HZ-encoded article."
2727 (let ((inhibit-read-only t))
2728 (rfc1843-decode-region (point-min) (point-max)))))
2730 (defun article-unsplit-urls ()
2731 "Remove the newlines that some other mailers insert into URLs."
2734 (let ((inhibit-read-only t))
2735 (goto-char (point-min))
2736 (while (re-search-forward
2737 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2738 (replace-match "\\1\\3" t)))
2739 (when (interactive-p)
2740 (gnus-treat-article nil))))
2742 (defun article-wash-html ()
2743 "Format an HTML article."
2746 (buffer-read-only nil))
2747 (when (gnus-buffer-live-p gnus-original-article-buffer)
2748 (setq handles (mm-dissect-buffer t t)))
2750 (delete-region (point) (point-max))
2751 (mm-inline-text-html handles)))
2753 (defvar gnus-article-browse-html-temp-list nil
2754 "List of temporary files created by `gnus-article-browse-html-parts'.
2755 Internal variable.")
2757 (defcustom gnus-article-browse-delete-temp 'ask
2758 "What to do with temporary files from `gnus-article-browse-html-parts'.
2759 If nil, don't delete temporary files. If it is t, delete them on
2760 exit from the summary buffer. If it is the symbol `file', query
2761 on each file, if it is `ask' ask once when exiting from the
2763 :group 'gnus-article
2764 :version "23.1" ;; No Gnus
2765 :type '(choice (const :tag "Don't delete" nil)
2766 (const :tag "Don't ask" t)
2767 (const :tag "Ask" ask)
2768 (const :tag "Ask for each file" file)))
2770 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2772 (defun gnus-article-browse-delete-temp-files (&optional how)
2773 "Delete temp-files created by `gnus-article-browse-html-parts'."
2774 (when (and gnus-article-browse-html-temp-list
2776 (or how (setq how gnus-article-browse-delete-temp))
2778 (let ((files (length gnus-article-browse-html-temp-list)))
2779 (gnus-y-or-n-p (format
2780 "Delete all %s temporary HTML file%s? "
2782 (if (> files 1) "s" ""))))
2784 (dolist (file gnus-article-browse-html-temp-list)
2785 (cond ((file-directory-p file)
2786 (when (or (not (eq how 'file))
2789 "Delete temporary HTML file(s) in directory `%s'? "
2790 (file-name-as-directory file))))
2791 (gnus-delete-directory file)))
2792 ((file-exists-p file)
2793 (when (or (not (eq how 'file))
2795 (format "Delete temporary HTML file `%s'? " file)))
2796 (delete-file file)))))
2797 ;; Also remove file from the list when not deleted or if file doesn't
2799 (setq gnus-article-browse-html-temp-list nil))
2800 gnus-article-browse-html-temp-list)
2802 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2803 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2808 (dolist (handle handles)
2810 ((not (listp handle)))
2811 ((equal (mm-handle-media-supertype handle) "multipart")
2812 (when (setq file (gnus-article-browse-html-save-cid-content
2813 cid handle directory))
2814 (throw 'found file)))
2815 ((equal (concat "<" cid ">") (mm-handle-id handle))
2818 (or (mm-handle-filename handle)
2820 (make-temp-name "cid")
2821 (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
2823 (mm-save-part-to-file handle file)
2824 (throw 'found file))))))))
2826 (defun gnus-article-browse-html-parts (list &optional header)
2827 "View all \"text/html\" parts from LIST.
2828 Recurse into multiparts. The optional HEADER that should be a decoded
2829 message header will be added to the bodies of the \"text/html\" parts."
2830 ;; Internal function used by `gnus-article-browse-html-article'.
2831 (let (type file charset content cid-dir tmp-file showed)
2832 ;; Find and show the html-parts.
2833 (dolist (handle list)
2834 ;; If HTML, show it:
2835 (cond ((not (listp handle)))
2836 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2837 (and (equal (car type) "message/external-body")
2839 (setq file (mm-handle-filename handle)))
2840 (or (mm-handle-cache handle)
2841 (condition-case code
2842 (progn (mm-extern-cache-contents handle) t)
2844 (gnus-message 3 "%s" (error-message-string code))
2845 (when (>= gnus-verbose 3) (sit-for 2))
2848 (setq handle (mm-handle-cache handle)
2849 type (mm-handle-type handle))
2850 (equal (car type) "text/html"))))
2851 (setq charset (mail-content-type-get type 'charset)
2852 content (mm-get-part handle))
2854 (if (eq charset 'gnus-decoded)
2855 (mm-enable-multibyte)
2856 (mm-disable-multibyte))
2858 ;; resolve cid contents
2859 (let ((case-fold-search t)
2861 (goto-char (point-min))
2862 (while (re-search-forward "\
2863 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2866 (setq cid-dir (mm-make-temp-file "cid" t))
2867 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2870 (when (setq cid-file
2871 (gnus-article-browse-html-save-cid-content
2873 (with-current-buffer gnus-article-buffer
2874 gnus-article-mime-handles)
2876 (replace-match (concat "file://" cid-file)
2878 (unless content (setq content (buffer-string))))
2879 (when (or charset header (not file))
2880 (setq tmp-file (mm-make-temp-file
2881 ;; Do we need to care for 8.3 filenames?
2882 "mm-" nil ".html")))
2883 ;; Add a meta html tag to specify charset and a header.
2886 (let (title eheader body hcharset coding force-charset)
2888 (mm-enable-multibyte)
2889 (setq case-fold-search t)
2890 (insert header "\n")
2891 (setq title (message-fetch-field "subject"))
2892 (goto-char (point-min))
2893 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2894 (replace-match (cond ((match-beginning 1) "<")
2895 ((match-beginning 2) ">")
2897 (goto-char (point-min))
2899 (goto-char (point-max))
2900 (insert "</pre>\n<hr>\n")
2901 ;; We have to examine charset one by one since
2902 ;; charset specified in parts might be different.
2903 (if (eq charset 'gnus-decoded)
2904 (setq charset 'utf-8
2905 eheader (mm-encode-coding-string (buffer-string)
2908 (mm-encode-coding-string title charset))
2909 body (mm-encode-coding-string content charset)
2911 (setq hcharset (mm-find-mime-charset-region (point-min)
2913 (cond ((= (length hcharset) 1)
2914 (setq hcharset (car hcharset)
2915 coding (mm-charset-to-coding-system
2917 ((> (length hcharset) 1)
2918 (setq hcharset 'utf-8
2924 (mm-charset-to-coding-system charset))
2925 (if (eq coding body)
2926 (setq eheader (mm-encode-coding-string
2927 (buffer-string) coding)
2929 (mm-encode-coding-string
2932 (setq charset 'utf-8
2933 eheader (mm-encode-coding-string
2934 (buffer-string) charset)
2936 (mm-encode-coding-string
2938 body (mm-encode-coding-string
2939 (mm-decode-coding-string
2943 (setq charset hcharset
2944 eheader (mm-encode-coding-string
2945 (buffer-string) coding)
2947 (mm-encode-coding-string
2950 (setq eheader (mm-string-as-unibyte (buffer-string))
2953 (mm-disable-multibyte)
2956 (mm-add-meta-html-tag handle charset force-charset))
2958 (goto-char (point-min))
2959 (unless (search-forward "<title>" nil t)
2960 (re-search-forward "<head>\\s-*" nil t)
2961 (insert "<title>" title "</title>\n")))
2962 (goto-char (point-min))
2963 (or (re-search-forward
2964 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2966 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2968 (mm-write-region (point-min) (point-max)
2969 tmp-file nil nil nil 'binary t))))
2971 (mm-with-unibyte-buffer
2972 (insert (if (eq charset 'gnus-decoded)
2973 (mm-encode-coding-string content
2974 (setq charset 'utf-8))
2976 (if (or (mm-add-meta-html-tag handle charset)
2978 (mm-write-region (point-min) (point-max)
2979 tmp-file nil nil nil 'binary t)
2980 (setq tmp-file nil))))
2982 (mm-save-part-to-file handle tmp-file)))
2984 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2985 (add-hook 'gnus-summary-prepare-exit-hook
2986 'gnus-article-browse-delete-temp-files)
2987 (add-hook 'gnus-exit-gnus-hook
2989 (gnus-article-browse-delete-temp-files t)))
2990 ;; FIXME: Warn if there's an <img> tag?
2991 (browse-url-of-file (or tmp-file (expand-file-name file)))
2993 ;; If multipart, recurse
2994 ((equal (mm-handle-media-supertype handle) "multipart")
2995 (when (gnus-article-browse-html-parts handle header)
2997 ((equal (mm-handle-media-type handle) "message/rfc822")
2998 (mm-with-multibyte-buffer
2999 (mm-insert-part handle)
3000 (setq handle (mm-dissect-buffer t t))
3001 (when (and (bufferp (car handle))
3002 (stringp (car (mm-handle-type handle))))
3003 (setq handle (list handle)))
3005 (article-decode-encoded-words)
3006 (let ((gnus-visible-headers
3007 (or (get 'gnus-visible-headers 'standard-value)
3008 gnus-visible-headers)))
3009 (article-hide-headers))
3010 (goto-char (point-min))
3011 (search-forward "\n\n" nil 'move)
3012 (skip-chars-backward "\t\n ")
3013 (setq header (buffer-substring (point-min) (point)))))
3015 (gnus-article-browse-html-parts handle header)
3016 (mm-destroy-parts handle))
3020 (defun gnus-article-browse-html-article (&optional arg)
3021 "View \"text/html\" parts of the current article with a WWW browser.
3022 Inline images embedded in a message using the cid scheme, as they are
3023 generally considered to be safe, will be processed properly.
3024 The message header is added to the beginning of every html part unless
3025 the prefix argument ARG is given.
3027 Warning: Spammers use links to images (using the http scheme) in HTML
3028 articles to verify whether you have read the message. As
3029 `gnus-article-browse-html-article' passes the HTML content to the
3030 browser without eliminating these \"web bugs\" you should only
3031 use it for mails from trusted senders.
3033 If you always want to display HTML parts in the browser, set
3034 `mm-text-html-renderer' to nil.
3036 This command creates temporary files to pass HTML contents including
3037 images if any to the browser, and deletes them when exiting the group
3039 ;; Cf. `mm-w3m-safe-url-regexp'
3042 (gnus-summary-show-article)
3043 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3044 gnus-visible-headers))
3045 ;; As we insert a <hr>, there's no need for the body boundary.
3046 (gnus-treat-body-boundary nil))
3047 (gnus-summary-show-article)))
3048 (with-current-buffer gnus-article-buffer
3049 (let ((header (unless arg
3052 (buffer-substring-no-properties
3053 (goto-char (point-min))
3054 (if (search-forward "\n\n" nil t)
3056 (goto-char (point-max))
3057 (skip-chars-backward "\t\n ")
3060 (set-buffer gnus-original-article-buffer)
3061 (setq parts (mm-dissect-buffer t t))
3062 ;; If singlepart, enforce a list.
3063 (when (and (bufferp (car parts))
3064 (stringp (car (mm-handle-type parts))))
3065 (setq parts (list parts)))
3067 (unless (gnus-article-browse-html-parts parts header)
3068 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3069 (mm-destroy-parts parts)
3071 (gnus-summary-show-article)))))
3073 (defun article-hide-list-identifiers ()
3074 "Remove list identifies from the Subject header.
3075 The `gnus-list-identifiers' variable specifies what to do."
3077 (let ((inhibit-point-motion-hooks t)
3078 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3079 (inhibit-read-only t))
3083 (article-narrow-to-head)
3084 (goto-char (point-min))
3085 (while (re-search-forward
3086 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3088 (delete-region (match-beginning 2) (match-end 0))
3089 (beginning-of-line))
3090 (when (re-search-forward
3091 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3092 (delete-region (match-beginning 1) (match-end 1))))))))
3094 (defun article-hide-pem (&optional arg)
3095 "Toggle hiding of any PEM headers and signatures in the current article.
3096 If given a negative prefix, always show; if given a positive prefix,
3098 (interactive (gnus-article-hidden-arg))
3099 (unless (gnus-article-check-hidden-text 'pem arg)
3101 (let ((inhibit-read-only t) end)
3102 (goto-char (point-min))
3103 ;; Hide the horrendously ugly "header".
3104 (when (and (search-forward
3105 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3107 (setq end (1+ (match-beginning 0))))
3108 (gnus-add-wash-type 'pem)
3109 (gnus-article-hide-text-type
3111 (if (search-forward "\n\n" nil t)
3115 ;; Hide the trailer as well
3116 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3118 (gnus-article-hide-text-type
3119 (match-beginning 0) (match-end 0) 'pem)))))))
3121 (defun article-strip-banner ()
3122 "Strip the banners specified by the `banner' group parameter and by
3123 `gnus-article-address-banner-alist'."
3127 (let ((inhibit-point-motion-hooks t))
3128 (when (gnus-parameter-banner gnus-newsgroup-name)
3129 (article-really-strip-banner
3130 (gnus-parameter-banner gnus-newsgroup-name)))
3131 (when gnus-article-address-banner-alist
3132 ;; Note that the From header is decoded here, so it is
3133 ;; required that the *-extract-address-components function
3134 ;; supports non-ASCII text.
3135 (let ((from (save-restriction
3137 (article-narrow-to-head)
3138 (mail-fetch-field "from"))))
3141 (cadr (funcall gnus-extract-address-components
3144 (dolist (pair gnus-article-address-banner-alist)
3145 (when (string-match (car pair) from)
3147 (article-really-strip-banner (cdr pair)))))))))))))
3149 (defun article-really-strip-banner (banner)
3150 "Strip the banner specified by the argument."
3153 (let ((inhibit-point-motion-hooks t)
3154 (gnus-signature-limit nil)
3155 (inhibit-read-only t))
3158 ((eq banner 'signature)
3159 (when (gnus-article-narrow-to-signature)
3162 (delete-region (point) (point-max))))
3164 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3165 (while (re-search-forward banner nil t)
3166 (delete-region (match-beginning 0) (match-end 0)))))
3168 (while (re-search-forward banner nil t)
3169 (delete-region (match-beginning 0) (match-end 0)))))))))
3171 (defun article-babel ()
3172 "Translate article using an online translation service."
3175 (gnus-with-article-buffer
3176 (when (article-goto-body)
3177 (let* ((start (point))
3179 (orig (buffer-substring start end))
3180 (trans (babel-as-string orig)))
3182 (narrow-to-region start end)
3183 (delete-region start end)
3186 (defun article-hide-signature (&optional arg)
3187 "Hide the signature in the current article.
3188 If given a negative prefix, always show; if given a positive prefix,
3190 (interactive (gnus-article-hidden-arg))
3191 (unless (gnus-article-check-hidden-text 'signature arg)
3194 (let ((inhibit-read-only t))
3195 (when (gnus-article-narrow-to-signature)
3196 (gnus-article-hide-text-type
3197 (point-min) (point-max) 'signature))))))
3198 (gnus-set-mode-line 'article))
3200 (defun article-strip-headers-in-body ()
3201 "Strip offensive headers from bodies."
3205 (let ((case-fold-search t))
3206 (when (looking-at "x-no-archive:")
3207 (gnus-delete-line)))))
3209 (defun article-strip-leading-blank-lines ()
3210 "Remove all blank lines from the beginning of the article."
3213 (let ((inhibit-point-motion-hooks t)
3214 (inhibit-read-only t))
3215 (when (article-goto-body)
3216 (while (and (not (eobp))
3217 (looking-at "[ \t]*$"))
3218 (gnus-delete-line))))))
3220 (defun article-narrow-to-head ()
3221 "Narrow the buffer to the head of the message.
3222 Point is left at the beginning of the narrowed-to region."
3224 (goto-char (point-min))
3225 (if (search-forward "\n\n" nil 1)
3228 (goto-char (point-min)))
3230 (defun article-goto-body ()
3231 "Place point at the start of the body."
3232 (goto-char (point-min))
3234 ;; This variable is only bound when dealing with separate
3236 (article-goto-body-goes-to-point-min-p
3238 ((search-forward "\n\n" nil t)
3241 (goto-char (point-max))
3244 (defun article-strip-multiple-blank-lines ()
3245 "Replace consecutive blank lines with one empty line."
3248 (let ((inhibit-point-motion-hooks t)
3249 (inhibit-read-only t))
3250 ;; First make all blank lines empty.
3252 (while (re-search-forward "^[ \t]+$" nil t)
3253 (unless (gnus-annotation-in-region-p
3254 (match-beginning 0) (match-end 0))
3255 (replace-match "" nil t)))
3256 ;; Then replace multiple empty lines with a single empty line.
3258 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3259 (unless (gnus-annotation-in-region-p
3260 (match-beginning 0) (match-end 0))
3261 (delete-region (match-beginning 1) (match-end 1)))))))
3263 (defun article-strip-leading-space ()
3264 "Remove all white space from the beginning of the lines in the article."
3267 (let ((inhibit-point-motion-hooks t)
3268 (inhibit-read-only t))
3270 (while (re-search-forward "^[ \t]+" nil t)
3271 (replace-match "" t t)))))
3273 (defun article-strip-trailing-space ()
3274 "Remove all white space from the end of the lines in the article."
3277 (let ((inhibit-point-motion-hooks t)
3278 (inhibit-read-only t))
3280 (while (re-search-forward "[ \t]+$" nil t)
3281 (replace-match "" t t)))))
3283 (defun article-strip-blank-lines ()
3284 "Strip leading, trailing and multiple blank lines."
3286 (article-strip-leading-blank-lines)
3287 (article-remove-trailing-blank-lines)
3288 (article-strip-multiple-blank-lines))
3290 (defun article-strip-all-blank-lines ()
3291 "Strip all blank lines."
3294 (let ((inhibit-point-motion-hooks t)
3295 (inhibit-read-only t))
3297 (while (re-search-forward "^[ \t]*\n" nil t)
3298 (replace-match "" t t)))))
3300 (defun gnus-article-narrow-to-signature ()
3301 "Narrow to the signature; return t if a signature is found, else nil."
3302 (let ((inhibit-point-motion-hooks t))
3303 (when (gnus-article-search-signature)
3305 ;; Check whether we have some limits to what we consider
3306 ;; to be a signature.
3307 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3308 (list gnus-signature-limit)))
3310 (while (setq limit (pop limits))
3311 (if (or (and (integerp limit)
3312 (< (- (point-max) (point)) limit))
3314 (< (count-lines (point) (point-max)) limit))
3315 (and (functionp limit)
3317 (and (stringp limit)
3318 (not (re-search-forward limit nil t))))
3319 () ; This limit did not succeed.
3323 (narrow-to-region (point) (point-max))
3326 (defun gnus-article-search-signature ()
3327 "Search the current buffer for the signature separator.
3328 Put point at the beginning of the signature separator."
3329 (let ((cur (point)))
3330 (goto-char (point-max))
3331 (if (if (stringp gnus-signature-separator)
3332 (re-search-backward gnus-signature-separator nil t)
3333 (let ((seps gnus-signature-separator))
3335 (not (re-search-backward (car seps) nil t)))
3342 (defun gnus-article-hidden-arg ()
3343 "Return the current prefix arg as a number, or 0 if no prefix."
3344 (list (if current-prefix-arg
3345 (prefix-numeric-value current-prefix-arg)
3348 (defun gnus-article-check-hidden-text (type arg)
3349 "Return nil if hiding is necessary.
3350 Arg can be nil or a number. nil and positive means hide, negative
3351 means show, 0 means toggle."
3354 (let ((hide (gnus-article-hidden-text-p type)))
3360 (gnus-article-show-hidden-text type)
3363 (if (eq hide 'hidden)
3365 (gnus-article-show-hidden-text type)
3369 (defun gnus-article-hidden-text-p (type)
3370 "Say whether the current buffer contains hidden text of type TYPE."
3371 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3373 (not (get-text-property pos 'invisible))
3374 (not (get-text-property pos 'dummy-invisible)))
3376 (text-property-any (1+ pos) (point-max) 'article-type type)))
3381 (defun gnus-article-show-hidden-text (type &optional dummy)
3382 "Show all hidden text of type TYPE.
3383 Originally it is hide instead of DUMMY."
3384 (let ((inhibit-read-only t)
3385 (inhibit-point-motion-hooks t))
3386 (gnus-remove-text-properties-when
3388 (point-min) (point-max)
3389 (cons 'article-type (cons type
3390 gnus-hidden-properties)))
3391 (gnus-delete-wash-type type)))
3393 (defconst article-time-units
3394 `((year . ,(* 365.25 24 60 60))
3395 (week . ,(* 7 24 60 60))
3396 (day . ,(* 24 60 60))
3400 "Mapping from time units to seconds.")
3402 (defun gnus-article-forward-header ()
3403 "Move point to the start of the next header.
3404 If the current header is a continuation header, this can be several
3409 (if (looking-at "[ \t]+[^ \t]")
3413 (defun article-treat-date ()
3414 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3415 (with-current-buffer gnus-summary-buffer
3416 gnus-article-date-headers)
3417 gnus-article-date-headers)
3420 (defun article-date-ut (&optional type highlight date-position)
3421 "Convert DATE date to TYPE in the current article.
3422 The default type is `ut'. See `gnus-article-date-headers' for
3424 (interactive (list 'ut t))
3425 (let* ((case-fold-search t)
3426 (inhibit-read-only t)
3427 (inhibit-point-motion-hooks t)
3429 (visible-date (mail-fetch-field "Date"))
3430 pos date bface eface)
3432 (goto-char (point-min))
3433 (when (re-search-forward "^Date:" nil t)
3434 (setq bface (get-text-property (point-at-bol) 'face)
3435 eface (get-text-property (1- (point-at-eol)) 'face)))
3436 ;; Delete any old Date headers.
3439 (goto-char date-position)
3440 (setq date (get-text-property (point) 'original-date))
3441 (delete-region (point)
3443 (gnus-article-forward-header)
3445 (article-transform-date date type bface eface))
3448 (goto-char (point-min))
3449 (while (or (get-text-property (setq pos (point)) 'original-date)
3450 (and (setq pos (next-single-property-change
3451 (point) 'original-date))
3453 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3454 (1+ (match-beginning 0))
3456 (goto-char (point-min))
3457 (while (re-search-forward "^Date:" nil t)
3458 (setq date (get-text-property (match-beginning 0) 'original-date))
3459 (delete-region (point-at-bol) (progn
3460 (gnus-article-forward-header)
3462 (when (and (not date)
3464 (setq date visible-date))
3466 (article-transform-date date type bface eface))
3467 (goto-char (point-max))
3470 (defun article-transform-date (date type bface eface)
3471 (dolist (this-type (cond
3478 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3481 (put-text-property (point) (1+ (point))
3482 'original-date date)
3483 (put-text-property (point) (1+ (point))
3484 'gnus-date-type this-type)
3486 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3487 (put-text-property (match-beginning 1) (1+ (match-end 1))
3489 (put-text-property (match-beginning 2) (match-end 2)
3493 (defun article-make-date-line (date type)
3494 "Return a DATE line of TYPE."
3495 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3497 (error "Unknown conversion type: %s" type))
3499 (let ((time (ignore-errors (date-to-time date))))
3501 ;; Convert to the local timezone.
3503 (concat "Date: " (message-make-date time)))
3504 ;; Convert to Universal Time.
3509 (let* ((e (parse-time-string date))
3510 (tm (apply 'encode-time e))
3512 (ls (- (cadr tm) (car (current-time-zone time)))))
3513 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3514 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3518 ;; Get the original date from the article.
3519 ((eq type 'original)
3520 (concat "Date: " (if (string-match "\n+$" date)
3521 (substring date 0 (match-beginning 0))
3523 ;; Let the user define the format.
3524 ((eq type 'user-defined)
3525 (let ((format (or (condition-case nil
3526 (with-current-buffer gnus-summary-buffer
3527 gnus-article-time-format)
3529 gnus-article-time-format)))
3530 (if (functionp format)
3531 (funcall format time)
3532 (concat "Date: " (format-time-string format time)))))
3535 (let ((tz (car (current-time-zone time))))
3538 (format-time-string "%Y%m%dT%H%M%S" time)
3539 (format "%s%02d%02d"
3540 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3541 (/ (% (abs tz) 3600) 60)))))
3542 ;; Do a lapsed format.
3544 (concat "Date: " (article-lapsed-string time)))
3545 ;; A combined date/lapsed format.
3546 ((eq type 'combined-lapsed)
3547 (let ((date-string (article-make-date-line date 'original))
3553 (concat " (" (article-lapsed-string time segments) ")"))
3554 (> (+ (length date-string)
3555 (length lapsed-string))
3558 (setq segments (1- segments)))
3560 (concat date-string lapsed-string)
3562 ;; Display the date in proper English
3564 (let ((dtime (decode-time time)))
3567 (number-to-string (nth 3 dtime))
3568 (let ((digit (% (nth 3 dtime) 10)))
3570 ((memq (nth 3 dtime) '(11 12 13)) "th")
3576 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3578 (number-to-string (nth 5 dtime))
3580 (format "%02d" (nth 2 dtime))
3582 (format "%02d" (nth 1 dtime)))))))
3584 (format "Date: %s (from Gnus)" date))))
3586 (defun article-lapsed-string (time &optional max-segments)
3587 ;; If the date is seriously mangled, the timezone functions are
3588 ;; liable to bug out, so we ignore all errors.
3589 (let* ((now (current-time))
3590 (real-time (subtract-time now time))
3591 (real-sec (and real-time
3592 (+ (* (float (car real-time)) 65536)
3594 (sec (and real-time (abs real-sec)))
3597 (unless max-segments
3598 (setq max-segments (length article-time-units)))
3606 ;; This is a bit convoluted, but basically we go
3607 ;; through the time units for years, weeks, etc,
3608 ;; and divide things to see whether that results
3609 ;; in positive answers.
3612 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3613 (>= segments max-segments))
3614 ;; The (remaining) seconds are too few to
3615 ;; be divided into this time unit.
3617 ;; It's big enough, so we output it.
3618 (setq sec (- sec (* num (cdr unit))))
3620 (concat (if prev ", " "") (int-to-string
3622 " " (symbol-name (car unit))
3623 (if (> num 1) "s" ""))
3625 segments (1+ segments)))))
3626 article-time-units "")
3627 ;; If dates are odd, then it might appear like the
3628 ;; article was sent in the future.
3631 " in the future"))))))
3633 (defun article-date-local (&optional highlight)
3634 "Convert the current article date to the local timezone."
3635 (interactive (list t))
3636 (article-date-ut 'local highlight))
3638 (defun article-date-english (&optional highlight)
3639 "Convert the current article date to something that is proper English."
3640 (interactive (list t))
3641 (article-date-ut 'english highlight))
3643 (defun article-date-original (&optional highlight)
3644 "Convert the current article date to what it was originally.
3645 This is only useful if you have used some other date conversion
3646 function and want to see what the date was before converting."
3647 (interactive (list t))
3648 (article-date-ut 'original highlight))
3650 (defun article-date-lapsed (&optional highlight)
3651 "Convert the current article date to time lapsed since it was sent."
3652 (interactive (list t))
3653 (article-date-ut 'lapsed highlight))
3655 (defun article-date-combined-lapsed (&optional highlight)
3656 "Convert the current article date to time lapsed since it was sent."
3657 (interactive (list t))
3658 (article-date-ut 'combined-lapsed highlight))
3660 (defun article-update-date-lapsed ()
3661 "Function to be run from a timer to update the lapsed time line."
3663 (let ((buffer (current-buffer)))
3667 (set-buffer (window-buffer w))
3668 (when (eq major-mode 'gnus-article-mode)
3669 (let ((old-line (count-lines (point-min) (point)))
3670 (old-column (- (point) (line-beginning-position)))
3672 (window-start (get-buffer-window (current-buffer)))))
3673 (goto-char (point-min))
3674 (while (re-search-forward "^Date:" nil t)
3675 (let ((type (get-text-property (match-beginning 0)
3677 (when (memq type '(lapsed combined-lapsed user-format))
3678 (when (and window-start
3679 (not (= window-start
3683 (setq window-start nil))
3685 (article-date-ut type t (match-beginning 0)))
3688 (set-window-start (get-buffer-window (current-buffer))
3690 (goto-char (point-min))
3691 (when (> old-column 0)
3692 (setq old-line (1- old-line)))
3693 (forward-line old-line)
3695 (when (> (current-column) old-column)
3697 (forward-char old-column)))))
3699 (set-buffer buffer))))
3701 (defun gnus-start-date-timer (&optional n)
3702 "Start a timer to update the Date headers in the article buffers.
3703 The numerical prefix says how frequently (in seconds) the function
3708 (gnus-stop-date-timer)
3709 (setq article-lapsed-timer
3710 (run-at-time 1 n 'article-update-date-lapsed)))
3712 (defun gnus-stop-date-timer ()
3713 "Stop the Date timer."
3715 (when article-lapsed-timer
3716 (nnheader-cancel-timer article-lapsed-timer)
3717 (setq article-lapsed-timer nil)))
3719 (defun article-date-user (&optional highlight)
3720 "Convert the current article date to the user-defined format.
3721 This format is defined by the `gnus-article-time-format' variable."
3722 (interactive (list t))
3723 (article-date-ut 'user highlight))
3725 (defun article-date-iso8601 (&optional highlight)
3726 "Convert the current article date to ISO8601."
3727 (interactive (list t))
3728 (article-date-ut 'iso8601 highlight))
3730 (defmacro gnus-article-save-original-date (&rest forms)
3731 "Save the original date as a text property and evaluate FORMS."
3732 `(let* ((case-fold-search t)
3734 (goto-char (point-min))
3735 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3738 (date (when (and start
3739 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3741 (buffer-substring-no-properties start
3742 (match-beginning 0)))))
3743 (goto-char (point-max))
3744 (skip-chars-backward "\n")
3745 (put-text-property (point-min) (point) 'original-date date)
3747 (goto-char (point-max))
3748 (skip-chars-backward "\n")
3749 (put-text-property (point-min) (point) 'original-date date)))
3751 ;; (defun article-show-all ()
3752 ;; "Show all hidden text in the article buffer."
3755 ;; (let ((inhibit-read-only t))
3756 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3758 (defun article-remove-leading-whitespace ()
3759 "Remove excessive whitespace from all headers."
3763 (let ((inhibit-read-only t))
3764 (article-narrow-to-head)
3765 (goto-char (point-min))
3766 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3767 (delete-region (match-beginning 1) (match-end 1)))))))
3769 (defun article-emphasize (&optional arg)
3770 "Emphasize text according to `gnus-emphasis-alist'."
3771 (interactive (gnus-article-hidden-arg))
3772 (unless (gnus-article-check-hidden-text 'emphasis arg)
3776 (with-current-buffer gnus-summary-buffer
3777 gnus-article-emphasis-alist)
3779 gnus-emphasis-alist))
3780 (inhibit-read-only t)
3781 (props (append '(article-type emphasis)
3782 gnus-hidden-properties))
3783 regexp elem beg invisible visible face)
3786 (while (setq elem (pop alist))
3788 (setq regexp (car elem)
3789 invisible (nth 1 elem)
3790 visible (nth 2 elem)
3792 (while (re-search-forward regexp nil t)
3793 (when (and (match-beginning visible) (match-beginning invisible))
3794 (gnus-article-hide-text
3795 (match-beginning invisible) (match-end invisible) props)
3796 (gnus-article-unhide-text-type
3797 (match-beginning visible) (match-end visible) 'emphasis)
3798 (gnus-put-overlay-excluding-newlines
3799 (match-beginning visible) (match-end visible) 'face face)
3800 (gnus-add-wash-type 'emphasis)
3801 (goto-char (match-end invisible)))))))))
3803 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3804 "Setup newsgroup emphasis alist."
3805 (unless gnus-article-emphasis-alist
3806 (let ((name (and gnus-newsgroup-name
3807 (gnus-group-real-name gnus-newsgroup-name))))
3808 (make-local-variable 'gnus-article-emphasis-alist)
3809 (setq gnus-article-emphasis-alist
3811 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3812 (while (setq elem (pop alist))
3813 (when (and name (string-match (car elem) name))
3815 highlight (copy-sequence (cdr elem)))))
3817 (copy-sequence highlight-words)
3818 (if gnus-newsgroup-name
3819 (copy-sequence (gnus-group-find-parameter
3820 gnus-newsgroup-name 'highlight-words t)))
3821 gnus-emphasis-alist)))))
3823 (defvar gnus-summary-article-menu)
3824 (defvar gnus-summary-post-menu)
3826 ;;; Saving functions.
3828 (defun gnus-article-save (save-buffer file &optional num)
3829 "Save the currently selected article."
3830 (when (or (get gnus-default-article-saver :headers)
3831 (not gnus-save-all-headers))
3832 ;; Remove headers according to `gnus-saved-headers' or the value
3833 ;; of the `:headers' property that the saver function might have.
3834 (let ((gnus-visible-headers
3835 (or (symbol-value (get gnus-default-article-saver :headers))
3836 gnus-saved-headers gnus-visible-headers))
3837 ;; Ignore group parameter. See `article-hide-headers'.
3838 (gnus-summary-buffer nil))
3839 (with-current-buffer save-buffer
3840 (article-hide-headers 1 t))))
3841 (save-window-excursion
3842 (if (not gnus-default-article-saver)
3843 (error "No default saver is defined")
3844 ;; !!! Magic! The saving functions all save
3845 ;; `gnus-save-article-buffer' (or so they think), but we
3846 ;; bind that variable to our save-buffer.
3847 (set-buffer gnus-article-buffer)
3848 (let* ((gnus-save-article-buffer save-buffer)
3851 ((not gnus-prompt-before-saving) 'default)
3852 ((eq gnus-prompt-before-saving 'always) nil)
3854 (gnus-number-of-articles-to-be-saved
3855 (when (eq gnus-prompt-before-saving t)
3857 (set-buffer gnus-article-current-summary)
3858 (funcall gnus-default-article-saver filename)))))
3860 (defun gnus-read-save-file-name (prompt &optional filename
3861 function group headers variable
3864 (funcall function group headers (symbol-value variable)))
3869 ((eq filename 'default)
3875 (when (symbol-value dir-var)
3876 (setq default-name (expand-file-name
3877 (file-name-nondirectory default-name)
3878 (symbol-value dir-var))))
3879 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3882 (if (and gnus-number-of-articles-to-be-saved
3883 (> gnus-number-of-articles-to-be-saved 1))
3884 (format "these %d articles"
3885 gnus-number-of-articles-to-be-saved)
3888 ;; Let the split methods have their say.
3890 ;; No split name was found.
3893 (concat prompt " (default "
3894 (file-name-nondirectory default-name) "): ")
3895 (file-name-directory default-name)
3897 ;; A single group name is returned.
3898 ((stringp split-name)
3900 (funcall function split-name headers
3901 (symbol-value variable)))
3903 (concat prompt " (default "
3904 (file-name-nondirectory default-name) "): ")
3905 (file-name-directory default-name)
3907 ;; A single split name was found
3908 ((= 1 (length split-name))
3909 (let* ((name (expand-file-name
3911 gnus-article-save-directory))
3912 (dir (cond ((file-directory-p name)
3913 (file-name-as-directory name))
3914 ((file-exists-p name) name)
3915 (t gnus-article-save-directory))))
3917 (concat prompt " (default " name "): ")
3919 ;; A list of splits was found.
3921 (setq split-name (nreverse split-name))
3923 (let ((file-name-history
3924 (nconc split-name file-name-history)))
3928 (concat prompt " (`M-p' for defaults): ")
3929 gnus-article-save-directory
3931 gnus-article-save-directory)))
3932 (car (push result file-name-history)))))))
3933 ;; Create the directory.
3934 (gnus-make-directory (file-name-directory file))
3935 ;; If we have read a directory, we append the default file name.
3936 (when (file-directory-p file)
3937 (setq file (expand-file-name (file-name-nondirectory
3939 (file-name-as-directory file))))
3940 ;; Possibly translate some characters.
3941 (nnheader-translate-file-chars file))))))
3942 (gnus-make-directory (file-name-directory result))
3944 (set variable result))
3946 (set dir-var (file-name-directory result)))
3949 (defun gnus-article-archive-name (group)
3950 "Return the first instance of an \"Archive-name\" in the current buffer."
3951 (let ((case-fold-search t))
3952 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3953 (nnheader-concat gnus-article-save-directory
3954 (match-string 1)))))
3956 (defun gnus-article-nndoc-name (group)
3957 "If GROUP is an nndoc group, return the name of the parent group."
3958 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3959 (gnus-group-get-parameter group 'save-article-group)))
3961 (defun gnus-summary-save-in-rmail (&optional filename)
3962 "Append this article to Rmail file.
3963 Optional argument FILENAME specifies file name.
3964 Directory to save to is default to `gnus-article-save-directory'."
3965 (setq filename (gnus-read-save-file-name
3966 "Save %s in rmail file" filename
3967 gnus-rmail-save-name gnus-newsgroup-name
3968 gnus-current-headers 'gnus-newsgroup-last-rmail))
3969 (with-current-buffer gnus-save-article-buffer
3973 ;; Note that unlike gnus-summary-save-in-mail, there is no
3974 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3976 (gnus-output-to-rmail filename))))
3979 (defun gnus-summary-save-in-mail (&optional filename)
3980 "Append this article to Unix mail file.
3981 Optional argument FILENAME specifies file name.
3982 Directory to save to is default to `gnus-article-save-directory'."
3983 (setq filename (gnus-read-save-file-name
3984 "Save %s in Unix mail file" filename
3985 gnus-mail-save-name gnus-newsgroup-name
3986 gnus-current-headers 'gnus-newsgroup-last-mail))
3987 (with-current-buffer gnus-save-article-buffer
3991 (if (and (file-readable-p filename)
3992 (file-regular-p filename)
3993 (mail-file-babyl-p filename))
3994 (gnus-output-to-rmail filename)
3995 (gnus-output-to-mail filename)))))
3998 (put 'gnus-summary-save-in-file :decode t)
3999 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4000 (defun gnus-summary-save-in-file (&optional filename overwrite)
4001 "Append this article to file.
4002 Optional argument FILENAME specifies file name.
4003 Directory to save to is default to `gnus-article-save-directory'."
4004 (setq filename (gnus-read-save-file-name
4005 "Save %s in file" filename
4006 gnus-file-save-name gnus-newsgroup-name
4007 gnus-current-headers 'gnus-newsgroup-last-file))
4008 (with-current-buffer gnus-save-article-buffer
4012 (when (and overwrite
4013 (file-exists-p filename))
4014 (delete-file filename))
4015 (gnus-output-to-file filename))))
4018 (put 'gnus-summary-write-to-file :decode t)
4019 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4020 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4021 (defun gnus-summary-write-to-file (&optional filename)
4022 "Write this article to a file, overwriting it if the file exists.
4023 Optional argument FILENAME specifies file name.
4024 The directory to save in defaults to `gnus-article-save-directory'."
4025 (setq filename (gnus-read-save-file-name
4026 "Save %s in file" filename
4027 gnus-file-save-name gnus-newsgroup-name
4028 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4029 (gnus-summary-save-in-file filename t))
4031 (put 'gnus-summary-save-body-in-file :decode t)
4032 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4033 "Append this article body to a file.
4034 Optional argument FILENAME specifies file name.
4035 The directory to save in defaults to `gnus-article-save-directory'."
4036 (setq filename (gnus-read-save-file-name
4037 "Save %s body in file" filename
4038 gnus-file-save-name gnus-newsgroup-name
4039 gnus-current-headers 'gnus-newsgroup-last-file))
4040 (with-current-buffer gnus-save-article-buffer
4044 (when (article-goto-body)
4045 (narrow-to-region (point) (point-max)))
4046 (when (and overwrite
4047 (file-exists-p filename))
4048 (delete-file filename))
4049 (gnus-output-to-file filename))))
4052 (put 'gnus-summary-write-body-to-file :decode t)
4053 (put 'gnus-summary-write-body-to-file
4054 :function 'gnus-summary-save-body-in-file)
4055 (defun gnus-summary-write-body-to-file (&optional filename)
4056 "Write this article body to a file, overwriting it if the file exists.
4057 Optional argument FILENAME specifies file name.
4058 The directory to save in defaults to `gnus-article-save-directory'."
4059 (setq filename (gnus-read-save-file-name
4060 "Save %s body in file" filename
4061 gnus-file-save-name gnus-newsgroup-name
4062 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4063 (gnus-summary-save-body-in-file filename t))
4065 (put 'gnus-summary-save-in-pipe :decode t)
4066 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4067 (defun gnus-summary-save-in-pipe (&optional command raw)
4068 "Pipe this article to subprocess COMMAND.
4069 Valid values for COMMAND include:
4071 The executable command name and possibly arguments.
4073 You will be prompted for the command in the minibuffer.
4074 the symbol `default'
4075 It will be replaced with the command which the variable
4076 `gnus-summary-pipe-output-default-command' holds or the command
4077 last used for saving.
4078 Non-nil value for RAW overrides `:decode' and `:headers' properties
4079 and the raw article including all headers will be piped."
4080 (let ((article (gnus-summary-article-number))
4082 (get 'gnus-summary-save-in-pipe :decode)))
4083 save-buffer default)
4085 (if (vectorp (gnus-summary-article-header article))
4086 (save-current-buffer
4087 (gnus-summary-select-article decode decode nil article)
4088 (insert-buffer-substring
4092 gnus-original-article-buffer)
4094 (nnheader-set-temp-buffer " *Gnus Save*"))))
4095 ;; Remove unwanted headers.
4096 (when (and (not raw)
4097 (or (get 'gnus-summary-save-in-pipe :headers)
4098 (not gnus-save-all-headers)))
4099 (let ((gnus-visible-headers
4100 (or (symbol-value (get 'gnus-summary-save-in-pipe
4102 gnus-saved-headers gnus-visible-headers))
4103 (gnus-summary-buffer nil))
4104 (article-hide-headers 1 t))))
4105 (error "%d is not a real article" article))
4106 (error "No article to pipe"))
4107 (setq default (or gnus-summary-pipe-output-default-command
4108 gnus-last-shell-command))
4109 (unless (stringp command)
4111 (if (and (eq command 'default) default)
4113 (gnus-read-shell-command "Shell command on this article: "
4115 (when (string-equal command "")
4117 (setq command default)
4118 (error "A command is required")))
4119 (with-current-buffer save-buffer
4122 (shell-command-on-region (point-min) (point-max) command nil)))
4123 (gnus-kill-buffer save-buffer))
4124 (setq gnus-summary-pipe-output-default-command command))
4126 (defun gnus-summary-pipe-to-muttprint (&optional command)
4127 "Pipe this article to muttprint."
4128 (unless (stringp command)
4129 (setq command (read-string
4130 "Print using command: " gnus-summary-muttprint-program
4131 nil gnus-summary-muttprint-program)))
4132 (let ((gnus-summary-pipe-output-default-command
4133 gnus-summary-pipe-output-default-command))
4134 (gnus-summary-save-in-pipe command))
4135 (setq gnus-summary-muttprint-program command))
4137 ;;; Article file names when saving.
4139 (defun gnus-capitalize-newsgroup (newsgroup)
4140 "Capitalize NEWSGROUP name."
4141 (when (not (zerop (length newsgroup)))
4142 (concat (char-to-string (upcase (aref newsgroup 0)))
4143 (substring newsgroup 1))))
4145 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4146 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4147 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4148 Otherwise, it is like ~/News/news/group/num."
4151 (concat (if (gnus-use-long-file-name 'not-save)
4152 (gnus-capitalize-newsgroup newsgroup)
4153 (gnus-newsgroup-directory-form newsgroup))
4154 "/" (int-to-string (mail-header-number headers)))
4155 gnus-article-save-directory)))
4157 (string-equal (file-name-directory default)
4158 (file-name-directory last-file))
4159 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4161 (or last-file default))))
4163 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4164 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4165 If variable `gnus-use-long-file-name' is non-nil, it is
4166 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4169 (concat (if (gnus-use-long-file-name 'not-save)
4171 (gnus-newsgroup-directory-form newsgroup))
4172 "/" (int-to-string (mail-header-number headers)))
4173 gnus-article-save-directory)))
4175 (string-equal (file-name-directory default)
4176 (file-name-directory last-file))
4177 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4179 (or last-file default))))
4181 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4182 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4183 If variable `gnus-use-long-file-name' is non-nil, it is
4184 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4187 (if (gnus-use-long-file-name 'not-save)
4190 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4192 gnus-article-save-directory)))
4194 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4195 "Generate file name from sender."
4196 (let ((from (mail-header-from headers)))
4198 (if (and from (string-match "\\([^ <]+\\)@" from))
4199 (match-string 1 from)
4201 gnus-article-save-directory)))
4203 (defun article-verify-x-pgp-sig ()
4205 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4207 (if (gnus-buffer-live-p gnus-original-article-buffer)
4208 (let ((sig (with-current-buffer gnus-original-article-buffer
4209 (gnus-fetch-field "X-PGP-Sig")))
4213 (mml2015-clear-verify-function))
4215 (insert-buffer-substring gnus-original-article-buffer)
4216 (setq items (split-string sig))
4217 (message-narrow-to-head)
4218 (let ((inhibit-point-motion-hooks t)
4219 (case-fold-search t))
4220 ;; Don't verify multiple headers.
4221 (setq headers (mapconcat (lambda (header)
4223 (mail-fetch-field header)
4225 (split-string (nth 1 items) ",") "")))
4226 (delete-region (point-min) (point-max))
4227 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4228 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4233 (if (looking-at "^-")
4236 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4237 (insert "Version: " (car items) "\n\n")
4238 (insert (mapconcat 'identity (cddr items) "\n"))
4239 (insert "\n-----END PGP SIGNATURE-----\n")
4240 (let ((mm-security-handle (list (format "multipart/signed"))))
4241 (mml2015-clean-buffer)
4242 (let ((coding-system-for-write (or gnus-newsgroup-charset
4244 (funcall (mml2015-clear-verify-function)))
4246 (or (mm-handle-multipart-ctl-parameter
4247 mm-security-handle 'gnus-details)
4248 (mm-handle-multipart-ctl-parameter
4249 mm-security-handle 'gnus-info)))))
4251 (let ((inhibit-read-only t) bface eface)
4253 (message-narrow-to-head)
4254 (goto-char (point-max))
4256 (setq bface (get-text-property (point-at-bol) 'face)
4257 eface (get-text-property (1- (point-at-eol)) 'face))
4258 (message-remove-header "X-Gnus-PGP-Verify")
4259 (if (re-search-forward "^X-PGP-Sig:" nil t)
4261 (goto-char (point-max)))
4262 (narrow-to-region (point) (point))
4263 (insert "X-Gnus-PGP-Verify: " info "\n")
4264 (goto-char (point-min))
4267 (if (not (looking-at "^[ \t]"))
4271 (goto-char (point-min))
4272 (when (looking-at "\\([^:]+\\): *")
4273 (put-text-property (match-beginning 1) (1+ (match-end 1))
4275 (put-text-property (match-end 0) (point-max)
4276 'face eface)))))))))
4278 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4280 (defun article-verify-cancel-lock ()
4281 "Verify Cancel-Lock header."
4283 (if (gnus-buffer-live-p gnus-original-article-buffer)
4284 (canlock-verify gnus-original-article-buffer)))
4291 (setq afunc (car func)
4294 gfunc (intern (format "gnus-%s" func))))
4296 (when (fboundp afunc)
4297 `(lambda (&optional interactive &rest args)
4298 ,(documentation afunc t)
4299 (interactive (list t))
4300 (with-current-buffer gnus-article-buffer
4302 (call-interactively ',afunc)
4303 (apply ',afunc args))))))))
4304 '(article-hide-headers
4305 article-verify-x-pgp-sig
4306 article-verify-cancel-lock
4307 article-hide-boring-headers
4308 article-treat-overstrike
4309 article-treat-ansi-sequences
4310 article-fill-long-lines
4311 article-capitalize-sentences
4313 article-remove-leading-whitespace
4314 article-display-x-face
4315 article-display-face
4316 article-de-quoted-unreadable
4317 article-de-base64-unreadable
4320 article-unsplit-urls
4321 article-hide-list-identifiers
4322 article-strip-banner
4325 article-hide-signature
4326 article-strip-headers-in-body
4327 article-remove-trailing-blank-lines
4328 article-strip-leading-blank-lines
4329 article-strip-multiple-blank-lines
4330 article-strip-leading-space
4331 article-strip-trailing-space
4332 article-strip-blank-lines
4333 article-strip-all-blank-lines
4335 article-date-english
4336 article-date-iso8601
4337 article-date-original
4340 article-decode-mime-words
4341 article-decode-charset
4342 article-decode-encoded-words
4345 article-date-combined-lapsed
4347 article-treat-dumbquotes
4348 article-treat-non-ascii
4349 article-normalize-headers
4350 ;;(article-show-all . gnus-article-show-all-headers)
4354 ;;; Gnus article mode
4357 (put 'gnus-article-mode 'mode-class 'special)
4359 (set-keymap-parent gnus-article-mode-map widget-keymap)
4361 (gnus-define-keys gnus-article-mode-map
4362 " " gnus-article-goto-next-page
4363 "\177" gnus-article-goto-prev-page
4364 [delete] gnus-article-goto-prev-page
4365 [backspace] gnus-article-goto-prev-page
4366 "\C-c^" gnus-article-refer-article
4367 "h" gnus-article-show-summary
4368 "s" gnus-article-show-summary
4369 "\C-c\C-m" gnus-article-mail
4370 "?" gnus-article-describe-briefly
4371 "<" beginning-of-buffer
4373 "\C-c\C-i" gnus-info-find-node
4375 "R" gnus-article-reply-with-original
4376 "F" gnus-article-followup-with-original
4377 "\C-hk" gnus-article-describe-key
4378 "\C-hc" gnus-article-describe-key-briefly
4379 "\C-hb" gnus-article-describe-bindings
4381 "e" gnus-article-read-summary-keys
4382 "\C-d" gnus-article-read-summary-keys
4383 "\M-*" gnus-article-read-summary-keys
4384 "\M-#" gnus-article-read-summary-keys
4385 "\M-^" gnus-article-read-summary-keys
4386 "\M-g" gnus-article-read-summary-keys)
4388 (substitute-key-definition
4389 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4391 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4392 "W" gnus-article-wide-reply-with-original)
4393 (if (featurep 'xemacs)
4394 (set-keymap-default-binding gnus-article-send-map
4395 'gnus-article-read-summary-send-keys)
4396 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4398 (defun gnus-article-make-menu-bar ()
4399 (unless (boundp 'gnus-article-commands-menu)
4400 (gnus-summary-make-menu-bar))
4401 (unless (boundp 'gnus-article-article-menu)
4403 gnus-article-article-menu gnus-article-mode-map ""
4405 ["Scroll forwards" gnus-article-goto-next-page t]
4406 ["Scroll backwards" gnus-article-goto-prev-page t]
4407 ["Show summary" gnus-article-show-summary t]
4408 ["Fetch Message-ID at point" gnus-article-refer-article t]
4409 ["Mail to address at point" gnus-article-mail t]
4410 ["Send a bug report" gnus-bug t]))
4413 gnus-article-treatment-menu gnus-article-mode-map ""
4414 ;; Fixme: this should use :active (and maybe :visible).
4416 ["Hide headers" gnus-article-hide-headers t]
4417 ["Hide signature" gnus-article-hide-signature t]
4418 ["Hide citation" gnus-article-hide-citation t]
4419 ["Treat overstrike" gnus-article-treat-overstrike t]
4420 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4421 ["Remove carriage return" gnus-article-remove-cr t]
4422 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4423 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4424 ["Remove base64" gnus-article-de-base64-unreadable t]
4425 ["Treat html" gnus-article-wash-html t]
4426 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4427 ["Decode HZ" gnus-article-decode-HZ t]))
4429 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4431 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4433 (gnus-run-hooks 'gnus-article-menu-hook)))
4435 (defvar bookmark-make-record-function)
4436 (defvar shr-put-image-function)
4438 (defun gnus-article-mode ()
4439 "Major mode for displaying an article.
4441 All normal editing commands are switched off.
4443 The following commands are available in addition to all summary mode
4445 \\<gnus-article-mode-map>
4446 \\[gnus-article-next-page]\t Scroll the article one page forwards
4447 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4448 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4449 \\[gnus-article-show-summary]\t Display the summary buffer
4450 \\[gnus-article-mail]\t Send a reply to the address near point
4451 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4452 \\[gnus-info-find-node]\t Go to the Gnus info node"
4454 (kill-all-local-variables)
4455 (gnus-simplify-mode-line)
4456 (setq mode-name "Article")
4457 (setq major-mode 'gnus-article-mode)
4458 (make-local-variable 'minor-mode-alist)
4459 (use-local-map gnus-article-mode-map)
4460 (when (gnus-visual-p 'article-menu 'menu)
4461 (gnus-article-make-menu-bar)
4462 (when gnus-summary-tool-bar-map
4463 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4464 (gnus-update-format-specifications nil 'article-mode)
4465 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4466 (set (make-local-variable 'gnus-page-broken) nil)
4467 (make-local-variable 'gnus-article-current-summary)
4468 (make-local-variable 'gnus-article-mime-handles)
4469 (make-local-variable 'gnus-article-decoded-p)
4470 (make-local-variable 'gnus-article-mime-handle-alist)
4471 (make-local-variable 'gnus-article-wash-types)
4472 (make-local-variable 'gnus-article-image-alist)
4473 (make-local-variable 'gnus-article-charset)
4474 (make-local-variable 'gnus-article-ignored-charsets)
4475 (set (make-local-variable 'bookmark-make-record-function)
4476 'gnus-summary-bookmark-make-record)
4477 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4479 (set (make-local-variable 'nobreak-char-display) nil)
4480 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4481 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4482 (setq cursor-in-non-selected-windows nil)
4483 (gnus-set-default-directory)
4484 (buffer-disable-undo)
4485 (setq buffer-read-only t
4486 show-trailing-whitespace nil)
4487 (set-syntax-table gnus-article-mode-syntax-table)
4488 (mm-enable-multibyte)
4489 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4491 (defun gnus-article-setup-buffer ()
4492 "Initialize the article buffer."
4493 (let* ((name (if gnus-single-article-buffer "*Article*"
4494 (concat "*Article " gnus-newsgroup-name "*")))
4496 (progn (string-match "\\*Article" name)
4497 (concat " *Original Article"
4498 (substring name (match-end 0))))))
4499 (setq gnus-article-buffer name)
4500 (setq gnus-original-article-buffer original)
4501 (setq gnus-article-mime-handle-alist nil)
4502 (with-current-buffer gnus-summary-buffer
4503 ;; This might be a variable local to the summary buffer.
4504 (unless gnus-single-article-buffer
4505 (setq gnus-article-buffer name)
4506 (setq gnus-original-article-buffer original)
4507 (gnus-set-global-variables)))
4508 (gnus-article-setup-highlight-words)
4509 ;; Init original article buffer.
4510 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4511 (mm-enable-multibyte)
4512 (setq major-mode 'gnus-original-article-mode)
4513 (make-local-variable 'gnus-original-article))
4514 (if (and (get-buffer name)
4515 (with-current-buffer name
4516 (if gnus-article-edit-mode
4517 (if (y-or-n-p "Article mode edit in progress; discard? ")
4519 (set-buffer-modified-p nil)
4520 (gnus-kill-buffer name)
4523 (error "Action aborted"))
4525 (with-current-buffer name
4526 (set (make-local-variable 'gnus-article-edit-mode) nil)
4527 (gnus-article-stop-animations)
4528 (when gnus-article-mime-handles
4529 (mm-destroy-parts gnus-article-mime-handles)
4530 (setq gnus-article-mime-handles nil))
4531 ;; Set it to nil in article-buffer!
4532 (setq gnus-article-mime-handle-alist nil)
4533 (buffer-disable-undo)
4534 (setq buffer-read-only t)
4535 (unless (eq major-mode 'gnus-article-mode)
4536 (gnus-article-mode))
4537 (setq truncate-lines gnus-article-truncate-lines)
4539 (with-current-buffer (gnus-get-buffer-create name)
4541 (setq truncate-lines gnus-article-truncate-lines)
4542 (make-local-variable 'gnus-summary-buffer)
4543 (setq gnus-summary-buffer
4544 (gnus-summary-buffer-name gnus-newsgroup-name))
4545 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4546 (when article-lapsed-timer
4547 (gnus-stop-date-timer))
4548 (when gnus-article-update-date-headers
4549 (gnus-start-date-timer gnus-article-update-date-headers))
4550 (current-buffer)))))
4552 (defun gnus-article-stop-animations ()
4553 (dolist (timer (and (boundp 'timer-list)
4555 (when (eq (elt timer 5) 'image-animate-timeout)
4556 (cancel-timer timer))))
4558 ;; Set article window start at LINE, where LINE is the number of lines
4559 ;; from the head of the article.
4560 (defun gnus-article-set-window-start (&optional line)
4561 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4562 (when article-window
4565 (with-current-buffer gnus-article-buffer
4566 (goto-char (point-min))
4569 (gnus-message 6 "Moved to bookmark")
4570 (search-forward "\n\n" nil t)
4574 (defun gnus-article-prepare (article &optional all-headers header)
4575 "Prepare ARTICLE in article mode buffer.
4576 ARTICLE should either be an article number or a Message-ID.
4577 If ARTICLE is an id, HEADER should be the article headers.
4578 If ALL-HEADERS is non-nil, no headers are hidden."
4580 ;; Make sure we start in a summary buffer.
4581 (unless (eq major-mode 'gnus-summary-mode)
4582 (set-buffer gnus-summary-buffer))
4583 (setq gnus-summary-buffer (current-buffer))
4584 (let* ((gnus-article (if header (mail-header-number header) article))
4585 (summary-buffer (current-buffer))
4586 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4587 (group gnus-newsgroup-name)
4590 (gnus-article-setup-buffer)
4591 (set-buffer gnus-article-buffer)
4592 ;; Deactivate active regions.
4593 (when (and (boundp 'transient-mark-mode)
4594 transient-mark-mode)
4595 (setq mark-active nil))
4596 (if (not (setq result (let ((inhibit-read-only t))
4597 (gnus-request-article-this-buffer
4599 ;; There is no such article.
4601 (when (and (numberp article)
4602 (not (memq article gnus-newsgroup-sparse)))
4603 (setq gnus-article-current
4604 (cons gnus-newsgroup-name article))
4605 (set-buffer gnus-summary-buffer)
4606 (setq gnus-current-article article)
4607 (if (and (memq article gnus-newsgroup-undownloaded)
4608 (not (gnus-online (gnus-find-method-for-group
4609 gnus-newsgroup-name))))
4611 (gnus-summary-set-agent-mark article)
4612 (message "Message marked for downloading"))
4613 (gnus-summary-mark-article article gnus-canceled-mark)
4614 (unless (memq article gnus-newsgroup-sparse)
4615 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4616 (if (or (eq result 'pseudo)
4617 (eq result 'nneething))
4619 (with-current-buffer summary-buffer
4620 (push article gnus-newsgroup-history)
4621 (setq gnus-last-article gnus-current-article
4622 gnus-current-article 0
4623 gnus-current-headers nil
4624 gnus-article-current nil)
4625 (if (eq result 'nneething)
4626 (gnus-configure-windows 'summary)
4627 (gnus-configure-windows 'article))
4628 (gnus-set-global-variables))
4629 (let ((gnus-article-mime-handle-alist-1
4630 gnus-article-mime-handle-alist))
4631 (gnus-set-mode-line 'article)))
4632 ;; The result from the `request' was an actual article -
4633 ;; or at least some text that is now displayed in the
4635 (when (and (numberp article)
4636 (not (eq article gnus-current-article)))
4637 ;; Seems like a new article has been selected.
4638 ;; `gnus-current-article' must be an article number.
4639 (with-current-buffer summary-buffer
4640 (push article gnus-newsgroup-history)
4641 (setq gnus-last-article gnus-current-article
4642 gnus-current-article article
4643 gnus-current-headers
4644 (gnus-summary-article-header gnus-current-article)
4645 gnus-article-current
4646 (cons gnus-newsgroup-name gnus-current-article))
4647 (unless (vectorp gnus-current-headers)
4648 (setq gnus-current-headers nil))
4649 (gnus-summary-goto-subject gnus-current-article)
4650 (when (gnus-summary-show-thread)
4651 ;; If the summary buffer really was folded, the
4652 ;; previous goto may not actually have gone to
4653 ;; the right article, but the thread root instead.
4655 (gnus-summary-goto-subject gnus-current-article))
4656 (gnus-run-hooks 'gnus-mark-article-hook)
4657 (gnus-set-mode-line 'summary)
4658 (when (gnus-visual-p 'article-highlight 'highlight)
4659 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4660 ;; Set the global newsgroup variables here.
4661 (gnus-set-global-variables)
4662 (setq gnus-have-all-headers
4663 (or all-headers gnus-show-all-headers))))
4665 (gnus-configure-windows 'article))
4666 (when (or (numberp article)
4668 (gnus-article-prepare-display)
4670 (goto-char (point-min))
4671 (when gnus-break-pages
4672 (gnus-narrow-to-page)))
4673 (let ((gnus-article-mime-handle-alist-1
4674 gnus-article-mime-handle-alist))
4675 (gnus-set-mode-line 'article))
4679 (set-window-point (get-buffer-window (current-buffer)) (point))
4680 (gnus-configure-windows 'article)
4681 (gnus-run-hooks 'gnus-article-prepare-hook)
4685 (defun gnus-article-prepare-display ()
4686 "Make the current buffer look like a nice article."
4687 ;; Hooks for getting information from the article.
4688 ;; This hook must be called before being narrowed.
4689 (let ((gnus-article-buffer (current-buffer))
4691 (inhibit-read-only t))
4692 (unless (eq major-mode 'gnus-article-mode)
4693 (gnus-article-mode))
4694 (setq buffer-read-only nil
4695 gnus-article-wash-types nil
4696 gnus-article-image-alist nil)
4697 (gnus-run-hooks 'gnus-tmp-internal-hook)
4698 (when gnus-display-mime-function
4699 (funcall gnus-display-mime-function))))
4702 ;;; Gnus Sticky Article Mode
4705 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4706 "Mode for sticky articles."
4707 ;; Release bindings that won't work.
4708 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4709 gnus-sticky-article-mode-map)
4710 (substitute-key-definition 'gnus-article-refer-article 'undefined
4711 gnus-sticky-article-mode-map)
4712 (dolist (k '("e" "h" "s" "F" "R"))
4713 (define-key gnus-sticky-article-mode-map k nil))
4714 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4715 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4716 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4717 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4719 (defun gnus-sticky-article (arg)
4720 "Make the current article sticky.
4721 If a prefix ARG is given, ask for a name for this sticky article buffer."
4723 (gnus-summary-show-thread)
4724 (gnus-summary-select-article nil nil 'pseudo)
4725 (let (new-art-buf-name)
4726 (gnus-eval-in-buffer-window gnus-article-buffer
4727 (setq new-art-buf-name
4731 (read-from-minibuffer "Sticky article buffer name: ")
4732 (gnus-with-article-headers
4733 (gnus-article-goto-header "subject")
4734 (setq new-art-buf-name
4735 (buffer-substring-no-properties
4736 (line-beginning-position) (line-end-position)))
4737 (goto-char (point-min))
4738 (gnus-article-goto-header "from")
4739 (setq new-art-buf-name
4741 new-art-buf-name ", "
4742 (buffer-substring-no-properties
4743 (line-beginning-position) (line-end-position))))
4744 (goto-char (point-min))
4745 (gnus-article-goto-header "date")
4746 (setq new-art-buf-name
4748 new-art-buf-name ", "
4749 (buffer-substring-no-properties
4750 (line-beginning-position) (line-end-position))))))
4752 (if (and (gnus-buffer-live-p new-art-buf-name)
4753 (with-current-buffer new-art-buf-name
4754 (eq major-mode 'gnus-sticky-article-mode)))
4755 (switch-to-buffer new-art-buf-name)
4756 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4757 (gnus-sticky-article-mode))
4758 (setq gnus-article-buffer new-art-buf-name))
4759 (gnus-summary-recenter)
4760 (gnus-summary-position-point))
4762 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4763 "Kill the given sticky article BUFFER.
4764 If none is given, assume the current buffer and kill it if it has
4765 `gnus-sticky-article-mode'."
4768 (setq buffer (current-buffer)))
4769 (with-current-buffer buffer
4770 (when (eq major-mode 'gnus-sticky-article-mode)
4771 (gnus-kill-buffer buffer))))
4773 (defun gnus-kill-sticky-article-buffers (arg)
4774 "Kill all sticky article buffers.
4775 If a prefix ARG is given, ask for confirmation."
4777 (dolist (buf (gnus-buffers))
4778 (with-current-buffer buf
4779 (when (eq major-mode 'gnus-sticky-article-mode)
4781 (gnus-kill-buffer buf)
4782 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4783 (gnus-kill-buffer buf)))))))
4786 ;;; Gnus MIME viewing functions
4789 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4790 "Format of the MIME buttons.
4792 Valid specifiers include:
4794 %T MIME type, along with additional info
4795 %n The `name' parameter
4796 %d The description, if any
4797 %l The length of the encoded part
4798 %p The part identifier number
4799 %e Dots if the part isn't displayed
4801 General format specifiers can also be used. See Info node
4802 `(gnus)Formatting Variables'.")
4804 (defvar gnus-mime-button-line-format-alist
4805 '((?t gnus-tmp-type ?s)
4806 (?T gnus-tmp-type-long ?s)
4807 (?n gnus-tmp-name ?s)
4808 (?d gnus-tmp-description ?s)
4810 (?l gnus-tmp-length ?d)
4811 (?e gnus-tmp-dots ?s)))
4813 (defvar gnus-mime-button-commands
4814 '((gnus-article-press-button "\r" "Toggle Display")
4815 (gnus-mime-view-part "v" "View Interactively...")
4816 (gnus-mime-view-part-as-type "t" "View As Type...")
4817 (gnus-mime-view-part-as-charset "C" "View As charset...")
4818 (gnus-mime-save-part "o" "Save...")
4819 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4820 (gnus-mime-replace-part "r" "Replace part")
4821 (gnus-mime-delete-part "d" "Delete part")
4822 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4823 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4824 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4825 (gnus-mime-view-part-externally "e" "View Externally")
4826 (gnus-mime-print-part "p" "Print")
4827 (gnus-mime-pipe-part "|" "Pipe To Command...")
4828 (gnus-mime-action-on-part "." "Take action on the part...")))
4830 (defun gnus-article-mime-part-status ()
4831 (if gnus-article-mime-handle-alist-1
4832 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4834 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4837 (defvar gnus-mime-button-map
4838 (let ((map (make-sparse-keymap)))
4839 (define-key map gnus-mouse-2 'gnus-article-push-button)
4840 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4841 (dolist (c gnus-mime-button-commands)
4842 (define-key map (cadr c) (car c)))
4846 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4848 ,@(mapcar (lambda (c)
4849 (vector (caddr c) (car c) :active t))
4850 gnus-mime-button-commands)))
4852 (defvar gnus-url-button-commands
4853 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4855 (defvar gnus-url-button-map
4856 (let ((map (make-sparse-keymap)))
4857 (dolist (c gnus-url-button-commands)
4858 (define-key map (cadr c) (car c)))
4862 gnus-url-button-menu gnus-url-button-map "URL button menu."
4864 ,@(mapcar (lambda (c)
4865 (vector (caddr c) (car c) :active t))
4866 gnus-url-button-commands)))
4868 (defmacro gnus-bind-safe-url-regexp (&rest body)
4869 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4870 `(let ((mm-w3m-safe-url-regexp
4871 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4873 gnus-article-current-summary))
4874 (with-current-buffer gnus-article-current-summary
4875 gnus-newsgroup-name)
4876 gnus-newsgroup-name)))
4877 (if (cond ((not group)
4878 ;; Maybe we're in a mml-preview buffer
4879 ;; and no group is selected.
4881 ((stringp gnus-safe-html-newsgroups)
4882 (string-match gnus-safe-html-newsgroups group))
4883 ((consp gnus-safe-html-newsgroups)
4884 (member group gnus-safe-html-newsgroups)))
4886 mm-w3m-safe-url-regexp))))
4889 (defun gnus-mime-button-menu (event prefix)
4890 "Construct a context-sensitive menu of MIME commands."
4891 (interactive "e\nP")
4892 (save-window-excursion
4893 (let ((pos (event-start event)))
4894 (select-window (posn-window pos))
4895 (goto-char (posn-point pos))
4896 (gnus-article-check-buffer)
4897 (popup-menu gnus-mime-button-menu nil prefix))))
4899 (defun gnus-mime-view-all-parts (&optional handles)
4900 "View all the MIME parts."
4902 (with-current-buffer gnus-article-buffer
4903 (let ((handles (or handles gnus-article-mime-handles))
4904 (mail-parse-charset gnus-newsgroup-charset)
4905 (mail-parse-ignored-charsets
4906 (with-current-buffer gnus-summary-buffer
4907 gnus-newsgroup-ignored-charsets)))
4909 (mm-remove-parts handles)
4910 (goto-char (point-min))
4911 (or (search-forward "\n\n") (goto-char (point-max)))
4912 (let ((inhibit-read-only t))
4913 (delete-region (point) (point-max))
4914 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4916 (defun gnus-article-jump-to-part (n)
4917 "Jump to MIME part N."
4919 (let ((parts (with-current-buffer gnus-article-buffer
4920 (length gnus-article-mime-handle-alist))))
4922 (error "No such part"))
4923 (pop-to-buffer gnus-article-buffer)
4925 (setq n (if (= parts 1)
4927 (read-number (format "Jump to part (1..%s): " parts)))))
4928 (unless (and (integerp n) (<= n parts) (>= n 1))
4931 (gnus-message 7 "Invalid part `%s', using %s instead."
4934 (gnus-message 9 "Jumping to part %s." n)
4935 (cond ((>= gnus-auto-select-part 1)
4936 (while (and (<= n parts)
4937 (not (gnus-article-goto-part n)))
4939 ((< gnus-auto-select-part 0)
4940 (while (and (>= n 1)
4941 (not (gnus-article-goto-part n)))
4944 (gnus-article-goto-part n)))))
4946 (defvar gnus-mime-buttonized-part-id nil
4947 "ID of a mime part that should be buttonized.
4948 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4951 (defsubst gnus-article-edit-part (handles &optional current-id)
4952 "Edit an article in order to delete a mime part.
4953 This function is exclusively used by `gnus-mime-save-part-and-strip'
4954 and `gnus-mime-delete-part', and not provided at run-time normally."
4955 (gnus-article-edit-article
4957 (buffer-disable-undo)
4959 (let ((mail-parse-charset (or gnus-article-charset
4960 ',gnus-newsgroup-charset))
4961 (mail-parse-ignored-charsets
4962 (or gnus-article-ignored-charsets
4963 ',gnus-newsgroup-ignored-charsets))
4964 (mbl mml-buffer-list))
4965 (setq mml-buffer-list nil)
4966 (insert-buffer-substring gnus-original-article-buffer)
4967 (mime-to-mml ',handles)
4968 (setq gnus-article-mime-handles nil)
4969 (let ((mbl1 mml-buffer-list))
4970 (setq mml-buffer-list mbl)
4971 (set (make-local-variable 'mml-buffer-list) mbl1))
4972 (gnus-make-local-hook 'kill-buffer-hook)
4973 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4974 `(lambda (no-highlight)
4975 (let ((mail-parse-charset (or gnus-article-charset
4976 ',gnus-newsgroup-charset))
4977 (message-options message-options)
4978 (message-options-set-recipient)
4979 (mail-parse-ignored-charsets
4980 (or gnus-article-ignored-charsets
4981 ',gnus-newsgroup-ignored-charsets)))
4983 (mml-destroy-buffers)
4984 (remove-hook 'kill-buffer-hook
4985 'mml-destroy-buffers t)
4986 (kill-local-variable 'mml-buffer-list))
4987 (gnus-summary-edit-article-done
4988 ,(or (mail-header-references gnus-current-headers) "")
4989 ,(gnus-group-read-only-p)
4990 ,gnus-summary-buffer no-highlight))
4992 ;; Force buttonizing this part.
4993 (let ((gnus-mime-buttonized-part-id current-id))
4994 (gnus-article-edit-done))
4995 (gnus-configure-windows 'article)
4996 (when (and current-id (integerp gnus-auto-select-part))
4997 (gnus-article-jump-to-part
4998 (min (max (+ current-id gnus-auto-select-part) 1)
4999 (with-current-buffer gnus-article-buffer
5000 (length gnus-article-mime-handle-alist)))))))
5002 (defun gnus-mime-replace-part (file)
5003 "Replace MIME part under point with an external body."
5004 ;; Useful if file has already been saved to disk
5007 (read-file-name "Replace MIME part with file: "
5008 (or mm-default-directory default-directory)
5010 (gnus-mime-save-part-and-strip file))
5012 (defun gnus-mime-save-part-and-strip (&optional file)
5013 "Save the MIME part under point then replace it with an external body.
5014 If FILE is given, use it for the external part."
5016 (gnus-article-check-buffer)
5017 (when (gnus-group-read-only-p)
5018 (error "The current group does not support deleting of parts"))
5019 (when (mm-complicated-handles gnus-article-mime-handles)
5021 The current article has a complicated MIME structure, giving up..."))
5022 (let* ((data (get-text-property (point) 'gnus-data))
5023 (id (get-text-property (point) 'gnus-part))
5025 (handles gnus-article-mime-handles))
5028 (and data (mm-save-part data "Delete MIME part and save to: "))))
5030 (with-current-buffer (mm-handle-buffer data)
5032 (insert "Content-Type: " (mm-handle-media-type data))
5033 (mml-insert-parameter-string (cdr (mm-handle-type data))
5035 ;; Add a filename for the sake of saving the part again.
5036 (mml-insert-parameter
5037 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5039 (insert "Content-ID: " (message-make-message-id) "\n")
5040 (insert "Content-Transfer-Encoding: binary\n")
5043 (cdr (mm-make-handle nil
5044 `("message/external-body"
5045 (access-type . "LOCAL-FILE")
5047 ;; (set-buffer gnus-summary-buffer)
5048 (gnus-article-edit-part handles id))))
5050 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5051 ;; parts...>') but with stripping would be nice.
5053 (defun gnus-mime-delete-part ()
5054 "Delete the MIME part under point.
5055 Replace it with some information about the removed part."
5057 (gnus-article-check-buffer)
5058 (when (gnus-group-read-only-p)
5059 (error "The current group does not support deleting of parts"))
5060 (when (mm-complicated-handles gnus-article-mime-handles)
5062 The current article has a complicated MIME structure, giving up..."))
5063 (when (or gnus-expert-user
5064 (gnus-yes-or-no-p "\
5065 Deleting parts may malfunction or destroy the article; continue? "))
5066 (let* ((data (get-text-property (point) 'gnus-data))
5067 (id (get-text-property (point) 'gnus-part))
5068 (handles gnus-article-mime-handles)
5070 (let ((desc (mm-handle-description data)))
5072 (mail-decode-encoded-word-string desc))))
5073 (filename (or (mm-handle-filename data) "(none)"))
5074 (type (mm-handle-media-type data)))
5076 (error "No MIME part under point"))
5077 (with-current-buffer (mm-handle-buffer data)
5078 (let ((bsize (buffer-size)))
5083 "| The following attachment has been deleted:\n"
5085 "| Type: " type "\n"
5086 "| Filename: " filename "\n"
5087 "| Size (encoded): " (format "%s byte%s\n"
5088 bsize (if (= bsize 1)
5092 (concat "| Description: " description "\n"))
5095 (cdr (mm-make-handle
5096 nil `("text/plain" (charset . gnus-decoded)) nil nil
5098 (format "Deleted attachment (%s bytes)" bsize))))))
5099 ;; (set-buffer gnus-summary-buffer)
5100 (gnus-article-edit-part handles id))))
5102 (defun gnus-mime-save-part ()
5103 "Save the MIME part under point."
5105 (gnus-article-check-buffer)
5106 (let ((data (get-text-property (point) 'gnus-data)))
5108 (mm-save-part data))))
5110 (defun gnus-mime-pipe-part (&optional cmd)
5111 "Pipe the MIME part under point to a process.
5112 Use CMD as the process."
5114 (gnus-article-check-buffer)
5115 (let ((data (get-text-property (point) 'gnus-data)))
5117 (mm-pipe-part data cmd))))
5119 (defun gnus-mime-view-part ()
5120 "Interactively choose a viewing method for the MIME part under point."
5122 (gnus-article-check-buffer)
5123 (let ((data (get-text-property (point) 'gnus-data)))
5125 (setq gnus-article-mime-handles
5127 gnus-article-mime-handles (setq data (copy-sequence data))))
5128 (mm-interactively-view-part data))))
5130 (defun gnus-mime-view-part-as-type-internal ()
5131 (gnus-article-check-buffer)
5132 (let* ((handle (get-text-property (point) 'gnus-data))
5134 ;; Content-Type: foo/bar; name=...
5135 (mail-content-type-get (mm-handle-type handle) 'name)
5136 ;; Content-Disposition: attachment; filename=...
5137 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5138 (def-type (and name (mm-default-file-encoding name))))
5139 (or (and def-type (cons def-type 0))
5141 (equal (mm-handle-media-supertype handle) "text")
5142 '("text/plain" . 0))
5143 '("application/octet-stream" . 0))))
5145 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5146 "Choose a MIME media type, and view the part as such.
5147 If non-nil, PRED is a predicate to use during completion to limit the
5148 available media-types."
5152 (let ((default (gnus-mime-view-part-as-type-internal)))
5153 (gnus-completing-read
5156 (gnus-remove-if-not pred (mailcap-mime-types))
5157 (mailcap-mime-types))
5160 (gnus-article-check-buffer)
5161 (let ((handle (get-text-property (point) 'gnus-data)))
5163 (when (equal (mm-handle-media-type handle) "message/external-body")
5164 (unless (mm-handle-cache handle)
5165 (mm-extern-cache-contents handle))
5166 (setq handle (mm-handle-cache handle)))
5168 (mm-make-handle (mm-handle-buffer handle)
5169 (cons mime-type (cdr (mm-handle-type handle)))
5170 (mm-handle-encoding handle)
5171 (mm-handle-undisplayer handle)
5172 (mm-handle-disposition handle)
5173 (mm-handle-description handle)
5175 (mm-handle-id handle)))
5176 (setq gnus-article-mime-handles
5177 (mm-merge-handles gnus-article-mime-handles handle))
5178 (when (mm-handle-displayed-p handle)
5179 (mm-remove-part handle))
5180 (gnus-mm-display-part handle))))
5182 (defun gnus-mime-copy-part (&optional handle arg)
5183 "Put the MIME part under point into a new buffer.
5184 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5186 (interactive (list nil current-prefix-arg))
5187 (gnus-article-check-buffer)
5189 (setq handle (get-text-property (point) 'gnus-data)))
5191 (let ((filename (mm-handle-filename handle))
5192 contents dont-decode charset coding-system)
5193 (mm-with-unibyte-buffer
5194 (mm-insert-part handle)
5195 (setq contents (or (condition-case nil
5196 (mm-decompress-buffer filename nil 'sig)
5198 (setq dont-decode t)
5201 (setq filename (cond (filename (file-name-nondirectory filename))
5202 (dont-decode "*raw data*")
5207 (unless (setq charset (mail-content-type-get
5208 (mm-handle-type handle) 'charset))
5209 (unless (setq coding-system (mm-with-unibyte-buffer
5211 (mm-find-buffer-file-coding-system)))
5212 (setq charset gnus-newsgroup-charset))))
5214 (setq charset (or (cdr (assq arg
5215 gnus-summary-show-article-charset-alist))
5216 (mm-read-coding-system "Charset: ")))))
5217 (switch-to-buffer (generate-new-buffer filename))
5218 (if (or coding-system
5220 (setq coding-system (mm-charset-to-coding-system charset))
5221 (not (eq coding-system 'ascii))))
5223 (mm-enable-multibyte)
5224 (insert (mm-decode-coding-string contents coding-system))
5225 (setq buffer-file-coding-system
5226 (if (boundp 'last-coding-system-used)
5227 (symbol-value 'last-coding-system-used)
5229 (mm-disable-multibyte)
5231 (setq buffer-file-coding-system mm-binary-coding-system))
5232 ;; We do it this way to make `normal-mode' set the appropriate mode.
5235 (setq buffer-file-name (expand-file-name filename))
5237 (setq buffer-file-name nil))
5238 (goto-char (point-min)))))
5240 (defun gnus-mime-print-part (&optional handle filename)
5241 "Print the MIME part under point."
5242 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5243 (gnus-article-check-buffer)
5244 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5245 (contents (and handle (mm-get-part handle)))
5246 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5247 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5252 (mm-save-part-to-file handle file)
5253 (call-process shell-file-name nil
5254 (generate-new-buffer " *mm*")
5256 shell-command-switch
5258 printer file (mm-handle-type handle))))
5262 (gnus-print-buffer))
5263 (ps-despool filename)))))
5265 (defun gnus-mime-inline-part (&optional handle arg)
5266 "Insert the MIME part under point into the current buffer.
5267 Compressed files like .gz and .bz2 are decompressed."
5268 (interactive (list nil current-prefix-arg))
5269 (gnus-article-check-buffer)
5271 (setq handle (get-text-property (point) 'gnus-data)))
5274 (inhibit-read-only t)
5275 contents charset coding-system)
5276 (if (and (not arg) (mm-handle-undisplayer handle))
5277 (mm-remove-part handle)
5278 (mm-with-unibyte-buffer
5279 (mm-insert-part handle)
5281 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5285 (unless (setq charset (mail-content-type-get
5286 (mm-handle-type handle) 'charset))
5287 (unless (setq coding-system
5288 (mm-with-unibyte-buffer
5290 (mm-find-buffer-file-coding-system)))
5291 (setq charset gnus-newsgroup-charset))))
5293 (if (mm-handle-undisplayer handle)
5294 (mm-remove-part handle))
5297 gnus-summary-show-article-charset-alist))
5298 (mm-read-coding-system "Charset: "))))
5300 (if (mm-handle-undisplayer handle)
5301 (mm-remove-part handle))))
5303 (mm-display-inline handle)
5306 (defun gnus-mime-set-charset-parameters (handle charset)
5307 "Set CHARSET to parameters in HANDLE.
5308 CHARSET may either be a string or a symbol."
5309 (unless (stringp charset)
5310 (setq charset (symbol-name charset)))
5311 (if (stringp (car handle))
5312 (dolist (h (cdr handle))
5313 (gnus-mime-set-charset-parameters h charset))
5314 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5315 "message/external-body")
5317 (unless (mm-handle-cache handle)
5318 (mm-extern-cache-contents handle))
5319 (mm-handle-cache handle))
5321 (param (assq 'charset (cdr type))))
5323 (setcdr param charset)
5324 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5326 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5327 "Insert the MIME part under point into the current buffer using the
5329 (interactive (list nil current-prefix-arg))
5330 (gnus-article-check-buffer)
5331 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5332 (fun (get-text-property (point) 'gnus-callback))
5333 (gnus-newsgroup-ignored-charsets 'gnus-all)
5334 charset form preferred parts)
5341 gnus-summary-show-article-charset-alist))
5342 (mm-read-coding-system "Charset: "))))
5343 (if (mm-handle-undisplayer handle)
5344 (mm-remove-part handle)))
5345 (gnus-mime-set-charset-parameters handle charset)
5346 (when (and (consp (setq form (cdr-safe fun)))
5347 (setq form (ignore-errors
5348 (assq 'gnus-mime-display-alternative form)))
5349 (setq preferred (caddr form))
5351 (when (eq (car preferred) 'quote)
5352 (setq preferred (cadr preferred)))
5353 (not (equal preferred
5354 (get-text-property (point) 'gnus-data))))
5355 (setq parts (get-text-property (point) 'gnus-part))
5356 (setq parts (cdr (assq parts
5357 gnus-article-mime-handle-alist)))
5358 (equal (mm-handle-media-type parts) "multipart/alternative")
5359 (setq parts (reverse (cdr parts))))
5361 (list 'quote (or (cadr (member preferred parts))
5363 (funcall fun handle)))))
5365 (defun gnus-mime-view-part-externally (&optional handle)
5366 "View the MIME part under point with an external viewer."
5368 (gnus-article-check-buffer)
5369 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5370 (mm-user-display-methods nil)
5371 (mm-inlined-types nil)
5372 (mail-parse-charset gnus-newsgroup-charset)
5373 (mail-parse-ignored-charsets
5374 (with-current-buffer gnus-summary-buffer
5375 gnus-newsgroup-ignored-charsets))
5376 (type (mm-handle-media-type handle))
5377 (method (mailcap-mime-info type))
5378 (mm-enable-external t))
5379 (if (not (stringp method))
5380 (gnus-mime-view-part-as-type
5381 nil (lambda (type) (stringp (mailcap-mime-info type))))
5383 (mm-display-part handle nil t)))))
5385 (defun gnus-mime-view-part-internally (&optional handle)
5386 "View the MIME part under point with an internal viewer.
5387 If no internal viewer is available, use an external viewer."
5389 (gnus-article-check-buffer)
5390 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5391 (mm-inlined-types '(".*"))
5392 (mm-inline-large-images t)
5393 (mail-parse-charset gnus-newsgroup-charset)
5394 (mail-parse-ignored-charsets
5395 (with-current-buffer gnus-summary-buffer
5396 gnus-newsgroup-ignored-charsets))
5397 (inhibit-read-only t))
5398 (if (not (mm-inlinable-p handle))
5399 (gnus-mime-view-part-as-type
5400 nil (lambda (type) (mm-inlinable-p handle type)))
5402 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5404 (defun gnus-mime-action-on-part (&optional action)
5405 "Do something with the MIME attachment at \(point\)."
5407 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5408 (gnus-article-check-buffer)
5409 (let ((action-pair (assoc action gnus-mime-action-alist)))
5411 (funcall (cdr action-pair)))))
5413 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5414 "Call FUNCTION on MIME part N.
5415 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5416 If INTERACTIVE, call FUNCTION interactivly."
5418 ;; Check whether the article is displayed.
5419 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5420 (setq window (get-buffer-window gnus-article-buffer t))
5421 (frame-visible-p (setq frame (window-frame window))))
5422 (error "No article is displayed"))
5423 (with-current-buffer gnus-article-buffer
5424 ;; Check whether the article displays the right contents.
5425 (unless (with-current-buffer gnus-summary-buffer
5426 (eq gnus-current-article (gnus-summary-article-number)))
5427 (error "You should select the right article first"))
5429 (setq n (prefix-numeric-value n))
5431 (setq n (or (get-text-property pt 'gnus-part)
5433 (get-text-property (1- pt) 'gnus-part))
5434 (get-text-property (prog2
5440 (or (and (setq pt (previous-single-property-change
5443 (next-single-property-change (point) 'gnus-part)
5447 ;; Check whether the specified part exists.
5448 (when (> n (length gnus-article-mime-handle-alist))
5449 (error "No such part")))
5452 ;; To select the window is needed so that the cursor
5453 ;; might be visible on the MIME button.
5454 (select-window (prog1
5456 (setq window (selected-window))
5457 ;; Article may be displayed in the other frame.
5458 (gnus-select-frame-set-input-focus
5461 (setq frame (selected-frame))))))
5462 (when (gnus-article-goto-part n)
5463 ;; We point the cursor and the arrow at the MIME button
5464 ;; when the `function' prompt the user for something.
5465 (unless (and (pos-visible-in-window-p)
5466 (> (count-lines (point) (window-end))
5467 (/ (1- (window-height)) 3)))
5468 (recenter (/ (1- (window-height)) 3)))
5469 (let ((cursor-in-non-selected-windows t)
5470 (overlay-arrow-string "=>")
5471 (overlay-arrow-position (point-marker)))
5474 ((and no-handle interactive)
5475 (call-interactively function))
5480 function (get-text-property (point) 'gnus-data)))
5483 (get-text-property (point) 'gnus-data))))
5484 (set-marker overlay-arrow-position nil)
5485 (unless gnus-auto-select-part
5486 (gnus-select-frame-set-input-focus frame)
5487 (select-window window))))
5489 (if gnus-inhibit-mime-unbuttonizing
5490 ;; This is the default though the program shouldn't reach here.
5491 (error "No such part")
5492 ;; The part which doesn't have the MIME button is selected.
5493 ;; So, we display all the buttons and redo it.
5494 (let ((gnus-inhibit-mime-unbuttonizing t))
5495 (gnus-summary-show-article)
5496 (gnus-article-part-wrapper n function no-handle))))))
5498 (defun gnus-article-pipe-part (n)
5499 "Pipe MIME part N, which is the numerical prefix."
5501 (gnus-article-part-wrapper n 'mm-pipe-part))
5503 (defun gnus-article-save-part (n)
5504 "Save MIME part N, which is the numerical prefix."
5506 (gnus-article-part-wrapper n 'mm-save-part))
5508 (defun gnus-article-interactively-view-part (n)
5509 "View MIME part N interactively, which is the numerical prefix."
5511 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5513 (defun gnus-article-copy-part (n)
5514 "Copy MIME part N, which is the numerical prefix."
5516 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5518 (defun gnus-article-view-part-as-charset (n)
5519 "View MIME part N using a specified charset.
5520 N is the numerical prefix."
5522 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5524 (defun gnus-article-view-part-externally (n)
5525 "View MIME part N externally, which is the numerical prefix."
5527 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5529 (defun gnus-article-inline-part (n)
5530 "Inline MIME part N, which is the numerical prefix."
5532 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5534 (defun gnus-article-save-part-and-strip (n)
5535 "Save MIME part N and replace it with an external body.
5536 N is the numerical prefix."
5538 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5540 (defun gnus-article-replace-part (n)
5541 "Replace MIME part N with an external body.
5542 N is the numerical prefix."
5544 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5546 (defun gnus-article-delete-part (n)
5547 "Delete MIME part N and add some information about the removed part.
5548 N is the numerical prefix."
5550 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5552 (defun gnus-article-view-part-as-type (n)
5553 "Choose a MIME media type, and view part N as such.
5554 N is the numerical prefix."
5556 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5558 (defun gnus-article-mime-match-handle-first (condition)
5561 (dolist (ihandle gnus-article-mime-handle-alist)
5563 ((functionp condition)
5564 (funcall condition (cdr ihandle)))
5565 ((eq condition 'undisplayed)
5566 (not (or (mm-handle-undisplayer (cdr ihandle))
5567 (equal (mm-handle-media-type (cdr ihandle))
5568 "multipart/alternative"))))
5569 ((eq condition 'undisplayed-alternative)
5570 (not (mm-handle-undisplayer (cdr ihandle))))
5572 (gnus-article-goto-part (car ihandle))
5573 (or (not n) (< (car ihandle) n)))
5574 (setq n (car ihandle))))
5578 (defun gnus-article-view-part (&optional n)
5579 "View MIME part N, which is the numerical prefix.
5580 If the part is already shown, hide the part. If N is nil, view
5583 (with-current-buffer gnus-article-buffer
5584 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5585 gnus-article-mime-match-handle-function)))
5586 (when (> n (length gnus-article-mime-handle-alist))
5587 (error "No such part"))
5588 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5589 (when (gnus-article-goto-part n)
5590 (if (equal (car handle) "multipart/alternative")
5591 (gnus-article-press-button)
5592 (when (eq (gnus-mm-display-part handle) 'internal)
5593 (gnus-set-window-start)))))))
5595 (defsubst gnus-article-mime-total-parts ()
5596 (if (bufferp (car gnus-article-mime-handles))
5598 (1- (length gnus-article-mime-handles))))
5600 (defun gnus-mm-display-part (handle)
5601 "Display HANDLE and fix MIME button."
5602 (let ((id (get-text-property (point) 'gnus-part))
5604 (inhibit-read-only t))
5607 (let ((window (selected-window))
5608 (mail-parse-charset gnus-newsgroup-charset)
5609 (mail-parse-ignored-charsets
5610 (if (gnus-buffer-live-p gnus-summary-buffer)
5611 (with-current-buffer gnus-summary-buffer
5612 gnus-newsgroup-ignored-charsets)
5616 (let ((win (gnus-get-buffer-window (current-buffer) t))
5619 (select-window win))
5622 (if (mm-handle-displayed-p handle)
5623 ;; This will remove the part.
5624 (mm-display-part handle)
5626 (narrow-to-region (point)
5627 (if (eobp) (point) (1+ (point))))
5628 (gnus-bind-safe-url-regexp (mm-display-part handle))
5629 ;; We narrow to the part itself and
5630 ;; then call the treatment functions.
5631 (goto-char (point-min))
5633 (narrow-to-region (point) (point-max))
5636 (gnus-article-mime-total-parts)
5637 (mm-handle-media-type handle)))))
5638 (if (window-live-p window)
5639 (select-window window)))))
5642 (gnus-insert-mime-button
5643 handle id (list (mm-handle-displayed-p handle)))
5644 (goto-char point))))
5646 (defun gnus-article-goto-part (n)
5647 "Go to MIME part N."
5648 (when gnus-break-pages
5651 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5652 part handle end next handles)
5655 (if (setq handle (get-text-property start 'gnus-data))
5657 ;; Go to the displayed subpart, assuming this is
5658 ;; multipart/alternative.
5661 (while (and (not handle)
5664 (setq next (text-property-not-all part end
5667 handle (get-text-property part 'gnus-data))
5668 (push (cons handle part) handles)
5669 (unless (mm-handle-displayed-p handle)
5671 part (text-property-any part end 'gnus-data nil))))
5673 ;; No subpart is displayed, so we find preferred one.
5675 (cdr (assq (mm-preferred-alternative
5676 (nreverse (mapcar 'car handles)))
5679 (goto-char (1+ part))
5681 (when gnus-break-pages
5682 (gnus-narrow-to-page))))
5684 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5685 (let ((gnus-tmp-name
5686 (or (mm-handle-filename handle)
5687 (mail-content-type-get (mm-handle-type handle) 'url)
5689 (gnus-tmp-type (mm-handle-media-type handle))
5690 (gnus-tmp-description (or (mm-handle-description handle) ""))
5692 (if (if displayed (car displayed)
5693 (mm-handle-displayed-p handle))
5695 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5697 gnus-tmp-type-long b e)
5698 (when (string-match ".*/" gnus-tmp-name)
5699 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5700 (setq gnus-tmp-type-long (concat gnus-tmp-type
5701 (and (not (equal gnus-tmp-name ""))
5702 (concat "; " gnus-tmp-name))))
5703 (unless (equal gnus-tmp-description "")
5704 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5709 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5710 `(keymap ,gnus-mime-button-map
5711 gnus-callback gnus-mm-display-part
5712 gnus-part ,gnus-tmp-id
5713 article-type annotation
5717 ;; Exclude a newline.
5720 (when gnus-article-button-face
5721 (gnus-overlay-put (gnus-make-overlay b e nil t)
5722 'face gnus-article-button-face))
5723 (widget-convert-button
5726 :action 'gnus-widget-press-button
5727 :button-keymap gnus-mime-button-map
5730 ;; Needed to properly clear the message due to a bug in
5731 ;; wid-edit (XEmacs only).
5732 (if (boundp 'help-echo-owns-message)
5733 (setq help-echo-owns-message t))
5735 "%S: %s the MIME part; %S: more options"
5736 (aref gnus-mouse-2 0)
5737 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5739 (aref gnus-down-mouse-3 0))))))
5741 (defun gnus-widget-press-button (elems el)
5742 (goto-char (widget-get elems :from))
5743 (gnus-article-press-button))
5745 (defvar gnus-displaying-mime nil)
5747 (defun gnus-display-mime (&optional ihandles)
5748 "Display the MIME parts."
5750 (save-selected-window
5751 (let ((window (get-buffer-window gnus-article-buffer))
5754 (select-window window)
5755 ;; We have to do this since selecting the window
5756 ;; may change the point. So we set the window point.
5757 (set-window-point window point)))
5758 (let ((handles ihandles)
5759 (inhibit-read-only t)
5762 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5763 (when gnus-article-emulate-mime
5764 (mm-uu-dissect-text-parts handles)))
5765 (gnus-article-emulate-mime
5766 (setq handles (mm-uu-dissect))))
5767 (when (and (not ihandles)
5768 (not gnus-displaying-mime))
5769 ;; Top-level call; we clean up.
5770 (when gnus-article-mime-handles
5771 (mm-destroy-parts gnus-article-mime-handles)
5772 (setq gnus-article-mime-handle-alist nil));; A trick.
5773 (setq gnus-article-mime-handles handles)
5774 ;; We allow users to glean info from the handles.
5775 (when gnus-article-mime-part-function
5776 (gnus-mime-part-function handles)))
5778 (or (not (stringp (car handles)))
5781 (when (and (not ihandles)
5782 (not gnus-displaying-mime))
5783 ;; Clean up for mime parts.
5785 (delete-region (point) (point-max)))
5786 (let ((gnus-displaying-mime t))
5787 (gnus-mime-display-part handles)))
5790 (narrow-to-region (point) (point-max))
5791 (gnus-treat-article nil 1 1 "text/plain")
5794 ;; Highlight the headers.
5798 (narrow-to-region (point-min) (point))
5799 (gnus-article-save-original-date
5800 (gnus-treat-article 'head)))))))
5801 ;; Cope with broken MIME messages.
5802 (goto-char (point-max))
5806 (defcustom gnus-mime-display-multipart-as-mixed nil
5807 "Display \"multipart\" parts as \"multipart/mixed\".
5809 If t, it overrides nil values of
5810 `gnus-mime-display-multipart-alternative-as-mixed' and
5811 `gnus-mime-display-multipart-related-as-mixed'."
5812 :group 'gnus-article-mime
5815 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5816 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5818 :group 'gnus-article-mime
5821 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5822 "Display \"multipart/related\" parts as \"multipart/mixed\".
5824 If displaying \"text/html\" is discouraged \(see
5825 `mm-discouraged-alternatives'\) images or other material inside a
5826 \"multipart/related\" part might be overlooked when this variable is nil."
5828 :group 'gnus-article-mime
5831 (defun gnus-mime-display-part (handle)
5833 ;; Maybe a broken MIME message.
5836 ((not (stringp (car handle)))
5837 (gnus-mime-display-single handle))
5838 ;; User-defined multipart
5839 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5840 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5842 ;; multipart/alternative
5843 ((and (equal (car handle) "multipart/alternative")
5844 (not (or gnus-mime-display-multipart-as-mixed
5845 gnus-mime-display-multipart-alternative-as-mixed)))
5846 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5847 (push (cons id handle) gnus-article-mime-handle-alist)
5848 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5849 ;; multipart/related
5850 ((and (equal (car handle) "multipart/related")
5851 (not (or gnus-mime-display-multipart-as-mixed
5852 gnus-mime-display-multipart-related-as-mixed)))
5853 ;;;!!!We should find the start part, but we just default
5854 ;;;!!!to the first part.
5855 ;;(gnus-mime-display-part (cadr handle))
5856 ;;;!!! Most multipart/related is an HTML message plus images.
5857 ;;;!!! Unfortunately we are unable to let W3 display those
5858 ;;;!!! included images, so we just display it as a mixed multipart.
5859 ;;(gnus-mime-display-mixed (cdr handle))
5860 ;;;!!! No, w3 can display everything just fine.
5861 (gnus-mime-display-part (cadr handle)))
5862 ((equal (car handle) "multipart/signed")
5863 (gnus-add-wash-type 'signed)
5864 (gnus-mime-display-security handle))
5865 ((equal (car handle) "multipart/encrypted")
5866 (gnus-add-wash-type 'encrypted)
5867 (gnus-mime-display-security handle))
5868 ;; Other multiparts are handled like multipart/mixed.
5870 (gnus-mime-display-mixed (cdr handle)))))
5872 (defun gnus-mime-part-function (handles)
5873 (if (stringp (car handles))
5874 (mapcar 'gnus-mime-part-function (cdr handles))
5875 (funcall gnus-article-mime-part-function handles)))
5877 (defun gnus-mime-display-mixed (handles)
5878 (mapcar 'gnus-mime-display-part handles))
5880 (defun gnus-mime-display-single (handle)
5881 (let ((type (mm-handle-media-type handle))
5882 (ignored gnus-ignored-mime-types)
5889 (when (string-match (pop ignored) type)
5890 (throw 'ignored nil)))
5891 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5892 (with-current-buffer gnus-summary-buffer
5893 gnus-inhibit-images)
5894 gnus-inhibit-images)
5895 (string-match "\\`image/" type)))
5896 (setq not-attachment
5897 (and (not (mm-inline-override-p handle))
5898 (or (not (mm-handle-disposition handle))
5899 (equal (car (mm-handle-disposition handle))
5901 (mm-attachment-override-p handle))))
5902 (mm-automatic-display-p handle)
5904 (mm-inlinable-p handle)
5905 (mm-inlined-p handle))
5906 (mm-automatic-external-display-p type)))
5908 (when (equal (mm-handle-media-supertype handle) "text")
5910 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5912 (push (cons id handle) gnus-article-mime-handle-alist)
5914 (equal (mm-handle-media-supertype handle) "message"))
5917 (cond ((not (bolp)) 2)
5918 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5920 (when (or (not display)
5921 (not (gnus-unbuttonized-mime-type-p type))
5922 (eq id gnus-mime-buttonized-part-id))
5923 (gnus-insert-mime-button
5924 handle id (list (or display (and not-attachment text))))
5925 (gnus-article-insert-newline)
5926 ;; Remember modify the number of forward lines.
5934 (let ((mail-parse-charset gnus-newsgroup-charset)
5935 (mail-parse-ignored-charsets
5936 (save-excursion (condition-case ()
5937 (set-buffer gnus-summary-buffer)
5939 gnus-newsgroup-ignored-charsets)))
5940 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5941 (goto-char (point-max)))
5942 ((and text not-attachment)
5946 (gnus-article-insert-newline)
5947 (mm-display-inline handle)
5948 (goto-char (point-max))))
5952 (narrow-to-region beg (point))
5953 (if (eq handle gnus-article-mime-handles)
5954 ;; The format=flowed case.
5955 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5956 ;; Don't count signature parts that are never displayed.
5957 ;; The part number should be re-calculated supposing this
5958 ;; might be a message/rfc822 part.
5960 (dolist (part gnus-article-mime-handles)
5961 (unless (or (stringp part)
5962 (equal (car (mm-handle-type part))
5963 "application/pgp-signature"))
5964 (push part handles)))
5966 nil (length (memq handle handles)) (length handles)
5967 (mm-handle-media-type handle)))))))))))
5969 (defun gnus-unbuttonized-mime-type-p (type)
5970 "Say whether TYPE is to be unbuttonized."
5971 (unless gnus-inhibit-mime-unbuttonizing
5973 (let ((types gnus-unbuttonized-mime-types))
5975 (when (string-match (pop types) type)
5976 (throw 'found t)))))
5978 (let ((types gnus-buttonized-mime-types))
5980 (when (string-match (pop types) type)
5981 (throw 'found t)))))))))
5983 (defun gnus-article-insert-newline ()
5984 "Insert a newline, but mark it as undeletable."
5985 (gnus-put-text-property
5986 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5988 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5989 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5992 handle (inhibit-read-only t) from props begend not-pref)
5993 (save-window-excursion
5996 (narrow-to-region (car ibegend)
5999 (goto-char (car ibegend))
6002 (delete-region (point-min) (point-max))
6003 (mm-remove-parts handles))
6004 (setq begend (list (point-marker)))
6006 (unless (setq not-pref (cadr (member preferred ihandles)))
6007 (setq not-pref (car ihandles)))
6010 (not (gnus-unbuttonized-mime-type-p
6011 "multipart/alternative")))
6012 (gnus-add-text-properties
6015 (insert (format "%d. " id))
6019 (unless ,(not ibegend)
6020 (setq gnus-article-mime-handle-alist
6021 ',gnus-article-mime-handle-alist))
6022 (gnus-mime-display-alternative
6023 ',ihandles ',not-pref ',begend ,id))
6024 keymap ,gnus-mime-button-map
6025 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6026 face ,gnus-article-button-face
6028 article-type multipart
6030 (widget-convert-button 'link from (point)
6031 :action 'gnus-widget-press-button
6032 :button-keymap gnus-widget-button-keymap)
6034 (while (setq handle (pop handles))
6035 (gnus-add-text-properties
6038 (insert (format "(%c) %-18s"
6039 (if (equal handle preferred) ?* ? )
6040 (mm-handle-media-type handle)))
6044 (unless ,(not ibegend)
6045 (setq gnus-article-mime-handle-alist
6046 ',gnus-article-mime-handle-alist))
6047 (gnus-mime-display-alternative
6048 ',ihandles ',handle ',begend ,id))
6049 keymap ,gnus-mime-button-map
6050 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6051 face ,gnus-article-button-face
6055 (widget-convert-button 'link from (point)
6056 :action 'gnus-widget-press-button
6057 :button-keymap gnus-widget-button-keymap)
6061 (if (stringp (car preferred))
6062 (gnus-display-mime preferred)
6063 (let ((mail-parse-charset gnus-newsgroup-charset)
6064 (mail-parse-ignored-charsets
6065 (with-current-buffer gnus-summary-buffer
6066 gnus-newsgroup-ignored-charsets)))
6067 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6071 (narrow-to-region (car begend) (point-max))
6073 nil (length gnus-article-mime-handle-alist)
6074 (gnus-article-mime-total-parts)
6075 (mm-handle-media-type preferred))))))
6076 (goto-char (point-max))
6077 (setcdr begend (point-marker)))))
6079 (goto-char point))))
6081 (defconst gnus-article-wash-status-strings
6082 (let ((alist '((cite "c" "Possible hidden citation text"
6083 " " "All citation text visible")
6084 (headers "h" "Hidden headers"
6085 " " "All headers visible.")
6086 (pgp "p" "Encrypted or signed message status hidden"
6087 " " "No hidden encryption nor digital signature status")
6088 (signature "s" "Signature has been hidden"
6089 " " "Signature is visible")
6090 (overstrike "o" "Overstrike (^H) characters applied"
6091 " " "No overstrike characters applied")
6092 (emphasis "e" "/*_Emphasis_*/ characters applied"
6093 " " "No /*_emphasis_*/ characters applied")))
6095 (dolist (entry alist result)
6096 (let ((key (nth 0 entry))
6097 (on (copy-sequence (nth 1 entry)))
6098 (on-help (nth 2 entry))
6099 (off (copy-sequence (nth 3 entry)))
6100 (off-help (nth 4 entry)))
6101 (put-text-property 0 1 'help-echo on-help on)
6102 (put-text-property 0 1 'help-echo off-help off)
6103 (push (list key on off) result))))
6104 "Alist of strings describing wash status in the mode line.
6105 Each entry has the form (KEY ON OF), where the KEY is a symbol
6106 representing the particular washing function, ON is the string to use
6107 in the article mode line when the washing function is active, and OFF
6108 is the string to use when it is inactive.")
6110 (defun gnus-article-wash-status-entry (key value)
6111 (let ((entry (assoc key gnus-article-wash-status-strings)))
6112 (if value (nth 1 entry) (nth 2 entry))))
6114 (defun gnus-article-wash-status ()
6115 "Return a string which display status of article washing."
6116 (with-current-buffer gnus-article-buffer
6117 (let ((cite (memq 'cite gnus-article-wash-types))
6118 (headers (memq 'headers gnus-article-wash-types))
6119 (boring (memq 'boring-headers gnus-article-wash-types))
6120 (pgp (memq 'pgp gnus-article-wash-types))
6121 (pem (memq 'pem gnus-article-wash-types))
6122 (signed (memq 'signed gnus-article-wash-types))
6123 (encrypted (memq 'encrypted gnus-article-wash-types))
6124 (signature (memq 'signature gnus-article-wash-types))
6125 (overstrike (memq 'overstrike gnus-article-wash-types))
6126 (emphasis (memq 'emphasis gnus-article-wash-types)))
6128 (gnus-article-wash-status-entry 'cite cite)
6129 (gnus-article-wash-status-entry 'headers (or headers boring))
6130 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6131 (gnus-article-wash-status-entry 'signature signature)
6132 (gnus-article-wash-status-entry 'overstrike overstrike)
6133 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6135 (defun gnus-add-wash-type (type)
6136 "Add a washing of TYPE to the current status."
6137 (add-to-list 'gnus-article-wash-types type))
6139 (defun gnus-delete-wash-type (type)
6140 "Add a washing of TYPE to the current status."
6141 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6143 (defun gnus-add-image (category image)
6144 "Add IMAGE of CATEGORY to the list of displayed images."
6145 (let ((entry (assq category gnus-article-image-alist)))
6147 (setq entry (list category))
6148 (push entry gnus-article-image-alist))
6149 (nconc entry (list image))))
6151 (defun gnus-delete-images (category)
6152 "Delete all images in CATEGORY."
6153 (let ((entry (assq category gnus-article-image-alist)))
6154 (dolist (image (cdr entry))
6155 (gnus-remove-image image category))
6156 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6157 (gnus-delete-wash-type category)))
6159 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6161 (defun gnus-article-maybe-hide-headers ()
6162 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6163 Provided for backwards compatibility."
6164 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6165 (not (with-current-buffer gnus-summary-buffer
6166 gnus-have-all-headers)))
6167 (not gnus-inhibit-hiding))
6168 (gnus-article-hide-headers)))
6170 (declare-function shr-put-image "shr" (data alt))
6172 (defun gnus-shr-put-image (data alt)
6173 "Put image DATA with a string ALT. Enable image to be deleted."
6174 (let ((image (shr-put-image data (propertize (or alt "*")
6175 'gnus-image-category 'shr))))
6177 (gnus-add-image 'shr image))))
6181 (defun gnus-output-to-file (file-name)
6182 "Append the current article to a file named FILE-NAME.
6183 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6184 text and used as the value of the coding cookie which is added to the
6185 top of a file. Otherwise, this function saves a raw article without
6187 (let* ((artbuf (current-buffer))
6188 (file-name-coding-system nnmail-pathname-coding-system)
6189 (coding gnus-article-save-coding-system)
6190 (coding-system-for-read (if coding
6191 nil ;; Rely on the coding cookie.
6192 mm-text-coding-system))
6193 (coding-system-for-write (or coding
6194 mm-text-coding-system-for-write
6195 mm-text-coding-system))
6196 (exists (file-exists-p file-name)))
6199 (insert-file-contents file-name)
6200 (goto-char (point-min))
6201 ;; Remove the existing coding cookie.
6202 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6203 (delete-region (match-beginning 0) (match-end 0))))
6204 (goto-char (point-max))
6205 (insert-buffer-substring artbuf)
6206 ;; Append newline at end of the buffer as separator, and then
6208 (goto-char (point-max))
6211 ;; If the coding system is not suitable to encode the text,
6212 ;; ask a user for a proper one.
6213 (when (fboundp 'select-safe-coding-system)
6214 (setq coding (coding-system-base
6215 (save-window-excursion
6216 (select-safe-coding-system (point-min) (point-max)
6218 (setq coding-system-for-write
6219 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6221 (goto-char (point-min))
6222 ;; Add the coding cookie.
6223 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6224 coding-system-for-write)))
6227 (write-region (point-min) (point-max) file-name nil 'no-message)
6228 (message "Appended to %s" file-name))
6229 (write-region (point-min) (point-max) file-name))))
6232 (defun gnus-narrow-to-page (&optional arg)
6233 "Narrow the article buffer to a page.
6234 If given a numerical ARG, move forward ARG pages."
6236 (setq arg (if arg (prefix-numeric-value arg) 0))
6237 (with-current-buffer gnus-article-buffer
6239 ;; Remove any old next/prev buttons.
6240 (when (gnus-visual-p 'page-marker)
6241 (let ((inhibit-read-only t))
6242 (gnus-remove-text-with-property 'gnus-prev)
6243 (gnus-remove-text-with-property 'gnus-next)))
6245 (when (save-excursion
6247 (if (re-search-backward page-delimiter nil 'move (abs arg))
6249 (setq nd (match-beginning 0)
6251 (when (re-search-backward page-delimiter nil t)
6252 (setq st (match-end 0))))
6253 (when (re-search-forward page-delimiter nil t)
6254 (setq nd (match-beginning 0)
6257 (if (re-search-forward page-delimiter nil 'move arg)
6259 (setq st (match-end 0)
6261 (when (re-search-forward page-delimiter nil t)
6262 (setq nd (match-beginning 0))))
6263 (when (re-search-backward page-delimiter nil t)
6264 (setq st (match-end 0)
6267 (when (re-search-backward page-delimiter nil t)
6268 (goto-char (setq st (match-end 0))))
6269 (when (re-search-forward page-delimiter nil t)
6270 (setq nd (match-beginning 0)))
6272 (setq gnus-page-broken t)
6273 (when pt (goto-char pt))
6274 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6275 (when (gnus-visual-p 'page-marker)
6279 (gnus-insert-next-page-button))
6282 (gnus-insert-prev-page-button))))))))
6284 ;; Article mode commands
6286 (defun gnus-article-goto-next-page ()
6287 "Show the next page of the article."
6289 (when (gnus-article-next-page)
6290 (goto-char (point-min))
6291 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6294 (defun gnus-article-goto-prev-page ()
6295 "Show the previous page of the article."
6297 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6298 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6299 (gnus-article-prev-page nil)))
6301 ;; This is cleaner but currently breaks `gnus-pick-mode':
6303 ;; (defun gnus-article-goto-next-page ()
6304 ;; "Show the next page of the article."
6306 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6307 ;; (gnus-summary-next-page)))
6309 ;; (defun gnus-article-goto-prev-page ()
6310 ;; "Show the next page of the article."
6312 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6313 ;; (gnus-summary-prev-page)))
6315 (defun gnus-article-next-page (&optional lines)
6316 "Show the next page of the current article.
6317 If end of article, return non-nil. Otherwise return nil.
6318 Argument LINES specifies lines to be scrolled up."
6320 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6321 (if (and (not (and gnus-article-over-scroll
6322 (> (count-lines (window-start) (point-max))
6323 (if (featurep 'xemacs)
6324 (or lines (1- (window-height)))
6325 (+ (or lines (1- (window-height))) scroll-margin)))))
6328 (and (pos-visible-in-window-p) ;Not continuation line.
6329 (>= (point) (point-max)))))
6330 ;; Nothing in this page.
6331 (if (or (not gnus-page-broken)
6336 (eobp)))) ;Real end-of-buffer?
6338 (when gnus-article-over-scroll
6339 (gnus-article-next-page-1 lines))
6341 (gnus-narrow-to-page 1) ;Go to next page.
6343 ;; More in this page.
6344 (gnus-article-next-page-1 lines)
6347 (defun gnus-article-beginning-of-window ()
6348 "Move point to the beginning of the window.
6349 In Emacs, the point is placed at the line number which `scroll-margin'
6351 (if (featurep 'xemacs)
6352 (move-to-window-line 0)
6353 ;; There is an obscure bug in Emacs that makes it impossible to
6354 ;; scroll past big pictures in the article buffer. Try to fix
6355 ;; this by adding a sanity check by counting the lines visible.
6356 (when (> (count-lines (window-start) (window-end)) 30)
6357 (move-to-window-line
6358 (min (max 0 scroll-margin)
6359 (max 1 (- (window-height)
6360 (if mode-line-format 1 0)
6361 (if header-line-format 1 0)
6364 (defun gnus-article-next-page-1 (lines)
6366 (let ((scroll-in-place nil)
6367 (auto-window-vscroll nil))
6370 ;; Long lines may cause an end-of-buffer error.
6371 (goto-char (point-max))))
6372 (gnus-article-beginning-of-window))
6374 (defun gnus-article-prev-page (&optional lines)
6375 "Show previous page of current article.
6376 Argument LINES specifies lines to be scrolled down."
6378 (move-to-window-line 0)
6379 (if (and gnus-page-broken
6381 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6383 (gnus-narrow-to-page -1) ;Go to previous page.
6384 (goto-char (point-max))
6385 (recenter (if gnus-article-over-scroll
6387 (max (if (featurep 'xemacs)
6389 (+ lines scroll-margin))
6391 (- (window-height) 2))
6395 (let ((scroll-in-place nil))
6396 (scroll-down lines))
6397 (beginning-of-buffer
6398 (goto-char (point-min))))
6399 (gnus-article-beginning-of-window))))
6401 (defun gnus-article-only-boring-p ()
6402 "Decide whether there is only boring text remaining in the article.
6403 Something \"interesting\" is a word of at least two letters that does
6404 not have a face in `gnus-article-boring-faces'."
6405 (when (and gnus-article-skip-boring
6406 (boundp 'gnus-article-boring-faces)
6407 (symbol-value 'gnus-article-boring-faces))
6409 (let ((inhibit-point-motion-hooks t))
6411 (while (re-search-forward "\\b\\w\\w" nil t)
6413 (when (not (gnus-intersection
6414 (gnus-faces-at (point))
6415 (symbol-value 'gnus-article-boring-faces)))
6416 (throw 'only-boring nil)))
6417 (throw 'only-boring t))))))
6419 (defun gnus-article-refer-article ()
6420 "Read article specified by message-id around point."
6423 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6424 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6425 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6426 (let ((msg-id (concat "<" (match-string 0) ">")))
6427 (set-buffer gnus-summary-buffer)
6428 (gnus-summary-refer-article msg-id))
6429 (error "No references around point"))))
6431 (defun gnus-article-show-summary ()
6432 "Reconfigure windows to show summary buffer."
6434 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6435 (error "There is no summary buffer for this article buffer")
6436 (gnus-article-set-globals)
6437 (gnus-configure-windows 'article)
6438 (gnus-summary-goto-subject gnus-current-article)
6439 (gnus-summary-position-point)))
6441 (defun gnus-article-describe-briefly ()
6442 "Describe article mode commands briefly."
6444 (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")))
6446 (defun gnus-article-check-buffer ()
6447 "Beep if not in an article buffer."
6448 (unless (equal major-mode 'gnus-article-mode)
6449 (error "Command invoked outside of a Gnus article buffer")))
6451 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6452 "Read a summary buffer key sequence and execute it from the article buffer."
6454 (gnus-article-check-buffer)
6456 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6457 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6458 "=" "^" "\M-^" "|"))
6460 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6461 "An" "Ap" [?A (meta return)] [?A delete]))
6465 '("n" "Gn" "p" "Gp"))
6467 (with-current-buffer gnus-article-current-summary
6468 (let (gnus-pick-mode)
6469 (setq unread-command-events (nconc unread-command-events
6470 (list (or key last-command-event)))
6471 keys (if (featurep 'xemacs)
6472 (events-to-keys (read-key-sequence nil t))
6473 (read-key-sequence nil t)))))
6478 ((eq (aref keys (1- (length keys))) ?\C-h)
6479 (gnus-article-describe-bindings (substring keys 0 -1)))
6480 ((or (member keys nosaves)
6481 (member keys nosave-but-article)
6482 (member keys nosave-in-article))
6484 (save-window-excursion
6485 (pop-to-buffer gnus-article-current-summary)
6486 ;; We disable the pick minor mode commands.
6487 (let (gnus-pick-mode)
6488 (setq func (key-binding keys t))))
6492 (unless (member keys nosave-in-article)
6493 (set-buffer gnus-article-current-summary))
6494 (when (get func 'disabled)
6495 (error "Function %s disabled" func))
6496 (call-interactively func)
6497 (setq new-sum-point (point)))
6498 (when (member keys nosave-but-article)
6499 (pop-to-buffer gnus-article-buffer))))
6501 ;; These commands should restore window configuration.
6502 (let ((obuf (current-buffer))
6503 (owin (current-window-configuration))
6504 win func in-buffer selected new-sum-start new-sum-hscroll err)
6505 (cond (not-restore-window
6506 (pop-to-buffer gnus-article-current-summary)
6507 (setq win (selected-window)))
6508 ((setq win (get-buffer-window gnus-article-current-summary))
6509 (select-window win))
6511 (let ((summary-buffer gnus-article-current-summary))
6512 (gnus-configure-windows 'article)
6513 (unless (setq win (get-buffer-window summary-buffer 'visible))
6514 (let ((gnus-buffer-configuration
6515 '((article ((vertical 1.0
6516 (summary 0.25 point)
6518 (gnus-configure-windows 'article))
6519 (setq win (get-buffer-window summary-buffer 'visible)))
6520 (gnus-select-frame-set-input-focus (window-frame win))
6521 (select-window win))))
6522 (setq in-buffer (current-buffer))
6523 ;; We disable the pick minor mode commands.
6524 (setq func (let (gnus-pick-mode)
6525 (key-binding keys t)))
6526 (when (get func 'disabled)
6527 (error "Function %s disabled" func))
6530 (condition-case code
6532 (call-interactively func)
6538 (when (eq win (selected-window))
6539 (setq new-sum-point (point)
6540 new-sum-start (window-start win)
6541 new-sum-hscroll (window-hscroll win)))
6542 (when (or (eq in-buffer (current-buffer))
6543 (when (eq obuf (current-buffer))
6544 (set-buffer in-buffer)
6546 (setq selected (gnus-summary-select-article))
6548 (unless not-restore-window
6549 (set-window-configuration owin))
6550 (when (and (eq selected 'old)
6552 (set-window-start (get-buffer-window (current-buffer))
6554 (set-window-point (get-buffer-window (current-buffer))
6555 (if (article-goto-body)
6558 (when (and (not not-restore-window)
6561 (with-current-buffer (window-buffer win)
6562 (eq major-mode 'gnus-summary-mode)))
6563 (set-window-point win new-sum-point)
6564 (set-window-start win new-sum-start)
6565 (set-window-hscroll win new-sum-hscroll))))
6566 (set-window-configuration owin)
6568 (signal (car err) (cdr err))
6571 (defun gnus-article-read-summary-send-keys ()
6573 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6574 (gnus-article-read-summary-keys)))
6576 (defun gnus-article-describe-key (key)
6577 "Display documentation of the function invoked by KEY.
6578 KEY is a string or a vector."
6579 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6580 (read-key-sequence "Describe key: "))))
6581 (gnus-article-check-buffer)
6582 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6583 gnus-article-read-summary-send-keys))
6584 (with-current-buffer gnus-article-current-summary
6585 (setq unread-command-events
6586 (if (featurep 'xemacs)
6588 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6589 (list 'meta (- x 128))
6592 (let ((cursor-in-echo-area t)
6594 (describe-key (read-key-sequence nil t))))
6595 (describe-key key)))
6597 (defun gnus-article-describe-key-briefly (key &optional insert)
6598 "Display documentation of the function invoked by KEY.
6599 KEY is a string or a vector."
6600 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6601 (read-key-sequence "Describe key: "))
6602 current-prefix-arg))
6603 (gnus-article-check-buffer)
6604 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6605 gnus-article-read-summary-send-keys))
6606 (with-current-buffer gnus-article-current-summary
6607 (setq unread-command-events
6608 (if (featurep 'xemacs)
6610 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6611 (list 'meta (- x 128))
6614 (let ((cursor-in-echo-area t)
6616 (describe-key-briefly (read-key-sequence nil t) insert)))
6617 (describe-key-briefly key insert)))
6619 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6620 (defvar gnus-agent-summary-mode)
6621 (defvar gnus-draft-mode)
6622 ;; Calling help-buffer will autoload help-mode.
6623 (defvar help-xref-stack-item)
6624 ;; Emacs 22 doesn't load it in the batch mode.
6626 (autoload 'help-buffer "help-mode"))
6628 (defun gnus-article-describe-bindings (&optional prefix)
6629 "Show a list of all defined keys, and their definitions.
6630 The optional argument PREFIX, if non-nil, should be a key sequence;
6631 then we display only bindings that start with that prefix."
6633 (gnus-article-check-buffer)
6634 (let ((keymap (copy-keymap gnus-article-mode-map))
6635 (map (copy-keymap gnus-article-send-map))
6636 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6638 (define-key keymap "S" map)
6639 (define-key map [t] nil)
6640 (with-current-buffer gnus-article-current-summary
6643 (if (setq parent (keymap-parent gnus-article-mode-map))
6645 (setq parent (copy-keymap parent))
6646 (set-keymap-parent parent (current-local-map)))
6647 (current-local-map)))
6648 (set-keymap-parent map (key-binding "S"))
6649 (let (key def gnus-pick-mode)
6651 (setq key (pop sumkeys))
6652 (cond ((and (vectorp key) (= (length key) 1)
6653 (consp (setq def (aref key 0)))
6654 (numberp (car def)) (numberp (cdr def)))
6655 (when (< (max (car def) (cdr def)) 128)
6659 (nreverse (gnus-uncompress-range def)))
6661 ((setq def (key-binding key))
6662 (unless (eq def 'undefined)
6663 (define-key keymap key def))))))
6664 (when (boundp 'gnus-agent-summary-mode)
6665 (setq agent gnus-agent-summary-mode))
6666 (when (boundp 'gnus-draft-mode)
6667 (setq draft gnus-draft-mode)))
6669 (use-local-map keymap)
6670 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6671 (set (make-local-variable 'gnus-draft-mode) draft)
6672 (describe-bindings prefix))
6673 (let ((item `((lambda (prefix)
6674 (with-current-buffer ,(current-buffer)
6675 (gnus-article-describe-bindings prefix)))
6677 (with-current-buffer (let (help-xref-following) (help-buffer))
6678 (setq help-xref-stack-item item)))))
6680 (defun gnus-article-reply-with-original (&optional wide)
6681 "Start composing a reply mail to the current message.
6682 The text in the region will be yanked. If the region isn't active,
6683 the entire article will be yanked."
6685 (let ((article (cdr gnus-article-current))
6687 (if (not (gnus-region-active-p))
6688 (with-current-buffer gnus-summary-buffer
6689 (gnus-summary-reply (list (list article)) wide))
6690 (setq contents (buffer-substring (point) (mark t)))
6691 ;; Deactivate active regions.
6692 (when (and (boundp 'transient-mark-mode)
6693 transient-mark-mode)
6694 (setq mark-active nil))
6695 (with-current-buffer gnus-summary-buffer
6697 (list (list article contents)) wide)))))
6699 (defun gnus-article-wide-reply-with-original ()
6700 "Start composing a wide 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 (gnus-article-reply-with-original t))
6706 (defun gnus-article-followup-with-original ()
6707 "Compose a followup to the current article.
6708 The text in the region will be yanked. If the region isn't active,
6709 the entire article will be yanked."
6711 (let ((article (cdr gnus-article-current))
6713 (if (not (gnus-region-active-p))
6714 (with-current-buffer gnus-summary-buffer
6715 (gnus-summary-followup (list (list article))))
6716 (setq contents (buffer-substring (point) (mark t)))
6717 ;; Deactivate active regions.
6718 (when (and (boundp 'transient-mark-mode)
6719 transient-mark-mode)
6720 (setq mark-active nil))
6721 (with-current-buffer gnus-summary-buffer
6722 (gnus-summary-followup
6723 (list (list article contents)))))))
6725 (defun gnus-article-hide (&optional arg force)
6726 "Hide all the gruft in the current article.
6727 This means that signatures, cited text and (some) headers will be
6729 If given a prefix, show the hidden text instead."
6730 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6731 (gnus-article-hide-headers arg)
6732 (gnus-article-hide-list-identifiers arg)
6733 (gnus-article-hide-citation-maybe arg force)
6734 (gnus-article-hide-signature arg))
6736 (defun gnus-article-maybe-highlight ()
6737 "Do some article highlighting if article highlighting is requested."
6738 (when (gnus-visual-p 'article-highlight 'highlight)
6739 (gnus-article-highlight-some)))
6741 (defun gnus-check-group-server ()
6742 ;; Make sure the connection to the server is alive.
6743 (unless (gnus-server-opened
6744 (gnus-find-method-for-group gnus-newsgroup-name))
6745 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6746 (gnus-request-group gnus-newsgroup-name t)))
6749 (autoload 'nneething-get-file-name "nneething"))
6751 (defun gnus-request-article-this-buffer (article group)
6752 "Get an article and insert it into this buffer."
6753 (let (do-update-line sparse-header)
6757 (gnus-kill-all-overlays)
6758 (setq group (or group gnus-newsgroup-name))
6760 ;; Using `gnus-request-article' directly will insert the article into
6761 ;; `nntp-server-buffer' - so we'll save some time by not having to
6762 ;; copy it from the server buffer into the article buffer.
6764 ;; We only request an article by message-id when we do not have the
6765 ;; headers for it, so we'll have to get those.
6766 (when (stringp article)
6767 (gnus-read-header article))
6769 ;; If the article number is negative, that means that this article
6770 ;; doesn't belong in this newsgroup (possibly), so we find its
6771 ;; message-id and request it by id instead of number.
6772 (when (and (numberp article)
6774 (get-buffer gnus-summary-buffer)
6775 (gnus-buffer-exists-p gnus-summary-buffer))
6776 (with-current-buffer gnus-summary-buffer
6777 (let ((header (gnus-summary-article-header article)))
6780 ((memq article gnus-newsgroup-sparse)
6781 ;; This is a sparse gap article.
6782 (setq do-update-line article)
6783 (setq article (mail-header-id header))
6784 (setq sparse-header (gnus-read-header article))
6785 (setq gnus-newsgroup-sparse
6786 (delq article gnus-newsgroup-sparse)))
6788 ;; It's a real article.
6789 (setq article (mail-header-id header)))
6791 ;; It is an extracted pseudo-article.
6792 (setq article 'pseudo)
6793 (gnus-request-pseudo-article header))))
6795 (let ((method (gnus-find-method-for-group
6796 gnus-newsgroup-name)))
6797 (when (and (eq (car method) 'nneething)
6799 (let ((dir (nneething-get-file-name
6800 (mail-header-id header))))
6801 (when (and (stringp dir)
6802 (file-directory-p dir))
6803 (setq article 'nneething)
6804 (gnus-group-enter-directory dir))))))))
6807 ;; Refuse to select canceled articles.
6808 ((and (numberp article)
6810 (get-buffer gnus-summary-buffer)
6811 (gnus-buffer-exists-p gnus-summary-buffer)
6812 (eq (cdr (with-current-buffer gnus-summary-buffer
6813 (assq article gnus-newsgroup-reads)))
6814 gnus-canceled-mark))
6816 ;; We first check `gnus-original-article-buffer'.
6817 ((and (get-buffer gnus-original-article-buffer)
6819 (with-current-buffer gnus-original-article-buffer
6820 (and (equal (car gnus-original-article) group)
6821 (eq (cdr gnus-original-article) article))))
6822 ;; `insert-buffer-substring' would incorrectly use the
6823 ;; equivalent of string-make-multibyte which amount to decoding
6824 ;; with locale-coding-system, causing failure of
6825 ;; subsequent decoding.
6826 (insert (mm-string-to-multibyte
6827 (with-current-buffer gnus-original-article-buffer
6828 (buffer-substring (point-min) (point-max)))))
6830 ;; Check the backlog.
6831 ((and gnus-keep-backlog
6832 (gnus-backlog-request-article group article (current-buffer)))
6834 ;; Check asynchronous pre-fetch.
6835 ((gnus-async-request-fetched-article group article (current-buffer))
6836 (gnus-async-prefetch-next group article gnus-summary-buffer)
6837 (when (and (numberp article) gnus-keep-backlog)
6838 (gnus-backlog-enter-article group article (current-buffer)))
6841 ((and gnus-use-cache
6843 (gnus-cache-request-article article group))
6845 ;; Check the agent cache.
6846 ((gnus-agent-request-article article group)
6848 ;; Get the article and put into the article buffer.
6849 ((or (stringp article)
6851 (let ((gnus-override-method gnus-override-method)
6852 (methods (and (stringp article)
6853 (with-current-buffer gnus-summary-buffer
6854 (gnus-refer-article-methods))))
6855 (backend (car (gnus-find-method-for-group
6856 gnus-newsgroup-name)))
6858 (inhibit-read-only t))
6859 (when (and (null gnus-override-method)
6861 (setq gnus-override-method (pop methods)))
6864 (gnus-kill-all-overlays)
6865 (let ((gnus-newsgroup-name group))
6866 (gnus-check-group-server))
6868 ((gnus-request-article article group (current-buffer))
6869 (when (numberp article)
6870 (gnus-async-prefetch-next group article
6871 gnus-summary-buffer)
6872 (when gnus-keep-backlog
6873 (gnus-backlog-enter-article
6874 group article (current-buffer)))
6875 (when (and gnus-agent
6876 (gnus-agent-group-covered-p group))
6877 (gnus-agent-store-article article group)))
6878 (setq result 'article))
6880 (setq gnus-override-method (pop methods)))
6881 ((not (string-match "^400 "
6882 (nnheader-get-report backend)))
6883 ;; If we get 400 server disconnect, reconnect and
6884 ;; retry; otherwise, assume the article has expired.
6885 (setq result 'done))))
6886 (and (eq result 'article) 'article)))
6890 ;; Associate this article with the current summary buffer.
6891 (setq gnus-article-current-summary gnus-summary-buffer)
6893 ;; Take the article from the original article buffer
6894 ;; and place it in the buffer it's supposed to be in.
6895 (when (and (get-buffer gnus-article-buffer)
6896 (equal (buffer-name (current-buffer))
6897 (buffer-name (get-buffer gnus-article-buffer))))
6899 (if (get-buffer gnus-original-article-buffer)
6900 (set-buffer gnus-original-article-buffer)
6901 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6902 (buffer-disable-undo)
6903 (setq major-mode 'gnus-original-article-mode)
6904 (setq buffer-read-only t))
6905 (let ((inhibit-read-only t))
6907 (insert-buffer-substring gnus-article-buffer))
6908 (setq gnus-original-article (cons group article)))
6911 (run-hooks 'gnus-article-decode-hook)
6912 ;; Mark article as decoded or not.
6913 (setq gnus-article-decoded-p gnus-article-decode-hook))
6915 ;; Update sparse articles.
6916 (when (and do-update-line
6917 (or (numberp article)
6919 (let ((buf (current-buffer)))
6920 (set-buffer gnus-summary-buffer)
6921 (gnus-summary-update-article do-update-line sparse-header)
6922 (gnus-summary-goto-subject do-update-line nil t)
6923 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6925 (set-buffer buf))))))
6927 (defun gnus-block-private-groups (group)
6928 (if (gnus-news-group-p group)
6929 ;; Block nothing in news groups.
6931 ;; Block everything anywhere else.
6934 (defun gnus-blocked-images ()
6935 (if (functionp gnus-blocked-images)
6936 (funcall gnus-blocked-images gnus-newsgroup-name)
6937 gnus-blocked-images))
6943 (defcustom gnus-article-edit-mode-hook nil
6944 "Hook run in article edit mode buffers."
6945 :group 'gnus-article-various
6948 (defvar gnus-article-edit-done-function nil)
6950 (defvar gnus-article-edit-mode-map nil)
6952 ;; Should we be using derived.el for this?
6953 (unless gnus-article-edit-mode-map
6954 (setq gnus-article-edit-mode-map (make-keymap))
6955 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6957 (gnus-define-keys gnus-article-edit-mode-map
6958 "\C-c?" describe-mode
6959 "\C-c\C-c" gnus-article-edit-done
6960 "\C-c\C-k" gnus-article-edit-exit
6961 "\C-c\C-f\C-t" message-goto-to
6962 "\C-c\C-f\C-o" message-goto-from
6963 "\C-c\C-f\C-b" message-goto-bcc
6964 ;;"\C-c\C-f\C-w" message-goto-fcc
6965 "\C-c\C-f\C-c" message-goto-cc
6966 "\C-c\C-f\C-s" message-goto-subject
6967 "\C-c\C-f\C-r" message-goto-reply-to
6968 "\C-c\C-f\C-n" message-goto-newsgroups
6969 "\C-c\C-f\C-d" message-goto-distribution
6970 "\C-c\C-f\C-f" message-goto-followup-to
6971 "\C-c\C-f\C-m" message-goto-mail-followup-to
6972 "\C-c\C-f\C-k" message-goto-keywords
6973 "\C-c\C-f\C-u" message-goto-summary
6974 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6975 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6976 "\C-c\C-b" message-goto-body
6977 "\C-c\C-i" message-goto-signature
6979 "\C-c\C-t" message-insert-to
6980 "\C-c\C-n" message-insert-newsgroups
6981 "\C-c\C-o" message-sort-headers
6982 "\C-c\C-e" message-elide-region
6983 "\C-c\C-v" message-delete-not-region
6984 "\C-c\C-z" message-kill-to-signature
6985 "\M-\r" message-newline-and-reformat
6986 "\C-c\C-a" mml-attach-file
6987 "\C-a" message-beginning-of-line
6989 "\M-;" comment-region)
6991 (gnus-define-keys (gnus-article-edit-wash-map
6992 "\C-c\C-w" gnus-article-edit-mode-map)
6993 "f" gnus-article-edit-full-stops))
6996 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6998 ["Fetch To" message-insert-to t]
6999 ["Fetch Newsgroups" message-insert-newsgroups t]
7001 ["To" message-goto-to t]
7002 ["From" message-goto-from t]
7003 ["Subject" message-goto-subject t]
7004 ["Cc" message-goto-cc t]
7005 ["Reply-To" message-goto-reply-to t]
7006 ["Summary" message-goto-summary t]
7007 ["Keywords" message-goto-keywords t]
7008 ["Newsgroups" message-goto-newsgroups t]
7009 ["Followup-To" message-goto-followup-to t]
7010 ["Mail-Followup-To" message-goto-mail-followup-to t]
7011 ["Distribution" message-goto-distribution t]
7012 ["Body" message-goto-body t]
7013 ["Signature" message-goto-signature t]))
7015 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7016 "Major mode for editing articles.
7017 This is an extended text-mode.
7019 \\{gnus-article-edit-mode-map}"
7020 (make-local-variable 'gnus-article-edit-done-function)
7021 (make-local-variable 'gnus-prev-winconf)
7022 (set (make-local-variable 'font-lock-defaults)
7023 '(message-font-lock-keywords t))
7024 (set (make-local-variable 'mail-header-separator) "")
7025 (set (make-local-variable 'gnus-article-edit-mode) t)
7026 (easy-menu-add message-mode-field-menu message-mode-map)
7028 (setq buffer-read-only nil)
7029 (buffer-enable-undo)
7032 (defun gnus-article-edit (&optional force)
7033 "Edit the current article.
7034 This will have permanent effect only in mail groups.
7035 If FORCE is non-nil, allow editing of articles even in read-only
7038 (when (and (not force)
7039 (gnus-group-read-only-p))
7040 (error "The current newsgroup does not support article editing"))
7041 (gnus-article-date-original)
7042 (gnus-article-edit-article
7044 `(lambda (no-highlight)
7046 (gnus-summary-edit-article-done
7047 ,(or (mail-header-references gnus-current-headers) "")
7048 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7050 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7051 "Start editing the contents of the current article buffer."
7052 (let ((winconf (current-window-configuration)))
7053 (set-buffer gnus-article-buffer)
7054 (let ((message-auto-save-directory
7055 ;; Don't associate the article buffer with a draft file.
7057 (gnus-article-edit-mode))
7058 (funcall start-func)
7059 (set-buffer-modified-p nil)
7060 (gnus-configure-windows 'edit-article)
7061 (setq gnus-article-edit-done-function exit-func)
7062 (setq gnus-prev-winconf winconf)
7064 (gnus-message 6 "C-c C-c to end edits"))))
7066 (defun gnus-article-edit-done (&optional arg)
7067 "Update the article edits and exit."
7069 (let ((func gnus-article-edit-done-function)
7070 (buf (current-buffer))
7071 (start (window-start))
7073 (winconf gnus-prev-winconf))
7074 (widen) ;; Widen it in case that users narrowed the buffer.
7077 ;; The cache and backlog have to be flushed somewhat.
7078 (when gnus-keep-backlog
7079 (gnus-backlog-remove-article
7080 (car gnus-article-current) (cdr gnus-article-current)))
7081 ;; Flush original article as well.
7082 (gnus-flush-original-article-buffer)
7083 (when gnus-use-cache
7084 (gnus-cache-update-article
7085 (car gnus-article-current) (cdr gnus-article-current)))
7086 ;; We remove all text props from the article buffer.
7087 (kill-all-local-variables)
7088 (set-text-properties (point-min) (point-max) nil)
7090 (set-window-configuration winconf)
7092 (set-window-start (get-buffer-window buf) start)
7093 (set-window-point (get-buffer-window buf) (point)))
7094 (gnus-summary-show-article))
7096 (defun gnus-flush-original-article-buffer ()
7097 (when (get-buffer gnus-original-article-buffer)
7098 (with-current-buffer gnus-original-article-buffer
7099 (setq gnus-original-article nil))))
7101 (defun gnus-article-edit-exit ()
7102 "Exit the article editing without updating."
7104 (when (or (not (buffer-modified-p))
7105 (yes-or-no-p "Article modified; kill anyway? "))
7106 (let ((curbuf (current-buffer))
7108 (window-start (window-start)))
7110 (if (gnus-buffer-live-p gnus-original-article-buffer)
7111 (insert-buffer-substring gnus-original-article-buffer))
7112 (let ((winconf gnus-prev-winconf))
7113 (kill-all-local-variables)
7115 (set-window-configuration winconf)
7116 ;; Tippy-toe some to make sure that point remains where it was.
7117 (save-current-buffer
7119 (set-window-start (get-buffer-window (current-buffer)) window-start)
7121 (gnus-summary-show-article)))
7123 (defun gnus-article-edit-full-stops ()
7124 "Interactively repair spacing at end of sentences."
7127 (goto-char (point-min))
7128 (search-forward-regexp "^$" nil t)
7129 (let ((case-fold-search nil))
7130 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7133 ;;; Article highlights
7136 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7138 ;;; Internal Variables:
7140 (defcustom gnus-button-url-regexp
7142 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7143 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7144 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7145 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7146 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7150 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7151 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7152 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7154 "[" chars punct "]+" "[" chars "]"
7156 (concat ;; XEmacs 21.4 doesn't support POSIX.
7157 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7158 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7160 "Regular expression that matches URLs."
7161 :group 'gnus-article-buttons
7164 (defcustom gnus-button-valid-fqdn-regexp
7165 message-valid-fqdn-regexp
7166 "Regular expression that matches a valid FQDN."
7168 :group 'gnus-article-buttons
7171 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7172 (defcustom gnus-button-valid-localpart-regexp
7173 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7174 "Regular expression that matches a localpart of mail addresses or MIDs."
7176 :group 'gnus-article-buttons
7179 (defcustom gnus-button-man-handler 'manual-entry
7180 "Function to use for displaying man pages.
7181 The function must take at least one argument with a string naming the
7184 :type '(choice (function-item :tag "Man" manual-entry)
7185 (function-item :tag "Woman" woman)
7186 (function :tag "Other"))
7187 :group 'gnus-article-buttons)
7189 (defcustom gnus-button-mid-or-mail-regexp
7190 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7191 gnus-button-valid-fqdn-regexp
7193 "Regular expression that matches a message ID or a mail address."
7195 :group 'gnus-article-buttons
7198 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7199 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7200 Strings like this can be either a message ID or a mail address. If it is one
7201 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7202 message ID or a mail address, respectively. If this variable is set to the
7203 symbol `ask', always query the user what do do. If it is a function, this
7204 function will be called with the string as its only argument. The function
7205 must return `mid', `mail', `invalid' or `ask'."
7207 :group 'gnus-article-buttons
7208 :type '(choice (function-item :tag "Heuristic function"
7209 gnus-button-mid-or-mail-heuristic)
7214 (defcustom gnus-button-mid-or-mail-heuristic-alist
7215 '((-10.0 . ".+\\$.+@")
7218 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7219 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7220 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7221 (-1.0 . "^[^a-z]+@")
7223 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7224 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7225 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7226 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7229 (-1.0 . "^[0-9][0-9]")
7231 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7232 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7233 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7234 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7236 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7237 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7240 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7242 ;; compensation for TDMA dated mail addresses:
7243 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7245 (-20.0 . "\\.fsf@") ;; Gnus
7248 (-20.0 . "^alpine\\.")
7249 (-20.0 . "_-_") ;; Subject change in thread
7251 (-20.0 . "\\.ln@") ;; leafnode
7252 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7253 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7255 ;; (5.0 . "") ;; $local_part_len <= 7
7256 (10.0 . "^[^0-9]+@")
7257 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7258 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7261 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7263 (0.5 . "^[A-Z][a-z]")
7264 (0.5 . "^[A-Z][a-z][a-z]")
7265 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7266 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7267 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7269 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7270 address. The REGEXP is processed with `case-fold-search' set to nil."
7272 :group 'gnus-article-buttons
7273 :type '(repeat (cons (number :tag "Rate")
7274 (regexp :tag "Regexp"))))
7276 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7277 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7278 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7279 address, `ask' if unsure and `invalid' if the string is invalid."
7280 (let ((case-fold-search nil)
7281 (list gnus-button-mid-or-mail-heuristic-alist)
7282 (result 0) rate regexp lpartlen elem)
7284 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7285 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7286 ;; Certain special cases...
7289 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7290 "^[0-9]+\\.[0-9]+@compuserve\\|"
7291 "@public\\.gmane\\.org")
7293 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7294 (setq result 'mail))
7295 (when (string-match "@.*@\\| " mid-or-mail)
7296 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7297 (setq result 'invalid))
7298 ;; Nothing more to do, if result is not a number here...
7299 (when (numberp result)
7301 (setq elem (car list)
7305 (when (string-match regexp mid-or-mail)
7306 (setq result (+ result rate))
7308 9 "`%s' matched `%s', rate `%s', result `%s'."
7309 mid-or-mail regexp rate result)))
7310 (when (<= lpartlen 7)
7311 (setq result (+ result 5.0))
7312 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7313 mid-or-mail result))
7314 (when (>= lpartlen 12)
7315 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7317 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7318 ;; Long local part should contain realname if e-mail address,
7319 ;; too many digits: message-id.
7320 ;; $score -= 5.0 + 0.1 * $local_part_len;
7321 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7322 (setq result (+ result rate))
7324 9 "Many digits in `%s', rate `%s', result `%s'."
7325 mid-or-mail rate result))
7326 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7328 ;; Too few vowels [^aeiouy]{4,}.*\@
7329 (setq result (+ result -5.0))
7331 9 "Few vowels in `%s', rate `%s', result `%s'."
7332 mid-or-mail -5.0 result))
7334 (setq result (+ result 5.0))
7336 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7337 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7338 ;; Maybe we should make this a customizable alist: (condition . 'result)
7340 ((symbolp result) result)
7341 ;; Now convert number into proper results:
7342 ((< result -10.0) 'mid)
7343 ((> result 10.0) 'mail)
7346 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7347 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7348 (url-mid (concat "news" ":" mid-or-mail))
7349 (url-mailto (concat "mailto" ":" mid-or-mail)))
7350 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7351 (when (fboundp pref)
7353 ;; get rid of surrounding angles...
7355 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7356 (if (or (eq 'mid guessed) (eq 'mail guessed))
7360 (save-window-excursion
7361 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7364 (cond ((eq pref 'mid)
7365 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7366 (gnus-button-handle-news url-mid))
7368 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7369 (gnus-url-mailto url-mailto))
7370 (t (gnus-message 3 "Invalid string.")))))
7372 (defun gnus-button-handle-custom (fun arg)
7373 "Call function FUN on argument ARG.
7374 Both FUN and ARG are supposed to be strings. ARG will be passed
7375 as a symbol to FUN."
7376 (funcall (intern fun)
7377 (if (string-match "^customize-apropos" fun)
7381 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7383 (defun gnus-button-handle-describe-function (url)
7384 "Call `describe-function' when pushing the corresponding URL button."
7387 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7389 (defun gnus-button-handle-describe-variable (url)
7390 "Call `describe-variable' when pushing the corresponding URL button."
7393 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7395 (defun gnus-button-handle-symbol (url)
7396 "Display help on variable or function.
7397 Calls `describe-variable' or `describe-function'."
7398 (let ((sym (intern url)))
7400 ((fboundp sym) (describe-function sym))
7401 ((boundp sym) (describe-variable sym))
7402 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7404 (defun gnus-button-handle-describe-key (url)
7405 "Call `describe-key' when pushing the corresponding URL button."
7407 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7408 (keys (ignore-errors (eval `(kbd ,key-string)))))
7411 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7413 (defun gnus-button-handle-apropos (url)
7414 "Call `apropos' when pushing the corresponding URL button."
7415 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7417 (defun gnus-button-handle-apropos-command (url)
7418 "Call `apropos' when pushing the corresponding URL button."
7420 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7422 (defun gnus-button-handle-apropos-variable (url)
7423 "Call `apropos' when pushing the corresponding URL button."
7425 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7426 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7428 (defun gnus-button-handle-apropos-documentation (url)
7429 "Call `apropos' when pushing the corresponding URL button."
7431 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7432 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7434 (defun gnus-button-handle-library (url)
7435 "Call `locate-library' when pushing the corresponding URL button."
7436 (gnus-message 9 "url=`%s'" url)
7437 (let* ((lib (locate-library url))
7438 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7440 (gnus-message 1 "Cannot locale library `%s'." url)
7441 (find-file-read-only file))))
7443 (defcustom gnus-button-man-level 5
7444 "*Integer that says how many man-related buttons Gnus will show.
7445 The higher the number, the more buttons will appear and the more false
7446 positives are possible. Note that you can set this variable local to
7447 specific groups. Setting it higher in Unix groups is probably a good idea.
7448 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7449 how to set variables in specific groups."
7451 :group 'gnus-article-buttons
7452 :link '(custom-manual "(gnus)Group Parameters")
7455 (defcustom gnus-button-emacs-level 5
7456 "*Integer that says how many emacs-related buttons Gnus will show.
7457 The higher the number, the more buttons will appear and the more false
7458 positives are possible. Note that you can set this variable local to
7459 specific groups. Setting it higher in Emacs or Gnus related groups is
7460 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7461 `gnus-parameters' on how to set variables in specific groups."
7463 :group 'gnus-article-buttons
7464 :link '(custom-manual "(gnus)Group Parameters")
7467 (defcustom gnus-button-message-level 5
7468 "*Integer that says how many buttons for news or mail messages will appear.
7469 The higher the number, the more buttons will appear and the more false
7470 positives are possible."
7471 ;; mail addresses, MIDs, URLs for news, ...
7473 :group 'gnus-article-buttons
7476 (defcustom gnus-button-browse-level 5
7477 "*Integer that says how many buttons for browsing will appear.
7478 The higher the number, the more buttons will appear and the more false
7479 positives are possible."
7480 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7482 :group 'gnus-article-buttons
7485 (defcustom gnus-button-alist
7486 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7487 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7488 ((concat "\\b\\(nntp\\|news\\):\\("
7489 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7490 0 t gnus-button-handle-news 2)
7491 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7492 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7493 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7494 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7495 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7496 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7497 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7498 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7499 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7500 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7501 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7502 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7503 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7504 ;; RFC 2368 (The mailto URL scheme)
7505 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7506 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7507 ("\\bmailto:\\([^ \n\t]+\\)"
7508 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7509 ;; Info Konqueror style <info:/foo/bar baz>.
7510 ;; Must come before " Gnus home-grown style".
7511 ("\\binfo://?\\([^'\">\n\t]+\\)"
7512 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7513 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7514 ("\\binfo://\\([^'\">\n\t ]+\\)"
7515 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7516 ;; Info GNOME style <info:foo#bar_baz>
7517 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7518 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7519 ;; Info KDE style <info:(foo)bar baz>
7520 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7521 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7522 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7523 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7524 ("\\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,]*\\)\\)?"
7525 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7526 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7528 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7529 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7530 ;; Emacs help commands
7531 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7532 ;; regexp doesn't match arguments containing ` '.
7533 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7534 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7535 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7536 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7537 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7538 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7539 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7540 ;; The following entries may lead to many false positives so don't enable
7541 ;; them by default (use a high button level).
7542 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7543 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7544 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7545 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7546 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7547 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7548 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7549 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7550 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7551 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7552 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7553 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7554 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7555 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7556 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7557 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7558 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7559 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7560 ;; Unlike the other regexps we really have to require quoting
7561 ;; here to determine where it ends.
7562 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7563 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7564 ("<URL: *\\([^\n<>]*\\)>"
7565 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7566 ;; RFC 2396 (2.4.3., delims) ...
7567 ("\"URL: *\\([^\n\"]*\\)\""
7568 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7570 (gnus-button-url-regexp
7571 0 (>= gnus-button-browse-level 0) browse-url 0)
7573 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7574 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7575 gnus-button-handle-man 1)
7576 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7577 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7578 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7579 gnus-button-handle-man 1)
7580 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7581 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7582 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7583 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7584 ;; Recognizing patches to .el files. This is somewhat obscure,
7585 ;; but considering the percentage of Gnus users who hack Emacs
7587 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7588 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7589 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7590 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7591 ;; MID or mail: To avoid too many false positives we don't try to catch
7592 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7593 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7594 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7595 ;; so that non-ambiguous entries (see above) match first.
7596 (gnus-button-mid-or-mail-regexp
7597 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7598 "*Alist of regexps matching buttons in article bodies.
7600 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7601 REGEXP: is the string (case insensitive) matching text around the button (can
7602 also be Lisp expression evaluating to a string),
7603 BUTTON: is the number of the regexp grouping actually matching the button,
7604 FORM: is a Lisp expression which must eval to true for the button to
7606 CALLBACK: is the function to call when the user push this button, and each
7607 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7609 CALLBACK can also be a variable, in that case the value of that
7610 variable it the real callback function."
7611 :group 'gnus-article-buttons
7612 :type '(repeat (list (choice regexp variable sexp)
7613 (integer :tag "Button")
7615 (function :tag "Callback")
7618 (integer :tag "Regexp group")))))
7619 (put 'gnus-button-alist 'risky-local-variable t)
7621 (defcustom gnus-header-button-alist
7622 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7623 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7624 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7625 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7626 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7627 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7628 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7629 0 (>= gnus-button-browse-level 0) browse-url 0)
7630 ("^Subject:" gnus-button-url-regexp
7631 0 (>= gnus-button-browse-level 0) browse-url 0)
7632 ("^[^:]+:" gnus-button-url-regexp
7633 0 (>= gnus-button-browse-level 0) browse-url 0)
7634 ("^OpenPGP:.*url=" gnus-button-url-regexp
7635 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7636 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7637 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7638 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7639 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7640 "*Alist of headers and regexps to match buttons in article heads.
7642 This alist is very similar to `gnus-button-alist', except that each
7643 alist has an additional HEADER element first in each entry:
7645 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7647 HEADER is a regexp to match a header. For a fuller explanation, see
7648 `gnus-button-alist'."
7649 :group 'gnus-article-buttons
7650 :group 'gnus-article-headers
7651 :type '(repeat (list (regexp :tag "Header")
7652 (choice regexp variable)
7653 (integer :tag "Button")
7655 (function :tag "Callback")
7658 (integer :tag "Regexp group")))))
7659 (put 'gnus-header-button-alist 'risky-local-variable t)
7663 (defun gnus-article-push-button (event)
7664 "Check text under the mouse pointer for a callback function.
7665 If the text under the mouse pointer has a `gnus-callback' property,
7666 call it with the value of the `gnus-data' text property."
7668 (set-buffer (window-buffer (posn-window (event-start event))))
7669 (let* ((pos (posn-point (event-start event)))
7670 (data (get-text-property pos 'gnus-data))
7671 (fun (get-text-property pos 'gnus-callback)))
7674 (funcall fun data))))
7676 (defun gnus-article-press-button ()
7677 "Check text at point for a callback function.
7678 If the text at point has a `gnus-callback' property,
7679 call it with the value of the `gnus-data' text property."
7681 (let ((data (get-text-property (point) 'gnus-data))
7682 (fun (get-text-property (point) 'gnus-callback)))
7684 (funcall fun data))))
7686 (defun gnus-article-highlight (&optional force)
7687 "Highlight current article.
7688 This function calls `gnus-article-highlight-headers',
7689 `gnus-article-highlight-citation',
7690 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7691 do the highlighting. See the documentation for those functions."
7692 (interactive (list 'force))
7693 (gnus-article-highlight-headers)
7694 (gnus-article-highlight-citation force)
7695 (gnus-article-highlight-signature)
7696 (gnus-article-add-buttons)
7697 (gnus-article-add-buttons-to-head))
7699 (defun gnus-article-highlight-some (&optional force)
7700 "Highlight current article.
7701 This function calls `gnus-article-highlight-headers',
7702 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7703 do the highlighting. See the documentation for those functions."
7704 (interactive (list 'force))
7705 (gnus-article-highlight-headers)
7706 (gnus-article-highlight-signature)
7707 (gnus-article-add-buttons))
7709 (defun gnus-article-highlight-headers ()
7710 "Highlight article headers as specified by `gnus-header-face-alist'."
7712 (gnus-with-article-headers
7713 (let (regexp header-face field-face from hpoints fpoints)
7714 (dolist (entry gnus-header-face-alist)
7715 (goto-char (point-min))
7716 (setq regexp (concat "^\\("
7717 (if (string-equal "" (nth 0 entry))
7721 header-face (nth 1 entry)
7722 field-face (nth 2 entry))
7723 (while (and (re-search-forward regexp nil t)
7727 (unless (search-forward ":" nil t)
7729 (when (and header-face
7730 (not (memq (point) hpoints)))
7731 (push (point) hpoints)
7732 (gnus-put-text-property from (point) 'face header-face))
7733 (when (and field-face
7734 (not (memq (setq from (point)) fpoints)))
7736 (if (re-search-forward "^[^ \t]" nil t)
7738 (goto-char (point-max)))
7739 (gnus-put-text-property from (point) 'face field-face)))))))
7741 (defun gnus-article-highlight-signature ()
7742 "Highlight the signature in an article.
7743 It does this by highlighting everything after
7744 `gnus-signature-separator' using the face `gnus-signature'."
7746 (gnus-with-article-buffer
7747 (let ((inhibit-point-motion-hooks t))
7749 (when (and gnus-signature-face
7750 (gnus-article-narrow-to-signature))
7751 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7752 'face gnus-signature-face)
7754 (gnus-article-search-signature)
7755 (let ((start (match-beginning 0))
7756 (end (set-marker (make-marker) (1+ (match-end 0)))))
7757 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7760 (defun gnus-button-in-region-p (b e prop)
7761 "Say whether PROP exists in the region."
7762 (text-property-not-all b e prop nil))
7764 (defun gnus-article-add-buttons ()
7765 "Find external references in the article and make buttons of them.
7766 \"External references\" are things like Message-IDs and URLs, as
7767 specified by `gnus-button-alist'."
7769 (gnus-with-article-buffer
7770 (let ((inhibit-point-motion-hooks t)
7771 (case-fold-search t)
7772 (alist gnus-button-alist)
7774 ;; We skip the headers.
7777 (while (setq entry (pop alist))
7778 (setq regexp (eval (car entry)))
7780 (while (re-search-forward regexp nil t)
7781 (let ((start (match-beginning (nth 1 entry)))
7782 (end (match-end (nth 1 entry)))
7783 (from (match-beginning 0)))
7784 (when (and (eval (nth 2 entry))
7785 (not (gnus-button-in-region-p
7786 start end 'gnus-callback)))
7787 ;; That optional form returned non-nil, so we add the
7789 (setq from (set-marker (make-marker) from))
7790 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7791 (gnus-article-extend-url-button from start end))
7792 (gnus-article-add-button start end
7793 'gnus-button-push (list from entry))
7794 (gnus-put-text-property
7796 'gnus-string (buffer-substring-no-properties
7799 (defun gnus-article-extend-url-button (beg start end)
7800 "Extend url button if url is folded into two or more lines.
7801 Return non-nil if button is extended. BEG is a marker that points to
7802 the beginning position of a text containing url. START and END are
7803 the endpoints of a url button before it is extended. The concatenated
7804 url is put as the `gnus-button-url' overlay property on the button."
7805 (let ((opoint (point))
7806 (points (list start end))
7811 (not (looking-at "[\t ]*[\">]")))
7815 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7816 (buffer-substring (point-at-bol) start)))
7818 (setq url (list (buffer-substring start end))
7819 delim (if (match-beginning 1) ">" "\""))
7821 (setq regexp (concat
7822 (when (and (looking-at
7823 message-cite-prefix-regexp)
7824 (< (match-end 0) start))
7825 (regexp-quote (match-string 0)))
7827 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7831 (and (looking-at regexp)
7834 (push (or (match-string 2)
7837 (push (setq end (or (match-end 2)
7840 (push (or (match-beginning 2)
7841 (match-beginning 1))
7843 (match-beginning 2)))
7844 (let (gnus-article-mouse-face widget-mouse-face)
7846 (gnus-article-add-button (pop points) (pop points)
7847 'gnus-button-push beg)))
7848 (let ((overlay (gnus-make-overlay start end)))
7849 (gnus-overlay-put overlay 'evaporate t)
7850 (gnus-overlay-put overlay 'gnus-button-url
7851 (list (mapconcat 'identity (nreverse url) "")))
7852 (when gnus-article-mouse-face
7853 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7855 (goto-char opoint))))
7857 ;; Add buttons to the head of an article.
7858 (defun gnus-article-add-buttons-to-head ()
7859 "Add buttons to the head of the article."
7861 (gnus-with-article-headers
7863 (dolist (entry gnus-header-button-alist)
7864 ;; Each alist entry.
7865 (goto-char (point-min))
7866 (while (re-search-forward (car entry) nil t)
7867 ;; Each header matching the entry.
7868 (setq beg (match-beginning 0))
7869 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7870 (match-beginning 0))
7873 (while (re-search-forward (eval (nth 1 entry)) end t)
7874 ;; Each match within a header.
7875 (let* ((entry (cdr entry))
7876 (start (match-beginning (nth 1 entry)))
7877 (end (match-end (nth 1 entry)))
7878 (form (nth 2 entry)))
7879 (goto-char (match-end 0))
7881 (gnus-article-add-button
7882 start end (nth 3 entry)
7883 (buffer-substring (match-beginning (nth 4 entry))
7884 (match-end (nth 4 entry)))))))
7885 (goto-char end))))))
7887 ;;; External functions:
7889 (defun gnus-article-add-button (from to fun &optional data text)
7890 "Create a button between FROM and TO with callback FUN and data DATA."
7891 (when gnus-article-button-face
7892 (gnus-overlay-put (gnus-make-overlay from to nil t)
7893 'face gnus-article-button-face))
7894 (gnus-add-text-properties
7896 (nconc (and gnus-article-mouse-face
7897 (list gnus-mouse-face-prop gnus-article-mouse-face))
7898 (list 'gnus-callback fun)
7899 (and data (list 'gnus-data data))))
7900 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7901 :help-echo (or text "Follow the link")
7902 :keymap gnus-url-button-map
7903 :button-keymap gnus-widget-button-keymap))
7905 (defun gnus-article-copy-string ()
7906 "Copy the string in the button to the kill ring."
7908 (gnus-article-check-buffer)
7909 (let ((data (get-text-property (point) 'gnus-string)))
7913 (copy-region-as-kill (point-min) (point-max))
7914 (message "Copied %s" data)))))
7916 ;;; Internal functions:
7918 (defun gnus-article-set-globals ()
7919 (with-current-buffer gnus-summary-buffer
7920 (gnus-set-global-variables)))
7922 (defun gnus-signature-toggle (end)
7923 (gnus-with-article-buffer
7924 (let ((inhibit-point-motion-hooks t))
7925 (if (text-property-any end (point-max) 'article-type 'signature)
7927 (gnus-delete-wash-type 'signature)
7928 (gnus-remove-text-properties-when
7929 'article-type 'signature end (point-max)
7930 (cons 'article-type (cons 'signature
7931 gnus-hidden-properties))))
7932 (gnus-add-wash-type 'signature)
7933 (gnus-add-text-properties-when
7934 'article-type nil end (point-max)
7935 (cons 'article-type (cons 'signature
7936 gnus-hidden-properties)))))
7937 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7938 (gnus-set-mode-line 'article))))
7940 (defun gnus-button-push (marker-and-entry)
7941 ;; Push button starting at MARKER.
7943 (let* ((marker (car marker-and-entry))
7944 (entry (cadr marker-and-entry))
7945 (regexp (car entry))
7946 (inhibit-point-motion-hooks t))
7948 ;; This is obviously true, or something bad is happening :)
7949 ;; But we need it to have the match-data
7950 (when (looking-at (or (if (symbolp regexp)
7951 (symbol-value regexp)
7953 (let ((fun (nth 3 entry))
7954 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7955 (get-char-property marker 'gnus-button-url))
7956 (mapcar (lambda (group)
7957 (let ((string (match-string group)))
7958 (set-text-properties
7959 0 (length string) nil string)
7961 (nthcdr 4 entry)))))
7967 (fboundp (symbol-value fun)))
7968 (apply (symbol-value fun) args))
7970 (gnus-message 1 "You must define `%S' to use this button"
7971 (cons fun args)))))))))
7973 (defun gnus-parse-news-url (url)
7974 (let (scheme server port group message-id articles)
7977 (goto-char (point-min))
7978 (when (looking-at "\\([A-Za-z]+\\):")
7979 (setq scheme (match-string 1))
7980 (goto-char (match-end 0)))
7981 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7982 (setq server (match-string 1))
7983 (setq port (if (stringp (match-string 3))
7984 (string-to-number (match-string 3))
7986 (goto-char (match-end 0)))
7989 ((looking-at "\\(.*@.*\\)")
7990 (setq message-id (match-string 1)))
7991 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7992 (setq group (match-string 1)
7993 articles (split-string (match-string 2) "-")))
7994 ((looking-at "\\([^/]+\\)/?")
7995 (setq group (match-string 1)))
7997 (error "Unknown news URL syntax"))))
7998 (list scheme server port group message-id articles)))
8000 (defun gnus-button-handle-news (url)
8002 (destructuring-bind (scheme server port group message-id articles)
8003 (gnus-parse-news-url url)
8006 (with-current-buffer gnus-summary-buffer
8008 (let ((gnus-refer-article-method
8009 (nconc (list (list 'nntp server))
8010 gnus-refer-article-method))
8011 (nntp-port-number (or port "nntp")))
8012 (gnus-message 7 "Fetching %s with %s"
8013 message-id gnus-refer-article-method)
8014 (gnus-summary-refer-article message-id))
8015 (gnus-summary-refer-article message-id))))
8017 (gnus-button-fetch-group url)))))
8019 (defun gnus-button-patch (library line)
8020 "Visit an Emacs Lisp library LIBRARY on line LINE."
8022 (let ((file (locate-library (file-name-nondirectory library))))
8024 (error "Couldn't find library %s" library))
8026 (goto-char (point-min))
8027 (forward-line (1- (string-to-number line)))))
8029 (defun gnus-button-handle-man (url)
8031 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8032 (when (eq gnus-button-man-handler 'woman)
8033 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8034 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8035 (funcall gnus-button-man-handler url))
8037 (defun gnus-button-handle-info-url (url)
8038 "Fetch an info URL."
8039 (setq url (mm-subst-char-in-string ?+ ?\ url))
8041 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8042 (gnus-info-find-node
8043 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8045 ")" (gnus-url-unhex-string (match-string 2 url)))))
8046 ((string-match "([^)\"]+)[^\"]+" url)
8048 (gnus-replace-in-string
8049 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8050 (gnus-info-find-node url))
8051 (t (error "Can't parse %s" url))))
8053 (defun gnus-button-handle-info-url-gnome (url)
8054 "Fetch GNOME style info URL."
8055 (setq url (mm-subst-char-in-string ?_ ?\ url))
8056 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8057 (gnus-info-find-node
8059 (gnus-url-unhex-string
8060 (match-string 1 url))
8062 (or (gnus-url-unhex-string
8063 (match-string 2 url))
8065 (error "Can't parse %s" url)))
8067 (defun gnus-button-handle-info-url-kde (url)
8068 "Fetch KDE style info URL."
8069 (gnus-info-find-node (gnus-url-unhex-string url)))
8071 ;; (info) will autoload info.el
8072 (declare-function Info-menu "info" (menu-item &optional fork))
8073 (declare-function Info-index-next "info" (num))
8075 (defun gnus-button-handle-info-keystrokes (url)
8076 "Call `info' when pushing the corresponding URL button."
8077 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8078 (let (node indx comma)
8080 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8081 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8082 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8083 "\\(?:[ \t\n,]*\\)\\)?")
8085 (setq node (match-string 2 url)
8086 indx (match-string 3 url))
8087 (error "Can't parse %s" url))
8091 (when (> (length indx) 0)
8092 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8095 (setq comma (match-string 2 indx))
8096 (setq indx (match-string 1 indx))
8099 (dotimes (i (with-temp-buffer
8101 ;; Note: the XEmacs version of `how-many' takes
8102 ;; no optional argument.
8103 (goto-char (point-min))
8105 (Info-index-next 1)))
8108 (autoload 'pgg-snarf-keys-region "pgg")
8109 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8110 (declare-function pgg-display-output-buffer "pgg" (start end status))
8112 (defun gnus-button-openpgp (url)
8113 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8115 (mm-url-insert-file-contents-external url)
8116 (pgg-snarf-keys-region (point-min) (point-max))
8117 (pgg-display-output-buffer nil nil nil)))
8119 (defun gnus-button-message-id (message-id)
8121 (with-current-buffer gnus-summary-buffer
8122 (gnus-summary-refer-article message-id)))
8124 (defun gnus-button-fetch-group (address &rest ignore)
8125 "Fetch GROUP specified by ADDRESS."
8126 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8128 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8129 ;; for nntp:// and news://
8130 (setq address (match-string 3 address)))
8131 (if (not (string-match "[:/]" address))
8132 ;; This is just a simple group url.
8133 (gnus-group-read-ephemeral-group address gnus-select-method)
8136 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8138 (error "Can't parse %s" address)
8139 (gnus-group-read-ephemeral-group
8140 (match-string 4 address)
8141 `(nntp ,(match-string 1 address)
8142 (nntp-address ,(match-string 1 address))
8143 (nntp-port-number ,(if (match-end 3)
8144 (match-string 3 address)
8147 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8149 (defun gnus-url-parse-query-string (query &optional downcase)
8150 (let (retval pairs cur key val)
8151 (setq pairs (split-string query "&"))
8153 (setq cur (car pairs)
8155 (if (not (string-match "=" cur))
8157 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8158 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8160 (setq key (downcase key)))
8161 (setq cur (assoc key retval))
8163 (setcdr cur (cons val (cdr cur)))
8164 (setq retval (cons (list key val) retval)))))
8167 (defun gnus-url-mailto (url)
8168 ;; Send mail to someone
8169 (setq url (replace-regexp-in-string "\n" " " url))
8170 (when (string-match "mailto:/*\\(.*\\)" url)
8171 (setq url (substring url (match-beginning 1) nil)))
8172 (let (to args subject func)
8173 (setq args (gnus-url-parse-query-string
8174 (if (string-match "^\\?" url)
8176 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8177 (concat "to=" (match-string 1 url) "&"
8178 (match-string 2 url))
8179 (concat "to=" url))))
8180 subject (cdr-safe (assoc "subject" args)))
8183 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8186 (message-position-on-field (caar args)))
8187 (insert (gnus-replace-in-string
8188 (mapconcat 'identity (reverse (cdar args)) ", ")
8190 (setq args (cdr args)))
8193 (message-goto-subject))))
8195 (defun gnus-button-embedded-url (address)
8196 "Activate ADDRESS with `browse-url'."
8197 (browse-url (gnus-strip-whitespace address)))
8199 ;;; Next/prev buttons in the article buffer.
8201 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8202 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8204 (defvar gnus-prev-page-map
8205 (let ((map (make-sparse-keymap)))
8206 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8207 (define-key map "\r" 'gnus-button-prev-page)
8210 (defvar gnus-next-page-map
8211 (let ((map (make-sparse-keymap)))
8212 (define-key map gnus-mouse-2 'gnus-button-next-page)
8213 (define-key map "\r" 'gnus-button-next-page)
8216 (defun gnus-insert-prev-page-button ()
8218 (inhibit-read-only t))
8220 gnus-prev-page-line-format nil
8221 `(keymap ,gnus-prev-page-map
8223 gnus-callback gnus-article-button-prev-page
8224 article-type annotation))
8226 ;; Exclude a newline.
8229 (when gnus-article-button-face
8230 (gnus-overlay-put (gnus-make-overlay b e nil t)
8231 'face gnus-article-button-face))
8232 (widget-convert-button
8234 :action 'gnus-button-prev-page
8235 :button-keymap gnus-prev-page-map)))
8237 (defun gnus-button-next-page (&optional args more-args)
8238 "Go to the next page."
8240 (let ((win (selected-window)))
8241 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8242 (gnus-article-next-page)
8243 (select-window win)))
8245 (defun gnus-button-prev-page (&optional args more-args)
8246 "Go to the prev page."
8248 (let ((win (selected-window)))
8249 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8250 (gnus-article-prev-page)
8251 (select-window win)))
8253 (defun gnus-insert-next-page-button ()
8255 (inhibit-read-only t))
8256 (gnus-eval-format gnus-next-page-line-format nil
8257 `(keymap ,gnus-next-page-map
8259 gnus-callback gnus-article-button-next-page
8260 article-type annotation))
8262 ;; Exclude a newline.
8265 (when gnus-article-button-face
8266 (gnus-overlay-put (gnus-make-overlay b e nil t)
8267 'face gnus-article-button-face))
8268 (widget-convert-button
8270 :action 'gnus-button-next-page
8271 :button-keymap gnus-next-page-map)))
8273 (defun gnus-article-button-next-page (arg)
8274 "Go to the next page."
8276 (let ((win (selected-window)))
8277 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8278 (gnus-article-next-page)
8279 (select-window win)))
8281 (defun gnus-article-button-prev-page (arg)
8282 "Go to the prev page."
8284 (let ((win (selected-window)))
8285 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8286 (gnus-article-prev-page)
8287 (select-window win)))
8289 (defvar gnus-decode-header-methods
8290 '(mail-decode-encoded-word-region)
8291 "List of methods used to decode headers.
8293 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8294 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8295 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8296 whose names match REGEXP.
8299 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8300 mail-decode-encoded-word-region
8301 (\"chinese\" . rfc1843-decode-region))
8304 (defvar gnus-decode-header-methods-cache nil)
8306 (defun gnus-multi-decode-header (start end)
8307 "Apply the functions from `gnus-encoded-word-methods' that match."
8308 (unless (and gnus-decode-header-methods-cache
8309 (eq gnus-newsgroup-name
8310 (car gnus-decode-header-methods-cache)))
8311 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8312 (dolist (x gnus-decode-header-methods)
8314 (nconc gnus-decode-header-methods-cache (list x))
8315 (if (and gnus-newsgroup-name
8316 (string-match (car x) gnus-newsgroup-name))
8317 (nconc gnus-decode-header-methods-cache
8319 (let ((xlist gnus-decode-header-methods-cache))
8322 (narrow-to-region start end)
8324 (funcall (pop xlist) (point-min) (point-max))))))
8327 ;;; Treatment top-level handling.
8330 (defvar gnus-inhibit-article-treatments nil)
8332 (defun gnus-treat-article (gnus-treat-condition
8333 &optional part-number total-parts gnus-treat-type)
8334 (let ((gnus-treat-length (- (point-max) (point-min)))
8335 (alist gnus-treatment-function-alist)
8336 (article-goto-body-goes-to-point-min-p t)
8338 (or (not gnus-treat-type)
8340 (let ((list gnus-article-treat-types))
8342 (when (string-match (pop list) gnus-treat-type)
8343 (throw 'found t)))))))
8344 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8346 (gnus-run-hooks 'gnus-part-display-hook)
8347 (dolist (elem alist)
8350 (when (gnus-buffer-live-p gnus-summary-buffer)
8351 (set-buffer gnus-summary-buffer))
8352 (symbol-value (car elem))))
8353 (when (and (or (consp val)
8355 (or (not gnus-inhibit-article-treatments)
8356 (eq gnus-treat-condition 'head))
8357 (gnus-treat-predicate val)
8358 (or (not (get (car elem) 'highlight))
8361 (funcall (cadr elem)))))))
8363 ;; Dynamic variables.
8364 (defvar part-number)
8365 (defvar total-parts)
8366 (defvar gnus-treat-type)
8367 (defvar gnus-treat-condition)
8368 (defvar gnus-treat-length)
8370 (defun gnus-treat-predicate (val)
8374 (gnus-treat-condition
8375 (eq gnus-treat-condition val))
8377 (stringp (car val)))
8378 (apply 'gnus-or (mapcar `(lambda (s)
8379 (string-match s ,(or gnus-newsgroup-name "")))
8382 (let ((pred (pop val)))
8385 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8387 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8389 (not (gnus-treat-predicate (car val))))
8391 (equal (car val) gnus-treat-type))
8393 (error "%S is not a valid predicate" pred)))))
8401 (eq part-number total-parts))
8403 (< gnus-treat-length val))
8405 (error "%S is not a valid value" val))))
8407 (defun gnus-article-encrypt-body (protocol &optional n)
8408 "Encrypt the article body."
8411 (or gnus-article-encrypt-protocol
8412 (gnus-completing-read "Encrypt protocol"
8413 (mapcar 'car gnus-article-encrypt-protocol-alist)
8415 current-prefix-arg))
8416 ;; User might hit `K E' instead of `K e', so prompt once.
8417 (when (and gnus-article-encrypt-protocol
8419 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8420 (error "Encrypt aborted")))
8421 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8423 (error "Can't find the encrypt protocol %s" protocol))
8424 (if (member gnus-newsgroup-name '("nndraft:delayed"
8427 (error "Can't encrypt the article in group %s"
8428 gnus-newsgroup-name))
8429 (gnus-summary-iterate n
8430 (with-current-buffer gnus-summary-buffer
8431 (let ((mail-parse-charset gnus-newsgroup-charset)
8432 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8433 (summary-buffer gnus-summary-buffer)
8435 (gnus-set-global-variables)
8436 (when (gnus-group-read-only-p)
8437 (error "The current newsgroup does not support article encrypt"))
8438 (gnus-summary-show-article t)
8440 (or (mail-header-references gnus-current-headers) ""))
8441 (set-buffer gnus-article-buffer)
8442 (let* ((inhibit-read-only t)
8444 (mapcar (lambda (field)
8445 (and (save-restriction
8446 (message-narrow-to-head)
8447 (goto-char (point-min))
8448 (search-forward field nil t))
8450 (message-narrow-to-field)
8452 (delete-region (point-min) (point-max))
8454 '("Content-Type:" "Content-Transfer-Encoding:"
8455 "Content-Disposition:"))))
8456 (message-narrow-to-head)
8457 (message-remove-header "MIME-Version")
8458 (goto-char (point-max))
8459 (setq point (point))
8460 (insert (apply 'concat headers))
8462 (narrow-to-region point (point-max))
8463 (let ((message-options message-options))
8464 (message-options-set 'message-sender user-mail-address)
8465 (message-options-set 'message-recipients user-mail-address)
8466 (message-options-set 'message-sign-encrypt 'not)
8468 (goto-char (point-min))
8469 (insert "MIME-Version: 1.0\n")
8471 (gnus-summary-edit-article-done
8472 references nil summary-buffer t))
8473 (when gnus-keep-backlog
8474 (gnus-backlog-remove-article
8475 (car gnus-article-current) (cdr gnus-article-current)))
8476 (gnus-flush-original-article-buffer)
8477 (when gnus-use-cache
8478 (gnus-cache-update-article
8479 (car gnus-article-current) (cdr gnus-article-current))))))))
8481 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8482 "The following specs can be used:
8483 %t The security MIME type
8486 %D Details if button is pressed")
8488 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8489 "The following specs can be used:
8490 %t The security MIME type
8493 %D Details if button is pressed")
8495 (defvar gnus-mime-security-button-line-format-alist
8496 '((?t gnus-tmp-type ?s)
8497 (?i gnus-tmp-info ?s)
8498 (?d gnus-tmp-details ?s)
8499 (?D gnus-tmp-pressed-details ?s)))
8501 (defvar gnus-mime-security-button-commands
8502 '((gnus-article-press-button "\r" "Show Detail")
8506 (gnus-mime-security-save-part "o" "Save...")
8515 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8518 (defvar gnus-mime-security-button-map
8519 (let ((map (make-sparse-keymap)))
8520 (define-key map gnus-mouse-2 'gnus-article-push-button)
8521 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8522 (dolist (c gnus-mime-security-button-commands)
8523 (define-key map (cadr c) (car c)))
8527 gnus-mime-security-button-menu gnus-mime-security-button-map
8528 "Security button menu."
8532 (unless (eq (car c) 'undefined)
8533 (vector (caddr c) (car c) :active t)))
8534 gnus-mime-security-button-commands))))
8536 (defun gnus-mime-security-button-menu (event prefix)
8537 "Construct a context-sensitive menu of security commands."
8538 (interactive "e\nP")
8539 (save-window-excursion
8540 (let ((pos (event-start event)))
8541 (select-window (posn-window pos))
8542 (goto-char (posn-point pos))
8543 (gnus-article-check-buffer)
8544 (popup-menu gnus-mime-security-button-menu nil prefix))))
8546 (defvar gnus-mime-security-details-buffer nil)
8548 (defvar gnus-mime-security-button-pressed nil)
8550 (defvar gnus-mime-security-show-details-inline t
8551 "If non-nil, show details in the article buffer.")
8553 (defun gnus-mime-security-verify-or-decrypt (handle)
8554 (mm-remove-parts (cdr handle))
8555 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8556 point (inhibit-read-only t))
8558 (goto-char (car region)))
8559 (setq point (point))
8560 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8561 (let* ((mm-verify-option 'known)
8562 (mm-decrypt-option 'known)
8563 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8564 (unless (eq nparts (cdr handle))
8565 (mm-destroy-parts (cdr handle))
8566 (setcdr handle nparts))))
8567 (gnus-mime-display-security handle)
8569 (delete-region (point) (cdr region))
8570 (set-marker (car region) nil)
8571 (set-marker (cdr region) nil))
8574 (defun gnus-mime-security-show-details (handle)
8575 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8577 (gnus-message 5 "No details.")
8578 (if gnus-mime-security-show-details-inline
8579 (let ((gnus-mime-security-button-pressed
8580 (not (get-text-property (point) 'gnus-mime-details)))
8581 (gnus-mime-security-button-line-format
8582 (get-text-property (point) 'gnus-line-format))
8583 (inhibit-read-only t))
8585 (while (eq (get-text-property (point) 'gnus-line-format)
8586 gnus-mime-security-button-line-format)
8590 (narrow-to-region (point) (point))
8591 (gnus-insert-mime-security-button handle))
8592 (delete-region (point)
8593 (or (text-property-not-all
8596 gnus-mime-security-button-line-format)
8599 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8600 (with-current-buffer gnus-mime-security-details-buffer
8603 (setq gnus-mime-security-details-buffer
8604 (gnus-get-buffer-create "*MIME Security Details*")))
8605 (with-current-buffer gnus-mime-security-details-buffer
8607 (goto-char (point-min)))
8608 (pop-to-buffer gnus-mime-security-details-buffer)))))
8610 (defun gnus-mime-security-press-button (handle)
8612 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8613 (gnus-mime-security-show-details handle)
8614 (gnus-mime-security-verify-or-decrypt handle))))
8616 (defun gnus-insert-mime-security-button (handle &optional displayed)
8617 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8620 (or (nth 2 (assoc protocol mm-verify-function-alist))
8621 (nth 2 (assoc protocol mm-decrypt-function-alist))
8623 (if (equal (car handle) "multipart/signed")
8624 " Signed" " Encrypted")
8627 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8630 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8631 gnus-tmp-pressed-details
8633 (setq gnus-tmp-details
8634 (if gnus-tmp-details
8635 (concat "\n" gnus-tmp-details)
8637 (setq gnus-tmp-pressed-details
8638 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8643 gnus-mime-security-button-line-format
8644 gnus-mime-security-button-line-format-alist
8645 `(keymap ,gnus-mime-security-button-map
8646 gnus-callback gnus-mime-security-press-button
8647 gnus-line-format ,gnus-mime-security-button-line-format
8648 gnus-mime-details ,gnus-mime-security-button-pressed
8649 article-type annotation
8652 ;; Exclude a newline.
8655 (when gnus-article-button-face
8656 (gnus-overlay-put (gnus-make-overlay b e nil t)
8657 'face gnus-article-button-face))
8658 (widget-convert-button
8661 :action 'gnus-widget-press-button
8662 :button-keymap gnus-mime-security-button-map
8665 ;; Needed to properly clear the message due to a bug in
8666 ;; wid-edit (XEmacs only).
8667 (when (boundp 'help-echo-owns-message)
8668 (setq help-echo-owns-message t))
8670 "%S: show detail; %S: more options"
8671 (aref gnus-mouse-2 0)
8672 (aref gnus-down-mouse-3 0))))))
8674 (defun gnus-mime-display-security (handle)
8676 (narrow-to-region (point) (point))
8677 (unless (gnus-unbuttonized-mime-type-p (car handle))
8678 (gnus-insert-mime-security-button handle))
8679 (gnus-mime-display-part (cadr handle))
8682 (unless (gnus-unbuttonized-mime-type-p (car handle))
8683 (let ((gnus-mime-security-button-line-format
8684 gnus-mime-security-button-end-line-format))
8685 (gnus-insert-mime-security-button handle)))
8686 (mm-set-handle-multipart-parameter
8688 (cons (set-marker (make-marker) (point-min))
8689 (set-marker (make-marker) (point-max))))
8690 (goto-char (point-max))))
8692 (defun gnus-mime-security-run-function (function)
8693 "Run FUNCTION with the security part under point."
8694 (gnus-article-check-buffer)
8695 (let ((data (get-text-property (point) 'gnus-data))
8697 (when (and (stringp (car-safe data))
8698 (setq buffer (mm-handle-multipart-original-buffer data))
8699 (setq handle (cadr data)))
8700 (if (bufferp (mm-handle-buffer handle))
8702 (setq handle (cons buffer (copy-sequence (cdr handle))))
8703 (mm-handle-set-undisplayer handle nil))
8704 (setq handle (mm-make-handle
8706 (mm-handle-multipart-ctl-parameter handle 'protocol)
8707 nil nil nil nil nil nil)))
8708 (funcall function handle))))
8710 (defun gnus-mime-security-save-part ()
8711 "Save the security part under point."
8713 (gnus-mime-security-run-function 'mm-save-part))
8715 (defun gnus-mime-security-pipe-part ()
8716 "Pipe the security part under point to a process."
8718 (gnus-mime-security-run-function 'mm-pipe-part))
8724 (run-hooks 'gnus-art-load-hook)
8726 ;;; gnus-art.el ends here