1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 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 3, 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.
32 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
36 (defvar w3m-minor-mode-map)
39 ;; Avoid the "Recursive load suspected" error in Emacs 21.1.
41 (let ((recursive-load-depth-limit 100))
54 (autoload 'gnus-msg-mail "gnus-msg" nil t)
55 (autoload 'gnus-button-mailto "gnus-msg")
56 (autoload 'gnus-button-reply "gnus-msg" nil t)
57 (autoload 'parse-time-string "parse-time" nil nil)
58 (autoload 'ansi-color-apply-on-region "ansi-color")
59 (autoload 'mm-url-insert-file-contents-external "mm-url")
60 (autoload 'mm-extern-cache-contents "mm-extern")
62 (defgroup gnus-article nil
64 :link '(custom-manual "(gnus)Article Buffer")
67 (defgroup gnus-article-treat nil
68 "Treating article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-hiding nil
73 "Hiding article parts."
74 :link '(custom-manual "(gnus)Article Hiding")
77 (defgroup gnus-article-highlight nil
78 "Article highlighting."
79 :link '(custom-manual "(gnus)Article Highlighting")
83 (defgroup gnus-article-signature nil
85 :link '(custom-manual "(gnus)Article Signature")
88 (defgroup gnus-article-headers nil
90 :link '(custom-manual "(gnus)Hiding Headers")
93 (defgroup gnus-article-washing nil
94 "Special commands on articles."
95 :link '(custom-manual "(gnus)Article Washing")
98 (defgroup gnus-article-emphasis nil
99 "Fontisizing articles."
100 :link '(custom-manual "(gnus)Article Fontisizing")
101 :group 'gnus-article)
103 (defgroup gnus-article-saving nil
105 :link '(custom-manual "(gnus)Saving Articles")
106 :group 'gnus-article)
108 (defgroup gnus-article-mime nil
109 "Worshiping the MIME wonder."
110 :link '(custom-manual "(gnus)Using MIME")
111 :group 'gnus-article)
113 (defgroup gnus-article-buttons nil
114 "Pushable buttons in the article buffer."
115 :link '(custom-manual "(gnus)Article Buttons")
116 :group 'gnus-article)
118 (defgroup gnus-article-various nil
119 "Other article options."
120 :link '(custom-manual "(gnus)Misc Article")
121 :group 'gnus-article)
123 (defcustom gnus-ignored-headers
126 (concat "^" header ":"))
127 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
128 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
129 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
130 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
131 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
132 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
133 "X-Attribution" "X-Originating-IP" "Delivered-To"
134 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
135 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
136 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
137 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
138 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
139 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
140 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
141 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
142 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
143 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
144 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
145 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
146 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
147 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
148 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
149 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
150 "List-[A-Za-z]+" "X-Listprocessor-Version"
151 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
152 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
153 "X-Received" "Content-length" "X-precedence"
154 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
155 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
156 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
157 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
158 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
159 "X-Content-length" "X-Posting-Agent" "Original-Received"
160 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
161 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
162 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
163 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
164 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
165 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
166 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
167 "Envelope-Sender" "Envelope-Recipients"))
168 "*All headers that start with this regexp will be hidden.
169 This variable can also be a list of regexps of headers to be ignored.
170 If `gnus-visible-headers' is non-nil, this variable will be ignored."
171 :type '(choice :custom-show nil
174 :group 'gnus-article-hiding)
176 (defcustom gnus-visible-headers
177 "^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:"
178 "*All headers that do not match this regexp will be hidden.
179 This variable can also be a list of regexp of headers to remain visible.
180 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181 :type '(repeat :value-to-internal (lambda (widget value)
182 (custom-split-regexp-maybe value))
183 :match (lambda (widget value)
185 (widget-editable-list-match widget value)))
187 :group 'gnus-article-hiding)
189 (defcustom gnus-sorted-header-list
190 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
192 "*This variable is a list of regular expressions.
193 If it is non-nil, headers that match the regular expressions will
194 be placed first in the article buffer in the sequence specified by
196 :type '(repeat regexp)
197 :group 'gnus-article-hiding)
199 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200 "Headers that are only to be displayed if they have interesting data.
201 Possible values in this list are:
203 'empty Headers with no content.
204 'newsgroups Newsgroup identical to Gnus group.
205 'to-address To identical to To-address.
206 'to-list To identical to To-list.
207 'cc-list CC identical to To-list.
208 'followup-to Followup-to identical to Newsgroups.
209 'reply-to Reply-to identical to From.
210 'date Date less than four days old.
211 'long-to To and/or Cc longer than 1024 characters.
212 'many-to Multiple To and/or Cc."
213 :type '(set (const :tag "Headers with no content." empty)
214 (const :tag "Newsgroups identical to Gnus group." newsgroups)
215 (const :tag "To identical to To-address." to-address)
216 (const :tag "To identical to To-list." to-list)
217 (const :tag "CC identical to To-list." cc-list)
218 (const :tag "Followup-to identical to Newsgroups." followup-to)
219 (const :tag "Reply-to identical to From." reply-to)
220 (const :tag "Date less than four days old." date)
221 (const :tag "To and/or Cc longer than 1024 characters." long-to)
222 (const :tag "Multiple To and/or Cc headers." many-to))
223 :group 'gnus-article-hiding)
225 (defcustom gnus-article-skip-boring nil
226 "Skip over text that is not worth reading.
227 By default, if you set this t, then Gnus will display citations and
228 signatures, but will never scroll down to show you a page consisting
229 only of boring text. Boring text is controlled by
230 `gnus-article-boring-faces'."
233 :group 'gnus-article-hiding)
235 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
236 "Regexp matching signature separator.
237 This can also be a list of regexps. In that case, it will be checked
238 from head to tail looking for a separator. Searches will be done from
239 the end of the buffer."
240 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
242 (repeat :tag "List of regexp" regexp))
243 :group 'gnus-article-signature)
245 (defcustom gnus-signature-limit nil
246 "Provide a limit to what is considered a signature.
247 If it is a number, no signature may not be longer (in characters) than
248 that number. If it is a floating point number, no signature may be
249 longer (in lines) than that number. If it is a function, the function
250 will be called without any parameters, and if it returns nil, there is
251 no signature in the buffer. If it is a string, it will be used as a
252 regexp. If it matches, the text in question is not a signature.
254 This can also be a list of the above values."
255 :type '(choice (const nil)
259 (regexp :value ".*"))
260 :group 'gnus-article-signature)
262 (defcustom gnus-hidden-properties '(invisible t intangible t)
263 "Property list to use for hiding text."
265 :group 'gnus-article-hiding)
267 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
268 ;; frames in a session.
269 (defcustom gnus-article-x-face-command
270 (if (featurep 'xemacs)
271 (if (or (gnus-image-type-available-p 'xface)
272 (gnus-image-type-available-p 'pbm))
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
275 (if (gnus-image-type-available-p 'pbm)
276 'gnus-display-x-face-in-from
277 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
279 "*String or function to be executed to display an X-Face header.
280 If it is a string, the command will be executed in a sub-shell
281 asynchronously. The compressed face will be piped to this command."
282 :type `(choice string
283 (function-item gnus-display-x-face-in-from)
287 :group 'gnus-article-washing)
289 (defcustom gnus-article-x-face-too-ugly nil
290 "Regexp matching posters whose face shouldn't be shown automatically."
291 :type '(choice regexp (const nil))
292 :group 'gnus-article-washing)
294 (defcustom gnus-article-banner-alist nil
295 "Banner alist for stripping.
297 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
299 :type '(repeat (cons symbol regexp))
300 :group 'gnus-article-washing)
302 (gnus-define-group-parameter
305 "Alist of regexps (to match group names) and banner."
306 :variable-group gnus-article-washing
308 '(choice :tag "Banner"
310 (const :tag "Remove signature" signature)
311 (symbol :tag "Item in `gnus-article-banner-alist'" none)
313 (const :tag "None" nil))
315 "If non-nil, specify how to remove `banners' from articles.
317 Symbol `signature' means to remove signatures delimited by
318 `gnus-signature-separator'. Any other symbol is used to look up a
319 regular expression to match the banner in `gnus-article-banner-alist'.
320 A string is used as a regular expression to match the banner
323 (defcustom gnus-article-address-banner-alist nil
324 "Alist of mail addresses and banners.
325 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
326 to match a mail address in the From: header, BANNER is one of a symbol
327 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
328 If ADDRESS matches author's mail address, it will remove things like
329 advertisements. For example:
331 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
335 (regexp :tag "Address")
336 (choice :tag "Banner" :value nil
337 (const :tag "Remove signature" signature)
338 (symbol :tag "Item in `gnus-article-banner-alist'" none)
340 (const :tag "None" nil))))
342 :group 'gnus-article-washing)
344 (defmacro gnus-emphasis-custom-with-format (&rest body)
346 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
347 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
350 (defun gnus-emphasis-custom-value-to-external (value)
351 (gnus-emphasis-custom-with-format
352 (if (consp (car value))
353 (list (format format (car (car value)) (cdr (car value)))
355 (if (nth 1 value) 2 3)
359 (defun gnus-emphasis-custom-value-to-internal (value)
360 (gnus-emphasis-custom-with-format
361 (let ((regexp (concat "\\`"
362 (format (regexp-quote format)
363 "\\([^()]+\\)" "\\([^()]+\\)")
366 (if (string-match regexp (setq pattern (car value)))
367 (list (cons (match-string 1 pattern) (match-string 2 pattern))
372 (defcustom gnus-emphasis-alist
374 '(("\\*" "\\*" bold nil 2)
377 ("_/" "/_" underline-italic)
378 ("_\\*" "\\*_" underline-bold)
379 ("\\*/" "/\\*" bold-italic)
380 ("_\\*/" "/\\*_" underline-bold-italic))))
382 (gnus-emphasis-custom-with-format
383 (mapcar (lambda (spec)
384 (list (format format (car spec) (cadr spec))
387 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
389 '(;; I've never seen anyone use this strikethru convention whereas I've
390 ;; several times seen it triggered by normal text. --Stef
391 ;; Miles suggests that this form is sometimes used but for italics,
392 ;; so maybe we should map it to `italic'.
393 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
394 ;; 2 3 gnus-emphasis-strikethru)
395 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
396 2 3 gnus-emphasis-underline))))
397 "*Alist that says how to fontify certain phrases.
398 Each item looks like this:
400 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
402 The first element is a regular expression to be matched. The second
403 is a number that says what regular expression grouping used to find
404 the entire emphasized word. The third is a number that says what
405 regexp grouping should be displayed and highlighted. The fourth
406 is the face used for highlighting."
410 :format "%[Customizing Style%]\n%v"
412 (group :tag "Default"
413 :value ("" 0 0 default)
416 (let ((value (widget-get
417 (cadr (widget-get (widget-get widget :parent)
420 (if (not (eq (nth 2 value) 'default))
424 (gnus-emphasis-custom-value-to-external value))))
425 (widget-group-value-create widget))
427 (integer :format "Match group: %v")
428 (integer :format "Emphasize group: %v")
431 :value (("_" . "_") nil default)
433 (regexp :format "Start regexp: %v")
434 (regexp :format "End regexp: %v"))
435 (boolean :format "Show start and end patterns: %[%v%]\n"
436 :on " On " :off " Off ")
438 :get (lambda (symbol)
439 (mapcar 'gnus-emphasis-custom-value-to-internal
440 (default-value symbol)))
441 :set (lambda (symbol value)
442 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
444 :group 'gnus-article-emphasis)
446 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
447 "A regexp to describe whitespace which should not be emphasized.
448 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
449 The former avoids underlining of leading and trailing whitespace,
450 and the latter avoids underlining any whitespace at all."
452 :group 'gnus-article-emphasis
455 (defface gnus-emphasis-bold '((t (:bold t)))
456 "Face used for displaying strong emphasized text (*word*)."
457 :group 'gnus-article-emphasis)
459 (defface gnus-emphasis-italic '((t (:italic t)))
460 "Face used for displaying italic emphasized text (/word/)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-underline '((t (:underline t)))
464 "Face used for displaying underlined emphasized text (_word_)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
468 "Face used for displaying underlined bold emphasized text (_*word*_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
472 "Face used for displaying underlined italic emphasized text (_/word/_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
476 "Face used for displaying bold italic emphasized text (/*word*/)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-underline-bold-italic
480 '((t (:bold t :italic t :underline t)))
481 "Face used for displaying underlined bold italic emphasized text.
482 Example: (_/*word*/_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
486 '((t (:strikethru t)))
487 '((t (:strike-through t))))
488 "Face used for displaying strike-through text (-word-)."
489 :group 'gnus-article-emphasis)
491 (defface gnus-emphasis-highlight-words
492 '((t (:background "black" :foreground "yellow")))
493 "Face used for displaying highlighted words."
494 :group 'gnus-article-emphasis)
496 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
497 "Format for display of Date headers in article bodies.
498 See `format-time-string' for the possible values.
500 The variable can also be function, which should return a complete Date
501 header. The function is called with one argument, the time, which can
502 be fed to `format-time-string'."
503 :type '(choice string function)
504 :link '(custom-manual "(gnus)Article Date")
505 :group 'gnus-article-washing)
507 (defcustom gnus-save-all-headers t
508 "*If non-nil, don't remove any headers before saving.
509 This will be overridden by the `:headers' property that the symbol of
510 the saver function, which is specified by `gnus-default-article-saver',
512 :group 'gnus-article-saving
515 (defcustom gnus-prompt-before-saving 'always
516 "*This variable says how much prompting is to be done when saving articles.
517 If it is nil, no prompting will be done, and the articles will be
518 saved to the default files. If this variable is `always', each and
519 every article that is saved will be preceded by a prompt, even when
520 saving large batches of articles. If this variable is neither nil not
521 `always', there the user will be prompted once for a file name for
522 each invocation of the saving commands."
523 :group 'gnus-article-saving
524 :type '(choice (item always)
525 (item :tag "never" nil)
526 (sexp :tag "once" :format "%t\n" :value t)))
528 (defcustom gnus-saved-headers gnus-visible-headers
529 "Headers to keep if `gnus-save-all-headers' is nil.
530 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
531 If that variable is nil, however, all headers that match this regexp
532 will be kept while the rest will be deleted before saving. This and
533 `gnus-save-all-headers' will be overridden by the `:headers' property
534 that the symbol of the saver function, which is specified by
535 `gnus-default-article-saver', might have."
536 :group 'gnus-article-saving
539 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
540 "A function to save articles in your favourite format.
541 The function will be called by way of the `gnus-summary-save-article'
542 command, and friends such as `gnus-summary-save-article-rmail'.
544 Gnus provides the following functions:
546 * gnus-summary-save-in-rmail (Rmail format)
547 * gnus-summary-save-in-mail (Unix mail format)
548 * gnus-summary-save-in-folder (MH folder)
549 * gnus-summary-save-in-file (article format)
550 * gnus-summary-save-body-in-file (article body)
551 * gnus-summary-save-in-vm (use VM's folder format)
552 * gnus-summary-write-to-file (article format -- overwrite)
553 * gnus-summary-write-body-to-file (article body -- overwrite)
555 The symbol of each function may have the following properties:
558 The value non-nil means save decoded articles. This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', and `gnus-summary-write-body-to-file'.
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
585 (defcustom gnus-article-save-coding-system
586 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
587 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
588 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
589 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
590 "Coding system used to save decoded articles to a file.
592 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
593 which can safely encode any characters in text. This is used by the
596 * gnus-summary-save-article-file
597 * gnus-summary-save-article-body-file
598 * gnus-summary-write-article-file
599 * gnus-summary-write-article-body-file
601 and the functions to which you may set `gnus-default-article-saver':
603 * gnus-summary-save-in-file
604 * gnus-summary-save-body-in-file
605 * gnus-summary-write-to-file
606 * gnus-summary-write-body-to-file
608 Those commands and functions save just text displayed in the article
609 buffer to a file if the value of this variable is non-nil. Note that
610 buttonized MIME parts will be lost in a saved file in that case.
611 Otherwise, raw articles will be saved."
612 :group 'gnus-article-saving
614 :format "%{%t%}:\n %[Value Menu%] %v"
615 (const :tag "Save raw articles" nil)
618 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
619 '((const :tag "UTF-8" utf-8)
620 (const :tag "iso-2022-7bit" iso-2022-7bit)
621 (const :tag "Emacs internal" emacs-mule)
622 (const :tag "escape-quoted" escape-quoted))))
623 (symbol :tag "Coding system")))
625 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
626 "A function generating a file name to save articles in Rmail format.
627 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
628 :group 'gnus-article-saving
631 (defcustom gnus-mail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Unix mail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
637 (defcustom gnus-folder-save-name 'gnus-folder-save-name
638 "A function generating a file name to save articles in MH folder.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
640 :group 'gnus-article-saving
643 (defcustom gnus-file-save-name 'gnus-numeric-save-name
644 "A function generating a file name to save articles in article format.
645 The function is called with NEWSGROUP, HEADERS, and optional
647 :group 'gnus-article-saving
650 (defcustom gnus-split-methods
651 '((gnus-article-archive-name)
652 (gnus-article-nndoc-name))
653 "*Variable used to suggest where articles are to be saved.
654 For instance, if you would like to save articles related to Gnus in
655 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
656 you could set this variable to something like:
658 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
659 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
661 This variable is an alist where the key is the match and the
662 value is a list of possible files to save in if the match is
665 If the match is a string, it is used as a regexp match on the
666 article. If the match is a symbol, that symbol will be funcalled
667 from the buffer of the article to be saved with the newsgroup as the
668 parameter. If it is a list, it will be evaled in the same buffer.
670 If this form or function returns a string, this string will be used as a
671 possible file name; and if it returns a non-nil list, that list will be
672 used as possible file names."
673 :group 'gnus-article-saving
674 :type '(repeat (choice (list :value (fun) function)
675 (cons :value ("" "") regexp (repeat string))
678 (defcustom gnus-page-delimiter "^\^L"
679 "*Regexp describing what to use as article page delimiters.
680 The default value is \"^\^L\", which is a form linefeed at the
681 beginning of a line."
683 :group 'gnus-article-various)
685 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
686 "*The format specification for the article mode line.
687 See `gnus-summary-mode-line-format' for a closer description.
689 The following additional specs are available:
691 %w The article washing status.
692 %m The number of MIME parts in the article."
694 :group 'gnus-article-various)
696 (defcustom gnus-article-mode-hook nil
697 "*A hook for Gnus article mode."
699 :group 'gnus-article-various)
701 (when (featurep 'xemacs)
702 ;; Extracted from gnus-xmas-define in order to preserve user settings
703 (when (fboundp 'turn-off-scroll-in-place)
704 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
705 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
706 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
708 (defcustom gnus-article-menu-hook nil
709 "*Hook run after the creation of the article mode menu."
711 :group 'gnus-article-various)
713 (defcustom gnus-article-prepare-hook nil
714 "*A hook called after an article has been prepared in the article buffer."
716 :group 'gnus-article-various)
718 (defcustom gnus-copy-article-ignored-headers nil
719 "List of headers to be removed when copying an article.
720 Each element is a regular expression."
721 :version "23.0" ;; No Gnus
722 :type '(repeat regexp)
723 :group 'gnus-article-various)
725 (make-obsolete-variable 'gnus-article-hide-pgp-hook
726 "This variable is obsolete in Gnus 5.10.")
729 '((t (:weight bold)))
730 "Face used for highlighting a button in the article buffer."
731 :group 'gnus-article-buttons)
733 (defcustom gnus-article-button-face 'gnus-button
734 "Face used for highlighting buttons in the article buffer.
736 An article button is a piece of text that you can activate by pressing
737 `RET' or `mouse-2' above it."
739 :group 'gnus-article-buttons)
741 (defcustom gnus-article-mouse-face 'highlight
742 "Face used for mouse highlighting in the article buffer.
744 Article buttons will be displayed in this face when the cursor is
747 :group 'gnus-article-buttons)
749 (defcustom gnus-signature-face 'gnus-signature
750 "Face used for highlighting a signature in the article buffer.
751 Obsolete; use the face `gnus-signature' for customizations instead."
753 :group 'gnus-article-highlight
754 :group 'gnus-article-signature)
756 (defface gnus-signature
759 "Face used for highlighting a signature in the article buffer."
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
762 ;; backward-compatibility alias
763 (put 'gnus-signature-face 'face-alias 'gnus-signature)
765 (defface gnus-header-from
768 (:foreground "PaleGreen1"))
771 (:foreground "red3"))
774 "Face used for displaying from headers."
775 :group 'gnus-article-headers
776 :group 'gnus-article-highlight)
777 ;; backward-compatibility alias
778 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
780 (defface gnus-header-subject
783 (:foreground "SeaGreen1"))
786 (:foreground "red4"))
788 (:bold t :italic t)))
789 "Face used for displaying subject headers."
790 :group 'gnus-article-headers
791 :group 'gnus-article-highlight)
792 ;; backward-compatibility alias
793 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
795 (defface gnus-header-newsgroups
798 (:foreground "yellow" :italic t))
801 (:foreground "MidnightBlue" :italic t))
804 "Face used for displaying newsgroups headers.
805 In the default setup this face is only used for crossposted
807 :group 'gnus-article-headers
808 :group 'gnus-article-highlight)
809 ;; backward-compatibility alias
810 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
812 (defface gnus-header-name
815 (:foreground "SpringGreen2"))
818 (:foreground "maroon"))
821 "Face used for displaying header names."
822 :group 'gnus-article-headers
823 :group 'gnus-article-highlight)
824 ;; backward-compatibility alias
825 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
827 (defface gnus-header-content
830 (:foreground "SpringGreen1" :italic t))
833 (:foreground "indianred4" :italic t))
835 (:italic t))) "Face used for displaying header content."
836 :group 'gnus-article-headers
837 :group 'gnus-article-highlight)
838 ;; backward-compatibility alias
839 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
841 (defcustom gnus-header-face-alist
842 '(("From" nil gnus-header-from)
843 ("Subject" nil gnus-header-subject)
844 ("Newsgroups:.*," nil gnus-header-newsgroups)
845 ("" gnus-header-name gnus-header-content))
846 "*Controls highlighting of article headers.
848 An alist of the form (HEADER NAME CONTENT).
850 HEADER is a regular expression which should match the name of a
851 header and NAME and CONTENT are either face names or nil.
853 The name of each header field will be displayed using the face
854 specified by the first element in the list where HEADER matches
855 the header name and NAME is non-nil. Similarly, the content will
856 be displayed by the first non-nil matching CONTENT face."
857 :group 'gnus-article-headers
858 :group 'gnus-article-highlight
859 :type '(repeat (list (regexp :tag "Header")
861 (item :tag "skip" nil)
862 (face :value default))
863 (choice :tag "Content"
864 (item :tag "skip" nil)
865 (face :value default)))))
867 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
868 '((xface . (:face gnus-x-face)))
869 '((pbm . (:face gnus-x-face))
871 "Alist of image types and properties applied to Face and X-Face images.
874 ;; Specify the altitude of Face images in the From header.
875 \(setq gnus-face-properties-alist
876 '((pbm . (:face gnus-x-face :ascent 80))
877 (png . (:ascent 80))))
879 ;; Show Face images as pressed buttons.
880 \(setq gnus-face-properties-alist
881 '((pbm . (:face gnus-x-face :relief -2))
882 (png . (:relief -2))))
884 See the manual for the valid properties for various image types.
885 Currently, `pbm' is used for X-Face images and `png' is used for Face
886 images in Emacs. Only the `:face' property is effective on the `xface'
887 image type in XEmacs if it is built with the libcompface library."
888 :version "23.0" ;; No Gnus
889 :group 'gnus-article-headers
890 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
892 (defcustom gnus-article-decode-hook
893 '(article-decode-charset article-decode-encoded-words
894 article-decode-group-name article-decode-idna-rhs)
895 "*Hook run to decode charsets in articles."
896 :group 'gnus-article-headers
899 (defcustom gnus-display-mime-function 'gnus-display-mime
900 "Function to display MIME articles."
901 :group 'gnus-article-mime
904 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
905 "Function used to decode headers.")
907 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
908 "Function used to decode addresses.")
910 (defvar gnus-article-dumbquotes-map
930 "Table for MS-to-Latin1 translation.")
932 (defcustom gnus-ignored-mime-types nil
933 "List of MIME types that should be ignored by Gnus."
935 :group 'gnus-article-mime
936 :type '(repeat regexp))
938 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
939 "List of MIME types that should not be given buttons when rendered inline.
940 See also `gnus-buttonized-mime-types' which may override this variable.
941 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-buttonized-mime-types nil
947 "List of MIME types that should be given buttons when rendered inline.
948 If set, this variable overrides `gnus-unbuttonized-mime-types'.
949 To see e.g. security buttons you could set this to
950 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
951 this list to display radio buttons that allow you to choose one of two
952 media types those mails include. See also `mm-discouraged-alternatives'.
953 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
955 :group 'gnus-article-mime
956 :type '(repeat regexp))
958 (defcustom gnus-inhibit-mime-unbuttonizing nil
959 "If non-nil, all MIME parts get buttons.
960 When nil (the default value), then some MIME parts do not get buttons,
961 as described by the variables `gnus-buttonized-mime-types' and
962 `gnus-unbuttonized-mime-types'."
964 :group 'gnus-article-mime
967 (defcustom gnus-body-boundary-delimiter "_"
968 "String used to delimit header and body.
969 This variable is used by `gnus-article-treat-body-boundary' which can
970 be controlled by `gnus-treat-body-boundary'."
972 :group 'gnus-article-various
973 :type '(choice (item :tag "None" :value nil)
976 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
978 "Defines the location of the faces database.
979 For information on obtaining this database of pretty pictures, please
980 see http://www.cs.indiana.edu/picons/ftp/index.html"
982 :type '(repeat directory)
983 :link '(url-link :tag "download"
984 "http://www.cs.indiana.edu/picons/ftp/index.html")
985 :link '(custom-manual "(gnus)Picons")
988 (defun gnus-picons-installed-p ()
989 "Say whether picons are installed on your machine."
990 (let ((installed nil))
991 (dolist (database gnus-picon-databases)
992 (when (file-exists-p database)
996 (defcustom gnus-article-mime-part-function nil
997 "Function called with a MIME handle as the argument.
998 This is meant for people who want to do something automatic based
999 on parts -- for instance, adding Vcard info to a database."
1000 :group 'gnus-article-mime
1001 :type '(choice (const nil)
1004 (defcustom gnus-mime-multipart-functions nil
1005 "An alist of MIME types to functions to display them."
1007 :group 'gnus-article-mime
1008 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1010 (defcustom gnus-article-date-lapsed-new-header nil
1011 "Whether the X-Sent and Date headers can coexist.
1012 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1013 either replace the old \"Date:\" header (if this variable is nil), or
1014 be added below it (otherwise)."
1016 :group 'gnus-article-headers
1019 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1020 "Function called with a MIME handle as the argument.
1021 This is meant for people who want to view first matched part.
1022 For `undisplayed-alternative' (default), the first undisplayed
1023 part or alternative part is used. For `undisplayed', the first
1024 undisplayed part is used. For a function, the first part which
1025 the function return t is used. For nil, the first part is
1028 :group 'gnus-article-mime
1030 (item :tag "first" :value nil)
1031 (item :tag "undisplayed" :value undisplayed)
1032 (item :tag "undisplayed or alternative"
1033 :value undisplayed-alternative)
1036 (defcustom gnus-mime-action-alist
1037 '(("save to file" . gnus-mime-save-part)
1038 ("save and strip" . gnus-mime-save-part-and-strip)
1039 ("replace with file" . gnus-mime-replace-part)
1040 ("delete part" . gnus-mime-delete-part)
1041 ("display as text" . gnus-mime-inline-part)
1042 ("view the part" . gnus-mime-view-part)
1043 ("pipe to command" . gnus-mime-pipe-part)
1044 ("toggle display" . gnus-article-press-button)
1045 ("toggle display" . gnus-article-view-part-as-charset)
1046 ("view as type" . gnus-mime-view-part-as-type)
1047 ("view internally" . gnus-mime-view-part-internally)
1048 ("view externally" . gnus-mime-view-part-externally))
1049 "An alist of actions that run on the MIME attachment."
1050 :group 'gnus-article-mime
1051 :type '(repeat (cons (string :tag "name")
1054 (defcustom gnus-auto-select-part 1
1055 "Advance to next MIME part when deleting or stripping parts.
1057 When 0, point will be placed on the same part as before. When
1058 positive (negative), move point forward (backwards) this many
1059 parts. When nil, redisplay article."
1060 :version "23.0" ;; No Gnus
1061 :group 'gnus-article-mime
1062 :type '(choice (const nil :tag "Redisplay article.")
1063 (const 1 :tag "Next part.")
1064 (const 0 :tag "Current part.")
1068 ;;; The treatment variables
1071 (defvar gnus-part-display-hook nil
1072 "Hook called on parts that are to receive treatment.")
1074 (defvar gnus-article-treat-custom
1075 '(choice (const :tag "Off" nil)
1077 (const :tag "Header" head)
1078 (const :tag "First" first)
1079 (const :tag "Last" last)
1080 (integer :tag "Less")
1081 (repeat :tag "Groups" regexp)
1082 (sexp :tag "Predicate")))
1084 (defvar gnus-article-treat-head-custom
1085 '(choice (const :tag "Off" nil)
1086 (const :tag "Header" head)))
1088 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1092 (defvar gnus-inhibit-treatment nil
1093 "Whether to inhibit treatment.")
1095 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1096 "Highlight the signature.
1097 Valid values are nil, t, `head', `first', `last', an integer or a
1098 predicate. See Info node `(gnus)Customizing Articles'."
1099 :group 'gnus-article-treat
1100 :link '(custom-manual "(gnus)Customizing Articles")
1101 :type gnus-article-treat-custom)
1102 (put 'gnus-treat-highlight-signature 'highlight t)
1104 (defcustom gnus-treat-buttonize 100000
1106 Valid values are nil, t, `head', `first', `last', an integer or a
1107 predicate. See Info node `(gnus)Customizing Articles'."
1108 :group 'gnus-article-treat
1109 :link '(custom-manual "(gnus)Customizing Articles")
1110 :type gnus-article-treat-custom)
1111 (put 'gnus-treat-buttonize 'highlight t)
1113 (defcustom gnus-treat-buttonize-head 'head
1114 "Add buttons to the head.
1115 Valid values are nil, t, `head', `first', `last', an integer or a
1116 predicate. See Info node `(gnus)Customizing Articles'."
1117 :group 'gnus-article-treat
1118 :link '(custom-manual "(gnus)Customizing Articles")
1119 :type gnus-article-treat-head-custom)
1120 (put 'gnus-treat-buttonize-head 'highlight t)
1122 (defcustom gnus-treat-emphasize 50000
1124 Valid values are nil, t, `head', `first', `last', an integer or a
1125 predicate. See Info node `(gnus)Customizing Articles'."
1126 :group 'gnus-article-treat
1127 :link '(custom-manual "(gnus)Customizing Articles")
1128 :type gnus-article-treat-custom)
1129 (put 'gnus-treat-emphasize 'highlight t)
1131 (defcustom gnus-treat-strip-cr nil
1132 "Remove carriage returns.
1133 Valid values are nil, t, `head', `first', `last', an integer or a
1134 predicate. See Info node `(gnus)Customizing Articles'."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1140 (defcustom gnus-treat-unsplit-urls nil
1141 "Remove newlines from within URLs.
1142 Valid values are nil, t, `head', `first', `last', an integer or a
1143 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1149 (defcustom gnus-treat-leading-whitespace nil
1150 "Remove leading whitespace in headers.
1151 Valid values are nil, t, `head', `first', `last', an integer or a
1152 predicate. See Info node `(gnus)Customizing Articles'."
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-custom)
1158 (defcustom gnus-treat-hide-headers 'head
1160 Valid values are nil, t, `head', `first', `last', an integer or a
1161 predicate. See Info node `(gnus)Customizing Articles'."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-head-custom)
1166 (defcustom gnus-treat-hide-boring-headers nil
1167 "Hide boring headers.
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-head-custom)
1174 (defcustom gnus-treat-hide-signature nil
1175 "Hide the signature.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1182 (defcustom gnus-treat-fill-article nil
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-hide-citation nil
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-custom)
1198 (defcustom gnus-treat-hide-citation-maybe nil
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1206 (defcustom gnus-treat-strip-list-identifiers 'head
1207 "Strip list identifiers from `gnus-list-identifiers`.
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1211 :group 'gnus-article-treat
1212 :link '(custom-manual "(gnus)Customizing Articles")
1213 :type gnus-article-treat-custom)
1215 (make-obsolete-variable 'gnus-treat-strip-pgp
1216 "This option is obsolete in Gnus 5.10.")
1218 (defcustom gnus-treat-strip-pem nil
1219 "Strip PEM signatures.
1220 Valid values are nil, t, `head', `first', `last', an integer or a
1221 predicate. See Info node `(gnus)Customizing Articles'."
1222 :group 'gnus-article-treat
1223 :link '(custom-manual "(gnus)Customizing Articles")
1224 :type gnus-article-treat-custom)
1226 (defcustom gnus-treat-strip-banner t
1227 "Strip banners from articles.
1228 The banner to be stripped is specified in the `banner' group parameter.
1229 Valid values are nil, t, `head', `first', `last', an integer or a
1230 predicate. See Info node `(gnus)Customizing Articles'."
1231 :group 'gnus-article-treat
1232 :link '(custom-manual "(gnus)Customizing Articles")
1233 :type gnus-article-treat-custom)
1235 (defcustom gnus-treat-highlight-headers 'head
1236 "Highlight the headers.
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate. See Info node `(gnus)Customizing Articles'."
1239 :group 'gnus-article-treat
1240 :link '(custom-manual "(gnus)Customizing Articles")
1241 :type gnus-article-treat-head-custom)
1242 (put 'gnus-treat-highlight-headers 'highlight t)
1244 (defcustom gnus-treat-highlight-citation t
1245 "Highlight cited text.
1246 Valid values are nil, t, `head', `first', `last', an integer or a
1247 predicate. See Info node `(gnus)Customizing Articles'."
1248 :group 'gnus-article-treat
1249 :link '(custom-manual "(gnus)Customizing Articles")
1250 :type gnus-article-treat-custom)
1251 (put 'gnus-treat-highlight-citation 'highlight t)
1253 (defcustom gnus-treat-date-ut nil
1254 "Display the Date in UT (GMT).
1255 Valid values are nil, t, `head', `first', `last', an integer or a
1256 predicate. See Info node `(gnus)Customizing Articles'."
1257 :group 'gnus-article-treat
1258 :link '(custom-manual "(gnus)Customizing Articles")
1259 :type gnus-article-treat-head-custom)
1261 (defcustom gnus-treat-date-local nil
1262 "Display the Date in the local timezone.
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-head-custom)
1269 (defcustom gnus-treat-date-english nil
1270 "Display the Date in a format that can be read aloud in English.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1274 :group 'gnus-article-treat
1275 :link '(custom-manual "(gnus)Customizing Articles")
1276 :type gnus-article-treat-head-custom)
1278 (defcustom gnus-treat-date-lapsed nil
1279 "Display the Date header in a way that says how much time has elapsed.
1280 Valid values are nil, t, `head', `first', `last', an integer or a
1281 predicate. See Info node `(gnus)Customizing Articles'."
1282 :group 'gnus-article-treat
1283 :link '(custom-manual "(gnus)Customizing Articles")
1284 :type gnus-article-treat-head-custom)
1286 (defcustom gnus-treat-date-original nil
1287 "Display the date in the original timezone.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-head-custom)
1294 (defcustom gnus-treat-date-iso8601 nil
1295 "Display the date in the ISO8601 format.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1299 :group 'gnus-article-treat
1300 :link '(custom-manual "(gnus)Customizing Articles")
1301 :type gnus-article-treat-head-custom)
1303 (defcustom gnus-treat-date-user-defined nil
1304 "Display the date in a user-defined format.
1305 The format is defined by the `gnus-article-time-format' variable.
1306 Valid values are nil, t, `head', `first', `last', an integer or a
1307 predicate. See Info node `(gnus)Customizing Articles'."
1308 :group 'gnus-article-treat
1309 :link '(custom-manual "(gnus)Customizing Articles")
1310 :type gnus-article-treat-head-custom)
1312 (defcustom gnus-treat-strip-headers-in-body t
1313 "Strip the X-No-Archive header line from the beginning of the body.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1317 :group 'gnus-article-treat
1318 :link '(custom-manual "(gnus)Customizing Articles")
1319 :type gnus-article-treat-custom)
1321 (defcustom gnus-treat-strip-trailing-blank-lines nil
1322 "Strip trailing blank lines.
1323 Valid values are nil, t, `head', `first', `last', an integer or a
1324 predicate. See Info node `(gnus)Customizing Articles'.
1326 When set to t, it also strips trailing blanks in all MIME parts.
1327 Consider to use `last' instead."
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1332 (defcustom gnus-treat-strip-leading-blank-lines nil
1333 "Strip leading blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1337 When set to t, it also strips trailing blanks in all MIME parts."
1338 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :type gnus-article-treat-custom)
1342 (defcustom gnus-treat-strip-multiple-blank-lines nil
1343 "Strip multiple blank lines.
1344 Valid values are nil, t, `head', `first', `last', an integer or a
1345 predicate. See Info node `(gnus)Customizing Articles'."
1346 :group 'gnus-article-treat
1347 :link '(custom-manual "(gnus)Customizing Articles")
1348 :type gnus-article-treat-custom)
1350 (defcustom gnus-treat-unfold-headers 'head
1351 "Unfold folded header lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 predicate. See Info node `(gnus)Customizing Articles'."
1355 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :type gnus-article-treat-custom)
1359 (defcustom gnus-article-unfold-long-headers nil
1360 "If non-nil, allow unfolding headers even if the header is long.
1361 If it is a regexp, only long headers matching this regexp are unfolded.
1362 If it is t, all long headers are unfolded.
1364 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1365 :version "23.0" ;; No Gnus
1366 :group 'gnus-article-treat
1367 :type '(choice (const nil)
1368 (const :tag "all" t)
1371 (defcustom gnus-treat-fold-headers nil
1373 Valid values are nil, t, `head', `first', `last', an integer or a
1374 predicate. See Info node `(gnus)Customizing Articles'."
1376 :group 'gnus-article-treat
1377 :link '(custom-manual "(gnus)Customizing Articles")
1378 :type gnus-article-treat-custom)
1380 (defcustom gnus-treat-fold-newsgroups 'head
1381 "Fold the Newsgroups and Followup-To headers.
1382 Valid values are nil, t, `head', `first', `last', an integer or a
1383 predicate. See Info node `(gnus)Customizing Articles'."
1385 :group 'gnus-article-treat
1386 :link '(custom-manual "(gnus)Customizing Articles")
1387 :type gnus-article-treat-custom)
1389 (defcustom gnus-treat-overstrike t
1390 "Treat overstrike highlighting.
1391 Valid values are nil, t, `head', `first', `last', an integer or a
1392 predicate. See Info node `(gnus)Customizing Articles'."
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
1395 :type gnus-article-treat-custom)
1396 (put 'gnus-treat-overstrike 'highlight t)
1398 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1399 "Treat ANSI SGR control sequences.
1400 Valid values are nil, t, `head', `first', `last', an integer or a
1401 predicate. See Info node `(gnus)Customizing Articles'."
1402 :group 'gnus-article-treat
1403 :link '(custom-manual "(gnus)Customizing Articles")
1404 :type gnus-article-treat-custom)
1406 (make-obsolete-variable 'gnus-treat-display-xface
1407 'gnus-treat-display-x-face)
1409 (defcustom gnus-treat-display-x-face
1410 (and (not noninteractive)
1411 (gnus-image-type-available-p 'xbm)
1412 (if (featurep 'xemacs)
1414 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1415 (executable-find "icontopbm")))
1417 "Display X-Face headers.
1418 Valid values are nil and `head'.
1419 See Info node `(gnus)Customizing Articles' and Info node
1420 `(gnus)X-Face' for details."
1421 :group 'gnus-article-treat
1423 :link '(custom-manual "(gnus)Customizing Articles")
1424 :link '(custom-manual "(gnus)X-Face")
1425 :type gnus-article-treat-head-custom
1426 :set (lambda (symbol value)
1429 (cond ((or (boundp symbol) (get symbol 'saved-value))
1431 ((boundp 'gnus-treat-display-xface)
1433 ** gnus-treat-display-xface is an obsolete variable;\
1434 use gnus-treat-display-x-face instead")
1435 (default-value 'gnus-treat-display-xface))
1436 ((get 'gnus-treat-display-xface 'saved-value)
1438 ** gnus-treat-display-xface is an obsolete variable;\
1439 use gnus-treat-display-x-face instead")
1440 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1443 (put 'gnus-treat-display-x-face 'highlight t)
1445 (defcustom gnus-treat-display-face
1446 (and (not noninteractive)
1447 (gnus-image-type-available-p 'png)
1449 "Display Face headers.
1450 Valid values are nil, t, `head', `first', `last', an integer or a
1451 predicate. See Info node `(gnus)Customizing Articles' and Info
1452 node `(gnus)X-Face' for details."
1453 :group 'gnus-article-treat
1455 :link '(custom-manual "(gnus)Customizing Articles")
1456 :link '(custom-manual "(gnus)X-Face")
1457 :type gnus-article-treat-head-custom)
1458 (put 'gnus-treat-display-face 'highlight t)
1460 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate. See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Smileys' for details."
1465 :group 'gnus-article-treat
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)Smileys")
1469 :type gnus-article-treat-custom)
1470 (put 'gnus-treat-display-smileys 'highlight t)
1472 (defcustom gnus-treat-from-picon
1473 (if (and (gnus-image-type-available-p 'xpm)
1474 (gnus-picons-installed-p))
1476 "Display picons in the From header.
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Picons' for details."
1481 :group 'gnus-article-treat
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)Picons")
1485 :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-from-picon 'highlight t)
1488 (defcustom gnus-treat-mail-picon
1489 (if (and (gnus-image-type-available-p 'xpm)
1490 (gnus-picons-installed-p))
1492 "Display picons in To and Cc headers.
1493 Valid values are nil, t, `head', `first', `last', an integer or a
1494 predicate. See Info node `(gnus)Customizing Articles' and Info
1495 node `(gnus)Picons' for details."
1497 :group 'gnus-article-treat
1499 :link '(custom-manual "(gnus)Customizing Articles")
1500 :link '(custom-manual "(gnus)Picons")
1501 :type gnus-article-treat-head-custom)
1502 (put 'gnus-treat-mail-picon 'highlight t)
1504 (defcustom gnus-treat-newsgroups-picon
1505 (if (and (gnus-image-type-available-p 'xpm)
1506 (gnus-picons-installed-p))
1508 "Display picons in the Newsgroups and Followup-To headers.
1509 Valid values are nil, t, `head', `first', `last', an integer or a
1510 predicate. See Info node `(gnus)Customizing Articles' and Info
1511 node `(gnus)Picons' for details."
1513 :group 'gnus-article-treat
1515 :link '(custom-manual "(gnus)Customizing Articles")
1516 :link '(custom-manual "(gnus)Picons")
1517 :type gnus-article-treat-head-custom)
1518 (put 'gnus-treat-newsgroups-picon 'highlight t)
1520 (defcustom gnus-treat-body-boundary
1521 (if (or gnus-treat-newsgroups-picon
1522 gnus-treat-mail-picon
1523 gnus-treat-from-picon)
1524 ;; If there's much decoration, the user might prefer a boundery.
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-value '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))))
2338 (defvar gnus-face-properties-alist)
2340 (defun article-display-face (&optional force)
2341 "Display any Face headers in the header."
2342 (interactive (list 'force))
2343 (let ((wash-face-p buffer-read-only))
2344 (gnus-with-article-headers
2345 ;; When displaying parts, this function can be called several times on
2346 ;; the same article, without any intended toggle semantic (as typing `W
2347 ;; D d' would have). So face deletion must occur only when we come from
2348 ;; an interactive command, that is when the *Article* buffer is
2350 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2351 (gnus-delete-images 'face)
2352 (let ((from (message-fetch-field "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)
2362 ;; Check whether this face is censored.
2363 (not (and gnus-article-x-face-too-ugly
2365 (setq from (message-fetch-field "from")))
2366 (string-match gnus-article-x-face-too-ugly
2368 (while (gnus-article-goto-header "Face")
2369 (push (mail-header-field-value) faces)))))
2371 (goto-char (point-min))
2373 (unless (setq from (gnus-article-goto-header "from"))
2376 (insert " [no `from' set]\n"))
2378 (when (setq png (gnus-convert-face-to-png (pop faces)))
2380 (apply 'gnus-create-image png 'png t
2381 (cdr (assq 'png gnus-face-properties-alist))))
2383 (gnus-add-wash-type 'face)
2384 (gnus-add-image 'face image)
2385 (gnus-put-image image nil 'face))))))))))
2387 (defun article-display-x-face (&optional force)
2388 "Look for an X-Face header and display it if present."
2389 (interactive (list 'force))
2390 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2391 (gnus-with-article-headers
2392 ;; Delete the old process, if any.
2393 (when (process-status "article-x-face")
2394 (delete-process "article-x-face"))
2395 ;; See the comment in `article-display-face'.
2396 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2397 ;; We have already displayed X-Faces, so we remove them
2399 (gnus-delete-images 'xface)
2401 (let ((from (message-fetch-field "from"))
2403 (save-current-buffer
2404 (when (and wash-face-p
2405 (gnus-buffer-live-p gnus-original-article-buffer)
2406 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2407 ;; If type `W f', use gnus-original-article-buffer,
2408 ;; otherwise use the current buffer because displaying
2409 ;; RFC822 parts calls this function too.
2410 (set-buffer gnus-original-article-buffer))
2412 (mail-narrow-to-head)
2413 (and gnus-article-x-face-command
2415 ;; Check whether this face is censored.
2416 (not (and gnus-article-x-face-too-ugly
2418 (setq from (message-fetch-field "from")))
2419 (string-match gnus-article-x-face-too-ugly
2421 (while (gnus-article-goto-header "X-Face")
2422 (push (mail-header-field-value) x-faces)))))
2424 ;; We display the face.
2425 (cond ((functionp gnus-article-x-face-command)
2426 ;; The command is a lisp function, so we call it.
2427 (mapc gnus-article-x-face-command x-faces))
2428 ((stringp gnus-article-x-face-command)
2429 ;; The command is a string, so we interpret the command
2430 ;; as a, well, command, and fork it off.
2431 (let ((process-connection-type nil))
2432 (gnus-set-process-query-on-exit-flag
2434 "article-x-face" nil shell-file-name
2435 shell-command-switch gnus-article-x-face-command)
2437 ;; Sending multiple EOFs to xv doesn't work,
2438 ;; so we only do a single external face.
2440 (insert (car x-faces))
2441 (process-send-region "article-x-face"
2442 (point-min) (point-max)))
2443 (process-send-eof "article-x-face")))
2445 (error "`%s' set to `%s' is not a function"
2446 gnus-article-x-face-command
2447 'gnus-article-x-face-command)))))))))
2449 (defun article-decode-mime-words ()
2450 "Decode all MIME-encoded words in the article."
2452 (gnus-with-article-buffer
2453 (let ((inhibit-point-motion-hooks t)
2454 (mail-parse-charset gnus-newsgroup-charset)
2455 (mail-parse-ignored-charsets
2456 (with-current-buffer gnus-summary-buffer
2457 gnus-newsgroup-ignored-charsets)))
2458 (mail-decode-encoded-word-region (point-min) (point-max)))))
2460 (defun article-decode-charset (&optional prompt)
2461 "Decode charset-encoded text in the article.
2462 If PROMPT (the prefix), prompt for a coding system to use."
2464 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2465 (inhibit-read-only t)
2466 (mail-parse-charset gnus-newsgroup-charset)
2467 (mail-parse-ignored-charsets
2468 (save-excursion (condition-case nil
2469 (set-buffer gnus-summary-buffer)
2471 gnus-newsgroup-ignored-charsets))
2472 ct cte ctl charset format)
2475 (article-narrow-to-head)
2476 (setq ct (message-fetch-field "Content-Type" t)
2477 cte (message-fetch-field "Content-Transfer-Encoding" t)
2478 ctl (and ct (mail-header-parse-content-type ct))
2481 (mm-read-coding-system "Charset to decode: "))
2483 (mail-content-type-get ctl 'charset)))
2484 format (and ctl (mail-content-type-get ctl 'format)))
2486 (setq cte (mail-header-strip cte)))
2487 (if (and ctl (not (string-match "/" (car ctl))))
2489 (goto-char (point-max)))
2492 (narrow-to-region (point) (point-max))
2493 (when (and (eq mail-parse-charset 'gnus-decoded)
2494 (eq (mm-body-7-or-8) '8bit))
2495 ;; The text code could have been decoded.
2496 (setq charset mail-parse-charset))
2497 (when (and (or (not ctl)
2498 (equal (car ctl) "text/plain"))
2499 (not format)) ;; article with format will decode later.
2501 charset (and cte (intern (downcase
2502 (gnus-strip-whitespace cte))))
2505 (defun article-decode-encoded-words ()
2506 "Remove encoded-word encoding from headers."
2507 (let ((inhibit-point-motion-hooks t)
2508 (mail-parse-charset gnus-newsgroup-charset)
2509 (mail-parse-ignored-charsets
2510 (save-excursion (condition-case nil
2511 (set-buffer gnus-summary-buffer)
2513 gnus-newsgroup-ignored-charsets))
2514 (inhibit-read-only t)
2516 (goto-char (point-min))
2517 (when (search-forward "\n\n" nil 'move)
2524 (memq (char-after) '(?\t ? )))))
2525 (setq start (point))
2527 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2528 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2529 (funcall gnus-decode-address-function start end)
2530 (funcall gnus-decode-header-function start end))
2531 (goto-char (setq end start)))))
2533 (defun article-decode-group-name ()
2534 "Decode group names in Newsgroups, Followup-To and Xref headers."
2535 (let ((inhibit-point-motion-hooks t)
2536 (inhibit-read-only t)
2537 (method (gnus-find-method-for-group gnus-newsgroup-name))
2539 (when (and (or gnus-group-name-charset-method-alist
2540 gnus-group-name-charset-group-alist)
2541 (gnus-buffer-live-p gnus-original-article-buffer))
2543 (article-narrow-to-head)
2544 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2545 (with-current-buffer gnus-original-article-buffer
2546 (goto-char (point-min)))
2547 (setq regexp (concat "^" header
2548 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2549 (while (re-search-forward regexp nil t)
2550 (replace-match (save-match-data
2551 (gnus-decode-newsgroups
2552 ;; XXX how to use data in article buffer?
2553 (with-current-buffer gnus-original-article-buffer
2554 (re-search-forward regexp nil t)
2556 gnus-newsgroup-name method))
2558 (goto-char (point-min)))))))
2560 (autoload 'idna-to-unicode "idna")
2562 (defun article-decode-idna-rhs ()
2563 "Decode IDNA strings in RHS in various headers in current buffer.
2564 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2565 Mail-Reply-To: and Mail-Followup-To:."
2568 (let ((inhibit-point-motion-hooks t)
2569 (inhibit-read-only t))
2570 (article-narrow-to-head)
2571 (goto-char (point-min))
2572 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2574 (when (save-match-data
2575 (and (setq ace (match-string 1))
2577 (and (re-search-backward "^[^ \t]" nil t)
2578 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2579 (setq unicode (idna-to-unicode ace))))
2580 (unless (string= ace unicode)
2581 (replace-match unicode nil nil nil 1)))))))))
2583 (defun article-de-quoted-unreadable (&optional force read-charset)
2584 "Translate a quoted-printable-encoded article.
2585 If FORCE, decode the article whether it is marked as quoted-printable
2587 If READ-CHARSET, ask for a coding system."
2588 (interactive (list 'force current-prefix-arg))
2590 (let ((inhibit-read-only t) type charset)
2591 (if (gnus-buffer-live-p gnus-original-article-buffer)
2592 (with-current-buffer gnus-original-article-buffer
2594 (gnus-fetch-field "content-transfer-encoding"))
2595 (let* ((ct (gnus-fetch-field "content-type"))
2596 (ctl (and ct (mail-header-parse-content-type ct))))
2597 (setq charset (and ctl
2598 (mail-content-type-get ctl 'charset)))
2599 (if (stringp charset)
2600 (setq charset (intern (downcase charset)))))))
2602 (setq charset (mm-read-coding-system "Charset: " charset)))
2604 (setq charset gnus-newsgroup-charset))
2606 (and type (let ((case-fold-search t))
2607 (string-match "quoted-printable" type))))
2609 (quoted-printable-decode-region
2610 (point) (point-max) (mm-charset-to-coding-system charset))))))
2612 (defun article-de-base64-unreadable (&optional force read-charset)
2613 "Translate a base64 article.
2614 If FORCE, decode the article whether it is marked as base64 not.
2615 If READ-CHARSET, ask for a coding system."
2616 (interactive (list 'force current-prefix-arg))
2618 (let ((inhibit-read-only t) type charset)
2619 (if (gnus-buffer-live-p gnus-original-article-buffer)
2620 (with-current-buffer gnus-original-article-buffer
2622 (gnus-fetch-field "content-transfer-encoding"))
2623 (let* ((ct (gnus-fetch-field "content-type"))
2624 (ctl (and ct (mail-header-parse-content-type ct))))
2625 (setq charset (and ctl
2626 (mail-content-type-get ctl 'charset)))
2627 (if (stringp charset)
2628 (setq charset (intern (downcase charset)))))))
2630 (setq charset (mm-read-coding-system "Charset: " charset)))
2632 (setq charset gnus-newsgroup-charset))
2634 (and type (let ((case-fold-search t))
2635 (string-match "base64" type))))
2638 (narrow-to-region (point) (point-max))
2639 (base64-decode-region (point-min) (point-max))
2640 (mm-decode-coding-region
2641 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2646 (defun article-decode-HZ ()
2647 "Translate a HZ-encoded article."
2651 (let ((inhibit-read-only t))
2652 (rfc1843-decode-region (point-min) (point-max)))))
2654 (defun article-unsplit-urls ()
2655 "Remove the newlines that some other mailers insert into URLs."
2658 (let ((inhibit-read-only t))
2659 (goto-char (point-min))
2660 (while (re-search-forward
2661 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2662 (replace-match "\\1\\3" t)))
2663 (when (interactive-p)
2664 (gnus-treat-article nil))))
2667 (defun article-wash-html (&optional read-charset)
2668 "Format an HTML article.
2669 If READ-CHARSET, ask for a coding system. If it is a number, the
2670 charset defined in `gnus-summary-show-article-charset-alist' is used."
2673 (let ((inhibit-read-only t)
2676 (if (or (and (numberp read-charset)
2680 gnus-summary-show-article-charset-alist))))
2681 (setq charset (mm-read-coding-system "Charset: ")))
2682 (let ((gnus-summary-show-article-charset-alist
2683 (list (cons 1 charset))))
2684 (with-current-buffer gnus-summary-buffer
2685 (gnus-summary-show-article 1)))
2686 (error "No charset is given"))
2687 (when (gnus-buffer-live-p gnus-original-article-buffer)
2688 (with-current-buffer gnus-original-article-buffer
2689 (let* ((ct (gnus-fetch-field "content-type"))
2690 (ctl (and ct (mail-header-parse-content-type ct))))
2691 (setq charset (and ctl
2692 (mail-content-type-get ctl 'charset)))
2693 (when (stringp charset)
2694 (setq charset (intern (downcase charset)))))))
2696 (setq charset gnus-newsgroup-charset)))
2698 (save-window-excursion
2700 (narrow-to-region (point) (point-max))
2701 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2702 (entry (assq func mm-text-html-washer-alist)))
2704 (setq func (cdr entry)))
2709 (apply (car func) (cdr func))))))))))
2712 (declare-function w3-region "ext:w3-display" (st nd))
2714 (defun gnus-article-wash-html-with-w3 ()
2715 "Wash the current buffer with w3."
2717 (let ((w3-strict-width (window-width))
2718 (url-standalone-mode t)
2719 (url-gateway-unplugged t)
2720 (w3-honor-stylesheets nil))
2722 (w3-region (point-min) (point-max))
2726 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2728 (defun gnus-article-wash-html-with-w3m ()
2729 "Wash the current buffer with emacs-w3m."
2731 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2732 w3m-force-redisplay)
2733 (w3m-region (point-min) (point-max)))
2734 (when (and mm-inline-text-html-with-w3m-keymap
2735 (boundp 'w3m-minor-mode-map)
2737 (add-text-properties
2738 (point-min) (point-max)
2739 (list 'keymap w3m-minor-mode-map
2740 ;; Put the mark meaning this part was rendered by emacs-w3m.
2741 'mm-inline-text-html-with-w3m t))))
2743 (defvar charset) ;; Bound by `article-wash-html'.
2745 (defun gnus-article-wash-html-with-w3m-standalone ()
2746 "Wash the current buffer with w3m."
2747 (if (mm-w3m-standalone-supports-m17n-p)
2749 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2751 (setq charset 'iso-8859-1))
2752 (let ((coding-system-for-write charset)
2753 (coding-system-for-read charset))
2754 (call-process-region
2755 (point-min) (point-max)
2756 "w3m" t t nil "-dump" "-T" "text/html"
2757 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2758 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2760 (defvar gnus-article-browse-html-temp-list nil
2761 "List of temporary files created by `gnus-article-browse-html-parts'.
2762 Internal variable.")
2764 (defcustom gnus-article-browse-delete-temp 'ask
2765 "What to do with temporary files from `gnus-article-browse-html-parts'.
2766 If nil, don't delete temporary files. If it is t, delete them on
2767 exit from the summary buffer. If it is the symbol `file', query
2768 on each file, if it is `ask' ask once when exiting from the
2770 :group 'gnus-article
2771 :version "23.0" ;; No Gnus
2772 :type '(choice (const :tag "Don't delete" nil)
2773 (const :tag "Don't ask" t)
2774 (const :tag "Ask" ask)
2775 (const :tag "Ask for each file" file)))
2777 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2779 (defun gnus-article-browse-delete-temp-files (&optional how)
2780 "Delete temp-files created by `gnus-article-browse-html-parts'."
2781 (when (and gnus-article-browse-html-temp-list
2783 (setq how gnus-article-browse-delete-temp)))
2784 (when (and (eq how 'ask)
2785 (gnus-y-or-n-p (format
2786 "Delete all %s temporary HTML file(s)? "
2787 (length gnus-article-browse-html-temp-list)))
2789 (dolist (file gnus-article-browse-html-temp-list)
2790 (when (and (file-exists-p file)
2792 ;; `how' is neither `nil', `ask' nor `t' (i.e. `file'):
2794 (format "Delete temporary HTML file `%s'? " file))))
2795 (delete-file file)))
2796 ;; Also remove file from the list when not deleted or if file doesn't
2798 (setq gnus-article-browse-html-temp-list nil))
2799 gnus-article-browse-html-temp-list)
2801 (defun gnus-article-browse-html-parts (list &optional header)
2802 "View all \"text/html\" parts from LIST.
2803 Recurse into multiparts. The optional HEADER that should be a decoded
2804 message header will be added to the bodies of the \"text/html\" parts."
2805 ;; Internal function used by `gnus-article-browse-html-article'.
2806 (let (type file charset tmp-file showed)
2807 ;; Find and show the html-parts.
2808 (dolist (handle list)
2809 ;; If HTML, show it:
2810 (cond ((not (listp handle)))
2811 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2812 (and (equal (car type) "message/external-body")
2814 (setq file (or (mail-content-type-get type 'name)
2815 (mail-content-type-get
2816 (mm-handle-disposition handle)
2818 (or (mm-handle-cache handle)
2819 (condition-case code
2820 (progn (mm-extern-cache-contents handle) t)
2822 (gnus-message 3 "%s" (error-message-string code))
2823 (when (>= gnus-verbose 3) (sit-for 2))
2826 (setq handle (mm-handle-cache handle)
2827 type (mm-handle-type handle))
2828 (equal (car type) "text/html"))))
2829 (when (or (setq charset (mail-content-type-get type 'charset))
2832 (setq tmp-file (mm-make-temp-file
2833 ;; Do we need to care for 8.3 filenames?
2834 "mm-" nil ".html")))
2835 ;; Add a meta html tag to specify charset and a header.
2838 (let (title eheader body hcharset coding)
2840 (mm-enable-multibyte)
2841 (setq case-fold-search t)
2842 (insert header "\n")
2843 (setq title (message-fetch-field "subject"))
2844 (goto-char (point-min))
2845 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2846 (replace-match (cond ((match-beginning 1) "<")
2847 ((match-beginning 2) ">")
2849 (goto-char (point-min))
2851 (goto-char (point-max))
2852 (insert "</pre>\n<hr>\n")
2853 ;; We have to examine charset one by one since
2854 ;; charset specified in parts might be different.
2855 (if (eq charset 'gnus-decoded)
2856 (setq charset 'utf-8
2857 eheader (mm-encode-coding-string (buffer-string)
2860 (mm-encode-coding-string title charset))
2861 body (mm-encode-coding-string (mm-get-part handle)
2863 (setq hcharset (mm-find-mime-charset-region (point-min)
2865 (cond ((= (length hcharset) 1)
2866 (setq hcharset (car hcharset)
2867 coding (mm-charset-to-coding-system
2869 ((> (length hcharset) 1)
2870 (setq hcharset 'utf-8
2876 (mm-charset-to-coding-system charset))
2877 (if (eq coding body)
2878 (setq eheader (mm-encode-coding-string
2879 (buffer-string) coding)
2881 (mm-encode-coding-string
2883 body (mm-get-part handle))
2884 (setq charset 'utf-8
2885 eheader (mm-encode-coding-string
2886 (buffer-string) charset)
2888 (mm-encode-coding-string
2890 body (mm-encode-coding-string
2891 (mm-decode-coding-string
2892 (mm-get-part handle) body)
2894 (setq charset hcharset
2895 eheader (mm-encode-coding-string
2896 (buffer-string) coding)
2898 (mm-encode-coding-string
2900 body (mm-get-part handle)))
2901 (setq eheader (mm-string-as-unibyte (buffer-string))
2902 body (mm-get-part handle))))
2904 (mm-disable-multibyte)
2907 (mm-add-meta-html-tag handle charset))
2909 (goto-char (point-min))
2910 (unless (search-forward "<title>" nil t)
2911 (re-search-forward "<head>\\s-*" nil t)
2912 (insert "<title>" title "</title>\n")))
2913 (goto-char (point-min))
2914 (or (re-search-forward
2915 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2917 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2919 (mm-write-region (point-min) (point-max)
2920 tmp-file nil nil nil 'binary t))))
2922 (mm-with-unibyte-buffer
2923 (insert (if (eq charset 'gnus-decoded)
2924 (mm-encode-coding-string
2925 (mm-get-part handle)
2926 (setq charset 'utf-8))
2927 (mm-get-part handle)))
2928 (if (or (mm-add-meta-html-tag handle charset)
2930 (mm-write-region (point-min) (point-max)
2931 tmp-file nil nil nil 'binary t)
2932 (setq tmp-file nil))))
2934 (mm-save-part-to-file handle tmp-file)))
2936 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2937 (add-hook 'gnus-summary-prepare-exit-hook
2938 'gnus-article-browse-delete-temp-files)
2939 (add-hook 'gnus-exit-gnus-hook
2941 (gnus-article-browse-delete-temp-files t)))
2942 ;; FIXME: Warn if there's an <img> tag?
2943 (browse-url-of-file (or tmp-file (expand-file-name file)))
2945 ;; If multipart, recurse
2946 ((equal (mm-handle-media-supertype handle) "multipart")
2947 (when (gnus-article-browse-html-parts handle header)
2949 ((equal (mm-handle-media-type handle) "message/rfc822")
2950 (mm-with-multibyte-buffer
2951 (mm-insert-part handle)
2952 (setq handle (mm-dissect-buffer t t))
2953 (when (and (bufferp (car handle))
2954 (stringp (car (mm-handle-type handle))))
2955 (setq handle (list handle)))
2957 (article-decode-encoded-words)
2958 (let ((gnus-visible-headers
2959 (or (get 'gnus-visible-headers 'standard-value)
2960 gnus-visible-headers)))
2961 (article-hide-headers))
2962 (goto-char (point-min))
2963 (search-forward "\n\n" nil 'move)
2964 (skip-chars-backward "\t\n ")
2965 (setq header (buffer-substring (point-min) (point)))))
2967 (gnus-article-browse-html-parts handle header)
2968 (mm-destroy-parts handle))
2972 ;; FIXME: Documentation in texi/gnus.texi missing.
2973 (defun gnus-article-browse-html-article (&optional arg)
2974 "View \"text/html\" parts of the current article with a WWW browser.
2975 The message header is added to the beginning of every html part unless
2976 the prefix argument ARG is given.
2978 Warning: Spammers use links to images in HTML articles to verify
2979 whether you have read the message. As
2980 `gnus-article-browse-html-article' passes the unmodified HTML
2981 content to the browser without eliminating these \"web bugs\" you
2982 should only use it for mails from trusted senders.
2984 If you alwasy want to display HTML part in the browser, set
2985 `mm-text-html-renderer' to nil."
2986 ;; Cf. `mm-w3m-safe-url-regexp'
2989 (gnus-summary-show-article)
2990 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
2991 gnus-visible-headers)))
2992 (gnus-summary-show-article)))
2993 (with-current-buffer gnus-article-buffer
2994 (let ((header (unless arg
2997 (buffer-substring-no-properties
2998 (goto-char (point-min))
2999 (if (search-forward "\n\n" nil t)
3001 (goto-char (point-max))
3002 (skip-chars-backward "\t\n ")
3005 (set-buffer gnus-original-article-buffer)
3006 (setq parts (mm-dissect-buffer t t))
3007 ;; If singlepart, enforce a list.
3008 (when (and (bufferp (car parts))
3009 (stringp (car (mm-handle-type parts))))
3010 (setq parts (list parts)))
3012 (unless (gnus-article-browse-html-parts parts header)
3013 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3014 (mm-destroy-parts parts)
3016 (gnus-summary-show-article)))))
3018 (defun article-hide-list-identifiers ()
3019 "Remove list identifies from the Subject header.
3020 The `gnus-list-identifiers' variable specifies what to do."
3022 (let ((inhibit-point-motion-hooks t)
3023 (regexp (if (consp gnus-list-identifiers)
3024 (mapconcat 'identity gnus-list-identifiers " *\\|")
3025 gnus-list-identifiers))
3026 (inhibit-read-only t))
3030 (article-narrow-to-head)
3031 (goto-char (point-min))
3032 (while (re-search-forward
3033 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3035 (delete-region (match-beginning 2) (match-end 0))
3036 (beginning-of-line))
3037 (when (re-search-forward
3038 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3039 (delete-region (match-beginning 1) (match-end 1))))))))
3041 (defun article-hide-pem (&optional arg)
3042 "Toggle hiding of any PEM headers and signatures in the current article.
3043 If given a negative prefix, always show; if given a positive prefix,
3045 (interactive (gnus-article-hidden-arg))
3046 (unless (gnus-article-check-hidden-text 'pem arg)
3048 (let ((inhibit-read-only t) end)
3049 (goto-char (point-min))
3050 ;; Hide the horrendously ugly "header".
3051 (when (and (search-forward
3052 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3054 (setq end (1+ (match-beginning 0))))
3055 (gnus-add-wash-type 'pem)
3056 (gnus-article-hide-text-type
3058 (if (search-forward "\n\n" nil t)
3062 ;; Hide the trailer as well
3063 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3065 (gnus-article-hide-text-type
3066 (match-beginning 0) (match-end 0) 'pem)))))))
3068 (defun article-strip-banner ()
3069 "Strip the banners specified by the `banner' group parameter and by
3070 `gnus-article-address-banner-alist'."
3074 (let ((inhibit-point-motion-hooks t))
3075 (when (gnus-parameter-banner gnus-newsgroup-name)
3076 (article-really-strip-banner
3077 (gnus-parameter-banner gnus-newsgroup-name)))
3078 (when gnus-article-address-banner-alist
3079 ;; Note that the From header is decoded here, so it is
3080 ;; required that the *-extract-address-components function
3081 ;; supports non-ASCII text.
3082 (let ((from (save-restriction
3084 (article-narrow-to-head)
3085 (mail-fetch-field "from"))))
3088 (cadr (funcall gnus-extract-address-components
3091 (dolist (pair gnus-article-address-banner-alist)
3092 (when (string-match (car pair) from)
3094 (article-really-strip-banner (cdr pair)))))))))))))
3096 (defun article-really-strip-banner (banner)
3097 "Strip the banner specified by the argument."
3100 (let ((inhibit-point-motion-hooks t)
3101 (gnus-signature-limit nil)
3102 (inhibit-read-only t))
3105 ((eq banner 'signature)
3106 (when (gnus-article-narrow-to-signature)
3109 (delete-region (point) (point-max))))
3111 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3112 (while (re-search-forward banner nil t)
3113 (delete-region (match-beginning 0) (match-end 0)))))
3115 (while (re-search-forward banner nil t)
3116 (delete-region (match-beginning 0) (match-end 0)))))))))
3118 (defun article-babel ()
3119 "Translate article using an online translation service."
3122 (gnus-with-article-buffer
3123 (when (article-goto-body)
3124 (let* ((start (point))
3126 (orig (buffer-substring start end))
3127 (trans (babel-as-string orig)))
3129 (narrow-to-region start end)
3130 (delete-region start end)
3133 (defun article-hide-signature (&optional arg)
3134 "Hide the signature in the current article.
3135 If given a negative prefix, always show; if given a positive prefix,
3137 (interactive (gnus-article-hidden-arg))
3138 (unless (gnus-article-check-hidden-text 'signature arg)
3141 (let ((inhibit-read-only t))
3142 (when (gnus-article-narrow-to-signature)
3143 (gnus-article-hide-text-type
3144 (point-min) (point-max) 'signature))))))
3145 (gnus-set-mode-line 'article))
3147 (defun article-strip-headers-in-body ()
3148 "Strip offensive headers from bodies."
3152 (let ((case-fold-search t))
3153 (when (looking-at "x-no-archive:")
3154 (gnus-delete-line)))))
3156 (defun article-strip-leading-blank-lines ()
3157 "Remove all blank lines from the beginning of the article."
3160 (let ((inhibit-point-motion-hooks t)
3161 (inhibit-read-only t))
3162 (when (article-goto-body)
3163 (while (and (not (eobp))
3164 (looking-at "[ \t]*$"))
3165 (gnus-delete-line))))))
3167 (defun article-narrow-to-head ()
3168 "Narrow the buffer to the head of the message.
3169 Point is left at the beginning of the narrowed-to region."
3171 (goto-char (point-min))
3172 (if (search-forward "\n\n" nil 1)
3175 (goto-char (point-min)))
3177 (defun article-goto-body ()
3178 "Place point at the start of the body."
3179 (goto-char (point-min))
3181 ;; This variable is only bound when dealing with separate
3183 (article-goto-body-goes-to-point-min-p
3185 ((search-forward "\n\n" nil t)
3188 (goto-char (point-max))
3191 (defun article-strip-multiple-blank-lines ()
3192 "Replace consecutive blank lines with one empty line."
3195 (let ((inhibit-point-motion-hooks t)
3196 (inhibit-read-only t))
3197 ;; First make all blank lines empty.
3199 (while (re-search-forward "^[ \t]+$" nil t)
3200 (unless (gnus-annotation-in-region-p
3201 (match-beginning 0) (match-end 0))
3202 (replace-match "" nil t)))
3203 ;; Then replace multiple empty lines with a single empty line.
3205 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3206 (unless (gnus-annotation-in-region-p
3207 (match-beginning 0) (match-end 0))
3208 (delete-region (match-beginning 1) (match-end 1)))))))
3210 (defun article-strip-leading-space ()
3211 "Remove all white space from the beginning of the lines in the article."
3214 (let ((inhibit-point-motion-hooks t)
3215 (inhibit-read-only t))
3217 (while (re-search-forward "^[ \t]+" nil t)
3218 (replace-match "" t t)))))
3220 (defun article-strip-trailing-space ()
3221 "Remove all white space from the end of the lines in the article."
3224 (let ((inhibit-point-motion-hooks t)
3225 (inhibit-read-only t))
3227 (while (re-search-forward "[ \t]+$" nil t)
3228 (replace-match "" t t)))))
3230 (defun article-strip-blank-lines ()
3231 "Strip leading, trailing and multiple blank lines."
3233 (article-strip-leading-blank-lines)
3234 (article-remove-trailing-blank-lines)
3235 (article-strip-multiple-blank-lines))
3237 (defun article-strip-all-blank-lines ()
3238 "Strip all blank lines."
3241 (let ((inhibit-point-motion-hooks t)
3242 (inhibit-read-only t))
3244 (while (re-search-forward "^[ \t]*\n" nil t)
3245 (replace-match "" t t)))))
3247 (defun gnus-article-narrow-to-signature ()
3248 "Narrow to the signature; return t if a signature is found, else nil."
3249 (let ((inhibit-point-motion-hooks t))
3250 (when (gnus-article-search-signature)
3252 ;; Check whether we have some limits to what we consider
3253 ;; to be a signature.
3254 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3255 (list gnus-signature-limit)))
3257 (while (setq limit (pop limits))
3258 (if (or (and (integerp limit)
3259 (< (- (point-max) (point)) limit))
3261 (< (count-lines (point) (point-max)) limit))
3262 (and (functionp limit)
3264 (and (stringp limit)
3265 (not (re-search-forward limit nil t))))
3266 () ; This limit did not succeed.
3270 (narrow-to-region (point) (point-max))
3273 (defun gnus-article-search-signature ()
3274 "Search the current buffer for the signature separator.
3275 Put point at the beginning of the signature separator."
3276 (let ((cur (point)))
3277 (goto-char (point-max))
3278 (if (if (stringp gnus-signature-separator)
3279 (re-search-backward gnus-signature-separator nil t)
3280 (let ((seps gnus-signature-separator))
3282 (not (re-search-backward (car seps) nil t)))
3289 (defun gnus-article-hidden-arg ()
3290 "Return the current prefix arg as a number, or 0 if no prefix."
3291 (list (if current-prefix-arg
3292 (prefix-numeric-value current-prefix-arg)
3295 (defun gnus-article-check-hidden-text (type arg)
3296 "Return nil if hiding is necessary.
3297 Arg can be nil or a number. nil and positive means hide, negative
3298 means show, 0 means toggle."
3301 (let ((hide (gnus-article-hidden-text-p type)))
3307 (gnus-article-show-hidden-text type)
3310 (if (eq hide 'hidden)
3312 (gnus-article-show-hidden-text type)
3316 (defun gnus-article-hidden-text-p (type)
3317 "Say whether the current buffer contains hidden text of type TYPE."
3318 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3320 (not (get-text-property pos 'invisible))
3321 (not (get-text-property pos 'dummy-invisible)))
3323 (text-property-any (1+ pos) (point-max) 'article-type type)))
3328 (defun gnus-article-show-hidden-text (type &optional dummy)
3329 "Show all hidden text of type TYPE.
3330 Originally it is hide instead of DUMMY."
3331 (let ((inhibit-read-only t)
3332 (inhibit-point-motion-hooks t))
3333 (gnus-remove-text-properties-when
3335 (point-min) (point-max)
3336 (cons 'article-type (cons type
3337 gnus-hidden-properties)))
3338 (gnus-delete-wash-type type)))
3340 (defconst article-time-units
3341 `((year . ,(* 365.25 24 60 60))
3342 (week . ,(* 7 24 60 60))
3343 (day . ,(* 24 60 60))
3347 "Mapping from time units to seconds.")
3349 (defun gnus-article-forward-header ()
3350 "Move point to the start of the next header.
3351 If the current header is a continuation header, this can be several
3356 (if (looking-at "[ \t]+[^ \t]")
3360 (defun article-date-ut (&optional type highlight)
3361 "Convert DATE date to universal time in the current article.
3362 If TYPE is `local', convert to local time; if it is `lapsed', output
3363 how much time has lapsed since DATE. For `lapsed', the value of
3364 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3365 should replace the \"Date:\" one, or should be added below it."
3366 (interactive (list 'ut t))
3367 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3368 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3372 (article-lapsed-timer
3376 (case-fold-search t)
3377 (inhibit-read-only t)
3378 (inhibit-point-motion-hooks t)
3379 pos date bface eface)
3383 (goto-char (point-min))
3384 (while (or (setq date (get-text-property (setq pos (point))
3386 (when (setq pos (next-single-property-change
3387 (point) 'original-date))
3388 (setq date (get-text-property pos 'original-date))
3390 (narrow-to-region pos (or (text-property-any pos (point-max)
3393 (goto-char (point-min))
3394 (when (re-search-forward tdate-regexp nil t)
3395 (setq bface (get-text-property (point-at-bol) 'face)
3396 eface (get-text-property (1- (point-at-eol)) 'face)))
3397 (goto-char (point-min))
3399 ;; Delete any old Date headers.
3400 (while (re-search-forward date-regexp nil t)
3402 (delete-region (point-at-bol) (progn
3403 (gnus-article-forward-header)
3405 (delete-region (point-at-bol) (progn
3406 (gnus-article-forward-header)
3409 (setq pos (point))))
3410 (when (and (not pos)
3411 (re-search-forward tdate-regexp nil t))
3413 (gnus-goto-char pos)
3414 (insert (article-make-date-line date (or type 'ut)))
3420 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3421 (put-text-property (match-beginning 1) (1+ (match-end 1))
3423 (put-text-property (match-beginning 2) (match-end 2)
3425 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3426 (goto-char (point-max))
3429 (defun article-make-date-line (date type)
3430 "Return a DATE line of TYPE."
3431 (unless (memq type '(local ut original user iso8601 lapsed english))
3432 (error "Unknown conversion type: %s" type))
3434 (let ((time (date-to-time date)))
3436 ;; Convert to the local timezone.
3438 (concat "Date: " (message-make-date time)))
3439 ;; Convert to Universal Time.
3444 (let* ((e (parse-time-string date))
3445 (tm (apply 'encode-time e))
3447 (ls (- (cadr tm) (car (current-time-zone time)))))
3448 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3449 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3453 ;; Get the original date from the article.
3454 ((eq type 'original)
3455 (concat "Date: " (if (string-match "\n+$" date)
3456 (substring date 0 (match-beginning 0))
3458 ;; Let the user define the format.
3460 (let ((format (or (condition-case nil
3461 (with-current-buffer gnus-summary-buffer
3462 gnus-article-time-format)
3464 gnus-article-time-format)))
3465 (if (functionp format)
3466 (funcall format time)
3467 (concat "Date: " (format-time-string format time)))))
3470 (let ((tz (car (current-time-zone time))))
3473 (format-time-string "%Y%m%dT%H%M%S" time)
3474 (format "%s%02d%02d"
3475 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3476 (/ (% (abs tz) 3600) 60)))))
3477 ;; Do an X-Sent lapsed format.
3479 ;; If the date is seriously mangled, the timezone functions are
3480 ;; liable to bug out, so we ignore all errors.
3481 (let* ((now (current-time))
3482 (real-time (subtract-time now time))
3483 (real-sec (and real-time
3484 (+ (* (float (car real-time)) 65536)
3486 (sec (and real-time (abs real-sec)))
3496 ;; This is a bit convoluted, but basically we go
3497 ;; through the time units for years, weeks, etc,
3498 ;; and divide things to see whether that results
3499 ;; in positive answers.
3502 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3503 ;; The (remaining) seconds are too few to
3504 ;; be divided into this time unit.
3506 ;; It's big enough, so we output it.
3507 (setq sec (- sec (* num (cdr unit))))
3509 (concat (if prev ", " "") (int-to-string
3511 " " (symbol-name (car unit))
3512 (if (> num 1) "s" ""))
3514 article-time-units "")
3515 ;; If dates are odd, then it might appear like the
3516 ;; article was sent in the future.
3519 " in the future"))))))
3520 ;; Display the date in proper English
3522 (let ((dtime (decode-time time)))
3525 (number-to-string (nth 3 dtime))
3526 (let ((digit (% (nth 3 dtime) 10)))
3528 ((memq (nth 3 dtime) '(11 12 13)) "th")
3534 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3536 (number-to-string (nth 5 dtime))
3538 (format "%02d" (nth 2 dtime))
3540 (format "%02d" (nth 1 dtime)))))))
3542 (format "Date: %s (from Gnus)" date))))
3544 (defun article-date-local (&optional highlight)
3545 "Convert the current article date to the local timezone."
3546 (interactive (list t))
3547 (article-date-ut 'local highlight))
3549 (defun article-date-english (&optional highlight)
3550 "Convert the current article date to something that is proper English."
3551 (interactive (list t))
3552 (article-date-ut 'english highlight))
3554 (defun article-date-original (&optional highlight)
3555 "Convert the current article date to what it was originally.
3556 This is only useful if you have used some other date conversion
3557 function and want to see what the date was before converting."
3558 (interactive (list t))
3559 (article-date-ut 'original highlight))
3561 (defun article-date-lapsed (&optional highlight)
3562 "Convert the current article date to time lapsed since it was sent."
3563 (interactive (list t))
3564 (article-date-ut 'lapsed highlight))
3566 (defun article-update-date-lapsed ()
3567 "Function to be run from a timer to update the lapsed time line."
3569 (let (deactivate-mark)
3574 (set-buffer (window-buffer w))
3575 (when (eq major-mode 'gnus-article-mode)
3576 (let ((mark (point-marker)))
3577 (goto-char (point-min))
3578 (when (re-search-forward "^X-Sent:" nil t)
3579 (article-date-lapsed t))
3580 (goto-char (marker-position mark))
3581 (move-marker mark nil))))
3584 (defun gnus-start-date-timer (&optional n)
3585 "Start a timer to update the X-Sent header in the article buffers.
3586 The numerical prefix says how frequently (in seconds) the function
3591 (gnus-stop-date-timer)
3592 (setq article-lapsed-timer
3593 (run-at-time 1 n 'article-update-date-lapsed)))
3595 (defun gnus-stop-date-timer ()
3596 "Stop the X-Sent timer."
3598 (when article-lapsed-timer
3599 (nnheader-cancel-timer article-lapsed-timer)
3600 (setq article-lapsed-timer nil)))
3602 (defun article-date-user (&optional highlight)
3603 "Convert the current article date to the user-defined format.
3604 This format is defined by the `gnus-article-time-format' variable."
3605 (interactive (list t))
3606 (article-date-ut 'user highlight))
3608 (defun article-date-iso8601 (&optional highlight)
3609 "Convert the current article date to ISO8601."
3610 (interactive (list t))
3611 (article-date-ut 'iso8601 highlight))
3613 (defmacro gnus-article-save-original-date (&rest forms)
3614 "Save the original date as a text property and evaluate FORMS."
3615 `(let* ((case-fold-search t)
3617 (goto-char (point-min))
3618 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3621 (date (when (and start
3622 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3624 (buffer-substring-no-properties start
3625 (match-beginning 0)))))
3626 (goto-char (point-max))
3627 (skip-chars-backward "\n")
3628 (put-text-property (point-min) (point) 'original-date date)
3630 (goto-char (point-max))
3631 (skip-chars-backward "\n")
3632 (put-text-property (point-min) (point) 'original-date date)))
3634 ;; (defun article-show-all ()
3635 ;; "Show all hidden text in the article buffer."
3638 ;; (let ((inhibit-read-only t))
3639 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3641 (defun article-remove-leading-whitespace ()
3642 "Remove excessive whitespace from all headers."
3646 (let ((inhibit-read-only t))
3647 (article-narrow-to-head)
3648 (goto-char (point-min))
3649 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3650 (delete-region (match-beginning 1) (match-end 1)))))))
3652 (defun article-emphasize (&optional arg)
3653 "Emphasize text according to `gnus-emphasis-alist'."
3654 (interactive (gnus-article-hidden-arg))
3655 (unless (gnus-article-check-hidden-text 'emphasis arg)
3659 (with-current-buffer gnus-summary-buffer
3660 gnus-article-emphasis-alist)
3662 gnus-emphasis-alist))
3663 (inhibit-read-only t)
3664 (props (append '(article-type emphasis)
3665 gnus-hidden-properties))
3666 regexp elem beg invisible visible face)
3669 (while (setq elem (pop alist))
3671 (setq regexp (car elem)
3672 invisible (nth 1 elem)
3673 visible (nth 2 elem)
3675 (while (re-search-forward regexp nil t)
3676 (when (and (match-beginning visible) (match-beginning invisible))
3677 (gnus-article-hide-text
3678 (match-beginning invisible) (match-end invisible) props)
3679 (gnus-article-unhide-text-type
3680 (match-beginning visible) (match-end visible) 'emphasis)
3681 (gnus-put-overlay-excluding-newlines
3682 (match-beginning visible) (match-end visible) 'face face)
3683 (gnus-add-wash-type 'emphasis)
3684 (goto-char (match-end invisible)))))))))
3686 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3687 "Setup newsgroup emphasis alist."
3688 (unless gnus-article-emphasis-alist
3689 (let ((name (and gnus-newsgroup-name
3690 (gnus-group-real-name gnus-newsgroup-name))))
3691 (make-local-variable 'gnus-article-emphasis-alist)
3692 (setq gnus-article-emphasis-alist
3694 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3695 (while (setq elem (pop alist))
3696 (when (and name (string-match (car elem) name))
3698 highlight (copy-sequence (cdr elem)))))
3700 (copy-sequence highlight-words)
3701 (if gnus-newsgroup-name
3702 (copy-sequence (gnus-group-find-parameter
3703 gnus-newsgroup-name 'highlight-words t)))
3704 gnus-emphasis-alist)))))
3706 (defvar gnus-summary-article-menu)
3707 (defvar gnus-summary-post-menu)
3709 ;;; Saving functions.
3711 (defun gnus-article-save (save-buffer file &optional num)
3712 "Save the currently selected article."
3713 (when (or (get gnus-default-article-saver :headers)
3714 (not gnus-save-all-headers))
3715 ;; Remove headers according to `gnus-saved-headers' or the value
3716 ;; of the `:headers' property that the saver function might have.
3717 (let ((gnus-visible-headers
3718 (or (symbol-value (get gnus-default-article-saver :headers))
3719 gnus-saved-headers gnus-visible-headers))
3720 (gnus-article-buffer save-buffer))
3722 (set-buffer save-buffer)
3723 (article-hide-headers 1 t))))
3724 (save-window-excursion
3725 (if (not gnus-default-article-saver)
3726 (error "No default saver is defined")
3727 ;; !!! Magic! The saving functions all save
3728 ;; `gnus-save-article-buffer' (or so they think), but we
3729 ;; bind that variable to our save-buffer.
3730 (set-buffer gnus-article-buffer)
3731 (let* ((gnus-save-article-buffer save-buffer)
3734 ((not gnus-prompt-before-saving) 'default)
3735 ((eq gnus-prompt-before-saving 'always) nil)
3737 (gnus-number-of-articles-to-be-saved
3738 (when (eq gnus-prompt-before-saving t)
3740 (set-buffer gnus-article-current-summary)
3741 (funcall gnus-default-article-saver filename)))))
3743 (defun gnus-read-save-file-name (prompt &optional filename
3744 function group headers variable
3747 (funcall function group headers (symbol-value variable)))
3752 ((eq filename 'default)
3758 (when (symbol-value dir-var)
3759 (setq default-name (expand-file-name
3760 (file-name-nondirectory default-name)
3761 (symbol-value dir-var))))
3762 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3765 (if (and gnus-number-of-articles-to-be-saved
3766 (> gnus-number-of-articles-to-be-saved 1))
3767 (format "these %d articles"
3768 gnus-number-of-articles-to-be-saved)
3771 ;; Let the split methods have their say.
3773 ;; No split name was found.
3776 (concat prompt " (default "
3777 (file-name-nondirectory default-name) "): ")
3778 (file-name-directory default-name)
3780 ;; A single group name is returned.
3781 ((stringp split-name)
3783 (funcall function split-name headers
3784 (symbol-value variable)))
3786 (concat prompt " (default "
3787 (file-name-nondirectory default-name) "): ")
3788 (file-name-directory default-name)
3790 ;; A single split name was found
3791 ((= 1 (length split-name))
3792 (let* ((name (expand-file-name
3794 gnus-article-save-directory))
3795 (dir (cond ((file-directory-p name)
3796 (file-name-as-directory name))
3797 ((file-exists-p name) name)
3798 (t gnus-article-save-directory))))
3800 (concat prompt " (default " name "): ")
3802 ;; A list of splits was found.
3804 (setq split-name (nreverse split-name))
3806 (let ((file-name-history
3807 (nconc split-name file-name-history)))
3811 (concat prompt " (`M-p' for defaults): ")
3812 gnus-article-save-directory
3814 gnus-article-save-directory)))
3815 (car (push result file-name-history)))))))
3816 ;; Create the directory.
3817 (gnus-make-directory (file-name-directory file))
3818 ;; If we have read a directory, we append the default file name.
3819 (when (file-directory-p file)
3820 (setq file (expand-file-name (file-name-nondirectory
3822 (file-name-as-directory file))))
3823 ;; Possibly translate some characters.
3824 (nnheader-translate-file-chars file))))))
3825 (gnus-make-directory (file-name-directory result))
3827 (set variable result))
3829 (set dir-var (file-name-directory result)))
3832 (defun gnus-article-archive-name (group)
3833 "Return the first instance of an \"Archive-name\" in the current buffer."
3834 (let ((case-fold-search t))
3835 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3836 (nnheader-concat gnus-article-save-directory
3837 (match-string 1)))))
3839 (defun gnus-article-nndoc-name (group)
3840 "If GROUP is an nndoc group, return the name of the parent group."
3841 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3842 (gnus-group-get-parameter group 'save-article-group)))
3844 (defun gnus-summary-save-in-rmail (&optional filename)
3845 "Append this article to Rmail file.
3846 Optional argument FILENAME specifies file name.
3847 Directory to save to is default to `gnus-article-save-directory'."
3848 (setq filename (gnus-read-save-file-name
3849 "Save %s in rmail file" filename
3850 gnus-rmail-save-name gnus-newsgroup-name
3851 gnus-current-headers 'gnus-newsgroup-last-rmail))
3852 (gnus-eval-in-buffer-window gnus-save-article-buffer
3856 (gnus-output-to-rmail filename))))
3859 (defun gnus-summary-save-in-mail (&optional filename)
3860 "Append this article to Unix mail file.
3861 Optional argument FILENAME specifies file name.
3862 Directory to save to is default to `gnus-article-save-directory'."
3863 (setq filename (gnus-read-save-file-name
3864 "Save %s in Unix mail file" filename
3865 gnus-mail-save-name gnus-newsgroup-name
3866 gnus-current-headers 'gnus-newsgroup-last-mail))
3867 (gnus-eval-in-buffer-window gnus-save-article-buffer
3871 (if (and (file-readable-p filename)
3872 (file-regular-p filename)
3873 (mail-file-babyl-p filename))
3874 (rmail-output-to-rmail-file filename t)
3875 (gnus-output-to-mail filename)))))
3878 (put 'gnus-summary-save-in-file :decode t)
3879 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3880 (defun gnus-summary-save-in-file (&optional filename overwrite)
3881 "Append this article to file.
3882 Optional argument FILENAME specifies file name.
3883 Directory to save to is default to `gnus-article-save-directory'."
3884 (setq filename (gnus-read-save-file-name
3885 "Save %s in file" filename
3886 gnus-file-save-name gnus-newsgroup-name
3887 gnus-current-headers 'gnus-newsgroup-last-file))
3888 (gnus-eval-in-buffer-window gnus-save-article-buffer
3892 (when (and overwrite
3893 (file-exists-p filename))
3894 (delete-file filename))
3895 (gnus-output-to-file filename))))
3898 (put 'gnus-summary-write-to-file :decode t)
3899 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3900 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3901 (defun gnus-summary-write-to-file (&optional filename)
3902 "Write this article to a file, overwriting it if the file exists.
3903 Optional argument FILENAME specifies file name.
3904 The directory to save in defaults to `gnus-article-save-directory'."
3905 (setq filename (gnus-read-save-file-name
3906 "Save %s in file" filename
3907 gnus-file-save-name gnus-newsgroup-name
3908 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3909 (gnus-summary-save-in-file filename t))
3911 (put 'gnus-summary-save-body-in-file :decode t)
3912 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3913 "Append this article body to a file.
3914 Optional argument FILENAME specifies file name.
3915 The directory to save in defaults to `gnus-article-save-directory'."
3916 (setq filename (gnus-read-save-file-name
3917 "Save %s body in file" filename
3918 gnus-file-save-name gnus-newsgroup-name
3919 gnus-current-headers 'gnus-newsgroup-last-file))
3920 (gnus-eval-in-buffer-window gnus-save-article-buffer
3924 (when (article-goto-body)
3925 (narrow-to-region (point) (point-max)))
3926 (when (and overwrite
3927 (file-exists-p filename))
3928 (delete-file filename))
3929 (gnus-output-to-file filename))))
3932 (put 'gnus-summary-write-body-to-file :decode t)
3933 (put 'gnus-summary-write-body-to-file
3934 :function 'gnus-summary-save-body-in-file)
3935 (defun gnus-summary-write-body-to-file (&optional filename)
3936 "Write this article body to a file, overwriting it if the file exists.
3937 Optional argument FILENAME specifies file name.
3938 The directory to save in defaults to `gnus-article-save-directory'."
3939 (setq filename (gnus-read-save-file-name
3940 "Save %s body in file" filename
3941 gnus-file-save-name gnus-newsgroup-name
3942 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3943 (gnus-summary-save-body-in-file filename t))
3945 (defun gnus-summary-save-in-pipe (&optional command)
3946 "Pipe this article to subprocess."
3948 (cond ((and (eq command 'default)
3949 gnus-last-shell-command)
3950 gnus-last-shell-command)
3955 "Shell command on %s: "
3956 (if (and gnus-number-of-articles-to-be-saved
3957 (> gnus-number-of-articles-to-be-saved 1))
3958 (format "these %d articles"
3959 gnus-number-of-articles-to-be-saved)
3961 gnus-last-shell-command))))
3962 (when (string-equal command "")
3963 (if gnus-last-shell-command
3964 (setq command gnus-last-shell-command)
3965 (error "A command is required")))
3966 (gnus-eval-in-buffer-window gnus-article-buffer
3969 (shell-command-on-region (point-min) (point-max) command nil)))
3970 (setq gnus-last-shell-command command))
3972 (defun gnus-summary-pipe-to-muttprint (&optional command)
3973 "Pipe this article to muttprint."
3974 (setq command (read-string
3975 "Print using command: " gnus-summary-muttprint-program
3976 nil gnus-summary-muttprint-program))
3977 (gnus-summary-save-in-pipe command))
3979 ;;; Article file names when saving.
3981 (defun gnus-capitalize-newsgroup (newsgroup)
3982 "Capitalize NEWSGROUP name."
3983 (when (not (zerop (length newsgroup)))
3984 (concat (char-to-string (upcase (aref newsgroup 0)))
3985 (substring newsgroup 1))))
3987 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3988 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3989 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3990 Otherwise, it is like ~/News/news/group/num."
3993 (concat (if (gnus-use-long-file-name 'not-save)
3994 (gnus-capitalize-newsgroup newsgroup)
3995 (gnus-newsgroup-directory-form newsgroup))
3996 "/" (int-to-string (mail-header-number headers)))
3997 gnus-article-save-directory)))
3999 (string-equal (file-name-directory default)
4000 (file-name-directory last-file))
4001 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4003 (or last-file default))))
4005 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4006 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4007 If variable `gnus-use-long-file-name' is non-nil, it is
4008 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4011 (concat (if (gnus-use-long-file-name 'not-save)
4013 (gnus-newsgroup-directory-form newsgroup))
4014 "/" (int-to-string (mail-header-number headers)))
4015 gnus-article-save-directory)))
4017 (string-equal (file-name-directory default)
4018 (file-name-directory last-file))
4019 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4021 (or last-file default))))
4023 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4024 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4025 If variable `gnus-use-long-file-name' is non-nil, it is
4026 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4029 (if (gnus-use-long-file-name 'not-save)
4032 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4034 gnus-article-save-directory)))
4036 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4037 "Generate file name from sender."
4038 (let ((from (mail-header-from headers)))
4040 (if (and from (string-match "\\([^ <]+\\)@" from))
4041 (match-string 1 from)
4043 gnus-article-save-directory)))
4045 (defun article-verify-x-pgp-sig ()
4047 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4049 (if (gnus-buffer-live-p gnus-original-article-buffer)
4050 (let ((sig (with-current-buffer gnus-original-article-buffer
4051 (gnus-fetch-field "X-PGP-Sig")))
4055 (mml2015-clear-verify-function))
4057 (insert-buffer-substring gnus-original-article-buffer)
4058 (setq items (split-string sig))
4059 (message-narrow-to-head)
4060 (let ((inhibit-point-motion-hooks t)
4061 (case-fold-search t))
4062 ;; Don't verify multiple headers.
4063 (setq headers (mapconcat (lambda (header)
4065 (mail-fetch-field header)
4067 (split-string (nth 1 items) ",") "")))
4068 (delete-region (point-min) (point-max))
4069 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4070 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4075 (if (looking-at "^-")
4078 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4079 (insert "Version: " (car items) "\n\n")
4080 (insert (mapconcat 'identity (cddr items) "\n"))
4081 (insert "\n-----END PGP SIGNATURE-----\n")
4082 (let ((mm-security-handle (list (format "multipart/signed"))))
4083 (mml2015-clean-buffer)
4084 (let ((coding-system-for-write (or gnus-newsgroup-charset
4086 (funcall (mml2015-clear-verify-function)))
4088 (or (mm-handle-multipart-ctl-parameter
4089 mm-security-handle 'gnus-details)
4090 (mm-handle-multipart-ctl-parameter
4091 mm-security-handle 'gnus-info)))))
4093 (let ((inhibit-read-only t) bface eface)
4095 (message-narrow-to-head)
4096 (goto-char (point-max))
4098 (setq bface (get-text-property (point-at-bol) 'face)
4099 eface (get-text-property (1- (point-at-eol)) 'face))
4100 (message-remove-header "X-Gnus-PGP-Verify")
4101 (if (re-search-forward "^X-PGP-Sig:" nil t)
4103 (goto-char (point-max)))
4104 (narrow-to-region (point) (point))
4105 (insert "X-Gnus-PGP-Verify: " info "\n")
4106 (goto-char (point-min))
4109 (if (not (looking-at "^[ \t]"))
4113 (goto-char (point-min))
4114 (when (looking-at "\\([^:]+\\): *")
4115 (put-text-property (match-beginning 1) (1+ (match-end 1))
4117 (put-text-property (match-end 0) (point-max)
4118 'face eface)))))))))
4120 (defun article-verify-cancel-lock ()
4121 "Verify Cancel-Lock header."
4123 (if (gnus-buffer-live-p gnus-original-article-buffer)
4124 (canlock-verify gnus-original-article-buffer)))
4131 (setq afunc (car func)
4134 gfunc (intern (format "gnus-%s" func))))
4136 (when (fboundp afunc)
4137 `(lambda (&optional interactive &rest args)
4138 ,(documentation afunc t)
4139 (interactive (list t))
4141 (set-buffer gnus-article-buffer)
4143 (call-interactively ',afunc)
4144 (apply ',afunc args))))))))
4145 '(article-hide-headers
4146 article-verify-x-pgp-sig
4147 article-verify-cancel-lock
4148 article-hide-boring-headers
4149 article-treat-overstrike
4150 article-treat-ansi-sequences
4151 article-fill-long-lines
4152 article-capitalize-sentences
4154 article-remove-leading-whitespace
4155 article-display-x-face
4156 article-display-face
4157 article-de-quoted-unreadable
4158 article-de-base64-unreadable
4161 article-unsplit-urls
4162 article-hide-list-identifiers
4163 article-strip-banner
4166 article-hide-signature
4167 article-strip-headers-in-body
4168 article-remove-trailing-blank-lines
4169 article-strip-leading-blank-lines
4170 article-strip-multiple-blank-lines
4171 article-strip-leading-space
4172 article-strip-trailing-space
4173 article-strip-blank-lines
4174 article-strip-all-blank-lines
4176 article-date-english
4177 article-date-iso8601
4178 article-date-original
4180 article-decode-mime-words
4181 article-decode-charset
4182 article-decode-encoded-words
4186 article-treat-dumbquotes
4187 article-normalize-headers
4188 ;;(article-show-all . gnus-article-show-all-headers)
4192 ;;; Gnus article mode
4195 (put 'gnus-article-mode 'mode-class 'special)
4197 (set-keymap-parent gnus-article-mode-map widget-keymap)
4199 (gnus-define-keys gnus-article-mode-map
4200 " " gnus-article-goto-next-page
4201 "\177" gnus-article-goto-prev-page
4202 [delete] gnus-article-goto-prev-page
4203 [backspace] gnus-article-goto-prev-page
4204 "\C-c^" gnus-article-refer-article
4205 "h" gnus-article-show-summary
4206 "s" gnus-article-show-summary
4207 "\C-c\C-m" gnus-article-mail
4208 "?" gnus-article-describe-briefly
4209 "e" gnus-summary-edit-article
4210 "<" beginning-of-buffer
4212 "\C-c\C-i" gnus-info-find-node
4214 "R" gnus-article-reply-with-original
4215 "F" gnus-article-followup-with-original
4216 "\C-hk" gnus-article-describe-key
4217 "\C-hc" gnus-article-describe-key-briefly
4218 "\C-hb" gnus-article-describe-bindings
4220 "\C-d" gnus-article-read-summary-keys
4221 "\M-*" gnus-article-read-summary-keys
4222 "\M-#" gnus-article-read-summary-keys
4223 "\M-^" gnus-article-read-summary-keys
4224 "\M-g" gnus-article-read-summary-keys)
4226 (substitute-key-definition
4227 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4229 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4230 "W" gnus-article-wide-reply-with-original)
4231 (if (featurep 'xemacs)
4232 (set-keymap-default-binding gnus-article-send-map
4233 'gnus-article-read-summary-send-keys)
4234 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4236 (defun gnus-article-make-menu-bar ()
4237 (unless (boundp 'gnus-article-commands-menu)
4238 (gnus-summary-make-menu-bar))
4239 (gnus-turn-off-edit-menu 'article)
4240 (unless (boundp 'gnus-article-article-menu)
4242 gnus-article-article-menu gnus-article-mode-map ""
4244 ["Scroll forwards" gnus-article-goto-next-page t]
4245 ["Scroll backwards" gnus-article-goto-prev-page t]
4246 ["Show summary" gnus-article-show-summary t]
4247 ["Fetch Message-ID at point" gnus-article-refer-article t]
4248 ["Mail to address at point" gnus-article-mail t]
4249 ["Send a bug report" gnus-bug t]))
4252 gnus-article-treatment-menu gnus-article-mode-map ""
4253 ;; Fixme: this should use :active (and maybe :visible).
4255 ["Hide headers" gnus-article-hide-headers t]
4256 ["Hide signature" gnus-article-hide-signature t]
4257 ["Hide citation" gnus-article-hide-citation t]
4258 ["Treat overstrike" gnus-article-treat-overstrike t]
4259 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4260 ["Remove carriage return" gnus-article-remove-cr t]
4261 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4262 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4263 ["Remove base64" gnus-article-de-base64-unreadable t]
4264 ["Treat html" gnus-article-wash-html t]
4265 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4266 ["Decode HZ" gnus-article-decode-HZ t]))
4268 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4270 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4272 (gnus-run-hooks 'gnus-article-menu-hook)))
4274 (defun gnus-article-mode ()
4275 "Major mode for displaying an article.
4277 All normal editing commands are switched off.
4279 The following commands are available in addition to all summary mode
4281 \\<gnus-article-mode-map>
4282 \\[gnus-article-next-page]\t Scroll the article one page forwards
4283 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4284 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4285 \\[gnus-article-show-summary]\t Display the summary buffer
4286 \\[gnus-article-mail]\t Send a reply to the address near point
4287 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4288 \\[gnus-info-find-node]\t Go to the Gnus info node"
4290 (kill-all-local-variables)
4291 (gnus-simplify-mode-line)
4292 (setq mode-name "Article")
4293 (setq major-mode 'gnus-article-mode)
4294 (make-local-variable 'minor-mode-alist)
4295 (use-local-map gnus-article-mode-map)
4296 (when (gnus-visual-p 'article-menu 'menu)
4297 (gnus-article-make-menu-bar)
4298 (when gnus-summary-tool-bar-map
4299 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4300 (gnus-update-format-specifications nil 'article-mode)
4301 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4302 (set (make-local-variable 'gnus-page-broken) nil)
4303 (make-local-variable 'gnus-button-marker-list)
4304 (make-local-variable 'gnus-article-current-summary)
4305 (make-local-variable 'gnus-article-mime-handles)
4306 (make-local-variable 'gnus-article-decoded-p)
4307 (make-local-variable 'gnus-article-mime-handle-alist)
4308 (make-local-variable 'gnus-article-wash-types)
4309 (make-local-variable 'gnus-article-image-alist)
4310 (make-local-variable 'gnus-article-charset)
4311 (make-local-variable 'gnus-article-ignored-charsets)
4312 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4314 (set (make-local-variable 'nobreak-char-display) nil)
4315 (setq cursor-in-non-selected-windows nil)
4316 (setq truncate-lines gnus-article-truncate-lines)
4317 (gnus-set-default-directory)
4318 (buffer-disable-undo)
4319 (setq buffer-read-only t
4320 show-trailing-whitespace nil)
4321 (set-syntax-table gnus-article-mode-syntax-table)
4322 (mm-enable-multibyte)
4323 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4325 (defvar gnus-button-marker-list nil
4326 "Regexp matching any of the regexps from `gnus-button-alist'.
4327 Internal variable.")
4329 (defun gnus-article-setup-buffer ()
4330 "Initialize the article buffer."
4331 (let* ((name (if gnus-single-article-buffer "*Article*"
4332 (concat "*Article " gnus-newsgroup-name "*")))
4334 (progn (string-match "\\*Article" name)
4335 (concat " *Original Article"
4336 (substring name (match-end 0))))))
4337 (setq gnus-article-buffer name)
4338 (setq gnus-original-article-buffer original)
4339 (setq gnus-article-mime-handle-alist nil)
4340 (with-current-buffer gnus-summary-buffer
4341 ;; This might be a variable local to the summary buffer.
4342 (unless gnus-single-article-buffer
4343 (setq gnus-article-buffer name)
4344 (setq gnus-original-article-buffer original)
4345 (gnus-set-global-variables)))
4346 (gnus-article-setup-highlight-words)
4347 ;; Init original article buffer.
4349 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
4350 (mm-enable-multibyte)
4351 (setq major-mode 'gnus-original-article-mode)
4352 (make-local-variable 'gnus-original-article))
4353 (if (and (get-buffer name)
4354 (with-current-buffer name
4355 (if gnus-article-edit-mode
4356 (if (y-or-n-p "Article mode edit in progress; discard? ")
4358 (set-buffer-modified-p nil)
4359 (gnus-kill-buffer name)
4362 (error "Action aborted"))
4366 (set (make-local-variable 'gnus-article-edit-mode) nil)
4367 (when gnus-article-mime-handles
4368 (mm-destroy-parts gnus-article-mime-handles)
4369 (setq gnus-article-mime-handles nil))
4370 ;; Set it to nil in article-buffer!
4371 (setq gnus-article-mime-handle-alist nil)
4372 (buffer-disable-undo)
4373 (setq buffer-read-only t)
4374 ;; This list just keeps growing if we don't reset it.
4375 (setq gnus-button-marker-list nil)
4376 (unless (eq major-mode 'gnus-article-mode)
4377 (gnus-article-mode))
4380 (set-buffer (gnus-get-buffer-create name))
4382 (make-local-variable 'gnus-summary-buffer)
4383 (setq gnus-summary-buffer
4384 (gnus-summary-buffer-name gnus-newsgroup-name))
4385 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4386 (current-buffer)))))
4388 ;; Set article window start at LINE, where LINE is the number of lines
4389 ;; from the head of the article.
4390 (defun gnus-article-set-window-start (&optional line)
4391 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4392 (when article-window
4396 (set-buffer gnus-article-buffer)
4397 (goto-char (point-min))
4400 (gnus-message 6 "Moved to bookmark")
4401 (search-forward "\n\n" nil t)
4405 (defun gnus-article-prepare (article &optional all-headers header)
4406 "Prepare ARTICLE in article mode buffer.
4407 ARTICLE should either be an article number or a Message-ID.
4408 If ARTICLE is an id, HEADER should be the article headers.
4409 If ALL-HEADERS is non-nil, no headers are hidden."
4411 ;; Make sure we start in a summary buffer.
4412 (unless (eq major-mode 'gnus-summary-mode)
4413 (set-buffer gnus-summary-buffer))
4414 (setq gnus-summary-buffer (current-buffer))
4415 (let* ((gnus-article (if header (mail-header-number header) article))
4416 (summary-buffer (current-buffer))
4417 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4418 (group gnus-newsgroup-name)
4421 (gnus-article-setup-buffer)
4422 (set-buffer gnus-article-buffer)
4423 ;; Deactivate active regions.
4424 (when (and (boundp 'transient-mark-mode)
4425 transient-mark-mode)
4426 (setq mark-active nil))
4427 (if (not (setq result (let ((inhibit-read-only t))
4428 (gnus-request-article-this-buffer
4430 ;; There is no such article.
4432 (when (and (numberp article)
4433 (not (memq article gnus-newsgroup-sparse)))
4434 (setq gnus-article-current
4435 (cons gnus-newsgroup-name article))
4436 (set-buffer gnus-summary-buffer)
4437 (setq gnus-current-article article)
4438 (if (and (memq article gnus-newsgroup-undownloaded)
4439 (not (gnus-online (gnus-find-method-for-group
4440 gnus-newsgroup-name))))
4442 (gnus-summary-set-agent-mark article)
4443 (message "Message marked for downloading"))
4444 (gnus-summary-mark-article article gnus-canceled-mark)
4445 (unless (memq article gnus-newsgroup-sparse)
4446 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4447 (if (or (eq result 'pseudo)
4448 (eq result 'nneething))
4451 (set-buffer summary-buffer)
4452 (push article gnus-newsgroup-history)
4453 (setq gnus-last-article gnus-current-article
4454 gnus-current-article 0
4455 gnus-current-headers nil
4456 gnus-article-current nil)
4457 (if (eq result 'nneething)
4458 (gnus-configure-windows 'summary)
4459 (gnus-configure-windows 'article))
4460 (gnus-set-global-variables))
4461 (let ((gnus-article-mime-handle-alist-1
4462 gnus-article-mime-handle-alist))
4463 (gnus-set-mode-line 'article)))
4464 ;; The result from the `request' was an actual article -
4465 ;; or at least some text that is now displayed in the
4467 (when (and (numberp article)
4468 (not (eq article gnus-current-article)))
4469 ;; Seems like a new article has been selected.
4470 ;; `gnus-current-article' must be an article number.
4472 (set-buffer summary-buffer)
4473 (push article gnus-newsgroup-history)
4474 (setq gnus-last-article gnus-current-article
4475 gnus-current-article article
4476 gnus-current-headers
4477 (gnus-summary-article-header gnus-current-article)
4478 gnus-article-current
4479 (cons gnus-newsgroup-name gnus-current-article))
4480 (unless (vectorp gnus-current-headers)
4481 (setq gnus-current-headers nil))
4482 (gnus-summary-goto-subject gnus-current-article)
4483 (when (gnus-summary-show-thread)
4484 ;; If the summary buffer really was folded, the
4485 ;; previous goto may not actually have gone to
4486 ;; the right article, but the thread root instead.
4488 (gnus-summary-goto-subject gnus-current-article))
4489 (gnus-run-hooks 'gnus-mark-article-hook)
4490 (gnus-set-mode-line 'summary)
4491 (when (gnus-visual-p 'article-highlight 'highlight)
4492 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4493 ;; Set the global newsgroup variables here.
4494 (gnus-set-global-variables)
4495 (setq gnus-have-all-headers
4496 (or all-headers gnus-show-all-headers))))
4498 (gnus-configure-windows 'article))
4499 (when (or (numberp article)
4501 (gnus-article-prepare-display)
4503 (goto-char (point-min))
4504 (when gnus-break-pages
4505 (gnus-narrow-to-page)))
4506 (let ((gnus-article-mime-handle-alist-1
4507 gnus-article-mime-handle-alist))
4508 (gnus-set-mode-line 'article))
4512 (set-window-point (get-buffer-window (current-buffer)) (point))
4513 (gnus-configure-windows 'article)
4517 (defun gnus-article-prepare-display ()
4518 "Make the current buffer look like a nice article."
4519 ;; Hooks for getting information from the article.
4520 ;; This hook must be called before being narrowed.
4521 (let ((gnus-article-buffer (current-buffer))
4523 (inhibit-read-only t))
4524 (unless (eq major-mode 'gnus-article-mode)
4525 (gnus-article-mode))
4526 (setq buffer-read-only nil
4527 gnus-article-wash-types nil
4528 gnus-article-image-alist nil)
4529 (gnus-run-hooks 'gnus-tmp-internal-hook)
4530 (when gnus-display-mime-function
4531 (funcall gnus-display-mime-function))
4532 (gnus-run-hooks 'gnus-article-prepare-hook)))
4535 ;;; Gnus Sticky Article Mode
4538 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4539 "Mode for sticky articles."
4540 ;; Release bindings that won't work.
4541 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4542 gnus-sticky-article-mode-map)
4543 (substitute-key-definition 'gnus-article-refer-article 'undefined
4544 gnus-sticky-article-mode-map)
4545 (dolist (k '("e" "h" "s" "F" "R"))
4546 (define-key gnus-sticky-article-mode-map k nil))
4547 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4548 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4549 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4550 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4552 (defun gnus-sticky-article (arg)
4553 "Make the current article sticky.
4554 If a prefix ARG is given, ask for a name for this sticky article buffer."
4556 (gnus-summary-show-thread)
4557 (gnus-summary-select-article nil nil 'pseudo)
4558 (let (new-art-buf-name)
4559 (gnus-eval-in-buffer-window gnus-article-buffer
4560 (setq new-art-buf-name
4564 (read-from-minibuffer "Sticky article buffer name: ")
4565 (gnus-with-article-headers
4566 (gnus-article-goto-header "subject")
4567 (setq new-art-buf-name
4568 (buffer-substring-no-properties
4569 (line-beginning-position) (line-end-position)))
4570 (goto-char (point-min))
4571 (gnus-article-goto-header "from")
4572 (setq new-art-buf-name
4574 new-art-buf-name ", "
4575 (buffer-substring-no-properties
4576 (line-beginning-position) (line-end-position))))
4577 (goto-char (point-min))
4578 (gnus-article-goto-header "date")
4579 (setq new-art-buf-name
4581 new-art-buf-name ", "
4582 (buffer-substring-no-properties
4583 (line-beginning-position) (line-end-position))))))
4585 (if (and (gnus-buffer-live-p new-art-buf-name)
4586 (with-current-buffer new-art-buf-name
4587 (eq major-mode 'gnus-sticky-article-mode)))
4588 (switch-to-buffer new-art-buf-name)
4589 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4590 (gnus-sticky-article-mode))
4591 (setq gnus-article-buffer new-art-buf-name))
4592 (gnus-summary-recenter)
4593 (gnus-summary-position-point))
4595 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4596 "Kill the given sticky article BUFFER.
4597 If none is given, assume the current buffer and kill it if it has
4598 `gnus-sticky-article-mode'."
4601 (setq buffer (current-buffer)))
4602 (with-current-buffer buffer
4603 (when (eq major-mode 'gnus-sticky-article-mode)
4604 (gnus-kill-buffer buffer))))
4606 (defun gnus-kill-sticky-article-buffers (arg)
4607 "Kill all sticky article buffers.
4608 If a prefix ARG is given, ask for confirmation."
4610 (dolist (buf (gnus-buffers))
4611 (with-current-buffer buf
4612 (when (eq major-mode 'gnus-sticky-article-mode)
4614 (gnus-kill-buffer buf)
4615 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4616 (gnus-kill-buffer buf)))))))
4619 ;;; Gnus MIME viewing functions
4622 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4623 "Format of the MIME buttons.
4625 Valid specifiers include:
4627 %T MIME type, along with additional info
4628 %n The `name' parameter
4629 %d The description, if any
4630 %l The length of the encoded part
4631 %p The part identifier number
4632 %e Dots if the part isn't displayed
4634 General format specifiers can also be used. See Info node
4635 `(gnus)Formatting Variables'.")
4637 (defvar gnus-mime-button-line-format-alist
4638 '((?t gnus-tmp-type ?s)
4639 (?T gnus-tmp-type-long ?s)
4640 (?n gnus-tmp-name ?s)
4641 (?d gnus-tmp-description ?s)
4643 (?l gnus-tmp-length ?d)
4644 (?e gnus-tmp-dots ?s)))
4646 (defvar gnus-mime-button-commands
4647 '((gnus-article-press-button "\r" "Toggle Display")
4648 (gnus-mime-view-part "v" "View Interactively...")
4649 (gnus-mime-view-part-as-type "t" "View As Type...")
4650 (gnus-mime-view-part-as-charset "C" "View As charset...")
4651 (gnus-mime-save-part "o" "Save...")
4652 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4653 (gnus-mime-replace-part "r" "Replace part")
4654 (gnus-mime-delete-part "d" "Delete part")
4655 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4656 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4657 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4658 (gnus-mime-view-part-externally "e" "View Externally")
4659 (gnus-mime-print-part "p" "Print")
4660 (gnus-mime-pipe-part "|" "Pipe To Command...")
4661 (gnus-mime-action-on-part "." "Take action on the part...")))
4663 (defun gnus-article-mime-part-status ()
4664 (if gnus-article-mime-handle-alist-1
4665 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4667 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4670 (defvar gnus-mime-button-map
4671 (let ((map (make-sparse-keymap)))
4672 (define-key map gnus-mouse-2 'gnus-article-push-button)
4673 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4674 (dolist (c gnus-mime-button-commands)
4675 (define-key map (cadr c) (car c)))
4679 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4681 ,@(mapcar (lambda (c)
4682 (vector (caddr c) (car c) :active t))
4683 gnus-mime-button-commands)))
4685 (defun gnus-mime-button-menu (event prefix)
4686 "Construct a context-sensitive menu of MIME commands."
4687 (interactive "e\nP")
4688 (save-window-excursion
4689 (let ((pos (event-start event)))
4690 (select-window (posn-window pos))
4691 (goto-char (posn-point pos))
4692 (gnus-article-check-buffer)
4693 (popup-menu gnus-mime-button-menu nil prefix))))
4695 (defun gnus-mime-view-all-parts (&optional handles)
4696 "View all the MIME parts."
4698 (with-current-buffer gnus-article-buffer
4699 (let ((handles (or handles gnus-article-mime-handles))
4700 (mail-parse-charset gnus-newsgroup-charset)
4701 (mail-parse-ignored-charsets
4702 (with-current-buffer gnus-summary-buffer
4703 gnus-newsgroup-ignored-charsets)))
4705 (mm-remove-parts handles)
4706 (goto-char (point-min))
4707 (or (search-forward "\n\n") (goto-char (point-max)))
4708 (let ((inhibit-read-only t))
4709 (delete-region (point) (point-max))
4710 (mm-display-parts handles))))))
4712 (defun gnus-article-jump-to-part (n)
4713 "Jump to MIME part N."
4715 (pop-to-buffer gnus-article-buffer)
4716 ;; FIXME: why is it necessary?
4718 (let ((parts (length gnus-article-mime-handle-alist)))
4721 (read-string ;; Emacs 21 doesn't have `read-number'.
4722 (format "Jump to part (2..%s): " parts)))))
4723 (unless (and (integerp n) (<= n parts) (>= n 1))
4726 (gnus-message 7 "Invalid part `%s', using %s instead."
4729 (gnus-message 9 "Jumping to part %s." n)
4730 (cond ((>= gnus-auto-select-part 1)
4731 (while (and (<= n parts)
4732 (not (gnus-article-goto-part n)))
4734 ((< gnus-auto-select-part 0)
4735 (while (and (>= n 1)
4736 (not (gnus-article-goto-part n)))
4739 (gnus-article-goto-part n)))))
4742 (defsubst gnus-article-edit-part (handles &optional current-id)
4743 "Edit an article in order to delete a mime part.
4744 This function is exclusively used by `gnus-mime-save-part-and-strip'
4745 and `gnus-mime-delete-part', and not provided at run-time normally."
4746 (gnus-article-edit-article
4748 (buffer-disable-undo)
4750 (let ((mail-parse-charset (or gnus-article-charset
4751 ',gnus-newsgroup-charset))
4752 (mail-parse-ignored-charsets
4753 (or gnus-article-ignored-charsets
4754 ',gnus-newsgroup-ignored-charsets))
4755 (mbl mml-buffer-list))
4756 (setq mml-buffer-list nil)
4757 (insert-buffer-substring gnus-original-article-buffer)
4758 (mime-to-mml ',handles)
4759 (setq gnus-article-mime-handles nil)
4760 (let ((mbl1 mml-buffer-list))
4761 (setq mml-buffer-list mbl)
4762 (set (make-local-variable 'mml-buffer-list) mbl1))
4763 (gnus-make-local-hook 'kill-buffer-hook)
4764 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4765 `(lambda (no-highlight)
4766 (let ((mail-parse-charset (or gnus-article-charset
4767 ',gnus-newsgroup-charset))
4768 (message-options message-options)
4769 (message-options-set-recipient)
4770 (mail-parse-ignored-charsets
4771 (or gnus-article-ignored-charsets
4772 ',gnus-newsgroup-ignored-charsets)))
4774 (mml-destroy-buffers)
4775 (remove-hook 'kill-buffer-hook
4776 'mml-destroy-buffers t)
4777 (kill-local-variable 'mml-buffer-list))
4778 (gnus-summary-edit-article-done
4779 ,(or (mail-header-references gnus-current-headers) "")
4780 ,(gnus-group-read-only-p)
4781 ,gnus-summary-buffer no-highlight))
4783 (gnus-article-edit-done)
4784 (gnus-summary-expand-window)
4785 (gnus-summary-show-article)
4786 (when (and current-id (integerp gnus-auto-select-part))
4787 (gnus-article-jump-to-part
4788 (if (text-property-any (point-min) (point-max)
4789 'gnus-part (+ current-id gnus-auto-select-part))
4790 (+ current-id gnus-auto-select-part)
4791 (with-current-buffer gnus-article-buffer
4792 (length gnus-article-mime-handle-alist)))))))
4794 (defun gnus-mime-replace-part (file)
4795 "Replace MIME part under point with an external body."
4796 ;; Useful if file has already been saved to disk
4800 (read-file-name "Replace MIME part with file: "
4801 (or mm-default-directory default-directory)
4803 (gnus-mime-save-part-and-strip file))
4805 (defun gnus-mime-save-part-and-strip (&optional file)
4806 "Save the MIME part under point then replace it with an external body.
4807 If FILE is given, use it for the external part."
4809 (gnus-article-check-buffer)
4810 (when (gnus-group-read-only-p)
4811 (error "The current group does not support deleting of parts"))
4812 (when (mm-complicated-handles gnus-article-mime-handles)
4814 The current article has a complicated MIME structure, giving up..."))
4815 (let* ((data (get-text-property (point) 'gnus-data))
4816 (id (get-text-property (point) 'gnus-part))
4818 (handles gnus-article-mime-handles))
4821 (and data (mm-save-part data "Delete MIME part and save to: "))))
4823 (with-current-buffer (mm-handle-buffer data)
4825 (insert "Content-Type: " (mm-handle-media-type data))
4826 (mml-insert-parameter-string (cdr (mm-handle-type data))
4828 ;; Add a filename for the sake of saving the part again.
4829 (mml-insert-parameter
4830 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4832 (insert "Content-ID: " (message-make-message-id) "\n")
4833 (insert "Content-Transfer-Encoding: binary\n")
4836 (cdr (mm-make-handle nil
4837 `("message/external-body"
4838 (access-type . "LOCAL-FILE")
4840 ;; (set-buffer gnus-summary-buffer)
4841 (gnus-article-edit-part handles id))))
4843 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4844 ;; parts...>') but with stripping would be nice.
4846 (defun gnus-mime-delete-part ()
4847 "Delete the MIME part under point.
4848 Replace it with some information about the removed part."
4850 (gnus-article-check-buffer)
4851 (when (gnus-group-read-only-p)
4852 (error "The current group does not support deleting of parts"))
4853 (when (mm-complicated-handles gnus-article-mime-handles)
4855 The current article has a complicated MIME structure, giving up..."))
4856 (when (or gnus-expert-user
4857 (gnus-yes-or-no-p "\
4858 Deleting parts may malfunction or destroy the article; continue? "))
4859 (let* ((data (get-text-property (point) 'gnus-data))
4860 (id (get-text-property (point) 'gnus-part))
4861 (handles gnus-article-mime-handles)
4864 (let ((desc (mm-handle-description data)))
4866 (mail-decode-encoded-word-string desc))))
4868 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4870 (type (mm-handle-media-type data)))
4872 (error "No MIME part under point"))
4873 (with-current-buffer (mm-handle-buffer data)
4874 (let ((bsize (format "%s" (buffer-size))))
4879 "| The following attachment has been deleted:\n"
4881 "| Type: " type "\n"
4882 "| Filename: " filename "\n"
4883 "| Size (encoded): " bsize " Byte\n"
4885 (concat "| Description: " description "\n"))
4888 (cdr (mm-make-handle
4889 nil `("text/plain") nil nil
4891 (format "Deleted attachment (%s bytes)" bsize))))))
4892 ;; (set-buffer gnus-summary-buffer)
4893 (gnus-article-edit-part handles id))))
4895 (defun gnus-mime-save-part ()
4896 "Save the MIME part under point."
4898 (gnus-article-check-buffer)
4899 (let ((data (get-text-property (point) 'gnus-data)))
4901 (mm-save-part data))))
4903 (defun gnus-mime-pipe-part ()
4904 "Pipe the MIME part under point to a process."
4906 (gnus-article-check-buffer)
4907 (let ((data (get-text-property (point) 'gnus-data)))
4909 (mm-pipe-part data))))
4911 (defun gnus-mime-view-part ()
4912 "Interactively choose a viewing method for the MIME part under point."
4914 (gnus-article-check-buffer)
4915 (let ((data (get-text-property (point) 'gnus-data)))
4917 (setq gnus-article-mime-handles
4919 gnus-article-mime-handles (setq data (copy-sequence data))))
4920 (mm-interactively-view-part data))))
4922 (defun gnus-mime-view-part-as-type-internal ()
4923 (gnus-article-check-buffer)
4924 (let* ((handle (get-text-property (point) 'gnus-data))
4926 ;; Content-Type: foo/bar; name=...
4927 (mail-content-type-get (mm-handle-type handle) 'name)
4928 ;; Content-Disposition: attachment; filename=...
4929 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
4930 (def-type (and name (mm-default-file-encoding name))))
4931 (or (and def-type (cons def-type 0))
4933 (equal (mm-handle-media-supertype handle) "text")
4934 '("text/plain" . 0))
4935 '("application/octet-stream" . 0))))
4937 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
4938 "Choose a MIME media type, and view the part as such.
4939 If non-nil, PRED is a predicate to use during completion to limit the
4940 available media-types."
4944 (let ((default (gnus-mime-view-part-as-type-internal)))
4946 (format "View as MIME type (default %s): "
4948 (mapcar #'list (mailcap-mime-types))
4951 (gnus-article-check-buffer)
4952 (let ((handle (get-text-property (point) 'gnus-data)))
4954 (when (equal (mm-handle-media-type handle) "message/external-body")
4955 (unless (mm-handle-cache handle)
4956 (mm-extern-cache-contents handle))
4957 (setq handle (mm-handle-cache handle)))
4959 (mm-make-handle (mm-handle-buffer handle)
4960 (cons mime-type (cdr (mm-handle-type handle)))
4961 (mm-handle-encoding handle)
4962 (mm-handle-undisplayer handle)
4963 (mm-handle-disposition handle)
4964 (mm-handle-description handle)
4966 (mm-handle-id handle)))
4967 (setq gnus-article-mime-handles
4968 (mm-merge-handles gnus-article-mime-handles handle))
4969 (when (mm-handle-displayed-p handle)
4970 (mm-remove-part handle))
4971 (gnus-mm-display-part handle))))
4973 (defun gnus-mime-copy-part (&optional handle arg)
4974 "Put the MIME part under point into a new buffer.
4975 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4977 (interactive (list nil current-prefix-arg))
4978 (gnus-article-check-buffer)
4980 (setq handle (get-text-property (point) 'gnus-data)))
4982 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
4984 (mail-content-type-get (mm-handle-disposition handle)
4986 contents dont-decode charset coding-system)
4987 (mm-with-unibyte-buffer
4988 (mm-insert-part handle)
4989 (setq contents (or (condition-case nil
4990 (mm-decompress-buffer filename nil 'sig)
4992 (setq dont-decode t)
4995 (setq filename (cond (filename (file-name-nondirectory filename))
4996 (dont-decode "*raw data*")
5001 (unless (setq charset (mail-content-type-get
5002 (mm-handle-type handle) 'charset))
5003 (unless (setq coding-system (mm-with-unibyte-buffer
5005 (mm-find-buffer-file-coding-system)))
5006 (setq charset gnus-newsgroup-charset))))
5008 (setq charset (or (cdr (assq arg
5009 gnus-summary-show-article-charset-alist))
5010 (mm-read-coding-system "Charset: ")))))
5011 (switch-to-buffer (generate-new-buffer filename))
5012 (if (or coding-system
5014 (setq coding-system (mm-charset-to-coding-system charset))
5015 (not (eq charset 'ascii))))
5017 (mm-enable-multibyte)
5018 (insert (mm-decode-coding-string contents coding-system))
5019 (setq buffer-file-coding-system
5020 (if (boundp 'last-coding-system-used)
5021 (symbol-value 'last-coding-system-used)
5023 (mm-disable-multibyte)
5025 (setq buffer-file-coding-system mm-binary-coding-system))
5026 ;; We do it this way to make `normal-mode' set the appropriate mode.
5029 (setq buffer-file-name (expand-file-name filename))
5031 (setq buffer-file-name nil))
5032 (goto-char (point-min)))))
5034 (defun gnus-mime-print-part (&optional handle filename)
5035 "Print the MIME part under point."
5036 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5037 (gnus-article-check-buffer)
5038 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5039 (contents (and handle (mm-get-part handle)))
5040 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5041 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5046 (mm-save-part-to-file handle file)
5047 (call-process shell-file-name nil
5048 (generate-new-buffer " *mm*")
5050 shell-command-switch
5052 printer file (mm-handle-type handle))))
5056 (gnus-print-buffer))
5057 (ps-despool filename)))))
5059 (defun gnus-mime-inline-part (&optional handle arg)
5060 "Insert the MIME part under point into the current buffer.
5061 Compressed files like .gz and .bz2 are decompressed."
5062 (interactive (list nil current-prefix-arg))
5063 (gnus-article-check-buffer)
5065 (setq handle (get-text-property (point) 'gnus-data)))
5068 (inhibit-read-only t)
5069 contents charset coding-system)
5070 (if (and (not arg) (mm-handle-undisplayer handle))
5071 (mm-remove-part handle)
5072 (mm-with-unibyte-buffer
5073 (mm-insert-part handle)
5075 (or (mm-decompress-buffer
5076 (or (mail-content-type-get (mm-handle-type handle)
5078 (mail-content-type-get (mm-handle-disposition handle)
5084 (unless (setq charset (mail-content-type-get
5085 (mm-handle-type handle) 'charset))
5086 (unless (setq coding-system
5087 (mm-with-unibyte-buffer
5089 (mm-find-buffer-file-coding-system)))
5090 (setq charset gnus-newsgroup-charset))))
5092 (if (mm-handle-undisplayer handle)
5093 (mm-remove-part handle))
5096 gnus-summary-show-article-charset-alist))
5097 (mm-read-coding-system "Charset: "))))
5099 (if (mm-handle-undisplayer handle)
5100 (mm-remove-part handle))))
5104 (if (or coding-system
5107 (mm-charset-to-coding-system charset))
5108 (not (eq coding-system 'ascii))))
5109 (mm-decode-coding-string contents coding-system)
5110 (mm-string-to-multibyte contents)))
5113 (defun gnus-mime-strip-charset-parameters (handle)
5114 "Strip charset parameters from HANDLE."
5115 (if (stringp (car handle))
5116 (mapc #'gnus-mime-strip-charset-parameters (cdr handle))
5117 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5118 "message/external-body")
5120 (unless (mm-handle-cache handle)
5121 (mm-extern-cache-contents handle))
5122 (mm-handle-cache handle))
5124 (charset (assq 'charset (cdr type))))
5126 (delq charset type)))))
5128 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5129 "Insert the MIME part under point into the current buffer using the
5131 (interactive (list nil current-prefix-arg))
5132 (gnus-article-check-buffer)
5133 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5134 (fun (get-text-property (point) 'gnus-callback))
5135 (gnus-newsgroup-ignored-charsets 'gnus-all)
5136 gnus-newsgroup-charset form preferred parts)
5140 (setq gnus-newsgroup-charset
5143 gnus-summary-show-article-charset-alist))
5144 (mm-read-coding-system "Charset: "))))
5145 (if (mm-handle-undisplayer handle)
5146 (mm-remove-part handle)))
5147 (gnus-mime-strip-charset-parameters handle)
5148 (when (and (consp (setq form (cdr-safe fun)))
5149 (setq form (ignore-errors
5150 (assq 'gnus-mime-display-alternative form)))
5151 (setq preferred (caddr form))
5153 (when (eq (car preferred) 'quote)
5154 (setq preferred (cadr preferred)))
5155 (not (equal preferred
5156 (get-text-property (point) 'gnus-data))))
5157 (setq parts (get-text-property (point) 'gnus-part))
5158 (setq parts (cdr (assq parts
5159 gnus-article-mime-handle-alist)))
5160 (equal (mm-handle-media-type parts) "multipart/alternative")
5161 (setq parts (reverse (cdr parts))))
5163 (list 'quote (or (cadr (member preferred parts))
5165 (funcall fun handle)))))
5167 (defun gnus-mime-view-part-externally (&optional handle)
5168 "View the MIME part under point with an external viewer."
5170 (gnus-article-check-buffer)
5171 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5172 (mm-user-display-methods nil)
5173 (mm-inlined-types nil)
5174 (mail-parse-charset gnus-newsgroup-charset)
5175 (mail-parse-ignored-charsets
5176 (with-current-buffer gnus-summary-buffer
5177 gnus-newsgroup-ignored-charsets))
5178 (type (mm-handle-media-type handle))
5179 (method (mailcap-mime-info type))
5180 (mm-enable-external t))
5181 (if (not (stringp method))
5182 (gnus-mime-view-part-as-type
5183 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5185 (if (mm-handle-undisplayer handle)
5186 (mm-remove-part handle)
5187 (mm-display-part handle))))))
5189 (defun gnus-mime-view-part-internally (&optional handle)
5190 "View the MIME part under point with an internal viewer.
5191 If no internal viewer is available, use an external viewer."
5193 (gnus-article-check-buffer)
5194 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5195 (mm-inlined-types '(".*"))
5196 (mm-inline-large-images t)
5197 (mail-parse-charset gnus-newsgroup-charset)
5198 (mail-parse-ignored-charsets
5199 (with-current-buffer gnus-summary-buffer
5200 gnus-newsgroup-ignored-charsets))
5201 (inhibit-read-only t))
5202 (if (not (mm-inlinable-p handle))
5203 (gnus-mime-view-part-as-type
5204 nil (lambda (types) (mm-inlinable-p handle (car types))))
5206 (if (mm-handle-undisplayer handle)
5207 (mm-remove-part handle)
5208 (mm-display-part handle))))))
5210 (defun gnus-mime-action-on-part (&optional action)
5211 "Do something with the MIME attachment at \(point\)."
5213 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5214 (gnus-article-check-buffer)
5215 (let ((action-pair (assoc action gnus-mime-action-alist)))
5217 (funcall (cdr action-pair)))))
5219 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5220 "Call FUNCTION on MIME part N.
5221 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5222 If INTERACTIVE, call FUNCTION interactivly."
5224 ;; Check whether the article is displayed.
5225 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5226 (setq window (get-buffer-window gnus-article-buffer t))
5227 (frame-visible-p (setq frame (window-frame window))))
5228 (error "No article is displayed"))
5229 (with-current-buffer gnus-article-buffer
5230 ;; Check whether the article displays the right contents.
5231 (unless (with-current-buffer gnus-summary-buffer
5232 (eq gnus-current-article (gnus-summary-article-number)))
5233 (error "You should select the right article first"))
5235 (setq n (prefix-numeric-value n))
5237 (setq n (or (get-text-property pt 'gnus-part)
5239 (get-text-property (1- pt) 'gnus-part))
5240 (get-text-property (prog2
5246 (or (and (setq pt (previous-single-property-change
5249 (next-single-property-change (point) 'gnus-part)
5253 ;; Check whether the specified part exists.
5254 (when (> n (length gnus-article-mime-handle-alist))
5255 (error "No such part")))
5258 ;; To select the window is needed so that the cursor
5259 ;; might be visible on the MIME button.
5260 (select-window (prog1
5262 (setq window (selected-window))
5263 ;; Article may be displayed in the other frame.
5264 (gnus-select-frame-set-input-focus
5267 (setq frame (selected-frame))))))
5268 (when (gnus-article-goto-part n)
5269 ;; We point the cursor and the arrow at the MIME button
5270 ;; when the `function' prompt the user for something.
5271 (let ((cursor-in-non-selected-windows t)
5272 (overlay-arrow-string "=>")
5273 (overlay-arrow-position (point-marker)))
5276 ((and no-handle interactive)
5277 (call-interactively function))
5283 (cdr (assq n gnus-article-mime-handle-alist))))
5286 (cdr (assq n gnus-article-mime-handle-alist)))))
5287 (set-marker overlay-arrow-position nil)
5288 (unless gnus-auto-select-part
5289 (gnus-select-frame-set-input-focus frame)
5290 (select-window window))))
5292 (if gnus-inhibit-mime-unbuttonizing
5293 ;; This is the default though the program shouldn't reach here.
5294 (error "No such part")
5295 ;; The part which doesn't have the MIME button is selected.
5296 ;; So, we display all the buttons and redo it.
5297 (let ((gnus-inhibit-mime-unbuttonizing t))
5298 (gnus-summary-show-article)
5299 (gnus-article-part-wrapper n function no-handle))))))
5301 (defun gnus-article-pipe-part (n)
5302 "Pipe MIME part N, which is the numerical prefix."
5304 (gnus-article-part-wrapper n 'mm-pipe-part))
5306 (defun gnus-article-save-part (n)
5307 "Save MIME part N, which is the numerical prefix."
5309 (gnus-article-part-wrapper n 'mm-save-part))
5311 (defun gnus-article-interactively-view-part (n)
5312 "View MIME part N interactively, which is the numerical prefix."
5314 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5316 (defun gnus-article-copy-part (n)
5317 "Copy MIME part N, which is the numerical prefix."
5319 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5321 (defun gnus-article-view-part-as-charset (n)
5322 "View MIME part N using a specified charset.
5323 N is the numerical prefix."
5325 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5327 (defun gnus-article-view-part-externally (n)
5328 "View MIME part N externally, which is the numerical prefix."
5330 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5332 (defun gnus-article-inline-part (n)
5333 "Inline MIME part N, which is the numerical prefix."
5335 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5337 (defun gnus-article-save-part-and-strip (n)
5338 "Save MIME part N and replace it with an external body.
5339 N is the numerical prefix."
5341 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5343 (defun gnus-article-replace-part (n)
5344 "Replace MIME part N with an external body.
5345 N is the numerical prefix."
5347 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5349 (defun gnus-article-delete-part (n)
5350 "Delete MIME part N and add some information about the removed part.
5351 N is the numerical prefix."
5353 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5355 (defun gnus-article-view-part-as-type (n)
5356 "Choose a MIME media type, and view part N as such.
5357 N is the numerical prefix."
5359 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5361 (defun gnus-article-mime-match-handle-first (condition)
5364 (dolist (ihandle gnus-article-mime-handle-alist)
5366 ((functionp condition)
5367 (funcall condition (cdr ihandle)))
5368 ((eq condition 'undisplayed)
5369 (not (or (mm-handle-undisplayer (cdr ihandle))
5370 (equal (mm-handle-media-type (cdr ihandle))
5371 "multipart/alternative"))))
5372 ((eq condition 'undisplayed-alternative)
5373 (not (mm-handle-undisplayer (cdr ihandle))))
5375 (gnus-article-goto-part (car ihandle))
5376 (or (not n) (< (car ihandle) n)))
5377 (setq n (car ihandle))))
5381 (defun gnus-article-view-part (&optional n)
5382 "View MIME part N, which is the numerical prefix."
5384 (with-current-buffer gnus-article-buffer
5385 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5386 gnus-article-mime-match-handle-function)))
5387 (when (> n (length gnus-article-mime-handle-alist))
5388 (error "No such part"))
5389 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5390 (when (gnus-article-goto-part n)
5391 (if (equal (car handle) "multipart/alternative")
5392 (gnus-article-press-button)
5393 (when (eq (gnus-mm-display-part handle) 'internal)
5394 (gnus-set-window-start)))))))
5396 (defsubst gnus-article-mime-total-parts ()
5397 (if (bufferp (car gnus-article-mime-handles))
5399 (1- (length gnus-article-mime-handles))))
5401 (defun gnus-mm-display-part (handle)
5402 "Display HANDLE and fix MIME button."
5403 (let ((id (get-text-property (point) 'gnus-part))
5405 (inhibit-read-only t))
5408 (let ((window (selected-window))
5409 (mail-parse-charset gnus-newsgroup-charset)
5410 (mail-parse-ignored-charsets
5411 (if (gnus-buffer-live-p gnus-summary-buffer)
5412 (with-current-buffer gnus-summary-buffer
5413 gnus-newsgroup-ignored-charsets)
5417 (let ((win (gnus-get-buffer-window (current-buffer) t))
5420 (select-window win))
5423 (if (mm-handle-displayed-p handle)
5424 ;; This will remove the part.
5425 (mm-display-part handle)
5427 (narrow-to-region (point)
5428 (if (eobp) (point) (1+ (point))))
5429 (mm-display-part handle)
5430 ;; We narrow to the part itself and
5431 ;; then call the treatment functions.
5432 (goto-char (point-min))
5434 (narrow-to-region (point) (point-max))
5437 (gnus-article-mime-total-parts)
5438 (mm-handle-media-type handle)))))
5439 (if (window-live-p window)
5440 (select-window window)))))
5443 (gnus-insert-mime-button
5444 handle id (list (mm-handle-displayed-p handle)))
5445 (goto-char point))))
5447 (defun gnus-article-goto-part (n)
5448 "Go to MIME part N."
5449 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5451 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5452 (let ((gnus-tmp-name
5453 (or (mail-content-type-get (mm-handle-type handle) 'name)
5454 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5455 (mail-content-type-get (mm-handle-type handle) 'url)
5457 (gnus-tmp-type (mm-handle-media-type handle))
5458 (gnus-tmp-description
5459 (mail-decode-encoded-word-string (or (mm-handle-description handle)
5462 (if (if displayed (car displayed)
5463 (mm-handle-displayed-p handle))
5465 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5467 gnus-tmp-type-long b e)
5468 (when (string-match ".*/" gnus-tmp-name)
5469 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5470 (setq gnus-tmp-type-long (concat gnus-tmp-type
5471 (and (not (equal gnus-tmp-name ""))
5472 (concat "; " gnus-tmp-name))))
5473 (unless (equal gnus-tmp-description "")
5474 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5479 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5480 `(keymap ,gnus-mime-button-map
5481 gnus-callback gnus-mm-display-part
5482 gnus-part ,gnus-tmp-id
5483 article-type annotation
5486 ;; Exclude a newline.
5489 (when gnus-article-button-face
5490 (gnus-overlay-put (gnus-make-overlay b e nil t)
5491 'face gnus-article-button-face))
5492 (widget-convert-button
5495 :action 'gnus-widget-press-button
5496 :button-keymap gnus-mime-button-map
5498 (lambda (widget/window &optional overlay pos)
5499 ;; Needed to properly clear the message due to a bug in
5500 ;; wid-edit (XEmacs only).
5501 (if (boundp 'help-echo-owns-message)
5502 (setq help-echo-owns-message t))
5504 "%S: %s the MIME part; %S: more options"
5505 (aref gnus-mouse-2 0)
5506 ;; XEmacs will get a single widget arg; Emacs 21 will get
5507 ;; window, overlay, position.
5508 (if (mm-handle-displayed-p
5510 (with-current-buffer (gnus-overlay-buffer overlay)
5511 (widget-get (widget-at (gnus-overlay-start overlay))
5513 (widget-get widget/window :mime-handle)))
5515 (aref gnus-down-mouse-3 0))))))
5517 (defun gnus-widget-press-button (elems el)
5518 (goto-char (widget-get elems :from))
5519 (gnus-article-press-button))
5521 (defvar gnus-displaying-mime nil)
5523 (defun gnus-display-mime (&optional ihandles)
5524 "Display the MIME parts."
5526 (save-selected-window
5527 (let ((window (get-buffer-window gnus-article-buffer))
5530 (select-window window)
5531 ;; We have to do this since selecting the window
5532 ;; may change the point. So we set the window point.
5533 (set-window-point window point)))
5534 (let ((handles ihandles)
5535 (inhibit-read-only t)
5538 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5539 (when gnus-article-emulate-mime
5540 (mm-uu-dissect-text-parts handles)))
5541 (gnus-article-emulate-mime
5542 (setq handles (mm-uu-dissect))))
5543 (when (and (not ihandles)
5544 (not gnus-displaying-mime))
5545 ;; Top-level call; we clean up.
5546 (when gnus-article-mime-handles
5547 (mm-destroy-parts gnus-article-mime-handles)
5548 (setq gnus-article-mime-handle-alist nil));; A trick.
5549 (setq gnus-article-mime-handles handles)
5550 ;; We allow users to glean info from the handles.
5551 (when gnus-article-mime-part-function
5552 (gnus-mime-part-function handles)))
5554 (or (not (stringp (car handles)))
5557 (when (and (not ihandles)
5558 (not gnus-displaying-mime))
5559 ;; Clean up for mime parts.
5561 (delete-region (point) (point-max)))
5562 (let ((gnus-displaying-mime t))
5563 (gnus-mime-display-part handles)))
5566 (narrow-to-region (point) (point-max))
5567 (gnus-treat-article nil 1 1)
5570 ;; Highlight the headers.
5574 (narrow-to-region (point-min) (point))
5575 (gnus-article-save-original-date
5576 (gnus-treat-article 'head)))))))
5577 ;; Cope with broken MIME messages.
5578 (goto-char (point-max))
5582 (defcustom gnus-mime-display-multipart-as-mixed nil
5583 "Display \"multipart\" parts as \"multipart/mixed\".
5585 If t, it overrides nil values of
5586 `gnus-mime-display-multipart-alternative-as-mixed' and
5587 `gnus-mime-display-multipart-related-as-mixed'."
5588 :group 'gnus-article-mime
5591 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5592 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5594 :group 'gnus-article-mime
5597 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5598 "Display \"multipart/related\" parts as \"multipart/mixed\".
5600 If displaying \"text/html\" is discouraged \(see
5601 `mm-discouraged-alternatives'\) images or other material inside a
5602 \"multipart/related\" part might be overlooked when this variable is nil."
5604 :group 'gnus-article-mime
5607 (defun gnus-mime-display-part (handle)
5609 ;; Maybe a broken MIME message.
5612 ((not (stringp (car handle)))
5613 (gnus-mime-display-single handle))
5614 ;; User-defined multipart
5615 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5616 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5618 ;; multipart/alternative
5619 ((and (equal (car handle) "multipart/alternative")
5620 (not (or gnus-mime-display-multipart-as-mixed
5621 gnus-mime-display-multipart-alternative-as-mixed)))
5622 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5623 (push (cons id handle) gnus-article-mime-handle-alist)
5624 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5625 ;; multipart/related
5626 ((and (equal (car handle) "multipart/related")
5627 (not (or gnus-mime-display-multipart-as-mixed
5628 gnus-mime-display-multipart-related-as-mixed)))
5629 ;;;!!!We should find the start part, but we just default
5630 ;;;!!!to the first part.
5631 ;;(gnus-mime-display-part (cadr handle))
5632 ;;;!!! Most multipart/related is an HTML message plus images.
5633 ;;;!!! Unfortunately we are unable to let W3 display those
5634 ;;;!!! included images, so we just display it as a mixed multipart.
5635 ;;(gnus-mime-display-mixed (cdr handle))
5636 ;;;!!! No, w3 can display everything just fine.
5637 (gnus-mime-display-part (cadr handle)))
5638 ((equal (car handle) "multipart/signed")
5639 (gnus-add-wash-type 'signed)
5640 (gnus-mime-display-security handle))
5641 ((equal (car handle) "multipart/encrypted")
5642 (gnus-add-wash-type 'encrypted)
5643 (gnus-mime-display-security handle))
5644 ;; Other multiparts are handled like multipart/mixed.
5646 (gnus-mime-display-mixed (cdr handle)))))
5648 (defun gnus-mime-part-function (handles)
5649 (if (stringp (car handles))
5650 (mapcar 'gnus-mime-part-function (cdr handles))
5651 (funcall gnus-article-mime-part-function handles)))
5653 (defun gnus-mime-display-mixed (handles)
5654 (mapcar 'gnus-mime-display-part handles))
5656 (defun gnus-mime-display-single (handle)
5657 (let ((type (mm-handle-media-type handle))
5658 (ignored gnus-ignored-mime-types)
5665 (when (string-match (pop ignored) type)
5666 (throw 'ignored nil)))
5667 (if (and (setq not-attachment
5668 (and (not (mm-inline-override-p handle))
5669 (or (not (mm-handle-disposition handle))
5670 (equal (car (mm-handle-disposition handle))
5672 (mm-attachment-override-p handle))))
5673 (mm-automatic-display-p handle)
5675 (mm-inlinable-p handle)
5676 (mm-inlined-p handle))
5677 (mm-automatic-external-display-p type)))
5679 (when (equal (mm-handle-media-supertype handle) "text")
5681 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5683 (push (cons id handle) gnus-article-mime-handle-alist)
5685 (equal (mm-handle-media-supertype handle) "message"))
5688 (cond ((not (bolp)) 2)
5689 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5691 (when (or (not display)
5692 (not (gnus-unbuttonized-mime-type-p type)))
5693 (gnus-insert-mime-button
5694 handle id (list (or display (and not-attachment text))))
5695 (gnus-article-insert-newline)
5696 ;; Remember modify the number of forward lines.
5704 (let ((mail-parse-charset gnus-newsgroup-charset)
5705 (mail-parse-ignored-charsets
5706 (save-excursion (condition-case ()
5707 (set-buffer gnus-summary-buffer)
5709 gnus-newsgroup-ignored-charsets)))
5710 (mm-display-part handle t))
5711 (goto-char (point-max)))
5712 ((and text not-attachment)
5716 (gnus-article-insert-newline)
5719 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5721 (and (equal type "text/calendar") 'utf-8))))
5722 (cond ((not charset)
5723 (mm-string-as-multibyte (mm-get-part handle)))
5724 ((eq charset 'gnus-decoded)
5725 (with-current-buffer (mm-handle-buffer handle)
5728 (mm-decode-string (mm-get-part handle) charset)))))
5729 (goto-char (point-max))))
5733 (narrow-to-region beg (point))
5734 (if (eq handle gnus-article-mime-handles)
5735 ;; The format=flowed case.
5736 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5737 ;; Don't count signature parts that are never displayed.
5738 ;; The part number should be re-calculated supposing this
5739 ;; might be a message/rfc822 part.
5741 (dolist (part gnus-article-mime-handles)
5742 (unless (or (stringp part)
5743 (equal (car (mm-handle-type part))
5744 "application/pgp-signature"))
5745 (push part handles)))
5747 nil (length (memq handle handles)) (length handles)
5748 (mm-handle-media-type handle)))))))))))
5750 (defun gnus-unbuttonized-mime-type-p (type)
5751 "Say whether TYPE is to be unbuttonized."
5752 (unless gnus-inhibit-mime-unbuttonizing
5754 (let ((types gnus-unbuttonized-mime-types))
5756 (when (string-match (pop types) type)
5757 (throw 'found t)))))
5759 (let ((types gnus-buttonized-mime-types))
5761 (when (string-match (pop types) type)
5762 (throw 'found t)))))))))
5764 (defun gnus-article-insert-newline ()
5765 "Insert a newline, but mark it as undeletable."
5766 (gnus-put-text-property
5767 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5769 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5770 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5773 handle (inhibit-read-only t) from props begend not-pref)
5774 (save-window-excursion
5777 (narrow-to-region (car ibegend)
5780 (goto-char (car ibegend))
5783 (delete-region (point-min) (point-max))
5784 (mm-remove-parts handles))
5785 (setq begend (list (point-marker)))
5787 (unless (setq not-pref (cadr (member preferred ihandles)))
5788 (setq not-pref (car ihandles)))
5791 (not (gnus-unbuttonized-mime-type-p
5792 "multipart/alternative")))
5793 (gnus-add-text-properties
5796 (insert (format "%d. " id))
5800 (unless ,(not ibegend)
5801 (setq gnus-article-mime-handle-alist
5802 ',gnus-article-mime-handle-alist))
5803 (gnus-mime-display-alternative
5804 ',ihandles ',not-pref ',begend ,id))
5805 keymap ,gnus-mime-button-map
5806 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5807 face ,gnus-article-button-face
5809 article-type multipart))
5810 (widget-convert-button 'link from (point)
5811 :action 'gnus-widget-press-button
5812 :button-keymap gnus-widget-button-keymap)
5814 (while (setq handle (pop handles))
5815 (gnus-add-text-properties
5818 (insert (format "(%c) %-18s"
5819 (if (equal handle preferred) ?* ? )
5820 (mm-handle-media-type handle)))
5824 (unless ,(not ibegend)
5825 (setq gnus-article-mime-handle-alist
5826 ',gnus-article-mime-handle-alist))
5827 (gnus-mime-display-alternative
5828 ',ihandles ',handle ',begend ,id))
5829 keymap ,gnus-mime-button-map
5830 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5831 face ,gnus-article-button-face
5834 (widget-convert-button 'link from (point)
5835 :action 'gnus-widget-press-button
5836 :button-keymap gnus-widget-button-keymap)
5840 (if (stringp (car preferred))
5841 (gnus-display-mime preferred)
5842 (let ((mail-parse-charset gnus-newsgroup-charset)
5843 (mail-parse-ignored-charsets
5844 (with-current-buffer gnus-summary-buffer
5845 gnus-newsgroup-ignored-charsets)))
5846 (mm-display-part preferred)
5850 (narrow-to-region (car begend) (point-max))
5852 nil (length gnus-article-mime-handle-alist)
5853 (gnus-article-mime-total-parts)
5854 (mm-handle-media-type handle))))))
5855 (goto-char (point-max))
5856 (setcdr begend (point-marker)))))
5858 (goto-char point))))
5860 (defconst gnus-article-wash-status-strings
5861 (let ((alist '((cite "c" "Possible hidden citation text"
5862 " " "All citation text visible")
5863 (headers "h" "Hidden headers"
5864 " " "All headers visible.")
5865 (pgp "p" "Encrypted or signed message status hidden"
5866 " " "No hidden encryption nor digital signature status")
5867 (signature "s" "Signature has been hidden"
5868 " " "Signature is visible")
5869 (overstrike "o" "Overstrike (^H) characters applied"
5870 " " "No overstrike characters applied")
5871 (emphasis "e" "/*_Emphasis_*/ characters applied"
5872 " " "No /*_emphasis_*/ characters applied")))
5874 (dolist (entry alist result)
5875 (let ((key (nth 0 entry))
5876 (on (copy-sequence (nth 1 entry)))
5877 (on-help (nth 2 entry))
5878 (off (copy-sequence (nth 3 entry)))
5879 (off-help (nth 4 entry)))
5880 (put-text-property 0 1 'help-echo on-help on)
5881 (put-text-property 0 1 'help-echo off-help off)
5882 (push (list key on off) result))))
5883 "Alist of strings describing wash status in the mode line.
5884 Each entry has the form (KEY ON OF), where the KEY is a symbol
5885 representing the particular washing function, ON is the string to use
5886 in the article mode line when the washing function is active, and OFF
5887 is the string to use when it is inactive.")
5889 (defun gnus-article-wash-status-entry (key value)
5890 (let ((entry (assoc key gnus-article-wash-status-strings)))
5891 (if value (nth 1 entry) (nth 2 entry))))
5893 (defun gnus-article-wash-status ()
5894 "Return a string which display status of article washing."
5895 (with-current-buffer gnus-article-buffer
5896 (let ((cite (memq 'cite gnus-article-wash-types))
5897 (headers (memq 'headers gnus-article-wash-types))
5898 (boring (memq 'boring-headers gnus-article-wash-types))
5899 (pgp (memq 'pgp gnus-article-wash-types))
5900 (pem (memq 'pem gnus-article-wash-types))
5901 (signed (memq 'signed gnus-article-wash-types))
5902 (encrypted (memq 'encrypted gnus-article-wash-types))
5903 (signature (memq 'signature gnus-article-wash-types))
5904 (overstrike (memq 'overstrike gnus-article-wash-types))
5905 (emphasis (memq 'emphasis gnus-article-wash-types)))
5907 (gnus-article-wash-status-entry 'cite cite)
5908 (gnus-article-wash-status-entry 'headers (or headers boring))
5909 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5910 (gnus-article-wash-status-entry 'signature signature)
5911 (gnus-article-wash-status-entry 'overstrike overstrike)
5912 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5914 (defun gnus-add-wash-type (type)
5915 "Add a washing of TYPE to the current status."
5916 (add-to-list 'gnus-article-wash-types type))
5918 (defun gnus-delete-wash-type (type)
5919 "Add a washing of TYPE to the current status."
5920 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5922 (defun gnus-add-image (category image)
5923 "Add IMAGE of CATEGORY to the list of displayed images."
5924 (let ((entry (assq category gnus-article-image-alist)))
5926 (setq entry (list category))
5927 (push entry gnus-article-image-alist))
5928 (nconc entry (list image))))
5930 (defun gnus-delete-images (category)
5931 "Delete all images in CATEGORY."
5932 (let ((entry (assq category gnus-article-image-alist)))
5933 (dolist (image (cdr entry))
5934 (gnus-remove-image image category))
5935 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5936 (gnus-delete-wash-type category)))
5938 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5940 (defun gnus-article-maybe-hide-headers ()
5941 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5942 Provided for backwards compatibility."
5943 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5944 (not (with-current-buffer gnus-summary-buffer
5945 gnus-have-all-headers)))
5946 (not gnus-inhibit-hiding))
5947 (gnus-article-hide-headers)))
5951 (defun gnus-output-to-file (file-name)
5952 "Append the current article to a file named FILE-NAME.
5953 If `gnus-article-save-coding-system' is non-nil, it is used to encode
5954 text and used as the value of the coding cookie which is added to the
5955 top of a file. Otherwise, this function saves a raw article without
5957 (let* ((artbuf (current-buffer))
5958 (file-name-coding-system nnmail-pathname-coding-system)
5959 (coding gnus-article-save-coding-system)
5960 (coding-system-for-read (if coding
5961 nil ;; Rely on the coding cookie.
5962 mm-text-coding-system))
5963 (coding-system-for-write (or coding
5964 mm-text-coding-system-for-write
5965 mm-text-coding-system))
5966 (exists (file-exists-p file-name)))
5969 (insert-file-contents file-name)
5970 (goto-char (point-min))
5971 ;; Remove the existing coding cookie.
5972 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
5973 (delete-region (match-beginning 0) (match-end 0))))
5974 (goto-char (point-max))
5975 (insert-buffer-substring artbuf)
5976 ;; Append newline at end of the buffer as separator, and then
5978 (goto-char (point-max))
5981 ;; If the coding system is not suitable to encode the text,
5982 ;; ask a user for a proper one.
5983 (when (fboundp 'select-safe-coding-system)
5984 (setq coding (coding-system-base
5985 (save-window-excursion
5986 (select-safe-coding-system (point-min) (point-max)
5988 (setq coding-system-for-write
5989 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
5991 (goto-char (point-min))
5992 ;; Add the coding cookie.
5993 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
5994 coding-system-for-write)))
5997 (write-region (point-min) (point-max) file-name nil 'no-message)
5998 (message "Appended to %s" file-name))
5999 (write-region (point-min) (point-max) file-name))))
6002 (defun gnus-narrow-to-page (&optional arg)
6003 "Narrow the article buffer to a page.
6004 If given a numerical ARG, move forward ARG pages."
6006 (setq arg (if arg (prefix-numeric-value arg) 0))
6008 (set-buffer gnus-article-buffer)
6009 (goto-char (point-min))
6011 ;; Remove any old next/prev buttons.
6012 (when (gnus-visual-p 'page-marker)
6013 (let ((inhibit-read-only t))
6014 (gnus-remove-text-with-property 'gnus-prev)
6015 (gnus-remove-text-with-property 'gnus-next)))
6018 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
6020 (re-search-forward page-delimiter nil 'move arg)))
6021 (goto-char (match-end 0))
6023 (goto-char (point-min))
6024 (setq gnus-page-broken
6025 (and (re-search-forward page-delimiter nil t) t))))
6026 (when gnus-page-broken
6029 (if (re-search-forward page-delimiter nil 'move)
6032 (when (and (gnus-visual-p 'page-marker)
6033 (> (point-min) (save-restriction (widen) (point-min))))
6035 (goto-char (point-min))
6036 (gnus-insert-prev-page-button)))
6037 (when (and (gnus-visual-p 'page-marker)
6038 (< (point-max) (save-restriction (widen) (point-max))))
6040 (goto-char (point-max))
6041 (gnus-insert-next-page-button))))))
6043 ;; Article mode commands
6045 (defun gnus-article-goto-next-page ()
6046 "Show the next page of the article."
6048 (when (gnus-article-next-page)
6049 (goto-char (point-min))
6050 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6053 (defun gnus-article-goto-prev-page ()
6054 "Show the previous page of the article."
6057 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6058 (gnus-article-prev-page nil)))
6060 ;; This is cleaner but currently breaks `gnus-pick-mode':
6062 ;; (defun gnus-article-goto-next-page ()
6063 ;; "Show the next page of the article."
6065 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6066 ;; (gnus-summary-next-page)))
6068 ;; (defun gnus-article-goto-prev-page ()
6069 ;; "Show the next page of the article."
6071 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6072 ;; (gnus-summary-prev-page)))
6074 (defun gnus-article-next-page (&optional lines)
6075 "Show the next page of the current article.
6076 If end of article, return non-nil. Otherwise return nil.
6077 Argument LINES specifies lines to be scrolled up."
6079 (move-to-window-line -1)
6080 (if (and (not (and gnus-article-over-scroll
6081 (> (count-lines (window-start) (point-max))
6082 (+ (or lines (1- (window-height)))
6083 (or (and (boundp 'scroll-margin)
6084 (symbol-value 'scroll-margin))
6088 (and (pos-visible-in-window-p) ;Not continuation line.
6089 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
6090 ;; Nothing in this page.
6091 (if (or (not gnus-page-broken)
6096 (eobp)))) ;Real end-of-buffer?
6098 (when gnus-article-over-scroll
6099 (gnus-article-next-page-1 lines))
6101 (gnus-narrow-to-page 1) ;Go to next page.
6103 ;; More in this page.
6104 (gnus-article-next-page-1 lines)
6107 (defmacro gnus-article-beginning-of-window ()
6108 "Move point to the beginning of the window.
6109 In Emacs, the point is placed at the line number which `scroll-margin'
6111 (if (featurep 'xemacs)
6112 '(move-to-window-line 0)
6113 '(move-to-window-line
6114 (min (max 0 scroll-margin)
6115 (max 1 (- (window-height)
6116 (if mode-line-format 1 0)
6117 (if header-line-format 1 0)))))))
6119 (defun gnus-article-next-page-1 (lines)
6120 (when (and (not (featurep 'xemacs))
6123 (numberp (symbol-value 'scroll-margin))
6124 (> (symbol-value 'scroll-margin) 0))
6125 ;; Protect against the bug that Emacs 21.x hangs up when scrolling up for
6126 ;; too many number of lines if `scroll-margin' is set as two or greater.
6127 (setq lines (min lines
6128 (max 0 (- (count-lines (window-start) (point-max))
6129 (symbol-value 'scroll-margin))))))
6131 (let ((scroll-in-place nil))
6134 ;; Long lines may cause an end-of-buffer error.
6135 (goto-char (point-max))))
6136 (gnus-article-beginning-of-window))
6138 (defun gnus-article-prev-page (&optional lines)
6139 "Show previous page of current article.
6140 Argument LINES specifies lines to be scrolled down."
6142 (move-to-window-line 0)
6143 (if (and gnus-page-broken
6145 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6147 (gnus-narrow-to-page -1) ;Go to previous page.
6148 (goto-char (point-max))
6149 (recenter (if gnus-article-over-scroll
6151 (max (+ lines (or (and (boundp 'scroll-margin)
6152 (symbol-value 'scroll-margin))
6155 (- (window-height) 2))
6159 (let ((scroll-in-place nil))
6160 (scroll-down lines))
6161 (beginning-of-buffer
6162 (goto-char (point-min))))
6163 (gnus-article-beginning-of-window))))
6165 (defun gnus-article-only-boring-p ()
6166 "Decide whether there is only boring text remaining in the article.
6167 Something \"interesting\" is a word of at least two letters that does
6168 not have a face in `gnus-article-boring-faces'."
6169 (when (and gnus-article-skip-boring
6170 (boundp 'gnus-article-boring-faces)
6171 (symbol-value 'gnus-article-boring-faces))
6173 (let ((inhibit-point-motion-hooks t))
6175 (while (re-search-forward "\\b\\w\\w" nil t)
6177 (when (not (gnus-intersection
6178 (gnus-faces-at (point))
6179 (symbol-value 'gnus-article-boring-faces)))
6180 (throw 'only-boring nil)))
6181 (throw 'only-boring t))))))
6183 (defun gnus-article-refer-article ()
6184 "Read article specified by message-id around point."
6187 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6188 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6189 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6190 (let ((msg-id (concat "<" (match-string 0) ">")))
6191 (set-buffer gnus-summary-buffer)
6192 (gnus-summary-refer-article msg-id))
6193 (error "No references around point"))))
6195 (defun gnus-article-show-summary ()
6196 "Reconfigure windows to show summary buffer."
6198 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6199 (error "There is no summary buffer for this article buffer")
6200 (gnus-article-set-globals)
6201 (gnus-configure-windows 'article)
6202 (gnus-summary-goto-subject gnus-current-article)
6203 (gnus-summary-position-point)))
6205 (defun gnus-article-describe-briefly ()
6206 "Describe article mode commands briefly."
6208 (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")))
6210 (defun gnus-article-summary-command ()
6211 "Execute the last keystroke in the summary buffer."
6213 (let ((obuf (current-buffer))
6214 (owin (current-window-configuration))
6216 (switch-to-buffer gnus-article-current-summary 'norecord)
6217 (setq func (lookup-key (current-local-map) (this-command-keys)))
6218 (call-interactively func)
6220 (set-window-configuration owin)
6221 (set-window-point (get-buffer-window (current-buffer)) (point))))
6223 (defun gnus-article-summary-command-nosave ()
6224 "Execute the last keystroke in the summary buffer."
6227 (pop-to-buffer gnus-article-current-summary)
6228 (setq func (lookup-key (current-local-map) (this-command-keys)))
6229 (call-interactively func)))
6231 (defun gnus-article-check-buffer ()
6232 "Beep if not in an article buffer."
6233 (unless (equal major-mode 'gnus-article-mode)
6234 (error "Command invoked outside of a Gnus article buffer")))
6236 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6237 "Read a summary buffer key sequence and execute it from the article buffer."
6239 (gnus-article-check-buffer)
6241 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6242 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6243 "=" "^" "\M-^" "|"))
6249 '("n" "Gn" "p" "Gp"))
6252 (set-buffer gnus-article-current-summary)
6253 (let (gnus-pick-mode)
6254 (setq unread-command-events (nconc unread-command-events
6255 (list (or key last-command-event)))
6256 keys (if (featurep 'xemacs)
6257 (events-to-keys (read-key-sequence nil t))
6258 (read-key-sequence nil t)))))
6263 ((eq (aref keys (1- (length keys))) ?\C-h)
6264 (gnus-article-describe-bindings (substring keys 0 -1)))
6265 ((or (member keys nosaves)
6266 (member keys nosave-but-article)
6267 (member keys nosave-in-article))
6269 (save-window-excursion
6270 (pop-to-buffer gnus-article-current-summary)
6271 ;; We disable the pick minor mode commands.
6272 (let (gnus-pick-mode)
6273 (setq func (lookup-key (current-local-map) keys))))
6277 (unless (member keys nosave-in-article)
6278 (set-buffer gnus-article-current-summary))
6279 (call-interactively func)
6280 (setq new-sum-point (point)))
6281 (when (member keys nosave-but-article)
6282 (pop-to-buffer gnus-article-buffer))))
6284 ;; These commands should restore window configuration.
6285 (let ((obuf (current-buffer))
6286 (owin (current-window-configuration))
6287 win func in-buffer selected new-sum-start new-sum-hscroll err)
6288 (cond (not-restore-window
6289 (pop-to-buffer gnus-article-current-summary)
6290 (setq win (selected-window)))
6291 ((setq win (get-buffer-window gnus-article-current-summary))
6292 (select-window win))
6294 (let ((summary-buffer gnus-article-current-summary))
6295 (gnus-configure-windows 'article)
6296 (unless (setq win (get-buffer-window summary-buffer 'visible))
6297 (let ((gnus-buffer-configuration
6298 '(article ((vertical 1.0
6299 (summary 0.25 point)
6301 (gnus-configure-windows 'article))
6302 (setq win (get-buffer-window summary-buffer 'visible)))
6303 (gnus-select-frame-set-input-focus (window-frame win))
6304 (select-window win))))
6305 (setq in-buffer (current-buffer))
6306 ;; We disable the pick minor mode commands.
6307 (if (and (setq func (let (gnus-pick-mode)
6308 (lookup-key (current-local-map) keys)))
6310 (condition-case code
6312 (call-interactively func)
6318 (when (eq win (selected-window))
6319 (setq new-sum-point (point)
6320 new-sum-start (window-start win)
6321 new-sum-hscroll (window-hscroll win)))
6322 (when (or (eq in-buffer (current-buffer))
6323 (when (eq obuf (current-buffer))
6324 (set-buffer in-buffer)
6326 (setq selected (gnus-summary-select-article))
6328 (unless not-restore-window
6329 (set-window-configuration owin))
6330 (when (and (eq selected 'old)
6332 (set-window-start (get-buffer-window (current-buffer))
6334 (set-window-point (get-buffer-window (current-buffer))
6335 (if (article-goto-body)
6338 (when (and (not not-restore-window)
6340 (with-current-buffer (window-buffer win)
6341 (eq major-mode 'gnus-summary-mode)))
6342 (set-window-point win new-sum-point)
6343 (set-window-start win new-sum-start)
6344 (set-window-hscroll win new-sum-hscroll))))
6345 (set-window-configuration owin)
6347 (signal (car err) (cdr err))
6350 (defun gnus-article-read-summary-send-keys ()
6352 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6353 (gnus-article-read-summary-keys)))
6355 (defun gnus-article-describe-key (key)
6356 "Display documentation of the function invoked by KEY.
6357 KEY is a string or a vector."
6358 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6359 (read-key-sequence "Describe key: "))))
6360 (gnus-article-check-buffer)
6361 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6362 gnus-article-read-summary-send-keys))
6364 (set-buffer gnus-article-current-summary)
6365 (setq unread-command-events
6366 (if (featurep 'xemacs)
6368 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6369 (list 'meta (- x 128))
6372 (let ((cursor-in-echo-area t)
6374 (describe-key (read-key-sequence nil t))))
6375 (describe-key key)))
6377 (defun gnus-article-describe-key-briefly (key &optional insert)
6378 "Display documentation of the function invoked by KEY.
6379 KEY is a string or a vector."
6380 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6381 (read-key-sequence "Describe key: "))
6382 current-prefix-arg))
6383 (gnus-article-check-buffer)
6384 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6385 gnus-article-read-summary-send-keys))
6387 (set-buffer gnus-article-current-summary)
6388 (setq unread-command-events
6389 (if (featurep 'xemacs)
6391 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6392 (list 'meta (- x 128))
6395 (let ((cursor-in-echo-area t)
6397 (describe-key-briefly (read-key-sequence nil t) insert)))
6398 (describe-key-briefly key insert)))
6400 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6401 (defvar gnus-agent-summary-mode)
6403 (defun gnus-article-describe-bindings (&optional prefix)
6404 "Show a list of all defined keys, and their definitions.
6405 The optional argument PREFIX, if non-nil, should be a key sequence;
6406 then we display only bindings that start with that prefix."
6408 (gnus-article-check-buffer)
6409 (let ((keymap (copy-keymap gnus-article-mode-map))
6410 (map (copy-keymap gnus-article-send-map))
6411 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6413 (define-key keymap "S" map)
6414 (define-key map [t] nil)
6415 (with-current-buffer gnus-article-current-summary
6416 (set-keymap-parent map (key-binding "S"))
6417 (let (def gnus-pick-mode)
6418 (dolist (key sumkeys)
6419 (when (setq def (key-binding key))
6420 (define-key keymap key def))))
6421 (when (boundp 'gnus-agent-summary-mode)
6422 (setq agent gnus-agent-summary-mode)))
6424 (use-local-map keymap)
6425 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6426 (describe-bindings prefix))))
6428 (defun gnus-article-reply-with-original (&optional wide)
6429 "Start composing a reply mail to the current message.
6430 The text in the region will be yanked. If the region isn't active,
6431 the entire article will be yanked."
6433 (let ((article (cdr gnus-article-current))
6435 (if (not (gnus-region-active-p))
6436 (with-current-buffer gnus-summary-buffer
6437 (gnus-summary-reply (list (list article)) wide))
6438 (setq contents (buffer-substring (point) (mark t)))
6439 ;; Deactivate active regions.
6440 (when (and (boundp 'transient-mark-mode)
6441 transient-mark-mode)
6442 (setq mark-active nil))
6443 (with-current-buffer gnus-summary-buffer
6445 (list (list article contents)) wide)))))
6447 (defun gnus-article-wide-reply-with-original ()
6448 "Start composing a wide reply mail to the current message.
6449 The text in the region will be yanked. If the region isn't active,
6450 the entire article will be yanked."
6452 (gnus-article-reply-with-original t))
6454 (defun gnus-article-followup-with-original ()
6455 "Compose a followup to the current article.
6456 The text in the region will be yanked. If the region isn't active,
6457 the entire article will be yanked."
6459 (let ((article (cdr gnus-article-current))
6461 (if (not (gnus-region-active-p))
6462 (with-current-buffer gnus-summary-buffer
6463 (gnus-summary-followup (list (list article))))
6464 (setq contents (buffer-substring (point) (mark t)))
6465 ;; Deactivate active regions.
6466 (when (and (boundp 'transient-mark-mode)
6467 transient-mark-mode)
6468 (setq mark-active nil))
6469 (with-current-buffer gnus-summary-buffer
6470 (gnus-summary-followup
6471 (list (list article contents)))))))
6473 (defun gnus-article-hide (&optional arg force)
6474 "Hide all the gruft in the current article.
6475 This means that signatures, cited text and (some) headers will be
6477 If given a prefix, show the hidden text instead."
6478 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6479 (gnus-article-hide-headers arg)
6480 (gnus-article-hide-list-identifiers arg)
6481 (gnus-article-hide-citation-maybe arg force)
6482 (gnus-article-hide-signature arg))
6484 (defun gnus-article-maybe-highlight ()
6485 "Do some article highlighting if article highlighting is requested."
6486 (when (gnus-visual-p 'article-highlight 'highlight)
6487 (gnus-article-highlight-some)))
6489 (defun gnus-check-group-server ()
6490 ;; Make sure the connection to the server is alive.
6491 (unless (gnus-server-opened
6492 (gnus-find-method-for-group gnus-newsgroup-name))
6493 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6494 (gnus-request-group gnus-newsgroup-name t)))
6497 (autoload 'nneething-get-file-name "nneething"))
6499 (defun gnus-request-article-this-buffer (article group)
6500 "Get an article and insert it into this buffer."
6501 (let (do-update-line sparse-header)
6505 (gnus-kill-all-overlays)
6506 (setq group (or group gnus-newsgroup-name))
6508 ;; Using `gnus-request-article' directly will insert the article into
6509 ;; `nntp-server-buffer' - so we'll save some time by not having to
6510 ;; copy it from the server buffer into the article buffer.
6512 ;; We only request an article by message-id when we do not have the
6513 ;; headers for it, so we'll have to get those.
6514 (when (stringp article)
6515 (gnus-read-header article))
6517 ;; If the article number is negative, that means that this article
6518 ;; doesn't belong in this newsgroup (possibly), so we find its
6519 ;; message-id and request it by id instead of number.
6520 (when (and (numberp article)
6522 (get-buffer gnus-summary-buffer)
6523 (gnus-buffer-exists-p gnus-summary-buffer))
6525 (set-buffer gnus-summary-buffer)
6526 (let ((header (gnus-summary-article-header article)))
6529 ((memq article gnus-newsgroup-sparse)
6530 ;; This is a sparse gap article.
6531 (setq do-update-line article)
6532 (setq article (mail-header-id header))
6533 (setq sparse-header (gnus-read-header article))
6534 (setq gnus-newsgroup-sparse
6535 (delq article gnus-newsgroup-sparse)))
6537 ;; It's a real article.
6538 (setq article (mail-header-id header)))
6540 ;; It is an extracted pseudo-article.
6541 (setq article 'pseudo)
6542 (gnus-request-pseudo-article header))))
6544 (let ((method (gnus-find-method-for-group
6545 gnus-newsgroup-name)))
6546 (when (and (eq (car method) 'nneething)
6548 (let ((dir (nneething-get-file-name
6549 (mail-header-id header))))
6550 (when (and (stringp dir)
6551 (file-directory-p dir))
6552 (setq article 'nneething)
6553 (gnus-group-enter-directory dir))))))))
6556 ;; Refuse to select canceled articles.
6557 ((and (numberp article)
6559 (get-buffer gnus-summary-buffer)
6560 (gnus-buffer-exists-p gnus-summary-buffer)
6561 (eq (cdr (with-current-buffer gnus-summary-buffer
6562 (assq article gnus-newsgroup-reads)))
6563 gnus-canceled-mark))
6565 ;; We first check `gnus-original-article-buffer'.
6566 ((and (get-buffer gnus-original-article-buffer)
6568 (with-current-buffer gnus-original-article-buffer
6569 (and (equal (car gnus-original-article) group)
6570 (eq (cdr gnus-original-article) article))))
6571 (insert-buffer-substring gnus-original-article-buffer)
6573 ;; Check the backlog.
6574 ((and gnus-keep-backlog
6575 (gnus-backlog-request-article group article (current-buffer)))
6577 ;; Check asynchronous pre-fetch.
6578 ((gnus-async-request-fetched-article group article (current-buffer))
6579 (gnus-async-prefetch-next group article gnus-summary-buffer)
6580 (when (and (numberp article) gnus-keep-backlog)
6581 (gnus-backlog-enter-article group article (current-buffer)))
6584 ((and gnus-use-cache
6586 (gnus-cache-request-article article group))
6588 ;; Check the agent cache.
6589 ((gnus-agent-request-article article group)
6591 ;; Get the article and put into the article buffer.
6592 ((or (stringp article)
6594 (let ((gnus-override-method gnus-override-method)
6595 (methods (and (stringp article)
6596 gnus-refer-article-method))
6597 (backend (car (gnus-find-method-for-group
6598 gnus-newsgroup-name)))
6600 (inhibit-read-only t))
6601 (if (or (not (listp methods))
6602 (and (symbolp (car methods))
6603 (assq (car methods) nnoo-definition-alist)))
6604 (setq methods (list methods)))
6605 (when (and (null gnus-override-method)
6607 (setq gnus-override-method (pop methods)))
6609 (when (eq gnus-override-method 'current)
6610 (setq gnus-override-method
6611 (with-current-buffer gnus-summary-buffer
6612 gnus-current-select-method)))
6614 (gnus-kill-all-overlays)
6615 (let ((gnus-newsgroup-name group))
6616 (gnus-check-group-server))
6618 ((gnus-request-article article group (current-buffer))
6619 (when (numberp article)
6620 (gnus-async-prefetch-next group article
6621 gnus-summary-buffer)
6622 (when gnus-keep-backlog
6623 (gnus-backlog-enter-article
6624 group article (current-buffer))))
6625 (setq result 'article))
6627 (setq gnus-override-method (pop methods)))
6628 ((not (string-match "^400 "
6629 (nnheader-get-report backend)))
6630 ;; If we get 400 server disconnect, reconnect and
6631 ;; retry; otherwise, assume the article has expired.
6632 (setq result 'done))))
6633 (and (eq result 'article) 'article)))
6637 ;; Associate this article with the current summary buffer.
6638 (setq gnus-article-current-summary gnus-summary-buffer)
6640 ;; Take the article from the original article buffer
6641 ;; and place it in the buffer it's supposed to be in.
6642 (when (and (get-buffer gnus-article-buffer)
6643 (equal (buffer-name (current-buffer))
6644 (buffer-name (get-buffer gnus-article-buffer))))
6646 (if (get-buffer gnus-original-article-buffer)
6647 (set-buffer gnus-original-article-buffer)
6648 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6649 (buffer-disable-undo)
6650 (setq major-mode 'gnus-original-article-mode)
6651 (setq buffer-read-only t))
6652 (let ((inhibit-read-only t))
6654 (insert-buffer-substring gnus-article-buffer))
6655 (setq gnus-original-article (cons group article)))
6658 (run-hooks 'gnus-article-decode-hook)
6659 ;; Mark article as decoded or not.
6660 (setq gnus-article-decoded-p gnus-article-decode-hook))
6662 ;; Update sparse articles.
6663 (when (and do-update-line
6664 (or (numberp article)
6666 (let ((buf (current-buffer)))
6667 (set-buffer gnus-summary-buffer)
6668 (gnus-summary-update-article do-update-line sparse-header)
6669 (gnus-summary-goto-subject do-update-line nil t)
6670 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6672 (set-buffer buf))))))
6678 (defcustom gnus-article-edit-mode-hook nil
6679 "Hook run in article edit mode buffers."
6680 :group 'gnus-article-various
6683 (defvar gnus-article-edit-done-function nil)
6685 (defvar gnus-article-edit-mode-map nil)
6687 ;; Should we be using derived.el for this?
6688 (unless gnus-article-edit-mode-map
6689 (setq gnus-article-edit-mode-map (make-keymap))
6690 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6692 (gnus-define-keys gnus-article-edit-mode-map
6693 "\C-c?" describe-mode
6694 "\C-c\C-c" gnus-article-edit-done
6695 "\C-c\C-k" gnus-article-edit-exit
6696 "\C-c\C-f\C-t" message-goto-to
6697 "\C-c\C-f\C-o" message-goto-from
6698 "\C-c\C-f\C-b" message-goto-bcc
6699 ;;"\C-c\C-f\C-w" message-goto-fcc
6700 "\C-c\C-f\C-c" message-goto-cc
6701 "\C-c\C-f\C-s" message-goto-subject
6702 "\C-c\C-f\C-r" message-goto-reply-to
6703 "\C-c\C-f\C-n" message-goto-newsgroups
6704 "\C-c\C-f\C-d" message-goto-distribution
6705 "\C-c\C-f\C-f" message-goto-followup-to
6706 "\C-c\C-f\C-m" message-goto-mail-followup-to
6707 "\C-c\C-f\C-k" message-goto-keywords
6708 "\C-c\C-f\C-u" message-goto-summary
6709 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6710 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6711 "\C-c\C-b" message-goto-body
6712 "\C-c\C-i" message-goto-signature
6714 "\C-c\C-t" message-insert-to
6715 "\C-c\C-n" message-insert-newsgroups
6716 "\C-c\C-o" message-sort-headers
6717 "\C-c\C-e" message-elide-region
6718 "\C-c\C-v" message-delete-not-region
6719 "\C-c\C-z" message-kill-to-signature
6720 "\M-\r" message-newline-and-reformat
6721 "\C-c\C-a" mml-attach-file
6722 "\C-a" message-beginning-of-line
6724 "\M-;" comment-region)
6726 (gnus-define-keys (gnus-article-edit-wash-map
6727 "\C-c\C-w" gnus-article-edit-mode-map)
6728 "f" gnus-article-edit-full-stops))
6731 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6733 ["Fetch To" message-insert-to t]
6734 ["Fetch Newsgroups" message-insert-newsgroups t]
6736 ["To" message-goto-to t]
6737 ["From" message-goto-from t]
6738 ["Subject" message-goto-subject t]
6739 ["Cc" message-goto-cc t]
6740 ["Reply-To" message-goto-reply-to t]
6741 ["Summary" message-goto-summary t]
6742 ["Keywords" message-goto-keywords t]
6743 ["Newsgroups" message-goto-newsgroups t]
6744 ["Followup-To" message-goto-followup-to t]
6745 ["Mail-Followup-To" message-goto-mail-followup-to t]
6746 ["Distribution" message-goto-distribution t]
6747 ["Body" message-goto-body t]
6748 ["Signature" message-goto-signature t]))
6750 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6751 "Major mode for editing articles.
6752 This is an extended text-mode.
6754 \\{gnus-article-edit-mode-map}"
6755 (make-local-variable 'gnus-article-edit-done-function)
6756 (make-local-variable 'gnus-prev-winconf)
6757 (set (make-local-variable 'font-lock-defaults)
6758 '(message-font-lock-keywords t))
6759 (set (make-local-variable 'mail-header-separator) "")
6760 (set (make-local-variable 'gnus-article-edit-mode) t)
6761 (easy-menu-add message-mode-field-menu message-mode-map)
6763 (setq buffer-read-only nil)
6764 (buffer-enable-undo)
6767 (defun gnus-article-edit (&optional force)
6768 "Edit the current article.
6769 This will have permanent effect only in mail groups.
6770 If FORCE is non-nil, allow editing of articles even in read-only
6773 (when (and (not force)
6774 (gnus-group-read-only-p))
6775 (error "The current newsgroup does not support article editing"))
6776 (gnus-article-date-original)
6777 (gnus-article-edit-article
6779 `(lambda (no-highlight)
6781 (gnus-summary-edit-article-done
6782 ,(or (mail-header-references gnus-current-headers) "")
6783 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6785 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6786 "Start editing the contents of the current article buffer."
6787 (let ((winconf (current-window-configuration)))
6788 (set-buffer gnus-article-buffer)
6789 (let ((message-auto-save-directory
6790 ;; Don't associate the article buffer with a draft file.
6792 (gnus-article-edit-mode))
6793 (funcall start-func)
6794 (set-buffer-modified-p nil)
6795 (gnus-configure-windows 'edit-article)
6796 (setq gnus-article-edit-done-function exit-func)
6797 (setq gnus-prev-winconf winconf)
6799 (gnus-message 6 "C-c C-c to end edits"))))
6801 (defun gnus-article-edit-done (&optional arg)
6802 "Update the article edits and exit."
6804 (let ((func gnus-article-edit-done-function)
6805 (buf (current-buffer))
6806 (start (window-start))
6808 (winconf gnus-prev-winconf))
6809 (widen) ;; Widen it in case that users narrowed the buffer.
6812 ;; The cache and backlog have to be flushed somewhat.
6813 (when gnus-keep-backlog
6814 (gnus-backlog-remove-article
6815 (car gnus-article-current) (cdr gnus-article-current)))
6816 ;; Flush original article as well.
6818 (when (get-buffer gnus-original-article-buffer)
6819 (set-buffer gnus-original-article-buffer)
6820 (setq gnus-original-article nil)))
6821 (when gnus-use-cache
6822 (gnus-cache-update-article
6823 (car gnus-article-current) (cdr gnus-article-current)))
6824 ;; We remove all text props from the article buffer.
6825 (kill-all-local-variables)
6826 (set-text-properties (point-min) (point-max) nil)
6828 (set-window-configuration winconf)
6830 (set-window-start (get-buffer-window buf) start)
6831 (set-window-point (get-buffer-window buf) (point)))
6832 (gnus-summary-show-article))
6834 (defun gnus-article-edit-exit ()
6835 "Exit the article editing without updating."
6837 (when (or (not (buffer-modified-p))
6838 (yes-or-no-p "Article modified; kill anyway? "))
6839 (let ((curbuf (current-buffer))
6841 (window-start (window-start)))
6843 (if (gnus-buffer-live-p gnus-original-article-buffer)
6844 (insert-buffer-substring gnus-original-article-buffer))
6845 (let ((winconf gnus-prev-winconf))
6846 (kill-all-local-variables)
6848 (set-window-configuration winconf)
6849 ;; Tippy-toe some to make sure that point remains where it was.
6850 (save-current-buffer
6852 (set-window-start (get-buffer-window (current-buffer)) window-start)
6854 (gnus-summary-show-article)))
6856 (defun gnus-article-edit-full-stops ()
6857 "Interactively repair spacing at end of sentences."
6860 (goto-char (point-min))
6861 (search-forward-regexp "^$" nil t)
6862 (let ((case-fold-search nil))
6863 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6866 ;;; Article highlights
6869 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6871 ;;; Internal Variables:
6873 (defcustom gnus-button-url-regexp
6875 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
6876 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
6877 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
6878 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
6879 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
6883 ;; Match paired parentheses, e.g. in Wikipedia URLs:
6884 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]"
6886 "[" chars punct "]+" "[" chars "]"
6888 (concat ;; XEmacs 21.4 doesn't support POSIX.
6889 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
6890 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
6892 "Regular expression that matches URLs."
6893 :group 'gnus-article-buttons
6896 (defcustom gnus-button-valid-fqdn-regexp
6897 message-valid-fqdn-regexp
6898 "Regular expression that matches a valid FQDN."
6900 :group 'gnus-article-buttons
6903 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6904 (defcustom gnus-button-valid-localpart-regexp
6905 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
6906 "Regular expression that matches a localpart of mail addresses or MIDs."
6908 :group 'gnus-article-buttons
6911 (defcustom gnus-button-man-handler 'manual-entry
6912 "Function to use for displaying man pages.
6913 The function must take at least one argument with a string naming the
6916 :type '(choice (function-item :tag "Man" manual-entry)
6917 (function-item :tag "Woman" woman)
6918 (function :tag "Other"))
6919 :group 'gnus-article-buttons)
6921 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6922 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6923 If the default site is too slow, try to find a CTAN mirror, see
6924 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6925 the variable `gnus-button-handle-ctan'."
6927 :group 'gnus-article-buttons
6928 :link '(custom-manual "(gnus)Group Parameters")
6929 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6930 (const "http://tug.ctan.org/tex-archive/")
6931 (const "http://www.dante.de/CTAN/")
6932 (string :tag "Other")))
6934 (defcustom gnus-button-ctan-handler 'browse-url
6935 "Function to use for displaying CTAN links.
6936 The function must take one argument, the string naming the URL."
6938 :type '(choice (function-item :tag "Browse Url" browse-url)
6939 (function :tag "Other"))
6940 :group 'gnus-article-buttons)
6942 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6943 "Bogus strings removed from CTAN URLs."
6945 :group 'gnus-article-buttons
6946 :type '(choice (const "^/?tex-archive/\\|/")
6947 (regexp :tag "Other")))
6949 (defcustom gnus-button-ctan-directory-regexp
6951 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
6952 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
6953 "languages" "macros" "nonfree" "obsolete" "support" "systems"
6954 "tds" "tools" "usergrps" "web") t)
6955 "Regular expression for ctan directories.
6956 It should match all directories in the top level of `gnus-ctan-url'."
6958 :group 'gnus-article-buttons
6961 (defcustom gnus-button-mid-or-mail-regexp
6962 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
6963 gnus-button-valid-fqdn-regexp
6965 "Regular expression that matches a message ID or a mail address."
6967 :group 'gnus-article-buttons
6970 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6971 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6972 Strings like this can be either a message ID or a mail address. If it is one
6973 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6974 message ID or a mail address, respectively. If this variable is set to the
6975 symbol `ask', always query the user what do do. If it is a function, this
6976 function will be called with the string as its only argument. The function
6977 must return `mid', `mail', `invalid' or `ask'."
6979 :group 'gnus-article-buttons
6980 :type '(choice (function-item :tag "Heuristic function"
6981 gnus-button-mid-or-mail-heuristic)
6986 (defcustom gnus-button-mid-or-mail-heuristic-alist
6987 '((-10.0 . ".+\\$.+@")
6990 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6991 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6992 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6993 (-1.0 . "^[^a-z]+@")
6995 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6996 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6997 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6998 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7001 (-1.0 . "^[0-9][0-9]")
7003 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7004 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7005 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7006 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7008 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7009 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7012 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7014 ;; compensation for TDMA dated mail addresses:
7015 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7017 (-20.0 . "\\.fsf@") ;; Gnus
7020 (-20.0 . "^alpine\\.")
7021 (-20.0 . "_-_") ;; Subject change in thread
7023 (-20.0 . "\\.ln@") ;; leafnode
7024 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7025 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7027 ;; (5.0 . "") ;; $local_part_len <= 7
7028 (10.0 . "^[^0-9]+@")
7029 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7030 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7033 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7035 (0.5 . "^[A-Z][a-z]")
7036 (0.5 . "^[A-Z][a-z][a-z]")
7037 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7038 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7039 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7041 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7042 address. The REGEXP is processed with `case-fold-search' set to nil."
7044 :group 'gnus-article-buttons
7045 :type '(repeat (cons (number :tag "Rate")
7046 (regexp :tag "Regexp"))))
7048 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7049 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7050 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7051 address, `ask' if unsure and `invalid' if the string is invalid."
7052 (let ((case-fold-search nil)
7053 (list gnus-button-mid-or-mail-heuristic-alist)
7054 (result 0) rate regexp lpartlen elem)
7056 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7057 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7058 ;; Certain special cases...
7061 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7062 "^[0-9]+\\.[0-9]+@compuserve\\|"
7063 "@public\\.gmane\\.org")
7065 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7066 (setq result 'mail))
7067 (when (string-match "@.*@\\| " mid-or-mail)
7068 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7069 (setq result 'invalid))
7070 ;; Nothing more to do, if result is not a number here...
7071 (when (numberp result)
7073 (setq elem (car list)
7077 (when (string-match regexp mid-or-mail)
7078 (setq result (+ result rate))
7080 9 "`%s' matched `%s', rate `%s', result `%s'."
7081 mid-or-mail regexp rate result)))
7082 (when (<= lpartlen 7)
7083 (setq result (+ result 5.0))
7084 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7085 mid-or-mail result))
7086 (when (>= lpartlen 12)
7087 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7089 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7090 ;; Long local part should contain realname if e-mail address,
7091 ;; too many digits: message-id.
7092 ;; $score -= 5.0 + 0.1 * $local_part_len;
7093 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7094 (setq result (+ result rate))
7096 9 "Many digits in `%s', rate `%s', result `%s'."
7097 mid-or-mail rate result))
7098 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7100 ;; Too few vowels [^aeiouy]{4,}.*\@
7101 (setq result (+ result -5.0))
7103 9 "Few vowels in `%s', rate `%s', result `%s'."
7104 mid-or-mail -5.0 result))
7106 (setq result (+ result 5.0))
7108 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7109 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7110 ;; Maybe we should make this a customizable alist: (condition . 'result)
7112 ((symbolp result) result)
7113 ;; Now convert number into proper results:
7114 ((< result -10.0) 'mid)
7115 ((> result 10.0) 'mail)
7118 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7119 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7120 (url-mid (concat "news" ":" mid-or-mail))
7121 (url-mailto (concat "mailto" ":" mid-or-mail)))
7122 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7123 (when (fboundp pref)
7125 ;; get rid of surrounding angles...
7127 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7128 (if (or (eq 'mid guessed) (eq 'mail guessed))
7132 (save-window-excursion
7133 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7136 (cond ((eq pref 'mid)
7137 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7138 (gnus-button-handle-news url-mid))
7140 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7141 (gnus-url-mailto url-mailto))
7142 (t (gnus-message 3 "Invalid string.")))))
7144 (defun gnus-button-handle-custom (fun arg)
7145 "Call function FUN on argument ARG.
7146 Both FUN and ARG are supposed to be strings. ARG will be passed
7147 as a symbol to FUN."
7148 (funcall (intern fun)
7149 (if (string-match "^customize-apropos" fun)
7153 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7155 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7158 (defun gnus-button-handle-describe-function (url)
7159 "Call `describe-function' when pushing the corresponding URL button."
7162 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7164 (defun gnus-button-handle-describe-variable (url)
7165 "Call `describe-variable' when pushing the corresponding URL button."
7168 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7170 (defun gnus-button-handle-symbol (url)
7171 "Display help on variable or function.
7172 Calls `describe-variable' or `describe-function'."
7173 (let ((sym (intern url)))
7175 ((fboundp sym) (describe-function sym))
7176 ((boundp sym) (describe-variable sym))
7177 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7179 (defun gnus-button-handle-describe-key (url)
7180 "Call `describe-key' when pushing the corresponding URL button."
7182 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7183 (keys (ignore-errors (eval `(kbd ,key-string)))))
7186 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7188 (defun gnus-button-handle-apropos (url)
7189 "Call `apropos' when pushing the corresponding URL button."
7190 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7192 (defun gnus-button-handle-apropos-command (url)
7193 "Call `apropos' when pushing the corresponding URL button."
7195 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7197 (defun gnus-button-handle-apropos-variable (url)
7198 "Call `apropos' when pushing the corresponding URL button."
7200 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7201 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7203 (defun gnus-button-handle-apropos-documentation (url)
7204 "Call `apropos' when pushing the corresponding URL button."
7206 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7207 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7209 (defun gnus-button-handle-library (url)
7210 "Call `locate-library' when pushing the corresponding URL button."
7211 (gnus-message 9 "url=`%s'" url)
7212 (let* ((lib (locate-library url))
7213 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7215 (gnus-message 1 "Cannot locale library `%s'." url)
7216 (find-file-read-only file))))
7218 (defun gnus-button-handle-ctan (url)
7219 "Call `browse-url' when pushing a CTAN URL button."
7221 gnus-button-ctan-handler
7224 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7226 (defcustom gnus-button-tex-level 5
7227 "*Integer that says how many TeX-related buttons Gnus will show.
7228 The higher the number, the more buttons will appear and the more false
7229 positives are possible. Note that you can set this variable local to
7230 specific groups. Setting it higher in TeX groups is probably a good idea.
7231 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7232 how to set variables in specific groups."
7234 :group 'gnus-article-buttons
7235 :link '(custom-manual "(gnus)Group Parameters")
7238 (defcustom gnus-button-man-level 5
7239 "*Integer that says how many man-related buttons Gnus will show.
7240 The higher the number, the more buttons will appear and the more false
7241 positives are possible. Note that you can set this variable local to
7242 specific groups. Setting it higher in Unix groups is probably a good idea.
7243 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7244 how to set variables in specific groups."
7246 :group 'gnus-article-buttons
7247 :link '(custom-manual "(gnus)Group Parameters")
7250 (defcustom gnus-button-emacs-level 5
7251 "*Integer that says how many emacs-related buttons Gnus will show.
7252 The higher the number, the more buttons will appear and the more false
7253 positives are possible. Note that you can set this variable local to
7254 specific groups. Setting it higher in Emacs or Gnus related groups is
7255 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7256 `gnus-parameters' on how to set variables in specific groups."
7258 :group 'gnus-article-buttons
7259 :link '(custom-manual "(gnus)Group Parameters")
7262 (defcustom gnus-button-message-level 5
7263 "*Integer that says how many buttons for news or mail messages will appear.
7264 The higher the number, the more buttons will appear and the more false
7265 positives are possible."
7266 ;; mail addresses, MIDs, URLs for news, ...
7268 :group 'gnus-article-buttons
7271 (defcustom gnus-button-browse-level 5
7272 "*Integer that says how many buttons for browsing will appear.
7273 The higher the number, the more buttons will appear and the more false
7274 positives are possible."
7275 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7277 :group 'gnus-article-buttons
7280 (defcustom gnus-button-alist
7281 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7282 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7283 ((concat "\\b\\(nntp\\|news\\):\\("
7284 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7285 0 t gnus-button-handle-news 2)
7286 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7287 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7288 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7289 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7290 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7291 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7292 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7293 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7294 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7295 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7296 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7297 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7298 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7299 ;; RFC 2368 (The mailto URL scheme)
7300 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7301 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7302 ("\\bmailto:\\([^ \n\t]+\\)"
7303 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7305 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7306 gnus-button-ctan-directory-regexp
7307 "[^][>)!;:,'\n\t ]+\\)")
7308 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7309 ((concat "\\btex-archive/\\("
7310 gnus-button-ctan-directory-regexp
7311 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7312 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7315 gnus-button-ctan-directory-regexp
7316 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7317 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7318 ;; This is info (home-grown style) <info://foo/bar+baz>
7319 ("\\binfo://\\([^'\">\n\t ]+\\)"
7320 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7321 ;; Info GNOME style <info:foo#bar_baz>
7322 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7323 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7324 ;; Info KDE style <info:(foo)bar baz>
7325 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7326 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7327 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7328 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7329 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
7330 ;; Info links like `C-h i d m CC Mode RET'
7331 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
7333 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7334 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7335 ;; Emacs help commands
7336 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7337 ;; regexp doesn't match arguments containing ` '.
7338 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7339 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7340 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7341 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7342 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7343 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7344 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7345 ;; The following entries may lead to many false positives so don't enable
7346 ;; them by default (use a high button level).
7347 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7348 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7349 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7350 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7351 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7352 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7353 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7354 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7355 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7356 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7357 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7358 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7359 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7360 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7361 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7362 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7363 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7364 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7365 ;; Unlike the other regexps we really have to require quoting
7366 ;; here to determine where it ends.
7367 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7368 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7369 ("<URL: *\\([^\n<>]*\\)>"
7370 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7371 ;; RFC 2396 (2.4.3., delims) ...
7372 ("\"URL: *\\([^\n\"]*\\)\""
7373 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7375 (gnus-button-url-regexp
7376 0 (>= gnus-button-browse-level 0) browse-url 0)
7378 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7379 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7380 gnus-button-handle-man 1)
7381 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7382 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7383 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7384 gnus-button-handle-man 1)
7385 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7386 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7387 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7388 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7389 ;; Recognizing patches to .el files. This is somewhat obscure,
7390 ;; but considering the percentage of Gnus users who hack Emacs
7392 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7393 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7394 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7395 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7396 ;; MID or mail: To avoid too many false positives we don't try to catch
7397 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7398 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7399 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7400 ;; so that non-ambiguous entries (see above) match first.
7401 (gnus-button-mid-or-mail-regexp
7402 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7403 "*Alist of regexps matching buttons in article bodies.
7405 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7406 REGEXP: is the string (case insensitive) matching text around the button (can
7407 also be Lisp expression evaluating to a string),
7408 BUTTON: is the number of the regexp grouping actually matching the button,
7409 FORM: is a Lisp expression which must eval to true for the button to
7411 CALLBACK: is the function to call when the user push this button, and each
7412 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7414 CALLBACK can also be a variable, in that case the value of that
7415 variable it the real callback function."
7416 :group 'gnus-article-buttons
7417 :type '(repeat (list (choice regexp variable sexp)
7418 (integer :tag "Button")
7420 (function :tag "Callback")
7423 (integer :tag "Regexp group")))))
7424 (put 'gnus-button-alist 'risky-local-variable t)
7426 (defcustom gnus-header-button-alist
7427 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7428 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7429 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7430 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7431 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7432 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7433 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7434 0 (>= gnus-button-browse-level 0) browse-url 0)
7435 ("^Subject:" gnus-button-url-regexp
7436 0 (>= gnus-button-browse-level 0) browse-url 0)
7437 ("^[^:]+:" gnus-button-url-regexp
7438 0 (>= gnus-button-browse-level 0) browse-url 0)
7439 ("^OpenPGP:.*url=" gnus-button-url-regexp
7440 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7441 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7442 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7443 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7444 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7445 "*Alist of headers and regexps to match buttons in article heads.
7447 This alist is very similar to `gnus-button-alist', except that each
7448 alist has an additional HEADER element first in each entry:
7450 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7452 HEADER is a regexp to match a header. For a fuller explanation, see
7453 `gnus-button-alist'."
7454 :group 'gnus-article-buttons
7455 :group 'gnus-article-headers
7456 :type '(repeat (list (regexp :tag "Header")
7457 (choice regexp variable)
7458 (integer :tag "Button")
7460 (function :tag "Callback")
7463 (integer :tag "Regexp group")))))
7464 (put 'gnus-header-button-alist 'risky-local-variable t)
7468 (defun gnus-article-push-button (event)
7469 "Check text under the mouse pointer for a callback function.
7470 If the text under the mouse pointer has a `gnus-callback' property,
7471 call it with the value of the `gnus-data' text property."
7473 (set-buffer (window-buffer (posn-window (event-start event))))
7474 (let* ((pos (posn-point (event-start event)))
7475 (data (get-text-property pos 'gnus-data))
7476 (fun (get-text-property pos 'gnus-callback)))
7479 (funcall fun data))))
7481 (defun gnus-article-press-button ()
7482 "Check text at point for a callback function.
7483 If the text at point has a `gnus-callback' property,
7484 call it with the value of the `gnus-data' text property."
7486 (let ((data (get-text-property (point) 'gnus-data))
7487 (fun (get-text-property (point) 'gnus-callback)))
7489 (funcall fun data))))
7491 (defun gnus-article-highlight (&optional force)
7492 "Highlight current article.
7493 This function calls `gnus-article-highlight-headers',
7494 `gnus-article-highlight-citation',
7495 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7496 do the highlighting. See the documentation for those functions."
7497 (interactive (list 'force))
7498 (gnus-article-highlight-headers)
7499 (gnus-article-highlight-citation force)
7500 (gnus-article-highlight-signature)
7501 (gnus-article-add-buttons force)
7502 (gnus-article-add-buttons-to-head))
7504 (defun gnus-article-highlight-some (&optional force)
7505 "Highlight current article.
7506 This function calls `gnus-article-highlight-headers',
7507 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7508 do the highlighting. See the documentation for those functions."
7509 (interactive (list 'force))
7510 (gnus-article-highlight-headers)
7511 (gnus-article-highlight-signature)
7512 (gnus-article-add-buttons))
7514 (defun gnus-article-highlight-headers ()
7515 "Highlight article headers as specified by `gnus-header-face-alist'."
7517 (gnus-with-article-headers
7518 (let (regexp header-face field-face from hpoints fpoints)
7519 (dolist (entry gnus-header-face-alist)
7520 (goto-char (point-min))
7521 (setq regexp (concat "^\\("
7522 (if (string-equal "" (nth 0 entry))
7526 header-face (nth 1 entry)
7527 field-face (nth 2 entry))
7528 (while (and (re-search-forward regexp nil t)
7532 (unless (search-forward ":" nil t)
7534 (when (and header-face
7535 (not (memq (point) hpoints)))
7536 (push (point) hpoints)
7537 (gnus-put-text-property from (point) 'face header-face))
7538 (when (and field-face
7539 (not (memq (setq from (point)) fpoints)))
7541 (if (re-search-forward "^[^ \t]" nil t)
7543 (goto-char (point-max)))
7544 (gnus-put-text-property from (point) 'face field-face)))))))
7546 (defun gnus-article-highlight-signature ()
7547 "Highlight the signature in an article.
7548 It does this by highlighting everything after
7549 `gnus-signature-separator' using the face `gnus-signature'."
7551 (gnus-with-article-buffer
7552 (let ((inhibit-point-motion-hooks t))
7554 (when (and gnus-signature-face
7555 (gnus-article-narrow-to-signature))
7556 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7557 'face gnus-signature-face)
7559 (gnus-article-search-signature)
7560 (let ((start (match-beginning 0))
7561 (end (set-marker (make-marker) (1+ (match-end 0)))))
7562 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7565 (defun gnus-button-in-region-p (b e prop)
7566 "Say whether PROP exists in the region."
7567 (text-property-not-all b e prop nil))
7569 (defun gnus-article-add-buttons (&optional force)
7570 "Find external references in the article and make buttons of them.
7571 \"External references\" are things like Message-IDs and URLs, as
7572 specified by `gnus-button-alist'."
7573 (interactive (list 'force))
7574 (gnus-with-article-buffer
7575 (let ((inhibit-point-motion-hooks t)
7576 (case-fold-search t)
7577 (alist gnus-button-alist)
7579 ;; Remove all old markers.
7580 (let (marker entry new-list)
7581 (while (setq marker (pop gnus-button-marker-list))
7582 (if (or (< marker (point-min)) (>= marker (point-max)))
7583 (push marker new-list)
7585 (when (setq entry (gnus-button-entry))
7586 (put-text-property (match-beginning (nth 1 entry))
7587 (match-end (nth 1 entry))
7588 'gnus-callback nil))
7589 (set-marker marker nil)))
7590 (setq gnus-button-marker-list new-list))
7591 ;; We skip the headers.
7594 (while (setq entry (pop alist))
7595 (setq regexp (eval (car entry)))
7597 (while (re-search-forward regexp nil t)
7598 (let ((start (match-beginning (nth 1 entry)))
7599 (end (match-end (nth 1 entry)))
7600 (from (match-beginning 0)))
7601 (when (and (or (eq t (nth 2 entry))
7602 (eval (nth 2 entry)))
7603 (not (gnus-button-in-region-p
7604 start end 'gnus-callback)))
7605 ;; That optional form returned non-nil, so we add the
7607 (setq from (set-marker (make-marker) from))
7608 (push from gnus-button-marker-list)
7609 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7610 (gnus-article-extend-url-button from start end))
7611 (gnus-article-add-button start end
7612 'gnus-button-push from)))))))))
7614 (defun gnus-article-extend-url-button (beg start end)
7615 "Extend url button if url is folded into two or more lines.
7616 Return non-nil if button is extended. BEG is a marker that points to
7617 the beginning position of a text containing url. START and END are
7618 the endpoints of a url button before it is extended. The concatenated
7619 url is put as the `gnus-button-url' overlay property on the button."
7620 (let ((opoint (point))
7621 (points (list start end))
7626 (not (looking-at "[\t ]*[\">]")))
7630 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7631 (buffer-substring (point-at-bol) start)))
7633 (setq url (list (buffer-substring start end))
7634 delim (if (match-beginning 1) ">" "\""))
7636 (setq regexp (concat
7637 (when (and (looking-at
7638 message-cite-prefix-regexp)
7639 (< (match-end 0) start))
7640 (regexp-quote (match-string 0)))
7642 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7646 (and (looking-at regexp)
7649 (push (or (match-string 2)
7652 (push (setq end (or (match-end 2)
7655 (push (or (match-beginning 2)
7656 (match-beginning 1))
7658 (match-beginning 2)))
7659 (let (gnus-article-mouse-face widget-mouse-face)
7661 (gnus-article-add-button (pop points) (pop points)
7662 'gnus-button-push beg)))
7663 (let ((overlay (gnus-make-overlay start end)))
7664 (gnus-overlay-put overlay 'evaporate t)
7665 (gnus-overlay-put overlay 'gnus-button-url
7666 (list (mapconcat 'identity (nreverse url) "")))
7667 (when gnus-article-mouse-face
7668 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7670 (goto-char opoint))))
7672 ;; Add buttons to the head of an article.
7673 (defun gnus-article-add-buttons-to-head ()
7674 "Add buttons to the head of the article."
7676 (gnus-with-article-headers
7678 (dolist (entry gnus-header-button-alist)
7679 ;; Each alist entry.
7680 (goto-char (point-min))
7681 (while (re-search-forward (car entry) nil t)
7682 ;; Each header matching the entry.
7683 (setq beg (match-beginning 0))
7684 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7685 (match-beginning 0))
7688 (while (re-search-forward (eval (nth 1 entry)) end t)
7689 ;; Each match within a header.
7690 (let* ((entry (cdr entry))
7691 (start (match-beginning (nth 1 entry)))
7692 (end (match-end (nth 1 entry)))
7693 (form (nth 2 entry)))
7694 (goto-char (match-end 0))
7696 (gnus-article-add-button
7697 start end (nth 3 entry)
7698 (buffer-substring (match-beginning (nth 4 entry))
7699 (match-end (nth 4 entry)))))))
7700 (goto-char end))))))
7702 ;;; External functions:
7704 (defun gnus-article-add-button (from to fun &optional data)
7705 "Create a button between FROM and TO with callback FUN and data DATA."
7706 (when gnus-article-button-face
7707 (gnus-overlay-put (gnus-make-overlay from to nil t)
7708 'face gnus-article-button-face))
7709 (gnus-add-text-properties
7711 (nconc (and gnus-article-mouse-face
7712 (list gnus-mouse-face-prop gnus-article-mouse-face))
7713 (list 'gnus-callback fun)
7714 (and data (list 'gnus-data data))))
7715 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7716 :button-keymap gnus-widget-button-keymap))
7718 ;;; Internal functions:
7720 (defun gnus-article-set-globals ()
7721 (with-current-buffer gnus-summary-buffer
7722 (gnus-set-global-variables)))
7724 (defun gnus-signature-toggle (end)
7725 (gnus-with-article-buffer
7726 (let ((inhibit-point-motion-hooks t))
7727 (if (text-property-any end (point-max) 'article-type 'signature)
7729 (gnus-delete-wash-type 'signature)
7730 (gnus-remove-text-properties-when
7731 'article-type 'signature end (point-max)
7732 (cons 'article-type (cons 'signature
7733 gnus-hidden-properties))))
7734 (gnus-add-wash-type 'signature)
7735 (gnus-add-text-properties-when
7736 'article-type nil end (point-max)
7737 (cons 'article-type (cons 'signature
7738 gnus-hidden-properties)))))
7739 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7740 (gnus-set-mode-line 'article))))
7742 (defun gnus-button-entry ()
7743 ;; Return the first entry in `gnus-button-alist' matching this place.
7744 (let ((alist gnus-button-alist)
7747 (setq entry (pop alist))
7748 (if (looking-at (eval (car entry)))
7753 (defun gnus-button-push (marker)
7754 ;; Push button starting at MARKER.
7757 (let* ((entry (gnus-button-entry))
7758 (inhibit-point-motion-hooks t)
7760 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7761 (get-char-property marker 'gnus-button-url))
7762 (mapcar (lambda (group)
7763 (let ((string (match-string group)))
7764 (set-text-properties
7765 0 (length string) nil string)
7767 (nthcdr 4 entry)))))
7772 (fboundp (symbol-value fun)))
7773 (apply (symbol-value fun) args))
7775 (gnus-message 1 "You must define `%S' to use this button"
7776 (cons fun args)))))))
7778 (defun gnus-parse-news-url (url)
7779 (let (scheme server port group message-id articles)
7782 (goto-char (point-min))
7783 (when (looking-at "\\([A-Za-z]+\\):")
7784 (setq scheme (match-string 1))
7785 (goto-char (match-end 0)))
7786 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7787 (setq server (match-string 1))
7788 (setq port (if (stringp (match-string 3))
7789 (string-to-number (match-string 3))
7791 (goto-char (match-end 0)))
7794 ((looking-at "\\(.*@.*\\)")
7795 (setq message-id (match-string 1)))
7796 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7797 (setq group (match-string 1)
7798 articles (split-string (match-string 2) "-")))
7799 ((looking-at "\\([^/]+\\)/?")
7800 (setq group (match-string 1)))
7802 (error "Unknown news URL syntax"))))
7803 (list scheme server port group message-id articles)))
7805 (defun gnus-button-handle-news (url)
7807 (destructuring-bind (scheme server port group message-id articles)
7808 (gnus-parse-news-url url)
7812 (set-buffer gnus-summary-buffer)
7814 (let ((gnus-refer-article-method
7815 (nconc (list (list 'nntp server))
7816 gnus-refer-article-method))
7817 (nntp-port-number (or port "nntp")))
7818 (gnus-message 7 "Fetching %s with %s"
7819 message-id gnus-refer-article-method)
7820 (gnus-summary-refer-article message-id))
7821 (gnus-summary-refer-article message-id))))
7823 (gnus-button-fetch-group url)))))
7825 (defun gnus-button-patch (library line)
7826 "Visit an Emacs Lisp library LIBRARY on line LINE."
7828 (let ((file (locate-library (file-name-nondirectory library))))
7830 (error "Couldn't find library %s" library))
7832 (goto-line (string-to-number line))))
7834 (defun gnus-button-handle-man (url)
7836 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7837 (when (eq gnus-button-man-handler 'woman)
7838 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7839 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7840 (funcall gnus-button-man-handler url))
7842 (defun gnus-button-handle-info-url (url)
7843 "Fetch an info URL."
7844 (setq url (mm-subst-char-in-string ?+ ?\ url))
7846 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7847 (gnus-info-find-node
7848 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7850 ")" (gnus-url-unhex-string (match-string 2 url)))))
7851 ((string-match "([^)\"]+)[^\"]+" url)
7853 (gnus-replace-in-string
7854 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7855 (gnus-info-find-node url))
7856 (t (error "Can't parse %s" url))))
7858 (defun gnus-button-handle-info-url-gnome (url)
7859 "Fetch GNOME style info URL."
7860 (setq url (mm-subst-char-in-string ?_ ?\ url))
7861 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7862 (gnus-info-find-node
7864 (gnus-url-unhex-string
7865 (match-string 1 url))
7867 (or (gnus-url-unhex-string
7868 (match-string 2 url))
7870 (error "Can't parse %s" url)))
7872 (defun gnus-button-handle-info-url-kde (url)
7873 "Fetch KDE style info URL."
7874 (gnus-info-find-node (gnus-url-unhex-string url)))
7876 ;; (info) will autoload info.el
7877 (declare-function Info-menu "info" (menu-item &optional fork))
7879 (defun gnus-button-handle-info-keystrokes (url)
7880 "Call `info' when pushing the corresponding URL button."
7881 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7886 (defun gnus-button-openpgp (url)
7887 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
7889 (mm-url-insert-file-contents-external url)
7890 (pgg-snarf-keys-region (point-min) (point-max))
7891 (pgg-display-output-buffer nil nil nil)))
7893 (defun gnus-button-message-id (message-id)
7895 (with-current-buffer gnus-summary-buffer
7896 (gnus-summary-refer-article message-id)))
7898 (defun gnus-button-fetch-group (address &rest ignore)
7899 "Fetch GROUP specified by ADDRESS."
7900 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
7902 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
7903 ;; for nntp:// and news://
7904 (setq address (match-string 3 address)))
7905 (if (not (string-match "[:/]" address))
7906 ;; This is just a simple group url.
7907 (gnus-group-read-ephemeral-group address gnus-select-method)
7910 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7912 (error "Can't parse %s" address)
7913 (gnus-group-read-ephemeral-group
7914 (match-string 4 address)
7915 `(nntp ,(match-string 1 address)
7916 (nntp-address ,(match-string 1 address))
7917 (nntp-port-number ,(if (match-end 3)
7918 (match-string 3 address)
7921 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
7923 (defun gnus-url-parse-query-string (query &optional downcase)
7924 (let (retval pairs cur key val)
7925 (setq pairs (split-string query "&"))
7927 (setq cur (car pairs)
7929 (if (not (string-match "=" cur))
7931 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7932 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7934 (setq key (downcase key)))
7935 (setq cur (assoc key retval))
7937 (setcdr cur (cons val (cdr cur)))
7938 (setq retval (cons (list key val) retval)))))
7941 (defun gnus-url-mailto (url)
7942 ;; Send mail to someone
7943 (when (string-match "mailto:/*\\(.*\\)" url)
7944 (setq url (substring url (match-beginning 1) nil)))
7945 (let (to args subject func)
7946 (setq args (gnus-url-parse-query-string
7947 (if (string-match "^\\?" url)
7949 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7950 (concat "to=" (match-string 1 url) "&"
7951 (match-string 2 url))
7952 (concat "to=" url)))
7954 subject (cdr-safe (assoc "subject" args)))
7957 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7960 (message-position-on-field (caar args)))
7961 (insert (gnus-replace-in-string
7962 (mapconcat 'identity (reverse (cdar args)) ", ")
7964 (setq args (cdr args)))
7967 (message-goto-subject))))
7969 (defun gnus-button-embedded-url (address)
7970 "Activate ADDRESS with `browse-url'."
7971 (browse-url (gnus-strip-whitespace address)))
7973 ;;; Next/prev buttons in the article buffer.
7975 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7976 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7978 (defvar gnus-prev-page-map
7979 (let ((map (make-sparse-keymap)))
7980 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7981 (define-key map "\r" 'gnus-button-prev-page)
7984 (defvar gnus-next-page-map
7985 (let ((map (make-sparse-keymap)))
7986 (unless (>= emacs-major-version 21)
7987 ;; XEmacs doesn't care.
7988 (set-keymap-parent map gnus-article-mode-map))
7989 (define-key map gnus-mouse-2 'gnus-button-next-page)
7990 (define-key map "\r" 'gnus-button-next-page)
7993 (defun gnus-insert-prev-page-button ()
7995 (inhibit-read-only t))
7997 gnus-prev-page-line-format nil
7998 `(keymap ,gnus-prev-page-map
8000 gnus-callback gnus-article-button-prev-page
8001 article-type annotation))
8003 ;; Exclude a newline.
8006 (when gnus-article-button-face
8007 (gnus-overlay-put (gnus-make-overlay b e nil t)
8008 'face gnus-article-button-face))
8009 (widget-convert-button
8011 :action 'gnus-button-prev-page
8012 :button-keymap gnus-prev-page-map)))
8014 (defun gnus-button-next-page (&optional args more-args)
8015 "Go to the next page."
8017 (let ((win (selected-window)))
8018 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8019 (gnus-article-next-page)
8020 (select-window win)))
8022 (defun gnus-button-prev-page (&optional args more-args)
8023 "Go to the prev page."
8025 (let ((win (selected-window)))
8026 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8027 (gnus-article-prev-page)
8028 (select-window win)))
8030 (defun gnus-insert-next-page-button ()
8032 (inhibit-read-only t))
8033 (gnus-eval-format gnus-next-page-line-format nil
8034 `(keymap ,gnus-next-page-map
8036 gnus-callback gnus-article-button-next-page
8037 article-type annotation))
8039 ;; Exclude a newline.
8042 (when gnus-article-button-face
8043 (gnus-overlay-put (gnus-make-overlay b e nil t)
8044 'face gnus-article-button-face))
8045 (widget-convert-button
8047 :action 'gnus-button-next-page
8048 :button-keymap gnus-next-page-map)))
8050 (defun gnus-article-button-next-page (arg)
8051 "Go to the next page."
8053 (let ((win (selected-window)))
8054 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8055 (gnus-article-next-page)
8056 (select-window win)))
8058 (defun gnus-article-button-prev-page (arg)
8059 "Go to the prev page."
8061 (let ((win (selected-window)))
8062 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8063 (gnus-article-prev-page)
8064 (select-window win)))
8066 (defvar gnus-decode-header-methods
8067 '(mail-decode-encoded-word-region)
8068 "List of methods used to decode headers.
8070 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8071 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8072 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8073 whose names match REGEXP.
8076 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8077 mail-decode-encoded-word-region
8078 (\"chinese\" . rfc1843-decode-region))
8081 (defvar gnus-decode-header-methods-cache nil)
8083 (defun gnus-multi-decode-header (start end)
8084 "Apply the functions from `gnus-encoded-word-methods' that match."
8085 (unless (and gnus-decode-header-methods-cache
8086 (eq gnus-newsgroup-name
8087 (car gnus-decode-header-methods-cache)))
8088 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8089 (dolist (x gnus-decode-header-methods)
8091 (nconc gnus-decode-header-methods-cache (list x))
8092 (if (and gnus-newsgroup-name
8093 (string-match (car x) gnus-newsgroup-name))
8094 (nconc gnus-decode-header-methods-cache
8096 (let ((xlist gnus-decode-header-methods-cache))
8099 (narrow-to-region start end)
8101 (funcall (pop xlist) (point-min) (point-max))))))
8104 ;;; Treatment top-level handling.
8107 (defun gnus-treat-article (condition &optional part-number total-parts type)
8108 (let ((length (- (point-max) (point-min)))
8109 (alist gnus-treatment-function-alist)
8110 (article-goto-body-goes-to-point-min-p t)
8114 (let ((list gnus-article-treat-types))
8116 (when (string-match (pop list) type)
8117 (throw 'found t)))))))
8118 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8120 (gnus-run-hooks 'gnus-part-display-hook)
8121 (dolist (elem alist)
8124 (when (gnus-buffer-live-p gnus-summary-buffer)
8125 (set-buffer gnus-summary-buffer))
8126 (symbol-value (car elem))))
8127 (when (and (or (consp val)
8129 (gnus-treat-predicate val)
8130 (or (not (get (car elem) 'highlight))
8133 (funcall (cadr elem)))))))
8135 ;; Dynamic variables.
8136 (defvar part-number)
8137 (defvar total-parts)
8142 (defun gnus-treat-predicate (val)
8149 (stringp (car val)))
8150 (apply 'gnus-or (mapcar `(lambda (s)
8151 (string-match s ,(or gnus-newsgroup-name "")))
8154 (let ((pred (pop val)))
8157 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8159 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8161 (not (gnus-treat-predicate (car val))))
8163 (equal (car val) type))
8165 (error "%S is not a valid predicate" pred)))))
8173 (eq part-number total-parts))
8177 (error "%S is not a valid value" val))))
8179 (defun gnus-article-encrypt-body (protocol &optional n)
8180 "Encrypt the article body."
8183 (or gnus-article-encrypt-protocol
8184 (completing-read "Encrypt protocol: "
8185 gnus-article-encrypt-protocol-alist
8187 current-prefix-arg))
8188 ;; User might hit `K E' instead of `K e', so prompt once.
8189 (when (and gnus-article-encrypt-protocol
8191 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8192 (error "Encrypt aborted.")))
8193 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8195 (error "Can't find the encrypt protocol %s" protocol))
8196 (if (member gnus-newsgroup-name '("nndraft:delayed"
8199 (error "Can't encrypt the article in group %s"
8200 gnus-newsgroup-name))
8201 (gnus-summary-iterate n
8203 (set-buffer gnus-summary-buffer)
8204 (let ((mail-parse-charset gnus-newsgroup-charset)
8205 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8206 (summary-buffer gnus-summary-buffer)
8208 (gnus-set-global-variables)
8209 (when (gnus-group-read-only-p)
8210 (error "The current newsgroup does not support article encrypt"))
8211 (gnus-summary-show-article t)
8213 (or (mail-header-references gnus-current-headers) ""))
8214 (set-buffer gnus-article-buffer)
8215 (let* ((inhibit-read-only t)
8217 (mapcar (lambda (field)
8218 (and (save-restriction
8219 (message-narrow-to-head)
8220 (goto-char (point-min))
8221 (search-forward field nil t))
8223 (message-narrow-to-field)
8225 (delete-region (point-min) (point-max))
8227 '("Content-Type:" "Content-Transfer-Encoding:"
8228 "Content-Disposition:"))))
8229 (message-narrow-to-head)
8230 (message-remove-header "MIME-Version")
8231 (goto-char (point-max))
8232 (setq point (point))
8233 (insert (apply 'concat headers))
8235 (narrow-to-region point (point-max))
8236 (let ((message-options message-options))
8237 (message-options-set 'message-sender user-mail-address)
8238 (message-options-set 'message-recipients user-mail-address)
8239 (message-options-set 'message-sign-encrypt 'not)
8241 (goto-char (point-min))
8242 (insert "MIME-Version: 1.0\n")
8244 (gnus-summary-edit-article-done
8245 references nil summary-buffer t))
8246 (when gnus-keep-backlog
8247 (gnus-backlog-remove-article
8248 (car gnus-article-current) (cdr gnus-article-current)))
8250 (when (get-buffer gnus-original-article-buffer)
8251 (set-buffer gnus-original-article-buffer)
8252 (setq gnus-original-article nil)))
8253 (when gnus-use-cache
8254 (gnus-cache-update-article
8255 (car gnus-article-current) (cdr gnus-article-current))))))))
8257 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8258 "The following specs can be used:
8259 %t The security MIME type
8262 %D Details if button is pressed")
8264 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8265 "The following specs can be used:
8266 %t The security MIME type
8269 %D Details if button is pressed")
8271 (defvar gnus-mime-security-button-line-format-alist
8272 '((?t gnus-tmp-type ?s)
8273 (?i gnus-tmp-info ?s)
8274 (?d gnus-tmp-details ?s)
8275 (?D gnus-tmp-pressed-details ?s)))
8277 (defvar gnus-mime-security-button-commands
8278 '((gnus-article-press-button "\r" "Show Detail")
8282 (gnus-mime-security-save-part "o" "Save...")
8291 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8294 (defvar gnus-mime-security-button-map
8295 (let ((map (make-sparse-keymap)))
8296 (define-key map gnus-mouse-2 'gnus-article-push-button)
8297 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8298 (dolist (c gnus-mime-security-button-commands)
8299 (define-key map (cadr c) (car c)))
8303 gnus-mime-security-button-menu gnus-mime-security-button-map
8304 "Security button menu."
8308 (unless (eq (car c) 'undefined)
8309 (vector (caddr c) (car c) :active t)))
8310 gnus-mime-security-button-commands))))
8312 (defun gnus-mime-security-button-menu (event prefix)
8313 "Construct a context-sensitive menu of security commands."
8314 (interactive "e\nP")
8315 (save-window-excursion
8316 (let ((pos (event-start event)))
8317 (select-window (posn-window pos))
8318 (goto-char (posn-point pos))
8319 (gnus-article-check-buffer)
8320 (popup-menu gnus-mime-security-button-menu nil prefix))))
8322 (defvar gnus-mime-security-details-buffer nil)
8324 (defvar gnus-mime-security-button-pressed nil)
8326 (defvar gnus-mime-security-show-details-inline t
8327 "If non-nil, show details in the article buffer.")
8329 (defun gnus-mime-security-verify-or-decrypt (handle)
8330 (mm-remove-parts (cdr handle))
8331 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8332 point (inhibit-read-only t))
8334 (goto-char (car region)))
8335 (setq point (point))
8336 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8337 (let* ((mm-verify-option 'known)
8338 (mm-decrypt-option 'known)
8339 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8340 (unless (eq nparts (cdr handle))
8341 (mm-destroy-parts (cdr handle))
8342 (setcdr handle nparts))))
8343 (gnus-mime-display-security handle)
8345 (delete-region (point) (cdr region))
8346 (set-marker (car region) nil)
8347 (set-marker (cdr region) nil))
8350 (defun gnus-mime-security-show-details (handle)
8351 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8353 (gnus-message 5 "No details.")
8354 (if gnus-mime-security-show-details-inline
8355 (let ((gnus-mime-security-button-pressed
8356 (not (get-text-property (point) 'gnus-mime-details)))
8357 (gnus-mime-security-button-line-format
8358 (get-text-property (point) 'gnus-line-format))
8359 (inhibit-read-only t))
8361 (while (eq (get-text-property (point) 'gnus-line-format)
8362 gnus-mime-security-button-line-format)
8366 (narrow-to-region (point) (point))
8367 (gnus-insert-mime-security-button handle))
8368 (delete-region (point)
8369 (or (text-property-not-all
8372 gnus-mime-security-button-line-format)
8375 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8376 (with-current-buffer gnus-mime-security-details-buffer
8379 (setq gnus-mime-security-details-buffer
8380 (gnus-get-buffer-create "*MIME Security Details*")))
8381 (with-current-buffer gnus-mime-security-details-buffer
8383 (goto-char (point-min)))
8384 (pop-to-buffer gnus-mime-security-details-buffer)))))
8386 (defun gnus-mime-security-press-button (handle)
8388 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8389 (gnus-mime-security-show-details handle)
8390 (gnus-mime-security-verify-or-decrypt handle))))
8392 (defun gnus-insert-mime-security-button (handle &optional displayed)
8393 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8396 (or (nth 2 (assoc protocol mm-verify-function-alist))
8397 (nth 2 (assoc protocol mm-decrypt-function-alist))
8399 (if (equal (car handle) "multipart/signed")
8400 " Signed" " Encrypted")
8403 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8406 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8407 gnus-tmp-pressed-details
8409 (setq gnus-tmp-details
8410 (if gnus-tmp-details
8411 (concat "\n" gnus-tmp-details)
8413 (setq gnus-tmp-pressed-details
8414 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8419 gnus-mime-security-button-line-format
8420 gnus-mime-security-button-line-format-alist
8421 `(keymap ,gnus-mime-security-button-map
8422 gnus-callback gnus-mime-security-press-button
8423 gnus-line-format ,gnus-mime-security-button-line-format
8424 gnus-mime-details ,gnus-mime-security-button-pressed
8425 article-type annotation
8428 ;; Exclude a newline.
8431 (when gnus-article-button-face
8432 (gnus-overlay-put (gnus-make-overlay b e nil t)
8433 'face gnus-article-button-face))
8434 (widget-convert-button
8437 :action 'gnus-widget-press-button
8438 :button-keymap gnus-mime-security-button-map
8440 (lambda (widget/window &optional overlay pos)
8441 ;; Needed to properly clear the message due to a bug in
8442 ;; wid-edit (XEmacs only).
8443 (when (boundp 'help-echo-owns-message)
8444 (setq help-echo-owns-message t))
8446 "%S: show detail; %S: more options"
8447 (aref gnus-mouse-2 0)
8448 (aref gnus-down-mouse-3 0))))))
8450 (defun gnus-mime-display-security (handle)
8452 (narrow-to-region (point) (point))
8453 (unless (gnus-unbuttonized-mime-type-p (car handle))
8454 (gnus-insert-mime-security-button handle))
8455 (gnus-mime-display-part (cadr handle))
8458 (unless (gnus-unbuttonized-mime-type-p (car handle))
8459 (let ((gnus-mime-security-button-line-format
8460 gnus-mime-security-button-end-line-format))
8461 (gnus-insert-mime-security-button handle)))
8462 (mm-set-handle-multipart-parameter
8464 (cons (set-marker (make-marker) (point-min))
8465 (set-marker (make-marker) (point-max))))
8466 (goto-char (point-max))))
8468 (defun gnus-mime-security-run-function (function)
8469 "Run FUNCTION with the security part under point."
8470 (gnus-article-check-buffer)
8471 (let ((data (get-text-property (point) 'gnus-data))
8473 (when (and (stringp (car-safe data))
8474 (setq buffer (mm-handle-multipart-original-buffer data))
8475 (setq handle (cadr data)))
8476 (if (bufferp (mm-handle-buffer handle))
8478 (setq handle (cons buffer (copy-sequence (cdr handle))))
8479 (mm-handle-set-undisplayer handle nil))
8480 (setq handle (mm-make-handle
8482 (mm-handle-multipart-ctl-parameter handle 'protocol)
8483 nil nil nil nil nil nil)))
8484 (funcall function handle))))
8486 (defun gnus-mime-security-save-part ()
8487 "Save the security part under point."
8489 (gnus-mime-security-run-function 'mm-save-part))
8491 (defun gnus-mime-security-pipe-part ()
8492 "Pipe the security part under point to a process."
8494 (gnus-mime-security-run-function 'mm-pipe-part))
8500 (run-hooks 'gnus-art-load-hook)
8502 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
8503 ;;; gnus-art.el ends here