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)
48 (autoload 'gnus-msg-mail "gnus-msg" nil t)
49 (autoload 'gnus-button-mailto "gnus-msg")
50 (autoload 'gnus-button-reply "gnus-msg" nil t)
51 (autoload 'parse-time-string "parse-time" nil nil)
52 (autoload 'ansi-color-apply-on-region "ansi-color")
53 (autoload 'mm-url-insert-file-contents-external "mm-url")
54 (autoload 'mm-extern-cache-contents "mm-extern")
56 (defgroup gnus-article nil
58 :link '(custom-manual "(gnus)Article Buffer")
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
77 (defgroup gnus-article-signature nil
79 :link '(custom-manual "(gnus)Article Signature")
82 (defgroup gnus-article-headers nil
84 :link '(custom-manual "(gnus)Hiding Headers")
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
97 (defgroup gnus-article-saving nil
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
120 (concat "^" header ":"))
121 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
122 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
123 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
124 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
125 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
126 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
127 "X-Attribution" "X-Originating-IP" "Delivered-To"
128 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
129 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
130 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
131 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
132 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
133 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
134 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
135 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
136 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
137 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
138 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
139 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
140 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
141 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
142 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
143 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
144 "List-[A-Za-z]+" "X-Listprocessor-Version"
145 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
146 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
147 "X-Received" "Content-length" "X-precedence"
148 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
149 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
150 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
151 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
152 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
153 "X-Content-length" "X-Posting-Agent" "Original-Received"
154 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
155 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
156 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
157 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
158 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
159 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
160 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
161 "Envelope-Sender" "Envelope-Recipients"))
162 "*All headers that start with this regexp will be hidden.
163 This variable can also be a list of regexps of headers to be ignored.
164 If `gnus-visible-headers' is non-nil, this variable will be ignored."
165 :type '(choice :custom-show nil
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 [%w] %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."
695 :group 'gnus-article-various)
697 (defcustom gnus-article-mode-hook nil
698 "*A hook for Gnus article mode."
700 :group 'gnus-article-various)
702 (when (featurep 'xemacs)
703 ;; Extracted from gnus-xmas-define in order to preserve user settings
704 (when (fboundp 'turn-off-scroll-in-place)
705 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
706 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
707 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
709 (defcustom gnus-article-menu-hook nil
710 "*Hook run after the creation of the article mode menu."
712 :group 'gnus-article-various)
714 (defcustom gnus-article-prepare-hook nil
715 "*A hook called after an article has been prepared in the article buffer."
717 :group 'gnus-article-various)
719 (defcustom gnus-copy-article-ignored-headers nil
720 "List of headers to be removed when copying an article.
721 Each element is a regular expression."
722 :version "23.1" ;; No Gnus
723 :type '(repeat regexp)
724 :group 'gnus-article-various)
726 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
727 "Gnus 5.10 (Emacs 22.1)")
730 '((t (:weight bold)))
731 "Face used for highlighting a button in the article buffer."
732 :group 'gnus-article-buttons)
734 (defcustom gnus-article-button-face 'gnus-button
735 "Face used for highlighting buttons in the article buffer.
737 An article button is a piece of text that you can activate by pressing
738 `RET' or `mouse-2' above it."
740 :group 'gnus-article-buttons)
742 (defcustom gnus-article-mouse-face 'highlight
743 "Face used for mouse highlighting in the article buffer.
745 Article buttons will be displayed in this face when the cursor is
748 :group 'gnus-article-buttons)
750 (defcustom gnus-signature-face 'gnus-signature
751 "Face used for highlighting a signature in the article buffer.
752 Obsolete; use the face `gnus-signature' for customizations instead."
754 :group 'gnus-article-highlight
755 :group 'gnus-article-signature)
757 (defface gnus-signature
760 "Face used for highlighting a signature in the article buffer."
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
763 ;; backward-compatibility alias
764 (put 'gnus-signature-face 'face-alias 'gnus-signature)
765 (put 'gnus-signature-face 'obsolete-face "22.1")
767 (defface gnus-header-from
770 (:foreground "PaleGreen1"))
773 (:foreground "red3"))
776 "Face used for displaying from headers."
777 :group 'gnus-article-headers
778 :group 'gnus-article-highlight)
779 ;; backward-compatibility alias
780 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
781 (put 'gnus-header-from-face 'obsolete-face "22.1")
783 (defface gnus-header-subject
786 (:foreground "SeaGreen1"))
789 (:foreground "red4"))
791 (:bold t :italic t)))
792 "Face used for displaying subject headers."
793 :group 'gnus-article-headers
794 :group 'gnus-article-highlight)
795 ;; backward-compatibility alias
796 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
797 (put 'gnus-header-subject-face 'obsolete-face "22.1")
799 (defface gnus-header-newsgroups
802 (:foreground "yellow" :italic t))
805 (:foreground "MidnightBlue" :italic t))
808 "Face used for displaying newsgroups headers.
809 In the default setup this face is only used for crossposted
811 :group 'gnus-article-headers
812 :group 'gnus-article-highlight)
813 ;; backward-compatibility alias
814 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
815 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
817 (defface gnus-header-name
820 (:foreground "SpringGreen2"))
823 (:foreground "maroon"))
826 "Face used for displaying header names."
827 :group 'gnus-article-headers
828 :group 'gnus-article-highlight)
829 ;; backward-compatibility alias
830 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
831 (put 'gnus-header-name-face 'obsolete-face "22.1")
833 (defface gnus-header-content
836 (:foreground "SpringGreen1" :italic t))
839 (:foreground "indianred4" :italic t))
841 (:italic t))) "Face used for displaying header content."
842 :group 'gnus-article-headers
843 :group 'gnus-article-highlight)
844 ;; backward-compatibility alias
845 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
846 (put 'gnus-header-content-face 'obsolete-face "22.1")
848 (defcustom gnus-header-face-alist
849 '(("From" nil gnus-header-from)
850 ("Subject" nil gnus-header-subject)
851 ("Newsgroups:.*," nil gnus-header-newsgroups)
852 ("" gnus-header-name gnus-header-content))
853 "*Controls highlighting of article headers.
855 An alist of the form (HEADER NAME CONTENT).
857 HEADER is a regular expression which should match the name of a
858 header and NAME and CONTENT are either face names or nil.
860 The name of each header field will be displayed using the face
861 specified by the first element in the list where HEADER matches
862 the header name and NAME is non-nil. Similarly, the content will
863 be displayed by the first non-nil matching CONTENT face."
864 :group 'gnus-article-headers
865 :group 'gnus-article-highlight
866 :type '(repeat (list (regexp :tag "Header")
868 (item :tag "skip" nil)
869 (face :value default))
870 (choice :tag "Content"
871 (item :tag "skip" nil)
872 (face :value default)))))
874 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
875 '((xface . (:face gnus-x-face)))
876 '((pbm . (:face gnus-x-face))
878 "Alist of image types and properties applied to Face and X-Face images.
881 ;; Specify the altitude of Face images in the From header.
882 \(setq gnus-face-properties-alist
883 '((pbm . (:face gnus-x-face :ascent 80))
884 (png . (:ascent 80))))
886 ;; Show Face images as pressed buttons.
887 \(setq gnus-face-properties-alist
888 '((pbm . (:face gnus-x-face :relief -2))
889 (png . (:relief -2))))
891 See the manual for the valid properties for various image types.
892 Currently, `pbm' is used for X-Face images and `png' is used for Face
893 images in Emacs. Only the `:face' property is effective on the `xface'
894 image type in XEmacs if it is built with the libcompface library."
895 :version "23.1" ;; No Gnus
896 :group 'gnus-article-headers
897 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
899 (defcustom gnus-article-decode-hook
900 '(article-decode-charset article-decode-encoded-words
901 article-decode-group-name article-decode-idna-rhs)
902 "*Hook run to decode charsets in articles."
903 :group 'gnus-article-headers
906 (defcustom gnus-display-mime-function 'gnus-display-mime
907 "Function to display MIME articles."
908 :group 'gnus-article-mime
911 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
912 "Function used to decode headers.")
914 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
915 "Function used to decode addresses.")
917 (defvar gnus-article-dumbquotes-map
937 "Table for MS-to-Latin1 translation.")
939 (defcustom gnus-ignored-mime-types nil
940 "List of MIME types that should be ignored by Gnus."
942 :group 'gnus-article-mime
943 :type '(repeat regexp))
945 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
946 "List of MIME types that should not be given buttons when rendered inline.
947 See also `gnus-buttonized-mime-types' which may override this variable.
948 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :group 'gnus-article-mime
951 :type '(repeat regexp))
953 (defcustom gnus-buttonized-mime-types nil
954 "List of MIME types that should be given buttons when rendered inline.
955 If set, this variable overrides `gnus-unbuttonized-mime-types'.
956 To see e.g. security buttons you could set this to
957 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
958 this list to display radio buttons that allow you to choose one of two
959 media types those mails include. See also `mm-discouraged-alternatives'.
960 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962 :group 'gnus-article-mime
963 :type '(repeat regexp))
965 (defcustom gnus-inhibit-mime-unbuttonizing nil
966 "If non-nil, all MIME parts get buttons.
967 When nil (the default value), then some MIME parts do not get buttons,
968 as described by the variables `gnus-buttonized-mime-types' and
969 `gnus-unbuttonized-mime-types'."
971 :group 'gnus-article-mime
974 (defcustom gnus-body-boundary-delimiter "_"
975 "String used to delimit header and body.
976 This variable is used by `gnus-article-treat-body-boundary' which can
977 be controlled by `gnus-treat-body-boundary'."
979 :group 'gnus-article-various
980 :type '(choice (item :tag "None" :value nil)
983 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "Defines the location of the faces database.
986 For information on obtaining this database of pretty pictures, please
987 see http://www.cs.indiana.edu/picons/ftp/index.html"
989 :type '(repeat directory)
990 :link '(url-link :tag "download"
991 "http://www.cs.indiana.edu/picons/ftp/index.html")
992 :link '(custom-manual "(gnus)Picons")
995 (defun gnus-picons-installed-p ()
996 "Say whether picons are installed on your machine."
997 (let ((installed nil))
998 (dolist (database gnus-picon-databases)
999 (when (file-exists-p database)
1000 (setq installed t)))
1003 (defcustom gnus-article-mime-part-function nil
1004 "Function called with a MIME handle as the argument.
1005 This is meant for people who want to do something automatic based
1006 on parts -- for instance, adding Vcard info to a database."
1007 :group 'gnus-article-mime
1008 :type '(choice (const nil)
1011 (defcustom gnus-mime-multipart-functions nil
1012 "An alist of MIME types to functions to display them."
1014 :group 'gnus-article-mime
1015 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1017 (defcustom gnus-article-date-headers '(combined-lapsed)
1018 "A list of Date header formats to display.
1019 Valid formats are `ut' (universal time), `local' (local time
1020 zone), `english' (readable English), `lapsed' (elapsed time),
1021 `combined-lapsed' (both the original date and the elapsed time),
1022 `original' (the original date header), `iso8601' (ISO8601
1023 format), and `user-defined' (a user-defined format defined by the
1024 `gnus-article-time-format' variable).
1026 You have as many date headers as you want in the article buffer.
1027 Some of these headers are updated automatically. See
1028 `gnus-article-update-date-headers' for details."
1030 :group 'gnus-article-headers
1032 (item :tag "Universal time (UT)" :value 'ut)
1033 (item :tag "Local time zone" :value 'local)
1034 (item :tag "Readable English" :value 'english)
1035 (item :tag "Elapsed time" :value 'lapsed)
1036 (item :tag "Original and elapsed time" :value 'combined-lapsed)
1037 (item :tag "Original date header" :value 'original)
1038 (item :tag "ISO8601 format" :value 'iso8601)
1039 (item :tag "User-defined" :value 'user-defined)))
1041 (defcustom gnus-article-update-date-headers 1
1042 "How often to update the date header.
1043 If nil, don't update it at all."
1045 :group 'gnus-article-headers
1047 (item :tag "Don't update" :value nil)
1050 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1051 "Function called with a MIME handle as the argument.
1052 This is meant for people who want to view first matched part.
1053 For `undisplayed-alternative' (default), the first undisplayed
1054 part or alternative part is used. For `undisplayed', the first
1055 undisplayed part is used. For a function, the first part which
1056 the function return t is used. For nil, the first part is
1059 :group 'gnus-article-mime
1061 (item :tag "first" :value nil)
1062 (item :tag "undisplayed" :value undisplayed)
1063 (item :tag "undisplayed or alternative"
1064 :value undisplayed-alternative)
1067 (defcustom gnus-mime-action-alist
1068 '(("save to file" . gnus-mime-save-part)
1069 ("save and strip" . gnus-mime-save-part-and-strip)
1070 ("replace with file" . gnus-mime-replace-part)
1071 ("delete part" . gnus-mime-delete-part)
1072 ("display as text" . gnus-mime-inline-part)
1073 ("view the part" . gnus-mime-view-part)
1074 ("pipe to command" . gnus-mime-pipe-part)
1075 ("toggle display" . gnus-article-press-button)
1076 ("toggle display" . gnus-article-view-part-as-charset)
1077 ("view as type" . gnus-mime-view-part-as-type)
1078 ("view internally" . gnus-mime-view-part-internally)
1079 ("view externally" . gnus-mime-view-part-externally))
1080 "An alist of actions that run on the MIME attachment."
1081 :group 'gnus-article-mime
1082 :type '(repeat (cons (string :tag "name")
1085 (defcustom gnus-auto-select-part 1
1086 "Advance to next MIME part when deleting or stripping parts.
1088 When 0, point will be placed on the same part as before. When
1089 positive (negative), move point forward (backwards) this many
1090 parts. When nil, redisplay article."
1091 :version "23.1" ;; No Gnus
1092 :group 'gnus-article-mime
1093 :type '(choice (const nil :tag "Redisplay article.")
1094 (const 1 :tag "Next part.")
1095 (const 0 :tag "Current part.")
1099 ;;; The treatment variables
1102 (defvar gnus-part-display-hook nil
1103 "Hook called on parts that are to receive treatment.")
1105 (defvar gnus-article-treat-custom
1106 '(choice (const :tag "Off" nil)
1108 (const :tag "Header" head)
1109 (const :tag "First" first)
1110 (const :tag "Last" last)
1111 (integer :tag "Less")
1112 (repeat :tag "Groups" regexp)
1113 (sexp :tag "Predicate")))
1115 (defvar gnus-article-treat-head-custom
1116 '(choice (const :tag "Off" nil)
1117 (const :tag "Header" head)))
1119 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1123 (defvar gnus-inhibit-treatment nil
1124 "Whether to inhibit treatment.")
1126 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1127 "Highlight the signature.
1128 Valid values are nil, t, `head', `first', `last', an integer or a
1129 predicate. See Info node `(gnus)Customizing Articles'."
1130 :group 'gnus-article-treat
1131 :link '(custom-manual "(gnus)Customizing Articles")
1132 :type gnus-article-treat-custom)
1133 (put 'gnus-treat-highlight-signature 'highlight t)
1135 (defcustom gnus-treat-buttonize 100000
1137 Valid values are nil, t, `head', `first', `last', an integer or a
1138 predicate. See Info node `(gnus)Customizing Articles'."
1139 :group 'gnus-article-treat
1140 :link '(custom-manual "(gnus)Customizing Articles")
1141 :type gnus-article-treat-custom)
1142 (put 'gnus-treat-buttonize 'highlight t)
1144 (defcustom gnus-treat-buttonize-head 'head
1145 "Add buttons to the head.
1146 Valid values are nil, t, `head', `first', `last', an integer or a
1147 predicate. See Info node `(gnus)Customizing Articles'."
1148 :group 'gnus-article-treat
1149 :link '(custom-manual "(gnus)Customizing Articles")
1150 :type gnus-article-treat-head-custom)
1151 (put 'gnus-treat-buttonize-head 'highlight t)
1153 (defcustom gnus-treat-date 'head
1154 "Display dates according to the `gnus-article-date-headers' variable.
1155 Valid values are nil, t, `head', `first', `last', an integer or a
1156 predicate. See Info node `(gnus)Customizing Articles'."
1158 :group 'gnus-article-treat
1159 :link '(custom-manual "(gnus)Customizing Articles")
1160 :type gnus-article-treat-head-custom)
1162 (defcustom gnus-treat-emphasize 50000
1164 Valid values are nil, t, `head', `first', `last', an integer or a
1165 predicate. See Info node `(gnus)Customizing Articles'."
1166 :group 'gnus-article-treat
1167 :link '(custom-manual "(gnus)Customizing Articles")
1168 :type gnus-article-treat-custom)
1169 (put 'gnus-treat-emphasize 'highlight t)
1171 (defcustom gnus-treat-strip-cr nil
1172 "Remove carriage returns.
1173 Valid values are nil, t, `head', `first', `last', an integer or a
1174 predicate. See Info node `(gnus)Customizing Articles'."
1176 :group 'gnus-article-treat
1177 :link '(custom-manual "(gnus)Customizing Articles")
1178 :type gnus-article-treat-custom)
1180 (defcustom gnus-treat-unsplit-urls nil
1181 "Remove newlines from within URLs.
1182 Valid values are nil, t, `head', `first', `last', an integer or a
1183 predicate. See Info node `(gnus)Customizing Articles'."
1185 :group 'gnus-article-treat
1186 :link '(custom-manual "(gnus)Customizing Articles")
1187 :type gnus-article-treat-custom)
1189 (defcustom gnus-treat-leading-whitespace nil
1190 "Remove leading whitespace in headers.
1191 Valid values are nil, t, `head', `first', `last', an integer or a
1192 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-custom)
1198 (defcustom gnus-treat-hide-headers 'head
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-head-custom)
1206 (defcustom gnus-treat-hide-boring-headers nil
1207 "Hide boring headers.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1210 :group 'gnus-article-treat
1211 :link '(custom-manual "(gnus)Customizing Articles")
1212 :type gnus-article-treat-head-custom)
1214 (defcustom gnus-treat-hide-signature nil
1215 "Hide the signature.
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1218 :group 'gnus-article-treat
1219 :link '(custom-manual "(gnus)Customizing Articles")
1220 :type gnus-article-treat-custom)
1222 (defcustom gnus-treat-fill-article nil
1224 Valid values are nil, t, `head', `first', `last', an integer or a
1225 predicate. See Info node `(gnus)Customizing Articles'."
1226 :group 'gnus-article-treat
1227 :link '(custom-manual "(gnus)Customizing Articles")
1228 :type gnus-article-treat-custom)
1230 (defcustom gnus-treat-hide-citation nil
1232 Valid values are nil, t, `head', `first', `last', an integer or a
1233 predicate. See Info node `(gnus)Customizing Articles'."
1234 :group 'gnus-article-treat
1235 :link '(custom-manual "(gnus)Customizing Articles")
1236 :type gnus-article-treat-custom)
1238 (defcustom gnus-treat-hide-citation-maybe nil
1240 Valid values are nil, t, `head', `first', `last', an integer or a
1241 predicate. See Info node `(gnus)Customizing Articles'."
1242 :group 'gnus-article-treat
1243 :link '(custom-manual "(gnus)Customizing Articles")
1244 :type gnus-article-treat-custom)
1246 (defcustom gnus-treat-strip-list-identifiers 'head
1247 "Strip list identifiers from `gnus-list-identifiers`.
1248 Valid values are nil, t, `head', `first', `last', an integer or a
1249 predicate. See Info node `(gnus)Customizing Articles'."
1251 :group 'gnus-article-treat
1252 :link '(custom-manual "(gnus)Customizing Articles")
1253 :type gnus-article-treat-custom)
1255 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1256 "Gnus 5.10 (Emacs 22.1)")
1258 (defcustom gnus-treat-strip-pem nil
1259 "Strip PEM signatures.
1260 Valid values are nil, t, `head', `first', `last', an integer or a
1261 predicate. See Info node `(gnus)Customizing Articles'."
1262 :group 'gnus-article-treat
1263 :link '(custom-manual "(gnus)Customizing Articles")
1264 :type gnus-article-treat-custom)
1266 (defcustom gnus-treat-strip-banner t
1267 "Strip banners from articles.
1268 The banner to be stripped is specified in the `banner' group parameter.
1269 Valid values are nil, t, `head', `first', `last', an integer or a
1270 predicate. See Info node `(gnus)Customizing Articles'."
1271 :group 'gnus-article-treat
1272 :link '(custom-manual "(gnus)Customizing Articles")
1273 :type gnus-article-treat-custom)
1275 (defcustom gnus-treat-highlight-headers 'head
1276 "Highlight the headers.
1277 Valid values are nil, t, `head', `first', `last', an integer or a
1278 predicate. See Info node `(gnus)Customizing Articles'."
1279 :group 'gnus-article-treat
1280 :link '(custom-manual "(gnus)Customizing Articles")
1281 :type gnus-article-treat-head-custom)
1282 (put 'gnus-treat-highlight-headers 'highlight t)
1284 (defcustom gnus-treat-highlight-citation t
1285 "Highlight cited text.
1286 Valid values are nil, t, `head', `first', `last', an integer or a
1287 predicate. See Info node `(gnus)Customizing Articles'."
1288 :group 'gnus-article-treat
1289 :link '(custom-manual "(gnus)Customizing Articles")
1290 :type gnus-article-treat-custom)
1291 (put 'gnus-treat-highlight-citation 'highlight t)
1293 (defcustom gnus-treat-strip-headers-in-body t
1294 "Strip the X-No-Archive header line from the beginning of the body.
1295 Valid values are nil, t, `head', `first', `last', an integer or a
1296 predicate. See Info node `(gnus)Customizing Articles'."
1298 :group 'gnus-article-treat
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :type gnus-article-treat-custom)
1302 (defcustom gnus-treat-strip-trailing-blank-lines nil
1303 "Strip trailing blank lines.
1304 Valid values are nil, t, `head', `first', `last', an integer or a
1305 predicate. See Info node `(gnus)Customizing Articles'.
1307 When set to t, it also strips trailing blanks in all MIME parts.
1308 Consider to use `last' instead."
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-custom)
1313 (defcustom gnus-treat-strip-leading-blank-lines nil
1314 "Strip leading blank lines.
1315 Valid values are nil, t, `head', `first', `last', an integer or a
1316 predicate. See Info node `(gnus)Customizing Articles'.
1318 When set to t, it also strips trailing blanks in all MIME parts."
1319 :group 'gnus-article-treat
1320 :link '(custom-manual "(gnus)Customizing Articles")
1321 :type gnus-article-treat-custom)
1323 (defcustom gnus-treat-strip-multiple-blank-lines nil
1324 "Strip multiple blank lines.
1325 Valid values are nil, t, `head', `first', `last', an integer or a
1326 predicate. See Info node `(gnus)Customizing Articles'."
1327 :group 'gnus-article-treat
1328 :link '(custom-manual "(gnus)Customizing Articles")
1329 :type gnus-article-treat-custom)
1331 (defcustom gnus-treat-unfold-headers 'head
1332 "Unfold folded header lines.
1333 Valid values are nil, t, `head', `first', `last', an integer or a
1334 predicate. See Info node `(gnus)Customizing Articles'."
1336 :group 'gnus-article-treat
1337 :link '(custom-manual "(gnus)Customizing Articles")
1338 :type gnus-article-treat-custom)
1340 (defcustom gnus-article-unfold-long-headers nil
1341 "If non-nil, allow unfolding headers even if the header is long.
1342 If it is a regexp, only long headers matching this regexp are unfolded.
1343 If it is t, all long headers are unfolded.
1345 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1346 :version "23.1" ;; No Gnus
1347 :group 'gnus-article-treat
1348 :type '(choice (const nil)
1349 (const :tag "all" t)
1352 (defcustom gnus-treat-fold-headers nil
1354 Valid values are nil, t, `head', `first', `last', an integer or a
1355 predicate. See Info node `(gnus)Customizing Articles'."
1357 :group 'gnus-article-treat
1358 :link '(custom-manual "(gnus)Customizing Articles")
1359 :type gnus-article-treat-custom)
1361 (defcustom gnus-treat-fold-newsgroups 'head
1362 "Fold the Newsgroups and Followup-To headers.
1363 Valid values are nil, t, `head', `first', `last', an integer or a
1364 predicate. See Info node `(gnus)Customizing Articles'."
1366 :group 'gnus-article-treat
1367 :link '(custom-manual "(gnus)Customizing Articles")
1368 :type gnus-article-treat-custom)
1370 (defcustom gnus-treat-overstrike t
1371 "Treat overstrike highlighting.
1372 Valid values are nil, t, `head', `first', `last', an integer or a
1373 predicate. See Info node `(gnus)Customizing Articles'."
1374 :group 'gnus-article-treat
1375 :link '(custom-manual "(gnus)Customizing Articles")
1376 :type gnus-article-treat-custom)
1377 (put 'gnus-treat-overstrike 'highlight t)
1379 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1380 "Treat ANSI SGR control sequences.
1381 Valid values are nil, t, `head', `first', `last', an integer or a
1382 predicate. See Info node `(gnus)Customizing Articles'."
1383 :group 'gnus-article-treat
1384 :link '(custom-manual "(gnus)Customizing Articles")
1385 :type gnus-article-treat-custom)
1387 (make-obsolete-variable 'gnus-treat-display-xface
1388 'gnus-treat-display-x-face "Emacs 22.1")
1390 (defcustom gnus-treat-display-x-face
1391 (and (not noninteractive)
1392 (gnus-image-type-available-p 'xbm)
1393 (if (featurep 'xemacs)
1396 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1397 (executable-find "icontopbm"))
1398 ;; shell-command-to-string may signal an error, e.g. if
1399 ;; shell-file-name is not found.
1402 "Display X-Face headers.
1403 Valid values are nil and `head'.
1404 See Info node `(gnus)Customizing Articles' and Info node
1405 `(gnus)X-Face' for details."
1406 :group 'gnus-article-treat
1408 :link '(custom-manual "(gnus)Customizing Articles")
1409 :link '(custom-manual "(gnus)X-Face")
1410 :type gnus-article-treat-head-custom
1411 :set (lambda (symbol value)
1414 (cond ((or (boundp symbol) (get symbol 'saved-value))
1416 ((boundp 'gnus-treat-display-xface)
1418 ** gnus-treat-display-xface is an obsolete variable;\
1419 use gnus-treat-display-x-face instead")
1420 (default-value 'gnus-treat-display-xface))
1421 ((get 'gnus-treat-display-xface 'saved-value)
1423 ** gnus-treat-display-xface is an obsolete variable;\
1424 use gnus-treat-display-x-face instead")
1425 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1428 (put 'gnus-treat-display-x-face 'highlight t)
1430 (defcustom gnus-treat-display-face
1431 (and (not noninteractive)
1432 (gnus-image-type-available-p 'png)
1434 "Display Face headers.
1435 Valid values are nil, t, `head', `first', `last', an integer or a
1436 predicate. See Info node `(gnus)Customizing Articles' and Info
1437 node `(gnus)Face' for details."
1438 :group 'gnus-article-treat
1440 :link '(custom-manual "(gnus)Customizing Articles")
1441 :link '(custom-manual "(gnus)X-Face")
1442 :type gnus-article-treat-head-custom)
1443 (put 'gnus-treat-display-face 'highlight t)
1445 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1447 Valid values are nil, t, `head', `first', `last', an integer or a
1448 predicate. See Info node `(gnus)Customizing Articles' and Info
1449 node `(gnus)Smileys' for details."
1450 :group 'gnus-article-treat
1452 :link '(custom-manual "(gnus)Customizing Articles")
1453 :link '(custom-manual "(gnus)Smileys")
1454 :type gnus-article-treat-custom)
1455 (put 'gnus-treat-display-smileys 'highlight t)
1457 (defcustom gnus-treat-from-picon
1458 (if (and (gnus-image-type-available-p 'xpm)
1459 (gnus-picons-installed-p))
1461 "Display picons in the From header.
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate. See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Picons' for details."
1466 :group 'gnus-article-treat
1468 :link '(custom-manual "(gnus)Customizing Articles")
1469 :link '(custom-manual "(gnus)Picons")
1470 :type gnus-article-treat-head-custom)
1471 (put 'gnus-treat-from-picon 'highlight t)
1473 (defcustom gnus-treat-mail-picon
1474 (if (and (gnus-image-type-available-p 'xpm)
1475 (gnus-picons-installed-p))
1477 "Display picons in To and Cc headers.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Picons' for details."
1482 :group 'gnus-article-treat
1484 :link '(custom-manual "(gnus)Customizing Articles")
1485 :link '(custom-manual "(gnus)Picons")
1486 :type gnus-article-treat-head-custom)
1487 (put 'gnus-treat-mail-picon 'highlight t)
1489 (defcustom gnus-treat-newsgroups-picon
1490 (if (and (gnus-image-type-available-p 'xpm)
1491 (gnus-picons-installed-p))
1493 "Display picons in the Newsgroups and Followup-To headers.
1494 Valid values are nil, t, `head', `first', `last', an integer or a
1495 predicate. See Info node `(gnus)Customizing Articles' and Info
1496 node `(gnus)Picons' for details."
1498 :group 'gnus-article-treat
1500 :link '(custom-manual "(gnus)Customizing Articles")
1501 :link '(custom-manual "(gnus)Picons")
1502 :type gnus-article-treat-head-custom)
1503 (put 'gnus-treat-newsgroups-picon 'highlight t)
1505 (defcustom gnus-treat-from-gravatar nil
1506 "Display gravatars in the From header.
1507 Valid values are nil, t, `head', `first', `last', an integer or a
1508 predicate. See Info node `(gnus)Customizing Articles' and Info
1509 node `(gnus)Gravatars' for details."
1511 :group 'gnus-article-treat
1512 :group 'gnus-gravatar
1513 :link '(custom-manual "(gnus)Customizing Articles")
1514 :link '(custom-manual "(gnus)Gravatars")
1515 :type gnus-article-treat-head-custom)
1516 (put 'gnus-treat-from-gravatar 'highlight t)
1518 (defcustom gnus-treat-mail-gravatar nil
1519 "Display gravatars in To and Cc headers.
1520 Valid values are nil, t, `head', `first', `last', an integer or a
1521 predicate. See Info node `(gnus)Customizing Articles' and Info
1522 node `(gnus)Gravatars' for details."
1524 :group 'gnus-article-treat
1525 :group 'gnus-gravatar
1526 :link '(custom-manual "(gnus)Customizing Articles")
1527 :link '(custom-manual "(gnus)Gravatars")
1528 :type gnus-article-treat-head-custom)
1529 (put 'gnus-treat-mail-gravatar 'highlight t)
1531 (defcustom gnus-treat-body-boundary
1532 (if (or gnus-treat-newsgroups-picon
1533 gnus-treat-mail-picon
1534 gnus-treat-from-picon
1535 gnus-treat-from-gravatar
1536 gnus-treat-mail-gravatar)
1537 ;; If there's much decoration, the user might prefer a boundery.
1540 "Draw a boundary at the end of the headers.
1541 Valid values are nil and `head'.
1542 See Info node `(gnus)Customizing Articles' for details."
1544 :group 'gnus-article-treat
1545 :link '(custom-manual "(gnus)Customizing Articles")
1546 :type gnus-article-treat-head-custom)
1548 (defcustom gnus-treat-capitalize-sentences nil
1549 "Capitalize sentence-starting words.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate. See Info node `(gnus)Customizing Articles'."
1553 :group 'gnus-article-treat
1554 :link '(custom-manual "(gnus)Customizing Articles")
1555 :type gnus-article-treat-custom)
1557 (defcustom gnus-treat-wash-html nil
1559 Valid values are nil, t, `head', `first', `last', an integer or a
1560 predicate. See Info node `(gnus)Customizing Articles'."
1562 :group 'gnus-article-treat
1563 :link '(custom-manual "(gnus)Customizing Articles")
1564 :type gnus-article-treat-custom)
1566 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1568 Valid values are nil, t, `head', `first', `last', an integer or a
1569 predicate. See Info node `(gnus)Customizing Articles'."
1571 :group 'gnus-article-treat
1572 :link '(custom-manual "(gnus)Customizing Articles")
1573 :type gnus-article-treat-custom)
1575 (defcustom gnus-treat-x-pgp-sig nil
1577 To automatically treat X-PGP-Sig, set it to head.
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 :group 'mime-security
1583 :link '(custom-manual "(gnus)Customizing Articles")
1584 :type gnus-article-treat-custom)
1586 (defvar gnus-article-encrypt-protocol-alist
1587 '(("PGP" . mml2015-self-encrypt)))
1589 ;; Set to nil if more than one protocol added to
1590 ;; gnus-article-encrypt-protocol-alist.
1591 (defcustom gnus-article-encrypt-protocol "PGP"
1592 "The protocol used for encrypt articles.
1593 It is a string, such as \"PGP\". If nil, ask user."
1596 :group 'mime-security)
1598 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1599 (mm-coding-system-p 'utf-8)
1600 (executable-find idna-program))
1601 "Whether IDNA decoding of headers is used when viewing messages.
1602 This requires GNU Libidn, and by default only enabled if it is found."
1604 :group 'gnus-article-headers
1607 (defcustom gnus-article-over-scroll nil
1608 "If non-nil, allow scrolling the article buffer even when there no more text."
1610 :group 'gnus-article
1613 (defcustom gnus-inhibit-images nil
1614 "Non-nil means inhibit displaying of images inline in the article body."
1616 :group 'gnus-article
1619 (defcustom gnus-blocked-images 'gnus-block-private-groups
1620 "Images that have URLs matching this regexp will be blocked.
1621 This can also be a function to be evaluated. If so, it will be
1622 called with the group name as the parameter, and should return a
1628 ;;; Internal variables
1630 (defvar gnus-english-month-names
1631 '("January" "February" "March" "April" "May" "June" "July" "August"
1632 "September" "October" "November" "December"))
1634 (defvar article-goto-body-goes-to-point-min-p nil)
1635 (defvar gnus-article-wash-types nil)
1636 (defvar gnus-article-emphasis-alist nil)
1637 (defvar gnus-article-image-alist nil)
1639 (defvar gnus-article-mime-handle-alist-1 nil)
1640 (defvar gnus-treatment-function-alist
1641 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1642 (gnus-treat-strip-banner gnus-article-strip-banner)
1643 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1644 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1645 (gnus-treat-buttonize gnus-article-add-buttons)
1646 (gnus-treat-fill-article gnus-article-fill-cited-article)
1647 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1648 (gnus-treat-strip-cr gnus-article-remove-cr)
1649 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1650 (gnus-treat-display-x-face gnus-article-display-x-face)
1651 (gnus-treat-display-face gnus-article-display-face)
1652 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1653 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1654 (gnus-treat-hide-signature gnus-article-hide-signature)
1655 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1656 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1657 (gnus-treat-from-picon gnus-treat-from-picon)
1658 (gnus-treat-mail-picon gnus-treat-mail-picon)
1659 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1660 (gnus-treat-strip-pem gnus-article-hide-pem)
1661 (gnus-treat-date gnus-article-treat-date)
1662 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1663 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1664 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1665 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1666 (gnus-treat-strip-trailing-blank-lines
1667 gnus-article-remove-trailing-blank-lines)
1668 (gnus-treat-strip-leading-blank-lines
1669 gnus-article-strip-leading-blank-lines)
1670 (gnus-treat-strip-multiple-blank-lines
1671 gnus-article-strip-multiple-blank-lines)
1672 (gnus-treat-overstrike gnus-article-treat-overstrike)
1673 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1674 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1675 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1676 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1677 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1678 (gnus-treat-display-smileys gnus-treat-smiley)
1679 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1680 (gnus-treat-wash-html gnus-article-wash-html)
1681 (gnus-treat-emphasize gnus-article-emphasize)
1682 (gnus-treat-hide-citation gnus-article-hide-citation)
1683 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1684 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1685 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1687 (defvar gnus-article-mime-handle-alist nil)
1688 (defvar article-lapsed-timer nil)
1689 (defvar gnus-article-current-summary nil)
1691 (defvar gnus-article-mode-syntax-table
1692 (let ((table (copy-syntax-table text-mode-syntax-table)))
1693 ;; This causes the citation match run O(2^n).
1694 ;; (modify-syntax-entry ?- "w" table)
1695 (modify-syntax-entry ?> ")<" table)
1696 (modify-syntax-entry ?< "(>" table)
1697 ;; make M-. in article buffers work for `foo' strings
1698 (modify-syntax-entry ?' " " table)
1699 (modify-syntax-entry ?` " " table)
1701 "Syntax table used in article mode buffers.
1702 Initialized from `text-mode-syntax-table.")
1704 (defvar gnus-save-article-buffer nil)
1706 (defvar gnus-number-of-articles-to-be-saved nil)
1708 (defvar gnus-inhibit-hiding nil)
1710 (defvar gnus-article-edit-mode nil)
1712 ;;; Macros for dealing with the article buffer.
1714 (defmacro gnus-with-article-headers (&rest forms)
1715 `(with-current-buffer gnus-article-buffer
1717 (let ((inhibit-read-only t)
1718 (inhibit-point-motion-hooks t)
1719 (case-fold-search t))
1720 (article-narrow-to-head)
1723 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1724 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1726 (defmacro gnus-with-article-buffer (&rest forms)
1727 `(with-current-buffer gnus-article-buffer
1728 (let ((inhibit-read-only t))
1731 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1732 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1734 (defun gnus-article-goto-header (header)
1735 "Go to HEADER, which is a regular expression."
1736 (re-search-forward (concat "^\\(" header "\\):") nil t))
1738 (defsubst gnus-article-hide-text (b e props)
1739 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1740 (gnus-add-text-properties-when 'article-type nil b e props)
1741 (when (memq 'intangible props)
1743 (max (1- b) (point-min))
1744 b 'intangible (cddr (memq 'intangible props)))))
1746 (defsubst gnus-article-unhide-text (b e)
1747 "Remove hidden text properties from region between B and E."
1748 (remove-text-properties b e gnus-hidden-properties)
1749 (when (memq 'intangible gnus-hidden-properties)
1750 (put-text-property (max (1- b) (point-min))
1751 b 'intangible nil)))
1753 (defun gnus-article-hide-text-type (b e type)
1754 "Hide text of TYPE between B and E."
1755 (gnus-add-wash-type type)
1756 (gnus-article-hide-text
1757 b e (cons 'article-type (cons type gnus-hidden-properties))))
1759 (defun gnus-article-unhide-text-type (b e type)
1760 "Unhide text of TYPE between B and E."
1761 (gnus-delete-wash-type type)
1762 (remove-text-properties
1763 b e (cons 'article-type (cons type gnus-hidden-properties)))
1764 (when (memq 'intangible gnus-hidden-properties)
1765 (put-text-property (max (1- b) (point-min))
1766 b 'intangible nil)))
1768 (defun gnus-article-hide-text-of-type (type)
1769 "Hide text of TYPE in the current buffer."
1771 (let ((b (point-min))
1773 (while (setq b (text-property-any b e 'article-type type))
1774 (add-text-properties b (incf b) gnus-hidden-properties)))))
1776 (defun gnus-article-delete-text-of-type (type)
1777 "Delete text of TYPE in the current buffer."
1779 (let ((b (point-min)))
1780 (if (eq type 'multipart)
1781 ;; Remove MIME buttons associated with multipart/alternative parts.
1784 (while (if (get-text-property (point) 'gnus-part)
1786 (when (setq b (next-single-property-change (point)
1791 (skip-chars-forward "\n")
1792 (when (eq (get-text-property b 'article-type) 'multipart)
1793 (delete-region b (point)))))
1794 (while (setq b (text-property-any b (point-max) 'article-type type))
1796 b (or (text-property-not-all b (point-max) 'article-type type)
1799 (defun gnus-article-delete-invisible-text ()
1800 "Delete all invisible text in the current buffer."
1802 (let ((b (point-min)))
1803 (while (setq b (text-property-any b (point-max) 'invisible t))
1805 b (or (text-property-not-all b (point-max) 'invisible t)
1808 (defun gnus-article-text-type-exists-p (type)
1809 "Say whether any text of type TYPE exists in the buffer."
1810 (text-property-any (point-min) (point-max) 'article-type type))
1812 (defsubst gnus-article-header-rank ()
1813 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1814 (let ((list gnus-sorted-header-list)
1817 (if (looking-at (car list))
1819 (setq list (cdr list))
1823 (defun article-hide-headers (&optional arg delete)
1824 "Hide unwanted headers and possibly sort them as well."
1826 ;; This function might be inhibited.
1827 (unless gnus-inhibit-hiding
1828 (let ((inhibit-read-only t)
1829 (case-fold-search t)
1830 (max (1+ (length gnus-sorted-header-list)))
1831 (inhibit-point-motion-hooks t)
1832 (cur (current-buffer))
1833 ignored visible beg)
1835 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1836 ;; group parameters, so we should go to the summary buffer.
1839 (progn (set-buffer gnus-summary-buffer) t)
1841 (setq ignored (when (not gnus-visible-headers)
1842 (cond ((stringp gnus-ignored-headers)
1843 gnus-ignored-headers)
1844 ((listp gnus-ignored-headers)
1845 (mapconcat 'identity
1846 gnus-ignored-headers
1848 visible (cond ((stringp gnus-visible-headers)
1849 gnus-visible-headers)
1850 ((and gnus-visible-headers
1851 (listp gnus-visible-headers))
1852 (mapconcat 'identity
1853 gnus-visible-headers
1857 ;; First we narrow to just the headers.
1858 (article-narrow-to-head)
1859 ;; Hide any "From " lines at the beginning of (mail) articles.
1860 (while (looking-at "From ")
1863 (delete-region (point-min) (point)))
1864 ;; Then treat the rest of the header lines.
1865 ;; Then we use the two regular expressions
1866 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1867 ;; select which header lines is to remain visible in the
1869 (while (re-search-forward "^[^ \t:]*:" nil t)
1871 ;; Mark the rank of the header.
1873 (point) (1+ (point)) 'message-rank
1874 (if (or (and visible (looking-at visible))
1876 (not (looking-at ignored))))
1877 (gnus-article-header-rank)
1880 (message-sort-headers-1)
1881 (when (setq beg (text-property-any
1882 (point-min) (point-max) 'message-rank (+ 2 max)))
1883 ;; We delete the unwanted headers.
1884 (gnus-add-wash-type 'headers)
1885 (add-text-properties (point-min) (+ 5 (point-min))
1886 '(article-type headers dummy-invisible t))
1887 (delete-region beg (point-max))))))))
1889 (defun article-hide-boring-headers (&optional arg)
1890 "Toggle hiding of headers that aren't very interesting.
1891 If given a negative prefix, always show; if given a positive prefix,
1893 (interactive (gnus-article-hidden-arg))
1894 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1895 (not gnus-show-all-headers))
1898 (let ((inhibit-read-only t)
1899 (inhibit-point-motion-hooks t))
1900 (article-narrow-to-head)
1901 (dolist (elem gnus-boring-article-headers)
1902 (goto-char (point-min))
1904 ;; Hide empty headers.
1906 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1908 (gnus-article-hide-text-type
1912 (if (re-search-forward "^[^ \t]" nil t)
1916 ;; Hide boring Newsgroups header.
1917 ((eq elem 'newsgroups)
1918 (when (gnus-string-equal
1919 (gnus-fetch-field "newsgroups")
1920 (gnus-group-real-name
1921 (if (boundp 'gnus-newsgroup-name)
1924 (gnus-article-hide-header "newsgroups")))
1925 ((eq elem 'to-address)
1926 (let ((to (message-fetch-field "to"))
1928 (gnus-parameter-to-address
1929 (if (boundp 'gnus-newsgroup-name)
1930 gnus-newsgroup-name ""))))
1931 (when (and to to-address
1934 ;; only one address in To
1935 (nth 1 (mail-extract-address-components to))
1937 (gnus-article-hide-header "to"))))
1939 (let ((to (message-fetch-field "to"))
1941 (gnus-parameter-to-list
1942 (if (boundp 'gnus-newsgroup-name)
1943 gnus-newsgroup-name ""))))
1944 (when (and to to-list
1947 ;; only one address in To
1948 (nth 1 (mail-extract-address-components to))
1950 (gnus-article-hide-header "to"))))
1952 (let ((cc (message-fetch-field "cc"))
1954 (gnus-parameter-to-list
1955 (if (boundp 'gnus-newsgroup-name)
1956 gnus-newsgroup-name ""))))
1957 (when (and cc to-list
1960 ;; only one address in CC
1961 (nth 1 (mail-extract-address-components cc))
1963 (gnus-article-hide-header "cc"))))
1964 ((eq elem 'followup-to)
1965 (when (gnus-string-equal
1966 (message-fetch-field "followup-to")
1967 (message-fetch-field "newsgroups"))
1968 (gnus-article-hide-header "followup-to")))
1969 ((eq elem 'reply-to)
1970 (if (gnus-group-find-parameter
1971 gnus-newsgroup-name 'broken-reply-to)
1972 (gnus-article-hide-header "reply-to")
1973 (let ((from (message-fetch-field "from"))
1974 (reply-to (message-fetch-field "reply-to")))
1981 (lambda (x) (downcase (cadr x)))
1982 (mail-extract-address-components from t))
1985 (lambda (x) (downcase (cadr x)))
1986 (mail-extract-address-components reply-to t))
1988 (gnus-article-hide-header "reply-to")))))
1990 (let ((date (with-current-buffer gnus-original-article-buffer
1991 ;; If date in `gnus-article-buffer' is localized
1992 ;; (`gnus-treat-date-user-defined'),
1993 ;; `days-between' might fail.
1994 (message-fetch-field "date"))))
1996 (< (days-between (current-time-string) date)
1998 (gnus-article-hide-header "date"))))
2000 (let ((to (message-fetch-field "to"))
2001 (cc (message-fetch-field "cc")))
2002 (when (> (length to) 1024)
2003 (gnus-article-hide-header "to"))
2004 (when (> (length cc) 1024)
2005 (gnus-article-hide-header "cc"))))
2009 (goto-char (point-min))
2010 (while (re-search-forward "^to:" nil t)
2011 (setq to-count (1+ to-count)))
2012 (when (> to-count 1)
2013 (while (> to-count 0)
2014 (goto-char (point-min))
2016 (re-search-forward "^to:" nil nil to-count)
2018 (narrow-to-region (point) (point-max))
2019 (gnus-article-hide-header "to"))
2020 (setq to-count (1- to-count))))
2021 (goto-char (point-min))
2022 (while (re-search-forward "^cc:" nil t)
2023 (setq cc-count (1+ cc-count)))
2024 (when (> cc-count 1)
2025 (while (> cc-count 0)
2026 (goto-char (point-min))
2028 (re-search-forward "^cc:" nil nil cc-count)
2030 (narrow-to-region (point) (point-max))
2031 (gnus-article-hide-header "cc"))
2032 (setq cc-count (1- cc-count)))))))))))))
2034 (defun gnus-article-hide-header (header)
2036 (goto-char (point-min))
2037 (when (re-search-forward (concat "^" header ":") nil t)
2038 (gnus-article-hide-text-type
2042 (if (re-search-forward "^[^ \t]" nil t)
2047 (defvar gnus-article-normalized-header-length 40
2048 "Length of normalized headers.")
2050 (defun article-normalize-headers ()
2051 "Make all header lines 40 characters long."
2053 (let ((inhibit-read-only t)
2057 (article-narrow-to-head)
2060 ((< (setq column (- (point-at-eol) (point)))
2061 gnus-article-normalized-header-length)
2063 (insert (make-string
2064 (- gnus-article-normalized-header-length column)
2066 ((> column gnus-article-normalized-header-length)
2067 (gnus-put-text-property
2069 (forward-char gnus-article-normalized-header-length)
2076 (forward-line 1))))))
2078 (defun article-treat-dumbquotes ()
2079 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2080 Note that this function guesses whether a character is a sm*rtq**t* or
2081 not, so it should only be used interactively.
2083 Sm*rtq**t*s are M****s***'s unilateral extension to the
2084 iso-8859-1 character map in an attempt to provide more quoting
2085 characters. If you see something like \\222 or \\264 where
2086 you're expecting some kind of apostrophe or quotation mark, then
2089 (article-translate-strings gnus-article-dumbquotes-map))
2091 (defvar org-entities)
2093 (defun article-treat-non-ascii ()
2094 "Translate many Unicode characters into their ASCII equivalents."
2096 (require 'org-entities)
2097 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2098 (dolist (elem org-entities)
2099 (when (and (listp elem)
2100 (= (length (nth 6 elem)) 1))
2101 (if (featurep 'xemacs)
2102 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2103 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2105 (when (article-goto-body)
2106 (let ((inhibit-read-only t)
2109 (if (not (setq replace (if (featurep 'xemacs)
2110 (get-char-table (following-char) table)
2111 (aref table (following-char)))))
2114 (setq props (text-properties-at (point)))
2116 (add-text-properties (point) (progn (insert replace) (point))
2118 (insert replace)))))))))
2120 (defun article-translate-characters (from to)
2121 "Translate all characters in the body of the article according to FROM and TO.
2122 FROM is a string of characters to translate from; to is a string of
2123 characters to translate to."
2125 (when (article-goto-body)
2126 (let ((inhibit-read-only t)
2127 (x (make-string 225 ?x))
2129 (while (< (incf i) (length x))
2132 (while (< i (length from))
2133 (aset x (aref from i) (aref to i))
2135 (translate-region (point) (point-max) x)))))
2137 (defun article-translate-strings (map)
2138 "Translate all string in the body of the article according to MAP.
2139 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2141 (when (article-goto-body)
2142 (let ((inhibit-read-only t))
2144 (let ((from (car elem))
2148 (while (search-forward from nil t)
2151 (if (eq (following-char) from)
2155 (forward-char 1)))))))))))
2157 (defun article-treat-overstrike ()
2158 "Translate overstrikes into bold text."
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (while (search-forward "\b" nil t)
2164 (let ((next (char-after))
2165 (previous (char-after (- (point) 2))))
2166 ;; We do the boldification/underlining by hiding the
2167 ;; overstrikes and putting the proper text property
2171 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2172 (put-text-property (point) (1+ (point)) 'face 'bold))
2174 (gnus-article-hide-text-type
2175 (1- (point)) (1+ (point)) 'overstrike)
2177 (- (point) 2) (1- (point)) 'face 'underline))
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2181 (point) (1+ (point)) 'face 'underline)))))))))
2183 (defun article-treat-ansi-sequences ()
2184 "Translate ANSI SGR control sequences into overlays or extents."
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (ansi-color-apply-on-region (point) (point-max))))))
2191 (defun gnus-article-treat-unfold-headers ()
2192 "Unfold folded message headers.
2193 Only the headers that fit into the current window width will be
2196 (gnus-with-article-headers
2200 (mail-header-narrow-to-field)
2201 (let* ((header (buffer-string))
2203 (or (equal gnus-article-unfold-long-headers t)
2204 (and (stringp gnus-article-unfold-long-headers)
2205 (string-match gnus-article-unfold-long-headers header)))))
2208 (goto-char (point-min))
2209 (while (re-search-forward "\n[\t ]" nil t)
2210 (replace-match " " t t)))
2211 (setq length (- (point-max) (point-min) 1))
2212 (when (or unfoldable
2213 (< length (window-width)))
2214 (while (re-search-forward "\n[\t ]" nil t)
2215 (replace-match " " t t))))
2216 (goto-char (point-max)))))))
2218 (defun gnus-article-treat-fold-headers ()
2219 "Fold message headers."
2221 (gnus-with-article-headers
2224 (mail-header-narrow-to-field)
2225 (mail-header-fold-field)
2226 (goto-char (point-max))))))
2228 (defun gnus-treat-smiley ()
2229 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2231 (gnus-with-article-buffer
2232 (if (memq 'smiley gnus-article-wash-types)
2233 (gnus-delete-images 'smiley)
2235 (let ((images (smiley-region (point) (point-max))))
2237 (gnus-add-wash-type 'smiley)
2238 (dolist (image images)
2239 (gnus-add-image 'smiley image)))))))
2241 (defun gnus-article-remove-images ()
2242 "Remove all images from the article buffer."
2244 (gnus-with-article-buffer
2247 (dolist (elem gnus-article-image-alist)
2248 (gnus-delete-images (car elem))))))
2250 (defun gnus-article-show-images ()
2251 "Show any images that are in the HTML-rendered article buffer.
2252 This only works if the article in question is HTML."
2254 (gnus-with-article-buffer
2257 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2259 (destructuring-bind (start end function) region
2260 (funcall function (get-text-property start 'image-url)
2263 (defun gnus-article-treat-fold-newsgroups ()
2264 "Unfold folded message headers.
2265 Only the headers that fit into the current window width will be
2268 (gnus-with-article-headers
2269 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2271 (mail-header-narrow-to-field)
2272 (while (re-search-forward ", *" nil t)
2273 (replace-match ", " t t))
2274 (mail-header-fold-field)
2275 (goto-char (point-max))))))
2277 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2278 "Value of `truncate-lines' in Gnus Article buffer.
2279 Valid values are nil, t, `head', `first', `last', an integer or a
2280 predicate. See Info node `(gnus)Customizing Articles'."
2281 :version "23.1" ;; No Gnus
2282 :group 'gnus-article
2283 ;; :link '(custom-manual "(gnus)Customizing Articles")
2286 (defun gnus-article-toggle-truncate-lines (&optional arg)
2287 "Toggle whether to fold or truncate long lines in article the buffer.
2288 If ARG is non-nil and not a number, toggle
2289 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2290 long lines if and only if arg is positive."
2293 ((and (numberp arg) (> arg 0))
2294 (setq gnus-article-truncate-lines t))
2296 (setq gnus-article-truncate-lines nil))
2298 (setq gnus-article-truncate-lines
2299 (not gnus-article-truncate-lines))))
2300 (gnus-with-article-buffer
2302 ((and (numberp arg) (> arg 0))
2303 (setq truncate-lines nil))
2305 (setq truncate-lines t)))
2306 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2307 ;; `toggle-truncate-lines' needs an argument.
2308 (toggle-truncate-lines)))
2310 (defun gnus-article-treat-body-boundary ()
2311 "Place a boundary line at the end of the headers."
2313 (when (and gnus-body-boundary-delimiter
2314 (> (length gnus-body-boundary-delimiter) 0))
2315 (gnus-with-article-headers
2316 (goto-char (point-max))
2317 (let ((start (point)))
2318 (insert "X-Boundary: ")
2319 (gnus-add-text-properties start (point) '(invisible t intangible t))
2321 (while (>= (window-width) (length str))
2322 (setq str (concat str gnus-body-boundary-delimiter)))
2323 (substring str 0 (window-width)))
2325 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2327 (defun article-fill-long-lines ()
2328 "Fill lines that are wider than the window width."
2331 (let ((inhibit-read-only t)
2332 (width (window-width (get-buffer-window (current-buffer)))))
2335 (let ((adaptive-fill-mode nil)) ;Why? -sm
2338 (when (>= (current-column) (min fill-column width))
2339 (narrow-to-region (min (1+ (point)) (point-max))
2341 (let ((goback (point-marker)))
2342 (fill-paragraph nil)
2343 (goto-char (marker-position goback)))
2345 (forward-line 1)))))))
2347 (defun article-capitalize-sentences ()
2348 "Capitalize the first word in each sentence."
2351 (let ((inhibit-read-only t)
2352 (paragraph-start "^[\n\^L]"))
2356 (forward-sentence)))))
2358 (defun article-remove-cr ()
2359 "Remove trailing CRs and then translate remaining CRs into LFs."
2362 (let ((inhibit-read-only t))
2363 (goto-char (point-min))
2364 (while (re-search-forward "\r+$" nil t)
2365 (replace-match "" t t))
2366 (goto-char (point-min))
2367 (while (search-forward "\r" nil t)
2368 (replace-match "\n" t t)))))
2370 (defun article-remove-trailing-blank-lines ()
2371 "Remove all trailing blank lines from the article."
2374 (let ((inhibit-read-only t))
2375 (goto-char (point-max))
2379 (while (and (not (bobp))
2380 (looking-at "^[ \t]*$")
2381 (not (gnus-annotation-in-region-p
2382 (point) (point-at-eol))))
2387 (defvar gnus-face-properties-alist)
2389 (defun article-display-face (&optional force)
2390 "Display any Face headers in the header."
2391 (interactive (list 'force))
2392 (let ((wash-face-p buffer-read-only))
2393 (gnus-with-article-headers
2394 ;; When displaying parts, this function can be called several times on
2395 ;; the same article, without any intended toggle semantic (as typing `W
2396 ;; D d' would have). So face deletion must occur only when we come from
2397 ;; an interactive command, that is when the *Article* buffer is
2399 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2400 (gnus-delete-images 'face)
2401 (let ((from (message-fetch-field "from"))
2403 (save-current-buffer
2404 (when (and wash-face-p
2405 (gnus-buffer-live-p gnus-original-article-buffer)
2406 (not (re-search-forward "^Face:[\t ]*" nil t)))
2407 (set-buffer gnus-original-article-buffer))
2409 (mail-narrow-to-head)
2411 ;; Check whether this face is censored.
2412 (not (and gnus-article-x-face-too-ugly
2414 (setq from (message-fetch-field "from")))
2415 (string-match gnus-article-x-face-too-ugly
2417 (while (gnus-article-goto-header "Face")
2418 (push (mail-header-field-value) faces)))))
2420 (goto-char (point-min))
2422 (unless (setq from (gnus-article-goto-header "from"))
2425 (insert " [no `from' set]\n"))
2427 (when (setq png (gnus-convert-face-to-png (pop faces)))
2429 (apply 'gnus-create-image png 'png t
2430 (cdr (assq 'png gnus-face-properties-alist))))
2432 (gnus-add-wash-type 'face)
2433 (gnus-add-image 'face image)
2434 (gnus-put-image image nil 'face))))))))))
2436 (defun article-display-x-face (&optional force)
2437 "Look for an X-Face header and display it if present."
2438 (interactive (list 'force))
2439 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2440 (gnus-with-article-headers
2441 ;; Delete the old process, if any.
2442 (when (process-status "article-x-face")
2443 (delete-process "article-x-face"))
2444 ;; See the comment in `article-display-face'.
2445 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2446 ;; We have already displayed X-Faces, so we remove them
2448 (gnus-delete-images 'xface)
2450 (let ((from (message-fetch-field "from"))
2452 (save-current-buffer
2453 (when (and wash-face-p
2454 (gnus-buffer-live-p gnus-original-article-buffer)
2455 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2456 ;; If type `W f', use gnus-original-article-buffer,
2457 ;; otherwise use the current buffer because displaying
2458 ;; RFC822 parts calls this function too.
2459 (set-buffer gnus-original-article-buffer))
2461 (mail-narrow-to-head)
2462 (and gnus-article-x-face-command
2464 ;; Check whether this face is censored.
2465 (not (and gnus-article-x-face-too-ugly
2467 (setq from (message-fetch-field "from")))
2468 (string-match gnus-article-x-face-too-ugly
2470 (while (gnus-article-goto-header "X-Face")
2471 (push (mail-header-field-value) x-faces)))))
2473 ;; We display the face.
2474 (cond ((functionp gnus-article-x-face-command)
2475 ;; The command is a lisp function, so we call it.
2476 (mapc gnus-article-x-face-command x-faces))
2477 ((stringp gnus-article-x-face-command)
2478 ;; The command is a string, so we interpret the command
2479 ;; as a, well, command, and fork it off.
2480 (let ((process-connection-type nil))
2481 (gnus-set-process-query-on-exit-flag
2483 "article-x-face" nil shell-file-name
2484 shell-command-switch gnus-article-x-face-command)
2486 ;; Sending multiple EOFs to xv doesn't work,
2487 ;; so we only do a single external face.
2489 (insert (car x-faces))
2490 (process-send-region "article-x-face"
2491 (point-min) (point-max)))
2492 (process-send-eof "article-x-face")))
2494 (error "`%s' set to `%s' is not a function"
2495 gnus-article-x-face-command
2496 'gnus-article-x-face-command)))))))))
2498 (defun article-decode-mime-words ()
2499 "Decode all MIME-encoded words in the article."
2501 (gnus-with-article-buffer
2502 (let ((inhibit-point-motion-hooks t)
2503 (mail-parse-charset gnus-newsgroup-charset)
2504 (mail-parse-ignored-charsets
2505 (with-current-buffer gnus-summary-buffer
2506 gnus-newsgroup-ignored-charsets)))
2507 (mail-decode-encoded-word-region (point-min) (point-max)))))
2509 (defun article-decode-charset (&optional prompt)
2510 "Decode charset-encoded text in the article.
2511 If PROMPT (the prefix), prompt for a coding system to use."
2513 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2514 (inhibit-read-only t)
2515 (mail-parse-charset gnus-newsgroup-charset)
2516 (mail-parse-ignored-charsets
2517 (save-excursion (condition-case nil
2518 (set-buffer gnus-summary-buffer)
2520 gnus-newsgroup-ignored-charsets))
2521 ct cte ctl charset format)
2524 (article-narrow-to-head)
2525 (setq ct (message-fetch-field "Content-Type" t)
2526 cte (message-fetch-field "Content-Transfer-Encoding" t)
2527 ctl (and ct (mail-header-parse-content-type ct))
2530 (mm-read-coding-system "Charset to decode: "))
2532 (mail-content-type-get ctl 'charset)))
2533 format (and ctl (mail-content-type-get ctl 'format)))
2535 (setq cte (mail-header-strip cte)))
2536 (if (and ctl (not (string-match "/" (car ctl))))
2538 (goto-char (point-max)))
2541 (narrow-to-region (point) (point-max))
2542 (when (and (eq mail-parse-charset 'gnus-decoded)
2543 (eq (mm-body-7-or-8) '8bit))
2544 ;; The text code could have been decoded.
2545 (setq charset mail-parse-charset))
2546 (when (and (or (not ctl)
2547 (equal (car ctl) "text/plain"))
2548 (not format)) ;; article with format will decode later.
2550 charset (and cte (intern (downcase
2551 (gnus-strip-whitespace cte))))
2554 (defun article-decode-encoded-words ()
2555 "Remove encoded-word encoding from headers."
2556 (let ((inhibit-point-motion-hooks t)
2557 (mail-parse-charset gnus-newsgroup-charset)
2558 (mail-parse-ignored-charsets
2559 (save-excursion (condition-case nil
2560 (set-buffer gnus-summary-buffer)
2562 gnus-newsgroup-ignored-charsets))
2563 (inhibit-read-only t)
2565 (goto-char (point-min))
2566 (when (search-forward "\n\n" nil 'move)
2573 (memq (char-after) '(?\t ? )))))
2574 (setq start (point))
2576 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2577 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2578 (funcall gnus-decode-address-function start end)
2579 (funcall gnus-decode-header-function start end))
2580 (goto-char (setq end start)))))
2582 (defun article-decode-group-name ()
2583 "Decode group names in Newsgroups, Followup-To and Xref headers."
2584 (let ((inhibit-point-motion-hooks t)
2585 (inhibit-read-only t)
2586 (method (gnus-find-method-for-group gnus-newsgroup-name))
2588 (when (and (or gnus-group-name-charset-method-alist
2589 gnus-group-name-charset-group-alist)
2590 (gnus-buffer-live-p gnus-original-article-buffer))
2592 (article-narrow-to-head)
2593 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2594 (with-current-buffer gnus-original-article-buffer
2595 (goto-char (point-min)))
2596 (setq regexp (concat "^" header
2597 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2598 (while (re-search-forward regexp nil t)
2599 (replace-match (save-match-data
2600 (gnus-decode-newsgroups
2601 ;; XXX how to use data in article buffer?
2602 (with-current-buffer gnus-original-article-buffer
2603 (re-search-forward regexp nil t)
2605 gnus-newsgroup-name method))
2607 (goto-char (point-min)))))))
2609 (autoload 'idna-to-unicode "idna")
2611 (defun article-decode-idna-rhs ()
2612 "Decode IDNA strings in RHS in various headers in current buffer.
2613 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2614 Mail-Reply-To: and Mail-Followup-To:."
2617 (let ((inhibit-point-motion-hooks t)
2618 (inhibit-read-only t))
2619 (article-narrow-to-head)
2620 (goto-char (point-min))
2621 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2623 (when (save-match-data
2624 (and (setq ace (match-string 1))
2626 (and (re-search-backward "^[^ \t]" nil t)
2627 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2628 (setq unicode (idna-to-unicode ace))))
2629 (unless (string= ace unicode)
2630 (replace-match unicode nil nil nil 1)))))))))
2632 (defun article-de-quoted-unreadable (&optional force read-charset)
2633 "Translate a quoted-printable-encoded article.
2634 If FORCE, decode the article whether it is marked as quoted-printable
2636 If READ-CHARSET, ask for a coding system."
2637 (interactive (list 'force current-prefix-arg))
2639 (let ((inhibit-read-only t) type charset)
2640 (if (gnus-buffer-live-p gnus-original-article-buffer)
2641 (with-current-buffer gnus-original-article-buffer
2643 (gnus-fetch-field "content-transfer-encoding"))
2644 (let* ((ct (gnus-fetch-field "content-type"))
2645 (ctl (and ct (mail-header-parse-content-type ct))))
2646 (setq charset (and ctl
2647 (mail-content-type-get ctl 'charset)))
2648 (if (stringp charset)
2649 (setq charset (intern (downcase charset)))))))
2651 (setq charset (mm-read-coding-system "Charset: " charset)))
2653 (setq charset gnus-newsgroup-charset))
2655 (and type (let ((case-fold-search t))
2656 (string-match "quoted-printable" type))))
2658 (quoted-printable-decode-region
2659 (point) (point-max) (mm-charset-to-coding-system charset))))))
2661 (defun article-de-base64-unreadable (&optional force read-charset)
2662 "Translate a base64 article.
2663 If FORCE, decode the article whether it is marked as base64 not.
2664 If READ-CHARSET, ask for a coding system."
2665 (interactive (list 'force current-prefix-arg))
2667 (let ((inhibit-read-only t) type charset)
2668 (if (gnus-buffer-live-p gnus-original-article-buffer)
2669 (with-current-buffer gnus-original-article-buffer
2671 (gnus-fetch-field "content-transfer-encoding"))
2672 (let* ((ct (gnus-fetch-field "content-type"))
2673 (ctl (and ct (mail-header-parse-content-type ct))))
2674 (setq charset (and ctl
2675 (mail-content-type-get ctl 'charset)))
2676 (if (stringp charset)
2677 (setq charset (intern (downcase charset)))))))
2679 (setq charset (mm-read-coding-system "Charset: " charset)))
2681 (setq charset gnus-newsgroup-charset))
2683 (and type (let ((case-fold-search t))
2684 (string-match "base64" type))))
2687 (narrow-to-region (point) (point-max))
2688 (base64-decode-region (point-min) (point-max))
2689 (mm-decode-coding-region
2690 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2695 (defun article-decode-HZ ()
2696 "Translate a HZ-encoded article."
2700 (let ((inhibit-read-only t))
2701 (rfc1843-decode-region (point-min) (point-max)))))
2703 (defun article-unsplit-urls ()
2704 "Remove the newlines that some other mailers insert into URLs."
2707 (let ((inhibit-read-only t))
2708 (goto-char (point-min))
2709 (while (re-search-forward
2710 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2711 (replace-match "\\1\\3" t)))
2712 (when (interactive-p)
2713 (gnus-treat-article nil))))
2715 (defun article-wash-html ()
2716 "Format an HTML article."
2719 (buffer-read-only nil))
2720 (when (gnus-buffer-live-p gnus-original-article-buffer)
2721 (setq handles (mm-dissect-buffer t t)))
2723 (delete-region (point) (point-max))
2724 (mm-inline-text-html handles)))
2726 (defvar gnus-article-browse-html-temp-list nil
2727 "List of temporary files created by `gnus-article-browse-html-parts'.
2728 Internal variable.")
2730 (defcustom gnus-article-browse-delete-temp 'ask
2731 "What to do with temporary files from `gnus-article-browse-html-parts'.
2732 If nil, don't delete temporary files. If it is t, delete them on
2733 exit from the summary buffer. If it is the symbol `file', query
2734 on each file, if it is `ask' ask once when exiting from the
2736 :group 'gnus-article
2737 :version "23.1" ;; No Gnus
2738 :type '(choice (const :tag "Don't delete" nil)
2739 (const :tag "Don't ask" t)
2740 (const :tag "Ask" ask)
2741 (const :tag "Ask for each file" file)))
2743 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2745 (defun gnus-article-browse-delete-temp-files (&optional how)
2746 "Delete temp-files created by `gnus-article-browse-html-parts'."
2747 (when (and gnus-article-browse-html-temp-list
2749 (or how (setq how gnus-article-browse-delete-temp))
2751 (let ((files (length gnus-article-browse-html-temp-list)))
2752 (gnus-y-or-n-p (format
2753 "Delete all %s temporary HTML file%s? "
2755 (if (> files 1) "s" ""))))
2757 (dolist (file gnus-article-browse-html-temp-list)
2758 (cond ((file-directory-p file)
2759 (when (or (not (eq how 'file))
2762 "Delete temporary HTML file(s) in directory `%s'? "
2763 (file-name-as-directory file))))
2764 (gnus-delete-directory file)))
2765 ((file-exists-p file)
2766 (when (or (not (eq how 'file))
2768 (format "Delete temporary HTML file `%s'? " file)))
2769 (delete-file file)))))
2770 ;; Also remove file from the list when not deleted or if file doesn't
2772 (setq gnus-article-browse-html-temp-list nil))
2773 gnus-article-browse-html-temp-list)
2775 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2776 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2781 (dolist (handle handles)
2783 ((not (listp handle)))
2784 ((equal (mm-handle-media-supertype handle) "multipart")
2785 (when (setq file (gnus-article-browse-html-save-cid-content
2786 cid handle directory))
2787 (throw 'found file)))
2788 ((equal (concat "<" cid ">") (mm-handle-id handle))
2791 (or (mail-content-type-get
2792 (mm-handle-disposition handle) 'filename)
2793 (mail-content-type-get
2794 (setq type (mm-handle-type handle)) 'name)
2796 (make-temp-name "cid")
2797 (car (rassoc (car type) mailcap-mime-extensions))))
2799 (mm-save-part-to-file handle file)
2800 (throw 'found file))))))))
2802 (defun gnus-article-browse-html-parts (list &optional header)
2803 "View all \"text/html\" parts from LIST.
2804 Recurse into multiparts. The optional HEADER that should be a decoded
2805 message header will be added to the bodies of the \"text/html\" parts."
2806 ;; Internal function used by `gnus-article-browse-html-article'.
2807 (let (type file charset content cid-dir tmp-file showed)
2808 ;; Find and show the html-parts.
2809 (dolist (handle list)
2810 ;; If HTML, show it:
2811 (cond ((not (listp handle)))
2812 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2813 (and (equal (car type) "message/external-body")
2815 (setq file (or (mail-content-type-get type 'name)
2816 (mail-content-type-get
2817 (mm-handle-disposition handle)
2819 (or (mm-handle-cache handle)
2820 (condition-case code
2821 (progn (mm-extern-cache-contents handle) t)
2823 (gnus-message 3 "%s" (error-message-string code))
2824 (when (>= gnus-verbose 3) (sit-for 2))
2827 (setq handle (mm-handle-cache handle)
2828 type (mm-handle-type handle))
2829 (equal (car type) "text/html"))))
2830 (setq charset (mail-content-type-get type 'charset)
2831 content (mm-get-part handle))
2833 (if (eq charset 'gnus-decoded)
2834 (mm-enable-multibyte)
2835 (mm-disable-multibyte))
2837 ;; resolve cid contents
2838 (let ((case-fold-search t)
2840 (goto-char (point-min))
2841 (while (re-search-forward "\
2842 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2845 (setq cid-dir (mm-make-temp-file "cid" t))
2846 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2849 (when (setq cid-file
2850 (gnus-article-browse-html-save-cid-content
2852 (with-current-buffer gnus-article-buffer
2853 gnus-article-mime-handles)
2855 (replace-match (concat "file://" cid-file)
2857 (unless content (setq content (buffer-string))))
2858 (when (or charset header (not file))
2859 (setq tmp-file (mm-make-temp-file
2860 ;; Do we need to care for 8.3 filenames?
2861 "mm-" nil ".html")))
2862 ;; Add a meta html tag to specify charset and a header.
2865 (let (title eheader body hcharset coding force-charset)
2867 (mm-enable-multibyte)
2868 (setq case-fold-search t)
2869 (insert header "\n")
2870 (setq title (message-fetch-field "subject"))
2871 (goto-char (point-min))
2872 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2873 (replace-match (cond ((match-beginning 1) "<")
2874 ((match-beginning 2) ">")
2876 (goto-char (point-min))
2878 (goto-char (point-max))
2879 (insert "</pre>\n<hr>\n")
2880 ;; We have to examine charset one by one since
2881 ;; charset specified in parts might be different.
2882 (if (eq charset 'gnus-decoded)
2883 (setq charset 'utf-8
2884 eheader (mm-encode-coding-string (buffer-string)
2887 (mm-encode-coding-string title charset))
2888 body (mm-encode-coding-string content charset)
2890 (setq hcharset (mm-find-mime-charset-region (point-min)
2892 (cond ((= (length hcharset) 1)
2893 (setq hcharset (car hcharset)
2894 coding (mm-charset-to-coding-system
2896 ((> (length hcharset) 1)
2897 (setq hcharset 'utf-8
2903 (mm-charset-to-coding-system charset))
2904 (if (eq coding body)
2905 (setq eheader (mm-encode-coding-string
2906 (buffer-string) coding)
2908 (mm-encode-coding-string
2911 (setq charset 'utf-8
2912 eheader (mm-encode-coding-string
2913 (buffer-string) charset)
2915 (mm-encode-coding-string
2917 body (mm-encode-coding-string
2918 (mm-decode-coding-string
2922 (setq charset hcharset
2923 eheader (mm-encode-coding-string
2924 (buffer-string) coding)
2926 (mm-encode-coding-string
2929 (setq eheader (mm-string-as-unibyte (buffer-string))
2932 (mm-disable-multibyte)
2935 (mm-add-meta-html-tag handle charset force-charset))
2937 (goto-char (point-min))
2938 (unless (search-forward "<title>" nil t)
2939 (re-search-forward "<head>\\s-*" nil t)
2940 (insert "<title>" title "</title>\n")))
2941 (goto-char (point-min))
2942 (or (re-search-forward
2943 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2945 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2947 (mm-write-region (point-min) (point-max)
2948 tmp-file nil nil nil 'binary t))))
2950 (mm-with-unibyte-buffer
2951 (insert (if (eq charset 'gnus-decoded)
2952 (mm-encode-coding-string content
2953 (setq charset 'utf-8))
2955 (if (or (mm-add-meta-html-tag handle charset)
2957 (mm-write-region (point-min) (point-max)
2958 tmp-file nil nil nil 'binary t)
2959 (setq tmp-file nil))))
2961 (mm-save-part-to-file handle tmp-file)))
2963 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2964 (add-hook 'gnus-summary-prepare-exit-hook
2965 'gnus-article-browse-delete-temp-files)
2966 (add-hook 'gnus-exit-gnus-hook
2968 (gnus-article-browse-delete-temp-files t)))
2969 ;; FIXME: Warn if there's an <img> tag?
2970 (browse-url-of-file (or tmp-file (expand-file-name file)))
2972 ;; If multipart, recurse
2973 ((equal (mm-handle-media-supertype handle) "multipart")
2974 (when (gnus-article-browse-html-parts handle header)
2976 ((equal (mm-handle-media-type handle) "message/rfc822")
2977 (mm-with-multibyte-buffer
2978 (mm-insert-part handle)
2979 (setq handle (mm-dissect-buffer t t))
2980 (when (and (bufferp (car handle))
2981 (stringp (car (mm-handle-type handle))))
2982 (setq handle (list handle)))
2984 (article-decode-encoded-words)
2985 (let ((gnus-visible-headers
2986 (or (get 'gnus-visible-headers 'standard-value)
2987 gnus-visible-headers)))
2988 (article-hide-headers))
2989 (goto-char (point-min))
2990 (search-forward "\n\n" nil 'move)
2991 (skip-chars-backward "\t\n ")
2992 (setq header (buffer-substring (point-min) (point)))))
2994 (gnus-article-browse-html-parts handle header)
2995 (mm-destroy-parts handle))
2999 (defun gnus-article-browse-html-article (&optional arg)
3000 "View \"text/html\" parts of the current article with a WWW browser.
3001 Inline images embedded in a message using the cid scheme, as they are
3002 generally considered to be safe, will be processed properly.
3003 The message header is added to the beginning of every html part unless
3004 the prefix argument ARG is given.
3006 Warning: Spammers use links to images (using the http scheme) in HTML
3007 articles to verify whether you have read the message. As
3008 `gnus-article-browse-html-article' passes the HTML content to the
3009 browser without eliminating these \"web bugs\" you should only
3010 use it for mails from trusted senders.
3012 If you always want to display HTML parts in the browser, set
3013 `mm-text-html-renderer' to nil.
3015 This command creates temporary files to pass HTML contents including
3016 images if any to the browser, and deletes them when exiting the group
3018 ;; Cf. `mm-w3m-safe-url-regexp'
3021 (gnus-summary-show-article)
3022 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3023 gnus-visible-headers))
3024 ;; As we insert a <hr>, there's no need for the body boundary.
3025 (gnus-treat-body-boundary nil))
3026 (gnus-summary-show-article)))
3027 (with-current-buffer gnus-article-buffer
3028 (let ((header (unless arg
3031 (buffer-substring-no-properties
3032 (goto-char (point-min))
3033 (if (search-forward "\n\n" nil t)
3035 (goto-char (point-max))
3036 (skip-chars-backward "\t\n ")
3039 (set-buffer gnus-original-article-buffer)
3040 (setq parts (mm-dissect-buffer t t))
3041 ;; If singlepart, enforce a list.
3042 (when (and (bufferp (car parts))
3043 (stringp (car (mm-handle-type parts))))
3044 (setq parts (list parts)))
3046 (unless (gnus-article-browse-html-parts parts header)
3047 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3048 (mm-destroy-parts parts)
3050 (gnus-summary-show-article)))))
3052 (defun article-hide-list-identifiers ()
3053 "Remove list identifies from the Subject header.
3054 The `gnus-list-identifiers' variable specifies what to do."
3056 (let ((inhibit-point-motion-hooks t)
3057 (regexp (if (consp gnus-list-identifiers)
3058 (mapconcat 'identity gnus-list-identifiers " *\\|")
3059 gnus-list-identifiers))
3060 (inhibit-read-only t))
3064 (article-narrow-to-head)
3065 (goto-char (point-min))
3066 (while (re-search-forward
3067 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3069 (delete-region (match-beginning 2) (match-end 0))
3070 (beginning-of-line))
3071 (when (re-search-forward
3072 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3073 (delete-region (match-beginning 1) (match-end 1))))))))
3075 (defun article-hide-pem (&optional arg)
3076 "Toggle hiding of any PEM headers and signatures in the current article.
3077 If given a negative prefix, always show; if given a positive prefix,
3079 (interactive (gnus-article-hidden-arg))
3080 (unless (gnus-article-check-hidden-text 'pem arg)
3082 (let ((inhibit-read-only t) end)
3083 (goto-char (point-min))
3084 ;; Hide the horrendously ugly "header".
3085 (when (and (search-forward
3086 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3088 (setq end (1+ (match-beginning 0))))
3089 (gnus-add-wash-type 'pem)
3090 (gnus-article-hide-text-type
3092 (if (search-forward "\n\n" nil t)
3096 ;; Hide the trailer as well
3097 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3099 (gnus-article-hide-text-type
3100 (match-beginning 0) (match-end 0) 'pem)))))))
3102 (defun article-strip-banner ()
3103 "Strip the banners specified by the `banner' group parameter and by
3104 `gnus-article-address-banner-alist'."
3108 (let ((inhibit-point-motion-hooks t))
3109 (when (gnus-parameter-banner gnus-newsgroup-name)
3110 (article-really-strip-banner
3111 (gnus-parameter-banner gnus-newsgroup-name)))
3112 (when gnus-article-address-banner-alist
3113 ;; Note that the From header is decoded here, so it is
3114 ;; required that the *-extract-address-components function
3115 ;; supports non-ASCII text.
3116 (let ((from (save-restriction
3118 (article-narrow-to-head)
3119 (mail-fetch-field "from"))))
3122 (cadr (funcall gnus-extract-address-components
3125 (dolist (pair gnus-article-address-banner-alist)
3126 (when (string-match (car pair) from)
3128 (article-really-strip-banner (cdr pair)))))))))))))
3130 (defun article-really-strip-banner (banner)
3131 "Strip the banner specified by the argument."
3134 (let ((inhibit-point-motion-hooks t)
3135 (gnus-signature-limit nil)
3136 (inhibit-read-only t))
3139 ((eq banner 'signature)
3140 (when (gnus-article-narrow-to-signature)
3143 (delete-region (point) (point-max))))
3145 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3146 (while (re-search-forward banner nil t)
3147 (delete-region (match-beginning 0) (match-end 0)))))
3149 (while (re-search-forward banner nil t)
3150 (delete-region (match-beginning 0) (match-end 0)))))))))
3152 (defun article-babel ()
3153 "Translate article using an online translation service."
3156 (gnus-with-article-buffer
3157 (when (article-goto-body)
3158 (let* ((start (point))
3160 (orig (buffer-substring start end))
3161 (trans (babel-as-string orig)))
3163 (narrow-to-region start end)
3164 (delete-region start end)
3167 (defun article-hide-signature (&optional arg)
3168 "Hide the signature in the current article.
3169 If given a negative prefix, always show; if given a positive prefix,
3171 (interactive (gnus-article-hidden-arg))
3172 (unless (gnus-article-check-hidden-text 'signature arg)
3175 (let ((inhibit-read-only t))
3176 (when (gnus-article-narrow-to-signature)
3177 (gnus-article-hide-text-type
3178 (point-min) (point-max) 'signature))))))
3179 (gnus-set-mode-line 'article))
3181 (defun article-strip-headers-in-body ()
3182 "Strip offensive headers from bodies."
3186 (let ((case-fold-search t))
3187 (when (looking-at "x-no-archive:")
3188 (gnus-delete-line)))))
3190 (defun article-strip-leading-blank-lines ()
3191 "Remove all blank lines from the beginning of the article."
3194 (let ((inhibit-point-motion-hooks t)
3195 (inhibit-read-only t))
3196 (when (article-goto-body)
3197 (while (and (not (eobp))
3198 (looking-at "[ \t]*$"))
3199 (gnus-delete-line))))))
3201 (defun article-narrow-to-head ()
3202 "Narrow the buffer to the head of the message.
3203 Point is left at the beginning of the narrowed-to region."
3205 (goto-char (point-min))
3206 (if (search-forward "\n\n" nil 1)
3209 (goto-char (point-min)))
3211 (defun article-goto-body ()
3212 "Place point at the start of the body."
3213 (goto-char (point-min))
3215 ;; This variable is only bound when dealing with separate
3217 (article-goto-body-goes-to-point-min-p
3219 ((search-forward "\n\n" nil t)
3222 (goto-char (point-max))
3225 (defun article-strip-multiple-blank-lines ()
3226 "Replace consecutive blank lines with one empty line."
3229 (let ((inhibit-point-motion-hooks t)
3230 (inhibit-read-only t))
3231 ;; First make all blank lines empty.
3233 (while (re-search-forward "^[ \t]+$" nil t)
3234 (unless (gnus-annotation-in-region-p
3235 (match-beginning 0) (match-end 0))
3236 (replace-match "" nil t)))
3237 ;; Then replace multiple empty lines with a single empty line.
3239 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3240 (unless (gnus-annotation-in-region-p
3241 (match-beginning 0) (match-end 0))
3242 (delete-region (match-beginning 1) (match-end 1)))))))
3244 (defun article-strip-leading-space ()
3245 "Remove all white space from the beginning of the lines in the article."
3248 (let ((inhibit-point-motion-hooks t)
3249 (inhibit-read-only t))
3251 (while (re-search-forward "^[ \t]+" nil t)
3252 (replace-match "" t t)))))
3254 (defun article-strip-trailing-space ()
3255 "Remove all white space from the end of the lines in the article."
3258 (let ((inhibit-point-motion-hooks t)
3259 (inhibit-read-only t))
3261 (while (re-search-forward "[ \t]+$" nil t)
3262 (replace-match "" t t)))))
3264 (defun article-strip-blank-lines ()
3265 "Strip leading, trailing and multiple blank lines."
3267 (article-strip-leading-blank-lines)
3268 (article-remove-trailing-blank-lines)
3269 (article-strip-multiple-blank-lines))
3271 (defun article-strip-all-blank-lines ()
3272 "Strip all blank lines."
3275 (let ((inhibit-point-motion-hooks t)
3276 (inhibit-read-only t))
3278 (while (re-search-forward "^[ \t]*\n" nil t)
3279 (replace-match "" t t)))))
3281 (defun gnus-article-narrow-to-signature ()
3282 "Narrow to the signature; return t if a signature is found, else nil."
3283 (let ((inhibit-point-motion-hooks t))
3284 (when (gnus-article-search-signature)
3286 ;; Check whether we have some limits to what we consider
3287 ;; to be a signature.
3288 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3289 (list gnus-signature-limit)))
3291 (while (setq limit (pop limits))
3292 (if (or (and (integerp limit)
3293 (< (- (point-max) (point)) limit))
3295 (< (count-lines (point) (point-max)) limit))
3296 (and (functionp limit)
3298 (and (stringp limit)
3299 (not (re-search-forward limit nil t))))
3300 () ; This limit did not succeed.
3304 (narrow-to-region (point) (point-max))
3307 (defun gnus-article-search-signature ()
3308 "Search the current buffer for the signature separator.
3309 Put point at the beginning of the signature separator."
3310 (let ((cur (point)))
3311 (goto-char (point-max))
3312 (if (if (stringp gnus-signature-separator)
3313 (re-search-backward gnus-signature-separator nil t)
3314 (let ((seps gnus-signature-separator))
3316 (not (re-search-backward (car seps) nil t)))
3323 (defun gnus-article-hidden-arg ()
3324 "Return the current prefix arg as a number, or 0 if no prefix."
3325 (list (if current-prefix-arg
3326 (prefix-numeric-value current-prefix-arg)
3329 (defun gnus-article-check-hidden-text (type arg)
3330 "Return nil if hiding is necessary.
3331 Arg can be nil or a number. nil and positive means hide, negative
3332 means show, 0 means toggle."
3335 (let ((hide (gnus-article-hidden-text-p type)))
3341 (gnus-article-show-hidden-text type)
3344 (if (eq hide 'hidden)
3346 (gnus-article-show-hidden-text type)
3350 (defun gnus-article-hidden-text-p (type)
3351 "Say whether the current buffer contains hidden text of type TYPE."
3352 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3354 (not (get-text-property pos 'invisible))
3355 (not (get-text-property pos 'dummy-invisible)))
3357 (text-property-any (1+ pos) (point-max) 'article-type type)))
3362 (defun gnus-article-show-hidden-text (type &optional dummy)
3363 "Show all hidden text of type TYPE.
3364 Originally it is hide instead of DUMMY."
3365 (let ((inhibit-read-only t)
3366 (inhibit-point-motion-hooks t))
3367 (gnus-remove-text-properties-when
3369 (point-min) (point-max)
3370 (cons 'article-type (cons type
3371 gnus-hidden-properties)))
3372 (gnus-delete-wash-type type)))
3374 (defconst article-time-units
3375 `((year . ,(* 365.25 24 60 60))
3376 (week . ,(* 7 24 60 60))
3377 (day . ,(* 24 60 60))
3381 "Mapping from time units to seconds.")
3383 (defun gnus-article-forward-header ()
3384 "Move point to the start of the next header.
3385 If the current header is a continuation header, this can be several
3390 (if (looking-at "[ \t]+[^ \t]")
3394 (defun article-treat-date ()
3395 (article-date-ut gnus-article-date-headers t))
3397 (defun article-date-ut (&optional type highlight date-position)
3398 "Convert DATE date to TYPE in the current article.
3399 The default type is `ut'. See `gnus-article-date-headers' for
3401 (interactive (list 'ut t))
3402 (let* ((case-fold-search t)
3403 (inhibit-read-only t)
3404 (inhibit-point-motion-hooks t)
3406 pos date bface eface)
3409 (goto-char (point-min))
3410 (when (re-search-forward "^Date:" nil t)
3411 (setq bface (get-text-property (point-at-bol) 'face)
3412 eface (get-text-property (1- (point-at-eol)) 'face)))
3413 (goto-char (point-min))
3414 ;; Delete any old Date headers.
3417 (goto-char date-position)
3418 (setq date (get-text-property (point) 'original-date))
3419 (delete-region (point)
3421 (gnus-article-forward-header)
3423 (article-transform-date date type bface eface))
3424 (while (re-search-forward "^Date:" nil t)
3425 (setq date (get-text-property (match-beginning 0) 'original-date))
3426 (delete-region (point-at-bol) (progn
3427 (gnus-article-forward-header)
3430 (article-transform-date date type bface eface)))))))
3432 (defun article-transform-date (date type bface eface)
3433 (dolist (this-type (cond
3440 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3443 (put-text-property (point) (1+ (point))
3444 'original-date date)
3445 (put-text-property (point) (1+ (point))
3446 'gnus-date-type this-type)
3448 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3449 (put-text-property (match-beginning 1) (1+ (match-end 1))
3451 (put-text-property (match-beginning 2) (match-end 2)
3455 (defun article-make-date-line (date type)
3456 "Return a DATE line of TYPE."
3457 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3459 (error "Unknown conversion type: %s" type))
3461 (let ((time (date-to-time date)))
3463 ;; Convert to the local timezone.
3465 (concat "Date: " (message-make-date time)))
3466 ;; Convert to Universal Time.
3471 (let* ((e (parse-time-string date))
3472 (tm (apply 'encode-time e))
3474 (ls (- (cadr tm) (car (current-time-zone time)))))
3475 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3476 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3480 ;; Get the original date from the article.
3481 ((eq type 'original)
3482 (concat "Date: " (if (string-match "\n+$" date)
3483 (substring date 0 (match-beginning 0))
3485 ;; Let the user define the format.
3486 ((eq type 'user-defined)
3487 (let ((format (or (condition-case nil
3488 (with-current-buffer gnus-summary-buffer
3489 gnus-article-time-format)
3491 gnus-article-time-format)))
3492 (if (functionp format)
3493 (funcall format time)
3494 (concat "Date: " (format-time-string format time)))))
3497 (let ((tz (car (current-time-zone time))))
3500 (format-time-string "%Y%m%dT%H%M%S" time)
3501 (format "%s%02d%02d"
3502 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3503 (/ (% (abs tz) 3600) 60)))))
3504 ;; Do a lapsed format.
3506 (concat "Date: " (article-lapsed-string time)))
3507 ;; A combined date/lapsed format.
3508 ((eq type 'combined-lapsed)
3509 (let ((date-string (article-make-date-line date 'original))
3514 (concat " (" (article-lapsed-string time segments) ")"))
3515 (> (+ (length date-string)
3516 (length lapsed-string))
3519 (setq segments (1- segments)))
3521 (concat date-string lapsed-string)
3523 ;; Display the date in proper English
3525 (let ((dtime (decode-time time)))
3528 (number-to-string (nth 3 dtime))
3529 (let ((digit (% (nth 3 dtime) 10)))
3531 ((memq (nth 3 dtime) '(11 12 13)) "th")
3537 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3539 (number-to-string (nth 5 dtime))
3541 (format "%02d" (nth 2 dtime))
3543 (format "%02d" (nth 1 dtime)))))))
3545 (format "Date: %s (from Gnus)" date))))
3547 (defun article-lapsed-string (time &optional max-segments)
3548 ;; If the date is seriously mangled, the timezone functions are
3549 ;; liable to bug out, so we ignore all errors.
3550 (let* ((now (current-time))
3551 (real-time (subtract-time now time))
3552 (real-sec (and real-time
3553 (+ (* (float (car real-time)) 65536)
3555 (sec (and real-time (abs real-sec)))
3558 (unless max-segments
3559 (setq max-segments (length article-time-units)))
3567 ;; This is a bit convoluted, but basically we go
3568 ;; through the time units for years, weeks, etc,
3569 ;; and divide things to see whether that results
3570 ;; in positive answers.
3573 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3574 (>= segments max-segments))
3575 ;; The (remaining) seconds are too few to
3576 ;; be divided into this time unit.
3578 ;; It's big enough, so we output it.
3579 (setq sec (- sec (* num (cdr unit))))
3581 (concat (if prev ", " "") (int-to-string
3583 " " (symbol-name (car unit))
3584 (if (> num 1) "s" ""))
3586 segments (1+ segments)))))
3587 article-time-units "")
3588 ;; If dates are odd, then it might appear like the
3589 ;; article was sent in the future.
3592 " in the future"))))))
3594 (defun article-date-local (&optional highlight)
3595 "Convert the current article date to the local timezone."
3596 (interactive (list t))
3597 (article-date-ut 'local highlight))
3599 (defun article-date-english (&optional highlight)
3600 "Convert the current article date to something that is proper English."
3601 (interactive (list t))
3602 (article-date-ut 'english highlight))
3604 (defun article-date-original (&optional highlight)
3605 "Convert the current article date to what it was originally.
3606 This is only useful if you have used some other date conversion
3607 function and want to see what the date was before converting."
3608 (interactive (list t))
3609 (article-date-ut 'original highlight))
3611 (defun article-date-lapsed (&optional highlight)
3612 "Convert the current article date to time lapsed since it was sent."
3613 (interactive (list t))
3614 (article-date-ut 'lapsed highlight))
3616 (defun article-date-combined-lapsed (&optional highlight)
3617 "Convert the current article date to time lapsed since it was sent."
3618 (interactive (list t))
3619 (article-date-ut 'combined-lapsed highlight))
3621 (defun article-update-date-lapsed ()
3622 "Function to be run from a timer to update the lapsed time line."
3624 (let ((buffer (current-buffer)))
3628 (set-buffer (window-buffer w))
3629 (when (eq major-mode 'gnus-article-mode)
3630 (let ((old-line (count-lines (point-min) (point)))
3631 (old-column (- (point) (line-beginning-position))))
3632 (goto-char (point-min))
3633 (while (re-search-forward "^Date:" nil t)
3634 (let ((type (get-text-property (match-beginning 0)
3636 (when (memq type '(lapsed combined-lapsed user-format))
3638 (article-date-ut type t (match-beginning 0)))
3640 (goto-char (point-min))
3641 (when (> old-column 0)
3642 (setq old-line (1- old-line)))
3643 (forward-line old-line)
3645 (when (> (current-column) old-column)
3647 (forward-char old-column)))))
3649 (set-buffer buffer))))
3651 (defun gnus-start-date-timer (&optional n)
3652 "Start a timer to update the Date headers in the article buffers.
3653 The numerical prefix says how frequently (in seconds) the function
3658 (gnus-stop-date-timer)
3659 (setq article-lapsed-timer
3660 (run-at-time 1 n 'article-update-date-lapsed)))
3662 (defun gnus-stop-date-timer ()
3663 "Stop the Date timer."
3665 (when article-lapsed-timer
3666 (nnheader-cancel-timer article-lapsed-timer)
3667 (setq article-lapsed-timer nil)))
3669 (defun article-date-user (&optional highlight)
3670 "Convert the current article date to the user-defined format.
3671 This format is defined by the `gnus-article-time-format' variable."
3672 (interactive (list t))
3673 (article-date-ut 'user highlight))
3675 (defun article-date-iso8601 (&optional highlight)
3676 "Convert the current article date to ISO8601."
3677 (interactive (list t))
3678 (article-date-ut 'iso8601 highlight))
3680 (defmacro gnus-article-save-original-date (&rest forms)
3681 "Save the original date as a text property and evaluate FORMS."
3682 `(let* ((case-fold-search t)
3684 (goto-char (point-min))
3685 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3688 (date (when (and start
3689 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3691 (buffer-substring-no-properties start
3692 (match-beginning 0)))))
3693 (goto-char (point-max))
3694 (skip-chars-backward "\n")
3695 (put-text-property (point-min) (point) 'original-date date)
3697 (goto-char (point-max))
3698 (skip-chars-backward "\n")
3699 (put-text-property (point-min) (point) 'original-date date)))
3701 ;; (defun article-show-all ()
3702 ;; "Show all hidden text in the article buffer."
3705 ;; (let ((inhibit-read-only t))
3706 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3708 (defun article-remove-leading-whitespace ()
3709 "Remove excessive whitespace from all headers."
3713 (let ((inhibit-read-only t))
3714 (article-narrow-to-head)
3715 (goto-char (point-min))
3716 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3717 (delete-region (match-beginning 1) (match-end 1)))))))
3719 (defun article-emphasize (&optional arg)
3720 "Emphasize text according to `gnus-emphasis-alist'."
3721 (interactive (gnus-article-hidden-arg))
3722 (unless (gnus-article-check-hidden-text 'emphasis arg)
3726 (with-current-buffer gnus-summary-buffer
3727 gnus-article-emphasis-alist)
3729 gnus-emphasis-alist))
3730 (inhibit-read-only t)
3731 (props (append '(article-type emphasis)
3732 gnus-hidden-properties))
3733 regexp elem beg invisible visible face)
3736 (while (setq elem (pop alist))
3738 (setq regexp (car elem)
3739 invisible (nth 1 elem)
3740 visible (nth 2 elem)
3742 (while (re-search-forward regexp nil t)
3743 (when (and (match-beginning visible) (match-beginning invisible))
3744 (gnus-article-hide-text
3745 (match-beginning invisible) (match-end invisible) props)
3746 (gnus-article-unhide-text-type
3747 (match-beginning visible) (match-end visible) 'emphasis)
3748 (gnus-put-overlay-excluding-newlines
3749 (match-beginning visible) (match-end visible) 'face face)
3750 (gnus-add-wash-type 'emphasis)
3751 (goto-char (match-end invisible)))))))))
3753 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3754 "Setup newsgroup emphasis alist."
3755 (unless gnus-article-emphasis-alist
3756 (let ((name (and gnus-newsgroup-name
3757 (gnus-group-real-name gnus-newsgroup-name))))
3758 (make-local-variable 'gnus-article-emphasis-alist)
3759 (setq gnus-article-emphasis-alist
3761 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3762 (while (setq elem (pop alist))
3763 (when (and name (string-match (car elem) name))
3765 highlight (copy-sequence (cdr elem)))))
3767 (copy-sequence highlight-words)
3768 (if gnus-newsgroup-name
3769 (copy-sequence (gnus-group-find-parameter
3770 gnus-newsgroup-name 'highlight-words t)))
3771 gnus-emphasis-alist)))))
3773 (defvar gnus-summary-article-menu)
3774 (defvar gnus-summary-post-menu)
3776 ;;; Saving functions.
3778 (defun gnus-article-save (save-buffer file &optional num)
3779 "Save the currently selected article."
3780 (when (or (get gnus-default-article-saver :headers)
3781 (not gnus-save-all-headers))
3782 ;; Remove headers according to `gnus-saved-headers' or the value
3783 ;; of the `:headers' property that the saver function might have.
3784 (let ((gnus-visible-headers
3785 (or (symbol-value (get gnus-default-article-saver :headers))
3786 gnus-saved-headers gnus-visible-headers))
3787 ;; Ignore group parameter. See `article-hide-headers'.
3788 (gnus-summary-buffer nil))
3789 (with-current-buffer save-buffer
3790 (article-hide-headers 1 t))))
3791 (save-window-excursion
3792 (if (not gnus-default-article-saver)
3793 (error "No default saver is defined")
3794 ;; !!! Magic! The saving functions all save
3795 ;; `gnus-save-article-buffer' (or so they think), but we
3796 ;; bind that variable to our save-buffer.
3797 (set-buffer gnus-article-buffer)
3798 (let* ((gnus-save-article-buffer save-buffer)
3801 ((not gnus-prompt-before-saving) 'default)
3802 ((eq gnus-prompt-before-saving 'always) nil)
3804 (gnus-number-of-articles-to-be-saved
3805 (when (eq gnus-prompt-before-saving t)
3807 (set-buffer gnus-article-current-summary)
3808 (funcall gnus-default-article-saver filename)))))
3810 (defun gnus-read-save-file-name (prompt &optional filename
3811 function group headers variable
3814 (funcall function group headers (symbol-value variable)))
3819 ((eq filename 'default)
3825 (when (symbol-value dir-var)
3826 (setq default-name (expand-file-name
3827 (file-name-nondirectory default-name)
3828 (symbol-value dir-var))))
3829 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3832 (if (and gnus-number-of-articles-to-be-saved
3833 (> gnus-number-of-articles-to-be-saved 1))
3834 (format "these %d articles"
3835 gnus-number-of-articles-to-be-saved)
3838 ;; Let the split methods have their say.
3840 ;; No split name was found.
3843 (concat prompt " (default "
3844 (file-name-nondirectory default-name) "): ")
3845 (file-name-directory default-name)
3847 ;; A single group name is returned.
3848 ((stringp split-name)
3850 (funcall function split-name headers
3851 (symbol-value variable)))
3853 (concat prompt " (default "
3854 (file-name-nondirectory default-name) "): ")
3855 (file-name-directory default-name)
3857 ;; A single split name was found
3858 ((= 1 (length split-name))
3859 (let* ((name (expand-file-name
3861 gnus-article-save-directory))
3862 (dir (cond ((file-directory-p name)
3863 (file-name-as-directory name))
3864 ((file-exists-p name) name)
3865 (t gnus-article-save-directory))))
3867 (concat prompt " (default " name "): ")
3869 ;; A list of splits was found.
3871 (setq split-name (nreverse split-name))
3873 (let ((file-name-history
3874 (nconc split-name file-name-history)))
3878 (concat prompt " (`M-p' for defaults): ")
3879 gnus-article-save-directory
3881 gnus-article-save-directory)))
3882 (car (push result file-name-history)))))))
3883 ;; Create the directory.
3884 (gnus-make-directory (file-name-directory file))
3885 ;; If we have read a directory, we append the default file name.
3886 (when (file-directory-p file)
3887 (setq file (expand-file-name (file-name-nondirectory
3889 (file-name-as-directory file))))
3890 ;; Possibly translate some characters.
3891 (nnheader-translate-file-chars file))))))
3892 (gnus-make-directory (file-name-directory result))
3894 (set variable result))
3896 (set dir-var (file-name-directory result)))
3899 (defun gnus-article-archive-name (group)
3900 "Return the first instance of an \"Archive-name\" in the current buffer."
3901 (let ((case-fold-search t))
3902 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3903 (nnheader-concat gnus-article-save-directory
3904 (match-string 1)))))
3906 (defun gnus-article-nndoc-name (group)
3907 "If GROUP is an nndoc group, return the name of the parent group."
3908 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3909 (gnus-group-get-parameter group 'save-article-group)))
3911 (defun gnus-summary-save-in-rmail (&optional filename)
3912 "Append this article to Rmail file.
3913 Optional argument FILENAME specifies file name.
3914 Directory to save to is default to `gnus-article-save-directory'."
3915 (setq filename (gnus-read-save-file-name
3916 "Save %s in rmail file" filename
3917 gnus-rmail-save-name gnus-newsgroup-name
3918 gnus-current-headers 'gnus-newsgroup-last-rmail))
3919 (with-current-buffer gnus-save-article-buffer
3923 ;; Note that unlike gnus-summary-save-in-mail, there is no
3924 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3926 (gnus-output-to-rmail filename))))
3929 (defun gnus-summary-save-in-mail (&optional filename)
3930 "Append this article to Unix mail file.
3931 Optional argument FILENAME specifies file name.
3932 Directory to save to is default to `gnus-article-save-directory'."
3933 (setq filename (gnus-read-save-file-name
3934 "Save %s in Unix mail file" filename
3935 gnus-mail-save-name gnus-newsgroup-name
3936 gnus-current-headers 'gnus-newsgroup-last-mail))
3937 (with-current-buffer gnus-save-article-buffer
3941 (if (and (file-readable-p filename)
3942 (file-regular-p filename)
3943 (mail-file-babyl-p filename))
3944 (gnus-output-to-rmail filename)
3945 (gnus-output-to-mail filename)))))
3948 (put 'gnus-summary-save-in-file :decode t)
3949 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3950 (defun gnus-summary-save-in-file (&optional filename overwrite)
3951 "Append this article to file.
3952 Optional argument FILENAME specifies file name.
3953 Directory to save to is default to `gnus-article-save-directory'."
3954 (setq filename (gnus-read-save-file-name
3955 "Save %s in file" filename
3956 gnus-file-save-name gnus-newsgroup-name
3957 gnus-current-headers 'gnus-newsgroup-last-file))
3958 (with-current-buffer gnus-save-article-buffer
3962 (when (and overwrite
3963 (file-exists-p filename))
3964 (delete-file filename))
3965 (gnus-output-to-file filename))))
3968 (put 'gnus-summary-write-to-file :decode t)
3969 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3970 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3971 (defun gnus-summary-write-to-file (&optional filename)
3972 "Write this article to a file, overwriting it if the file exists.
3973 Optional argument FILENAME specifies file name.
3974 The directory to save in defaults to `gnus-article-save-directory'."
3975 (setq filename (gnus-read-save-file-name
3976 "Save %s in file" filename
3977 gnus-file-save-name gnus-newsgroup-name
3978 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3979 (gnus-summary-save-in-file filename t))
3981 (put 'gnus-summary-save-body-in-file :decode t)
3982 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3983 "Append this article body to a file.
3984 Optional argument FILENAME specifies file name.
3985 The directory to save in defaults to `gnus-article-save-directory'."
3986 (setq filename (gnus-read-save-file-name
3987 "Save %s body in file" filename
3988 gnus-file-save-name gnus-newsgroup-name
3989 gnus-current-headers 'gnus-newsgroup-last-file))
3990 (with-current-buffer gnus-save-article-buffer
3994 (when (article-goto-body)
3995 (narrow-to-region (point) (point-max)))
3996 (when (and overwrite
3997 (file-exists-p filename))
3998 (delete-file filename))
3999 (gnus-output-to-file filename))))
4002 (put 'gnus-summary-write-body-to-file :decode t)
4003 (put 'gnus-summary-write-body-to-file
4004 :function 'gnus-summary-save-body-in-file)
4005 (defun gnus-summary-write-body-to-file (&optional filename)
4006 "Write this article body to a file, overwriting it if the file exists.
4007 Optional argument FILENAME specifies file name.
4008 The directory to save in defaults to `gnus-article-save-directory'."
4009 (setq filename (gnus-read-save-file-name
4010 "Save %s body in file" filename
4011 gnus-file-save-name gnus-newsgroup-name
4012 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4013 (gnus-summary-save-body-in-file filename t))
4015 (put 'gnus-summary-save-in-pipe :decode t)
4016 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4017 (defun gnus-summary-save-in-pipe (&optional command raw)
4018 "Pipe this article to subprocess COMMAND.
4019 Valid values for COMMAND include:
4021 The executable command name and possibly arguments.
4023 You will be prompted for the command in the minibuffer.
4024 the symbol `default'
4025 It will be replaced with the command which the variable
4026 `gnus-summary-pipe-output-default-command' holds or the command
4027 last used for saving.
4028 Non-nil value for RAW overrides `:decode' and `:headers' properties
4029 and the raw article including all headers will be piped."
4030 (let ((article (gnus-summary-article-number))
4032 (get 'gnus-summary-save-in-pipe :decode)))
4033 save-buffer default)
4035 (if (vectorp (gnus-summary-article-header article))
4036 (save-current-buffer
4037 (gnus-summary-select-article decode decode nil article)
4038 (insert-buffer-substring
4042 gnus-original-article-buffer)
4044 (nnheader-set-temp-buffer " *Gnus Save*"))))
4045 ;; Remove unwanted headers.
4046 (when (and (not raw)
4047 (or (get 'gnus-summary-save-in-pipe :headers)
4048 (not gnus-save-all-headers)))
4049 (let ((gnus-visible-headers
4050 (or (symbol-value (get 'gnus-summary-save-in-pipe
4052 gnus-saved-headers gnus-visible-headers))
4053 (gnus-summary-buffer nil))
4054 (article-hide-headers 1 t))))
4055 (error "%d is not a real article" article))
4056 (error "No article to pipe"))
4057 (setq default (or gnus-summary-pipe-output-default-command
4058 gnus-last-shell-command))
4059 (unless (stringp command)
4061 (if (and (eq command 'default) default)
4063 (gnus-read-shell-command "Shell command on this article: "
4065 (when (string-equal command "")
4067 (setq command default)
4068 (error "A command is required")))
4069 (with-current-buffer save-buffer
4072 (shell-command-on-region (point-min) (point-max) command nil)))
4073 (gnus-kill-buffer save-buffer))
4074 (setq gnus-summary-pipe-output-default-command command))
4076 (defun gnus-summary-pipe-to-muttprint (&optional command)
4077 "Pipe this article to muttprint."
4078 (unless (stringp command)
4079 (setq command (read-string
4080 "Print using command: " gnus-summary-muttprint-program
4081 nil gnus-summary-muttprint-program)))
4082 (let ((gnus-summary-pipe-output-default-command
4083 gnus-summary-pipe-output-default-command))
4084 (gnus-summary-save-in-pipe command))
4085 (setq gnus-summary-muttprint-program command))
4087 ;;; Article file names when saving.
4089 (defun gnus-capitalize-newsgroup (newsgroup)
4090 "Capitalize NEWSGROUP name."
4091 (when (not (zerop (length newsgroup)))
4092 (concat (char-to-string (upcase (aref newsgroup 0)))
4093 (substring newsgroup 1))))
4095 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4096 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4097 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4098 Otherwise, it is like ~/News/news/group/num."
4101 (concat (if (gnus-use-long-file-name 'not-save)
4102 (gnus-capitalize-newsgroup newsgroup)
4103 (gnus-newsgroup-directory-form newsgroup))
4104 "/" (int-to-string (mail-header-number headers)))
4105 gnus-article-save-directory)))
4107 (string-equal (file-name-directory default)
4108 (file-name-directory last-file))
4109 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4111 (or last-file default))))
4113 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4114 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4115 If variable `gnus-use-long-file-name' is non-nil, it is
4116 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4119 (concat (if (gnus-use-long-file-name 'not-save)
4121 (gnus-newsgroup-directory-form newsgroup))
4122 "/" (int-to-string (mail-header-number headers)))
4123 gnus-article-save-directory)))
4125 (string-equal (file-name-directory default)
4126 (file-name-directory last-file))
4127 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4129 (or last-file default))))
4131 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4132 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4133 If variable `gnus-use-long-file-name' is non-nil, it is
4134 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4137 (if (gnus-use-long-file-name 'not-save)
4140 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4142 gnus-article-save-directory)))
4144 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4145 "Generate file name from sender."
4146 (let ((from (mail-header-from headers)))
4148 (if (and from (string-match "\\([^ <]+\\)@" from))
4149 (match-string 1 from)
4151 gnus-article-save-directory)))
4153 (defun article-verify-x-pgp-sig ()
4155 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4157 (if (gnus-buffer-live-p gnus-original-article-buffer)
4158 (let ((sig (with-current-buffer gnus-original-article-buffer
4159 (gnus-fetch-field "X-PGP-Sig")))
4163 (mml2015-clear-verify-function))
4165 (insert-buffer-substring gnus-original-article-buffer)
4166 (setq items (split-string sig))
4167 (message-narrow-to-head)
4168 (let ((inhibit-point-motion-hooks t)
4169 (case-fold-search t))
4170 ;; Don't verify multiple headers.
4171 (setq headers (mapconcat (lambda (header)
4173 (mail-fetch-field header)
4175 (split-string (nth 1 items) ",") "")))
4176 (delete-region (point-min) (point-max))
4177 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4178 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4183 (if (looking-at "^-")
4186 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4187 (insert "Version: " (car items) "\n\n")
4188 (insert (mapconcat 'identity (cddr items) "\n"))
4189 (insert "\n-----END PGP SIGNATURE-----\n")
4190 (let ((mm-security-handle (list (format "multipart/signed"))))
4191 (mml2015-clean-buffer)
4192 (let ((coding-system-for-write (or gnus-newsgroup-charset
4194 (funcall (mml2015-clear-verify-function)))
4196 (or (mm-handle-multipart-ctl-parameter
4197 mm-security-handle 'gnus-details)
4198 (mm-handle-multipart-ctl-parameter
4199 mm-security-handle 'gnus-info)))))
4201 (let ((inhibit-read-only t) bface eface)
4203 (message-narrow-to-head)
4204 (goto-char (point-max))
4206 (setq bface (get-text-property (point-at-bol) 'face)
4207 eface (get-text-property (1- (point-at-eol)) 'face))
4208 (message-remove-header "X-Gnus-PGP-Verify")
4209 (if (re-search-forward "^X-PGP-Sig:" nil t)
4211 (goto-char (point-max)))
4212 (narrow-to-region (point) (point))
4213 (insert "X-Gnus-PGP-Verify: " info "\n")
4214 (goto-char (point-min))
4217 (if (not (looking-at "^[ \t]"))
4221 (goto-char (point-min))
4222 (when (looking-at "\\([^:]+\\): *")
4223 (put-text-property (match-beginning 1) (1+ (match-end 1))
4225 (put-text-property (match-end 0) (point-max)
4226 'face eface)))))))))
4228 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4230 (defun article-verify-cancel-lock ()
4231 "Verify Cancel-Lock header."
4233 (if (gnus-buffer-live-p gnus-original-article-buffer)
4234 (canlock-verify gnus-original-article-buffer)))
4241 (setq afunc (car func)
4244 gfunc (intern (format "gnus-%s" func))))
4246 (when (fboundp afunc)
4247 `(lambda (&optional interactive &rest args)
4248 ,(documentation afunc t)
4249 (interactive (list t))
4250 (with-current-buffer gnus-article-buffer
4252 (call-interactively ',afunc)
4253 (apply ',afunc args))))))))
4254 '(article-hide-headers
4255 article-verify-x-pgp-sig
4256 article-verify-cancel-lock
4257 article-hide-boring-headers
4258 article-treat-overstrike
4259 article-treat-ansi-sequences
4260 article-fill-long-lines
4261 article-capitalize-sentences
4263 article-remove-leading-whitespace
4264 article-display-x-face
4265 article-display-face
4266 article-de-quoted-unreadable
4267 article-de-base64-unreadable
4270 article-unsplit-urls
4271 article-hide-list-identifiers
4272 article-strip-banner
4275 article-hide-signature
4276 article-strip-headers-in-body
4277 article-remove-trailing-blank-lines
4278 article-strip-leading-blank-lines
4279 article-strip-multiple-blank-lines
4280 article-strip-leading-space
4281 article-strip-trailing-space
4282 article-strip-blank-lines
4283 article-strip-all-blank-lines
4285 article-date-english
4286 article-date-iso8601
4287 article-date-original
4290 article-decode-mime-words
4291 article-decode-charset
4292 article-decode-encoded-words
4295 article-date-combined-lapsed
4297 article-treat-dumbquotes
4298 article-treat-non-ascii
4299 article-normalize-headers
4300 ;;(article-show-all . gnus-article-show-all-headers)
4304 ;;; Gnus article mode
4307 (put 'gnus-article-mode 'mode-class 'special)
4309 (set-keymap-parent gnus-article-mode-map widget-keymap)
4311 (gnus-define-keys gnus-article-mode-map
4312 " " gnus-article-goto-next-page
4313 "\177" gnus-article-goto-prev-page
4314 [delete] gnus-article-goto-prev-page
4315 [backspace] gnus-article-goto-prev-page
4316 "\C-c^" gnus-article-refer-article
4317 "h" gnus-article-show-summary
4318 "s" gnus-article-show-summary
4319 "\C-c\C-m" gnus-article-mail
4320 "?" gnus-article-describe-briefly
4321 "<" beginning-of-buffer
4323 "\C-c\C-i" gnus-info-find-node
4325 "R" gnus-article-reply-with-original
4326 "F" gnus-article-followup-with-original
4327 "\C-hk" gnus-article-describe-key
4328 "\C-hc" gnus-article-describe-key-briefly
4329 "\C-hb" gnus-article-describe-bindings
4331 "e" gnus-article-read-summary-keys
4332 "\C-d" gnus-article-read-summary-keys
4333 "\M-*" gnus-article-read-summary-keys
4334 "\M-#" gnus-article-read-summary-keys
4335 "\M-^" gnus-article-read-summary-keys
4336 "\M-g" gnus-article-read-summary-keys)
4338 (substitute-key-definition
4339 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4341 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4342 "W" gnus-article-wide-reply-with-original)
4343 (if (featurep 'xemacs)
4344 (set-keymap-default-binding gnus-article-send-map
4345 'gnus-article-read-summary-send-keys)
4346 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4348 (defun gnus-article-make-menu-bar ()
4349 (unless (boundp 'gnus-article-commands-menu)
4350 (gnus-summary-make-menu-bar))
4351 (unless (boundp 'gnus-article-article-menu)
4353 gnus-article-article-menu gnus-article-mode-map ""
4355 ["Scroll forwards" gnus-article-goto-next-page t]
4356 ["Scroll backwards" gnus-article-goto-prev-page t]
4357 ["Show summary" gnus-article-show-summary t]
4358 ["Fetch Message-ID at point" gnus-article-refer-article t]
4359 ["Mail to address at point" gnus-article-mail t]
4360 ["Send a bug report" gnus-bug t]))
4363 gnus-article-treatment-menu gnus-article-mode-map ""
4364 ;; Fixme: this should use :active (and maybe :visible).
4366 ["Hide headers" gnus-article-hide-headers t]
4367 ["Hide signature" gnus-article-hide-signature t]
4368 ["Hide citation" gnus-article-hide-citation t]
4369 ["Treat overstrike" gnus-article-treat-overstrike t]
4370 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4371 ["Remove carriage return" gnus-article-remove-cr t]
4372 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4373 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4374 ["Remove base64" gnus-article-de-base64-unreadable t]
4375 ["Treat html" gnus-article-wash-html t]
4376 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4377 ["Decode HZ" gnus-article-decode-HZ t]))
4379 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4381 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4383 (gnus-run-hooks 'gnus-article-menu-hook)))
4385 (defvar bookmark-make-record-function)
4387 (defun gnus-article-mode ()
4388 "Major mode for displaying an article.
4390 All normal editing commands are switched off.
4392 The following commands are available in addition to all summary mode
4394 \\<gnus-article-mode-map>
4395 \\[gnus-article-next-page]\t Scroll the article one page forwards
4396 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4397 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4398 \\[gnus-article-show-summary]\t Display the summary buffer
4399 \\[gnus-article-mail]\t Send a reply to the address near point
4400 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4401 \\[gnus-info-find-node]\t Go to the Gnus info node"
4403 (kill-all-local-variables)
4404 (gnus-simplify-mode-line)
4405 (setq mode-name "Article")
4406 (setq major-mode 'gnus-article-mode)
4407 (make-local-variable 'minor-mode-alist)
4408 (use-local-map gnus-article-mode-map)
4409 (when (gnus-visual-p 'article-menu 'menu)
4410 (gnus-article-make-menu-bar)
4411 (when gnus-summary-tool-bar-map
4412 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4413 (gnus-update-format-specifications nil 'article-mode)
4414 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4415 (set (make-local-variable 'gnus-page-broken) nil)
4416 (make-local-variable 'gnus-article-current-summary)
4417 (make-local-variable 'gnus-article-mime-handles)
4418 (make-local-variable 'gnus-article-decoded-p)
4419 (make-local-variable 'gnus-article-mime-handle-alist)
4420 (make-local-variable 'gnus-article-wash-types)
4421 (make-local-variable 'gnus-article-image-alist)
4422 (make-local-variable 'gnus-article-charset)
4423 (make-local-variable 'gnus-article-ignored-charsets)
4424 (set (make-local-variable 'bookmark-make-record-function)
4425 'gnus-summary-bookmark-make-record)
4426 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4428 (set (make-local-variable 'nobreak-char-display) nil)
4429 (setq cursor-in-non-selected-windows nil)
4430 (gnus-set-default-directory)
4431 (buffer-disable-undo)
4432 (setq buffer-read-only t
4433 show-trailing-whitespace nil)
4434 (set-syntax-table gnus-article-mode-syntax-table)
4435 (mm-enable-multibyte)
4436 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4438 (defun gnus-article-setup-buffer ()
4439 "Initialize the article buffer."
4440 (let* ((name (if gnus-single-article-buffer "*Article*"
4441 (concat "*Article " gnus-newsgroup-name "*")))
4443 (progn (string-match "\\*Article" name)
4444 (concat " *Original Article"
4445 (substring name (match-end 0))))))
4446 (setq gnus-article-buffer name)
4447 (setq gnus-original-article-buffer original)
4448 (setq gnus-article-mime-handle-alist nil)
4449 (with-current-buffer gnus-summary-buffer
4450 ;; This might be a variable local to the summary buffer.
4451 (unless gnus-single-article-buffer
4452 (setq gnus-article-buffer name)
4453 (setq gnus-original-article-buffer original)
4454 (gnus-set-global-variables)))
4455 (gnus-article-setup-highlight-words)
4456 ;; Init original article buffer.
4457 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4458 (mm-enable-multibyte)
4459 (setq major-mode 'gnus-original-article-mode)
4460 (make-local-variable 'gnus-original-article))
4461 (if (and (get-buffer name)
4462 (with-current-buffer name
4463 (if gnus-article-edit-mode
4464 (if (y-or-n-p "Article mode edit in progress; discard? ")
4466 (set-buffer-modified-p nil)
4467 (gnus-kill-buffer name)
4470 (error "Action aborted"))
4472 (with-current-buffer name
4473 (set (make-local-variable 'gnus-article-edit-mode) nil)
4474 (when gnus-article-mime-handles
4475 (mm-destroy-parts gnus-article-mime-handles)
4476 (setq gnus-article-mime-handles nil))
4477 ;; Set it to nil in article-buffer!
4478 (setq gnus-article-mime-handle-alist nil)
4479 (buffer-disable-undo)
4480 (setq buffer-read-only t)
4481 (unless (eq major-mode 'gnus-article-mode)
4482 (gnus-article-mode))
4483 (setq truncate-lines gnus-article-truncate-lines)
4485 (with-current-buffer (gnus-get-buffer-create name)
4487 (setq truncate-lines gnus-article-truncate-lines)
4488 (make-local-variable 'gnus-summary-buffer)
4489 (setq gnus-summary-buffer
4490 (gnus-summary-buffer-name gnus-newsgroup-name))
4491 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4493 ((and gnus-article-update-date-headers
4494 (not article-lapsed-timer))
4495 (gnus-start-date-timer gnus-article-update-date-headers))
4496 ((and (not gnus-article-update-date-headers)
4497 article-lapsed-timer)
4498 (gnus-stop-date-timer)))
4499 (current-buffer)))))
4501 ;; Set article window start at LINE, where LINE is the number of lines
4502 ;; from the head of the article.
4503 (defun gnus-article-set-window-start (&optional line)
4504 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4505 (when article-window
4508 (with-current-buffer gnus-article-buffer
4509 (goto-char (point-min))
4512 (gnus-message 6 "Moved to bookmark")
4513 (search-forward "\n\n" nil t)
4517 (defun gnus-article-prepare (article &optional all-headers header)
4518 "Prepare ARTICLE in article mode buffer.
4519 ARTICLE should either be an article number or a Message-ID.
4520 If ARTICLE is an id, HEADER should be the article headers.
4521 If ALL-HEADERS is non-nil, no headers are hidden."
4523 ;; Make sure we start in a summary buffer.
4524 (unless (eq major-mode 'gnus-summary-mode)
4525 (set-buffer gnus-summary-buffer))
4526 (setq gnus-summary-buffer (current-buffer))
4527 (let* ((gnus-article (if header (mail-header-number header) article))
4528 (summary-buffer (current-buffer))
4529 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4530 (group gnus-newsgroup-name)
4533 (gnus-article-setup-buffer)
4534 (set-buffer gnus-article-buffer)
4535 ;; Deactivate active regions.
4536 (when (and (boundp 'transient-mark-mode)
4537 transient-mark-mode)
4538 (setq mark-active nil))
4539 (if (not (setq result (let ((inhibit-read-only t))
4540 (gnus-request-article-this-buffer
4542 ;; There is no such article.
4544 (when (and (numberp article)
4545 (not (memq article gnus-newsgroup-sparse)))
4546 (setq gnus-article-current
4547 (cons gnus-newsgroup-name article))
4548 (set-buffer gnus-summary-buffer)
4549 (setq gnus-current-article article)
4550 (if (and (memq article gnus-newsgroup-undownloaded)
4551 (not (gnus-online (gnus-find-method-for-group
4552 gnus-newsgroup-name))))
4554 (gnus-summary-set-agent-mark article)
4555 (message "Message marked for downloading"))
4556 (gnus-summary-mark-article article gnus-canceled-mark)
4557 (unless (memq article gnus-newsgroup-sparse)
4558 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4559 (if (or (eq result 'pseudo)
4560 (eq result 'nneething))
4562 (with-current-buffer summary-buffer
4563 (push article gnus-newsgroup-history)
4564 (setq gnus-last-article gnus-current-article
4565 gnus-current-article 0
4566 gnus-current-headers nil
4567 gnus-article-current nil)
4568 (if (eq result 'nneething)
4569 (gnus-configure-windows 'summary)
4570 (gnus-configure-windows 'article))
4571 (gnus-set-global-variables))
4572 (let ((gnus-article-mime-handle-alist-1
4573 gnus-article-mime-handle-alist))
4574 (gnus-set-mode-line 'article)))
4575 ;; The result from the `request' was an actual article -
4576 ;; or at least some text that is now displayed in the
4578 (when (and (numberp article)
4579 (not (eq article gnus-current-article)))
4580 ;; Seems like a new article has been selected.
4581 ;; `gnus-current-article' must be an article number.
4582 (with-current-buffer summary-buffer
4583 (push article gnus-newsgroup-history)
4584 (setq gnus-last-article gnus-current-article
4585 gnus-current-article article
4586 gnus-current-headers
4587 (gnus-summary-article-header gnus-current-article)
4588 gnus-article-current
4589 (cons gnus-newsgroup-name gnus-current-article))
4590 (unless (vectorp gnus-current-headers)
4591 (setq gnus-current-headers nil))
4592 (gnus-summary-goto-subject gnus-current-article)
4593 (when (gnus-summary-show-thread)
4594 ;; If the summary buffer really was folded, the
4595 ;; previous goto may not actually have gone to
4596 ;; the right article, but the thread root instead.
4598 (gnus-summary-goto-subject gnus-current-article))
4599 (gnus-run-hooks 'gnus-mark-article-hook)
4600 (gnus-set-mode-line 'summary)
4601 (when (gnus-visual-p 'article-highlight 'highlight)
4602 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4603 ;; Set the global newsgroup variables here.
4604 (gnus-set-global-variables)
4605 (setq gnus-have-all-headers
4606 (or all-headers gnus-show-all-headers))))
4608 (gnus-configure-windows 'article))
4609 (when (or (numberp article)
4611 (gnus-article-prepare-display)
4613 (goto-char (point-min))
4614 (when gnus-break-pages
4615 (gnus-narrow-to-page)))
4616 (let ((gnus-article-mime-handle-alist-1
4617 gnus-article-mime-handle-alist))
4618 (gnus-set-mode-line 'article))
4622 (set-window-point (get-buffer-window (current-buffer)) (point))
4623 (gnus-configure-windows 'article)
4627 (defun gnus-article-prepare-display ()
4628 "Make the current buffer look like a nice article."
4629 ;; Hooks for getting information from the article.
4630 ;; This hook must be called before being narrowed.
4631 (let ((gnus-article-buffer (current-buffer))
4633 (inhibit-read-only t))
4634 (unless (eq major-mode 'gnus-article-mode)
4635 (gnus-article-mode))
4636 (setq buffer-read-only nil
4637 gnus-article-wash-types nil
4638 gnus-article-image-alist nil)
4639 (gnus-run-hooks 'gnus-tmp-internal-hook)
4640 (when gnus-display-mime-function
4641 (funcall gnus-display-mime-function))
4642 (gnus-run-hooks 'gnus-article-prepare-hook)))
4645 ;;; Gnus Sticky Article Mode
4648 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4649 "Mode for sticky articles."
4650 ;; Release bindings that won't work.
4651 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4652 gnus-sticky-article-mode-map)
4653 (substitute-key-definition 'gnus-article-refer-article 'undefined
4654 gnus-sticky-article-mode-map)
4655 (dolist (k '("e" "h" "s" "F" "R"))
4656 (define-key gnus-sticky-article-mode-map k nil))
4657 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4658 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4659 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4660 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4662 (defun gnus-sticky-article (arg)
4663 "Make the current article sticky.
4664 If a prefix ARG is given, ask for a name for this sticky article buffer."
4666 (gnus-summary-show-thread)
4667 (gnus-summary-select-article nil nil 'pseudo)
4668 (let (new-art-buf-name)
4669 (gnus-eval-in-buffer-window gnus-article-buffer
4670 (setq new-art-buf-name
4674 (read-from-minibuffer "Sticky article buffer name: ")
4675 (gnus-with-article-headers
4676 (gnus-article-goto-header "subject")
4677 (setq new-art-buf-name
4678 (buffer-substring-no-properties
4679 (line-beginning-position) (line-end-position)))
4680 (goto-char (point-min))
4681 (gnus-article-goto-header "from")
4682 (setq new-art-buf-name
4684 new-art-buf-name ", "
4685 (buffer-substring-no-properties
4686 (line-beginning-position) (line-end-position))))
4687 (goto-char (point-min))
4688 (gnus-article-goto-header "date")
4689 (setq new-art-buf-name
4691 new-art-buf-name ", "
4692 (buffer-substring-no-properties
4693 (line-beginning-position) (line-end-position))))))
4695 (if (and (gnus-buffer-live-p new-art-buf-name)
4696 (with-current-buffer new-art-buf-name
4697 (eq major-mode 'gnus-sticky-article-mode)))
4698 (switch-to-buffer new-art-buf-name)
4699 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4700 (gnus-sticky-article-mode))
4701 (setq gnus-article-buffer new-art-buf-name))
4702 (gnus-summary-recenter)
4703 (gnus-summary-position-point))
4705 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4706 "Kill the given sticky article BUFFER.
4707 If none is given, assume the current buffer and kill it if it has
4708 `gnus-sticky-article-mode'."
4711 (setq buffer (current-buffer)))
4712 (with-current-buffer buffer
4713 (when (eq major-mode 'gnus-sticky-article-mode)
4714 (gnus-kill-buffer buffer))))
4716 (defun gnus-kill-sticky-article-buffers (arg)
4717 "Kill all sticky article buffers.
4718 If a prefix ARG is given, ask for confirmation."
4720 (dolist (buf (gnus-buffers))
4721 (with-current-buffer buf
4722 (when (eq major-mode 'gnus-sticky-article-mode)
4724 (gnus-kill-buffer buf)
4725 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4726 (gnus-kill-buffer buf)))))))
4729 ;;; Gnus MIME viewing functions
4732 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4733 "Format of the MIME buttons.
4735 Valid specifiers include:
4737 %T MIME type, along with additional info
4738 %n The `name' parameter
4739 %d The description, if any
4740 %l The length of the encoded part
4741 %p The part identifier number
4742 %e Dots if the part isn't displayed
4744 General format specifiers can also be used. See Info node
4745 `(gnus)Formatting Variables'.")
4747 (defvar gnus-mime-button-line-format-alist
4748 '((?t gnus-tmp-type ?s)
4749 (?T gnus-tmp-type-long ?s)
4750 (?n gnus-tmp-name ?s)
4751 (?d gnus-tmp-description ?s)
4753 (?l gnus-tmp-length ?d)
4754 (?e gnus-tmp-dots ?s)))
4756 (defvar gnus-mime-button-commands
4757 '((gnus-article-press-button "\r" "Toggle Display")
4758 (gnus-mime-view-part "v" "View Interactively...")
4759 (gnus-mime-view-part-as-type "t" "View As Type...")
4760 (gnus-mime-view-part-as-charset "C" "View As charset...")
4761 (gnus-mime-save-part "o" "Save...")
4762 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4763 (gnus-mime-replace-part "r" "Replace part")
4764 (gnus-mime-delete-part "d" "Delete part")
4765 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4766 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4767 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4768 (gnus-mime-view-part-externally "e" "View Externally")
4769 (gnus-mime-print-part "p" "Print")
4770 (gnus-mime-pipe-part "|" "Pipe To Command...")
4771 (gnus-mime-action-on-part "." "Take action on the part...")))
4773 (defun gnus-article-mime-part-status ()
4774 (if gnus-article-mime-handle-alist-1
4775 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4777 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4780 (defvar gnus-mime-button-map
4781 (let ((map (make-sparse-keymap)))
4782 (define-key map gnus-mouse-2 'gnus-article-push-button)
4783 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4784 (dolist (c gnus-mime-button-commands)
4785 (define-key map (cadr c) (car c)))
4789 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4791 ,@(mapcar (lambda (c)
4792 (vector (caddr c) (car c) :active t))
4793 gnus-mime-button-commands)))
4795 (defvar gnus-url-button-commands
4796 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4798 (defvar gnus-url-button-map
4799 (let ((map (make-sparse-keymap)))
4800 (dolist (c gnus-url-button-commands)
4801 (define-key map (cadr c) (car c)))
4805 gnus-url-button-menu gnus-url-button-map "URL button menu."
4807 ,@(mapcar (lambda (c)
4808 (vector (caddr c) (car c) :active t))
4809 gnus-url-button-commands)))
4811 (defmacro gnus-bind-safe-url-regexp (&rest body)
4812 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4813 `(let ((mm-w3m-safe-url-regexp
4814 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4816 gnus-article-current-summary))
4817 (with-current-buffer gnus-article-current-summary
4818 gnus-newsgroup-name)
4819 gnus-newsgroup-name)))
4820 (if (cond ((not group)
4821 ;; Maybe we're in a mml-preview buffer
4822 ;; and no group is selected.
4824 ((stringp gnus-safe-html-newsgroups)
4825 (string-match gnus-safe-html-newsgroups group))
4826 ((consp gnus-safe-html-newsgroups)
4827 (member group gnus-safe-html-newsgroups)))
4829 mm-w3m-safe-url-regexp))))
4832 (defun gnus-mime-button-menu (event prefix)
4833 "Construct a context-sensitive menu of MIME commands."
4834 (interactive "e\nP")
4835 (save-window-excursion
4836 (let ((pos (event-start event)))
4837 (select-window (posn-window pos))
4838 (goto-char (posn-point pos))
4839 (gnus-article-check-buffer)
4840 (popup-menu gnus-mime-button-menu nil prefix))))
4842 (defun gnus-mime-view-all-parts (&optional handles)
4843 "View all the MIME parts."
4845 (with-current-buffer gnus-article-buffer
4846 (let ((handles (or handles gnus-article-mime-handles))
4847 (mail-parse-charset gnus-newsgroup-charset)
4848 (mail-parse-ignored-charsets
4849 (with-current-buffer gnus-summary-buffer
4850 gnus-newsgroup-ignored-charsets)))
4852 (mm-remove-parts handles)
4853 (goto-char (point-min))
4854 (or (search-forward "\n\n") (goto-char (point-max)))
4855 (let ((inhibit-read-only t))
4856 (delete-region (point) (point-max))
4857 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4859 (defun gnus-article-jump-to-part (n)
4860 "Jump to MIME part N."
4862 (let ((parts (with-current-buffer gnus-article-buffer
4863 (length gnus-article-mime-handle-alist))))
4865 (error "No such part"))
4866 (pop-to-buffer gnus-article-buffer)
4867 ;; FIXME: why is it necessary?
4870 (setq n (if (= parts 1)
4872 (read-number (format "Jump to part (1..%s): " parts)))))
4873 (unless (and (integerp n) (<= n parts) (>= n 1))
4876 (gnus-message 7 "Invalid part `%s', using %s instead."
4879 (gnus-message 9 "Jumping to part %s." n)
4880 (cond ((>= gnus-auto-select-part 1)
4881 (while (and (<= n parts)
4882 (not (gnus-article-goto-part n)))
4884 ((< gnus-auto-select-part 0)
4885 (while (and (>= n 1)
4886 (not (gnus-article-goto-part n)))
4889 (gnus-article-goto-part n)))))
4891 (defvar gnus-mime-buttonized-part-id nil
4892 "ID of a mime part that should be buttonized.
4893 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4896 (defsubst gnus-article-edit-part (handles &optional current-id)
4897 "Edit an article in order to delete a mime part.
4898 This function is exclusively used by `gnus-mime-save-part-and-strip'
4899 and `gnus-mime-delete-part', and not provided at run-time normally."
4900 (gnus-article-edit-article
4902 (buffer-disable-undo)
4904 (let ((mail-parse-charset (or gnus-article-charset
4905 ',gnus-newsgroup-charset))
4906 (mail-parse-ignored-charsets
4907 (or gnus-article-ignored-charsets
4908 ',gnus-newsgroup-ignored-charsets))
4909 (mbl mml-buffer-list))
4910 (setq mml-buffer-list nil)
4911 (insert-buffer-substring gnus-original-article-buffer)
4912 (mime-to-mml ',handles)
4913 (setq gnus-article-mime-handles nil)
4914 (let ((mbl1 mml-buffer-list))
4915 (setq mml-buffer-list mbl)
4916 (set (make-local-variable 'mml-buffer-list) mbl1))
4917 (gnus-make-local-hook 'kill-buffer-hook)
4918 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4919 `(lambda (no-highlight)
4920 (let ((mail-parse-charset (or gnus-article-charset
4921 ',gnus-newsgroup-charset))
4922 (message-options message-options)
4923 (message-options-set-recipient)
4924 (mail-parse-ignored-charsets
4925 (or gnus-article-ignored-charsets
4926 ',gnus-newsgroup-ignored-charsets)))
4928 (mml-destroy-buffers)
4929 (remove-hook 'kill-buffer-hook
4930 'mml-destroy-buffers t)
4931 (kill-local-variable 'mml-buffer-list))
4932 (gnus-summary-edit-article-done
4933 ,(or (mail-header-references gnus-current-headers) "")
4934 ,(gnus-group-read-only-p)
4935 ,gnus-summary-buffer no-highlight))
4937 ;; Force buttonizing this part.
4938 (let ((gnus-mime-buttonized-part-id current-id))
4939 (gnus-article-edit-done))
4940 (gnus-configure-windows 'article)
4941 (when (and current-id (integerp gnus-auto-select-part))
4942 (gnus-article-jump-to-part
4943 (min (max (+ current-id gnus-auto-select-part) 1)
4944 (with-current-buffer gnus-article-buffer
4945 (length gnus-article-mime-handle-alist)))))))
4947 (defun gnus-mime-replace-part (file)
4948 "Replace MIME part under point with an external body."
4949 ;; Useful if file has already been saved to disk
4952 (read-file-name "Replace MIME part with file: "
4953 (or mm-default-directory default-directory)
4955 (gnus-mime-save-part-and-strip file))
4957 (defun gnus-mime-save-part-and-strip (&optional file)
4958 "Save the MIME part under point then replace it with an external body.
4959 If FILE is given, use it for the external part."
4961 (gnus-article-check-buffer)
4962 (when (gnus-group-read-only-p)
4963 (error "The current group does not support deleting of parts"))
4964 (when (mm-complicated-handles gnus-article-mime-handles)
4966 The current article has a complicated MIME structure, giving up..."))
4967 (let* ((data (get-text-property (point) 'gnus-data))
4968 (id (get-text-property (point) 'gnus-part))
4970 (handles gnus-article-mime-handles))
4973 (and data (mm-save-part data "Delete MIME part and save to: "))))
4975 (with-current-buffer (mm-handle-buffer data)
4977 (insert "Content-Type: " (mm-handle-media-type data))
4978 (mml-insert-parameter-string (cdr (mm-handle-type data))
4980 ;; Add a filename for the sake of saving the part again.
4981 (mml-insert-parameter
4982 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4984 (insert "Content-ID: " (message-make-message-id) "\n")
4985 (insert "Content-Transfer-Encoding: binary\n")
4988 (cdr (mm-make-handle nil
4989 `("message/external-body"
4990 (access-type . "LOCAL-FILE")
4992 ;; (set-buffer gnus-summary-buffer)
4993 (gnus-article-edit-part handles id))))
4995 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4996 ;; parts...>') but with stripping would be nice.
4998 (defun gnus-mime-delete-part ()
4999 "Delete the MIME part under point.
5000 Replace it with some information about the removed part."
5002 (gnus-article-check-buffer)
5003 (when (gnus-group-read-only-p)
5004 (error "The current group does not support deleting of parts"))
5005 (when (mm-complicated-handles gnus-article-mime-handles)
5007 The current article has a complicated MIME structure, giving up..."))
5008 (when (or gnus-expert-user
5009 (gnus-yes-or-no-p "\
5010 Deleting parts may malfunction or destroy the article; continue? "))
5011 (let* ((data (get-text-property (point) 'gnus-data))
5012 (id (get-text-property (point) 'gnus-part))
5013 (handles gnus-article-mime-handles)
5016 (let ((desc (mm-handle-description data)))
5018 (mail-decode-encoded-word-string desc))))
5020 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5022 (type (mm-handle-media-type data)))
5024 (error "No MIME part under point"))
5025 (with-current-buffer (mm-handle-buffer data)
5026 (let ((bsize (buffer-size)))
5031 "| The following attachment has been deleted:\n"
5033 "| Type: " type "\n"
5034 "| Filename: " filename "\n"
5035 "| Size (encoded): " (format "%s byte%s\n"
5036 bsize (if (= bsize 1)
5040 (concat "| Description: " description "\n"))
5043 (cdr (mm-make-handle
5044 nil `("text/plain" (charset . gnus-decoded)) nil nil
5046 (format "Deleted attachment (%s bytes)" bsize))))))
5047 ;; (set-buffer gnus-summary-buffer)
5048 (gnus-article-edit-part handles id))))
5050 (defun gnus-mime-save-part ()
5051 "Save the MIME part under point."
5053 (gnus-article-check-buffer)
5054 (let ((data (get-text-property (point) 'gnus-data)))
5056 (mm-save-part data))))
5058 (defun gnus-mime-pipe-part (&optional cmd)
5059 "Pipe the MIME part under point to a process.
5060 Use CMD as the process."
5062 (gnus-article-check-buffer)
5063 (let ((data (get-text-property (point) 'gnus-data)))
5065 (mm-pipe-part data cmd))))
5067 (defun gnus-mime-view-part ()
5068 "Interactively choose a viewing method for the MIME part under point."
5070 (gnus-article-check-buffer)
5071 (let ((data (get-text-property (point) 'gnus-data)))
5073 (setq gnus-article-mime-handles
5075 gnus-article-mime-handles (setq data (copy-sequence data))))
5076 (mm-interactively-view-part data))))
5078 (defun gnus-mime-view-part-as-type-internal ()
5079 (gnus-article-check-buffer)
5080 (let* ((handle (get-text-property (point) 'gnus-data))
5082 ;; Content-Type: foo/bar; name=...
5083 (mail-content-type-get (mm-handle-type handle) 'name)
5084 ;; Content-Disposition: attachment; filename=...
5085 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5086 (def-type (and name (mm-default-file-encoding name))))
5087 (or (and def-type (cons def-type 0))
5089 (equal (mm-handle-media-supertype handle) "text")
5090 '("text/plain" . 0))
5091 '("application/octet-stream" . 0))))
5093 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5094 "Choose a MIME media type, and view the part as such.
5095 If non-nil, PRED is a predicate to use during completion to limit the
5096 available media-types."
5100 (let ((default (gnus-mime-view-part-as-type-internal)))
5101 (gnus-completing-read
5104 (gnus-remove-if-not pred (mailcap-mime-types))
5105 (mailcap-mime-types))
5108 (gnus-article-check-buffer)
5109 (let ((handle (get-text-property (point) 'gnus-data)))
5111 (when (equal (mm-handle-media-type handle) "message/external-body")
5112 (unless (mm-handle-cache handle)
5113 (mm-extern-cache-contents handle))
5114 (setq handle (mm-handle-cache handle)))
5116 (mm-make-handle (mm-handle-buffer handle)
5117 (cons mime-type (cdr (mm-handle-type handle)))
5118 (mm-handle-encoding handle)
5119 (mm-handle-undisplayer handle)
5120 (mm-handle-disposition handle)
5121 (mm-handle-description handle)
5123 (mm-handle-id handle)))
5124 (setq gnus-article-mime-handles
5125 (mm-merge-handles gnus-article-mime-handles handle))
5126 (when (mm-handle-displayed-p handle)
5127 (mm-remove-part handle))
5128 (gnus-mm-display-part handle))))
5130 (defun gnus-mime-copy-part (&optional handle arg)
5131 "Put the MIME part under point into a new buffer.
5132 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5134 (interactive (list nil current-prefix-arg))
5135 (gnus-article-check-buffer)
5137 (setq handle (get-text-property (point) 'gnus-data)))
5139 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5141 (mail-content-type-get (mm-handle-disposition handle)
5143 contents dont-decode charset coding-system)
5144 (mm-with-unibyte-buffer
5145 (mm-insert-part handle)
5146 (setq contents (or (condition-case nil
5147 (mm-decompress-buffer filename nil 'sig)
5149 (setq dont-decode t)
5152 (setq filename (cond (filename (file-name-nondirectory filename))
5153 (dont-decode "*raw data*")
5158 (unless (setq charset (mail-content-type-get
5159 (mm-handle-type handle) 'charset))
5160 (unless (setq coding-system (mm-with-unibyte-buffer
5162 (mm-find-buffer-file-coding-system)))
5163 (setq charset gnus-newsgroup-charset))))
5165 (setq charset (or (cdr (assq arg
5166 gnus-summary-show-article-charset-alist))
5167 (mm-read-coding-system "Charset: ")))))
5168 (switch-to-buffer (generate-new-buffer filename))
5169 (if (or coding-system
5171 (setq coding-system (mm-charset-to-coding-system charset))
5172 (not (eq coding-system 'ascii))))
5174 (mm-enable-multibyte)
5175 (insert (mm-decode-coding-string contents coding-system))
5176 (setq buffer-file-coding-system
5177 (if (boundp 'last-coding-system-used)
5178 (symbol-value 'last-coding-system-used)
5180 (mm-disable-multibyte)
5182 (setq buffer-file-coding-system mm-binary-coding-system))
5183 ;; We do it this way to make `normal-mode' set the appropriate mode.
5186 (setq buffer-file-name (expand-file-name filename))
5188 (setq buffer-file-name nil))
5189 (goto-char (point-min)))))
5191 (defun gnus-mime-print-part (&optional handle filename)
5192 "Print the MIME part under point."
5193 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5194 (gnus-article-check-buffer)
5195 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5196 (contents (and handle (mm-get-part handle)))
5197 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5198 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5203 (mm-save-part-to-file handle file)
5204 (call-process shell-file-name nil
5205 (generate-new-buffer " *mm*")
5207 shell-command-switch
5209 printer file (mm-handle-type handle))))
5213 (gnus-print-buffer))
5214 (ps-despool filename)))))
5216 (defun gnus-mime-inline-part (&optional handle arg)
5217 "Insert the MIME part under point into the current buffer.
5218 Compressed files like .gz and .bz2 are decompressed."
5219 (interactive (list nil current-prefix-arg))
5220 (gnus-article-check-buffer)
5222 (setq handle (get-text-property (point) 'gnus-data)))
5225 (inhibit-read-only t)
5226 contents charset coding-system)
5227 (if (and (not arg) (mm-handle-undisplayer handle))
5228 (mm-remove-part handle)
5229 (mm-with-unibyte-buffer
5230 (mm-insert-part handle)
5232 (or (mm-decompress-buffer
5233 (or (mail-content-type-get (mm-handle-type handle)
5235 (mail-content-type-get (mm-handle-disposition handle)
5241 (unless (setq charset (mail-content-type-get
5242 (mm-handle-type handle) 'charset))
5243 (unless (setq coding-system
5244 (mm-with-unibyte-buffer
5246 (mm-find-buffer-file-coding-system)))
5247 (setq charset gnus-newsgroup-charset))))
5249 (if (mm-handle-undisplayer handle)
5250 (mm-remove-part handle))
5253 gnus-summary-show-article-charset-alist))
5254 (mm-read-coding-system "Charset: "))))
5256 (if (mm-handle-undisplayer handle)
5257 (mm-remove-part handle))))
5259 (mm-display-inline handle)
5262 (defun gnus-mime-set-charset-parameters (handle charset)
5263 "Set CHARSET to parameters in HANDLE.
5264 CHARSET may either be a string or a symbol."
5265 (unless (stringp charset)
5266 (setq charset (symbol-name charset)))
5267 (if (stringp (car handle))
5268 (dolist (h (cdr handle))
5269 (gnus-mime-set-charset-parameters h charset))
5270 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5271 "message/external-body")
5273 (unless (mm-handle-cache handle)
5274 (mm-extern-cache-contents handle))
5275 (mm-handle-cache handle))
5277 (param (assq 'charset (cdr type))))
5279 (setcdr param charset)
5280 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5282 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5283 "Insert the MIME part under point into the current buffer using the
5285 (interactive (list nil current-prefix-arg))
5286 (gnus-article-check-buffer)
5287 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5288 (fun (get-text-property (point) 'gnus-callback))
5289 (gnus-newsgroup-ignored-charsets 'gnus-all)
5290 charset form preferred parts)
5297 gnus-summary-show-article-charset-alist))
5298 (mm-read-coding-system "Charset: "))))
5299 (if (mm-handle-undisplayer handle)
5300 (mm-remove-part handle)))
5301 (gnus-mime-set-charset-parameters handle charset)
5302 (when (and (consp (setq form (cdr-safe fun)))
5303 (setq form (ignore-errors
5304 (assq 'gnus-mime-display-alternative form)))
5305 (setq preferred (caddr form))
5307 (when (eq (car preferred) 'quote)
5308 (setq preferred (cadr preferred)))
5309 (not (equal preferred
5310 (get-text-property (point) 'gnus-data))))
5311 (setq parts (get-text-property (point) 'gnus-part))
5312 (setq parts (cdr (assq parts
5313 gnus-article-mime-handle-alist)))
5314 (equal (mm-handle-media-type parts) "multipart/alternative")
5315 (setq parts (reverse (cdr parts))))
5317 (list 'quote (or (cadr (member preferred parts))
5319 (funcall fun handle)))))
5321 (defun gnus-mime-view-part-externally (&optional handle)
5322 "View the MIME part under point with an external viewer."
5324 (gnus-article-check-buffer)
5325 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5326 (mm-user-display-methods nil)
5327 (mm-inlined-types nil)
5328 (mail-parse-charset gnus-newsgroup-charset)
5329 (mail-parse-ignored-charsets
5330 (with-current-buffer gnus-summary-buffer
5331 gnus-newsgroup-ignored-charsets))
5332 (type (mm-handle-media-type handle))
5333 (method (mailcap-mime-info type))
5334 (mm-enable-external t))
5335 (if (not (stringp method))
5336 (gnus-mime-view-part-as-type
5337 nil (lambda (type) (stringp (mailcap-mime-info type))))
5339 (mm-display-part handle nil t)))))
5341 (defun gnus-mime-view-part-internally (&optional handle)
5342 "View the MIME part under point with an internal viewer.
5343 If no internal viewer is available, use an external viewer."
5345 (gnus-article-check-buffer)
5346 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5347 (mm-inlined-types '(".*"))
5348 (mm-inline-large-images t)
5349 (mail-parse-charset gnus-newsgroup-charset)
5350 (mail-parse-ignored-charsets
5351 (with-current-buffer gnus-summary-buffer
5352 gnus-newsgroup-ignored-charsets))
5353 (inhibit-read-only t))
5354 (if (not (mm-inlinable-p handle))
5355 (gnus-mime-view-part-as-type
5356 nil (lambda (type) (mm-inlinable-p handle type)))
5358 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5360 (defun gnus-mime-action-on-part (&optional action)
5361 "Do something with the MIME attachment at \(point\)."
5363 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5364 (gnus-article-check-buffer)
5365 (let ((action-pair (assoc action gnus-mime-action-alist)))
5367 (funcall (cdr action-pair)))))
5369 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5370 "Call FUNCTION on MIME part N.
5371 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5372 If INTERACTIVE, call FUNCTION interactivly."
5374 ;; Check whether the article is displayed.
5375 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5376 (setq window (get-buffer-window gnus-article-buffer t))
5377 (frame-visible-p (setq frame (window-frame window))))
5378 (error "No article is displayed"))
5379 (with-current-buffer gnus-article-buffer
5380 ;; Check whether the article displays the right contents.
5381 (unless (with-current-buffer gnus-summary-buffer
5382 (eq gnus-current-article (gnus-summary-article-number)))
5383 (error "You should select the right article first"))
5385 (setq n (prefix-numeric-value n))
5387 (setq n (or (get-text-property pt 'gnus-part)
5389 (get-text-property (1- pt) 'gnus-part))
5390 (get-text-property (prog2
5396 (or (and (setq pt (previous-single-property-change
5399 (next-single-property-change (point) 'gnus-part)
5403 ;; Check whether the specified part exists.
5404 (when (> n (length gnus-article-mime-handle-alist))
5405 (error "No such part")))
5408 ;; To select the window is needed so that the cursor
5409 ;; might be visible on the MIME button.
5410 (select-window (prog1
5412 (setq window (selected-window))
5413 ;; Article may be displayed in the other frame.
5414 (gnus-select-frame-set-input-focus
5417 (setq frame (selected-frame))))))
5418 (when (gnus-article-goto-part n)
5419 ;; We point the cursor and the arrow at the MIME button
5420 ;; when the `function' prompt the user for something.
5421 (unless (and (pos-visible-in-window-p)
5422 (> (count-lines (point) (window-end))
5423 (/ (1- (window-height)) 3)))
5424 (recenter (/ (1- (window-height)) 3)))
5425 (let ((cursor-in-non-selected-windows t)
5426 (overlay-arrow-string "=>")
5427 (overlay-arrow-position (point-marker)))
5430 ((and no-handle interactive)
5431 (call-interactively function))
5436 function (get-text-property (point) 'gnus-data)))
5439 (get-text-property (point) 'gnus-data))))
5440 (set-marker overlay-arrow-position nil)
5441 (unless gnus-auto-select-part
5442 (gnus-select-frame-set-input-focus frame)
5443 (select-window window))))
5445 (if gnus-inhibit-mime-unbuttonizing
5446 ;; This is the default though the program shouldn't reach here.
5447 (error "No such part")
5448 ;; The part which doesn't have the MIME button is selected.
5449 ;; So, we display all the buttons and redo it.
5450 (let ((gnus-inhibit-mime-unbuttonizing t))
5451 (gnus-summary-show-article)
5452 (gnus-article-part-wrapper n function no-handle))))))
5454 (defun gnus-article-pipe-part (n)
5455 "Pipe MIME part N, which is the numerical prefix."
5457 (gnus-article-part-wrapper n 'mm-pipe-part))
5459 (defun gnus-article-save-part (n)
5460 "Save MIME part N, which is the numerical prefix."
5462 (gnus-article-part-wrapper n 'mm-save-part))
5464 (defun gnus-article-interactively-view-part (n)
5465 "View MIME part N interactively, which is the numerical prefix."
5467 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5469 (defun gnus-article-copy-part (n)
5470 "Copy MIME part N, which is the numerical prefix."
5472 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5474 (defun gnus-article-view-part-as-charset (n)
5475 "View MIME part N using a specified charset.
5476 N is the numerical prefix."
5478 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5480 (defun gnus-article-view-part-externally (n)
5481 "View MIME part N externally, which is the numerical prefix."
5483 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5485 (defun gnus-article-inline-part (n)
5486 "Inline MIME part N, which is the numerical prefix."
5488 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5490 (defun gnus-article-save-part-and-strip (n)
5491 "Save MIME part N and replace it with an external body.
5492 N is the numerical prefix."
5494 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5496 (defun gnus-article-replace-part (n)
5497 "Replace MIME part N with an external body.
5498 N is the numerical prefix."
5500 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5502 (defun gnus-article-delete-part (n)
5503 "Delete MIME part N and add some information about the removed part.
5504 N is the numerical prefix."
5506 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5508 (defun gnus-article-view-part-as-type (n)
5509 "Choose a MIME media type, and view part N as such.
5510 N is the numerical prefix."
5512 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5514 (defun gnus-article-mime-match-handle-first (condition)
5517 (dolist (ihandle gnus-article-mime-handle-alist)
5519 ((functionp condition)
5520 (funcall condition (cdr ihandle)))
5521 ((eq condition 'undisplayed)
5522 (not (or (mm-handle-undisplayer (cdr ihandle))
5523 (equal (mm-handle-media-type (cdr ihandle))
5524 "multipart/alternative"))))
5525 ((eq condition 'undisplayed-alternative)
5526 (not (mm-handle-undisplayer (cdr ihandle))))
5528 (gnus-article-goto-part (car ihandle))
5529 (or (not n) (< (car ihandle) n)))
5530 (setq n (car ihandle))))
5534 (defun gnus-article-view-part (&optional n)
5535 "View MIME part N, which is the numerical prefix.
5536 If the part is already shown, hide the part. If N is nil, view
5539 (with-current-buffer gnus-article-buffer
5540 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5541 gnus-article-mime-match-handle-function)))
5542 (when (> n (length gnus-article-mime-handle-alist))
5543 (error "No such part"))
5544 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5545 (when (gnus-article-goto-part n)
5546 (if (equal (car handle) "multipart/alternative")
5547 (gnus-article-press-button)
5548 (when (eq (gnus-mm-display-part handle) 'internal)
5549 (gnus-set-window-start)))))))
5551 (defsubst gnus-article-mime-total-parts ()
5552 (if (bufferp (car gnus-article-mime-handles))
5554 (1- (length gnus-article-mime-handles))))
5556 (defun gnus-mm-display-part (handle)
5557 "Display HANDLE and fix MIME button."
5558 (let ((id (get-text-property (point) 'gnus-part))
5560 (inhibit-read-only t))
5563 (let ((window (selected-window))
5564 (mail-parse-charset gnus-newsgroup-charset)
5565 (mail-parse-ignored-charsets
5566 (if (gnus-buffer-live-p gnus-summary-buffer)
5567 (with-current-buffer gnus-summary-buffer
5568 gnus-newsgroup-ignored-charsets)
5572 (let ((win (gnus-get-buffer-window (current-buffer) t))
5575 (select-window win))
5578 (if (mm-handle-displayed-p handle)
5579 ;; This will remove the part.
5580 (mm-display-part handle)
5582 (narrow-to-region (point)
5583 (if (eobp) (point) (1+ (point))))
5584 (gnus-bind-safe-url-regexp (mm-display-part handle))
5585 ;; We narrow to the part itself and
5586 ;; then call the treatment functions.
5587 (goto-char (point-min))
5589 (narrow-to-region (point) (point-max))
5592 (gnus-article-mime-total-parts)
5593 (mm-handle-media-type handle)))))
5594 (if (window-live-p window)
5595 (select-window window)))))
5598 (gnus-insert-mime-button
5599 handle id (list (mm-handle-displayed-p handle)))
5600 (goto-char point))))
5602 (defun gnus-article-goto-part (n)
5603 "Go to MIME part N."
5604 (when gnus-break-pages
5607 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5608 part handle end next handles)
5611 (if (setq handle (get-text-property start 'gnus-data))
5613 ;; Go to the displayed subpart, assuming this is
5614 ;; multipart/alternative.
5617 (while (and (not handle)
5620 (setq next (text-property-not-all part end
5623 handle (get-text-property part 'gnus-data))
5624 (push (cons handle part) handles)
5625 (unless (mm-handle-displayed-p handle)
5627 part (text-property-any part end 'gnus-data nil))))
5629 ;; No subpart is displayed, so we find preferred one.
5631 (cdr (assq (mm-preferred-alternative
5632 (nreverse (mapcar 'car handles)))
5635 (goto-char (1+ part))
5637 (when gnus-break-pages
5638 (gnus-narrow-to-page))))
5640 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5641 (let ((gnus-tmp-name
5642 (or (mail-content-type-get (mm-handle-type handle) 'name)
5643 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5644 (mail-content-type-get (mm-handle-type handle) 'url)
5646 (gnus-tmp-type (mm-handle-media-type handle))
5647 (gnus-tmp-description (or (mm-handle-description handle) ""))
5649 (if (if displayed (car displayed)
5650 (mm-handle-displayed-p handle))
5652 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5654 gnus-tmp-type-long b e)
5655 (when (string-match ".*/" gnus-tmp-name)
5656 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5657 (setq gnus-tmp-type-long (concat gnus-tmp-type
5658 (and (not (equal gnus-tmp-name ""))
5659 (concat "; " gnus-tmp-name))))
5660 (unless (equal gnus-tmp-description "")
5661 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5666 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5667 `(keymap ,gnus-mime-button-map
5668 gnus-callback gnus-mm-display-part
5669 gnus-part ,gnus-tmp-id
5670 article-type annotation
5673 ;; Exclude a newline.
5676 (when gnus-article-button-face
5677 (gnus-overlay-put (gnus-make-overlay b e nil t)
5678 'face gnus-article-button-face))
5679 (widget-convert-button
5682 :action 'gnus-widget-press-button
5683 :button-keymap gnus-mime-button-map
5686 ;; Needed to properly clear the message due to a bug in
5687 ;; wid-edit (XEmacs only).
5688 (if (boundp 'help-echo-owns-message)
5689 (setq help-echo-owns-message t))
5691 "%S: %s the MIME part; %S: more options"
5692 (aref gnus-mouse-2 0)
5693 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5695 (aref gnus-down-mouse-3 0))))))
5697 (defun gnus-widget-press-button (elems el)
5698 (goto-char (widget-get elems :from))
5699 (gnus-article-press-button))
5701 (defvar gnus-displaying-mime nil)
5703 (defun gnus-display-mime (&optional ihandles)
5704 "Display the MIME parts."
5706 (save-selected-window
5707 (let ((window (get-buffer-window gnus-article-buffer))
5710 (select-window window)
5711 ;; We have to do this since selecting the window
5712 ;; may change the point. So we set the window point.
5713 (set-window-point window point)))
5714 (let ((handles ihandles)
5715 (inhibit-read-only t)
5718 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5719 (when gnus-article-emulate-mime
5720 (mm-uu-dissect-text-parts handles)))
5721 (gnus-article-emulate-mime
5722 (setq handles (mm-uu-dissect))))
5723 (when (and (not ihandles)
5724 (not gnus-displaying-mime))
5725 ;; Top-level call; we clean up.
5726 (when gnus-article-mime-handles
5727 (mm-destroy-parts gnus-article-mime-handles)
5728 (setq gnus-article-mime-handle-alist nil));; A trick.
5729 (setq gnus-article-mime-handles handles)
5730 ;; We allow users to glean info from the handles.
5731 (when gnus-article-mime-part-function
5732 (gnus-mime-part-function handles)))
5734 (or (not (stringp (car handles)))
5737 (when (and (not ihandles)
5738 (not gnus-displaying-mime))
5739 ;; Clean up for mime parts.
5741 (delete-region (point) (point-max)))
5742 (let ((gnus-displaying-mime t))
5743 (gnus-mime-display-part handles)))
5746 (narrow-to-region (point) (point-max))
5747 (gnus-treat-article nil 1 1 "text/plain")
5750 ;; Highlight the headers.
5754 (narrow-to-region (point-min) (point))
5755 (gnus-article-save-original-date
5756 (gnus-treat-article 'head)))))))
5757 ;; Cope with broken MIME messages.
5758 (goto-char (point-max))
5762 (defcustom gnus-mime-display-multipart-as-mixed nil
5763 "Display \"multipart\" parts as \"multipart/mixed\".
5765 If t, it overrides nil values of
5766 `gnus-mime-display-multipart-alternative-as-mixed' and
5767 `gnus-mime-display-multipart-related-as-mixed'."
5768 :group 'gnus-article-mime
5771 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5772 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5774 :group 'gnus-article-mime
5777 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5778 "Display \"multipart/related\" parts as \"multipart/mixed\".
5780 If displaying \"text/html\" is discouraged \(see
5781 `mm-discouraged-alternatives'\) images or other material inside a
5782 \"multipart/related\" part might be overlooked when this variable is nil."
5784 :group 'gnus-article-mime
5787 (defun gnus-mime-display-part (handle)
5789 ;; Maybe a broken MIME message.
5792 ((not (stringp (car handle)))
5793 (gnus-mime-display-single handle))
5794 ;; User-defined multipart
5795 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5796 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5798 ;; multipart/alternative
5799 ((and (equal (car handle) "multipart/alternative")
5800 (not (or gnus-mime-display-multipart-as-mixed
5801 gnus-mime-display-multipart-alternative-as-mixed)))
5802 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5803 (push (cons id handle) gnus-article-mime-handle-alist)
5804 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5805 ;; multipart/related
5806 ((and (equal (car handle) "multipart/related")
5807 (not (or gnus-mime-display-multipart-as-mixed
5808 gnus-mime-display-multipart-related-as-mixed)))
5809 ;;;!!!We should find the start part, but we just default
5810 ;;;!!!to the first part.
5811 ;;(gnus-mime-display-part (cadr handle))
5812 ;;;!!! Most multipart/related is an HTML message plus images.
5813 ;;;!!! Unfortunately we are unable to let W3 display those
5814 ;;;!!! included images, so we just display it as a mixed multipart.
5815 ;;(gnus-mime-display-mixed (cdr handle))
5816 ;;;!!! No, w3 can display everything just fine.
5817 (gnus-mime-display-part (cadr handle)))
5818 ((equal (car handle) "multipart/signed")
5819 (gnus-add-wash-type 'signed)
5820 (gnus-mime-display-security handle))
5821 ((equal (car handle) "multipart/encrypted")
5822 (gnus-add-wash-type 'encrypted)
5823 (gnus-mime-display-security handle))
5824 ;; Other multiparts are handled like multipart/mixed.
5826 (gnus-mime-display-mixed (cdr handle)))))
5828 (defun gnus-mime-part-function (handles)
5829 (if (stringp (car handles))
5830 (mapcar 'gnus-mime-part-function (cdr handles))
5831 (funcall gnus-article-mime-part-function handles)))
5833 (defun gnus-mime-display-mixed (handles)
5834 (mapcar 'gnus-mime-display-part handles))
5836 (defun gnus-mime-display-single (handle)
5837 (let ((type (mm-handle-media-type handle))
5838 (ignored gnus-ignored-mime-types)
5845 (when (string-match (pop ignored) type)
5846 (throw 'ignored nil)))
5847 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5848 (with-current-buffer gnus-summary-buffer
5849 gnus-inhibit-images)
5850 gnus-inhibit-images)
5851 (string-match "\\`image/" type)))
5852 (setq not-attachment
5853 (and (not (mm-inline-override-p handle))
5854 (or (not (mm-handle-disposition handle))
5855 (equal (car (mm-handle-disposition handle))
5857 (mm-attachment-override-p handle))))
5858 (mm-automatic-display-p handle)
5860 (mm-inlinable-p handle)
5861 (mm-inlined-p handle))
5862 (mm-automatic-external-display-p type)))
5864 (when (equal (mm-handle-media-supertype handle) "text")
5866 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5868 (push (cons id handle) gnus-article-mime-handle-alist)
5870 (equal (mm-handle-media-supertype handle) "message"))
5873 (cond ((not (bolp)) 2)
5874 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5876 (when (or (not display)
5877 (not (gnus-unbuttonized-mime-type-p type))
5878 (eq id gnus-mime-buttonized-part-id))
5879 (gnus-insert-mime-button
5880 handle id (list (or display (and not-attachment text))))
5881 (gnus-article-insert-newline)
5882 ;; Remember modify the number of forward lines.
5890 (let ((mail-parse-charset gnus-newsgroup-charset)
5891 (mail-parse-ignored-charsets
5892 (save-excursion (condition-case ()
5893 (set-buffer gnus-summary-buffer)
5895 gnus-newsgroup-ignored-charsets)))
5896 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5897 (goto-char (point-max)))
5898 ((and text not-attachment)
5902 (gnus-article-insert-newline)
5903 (mm-display-inline handle)
5904 (goto-char (point-max))))
5908 (narrow-to-region beg (point))
5909 (if (eq handle gnus-article-mime-handles)
5910 ;; The format=flowed case.
5911 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5912 ;; Don't count signature parts that are never displayed.
5913 ;; The part number should be re-calculated supposing this
5914 ;; might be a message/rfc822 part.
5916 (dolist (part gnus-article-mime-handles)
5917 (unless (or (stringp part)
5918 (equal (car (mm-handle-type part))
5919 "application/pgp-signature"))
5920 (push part handles)))
5922 nil (length (memq handle handles)) (length handles)
5923 (mm-handle-media-type handle)))))))))))
5925 (defun gnus-unbuttonized-mime-type-p (type)
5926 "Say whether TYPE is to be unbuttonized."
5927 (unless gnus-inhibit-mime-unbuttonizing
5929 (let ((types gnus-unbuttonized-mime-types))
5931 (when (string-match (pop types) type)
5932 (throw 'found t)))))
5934 (let ((types gnus-buttonized-mime-types))
5936 (when (string-match (pop types) type)
5937 (throw 'found t)))))))))
5939 (defun gnus-article-insert-newline ()
5940 "Insert a newline, but mark it as undeletable."
5941 (gnus-put-text-property
5942 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5944 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5945 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5948 handle (inhibit-read-only t) from props begend not-pref)
5949 (save-window-excursion
5952 (narrow-to-region (car ibegend)
5955 (goto-char (car ibegend))
5958 (delete-region (point-min) (point-max))
5959 (mm-remove-parts handles))
5960 (setq begend (list (point-marker)))
5962 (unless (setq not-pref (cadr (member preferred ihandles)))
5963 (setq not-pref (car ihandles)))
5966 (not (gnus-unbuttonized-mime-type-p
5967 "multipart/alternative")))
5968 (gnus-add-text-properties
5971 (insert (format "%d. " id))
5975 (unless ,(not ibegend)
5976 (setq gnus-article-mime-handle-alist
5977 ',gnus-article-mime-handle-alist))
5978 (gnus-mime-display-alternative
5979 ',ihandles ',not-pref ',begend ,id))
5980 keymap ,gnus-mime-button-map
5981 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5982 face ,gnus-article-button-face
5984 article-type multipart))
5985 (widget-convert-button 'link from (point)
5986 :action 'gnus-widget-press-button
5987 :button-keymap gnus-widget-button-keymap)
5989 (while (setq handle (pop handles))
5990 (gnus-add-text-properties
5993 (insert (format "(%c) %-18s"
5994 (if (equal handle preferred) ?* ? )
5995 (mm-handle-media-type handle)))
5999 (unless ,(not ibegend)
6000 (setq gnus-article-mime-handle-alist
6001 ',gnus-article-mime-handle-alist))
6002 (gnus-mime-display-alternative
6003 ',ihandles ',handle ',begend ,id))
6004 keymap ,gnus-mime-button-map
6005 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6006 face ,gnus-article-button-face
6009 (widget-convert-button 'link from (point)
6010 :action 'gnus-widget-press-button
6011 :button-keymap gnus-widget-button-keymap)
6015 (if (stringp (car preferred))
6016 (gnus-display-mime preferred)
6017 (let ((mail-parse-charset gnus-newsgroup-charset)
6018 (mail-parse-ignored-charsets
6019 (with-current-buffer gnus-summary-buffer
6020 gnus-newsgroup-ignored-charsets)))
6021 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6025 (narrow-to-region (car begend) (point-max))
6027 nil (length gnus-article-mime-handle-alist)
6028 (gnus-article-mime-total-parts)
6029 (mm-handle-media-type preferred))))))
6030 (goto-char (point-max))
6031 (setcdr begend (point-marker)))))
6033 (goto-char point))))
6035 (defconst gnus-article-wash-status-strings
6036 (let ((alist '((cite "c" "Possible hidden citation text"
6037 " " "All citation text visible")
6038 (headers "h" "Hidden headers"
6039 " " "All headers visible.")
6040 (pgp "p" "Encrypted or signed message status hidden"
6041 " " "No hidden encryption nor digital signature status")
6042 (signature "s" "Signature has been hidden"
6043 " " "Signature is visible")
6044 (overstrike "o" "Overstrike (^H) characters applied"
6045 " " "No overstrike characters applied")
6046 (emphasis "e" "/*_Emphasis_*/ characters applied"
6047 " " "No /*_emphasis_*/ characters applied")))
6049 (dolist (entry alist result)
6050 (let ((key (nth 0 entry))
6051 (on (copy-sequence (nth 1 entry)))
6052 (on-help (nth 2 entry))
6053 (off (copy-sequence (nth 3 entry)))
6054 (off-help (nth 4 entry)))
6055 (put-text-property 0 1 'help-echo on-help on)
6056 (put-text-property 0 1 'help-echo off-help off)
6057 (push (list key on off) result))))
6058 "Alist of strings describing wash status in the mode line.
6059 Each entry has the form (KEY ON OF), where the KEY is a symbol
6060 representing the particular washing function, ON is the string to use
6061 in the article mode line when the washing function is active, and OFF
6062 is the string to use when it is inactive.")
6064 (defun gnus-article-wash-status-entry (key value)
6065 (let ((entry (assoc key gnus-article-wash-status-strings)))
6066 (if value (nth 1 entry) (nth 2 entry))))
6068 (defun gnus-article-wash-status ()
6069 "Return a string which display status of article washing."
6070 (with-current-buffer gnus-article-buffer
6071 (let ((cite (memq 'cite gnus-article-wash-types))
6072 (headers (memq 'headers gnus-article-wash-types))
6073 (boring (memq 'boring-headers gnus-article-wash-types))
6074 (pgp (memq 'pgp gnus-article-wash-types))
6075 (pem (memq 'pem gnus-article-wash-types))
6076 (signed (memq 'signed gnus-article-wash-types))
6077 (encrypted (memq 'encrypted gnus-article-wash-types))
6078 (signature (memq 'signature gnus-article-wash-types))
6079 (overstrike (memq 'overstrike gnus-article-wash-types))
6080 (emphasis (memq 'emphasis gnus-article-wash-types)))
6082 (gnus-article-wash-status-entry 'cite cite)
6083 (gnus-article-wash-status-entry 'headers (or headers boring))
6084 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6085 (gnus-article-wash-status-entry 'signature signature)
6086 (gnus-article-wash-status-entry 'overstrike overstrike)
6087 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6089 (defun gnus-add-wash-type (type)
6090 "Add a washing of TYPE to the current status."
6091 (add-to-list 'gnus-article-wash-types type))
6093 (defun gnus-delete-wash-type (type)
6094 "Add a washing of TYPE to the current status."
6095 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6097 (defun gnus-add-image (category image)
6098 "Add IMAGE of CATEGORY to the list of displayed images."
6099 (let ((entry (assq category gnus-article-image-alist)))
6101 (setq entry (list category))
6102 (push entry gnus-article-image-alist))
6103 (nconc entry (list image))))
6105 (defun gnus-delete-images (category)
6106 "Delete all images in CATEGORY."
6107 (let ((entry (assq category gnus-article-image-alist)))
6108 (dolist (image (cdr entry))
6109 (gnus-remove-image image category))
6110 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6111 (gnus-delete-wash-type category)))
6113 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6115 (defun gnus-article-maybe-hide-headers ()
6116 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6117 Provided for backwards compatibility."
6118 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6119 (not (with-current-buffer gnus-summary-buffer
6120 gnus-have-all-headers)))
6121 (not gnus-inhibit-hiding))
6122 (gnus-article-hide-headers)))
6126 (defun gnus-output-to-file (file-name)
6127 "Append the current article to a file named FILE-NAME.
6128 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6129 text and used as the value of the coding cookie which is added to the
6130 top of a file. Otherwise, this function saves a raw article without
6132 (let* ((artbuf (current-buffer))
6133 (file-name-coding-system nnmail-pathname-coding-system)
6134 (coding gnus-article-save-coding-system)
6135 (coding-system-for-read (if coding
6136 nil ;; Rely on the coding cookie.
6137 mm-text-coding-system))
6138 (coding-system-for-write (or coding
6139 mm-text-coding-system-for-write
6140 mm-text-coding-system))
6141 (exists (file-exists-p file-name)))
6144 (insert-file-contents file-name)
6145 (goto-char (point-min))
6146 ;; Remove the existing coding cookie.
6147 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6148 (delete-region (match-beginning 0) (match-end 0))))
6149 (goto-char (point-max))
6150 (insert-buffer-substring artbuf)
6151 ;; Append newline at end of the buffer as separator, and then
6153 (goto-char (point-max))
6156 ;; If the coding system is not suitable to encode the text,
6157 ;; ask a user for a proper one.
6158 (when (fboundp 'select-safe-coding-system)
6159 (setq coding (coding-system-base
6160 (save-window-excursion
6161 (select-safe-coding-system (point-min) (point-max)
6163 (setq coding-system-for-write
6164 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6166 (goto-char (point-min))
6167 ;; Add the coding cookie.
6168 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6169 coding-system-for-write)))
6172 (write-region (point-min) (point-max) file-name nil 'no-message)
6173 (message "Appended to %s" file-name))
6174 (write-region (point-min) (point-max) file-name))))
6177 (defun gnus-narrow-to-page (&optional arg)
6178 "Narrow the article buffer to a page.
6179 If given a numerical ARG, move forward ARG pages."
6181 (setq arg (if arg (prefix-numeric-value arg) 0))
6182 (with-current-buffer gnus-article-buffer
6184 ;; Remove any old next/prev buttons.
6185 (when (gnus-visual-p 'page-marker)
6186 (let ((inhibit-read-only t))
6187 (gnus-remove-text-with-property 'gnus-prev)
6188 (gnus-remove-text-with-property 'gnus-next)))
6190 (when (save-excursion
6192 (if (re-search-backward page-delimiter nil 'move (abs arg))
6194 (setq nd (match-beginning 0)
6196 (when (re-search-backward page-delimiter nil t)
6197 (setq st (match-end 0))))
6198 (when (re-search-forward page-delimiter nil t)
6199 (setq nd (match-beginning 0)
6202 (if (re-search-forward page-delimiter nil 'move arg)
6204 (setq st (match-end 0)
6206 (when (re-search-forward page-delimiter nil t)
6207 (setq nd (match-beginning 0))))
6208 (when (re-search-backward page-delimiter nil t)
6209 (setq st (match-end 0)
6212 (when (re-search-backward page-delimiter nil t)
6213 (goto-char (setq st (match-end 0))))
6214 (when (re-search-forward page-delimiter nil t)
6215 (setq nd (match-beginning 0)))
6217 (setq gnus-page-broken t)
6218 (when pt (goto-char pt))
6219 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6220 (when (gnus-visual-p 'page-marker)
6224 (gnus-insert-next-page-button))
6227 (gnus-insert-prev-page-button))))))))
6229 ;; Article mode commands
6231 (defun gnus-article-goto-next-page ()
6232 "Show the next page of the article."
6234 (when (gnus-article-next-page)
6235 (goto-char (point-min))
6236 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6239 (defun gnus-article-goto-prev-page ()
6240 "Show the previous page of the article."
6242 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6243 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6244 (gnus-article-prev-page nil)))
6246 ;; This is cleaner but currently breaks `gnus-pick-mode':
6248 ;; (defun gnus-article-goto-next-page ()
6249 ;; "Show the next page of the article."
6251 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6252 ;; (gnus-summary-next-page)))
6254 ;; (defun gnus-article-goto-prev-page ()
6255 ;; "Show the next page of the article."
6257 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6258 ;; (gnus-summary-prev-page)))
6260 (defun gnus-article-next-page (&optional lines)
6261 "Show the next page of the current article.
6262 If end of article, return non-nil. Otherwise return nil.
6263 Argument LINES specifies lines to be scrolled up."
6265 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6266 (if (and (not (and gnus-article-over-scroll
6267 (> (count-lines (window-start) (point-max))
6268 (if (featurep 'xemacs)
6269 (or lines (1- (window-height)))
6270 (+ (or lines (1- (window-height))) scroll-margin)))))
6273 (and (pos-visible-in-window-p) ;Not continuation line.
6274 (>= (point) (point-max)))))
6275 ;; Nothing in this page.
6276 (if (or (not gnus-page-broken)
6281 (eobp)))) ;Real end-of-buffer?
6283 (when gnus-article-over-scroll
6284 (gnus-article-next-page-1 lines))
6286 (gnus-narrow-to-page 1) ;Go to next page.
6288 ;; More in this page.
6289 (gnus-article-next-page-1 lines)
6292 (defun gnus-article-beginning-of-window ()
6293 "Move point to the beginning of the window.
6294 In Emacs, the point is placed at the line number which `scroll-margin'
6296 (if (featurep 'xemacs)
6297 (move-to-window-line 0)
6298 ;; There is an obscure bug in Emacs that makes it impossible to
6299 ;; scroll past big pictures in the article buffer. Try to fix
6300 ;; this by adding a sanity check by counting the lines visible.
6301 (when (> (count-lines (window-start) (window-end)) 30)
6302 (move-to-window-line
6303 (min (max 0 scroll-margin)
6304 (max 1 (- (window-height)
6305 (if mode-line-format 1 0)
6306 (if header-line-format 1 0)
6309 (defun gnus-article-next-page-1 (lines)
6311 (let ((scroll-in-place nil))
6314 ;; Long lines may cause an end-of-buffer error.
6315 (goto-char (point-max))))
6316 (gnus-article-beginning-of-window))
6318 (defun gnus-article-prev-page (&optional lines)
6319 "Show previous page of current article.
6320 Argument LINES specifies lines to be scrolled down."
6322 (move-to-window-line 0)
6323 (if (and gnus-page-broken
6325 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6327 (gnus-narrow-to-page -1) ;Go to previous page.
6328 (goto-char (point-max))
6329 (recenter (if gnus-article-over-scroll
6331 (max (if (featurep 'xemacs)
6333 (+ lines scroll-margin))
6335 (- (window-height) 2))
6339 (let ((scroll-in-place nil))
6340 (scroll-down lines))
6341 (beginning-of-buffer
6342 (goto-char (point-min))))
6343 (gnus-article-beginning-of-window))))
6345 (defun gnus-article-only-boring-p ()
6346 "Decide whether there is only boring text remaining in the article.
6347 Something \"interesting\" is a word of at least two letters that does
6348 not have a face in `gnus-article-boring-faces'."
6349 (when (and gnus-article-skip-boring
6350 (boundp 'gnus-article-boring-faces)
6351 (symbol-value 'gnus-article-boring-faces))
6353 (let ((inhibit-point-motion-hooks t))
6355 (while (re-search-forward "\\b\\w\\w" nil t)
6357 (when (not (gnus-intersection
6358 (gnus-faces-at (point))
6359 (symbol-value 'gnus-article-boring-faces)))
6360 (throw 'only-boring nil)))
6361 (throw 'only-boring t))))))
6363 (defun gnus-article-refer-article ()
6364 "Read article specified by message-id around point."
6367 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6368 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6369 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6370 (let ((msg-id (concat "<" (match-string 0) ">")))
6371 (set-buffer gnus-summary-buffer)
6372 (gnus-summary-refer-article msg-id))
6373 (error "No references around point"))))
6375 (defun gnus-article-show-summary ()
6376 "Reconfigure windows to show summary buffer."
6378 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6379 (error "There is no summary buffer for this article buffer")
6380 (gnus-article-set-globals)
6381 (gnus-configure-windows 'article)
6382 (gnus-summary-goto-subject gnus-current-article)
6383 (gnus-summary-position-point)))
6385 (defun gnus-article-describe-briefly ()
6386 "Describe article mode commands briefly."
6388 (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")))
6390 (defun gnus-article-check-buffer ()
6391 "Beep if not in an article buffer."
6392 (unless (equal major-mode 'gnus-article-mode)
6393 (error "Command invoked outside of a Gnus article buffer")))
6395 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6396 "Read a summary buffer key sequence and execute it from the article buffer."
6398 (gnus-article-check-buffer)
6400 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6401 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6402 "=" "^" "\M-^" "|"))
6404 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6405 "An" "Ap" [?A (meta return)] [?A delete]))
6409 '("n" "Gn" "p" "Gp"))
6411 (with-current-buffer gnus-article-current-summary
6412 (let (gnus-pick-mode)
6413 (setq unread-command-events (nconc unread-command-events
6414 (list (or key last-command-event)))
6415 keys (if (featurep 'xemacs)
6416 (events-to-keys (read-key-sequence nil t))
6417 (read-key-sequence nil t)))))
6422 ((eq (aref keys (1- (length keys))) ?\C-h)
6423 (gnus-article-describe-bindings (substring keys 0 -1)))
6424 ((or (member keys nosaves)
6425 (member keys nosave-but-article)
6426 (member keys nosave-in-article))
6428 (save-window-excursion
6429 (pop-to-buffer gnus-article-current-summary)
6430 ;; We disable the pick minor mode commands.
6431 (let (gnus-pick-mode)
6432 (setq func (key-binding keys t))))
6436 (unless (member keys nosave-in-article)
6437 (set-buffer gnus-article-current-summary))
6438 (when (get func 'disabled)
6439 (error "Function %s disabled" func))
6440 (call-interactively func)
6441 (setq new-sum-point (point)))
6442 (when (member keys nosave-but-article)
6443 (pop-to-buffer gnus-article-buffer))))
6445 ;; These commands should restore window configuration.
6446 (let ((obuf (current-buffer))
6447 (owin (current-window-configuration))
6448 win func in-buffer selected new-sum-start new-sum-hscroll err)
6449 (cond (not-restore-window
6450 (pop-to-buffer gnus-article-current-summary)
6451 (setq win (selected-window)))
6452 ((setq win (get-buffer-window gnus-article-current-summary))
6453 (select-window win))
6455 (let ((summary-buffer gnus-article-current-summary))
6456 (gnus-configure-windows 'article)
6457 (unless (setq win (get-buffer-window summary-buffer 'visible))
6458 (let ((gnus-buffer-configuration
6459 '((article ((vertical 1.0
6460 (summary 0.25 point)
6462 (gnus-configure-windows 'article))
6463 (setq win (get-buffer-window summary-buffer 'visible)))
6464 (gnus-select-frame-set-input-focus (window-frame win))
6465 (select-window win))))
6466 (setq in-buffer (current-buffer))
6467 ;; We disable the pick minor mode commands.
6468 (setq func (let (gnus-pick-mode)
6469 (key-binding keys t)))
6470 (when (get func 'disabled)
6471 (error "Function %s disabled" func))
6474 (condition-case code
6476 (call-interactively func)
6482 (when (eq win (selected-window))
6483 (setq new-sum-point (point)
6484 new-sum-start (window-start win)
6485 new-sum-hscroll (window-hscroll win)))
6486 (when (or (eq in-buffer (current-buffer))
6487 (when (eq obuf (current-buffer))
6488 (set-buffer in-buffer)
6490 (setq selected (gnus-summary-select-article))
6492 (unless not-restore-window
6493 (set-window-configuration owin))
6494 (when (and (eq selected 'old)
6496 (set-window-start (get-buffer-window (current-buffer))
6498 (set-window-point (get-buffer-window (current-buffer))
6499 (if (article-goto-body)
6502 (when (and (not not-restore-window)
6505 (with-current-buffer (window-buffer win)
6506 (eq major-mode 'gnus-summary-mode)))
6507 (set-window-point win new-sum-point)
6508 (set-window-start win new-sum-start)
6509 (set-window-hscroll win new-sum-hscroll))))
6510 (set-window-configuration owin)
6512 (signal (car err) (cdr err))
6515 (defun gnus-article-read-summary-send-keys ()
6517 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6518 (gnus-article-read-summary-keys)))
6520 (defun gnus-article-describe-key (key)
6521 "Display documentation of the function invoked by KEY.
6522 KEY is a string or a vector."
6523 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6524 (read-key-sequence "Describe key: "))))
6525 (gnus-article-check-buffer)
6526 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6527 gnus-article-read-summary-send-keys))
6528 (with-current-buffer gnus-article-current-summary
6529 (setq unread-command-events
6530 (if (featurep 'xemacs)
6532 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6533 (list 'meta (- x 128))
6536 (let ((cursor-in-echo-area t)
6538 (describe-key (read-key-sequence nil t))))
6539 (describe-key key)))
6541 (defun gnus-article-describe-key-briefly (key &optional insert)
6542 "Display documentation of the function invoked by KEY.
6543 KEY is a string or a vector."
6544 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6545 (read-key-sequence "Describe key: "))
6546 current-prefix-arg))
6547 (gnus-article-check-buffer)
6548 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6549 gnus-article-read-summary-send-keys))
6550 (with-current-buffer gnus-article-current-summary
6551 (setq unread-command-events
6552 (if (featurep 'xemacs)
6554 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6555 (list 'meta (- x 128))
6558 (let ((cursor-in-echo-area t)
6560 (describe-key-briefly (read-key-sequence nil t) insert)))
6561 (describe-key-briefly key insert)))
6563 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6564 (defvar gnus-agent-summary-mode)
6565 (defvar gnus-draft-mode)
6566 ;; Calling help-buffer will autoload help-mode.
6567 (defvar help-xref-stack-item)
6568 ;; Emacs 22 doesn't load it in the batch mode.
6570 (autoload 'help-buffer "help-mode"))
6572 (defun gnus-article-describe-bindings (&optional prefix)
6573 "Show a list of all defined keys, and their definitions.
6574 The optional argument PREFIX, if non-nil, should be a key sequence;
6575 then we display only bindings that start with that prefix."
6577 (gnus-article-check-buffer)
6578 (let ((keymap (copy-keymap gnus-article-mode-map))
6579 (map (copy-keymap gnus-article-send-map))
6580 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6582 (define-key keymap "S" map)
6583 (define-key map [t] nil)
6584 (with-current-buffer gnus-article-current-summary
6587 (if (setq parent (keymap-parent gnus-article-mode-map))
6589 (setq parent (copy-keymap parent))
6590 (set-keymap-parent parent (current-local-map)))
6591 (current-local-map)))
6592 (set-keymap-parent map (key-binding "S"))
6593 (let (key def gnus-pick-mode)
6595 (setq key (pop sumkeys))
6596 (cond ((and (vectorp key) (= (length key) 1)
6597 (consp (setq def (aref key 0)))
6598 (numberp (car def)) (numberp (cdr def)))
6599 (when (< (max (car def) (cdr def)) 128)
6603 (nreverse (gnus-uncompress-range def)))
6605 ((setq def (key-binding key))
6606 (unless (eq def 'undefined)
6607 (define-key keymap key def))))))
6608 (when (boundp 'gnus-agent-summary-mode)
6609 (setq agent gnus-agent-summary-mode))
6610 (when (boundp 'gnus-draft-mode)
6611 (setq draft gnus-draft-mode)))
6613 (use-local-map keymap)
6614 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6615 (set (make-local-variable 'gnus-draft-mode) draft)
6616 (describe-bindings prefix))
6617 (let ((item `((lambda (prefix)
6618 (with-current-buffer ,(current-buffer)
6619 (gnus-article-describe-bindings prefix)))
6621 (with-current-buffer (let (help-xref-following) (help-buffer))
6622 (setq help-xref-stack-item item)))))
6624 (defun gnus-article-reply-with-original (&optional wide)
6625 "Start composing a reply mail to the current message.
6626 The text in the region will be yanked. If the region isn't active,
6627 the entire article will be yanked."
6629 (let ((article (cdr gnus-article-current))
6631 (if (not (gnus-region-active-p))
6632 (with-current-buffer gnus-summary-buffer
6633 (gnus-summary-reply (list (list article)) wide))
6634 (setq contents (buffer-substring (point) (mark t)))
6635 ;; Deactivate active regions.
6636 (when (and (boundp 'transient-mark-mode)
6637 transient-mark-mode)
6638 (setq mark-active nil))
6639 (with-current-buffer gnus-summary-buffer
6641 (list (list article contents)) wide)))))
6643 (defun gnus-article-wide-reply-with-original ()
6644 "Start composing a wide reply mail to the current message.
6645 The text in the region will be yanked. If the region isn't active,
6646 the entire article will be yanked."
6648 (gnus-article-reply-with-original t))
6650 (defun gnus-article-followup-with-original ()
6651 "Compose a followup to the current article.
6652 The text in the region will be yanked. If the region isn't active,
6653 the entire article will be yanked."
6655 (let ((article (cdr gnus-article-current))
6657 (if (not (gnus-region-active-p))
6658 (with-current-buffer gnus-summary-buffer
6659 (gnus-summary-followup (list (list article))))
6660 (setq contents (buffer-substring (point) (mark t)))
6661 ;; Deactivate active regions.
6662 (when (and (boundp 'transient-mark-mode)
6663 transient-mark-mode)
6664 (setq mark-active nil))
6665 (with-current-buffer gnus-summary-buffer
6666 (gnus-summary-followup
6667 (list (list article contents)))))))
6669 (defun gnus-article-hide (&optional arg force)
6670 "Hide all the gruft in the current article.
6671 This means that signatures, cited text and (some) headers will be
6673 If given a prefix, show the hidden text instead."
6674 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6675 (gnus-article-hide-headers arg)
6676 (gnus-article-hide-list-identifiers arg)
6677 (gnus-article-hide-citation-maybe arg force)
6678 (gnus-article-hide-signature arg))
6680 (defun gnus-article-maybe-highlight ()
6681 "Do some article highlighting if article highlighting is requested."
6682 (when (gnus-visual-p 'article-highlight 'highlight)
6683 (gnus-article-highlight-some)))
6685 (defun gnus-check-group-server ()
6686 ;; Make sure the connection to the server is alive.
6687 (unless (gnus-server-opened
6688 (gnus-find-method-for-group gnus-newsgroup-name))
6689 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6690 (gnus-request-group gnus-newsgroup-name t)))
6693 (autoload 'nneething-get-file-name "nneething"))
6695 (defun gnus-request-article-this-buffer (article group)
6696 "Get an article and insert it into this buffer."
6697 (let (do-update-line sparse-header)
6701 (gnus-kill-all-overlays)
6702 (setq group (or group gnus-newsgroup-name))
6704 ;; Using `gnus-request-article' directly will insert the article into
6705 ;; `nntp-server-buffer' - so we'll save some time by not having to
6706 ;; copy it from the server buffer into the article buffer.
6708 ;; We only request an article by message-id when we do not have the
6709 ;; headers for it, so we'll have to get those.
6710 (when (stringp article)
6711 (gnus-read-header article))
6713 ;; If the article number is negative, that means that this article
6714 ;; doesn't belong in this newsgroup (possibly), so we find its
6715 ;; message-id and request it by id instead of number.
6716 (when (and (numberp article)
6718 (get-buffer gnus-summary-buffer)
6719 (gnus-buffer-exists-p gnus-summary-buffer))
6720 (with-current-buffer gnus-summary-buffer
6721 (let ((header (gnus-summary-article-header article)))
6724 ((memq article gnus-newsgroup-sparse)
6725 ;; This is a sparse gap article.
6726 (setq do-update-line article)
6727 (setq article (mail-header-id header))
6728 (setq sparse-header (gnus-read-header article))
6729 (setq gnus-newsgroup-sparse
6730 (delq article gnus-newsgroup-sparse)))
6732 ;; It's a real article.
6733 (setq article (mail-header-id header)))
6735 ;; It is an extracted pseudo-article.
6736 (setq article 'pseudo)
6737 (gnus-request-pseudo-article header))))
6739 (let ((method (gnus-find-method-for-group
6740 gnus-newsgroup-name)))
6741 (when (and (eq (car method) 'nneething)
6743 (let ((dir (nneething-get-file-name
6744 (mail-header-id header))))
6745 (when (and (stringp dir)
6746 (file-directory-p dir))
6747 (setq article 'nneething)
6748 (gnus-group-enter-directory dir))))))))
6751 ;; Refuse to select canceled articles.
6752 ((and (numberp article)
6754 (get-buffer gnus-summary-buffer)
6755 (gnus-buffer-exists-p gnus-summary-buffer)
6756 (eq (cdr (with-current-buffer gnus-summary-buffer
6757 (assq article gnus-newsgroup-reads)))
6758 gnus-canceled-mark))
6760 ;; We first check `gnus-original-article-buffer'.
6761 ((and (get-buffer gnus-original-article-buffer)
6763 (with-current-buffer gnus-original-article-buffer
6764 (and (equal (car gnus-original-article) group)
6765 (eq (cdr gnus-original-article) article))))
6766 ;; `insert-buffer-substring' would incorrectly use the
6767 ;; equivalent of string-make-multibyte which amount to decoding
6768 ;; with locale-coding-system, causing failure of
6769 ;; subsequent decoding.
6770 (insert (mm-string-to-multibyte
6771 (with-current-buffer gnus-original-article-buffer
6772 (buffer-substring (point-min) (point-max)))))
6774 ;; Check the backlog.
6775 ((and gnus-keep-backlog
6776 (gnus-backlog-request-article group article (current-buffer)))
6778 ;; Check asynchronous pre-fetch.
6779 ((gnus-async-request-fetched-article group article (current-buffer))
6780 (gnus-async-prefetch-next group article gnus-summary-buffer)
6781 (when (and (numberp article) gnus-keep-backlog)
6782 (gnus-backlog-enter-article group article (current-buffer)))
6785 ((and gnus-use-cache
6787 (gnus-cache-request-article article group))
6789 ;; Check the agent cache.
6790 ((gnus-agent-request-article article group)
6792 ;; Get the article and put into the article buffer.
6793 ((or (stringp article)
6795 (let ((gnus-override-method gnus-override-method)
6796 (methods (and (stringp article)
6797 gnus-refer-article-method))
6798 (backend (car (gnus-find-method-for-group
6799 gnus-newsgroup-name)))
6801 (inhibit-read-only t))
6802 (if (or (not (listp methods))
6803 (and (symbolp (car methods))
6804 (assq (car methods) nnoo-definition-alist)))
6805 (setq methods (list methods)))
6806 (when (and (null gnus-override-method)
6808 (setq gnus-override-method (pop methods)))
6810 (when (eq gnus-override-method 'current)
6811 (setq gnus-override-method
6812 (with-current-buffer gnus-summary-buffer
6813 gnus-current-select-method)))
6815 (gnus-kill-all-overlays)
6816 (let ((gnus-newsgroup-name group))
6817 (gnus-check-group-server))
6819 ((gnus-request-article article group (current-buffer))
6820 (when (numberp article)
6821 (gnus-async-prefetch-next group article
6822 gnus-summary-buffer)
6823 (when gnus-keep-backlog
6824 (gnus-backlog-enter-article
6825 group article (current-buffer))))
6826 (setq result 'article))
6828 (setq gnus-override-method (pop methods)))
6829 ((not (string-match "^400 "
6830 (nnheader-get-report backend)))
6831 ;; If we get 400 server disconnect, reconnect and
6832 ;; retry; otherwise, assume the article has expired.
6833 (setq result 'done))))
6834 (and (eq result 'article) 'article)))
6838 ;; Associate this article with the current summary buffer.
6839 (setq gnus-article-current-summary gnus-summary-buffer)
6841 ;; Take the article from the original article buffer
6842 ;; and place it in the buffer it's supposed to be in.
6843 (when (and (get-buffer gnus-article-buffer)
6844 (equal (buffer-name (current-buffer))
6845 (buffer-name (get-buffer gnus-article-buffer))))
6847 (if (get-buffer gnus-original-article-buffer)
6848 (set-buffer gnus-original-article-buffer)
6849 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6850 (buffer-disable-undo)
6851 (setq major-mode 'gnus-original-article-mode)
6852 (setq buffer-read-only t))
6853 (let ((inhibit-read-only t))
6855 (insert-buffer-substring gnus-article-buffer))
6856 (setq gnus-original-article (cons group article)))
6859 (run-hooks 'gnus-article-decode-hook)
6860 ;; Mark article as decoded or not.
6861 (setq gnus-article-decoded-p gnus-article-decode-hook))
6863 ;; Update sparse articles.
6864 (when (and do-update-line
6865 (or (numberp article)
6867 (let ((buf (current-buffer)))
6868 (set-buffer gnus-summary-buffer)
6869 (gnus-summary-update-article do-update-line sparse-header)
6870 (gnus-summary-goto-subject do-update-line nil t)
6871 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6873 (set-buffer buf))))))
6875 (defun gnus-block-private-groups (group)
6876 (if (gnus-news-group-p group)
6877 ;; Block nothing in news groups.
6879 ;; Block everything anywhere else.
6882 (defun gnus-blocked-images ()
6883 (if (functionp gnus-blocked-images)
6884 (funcall gnus-blocked-images gnus-newsgroup-name)
6885 gnus-blocked-images))
6891 (defcustom gnus-article-edit-mode-hook nil
6892 "Hook run in article edit mode buffers."
6893 :group 'gnus-article-various
6896 (defvar gnus-article-edit-done-function nil)
6898 (defvar gnus-article-edit-mode-map nil)
6900 ;; Should we be using derived.el for this?
6901 (unless gnus-article-edit-mode-map
6902 (setq gnus-article-edit-mode-map (make-keymap))
6903 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6905 (gnus-define-keys gnus-article-edit-mode-map
6906 "\C-c?" describe-mode
6907 "\C-c\C-c" gnus-article-edit-done
6908 "\C-c\C-k" gnus-article-edit-exit
6909 "\C-c\C-f\C-t" message-goto-to
6910 "\C-c\C-f\C-o" message-goto-from
6911 "\C-c\C-f\C-b" message-goto-bcc
6912 ;;"\C-c\C-f\C-w" message-goto-fcc
6913 "\C-c\C-f\C-c" message-goto-cc
6914 "\C-c\C-f\C-s" message-goto-subject
6915 "\C-c\C-f\C-r" message-goto-reply-to
6916 "\C-c\C-f\C-n" message-goto-newsgroups
6917 "\C-c\C-f\C-d" message-goto-distribution
6918 "\C-c\C-f\C-f" message-goto-followup-to
6919 "\C-c\C-f\C-m" message-goto-mail-followup-to
6920 "\C-c\C-f\C-k" message-goto-keywords
6921 "\C-c\C-f\C-u" message-goto-summary
6922 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6923 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6924 "\C-c\C-b" message-goto-body
6925 "\C-c\C-i" message-goto-signature
6927 "\C-c\C-t" message-insert-to
6928 "\C-c\C-n" message-insert-newsgroups
6929 "\C-c\C-o" message-sort-headers
6930 "\C-c\C-e" message-elide-region
6931 "\C-c\C-v" message-delete-not-region
6932 "\C-c\C-z" message-kill-to-signature
6933 "\M-\r" message-newline-and-reformat
6934 "\C-c\C-a" mml-attach-file
6935 "\C-a" message-beginning-of-line
6937 "\M-;" comment-region)
6939 (gnus-define-keys (gnus-article-edit-wash-map
6940 "\C-c\C-w" gnus-article-edit-mode-map)
6941 "f" gnus-article-edit-full-stops))
6944 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6946 ["Fetch To" message-insert-to t]
6947 ["Fetch Newsgroups" message-insert-newsgroups t]
6949 ["To" message-goto-to t]
6950 ["From" message-goto-from t]
6951 ["Subject" message-goto-subject t]
6952 ["Cc" message-goto-cc t]
6953 ["Reply-To" message-goto-reply-to t]
6954 ["Summary" message-goto-summary t]
6955 ["Keywords" message-goto-keywords t]
6956 ["Newsgroups" message-goto-newsgroups t]
6957 ["Followup-To" message-goto-followup-to t]
6958 ["Mail-Followup-To" message-goto-mail-followup-to t]
6959 ["Distribution" message-goto-distribution t]
6960 ["Body" message-goto-body t]
6961 ["Signature" message-goto-signature t]))
6963 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6964 "Major mode for editing articles.
6965 This is an extended text-mode.
6967 \\{gnus-article-edit-mode-map}"
6968 (make-local-variable 'gnus-article-edit-done-function)
6969 (make-local-variable 'gnus-prev-winconf)
6970 (set (make-local-variable 'font-lock-defaults)
6971 '(message-font-lock-keywords t))
6972 (set (make-local-variable 'mail-header-separator) "")
6973 (set (make-local-variable 'gnus-article-edit-mode) t)
6974 (easy-menu-add message-mode-field-menu message-mode-map)
6976 (setq buffer-read-only nil)
6977 (buffer-enable-undo)
6980 (defun gnus-article-edit (&optional force)
6981 "Edit the current article.
6982 This will have permanent effect only in mail groups.
6983 If FORCE is non-nil, allow editing of articles even in read-only
6986 (when (and (not force)
6987 (gnus-group-read-only-p))
6988 (error "The current newsgroup does not support article editing"))
6989 (gnus-article-date-original)
6990 (gnus-article-edit-article
6992 `(lambda (no-highlight)
6994 (gnus-summary-edit-article-done
6995 ,(or (mail-header-references gnus-current-headers) "")
6996 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6998 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6999 "Start editing the contents of the current article buffer."
7000 (let ((winconf (current-window-configuration)))
7001 (set-buffer gnus-article-buffer)
7002 (let ((message-auto-save-directory
7003 ;; Don't associate the article buffer with a draft file.
7005 (gnus-article-edit-mode))
7006 (funcall start-func)
7007 (set-buffer-modified-p nil)
7008 (gnus-configure-windows 'edit-article)
7009 (setq gnus-article-edit-done-function exit-func)
7010 (setq gnus-prev-winconf winconf)
7012 (gnus-message 6 "C-c C-c to end edits"))))
7014 (defun gnus-article-edit-done (&optional arg)
7015 "Update the article edits and exit."
7017 (let ((func gnus-article-edit-done-function)
7018 (buf (current-buffer))
7019 (start (window-start))
7021 (winconf gnus-prev-winconf))
7022 (widen) ;; Widen it in case that users narrowed the buffer.
7025 ;; The cache and backlog have to be flushed somewhat.
7026 (when gnus-keep-backlog
7027 (gnus-backlog-remove-article
7028 (car gnus-article-current) (cdr gnus-article-current)))
7029 ;; Flush original article as well.
7030 (gnus-flush-original-article-buffer)
7031 (when gnus-use-cache
7032 (gnus-cache-update-article
7033 (car gnus-article-current) (cdr gnus-article-current)))
7034 ;; We remove all text props from the article buffer.
7035 (kill-all-local-variables)
7036 (set-text-properties (point-min) (point-max) nil)
7038 (set-window-configuration winconf)
7040 (set-window-start (get-buffer-window buf) start)
7041 (set-window-point (get-buffer-window buf) (point)))
7042 (gnus-summary-show-article))
7044 (defun gnus-flush-original-article-buffer ()
7045 (when (get-buffer gnus-original-article-buffer)
7046 (with-current-buffer gnus-original-article-buffer
7047 (setq gnus-original-article nil))))
7049 (defun gnus-article-edit-exit ()
7050 "Exit the article editing without updating."
7052 (when (or (not (buffer-modified-p))
7053 (yes-or-no-p "Article modified; kill anyway? "))
7054 (let ((curbuf (current-buffer))
7056 (window-start (window-start)))
7058 (if (gnus-buffer-live-p gnus-original-article-buffer)
7059 (insert-buffer-substring gnus-original-article-buffer))
7060 (let ((winconf gnus-prev-winconf))
7061 (kill-all-local-variables)
7063 (set-window-configuration winconf)
7064 ;; Tippy-toe some to make sure that point remains where it was.
7065 (save-current-buffer
7067 (set-window-start (get-buffer-window (current-buffer)) window-start)
7069 (gnus-summary-show-article)))
7071 (defun gnus-article-edit-full-stops ()
7072 "Interactively repair spacing at end of sentences."
7075 (goto-char (point-min))
7076 (search-forward-regexp "^$" nil t)
7077 (let ((case-fold-search nil))
7078 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7081 ;;; Article highlights
7084 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7086 ;;; Internal Variables:
7088 (defcustom gnus-button-url-regexp
7090 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7091 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7092 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7093 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7094 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7098 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7099 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7100 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7102 "[" chars punct "]+" "[" chars "]"
7104 (concat ;; XEmacs 21.4 doesn't support POSIX.
7105 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7106 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7108 "Regular expression that matches URLs."
7109 :group 'gnus-article-buttons
7112 (defcustom gnus-button-valid-fqdn-regexp
7113 message-valid-fqdn-regexp
7114 "Regular expression that matches a valid FQDN."
7116 :group 'gnus-article-buttons
7119 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7120 (defcustom gnus-button-valid-localpart-regexp
7121 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7122 "Regular expression that matches a localpart of mail addresses or MIDs."
7124 :group 'gnus-article-buttons
7127 (defcustom gnus-button-man-handler 'manual-entry
7128 "Function to use for displaying man pages.
7129 The function must take at least one argument with a string naming the
7132 :type '(choice (function-item :tag "Man" manual-entry)
7133 (function-item :tag "Woman" woman)
7134 (function :tag "Other"))
7135 :group 'gnus-article-buttons)
7137 (defcustom gnus-button-mid-or-mail-regexp
7138 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7139 gnus-button-valid-fqdn-regexp
7141 "Regular expression that matches a message ID or a mail address."
7143 :group 'gnus-article-buttons
7146 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7147 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7148 Strings like this can be either a message ID or a mail address. If it is one
7149 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7150 message ID or a mail address, respectively. If this variable is set to the
7151 symbol `ask', always query the user what do do. If it is a function, this
7152 function will be called with the string as its only argument. The function
7153 must return `mid', `mail', `invalid' or `ask'."
7155 :group 'gnus-article-buttons
7156 :type '(choice (function-item :tag "Heuristic function"
7157 gnus-button-mid-or-mail-heuristic)
7162 (defcustom gnus-button-mid-or-mail-heuristic-alist
7163 '((-10.0 . ".+\\$.+@")
7166 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7167 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7168 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7169 (-1.0 . "^[^a-z]+@")
7171 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7172 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7173 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7174 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7177 (-1.0 . "^[0-9][0-9]")
7179 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7180 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7181 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7182 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7184 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7185 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7188 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7190 ;; compensation for TDMA dated mail addresses:
7191 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7193 (-20.0 . "\\.fsf@") ;; Gnus
7196 (-20.0 . "^alpine\\.")
7197 (-20.0 . "_-_") ;; Subject change in thread
7199 (-20.0 . "\\.ln@") ;; leafnode
7200 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7201 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7203 ;; (5.0 . "") ;; $local_part_len <= 7
7204 (10.0 . "^[^0-9]+@")
7205 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7206 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7209 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7211 (0.5 . "^[A-Z][a-z]")
7212 (0.5 . "^[A-Z][a-z][a-z]")
7213 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7214 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7215 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7217 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7218 address. The REGEXP is processed with `case-fold-search' set to nil."
7220 :group 'gnus-article-buttons
7221 :type '(repeat (cons (number :tag "Rate")
7222 (regexp :tag "Regexp"))))
7224 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7225 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7226 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7227 address, `ask' if unsure and `invalid' if the string is invalid."
7228 (let ((case-fold-search nil)
7229 (list gnus-button-mid-or-mail-heuristic-alist)
7230 (result 0) rate regexp lpartlen elem)
7232 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7233 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7234 ;; Certain special cases...
7237 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7238 "^[0-9]+\\.[0-9]+@compuserve\\|"
7239 "@public\\.gmane\\.org")
7241 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7242 (setq result 'mail))
7243 (when (string-match "@.*@\\| " mid-or-mail)
7244 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7245 (setq result 'invalid))
7246 ;; Nothing more to do, if result is not a number here...
7247 (when (numberp result)
7249 (setq elem (car list)
7253 (when (string-match regexp mid-or-mail)
7254 (setq result (+ result rate))
7256 9 "`%s' matched `%s', rate `%s', result `%s'."
7257 mid-or-mail regexp rate result)))
7258 (when (<= lpartlen 7)
7259 (setq result (+ result 5.0))
7260 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7261 mid-or-mail result))
7262 (when (>= lpartlen 12)
7263 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7265 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7266 ;; Long local part should contain realname if e-mail address,
7267 ;; too many digits: message-id.
7268 ;; $score -= 5.0 + 0.1 * $local_part_len;
7269 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7270 (setq result (+ result rate))
7272 9 "Many digits in `%s', rate `%s', result `%s'."
7273 mid-or-mail rate result))
7274 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7276 ;; Too few vowels [^aeiouy]{4,}.*\@
7277 (setq result (+ result -5.0))
7279 9 "Few vowels in `%s', rate `%s', result `%s'."
7280 mid-or-mail -5.0 result))
7282 (setq result (+ result 5.0))
7284 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7285 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7286 ;; Maybe we should make this a customizable alist: (condition . 'result)
7288 ((symbolp result) result)
7289 ;; Now convert number into proper results:
7290 ((< result -10.0) 'mid)
7291 ((> result 10.0) 'mail)
7294 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7295 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7296 (url-mid (concat "news" ":" mid-or-mail))
7297 (url-mailto (concat "mailto" ":" mid-or-mail)))
7298 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7299 (when (fboundp pref)
7301 ;; get rid of surrounding angles...
7303 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7304 (if (or (eq 'mid guessed) (eq 'mail guessed))
7308 (save-window-excursion
7309 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7312 (cond ((eq pref 'mid)
7313 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7314 (gnus-button-handle-news url-mid))
7316 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7317 (gnus-url-mailto url-mailto))
7318 (t (gnus-message 3 "Invalid string.")))))
7320 (defun gnus-button-handle-custom (fun arg)
7321 "Call function FUN on argument ARG.
7322 Both FUN and ARG are supposed to be strings. ARG will be passed
7323 as a symbol to FUN."
7324 (funcall (intern fun)
7325 (if (string-match "^customize-apropos" fun)
7329 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7331 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7334 (defun gnus-button-handle-describe-function (url)
7335 "Call `describe-function' when pushing the corresponding URL button."
7338 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7340 (defun gnus-button-handle-describe-variable (url)
7341 "Call `describe-variable' when pushing the corresponding URL button."
7344 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7346 (defun gnus-button-handle-symbol (url)
7347 "Display help on variable or function.
7348 Calls `describe-variable' or `describe-function'."
7349 (let ((sym (intern url)))
7351 ((fboundp sym) (describe-function sym))
7352 ((boundp sym) (describe-variable sym))
7353 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7355 (defun gnus-button-handle-describe-key (url)
7356 "Call `describe-key' when pushing the corresponding URL button."
7358 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7359 (keys (ignore-errors (eval `(kbd ,key-string)))))
7362 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7364 (defun gnus-button-handle-apropos (url)
7365 "Call `apropos' when pushing the corresponding URL button."
7366 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7368 (defun gnus-button-handle-apropos-command (url)
7369 "Call `apropos' when pushing the corresponding URL button."
7371 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7373 (defun gnus-button-handle-apropos-variable (url)
7374 "Call `apropos' when pushing the corresponding URL button."
7376 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7377 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7379 (defun gnus-button-handle-apropos-documentation (url)
7380 "Call `apropos' when pushing the corresponding URL button."
7382 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7383 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7385 (defun gnus-button-handle-library (url)
7386 "Call `locate-library' when pushing the corresponding URL button."
7387 (gnus-message 9 "url=`%s'" url)
7388 (let* ((lib (locate-library url))
7389 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7391 (gnus-message 1 "Cannot locale library `%s'." url)
7392 (find-file-read-only file))))
7394 (defcustom gnus-button-man-level 5
7395 "*Integer that says how many man-related buttons Gnus will show.
7396 The higher the number, the more buttons will appear and the more false
7397 positives are possible. Note that you can set this variable local to
7398 specific groups. Setting it higher in Unix groups is probably a good idea.
7399 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7400 how to set variables in specific groups."
7402 :group 'gnus-article-buttons
7403 :link '(custom-manual "(gnus)Group Parameters")
7406 (defcustom gnus-button-emacs-level 5
7407 "*Integer that says how many emacs-related buttons Gnus will show.
7408 The higher the number, the more buttons will appear and the more false
7409 positives are possible. Note that you can set this variable local to
7410 specific groups. Setting it higher in Emacs or Gnus related groups is
7411 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7412 `gnus-parameters' on how to set variables in specific groups."
7414 :group 'gnus-article-buttons
7415 :link '(custom-manual "(gnus)Group Parameters")
7418 (defcustom gnus-button-message-level 5
7419 "*Integer that says how many buttons for news or mail messages will appear.
7420 The higher the number, the more buttons will appear and the more false
7421 positives are possible."
7422 ;; mail addresses, MIDs, URLs for news, ...
7424 :group 'gnus-article-buttons
7427 (defcustom gnus-button-browse-level 5
7428 "*Integer that says how many buttons for browsing will appear.
7429 The higher the number, the more buttons will appear and the more false
7430 positives are possible."
7431 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7433 :group 'gnus-article-buttons
7436 (defcustom gnus-button-alist
7437 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7438 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7439 ((concat "\\b\\(nntp\\|news\\):\\("
7440 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7441 0 t gnus-button-handle-news 2)
7442 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7443 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7444 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7445 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7446 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7447 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7448 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7449 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7450 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7451 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7452 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7453 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7454 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7455 ;; RFC 2368 (The mailto URL scheme)
7456 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7457 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7458 ("\\bmailto:\\([^ \n\t]+\\)"
7459 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7460 ;; Info Konqueror style <info:/foo/bar baz>.
7461 ;; Must come before " Gnus home-grown style".
7462 ("\\binfo://?\\([^'\">\n\t]+\\)"
7463 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7464 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7465 ("\\binfo://\\([^'\">\n\t ]+\\)"
7466 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7467 ;; Info GNOME style <info:foo#bar_baz>
7468 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7469 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7470 ;; Info KDE style <info:(foo)bar baz>
7471 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7472 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7473 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7474 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7475 ("\\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,]*\\)\\)?"
7476 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7477 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7479 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7480 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7481 ;; Emacs help commands
7482 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7483 ;; regexp doesn't match arguments containing ` '.
7484 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7485 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7486 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7487 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7488 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7489 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7490 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7491 ;; The following entries may lead to many false positives so don't enable
7492 ;; them by default (use a high button level).
7493 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7494 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7495 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7496 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7497 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7498 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7499 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7500 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7501 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7502 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7503 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7504 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7505 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7506 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7507 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7508 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7509 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7510 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7511 ;; Unlike the other regexps we really have to require quoting
7512 ;; here to determine where it ends.
7513 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7514 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7515 ("<URL: *\\([^\n<>]*\\)>"
7516 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7517 ;; RFC 2396 (2.4.3., delims) ...
7518 ("\"URL: *\\([^\n\"]*\\)\""
7519 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7521 (gnus-button-url-regexp
7522 0 (>= gnus-button-browse-level 0) browse-url 0)
7524 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7525 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7526 gnus-button-handle-man 1)
7527 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7528 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7529 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7530 gnus-button-handle-man 1)
7531 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7532 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7533 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7534 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7535 ;; Recognizing patches to .el files. This is somewhat obscure,
7536 ;; but considering the percentage of Gnus users who hack Emacs
7538 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7539 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7540 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7541 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7542 ;; MID or mail: To avoid too many false positives we don't try to catch
7543 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7544 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7545 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7546 ;; so that non-ambiguous entries (see above) match first.
7547 (gnus-button-mid-or-mail-regexp
7548 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7549 "*Alist of regexps matching buttons in article bodies.
7551 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7552 REGEXP: is the string (case insensitive) matching text around the button (can
7553 also be Lisp expression evaluating to a string),
7554 BUTTON: is the number of the regexp grouping actually matching the button,
7555 FORM: is a Lisp expression which must eval to true for the button to
7557 CALLBACK: is the function to call when the user push this button, and each
7558 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7560 CALLBACK can also be a variable, in that case the value of that
7561 variable it the real callback function."
7562 :group 'gnus-article-buttons
7563 :type '(repeat (list (choice regexp variable sexp)
7564 (integer :tag "Button")
7566 (function :tag "Callback")
7569 (integer :tag "Regexp group")))))
7570 (put 'gnus-button-alist 'risky-local-variable t)
7572 (defcustom gnus-header-button-alist
7573 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7574 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7575 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7576 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7577 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7578 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7579 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7580 0 (>= gnus-button-browse-level 0) browse-url 0)
7581 ("^Subject:" gnus-button-url-regexp
7582 0 (>= gnus-button-browse-level 0) browse-url 0)
7583 ("^[^:]+:" gnus-button-url-regexp
7584 0 (>= gnus-button-browse-level 0) browse-url 0)
7585 ("^OpenPGP:.*url=" gnus-button-url-regexp
7586 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7587 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7588 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7589 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7590 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7591 "*Alist of headers and regexps to match buttons in article heads.
7593 This alist is very similar to `gnus-button-alist', except that each
7594 alist has an additional HEADER element first in each entry:
7596 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7598 HEADER is a regexp to match a header. For a fuller explanation, see
7599 `gnus-button-alist'."
7600 :group 'gnus-article-buttons
7601 :group 'gnus-article-headers
7602 :type '(repeat (list (regexp :tag "Header")
7603 (choice regexp variable)
7604 (integer :tag "Button")
7606 (function :tag "Callback")
7609 (integer :tag "Regexp group")))))
7610 (put 'gnus-header-button-alist 'risky-local-variable t)
7614 (defun gnus-article-push-button (event)
7615 "Check text under the mouse pointer for a callback function.
7616 If the text under the mouse pointer has a `gnus-callback' property,
7617 call it with the value of the `gnus-data' text property."
7619 (set-buffer (window-buffer (posn-window (event-start event))))
7620 (let* ((pos (posn-point (event-start event)))
7621 (data (get-text-property pos 'gnus-data))
7622 (fun (get-text-property pos 'gnus-callback)))
7625 (funcall fun data))))
7627 (defun gnus-article-press-button ()
7628 "Check text at point for a callback function.
7629 If the text at point has a `gnus-callback' property,
7630 call it with the value of the `gnus-data' text property."
7632 (let ((data (get-text-property (point) 'gnus-data))
7633 (fun (get-text-property (point) 'gnus-callback)))
7635 (funcall fun data))))
7637 (defun gnus-article-highlight (&optional force)
7638 "Highlight current article.
7639 This function calls `gnus-article-highlight-headers',
7640 `gnus-article-highlight-citation',
7641 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7642 do the highlighting. See the documentation for those functions."
7643 (interactive (list 'force))
7644 (gnus-article-highlight-headers)
7645 (gnus-article-highlight-citation force)
7646 (gnus-article-highlight-signature)
7647 (gnus-article-add-buttons)
7648 (gnus-article-add-buttons-to-head))
7650 (defun gnus-article-highlight-some (&optional force)
7651 "Highlight current article.
7652 This function calls `gnus-article-highlight-headers',
7653 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7654 do the highlighting. See the documentation for those functions."
7655 (interactive (list 'force))
7656 (gnus-article-highlight-headers)
7657 (gnus-article-highlight-signature)
7658 (gnus-article-add-buttons))
7660 (defun gnus-article-highlight-headers ()
7661 "Highlight article headers as specified by `gnus-header-face-alist'."
7663 (gnus-with-article-headers
7664 (let (regexp header-face field-face from hpoints fpoints)
7665 (dolist (entry gnus-header-face-alist)
7666 (goto-char (point-min))
7667 (setq regexp (concat "^\\("
7668 (if (string-equal "" (nth 0 entry))
7672 header-face (nth 1 entry)
7673 field-face (nth 2 entry))
7674 (while (and (re-search-forward regexp nil t)
7678 (unless (search-forward ":" nil t)
7680 (when (and header-face
7681 (not (memq (point) hpoints)))
7682 (push (point) hpoints)
7683 (gnus-put-text-property from (point) 'face header-face))
7684 (when (and field-face
7685 (not (memq (setq from (point)) fpoints)))
7687 (if (re-search-forward "^[^ \t]" nil t)
7689 (goto-char (point-max)))
7690 (gnus-put-text-property from (point) 'face field-face)))))))
7692 (defun gnus-article-highlight-signature ()
7693 "Highlight the signature in an article.
7694 It does this by highlighting everything after
7695 `gnus-signature-separator' using the face `gnus-signature'."
7697 (gnus-with-article-buffer
7698 (let ((inhibit-point-motion-hooks t))
7700 (when (and gnus-signature-face
7701 (gnus-article-narrow-to-signature))
7702 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7703 'face gnus-signature-face)
7705 (gnus-article-search-signature)
7706 (let ((start (match-beginning 0))
7707 (end (set-marker (make-marker) (1+ (match-end 0)))))
7708 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7711 (defun gnus-button-in-region-p (b e prop)
7712 "Say whether PROP exists in the region."
7713 (text-property-not-all b e prop nil))
7715 (defun gnus-article-add-buttons ()
7716 "Find external references in the article and make buttons of them.
7717 \"External references\" are things like Message-IDs and URLs, as
7718 specified by `gnus-button-alist'."
7720 (gnus-with-article-buffer
7721 (let ((inhibit-point-motion-hooks t)
7722 (case-fold-search t)
7723 (alist gnus-button-alist)
7725 ;; We skip the headers.
7728 (while (setq entry (pop alist))
7729 (setq regexp (eval (car entry)))
7731 (while (re-search-forward regexp nil t)
7732 (let ((start (match-beginning (nth 1 entry)))
7733 (end (match-end (nth 1 entry)))
7734 (from (match-beginning 0)))
7735 (when (and (eval (nth 2 entry))
7736 (not (gnus-button-in-region-p
7737 start end 'gnus-callback)))
7738 ;; That optional form returned non-nil, so we add the
7740 (setq from (set-marker (make-marker) from))
7741 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7742 (gnus-article-extend-url-button from start end))
7743 (gnus-article-add-button start end
7744 'gnus-button-push (list from entry))
7745 (gnus-put-text-property
7747 'gnus-string (buffer-substring-no-properties
7750 (defun gnus-article-extend-url-button (beg start end)
7751 "Extend url button if url is folded into two or more lines.
7752 Return non-nil if button is extended. BEG is a marker that points to
7753 the beginning position of a text containing url. START and END are
7754 the endpoints of a url button before it is extended. The concatenated
7755 url is put as the `gnus-button-url' overlay property on the button."
7756 (let ((opoint (point))
7757 (points (list start end))
7762 (not (looking-at "[\t ]*[\">]")))
7766 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7767 (buffer-substring (point-at-bol) start)))
7769 (setq url (list (buffer-substring start end))
7770 delim (if (match-beginning 1) ">" "\""))
7772 (setq regexp (concat
7773 (when (and (looking-at
7774 message-cite-prefix-regexp)
7775 (< (match-end 0) start))
7776 (regexp-quote (match-string 0)))
7778 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7782 (and (looking-at regexp)
7785 (push (or (match-string 2)
7788 (push (setq end (or (match-end 2)
7791 (push (or (match-beginning 2)
7792 (match-beginning 1))
7794 (match-beginning 2)))
7795 (let (gnus-article-mouse-face widget-mouse-face)
7797 (gnus-article-add-button (pop points) (pop points)
7798 'gnus-button-push beg)))
7799 (let ((overlay (gnus-make-overlay start end)))
7800 (gnus-overlay-put overlay 'evaporate t)
7801 (gnus-overlay-put overlay 'gnus-button-url
7802 (list (mapconcat 'identity (nreverse url) "")))
7803 (when gnus-article-mouse-face
7804 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7806 (goto-char opoint))))
7808 ;; Add buttons to the head of an article.
7809 (defun gnus-article-add-buttons-to-head ()
7810 "Add buttons to the head of the article."
7812 (gnus-with-article-headers
7814 (dolist (entry gnus-header-button-alist)
7815 ;; Each alist entry.
7816 (goto-char (point-min))
7817 (while (re-search-forward (car entry) nil t)
7818 ;; Each header matching the entry.
7819 (setq beg (match-beginning 0))
7820 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7821 (match-beginning 0))
7824 (while (re-search-forward (eval (nth 1 entry)) end t)
7825 ;; Each match within a header.
7826 (let* ((entry (cdr entry))
7827 (start (match-beginning (nth 1 entry)))
7828 (end (match-end (nth 1 entry)))
7829 (form (nth 2 entry)))
7830 (goto-char (match-end 0))
7832 (gnus-article-add-button
7833 start end (nth 3 entry)
7834 (buffer-substring (match-beginning (nth 4 entry))
7835 (match-end (nth 4 entry)))))))
7836 (goto-char end))))))
7838 ;;; External functions:
7840 (defun gnus-article-add-button (from to fun &optional data text)
7841 "Create a button between FROM and TO with callback FUN and data DATA."
7842 (when gnus-article-button-face
7843 (gnus-overlay-put (gnus-make-overlay from to nil t)
7844 'face gnus-article-button-face))
7845 (gnus-add-text-properties
7847 (nconc (and gnus-article-mouse-face
7848 (list gnus-mouse-face-prop gnus-article-mouse-face))
7849 (list 'gnus-callback fun)
7850 (and data (list 'gnus-data data))))
7851 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7852 :help-echo (or text "Follow the link")
7853 :keymap gnus-url-button-map
7854 :button-keymap gnus-widget-button-keymap))
7856 (defun gnus-article-copy-string ()
7857 "Copy the string in the button to the kill ring."
7859 (gnus-article-check-buffer)
7860 (let ((data (get-text-property (point) 'gnus-string)))
7864 (copy-region-as-kill (point-min) (point-max))
7865 (message "Copied %s" data)))))
7867 ;;; Internal functions:
7869 (defun gnus-article-set-globals ()
7870 (with-current-buffer gnus-summary-buffer
7871 (gnus-set-global-variables)))
7873 (defun gnus-signature-toggle (end)
7874 (gnus-with-article-buffer
7875 (let ((inhibit-point-motion-hooks t))
7876 (if (text-property-any end (point-max) 'article-type 'signature)
7878 (gnus-delete-wash-type 'signature)
7879 (gnus-remove-text-properties-when
7880 'article-type 'signature end (point-max)
7881 (cons 'article-type (cons 'signature
7882 gnus-hidden-properties))))
7883 (gnus-add-wash-type 'signature)
7884 (gnus-add-text-properties-when
7885 'article-type nil end (point-max)
7886 (cons 'article-type (cons 'signature
7887 gnus-hidden-properties)))))
7888 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7889 (gnus-set-mode-line 'article))))
7891 (defun gnus-button-push (marker-and-entry)
7892 ;; Push button starting at MARKER.
7894 (let* ((marker (car marker-and-entry))
7895 (entry (cadr marker-and-entry))
7896 (regexp (car entry))
7897 (inhibit-point-motion-hooks t))
7899 ;; This is obviously true, or something bad is happening :)
7900 ;; But we need it to have the match-data
7901 (when (looking-at (or (if (symbolp regexp)
7902 (symbol-value regexp)
7904 (let ((fun (nth 3 entry))
7905 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7906 (get-char-property marker 'gnus-button-url))
7907 (mapcar (lambda (group)
7908 (let ((string (match-string group)))
7909 (set-text-properties
7910 0 (length string) nil string)
7912 (nthcdr 4 entry)))))
7918 (fboundp (symbol-value fun)))
7919 (apply (symbol-value fun) args))
7921 (gnus-message 1 "You must define `%S' to use this button"
7922 (cons fun args)))))))))
7924 (defun gnus-parse-news-url (url)
7925 (let (scheme server port group message-id articles)
7928 (goto-char (point-min))
7929 (when (looking-at "\\([A-Za-z]+\\):")
7930 (setq scheme (match-string 1))
7931 (goto-char (match-end 0)))
7932 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7933 (setq server (match-string 1))
7934 (setq port (if (stringp (match-string 3))
7935 (string-to-number (match-string 3))
7937 (goto-char (match-end 0)))
7940 ((looking-at "\\(.*@.*\\)")
7941 (setq message-id (match-string 1)))
7942 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7943 (setq group (match-string 1)
7944 articles (split-string (match-string 2) "-")))
7945 ((looking-at "\\([^/]+\\)/?")
7946 (setq group (match-string 1)))
7948 (error "Unknown news URL syntax"))))
7949 (list scheme server port group message-id articles)))
7951 (defun gnus-button-handle-news (url)
7953 (destructuring-bind (scheme server port group message-id articles)
7954 (gnus-parse-news-url url)
7957 (with-current-buffer gnus-summary-buffer
7959 (let ((gnus-refer-article-method
7960 (nconc (list (list 'nntp server))
7961 gnus-refer-article-method))
7962 (nntp-port-number (or port "nntp")))
7963 (gnus-message 7 "Fetching %s with %s"
7964 message-id gnus-refer-article-method)
7965 (gnus-summary-refer-article message-id))
7966 (gnus-summary-refer-article message-id))))
7968 (gnus-button-fetch-group url)))))
7970 (defun gnus-button-patch (library line)
7971 "Visit an Emacs Lisp library LIBRARY on line LINE."
7973 (let ((file (locate-library (file-name-nondirectory library))))
7975 (error "Couldn't find library %s" library))
7977 (goto-char (point-min))
7978 (forward-line (1- (string-to-number line)))))
7980 (defun gnus-button-handle-man (url)
7982 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7983 (when (eq gnus-button-man-handler 'woman)
7984 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7985 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7986 (funcall gnus-button-man-handler url))
7988 (defun gnus-button-handle-info-url (url)
7989 "Fetch an info URL."
7990 (setq url (mm-subst-char-in-string ?+ ?\ url))
7992 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7993 (gnus-info-find-node
7994 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7996 ")" (gnus-url-unhex-string (match-string 2 url)))))
7997 ((string-match "([^)\"]+)[^\"]+" url)
7999 (gnus-replace-in-string
8000 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8001 (gnus-info-find-node url))
8002 (t (error "Can't parse %s" url))))
8004 (defun gnus-button-handle-info-url-gnome (url)
8005 "Fetch GNOME style info URL."
8006 (setq url (mm-subst-char-in-string ?_ ?\ url))
8007 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8008 (gnus-info-find-node
8010 (gnus-url-unhex-string
8011 (match-string 1 url))
8013 (or (gnus-url-unhex-string
8014 (match-string 2 url))
8016 (error "Can't parse %s" url)))
8018 (defun gnus-button-handle-info-url-kde (url)
8019 "Fetch KDE style info URL."
8020 (gnus-info-find-node (gnus-url-unhex-string url)))
8022 ;; (info) will autoload info.el
8023 (declare-function Info-menu "info" (menu-item &optional fork))
8024 (declare-function Info-index-next "info" (num))
8026 (defun gnus-button-handle-info-keystrokes (url)
8027 "Call `info' when pushing the corresponding URL button."
8028 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8029 (let (node indx comma)
8031 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8032 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8033 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8034 "\\(?:[ \t\n,]*\\)\\)?")
8036 (setq node (match-string 2 url)
8037 indx (match-string 3 url))
8038 (error "Can't parse %s" url))
8042 (when (> (length indx) 0)
8043 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8046 (setq comma (match-string 2 indx))
8047 (setq indx (match-string 1 indx))
8050 (dotimes (i (with-temp-buffer
8052 ;; Note: the XEmacs version of `how-many' takes
8053 ;; no optional argument.
8054 (goto-char (point-min))
8056 (Info-index-next 1)))
8059 (autoload 'pgg-snarf-keys-region "pgg")
8060 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8061 (declare-function pgg-display-output-buffer "pgg" (start end status))
8063 (defun gnus-button-openpgp (url)
8064 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8066 (mm-url-insert-file-contents-external url)
8067 (pgg-snarf-keys-region (point-min) (point-max))
8068 (pgg-display-output-buffer nil nil nil)))
8070 (defun gnus-button-message-id (message-id)
8072 (with-current-buffer gnus-summary-buffer
8073 (gnus-summary-refer-article message-id)))
8075 (defun gnus-button-fetch-group (address &rest ignore)
8076 "Fetch GROUP specified by ADDRESS."
8077 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8079 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8080 ;; for nntp:// and news://
8081 (setq address (match-string 3 address)))
8082 (if (not (string-match "[:/]" address))
8083 ;; This is just a simple group url.
8084 (gnus-group-read-ephemeral-group address gnus-select-method)
8087 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8089 (error "Can't parse %s" address)
8090 (gnus-group-read-ephemeral-group
8091 (match-string 4 address)
8092 `(nntp ,(match-string 1 address)
8093 (nntp-address ,(match-string 1 address))
8094 (nntp-port-number ,(if (match-end 3)
8095 (match-string 3 address)
8098 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8100 (defun gnus-url-parse-query-string (query &optional downcase)
8101 (let (retval pairs cur key val)
8102 (setq pairs (split-string query "&"))
8104 (setq cur (car pairs)
8106 (if (not (string-match "=" cur))
8108 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8109 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8111 (setq key (downcase key)))
8112 (setq cur (assoc key retval))
8114 (setcdr cur (cons val (cdr cur)))
8115 (setq retval (cons (list key val) retval)))))
8118 (defun gnus-url-mailto (url)
8119 ;; Send mail to someone
8120 (setq url (replace-regexp-in-string "\n" " " url))
8121 (when (string-match "mailto:/*\\(.*\\)" url)
8122 (setq url (substring url (match-beginning 1) nil)))
8123 (let (to args subject func)
8124 (setq args (gnus-url-parse-query-string
8125 (if (string-match "^\\?" url)
8127 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8128 (concat "to=" (match-string 1 url) "&"
8129 (match-string 2 url))
8130 (concat "to=" url))))
8131 subject (cdr-safe (assoc "subject" args)))
8134 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8137 (message-position-on-field (caar args)))
8138 (insert (gnus-replace-in-string
8139 (mapconcat 'identity (reverse (cdar args)) ", ")
8141 (setq args (cdr args)))
8144 (message-goto-subject))))
8146 (defun gnus-button-embedded-url (address)
8147 "Activate ADDRESS with `browse-url'."
8148 (browse-url (gnus-strip-whitespace address)))
8150 ;;; Next/prev buttons in the article buffer.
8152 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8153 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8155 (defvar gnus-prev-page-map
8156 (let ((map (make-sparse-keymap)))
8157 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8158 (define-key map "\r" 'gnus-button-prev-page)
8161 (defvar gnus-next-page-map
8162 (let ((map (make-sparse-keymap)))
8163 (define-key map gnus-mouse-2 'gnus-button-next-page)
8164 (define-key map "\r" 'gnus-button-next-page)
8167 (defun gnus-insert-prev-page-button ()
8169 (inhibit-read-only t))
8171 gnus-prev-page-line-format nil
8172 `(keymap ,gnus-prev-page-map
8174 gnus-callback gnus-article-button-prev-page
8175 article-type annotation))
8177 ;; Exclude a newline.
8180 (when gnus-article-button-face
8181 (gnus-overlay-put (gnus-make-overlay b e nil t)
8182 'face gnus-article-button-face))
8183 (widget-convert-button
8185 :action 'gnus-button-prev-page
8186 :button-keymap gnus-prev-page-map)))
8188 (defun gnus-button-next-page (&optional args more-args)
8189 "Go to the next page."
8191 (let ((win (selected-window)))
8192 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8193 (gnus-article-next-page)
8194 (select-window win)))
8196 (defun gnus-button-prev-page (&optional args more-args)
8197 "Go to the prev page."
8199 (let ((win (selected-window)))
8200 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8201 (gnus-article-prev-page)
8202 (select-window win)))
8204 (defun gnus-insert-next-page-button ()
8206 (inhibit-read-only t))
8207 (gnus-eval-format gnus-next-page-line-format nil
8208 `(keymap ,gnus-next-page-map
8210 gnus-callback gnus-article-button-next-page
8211 article-type annotation))
8213 ;; Exclude a newline.
8216 (when gnus-article-button-face
8217 (gnus-overlay-put (gnus-make-overlay b e nil t)
8218 'face gnus-article-button-face))
8219 (widget-convert-button
8221 :action 'gnus-button-next-page
8222 :button-keymap gnus-next-page-map)))
8224 (defun gnus-article-button-next-page (arg)
8225 "Go to the next page."
8227 (let ((win (selected-window)))
8228 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8229 (gnus-article-next-page)
8230 (select-window win)))
8232 (defun gnus-article-button-prev-page (arg)
8233 "Go to the prev page."
8235 (let ((win (selected-window)))
8236 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8237 (gnus-article-prev-page)
8238 (select-window win)))
8240 (defvar gnus-decode-header-methods
8241 '(mail-decode-encoded-word-region)
8242 "List of methods used to decode headers.
8244 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8245 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8246 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8247 whose names match REGEXP.
8250 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8251 mail-decode-encoded-word-region
8252 (\"chinese\" . rfc1843-decode-region))
8255 (defvar gnus-decode-header-methods-cache nil)
8257 (defun gnus-multi-decode-header (start end)
8258 "Apply the functions from `gnus-encoded-word-methods' that match."
8259 (unless (and gnus-decode-header-methods-cache
8260 (eq gnus-newsgroup-name
8261 (car gnus-decode-header-methods-cache)))
8262 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8263 (dolist (x gnus-decode-header-methods)
8265 (nconc gnus-decode-header-methods-cache (list x))
8266 (if (and gnus-newsgroup-name
8267 (string-match (car x) gnus-newsgroup-name))
8268 (nconc gnus-decode-header-methods-cache
8270 (let ((xlist gnus-decode-header-methods-cache))
8273 (narrow-to-region start end)
8275 (funcall (pop xlist) (point-min) (point-max))))))
8278 ;;; Treatment top-level handling.
8281 (defvar gnus-inhibit-article-treatments nil)
8283 (defun gnus-treat-article (gnus-treat-condition
8284 &optional part-number total-parts gnus-treat-type)
8285 (let ((gnus-treat-length (- (point-max) (point-min)))
8286 (alist gnus-treatment-function-alist)
8287 (article-goto-body-goes-to-point-min-p t)
8289 (or (not gnus-treat-type)
8291 (let ((list gnus-article-treat-types))
8293 (when (string-match (pop list) gnus-treat-type)
8294 (throw 'found t)))))))
8295 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8297 (gnus-run-hooks 'gnus-part-display-hook)
8298 (dolist (elem alist)
8301 (when (gnus-buffer-live-p gnus-summary-buffer)
8302 (set-buffer gnus-summary-buffer))
8303 (symbol-value (car elem))))
8304 (when (and (or (consp val)
8306 (or (not gnus-inhibit-article-treatments)
8307 (eq gnus-treat-condition 'head))
8308 (gnus-treat-predicate val)
8309 (or (not (get (car elem) 'highlight))
8312 (funcall (cadr elem)))))))
8314 ;; Dynamic variables.
8315 (defvar part-number)
8316 (defvar total-parts)
8317 (defvar gnus-treat-type)
8318 (defvar gnus-treat-condition)
8319 (defvar gnus-treat-length)
8321 (defun gnus-treat-predicate (val)
8325 (gnus-treat-condition
8326 (eq gnus-treat-condition val))
8328 (stringp (car val)))
8329 (apply 'gnus-or (mapcar `(lambda (s)
8330 (string-match s ,(or gnus-newsgroup-name "")))
8333 (let ((pred (pop val)))
8336 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8338 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8340 (not (gnus-treat-predicate (car val))))
8342 (equal (car val) gnus-treat-type))
8344 (error "%S is not a valid predicate" pred)))))
8352 (eq part-number total-parts))
8354 (< gnus-treat-length val))
8356 (error "%S is not a valid value" val))))
8358 (defun gnus-article-encrypt-body (protocol &optional n)
8359 "Encrypt the article body."
8362 (or gnus-article-encrypt-protocol
8363 (gnus-completing-read "Encrypt protocol"
8364 (mapcar 'car gnus-article-encrypt-protocol-alist)
8366 current-prefix-arg))
8367 ;; User might hit `K E' instead of `K e', so prompt once.
8368 (when (and gnus-article-encrypt-protocol
8370 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8371 (error "Encrypt aborted")))
8372 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8374 (error "Can't find the encrypt protocol %s" protocol))
8375 (if (member gnus-newsgroup-name '("nndraft:delayed"
8378 (error "Can't encrypt the article in group %s"
8379 gnus-newsgroup-name))
8380 (gnus-summary-iterate n
8381 (with-current-buffer gnus-summary-buffer
8382 (let ((mail-parse-charset gnus-newsgroup-charset)
8383 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8384 (summary-buffer gnus-summary-buffer)
8386 (gnus-set-global-variables)
8387 (when (gnus-group-read-only-p)
8388 (error "The current newsgroup does not support article encrypt"))
8389 (gnus-summary-show-article t)
8391 (or (mail-header-references gnus-current-headers) ""))
8392 (set-buffer gnus-article-buffer)
8393 (let* ((inhibit-read-only t)
8395 (mapcar (lambda (field)
8396 (and (save-restriction
8397 (message-narrow-to-head)
8398 (goto-char (point-min))
8399 (search-forward field nil t))
8401 (message-narrow-to-field)
8403 (delete-region (point-min) (point-max))
8405 '("Content-Type:" "Content-Transfer-Encoding:"
8406 "Content-Disposition:"))))
8407 (message-narrow-to-head)
8408 (message-remove-header "MIME-Version")
8409 (goto-char (point-max))
8410 (setq point (point))
8411 (insert (apply 'concat headers))
8413 (narrow-to-region point (point-max))
8414 (let ((message-options message-options))
8415 (message-options-set 'message-sender user-mail-address)
8416 (message-options-set 'message-recipients user-mail-address)
8417 (message-options-set 'message-sign-encrypt 'not)
8419 (goto-char (point-min))
8420 (insert "MIME-Version: 1.0\n")
8422 (gnus-summary-edit-article-done
8423 references nil summary-buffer t))
8424 (when gnus-keep-backlog
8425 (gnus-backlog-remove-article
8426 (car gnus-article-current) (cdr gnus-article-current)))
8427 (gnus-flush-original-article-buffer)
8428 (when gnus-use-cache
8429 (gnus-cache-update-article
8430 (car gnus-article-current) (cdr gnus-article-current))))))))
8432 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8433 "The following specs can be used:
8434 %t The security MIME type
8437 %D Details if button is pressed")
8439 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8440 "The following specs can be used:
8441 %t The security MIME type
8444 %D Details if button is pressed")
8446 (defvar gnus-mime-security-button-line-format-alist
8447 '((?t gnus-tmp-type ?s)
8448 (?i gnus-tmp-info ?s)
8449 (?d gnus-tmp-details ?s)
8450 (?D gnus-tmp-pressed-details ?s)))
8452 (defvar gnus-mime-security-button-commands
8453 '((gnus-article-press-button "\r" "Show Detail")
8457 (gnus-mime-security-save-part "o" "Save...")
8466 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8469 (defvar gnus-mime-security-button-map
8470 (let ((map (make-sparse-keymap)))
8471 (define-key map gnus-mouse-2 'gnus-article-push-button)
8472 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8473 (dolist (c gnus-mime-security-button-commands)
8474 (define-key map (cadr c) (car c)))
8478 gnus-mime-security-button-menu gnus-mime-security-button-map
8479 "Security button menu."
8483 (unless (eq (car c) 'undefined)
8484 (vector (caddr c) (car c) :active t)))
8485 gnus-mime-security-button-commands))))
8487 (defun gnus-mime-security-button-menu (event prefix)
8488 "Construct a context-sensitive menu of security commands."
8489 (interactive "e\nP")
8490 (save-window-excursion
8491 (let ((pos (event-start event)))
8492 (select-window (posn-window pos))
8493 (goto-char (posn-point pos))
8494 (gnus-article-check-buffer)
8495 (popup-menu gnus-mime-security-button-menu nil prefix))))
8497 (defvar gnus-mime-security-details-buffer nil)
8499 (defvar gnus-mime-security-button-pressed nil)
8501 (defvar gnus-mime-security-show-details-inline t
8502 "If non-nil, show details in the article buffer.")
8504 (defun gnus-mime-security-verify-or-decrypt (handle)
8505 (mm-remove-parts (cdr handle))
8506 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8507 point (inhibit-read-only t))
8509 (goto-char (car region)))
8510 (setq point (point))
8511 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8512 (let* ((mm-verify-option 'known)
8513 (mm-decrypt-option 'known)
8514 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8515 (unless (eq nparts (cdr handle))
8516 (mm-destroy-parts (cdr handle))
8517 (setcdr handle nparts))))
8518 (gnus-mime-display-security handle)
8520 (delete-region (point) (cdr region))
8521 (set-marker (car region) nil)
8522 (set-marker (cdr region) nil))
8525 (defun gnus-mime-security-show-details (handle)
8526 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8528 (gnus-message 5 "No details.")
8529 (if gnus-mime-security-show-details-inline
8530 (let ((gnus-mime-security-button-pressed
8531 (not (get-text-property (point) 'gnus-mime-details)))
8532 (gnus-mime-security-button-line-format
8533 (get-text-property (point) 'gnus-line-format))
8534 (inhibit-read-only t))
8536 (while (eq (get-text-property (point) 'gnus-line-format)
8537 gnus-mime-security-button-line-format)
8541 (narrow-to-region (point) (point))
8542 (gnus-insert-mime-security-button handle))
8543 (delete-region (point)
8544 (or (text-property-not-all
8547 gnus-mime-security-button-line-format)
8550 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8551 (with-current-buffer gnus-mime-security-details-buffer
8554 (setq gnus-mime-security-details-buffer
8555 (gnus-get-buffer-create "*MIME Security Details*")))
8556 (with-current-buffer gnus-mime-security-details-buffer
8558 (goto-char (point-min)))
8559 (pop-to-buffer gnus-mime-security-details-buffer)))))
8561 (defun gnus-mime-security-press-button (handle)
8563 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8564 (gnus-mime-security-show-details handle)
8565 (gnus-mime-security-verify-or-decrypt handle))))
8567 (defun gnus-insert-mime-security-button (handle &optional displayed)
8568 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8571 (or (nth 2 (assoc protocol mm-verify-function-alist))
8572 (nth 2 (assoc protocol mm-decrypt-function-alist))
8574 (if (equal (car handle) "multipart/signed")
8575 " Signed" " Encrypted")
8578 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8581 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8582 gnus-tmp-pressed-details
8584 (setq gnus-tmp-details
8585 (if gnus-tmp-details
8586 (concat "\n" gnus-tmp-details)
8588 (setq gnus-tmp-pressed-details
8589 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8594 gnus-mime-security-button-line-format
8595 gnus-mime-security-button-line-format-alist
8596 `(keymap ,gnus-mime-security-button-map
8597 gnus-callback gnus-mime-security-press-button
8598 gnus-line-format ,gnus-mime-security-button-line-format
8599 gnus-mime-details ,gnus-mime-security-button-pressed
8600 article-type annotation
8603 ;; Exclude a newline.
8606 (when gnus-article-button-face
8607 (gnus-overlay-put (gnus-make-overlay b e nil t)
8608 'face gnus-article-button-face))
8609 (widget-convert-button
8612 :action 'gnus-widget-press-button
8613 :button-keymap gnus-mime-security-button-map
8616 ;; Needed to properly clear the message due to a bug in
8617 ;; wid-edit (XEmacs only).
8618 (when (boundp 'help-echo-owns-message)
8619 (setq help-echo-owns-message t))
8621 "%S: show detail; %S: more options"
8622 (aref gnus-mouse-2 0)
8623 (aref gnus-down-mouse-3 0))))))
8625 (defun gnus-mime-display-security (handle)
8627 (narrow-to-region (point) (point))
8628 (unless (gnus-unbuttonized-mime-type-p (car handle))
8629 (gnus-insert-mime-security-button handle))
8630 (gnus-mime-display-part (cadr handle))
8633 (unless (gnus-unbuttonized-mime-type-p (car handle))
8634 (let ((gnus-mime-security-button-line-format
8635 gnus-mime-security-button-end-line-format))
8636 (gnus-insert-mime-security-button handle)))
8637 (mm-set-handle-multipart-parameter
8639 (cons (set-marker (make-marker) (point-min))
8640 (set-marker (make-marker) (point-max))))
8641 (goto-char (point-max))))
8643 (defun gnus-mime-security-run-function (function)
8644 "Run FUNCTION with the security part under point."
8645 (gnus-article-check-buffer)
8646 (let ((data (get-text-property (point) 'gnus-data))
8648 (when (and (stringp (car-safe data))
8649 (setq buffer (mm-handle-multipart-original-buffer data))
8650 (setq handle (cadr data)))
8651 (if (bufferp (mm-handle-buffer handle))
8653 (setq handle (cons buffer (copy-sequence (cdr handle))))
8654 (mm-handle-set-undisplayer handle nil))
8655 (setq handle (mm-make-handle
8657 (mm-handle-multipart-ctl-parameter handle 'protocol)
8658 nil nil nil nil nil nil)))
8659 (funcall function handle))))
8661 (defun gnus-mime-security-save-part ()
8662 "Save the security part under point."
8664 (gnus-mime-security-run-function 'mm-save-part))
8666 (defun gnus-mime-security-pipe-part ()
8667 "Pipe the security part under point to a process."
8669 (gnus-mime-security-run-function 'mm-pipe-part))
8675 (run-hooks 'gnus-art-load-hook)
8677 ;;; gnus-art.el ends here