1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
33 (defvar w3m-minor-mode-map))
36 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
38 (let ((recursive-load-depth-limit 100))
51 (autoload 'gnus-msg-mail "gnus-msg" nil t)
52 (autoload 'gnus-button-mailto "gnus-msg")
53 (autoload 'gnus-button-reply "gnus-msg" nil t)
54 (autoload 'parse-time-string "parse-time" nil nil)
55 (autoload 'ansi-color-apply-on-region "ansi-color")
56 (autoload 'mm-url-insert-file-contents-external "mm-url")
57 (autoload 'mm-extern-cache-contents "mm-extern")
59 (defgroup gnus-article nil
61 :link '(custom-manual "(gnus)Article Buffer")
64 (defgroup gnus-article-treat nil
65 "Treating article parts."
66 :link '(custom-manual "(gnus)Article Hiding")
69 (defgroup gnus-article-hiding nil
70 "Hiding article parts."
71 :link '(custom-manual "(gnus)Article Hiding")
74 (defgroup gnus-article-highlight nil
75 "Article highlighting."
76 :link '(custom-manual "(gnus)Article Highlighting")
80 (defgroup gnus-article-signature nil
82 :link '(custom-manual "(gnus)Article Signature")
85 (defgroup gnus-article-headers nil
87 :link '(custom-manual "(gnus)Hiding Headers")
90 (defgroup gnus-article-washing nil
91 "Special commands on articles."
92 :link '(custom-manual "(gnus)Article Washing")
95 (defgroup gnus-article-emphasis nil
96 "Fontisizing articles."
97 :link '(custom-manual "(gnus)Article Fontisizing")
100 (defgroup gnus-article-saving nil
102 :link '(custom-manual "(gnus)Saving Articles")
103 :group 'gnus-article)
105 (defgroup gnus-article-mime nil
106 "Worshiping the MIME wonder."
107 :link '(custom-manual "(gnus)Using MIME")
108 :group 'gnus-article)
110 (defgroup gnus-article-buttons nil
111 "Pushable buttons in the article buffer."
112 :link '(custom-manual "(gnus)Article Buttons")
113 :group 'gnus-article)
115 (defgroup gnus-article-various nil
116 "Other article options."
117 :link '(custom-manual "(gnus)Misc Article")
118 :group 'gnus-article)
120 (defcustom gnus-ignored-headers
123 (concat "^" header ":"))
124 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
125 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
126 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
127 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
128 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
129 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
130 "X-Attribution" "X-Originating-IP" "Delivered-To"
131 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
132 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
133 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
134 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
135 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
136 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
137 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
138 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
139 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
140 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
141 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
142 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
143 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
144 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
145 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
146 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
147 "List-[A-Za-z]+" "X-Listprocessor-Version"
148 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
149 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
150 "X-Received" "Content-length" "X-precedence"
151 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
152 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
153 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
154 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
155 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
156 "X-Content-length" "X-Posting-Agent" "Original-Received"
157 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
158 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
159 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
160 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
161 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
162 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
163 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
164 "Envelope-Sender" "Envelope-Recipients"))
165 "*All headers that start with this regexp will be hidden.
166 This variable can also be a list of regexps of headers to be ignored.
167 If `gnus-visible-headers' is non-nil, this variable will be ignored."
168 :type '(choice :custom-show nil
171 :group 'gnus-article-hiding)
173 (defcustom gnus-visible-headers
174 "^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:\\|^X-Sent:"
175 "*All headers that do not match this regexp will be hidden.
176 This variable can also be a list of regexp of headers to remain visible.
177 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
178 :type '(repeat :value-to-internal (lambda (widget value)
179 (custom-split-regexp-maybe value))
180 :match (lambda (widget value)
182 (widget-editable-list-match widget value)))
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)
255 (function :value fun)
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 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
537 "A function to save articles in your favourite format.
538 The function will be called by way of the `gnus-summary-save-article'
539 command, and friends such as `gnus-summary-save-article-rmail'.
541 Gnus provides the following functions:
543 * gnus-summary-save-in-rmail (Rmail format)
544 * gnus-summary-save-in-mail (Unix mail format)
545 * gnus-summary-save-in-folder (MH folder)
546 * gnus-summary-save-in-file (article format)
547 * gnus-summary-save-body-in-file (article body)
548 * gnus-summary-save-in-vm (use VM's folder format)
549 * gnus-summary-write-to-file (article format -- overwrite)
550 * gnus-summary-write-body-to-file (article body -- overwrite)
552 The symbol of each function may have the following properties:
555 The value non-nil means save decoded articles. This is meaningful
556 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
557 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
560 The value specifies an alternative function which appends, not
561 overwrites, articles to a file. This implies that when saving many
562 articles at a time, `gnus-prompt-before-saving' is bound to t and all
563 articles are saved in a single file. This is meaningful only with
564 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
567 The value specifies the symbol of a variable of which the value
568 specifies headers to be saved. If it is omitted,
569 `gnus-save-all-headers' and `gnus-saved-headers' control what
570 headers should be saved."
571 :group 'gnus-article-saving
572 :type '(radio (function-item gnus-summary-save-in-rmail)
573 (function-item gnus-summary-save-in-mail)
574 (function-item gnus-summary-save-in-folder)
575 (function-item gnus-summary-save-in-file)
576 (function-item gnus-summary-save-body-in-file)
577 (function-item gnus-summary-save-in-vm)
578 (function-item gnus-summary-write-to-file)
579 (function-item gnus-summary-write-body-to-file)
582 (defcustom gnus-article-save-coding-system
583 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
584 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
585 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
586 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
587 "Coding system used to save decoded articles to a file.
589 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
590 which can safely encode any characters in text. This is used by the
593 * gnus-summary-save-article-file
594 * gnus-summary-save-article-body-file
595 * gnus-summary-write-article-file
596 * gnus-summary-write-article-body-file
598 and the functions to which you may set `gnus-default-article-saver':
600 * gnus-summary-save-in-file
601 * gnus-summary-save-body-in-file
602 * gnus-summary-write-to-file
603 * gnus-summary-write-body-to-file
605 Those commands and functions save just text displayed in the article
606 buffer to a file if the value of this variable is non-nil. Note that
607 buttonized MIME parts will be lost in a saved file in that case.
608 Otherwise, raw articles will be saved."
609 :group 'gnus-article-saving
611 :format "%{%t%}:\n %[Value Menu%] %v"
612 (const :tag "Save raw articles" nil)
615 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
616 '((const :tag "UTF-8" utf-8)
617 (const :tag "iso-2022-7bit" iso-2022-7bit)
618 (const :tag "Emacs internal" emacs-mule)
619 (const :tag "escape-quoted" escape-quoted))))
620 (symbol :tag "Coding system")))
622 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
623 "A function generating a file name to save articles in Rmail format.
624 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
625 :group 'gnus-article-saving
628 (defcustom gnus-mail-save-name 'gnus-plain-save-name
629 "A function generating a file name to save articles in Unix mail format.
630 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
631 :group 'gnus-article-saving
634 (defcustom gnus-folder-save-name 'gnus-folder-save-name
635 "A function generating a file name to save articles in MH folder.
636 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
637 :group 'gnus-article-saving
640 (defcustom gnus-file-save-name 'gnus-numeric-save-name
641 "A function generating a file name to save articles in article format.
642 The function is called with NEWSGROUP, HEADERS, and optional
644 :group 'gnus-article-saving
647 (defcustom gnus-split-methods
648 '((gnus-article-archive-name)
649 (gnus-article-nndoc-name))
650 "*Variable used to suggest where articles are to be saved.
651 For instance, if you would like to save articles related to Gnus in
652 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
653 you could set this variable to something like:
655 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
656 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
658 This variable is an alist where the key is the match and the
659 value is a list of possible files to save in if the match is
662 If the match is a string, it is used as a regexp match on the
663 article. If the match is a symbol, that symbol will be funcalled
664 from the buffer of the article to be saved with the newsgroup as
665 the parameter. If it is a list, it will be evaled in the same
668 If this form or function returns a string, this string will be
669 used as a possible file name; and if it returns a non-nil list,
670 that list will be used as possible file names."
671 :group 'gnus-article-saving
672 :type '(repeat (choice (list :value (fun) function)
673 (cons :value ("" "") regexp (repeat string))
676 (defcustom gnus-page-delimiter "^\^L"
677 "*Regexp describing what to use as article page delimiters.
678 The default value is \"^\^L\", which is a form linefeed at the
679 beginning of a line."
681 :group 'gnus-article-various)
683 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
684 "*The format specification for the article mode line.
685 See `gnus-summary-mode-line-format' for a closer description.
687 The following additional specs are available:
689 %w The article washing status.
690 %m The number of MIME parts in the article."
692 :group 'gnus-article-various)
694 (defcustom gnus-article-mode-hook nil
695 "*A hook for Gnus article mode."
697 :group 'gnus-article-various)
699 (when (featurep 'xemacs)
700 ;; Extracted from gnus-xmas-define in order to preserve user settings
701 (when (fboundp 'turn-off-scroll-in-place)
702 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
703 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
704 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
706 (defcustom gnus-article-menu-hook nil
707 "*Hook run after the creation of the article mode menu."
709 :group 'gnus-article-various)
711 (defcustom gnus-article-prepare-hook nil
712 "*A hook called after an article has been prepared in the article buffer."
714 :group 'gnus-article-various)
716 (defcustom gnus-copy-article-ignored-headers nil
717 "List of headers to be removed when copying an article.
718 Each element is a regular expression."
719 :version "23.0" ;; No Gnus
720 :type '(repeat regexp)
721 :group 'gnus-article-various)
723 (make-obsolete-variable 'gnus-article-hide-pgp-hook
724 "This variable is obsolete in Gnus 5.10.")
727 '((t (:weight bold)))
728 "Face used for highlighting a button in the article buffer."
729 :group 'gnus-article-buttons)
731 (defcustom gnus-article-button-face 'gnus-button
732 "Face used for highlighting buttons in the article buffer.
734 An article button is a piece of text that you can activate by pressing
735 `RET' or `mouse-2' above it."
737 :group 'gnus-article-buttons)
739 (defcustom gnus-article-mouse-face 'highlight
740 "Face used for mouse highlighting in the article buffer.
742 Article buttons will be displayed in this face when the cursor is
745 :group 'gnus-article-buttons)
747 (defcustom gnus-signature-face 'gnus-signature
748 "Face used for highlighting a signature in the article buffer.
749 Obsolete; use the face `gnus-signature' for customizations instead."
751 :group 'gnus-article-highlight
752 :group 'gnus-article-signature)
754 (defface gnus-signature
757 "Face used for highlighting a signature in the article buffer."
758 :group 'gnus-article-highlight
759 :group 'gnus-article-signature)
760 ;; backward-compatibility alias
761 (put 'gnus-signature-face 'face-alias 'gnus-signature)
763 (defface gnus-header-from
766 (:foreground "spring green"))
769 (:foreground "red3"))
772 "Face used for displaying from headers."
773 :group 'gnus-article-headers
774 :group 'gnus-article-highlight)
775 ;; backward-compatibility alias
776 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
778 (defface gnus-header-subject
781 (:foreground "SeaGreen3"))
784 (:foreground "red4"))
786 (:bold t :italic t)))
787 "Face used for displaying subject headers."
788 :group 'gnus-article-headers
789 :group 'gnus-article-highlight)
790 ;; backward-compatibility alias
791 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
793 (defface gnus-header-newsgroups
796 (:foreground "yellow" :italic t))
799 (:foreground "MidnightBlue" :italic t))
802 "Face used for displaying newsgroups headers.
803 In the default setup this face is only used for crossposted
805 :group 'gnus-article-headers
806 :group 'gnus-article-highlight)
807 ;; backward-compatibility alias
808 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
810 (defface gnus-header-name
813 (:foreground "SeaGreen"))
816 (:foreground "maroon"))
819 "Face used for displaying header names."
820 :group 'gnus-article-headers
821 :group 'gnus-article-highlight)
822 ;; backward-compatibility alias
823 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
825 (defface gnus-header-content
828 (:foreground "forest green" :italic t))
831 (:foreground "indianred4" :italic t))
833 (:italic t))) "Face used for displaying header content."
834 :group 'gnus-article-headers
835 :group 'gnus-article-highlight)
836 ;; backward-compatibility alias
837 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
839 (defcustom gnus-header-face-alist
840 '(("From" nil gnus-header-from)
841 ("Subject" nil gnus-header-subject)
842 ("Newsgroups:.*," nil gnus-header-newsgroups)
843 ("" gnus-header-name gnus-header-content))
844 "*Controls highlighting of article headers.
846 An alist of the form (HEADER NAME CONTENT).
848 HEADER is a regular expression which should match the name of a
849 header and NAME and CONTENT are either face names or nil.
851 The name of each header field will be displayed using the face
852 specified by the first element in the list where HEADER matches
853 the header name and NAME is non-nil. Similarly, the content will
854 be displayed by the first non-nil matching CONTENT face."
855 :group 'gnus-article-headers
856 :group 'gnus-article-highlight
857 :type '(repeat (list (regexp :tag "Header")
859 (item :tag "skip" nil)
860 (face :value default))
861 (choice :tag "Content"
862 (item :tag "skip" nil)
863 (face :value default)))))
865 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
866 '((xface . (:face gnus-x-face)))
867 '((pbm . (:face gnus-x-face))
869 "Alist of image types and properties applied to Face and X-Face images.
872 ;; Specify the altitude of Face images in the From header.
873 \(setq gnus-face-properties-alist
874 '((pbm . (:face gnus-x-face :ascent 80))
875 (png . (:ascent 80))))
877 ;; Show Face images as pressed buttons.
878 \(setq gnus-face-properties-alist
879 '((pbm . (:face gnus-x-face :relief -2))
880 (png . (:relief -2))))
882 See the manual for the valid properties for various image types.
883 Currently, `pbm' is used for X-Face images and `png' is used for Face
884 images in Emacs. Only the `:face' property is effective on the `xface'
885 image type in XEmacs if it is built with the libcompface library."
886 :version "23.0" ;; No Gnus
887 :group 'gnus-article-headers
888 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
890 (defcustom gnus-article-decode-hook
891 '(article-decode-charset article-decode-encoded-words
892 article-decode-group-name article-decode-idna-rhs)
893 "*Hook run to decode charsets in articles."
894 :group 'gnus-article-headers
897 (defcustom gnus-display-mime-function 'gnus-display-mime
898 "Function to display MIME articles."
899 :group 'gnus-article-mime
902 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
903 "Function used to decode headers.")
905 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
906 "Function used to decode addresses.")
908 (defvar gnus-article-dumbquotes-map
928 "Table for MS-to-Latin1 translation.")
930 (defcustom gnus-ignored-mime-types nil
931 "List of MIME types that should be ignored by Gnus."
933 :group 'gnus-article-mime
934 :type '(repeat regexp))
936 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
937 "List of MIME types that should not be given buttons when rendered inline.
938 See also `gnus-buttonized-mime-types' which may override this variable.
939 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
941 :group 'gnus-article-mime
942 :type '(repeat regexp))
944 (defcustom gnus-buttonized-mime-types nil
945 "List of MIME types that should be given buttons when rendered inline.
946 If set, this variable overrides `gnus-unbuttonized-mime-types'.
947 To see e.g. security buttons you could set this to
948 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
949 this list to display radio buttons that allow you to choose one of two
950 media types those mails include. See also `mm-discouraged-alternatives'.
951 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
953 :group 'gnus-article-mime
954 :type '(repeat regexp))
956 (defcustom gnus-inhibit-mime-unbuttonizing nil
957 "If non-nil, all MIME parts get buttons.
958 When nil (the default value), then some MIME parts do not get buttons,
959 as described by the variables `gnus-buttonized-mime-types' and
960 `gnus-unbuttonized-mime-types'."
962 :group 'gnus-article-mime
965 (defcustom gnus-body-boundary-delimiter "_"
966 "String used to delimit header and body.
967 This variable is used by `gnus-article-treat-body-boundary' which can
968 be controlled by `gnus-treat-body-boundary'."
970 :group 'gnus-article-various
971 :type '(choice (item :tag "None" :value nil)
974 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
976 "Defines the location of the faces database.
977 For information on obtaining this database of pretty pictures, please
978 see http://www.cs.indiana.edu/picons/ftp/index.html"
980 :type '(repeat directory)
981 :link '(url-link :tag "download"
982 "http://www.cs.indiana.edu/picons/ftp/index.html")
983 :link '(custom-manual "(gnus)Picons")
986 (defun gnus-picons-installed-p ()
987 "Say whether picons are installed on your machine."
988 (let ((installed nil))
989 (dolist (database gnus-picon-databases)
990 (when (file-exists-p database)
994 (defcustom gnus-article-mime-part-function nil
995 "Function called with a MIME handle as the argument.
996 This is meant for people who want to do something automatic based
997 on parts -- for instance, adding Vcard info to a database."
998 :group 'gnus-article-mime
999 :type '(choice (const nil)
1002 (defcustom gnus-mime-multipart-functions nil
1003 "An alist of MIME types to functions to display them."
1005 :group 'gnus-article-mime
1006 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1008 (defcustom gnus-article-date-lapsed-new-header nil
1009 "Whether the X-Sent and Date headers can coexist.
1010 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1011 either replace the old \"Date:\" header (if this variable is nil), or
1012 be added below it (otherwise)."
1014 :group 'gnus-article-headers
1017 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1018 "Function called with a MIME handle as the argument.
1019 This is meant for people who want to view first matched part.
1020 For `undisplayed-alternative' (default), the first undisplayed
1021 part or alternative part is used. For `undisplayed', the first
1022 undisplayed part is used. For a function, the first part which
1023 the function return t is used. For nil, the first part is
1026 :group 'gnus-article-mime
1028 (item :tag "first" :value nil)
1029 (item :tag "undisplayed" :value undisplayed)
1030 (item :tag "undisplayed or alternative"
1031 :value undisplayed-alternative)
1034 (defcustom gnus-mime-action-alist
1035 '(("save to file" . gnus-mime-save-part)
1036 ("save and strip" . gnus-mime-save-part-and-strip)
1037 ("replace with file" . gnus-mime-replace-part)
1038 ("delete part" . gnus-mime-delete-part)
1039 ("display as text" . gnus-mime-inline-part)
1040 ("view the part" . gnus-mime-view-part)
1041 ("pipe to command" . gnus-mime-pipe-part)
1042 ("toggle display" . gnus-article-press-button)
1043 ("toggle display" . gnus-article-view-part-as-charset)
1044 ("view as type" . gnus-mime-view-part-as-type)
1045 ("view internally" . gnus-mime-view-part-internally)
1046 ("view externally" . gnus-mime-view-part-externally))
1047 "An alist of actions that run on the MIME attachment."
1048 :group 'gnus-article-mime
1049 :type '(repeat (cons (string :tag "name")
1052 (defcustom gnus-auto-select-part 1
1053 "Advance to next MIME part when deleting or stripping parts.
1055 When 0, point will be placed on the same part as before. When
1056 positive (negative), move point forward (backwards) this many
1057 parts. When nil, redisplay article."
1058 :version "23.0" ;; No Gnus
1059 :group 'gnus-article-mime
1060 :type '(choice (const nil :tag "Redisplay article.")
1061 (const 1 :tag "Next part.")
1062 (const 0 :tag "Current part.")
1066 ;;; The treatment variables
1069 (defvar gnus-part-display-hook nil
1070 "Hook called on parts that are to receive treatment.")
1072 (defvar gnus-article-treat-custom
1073 '(choice (const :tag "Off" nil)
1075 (const :tag "Header" head)
1076 (const :tag "First" first)
1077 (const :tag "Last" last)
1078 (integer :tag "Less")
1079 (repeat :tag "Groups" regexp)
1080 (sexp :tag "Predicate")))
1082 (defvar gnus-article-treat-head-custom
1083 '(choice (const :tag "Off" nil)
1084 (const :tag "Header" head)))
1086 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1090 (defvar gnus-inhibit-treatment nil
1091 "Whether to inhibit treatment.")
1093 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1094 "Highlight the signature.
1095 Valid values are nil, t, `head', `first', `last', an integer or a
1096 predicate. See Info node `(gnus)Customizing Articles'."
1097 :group 'gnus-article-treat
1098 :link '(custom-manual "(gnus)Customizing Articles")
1099 :type gnus-article-treat-custom)
1100 (put 'gnus-treat-highlight-signature 'highlight t)
1102 (defcustom gnus-treat-buttonize 100000
1104 Valid values are nil, t, `head', `first', `last', an integer or a
1105 predicate. See Info node `(gnus)Customizing Articles'."
1106 :group 'gnus-article-treat
1107 :link '(custom-manual "(gnus)Customizing Articles")
1108 :type gnus-article-treat-custom)
1109 (put 'gnus-treat-buttonize 'highlight t)
1111 (defcustom gnus-treat-buttonize-head 'head
1112 "Add buttons to the head.
1113 Valid values are nil, t, `head', `first', `last', an integer or a
1114 predicate. See Info node `(gnus)Customizing Articles'."
1115 :group 'gnus-article-treat
1116 :link '(custom-manual "(gnus)Customizing Articles")
1117 :type gnus-article-treat-head-custom)
1118 (put 'gnus-treat-buttonize-head 'highlight t)
1120 (defcustom gnus-treat-emphasize
1121 (and (or window-system
1125 Valid values are nil, t, `head', `first', `last', an integer or a
1126 predicate. See Info node `(gnus)Customizing Articles'."
1127 :group 'gnus-article-treat
1128 :link '(custom-manual "(gnus)Customizing Articles")
1129 :type gnus-article-treat-custom)
1130 (put 'gnus-treat-emphasize 'highlight t)
1132 (defcustom gnus-treat-strip-cr nil
1133 "Remove carriage returns.
1134 Valid values are nil, t, `head', `first', `last', an integer or a
1135 predicate. See Info node `(gnus)Customizing Articles'."
1137 :group 'gnus-article-treat
1138 :link '(custom-manual "(gnus)Customizing Articles")
1139 :type gnus-article-treat-custom)
1141 (defcustom gnus-treat-unsplit-urls nil
1142 "Remove newlines from within URLs.
1143 Valid values are nil, t, `head', `first', `last', an integer or a
1144 predicate. See Info node `(gnus)Customizing Articles'."
1146 :group 'gnus-article-treat
1147 :link '(custom-manual "(gnus)Customizing Articles")
1148 :type gnus-article-treat-custom)
1150 (defcustom gnus-treat-leading-whitespace nil
1151 "Remove leading whitespace in headers.
1152 Valid values are nil, t, `head', `first', `last', an integer or a
1153 predicate. See Info node `(gnus)Customizing Articles'."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-custom)
1159 (defcustom gnus-treat-hide-headers 'head
1161 Valid values are nil, t, `head', `first', `last', an integer or a
1162 predicate. See Info node `(gnus)Customizing Articles'."
1163 :group 'gnus-article-treat
1164 :link '(custom-manual "(gnus)Customizing Articles")
1165 :type gnus-article-treat-head-custom)
1167 (defcustom gnus-treat-hide-boring-headers nil
1168 "Hide boring headers.
1169 Valid values are nil, t, `head', `first', `last', an integer or a
1170 predicate. See Info node `(gnus)Customizing Articles'."
1171 :group 'gnus-article-treat
1172 :link '(custom-manual "(gnus)Customizing Articles")
1173 :type gnus-article-treat-head-custom)
1175 (defcustom gnus-treat-hide-signature nil
1176 "Hide the signature.
1177 Valid values are nil, t, `head', `first', `last', an integer or a
1178 predicate. See Info node `(gnus)Customizing Articles'."
1179 :group 'gnus-article-treat
1180 :link '(custom-manual "(gnus)Customizing Articles")
1181 :type gnus-article-treat-custom)
1183 (defcustom gnus-treat-fill-article nil
1185 Valid values are nil, t, `head', `first', `last', an integer or a
1186 predicate. See Info node `(gnus)Customizing Articles'."
1187 :group 'gnus-article-treat
1188 :link '(custom-manual "(gnus)Customizing Articles")
1189 :type gnus-article-treat-custom)
1191 (defcustom gnus-treat-hide-citation nil
1193 Valid values are nil, t, `head', `first', `last', an integer or a
1194 predicate. See Info node `(gnus)Customizing Articles'."
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-hide-citation-maybe nil
1201 Valid values are nil, t, `head', `first', `last', an integer or a
1202 predicate. See Info node `(gnus)Customizing Articles'."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-custom)
1207 (defcustom gnus-treat-strip-list-identifiers 'head
1208 "Strip list identifiers from `gnus-list-identifiers`.
1209 Valid values are nil, t, `head', `first', `last', an integer or a
1210 predicate. See Info node `(gnus)Customizing Articles'."
1212 :group 'gnus-article-treat
1213 :link '(custom-manual "(gnus)Customizing Articles")
1214 :type gnus-article-treat-custom)
1216 (make-obsolete-variable 'gnus-treat-strip-pgp
1217 "This option is obsolete in Gnus 5.10.")
1219 (defcustom gnus-treat-strip-pem nil
1220 "Strip PEM signatures.
1221 Valid values are nil, t, `head', `first', `last', an integer or a
1222 predicate. See Info node `(gnus)Customizing Articles'."
1223 :group 'gnus-article-treat
1224 :link '(custom-manual "(gnus)Customizing Articles")
1225 :type gnus-article-treat-custom)
1227 (defcustom gnus-treat-strip-banner t
1228 "Strip banners from articles.
1229 The banner to be stripped is specified in the `banner' group parameter.
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'."
1232 :group 'gnus-article-treat
1233 :link '(custom-manual "(gnus)Customizing Articles")
1234 :type gnus-article-treat-custom)
1236 (defcustom gnus-treat-highlight-headers 'head
1237 "Highlight the headers.
1238 Valid values are nil, t, `head', `first', `last', an integer or a
1239 predicate. See Info node `(gnus)Customizing Articles'."
1240 :group 'gnus-article-treat
1241 :link '(custom-manual "(gnus)Customizing Articles")
1242 :type gnus-article-treat-head-custom)
1243 (put 'gnus-treat-highlight-headers 'highlight t)
1245 (defcustom gnus-treat-highlight-citation t
1246 "Highlight cited text.
1247 Valid values are nil, t, `head', `first', `last', an integer or a
1248 predicate. See Info node `(gnus)Customizing Articles'."
1249 :group 'gnus-article-treat
1250 :link '(custom-manual "(gnus)Customizing Articles")
1251 :type gnus-article-treat-custom)
1252 (put 'gnus-treat-highlight-citation 'highlight t)
1254 (defcustom gnus-treat-date-ut nil
1255 "Display the Date in UT (GMT).
1256 Valid values are nil, t, `head', `first', `last', an integer or a
1257 predicate. See Info node `(gnus)Customizing Articles'."
1258 :group 'gnus-article-treat
1259 :link '(custom-manual "(gnus)Customizing Articles")
1260 :type gnus-article-treat-head-custom)
1262 (defcustom gnus-treat-date-local nil
1263 "Display the Date in the local timezone.
1264 Valid values are nil, t, `head', `first', `last', an integer or a
1265 predicate. See Info node `(gnus)Customizing Articles'."
1266 :group 'gnus-article-treat
1267 :link '(custom-manual "(gnus)Customizing Articles")
1268 :type gnus-article-treat-head-custom)
1270 (defcustom gnus-treat-date-english nil
1271 "Display the Date in a format that can be read aloud in English.
1272 Valid values are nil, t, `head', `first', `last', an integer or a
1273 predicate. See Info node `(gnus)Customizing Articles'."
1275 :group 'gnus-article-treat
1276 :link '(custom-manual "(gnus)Customizing Articles")
1277 :type gnus-article-treat-head-custom)
1279 (defcustom gnus-treat-date-lapsed nil
1280 "Display the Date header in a way that says how much time has elapsed.
1281 Valid values are nil, t, `head', `first', `last', an integer or a
1282 predicate. See Info node `(gnus)Customizing Articles'."
1283 :group 'gnus-article-treat
1284 :link '(custom-manual "(gnus)Customizing Articles")
1285 :type gnus-article-treat-head-custom)
1287 (defcustom gnus-treat-date-original nil
1288 "Display the date in the original timezone.
1289 Valid values are nil, t, `head', `first', `last', an integer or a
1290 predicate. See Info node `(gnus)Customizing Articles'."
1291 :group 'gnus-article-treat
1292 :link '(custom-manual "(gnus)Customizing Articles")
1293 :type gnus-article-treat-head-custom)
1295 (defcustom gnus-treat-date-iso8601 nil
1296 "Display the date in the ISO8601 format.
1297 Valid values are nil, t, `head', `first', `last', an integer or a
1298 predicate. See Info node `(gnus)Customizing Articles'."
1300 :group 'gnus-article-treat
1301 :link '(custom-manual "(gnus)Customizing Articles")
1302 :type gnus-article-treat-head-custom)
1304 (defcustom gnus-treat-date-user-defined nil
1305 "Display the date in a user-defined format.
1306 The format is defined by the `gnus-article-time-format' variable.
1307 Valid values are nil, t, `head', `first', `last', an integer or a
1308 predicate. See Info node `(gnus)Customizing Articles'."
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-head-custom)
1313 (defcustom gnus-treat-strip-headers-in-body t
1314 "Strip the X-No-Archive header line from the beginning of the body.
1315 Valid values are nil, t, `head', `first', `last', an integer or a
1316 predicate. See Info node `(gnus)Customizing Articles'."
1318 :group 'gnus-article-treat
1319 :link '(custom-manual "(gnus)Customizing Articles")
1320 :type gnus-article-treat-custom)
1322 (defcustom gnus-treat-strip-trailing-blank-lines nil
1323 "Strip trailing blank lines.
1324 Valid values are nil, t, `head', `first', `last', an integer or a
1325 predicate. See Info node `(gnus)Customizing Articles'.
1327 When set to t, it also strips trailing blanks in all MIME parts.
1328 Consider to use `last' instead."
1329 :group 'gnus-article-treat
1330 :link '(custom-manual "(gnus)Customizing Articles")
1331 :type gnus-article-treat-custom)
1333 (defcustom gnus-treat-strip-leading-blank-lines nil
1334 "Strip leading blank lines.
1335 Valid values are nil, t, `head', `first', `last', an integer or a
1336 predicate. See Info node `(gnus)Customizing Articles'.
1338 When set to t, it also strips trailing blanks in all MIME parts."
1339 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :type gnus-article-treat-custom)
1343 (defcustom gnus-treat-strip-multiple-blank-lines nil
1344 "Strip multiple blank lines.
1345 Valid values are nil, t, `head', `first', `last', an integer or a
1346 predicate. See Info node `(gnus)Customizing Articles'."
1347 :group 'gnus-article-treat
1348 :link '(custom-manual "(gnus)Customizing Articles")
1349 :type gnus-article-treat-custom)
1351 (defcustom gnus-treat-unfold-headers 'head
1352 "Unfold folded header lines.
1353 Valid values are nil, t, `head', `first', `last', an integer or a
1354 predicate. See Info node `(gnus)Customizing Articles'."
1356 :group 'gnus-article-treat
1357 :link '(custom-manual "(gnus)Customizing Articles")
1358 :type gnus-article-treat-custom)
1360 (defcustom gnus-article-unfold-long-headers nil
1361 "If non-nil, allow unfolding headers even if the header is long.
1362 If it is a regexp, only long headers matching this regexp are unfolded.
1363 If it is t, all long headers are unfolded.
1365 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1366 :version "23.0" ;; No Gnus
1367 :group 'gnus-article-treat
1368 :type '(choice (const nil)
1369 (const :tag "all" t)
1372 (defcustom gnus-treat-fold-headers nil
1374 Valid values are nil, t, `head', `first', `last', an integer or a
1375 predicate. See Info node `(gnus)Customizing Articles'."
1377 :group 'gnus-article-treat
1378 :link '(custom-manual "(gnus)Customizing Articles")
1379 :type gnus-article-treat-custom)
1381 (defcustom gnus-treat-fold-newsgroups 'head
1382 "Fold the Newsgroups and Followup-To headers.
1383 Valid values are nil, t, `head', `first', `last', an integer or a
1384 predicate. See Info node `(gnus)Customizing Articles'."
1386 :group 'gnus-article-treat
1387 :link '(custom-manual "(gnus)Customizing Articles")
1388 :type gnus-article-treat-custom)
1390 (defcustom gnus-treat-overstrike t
1391 "Treat overstrike highlighting.
1392 Valid values are nil, t, `head', `first', `last', an integer or a
1393 predicate. See Info node `(gnus)Customizing Articles'."
1394 :group 'gnus-article-treat
1395 :link '(custom-manual "(gnus)Customizing Articles")
1396 :type gnus-article-treat-custom)
1397 (put 'gnus-treat-overstrike 'highlight t)
1399 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1400 "Treat ANSI SGR control sequences.
1401 Valid values are nil, t, `head', `first', `last', an integer or a
1402 predicate. See Info node `(gnus)Customizing Articles'."
1403 :group 'gnus-article-treat
1404 :link '(custom-manual "(gnus)Customizing Articles")
1405 :type gnus-article-treat-custom)
1407 (make-obsolete-variable 'gnus-treat-display-xface
1408 'gnus-treat-display-x-face)
1410 (defcustom gnus-treat-display-x-face
1411 (and (not noninteractive)
1412 (gnus-image-type-available-p 'xbm)
1413 (if (featurep 'xemacs)
1415 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1416 (executable-find "icontopbm")))
1418 "Display X-Face headers.
1419 Valid values are nil, t, `head', `first', `last', an integer or a
1420 predicate. See Info node `(gnus)Customizing Articles' and Info
1421 node `(gnus)X-Face' for details."
1422 :group 'gnus-article-treat
1424 :link '(custom-manual "(gnus)Customizing Articles")
1425 :link '(custom-manual "(gnus)X-Face")
1426 :type gnus-article-treat-head-custom
1427 :set (lambda (symbol value)
1430 (cond ((or (boundp symbol) (get symbol 'saved-value))
1432 ((boundp 'gnus-treat-display-xface)
1434 ** gnus-treat-display-xface is an obsolete variable;\
1435 use gnus-treat-display-x-face instead")
1436 (default-value 'gnus-treat-display-xface))
1437 ((get 'gnus-treat-display-xface 'saved-value)
1439 ** gnus-treat-display-xface is an obsolete variable;\
1440 use gnus-treat-display-x-face instead")
1441 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1444 (put 'gnus-treat-display-x-face 'highlight t)
1446 (defcustom gnus-treat-display-face
1447 (and (not noninteractive)
1448 (gnus-image-type-available-p 'png)
1450 "Display Face headers.
1451 Valid values are nil, t, `head', `first', `last', an integer or a
1452 predicate. See Info node `(gnus)Customizing Articles' and Info
1453 node `(gnus)X-Face' for details."
1454 :group 'gnus-article-treat
1456 :link '(custom-manual "(gnus)Customizing Articles")
1457 :link '(custom-manual "(gnus)X-Face")
1458 :type gnus-article-treat-head-custom)
1459 (put 'gnus-treat-display-face 'highlight t)
1461 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1463 Valid values are nil, t, `head', `first', `last', an integer or a
1464 predicate. See Info node `(gnus)Customizing Articles' and Info
1465 node `(gnus)Smileys' for details."
1466 :group 'gnus-article-treat
1468 :link '(custom-manual "(gnus)Customizing Articles")
1469 :link '(custom-manual "(gnus)Smileys")
1470 :type gnus-article-treat-custom)
1471 (put 'gnus-treat-display-smileys 'highlight t)
1473 (defcustom gnus-treat-from-picon
1474 (if (and (gnus-image-type-available-p 'xpm)
1475 (gnus-picons-installed-p))
1477 "Display picons in the From header.
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-from-picon 'highlight t)
1489 (defcustom gnus-treat-mail-picon
1490 (if (and (gnus-image-type-available-p 'xpm)
1491 (gnus-picons-installed-p))
1493 "Display picons in To and Cc 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-mail-picon 'highlight t)
1505 (defcustom gnus-treat-newsgroups-picon
1506 (if (and (gnus-image-type-available-p 'xpm)
1507 (gnus-picons-installed-p))
1509 "Display picons in the Newsgroups and Followup-To headers.
1510 Valid values are nil, t, `head', `first', `last', an integer or a
1511 predicate. See Info node `(gnus)Customizing Articles' and Info
1512 node `(gnus)Picons' for details."
1514 :group 'gnus-article-treat
1516 :link '(custom-manual "(gnus)Customizing Articles")
1517 :link '(custom-manual "(gnus)Picons")
1518 :type gnus-article-treat-head-custom)
1519 (put 'gnus-treat-newsgroups-picon 'highlight t)
1521 (defcustom gnus-treat-body-boundary
1522 (if (and (eq window-system 'x)
1523 (or gnus-treat-newsgroups-picon
1524 gnus-treat-mail-picon
1525 gnus-treat-from-picon))
1527 "Draw a boundary at the end of the headers.
1528 Valid values are nil and `head'.
1529 See Info node `(gnus)Customizing Articles' for details."
1531 :group 'gnus-article-treat
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :type gnus-article-treat-head-custom)
1535 (defcustom gnus-treat-capitalize-sentences nil
1536 "Capitalize sentence-starting words.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles'."
1540 :group 'gnus-article-treat
1541 :link '(custom-manual "(gnus)Customizing Articles")
1542 :type gnus-article-treat-custom)
1544 (defcustom gnus-treat-wash-html nil
1546 Valid values are nil, t, `head', `first', `last', an integer or a
1547 predicate. See Info node `(gnus)Customizing Articles'."
1549 :group 'gnus-article-treat
1550 :link '(custom-manual "(gnus)Customizing Articles")
1551 :type gnus-article-treat-custom)
1553 (defcustom gnus-treat-fill-long-lines nil
1555 Valid values are nil, t, `head', `first', `last', an integer or a
1556 predicate. See Info node `(gnus)Customizing Articles'."
1557 :group 'gnus-article-treat
1558 :link '(custom-manual "(gnus)Customizing Articles")
1559 :type gnus-article-treat-custom)
1561 (defcustom gnus-treat-play-sounds nil
1563 Valid values are nil, t, `head', `first', `last', an integer or a
1564 predicate. See Info node `(gnus)Customizing Articles'."
1566 :group 'gnus-article-treat
1567 :link '(custom-manual "(gnus)Customizing Articles")
1568 :type gnus-article-treat-custom)
1570 (defcustom gnus-treat-translate nil
1571 "Translate articles from one language to another.
1572 Valid values are nil, t, `head', `first', `last', an integer or a
1573 predicate. See Info node `(gnus)Customizing Articles'."
1575 :group 'gnus-article-treat
1576 :link '(custom-manual "(gnus)Customizing Articles")
1577 :type gnus-article-treat-custom)
1579 (defcustom gnus-treat-x-pgp-sig nil
1581 To automatically treat X-PGP-Sig, set it to head.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate. See Info node `(gnus)Customizing Articles'."
1585 :group 'gnus-article-treat
1586 :group 'mime-security
1587 :link '(custom-manual "(gnus)Customizing Articles")
1588 :type gnus-article-treat-custom)
1590 (defvar gnus-article-encrypt-protocol-alist
1591 '(("PGP" . mml2015-self-encrypt)))
1593 ;; Set to nil if more than one protocol added to
1594 ;; gnus-article-encrypt-protocol-alist.
1595 (defcustom gnus-article-encrypt-protocol "PGP"
1596 "The protocol used for encrypt articles.
1597 It is a string, such as \"PGP\". If nil, ask user."
1600 :group 'mime-security)
1602 (defvar gnus-article-wash-function nil
1603 "Function used for converting HTML into text.")
1605 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1606 (mm-coding-system-p 'utf-8)
1607 (executable-find idna-program))
1608 "Whether IDNA decoding of headers is used when viewing messages.
1609 This requires GNU Libidn, and by default only enabled if it is found."
1611 :group 'gnus-article-headers
1614 (defcustom gnus-article-over-scroll nil
1615 "If non-nil, allow scrolling the article buffer even when there no more text."
1617 :group 'gnus-article
1620 ;;; Internal variables
1622 (defvar gnus-english-month-names
1623 '("January" "February" "March" "April" "May" "June" "July" "August"
1624 "September" "October" "November" "December"))
1626 (defvar article-goto-body-goes-to-point-min-p nil)
1627 (defvar gnus-article-wash-types nil)
1628 (defvar gnus-article-emphasis-alist nil)
1629 (defvar gnus-article-image-alist nil)
1631 (defvar gnus-article-mime-handle-alist-1 nil)
1632 (defvar gnus-treatment-function-alist
1633 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1634 (gnus-treat-strip-banner gnus-article-strip-banner)
1635 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1636 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1637 (gnus-treat-buttonize gnus-article-add-buttons)
1638 (gnus-treat-fill-article gnus-article-fill-cited-article)
1639 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1640 (gnus-treat-strip-cr gnus-article-remove-cr)
1641 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1642 (gnus-treat-date-ut gnus-article-date-ut)
1643 (gnus-treat-date-local gnus-article-date-local)
1644 (gnus-treat-date-english gnus-article-date-english)
1645 (gnus-treat-date-original gnus-article-date-original)
1646 (gnus-treat-date-user-defined gnus-article-date-user)
1647 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1648 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1649 (gnus-treat-display-x-face gnus-article-display-x-face)
1650 (gnus-treat-display-face gnus-article-display-face)
1651 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1652 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1653 (gnus-treat-hide-signature gnus-article-hide-signature)
1654 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1655 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1656 (gnus-treat-strip-pem gnus-article-hide-pem)
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-highlight-headers gnus-article-highlight-headers)
1661 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1662 (gnus-treat-strip-trailing-blank-lines
1663 gnus-article-remove-trailing-blank-lines)
1664 (gnus-treat-strip-leading-blank-lines
1665 gnus-article-strip-leading-blank-lines)
1666 (gnus-treat-strip-multiple-blank-lines
1667 gnus-article-strip-multiple-blank-lines)
1668 (gnus-treat-overstrike gnus-article-treat-overstrike)
1669 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1670 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1671 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1672 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1673 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1674 (gnus-treat-display-smileys gnus-treat-smiley)
1675 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1676 (gnus-treat-wash-html gnus-article-wash-html)
1677 (gnus-treat-emphasize gnus-article-emphasize)
1678 (gnus-treat-hide-citation gnus-article-hide-citation)
1679 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1680 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1681 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1682 (gnus-treat-play-sounds gnus-earcon-display)))
1684 (defvar gnus-article-mime-handle-alist nil)
1685 (defvar article-lapsed-timer nil)
1686 (defvar gnus-article-current-summary nil)
1688 (defvar gnus-article-mode-syntax-table
1689 (let ((table (copy-syntax-table text-mode-syntax-table)))
1690 ;; This causes the citation match run O(2^n).
1691 ;; (modify-syntax-entry ?- "w" table)
1692 (modify-syntax-entry ?> ")<" table)
1693 (modify-syntax-entry ?< "(>" table)
1694 ;; make M-. in article buffers work for `foo' strings
1695 (modify-syntax-entry ?' " " table)
1696 (modify-syntax-entry ?` " " table)
1698 "Syntax table used in article mode buffers.
1699 Initialized from `text-mode-syntax-table.")
1701 (defvar gnus-save-article-buffer nil)
1703 (defvar gnus-article-mode-line-format-alist
1704 (nconc '((?w (gnus-article-wash-status) ?s)
1705 (?m (gnus-article-mime-part-status) ?s))
1706 gnus-summary-mode-line-format-alist))
1708 (defvar gnus-number-of-articles-to-be-saved nil)
1710 (defvar gnus-inhibit-hiding nil)
1712 (defvar gnus-article-edit-mode nil)
1714 ;;; Macros for dealing with the article buffer.
1716 (defmacro gnus-with-article-headers (&rest forms)
1718 (set-buffer gnus-article-buffer)
1720 (let ((inhibit-read-only t)
1721 (inhibit-point-motion-hooks t)
1722 (case-fold-search t))
1723 (article-narrow-to-head)
1726 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1727 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1729 (defmacro gnus-with-article-buffer (&rest forms)
1731 (set-buffer gnus-article-buffer)
1732 (let ((inhibit-read-only t))
1735 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1736 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1738 (defun gnus-article-goto-header (header)
1739 "Go to HEADER, which is a regular expression."
1740 (re-search-forward (concat "^\\(" header "\\):") nil t))
1742 (defsubst gnus-article-hide-text (b e props)
1743 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1744 (gnus-add-text-properties-when 'article-type nil b e props)
1745 (when (memq 'intangible props)
1747 (max (1- b) (point-min))
1748 b 'intangible (cddr (memq 'intangible props)))))
1750 (defsubst gnus-article-unhide-text (b e)
1751 "Remove hidden text properties from region between B and E."
1752 (remove-text-properties b e gnus-hidden-properties)
1753 (when (memq 'intangible gnus-hidden-properties)
1754 (put-text-property (max (1- b) (point-min))
1755 b 'intangible nil)))
1757 (defun gnus-article-hide-text-type (b e type)
1758 "Hide text of TYPE between B and E."
1759 (gnus-add-wash-type type)
1760 (gnus-article-hide-text
1761 b e (cons 'article-type (cons type gnus-hidden-properties))))
1763 (defun gnus-article-unhide-text-type (b e type)
1764 "Unhide text of TYPE between B and E."
1765 (gnus-delete-wash-type type)
1766 (remove-text-properties
1767 b e (cons 'article-type (cons type gnus-hidden-properties)))
1768 (when (memq 'intangible gnus-hidden-properties)
1769 (put-text-property (max (1- b) (point-min))
1770 b 'intangible nil)))
1772 (defun gnus-article-hide-text-of-type (type)
1773 "Hide text of TYPE in the current buffer."
1775 (let ((b (point-min))
1777 (while (setq b (text-property-any b e 'article-type type))
1778 (add-text-properties b (incf b) gnus-hidden-properties)))))
1780 (defun gnus-article-delete-text-of-type (type)
1781 "Delete text of TYPE in the current buffer."
1783 (let ((b (point-min)))
1784 (if (eq type 'multipart)
1785 ;; Remove MIME buttons associated with multipart/alternative parts.
1788 (while (if (get-text-property (point) 'gnus-part)
1790 (when (setq b (next-single-property-change (point)
1795 (skip-chars-forward "\n")
1796 (when (eq (get-text-property b 'article-type) 'multipart)
1797 (delete-region b (point)))))
1798 (while (setq b (text-property-any b (point-max) 'article-type type))
1800 b (or (text-property-not-all b (point-max) 'article-type type)
1803 (defun gnus-article-delete-invisible-text ()
1804 "Delete all invisible text in the current buffer."
1806 (let ((b (point-min)))
1807 (while (setq b (text-property-any b (point-max) 'invisible t))
1809 b (or (text-property-not-all b (point-max) 'invisible t)
1812 (defun gnus-article-text-type-exists-p (type)
1813 "Say whether any text of type TYPE exists in the buffer."
1814 (text-property-any (point-min) (point-max) 'article-type type))
1816 (defsubst gnus-article-header-rank ()
1817 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1818 (let ((list gnus-sorted-header-list)
1821 (if (looking-at (car list))
1823 (setq list (cdr list))
1827 (defun article-hide-headers (&optional arg delete)
1828 "Hide unwanted headers and possibly sort them as well."
1830 ;; This function might be inhibited.
1831 (unless gnus-inhibit-hiding
1832 (let ((inhibit-read-only t)
1833 (case-fold-search t)
1834 (max (1+ (length gnus-sorted-header-list)))
1835 (inhibit-point-motion-hooks t)
1836 (cur (current-buffer))
1837 ignored visible beg)
1839 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1840 ;; group parameters, so we should go to the summary buffer.
1843 (progn (set-buffer gnus-summary-buffer) t)
1845 (setq ignored (when (not gnus-visible-headers)
1846 (cond ((stringp gnus-ignored-headers)
1847 gnus-ignored-headers)
1848 ((listp gnus-ignored-headers)
1849 (mapconcat 'identity
1850 gnus-ignored-headers
1852 visible (cond ((stringp gnus-visible-headers)
1853 gnus-visible-headers)
1854 ((and gnus-visible-headers
1855 (listp gnus-visible-headers))
1856 (mapconcat 'identity
1857 gnus-visible-headers
1861 ;; First we narrow to just the headers.
1862 (article-narrow-to-head)
1863 ;; Hide any "From " lines at the beginning of (mail) articles.
1864 (while (looking-at "From ")
1867 (delete-region (point-min) (point)))
1868 ;; Then treat the rest of the header lines.
1869 ;; Then we use the two regular expressions
1870 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1871 ;; select which header lines is to remain visible in the
1873 (while (re-search-forward "^[^ \t:]*:" nil t)
1875 ;; Mark the rank of the header.
1877 (point) (1+ (point)) 'message-rank
1878 (if (or (and visible (looking-at visible))
1880 (not (looking-at ignored))))
1881 (gnus-article-header-rank)
1884 (message-sort-headers-1)
1885 (when (setq beg (text-property-any
1886 (point-min) (point-max) 'message-rank (+ 2 max)))
1887 ;; We delete the unwanted headers.
1888 (gnus-add-wash-type 'headers)
1889 (add-text-properties (point-min) (+ 5 (point-min))
1890 '(article-type headers dummy-invisible t))
1891 (delete-region beg (point-max))))))))
1893 (defun article-hide-boring-headers (&optional arg)
1894 "Toggle hiding of headers that aren't very interesting.
1895 If given a negative prefix, always show; if given a positive prefix,
1897 (interactive (gnus-article-hidden-arg))
1898 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1899 (not gnus-show-all-headers))
1902 (let ((inhibit-read-only t)
1903 (inhibit-point-motion-hooks t))
1904 (article-narrow-to-head)
1905 (dolist (elem gnus-boring-article-headers)
1906 (goto-char (point-min))
1908 ;; Hide empty headers.
1910 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1912 (gnus-article-hide-text-type
1916 (if (re-search-forward "^[^ \t]" nil t)
1920 ;; Hide boring Newsgroups header.
1921 ((eq elem 'newsgroups)
1922 (when (gnus-string-equal
1923 (gnus-fetch-field "newsgroups")
1924 (gnus-group-real-name
1925 (if (boundp 'gnus-newsgroup-name)
1928 (gnus-article-hide-header "newsgroups")))
1929 ((eq elem 'to-address)
1930 (let ((to (message-fetch-field "to"))
1932 (gnus-parameter-to-address
1933 (if (boundp 'gnus-newsgroup-name)
1934 gnus-newsgroup-name ""))))
1935 (when (and to to-address
1938 ;; only one address in To
1939 (nth 1 (mail-extract-address-components to))
1941 (gnus-article-hide-header "to"))))
1943 (let ((to (message-fetch-field "to"))
1945 (gnus-parameter-to-list
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-list
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1954 (gnus-article-hide-header "to"))))
1956 (let ((cc (message-fetch-field "cc"))
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and cc to-list
1964 ;; only one address in CC
1965 (nth 1 (mail-extract-address-components cc))
1967 (gnus-article-hide-header "cc"))))
1968 ((eq elem 'followup-to)
1969 (when (gnus-string-equal
1970 (message-fetch-field "followup-to")
1971 (message-fetch-field "newsgroups"))
1972 (gnus-article-hide-header "followup-to")))
1973 ((eq elem 'reply-to)
1974 (if (gnus-group-find-parameter
1975 gnus-newsgroup-name 'broken-reply-to)
1976 (gnus-article-hide-header "reply-to")
1977 (let ((from (message-fetch-field "from"))
1978 (reply-to (message-fetch-field "reply-to")))
1985 (lambda (x) (downcase (cadr x)))
1986 (mail-extract-address-components from t))
1989 (lambda (x) (downcase (cadr x)))
1990 (mail-extract-address-components reply-to t))
1992 (gnus-article-hide-header "reply-to")))))
1994 (let ((date (with-current-buffer gnus-original-article-buffer
1995 ;; If date in `gnus-article-buffer' is localized
1996 ;; (`gnus-treat-date-user-defined'),
1997 ;; `days-between' might fail.
1998 (message-fetch-field "date"))))
2000 (< (days-between (current-time-string) date)
2002 (gnus-article-hide-header "date"))))
2004 (let ((to (message-fetch-field "to"))
2005 (cc (message-fetch-field "cc")))
2006 (when (> (length to) 1024)
2007 (gnus-article-hide-header "to"))
2008 (when (> (length cc) 1024)
2009 (gnus-article-hide-header "cc"))))
2013 (goto-char (point-min))
2014 (while (re-search-forward "^to:" nil t)
2015 (setq to-count (1+ to-count)))
2016 (when (> to-count 1)
2017 (while (> to-count 0)
2018 (goto-char (point-min))
2020 (re-search-forward "^to:" nil nil to-count)
2022 (narrow-to-region (point) (point-max))
2023 (gnus-article-hide-header "to"))
2024 (setq to-count (1- to-count))))
2025 (goto-char (point-min))
2026 (while (re-search-forward "^cc:" nil t)
2027 (setq cc-count (1+ cc-count)))
2028 (when (> cc-count 1)
2029 (while (> cc-count 0)
2030 (goto-char (point-min))
2032 (re-search-forward "^cc:" nil nil cc-count)
2034 (narrow-to-region (point) (point-max))
2035 (gnus-article-hide-header "cc"))
2036 (setq cc-count (1- cc-count)))))))))))))
2038 (defun gnus-article-hide-header (header)
2040 (goto-char (point-min))
2041 (when (re-search-forward (concat "^" header ":") nil t)
2042 (gnus-article-hide-text-type
2046 (if (re-search-forward "^[^ \t]" nil t)
2051 (defvar gnus-article-normalized-header-length 40
2052 "Length of normalized headers.")
2054 (defun article-normalize-headers ()
2055 "Make all header lines 40 characters long."
2057 (let ((inhibit-read-only t)
2061 (article-narrow-to-head)
2064 ((< (setq column (- (point-at-eol) (point)))
2065 gnus-article-normalized-header-length)
2067 (insert (make-string
2068 (- gnus-article-normalized-header-length column)
2070 ((> column gnus-article-normalized-header-length)
2071 (gnus-put-text-property
2073 (forward-char gnus-article-normalized-header-length)
2080 (forward-line 1))))))
2082 (defun article-treat-dumbquotes ()
2083 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2084 Note that this function guesses whether a character is a sm*rtq**t* or
2085 not, so it should only be used interactively.
2087 Sm*rtq**t*s are M****s***'s unilateral extension to the
2088 iso-8859-1 character map in an attempt to provide more quoting
2089 characters. If you see something like \\222 or \\264 where
2090 you're expecting some kind of apostrophe or quotation mark, then
2093 (article-translate-strings gnus-article-dumbquotes-map))
2095 (defun article-translate-characters (from to)
2096 "Translate all characters in the body of the article according to FROM and TO.
2097 FROM is a string of characters to translate from; to is a string of
2098 characters to translate to."
2100 (when (article-goto-body)
2101 (let ((inhibit-read-only t)
2102 (x (make-string 225 ?x))
2104 (while (< (incf i) (length x))
2107 (while (< i (length from))
2108 (aset x (aref from i) (aref to i))
2110 (translate-region (point) (point-max) x)))))
2112 (defun article-translate-strings (map)
2113 "Translate all string in the body of the article according to MAP.
2114 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2116 (when (article-goto-body)
2117 (let ((inhibit-read-only t))
2120 (while (search-forward (car elem) nil t)
2121 (replace-match (cadr elem)))))))))
2123 (defun article-treat-overstrike ()
2124 "Translate overstrikes into bold text."
2127 (when (article-goto-body)
2128 (let ((inhibit-read-only t))
2129 (while (search-forward "\b" nil t)
2130 (let ((next (char-after))
2131 (previous (char-after (- (point) 2))))
2132 ;; We do the boldification/underlining by hiding the
2133 ;; overstrikes and putting the proper text property
2137 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2138 (put-text-property (point) (1+ (point)) 'face 'bold))
2140 (gnus-article-hide-text-type
2141 (1- (point)) (1+ (point)) 'overstrike)
2143 (- (point) 2) (1- (point)) 'face 'underline))
2145 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2147 (point) (1+ (point)) 'face 'underline)))))))))
2149 (defun article-treat-ansi-sequences ()
2150 "Translate ANSI SGR control sequences into overlays or extents."
2153 (when (article-goto-body)
2154 (let ((inhibit-read-only t))
2155 (ansi-color-apply-on-region (point) (point-max))))))
2157 (defun gnus-article-treat-unfold-headers ()
2158 "Unfold folded message headers.
2159 Only the headers that fit into the current window width will be
2162 (gnus-with-article-headers
2166 (mail-header-narrow-to-field)
2167 (let* ((header (buffer-string))
2169 (or (equal gnus-article-unfold-long-headers t)
2170 (and (stringp gnus-article-unfold-long-headers)
2171 (string-match gnus-article-unfold-long-headers header)))))
2174 (goto-char (point-min))
2175 (while (re-search-forward "\n[\t ]" nil t)
2176 (replace-match " " t t)))
2177 (setq length (- (point-max) (point-min) 1))
2178 (when (or unfoldable
2179 (< length (window-width)))
2180 (while (re-search-forward "\n[\t ]" nil t)
2181 (replace-match " " t t))))
2182 (goto-char (point-max)))))))
2184 (defun gnus-article-treat-fold-headers ()
2185 "Fold message headers."
2187 (gnus-with-article-headers
2190 (mail-header-narrow-to-field)
2191 (mail-header-fold-field)
2192 (goto-char (point-max))))))
2194 (defun gnus-treat-smiley ()
2195 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2197 (gnus-with-article-buffer
2198 (if (memq 'smiley gnus-article-wash-types)
2199 (gnus-delete-images 'smiley)
2201 (let ((images (smiley-region (point) (point-max))))
2203 (gnus-add-wash-type 'smiley)
2204 (dolist (image images)
2205 (gnus-add-image 'smiley image)))))))
2207 (defun gnus-article-remove-images ()
2208 "Remove all images from the article buffer."
2210 (gnus-with-article-buffer
2211 (dolist (elem gnus-article-image-alist)
2212 (gnus-delete-images (car elem)))))
2214 (defun gnus-article-treat-fold-newsgroups ()
2215 "Unfold folded message headers.
2216 Only the headers that fit into the current window width will be
2219 (gnus-with-article-headers
2220 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2222 (mail-header-narrow-to-field)
2223 (while (re-search-forward ", *" nil t)
2224 (replace-match ", " t t))
2225 (mail-header-fold-field)
2226 (goto-char (point-max))))))
2228 (defcustom gnus-article-truncate-lines default-truncate-lines
2229 "Value of `truncate-lines' in Gnus Article buffer.
2230 Valid values are nil, t, `head', `first', `last', an integer or a
2231 predicate. See Info node `(gnus)Customizing Articles'."
2232 :version "23.0" ;; No Gnus
2233 :group 'gnus-article
2234 ;; :link '(custom-manual "(gnus)Customizing Articles")
2237 (defun gnus-article-toggle-truncate-lines (&optional arg)
2238 "Toggle whether to fold or truncate long lines in article the buffer.
2239 If ARG is non-nil and not a number, toggle
2240 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2241 long lines iff arg is positive."
2244 ((and (numberp arg) (> arg 0))
2245 (setq gnus-article-truncate-lines t))
2247 (setq gnus-article-truncate-lines nil))
2249 (setq gnus-article-truncate-lines
2250 (not gnus-article-truncate-lines))))
2251 (gnus-with-article-buffer
2253 ((and (numberp arg) (> arg 0))
2254 (setq truncate-lines nil))
2256 (setq truncate-lines t)))
2257 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2258 ;; `toggle-truncate-lines' needs an argument.
2259 (toggle-truncate-lines)))
2261 (defun gnus-article-treat-body-boundary ()
2262 "Place a boundary line at the end of the headers."
2264 (when (and gnus-body-boundary-delimiter
2265 (> (length gnus-body-boundary-delimiter) 0))
2266 (gnus-with-article-headers
2267 (goto-char (point-max))
2268 (let ((start (point)))
2269 (insert "X-Boundary: ")
2270 (gnus-add-text-properties start (point) '(invisible t intangible t))
2272 (while (>= (1- (window-width)) (length str))
2273 (setq str (concat str gnus-body-boundary-delimiter)))
2274 (substring str 0 (1- (window-width))))
2276 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2278 (defun article-fill-long-lines ()
2279 "Fill lines that are wider than the window width."
2282 (let ((inhibit-read-only t)
2283 (width (window-width (get-buffer-window (current-buffer)))))
2286 (let ((adaptive-fill-mode nil)) ;Why? -sm
2289 (when (>= (current-column) (min fill-column width))
2290 (narrow-to-region (min (1+ (point)) (point-max))
2292 (let ((goback (point-marker)))
2293 (fill-paragraph nil)
2294 (goto-char (marker-position goback)))
2296 (forward-line 1)))))))
2298 (defun article-capitalize-sentences ()
2299 "Capitalize the first word in each sentence."
2302 (let ((inhibit-read-only t)
2303 (paragraph-start "^[\n\^L]"))
2307 (forward-sentence)))))
2309 (defun article-remove-cr ()
2310 "Remove trailing CRs and then translate remaining CRs into LFs."
2313 (let ((inhibit-read-only t))
2314 (goto-char (point-min))
2315 (while (re-search-forward "\r+$" nil t)
2316 (replace-match "" t t))
2317 (goto-char (point-min))
2318 (while (search-forward "\r" nil t)
2319 (replace-match "\n" t t)))))
2321 (defun article-remove-trailing-blank-lines ()
2322 "Remove all trailing blank lines from the article."
2325 (let ((inhibit-read-only t))
2326 (goto-char (point-max))
2330 (while (and (not (bobp))
2331 (looking-at "^[ \t]*$")
2332 (not (gnus-annotation-in-region-p
2333 (point) (point-at-eol))))
2339 (defvar gnus-face-properties-alist))
2341 (defun article-display-face ()
2342 "Display any Face headers in the header."
2344 (let ((wash-face-p buffer-read-only))
2345 (gnus-with-article-headers
2346 ;; When displaying parts, this function can be called several times on
2347 ;; the same article, without any intended toggle semantic (as typing `W
2348 ;; D d' would have). So face deletion must occur only when we come from
2349 ;; an interactive command, that is when the *Article* buffer is
2351 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2352 (gnus-delete-images 'face)
2353 (let (face faces from)
2354 (save-current-buffer
2355 (when (and wash-face-p
2356 (gnus-buffer-live-p gnus-original-article-buffer)
2357 (not (re-search-forward "^Face:[\t ]*" nil t)))
2358 (set-buffer gnus-original-article-buffer))
2360 (mail-narrow-to-head)
2361 (while (gnus-article-goto-header "Face")
2362 (push (mail-header-field-value) faces))))
2364 (goto-char (point-min))
2365 (let ((from (gnus-article-goto-header "from"))
2370 (insert "[no `from' set]\n"))
2372 (when (setq png (gnus-convert-face-to-png (pop faces)))
2374 (apply 'gnus-create-image png 'png t
2375 (cdr (assq 'png gnus-face-properties-alist))))
2377 (gnus-add-wash-type 'face)
2378 (gnus-add-image 'face image)
2379 (gnus-put-image image nil 'face))))))))))
2381 (defun article-display-x-face (&optional force)
2382 "Look for an X-Face header and display it if present."
2383 (interactive (list 'force))
2384 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2385 (gnus-with-article-headers
2386 ;; Delete the old process, if any.
2387 (when (process-status "article-x-face")
2388 (delete-process "article-x-face"))
2389 ;; See the comment in `article-display-face'.
2390 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2391 ;; We have already displayed X-Faces, so we remove them
2393 (gnus-delete-images 'xface)
2395 (let (x-faces from face)
2396 (save-current-buffer
2397 (when (and wash-face-p
2398 (gnus-buffer-live-p gnus-original-article-buffer)
2399 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2400 ;; If type `W f', use gnus-original-article-buffer,
2401 ;; otherwise use the current buffer because displaying
2402 ;; RFC822 parts calls this function too.
2403 (set-buffer gnus-original-article-buffer))
2405 (mail-narrow-to-head)
2406 (while (gnus-article-goto-header "X-Face")
2407 (push (mail-header-field-value) x-faces))
2408 (setq from (message-fetch-field "from"))))
2409 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2410 ;; single external face.
2411 (when (stringp gnus-article-x-face-command)
2412 (setq x-faces (list (car x-faces))))
2414 gnus-article-x-face-command
2416 ;; Check whether this face is censored.
2417 (not gnus-article-x-face-too-ugly)
2419 (not (string-match gnus-article-x-face-too-ugly
2421 (while (setq face (pop x-faces))
2422 ;; We display the face.
2423 (cond ((stringp gnus-article-x-face-command)
2424 ;; The command is a string, so we interpret the command
2425 ;; as a, well, command, and fork it off.
2426 (let ((process-connection-type nil))
2427 (gnus-set-process-query-on-exit-flag
2429 "article-x-face" nil shell-file-name
2430 shell-command-switch gnus-article-x-face-command)
2434 (process-send-region "article-x-face"
2435 (point-min) (point-max)))
2436 (process-send-eof "article-x-face")))
2437 ((functionp gnus-article-x-face-command)
2438 ;; The command is a lisp function, so we call it.
2439 (funcall gnus-article-x-face-command face))
2441 (error "%s is not a function"
2442 gnus-article-x-face-command))))))))))
2444 (defun article-decode-mime-words ()
2445 "Decode all MIME-encoded words in the article."
2447 (gnus-with-article-buffer
2448 (let ((inhibit-point-motion-hooks t)
2449 (mail-parse-charset gnus-newsgroup-charset)
2450 (mail-parse-ignored-charsets
2451 (with-current-buffer gnus-summary-buffer
2452 gnus-newsgroup-ignored-charsets)))
2453 (mail-decode-encoded-word-region (point-min) (point-max)))))
2455 (defun article-decode-charset (&optional prompt)
2456 "Decode charset-encoded text in the article.
2457 If PROMPT (the prefix), prompt for a coding system to use."
2459 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2460 (inhibit-read-only t)
2461 (mail-parse-charset gnus-newsgroup-charset)
2462 (mail-parse-ignored-charsets
2463 (save-excursion (condition-case nil
2464 (set-buffer gnus-summary-buffer)
2466 gnus-newsgroup-ignored-charsets))
2467 ct cte ctl charset format)
2470 (article-narrow-to-head)
2471 (setq ct (message-fetch-field "Content-Type" t)
2472 cte (message-fetch-field "Content-Transfer-Encoding" t)
2473 ctl (and ct (mail-header-parse-content-type ct))
2476 (mm-read-coding-system "Charset to decode: "))
2478 (mail-content-type-get ctl 'charset)))
2479 format (and ctl (mail-content-type-get ctl 'format)))
2481 (setq cte (mail-header-strip cte)))
2482 (if (and ctl (not (string-match "/" (car ctl))))
2484 (goto-char (point-max)))
2487 (narrow-to-region (point) (point-max))
2488 (when (and (eq mail-parse-charset 'gnus-decoded)
2489 (eq (mm-body-7-or-8) '8bit))
2490 ;; The text code could have been decoded.
2491 (setq charset mail-parse-charset))
2492 (when (and (or (not ctl)
2493 (equal (car ctl) "text/plain"))
2494 (not format)) ;; article with format will decode later.
2496 charset (and cte (intern (downcase
2497 (gnus-strip-whitespace cte))))
2500 (defun article-decode-encoded-words ()
2501 "Remove encoded-word encoding from headers."
2502 (let ((inhibit-point-motion-hooks t)
2503 (mail-parse-charset gnus-newsgroup-charset)
2504 (mail-parse-ignored-charsets
2505 (save-excursion (condition-case nil
2506 (set-buffer gnus-summary-buffer)
2508 gnus-newsgroup-ignored-charsets))
2509 (inhibit-read-only t)
2511 (goto-char (point-min))
2512 (when (search-forward "\n\n" nil 'move)
2519 (memq (char-after) '(?\t ? )))))
2520 (setq start (point))
2522 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2523 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2524 (funcall gnus-decode-address-function start end)
2525 (funcall gnus-decode-header-function start end))
2526 (goto-char (setq end start)))))
2528 (defun article-decode-group-name ()
2529 "Decode group names in `Newsgroups:'."
2530 (let ((inhibit-point-motion-hooks t)
2531 (inhibit-read-only t)
2532 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2533 (when (and (or gnus-group-name-charset-method-alist
2534 gnus-group-name-charset-group-alist)
2535 (gnus-buffer-live-p gnus-original-article-buffer))
2537 (article-narrow-to-head)
2538 (with-current-buffer gnus-original-article-buffer
2539 (goto-char (point-min)))
2540 (while (re-search-forward
2541 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2542 (replace-match (save-match-data
2543 (gnus-decode-newsgroups
2544 ;; XXX how to use data in article buffer?
2545 (with-current-buffer gnus-original-article-buffer
2547 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2550 gnus-newsgroup-name method))
2552 (goto-char (point-min))
2553 (with-current-buffer gnus-original-article-buffer
2554 (goto-char (point-min)))
2555 (while (re-search-forward
2556 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2557 (replace-match (save-match-data
2558 (gnus-decode-newsgroups
2559 ;; XXX how to use data in article buffer?
2560 (with-current-buffer gnus-original-article-buffer
2562 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2565 gnus-newsgroup-name method))
2568 (autoload 'idna-to-unicode "idna")
2570 (defun article-decode-idna-rhs ()
2571 "Decode IDNA strings in RHS in various headers in current buffer.
2572 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2573 Mail-Reply-To: and Mail-Followup-To:."
2576 (let ((inhibit-point-motion-hooks t)
2577 (inhibit-read-only t))
2578 (article-narrow-to-head)
2579 (goto-char (point-min))
2580 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2582 (when (save-match-data
2583 (and (setq ace (match-string 1))
2585 (and (re-search-backward "^[^ \t]" nil t)
2586 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2587 (setq unicode (idna-to-unicode ace))))
2588 (unless (string= ace unicode)
2589 (replace-match unicode nil nil nil 1)))))))))
2591 (defun article-de-quoted-unreadable (&optional force read-charset)
2592 "Translate a quoted-printable-encoded article.
2593 If FORCE, decode the article whether it is marked as quoted-printable
2595 If READ-CHARSET, ask for a coding system."
2596 (interactive (list 'force current-prefix-arg))
2598 (let ((inhibit-read-only t) type charset)
2599 (if (gnus-buffer-live-p gnus-original-article-buffer)
2600 (with-current-buffer gnus-original-article-buffer
2602 (gnus-fetch-field "content-transfer-encoding"))
2603 (let* ((ct (gnus-fetch-field "content-type"))
2604 (ctl (and ct (mail-header-parse-content-type ct))))
2605 (setq charset (and ctl
2606 (mail-content-type-get ctl 'charset)))
2607 (if (stringp charset)
2608 (setq charset (intern (downcase charset)))))))
2610 (setq charset (mm-read-coding-system "Charset: " charset)))
2612 (setq charset gnus-newsgroup-charset))
2614 (and type (let ((case-fold-search t))
2615 (string-match "quoted-printable" type))))
2617 (quoted-printable-decode-region
2618 (point) (point-max) (mm-charset-to-coding-system charset))))))
2620 (defun article-de-base64-unreadable (&optional force read-charset)
2621 "Translate a base64 article.
2622 If FORCE, decode the article whether it is marked as base64 not.
2623 If READ-CHARSET, ask for a coding system."
2624 (interactive (list 'force current-prefix-arg))
2626 (let ((inhibit-read-only t) type charset)
2627 (if (gnus-buffer-live-p gnus-original-article-buffer)
2628 (with-current-buffer gnus-original-article-buffer
2630 (gnus-fetch-field "content-transfer-encoding"))
2631 (let* ((ct (gnus-fetch-field "content-type"))
2632 (ctl (and ct (mail-header-parse-content-type ct))))
2633 (setq charset (and ctl
2634 (mail-content-type-get ctl 'charset)))
2635 (if (stringp charset)
2636 (setq charset (intern (downcase charset)))))))
2638 (setq charset (mm-read-coding-system "Charset: " charset)))
2640 (setq charset gnus-newsgroup-charset))
2642 (and type (let ((case-fold-search t))
2643 (string-match "base64" type))))
2646 (narrow-to-region (point) (point-max))
2647 (base64-decode-region (point-min) (point-max))
2648 (mm-decode-coding-region
2649 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2654 (defun article-decode-HZ ()
2655 "Translate a HZ-encoded article."
2659 (let ((inhibit-read-only t))
2660 (rfc1843-decode-region (point-min) (point-max)))))
2662 (defun article-unsplit-urls ()
2663 "Remove the newlines that some other mailers insert into URLs."
2666 (let ((inhibit-read-only t))
2667 (goto-char (point-min))
2668 (while (re-search-forward
2669 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2670 (replace-match "\\1\\3" t)))
2671 (when (interactive-p)
2672 (gnus-treat-article nil))))
2675 (defun article-wash-html (&optional read-charset)
2676 "Format an HTML article.
2677 If READ-CHARSET, ask for a coding system. If it is a number, the
2678 charset defined in `gnus-summary-show-article-charset-alist' is used."
2681 (let ((inhibit-read-only t)
2684 (if (or (and (numberp read-charset)
2688 gnus-summary-show-article-charset-alist))))
2689 (setq charset (mm-read-coding-system "Charset: ")))
2690 (let ((gnus-summary-show-article-charset-alist
2691 (list (cons 1 charset))))
2692 (with-current-buffer gnus-summary-buffer
2693 (gnus-summary-show-article 1)))
2694 (error "No charset is given"))
2695 (when (gnus-buffer-live-p gnus-original-article-buffer)
2696 (with-current-buffer gnus-original-article-buffer
2697 (let* ((ct (gnus-fetch-field "content-type"))
2698 (ctl (and ct (mail-header-parse-content-type ct))))
2699 (setq charset (and ctl
2700 (mail-content-type-get ctl 'charset)))
2701 (when (stringp charset)
2702 (setq charset (intern (downcase charset)))))))
2704 (setq charset gnus-newsgroup-charset)))
2706 (save-window-excursion
2708 (narrow-to-region (point) (point-max))
2709 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2710 (entry (assq func mm-text-html-washer-alist)))
2712 (setq func (cdr entry)))
2717 (apply (car func) (cdr func))))))))))
2719 (defun gnus-article-wash-html-with-w3 ()
2720 "Wash the current buffer with w3."
2722 (let ((w3-strict-width (window-width))
2723 (url-standalone-mode t)
2724 (url-gateway-unplugged t)
2725 (w3-honor-stylesheets nil))
2727 (w3-region (point-min) (point-max))
2730 (defun gnus-article-wash-html-with-w3m ()
2731 "Wash the current buffer with emacs-w3m."
2733 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2734 w3m-force-redisplay)
2735 (w3m-region (point-min) (point-max)))
2736 (when (and mm-inline-text-html-with-w3m-keymap
2737 (boundp 'w3m-minor-mode-map)
2739 (add-text-properties
2740 (point-min) (point-max)
2741 (list 'keymap w3m-minor-mode-map
2742 ;; Put the mark meaning this part was rendered by emacs-w3m.
2743 'mm-inline-text-html-with-w3m t))))
2745 (eval-when-compile (defvar charset)) ;; Bound by `article-wash-html'.
2747 (defun gnus-article-wash-html-with-w3m-standalone ()
2748 "Wash the current buffer with w3m."
2749 (if (mm-w3m-standalone-supports-m17n-p)
2751 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2753 (setq charset 'iso-8859-1))
2754 (let ((coding-system-for-write charset)
2755 (coding-system-for-read charset))
2756 (call-process-region
2757 (point-min) (point-max)
2758 "w3m" t t nil "-dump" "-T" "text/html"
2759 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2760 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2762 (defvar gnus-article-browse-html-temp-list nil
2763 "List of temporary files created by `gnus-article-browse-html-parts'.
2764 Internal variable.")
2766 (defcustom gnus-article-browse-delete-temp 'ask
2767 "What to do with temporary files from `gnus-article-browse-html-parts'.
2768 If nil, don't delete temporary files. If it is t, delete them on
2769 exit from the summary buffer. If it is the symbol `file', query
2770 on each file, if it is `ask' ask once when exiting from the
2772 :group 'gnus-article
2773 :version "23.0" ;; No Gnus
2774 :type '(choice (const :tag "Don't delete" nil)
2775 (const :tag "Don't ask" t)
2776 (const :tag "Ask" ask)
2777 (const :tag "Ask for each file" file)))
2779 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2781 (defun gnus-article-browse-delete-temp-files (&optional how)
2782 "Delete temp-files created by `gnus-article-browse-html-parts'."
2783 (when (and gnus-article-browse-html-temp-list
2785 (setq how gnus-article-browse-delete-temp)))
2786 (when (and (eq how 'ask)
2788 "Delete all %s temporary HTML file(s)? "
2789 (length gnus-article-browse-html-temp-list)))
2791 (dolist (file gnus-article-browse-html-temp-list)
2792 (when (and (file-exists-p file)
2794 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2796 (format "Delete temporary HTML file `%s'? " file))))
2797 (delete-file file)))
2798 ;; Also remove file from the list when not deleted or if file doesn't
2800 (setq gnus-article-browse-html-temp-list nil))
2801 gnus-article-browse-html-temp-list)
2803 (defun gnus-article-browse-html-parts (list)
2804 "View all \"text/html\" parts from LIST.
2805 Recurse into multiparts."
2806 ;; Internal function used by `gnus-article-browse-html-article'.
2808 ;; Find and show the html-parts.
2809 (dolist (handle list)
2810 ;; If HTML, show it:
2811 (when (listp handle)
2812 (cond ((and (bufferp (car handle))
2813 (string-match "text/html" (car (mm-handle-type handle))))
2814 (let ((tmp-file (mm-make-temp-file
2815 ;; Do we need to care for 8.3 filenames?
2816 "mm-" nil ".html")))
2817 (mm-save-part-to-file handle tmp-file)
2818 (add-to-list 'gnus-article-browse-html-temp-list tmp-file)
2819 (add-hook 'gnus-summary-prepare-exit-hook
2820 'gnus-article-browse-delete-temp-files)
2821 (add-hook 'gnus-exit-gnus-hook
2823 (gnus-article-browse-delete-temp-files t)))
2824 ;; FIXME: Warn if there's an <img> tag?
2825 (browse-url-of-file tmp-file)
2827 ;; If multipart, recurse
2828 ((and (stringp (car handle))
2829 (string-match "^multipart/" (car handle))
2832 (gnus-article-browse-html-parts handle))))))))
2835 ;; FIXME: Documentation in texi/gnus.texi missing.
2836 (defun gnus-article-browse-html-article ()
2837 "View \"text/html\" parts of the current article with a WWW browser.
2839 Warning: Spammers use links to images in HTML articles to verify
2840 whether you have read the message. As
2841 `gnus-article-browse-html-article' passes the unmodified HTML
2842 content to the browser without eliminatin these \"web bugs\" you
2843 should only use it for mails from trusted senders."
2844 ;; Cf. `mm-w3m-safe-url-regexp'
2846 (save-window-excursion
2847 ;; Open raw article and select the buffer
2848 (gnus-summary-show-article t)
2849 (gnus-summary-select-article-buffer)
2850 (let ((parts (mm-dissect-buffer t t)))
2851 ;; If singlepart, enforce a list.
2852 (when (and (bufferp (car parts))
2853 (stringp (car (mm-handle-type parts))))
2854 (setq parts (list parts)))
2856 (unless (gnus-article-browse-html-parts parts)
2857 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
2858 (gnus-summary-show-article))))
2860 (defun article-hide-list-identifiers ()
2861 "Remove list identifies from the Subject header.
2862 The `gnus-list-identifiers' variable specifies what to do."
2864 (let ((inhibit-point-motion-hooks t)
2865 (regexp (if (consp gnus-list-identifiers)
2866 (mapconcat 'identity gnus-list-identifiers " *\\|")
2867 gnus-list-identifiers))
2868 (inhibit-read-only t))
2872 (article-narrow-to-head)
2873 (goto-char (point-min))
2874 (while (re-search-forward
2875 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2877 (delete-region (match-beginning 2) (match-end 0))
2878 (beginning-of-line))
2879 (when (re-search-forward
2880 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2881 (delete-region (match-beginning 1) (match-end 1))))))))
2883 (defun article-hide-pem (&optional arg)
2884 "Toggle hiding of any PEM headers and signatures in the current article.
2885 If given a negative prefix, always show; if given a positive prefix,
2887 (interactive (gnus-article-hidden-arg))
2888 (unless (gnus-article-check-hidden-text 'pem arg)
2890 (let ((inhibit-read-only t) end)
2891 (goto-char (point-min))
2892 ;; Hide the horrendously ugly "header".
2893 (when (and (search-forward
2894 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2896 (setq end (1+ (match-beginning 0))))
2897 (gnus-add-wash-type 'pem)
2898 (gnus-article-hide-text-type
2900 (if (search-forward "\n\n" nil t)
2904 ;; Hide the trailer as well
2905 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2907 (gnus-article-hide-text-type
2908 (match-beginning 0) (match-end 0) 'pem)))))))
2910 (defun article-strip-banner ()
2911 "Strip the banners specified by the `banner' group parameter and by
2912 `gnus-article-address-banner-alist'."
2916 (let ((inhibit-point-motion-hooks t))
2917 (when (gnus-parameter-banner gnus-newsgroup-name)
2918 (article-really-strip-banner
2919 (gnus-parameter-banner gnus-newsgroup-name)))
2920 (when gnus-article-address-banner-alist
2921 ;; Note that the From header is decoded here, so it is
2922 ;; required that the *-extract-address-components function
2923 ;; supports non-ASCII text.
2924 (let ((from (save-restriction
2926 (article-narrow-to-head)
2927 (mail-fetch-field "from"))))
2930 (cadr (funcall gnus-extract-address-components
2933 (dolist (pair gnus-article-address-banner-alist)
2934 (when (string-match (car pair) from)
2936 (article-really-strip-banner (cdr pair)))))))))))))
2938 (defun article-really-strip-banner (banner)
2939 "Strip the banner specified by the argument."
2942 (let ((inhibit-point-motion-hooks t)
2943 (gnus-signature-limit nil)
2944 (inhibit-read-only t))
2947 ((eq banner 'signature)
2948 (when (gnus-article-narrow-to-signature)
2951 (delete-region (point) (point-max))))
2953 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2954 (while (re-search-forward banner nil t)
2955 (delete-region (match-beginning 0) (match-end 0)))))
2957 (while (re-search-forward banner nil t)
2958 (delete-region (match-beginning 0) (match-end 0)))))))))
2960 (defun article-babel ()
2961 "Translate article using an online translation service."
2964 (gnus-with-article-buffer
2965 (when (article-goto-body)
2966 (let* ((start (point))
2968 (orig (buffer-substring start end))
2969 (trans (babel-as-string orig)))
2971 (narrow-to-region start end)
2972 (delete-region start end)
2975 (defun article-hide-signature (&optional arg)
2976 "Hide the signature in the current article.
2977 If given a negative prefix, always show; if given a positive prefix,
2979 (interactive (gnus-article-hidden-arg))
2980 (unless (gnus-article-check-hidden-text 'signature arg)
2983 (let ((inhibit-read-only t))
2984 (when (gnus-article-narrow-to-signature)
2985 (gnus-article-hide-text-type
2986 (point-min) (point-max) 'signature))))))
2987 (gnus-set-mode-line 'article))
2989 (defun article-strip-headers-in-body ()
2990 "Strip offensive headers from bodies."
2994 (let ((case-fold-search t))
2995 (when (looking-at "x-no-archive:")
2996 (gnus-delete-line)))))
2998 (defun article-strip-leading-blank-lines ()
2999 "Remove all blank lines from the beginning of the article."
3002 (let ((inhibit-point-motion-hooks t)
3003 (inhibit-read-only t))
3004 (when (article-goto-body)
3005 (while (and (not (eobp))
3006 (looking-at "[ \t]*$"))
3007 (gnus-delete-line))))))
3009 (defun article-narrow-to-head ()
3010 "Narrow the buffer to the head of the message.
3011 Point is left at the beginning of the narrowed-to region."
3013 (goto-char (point-min))
3014 (if (search-forward "\n\n" nil 1)
3017 (goto-char (point-min)))
3019 (defun article-goto-body ()
3020 "Place point at the start of the body."
3021 (goto-char (point-min))
3023 ;; This variable is only bound when dealing with separate
3025 (article-goto-body-goes-to-point-min-p
3027 ((search-forward "\n\n" nil t)
3030 (goto-char (point-max))
3033 (defun article-strip-multiple-blank-lines ()
3034 "Replace consecutive blank lines with one empty line."
3037 (let ((inhibit-point-motion-hooks t)
3038 (inhibit-read-only t))
3039 ;; First make all blank lines empty.
3041 (while (re-search-forward "^[ \t]+$" nil t)
3042 (unless (gnus-annotation-in-region-p
3043 (match-beginning 0) (match-end 0))
3044 (replace-match "" nil t)))
3045 ;; Then replace multiple empty lines with a single empty line.
3047 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3048 (unless (gnus-annotation-in-region-p
3049 (match-beginning 0) (match-end 0))
3050 (delete-region (match-beginning 1) (match-end 1)))))))
3052 (defun article-strip-leading-space ()
3053 "Remove all white space from the beginning of the lines in the article."
3056 (let ((inhibit-point-motion-hooks t)
3057 (inhibit-read-only t))
3059 (while (re-search-forward "^[ \t]+" nil t)
3060 (replace-match "" t t)))))
3062 (defun article-strip-trailing-space ()
3063 "Remove all white space from the end of the lines in the article."
3066 (let ((inhibit-point-motion-hooks t)
3067 (inhibit-read-only t))
3069 (while (re-search-forward "[ \t]+$" nil t)
3070 (replace-match "" t t)))))
3072 (defun article-strip-blank-lines ()
3073 "Strip leading, trailing and multiple blank lines."
3075 (article-strip-leading-blank-lines)
3076 (article-remove-trailing-blank-lines)
3077 (article-strip-multiple-blank-lines))
3079 (defun article-strip-all-blank-lines ()
3080 "Strip all blank lines."
3083 (let ((inhibit-point-motion-hooks t)
3084 (inhibit-read-only t))
3086 (while (re-search-forward "^[ \t]*\n" nil t)
3087 (replace-match "" t t)))))
3089 (defun gnus-article-narrow-to-signature ()
3090 "Narrow to the signature; return t if a signature is found, else nil."
3091 (let ((inhibit-point-motion-hooks t))
3092 (when (gnus-article-search-signature)
3094 ;; Check whether we have some limits to what we consider
3095 ;; to be a signature.
3096 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3097 (list gnus-signature-limit)))
3099 (while (setq limit (pop limits))
3100 (if (or (and (integerp limit)
3101 (< (- (point-max) (point)) limit))
3103 (< (count-lines (point) (point-max)) limit))
3104 (and (functionp limit)
3106 (and (stringp limit)
3107 (not (re-search-forward limit nil t))))
3108 () ; This limit did not succeed.
3112 (narrow-to-region (point) (point-max))
3115 (defun gnus-article-search-signature ()
3116 "Search the current buffer for the signature separator.
3117 Put point at the beginning of the signature separator."
3118 (let ((cur (point)))
3119 (goto-char (point-max))
3120 (if (if (stringp gnus-signature-separator)
3121 (re-search-backward gnus-signature-separator nil t)
3122 (let ((seps gnus-signature-separator))
3124 (not (re-search-backward (car seps) nil t)))
3131 (defun gnus-article-hidden-arg ()
3132 "Return the current prefix arg as a number, or 0 if no prefix."
3133 (list (if current-prefix-arg
3134 (prefix-numeric-value current-prefix-arg)
3137 (defun gnus-article-check-hidden-text (type arg)
3138 "Return nil if hiding is necessary.
3139 Arg can be nil or a number. nil and positive means hide, negative
3140 means show, 0 means toggle."
3143 (let ((hide (gnus-article-hidden-text-p type)))
3149 (gnus-article-show-hidden-text type)
3152 (if (eq hide 'hidden)
3154 (gnus-article-show-hidden-text type)
3158 (defun gnus-article-hidden-text-p (type)
3159 "Say whether the current buffer contains hidden text of type TYPE."
3160 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3162 (not (get-text-property pos 'invisible))
3163 (not (get-text-property pos 'dummy-invisible)))
3165 (text-property-any (1+ pos) (point-max) 'article-type type)))
3170 (defun gnus-article-show-hidden-text (type &optional dummy)
3171 "Show all hidden text of type TYPE.
3172 Originally it is hide instead of DUMMY."
3173 (let ((inhibit-read-only t)
3174 (inhibit-point-motion-hooks t))
3175 (gnus-remove-text-properties-when
3177 (point-min) (point-max)
3178 (cons 'article-type (cons type
3179 gnus-hidden-properties)))
3180 (gnus-delete-wash-type type)))
3182 (defconst article-time-units
3183 `((year . ,(* 365.25 24 60 60))
3184 (week . ,(* 7 24 60 60))
3185 (day . ,(* 24 60 60))
3189 "Mapping from time units to seconds.")
3191 (defun gnus-article-forward-header ()
3192 "Move point to the start of the next header.
3193 If the current header is a continuation header, this can be several
3198 (if (looking-at "[ \t]+[^ \t]")
3202 (defun article-date-ut (&optional type highlight)
3203 "Convert DATE date to universal time in the current article.
3204 If TYPE is `local', convert to local time; if it is `lapsed', output
3205 how much time has lapsed since DATE. For `lapsed', the value of
3206 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3207 should replace the \"Date:\" one, or should be added below it."
3208 (interactive (list 'ut t))
3209 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3210 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3214 (article-lapsed-timer
3218 (case-fold-search t)
3219 (inhibit-read-only t)
3220 (inhibit-point-motion-hooks t)
3221 pos date bface eface)
3225 (goto-char (point-min))
3226 (while (or (setq date (get-text-property (setq pos (point))
3228 (when (setq pos (next-single-property-change
3229 (point) 'original-date))
3230 (setq date (get-text-property pos 'original-date))
3232 (narrow-to-region pos (or (text-property-any pos (point-max)
3235 (goto-char (point-min))
3236 (when (re-search-forward tdate-regexp nil t)
3237 (setq bface (get-text-property (point-at-bol) 'face)
3238 eface (get-text-property (1- (point-at-eol)) 'face)))
3239 (goto-char (point-min))
3241 ;; Delete any old Date headers.
3242 (while (re-search-forward date-regexp nil t)
3244 (delete-region (point-at-bol) (progn
3245 (gnus-article-forward-header)
3247 (delete-region (point-at-bol) (progn
3248 (gnus-article-forward-header)
3251 (setq pos (point))))
3252 (when (and (not pos)
3253 (re-search-forward tdate-regexp nil t))
3255 (gnus-goto-char pos)
3256 (insert (article-make-date-line date (or type 'ut)))
3262 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3263 (put-text-property (match-beginning 1) (1+ (match-end 1))
3265 (put-text-property (match-beginning 2) (match-end 2)
3267 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3268 (goto-char (point-max))
3271 (defun article-make-date-line (date type)
3272 "Return a DATE line of TYPE."
3273 (unless (memq type '(local ut original user iso8601 lapsed english))
3274 (error "Unknown conversion type: %s" type))
3276 (let ((time (date-to-time date)))
3278 ;; Convert to the local timezone.
3280 (concat "Date: " (message-make-date time)))
3281 ;; Convert to Universal Time.
3286 (let* ((e (parse-time-string date))
3287 (tm (apply 'encode-time e))
3289 (ls (- (cadr tm) (car (current-time-zone time)))))
3290 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3291 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3295 ;; Get the original date from the article.
3296 ((eq type 'original)
3297 (concat "Date: " (if (string-match "\n+$" date)
3298 (substring date 0 (match-beginning 0))
3300 ;; Let the user define the format.
3302 (let ((format (or (condition-case nil
3303 (with-current-buffer gnus-summary-buffer
3304 gnus-article-time-format)
3306 gnus-article-time-format)))
3307 (if (functionp format)
3308 (funcall format time)
3309 (concat "Date: " (format-time-string format time)))))
3312 (let ((tz (car (current-time-zone time))))
3315 (format-time-string "%Y%m%dT%H%M%S" time)
3316 (format "%s%02d%02d"
3317 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3318 (/ (% (abs tz) 3600) 60)))))
3319 ;; Do an X-Sent lapsed format.
3321 ;; If the date is seriously mangled, the timezone functions are
3322 ;; liable to bug out, so we ignore all errors.
3323 (let* ((now (current-time))
3324 (real-time (subtract-time now time))
3325 (real-sec (and real-time
3326 (+ (* (float (car real-time)) 65536)
3328 (sec (and real-time (abs real-sec)))
3338 ;; This is a bit convoluted, but basically we go
3339 ;; through the time units for years, weeks, etc,
3340 ;; and divide things to see whether that results
3341 ;; in positive answers.
3344 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3345 ;; The (remaining) seconds are too few to
3346 ;; be divided into this time unit.
3348 ;; It's big enough, so we output it.
3349 (setq sec (- sec (* num (cdr unit))))
3351 (concat (if prev ", " "") (int-to-string
3353 " " (symbol-name (car unit))
3354 (if (> num 1) "s" ""))
3356 article-time-units "")
3357 ;; If dates are odd, then it might appear like the
3358 ;; article was sent in the future.
3361 " in the future"))))))
3362 ;; Display the date in proper English
3364 (let ((dtime (decode-time time)))
3367 (number-to-string (nth 3 dtime))
3368 (let ((digit (% (nth 3 dtime) 10)))
3370 ((memq (nth 3 dtime) '(11 12 13)) "th")
3376 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3378 (number-to-string (nth 5 dtime))
3380 (format "%02d" (nth 2 dtime))
3382 (format "%02d" (nth 1 dtime)))))))
3384 (format "Date: %s (from Gnus)" date))))
3386 (defun article-date-local (&optional highlight)
3387 "Convert the current article date to the local timezone."
3388 (interactive (list t))
3389 (article-date-ut 'local highlight))
3391 (defun article-date-english (&optional highlight)
3392 "Convert the current article date to something that is proper English."
3393 (interactive (list t))
3394 (article-date-ut 'english highlight))
3396 (defun article-date-original (&optional highlight)
3397 "Convert the current article date to what it was originally.
3398 This is only useful if you have used some other date conversion
3399 function and want to see what the date was before converting."
3400 (interactive (list t))
3401 (article-date-ut 'original highlight))
3403 (defun article-date-lapsed (&optional highlight)
3404 "Convert the current article date to time lapsed since it was sent."
3405 (interactive (list t))
3406 (article-date-ut 'lapsed highlight))
3408 (defun article-update-date-lapsed ()
3409 "Function to be run from a timer to update the lapsed time line."
3411 (let (deactivate-mark)
3416 (set-buffer (window-buffer w))
3417 (when (eq major-mode 'gnus-article-mode)
3418 (let ((mark (point-marker)))
3419 (goto-char (point-min))
3420 (when (re-search-forward "^X-Sent:" nil t)
3421 (article-date-lapsed t))
3422 (goto-char (marker-position mark))
3423 (move-marker mark nil))))
3426 (defun gnus-start-date-timer (&optional n)
3427 "Start a timer to update the X-Sent header in the article buffers.
3428 The numerical prefix says how frequently (in seconds) the function
3433 (gnus-stop-date-timer)
3434 (setq article-lapsed-timer
3435 (run-at-time 1 n 'article-update-date-lapsed)))
3437 (defun gnus-stop-date-timer ()
3438 "Stop the X-Sent timer."
3440 (when article-lapsed-timer
3441 (nnheader-cancel-timer article-lapsed-timer)
3442 (setq article-lapsed-timer nil)))
3444 (defun article-date-user (&optional highlight)
3445 "Convert the current article date to the user-defined format.
3446 This format is defined by the `gnus-article-time-format' variable."
3447 (interactive (list t))
3448 (article-date-ut 'user highlight))
3450 (defun article-date-iso8601 (&optional highlight)
3451 "Convert the current article date to ISO8601."
3452 (interactive (list t))
3453 (article-date-ut 'iso8601 highlight))
3455 (defmacro gnus-article-save-original-date (&rest forms)
3456 "Save the original date as a text property and evaluate FORMS."
3457 `(let* ((case-fold-search t)
3459 (goto-char (point-min))
3460 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3463 (date (when (and start
3464 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3466 (buffer-substring-no-properties start
3467 (match-beginning 0)))))
3468 (goto-char (point-max))
3469 (skip-chars-backward "\n")
3470 (put-text-property (point-min) (point) 'original-date date)
3472 (goto-char (point-max))
3473 (skip-chars-backward "\n")
3474 (put-text-property (point-min) (point) 'original-date date)))
3476 ;; (defun article-show-all ()
3477 ;; "Show all hidden text in the article buffer."
3480 ;; (let ((inhibit-read-only t))
3481 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3483 (defun article-remove-leading-whitespace ()
3484 "Remove excessive whitespace from all headers."
3488 (let ((inhibit-read-only t))
3489 (article-narrow-to-head)
3490 (goto-char (point-min))
3491 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3492 (delete-region (match-beginning 1) (match-end 1)))))))
3494 (defun article-emphasize (&optional arg)
3495 "Emphasize text according to `gnus-emphasis-alist'."
3496 (interactive (gnus-article-hidden-arg))
3497 (unless (gnus-article-check-hidden-text 'emphasis arg)
3501 (with-current-buffer gnus-summary-buffer
3502 gnus-article-emphasis-alist)
3504 gnus-emphasis-alist))
3505 (inhibit-read-only t)
3506 (props (append '(article-type emphasis)
3507 gnus-hidden-properties))
3508 regexp elem beg invisible visible face)
3511 (while (setq elem (pop alist))
3513 (setq regexp (car elem)
3514 invisible (nth 1 elem)
3515 visible (nth 2 elem)
3517 (while (re-search-forward regexp nil t)
3518 (when (and (match-beginning visible) (match-beginning invisible))
3519 (gnus-article-hide-text
3520 (match-beginning invisible) (match-end invisible) props)
3521 (gnus-article-unhide-text-type
3522 (match-beginning visible) (match-end visible) 'emphasis)
3523 (gnus-put-overlay-excluding-newlines
3524 (match-beginning visible) (match-end visible) 'face face)
3525 (gnus-add-wash-type 'emphasis)
3526 (goto-char (match-end invisible)))))))))
3528 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3529 "Setup newsgroup emphasis alist."
3530 (unless gnus-article-emphasis-alist
3531 (let ((name (and gnus-newsgroup-name
3532 (gnus-group-real-name gnus-newsgroup-name))))
3533 (make-local-variable 'gnus-article-emphasis-alist)
3534 (setq gnus-article-emphasis-alist
3536 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3537 (while (setq elem (pop alist))
3538 (when (and name (string-match (car elem) name))
3540 highlight (copy-sequence (cdr elem)))))
3542 (copy-sequence highlight-words)
3543 (if gnus-newsgroup-name
3544 (copy-sequence (gnus-group-find-parameter
3545 gnus-newsgroup-name 'highlight-words t)))
3546 gnus-emphasis-alist)))))
3549 (defvar gnus-summary-article-menu)
3550 (defvar gnus-summary-post-menu))
3552 ;;; Saving functions.
3554 (defun gnus-article-save (save-buffer file &optional num)
3555 "Save the currently selected article."
3556 (when (or (get gnus-default-article-saver :headers)
3557 (not gnus-save-all-headers))
3558 ;; Remove headers according to `gnus-saved-headers' or the value
3559 ;; of the `:headers' property that the saver function might have.
3560 (let ((gnus-visible-headers
3561 (or (symbol-value (get gnus-default-article-saver :headers))
3562 gnus-saved-headers gnus-visible-headers))
3563 (gnus-article-buffer save-buffer))
3565 (set-buffer save-buffer)
3566 (article-hide-headers 1 t))))
3567 (save-window-excursion
3568 (if (not gnus-default-article-saver)
3569 (error "No default saver is defined")
3570 ;; !!! Magic! The saving functions all save
3571 ;; `gnus-save-article-buffer' (or so they think), but we
3572 ;; bind that variable to our save-buffer.
3573 (set-buffer gnus-article-buffer)
3574 (let* ((gnus-save-article-buffer save-buffer)
3577 ((not gnus-prompt-before-saving) 'default)
3578 ((eq gnus-prompt-before-saving 'always) nil)
3580 (gnus-number-of-articles-to-be-saved
3581 (when (eq gnus-prompt-before-saving t)
3583 (set-buffer gnus-article-current-summary)
3584 (funcall gnus-default-article-saver filename)))))
3586 (defun gnus-read-save-file-name (prompt &optional filename
3587 function group headers variable
3590 (funcall function group headers (symbol-value variable)))
3595 ((eq filename 'default)
3601 (when (symbol-value dir-var)
3602 (setq default-name (expand-file-name
3603 (file-name-nondirectory default-name)
3604 (symbol-value dir-var))))
3605 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3608 (if (and gnus-number-of-articles-to-be-saved
3609 (> gnus-number-of-articles-to-be-saved 1))
3610 (format "these %d articles"
3611 gnus-number-of-articles-to-be-saved)
3614 ;; Let the split methods have their say.
3616 ;; No split name was found.
3619 (concat prompt " (default "
3620 (file-name-nondirectory default-name) "): ")
3621 (file-name-directory default-name)
3623 ;; A single group name is returned.
3624 ((stringp split-name)
3626 (funcall function split-name headers
3627 (symbol-value variable)))
3629 (concat prompt " (default "
3630 (file-name-nondirectory default-name) "): ")
3631 (file-name-directory default-name)
3633 ;; A single split name was found
3634 ((= 1 (length split-name))
3635 (let* ((name (expand-file-name
3637 gnus-article-save-directory))
3638 (dir (cond ((file-directory-p name)
3639 (file-name-as-directory name))
3640 ((file-exists-p name) name)
3641 (t gnus-article-save-directory))))
3643 (concat prompt " (default " name "): ")
3645 ;; A list of splits was found.
3647 (setq split-name (nreverse split-name))
3649 (let ((file-name-history
3650 (nconc split-name file-name-history)))
3654 (concat prompt " (`M-p' for defaults): ")
3655 gnus-article-save-directory
3657 gnus-article-save-directory)))
3658 (car (push result file-name-history)))))))
3659 ;; Create the directory.
3660 (gnus-make-directory (file-name-directory file))
3661 ;; If we have read a directory, we append the default file name.
3662 (when (file-directory-p file)
3663 (setq file (expand-file-name (file-name-nondirectory
3665 (file-name-as-directory file))))
3666 ;; Possibly translate some characters.
3667 (nnheader-translate-file-chars file))))))
3668 (gnus-make-directory (file-name-directory result))
3670 (set variable result))
3672 (set dir-var (file-name-directory result)))
3675 (defun gnus-article-archive-name (group)
3676 "Return the first instance of an \"Archive-name\" in the current buffer."
3677 (let ((case-fold-search t))
3678 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3679 (nnheader-concat gnus-article-save-directory
3680 (match-string 1)))))
3682 (defun gnus-article-nndoc-name (group)
3683 "If GROUP is an nndoc group, return the name of the parent group."
3684 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3685 (gnus-group-get-parameter group 'save-article-group)))
3687 (defun gnus-summary-save-in-rmail (&optional filename)
3688 "Append this article to Rmail file.
3689 Optional argument FILENAME specifies file name.
3690 Directory to save to is default to `gnus-article-save-directory'."
3691 (setq filename (gnus-read-save-file-name
3692 "Save %s in rmail file" filename
3693 gnus-rmail-save-name gnus-newsgroup-name
3694 gnus-current-headers 'gnus-newsgroup-last-rmail))
3695 (gnus-eval-in-buffer-window gnus-save-article-buffer
3699 (gnus-output-to-rmail filename))))
3702 (defun gnus-summary-save-in-mail (&optional filename)
3703 "Append this article to Unix mail file.
3704 Optional argument FILENAME specifies file name.
3705 Directory to save to is default to `gnus-article-save-directory'."
3706 (setq filename (gnus-read-save-file-name
3707 "Save %s in Unix mail file" filename
3708 gnus-mail-save-name gnus-newsgroup-name
3709 gnus-current-headers 'gnus-newsgroup-last-mail))
3710 (gnus-eval-in-buffer-window gnus-save-article-buffer
3714 (if (and (file-readable-p filename)
3715 (file-regular-p filename)
3716 (mail-file-babyl-p filename))
3717 (rmail-output-to-rmail-file filename t)
3718 (gnus-output-to-mail filename)))))
3721 (put 'gnus-summary-save-in-file :decode t)
3722 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3723 (defun gnus-summary-save-in-file (&optional filename overwrite)
3724 "Append this article to file.
3725 Optional argument FILENAME specifies file name.
3726 Directory to save to is default to `gnus-article-save-directory'."
3727 (setq filename (gnus-read-save-file-name
3728 "Save %s in file" filename
3729 gnus-file-save-name gnus-newsgroup-name
3730 gnus-current-headers 'gnus-newsgroup-last-file))
3731 (gnus-eval-in-buffer-window gnus-save-article-buffer
3735 (when (and overwrite
3736 (file-exists-p filename))
3737 (delete-file filename))
3738 (gnus-output-to-file filename))))
3741 (put 'gnus-summary-write-to-file :decode t)
3742 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3743 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3744 (defun gnus-summary-write-to-file (&optional filename)
3745 "Write this article to a file, overwriting it if the file exists.
3746 Optional argument FILENAME specifies file name.
3747 The directory to save in defaults to `gnus-article-save-directory'."
3748 (setq filename (gnus-read-save-file-name
3749 "Save %s in file" filename
3750 gnus-file-save-name gnus-newsgroup-name
3751 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3752 (gnus-summary-save-in-file filename t))
3754 (put 'gnus-summary-save-body-in-file :decode t)
3755 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3756 "Append this article body to a file.
3757 Optional argument FILENAME specifies file name.
3758 The directory to save in defaults to `gnus-article-save-directory'."
3759 (setq filename (gnus-read-save-file-name
3760 "Save %s body in file" filename
3761 gnus-file-save-name gnus-newsgroup-name
3762 gnus-current-headers 'gnus-newsgroup-last-file))
3763 (gnus-eval-in-buffer-window gnus-save-article-buffer
3767 (when (article-goto-body)
3768 (narrow-to-region (point) (point-max)))
3769 (when (and overwrite
3770 (file-exists-p filename))
3771 (delete-file filename))
3772 (gnus-output-to-file filename))))
3775 (put 'gnus-summary-write-body-to-file :decode t)
3776 (put 'gnus-summary-write-body-to-file
3777 :function 'gnus-summary-save-body-in-file)
3778 (defun gnus-summary-write-body-to-file (&optional filename)
3779 "Write this article body to a file, overwriting it if the file exists.
3780 Optional argument FILENAME specifies file name.
3781 The directory to save in defaults to `gnus-article-save-directory'."
3782 (setq filename (gnus-read-save-file-name
3783 "Save %s body in file" filename
3784 gnus-file-save-name gnus-newsgroup-name
3785 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3786 (gnus-summary-save-body-in-file filename t))
3788 (defun gnus-summary-save-in-pipe (&optional command)
3789 "Pipe this article to subprocess."
3791 (cond ((and (eq command 'default)
3792 gnus-last-shell-command)
3793 gnus-last-shell-command)
3798 "Shell command on %s: "
3799 (if (and gnus-number-of-articles-to-be-saved
3800 (> gnus-number-of-articles-to-be-saved 1))
3801 (format "these %d articles"
3802 gnus-number-of-articles-to-be-saved)
3804 gnus-last-shell-command))))
3805 (when (string-equal command "")
3806 (if gnus-last-shell-command
3807 (setq command gnus-last-shell-command)
3808 (error "A command is required")))
3809 (gnus-eval-in-buffer-window gnus-article-buffer
3812 (shell-command-on-region (point-min) (point-max) command nil)))
3813 (setq gnus-last-shell-command command))
3815 (defun gnus-summary-pipe-to-muttprint (&optional command)
3816 "Pipe this article to muttprint."
3817 (setq command (read-string
3818 "Print using command: " gnus-summary-muttprint-program
3819 nil gnus-summary-muttprint-program))
3820 (gnus-summary-save-in-pipe command))
3822 ;;; Article file names when saving.
3824 (defun gnus-capitalize-newsgroup (newsgroup)
3825 "Capitalize NEWSGROUP name."
3826 (when (not (zerop (length newsgroup)))
3827 (concat (char-to-string (upcase (aref newsgroup 0)))
3828 (substring newsgroup 1))))
3830 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3831 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3832 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3833 Otherwise, it is like ~/News/news/group/num."
3836 (concat (if (gnus-use-long-file-name 'not-save)
3837 (gnus-capitalize-newsgroup newsgroup)
3838 (gnus-newsgroup-directory-form newsgroup))
3839 "/" (int-to-string (mail-header-number headers)))
3840 gnus-article-save-directory)))
3842 (string-equal (file-name-directory default)
3843 (file-name-directory last-file))
3844 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3846 (or last-file default))))
3848 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3849 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3850 If variable `gnus-use-long-file-name' is non-nil, it is
3851 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3854 (concat (if (gnus-use-long-file-name 'not-save)
3856 (gnus-newsgroup-directory-form newsgroup))
3857 "/" (int-to-string (mail-header-number headers)))
3858 gnus-article-save-directory)))
3860 (string-equal (file-name-directory default)
3861 (file-name-directory last-file))
3862 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3864 (or last-file default))))
3866 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3867 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3868 If variable `gnus-use-long-file-name' is non-nil, it is
3869 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3872 (if (gnus-use-long-file-name 'not-save)
3875 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3877 gnus-article-save-directory)))
3879 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3880 "Generate file name from sender."
3881 (let ((from (mail-header-from headers)))
3883 (if (and from (string-match "\\([^ <]+\\)@" from))
3884 (match-string 1 from)
3886 gnus-article-save-directory)))
3888 (defun article-verify-x-pgp-sig ()
3891 (if (gnus-buffer-live-p gnus-original-article-buffer)
3892 (let ((sig (with-current-buffer gnus-original-article-buffer
3893 (gnus-fetch-field "X-PGP-Sig")))
3897 (mml2015-clear-verify-function))
3899 (insert-buffer-substring gnus-original-article-buffer)
3900 (setq items (split-string sig))
3901 (message-narrow-to-head)
3902 (let ((inhibit-point-motion-hooks t)
3903 (case-fold-search t))
3904 ;; Don't verify multiple headers.
3905 (setq headers (mapconcat (lambda (header)
3907 (mail-fetch-field header)
3909 (split-string (nth 1 items) ",") "")))
3910 (delete-region (point-min) (point-max))
3911 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3912 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3917 (if (looking-at "^-")
3920 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3921 (insert "Version: " (car items) "\n\n")
3922 (insert (mapconcat 'identity (cddr items) "\n"))
3923 (insert "\n-----END PGP SIGNATURE-----\n")
3924 (let ((mm-security-handle (list (format "multipart/signed"))))
3925 (mml2015-clean-buffer)
3926 (let ((coding-system-for-write (or gnus-newsgroup-charset
3928 (funcall (mml2015-clear-verify-function)))
3930 (or (mm-handle-multipart-ctl-parameter
3931 mm-security-handle 'gnus-details)
3932 (mm-handle-multipart-ctl-parameter
3933 mm-security-handle 'gnus-info)))))
3935 (let ((inhibit-read-only t) bface eface)
3937 (message-narrow-to-head)
3938 (goto-char (point-max))
3940 (setq bface (get-text-property (point-at-bol) 'face)
3941 eface (get-text-property (1- (point-at-eol)) 'face))
3942 (message-remove-header "X-Gnus-PGP-Verify")
3943 (if (re-search-forward "^X-PGP-Sig:" nil t)
3945 (goto-char (point-max)))
3946 (narrow-to-region (point) (point))
3947 (insert "X-Gnus-PGP-Verify: " info "\n")
3948 (goto-char (point-min))
3951 (if (not (looking-at "^[ \t]"))
3955 (goto-char (point-min))
3956 (when (looking-at "\\([^:]+\\): *")
3957 (put-text-property (match-beginning 1) (1+ (match-end 1))
3959 (put-text-property (match-end 0) (point-max)
3960 'face eface)))))))))
3962 (defun article-verify-cancel-lock ()
3963 "Verify Cancel-Lock header."
3965 (if (gnus-buffer-live-p gnus-original-article-buffer)
3966 (canlock-verify gnus-original-article-buffer)))
3973 (setq afunc (car func)
3976 gfunc (intern (format "gnus-%s" func))))
3978 (when (fboundp afunc)
3979 `(lambda (&optional interactive &rest args)
3980 ,(documentation afunc t)
3981 (interactive (list t))
3983 (set-buffer gnus-article-buffer)
3985 (call-interactively ',afunc)
3986 (apply ',afunc args))))))))
3987 '(article-hide-headers
3988 article-verify-x-pgp-sig
3989 article-verify-cancel-lock
3990 article-hide-boring-headers
3991 article-treat-overstrike
3992 article-treat-ansi-sequences
3993 article-fill-long-lines
3994 article-capitalize-sentences
3996 article-remove-leading-whitespace
3997 article-display-x-face
3998 article-display-face
3999 article-de-quoted-unreadable
4000 article-de-base64-unreadable
4003 article-unsplit-urls
4004 article-hide-list-identifiers
4005 article-strip-banner
4008 article-hide-signature
4009 article-strip-headers-in-body
4010 article-remove-trailing-blank-lines
4011 article-strip-leading-blank-lines
4012 article-strip-multiple-blank-lines
4013 article-strip-leading-space
4014 article-strip-trailing-space
4015 article-strip-blank-lines
4016 article-strip-all-blank-lines
4018 article-date-english
4019 article-date-iso8601
4020 article-date-original
4022 article-decode-mime-words
4023 article-decode-charset
4024 article-decode-encoded-words
4028 article-treat-dumbquotes
4029 article-normalize-headers
4030 ;; (article-show-all . gnus-article-show-all-headers)
4034 ;;; Gnus article mode
4037 (put 'gnus-article-mode 'mode-class 'special)
4039 (set-keymap-parent gnus-article-mode-map widget-keymap)
4041 (gnus-define-keys gnus-article-mode-map
4042 " " gnus-article-goto-next-page
4043 "\177" gnus-article-goto-prev-page
4044 [delete] gnus-article-goto-prev-page
4045 [backspace] gnus-article-goto-prev-page
4046 "\C-c^" gnus-article-refer-article
4047 "h" gnus-article-show-summary
4048 "s" gnus-article-show-summary
4049 "\C-c\C-m" gnus-article-mail
4050 "?" gnus-article-describe-briefly
4051 "e" gnus-summary-edit-article
4052 "<" beginning-of-buffer
4054 "\C-c\C-i" gnus-info-find-node
4056 "R" gnus-article-reply-with-original
4057 "F" gnus-article-followup-with-original
4058 "\C-hk" gnus-article-describe-key
4059 "\C-hc" gnus-article-describe-key-briefly
4061 "\C-d" gnus-article-read-summary-keys
4062 "\M-*" gnus-article-read-summary-keys
4063 "\M-#" gnus-article-read-summary-keys
4064 "\M-^" gnus-article-read-summary-keys
4065 "\M-g" gnus-article-read-summary-keys)
4067 (substitute-key-definition
4068 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4070 (defun gnus-article-make-menu-bar ()
4071 (unless (boundp 'gnus-article-commands-menu)
4072 (gnus-summary-make-menu-bar))
4073 (gnus-turn-off-edit-menu 'article)
4074 (unless (boundp 'gnus-article-article-menu)
4076 gnus-article-article-menu gnus-article-mode-map ""
4078 ["Scroll forwards" gnus-article-goto-next-page t]
4079 ["Scroll backwards" gnus-article-goto-prev-page t]
4080 ["Show summary" gnus-article-show-summary t]
4081 ["Fetch Message-ID at point" gnus-article-refer-article t]
4082 ["Mail to address at point" gnus-article-mail t]
4083 ["Send a bug report" gnus-bug t]))
4086 gnus-article-treatment-menu gnus-article-mode-map ""
4087 ;; Fixme: this should use :active (and maybe :visible).
4089 ["Hide headers" gnus-article-hide-headers t]
4090 ["Hide signature" gnus-article-hide-signature t]
4091 ["Hide citation" gnus-article-hide-citation t]
4092 ["Treat overstrike" gnus-article-treat-overstrike t]
4093 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4094 ["Remove carriage return" gnus-article-remove-cr t]
4095 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4096 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4097 ["Remove base64" gnus-article-de-base64-unreadable t]
4098 ["Treat html" gnus-article-wash-html t]
4099 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4100 ["Decode HZ" gnus-article-decode-HZ t]))
4102 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4104 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4106 (gnus-run-hooks 'gnus-article-menu-hook)))
4108 (defun gnus-article-mode ()
4109 "Major mode for displaying an article.
4111 All normal editing commands are switched off.
4113 The following commands are available in addition to all summary mode
4115 \\<gnus-article-mode-map>
4116 \\[gnus-article-next-page]\t Scroll the article one page forwards
4117 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4118 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4119 \\[gnus-article-show-summary]\t Display the summary buffer
4120 \\[gnus-article-mail]\t Send a reply to the address near point
4121 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4122 \\[gnus-info-find-node]\t Go to the Gnus info node"
4124 (kill-all-local-variables)
4125 (gnus-simplify-mode-line)
4126 (setq mode-name "Article")
4127 (setq major-mode 'gnus-article-mode)
4128 (make-local-variable 'minor-mode-alist)
4129 (use-local-map gnus-article-mode-map)
4130 (when (gnus-visual-p 'article-menu 'menu)
4131 (gnus-article-make-menu-bar)
4132 (when gnus-summary-tool-bar-map
4133 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4134 (gnus-update-format-specifications nil 'article-mode)
4135 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4136 (set (make-local-variable 'gnus-page-broken) nil)
4137 (make-local-variable 'gnus-button-marker-list)
4138 (make-local-variable 'gnus-article-current-summary)
4139 (make-local-variable 'gnus-article-mime-handles)
4140 (make-local-variable 'gnus-article-decoded-p)
4141 (make-local-variable 'gnus-article-mime-handle-alist)
4142 (make-local-variable 'gnus-article-wash-types)
4143 (make-local-variable 'gnus-article-image-alist)
4144 (make-local-variable 'gnus-article-charset)
4145 (make-local-variable 'gnus-article-ignored-charsets)
4146 ;; Prevent recent Emacsen from displaying non-break space as "\ ".
4147 (set (make-local-variable 'nobreak-char-display) nil)
4148 (setq cursor-in-non-selected-windows nil)
4149 (setq truncate-lines gnus-article-truncate-lines)
4150 (gnus-set-default-directory)
4151 (buffer-disable-undo)
4152 (setq buffer-read-only t
4153 show-trailing-whitespace nil)
4154 (set-syntax-table gnus-article-mode-syntax-table)
4155 (mm-enable-multibyte)
4156 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4158 (defvar gnus-button-marker-list nil
4159 "Regexp matching any of the regexps from `gnus-button-alist'.
4160 Internal variable.")
4162 (defun gnus-article-setup-buffer ()
4163 "Initialize the article buffer."
4164 (let* ((name (if gnus-single-article-buffer "*Article*"
4165 (concat "*Article " gnus-newsgroup-name "*")))
4167 (progn (string-match "\\*Article" name)
4168 (concat " *Original Article"
4169 (substring name (match-end 0))))))
4170 (setq gnus-article-buffer name)
4171 (setq gnus-original-article-buffer original)
4172 (setq gnus-article-mime-handle-alist nil)
4173 (with-current-buffer gnus-summary-buffer
4174 ;; This might be a variable local to the summary buffer.
4175 (unless gnus-single-article-buffer
4176 (setq gnus-article-buffer name)
4177 (setq gnus-original-article-buffer original)
4178 (gnus-set-global-variables)))
4179 (gnus-article-setup-highlight-words)
4180 ;; Init original article buffer.
4182 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4183 (mm-enable-multibyte)
4184 (setq major-mode 'gnus-original-article-mode)
4185 (make-local-variable 'gnus-original-article))
4186 (if (and (get-buffer name)
4187 (with-current-buffer name
4188 (if gnus-article-edit-mode
4189 (if (y-or-n-p "Article mode edit in progress; discard? ")
4191 (set-buffer-modified-p nil)
4192 (gnus-kill-buffer name)
4195 (error "Action aborted"))
4199 (set (make-local-variable 'gnus-article-edit-mode) nil)
4200 (when gnus-article-mime-handles
4201 (mm-destroy-parts gnus-article-mime-handles)
4202 (setq gnus-article-mime-handles nil))
4203 ;; Set it to nil in article-buffer!
4204 (setq gnus-article-mime-handle-alist nil)
4205 (buffer-disable-undo)
4206 (setq buffer-read-only t)
4207 ;; This list just keeps growing if we don't reset it.
4208 (setq gnus-button-marker-list nil)
4209 (unless (eq major-mode 'gnus-article-mode)
4210 (gnus-article-mode))
4213 (set-buffer (gnus-get-buffer-create name))
4215 (make-local-variable 'gnus-summary-buffer)
4216 (setq gnus-summary-buffer
4217 (gnus-summary-buffer-name gnus-newsgroup-name))
4218 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4219 (current-buffer)))))
4221 ;; Set article window start at LINE, where LINE is the number of lines
4222 ;; from the head of the article.
4223 (defun gnus-article-set-window-start (&optional line)
4225 (gnus-get-buffer-window gnus-article-buffer t)
4227 (set-buffer gnus-article-buffer)
4228 (goto-char (point-min))
4231 (gnus-message 6 "Moved to bookmark")
4232 (search-forward "\n\n" nil t)
4236 (defun gnus-article-prepare (article &optional all-headers header)
4237 "Prepare ARTICLE in article mode buffer.
4238 ARTICLE should either be an article number or a Message-ID.
4239 If ARTICLE is an id, HEADER should be the article headers.
4240 If ALL-HEADERS is non-nil, no headers are hidden."
4242 ;; Make sure we start in a summary buffer.
4243 (unless (eq major-mode 'gnus-summary-mode)
4244 (set-buffer gnus-summary-buffer))
4245 (setq gnus-summary-buffer (current-buffer))
4246 (let* ((gnus-article (if header (mail-header-number header) article))
4247 (summary-buffer (current-buffer))
4248 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4249 (group gnus-newsgroup-name)
4252 (gnus-article-setup-buffer)
4253 (set-buffer gnus-article-buffer)
4254 ;; Deactivate active regions.
4255 (when (and (boundp 'transient-mark-mode)
4256 transient-mark-mode)
4257 (setq mark-active nil))
4258 (if (not (setq result (let ((inhibit-read-only t))
4259 (gnus-request-article-this-buffer
4261 ;; There is no such article.
4263 (when (and (numberp article)
4264 (not (memq article gnus-newsgroup-sparse)))
4265 (setq gnus-article-current
4266 (cons gnus-newsgroup-name article))
4267 (set-buffer gnus-summary-buffer)
4268 (setq gnus-current-article article)
4269 (if (and (memq article gnus-newsgroup-undownloaded)
4270 (not (gnus-online (gnus-find-method-for-group
4271 gnus-newsgroup-name))))
4273 (gnus-summary-set-agent-mark article)
4274 (message "Message marked for downloading"))
4275 (gnus-summary-mark-article article gnus-canceled-mark)
4276 (unless (memq article gnus-newsgroup-sparse)
4277 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4278 (if (or (eq result 'pseudo)
4279 (eq result 'nneething))
4282 (set-buffer summary-buffer)
4283 (push article gnus-newsgroup-history)
4284 (setq gnus-last-article gnus-current-article
4285 gnus-current-article 0
4286 gnus-current-headers nil
4287 gnus-article-current nil)
4288 (if (eq result 'nneething)
4289 (gnus-configure-windows 'summary)
4290 (gnus-configure-windows 'article))
4291 (gnus-set-global-variables))
4292 (let ((gnus-article-mime-handle-alist-1
4293 gnus-article-mime-handle-alist))
4294 (gnus-set-mode-line 'article)))
4295 ;; The result from the `request' was an actual article -
4296 ;; or at least some text that is now displayed in the
4298 (when (and (numberp article)
4299 (not (eq article gnus-current-article)))
4300 ;; Seems like a new article has been selected.
4301 ;; `gnus-current-article' must be an article number.
4303 (set-buffer summary-buffer)
4304 (push article gnus-newsgroup-history)
4305 (setq gnus-last-article gnus-current-article
4306 gnus-current-article article
4307 gnus-current-headers
4308 (gnus-summary-article-header gnus-current-article)
4309 gnus-article-current
4310 (cons gnus-newsgroup-name gnus-current-article))
4311 (unless (vectorp gnus-current-headers)
4312 (setq gnus-current-headers nil))
4313 (gnus-summary-goto-subject gnus-current-article)
4314 (when (gnus-summary-show-thread)
4315 ;; If the summary buffer really was folded, the
4316 ;; previous goto may not actually have gone to
4317 ;; the right article, but the thread root instead.
4319 (gnus-summary-goto-subject gnus-current-article))
4320 (gnus-run-hooks 'gnus-mark-article-hook)
4321 (gnus-set-mode-line 'summary)
4322 (when (gnus-visual-p 'article-highlight 'highlight)
4323 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4324 ;; Set the global newsgroup variables here.
4325 (gnus-set-global-variables)
4326 (setq gnus-have-all-headers
4327 (or all-headers gnus-show-all-headers))))
4329 (gnus-configure-windows 'article))
4330 (when (or (numberp article)
4332 (gnus-article-prepare-display)
4334 (goto-char (point-min))
4335 (when gnus-break-pages
4336 (gnus-narrow-to-page)))
4337 (let ((gnus-article-mime-handle-alist-1
4338 gnus-article-mime-handle-alist))
4339 (gnus-set-mode-line 'article))
4343 (set-window-point (get-buffer-window (current-buffer)) (point))
4344 (gnus-configure-windows 'article)
4348 (defun gnus-article-prepare-display ()
4349 "Make the current buffer look like a nice article."
4350 ;; Hooks for getting information from the article.
4351 ;; This hook must be called before being narrowed.
4352 (let ((gnus-article-buffer (current-buffer))
4354 (inhibit-read-only t))
4355 (unless (eq major-mode 'gnus-article-mode)
4356 (gnus-article-mode))
4357 (setq buffer-read-only nil
4358 gnus-article-wash-types nil
4359 gnus-article-image-alist nil)
4360 (gnus-run-hooks 'gnus-tmp-internal-hook)
4361 (when gnus-display-mime-function
4362 (funcall gnus-display-mime-function))
4363 (gnus-run-hooks 'gnus-article-prepare-hook)))
4366 ;;; Gnus MIME viewing functions
4369 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4370 "Format of the MIME buttons.
4372 Valid specifiers include:
4374 %T MIME type, along with additional info
4375 %n The `name' parameter
4376 %d The description, if any
4377 %l The length of the encoded part
4378 %p The part identifier number
4379 %e Dots if the part isn't displayed
4381 General format specifiers can also be used. See Info node
4382 `(gnus)Formatting Variables'.")
4384 (defvar gnus-mime-button-line-format-alist
4385 '((?t gnus-tmp-type ?s)
4386 (?T gnus-tmp-type-long ?s)
4387 (?n gnus-tmp-name ?s)
4388 (?d gnus-tmp-description ?s)
4390 (?l gnus-tmp-length ?d)
4391 (?e gnus-tmp-dots ?s)))
4393 (defvar gnus-mime-button-commands
4394 '((gnus-article-press-button "\r" "Toggle Display")
4395 (gnus-mime-view-part "v" "View Interactively...")
4396 (gnus-mime-view-part-as-type "t" "View As Type...")
4397 (gnus-mime-view-part-as-charset "C" "View As charset...")
4398 (gnus-mime-save-part "o" "Save...")
4399 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4400 (gnus-mime-replace-part "r" "Replace part")
4401 (gnus-mime-delete-part "d" "Delete part")
4402 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4403 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4404 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4405 (gnus-mime-view-part-externally "e" "View Externally")
4406 (gnus-mime-print-part "p" "Print")
4407 (gnus-mime-pipe-part "|" "Pipe To Command...")
4408 (gnus-mime-action-on-part "." "Take action on the part...")))
4410 (defun gnus-article-mime-part-status ()
4411 (if gnus-article-mime-handle-alist-1
4412 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4414 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4417 (defvar gnus-mime-button-map
4418 (let ((map (make-sparse-keymap)))
4419 (define-key map gnus-mouse-2 'gnus-article-push-button)
4420 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4421 (dolist (c gnus-mime-button-commands)
4422 (define-key map (cadr c) (car c)))
4426 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4428 ,@(mapcar (lambda (c)
4429 (vector (caddr c) (car c) :active t))
4430 gnus-mime-button-commands)))
4432 (defun gnus-mime-button-menu (event prefix)
4433 "Construct a context-sensitive menu of MIME commands."
4434 (interactive "e\nP")
4435 (save-window-excursion
4436 (let ((pos (event-start event)))
4437 (select-window (posn-window pos))
4438 (goto-char (posn-point pos))
4439 (gnus-article-check-buffer)
4440 (popup-menu gnus-mime-button-menu nil prefix))))
4442 (defun gnus-mime-view-all-parts (&optional handles)
4443 "View all the MIME parts."
4445 (with-current-buffer gnus-article-buffer
4446 (let ((handles (or handles gnus-article-mime-handles))
4447 (mail-parse-charset gnus-newsgroup-charset)
4448 (mail-parse-ignored-charsets
4449 (with-current-buffer gnus-summary-buffer
4450 gnus-newsgroup-ignored-charsets)))
4452 (mm-remove-parts handles)
4453 (goto-char (point-min))
4454 (or (search-forward "\n\n") (goto-char (point-max)))
4455 (let ((inhibit-read-only t))
4456 (delete-region (point) (point-max))
4457 (mm-display-parts handles))))))
4459 (defun gnus-article-jump-to-part (n)
4460 "Jump to MIME part N."
4462 (pop-to-buffer gnus-article-buffer)
4463 ;; FIXME: why is it necessary?
4465 (let ((parts (length gnus-article-mime-handle-alist)))
4468 (read-string ;; Emacs 21 doesn't have `read-number'.
4469 (format "Jump to part (2..%s): " parts)))))
4470 (unless (and (integerp n) (<= n parts) (>= n 1))
4473 (gnus-message 7 "Invalid part `%s', using %s instead."
4476 (gnus-message 9 "Jumping to part %s." n)
4477 (cond ((>= gnus-auto-select-part 1)
4478 (while (and (<= n parts)
4479 (not (gnus-article-goto-part n)))
4481 ((< gnus-auto-select-part 0)
4482 (while (and (>= n 1)
4483 (not (gnus-article-goto-part n)))
4486 (gnus-article-goto-part n)))))
4489 (defsubst gnus-article-edit-part (handles &optional current-id)
4490 "Edit an article in order to delete a mime part.
4491 This function is exclusively used by `gnus-mime-save-part-and-strip'
4492 and `gnus-mime-delete-part', and not provided at run-time normally."
4493 (gnus-article-edit-article
4495 (buffer-disable-undo)
4497 (let ((mail-parse-charset (or gnus-article-charset
4498 ',gnus-newsgroup-charset))
4499 (mail-parse-ignored-charsets
4500 (or gnus-article-ignored-charsets
4501 ',gnus-newsgroup-ignored-charsets))
4502 (mbl mml-buffer-list))
4503 (setq mml-buffer-list nil)
4504 (insert-buffer-substring gnus-original-article-buffer)
4505 (mime-to-mml ',handles)
4506 (setq gnus-article-mime-handles nil)
4507 (let ((mbl1 mml-buffer-list))
4508 (setq mml-buffer-list mbl)
4509 (set (make-local-variable 'mml-buffer-list) mbl1))
4510 (gnus-make-local-hook 'kill-buffer-hook)
4511 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4512 `(lambda (no-highlight)
4513 (let ((mail-parse-charset (or gnus-article-charset
4514 ',gnus-newsgroup-charset))
4515 (message-options message-options)
4516 (message-options-set-recipient)
4517 (mail-parse-ignored-charsets
4518 (or gnus-article-ignored-charsets
4519 ',gnus-newsgroup-ignored-charsets)))
4521 (mml-destroy-buffers)
4522 (remove-hook 'kill-buffer-hook
4523 'mml-destroy-buffers t)
4524 (kill-local-variable 'mml-buffer-list))
4525 (gnus-summary-edit-article-done
4526 ,(or (mail-header-references gnus-current-headers) "")
4527 ,(gnus-group-read-only-p)
4528 ,gnus-summary-buffer no-highlight))
4530 (gnus-article-edit-done)
4531 (gnus-summary-expand-window)
4532 (gnus-summary-show-article)
4533 (when (and current-id (integerp gnus-auto-select-part))
4534 (gnus-article-jump-to-part
4535 (+ current-id gnus-auto-select-part)))))
4537 (defun gnus-mime-replace-part (file)
4538 "Replace MIME part under point with an external body."
4539 ;; Useful if file has already been saved to disk
4543 (read-file-name "Replace MIME part with file: "
4544 (or mm-default-directory default-directory)
4546 (gnus-mime-save-part-and-strip file))
4548 (defun gnus-mime-save-part-and-strip (&optional file)
4549 "Save the MIME part under point then replace it with an external body.
4550 If FILE is given, use it for the external part."
4552 (gnus-article-check-buffer)
4553 (when (gnus-group-read-only-p)
4554 (error "The current group does not support deleting of parts"))
4555 (when (mm-complicated-handles gnus-article-mime-handles)
4557 The current article has a complicated MIME structure, giving up..."))
4558 (let* ((data (get-text-property (point) 'gnus-data))
4559 (id (get-text-property (point) 'gnus-part))
4561 (handles gnus-article-mime-handles))
4564 (and data (mm-save-part data "Delete MIME part and save to: "))))
4566 (with-current-buffer (mm-handle-buffer data)
4568 (insert "Content-Type: " (mm-handle-media-type data))
4569 (mml-insert-parameter-string (cdr (mm-handle-type data))
4571 ;; Add a filename for the sake of saving the part again.
4572 (mml-insert-parameter
4573 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4575 (insert "Content-ID: " (message-make-message-id) "\n")
4576 (insert "Content-Transfer-Encoding: binary\n")
4579 (cdr (mm-make-handle nil
4580 `("message/external-body"
4581 (access-type . "LOCAL-FILE")
4583 ;; (set-buffer gnus-summary-buffer)
4584 (gnus-article-edit-part handles id))))
4586 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4587 ;; parts...>') but with stripping would be nice.
4589 (defun gnus-mime-delete-part ()
4590 "Delete the MIME part under point.
4591 Replace it with some information about the removed part."
4593 (gnus-article-check-buffer)
4594 (when (gnus-group-read-only-p)
4595 (error "The current group does not support deleting of parts"))
4596 (when (mm-complicated-handles gnus-article-mime-handles)
4598 The current article has a complicated MIME structure, giving up..."))
4599 (when (or gnus-expert-user
4600 (gnus-yes-or-no-p "\
4601 Deleting parts may malfunction or destroy the article; continue? "))
4602 (let* ((data (get-text-property (point) 'gnus-data))
4603 (id (get-text-property (point) 'gnus-part))
4604 (handles gnus-article-mime-handles)
4607 (mail-decode-encoded-word-string (or (mm-handle-description data)
4610 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4612 (type (mm-handle-media-type data)))
4614 (error "No MIME part under point"))
4615 (with-current-buffer (mm-handle-buffer data)
4616 (let ((bsize (format "%s" (buffer-size))))
4621 "| The following attachment has been deleted:\n"
4623 "| Type: " type "\n"
4624 "| Filename: " filename "\n"
4625 "| Size (encoded): " bsize " Byte\n"
4626 "| Description: " description "\n"
4629 (cdr (mm-make-handle
4630 nil `("text/plain") nil nil
4632 (format "Deleted attachment (%s bytes)" bsize))))))
4633 ;; (set-buffer gnus-summary-buffer)
4634 (gnus-article-edit-part handles id))))
4636 (defun gnus-mime-save-part ()
4637 "Save the MIME part under point."
4639 (gnus-article-check-buffer)
4640 (let ((data (get-text-property (point) 'gnus-data)))
4642 (mm-save-part data))))
4644 (defun gnus-mime-pipe-part ()
4645 "Pipe the MIME part under point to a process."
4647 (gnus-article-check-buffer)
4648 (let ((data (get-text-property (point) 'gnus-data)))
4650 (mm-pipe-part data))))
4652 (defun gnus-mime-view-part ()
4653 "Interactively choose a viewing method for the MIME part under point."
4655 (gnus-article-check-buffer)
4656 (let ((data (get-text-property (point) 'gnus-data)))
4658 (setq gnus-article-mime-handles
4660 gnus-article-mime-handles (setq data (copy-sequence data))))
4661 (mm-interactively-view-part data))))
4663 (defun gnus-mime-view-part-as-type-internal ()
4664 (gnus-article-check-buffer)
4665 (let* ((handle (get-text-property (point) 'gnus-data))
4667 ;; Content-Type: foo/bar; name=...
4668 (mail-content-type-get (mm-handle-type handle) 'name)
4669 ;; Content-Disposition: attachment; filename=...
4670 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4671 (def-type (and name (mm-default-file-encoding name))))
4672 (and def-type (cons def-type 0))))
4674 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4675 "Choose a MIME media type, and view the part as such.
4676 If non-nil, PRED is a predicate to use during completion to limit the
4677 available media-types."
4681 (let ((default (gnus-mime-view-part-as-type-internal)))
4683 (format "View as MIME type (default %s): "
4685 (mapcar #'list (mailcap-mime-types))
4688 (gnus-article-check-buffer)
4689 (let ((handle (get-text-property (point) 'gnus-data)))
4691 (when (equal (mm-handle-media-type handle) "message/external-body")
4692 (unless (mm-handle-cache handle)
4693 (mm-extern-cache-contents handle))
4694 (setq handle (mm-handle-cache handle)))
4696 (mm-make-handle (mm-handle-buffer handle)
4697 (cons mime-type (cdr (mm-handle-type handle)))
4698 (mm-handle-encoding handle)
4699 (mm-handle-undisplayer handle)
4700 (mm-handle-disposition handle)
4701 (mm-handle-description handle)
4703 (mm-handle-id handle)))
4704 (setq gnus-article-mime-handles
4705 (mm-merge-handles gnus-article-mime-handles handle))
4706 (gnus-mm-display-part handle))))
4708 (defun gnus-mime-copy-part (&optional handle arg)
4709 "Put the MIME part under point into a new buffer.
4710 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4712 (interactive (list nil current-prefix-arg))
4713 (gnus-article-check-buffer)
4715 (setq handle (get-text-property (point) 'gnus-data)))
4717 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4719 (mail-content-type-get (mm-handle-disposition handle)
4721 contents dont-decode charset coding-system)
4722 (mm-with-unibyte-buffer
4723 (mm-insert-part handle)
4724 (setq contents (or (condition-case nil
4725 (mm-decompress-buffer filename nil 'sig)
4727 (setq dont-decode t)
4730 (setq filename (cond (filename (file-name-nondirectory filename))
4731 (dont-decode "*raw data*")
4736 (unless (setq charset (mail-content-type-get
4737 (mm-handle-type handle) 'charset))
4738 (unless (setq coding-system (mm-with-unibyte-buffer
4740 (mm-find-buffer-file-coding-system)))
4741 (setq charset gnus-newsgroup-charset))))
4743 (setq charset (or (cdr (assq arg
4744 gnus-summary-show-article-charset-alist))
4745 (mm-read-coding-system "Charset: ")))))
4746 (switch-to-buffer (generate-new-buffer filename))
4747 (if (or coding-system
4749 (setq coding-system (mm-charset-to-coding-system charset))
4750 (not (eq charset 'ascii))))
4752 (mm-enable-multibyte)
4753 (insert (mm-decode-coding-string contents coding-system))
4754 (setq buffer-file-coding-system
4755 (if (boundp 'last-coding-system-used)
4756 (symbol-value 'last-coding-system-used)
4758 (mm-disable-multibyte)
4760 (setq buffer-file-coding-system mm-binary-coding-system))
4761 ;; We do it this way to make `normal-mode' set the appropriate mode.
4764 (setq buffer-file-name (expand-file-name filename))
4766 (setq buffer-file-name nil))
4767 (goto-char (point-min)))))
4769 (defun gnus-mime-print-part (&optional handle filename)
4770 "Print the MIME part under point."
4771 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4772 (gnus-article-check-buffer)
4773 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4774 (contents (and handle (mm-get-part handle)))
4775 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4776 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4781 (mm-save-part-to-file handle file)
4782 (call-process shell-file-name nil
4783 (generate-new-buffer " *mm*")
4785 shell-command-switch
4787 printer file (mm-handle-type handle))))
4791 (gnus-print-buffer))
4792 (ps-despool filename)))))
4794 (defun gnus-mime-inline-part (&optional handle arg)
4795 "Insert the MIME part under point into the current buffer.
4796 Compressed files like .gz and .bz2 are decompressed."
4797 (interactive (list nil current-prefix-arg))
4798 (gnus-article-check-buffer)
4800 (setq handle (get-text-property (point) 'gnus-data)))
4803 (inhibit-read-only t)
4804 contents charset coding-system)
4805 (if (and (not arg) (mm-handle-undisplayer handle))
4806 (mm-remove-part handle)
4807 (mm-with-unibyte-buffer
4808 (mm-insert-part handle)
4810 (or (mm-decompress-buffer
4811 (or (mail-content-type-get (mm-handle-type handle)
4813 (mail-content-type-get (mm-handle-disposition handle)
4819 (unless (setq charset (mail-content-type-get
4820 (mm-handle-type handle) 'charset))
4821 (unless (setq coding-system
4822 (mm-with-unibyte-buffer
4824 (mm-find-buffer-file-coding-system)))
4825 (setq charset gnus-newsgroup-charset))))
4827 (if (mm-handle-undisplayer handle)
4828 (mm-remove-part handle))
4831 gnus-summary-show-article-charset-alist))
4832 (mm-read-coding-system "Charset: "))))
4834 (if (mm-handle-undisplayer handle)
4835 (mm-remove-part handle))))
4839 (if (or coding-system
4842 (mm-charset-to-coding-system charset))
4843 (not (eq coding-system 'ascii))))
4844 (mm-decode-coding-string contents coding-system)
4845 (mm-string-to-multibyte contents)))
4848 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4849 "Insert the MIME part under point into the current buffer using the
4851 (interactive (list nil current-prefix-arg))
4852 (gnus-article-check-buffer)
4853 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
4854 (fun (get-text-property (point) 'gnus-callback))
4855 (gnus-newsgroup-ignored-charsets 'gnus-all)
4856 gnus-newsgroup-charset type charset)
4858 (if (mm-handle-undisplayer handle)
4859 (mm-remove-part handle))
4861 (setq gnus-newsgroup-charset
4862 (or (cdr (assq arg gnus-summary-show-article-charset-alist))
4863 (mm-read-coding-system "Charset: ")))
4864 ;; Strip the charset parameter from `handle'.
4865 (setq type (mm-handle-type
4866 (if (equal (mm-handle-media-type handle)
4867 "message/external-body")
4869 (unless (mm-handle-cache handle)
4870 (mm-extern-cache-contents handle))
4871 (mm-handle-cache handle))
4873 charset (assq 'charset (cdr type)))
4875 (funcall fun handle)))))
4877 (defun gnus-mime-view-part-externally (&optional handle)
4878 "View the MIME part under point with an external viewer."
4880 (gnus-article-check-buffer)
4881 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4882 (mm-user-display-methods nil)
4883 (mm-inlined-types nil)
4884 (mail-parse-charset gnus-newsgroup-charset)
4885 (mail-parse-ignored-charsets
4886 (with-current-buffer gnus-summary-buffer
4887 gnus-newsgroup-ignored-charsets))
4888 (type (mm-handle-media-type handle))
4889 (method (mailcap-mime-info type))
4890 (mm-enable-external t))
4891 (if (not (stringp method))
4892 (gnus-mime-view-part-as-type
4893 nil (lambda (type) (stringp (mailcap-mime-info type))))
4895 (if (mm-handle-undisplayer handle)
4896 (mm-remove-part handle)
4897 (mm-display-part handle))))))
4899 (defun gnus-mime-view-part-internally (&optional handle)
4900 "View the MIME part under point with an internal viewer.
4901 If no internal viewer is available, use an external viewer."
4903 (gnus-article-check-buffer)
4904 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4905 (mm-inlined-types '(".*"))
4906 (mm-inline-large-images t)
4907 (mail-parse-charset gnus-newsgroup-charset)
4908 (mail-parse-ignored-charsets
4909 (with-current-buffer gnus-summary-buffer
4910 gnus-newsgroup-ignored-charsets))
4911 (inhibit-read-only t))
4912 (if (not (mm-inlinable-p handle))
4913 (gnus-mime-view-part-as-type
4914 nil (lambda (type) (mm-inlinable-p handle type)))
4916 (if (mm-handle-undisplayer handle)
4917 (mm-remove-part handle)
4918 (mm-display-part handle))))))
4920 (defun gnus-mime-action-on-part (&optional action)
4921 "Do something with the MIME attachment at \(point\)."
4923 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4924 (gnus-article-check-buffer)
4925 (let ((action-pair (assoc action gnus-mime-action-alist)))
4927 (funcall (cdr action-pair)))))
4929 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
4930 "Call FUNCTION on MIME part N.
4931 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
4932 If INTERACTIVE, call FUNCTION interactivly."
4934 ;; Check whether the article is displayed.
4935 (unless (and (gnus-buffer-live-p gnus-article-buffer)
4936 (setq window (get-buffer-window gnus-article-buffer t))
4937 (frame-visible-p (setq frame (window-frame window))))
4938 (error "No article is displayed"))
4939 (with-current-buffer gnus-article-buffer
4940 ;; Check whether the article displays the right contents.
4941 (unless (with-current-buffer gnus-summary-buffer
4942 (eq gnus-current-article (gnus-summary-article-number)))
4943 (error "You should select the right article first"))
4944 ;; Check whether the specified part exists.
4945 (when (> n (length gnus-article-mime-handle-alist))
4946 (error "No such part")))
4949 ;; To select the window is needed so that the cursor
4950 ;; might be visible on the MIME button.
4951 (select-window (prog1
4953 (setq window (selected-window))
4954 ;; Article may be displayed in the other frame.
4955 (gnus-select-frame-set-input-focus
4958 (setq frame (selected-frame))))))
4959 (when (gnus-article-goto-part n)
4960 ;; We point the cursor and the arrow at the MIME button
4961 ;; when the `function' prompt the user for something.
4962 (let ((cursor-in-non-selected-windows t)
4963 (overlay-arrow-string "=>")
4964 (overlay-arrow-position (point-marker)))
4967 ((and no-handle interactive)
4968 (call-interactively function))
4974 (cdr (assq n gnus-article-mime-handle-alist))))
4977 (cdr (assq n gnus-article-mime-handle-alist)))))
4978 (set-marker overlay-arrow-position nil)
4979 (unless gnus-auto-select-part
4980 (gnus-select-frame-set-input-focus frame)
4981 (select-window window))))
4983 (if gnus-inhibit-mime-unbuttonizing
4984 ;; This is the default though the program shouldn't reach here.
4985 (error "No such part")
4986 ;; The part which doesn't have the MIME button is selected.
4987 ;; So, we display all the buttons and redo it.
4988 (let ((gnus-inhibit-mime-unbuttonizing t))
4989 (gnus-summary-show-article)
4990 (gnus-article-part-wrapper n function no-handle))))))
4992 (defun gnus-article-pipe-part (n)
4993 "Pipe MIME part N, which is the numerical prefix."
4995 (gnus-article-part-wrapper n 'mm-pipe-part))
4997 (defun gnus-article-save-part (n)
4998 "Save MIME part N, which is the numerical prefix."
5000 (gnus-article-part-wrapper n 'mm-save-part))
5002 (defun gnus-article-interactively-view-part (n)
5003 "View MIME part N interactively, which is the numerical prefix."
5005 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5007 (defun gnus-article-copy-part (n)
5008 "Copy MIME part N, which is the numerical prefix."
5010 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5012 (defun gnus-article-view-part-as-charset (n)
5013 "View MIME part N using a specified charset.
5014 N is the numerical prefix."
5016 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5018 (defun gnus-article-view-part-externally (n)
5019 "View MIME part N externally, which is the numerical prefix."
5021 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5023 (defun gnus-article-inline-part (n)
5024 "Inline MIME part N, which is the numerical prefix."
5026 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5028 (defun gnus-article-save-part-and-strip (n)
5029 "Save MIME part N and replace it with an external body.
5030 N is the numerical prefix."
5032 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5034 (defun gnus-article-replace-part (n)
5035 "Replace MIME part N with an external body.
5036 N is the numerical prefix."
5038 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5040 (defun gnus-article-delete-part (n)
5041 "Delete MIME part N and add some information about the removed part.
5042 N is the numerical prefix."
5044 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5046 (defun gnus-article-view-part-as-type (n)
5047 "Choose a MIME media type, and view part N as such.
5048 N is the numerical prefix."
5050 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5052 (defun gnus-article-mime-match-handle-first (condition)
5055 (dolist (ihandle gnus-article-mime-handle-alist)
5057 ((functionp condition)
5058 (funcall condition (cdr ihandle)))
5059 ((eq condition 'undisplayed)
5060 (not (or (mm-handle-undisplayer (cdr ihandle))
5061 (equal (mm-handle-media-type (cdr ihandle))
5062 "multipart/alternative"))))
5063 ((eq condition 'undisplayed-alternative)
5064 (not (mm-handle-undisplayer (cdr ihandle))))
5066 (gnus-article-goto-part (car ihandle))
5067 (or (not n) (< (car ihandle) n)))
5068 (setq n (car ihandle))))
5072 (defun gnus-article-view-part (&optional n)
5073 "View MIME part N, which is the numerical prefix."
5075 (with-current-buffer gnus-article-buffer
5076 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5077 gnus-article-mime-match-handle-function)))
5078 (when (> n (length gnus-article-mime-handle-alist))
5079 (error "No such part"))
5080 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5081 (when (gnus-article-goto-part n)
5082 (if (equal (car handle) "multipart/alternative")
5083 (gnus-article-press-button)
5084 (when (eq (gnus-mm-display-part handle) 'internal)
5085 (gnus-set-window-start)))))))
5087 (defsubst gnus-article-mime-total-parts ()
5088 (if (bufferp (car gnus-article-mime-handles))
5090 (1- (length gnus-article-mime-handles))))
5092 (defun gnus-mm-display-part (handle)
5093 "Display HANDLE and fix MIME button."
5094 (let ((id (get-text-property (point) 'gnus-part))
5096 (inhibit-read-only t))
5099 (let ((window (selected-window))
5100 (mail-parse-charset gnus-newsgroup-charset)
5101 (mail-parse-ignored-charsets
5102 (if (gnus-buffer-live-p gnus-summary-buffer)
5103 (with-current-buffer gnus-summary-buffer
5104 gnus-newsgroup-ignored-charsets)
5108 (let ((win (gnus-get-buffer-window (current-buffer) t))
5111 (select-window win))
5114 (if (mm-handle-displayed-p handle)
5115 ;; This will remove the part.
5116 (mm-display-part handle)
5118 (narrow-to-region (point)
5119 (if (eobp) (point) (1+ (point))))
5120 (mm-display-part handle)
5121 ;; We narrow to the part itself and
5122 ;; then call the treatment functions.
5123 (goto-char (point-min))
5125 (narrow-to-region (point) (point-max))
5128 (gnus-article-mime-total-parts)
5129 (mm-handle-media-type handle)))))
5130 (if (window-live-p window)
5131 (select-window window)))))
5134 (gnus-insert-mime-button
5135 handle id (list (mm-handle-displayed-p handle)))
5136 (goto-char point))))
5138 (defun gnus-article-goto-part (n)
5139 "Go to MIME part N."
5140 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5142 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5143 (let ((gnus-tmp-name
5144 (or (mail-content-type-get (mm-handle-type handle) 'name)
5145 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5146 (mail-content-type-get (mm-handle-type handle) 'url)
5148 (gnus-tmp-type (mm-handle-media-type handle))
5149 (gnus-tmp-description
5150 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5153 (if (if displayed (car displayed)
5154 (mm-handle-displayed-p handle))
5156 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5158 gnus-tmp-type-long b e)
5159 (when (string-match ".*/" gnus-tmp-name)
5160 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5161 (setq gnus-tmp-type-long (concat gnus-tmp-type
5162 (and (not (equal gnus-tmp-name ""))
5163 (concat "; " gnus-tmp-name))))
5164 (unless (equal gnus-tmp-description "")
5165 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5170 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5171 `(keymap ,gnus-mime-button-map
5172 gnus-callback gnus-mm-display-part
5173 gnus-part ,gnus-tmp-id
5174 article-type annotation
5177 ;; Exclude a newline.
5180 (when gnus-article-button-face
5181 (gnus-overlay-put (gnus-make-overlay b e)
5182 'face gnus-article-button-face))
5183 (widget-convert-button
5186 :action 'gnus-widget-press-button
5187 :button-keymap gnus-mime-button-map
5189 (lambda (widget/window &optional overlay pos)
5190 ;; Needed to properly clear the message due to a bug in
5191 ;; wid-edit (XEmacs only).
5192 (if (boundp 'help-echo-owns-message)
5193 (setq help-echo-owns-message t))
5195 "%S: %s the MIME part; %S: more options"
5196 (aref gnus-mouse-2 0)
5197 ;; XEmacs will get a single widget arg; Emacs 21 will get
5198 ;; window, overlay, position.
5199 (if (mm-handle-displayed-p
5201 (with-current-buffer (gnus-overlay-buffer overlay)
5202 (widget-get (widget-at (gnus-overlay-start overlay))
5204 (widget-get widget/window :mime-handle)))
5206 (aref gnus-down-mouse-3 0))))))
5208 (defun gnus-widget-press-button (elems el)
5209 (goto-char (widget-get elems :from))
5210 (gnus-article-press-button))
5212 (defvar gnus-displaying-mime nil)
5214 (defun gnus-display-mime (&optional ihandles)
5215 "Display the MIME parts."
5217 (save-selected-window
5218 (let ((window (get-buffer-window gnus-article-buffer))
5221 (select-window window)
5222 ;; We have to do this since selecting the window
5223 ;; may change the point. So we set the window point.
5224 (set-window-point window point)))
5225 (let ((handles ihandles)
5226 (inhibit-read-only t)
5229 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5230 (when gnus-article-emulate-mime
5231 (mm-uu-dissect-text-parts handles)))
5232 (gnus-article-emulate-mime
5233 (setq handles (mm-uu-dissect))))
5234 (when (and (not ihandles)
5235 (not gnus-displaying-mime))
5236 ;; Top-level call; we clean up.
5237 (when gnus-article-mime-handles
5238 (mm-destroy-parts gnus-article-mime-handles)
5239 (setq gnus-article-mime-handle-alist nil));; A trick.
5240 (setq gnus-article-mime-handles handles)
5241 ;; We allow users to glean info from the handles.
5242 (when gnus-article-mime-part-function
5243 (gnus-mime-part-function handles)))
5245 (or (not (stringp (car handles)))
5248 (when (and (not ihandles)
5249 (not gnus-displaying-mime))
5250 ;; Clean up for mime parts.
5252 (delete-region (point) (point-max)))
5253 (let ((gnus-displaying-mime t))
5254 (gnus-mime-display-part handles)))
5257 (narrow-to-region (point) (point-max))
5258 (gnus-treat-article nil 1 1)
5261 ;; Highlight the headers.
5265 (narrow-to-region (point-min) (point))
5266 (gnus-article-save-original-date
5267 (gnus-treat-article 'head)))))))
5268 ;; Cope with broken MIME messages.
5269 (goto-char (point-max))
5273 (defcustom gnus-mime-display-multipart-as-mixed nil
5274 "Display \"multipart\" parts as \"multipart/mixed\".
5276 If t, it overrides nil values of
5277 `gnus-mime-display-multipart-alternative-as-mixed' and
5278 `gnus-mime-display-multipart-related-as-mixed'."
5279 :group 'gnus-article-mime
5282 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5283 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5285 :group 'gnus-article-mime
5288 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5289 "Display \"multipart/related\" parts as \"multipart/mixed\".
5291 If displaying \"text/html\" is discouraged \(see
5292 `mm-discouraged-alternatives'\) images or other material inside a
5293 \"multipart/related\" part might be overlooked when this variable is nil."
5295 :group 'gnus-article-mime
5298 (defun gnus-mime-display-part (handle)
5300 ;; Maybe a broken MIME message.
5303 ((not (stringp (car handle)))
5304 (gnus-mime-display-single handle))
5305 ;; User-defined multipart
5306 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5307 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5309 ;; multipart/alternative
5310 ((and (equal (car handle) "multipart/alternative")
5311 (not (or gnus-mime-display-multipart-as-mixed
5312 gnus-mime-display-multipart-alternative-as-mixed)))
5313 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5314 (push (cons id handle) gnus-article-mime-handle-alist)
5315 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5316 ;; multipart/related
5317 ((and (equal (car handle) "multipart/related")
5318 (not (or gnus-mime-display-multipart-as-mixed
5319 gnus-mime-display-multipart-related-as-mixed)))
5320 ;;;!!!We should find the start part, but we just default
5321 ;;;!!!to the first part.
5322 ;;(gnus-mime-display-part (cadr handle))
5323 ;;;!!! Most multipart/related is an HTML message plus images.
5324 ;;;!!! Unfortunately we are unable to let W3 display those
5325 ;;;!!! included images, so we just display it as a mixed multipart.
5326 ;;(gnus-mime-display-mixed (cdr handle))
5327 ;;;!!! No, w3 can display everything just fine.
5328 (gnus-mime-display-part (cadr handle)))
5329 ((equal (car handle) "multipart/signed")
5330 (gnus-add-wash-type 'signed)
5331 (gnus-mime-display-security handle))
5332 ((equal (car handle) "multipart/encrypted")
5333 (gnus-add-wash-type 'encrypted)
5334 (gnus-mime-display-security handle))
5335 ;; Other multiparts are handled like multipart/mixed.
5337 (gnus-mime-display-mixed (cdr handle)))))
5339 (defun gnus-mime-part-function (handles)
5340 (if (stringp (car handles))
5341 (mapcar 'gnus-mime-part-function (cdr handles))
5342 (funcall gnus-article-mime-part-function handles)))
5344 (defun gnus-mime-display-mixed (handles)
5345 (mapcar 'gnus-mime-display-part handles))
5347 (defun gnus-mime-display-single (handle)
5348 (let ((type (mm-handle-media-type handle))
5349 (ignored gnus-ignored-mime-types)
5356 (when (string-match (pop ignored) type)
5357 (throw 'ignored nil)))
5358 (if (and (setq not-attachment
5359 (and (not (mm-inline-override-p handle))
5360 (or (not (mm-handle-disposition handle))
5361 (equal (car (mm-handle-disposition handle))
5363 (mm-attachment-override-p handle))))
5364 (mm-automatic-display-p handle)
5366 (mm-inlinable-p handle)
5367 (mm-inlined-p handle))
5368 (mm-automatic-external-display-p type)))
5370 (when (equal (mm-handle-media-supertype handle) "text")
5372 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5374 (push (cons id handle) gnus-article-mime-handle-alist)
5376 (equal (mm-handle-media-supertype handle) "message"))
5379 (cond ((not (bolp)) 2)
5380 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5382 (when (or (not display)
5383 (not (gnus-unbuttonized-mime-type-p type)))
5384 (gnus-insert-mime-button
5385 handle id (list (or display (and not-attachment text))))
5386 (gnus-article-insert-newline)
5387 ;; Remember modify the number of forward lines.
5395 (let ((mail-parse-charset gnus-newsgroup-charset)
5396 (mail-parse-ignored-charsets
5397 (save-excursion (condition-case ()
5398 (set-buffer gnus-summary-buffer)
5400 gnus-newsgroup-ignored-charsets)))
5401 (mm-display-part handle t))
5402 (goto-char (point-max)))
5403 ((and text not-attachment)
5407 (gnus-article-insert-newline)
5410 (let ((charset (mail-content-type-get (mm-handle-type handle)
5412 (cond ((not charset)
5413 (mm-string-as-multibyte (mm-get-part handle)))
5414 ((eq charset 'gnus-decoded)
5415 (with-current-buffer (mm-handle-buffer handle)
5418 (mm-decode-string (mm-get-part handle) charset)))))
5419 (goto-char (point-max))))
5423 (narrow-to-region beg (point))
5426 (gnus-article-mime-total-parts)
5427 (mm-handle-media-type handle)))))))))
5429 (defun gnus-unbuttonized-mime-type-p (type)
5430 "Say whether TYPE is to be unbuttonized."
5431 (unless gnus-inhibit-mime-unbuttonizing
5433 (let ((types gnus-unbuttonized-mime-types))
5435 (when (string-match (pop types) type)
5436 (throw 'found t)))))
5438 (let ((types gnus-buttonized-mime-types))
5440 (when (string-match (pop types) type)
5441 (throw 'found t)))))))))
5443 (defun gnus-article-insert-newline ()
5444 "Insert a newline, but mark it as undeletable."
5445 (gnus-put-text-property
5446 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5448 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5449 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5452 handle (inhibit-read-only t) from props begend not-pref)
5453 (save-window-excursion
5456 (narrow-to-region (car ibegend)
5459 (goto-char (car ibegend))
5462 (delete-region (point-min) (point-max))
5463 (mm-remove-parts handles))
5464 (setq begend (list (point-marker)))
5466 (unless (setq not-pref (cadr (member preferred ihandles)))
5467 (setq not-pref (car ihandles)))
5470 (not (gnus-unbuttonized-mime-type-p
5471 "multipart/alternative")))
5472 (gnus-add-text-properties
5475 (insert (format "%d. " id))
5479 (unless ,(not ibegend)
5480 (setq gnus-article-mime-handle-alist
5481 ',gnus-article-mime-handle-alist))
5482 (gnus-mime-display-alternative
5483 ',ihandles ',not-pref ',begend ,id))
5484 keymap ,gnus-mime-button-map
5485 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5486 face ,gnus-article-button-face
5488 article-type multipart))
5489 (widget-convert-button 'link from (point)
5490 :action 'gnus-widget-press-button
5491 :button-keymap gnus-widget-button-keymap)
5493 (while (setq handle (pop handles))
5494 (gnus-add-text-properties
5497 (insert (format "(%c) %-18s"
5498 (if (equal handle preferred) ?* ? )
5499 (mm-handle-media-type handle)))
5503 (unless ,(not ibegend)
5504 (setq gnus-article-mime-handle-alist
5505 ',gnus-article-mime-handle-alist))
5506 (gnus-mime-display-alternative
5507 ',ihandles ',handle ',begend ,id))
5508 keymap ,gnus-mime-button-map
5509 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5510 face ,gnus-article-button-face
5513 (widget-convert-button 'link from (point)
5514 :action 'gnus-widget-press-button
5515 :button-keymap gnus-widget-button-keymap)
5519 (if (stringp (car preferred))
5520 (gnus-display-mime preferred)
5521 (let ((mail-parse-charset gnus-newsgroup-charset)
5522 (mail-parse-ignored-charsets
5523 (with-current-buffer gnus-summary-buffer
5524 gnus-newsgroup-ignored-charsets)))
5525 (mm-display-part preferred)
5529 (narrow-to-region (car begend) (point-max))
5531 nil (length gnus-article-mime-handle-alist)
5532 (gnus-article-mime-total-parts)
5533 (mm-handle-media-type handle))))))
5534 (goto-char (point-max))
5535 (setcdr begend (point-marker)))))
5537 (goto-char point))))
5539 (defconst gnus-article-wash-status-strings
5540 (let ((alist '((cite "c" "Possible hidden citation text"
5541 " " "All citation text visible")
5542 (headers "h" "Hidden headers"
5543 " " "All headers visible.")
5544 (pgp "p" "Encrypted or signed message status hidden"
5545 " " "No hidden encryption nor digital signature status")
5546 (signature "s" "Signature has been hidden"
5547 " " "Signature is visible")
5548 (overstrike "o" "Overstrike (^H) characters applied"
5549 " " "No overstrike characters applied")
5550 (emphasis "e" "/*_Emphasis_*/ characters applied"
5551 " " "No /*_emphasis_*/ characters applied")))
5553 (dolist (entry alist result)
5554 (let ((key (nth 0 entry))
5555 (on (copy-sequence (nth 1 entry)))
5556 (on-help (nth 2 entry))
5557 (off (copy-sequence (nth 3 entry)))
5558 (off-help (nth 4 entry)))
5559 (put-text-property 0 1 'help-echo on-help on)
5560 (put-text-property 0 1 'help-echo off-help off)
5561 (push (list key on off) result))))
5562 "Alist of strings describing wash status in the mode line.
5563 Each entry has the form (KEY ON OF), where the KEY is a symbol
5564 representing the particular washing function, ON is the string to use
5565 in the article mode line when the washing function is active, and OFF
5566 is the string to use when it is inactive.")
5568 (defun gnus-article-wash-status-entry (key value)
5569 (let ((entry (assoc key gnus-article-wash-status-strings)))
5570 (if value (nth 1 entry) (nth 2 entry))))
5572 (defun gnus-article-wash-status ()
5573 "Return a string which display status of article washing."
5574 (with-current-buffer gnus-article-buffer
5575 (let ((cite (memq 'cite gnus-article-wash-types))
5576 (headers (memq 'headers gnus-article-wash-types))
5577 (boring (memq 'boring-headers gnus-article-wash-types))
5578 (pgp (memq 'pgp gnus-article-wash-types))
5579 (pem (memq 'pem gnus-article-wash-types))
5580 (signed (memq 'signed gnus-article-wash-types))
5581 (encrypted (memq 'encrypted gnus-article-wash-types))
5582 (signature (memq 'signature gnus-article-wash-types))
5583 (overstrike (memq 'overstrike gnus-article-wash-types))
5584 (emphasis (memq 'emphasis gnus-article-wash-types)))
5586 (gnus-article-wash-status-entry 'cite cite)
5587 (gnus-article-wash-status-entry 'headers (or headers boring))
5588 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5589 (gnus-article-wash-status-entry 'signature signature)
5590 (gnus-article-wash-status-entry 'overstrike overstrike)
5591 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5593 (defun gnus-add-wash-type (type)
5594 "Add a washing of TYPE to the current status."
5595 (add-to-list 'gnus-article-wash-types type))
5597 (defun gnus-delete-wash-type (type)
5598 "Add a washing of TYPE to the current status."
5599 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5601 (defun gnus-add-image (category image)
5602 "Add IMAGE of CATEGORY to the list of displayed images."
5603 (let ((entry (assq category gnus-article-image-alist)))
5605 (setq entry (list category))
5606 (push entry gnus-article-image-alist))
5607 (nconc entry (list image))))
5609 (defun gnus-delete-images (category)
5610 "Delete all images in CATEGORY."
5611 (let ((entry (assq category gnus-article-image-alist)))
5612 (dolist (image (cdr entry))
5613 (gnus-remove-image image category))
5614 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5615 (gnus-delete-wash-type category)))
5617 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5619 (defun gnus-article-maybe-hide-headers ()
5620 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5621 Provided for backwards compatibility."
5622 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5623 (not (with-current-buffer gnus-summary-buffer
5624 gnus-have-all-headers)))
5625 (not gnus-inhibit-hiding))
5626 (gnus-article-hide-headers)))
5630 (defun gnus-output-to-file (file-name)
5631 "Append the current article to a file named FILE-NAME.
5632 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5633 text and used as the value of the coding cookie which is added to the
5634 top of a file. Otherwise, this function saves a raw article without
5636 (let* ((artbuf (current-buffer))
5637 (file-name-coding-system nnmail-pathname-coding-system)
5638 (coding gnus-article-save-coding-system)
5639 (coding-system-for-read (if coding
5640 nil ;; Rely on the coding cookie.
5641 mm-text-coding-system))
5642 (coding-system-for-write (or coding
5643 mm-text-coding-system-for-write
5644 mm-text-coding-system))
5645 (exists (file-exists-p file-name)))
5648 (insert-file-contents file-name)
5649 (goto-char (point-min))
5650 ;; Remove the existing coding cookie.
5651 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5652 (delete-region (match-beginning 0) (match-end 0))))
5653 (goto-char (point-max))
5654 (insert-buffer-substring artbuf)
5655 ;; Append newline at end of the buffer as separator, and then
5657 (goto-char (point-max))
5660 ;; If the coding system is not suitable to encode the text,
5661 ;; ask a user for a proper one.
5662 (when (fboundp 'select-safe-coding-system)
5663 (setq coding (coding-system-base
5664 (save-window-excursion
5665 (select-safe-coding-system (point-min) (point-max)
5667 (setq coding-system-for-write
5668 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5670 (goto-char (point-min))
5671 ;; Add the coding cookie.
5672 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5673 coding-system-for-write)))
5676 (write-region (point-min) (point-max) file-name nil 'no-message)
5677 (message "Appended to %s" file-name))
5678 (write-region (point-min) (point-max) file-name))))
5681 (defun gnus-narrow-to-page (&optional arg)
5682 "Narrow the article buffer to a page.
5683 If given a numerical ARG, move forward ARG pages."
5685 (setq arg (if arg (prefix-numeric-value arg) 0))
5687 (set-buffer gnus-article-buffer)
5688 (goto-char (point-min))
5690 ;; Remove any old next/prev buttons.
5691 (when (gnus-visual-p 'page-marker)
5692 (let ((inhibit-read-only t))
5693 (gnus-remove-text-with-property 'gnus-prev)
5694 (gnus-remove-text-with-property 'gnus-next)))
5697 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5699 (re-search-forward page-delimiter nil 'move arg)))
5700 (goto-char (match-end 0))
5702 (goto-char (point-min))
5703 (setq gnus-page-broken
5704 (and (re-search-forward page-delimiter nil t) t))))
5705 (when gnus-page-broken
5708 (if (re-search-forward page-delimiter nil 'move)
5711 (when (and (gnus-visual-p 'page-marker)
5712 (> (point-min) (save-restriction (widen) (point-min))))
5714 (goto-char (point-min))
5715 (gnus-insert-prev-page-button)))
5716 (when (and (gnus-visual-p 'page-marker)
5717 (< (point-max) (save-restriction (widen) (point-max))))
5719 (goto-char (point-max))
5720 (gnus-insert-next-page-button))))))
5722 ;; Article mode commands
5724 (defun gnus-article-goto-next-page ()
5725 "Show the next page of the article."
5727 (when (gnus-article-next-page)
5728 (goto-char (point-min))
5729 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5732 (defun gnus-article-goto-prev-page ()
5733 "Show the previous page of the article."
5736 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5737 (gnus-article-prev-page nil)))
5739 ;; This is cleaner but currently breaks `gnus-pick-mode':
5741 ;; (defun gnus-article-goto-next-page ()
5742 ;; "Show the next page of the article."
5744 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5745 ;; (gnus-summary-next-page)))
5747 ;; (defun gnus-article-goto-prev-page ()
5748 ;; "Show the next page of the article."
5750 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5751 ;; (gnus-summary-prev-page)))
5753 (defun gnus-article-next-page (&optional lines)
5754 "Show the next page of the current article.
5755 If end of article, return non-nil. Otherwise return nil.
5756 Argument LINES specifies lines to be scrolled up."
5758 (move-to-window-line -1)
5761 (and (pos-visible-in-window-p) ;Not continuation line.
5762 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5763 ;; Nothing in this page.
5764 (if (or (not gnus-page-broken)
5769 (eobp)))) ;Real end-of-buffer?
5771 (when gnus-article-over-scroll
5772 (gnus-article-next-page-1 lines))
5774 (gnus-narrow-to-page 1) ;Go to next page.
5776 ;; More in this page.
5777 (gnus-article-next-page-1 lines)
5780 (defmacro gnus-article-beginning-of-window ()
5781 "Move point to the beginning of the window.
5782 In Emacs, the point is placed at the line number which `scroll-margin'
5784 (if (featurep 'xemacs)
5785 '(move-to-window-line 0)
5786 '(move-to-window-line
5787 (min (max 0 scroll-margin)
5788 (max 1 (- (window-height)
5789 (if mode-line-format 1 0)
5790 (if header-line-format 1 0)))))))
5792 (defun gnus-article-next-page-1 (lines)
5793 (when (and (not (featurep 'xemacs))
5796 (numberp (symbol-value 'scroll-margin))
5797 (> (symbol-value 'scroll-margin) 0))
5798 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
5799 ;; too many number of lines if `scroll-margin' is set as two or greater.
5800 (setq lines (min lines
5801 (max 0 (- (count-lines (window-start) (point-max))
5802 (symbol-value 'scroll-margin))))))
5804 (let ((scroll-in-place nil))
5807 ;; Long lines may cause an end-of-buffer error.
5808 (goto-char (point-max))))
5809 (gnus-article-beginning-of-window))
5811 (defun gnus-article-prev-page (&optional lines)
5812 "Show previous page of current article.
5813 Argument LINES specifies lines to be scrolled down."
5815 (move-to-window-line 0)
5816 (if (and gnus-page-broken
5818 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5820 (gnus-narrow-to-page -1) ;Go to previous page.
5821 (goto-char (point-max))
5825 (let ((scroll-in-place nil))
5826 (scroll-down lines))
5827 (beginning-of-buffer
5828 (goto-char (point-min))))
5829 (gnus-article-beginning-of-window))))
5831 (defun gnus-article-only-boring-p ()
5832 "Decide whether there is only boring text remaining in the article.
5833 Something \"interesting\" is a word of at least two letters that does
5834 not have a face in `gnus-article-boring-faces'."
5835 (when (and gnus-article-skip-boring
5836 (boundp 'gnus-article-boring-faces)
5837 (symbol-value 'gnus-article-boring-faces))
5839 (let ((inhibit-point-motion-hooks t))
5841 (while (re-search-forward "\\b\\w\\w" nil t)
5843 (when (not (gnus-intersection
5844 (gnus-faces-at (point))
5845 (symbol-value 'gnus-article-boring-faces)))
5846 (throw 'only-boring nil)))
5847 (throw 'only-boring t))))))
5849 (defun gnus-article-refer-article ()
5850 "Read article specified by message-id around point."
5853 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5854 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5855 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5856 (let ((msg-id (concat "<" (match-string 0) ">")))
5857 (set-buffer gnus-summary-buffer)
5858 (gnus-summary-refer-article msg-id))
5859 (error "No references around point"))))
5861 (defun gnus-article-show-summary ()
5862 "Reconfigure windows to show summary buffer."
5864 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5865 (error "There is no summary buffer for this article buffer")
5866 (gnus-article-set-globals)
5867 (gnus-configure-windows 'article)
5868 (gnus-summary-goto-subject gnus-current-article)
5869 (gnus-summary-position-point)))
5871 (defun gnus-article-describe-briefly ()
5872 "Describe article mode commands briefly."
5874 (gnus-message 6 (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")))
5876 (defun gnus-article-summary-command ()
5877 "Execute the last keystroke in the summary buffer."
5879 (let ((obuf (current-buffer))
5880 (owin (current-window-configuration))
5882 (switch-to-buffer gnus-article-current-summary 'norecord)
5883 (setq func (lookup-key (current-local-map) (this-command-keys)))
5884 (call-interactively func)
5886 (set-window-configuration owin)
5887 (set-window-point (get-buffer-window (current-buffer)) (point))))
5889 (defun gnus-article-summary-command-nosave ()
5890 "Execute the last keystroke in the summary buffer."
5893 (pop-to-buffer gnus-article-current-summary 'norecord)
5894 (setq func (lookup-key (current-local-map) (this-command-keys)))
5895 (call-interactively func)))
5897 (defun gnus-article-check-buffer ()
5898 "Beep if not in an article buffer."
5899 (unless (equal major-mode 'gnus-article-mode)
5900 (error "Command invoked outside of a Gnus article buffer")))
5902 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5903 "Read a summary buffer key sequence and execute it from the article buffer."
5905 (gnus-article-check-buffer)
5907 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5908 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5909 "=" "^" "\M-^" "|"))
5915 '("n" "Gn" "p" "Gp"))
5918 (set-buffer gnus-article-current-summary)
5919 (let (gnus-pick-mode)
5920 (push (or key last-command-event) unread-command-events)
5921 (setq keys (if (featurep 'xemacs)
5922 (events-to-keys (read-key-sequence nil))
5923 (read-key-sequence nil)))))
5927 (if (or (member keys nosaves)
5928 (member keys nosave-but-article)
5929 (member keys nosave-in-article))
5931 (save-window-excursion
5932 (pop-to-buffer gnus-article-current-summary 'norecord)
5933 ;; We disable the pick minor mode commands.
5934 (let (gnus-pick-mode)
5935 (setq func (lookup-key (current-local-map) keys))))
5939 (unless (member keys nosave-in-article)
5940 (set-buffer gnus-article-current-summary))
5941 (call-interactively func)
5942 (setq new-sum-point (point)))
5943 (when (member keys nosave-but-article)
5944 (pop-to-buffer gnus-article-buffer 'norecord)))
5945 ;; These commands should restore window configuration.
5946 (let ((obuf (current-buffer))
5947 (owin (current-window-configuration))
5949 win func in-buffer selected new-sum-start new-sum-hscroll)
5950 (cond (not-restore-window
5951 (pop-to-buffer gnus-article-current-summary 'norecord))
5952 ((setq win (get-buffer-window gnus-article-current-summary))
5953 (select-window win))
5955 (switch-to-buffer gnus-article-current-summary 'norecord)))
5956 (setq in-buffer (current-buffer))
5957 ;; We disable the pick minor mode commands.
5958 (if (and (setq func (let (gnus-pick-mode)
5959 (lookup-key (current-local-map) keys)))
5962 (call-interactively func)
5963 (when (eq win (selected-window))
5964 (setq new-sum-point (point)
5965 new-sum-start (window-start win)
5966 new-sum-hscroll (window-hscroll win)))
5967 (when (eq in-buffer (current-buffer))
5968 (setq selected (gnus-summary-select-article))
5970 (unless not-restore-window
5971 (set-window-configuration owin))
5972 (when (eq selected 'old)
5974 (set-window-start (get-buffer-window (current-buffer))
5976 (set-window-point (get-buffer-window (current-buffer))
5978 (when (and (not not-restore-window)
5980 (set-window-point win new-sum-point)
5981 (set-window-start win new-sum-start)
5982 (set-window-hscroll win new-sum-hscroll))))
5983 (set-window-configuration owin)
5986 (defun gnus-article-describe-key (key)
5987 "Display documentation of the function invoked by KEY. KEY is a string."
5988 (interactive "kDescribe key: ")
5989 (gnus-article-check-buffer)
5990 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5992 (set-buffer gnus-article-current-summary)
5993 (let (gnus-pick-mode)
5994 (if (featurep 'xemacs)
5996 (push (elt key 0) unread-command-events)
5997 (setq key (events-to-keys
5998 (read-key-sequence "Describe key: "))))
5999 (setq unread-command-events
6001 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6002 (string-to-list key)))
6003 (setq key (read-key-sequence "Describe key: "))))
6005 (describe-key key)))
6007 (defun gnus-article-describe-key-briefly (key &optional insert)
6008 "Display documentation of the function invoked by KEY. KEY is a string."
6009 (interactive "kDescribe key: \nP")
6010 (gnus-article-check-buffer)
6011 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
6013 (set-buffer gnus-article-current-summary)
6014 (let (gnus-pick-mode)
6015 (if (featurep 'xemacs)
6017 (push (elt key 0) unread-command-events)
6018 (setq key (events-to-keys
6019 (read-key-sequence "Describe key: "))))
6020 (setq unread-command-events
6022 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
6023 (string-to-list key)))
6024 (setq key (read-key-sequence "Describe key: "))))
6025 (describe-key-briefly key insert))
6026 (describe-key-briefly key insert)))
6028 (defun gnus-article-reply-with-original (&optional wide)
6029 "Start composing a reply mail to the current message.
6030 The text in the region will be yanked. If the region isn't active,
6031 the entire article will be yanked."
6033 (let ((article (cdr gnus-article-current))
6035 (if (not (gnus-region-active-p))
6036 (with-current-buffer gnus-summary-buffer
6037 (gnus-summary-reply (list (list article)) wide))
6038 (setq contents (buffer-substring (point) (mark t)))
6039 ;; Deactivate active regions.
6040 (when (and (boundp 'transient-mark-mode)
6041 transient-mark-mode)
6042 (setq mark-active nil))
6043 (with-current-buffer gnus-summary-buffer
6045 (list (list article contents)) wide)))))
6047 (defun gnus-article-followup-with-original ()
6048 "Compose a followup to the current article.
6049 The text in the region will be yanked. If the region isn't active,
6050 the entire article will be yanked."
6052 (let ((article (cdr gnus-article-current))
6054 (if (not (gnus-region-active-p))
6055 (with-current-buffer gnus-summary-buffer
6056 (gnus-summary-followup (list (list article))))
6057 (setq contents (buffer-substring (point) (mark t)))
6058 ;; Deactivate active regions.
6059 (when (and (boundp 'transient-mark-mode)
6060 transient-mark-mode)
6061 (setq mark-active nil))
6062 (with-current-buffer gnus-summary-buffer
6063 (gnus-summary-followup
6064 (list (list article contents)))))))
6066 (defun gnus-article-hide (&optional arg force)
6067 "Hide all the gruft in the current article.
6068 This means that signatures, cited text and (some) headers will be
6070 If given a prefix, show the hidden text instead."
6071 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6072 (gnus-article-hide-headers arg)
6073 (gnus-article-hide-list-identifiers arg)
6074 (gnus-article-hide-citation-maybe arg force)
6075 (gnus-article-hide-signature arg))
6077 (defun gnus-article-maybe-highlight ()
6078 "Do some article highlighting if article highlighting is requested."
6079 (when (gnus-visual-p 'article-highlight 'highlight)
6080 (gnus-article-highlight-some)))
6082 (defun gnus-check-group-server ()
6083 ;; Make sure the connection to the server is alive.
6084 (unless (gnus-server-opened
6085 (gnus-find-method-for-group gnus-newsgroup-name))
6086 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6087 (gnus-request-group gnus-newsgroup-name t)))
6090 (autoload 'nneething-get-file-name "nneething"))
6092 (defun gnus-request-article-this-buffer (article group)
6093 "Get an article and insert it into this buffer."
6094 (let (do-update-line sparse-header)
6098 (gnus-kill-all-overlays)
6099 (setq group (or group gnus-newsgroup-name))
6101 ;; Using `gnus-request-article' directly will insert the article into
6102 ;; `nntp-server-buffer' - so we'll save some time by not having to
6103 ;; copy it from the server buffer into the article buffer.
6105 ;; We only request an article by message-id when we do not have the
6106 ;; headers for it, so we'll have to get those.
6107 (when (stringp article)
6108 (gnus-read-header article))
6110 ;; If the article number is negative, that means that this article
6111 ;; doesn't belong in this newsgroup (possibly), so we find its
6112 ;; message-id and request it by id instead of number.
6113 (when (and (numberp article)
6115 (get-buffer gnus-summary-buffer)
6116 (gnus-buffer-exists-p gnus-summary-buffer))
6118 (set-buffer gnus-summary-buffer)
6119 (let ((header (gnus-summary-article-header article)))
6122 ((memq article gnus-newsgroup-sparse)
6123 ;; This is a sparse gap article.
6124 (setq do-update-line article)
6125 (setq article (mail-header-id header))
6126 (setq sparse-header (gnus-read-header article))
6127 (setq gnus-newsgroup-sparse
6128 (delq article gnus-newsgroup-sparse)))
6130 ;; It's a real article.
6131 (setq article (mail-header-id header)))
6133 ;; It is an extracted pseudo-article.
6134 (setq article 'pseudo)
6135 (gnus-request-pseudo-article header))))
6137 (let ((method (gnus-find-method-for-group
6138 gnus-newsgroup-name)))
6139 (when (and (eq (car method) 'nneething)
6141 (let ((dir (nneething-get-file-name
6142 (mail-header-id header))))
6143 (when (and (stringp dir)
6144 (file-directory-p dir))
6145 (setq article 'nneething)
6146 (gnus-group-enter-directory dir))))))))
6149 ;; Refuse to select canceled articles.
6150 ((and (numberp article)
6152 (get-buffer gnus-summary-buffer)
6153 (gnus-buffer-exists-p gnus-summary-buffer)
6154 (eq (cdr (with-current-buffer gnus-summary-buffer
6155 (assq article gnus-newsgroup-reads)))
6156 gnus-canceled-mark))
6158 ;; We first check `gnus-original-article-buffer'.
6159 ((and (get-buffer gnus-original-article-buffer)
6161 (with-current-buffer gnus-original-article-buffer
6162 (and (equal (car gnus-original-article) group)
6163 (eq (cdr gnus-original-article) article))))
6164 (insert-buffer-substring gnus-original-article-buffer)
6166 ;; Check the backlog.
6167 ((and gnus-keep-backlog
6168 (gnus-backlog-request-article group article (current-buffer)))
6170 ;; Check asynchronous pre-fetch.
6171 ((gnus-async-request-fetched-article group article (current-buffer))
6172 (gnus-async-prefetch-next group article gnus-summary-buffer)
6173 (when (and (numberp article) gnus-keep-backlog)
6174 (gnus-backlog-enter-article group article (current-buffer)))
6177 ((and gnus-use-cache
6179 (gnus-cache-request-article article group))
6181 ;; Check the agent cache.
6182 ((gnus-agent-request-article article group)
6184 ;; Get the article and put into the article buffer.
6185 ((or (stringp article)
6187 (let ((gnus-override-method gnus-override-method)
6188 (methods (and (stringp article)
6189 gnus-refer-article-method))
6190 (backend (car (gnus-find-method-for-group
6191 gnus-newsgroup-name)))
6193 (inhibit-read-only t))
6194 (if (or (not (listp methods))
6195 (and (symbolp (car methods))
6196 (assq (car methods) nnoo-definition-alist)))
6197 (setq methods (list methods)))
6198 (when (and (null gnus-override-method)
6200 (setq gnus-override-method (pop methods)))
6202 (when (eq gnus-override-method 'current)
6203 (setq gnus-override-method
6204 (with-current-buffer gnus-summary-buffer
6205 gnus-current-select-method)))
6207 (gnus-kill-all-overlays)
6208 (let ((gnus-newsgroup-name group))
6209 (gnus-check-group-server))
6211 ((gnus-request-article article group (current-buffer))
6212 (when (numberp article)
6213 (gnus-async-prefetch-next group article
6214 gnus-summary-buffer)
6215 (when gnus-keep-backlog
6216 (gnus-backlog-enter-article
6217 group article (current-buffer))))
6218 (setq result 'article))
6220 (setq gnus-override-method (pop methods)))
6221 ((not (string-match "^400 "
6222 (nnheader-get-report backend)))
6223 ;; If we get 400 server disconnect, reconnect and
6224 ;; retry; otherwise, assume the article has expired.
6225 (setq result 'done))))
6226 (and (eq result 'article) 'article)))
6230 ;; Associate this article with the current summary buffer.
6231 (setq gnus-article-current-summary gnus-summary-buffer)
6233 ;; Take the article from the original article buffer
6234 ;; and place it in the buffer it's supposed to be in.
6235 (when (and (get-buffer gnus-article-buffer)
6236 (equal (buffer-name (current-buffer))
6237 (buffer-name (get-buffer gnus-article-buffer))))
6239 (if (get-buffer gnus-original-article-buffer)
6240 (set-buffer gnus-original-article-buffer)
6241 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6242 (buffer-disable-undo)
6243 (setq major-mode 'gnus-original-article-mode)
6244 (setq buffer-read-only t))
6245 (let ((inhibit-read-only t))
6247 (insert-buffer-substring gnus-article-buffer))
6248 (setq gnus-original-article (cons group article)))
6251 (run-hooks 'gnus-article-decode-hook)
6252 ;; Mark article as decoded or not.
6253 (setq gnus-article-decoded-p gnus-article-decode-hook))
6255 ;; Update sparse articles.
6256 (when (and do-update-line
6257 (or (numberp article)
6259 (let ((buf (current-buffer)))
6260 (set-buffer gnus-summary-buffer)
6261 (gnus-summary-update-article do-update-line sparse-header)
6262 (gnus-summary-goto-subject do-update-line nil t)
6263 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6265 (set-buffer buf))))))
6271 (defcustom gnus-article-edit-mode-hook nil
6272 "Hook run in article edit mode buffers."
6273 :group 'gnus-article-various
6276 (defvar gnus-article-edit-done-function nil)
6278 (defvar gnus-article-edit-mode-map nil)
6280 ;; Should we be using derived.el for this?
6281 (unless gnus-article-edit-mode-map
6282 (setq gnus-article-edit-mode-map (make-keymap))
6283 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6285 (gnus-define-keys gnus-article-edit-mode-map
6286 "\C-c?" describe-mode
6287 "\C-c\C-c" gnus-article-edit-done
6288 "\C-c\C-k" gnus-article-edit-exit
6289 "\C-c\C-f\C-t" message-goto-to
6290 "\C-c\C-f\C-o" message-goto-from
6291 "\C-c\C-f\C-b" message-goto-bcc
6292 ;;"\C-c\C-f\C-w" message-goto-fcc
6293 "\C-c\C-f\C-c" message-goto-cc
6294 "\C-c\C-f\C-s" message-goto-subject
6295 "\C-c\C-f\C-r" message-goto-reply-to
6296 "\C-c\C-f\C-n" message-goto-newsgroups
6297 "\C-c\C-f\C-d" message-goto-distribution
6298 "\C-c\C-f\C-f" message-goto-followup-to
6299 "\C-c\C-f\C-m" message-goto-mail-followup-to
6300 "\C-c\C-f\C-k" message-goto-keywords
6301 "\C-c\C-f\C-u" message-goto-summary
6302 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6303 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6304 "\C-c\C-b" message-goto-body
6305 "\C-c\C-i" message-goto-signature
6307 "\C-c\C-t" message-insert-to
6308 "\C-c\C-n" message-insert-newsgroups
6309 "\C-c\C-o" message-sort-headers
6310 "\C-c\C-e" message-elide-region
6311 "\C-c\C-v" message-delete-not-region
6312 "\C-c\C-z" message-kill-to-signature
6313 "\M-\r" message-newline-and-reformat
6314 "\C-c\C-a" mml-attach-file
6315 "\C-a" message-beginning-of-line
6317 "\M-;" comment-region)
6319 (gnus-define-keys (gnus-article-edit-wash-map
6320 "\C-c\C-w" gnus-article-edit-mode-map)
6321 "f" gnus-article-edit-full-stops))
6324 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6326 ["Fetch To" message-insert-to t]
6327 ["Fetch Newsgroups" message-insert-newsgroups t]
6329 ["To" message-goto-to t]
6330 ["From" message-goto-from t]
6331 ["Subject" message-goto-subject t]
6332 ["Cc" message-goto-cc t]
6333 ["Reply-To" message-goto-reply-to t]
6334 ["Summary" message-goto-summary t]
6335 ["Keywords" message-goto-keywords t]
6336 ["Newsgroups" message-goto-newsgroups t]
6337 ["Followup-To" message-goto-followup-to t]
6338 ["Mail-Followup-To" message-goto-mail-followup-to t]
6339 ["Distribution" message-goto-distribution t]
6340 ["Body" message-goto-body t]
6341 ["Signature" message-goto-signature t]))
6343 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6344 "Major mode for editing articles.
6345 This is an extended text-mode.
6347 \\{gnus-article-edit-mode-map}"
6348 (make-local-variable 'gnus-article-edit-done-function)
6349 (make-local-variable 'gnus-prev-winconf)
6350 (set (make-local-variable 'font-lock-defaults)
6351 '(message-font-lock-keywords t))
6352 (set (make-local-variable 'mail-header-separator) "")
6353 (set (make-local-variable 'gnus-article-edit-mode) t)
6354 (easy-menu-add message-mode-field-menu message-mode-map)
6356 (setq buffer-read-only nil)
6357 (buffer-enable-undo)
6360 (defun gnus-article-edit (&optional force)
6361 "Edit the current article.
6362 This will have permanent effect only in mail groups.
6363 If FORCE is non-nil, allow editing of articles even in read-only
6366 (when (and (not force)
6367 (gnus-group-read-only-p))
6368 (error "The current newsgroup does not support article editing"))
6369 (gnus-article-date-original)
6370 (gnus-article-edit-article
6372 `(lambda (no-highlight)
6374 (gnus-summary-edit-article-done
6375 ,(or (mail-header-references gnus-current-headers) "")
6376 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6378 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6379 "Start editing the contents of the current article buffer."
6380 (let ((winconf (current-window-configuration)))
6381 (set-buffer gnus-article-buffer)
6382 (let ((message-auto-save-directory
6383 ;; Don't associate the article buffer with a draft file.
6385 (gnus-article-edit-mode))
6386 (funcall start-func)
6387 (set-buffer-modified-p nil)
6388 (gnus-configure-windows 'edit-article)
6389 (setq gnus-article-edit-done-function exit-func)
6390 (setq gnus-prev-winconf winconf)
6392 (gnus-message 6 "C-c C-c to end edits"))))
6394 (defun gnus-article-edit-done (&optional arg)
6395 "Update the article edits and exit."
6397 (let ((func gnus-article-edit-done-function)
6398 (buf (current-buffer))
6399 (start (window-start))
6401 (winconf gnus-prev-winconf))
6402 (widen) ;; Widen it in case that users narrowed the buffer.
6405 ;; The cache and backlog have to be flushed somewhat.
6406 (when gnus-keep-backlog
6407 (gnus-backlog-remove-article
6408 (car gnus-article-current) (cdr gnus-article-current)))
6409 ;; Flush original article as well.
6411 (when (get-buffer gnus-original-article-buffer)
6412 (set-buffer gnus-original-article-buffer)
6413 (setq gnus-original-article nil)))
6414 (when gnus-use-cache
6415 (gnus-cache-update-article
6416 (car gnus-article-current) (cdr gnus-article-current)))
6417 ;; We remove all text props from the article buffer.
6418 (kill-all-local-variables)
6419 (set-text-properties (point-min) (point-max) nil)
6421 (set-window-configuration winconf)
6423 (set-window-start (get-buffer-window buf) start)
6424 (set-window-point (get-buffer-window buf) (point)))
6425 (gnus-summary-show-article))
6427 (defun gnus-article-edit-exit ()
6428 "Exit the article editing without updating."
6430 (when (or (not (buffer-modified-p))
6431 (yes-or-no-p "Article modified; kill anyway? "))
6432 (let ((curbuf (current-buffer))
6434 (window-start (window-start)))
6436 (if (gnus-buffer-live-p gnus-original-article-buffer)
6437 (insert-buffer-substring gnus-original-article-buffer))
6438 (let ((winconf gnus-prev-winconf))
6439 (kill-all-local-variables)
6441 (set-window-configuration winconf)
6442 ;; Tippy-toe some to make sure that point remains where it was.
6443 (save-current-buffer
6445 (set-window-start (get-buffer-window (current-buffer)) window-start)
6447 (gnus-summary-show-article)))
6449 (defun gnus-article-edit-full-stops ()
6450 "Interactively repair spacing at end of sentences."
6453 (goto-char (point-min))
6454 (search-forward-regexp "^$" nil t)
6455 (let ((case-fold-search nil))
6456 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6459 ;;; Article highlights
6462 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6464 ;;; Internal Variables:
6466 (defcustom gnus-button-url-regexp
6468 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6469 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6470 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6471 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6472 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6476 ;; Match paired parentheses, e.g. in WikiPedia URLs:
6477 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6479 "[" chars punct "]+" "[" chars "]"
6481 (concat ;; XEmacs 21.4 doesn't support POSIX.
6482 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6483 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6485 "Regular expression that matches URLs."
6486 :group 'gnus-article-buttons
6489 (defcustom gnus-button-valid-fqdn-regexp
6490 message-valid-fqdn-regexp
6491 "Regular expression that matches a valid FQDN."
6493 :group 'gnus-article-buttons
6496 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6497 (defcustom gnus-button-valid-localpart-regexp
6498 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6499 "Regular expression that matches a localpart of mail addresses or MIDs."
6501 :group 'gnus-article-buttons
6504 (defcustom gnus-button-man-handler 'manual-entry
6505 "Function to use for displaying man pages.
6506 The function must take at least one argument with a string naming the
6509 :type '(choice (function-item :tag "Man" manual-entry)
6510 (function-item :tag "Woman" woman)
6511 (function :tag "Other"))
6512 :group 'gnus-article-buttons)
6514 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6515 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6516 If the default site is too slow, try to find a CTAN mirror, see
6517 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6518 the variable `gnus-button-handle-ctan'."
6520 :group 'gnus-article-buttons
6521 :link '(custom-manual "(gnus)Group Parameters")
6522 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6523 (const "http://tug.ctan.org/tex-archive/")
6524 (const "http://www.dante.de/CTAN/")
6525 (string :tag "Other")))
6527 (defcustom gnus-button-ctan-handler 'browse-url
6528 "Function to use for displaying CTAN links.
6529 The function must take one argument, the string naming the URL."
6531 :type '(choice (function-item :tag "Browse Url" browse-url)
6532 (function :tag "Other"))
6533 :group 'gnus-article-buttons)
6535 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6536 "Bogus strings removed from CTAN URLs."
6538 :group 'gnus-article-buttons
6539 :type '(choice (const "^/?tex-archive/\\|/")
6540 (regexp :tag "Other")))
6542 (defcustom gnus-button-ctan-directory-regexp
6544 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6545 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6546 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6547 "tds" "tools" "usergrps" "web") t)
6548 "Regular expression for ctan directories.
6549 It should match all directories in the top level of `gnus-ctan-url'."
6551 :group 'gnus-article-buttons
6554 (defcustom gnus-button-mid-or-mail-regexp
6555 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6556 gnus-button-valid-fqdn-regexp
6558 "Regular expression that matches a message ID or a mail address."
6560 :group 'gnus-article-buttons
6563 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6564 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6565 Strings like this can be either a message ID or a mail address. If it is one
6566 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6567 message ID or a mail address, respectively. If this variable is set to the
6568 symbol `ask', always query the user what do do. If it is a function, this
6569 function will be called with the string as it's only argument. The function
6570 must return `mid', `mail', `invalid' or `ask'."
6572 :group 'gnus-article-buttons
6573 :type '(choice (function-item :tag "Heuristic function"
6574 gnus-button-mid-or-mail-heuristic)
6579 (defcustom gnus-button-mid-or-mail-heuristic-alist
6580 '((-10.0 . ".+\\$.+@")
6583 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6584 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6585 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6586 (-1.0 . "^[^a-z]+@")
6588 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6589 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6590 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6591 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6594 (-1.0 . "^[0-9][0-9]")
6596 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6597 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6598 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6599 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6601 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6602 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6605 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6607 ;; compensation for TDMA dated mail addresses:
6608 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6610 (-20.0 . "\\.fsf@") ;; Gnus
6613 (-20.0 . "_-_") ;; Subject change in thread
6615 (-20.0 . "\\.ln@") ;; leafnode
6616 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6617 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6619 ;; (5.0 . "") ;; $local_part_len <= 7
6620 (10.0 . "^[^0-9]+@")
6621 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6622 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6625 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6627 (0.5 . "^[A-Z][a-z]")
6628 (0.5 . "^[A-Z][a-z][a-z]")
6629 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6630 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6631 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6633 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6634 address. The REGEXP is processed with `case-fold-search' set to nil."
6636 :group 'gnus-article-buttons
6637 :type '(repeat (cons (number :tag "Rate")
6638 (regexp :tag "Regexp"))))
6640 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6641 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6642 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6643 address, `ask' if unsure and `invalid' if the string is invalid."
6644 (let ((case-fold-search nil)
6645 (list gnus-button-mid-or-mail-heuristic-alist)
6646 (result 0) rate regexp lpartlen elem)
6648 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6649 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6650 ;; Certain special cases...
6653 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6654 "^[0-9]+\\.[0-9]+@compuserve\\|"
6655 "@public\\.gmane\\.org")
6657 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6658 (setq result 'mail))
6659 (when (string-match "@.*@\\| " mid-or-mail)
6660 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6661 (setq result 'invalid))
6662 ;; Nothing more to do, if result is not a number here...
6663 (when (numberp result)
6665 (setq elem (car list)
6669 (when (string-match regexp mid-or-mail)
6670 (setq result (+ result rate))
6672 9 "`%s' matched `%s', rate `%s', result `%s'."
6673 mid-or-mail regexp rate result)))
6674 (when (<= lpartlen 7)
6675 (setq result (+ result 5.0))
6676 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6677 mid-or-mail result))
6678 (when (>= lpartlen 12)
6679 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6681 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6682 ;; Long local part should contain realname if e-mail address,
6683 ;; too many digits: message-id.
6684 ;; $score -= 5.0 + 0.1 * $local_part_len;
6685 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6686 (setq result (+ result rate))
6688 9 "Many digits in `%s', rate `%s', result `%s'."
6689 mid-or-mail rate result))
6690 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6692 ;; Too few vowels [^aeiouy]{4,}.*\@
6693 (setq result (+ result -5.0))
6695 9 "Few vowels in `%s', rate `%s', result `%s'."
6696 mid-or-mail -5.0 result))
6698 (setq result (+ result 5.0))
6700 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6701 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6702 ;; Maybe we should make this a customizable alist: (condition . 'result)
6704 ((symbolp result) result)
6705 ;; Now convert number into proper results:
6706 ((< result -10.0) 'mid)
6707 ((> result 10.0) 'mail)
6710 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6711 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6712 (url-mid (concat "news" ":" mid-or-mail))
6713 (url-mailto (concat "mailto" ":" mid-or-mail)))
6714 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6715 (when (fboundp pref)
6717 ;; get rid of surrounding angles...
6719 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6720 (if (or (eq 'mid guessed) (eq 'mail guessed))
6724 (save-window-excursion
6725 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6728 (cond ((eq pref 'mid)
6729 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6730 (gnus-button-handle-news url-mid))
6732 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6733 (gnus-url-mailto url-mailto))
6734 (t (gnus-message 3 "Invalid string.")))))
6736 (defun gnus-button-handle-custom (fun arg)
6737 "Call function FUN on argument ARG.
6738 Both FUN and ARG are supposed to be strings. ARG will be passed
6739 as a symbol to FUN."
6740 (funcall (intern fun)
6741 (if (string-match "^customize-apropos" fun)
6745 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6747 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6750 (defun gnus-button-handle-describe-function (url)
6751 "Call `describe-function' when pushing the corresponding URL button."
6754 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6756 (defun gnus-button-handle-describe-variable (url)
6757 "Call `describe-variable' when pushing the corresponding URL button."
6760 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6762 (defun gnus-button-handle-symbol (url)
6763 "Display help on variable or function.
6764 Calls `describe-variable' or `describe-function'."
6765 (let ((sym (intern url)))
6767 ((fboundp sym) (describe-function sym))
6768 ((boundp sym) (describe-variable sym))
6769 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6771 (defun gnus-button-handle-describe-key (url)
6772 "Call `describe-key' when pushing the corresponding URL button."
6774 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6775 (keys (ignore-errors (eval `(kbd ,key-string)))))
6778 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6780 (defun gnus-button-handle-apropos (url)
6781 "Call `apropos' when pushing the corresponding URL button."
6782 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6784 (defun gnus-button-handle-apropos-command (url)
6785 "Call `apropos' when pushing the corresponding URL button."
6787 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6789 (defun gnus-button-handle-apropos-variable (url)
6790 "Call `apropos' when pushing the corresponding URL button."
6792 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6793 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6795 (defun gnus-button-handle-apropos-documentation (url)
6796 "Call `apropos' when pushing the corresponding URL button."
6798 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6799 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6801 (defun gnus-button-handle-library (url)
6802 "Call `locate-library' when pushing the corresponding URL button."
6803 (gnus-message 9 "url=`%s'" url)
6804 (let* ((lib (locate-library url))
6805 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6807 (gnus-message 1 "Cannot locale library `%s'." url)
6808 (find-file-read-only file))))
6810 (defun gnus-button-handle-ctan (url)
6811 "Call `browse-url' when pushing a CTAN URL button."
6813 gnus-button-ctan-handler
6816 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6818 (defcustom gnus-button-tex-level 5
6819 "*Integer that says how many TeX-related buttons Gnus will show.
6820 The higher the number, the more buttons will appear and the more false
6821 positives are possible. Note that you can set this variable local to
6822 specific groups. Setting it higher in TeX groups is probably a good idea.
6823 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6824 how to set variables in specific groups."
6826 :group 'gnus-article-buttons
6827 :link '(custom-manual "(gnus)Group Parameters")
6830 (defcustom gnus-button-man-level 5
6831 "*Integer that says how many man-related buttons Gnus will show.
6832 The higher the number, the more buttons will appear and the more false
6833 positives are possible. Note that you can set this variable local to
6834 specific groups. Setting it higher in Unix groups is probably a good idea.
6835 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6836 how to set variables in specific groups."
6838 :group 'gnus-article-buttons
6839 :link '(custom-manual "(gnus)Group Parameters")
6842 (defcustom gnus-button-emacs-level 5
6843 "*Integer that says how many emacs-related buttons Gnus will show.
6844 The higher the number, the more buttons will appear and the more false
6845 positives are possible. Note that you can set this variable local to
6846 specific groups. Setting it higher in Emacs or Gnus related groups is
6847 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6848 `gnus-parameters' on how to set variables in specific groups."
6850 :group 'gnus-article-buttons
6851 :link '(custom-manual "(gnus)Group Parameters")
6854 (defcustom gnus-button-message-level 5
6855 "*Integer that says how many buttons for news or mail messages will appear.
6856 The higher the number, the more buttons will appear and the more false
6857 positives are possible."
6858 ;; mail addresses, MIDs, URLs for news, ...
6860 :group 'gnus-article-buttons
6863 (defcustom gnus-button-browse-level 5
6864 "*Integer that says how many buttons for browsing will appear.
6865 The higher the number, the more buttons will appear and the more false
6866 positives are possible."
6867 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6869 :group 'gnus-article-buttons
6872 (defcustom gnus-button-alist
6873 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6874 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6875 ((concat "\\b\\(nntp\\|news\\):\\("
6876 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
6877 0 t gnus-button-handle-news 2)
6878 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6879 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6880 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6881 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6882 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6883 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6884 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6885 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6886 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6887 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6888 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6889 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6890 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6891 ;; RFC 2368 (The mailto URL scheme)
6892 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6893 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6894 ("\\bmailto:\\([^ \n\t]+\\)"
6895 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6897 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6898 gnus-button-ctan-directory-regexp
6899 "[^][>)!;:,'\n\t ]+\\)")
6900 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6901 ((concat "\\btex-archive/\\("
6902 gnus-button-ctan-directory-regexp
6903 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6904 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6907 gnus-button-ctan-directory-regexp
6908 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6909 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6910 ;; This is info (home-grown style) <info://foo/bar+baz>
6911 ("\\binfo://\\([^'\">\n\t ]+\\)"
6912 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6913 ;; Info GNOME style <info:foo#bar_baz>
6914 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6915 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6916 ;; Info KDE style <info:(foo)bar baz>
6917 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6918 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6919 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6920 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6921 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6922 ;; Info links like `C-h i d m CC Mode RET'
6923 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6925 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6926 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
6927 ;; Emacs help commands
6928 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6929 ;; regexp doesn't match arguments containing ` '.
6930 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6931 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6932 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6933 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6934 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6935 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6936 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6937 ;; The following entries may lead to many false positives so don't enable
6938 ;; them by default (use a high button level).
6939 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6940 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6941 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6942 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6943 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6944 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6945 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6946 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6947 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6948 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6949 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6950 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6951 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6952 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6953 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6954 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6955 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6956 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6957 ;; Unlike the other regexps we really have to require quoting
6958 ;; here to determine where it ends.
6959 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6960 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6961 ("<URL: *\\([^<>]*\\)>"
6962 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6963 ;; RFC 2396 (2.4.3., delims) ...
6964 ("\"URL: *\\([^\"]*\\)\""
6965 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6966 ;; RFC 2396 (2.4.3., delims) ...
6967 ("\"URL: *\\([^\"]*\\)\""
6968 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6970 (gnus-button-url-regexp
6971 0 (>= gnus-button-browse-level 0) browse-url 0)
6973 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6974 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6975 gnus-button-handle-man 1)
6976 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6977 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6978 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6979 gnus-button-handle-man 1)
6980 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6981 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6982 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6983 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6984 ;; Recognizing patches to .el files. This is somewhat obscure,
6985 ;; but considering the percentage of Gnus users who hack Emacs
6987 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
6988 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
6989 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
6990 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
6991 ;; MID or mail: To avoid too many false positives we don't try to catch
6992 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6993 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6994 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6995 ;; so that non-ambiguous entries (see above) match first.
6996 (gnus-button-mid-or-mail-regexp
6997 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6998 "*Alist of regexps matching buttons in article bodies.
7000 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7001 REGEXP: is the string (case insensitive) matching text around the button (can
7002 also be Lisp expression evaluating to a string),
7003 BUTTON: is the number of the regexp grouping actually matching the button,
7004 FORM: is a Lisp expression which must eval to true for the button to
7006 CALLBACK: is the function to call when the user push this button, and each
7007 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7009 CALLBACK can also be a variable, in that case the value of that
7010 variable it the real callback function."
7011 :group 'gnus-article-buttons
7012 :type '(repeat (list (choice regexp variable sexp)
7013 (integer :tag "Button")
7015 (function :tag "Callback")
7018 (integer :tag "Regexp group")))))
7020 (defcustom gnus-header-button-alist
7021 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7022 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7023 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7024 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7025 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7026 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7027 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7028 0 (>= gnus-button-browse-level 0) browse-url 0)
7029 ("^Subject:" gnus-button-url-regexp
7030 0 (>= gnus-button-browse-level 0) browse-url 0)
7031 ("^[^:]+:" gnus-button-url-regexp
7032 0 (>= gnus-button-browse-level 0) browse-url 0)
7033 ("^OpenPGP:.*url=" gnus-button-url-regexp
7034 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7035 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7036 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7037 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7038 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7039 "*Alist of headers and regexps to match buttons in article heads.
7041 This alist is very similar to `gnus-button-alist', except that each
7042 alist has an additional HEADER element first in each entry:
7044 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7046 HEADER is a regexp to match a header. For a fuller explanation, see
7047 `gnus-button-alist'."
7048 :group 'gnus-article-buttons
7049 :group 'gnus-article-headers
7050 :type '(repeat (list (regexp :tag "Header")
7051 (choice regexp variable)
7052 (integer :tag "Button")
7054 (function :tag "Callback")
7057 (integer :tag "Regexp group")))))
7061 (defun gnus-article-push-button (event)
7062 "Check text under the mouse pointer for a callback function.
7063 If the text under the mouse pointer has a `gnus-callback' property,
7064 call it with the value of the `gnus-data' text property."
7066 (set-buffer (window-buffer (posn-window (event-start event))))
7067 (let* ((pos (posn-point (event-start event)))
7068 (data (get-text-property pos 'gnus-data))
7069 (fun (get-text-property pos 'gnus-callback)))
7072 (funcall fun data))))
7074 (defun gnus-article-press-button ()
7075 "Check text at point for a callback function.
7076 If the text at point has a `gnus-callback' property,
7077 call it with the value of the `gnus-data' text property."
7079 (let ((data (get-text-property (point) 'gnus-data))
7080 (fun (get-text-property (point) 'gnus-callback)))
7082 (funcall fun data))))
7084 (defun gnus-article-highlight (&optional force)
7085 "Highlight current article.
7086 This function calls `gnus-article-highlight-headers',
7087 `gnus-article-highlight-citation',
7088 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7089 do the highlighting. See the documentation for those functions."
7090 (interactive (list 'force))
7091 (gnus-article-highlight-headers)
7092 (gnus-article-highlight-citation force)
7093 (gnus-article-highlight-signature)
7094 (gnus-article-add-buttons force)
7095 (gnus-article-add-buttons-to-head))
7097 (defun gnus-article-highlight-some (&optional force)
7098 "Highlight current article.
7099 This function calls `gnus-article-highlight-headers',
7100 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7101 do the highlighting. See the documentation for those functions."
7102 (interactive (list 'force))
7103 (gnus-article-highlight-headers)
7104 (gnus-article-highlight-signature)
7105 (gnus-article-add-buttons))
7107 (defun gnus-article-highlight-headers ()
7108 "Highlight article headers as specified by `gnus-header-face-alist'."
7110 (gnus-with-article-headers
7111 (let (regexp header-face field-face from hpoints fpoints)
7112 (dolist (entry gnus-header-face-alist)
7113 (goto-char (point-min))
7114 (setq regexp (concat "^\\("
7115 (if (string-equal "" (nth 0 entry))
7119 header-face (nth 1 entry)
7120 field-face (nth 2 entry))
7121 (while (and (re-search-forward regexp nil t)
7125 (unless (search-forward ":" nil t)
7127 (when (and header-face
7128 (not (memq (point) hpoints)))
7129 (push (point) hpoints)
7130 (gnus-put-text-property from (point) 'face header-face))
7131 (when (and field-face
7132 (not (memq (setq from (point)) fpoints)))
7134 (if (re-search-forward "^[^ \t]" nil t)
7136 (goto-char (point-max)))
7137 (gnus-put-text-property from (point) 'face field-face)))))))
7139 (defun gnus-article-highlight-signature ()
7140 "Highlight the signature in an article.
7141 It does this by highlighting everything after
7142 `gnus-signature-separator' using the face `gnus-signature'."
7144 (gnus-with-article-buffer
7145 (let ((inhibit-point-motion-hooks t))
7147 (when (and gnus-signature-face
7148 (gnus-article-narrow-to-signature))
7149 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
7150 'face gnus-signature-face)
7152 (gnus-article-search-signature)
7153 (let ((start (match-beginning 0))
7154 (end (set-marker (make-marker) (1+ (match-end 0)))))
7155 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7158 (defun gnus-button-in-region-p (b e prop)
7159 "Say whether PROP exists in the region."
7160 (text-property-not-all b e prop nil))
7162 (defun gnus-article-add-buttons (&optional force)
7163 "Find external references in the article and make buttons of them.
7164 \"External references\" are things like Message-IDs and URLs, as
7165 specified by `gnus-button-alist'."
7166 (interactive (list 'force))
7167 (gnus-with-article-buffer
7168 (let ((inhibit-point-motion-hooks t)
7169 (case-fold-search t)
7170 (alist gnus-button-alist)
7172 ;; Remove all old markers.
7173 (let (marker entry new-list)
7174 (while (setq marker (pop gnus-button-marker-list))
7175 (if (or (< marker (point-min)) (>= marker (point-max)))
7176 (push marker new-list)
7178 (when (setq entry (gnus-button-entry))
7179 (put-text-property (match-beginning (nth 1 entry))
7180 (match-end (nth 1 entry))
7181 'gnus-callback nil))
7182 (set-marker marker nil)))
7183 (setq gnus-button-marker-list new-list))
7184 ;; We skip the headers.
7187 (while (setq entry (pop alist))
7188 (setq regexp (eval (car entry)))
7190 (while (re-search-forward regexp nil t)
7191 (let* ((start (and entry (match-beginning (nth 1 entry))))
7192 (end (and entry (match-end (nth 1 entry))))
7193 (from (match-beginning 0)))
7194 (when (and (or (eq t (nth 2 entry))
7195 (eval (nth 2 entry)))
7196 (not (gnus-button-in-region-p
7197 start end 'gnus-callback)))
7198 ;; That optional form returned non-nil, so we add the
7200 (gnus-article-add-button
7201 start end 'gnus-button-push
7202 (car (push (set-marker (make-marker) from)
7203 gnus-button-marker-list))))))))))
7205 ;; Add buttons to the head of an article.
7206 (defun gnus-article-add-buttons-to-head ()
7207 "Add buttons to the head of the article."
7209 (gnus-with-article-headers
7211 (dolist (entry gnus-header-button-alist)
7212 ;; Each alist entry.
7213 (goto-char (point-min))
7214 (while (re-search-forward (car entry) nil t)
7215 ;; Each header matching the entry.
7216 (setq beg (match-beginning 0))
7217 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7218 (match-beginning 0))
7221 (while (re-search-forward (eval (nth 1 entry)) end t)
7222 ;; Each match within a header.
7223 (let* ((entry (cdr entry))
7224 (start (match-beginning (nth 1 entry)))
7225 (end (match-end (nth 1 entry)))
7226 (form (nth 2 entry)))
7227 (goto-char (match-end 0))
7229 (gnus-article-add-button
7230 start end (nth 3 entry)
7231 (buffer-substring (match-beginning (nth 4 entry))
7232 (match-end (nth 4 entry)))))))
7233 (goto-char end))))))
7235 ;;; External functions:
7237 (defun gnus-article-add-button (from to fun &optional data)
7238 "Create a button between FROM and TO with callback FUN and data DATA."
7239 (when gnus-article-button-face
7240 (gnus-overlay-put (gnus-make-overlay from to)
7241 'face gnus-article-button-face))
7242 (gnus-add-text-properties
7244 (nconc (and gnus-article-mouse-face
7245 (list gnus-mouse-face-prop gnus-article-mouse-face))
7246 (list 'gnus-callback fun)
7247 (and data (list 'gnus-data data))))
7248 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7249 :button-keymap gnus-widget-button-keymap))
7251 ;;; Internal functions:
7253 (defun gnus-article-set-globals ()
7254 (with-current-buffer gnus-summary-buffer
7255 (gnus-set-global-variables)))
7257 (defun gnus-signature-toggle (end)
7258 (gnus-with-article-buffer
7259 (let ((inhibit-point-motion-hooks t))
7260 (if (text-property-any end (point-max) 'article-type 'signature)
7262 (gnus-delete-wash-type 'signature)
7263 (gnus-remove-text-properties-when
7264 'article-type 'signature end (point-max)
7265 (cons 'article-type (cons 'signature
7266 gnus-hidden-properties))))
7267 (gnus-add-wash-type 'signature)
7268 (gnus-add-text-properties-when
7269 'article-type nil end (point-max)
7270 (cons 'article-type (cons 'signature
7271 gnus-hidden-properties)))))
7272 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7273 (gnus-set-mode-line 'article))))
7275 (defun gnus-button-entry ()
7276 ;; Return the first entry in `gnus-button-alist' matching this place.
7277 (let ((alist gnus-button-alist)
7280 (setq entry (pop alist))
7281 (if (looking-at (eval (car entry)))
7286 (defun gnus-button-push (marker)
7287 ;; Push button starting at MARKER.
7290 (let* ((entry (gnus-button-entry))
7291 (inhibit-point-motion-hooks t)
7293 (args (mapcar (lambda (group)
7294 (let ((string (match-string group)))
7295 (set-text-properties
7296 0 (length string) nil string)
7303 (fboundp (symbol-value fun)))
7304 (apply (symbol-value fun) args))
7306 (gnus-message 1 "You must define `%S' to use this button"
7307 (cons fun args)))))))
7309 (defun gnus-parse-news-url (url)
7310 (let (scheme server port group message-id articles)
7313 (goto-char (point-min))
7314 (when (looking-at "\\([A-Za-z]+\\):")
7315 (setq scheme (match-string 1))
7316 (goto-char (match-end 0)))
7317 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7318 (setq server (match-string 1))
7319 (setq port (if (stringp (match-string 3))
7320 (string-to-number (match-string 3))
7322 (goto-char (match-end 0)))
7325 ((looking-at "\\(.*@.*\\)")
7326 (setq message-id (match-string 1)))
7327 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7328 (setq group (match-string 1)
7329 articles (split-string (match-string 2) "-")))
7330 ((looking-at "\\([^/]+\\)/?")
7331 (setq group (match-string 1)))
7333 (error "Unknown news URL syntax"))))
7334 (list scheme server port group message-id articles)))
7336 (defun gnus-button-handle-news (url)
7338 (destructuring-bind (scheme server port group message-id articles)
7339 (gnus-parse-news-url url)
7343 (set-buffer gnus-summary-buffer)
7345 (let ((gnus-refer-article-method
7346 (nconc (list (list 'nntp server))
7347 gnus-refer-article-method))
7348 (nntp-port-number (or port "nntp")))
7349 (gnus-message 7 "Fetching %s with %s"
7350 message-id gnus-refer-article-method)
7351 (gnus-summary-refer-article message-id))
7352 (gnus-summary-refer-article message-id))))
7354 (gnus-button-fetch-group url)))))
7356 (defun gnus-button-patch (library line)
7357 "Visit an Emacs Lisp library LIBRARY on line LINE."
7359 (let ((file (locate-library (file-name-nondirectory library))))
7361 (error "Couldn't find library %s" library))
7363 (goto-line (string-to-number line))))
7365 (defun gnus-button-handle-man (url)
7367 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7368 (when (eq gnus-button-man-handler 'woman)
7369 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7370 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7371 (funcall gnus-button-man-handler url))
7373 (defun gnus-button-handle-info-url (url)
7374 "Fetch an info URL."
7375 (setq url (mm-subst-char-in-string ?+ ?\ url))
7377 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7378 (gnus-info-find-node
7379 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7381 ")" (gnus-url-unhex-string (match-string 2 url)))))
7382 ((string-match "([^)\"]+)[^\"]+" url)
7384 (gnus-replace-in-string
7385 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7386 (gnus-info-find-node url))
7387 (t (error "Can't parse %s" url))))
7389 (defun gnus-button-handle-info-url-gnome (url)
7390 "Fetch GNOME style info URL."
7391 (setq url (mm-subst-char-in-string ?_ ?\ url))
7392 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7393 (gnus-info-find-node
7395 (gnus-url-unhex-string
7396 (match-string 1 url))
7398 (or (gnus-url-unhex-string
7399 (match-string 2 url))
7401 (error "Can't parse %s" url)))
7403 (defun gnus-button-handle-info-url-kde (url)
7404 "Fetch KDE style info URL."
7405 (gnus-info-find-node (gnus-url-unhex-string url)))
7407 (defun gnus-button-handle-info-keystrokes (url)
7408 "Call `info' when pushing the corresponding URL button."
7409 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7414 (defun gnus-button-openpgp (url)
7415 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7417 (mm-url-insert-file-contents-external url)
7418 (pgg-snarf-keys-region (point-min) (point-max))
7419 (pgg-display-output-buffer nil nil nil)))
7421 (defun gnus-button-message-id (message-id)
7423 (with-current-buffer gnus-summary-buffer
7424 (gnus-summary-refer-article message-id)))
7426 (defun gnus-button-fetch-group (address &rest ignore)
7427 "Fetch GROUP specified by ADDRESS."
7428 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7430 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7431 ;; for nntp:// and news://
7432 (setq address (match-string 3 address)))
7433 (if (not (string-match "[:/]" address))
7434 ;; This is just a simple group url.
7435 (gnus-group-read-ephemeral-group address gnus-select-method)
7438 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7440 (error "Can't parse %s" address)
7441 (gnus-group-read-ephemeral-group
7442 (match-string 4 address)
7443 `(nntp ,(match-string 1 address)
7444 (nntp-address ,(match-string 1 address))
7445 (nntp-port-number ,(if (match-end 3)
7446 (match-string 3 address)
7449 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7451 (defun gnus-url-parse-query-string (query &optional downcase)
7452 (let (retval pairs cur key val)
7453 (setq pairs (split-string query "&"))
7455 (setq cur (car pairs)
7457 (if (not (string-match "=" cur))
7459 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7460 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7462 (setq key (downcase key)))
7463 (setq cur (assoc key retval))
7465 (setcdr cur (cons val (cdr cur)))
7466 (setq retval (cons (list key val) retval)))))
7469 (defun gnus-url-mailto (url)
7470 ;; Send mail to someone
7471 (when (string-match "mailto:/*\\(.*\\)" url)
7472 (setq url (substring url (match-beginning 1) nil)))
7473 (let (to args subject func)
7474 (setq args (gnus-url-parse-query-string
7475 (if (string-match "^\\?" url)
7477 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7478 (concat "to=" (match-string 1 url) "&"
7479 (match-string 2 url))
7480 (concat "to=" url)))
7482 subject (cdr-safe (assoc "subject" args)))
7485 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7488 (message-position-on-field (caar args)))
7489 (insert (gnus-replace-in-string
7490 (mapconcat 'identity (reverse (cdar args)) ", ")
7492 (setq args (cdr args)))
7495 (message-goto-subject))))
7497 (defun gnus-button-embedded-url (address)
7498 "Activate ADDRESS with `browse-url'."
7499 (browse-url (gnus-strip-whitespace address)))
7501 ;;; Next/prev buttons in the article buffer.
7503 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7504 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7506 (defvar gnus-prev-page-map
7507 (let ((map (make-sparse-keymap)))
7508 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7509 (define-key map "\r" 'gnus-button-prev-page)
7512 (defvar gnus-next-page-map
7513 (let ((map (make-sparse-keymap)))
7514 (unless (>= emacs-major-version 21)
7515 ;; XEmacs doesn't care.
7516 (set-keymap-parent map gnus-article-mode-map))
7517 (define-key map gnus-mouse-2 'gnus-button-next-page)
7518 (define-key map "\r" 'gnus-button-next-page)
7521 (defun gnus-insert-prev-page-button ()
7523 (inhibit-read-only t))
7525 gnus-prev-page-line-format nil
7526 `(keymap ,gnus-prev-page-map
7528 gnus-callback gnus-article-button-prev-page
7529 article-type annotation))
7531 ;; Exclude a newline.
7534 (when gnus-article-button-face
7535 (gnus-overlay-put (gnus-make-overlay b e)
7536 'face gnus-article-button-face))
7537 (widget-convert-button
7539 :action 'gnus-button-prev-page
7540 :button-keymap gnus-prev-page-map)))
7542 (defun gnus-button-next-page (&optional args more-args)
7543 "Go to the next page."
7545 (let ((win (selected-window)))
7546 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7547 (gnus-article-next-page)
7548 (select-window win)))
7550 (defun gnus-button-prev-page (&optional args more-args)
7551 "Go to the prev page."
7553 (let ((win (selected-window)))
7554 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7555 (gnus-article-prev-page)
7556 (select-window win)))
7558 (defun gnus-insert-next-page-button ()
7560 (inhibit-read-only t))
7561 (gnus-eval-format gnus-next-page-line-format nil
7562 `(keymap ,gnus-next-page-map
7564 gnus-callback gnus-article-button-next-page
7565 article-type annotation))
7567 ;; Exclude a newline.
7570 (when gnus-article-button-face
7571 (gnus-overlay-put (gnus-make-overlay b e)
7572 'face gnus-article-button-face))
7573 (widget-convert-button
7575 :action 'gnus-button-next-page
7576 :button-keymap gnus-next-page-map)))
7578 (defun gnus-article-button-next-page (arg)
7579 "Go to the next page."
7581 (let ((win (selected-window)))
7582 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7583 (gnus-article-next-page)
7584 (select-window win)))
7586 (defun gnus-article-button-prev-page (arg)
7587 "Go to the prev page."
7589 (let ((win (selected-window)))
7590 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7591 (gnus-article-prev-page)
7592 (select-window win)))
7594 (defvar gnus-decode-header-methods
7595 '(mail-decode-encoded-word-region)
7596 "List of methods used to decode headers.
7598 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7599 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
7600 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7601 whose names match REGEXP.
7604 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7605 mail-decode-encoded-word-region
7606 (\"chinese\" . rfc1843-decode-region))
7609 (defvar gnus-decode-header-methods-cache nil)
7611 (defun gnus-multi-decode-header (start end)
7612 "Apply the functions from `gnus-encoded-word-methods' that match."
7613 (unless (and gnus-decode-header-methods-cache
7614 (eq gnus-newsgroup-name
7615 (car gnus-decode-header-methods-cache)))
7616 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7619 (nconc gnus-decode-header-methods-cache (list x))
7620 (if (and gnus-newsgroup-name
7621 (string-match (car x) gnus-newsgroup-name))
7622 (nconc gnus-decode-header-methods-cache
7624 gnus-decode-header-methods))
7625 (let ((xlist gnus-decode-header-methods-cache))
7628 (narrow-to-region start end)
7630 (funcall (pop xlist) (point-min) (point-max))))))
7633 ;;; Treatment top-level handling.
7636 (defun gnus-treat-article (condition &optional part-number total-parts type)
7637 (let ((length (- (point-max) (point-min)))
7638 (alist gnus-treatment-function-alist)
7639 (article-goto-body-goes-to-point-min-p t)
7643 (let ((list gnus-article-treat-types))
7645 (when (string-match (pop list) type)
7646 (throw 'found t)))))))
7647 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7649 (gnus-run-hooks 'gnus-part-display-hook)
7650 (dolist (elem alist)
7653 (when (gnus-buffer-live-p gnus-summary-buffer)
7654 (set-buffer gnus-summary-buffer))
7655 (symbol-value (car elem))))
7656 (when (and (or (consp val)
7658 (gnus-treat-predicate val)
7659 (or (not (get (car elem) 'highlight))
7662 (funcall (cadr elem)))))))
7664 ;; Dynamic variables.
7666 (defvar part-number)
7667 (defvar total-parts)
7672 (defun gnus-treat-predicate (val)
7679 (stringp (car val)))
7680 (apply 'gnus-or (mapcar `(lambda (s)
7681 (string-match s ,(or gnus-newsgroup-name "")))
7684 (let ((pred (pop val)))
7687 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7689 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7691 (not (gnus-treat-predicate (car val))))
7693 (equal (car val) type))
7695 (error "%S is not a valid predicate" pred)))))
7703 (eq part-number total-parts))
7707 (error "%S is not a valid value" val))))
7709 (defun gnus-article-encrypt-body (protocol &optional n)
7710 "Encrypt the article body."
7713 (or gnus-article-encrypt-protocol
7714 (completing-read "Encrypt protocol: "
7715 gnus-article-encrypt-protocol-alist
7717 current-prefix-arg))
7718 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7720 (error "Can't find the encrypt protocol %s" protocol))
7721 (if (member gnus-newsgroup-name '("nndraft:delayed"
7724 (error "Can't encrypt the article in group %s"
7725 gnus-newsgroup-name))
7726 (gnus-summary-iterate n
7728 (set-buffer gnus-summary-buffer)
7729 (let ((mail-parse-charset gnus-newsgroup-charset)
7730 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7731 (summary-buffer gnus-summary-buffer)
7733 (gnus-set-global-variables)
7734 (when (gnus-group-read-only-p)
7735 (error "The current newsgroup does not support article encrypt"))
7736 (gnus-summary-show-article t)
7738 (or (mail-header-references gnus-current-headers) ""))
7739 (set-buffer gnus-article-buffer)
7740 (let* ((inhibit-read-only t)
7742 (mapcar (lambda (field)
7743 (and (save-restriction
7744 (message-narrow-to-head)
7745 (goto-char (point-min))
7746 (search-forward field nil t))
7748 (message-narrow-to-field)
7750 (delete-region (point-min) (point-max))
7752 '("Content-Type:" "Content-Transfer-Encoding:"
7753 "Content-Disposition:"))))
7754 (message-narrow-to-head)
7755 (message-remove-header "MIME-Version")
7756 (goto-char (point-max))
7757 (setq point (point))
7758 (insert (apply 'concat headers))
7760 (narrow-to-region point (point-max))
7761 (let ((message-options message-options))
7762 (message-options-set 'message-sender user-mail-address)
7763 (message-options-set 'message-recipients user-mail-address)
7764 (message-options-set 'message-sign-encrypt 'not)
7766 (goto-char (point-min))
7767 (insert "MIME-Version: 1.0\n")
7769 (gnus-summary-edit-article-done
7770 references nil summary-buffer t))
7771 (when gnus-keep-backlog
7772 (gnus-backlog-remove-article
7773 (car gnus-article-current) (cdr gnus-article-current)))
7775 (when (get-buffer gnus-original-article-buffer)
7776 (set-buffer gnus-original-article-buffer)
7777 (setq gnus-original-article nil)))
7778 (when gnus-use-cache
7779 (gnus-cache-update-article
7780 (car gnus-article-current) (cdr gnus-article-current))))))))
7782 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7783 "The following specs can be used:
7784 %t The security MIME type
7787 %D Details if button is pressed")
7789 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7790 "The following specs can be used:
7791 %t The security MIME type
7794 %D Details if button is pressed")
7796 (defvar gnus-mime-security-button-line-format-alist
7797 '((?t gnus-tmp-type ?s)
7798 (?i gnus-tmp-info ?s)
7799 (?d gnus-tmp-details ?s)
7800 (?D gnus-tmp-pressed-details ?s)))
7802 (defvar gnus-mime-security-button-commands
7803 '((gnus-article-press-button "\r" "Show Detail")
7807 (gnus-mime-security-save-part "o" "Save...")
7816 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
7819 (defvar gnus-mime-security-button-map
7820 (let ((map (make-sparse-keymap)))
7821 (define-key map gnus-mouse-2 'gnus-article-push-button)
7822 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
7823 (dolist (c gnus-mime-security-button-commands)
7824 (define-key map (cadr c) (car c)))
7828 gnus-mime-security-button-menu gnus-mime-security-button-map
7829 "Security button menu."
7833 (unless (eq (car c) 'undefined)
7834 (vector (caddr c) (car c) :active t)))
7835 gnus-mime-security-button-commands))))
7837 (defun gnus-mime-security-button-menu (event prefix)
7838 "Construct a context-sensitive menu of security commands."
7839 (interactive "e\nP")
7840 (save-window-excursion
7841 (let ((pos (event-start event)))
7842 (select-window (posn-window pos))
7843 (goto-char (posn-point pos))
7844 (gnus-article-check-buffer)
7845 (popup-menu gnus-mime-security-button-menu nil prefix))))
7847 (defvar gnus-mime-security-details-buffer nil)
7849 (defvar gnus-mime-security-button-pressed nil)
7851 (defvar gnus-mime-security-show-details-inline t
7852 "If non-nil, show details in the article buffer.")
7854 (defun gnus-mime-security-verify-or-decrypt (handle)
7855 (mm-remove-parts (cdr handle))
7856 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7857 point (inhibit-read-only t))
7859 (goto-char (car region)))
7861 (narrow-to-region (point) (point))
7862 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7863 (let* ((mm-verify-option 'known)
7864 (mm-decrypt-option 'known)
7865 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7866 (unless (eq nparts (cdr handle))
7867 (mm-destroy-parts (cdr handle))
7868 (setcdr handle nparts))))
7869 (setq point (point))
7870 (gnus-mime-display-security handle)
7871 (goto-char (point-max)))
7873 (delete-region (point) (cdr region))
7874 (set-marker (car region) nil)
7875 (set-marker (cdr region) nil))
7878 (defun gnus-mime-security-show-details (handle)
7879 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7881 (gnus-message 5 "No details.")
7882 (if gnus-mime-security-show-details-inline
7883 (let ((gnus-mime-security-button-pressed
7884 (not (get-text-property (point) 'gnus-mime-details)))
7885 (gnus-mime-security-button-line-format
7886 (get-text-property (point) 'gnus-line-format))
7887 (inhibit-read-only t))
7889 (while (eq (get-text-property (point) 'gnus-line-format)
7890 gnus-mime-security-button-line-format)
7894 (narrow-to-region (point) (point))
7895 (gnus-insert-mime-security-button handle))
7896 (delete-region (point)
7897 (or (text-property-not-all
7900 gnus-mime-security-button-line-format)
7903 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7904 (with-current-buffer gnus-mime-security-details-buffer
7907 (setq gnus-mime-security-details-buffer
7908 (gnus-get-buffer-create "*MIME Security Details*")))
7909 (with-current-buffer gnus-mime-security-details-buffer
7911 (goto-char (point-min)))
7912 (pop-to-buffer gnus-mime-security-details-buffer)))))
7914 (defun gnus-mime-security-press-button (handle)
7916 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7917 (gnus-mime-security-show-details handle)
7918 (gnus-mime-security-verify-or-decrypt handle))))
7920 (defun gnus-insert-mime-security-button (handle &optional displayed)
7921 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7924 (or (nth 2 (assoc protocol mm-verify-function-alist))
7925 (nth 2 (assoc protocol mm-decrypt-function-alist))
7927 (if (equal (car handle) "multipart/signed")
7928 " Signed" " Encrypted")
7931 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7934 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7935 gnus-tmp-pressed-details
7937 (setq gnus-tmp-details
7938 (if gnus-tmp-details
7939 (concat "\n" gnus-tmp-details)
7941 (setq gnus-tmp-pressed-details
7942 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7947 gnus-mime-security-button-line-format
7948 gnus-mime-security-button-line-format-alist
7949 `(keymap ,gnus-mime-security-button-map
7950 gnus-callback gnus-mime-security-press-button
7951 gnus-line-format ,gnus-mime-security-button-line-format
7952 gnus-mime-details ,gnus-mime-security-button-pressed
7953 article-type annotation
7956 ;; Exclude a newline.
7959 (when gnus-article-button-face
7960 (gnus-overlay-put (gnus-make-overlay b e)
7961 'face gnus-article-button-face))
7962 (widget-convert-button
7965 :action 'gnus-widget-press-button
7966 :button-keymap gnus-mime-security-button-map
7968 (lambda (widget/window &optional overlay pos)
7969 ;; Needed to properly clear the message due to a bug in
7970 ;; wid-edit (XEmacs only).
7971 (when (boundp 'help-echo-owns-message)
7972 (setq help-echo-owns-message t))
7974 "%S: show detail; %S: more options"
7975 (aref gnus-mouse-2 0)
7976 (aref gnus-down-mouse-3 0))))))
7978 (defun gnus-mime-display-security (handle)
7980 (narrow-to-region (point) (point))
7981 (unless (gnus-unbuttonized-mime-type-p (car handle))
7982 (gnus-insert-mime-security-button handle))
7983 (gnus-mime-display-part (cadr handle))
7986 (unless (gnus-unbuttonized-mime-type-p (car handle))
7987 (let ((gnus-mime-security-button-line-format
7988 gnus-mime-security-button-end-line-format))
7989 (gnus-insert-mime-security-button handle)))
7990 (mm-set-handle-multipart-parameter
7992 (cons (set-marker (make-marker) (point-min))
7993 (set-marker (make-marker) (point-max))))))
7995 (defun gnus-mime-security-run-function (function)
7996 "Run FUNCTION with the security part under point."
7997 (gnus-article-check-buffer)
7998 (let ((data (get-text-property (point) 'gnus-data))
8000 (when (and (stringp (car-safe data))
8001 (setq buffer (mm-handle-multipart-original-buffer data))
8002 (setq handle (cadr data)))
8003 (if (bufferp (mm-handle-buffer handle))
8005 (setq handle (cons buffer (copy-sequence (cdr handle))))
8006 (mm-handle-set-undisplayer handle nil))
8007 (setq handle (mm-make-handle
8009 (mm-handle-multipart-ctl-parameter handle 'protocol)
8010 nil nil nil nil nil nil)))
8011 (funcall function handle))))
8013 (defun gnus-mime-security-save-part ()
8014 "Save the security part under point."
8016 (gnus-mime-security-run-function 'mm-save-part))
8018 (defun gnus-mime-security-pipe-part ()
8019 "Pipe the security part under point to a process."
8021 (gnus-mime-security-run-function 'mm-pipe-part))
8027 (run-hooks 'gnus-art-load-hook)
8029 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8030 ;;; gnus-art.el ends here