1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; For Emacs <22.2 and XEmacs.
29 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
33 (defvar w3m-minor-mode-map)
48 (autoload 'gnus-msg-mail "gnus-msg" nil t)
49 (autoload 'gnus-button-mailto "gnus-msg")
50 (autoload 'gnus-button-reply "gnus-msg" nil t)
51 (autoload 'parse-time-string "parse-time" nil nil)
52 (autoload 'ansi-color-apply-on-region "ansi-color")
53 (autoload 'mm-url-insert-file-contents-external "mm-url")
54 (autoload 'mm-extern-cache-contents "mm-extern")
56 (defgroup gnus-article nil
58 :link '(custom-manual "(gnus)Article Buffer")
61 (defgroup gnus-article-treat nil
62 "Treating article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-hiding nil
67 "Hiding article parts."
68 :link '(custom-manual "(gnus)Article Hiding")
71 (defgroup gnus-article-highlight nil
72 "Article highlighting."
73 :link '(custom-manual "(gnus)Article Highlighting")
77 (defgroup gnus-article-signature nil
79 :link '(custom-manual "(gnus)Article Signature")
82 (defgroup gnus-article-headers nil
84 :link '(custom-manual "(gnus)Hiding Headers")
87 (defgroup gnus-article-washing nil
88 "Special commands on articles."
89 :link '(custom-manual "(gnus)Article Washing")
92 (defgroup gnus-article-emphasis nil
93 "Fontisizing articles."
94 :link '(custom-manual "(gnus)Article Fontisizing")
97 (defgroup gnus-article-saving nil
99 :link '(custom-manual "(gnus)Saving Articles")
100 :group 'gnus-article)
102 (defgroup gnus-article-mime nil
103 "Worshiping the MIME wonder."
104 :link '(custom-manual "(gnus)Using MIME")
105 :group 'gnus-article)
107 (defgroup gnus-article-buttons nil
108 "Pushable buttons in the article buffer."
109 :link '(custom-manual "(gnus)Article Buttons")
110 :group 'gnus-article)
112 (defgroup gnus-article-various nil
113 "Other article options."
114 :link '(custom-manual "(gnus)Misc Article")
115 :group 'gnus-article)
117 (defcustom gnus-ignored-headers
120 (concat "^" header ":"))
121 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
122 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
123 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
124 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
125 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
126 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
127 "X-Attribution" "X-Originating-IP" "Delivered-To"
128 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
129 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
130 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
131 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
132 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
133 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
134 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
135 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
136 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
137 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
138 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
139 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
140 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
141 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
142 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
143 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
144 "List-[A-Za-z]+" "X-Listprocessor-Version"
145 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
146 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
147 "X-Received" "Content-length" "X-precedence"
148 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
149 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
150 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
151 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
152 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
153 "X-Content-length" "X-Posting-Agent" "Original-Received"
154 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
155 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
156 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
157 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
158 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
159 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
160 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
161 "Envelope-Sender" "Envelope-Recipients"))
162 "*All headers that start with this regexp will be hidden.
163 This variable can also be a list of regexps of headers to be ignored.
164 If `gnus-visible-headers' is non-nil, this variable will be ignored."
165 :type '(choice :custom-show nil
168 :group 'gnus-article-hiding)
170 (defcustom gnus-visible-headers
171 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
172 "*All headers that do not match this regexp will be hidden.
173 This variable can also be a list of regexp of headers to remain visible.
174 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
176 (repeat :value-to-internal (lambda (widget value)
177 (custom-split-regexp-maybe value))
178 :match (lambda (widget value)
180 (widget-editable-list-match widget value)))
182 (const :tag "Use gnus-ignored-headers" nil)
184 :group 'gnus-article-hiding)
186 (defcustom gnus-sorted-header-list
187 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
188 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
189 "*This variable is a list of regular expressions.
190 If it is non-nil, headers that match the regular expressions will
191 be placed first in the article buffer in the sequence specified by
193 :type '(repeat regexp)
194 :group 'gnus-article-hiding)
196 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
197 "Headers that are only to be displayed if they have interesting data.
198 Possible values in this list are:
200 'empty Headers with no content.
201 'newsgroups Newsgroup identical to Gnus group.
202 'to-address To identical to To-address.
203 'to-list To identical to To-list.
204 'cc-list CC identical to To-list.
205 'followup-to Followup-to identical to Newsgroups.
206 'reply-to Reply-to identical to From.
207 'date Date less than four days old.
208 'long-to To and/or Cc longer than 1024 characters.
209 'many-to Multiple To and/or Cc."
210 :type '(set (const :tag "Headers with no content." empty)
211 (const :tag "Newsgroups identical to Gnus group." newsgroups)
212 (const :tag "To identical to To-address." to-address)
213 (const :tag "To identical to To-list." to-list)
214 (const :tag "CC identical to To-list." cc-list)
215 (const :tag "Followup-to identical to Newsgroups." followup-to)
216 (const :tag "Reply-to identical to From." reply-to)
217 (const :tag "Date less than four days old." date)
218 (const :tag "To and/or Cc longer than 1024 characters." long-to)
219 (const :tag "Multiple To and/or Cc headers." many-to))
220 :group 'gnus-article-hiding)
222 (defcustom gnus-article-skip-boring nil
223 "Skip over text that is not worth reading.
224 By default, if you set this t, then Gnus will display citations and
225 signatures, but will never scroll down to show you a page consisting
226 only of boring text. Boring text is controlled by
227 `gnus-article-boring-faces'."
230 :group 'gnus-article-hiding)
232 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
233 "Regexp matching signature separator.
234 This can also be a list of regexps. In that case, it will be checked
235 from head to tail looking for a separator. Searches will be done from
236 the end of the buffer."
237 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
239 (repeat :tag "List of regexp" regexp))
240 :group 'gnus-article-signature)
242 (defcustom gnus-signature-limit nil
243 "Provide a limit to what is considered a signature.
244 If it is a number, no signature may not be longer (in characters) than
245 that number. If it is a floating point number, no signature may be
246 longer (in lines) than that number. If it is a function, the function
247 will be called without any parameters, and if it returns nil, there is
248 no signature in the buffer. If it is a string, it will be used as a
249 regexp. If it matches, the text in question is not a signature.
251 This can also be a list of the above values."
252 :type '(choice (const nil)
256 (regexp :value ".*"))
257 :group 'gnus-article-signature)
259 (defcustom gnus-hidden-properties '(invisible t intangible t)
260 "Property list to use for hiding text."
262 :group 'gnus-article-hiding)
264 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
265 ;; frames in a session.
266 (defcustom gnus-article-x-face-command
267 (if (featurep 'xemacs)
268 (if (or (gnus-image-type-available-p 'xface)
269 (gnus-image-type-available-p 'pbm))
270 'gnus-display-x-face-in-from
271 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
272 (if (gnus-image-type-available-p 'pbm)
273 'gnus-display-x-face-in-from
274 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
276 "*String or function to be executed to display an X-Face header.
277 If it is a string, the command will be executed in a sub-shell
278 asynchronously. The compressed face will be piped to this command."
279 :type `(choice string
280 (function-item gnus-display-x-face-in-from)
284 :group 'gnus-article-washing)
286 (defcustom gnus-article-x-face-too-ugly nil
287 "Regexp matching posters whose face shouldn't be shown automatically."
288 :type '(choice regexp (const nil))
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-banner-alist nil
292 "Banner alist for stripping.
294 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
296 :type '(repeat (cons symbol regexp))
297 :group 'gnus-article-washing)
299 (gnus-define-group-parameter
302 "Alist of regexps (to match group names) and banner."
303 :variable-group gnus-article-washing
305 '(choice :tag "Banner"
307 (const :tag "Remove signature" signature)
308 (symbol :tag "Item in `gnus-article-banner-alist'" none)
310 (const :tag "None" nil))
312 "If non-nil, specify how to remove `banners' from articles.
314 Symbol `signature' means to remove signatures delimited by
315 `gnus-signature-separator'. Any other symbol is used to look up a
316 regular expression to match the banner in `gnus-article-banner-alist'.
317 A string is used as a regular expression to match the banner
320 (defcustom gnus-article-address-banner-alist nil
321 "Alist of mail addresses and banners.
322 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
323 to match a mail address in the From: header, BANNER is one of a symbol
324 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
325 If ADDRESS matches author's mail address, it will remove things like
326 advertisements. For example:
328 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
332 (regexp :tag "Address")
333 (choice :tag "Banner" :value nil
334 (const :tag "Remove signature" signature)
335 (symbol :tag "Item in `gnus-article-banner-alist'" none)
337 (const :tag "None" nil))))
339 :group 'gnus-article-washing)
341 (defmacro gnus-emphasis-custom-with-format (&rest body)
343 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
344 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
347 (defun gnus-emphasis-custom-value-to-external (value)
348 (gnus-emphasis-custom-with-format
349 (if (consp (car value))
350 (list (format format (car (car value)) (cdr (car value)))
352 (if (nth 1 value) 2 3)
356 (defun gnus-emphasis-custom-value-to-internal (value)
357 (gnus-emphasis-custom-with-format
358 (let ((regexp (concat "\\`"
359 (format (regexp-quote format)
360 "\\([^()]+\\)" "\\([^()]+\\)")
363 (if (string-match regexp (setq pattern (car value)))
364 (list (cons (match-string 1 pattern) (match-string 2 pattern))
369 (defcustom gnus-emphasis-alist
371 '(("\\*" "\\*" bold nil 2)
374 ("_/" "/_" underline-italic)
375 ("_\\*" "\\*_" underline-bold)
376 ("\\*/" "/\\*" bold-italic)
377 ("_\\*/" "/\\*_" underline-bold-italic))))
379 (gnus-emphasis-custom-with-format
380 (mapcar (lambda (spec)
381 (list (format format (car spec) (cadr spec))
384 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
386 '(;; I've never seen anyone use this strikethru convention whereas I've
387 ;; several times seen it triggered by normal text. --Stef
388 ;; Miles suggests that this form is sometimes used but for italics,
389 ;; so maybe we should map it to `italic'.
390 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
391 ;; 2 3 gnus-emphasis-strikethru)
392 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
393 2 3 gnus-emphasis-underline))))
394 "*Alist that says how to fontify certain phrases.
395 Each item looks like this:
397 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
399 The first element is a regular expression to be matched. The second
400 is a number that says what regular expression grouping used to find
401 the entire emphasized word. The third is a number that says what
402 regexp grouping should be displayed and highlighted. The fourth
403 is the face used for highlighting."
407 :format "%[Customizing Style%]\n%v"
409 (group :tag "Default"
410 :value ("" 0 0 default)
413 (let ((value (widget-get
414 (cadr (widget-get (widget-get widget :parent)
417 (if (not (eq (nth 2 value) 'default))
421 (gnus-emphasis-custom-value-to-external value))))
422 (widget-group-value-create widget))
424 (integer :format "Match group: %v")
425 (integer :format "Emphasize group: %v")
428 :value (("_" . "_") nil default)
430 (regexp :format "Start regexp: %v")
431 (regexp :format "End regexp: %v"))
432 (boolean :format "Show start and end patterns: %[%v%]\n"
433 :on " On " :off " Off ")
435 :get (lambda (symbol)
436 (mapcar 'gnus-emphasis-custom-value-to-internal
437 (default-value symbol)))
438 :set (lambda (symbol value)
439 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
441 :group 'gnus-article-emphasis)
443 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
444 "A regexp to describe whitespace which should not be emphasized.
445 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
446 The former avoids underlining of leading and trailing whitespace,
447 and the latter avoids underlining any whitespace at all."
449 :group 'gnus-article-emphasis
452 (defface gnus-emphasis-bold '((t (:bold t)))
453 "Face used for displaying strong emphasized text (*word*)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-italic '((t (:italic t)))
457 "Face used for displaying italic emphasized text (/word/)."
458 :group 'gnus-article-emphasis)
460 (defface gnus-emphasis-underline '((t (:underline t)))
461 "Face used for displaying underlined emphasized text (_word_)."
462 :group 'gnus-article-emphasis)
464 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
465 "Face used for displaying underlined bold emphasized text (_*word*_)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
469 "Face used for displaying underlined italic emphasized text (_/word/_)."
470 :group 'gnus-article-emphasis)
472 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
473 "Face used for displaying bold italic emphasized text (/*word*/)."
474 :group 'gnus-article-emphasis)
476 (defface gnus-emphasis-underline-bold-italic
477 '((t (:bold t :italic t :underline t)))
478 "Face used for displaying underlined bold italic emphasized text.
479 Example: (_/*word*/_)."
480 :group 'gnus-article-emphasis)
482 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
483 '((t (:strikethru t)))
484 '((t (:strike-through t))))
485 "Face used for displaying strike-through text (-word-)."
486 :group 'gnus-article-emphasis)
488 (defface gnus-emphasis-highlight-words
489 '((t (:background "black" :foreground "yellow")))
490 "Face used for displaying highlighted words."
491 :group 'gnus-article-emphasis)
493 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
494 "Format for display of Date headers in article bodies.
495 See `format-time-string' for the possible values.
497 The variable can also be function, which should return a complete Date
498 header. The function is called with one argument, the time, which can
499 be fed to `format-time-string'."
500 :type '(choice string function)
501 :link '(custom-manual "(gnus)Article Date")
502 :group 'gnus-article-washing)
504 (defcustom gnus-save-all-headers t
505 "*If non-nil, don't remove any headers before saving.
506 This will be overridden by the `:headers' property that the symbol of
507 the saver function, which is specified by `gnus-default-article-saver',
509 :group 'gnus-article-saving
512 (defcustom gnus-prompt-before-saving 'always
513 "*This variable says how much prompting is to be done when saving articles.
514 If it is nil, no prompting will be done, and the articles will be
515 saved to the default files. If this variable is `always', each and
516 every article that is saved will be preceded by a prompt, even when
517 saving large batches of articles. If this variable is neither nil not
518 `always', there the user will be prompted once for a file name for
519 each invocation of the saving commands."
520 :group 'gnus-article-saving
521 :type '(choice (item always)
522 (item :tag "never" nil)
523 (sexp :tag "once" :format "%t\n" :value t)))
525 (defcustom gnus-saved-headers gnus-visible-headers
526 "Headers to keep if `gnus-save-all-headers' is nil.
527 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
528 If that variable is nil, however, all headers that match this regexp
529 will be kept while the rest will be deleted before saving. This and
530 `gnus-save-all-headers' will be overridden by the `:headers' property
531 that the symbol of the saver function, which is specified by
532 `gnus-default-article-saver', might have."
533 :group 'gnus-article-saving
536 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
537 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
538 "A function to save articles in your favourite format.
539 The function will be called by way of the `gnus-summary-save-article'
540 command, and friends such as `gnus-summary-save-article-rmail'.
542 Gnus provides the following functions:
544 * gnus-summary-save-in-rmail (Rmail format)
545 * gnus-summary-save-in-mail (Unix mail format)
546 * gnus-summary-save-in-folder (MH folder)
547 * gnus-summary-save-in-file (article format)
548 * gnus-summary-save-body-in-file (article body)
549 * gnus-summary-save-in-vm (use VM's folder format)
550 * gnus-summary-write-to-file (article format -- overwrite)
551 * gnus-summary-write-body-to-file (article body -- overwrite)
552 * gnus-summary-save-in-pipe (article format)
554 The symbol of each function may have the following properties:
557 The value non-nil means save decoded articles. This is meaningful
558 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
559 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
560 `gnus-summary-save-in-pipe'.
563 The value specifies an alternative function which appends, not
564 overwrites, articles to a file. This implies that when saving many
565 articles at a time, `gnus-prompt-before-saving' is bound to t and all
566 articles are saved in a single file. This is meaningful only with
567 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
570 The value specifies the symbol of a variable of which the value
571 specifies headers to be saved. If it is omitted,
572 `gnus-save-all-headers' and `gnus-saved-headers' control what
573 headers should be saved."
574 :group 'gnus-article-saving
575 :type '(radio (function-item gnus-summary-save-in-rmail)
576 (function-item gnus-summary-save-in-mail)
577 (function-item gnus-summary-save-in-folder)
578 (function-item gnus-summary-save-in-file)
579 (function-item gnus-summary-save-body-in-file)
580 (function-item gnus-summary-save-in-vm)
581 (function-item gnus-summary-write-to-file)
582 (function-item gnus-summary-write-body-to-file)
583 (function-item gnus-summary-save-in-pipe)
586 (defcustom gnus-article-save-coding-system
587 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
588 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
589 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
590 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
591 "Coding system used to save decoded articles to a file.
593 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
594 which can safely encode any characters in text. This is used by the
597 * gnus-summary-save-article-file
598 * gnus-summary-save-article-body-file
599 * gnus-summary-write-article-file
600 * gnus-summary-write-article-body-file
602 and the functions to which you may set `gnus-default-article-saver':
604 * gnus-summary-save-in-file
605 * gnus-summary-save-body-in-file
606 * gnus-summary-write-to-file
607 * gnus-summary-write-body-to-file
609 Those commands and functions save just text displayed in the article
610 buffer to a file if the value of this variable is non-nil. Note that
611 buttonized MIME parts will be lost in a saved file in that case.
612 Otherwise, raw articles will be saved."
613 :group 'gnus-article-saving
615 :format "%{%t%}:\n %[Value Menu%] %v"
616 (const :tag "Save raw articles" nil)
619 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
620 '((const :tag "UTF-8" utf-8)
621 (const :tag "iso-2022-7bit" iso-2022-7bit)
622 (const :tag "Emacs internal" emacs-mule)
623 (const :tag "escape-quoted" escape-quoted))))
624 (symbol :tag "Coding system")))
626 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
627 "A function generating a file name to save articles in Rmail format.
628 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
629 :group 'gnus-article-saving
632 (defcustom gnus-mail-save-name 'gnus-plain-save-name
633 "A function generating a file name to save articles in Unix mail format.
634 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
635 :group 'gnus-article-saving
638 (defcustom gnus-folder-save-name 'gnus-folder-save-name
639 "A function generating a file name to save articles in MH folder.
640 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
641 :group 'gnus-article-saving
644 (defcustom gnus-file-save-name 'gnus-numeric-save-name
645 "A function generating a file name to save articles in article format.
646 The function is called with NEWSGROUP, HEADERS, and optional
648 :group 'gnus-article-saving
651 (defcustom gnus-split-methods
652 '((gnus-article-archive-name)
653 (gnus-article-nndoc-name))
654 "*Variable used to suggest where articles are to be saved.
655 For instance, if you would like to save articles related to Gnus in
656 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
657 you could set this variable to something like:
659 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
660 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
662 This variable is an alist where the key is the match and the
663 value is a list of possible files to save in if the match is
666 If the match is a string, it is used as a regexp match on the
667 article. If the match is a symbol, that symbol will be funcalled
668 from the buffer of the article to be saved with the newsgroup as the
669 parameter. If it is a list, it will be evaled in the same buffer.
671 If this form or function returns a string, this string will be used as a
672 possible file name; and if it returns a non-nil list, that list will be
673 used as possible file names."
674 :group 'gnus-article-saving
675 :type '(repeat (choice (list :value (fun) function)
676 (cons :value ("" "") regexp (repeat string))
679 (defcustom gnus-page-delimiter "^\^L"
680 "*Regexp describing what to use as article page delimiters.
681 The default value is \"^\^L\", which is a form linefeed at the
682 beginning of a line."
684 :group 'gnus-article-various)
686 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
687 "*The format specification for the article mode line.
688 See `gnus-summary-mode-line-format' for a closer description.
690 The following additional specs are available:
692 %w The article washing status.
693 %m The number of MIME parts in the article."
695 :group 'gnus-article-various)
697 (defcustom gnus-article-mode-hook nil
698 "*A hook for Gnus article mode."
700 :group 'gnus-article-various)
702 (when (featurep 'xemacs)
703 ;; Extracted from gnus-xmas-define in order to preserve user settings
704 (when (fboundp 'turn-off-scroll-in-place)
705 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
706 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
707 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
709 (defcustom gnus-article-menu-hook nil
710 "*Hook run after the creation of the article mode menu."
712 :group 'gnus-article-various)
714 (defcustom gnus-article-prepare-hook nil
715 "*A hook called after an article has been prepared in the article buffer."
717 :group 'gnus-article-various)
719 (defcustom gnus-copy-article-ignored-headers nil
720 "List of headers to be removed when copying an article.
721 Each element is a regular expression."
722 :version "23.1" ;; No Gnus
723 :type '(repeat regexp)
724 :group 'gnus-article-various)
726 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
727 "Gnus 5.10 (Emacs 22.1)")
730 '((t (:weight bold)))
731 "Face used for highlighting a button in the article buffer."
732 :group 'gnus-article-buttons)
734 (defcustom gnus-article-button-face 'gnus-button
735 "Face used for highlighting buttons in the article buffer.
737 An article button is a piece of text that you can activate by pressing
738 `RET' or `mouse-2' above it."
740 :group 'gnus-article-buttons)
742 (defcustom gnus-article-mouse-face 'highlight
743 "Face used for mouse highlighting in the article buffer.
745 Article buttons will be displayed in this face when the cursor is
748 :group 'gnus-article-buttons)
750 (defcustom gnus-signature-face 'gnus-signature
751 "Face used for highlighting a signature in the article buffer.
752 Obsolete; use the face `gnus-signature' for customizations instead."
754 :group 'gnus-article-highlight
755 :group 'gnus-article-signature)
757 (defface gnus-signature
760 "Face used for highlighting a signature in the article buffer."
761 :group 'gnus-article-highlight
762 :group 'gnus-article-signature)
763 ;; backward-compatibility alias
764 (put 'gnus-signature-face 'face-alias 'gnus-signature)
765 (put 'gnus-signature-face 'obsolete-face "22.1")
767 (defface gnus-header-from
770 (:foreground "PaleGreen1"))
773 (:foreground "red3"))
776 "Face used for displaying from headers."
777 :group 'gnus-article-headers
778 :group 'gnus-article-highlight)
779 ;; backward-compatibility alias
780 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
781 (put 'gnus-header-from-face 'obsolete-face "22.1")
783 (defface gnus-header-subject
786 (:foreground "SeaGreen1"))
789 (:foreground "red4"))
791 (:bold t :italic t)))
792 "Face used for displaying subject headers."
793 :group 'gnus-article-headers
794 :group 'gnus-article-highlight)
795 ;; backward-compatibility alias
796 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
797 (put 'gnus-header-subject-face 'obsolete-face "22.1")
799 (defface gnus-header-newsgroups
802 (:foreground "yellow" :italic t))
805 (:foreground "MidnightBlue" :italic t))
808 "Face used for displaying newsgroups headers.
809 In the default setup this face is only used for crossposted
811 :group 'gnus-article-headers
812 :group 'gnus-article-highlight)
813 ;; backward-compatibility alias
814 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
815 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
817 (defface gnus-header-name
820 (:foreground "SpringGreen2"))
823 (:foreground "maroon"))
826 "Face used for displaying header names."
827 :group 'gnus-article-headers
828 :group 'gnus-article-highlight)
829 ;; backward-compatibility alias
830 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
831 (put 'gnus-header-name-face 'obsolete-face "22.1")
833 (defface gnus-header-content
836 (:foreground "SpringGreen1" :italic t))
839 (:foreground "indianred4" :italic t))
841 (:italic t))) "Face used for displaying header content."
842 :group 'gnus-article-headers
843 :group 'gnus-article-highlight)
844 ;; backward-compatibility alias
845 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
846 (put 'gnus-header-content-face 'obsolete-face "22.1")
848 (defcustom gnus-header-face-alist
849 '(("From" nil gnus-header-from)
850 ("Subject" nil gnus-header-subject)
851 ("Newsgroups:.*," nil gnus-header-newsgroups)
852 ("" gnus-header-name gnus-header-content))
853 "*Controls highlighting of article headers.
855 An alist of the form (HEADER NAME CONTENT).
857 HEADER is a regular expression which should match the name of a
858 header and NAME and CONTENT are either face names or nil.
860 The name of each header field will be displayed using the face
861 specified by the first element in the list where HEADER matches
862 the header name and NAME is non-nil. Similarly, the content will
863 be displayed by the first non-nil matching CONTENT face."
864 :group 'gnus-article-headers
865 :group 'gnus-article-highlight
866 :type '(repeat (list (regexp :tag "Header")
868 (item :tag "skip" nil)
869 (face :value default))
870 (choice :tag "Content"
871 (item :tag "skip" nil)
872 (face :value default)))))
874 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
875 '((xface . (:face gnus-x-face)))
876 '((pbm . (:face gnus-x-face))
878 "Alist of image types and properties applied to Face and X-Face images.
881 ;; Specify the altitude of Face images in the From header.
882 \(setq gnus-face-properties-alist
883 '((pbm . (:face gnus-x-face :ascent 80))
884 (png . (:ascent 80))))
886 ;; Show Face images as pressed buttons.
887 \(setq gnus-face-properties-alist
888 '((pbm . (:face gnus-x-face :relief -2))
889 (png . (:relief -2))))
891 See the manual for the valid properties for various image types.
892 Currently, `pbm' is used for X-Face images and `png' is used for Face
893 images in Emacs. Only the `:face' property is effective on the `xface'
894 image type in XEmacs if it is built with the libcompface library."
895 :version "23.1" ;; No Gnus
896 :group 'gnus-article-headers
897 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
899 (defcustom gnus-article-decode-hook
900 '(article-decode-charset article-decode-encoded-words
901 article-decode-group-name article-decode-idna-rhs)
902 "*Hook run to decode charsets in articles."
903 :group 'gnus-article-headers
906 (defcustom gnus-display-mime-function 'gnus-display-mime
907 "Function to display MIME articles."
908 :group 'gnus-article-mime
911 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
912 "Function used to decode headers.")
914 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
915 "Function used to decode addresses.")
917 (defvar gnus-article-dumbquotes-map
937 "Table for MS-to-Latin1 translation.")
939 (defcustom gnus-ignored-mime-types nil
940 "List of MIME types that should be ignored by Gnus."
942 :group 'gnus-article-mime
943 :type '(repeat regexp))
945 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
946 "List of MIME types that should not be given buttons when rendered inline.
947 See also `gnus-buttonized-mime-types' which may override this variable.
948 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
950 :group 'gnus-article-mime
951 :type '(repeat regexp))
953 (defcustom gnus-buttonized-mime-types nil
954 "List of MIME types that should be given buttons when rendered inline.
955 If set, this variable overrides `gnus-unbuttonized-mime-types'.
956 To see e.g. security buttons you could set this to
957 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
958 this list to display radio buttons that allow you to choose one of two
959 media types those mails include. See also `mm-discouraged-alternatives'.
960 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
962 :group 'gnus-article-mime
963 :type '(repeat regexp))
965 (defcustom gnus-inhibit-mime-unbuttonizing nil
966 "If non-nil, all MIME parts get buttons.
967 When nil (the default value), then some MIME parts do not get buttons,
968 as described by the variables `gnus-buttonized-mime-types' and
969 `gnus-unbuttonized-mime-types'."
971 :group 'gnus-article-mime
974 (defcustom gnus-body-boundary-delimiter "_"
975 "String used to delimit header and body.
976 This variable is used by `gnus-article-treat-body-boundary' which can
977 be controlled by `gnus-treat-body-boundary'."
979 :group 'gnus-article-various
980 :type '(choice (item :tag "None" :value nil)
983 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
985 "Defines the location of the faces database.
986 For information on obtaining this database of pretty pictures, please
987 see http://www.cs.indiana.edu/picons/ftp/index.html"
989 :type '(repeat directory)
990 :link '(url-link :tag "download"
991 "http://www.cs.indiana.edu/picons/ftp/index.html")
992 :link '(custom-manual "(gnus)Picons")
995 (defun gnus-picons-installed-p ()
996 "Say whether picons are installed on your machine."
997 (let ((installed nil))
998 (dolist (database gnus-picon-databases)
999 (when (file-exists-p database)
1000 (setq installed t)))
1003 (defcustom gnus-article-mime-part-function nil
1004 "Function called with a MIME handle as the argument.
1005 This is meant for people who want to do something automatic based
1006 on parts -- for instance, adding Vcard info to a database."
1007 :group 'gnus-article-mime
1008 :type '(choice (const nil)
1011 (defcustom gnus-mime-multipart-functions nil
1012 "An alist of MIME types to functions to display them."
1014 :group 'gnus-article-mime
1015 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1017 (defcustom gnus-article-date-lapsed-new-header nil
1018 "Whether the X-Sent and Date headers can coexist.
1019 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1020 either replace the old \"Date:\" header (if this variable is nil), or
1021 be added below it (otherwise)."
1023 :group 'gnus-article-headers
1026 (defcustom gnus-article-update-lapsed-header 1
1027 "How often to update the lapsed date header.
1028 If nil, don't update it at all."
1030 :group 'gnus-article-headers
1032 (item :tag "Don't update" :value nil)
1035 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1036 "Function called with a MIME handle as the argument.
1037 This is meant for people who want to view first matched part.
1038 For `undisplayed-alternative' (default), the first undisplayed
1039 part or alternative part is used. For `undisplayed', the first
1040 undisplayed part is used. For a function, the first part which
1041 the function return t is used. For nil, the first part is
1044 :group 'gnus-article-mime
1046 (item :tag "first" :value nil)
1047 (item :tag "undisplayed" :value undisplayed)
1048 (item :tag "undisplayed or alternative"
1049 :value undisplayed-alternative)
1052 (defcustom gnus-mime-action-alist
1053 '(("save to file" . gnus-mime-save-part)
1054 ("save and strip" . gnus-mime-save-part-and-strip)
1055 ("replace with file" . gnus-mime-replace-part)
1056 ("delete part" . gnus-mime-delete-part)
1057 ("display as text" . gnus-mime-inline-part)
1058 ("view the part" . gnus-mime-view-part)
1059 ("pipe to command" . gnus-mime-pipe-part)
1060 ("toggle display" . gnus-article-press-button)
1061 ("toggle display" . gnus-article-view-part-as-charset)
1062 ("view as type" . gnus-mime-view-part-as-type)
1063 ("view internally" . gnus-mime-view-part-internally)
1064 ("view externally" . gnus-mime-view-part-externally))
1065 "An alist of actions that run on the MIME attachment."
1066 :group 'gnus-article-mime
1067 :type '(repeat (cons (string :tag "name")
1070 (defcustom gnus-auto-select-part 1
1071 "Advance to next MIME part when deleting or stripping parts.
1073 When 0, point will be placed on the same part as before. When
1074 positive (negative), move point forward (backwards) this many
1075 parts. When nil, redisplay article."
1076 :version "23.1" ;; No Gnus
1077 :group 'gnus-article-mime
1078 :type '(choice (const nil :tag "Redisplay article.")
1079 (const 1 :tag "Next part.")
1080 (const 0 :tag "Current part.")
1084 ;;; The treatment variables
1087 (defvar gnus-part-display-hook nil
1088 "Hook called on parts that are to receive treatment.")
1090 (defvar gnus-article-treat-custom
1091 '(choice (const :tag "Off" nil)
1093 (const :tag "Header" head)
1094 (const :tag "First" first)
1095 (const :tag "Last" last)
1096 (integer :tag "Less")
1097 (repeat :tag "Groups" regexp)
1098 (sexp :tag "Predicate")))
1100 (defvar gnus-article-treat-head-custom
1101 '(choice (const :tag "Off" nil)
1102 (const :tag "Header" head)))
1104 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1108 (defvar gnus-inhibit-treatment nil
1109 "Whether to inhibit treatment.")
1111 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1112 "Highlight the signature.
1113 Valid values are nil, t, `head', `first', `last', an integer or a
1114 predicate. See Info node `(gnus)Customizing Articles'."
1115 :group 'gnus-article-treat
1116 :link '(custom-manual "(gnus)Customizing Articles")
1117 :type gnus-article-treat-custom)
1118 (put 'gnus-treat-highlight-signature 'highlight t)
1120 (defcustom gnus-treat-buttonize 100000
1122 Valid values are nil, t, `head', `first', `last', an integer or a
1123 predicate. See Info node `(gnus)Customizing Articles'."
1124 :group 'gnus-article-treat
1125 :link '(custom-manual "(gnus)Customizing Articles")
1126 :type gnus-article-treat-custom)
1127 (put 'gnus-treat-buttonize 'highlight t)
1129 (defcustom gnus-treat-buttonize-head 'head
1130 "Add buttons to the head.
1131 Valid values are nil, t, `head', `first', `last', an integer or a
1132 predicate. See Info node `(gnus)Customizing Articles'."
1133 :group 'gnus-article-treat
1134 :link '(custom-manual "(gnus)Customizing Articles")
1135 :type gnus-article-treat-head-custom)
1136 (put 'gnus-treat-buttonize-head 'highlight t)
1138 (defcustom gnus-treat-emphasize 50000
1140 Valid values are nil, t, `head', `first', `last', an integer or a
1141 predicate. See Info node `(gnus)Customizing Articles'."
1142 :group 'gnus-article-treat
1143 :link '(custom-manual "(gnus)Customizing Articles")
1144 :type gnus-article-treat-custom)
1145 (put 'gnus-treat-emphasize 'highlight t)
1147 (defcustom gnus-treat-strip-cr nil
1148 "Remove carriage returns.
1149 Valid values are nil, t, `head', `first', `last', an integer or a
1150 predicate. See Info node `(gnus)Customizing Articles'."
1152 :group 'gnus-article-treat
1153 :link '(custom-manual "(gnus)Customizing Articles")
1154 :type gnus-article-treat-custom)
1156 (defcustom gnus-treat-unsplit-urls nil
1157 "Remove newlines from within URLs.
1158 Valid values are nil, t, `head', `first', `last', an integer or a
1159 predicate. See Info node `(gnus)Customizing Articles'."
1161 :group 'gnus-article-treat
1162 :link '(custom-manual "(gnus)Customizing Articles")
1163 :type gnus-article-treat-custom)
1165 (defcustom gnus-treat-leading-whitespace nil
1166 "Remove leading whitespace in headers.
1167 Valid values are nil, t, `head', `first', `last', an integer or a
1168 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-custom)
1174 (defcustom gnus-treat-hide-headers 'head
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-head-custom)
1182 (defcustom gnus-treat-hide-boring-headers nil
1183 "Hide boring headers.
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-head-custom)
1190 (defcustom gnus-treat-hide-signature nil
1191 "Hide the signature.
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-fill-article 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-hide-citation nil
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1210 :group 'gnus-article-treat
1211 :link '(custom-manual "(gnus)Customizing Articles")
1212 :type gnus-article-treat-custom)
1214 (defcustom gnus-treat-hide-citation-maybe nil
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1218 :group 'gnus-article-treat
1219 :link '(custom-manual "(gnus)Customizing Articles")
1220 :type gnus-article-treat-custom)
1222 (defcustom gnus-treat-strip-list-identifiers 'head
1223 "Strip list identifiers from `gnus-list-identifiers`.
1224 Valid values are nil, t, `head', `first', `last', an integer or a
1225 predicate. See Info node `(gnus)Customizing Articles'."
1227 :group 'gnus-article-treat
1228 :link '(custom-manual "(gnus)Customizing Articles")
1229 :type gnus-article-treat-custom)
1231 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1232 "Gnus 5.10 (Emacs 22.1)")
1234 (defcustom gnus-treat-strip-pem nil
1235 "Strip PEM signatures.
1236 Valid values are nil, t, `head', `first', `last', an integer or a
1237 predicate. See Info node `(gnus)Customizing Articles'."
1238 :group 'gnus-article-treat
1239 :link '(custom-manual "(gnus)Customizing Articles")
1240 :type gnus-article-treat-custom)
1242 (defcustom gnus-treat-strip-banner t
1243 "Strip banners from articles.
1244 The banner to be stripped is specified in the `banner' group parameter.
1245 Valid values are nil, t, `head', `first', `last', an integer or a
1246 predicate. See Info node `(gnus)Customizing Articles'."
1247 :group 'gnus-article-treat
1248 :link '(custom-manual "(gnus)Customizing Articles")
1249 :type gnus-article-treat-custom)
1251 (defcustom gnus-treat-highlight-headers 'head
1252 "Highlight the headers.
1253 Valid values are nil, t, `head', `first', `last', an integer or a
1254 predicate. See Info node `(gnus)Customizing Articles'."
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-head-custom)
1258 (put 'gnus-treat-highlight-headers 'highlight t)
1260 (defcustom gnus-treat-highlight-citation t
1261 "Highlight cited text.
1262 Valid values are nil, t, `head', `first', `last', an integer or a
1263 predicate. See Info node `(gnus)Customizing Articles'."
1264 :group 'gnus-article-treat
1265 :link '(custom-manual "(gnus)Customizing Articles")
1266 :type gnus-article-treat-custom)
1267 (put 'gnus-treat-highlight-citation 'highlight t)
1269 (defcustom gnus-treat-date-ut nil
1270 "Display the Date in UT (GMT).
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1273 :group 'gnus-article-treat
1274 :link '(custom-manual "(gnus)Customizing Articles")
1275 :type gnus-article-treat-head-custom)
1277 (defcustom gnus-treat-date-local nil
1278 "Display the Date in the local timezone.
1279 Valid values are nil, t, `head', `first', `last', an integer or a
1280 predicate. See Info node `(gnus)Customizing Articles'."
1281 :group 'gnus-article-treat
1282 :link '(custom-manual "(gnus)Customizing Articles")
1283 :type gnus-article-treat-head-custom)
1285 (defcustom gnus-treat-date-english nil
1286 "Display the Date in a format that can be read aloud in English.
1287 Valid values are nil, t, `head', `first', `last', an integer or a
1288 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-lapsed nil
1295 "Display the Date header in a way that says how much time has elapsed.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1298 :group 'gnus-article-treat
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :type gnus-article-treat-head-custom)
1302 (defcustom gnus-treat-date-combined-lapsed 'head
1303 "Display the Date header in a way that says how much time has elapsed.
1304 Valid values are nil, t, `head', `first', `last', an integer or a
1305 predicate. See Info node `(gnus)Customizing Articles'."
1306 :group 'gnus-article-treat
1307 :link '(custom-manual "(gnus)Customizing Articles")
1308 :type gnus-article-treat-head-custom)
1310 (defcustom gnus-treat-date-original nil
1311 "Display the date in the original timezone.
1312 Valid values are nil, t, `head', `first', `last', an integer or a
1313 predicate. See Info node `(gnus)Customizing Articles'."
1314 :group 'gnus-article-treat
1315 :link '(custom-manual "(gnus)Customizing Articles")
1316 :type gnus-article-treat-head-custom)
1318 (defcustom gnus-treat-date-iso8601 nil
1319 "Display the date in the ISO8601 format.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'."
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-head-custom)
1327 (defcustom gnus-treat-date-user-defined nil
1328 "Display the date in a user-defined format.
1329 The format is defined by the `gnus-article-time-format' variable.
1330 Valid values are nil, t, `head', `first', `last', an integer or a
1331 predicate. See Info node `(gnus)Customizing Articles'."
1332 :group 'gnus-article-treat
1333 :link '(custom-manual "(gnus)Customizing Articles")
1334 :type gnus-article-treat-head-custom)
1336 (defcustom gnus-treat-strip-headers-in-body t
1337 "Strip the X-No-Archive header line from the beginning of the body.
1338 Valid values are nil, t, `head', `first', `last', an integer or a
1339 predicate. See Info node `(gnus)Customizing Articles'."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-trailing-blank-lines nil
1346 "Strip trailing blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'.
1350 When set to t, it also strips trailing blanks in all MIME parts.
1351 Consider to use `last' instead."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1356 (defcustom gnus-treat-strip-leading-blank-lines nil
1357 "Strip leading blank lines.
1358 Valid values are nil, t, `head', `first', `last', an integer or a
1359 predicate. See Info node `(gnus)Customizing Articles'.
1361 When set to t, it also strips trailing blanks in all MIME parts."
1362 :group 'gnus-article-treat
1363 :link '(custom-manual "(gnus)Customizing Articles")
1364 :type gnus-article-treat-custom)
1366 (defcustom gnus-treat-strip-multiple-blank-lines nil
1367 "Strip multiple blank lines.
1368 Valid values are nil, t, `head', `first', `last', an integer or a
1369 predicate. See Info node `(gnus)Customizing Articles'."
1370 :group 'gnus-article-treat
1371 :link '(custom-manual "(gnus)Customizing Articles")
1372 :type gnus-article-treat-custom)
1374 (defcustom gnus-treat-unfold-headers 'head
1375 "Unfold folded header lines.
1376 Valid values are nil, t, `head', `first', `last', an integer or a
1377 predicate. See Info node `(gnus)Customizing Articles'."
1379 :group 'gnus-article-treat
1380 :link '(custom-manual "(gnus)Customizing Articles")
1381 :type gnus-article-treat-custom)
1383 (defcustom gnus-article-unfold-long-headers nil
1384 "If non-nil, allow unfolding headers even if the header is long.
1385 If it is a regexp, only long headers matching this regexp are unfolded.
1386 If it is t, all long headers are unfolded.
1388 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1389 :version "23.1" ;; No Gnus
1390 :group 'gnus-article-treat
1391 :type '(choice (const nil)
1392 (const :tag "all" t)
1395 (defcustom gnus-treat-fold-headers nil
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1400 :group 'gnus-article-treat
1401 :link '(custom-manual "(gnus)Customizing Articles")
1402 :type gnus-article-treat-custom)
1404 (defcustom gnus-treat-fold-newsgroups 'head
1405 "Fold the Newsgroups and Followup-To headers.
1406 Valid values are nil, t, `head', `first', `last', an integer or a
1407 predicate. See Info node `(gnus)Customizing Articles'."
1409 :group 'gnus-article-treat
1410 :link '(custom-manual "(gnus)Customizing Articles")
1411 :type gnus-article-treat-custom)
1413 (defcustom gnus-treat-overstrike t
1414 "Treat overstrike highlighting.
1415 Valid values are nil, t, `head', `first', `last', an integer or a
1416 predicate. See Info node `(gnus)Customizing Articles'."
1417 :group 'gnus-article-treat
1418 :link '(custom-manual "(gnus)Customizing Articles")
1419 :type gnus-article-treat-custom)
1420 (put 'gnus-treat-overstrike 'highlight t)
1422 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1423 "Treat ANSI SGR control sequences.
1424 Valid values are nil, t, `head', `first', `last', an integer or a
1425 predicate. See Info node `(gnus)Customizing Articles'."
1426 :group 'gnus-article-treat
1427 :link '(custom-manual "(gnus)Customizing Articles")
1428 :type gnus-article-treat-custom)
1430 (make-obsolete-variable 'gnus-treat-display-xface
1431 'gnus-treat-display-x-face "Emacs 22.1")
1433 (defcustom gnus-treat-display-x-face
1434 (and (not noninteractive)
1435 (gnus-image-type-available-p 'xbm)
1436 (if (featurep 'xemacs)
1439 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1440 (executable-find "icontopbm"))
1441 ;; shell-command-to-string may signal an error, e.g. if
1442 ;; shell-file-name is not found.
1445 "Display X-Face headers.
1446 Valid values are nil and `head'.
1447 See Info node `(gnus)Customizing Articles' and Info node
1448 `(gnus)X-Face' for details."
1449 :group 'gnus-article-treat
1451 :link '(custom-manual "(gnus)Customizing Articles")
1452 :link '(custom-manual "(gnus)X-Face")
1453 :type gnus-article-treat-head-custom
1454 :set (lambda (symbol value)
1457 (cond ((or (boundp symbol) (get symbol 'saved-value))
1459 ((boundp 'gnus-treat-display-xface)
1461 ** gnus-treat-display-xface is an obsolete variable;\
1462 use gnus-treat-display-x-face instead")
1463 (default-value 'gnus-treat-display-xface))
1464 ((get 'gnus-treat-display-xface 'saved-value)
1466 ** gnus-treat-display-xface is an obsolete variable;\
1467 use gnus-treat-display-x-face instead")
1468 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1471 (put 'gnus-treat-display-x-face 'highlight t)
1473 (defcustom gnus-treat-display-face
1474 (and (not noninteractive)
1475 (gnus-image-type-available-p 'png)
1477 "Display Face headers.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Face' for details."
1481 :group 'gnus-article-treat
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)X-Face")
1485 :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-display-face 'highlight t)
1488 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1490 Valid values are nil, t, `head', `first', `last', an integer or a
1491 predicate. See Info node `(gnus)Customizing Articles' and Info
1492 node `(gnus)Smileys' for details."
1493 :group 'gnus-article-treat
1495 :link '(custom-manual "(gnus)Customizing Articles")
1496 :link '(custom-manual "(gnus)Smileys")
1497 :type gnus-article-treat-custom)
1498 (put 'gnus-treat-display-smileys 'highlight t)
1500 (defcustom gnus-treat-from-picon
1501 (if (and (gnus-image-type-available-p 'xpm)
1502 (gnus-picons-installed-p))
1504 "Display picons in the From header.
1505 Valid values are nil, t, `head', `first', `last', an integer or a
1506 predicate. See Info node `(gnus)Customizing Articles' and Info
1507 node `(gnus)Picons' for details."
1509 :group 'gnus-article-treat
1511 :link '(custom-manual "(gnus)Customizing Articles")
1512 :link '(custom-manual "(gnus)Picons")
1513 :type gnus-article-treat-head-custom)
1514 (put 'gnus-treat-from-picon 'highlight t)
1516 (defcustom gnus-treat-mail-picon
1517 (if (and (gnus-image-type-available-p 'xpm)
1518 (gnus-picons-installed-p))
1520 "Display picons in To and Cc headers.
1521 Valid values are nil, t, `head', `first', `last', an integer or a
1522 predicate. See Info node `(gnus)Customizing Articles' and Info
1523 node `(gnus)Picons' for details."
1525 :group 'gnus-article-treat
1527 :link '(custom-manual "(gnus)Customizing Articles")
1528 :link '(custom-manual "(gnus)Picons")
1529 :type gnus-article-treat-head-custom)
1530 (put 'gnus-treat-mail-picon 'highlight t)
1532 (defcustom gnus-treat-newsgroups-picon
1533 (if (and (gnus-image-type-available-p 'xpm)
1534 (gnus-picons-installed-p))
1536 "Display picons in the Newsgroups and Followup-To headers.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles' and Info
1539 node `(gnus)Picons' for details."
1541 :group 'gnus-article-treat
1543 :link '(custom-manual "(gnus)Customizing Articles")
1544 :link '(custom-manual "(gnus)Picons")
1545 :type gnus-article-treat-head-custom)
1546 (put 'gnus-treat-newsgroups-picon 'highlight t)
1548 (defcustom gnus-treat-from-gravatar nil
1549 "Display gravatars in the From header.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate. See Info node `(gnus)Customizing Articles' and Info
1552 node `(gnus)Gravatars' for details."
1554 :group 'gnus-article-treat
1555 :group 'gnus-gravatar
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :link '(custom-manual "(gnus)Gravatars")
1558 :type gnus-article-treat-head-custom)
1559 (put 'gnus-treat-from-gravatar 'highlight t)
1561 (defcustom gnus-treat-mail-gravatar nil
1562 "Display gravatars in To and Cc headers.
1563 Valid values are nil, t, `head', `first', `last', an integer or a
1564 predicate. See Info node `(gnus)Customizing Articles' and Info
1565 node `(gnus)Gravatars' for details."
1567 :group 'gnus-article-treat
1568 :group 'gnus-gravatar
1569 :link '(custom-manual "(gnus)Customizing Articles")
1570 :link '(custom-manual "(gnus)Gravatars")
1571 :type gnus-article-treat-head-custom)
1572 (put 'gnus-treat-mail-gravatar 'highlight t)
1574 (defcustom gnus-treat-body-boundary
1575 (if (or gnus-treat-newsgroups-picon
1576 gnus-treat-mail-picon
1577 gnus-treat-from-picon
1578 gnus-treat-from-gravatar
1579 gnus-treat-mail-gravatar)
1580 ;; If there's much decoration, the user might prefer a boundery.
1583 "Draw a boundary at the end of the headers.
1584 Valid values are nil and `head'.
1585 See Info node `(gnus)Customizing Articles' for details."
1587 :group 'gnus-article-treat
1588 :link '(custom-manual "(gnus)Customizing Articles")
1589 :type gnus-article-treat-head-custom)
1591 (defcustom gnus-treat-capitalize-sentences nil
1592 "Capitalize sentence-starting words.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1596 :group 'gnus-article-treat
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1600 (defcustom gnus-treat-wash-html nil
1602 Valid values are nil, t, `head', `first', `last', an integer or a
1603 predicate. See Info node `(gnus)Customizing Articles'."
1605 :group 'gnus-article-treat
1606 :link '(custom-manual "(gnus)Customizing Articles")
1607 :type gnus-article-treat-custom)
1609 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1611 Valid values are nil, t, `head', `first', `last', an integer or a
1612 predicate. See Info node `(gnus)Customizing Articles'."
1614 :group 'gnus-article-treat
1615 :link '(custom-manual "(gnus)Customizing Articles")
1616 :type gnus-article-treat-custom)
1618 (defcustom gnus-treat-x-pgp-sig nil
1620 To automatically treat X-PGP-Sig, set it to head.
1621 Valid values are nil, t, `head', `first', `last', an integer or a
1622 predicate. See Info node `(gnus)Customizing Articles'."
1624 :group 'gnus-article-treat
1625 :group 'mime-security
1626 :link '(custom-manual "(gnus)Customizing Articles")
1627 :type gnus-article-treat-custom)
1629 (defvar gnus-article-encrypt-protocol-alist
1630 '(("PGP" . mml2015-self-encrypt)))
1632 ;; Set to nil if more than one protocol added to
1633 ;; gnus-article-encrypt-protocol-alist.
1634 (defcustom gnus-article-encrypt-protocol "PGP"
1635 "The protocol used for encrypt articles.
1636 It is a string, such as \"PGP\". If nil, ask user."
1639 :group 'mime-security)
1641 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1642 (mm-coding-system-p 'utf-8)
1643 (executable-find idna-program))
1644 "Whether IDNA decoding of headers is used when viewing messages.
1645 This requires GNU Libidn, and by default only enabled if it is found."
1647 :group 'gnus-article-headers
1650 (defcustom gnus-article-over-scroll nil
1651 "If non-nil, allow scrolling the article buffer even when there no more text."
1653 :group 'gnus-article
1656 (defcustom gnus-inhibit-images nil
1657 "Non-nil means inhibit displaying of images inline in the article body."
1659 :group 'gnus-article
1662 (defcustom gnus-blocked-images 'gnus-block-private-groups
1663 "Images that have URLs matching this regexp will be blocked.
1664 This can also be a function to be evaluated. If so, it will be
1665 called with the group name as the parameter, and should return a
1671 ;;; Internal variables
1673 (defvar gnus-english-month-names
1674 '("January" "February" "March" "April" "May" "June" "July" "August"
1675 "September" "October" "November" "December"))
1677 (defvar article-goto-body-goes-to-point-min-p nil)
1678 (defvar gnus-article-wash-types nil)
1679 (defvar gnus-article-emphasis-alist nil)
1680 (defvar gnus-article-image-alist nil)
1682 (defvar gnus-article-mime-handle-alist-1 nil)
1683 (defvar gnus-treatment-function-alist
1684 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1685 (gnus-treat-strip-banner gnus-article-strip-banner)
1686 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1687 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1688 (gnus-treat-buttonize gnus-article-add-buttons)
1689 (gnus-treat-fill-article gnus-article-fill-cited-article)
1690 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1691 (gnus-treat-strip-cr gnus-article-remove-cr)
1692 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1693 (gnus-treat-date-ut gnus-article-date-ut)
1694 (gnus-treat-date-local gnus-article-date-local)
1695 (gnus-treat-date-english gnus-article-date-english)
1696 (gnus-treat-date-original gnus-article-date-original)
1697 (gnus-treat-date-user-defined gnus-article-date-user)
1698 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1699 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1700 (gnus-treat-date-combined-lapsed gnus-article-date-combined-lapsed)
1701 (gnus-treat-display-x-face gnus-article-display-x-face)
1702 (gnus-treat-display-face gnus-article-display-face)
1703 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1704 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1705 (gnus-treat-hide-signature gnus-article-hide-signature)
1706 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1707 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1708 (gnus-treat-from-picon gnus-treat-from-picon)
1709 (gnus-treat-mail-picon gnus-treat-mail-picon)
1710 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1711 (gnus-treat-strip-pem gnus-article-hide-pem)
1712 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1713 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1714 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1715 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1716 (gnus-treat-strip-trailing-blank-lines
1717 gnus-article-remove-trailing-blank-lines)
1718 (gnus-treat-strip-leading-blank-lines
1719 gnus-article-strip-leading-blank-lines)
1720 (gnus-treat-strip-multiple-blank-lines
1721 gnus-article-strip-multiple-blank-lines)
1722 (gnus-treat-overstrike gnus-article-treat-overstrike)
1723 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1724 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1725 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1726 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1727 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1728 (gnus-treat-display-smileys gnus-treat-smiley)
1729 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1730 (gnus-treat-wash-html gnus-article-wash-html)
1731 (gnus-treat-emphasize gnus-article-emphasize)
1732 (gnus-treat-hide-citation gnus-article-hide-citation)
1733 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1734 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1735 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1737 (defvar gnus-article-mime-handle-alist nil)
1738 (defvar article-lapsed-timer nil)
1739 (defvar gnus-article-current-summary nil)
1741 (defvar gnus-article-mode-syntax-table
1742 (let ((table (copy-syntax-table text-mode-syntax-table)))
1743 ;; This causes the citation match run O(2^n).
1744 ;; (modify-syntax-entry ?- "w" table)
1745 (modify-syntax-entry ?> ")<" table)
1746 (modify-syntax-entry ?< "(>" table)
1747 ;; make M-. in article buffers work for `foo' strings
1748 (modify-syntax-entry ?' " " table)
1749 (modify-syntax-entry ?` " " table)
1751 "Syntax table used in article mode buffers.
1752 Initialized from `text-mode-syntax-table.")
1754 (defvar gnus-save-article-buffer nil)
1756 (defvar gnus-number-of-articles-to-be-saved nil)
1758 (defvar gnus-inhibit-hiding nil)
1760 (defvar gnus-article-edit-mode nil)
1762 ;;; Macros for dealing with the article buffer.
1764 (defmacro gnus-with-article-headers (&rest forms)
1765 `(with-current-buffer gnus-article-buffer
1767 (let ((inhibit-read-only t)
1768 (inhibit-point-motion-hooks t)
1769 (case-fold-search t))
1770 (article-narrow-to-head)
1773 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1774 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1776 (defmacro gnus-with-article-buffer (&rest forms)
1777 `(with-current-buffer gnus-article-buffer
1778 (let ((inhibit-read-only t))
1781 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1782 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1784 (defun gnus-article-goto-header (header)
1785 "Go to HEADER, which is a regular expression."
1786 (re-search-forward (concat "^\\(" header "\\):") nil t))
1788 (defsubst gnus-article-hide-text (b e props)
1789 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1790 (gnus-add-text-properties-when 'article-type nil b e props)
1791 (when (memq 'intangible props)
1793 (max (1- b) (point-min))
1794 b 'intangible (cddr (memq 'intangible props)))))
1796 (defsubst gnus-article-unhide-text (b e)
1797 "Remove hidden text properties from region between B and E."
1798 (remove-text-properties b e gnus-hidden-properties)
1799 (when (memq 'intangible gnus-hidden-properties)
1800 (put-text-property (max (1- b) (point-min))
1801 b 'intangible nil)))
1803 (defun gnus-article-hide-text-type (b e type)
1804 "Hide text of TYPE between B and E."
1805 (gnus-add-wash-type type)
1806 (gnus-article-hide-text
1807 b e (cons 'article-type (cons type gnus-hidden-properties))))
1809 (defun gnus-article-unhide-text-type (b e type)
1810 "Unhide text of TYPE between B and E."
1811 (gnus-delete-wash-type type)
1812 (remove-text-properties
1813 b e (cons 'article-type (cons type gnus-hidden-properties)))
1814 (when (memq 'intangible gnus-hidden-properties)
1815 (put-text-property (max (1- b) (point-min))
1816 b 'intangible nil)))
1818 (defun gnus-article-hide-text-of-type (type)
1819 "Hide text of TYPE in the current buffer."
1821 (let ((b (point-min))
1823 (while (setq b (text-property-any b e 'article-type type))
1824 (add-text-properties b (incf b) gnus-hidden-properties)))))
1826 (defun gnus-article-delete-text-of-type (type)
1827 "Delete text of TYPE in the current buffer."
1829 (let ((b (point-min)))
1830 (if (eq type 'multipart)
1831 ;; Remove MIME buttons associated with multipart/alternative parts.
1834 (while (if (get-text-property (point) 'gnus-part)
1836 (when (setq b (next-single-property-change (point)
1841 (skip-chars-forward "\n")
1842 (when (eq (get-text-property b 'article-type) 'multipart)
1843 (delete-region b (point)))))
1844 (while (setq b (text-property-any b (point-max) 'article-type type))
1846 b (or (text-property-not-all b (point-max) 'article-type type)
1849 (defun gnus-article-delete-invisible-text ()
1850 "Delete all invisible text in the current buffer."
1852 (let ((b (point-min)))
1853 (while (setq b (text-property-any b (point-max) 'invisible t))
1855 b (or (text-property-not-all b (point-max) 'invisible t)
1858 (defun gnus-article-text-type-exists-p (type)
1859 "Say whether any text of type TYPE exists in the buffer."
1860 (text-property-any (point-min) (point-max) 'article-type type))
1862 (defsubst gnus-article-header-rank ()
1863 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1864 (let ((list gnus-sorted-header-list)
1867 (if (looking-at (car list))
1869 (setq list (cdr list))
1873 (defun article-hide-headers (&optional arg delete)
1874 "Hide unwanted headers and possibly sort them as well."
1876 ;; This function might be inhibited.
1877 (unless gnus-inhibit-hiding
1878 (let ((inhibit-read-only t)
1879 (case-fold-search t)
1880 (max (1+ (length gnus-sorted-header-list)))
1881 (inhibit-point-motion-hooks t)
1882 (cur (current-buffer))
1883 ignored visible beg)
1885 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1886 ;; group parameters, so we should go to the summary buffer.
1889 (progn (set-buffer gnus-summary-buffer) t)
1891 (setq ignored (when (not gnus-visible-headers)
1892 (cond ((stringp gnus-ignored-headers)
1893 gnus-ignored-headers)
1894 ((listp gnus-ignored-headers)
1895 (mapconcat 'identity
1896 gnus-ignored-headers
1898 visible (cond ((stringp gnus-visible-headers)
1899 gnus-visible-headers)
1900 ((and gnus-visible-headers
1901 (listp gnus-visible-headers))
1902 (mapconcat 'identity
1903 gnus-visible-headers
1907 ;; First we narrow to just the headers.
1908 (article-narrow-to-head)
1909 ;; Hide any "From " lines at the beginning of (mail) articles.
1910 (while (looking-at "From ")
1913 (delete-region (point-min) (point)))
1914 ;; Then treat the rest of the header lines.
1915 ;; Then we use the two regular expressions
1916 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1917 ;; select which header lines is to remain visible in the
1919 (while (re-search-forward "^[^ \t:]*:" nil t)
1921 ;; Mark the rank of the header.
1923 (point) (1+ (point)) 'message-rank
1924 (if (or (and visible (looking-at visible))
1926 (not (looking-at ignored))))
1927 (gnus-article-header-rank)
1930 (message-sort-headers-1)
1931 (when (setq beg (text-property-any
1932 (point-min) (point-max) 'message-rank (+ 2 max)))
1933 ;; We delete the unwanted headers.
1934 (gnus-add-wash-type 'headers)
1935 (add-text-properties (point-min) (+ 5 (point-min))
1936 '(article-type headers dummy-invisible t))
1937 (delete-region beg (point-max))))))))
1939 (defun article-hide-boring-headers (&optional arg)
1940 "Toggle hiding of headers that aren't very interesting.
1941 If given a negative prefix, always show; if given a positive prefix,
1943 (interactive (gnus-article-hidden-arg))
1944 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1945 (not gnus-show-all-headers))
1948 (let ((inhibit-read-only t)
1949 (inhibit-point-motion-hooks t))
1950 (article-narrow-to-head)
1951 (dolist (elem gnus-boring-article-headers)
1952 (goto-char (point-min))
1954 ;; Hide empty headers.
1956 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1958 (gnus-article-hide-text-type
1962 (if (re-search-forward "^[^ \t]" nil t)
1966 ;; Hide boring Newsgroups header.
1967 ((eq elem 'newsgroups)
1968 (when (gnus-string-equal
1969 (gnus-fetch-field "newsgroups")
1970 (gnus-group-real-name
1971 (if (boundp 'gnus-newsgroup-name)
1974 (gnus-article-hide-header "newsgroups")))
1975 ((eq elem 'to-address)
1976 (let ((to (message-fetch-field "to"))
1978 (gnus-parameter-to-address
1979 (if (boundp 'gnus-newsgroup-name)
1980 gnus-newsgroup-name ""))))
1981 (when (and to to-address
1984 ;; only one address in To
1985 (nth 1 (mail-extract-address-components to))
1987 (gnus-article-hide-header "to"))))
1989 (let ((to (message-fetch-field "to"))
1991 (gnus-parameter-to-list
1992 (if (boundp 'gnus-newsgroup-name)
1993 gnus-newsgroup-name ""))))
1994 (when (and to to-list
1997 ;; only one address in To
1998 (nth 1 (mail-extract-address-components to))
2000 (gnus-article-hide-header "to"))))
2002 (let ((cc (message-fetch-field "cc"))
2004 (gnus-parameter-to-list
2005 (if (boundp 'gnus-newsgroup-name)
2006 gnus-newsgroup-name ""))))
2007 (when (and cc to-list
2010 ;; only one address in CC
2011 (nth 1 (mail-extract-address-components cc))
2013 (gnus-article-hide-header "cc"))))
2014 ((eq elem 'followup-to)
2015 (when (gnus-string-equal
2016 (message-fetch-field "followup-to")
2017 (message-fetch-field "newsgroups"))
2018 (gnus-article-hide-header "followup-to")))
2019 ((eq elem 'reply-to)
2020 (if (gnus-group-find-parameter
2021 gnus-newsgroup-name 'broken-reply-to)
2022 (gnus-article-hide-header "reply-to")
2023 (let ((from (message-fetch-field "from"))
2024 (reply-to (message-fetch-field "reply-to")))
2031 (lambda (x) (downcase (cadr x)))
2032 (mail-extract-address-components from t))
2035 (lambda (x) (downcase (cadr x)))
2036 (mail-extract-address-components reply-to t))
2038 (gnus-article-hide-header "reply-to")))))
2040 (let ((date (with-current-buffer gnus-original-article-buffer
2041 ;; If date in `gnus-article-buffer' is localized
2042 ;; (`gnus-treat-date-user-defined'),
2043 ;; `days-between' might fail.
2044 (message-fetch-field "date"))))
2046 (< (days-between (current-time-string) date)
2048 (gnus-article-hide-header "date"))))
2050 (let ((to (message-fetch-field "to"))
2051 (cc (message-fetch-field "cc")))
2052 (when (> (length to) 1024)
2053 (gnus-article-hide-header "to"))
2054 (when (> (length cc) 1024)
2055 (gnus-article-hide-header "cc"))))
2059 (goto-char (point-min))
2060 (while (re-search-forward "^to:" nil t)
2061 (setq to-count (1+ to-count)))
2062 (when (> to-count 1)
2063 (while (> to-count 0)
2064 (goto-char (point-min))
2066 (re-search-forward "^to:" nil nil to-count)
2068 (narrow-to-region (point) (point-max))
2069 (gnus-article-hide-header "to"))
2070 (setq to-count (1- to-count))))
2071 (goto-char (point-min))
2072 (while (re-search-forward "^cc:" nil t)
2073 (setq cc-count (1+ cc-count)))
2074 (when (> cc-count 1)
2075 (while (> cc-count 0)
2076 (goto-char (point-min))
2078 (re-search-forward "^cc:" nil nil cc-count)
2080 (narrow-to-region (point) (point-max))
2081 (gnus-article-hide-header "cc"))
2082 (setq cc-count (1- cc-count)))))))))))))
2084 (defun gnus-article-hide-header (header)
2086 (goto-char (point-min))
2087 (when (re-search-forward (concat "^" header ":") nil t)
2088 (gnus-article-hide-text-type
2092 (if (re-search-forward "^[^ \t]" nil t)
2097 (defvar gnus-article-normalized-header-length 40
2098 "Length of normalized headers.")
2100 (defun article-normalize-headers ()
2101 "Make all header lines 40 characters long."
2103 (let ((inhibit-read-only t)
2107 (article-narrow-to-head)
2110 ((< (setq column (- (point-at-eol) (point)))
2111 gnus-article-normalized-header-length)
2113 (insert (make-string
2114 (- gnus-article-normalized-header-length column)
2116 ((> column gnus-article-normalized-header-length)
2117 (gnus-put-text-property
2119 (forward-char gnus-article-normalized-header-length)
2126 (forward-line 1))))))
2128 (defun article-treat-dumbquotes ()
2129 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2130 Note that this function guesses whether a character is a sm*rtq**t* or
2131 not, so it should only be used interactively.
2133 Sm*rtq**t*s are M****s***'s unilateral extension to the
2134 iso-8859-1 character map in an attempt to provide more quoting
2135 characters. If you see something like \\222 or \\264 where
2136 you're expecting some kind of apostrophe or quotation mark, then
2139 (article-translate-strings gnus-article-dumbquotes-map))
2141 (defvar org-entities)
2143 (defun article-treat-non-ascii ()
2144 "Translate many Unicode characters into their ASCII equivalents."
2146 (require 'org-entities)
2147 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2148 (dolist (elem org-entities)
2149 (when (and (listp elem)
2150 (= (length (nth 6 elem)) 1))
2151 (if (featurep 'xemacs)
2152 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2153 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2155 (when (article-goto-body)
2156 (let ((inhibit-read-only t)
2159 (if (not (setq replace (if (featurep 'xemacs)
2160 (get-char-table (following-char) table)
2161 (aref table (following-char)))))
2164 (setq props (text-properties-at (point)))
2166 (add-text-properties (point) (progn (insert replace) (point))
2168 (insert replace)))))))))
2170 (defun article-translate-characters (from to)
2171 "Translate all characters in the body of the article according to FROM and TO.
2172 FROM is a string of characters to translate from; to is a string of
2173 characters to translate to."
2175 (when (article-goto-body)
2176 (let ((inhibit-read-only t)
2177 (x (make-string 225 ?x))
2179 (while (< (incf i) (length x))
2182 (while (< i (length from))
2183 (aset x (aref from i) (aref to i))
2185 (translate-region (point) (point-max) x)))))
2187 (defun article-translate-strings (map)
2188 "Translate all string in the body of the article according to MAP.
2189 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2191 (when (article-goto-body)
2192 (let ((inhibit-read-only t))
2194 (let ((from (car elem))
2198 (while (search-forward from nil t)
2201 (if (eq (following-char) from)
2205 (forward-char 1)))))))))))
2207 (defun article-treat-overstrike ()
2208 "Translate overstrikes into bold text."
2211 (when (article-goto-body)
2212 (let ((inhibit-read-only t))
2213 (while (search-forward "\b" nil t)
2214 (let ((next (char-after))
2215 (previous (char-after (- (point) 2))))
2216 ;; We do the boldification/underlining by hiding the
2217 ;; overstrikes and putting the proper text property
2221 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2222 (put-text-property (point) (1+ (point)) 'face 'bold))
2224 (gnus-article-hide-text-type
2225 (1- (point)) (1+ (point)) 'overstrike)
2227 (- (point) 2) (1- (point)) 'face 'underline))
2229 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2231 (point) (1+ (point)) 'face 'underline)))))))))
2233 (defun article-treat-ansi-sequences ()
2234 "Translate ANSI SGR control sequences into overlays or extents."
2237 (when (article-goto-body)
2238 (let ((inhibit-read-only t))
2239 (ansi-color-apply-on-region (point) (point-max))))))
2241 (defun gnus-article-treat-unfold-headers ()
2242 "Unfold folded message headers.
2243 Only the headers that fit into the current window width will be
2246 (gnus-with-article-headers
2250 (mail-header-narrow-to-field)
2251 (let* ((header (buffer-string))
2253 (or (equal gnus-article-unfold-long-headers t)
2254 (and (stringp gnus-article-unfold-long-headers)
2255 (string-match gnus-article-unfold-long-headers header)))))
2258 (goto-char (point-min))
2259 (while (re-search-forward "\n[\t ]" nil t)
2260 (replace-match " " t t)))
2261 (setq length (- (point-max) (point-min) 1))
2262 (when (or unfoldable
2263 (< length (window-width)))
2264 (while (re-search-forward "\n[\t ]" nil t)
2265 (replace-match " " t t))))
2266 (goto-char (point-max)))))))
2268 (defun gnus-article-treat-fold-headers ()
2269 "Fold message headers."
2271 (gnus-with-article-headers
2274 (mail-header-narrow-to-field)
2275 (mail-header-fold-field)
2276 (goto-char (point-max))))))
2278 (defun gnus-treat-smiley ()
2279 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2281 (gnus-with-article-buffer
2282 (if (memq 'smiley gnus-article-wash-types)
2283 (gnus-delete-images 'smiley)
2285 (let ((images (smiley-region (point) (point-max))))
2287 (gnus-add-wash-type 'smiley)
2288 (dolist (image images)
2289 (gnus-add-image 'smiley image)))))))
2291 (defun gnus-article-remove-images ()
2292 "Remove all images from the article buffer."
2294 (gnus-with-article-buffer
2297 (dolist (elem gnus-article-image-alist)
2298 (gnus-delete-images (car elem))))))
2300 (defun gnus-article-show-images ()
2301 "Show any images that are in the HTML-rendered article buffer.
2302 This only works if the article in question is HTML."
2304 (gnus-with-article-buffer
2307 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2309 (destructuring-bind (start end function) region
2310 (funcall function (get-text-property start 'image-url)
2313 (defun gnus-article-treat-fold-newsgroups ()
2314 "Unfold folded message headers.
2315 Only the headers that fit into the current window width will be
2318 (gnus-with-article-headers
2319 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2321 (mail-header-narrow-to-field)
2322 (while (re-search-forward ", *" nil t)
2323 (replace-match ", " t t))
2324 (mail-header-fold-field)
2325 (goto-char (point-max))))))
2327 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2328 "Value of `truncate-lines' in Gnus Article buffer.
2329 Valid values are nil, t, `head', `first', `last', an integer or a
2330 predicate. See Info node `(gnus)Customizing Articles'."
2331 :version "23.1" ;; No Gnus
2332 :group 'gnus-article
2333 ;; :link '(custom-manual "(gnus)Customizing Articles")
2336 (defun gnus-article-toggle-truncate-lines (&optional arg)
2337 "Toggle whether to fold or truncate long lines in article the buffer.
2338 If ARG is non-nil and not a number, toggle
2339 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2340 long lines if and only if arg is positive."
2343 ((and (numberp arg) (> arg 0))
2344 (setq gnus-article-truncate-lines t))
2346 (setq gnus-article-truncate-lines nil))
2348 (setq gnus-article-truncate-lines
2349 (not gnus-article-truncate-lines))))
2350 (gnus-with-article-buffer
2352 ((and (numberp arg) (> arg 0))
2353 (setq truncate-lines nil))
2355 (setq truncate-lines t)))
2356 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2357 ;; `toggle-truncate-lines' needs an argument.
2358 (toggle-truncate-lines)))
2360 (defun gnus-article-treat-body-boundary ()
2361 "Place a boundary line at the end of the headers."
2363 (when (and gnus-body-boundary-delimiter
2364 (> (length gnus-body-boundary-delimiter) 0))
2365 (gnus-with-article-headers
2366 (goto-char (point-max))
2367 (let ((start (point)))
2368 (insert "X-Boundary: ")
2369 (gnus-add-text-properties start (point) '(invisible t intangible t))
2371 (while (>= (window-width) (length str))
2372 (setq str (concat str gnus-body-boundary-delimiter)))
2373 (substring str 0 (window-width)))
2375 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2377 (defun article-fill-long-lines ()
2378 "Fill lines that are wider than the window width."
2381 (let ((inhibit-read-only t)
2382 (width (window-width (get-buffer-window (current-buffer)))))
2385 (let ((adaptive-fill-mode nil)) ;Why? -sm
2388 (when (>= (current-column) (min fill-column width))
2389 (narrow-to-region (min (1+ (point)) (point-max))
2391 (let ((goback (point-marker)))
2392 (fill-paragraph nil)
2393 (goto-char (marker-position goback)))
2395 (forward-line 1)))))))
2397 (defun article-capitalize-sentences ()
2398 "Capitalize the first word in each sentence."
2401 (let ((inhibit-read-only t)
2402 (paragraph-start "^[\n\^L]"))
2406 (forward-sentence)))))
2408 (defun article-remove-cr ()
2409 "Remove trailing CRs and then translate remaining CRs into LFs."
2412 (let ((inhibit-read-only t))
2413 (goto-char (point-min))
2414 (while (re-search-forward "\r+$" nil t)
2415 (replace-match "" t t))
2416 (goto-char (point-min))
2417 (while (search-forward "\r" nil t)
2418 (replace-match "\n" t t)))))
2420 (defun article-remove-trailing-blank-lines ()
2421 "Remove all trailing blank lines from the article."
2424 (let ((inhibit-read-only t))
2425 (goto-char (point-max))
2429 (while (and (not (bobp))
2430 (looking-at "^[ \t]*$")
2431 (not (gnus-annotation-in-region-p
2432 (point) (point-at-eol))))
2437 (defvar gnus-face-properties-alist)
2439 (defun article-display-face (&optional force)
2440 "Display any Face headers in the header."
2441 (interactive (list 'force))
2442 (let ((wash-face-p buffer-read-only))
2443 (gnus-with-article-headers
2444 ;; When displaying parts, this function can be called several times on
2445 ;; the same article, without any intended toggle semantic (as typing `W
2446 ;; D d' would have). So face deletion must occur only when we come from
2447 ;; an interactive command, that is when the *Article* buffer is
2449 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2450 (gnus-delete-images 'face)
2451 (let ((from (message-fetch-field "from"))
2453 (save-current-buffer
2454 (when (and wash-face-p
2455 (gnus-buffer-live-p gnus-original-article-buffer)
2456 (not (re-search-forward "^Face:[\t ]*" nil t)))
2457 (set-buffer gnus-original-article-buffer))
2459 (mail-narrow-to-head)
2461 ;; Check whether this face is censored.
2462 (not (and gnus-article-x-face-too-ugly
2464 (setq from (message-fetch-field "from")))
2465 (string-match gnus-article-x-face-too-ugly
2467 (while (gnus-article-goto-header "Face")
2468 (push (mail-header-field-value) faces)))))
2470 (goto-char (point-min))
2472 (unless (setq from (gnus-article-goto-header "from"))
2475 (insert " [no `from' set]\n"))
2477 (when (setq png (gnus-convert-face-to-png (pop faces)))
2479 (apply 'gnus-create-image png 'png t
2480 (cdr (assq 'png gnus-face-properties-alist))))
2482 (gnus-add-wash-type 'face)
2483 (gnus-add-image 'face image)
2484 (gnus-put-image image nil 'face))))))))))
2486 (defun article-display-x-face (&optional force)
2487 "Look for an X-Face header and display it if present."
2488 (interactive (list 'force))
2489 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2490 (gnus-with-article-headers
2491 ;; Delete the old process, if any.
2492 (when (process-status "article-x-face")
2493 (delete-process "article-x-face"))
2494 ;; See the comment in `article-display-face'.
2495 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2496 ;; We have already displayed X-Faces, so we remove them
2498 (gnus-delete-images 'xface)
2500 (let ((from (message-fetch-field "from"))
2502 (save-current-buffer
2503 (when (and wash-face-p
2504 (gnus-buffer-live-p gnus-original-article-buffer)
2505 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2506 ;; If type `W f', use gnus-original-article-buffer,
2507 ;; otherwise use the current buffer because displaying
2508 ;; RFC822 parts calls this function too.
2509 (set-buffer gnus-original-article-buffer))
2511 (mail-narrow-to-head)
2512 (and gnus-article-x-face-command
2514 ;; Check whether this face is censored.
2515 (not (and gnus-article-x-face-too-ugly
2517 (setq from (message-fetch-field "from")))
2518 (string-match gnus-article-x-face-too-ugly
2520 (while (gnus-article-goto-header "X-Face")
2521 (push (mail-header-field-value) x-faces)))))
2523 ;; We display the face.
2524 (cond ((functionp gnus-article-x-face-command)
2525 ;; The command is a lisp function, so we call it.
2526 (mapc gnus-article-x-face-command x-faces))
2527 ((stringp gnus-article-x-face-command)
2528 ;; The command is a string, so we interpret the command
2529 ;; as a, well, command, and fork it off.
2530 (let ((process-connection-type nil))
2531 (gnus-set-process-query-on-exit-flag
2533 "article-x-face" nil shell-file-name
2534 shell-command-switch gnus-article-x-face-command)
2536 ;; Sending multiple EOFs to xv doesn't work,
2537 ;; so we only do a single external face.
2539 (insert (car x-faces))
2540 (process-send-region "article-x-face"
2541 (point-min) (point-max)))
2542 (process-send-eof "article-x-face")))
2544 (error "`%s' set to `%s' is not a function"
2545 gnus-article-x-face-command
2546 'gnus-article-x-face-command)))))))))
2548 (defun article-decode-mime-words ()
2549 "Decode all MIME-encoded words in the article."
2551 (gnus-with-article-buffer
2552 (let ((inhibit-point-motion-hooks t)
2553 (mail-parse-charset gnus-newsgroup-charset)
2554 (mail-parse-ignored-charsets
2555 (with-current-buffer gnus-summary-buffer
2556 gnus-newsgroup-ignored-charsets)))
2557 (mail-decode-encoded-word-region (point-min) (point-max)))))
2559 (defun article-decode-charset (&optional prompt)
2560 "Decode charset-encoded text in the article.
2561 If PROMPT (the prefix), prompt for a coding system to use."
2563 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2564 (inhibit-read-only t)
2565 (mail-parse-charset gnus-newsgroup-charset)
2566 (mail-parse-ignored-charsets
2567 (save-excursion (condition-case nil
2568 (set-buffer gnus-summary-buffer)
2570 gnus-newsgroup-ignored-charsets))
2571 ct cte ctl charset format)
2574 (article-narrow-to-head)
2575 (setq ct (message-fetch-field "Content-Type" t)
2576 cte (message-fetch-field "Content-Transfer-Encoding" t)
2577 ctl (and ct (mail-header-parse-content-type ct))
2580 (mm-read-coding-system "Charset to decode: "))
2582 (mail-content-type-get ctl 'charset)))
2583 format (and ctl (mail-content-type-get ctl 'format)))
2585 (setq cte (mail-header-strip cte)))
2586 (if (and ctl (not (string-match "/" (car ctl))))
2588 (goto-char (point-max)))
2591 (narrow-to-region (point) (point-max))
2592 (when (and (eq mail-parse-charset 'gnus-decoded)
2593 (eq (mm-body-7-or-8) '8bit))
2594 ;; The text code could have been decoded.
2595 (setq charset mail-parse-charset))
2596 (when (and (or (not ctl)
2597 (equal (car ctl) "text/plain"))
2598 (not format)) ;; article with format will decode later.
2600 charset (and cte (intern (downcase
2601 (gnus-strip-whitespace cte))))
2604 (defun article-decode-encoded-words ()
2605 "Remove encoded-word encoding from headers."
2606 (let ((inhibit-point-motion-hooks t)
2607 (mail-parse-charset gnus-newsgroup-charset)
2608 (mail-parse-ignored-charsets
2609 (save-excursion (condition-case nil
2610 (set-buffer gnus-summary-buffer)
2612 gnus-newsgroup-ignored-charsets))
2613 (inhibit-read-only t)
2615 (goto-char (point-min))
2616 (when (search-forward "\n\n" nil 'move)
2623 (memq (char-after) '(?\t ? )))))
2624 (setq start (point))
2626 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2627 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2628 (funcall gnus-decode-address-function start end)
2629 (funcall gnus-decode-header-function start end))
2630 (goto-char (setq end start)))))
2632 (defun article-decode-group-name ()
2633 "Decode group names in Newsgroups, Followup-To and Xref headers."
2634 (let ((inhibit-point-motion-hooks t)
2635 (inhibit-read-only t)
2636 (method (gnus-find-method-for-group gnus-newsgroup-name))
2638 (when (and (or gnus-group-name-charset-method-alist
2639 gnus-group-name-charset-group-alist)
2640 (gnus-buffer-live-p gnus-original-article-buffer))
2642 (article-narrow-to-head)
2643 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2644 (with-current-buffer gnus-original-article-buffer
2645 (goto-char (point-min)))
2646 (setq regexp (concat "^" header
2647 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2648 (while (re-search-forward regexp nil t)
2649 (replace-match (save-match-data
2650 (gnus-decode-newsgroups
2651 ;; XXX how to use data in article buffer?
2652 (with-current-buffer gnus-original-article-buffer
2653 (re-search-forward regexp nil t)
2655 gnus-newsgroup-name method))
2657 (goto-char (point-min)))))))
2659 (autoload 'idna-to-unicode "idna")
2661 (defun article-decode-idna-rhs ()
2662 "Decode IDNA strings in RHS in various headers in current buffer.
2663 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2664 Mail-Reply-To: and Mail-Followup-To:."
2667 (let ((inhibit-point-motion-hooks t)
2668 (inhibit-read-only t))
2669 (article-narrow-to-head)
2670 (goto-char (point-min))
2671 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2673 (when (save-match-data
2674 (and (setq ace (match-string 1))
2676 (and (re-search-backward "^[^ \t]" nil t)
2677 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2678 (setq unicode (idna-to-unicode ace))))
2679 (unless (string= ace unicode)
2680 (replace-match unicode nil nil nil 1)))))))))
2682 (defun article-de-quoted-unreadable (&optional force read-charset)
2683 "Translate a quoted-printable-encoded article.
2684 If FORCE, decode the article whether it is marked as quoted-printable
2686 If READ-CHARSET, ask for a coding system."
2687 (interactive (list 'force current-prefix-arg))
2689 (let ((inhibit-read-only t) type charset)
2690 (if (gnus-buffer-live-p gnus-original-article-buffer)
2691 (with-current-buffer gnus-original-article-buffer
2693 (gnus-fetch-field "content-transfer-encoding"))
2694 (let* ((ct (gnus-fetch-field "content-type"))
2695 (ctl (and ct (mail-header-parse-content-type ct))))
2696 (setq charset (and ctl
2697 (mail-content-type-get ctl 'charset)))
2698 (if (stringp charset)
2699 (setq charset (intern (downcase charset)))))))
2701 (setq charset (mm-read-coding-system "Charset: " charset)))
2703 (setq charset gnus-newsgroup-charset))
2705 (and type (let ((case-fold-search t))
2706 (string-match "quoted-printable" type))))
2708 (quoted-printable-decode-region
2709 (point) (point-max) (mm-charset-to-coding-system charset))))))
2711 (defun article-de-base64-unreadable (&optional force read-charset)
2712 "Translate a base64 article.
2713 If FORCE, decode the article whether it is marked as base64 not.
2714 If READ-CHARSET, ask for a coding system."
2715 (interactive (list 'force current-prefix-arg))
2717 (let ((inhibit-read-only t) type charset)
2718 (if (gnus-buffer-live-p gnus-original-article-buffer)
2719 (with-current-buffer gnus-original-article-buffer
2721 (gnus-fetch-field "content-transfer-encoding"))
2722 (let* ((ct (gnus-fetch-field "content-type"))
2723 (ctl (and ct (mail-header-parse-content-type ct))))
2724 (setq charset (and ctl
2725 (mail-content-type-get ctl 'charset)))
2726 (if (stringp charset)
2727 (setq charset (intern (downcase charset)))))))
2729 (setq charset (mm-read-coding-system "Charset: " charset)))
2731 (setq charset gnus-newsgroup-charset))
2733 (and type (let ((case-fold-search t))
2734 (string-match "base64" type))))
2737 (narrow-to-region (point) (point-max))
2738 (base64-decode-region (point-min) (point-max))
2739 (mm-decode-coding-region
2740 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2745 (defun article-decode-HZ ()
2746 "Translate a HZ-encoded article."
2750 (let ((inhibit-read-only t))
2751 (rfc1843-decode-region (point-min) (point-max)))))
2753 (defun article-unsplit-urls ()
2754 "Remove the newlines that some other mailers insert into URLs."
2757 (let ((inhibit-read-only t))
2758 (goto-char (point-min))
2759 (while (re-search-forward
2760 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2761 (replace-match "\\1\\3" t)))
2762 (when (interactive-p)
2763 (gnus-treat-article nil))))
2765 (defun article-wash-html ()
2766 "Format an HTML article."
2769 (buffer-read-only nil))
2770 (when (gnus-buffer-live-p gnus-original-article-buffer)
2771 (setq handles (mm-dissect-buffer t t)))
2773 (delete-region (point) (point-max))
2774 (mm-inline-text-html handles)))
2776 (defvar gnus-article-browse-html-temp-list nil
2777 "List of temporary files created by `gnus-article-browse-html-parts'.
2778 Internal variable.")
2780 (defcustom gnus-article-browse-delete-temp 'ask
2781 "What to do with temporary files from `gnus-article-browse-html-parts'.
2782 If nil, don't delete temporary files. If it is t, delete them on
2783 exit from the summary buffer. If it is the symbol `file', query
2784 on each file, if it is `ask' ask once when exiting from the
2786 :group 'gnus-article
2787 :version "23.1" ;; No Gnus
2788 :type '(choice (const :tag "Don't delete" nil)
2789 (const :tag "Don't ask" t)
2790 (const :tag "Ask" ask)
2791 (const :tag "Ask for each file" file)))
2793 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2795 (defun gnus-article-browse-delete-temp-files (&optional how)
2796 "Delete temp-files created by `gnus-article-browse-html-parts'."
2797 (when (and gnus-article-browse-html-temp-list
2799 (or how (setq how gnus-article-browse-delete-temp))
2801 (let ((files (length gnus-article-browse-html-temp-list)))
2802 (gnus-y-or-n-p (format
2803 "Delete all %s temporary HTML file%s? "
2805 (if (> files 1) "s" ""))))
2807 (dolist (file gnus-article-browse-html-temp-list)
2808 (cond ((file-directory-p file)
2809 (when (or (not (eq how 'file))
2812 "Delete temporary HTML file(s) in directory `%s'? "
2813 (file-name-as-directory file))))
2814 (gnus-delete-directory file)))
2815 ((file-exists-p file)
2816 (when (or (not (eq how 'file))
2818 (format "Delete temporary HTML file `%s'? " file)))
2819 (delete-file file)))))
2820 ;; Also remove file from the list when not deleted or if file doesn't
2822 (setq gnus-article-browse-html-temp-list nil))
2823 gnus-article-browse-html-temp-list)
2825 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2826 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2831 (dolist (handle handles)
2833 ((not (listp handle)))
2834 ((equal (mm-handle-media-supertype handle) "multipart")
2835 (when (setq file (gnus-article-browse-html-save-cid-content
2836 cid handle directory))
2837 (throw 'found file)))
2838 ((equal (concat "<" cid ">") (mm-handle-id handle))
2841 (or (mail-content-type-get
2842 (mm-handle-disposition handle) 'filename)
2843 (mail-content-type-get
2844 (setq type (mm-handle-type handle)) 'name)
2846 (make-temp-name "cid")
2847 (car (rassoc (car type) mailcap-mime-extensions))))
2849 (mm-save-part-to-file handle file)
2850 (throw 'found file))))))))
2852 (defun gnus-article-browse-html-parts (list &optional header)
2853 "View all \"text/html\" parts from LIST.
2854 Recurse into multiparts. The optional HEADER that should be a decoded
2855 message header will be added to the bodies of the \"text/html\" parts."
2856 ;; Internal function used by `gnus-article-browse-html-article'.
2857 (let (type file charset content cid-dir tmp-file showed)
2858 ;; Find and show the html-parts.
2859 (dolist (handle list)
2860 ;; If HTML, show it:
2861 (cond ((not (listp handle)))
2862 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2863 (and (equal (car type) "message/external-body")
2865 (setq file (or (mail-content-type-get type 'name)
2866 (mail-content-type-get
2867 (mm-handle-disposition handle)
2869 (or (mm-handle-cache handle)
2870 (condition-case code
2871 (progn (mm-extern-cache-contents handle) t)
2873 (gnus-message 3 "%s" (error-message-string code))
2874 (when (>= gnus-verbose 3) (sit-for 2))
2877 (setq handle (mm-handle-cache handle)
2878 type (mm-handle-type handle))
2879 (equal (car type) "text/html"))))
2880 (setq charset (mail-content-type-get type 'charset)
2881 content (mm-get-part handle))
2883 (if (eq charset 'gnus-decoded)
2884 (mm-enable-multibyte)
2885 (mm-disable-multibyte))
2887 ;; resolve cid contents
2888 (let ((case-fold-search t)
2890 (goto-char (point-min))
2891 (while (re-search-forward "\
2892 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2895 (setq cid-dir (mm-make-temp-file "cid" t))
2896 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2899 (when (setq cid-file
2900 (gnus-article-browse-html-save-cid-content
2902 (with-current-buffer gnus-article-buffer
2903 gnus-article-mime-handles)
2905 (replace-match (concat "file://" cid-file)
2907 (unless content (setq content (buffer-string))))
2908 (when (or charset header (not file))
2909 (setq tmp-file (mm-make-temp-file
2910 ;; Do we need to care for 8.3 filenames?
2911 "mm-" nil ".html")))
2912 ;; Add a meta html tag to specify charset and a header.
2915 (let (title eheader body hcharset coding force-charset)
2917 (mm-enable-multibyte)
2918 (setq case-fold-search t)
2919 (insert header "\n")
2920 (setq title (message-fetch-field "subject"))
2921 (goto-char (point-min))
2922 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2923 (replace-match (cond ((match-beginning 1) "<")
2924 ((match-beginning 2) ">")
2926 (goto-char (point-min))
2928 (goto-char (point-max))
2929 (insert "</pre>\n<hr>\n")
2930 ;; We have to examine charset one by one since
2931 ;; charset specified in parts might be different.
2932 (if (eq charset 'gnus-decoded)
2933 (setq charset 'utf-8
2934 eheader (mm-encode-coding-string (buffer-string)
2937 (mm-encode-coding-string title charset))
2938 body (mm-encode-coding-string content charset)
2940 (setq hcharset (mm-find-mime-charset-region (point-min)
2942 (cond ((= (length hcharset) 1)
2943 (setq hcharset (car hcharset)
2944 coding (mm-charset-to-coding-system
2946 ((> (length hcharset) 1)
2947 (setq hcharset 'utf-8
2953 (mm-charset-to-coding-system charset))
2954 (if (eq coding body)
2955 (setq eheader (mm-encode-coding-string
2956 (buffer-string) coding)
2958 (mm-encode-coding-string
2961 (setq charset 'utf-8
2962 eheader (mm-encode-coding-string
2963 (buffer-string) charset)
2965 (mm-encode-coding-string
2967 body (mm-encode-coding-string
2968 (mm-decode-coding-string
2972 (setq charset hcharset
2973 eheader (mm-encode-coding-string
2974 (buffer-string) coding)
2976 (mm-encode-coding-string
2979 (setq eheader (mm-string-as-unibyte (buffer-string))
2982 (mm-disable-multibyte)
2985 (mm-add-meta-html-tag handle charset force-charset))
2987 (goto-char (point-min))
2988 (unless (search-forward "<title>" nil t)
2989 (re-search-forward "<head>\\s-*" nil t)
2990 (insert "<title>" title "</title>\n")))
2991 (goto-char (point-min))
2992 (or (re-search-forward
2993 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2995 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2997 (mm-write-region (point-min) (point-max)
2998 tmp-file nil nil nil 'binary t))))
3000 (mm-with-unibyte-buffer
3001 (insert (if (eq charset 'gnus-decoded)
3002 (mm-encode-coding-string content
3003 (setq charset 'utf-8))
3005 (if (or (mm-add-meta-html-tag handle charset)
3007 (mm-write-region (point-min) (point-max)
3008 tmp-file nil nil nil 'binary t)
3009 (setq tmp-file nil))))
3011 (mm-save-part-to-file handle tmp-file)))
3013 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3014 (add-hook 'gnus-summary-prepare-exit-hook
3015 'gnus-article-browse-delete-temp-files)
3016 (add-hook 'gnus-exit-gnus-hook
3018 (gnus-article-browse-delete-temp-files t)))
3019 ;; FIXME: Warn if there's an <img> tag?
3020 (browse-url-of-file (or tmp-file (expand-file-name file)))
3022 ;; If multipart, recurse
3023 ((equal (mm-handle-media-supertype handle) "multipart")
3024 (when (gnus-article-browse-html-parts handle header)
3026 ((equal (mm-handle-media-type handle) "message/rfc822")
3027 (mm-with-multibyte-buffer
3028 (mm-insert-part handle)
3029 (setq handle (mm-dissect-buffer t t))
3030 (when (and (bufferp (car handle))
3031 (stringp (car (mm-handle-type handle))))
3032 (setq handle (list handle)))
3034 (article-decode-encoded-words)
3035 (let ((gnus-visible-headers
3036 (or (get 'gnus-visible-headers 'standard-value)
3037 gnus-visible-headers)))
3038 (article-hide-headers))
3039 (goto-char (point-min))
3040 (search-forward "\n\n" nil 'move)
3041 (skip-chars-backward "\t\n ")
3042 (setq header (buffer-substring (point-min) (point)))))
3044 (gnus-article-browse-html-parts handle header)
3045 (mm-destroy-parts handle))
3049 (defun gnus-article-browse-html-article (&optional arg)
3050 "View \"text/html\" parts of the current article with a WWW browser.
3051 Inline images embedded in a message using the cid scheme, as they are
3052 generally considered to be safe, will be processed properly.
3053 The message header is added to the beginning of every html part unless
3054 the prefix argument ARG is given.
3056 Warning: Spammers use links to images (using the http scheme) in HTML
3057 articles to verify whether you have read the message. As
3058 `gnus-article-browse-html-article' passes the HTML content to the
3059 browser without eliminating these \"web bugs\" you should only
3060 use it for mails from trusted senders.
3062 If you always want to display HTML parts in the browser, set
3063 `mm-text-html-renderer' to nil.
3065 This command creates temporary files to pass HTML contents including
3066 images if any to the browser, and deletes them when exiting the group
3068 ;; Cf. `mm-w3m-safe-url-regexp'
3071 (gnus-summary-show-article)
3072 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3073 gnus-visible-headers))
3074 ;; As we insert a <hr>, there's no need for the body boundary.
3075 (gnus-treat-body-boundary nil))
3076 (gnus-summary-show-article)))
3077 (with-current-buffer gnus-article-buffer
3078 (let ((header (unless arg
3081 (buffer-substring-no-properties
3082 (goto-char (point-min))
3083 (if (search-forward "\n\n" nil t)
3085 (goto-char (point-max))
3086 (skip-chars-backward "\t\n ")
3089 (set-buffer gnus-original-article-buffer)
3090 (setq parts (mm-dissect-buffer t t))
3091 ;; If singlepart, enforce a list.
3092 (when (and (bufferp (car parts))
3093 (stringp (car (mm-handle-type parts))))
3094 (setq parts (list parts)))
3096 (unless (gnus-article-browse-html-parts parts header)
3097 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3098 (mm-destroy-parts parts)
3100 (gnus-summary-show-article)))))
3102 (defun article-hide-list-identifiers ()
3103 "Remove list identifies from the Subject header.
3104 The `gnus-list-identifiers' variable specifies what to do."
3106 (let ((inhibit-point-motion-hooks t)
3107 (regexp (if (consp gnus-list-identifiers)
3108 (mapconcat 'identity gnus-list-identifiers " *\\|")
3109 gnus-list-identifiers))
3110 (inhibit-read-only t))
3114 (article-narrow-to-head)
3115 (goto-char (point-min))
3116 (while (re-search-forward
3117 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3119 (delete-region (match-beginning 2) (match-end 0))
3120 (beginning-of-line))
3121 (when (re-search-forward
3122 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3123 (delete-region (match-beginning 1) (match-end 1))))))))
3125 (defun article-hide-pem (&optional arg)
3126 "Toggle hiding of any PEM headers and signatures in the current article.
3127 If given a negative prefix, always show; if given a positive prefix,
3129 (interactive (gnus-article-hidden-arg))
3130 (unless (gnus-article-check-hidden-text 'pem arg)
3132 (let ((inhibit-read-only t) end)
3133 (goto-char (point-min))
3134 ;; Hide the horrendously ugly "header".
3135 (when (and (search-forward
3136 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3138 (setq end (1+ (match-beginning 0))))
3139 (gnus-add-wash-type 'pem)
3140 (gnus-article-hide-text-type
3142 (if (search-forward "\n\n" nil t)
3146 ;; Hide the trailer as well
3147 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3149 (gnus-article-hide-text-type
3150 (match-beginning 0) (match-end 0) 'pem)))))))
3152 (defun article-strip-banner ()
3153 "Strip the banners specified by the `banner' group parameter and by
3154 `gnus-article-address-banner-alist'."
3158 (let ((inhibit-point-motion-hooks t))
3159 (when (gnus-parameter-banner gnus-newsgroup-name)
3160 (article-really-strip-banner
3161 (gnus-parameter-banner gnus-newsgroup-name)))
3162 (when gnus-article-address-banner-alist
3163 ;; Note that the From header is decoded here, so it is
3164 ;; required that the *-extract-address-components function
3165 ;; supports non-ASCII text.
3166 (let ((from (save-restriction
3168 (article-narrow-to-head)
3169 (mail-fetch-field "from"))))
3172 (cadr (funcall gnus-extract-address-components
3175 (dolist (pair gnus-article-address-banner-alist)
3176 (when (string-match (car pair) from)
3178 (article-really-strip-banner (cdr pair)))))))))))))
3180 (defun article-really-strip-banner (banner)
3181 "Strip the banner specified by the argument."
3184 (let ((inhibit-point-motion-hooks t)
3185 (gnus-signature-limit nil)
3186 (inhibit-read-only t))
3189 ((eq banner 'signature)
3190 (when (gnus-article-narrow-to-signature)
3193 (delete-region (point) (point-max))))
3195 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3196 (while (re-search-forward banner nil t)
3197 (delete-region (match-beginning 0) (match-end 0)))))
3199 (while (re-search-forward banner nil t)
3200 (delete-region (match-beginning 0) (match-end 0)))))))))
3202 (defun article-babel ()
3203 "Translate article using an online translation service."
3206 (gnus-with-article-buffer
3207 (when (article-goto-body)
3208 (let* ((start (point))
3210 (orig (buffer-substring start end))
3211 (trans (babel-as-string orig)))
3213 (narrow-to-region start end)
3214 (delete-region start end)
3217 (defun article-hide-signature (&optional arg)
3218 "Hide the signature in the current article.
3219 If given a negative prefix, always show; if given a positive prefix,
3221 (interactive (gnus-article-hidden-arg))
3222 (unless (gnus-article-check-hidden-text 'signature arg)
3225 (let ((inhibit-read-only t))
3226 (when (gnus-article-narrow-to-signature)
3227 (gnus-article-hide-text-type
3228 (point-min) (point-max) 'signature))))))
3229 (gnus-set-mode-line 'article))
3231 (defun article-strip-headers-in-body ()
3232 "Strip offensive headers from bodies."
3236 (let ((case-fold-search t))
3237 (when (looking-at "x-no-archive:")
3238 (gnus-delete-line)))))
3240 (defun article-strip-leading-blank-lines ()
3241 "Remove all blank lines from the beginning of the article."
3244 (let ((inhibit-point-motion-hooks t)
3245 (inhibit-read-only t))
3246 (when (article-goto-body)
3247 (while (and (not (eobp))
3248 (looking-at "[ \t]*$"))
3249 (gnus-delete-line))))))
3251 (defun article-narrow-to-head ()
3252 "Narrow the buffer to the head of the message.
3253 Point is left at the beginning of the narrowed-to region."
3255 (goto-char (point-min))
3256 (if (search-forward "\n\n" nil 1)
3259 (goto-char (point-min)))
3261 (defun article-goto-body ()
3262 "Place point at the start of the body."
3263 (goto-char (point-min))
3265 ;; This variable is only bound when dealing with separate
3267 (article-goto-body-goes-to-point-min-p
3269 ((search-forward "\n\n" nil t)
3272 (goto-char (point-max))
3275 (defun article-strip-multiple-blank-lines ()
3276 "Replace consecutive blank lines with one empty line."
3279 (let ((inhibit-point-motion-hooks t)
3280 (inhibit-read-only t))
3281 ;; First make all blank lines empty.
3283 (while (re-search-forward "^[ \t]+$" nil t)
3284 (unless (gnus-annotation-in-region-p
3285 (match-beginning 0) (match-end 0))
3286 (replace-match "" nil t)))
3287 ;; Then replace multiple empty lines with a single empty line.
3289 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3290 (unless (gnus-annotation-in-region-p
3291 (match-beginning 0) (match-end 0))
3292 (delete-region (match-beginning 1) (match-end 1)))))))
3294 (defun article-strip-leading-space ()
3295 "Remove all white space from the beginning of the lines in the article."
3298 (let ((inhibit-point-motion-hooks t)
3299 (inhibit-read-only t))
3301 (while (re-search-forward "^[ \t]+" nil t)
3302 (replace-match "" t t)))))
3304 (defun article-strip-trailing-space ()
3305 "Remove all white space from the end of the lines in the article."
3308 (let ((inhibit-point-motion-hooks t)
3309 (inhibit-read-only t))
3311 (while (re-search-forward "[ \t]+$" nil t)
3312 (replace-match "" t t)))))
3314 (defun article-strip-blank-lines ()
3315 "Strip leading, trailing and multiple blank lines."
3317 (article-strip-leading-blank-lines)
3318 (article-remove-trailing-blank-lines)
3319 (article-strip-multiple-blank-lines))
3321 (defun article-strip-all-blank-lines ()
3322 "Strip all blank lines."
3325 (let ((inhibit-point-motion-hooks t)
3326 (inhibit-read-only t))
3328 (while (re-search-forward "^[ \t]*\n" nil t)
3329 (replace-match "" t t)))))
3331 (defun gnus-article-narrow-to-signature ()
3332 "Narrow to the signature; return t if a signature is found, else nil."
3333 (let ((inhibit-point-motion-hooks t))
3334 (when (gnus-article-search-signature)
3336 ;; Check whether we have some limits to what we consider
3337 ;; to be a signature.
3338 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3339 (list gnus-signature-limit)))
3341 (while (setq limit (pop limits))
3342 (if (or (and (integerp limit)
3343 (< (- (point-max) (point)) limit))
3345 (< (count-lines (point) (point-max)) limit))
3346 (and (functionp limit)
3348 (and (stringp limit)
3349 (not (re-search-forward limit nil t))))
3350 () ; This limit did not succeed.
3354 (narrow-to-region (point) (point-max))
3357 (defun gnus-article-search-signature ()
3358 "Search the current buffer for the signature separator.
3359 Put point at the beginning of the signature separator."
3360 (let ((cur (point)))
3361 (goto-char (point-max))
3362 (if (if (stringp gnus-signature-separator)
3363 (re-search-backward gnus-signature-separator nil t)
3364 (let ((seps gnus-signature-separator))
3366 (not (re-search-backward (car seps) nil t)))
3373 (defun gnus-article-hidden-arg ()
3374 "Return the current prefix arg as a number, or 0 if no prefix."
3375 (list (if current-prefix-arg
3376 (prefix-numeric-value current-prefix-arg)
3379 (defun gnus-article-check-hidden-text (type arg)
3380 "Return nil if hiding is necessary.
3381 Arg can be nil or a number. nil and positive means hide, negative
3382 means show, 0 means toggle."
3385 (let ((hide (gnus-article-hidden-text-p type)))
3391 (gnus-article-show-hidden-text type)
3394 (if (eq hide 'hidden)
3396 (gnus-article-show-hidden-text type)
3400 (defun gnus-article-hidden-text-p (type)
3401 "Say whether the current buffer contains hidden text of type TYPE."
3402 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3404 (not (get-text-property pos 'invisible))
3405 (not (get-text-property pos 'dummy-invisible)))
3407 (text-property-any (1+ pos) (point-max) 'article-type type)))
3412 (defun gnus-article-show-hidden-text (type &optional dummy)
3413 "Show all hidden text of type TYPE.
3414 Originally it is hide instead of DUMMY."
3415 (let ((inhibit-read-only t)
3416 (inhibit-point-motion-hooks t))
3417 (gnus-remove-text-properties-when
3419 (point-min) (point-max)
3420 (cons 'article-type (cons type
3421 gnus-hidden-properties)))
3422 (gnus-delete-wash-type type)))
3424 (defconst article-time-units
3425 `((year . ,(* 365.25 24 60 60))
3426 (week . ,(* 7 24 60 60))
3427 (day . ,(* 24 60 60))
3431 "Mapping from time units to seconds.")
3433 (defun gnus-article-forward-header ()
3434 "Move point to the start of the next header.
3435 If the current header is a continuation header, this can be several
3440 (if (looking-at "[ \t]+[^ \t]")
3444 (defun article-date-ut (&optional type highlight)
3445 "Convert DATE date to universal time in the current article.
3446 If TYPE is `local', convert to local time; if it is `lapsed', output
3447 how much time has lapsed since DATE. For `lapsed', the value of
3448 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3449 should replace the \"Date:\" one, or should be added below it."
3450 (interactive (list 'ut t))
3451 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3452 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3456 (article-lapsed-timer
3460 (case-fold-search t)
3461 (inhibit-read-only t)
3462 (inhibit-point-motion-hooks t)
3463 pos date bface eface)
3467 (goto-char (point-min))
3468 (while (or (setq date (get-text-property (setq pos (point))
3470 (when (setq pos (next-single-property-change
3471 (point) 'original-date))
3472 (setq date (get-text-property pos 'original-date))
3475 pos (if (setq pos (text-property-any pos (point-max)
3476 'original-date nil))
3479 (if (or (bolp) (eobp))
3483 (goto-char (point-min))
3484 (when (re-search-forward tdate-regexp nil t)
3485 (setq bface (get-text-property (point-at-bol) 'face)
3486 eface (get-text-property (1- (point-at-eol)) 'face)))
3487 (goto-char (point-min))
3489 ;; Delete any old Date headers.
3490 (while (re-search-forward date-regexp nil t)
3492 (delete-region (point-at-bol) (progn
3493 (gnus-article-forward-header)
3495 (delete-region (point-at-bol) (progn
3496 (gnus-article-forward-header)
3499 (setq pos (point))))
3500 (when (and (not pos)
3501 (re-search-forward tdate-regexp nil t))
3503 (gnus-goto-char pos)
3504 (insert (article-make-date-line date (or type 'ut)))
3510 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3511 (put-text-property (match-beginning 1) (1+ (match-end 1))
3513 (put-text-property (match-beginning 2) (match-end 2)
3515 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3516 (goto-char (point-max))
3519 (defun article-make-date-line (date type)
3520 "Return a DATE line of TYPE."
3521 (unless (memq type '(local ut original user iso8601 lapsed english
3523 (error "Unknown conversion type: %s" type))
3525 (let ((time (date-to-time date)))
3527 ;; Convert to the local timezone.
3529 (concat "Date: " (message-make-date time)))
3530 ;; Convert to Universal Time.
3535 (let* ((e (parse-time-string date))
3536 (tm (apply 'encode-time e))
3538 (ls (- (cadr tm) (car (current-time-zone time)))))
3539 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3540 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3544 ;; Get the original date from the article.
3545 ((eq type 'original)
3546 (concat "Date: " (if (string-match "\n+$" date)
3547 (substring date 0 (match-beginning 0))
3549 ;; Let the user define the format.
3551 (let ((format (or (condition-case nil
3552 (with-current-buffer gnus-summary-buffer
3553 gnus-article-time-format)
3555 gnus-article-time-format)))
3556 (if (functionp format)
3557 (funcall format time)
3558 (concat "Date: " (format-time-string format time)))))
3561 (let ((tz (car (current-time-zone time))))
3564 (format-time-string "%Y%m%dT%H%M%S" time)
3565 (format "%s%02d%02d"
3566 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3567 (/ (% (abs tz) 3600) 60)))))
3568 ;; Do an X-Sent lapsed format.
3570 (concat "X-Sent: " (article-lapsed-string time)))
3571 ;; A combined date/lapsed format.
3572 ((eq type 'combined-lapsed)
3573 (concat (article-make-date-line date 'original)
3574 " (" (article-lapsed-string time 3) ")"))
3575 ;; Display the date in proper English
3577 (let ((dtime (decode-time time)))
3580 (number-to-string (nth 3 dtime))
3581 (let ((digit (% (nth 3 dtime) 10)))
3583 ((memq (nth 3 dtime) '(11 12 13)) "th")
3589 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3591 (number-to-string (nth 5 dtime))
3593 (format "%02d" (nth 2 dtime))
3595 (format "%02d" (nth 1 dtime)))))))
3597 (format "Date: %s (from Gnus)" date))))
3599 (defun article-lapsed-string (time &optional max-segments)
3600 ;; If the date is seriously mangled, the timezone functions are
3601 ;; liable to bug out, so we ignore all errors.
3602 (let* ((now (current-time))
3603 (real-time (subtract-time now time))
3604 (real-sec (and real-time
3605 (+ (* (float (car real-time)) 65536)
3607 (sec (and real-time (abs real-sec)))
3610 (unless max-segments
3611 (setq max-segments (length article-time-units)))
3619 ;; This is a bit convoluted, but basically we go
3620 ;; through the time units for years, weeks, etc,
3621 ;; and divide things to see whether that results
3622 ;; in positive answers.
3625 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3626 (>= segments max-segments))
3627 ;; The (remaining) seconds are too few to
3628 ;; be divided into this time unit.
3630 ;; It's big enough, so we output it.
3631 (setq sec (- sec (* num (cdr unit))))
3633 (concat (if prev ", " "") (int-to-string
3635 " " (symbol-name (car unit))
3636 (if (> num 1) "s" ""))
3638 segments (1+ segments)))))
3639 article-time-units "")
3640 ;; If dates are odd, then it might appear like the
3641 ;; article was sent in the future.
3644 " in the future"))))))
3646 (defun article-date-local (&optional highlight)
3647 "Convert the current article date to the local timezone."
3648 (interactive (list t))
3649 (article-date-ut 'local highlight))
3651 (defun article-date-english (&optional highlight)
3652 "Convert the current article date to something that is proper English."
3653 (interactive (list t))
3654 (article-date-ut 'english highlight))
3656 (defun article-date-original (&optional highlight)
3657 "Convert the current article date to what it was originally.
3658 This is only useful if you have used some other date conversion
3659 function and want to see what the date was before converting."
3660 (interactive (list t))
3661 (article-date-ut 'original highlight))
3663 (defun article-date-lapsed (&optional highlight)
3664 "Convert the current article date to time lapsed since it was sent."
3665 (interactive (list t))
3666 (article-date-ut 'lapsed highlight))
3668 (defun article-date-combined-lapsed (&optional highlight)
3669 "Convert the current article date to time lapsed since it was sent."
3670 (interactive (list t))
3671 (article-date-ut 'combined-lapsed highlight))
3673 (defun article-update-date-lapsed ()
3674 "Function to be run from a timer to update the lapsed time line."
3676 (let (deactivate-mark)
3681 (set-buffer (window-buffer w))
3682 (when (eq major-mode 'gnus-article-mode)
3683 (let ((mark (point-marker)))
3684 (goto-char (point-min))
3685 (when (re-search-forward "^X-Sent:\\|^Date:" nil t)
3686 (if gnus-treat-date-combined-lapsed
3687 (article-date-combined-lapsed t)
3688 (article-date-lapsed t)))
3689 (goto-char (marker-position mark))
3690 (move-marker mark nil))))
3693 (defun gnus-start-date-timer (&optional n)
3694 "Start a timer to update the X-Sent header in the article buffers.
3695 The numerical prefix says how frequently (in seconds) the function
3700 (gnus-stop-date-timer)
3701 (setq article-lapsed-timer
3702 (run-at-time 1 n 'article-update-date-lapsed)))
3704 (defun gnus-stop-date-timer ()
3705 "Stop the X-Sent timer."
3707 (when article-lapsed-timer
3708 (nnheader-cancel-timer article-lapsed-timer)
3709 (setq article-lapsed-timer nil)))
3711 (defun article-date-user (&optional highlight)
3712 "Convert the current article date to the user-defined format.
3713 This format is defined by the `gnus-article-time-format' variable."
3714 (interactive (list t))
3715 (article-date-ut 'user highlight))
3717 (defun article-date-iso8601 (&optional highlight)
3718 "Convert the current article date to ISO8601."
3719 (interactive (list t))
3720 (article-date-ut 'iso8601 highlight))
3722 (defmacro gnus-article-save-original-date (&rest forms)
3723 "Save the original date as a text property and evaluate FORMS."
3724 `(let* ((case-fold-search t)
3726 (goto-char (point-min))
3727 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3730 (date (when (and start
3731 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3733 (buffer-substring-no-properties start
3734 (match-beginning 0)))))
3735 (goto-char (point-max))
3736 (skip-chars-backward "\n")
3737 (put-text-property (point-min) (point) 'original-date date)
3739 (goto-char (point-max))
3740 (skip-chars-backward "\n")
3741 (put-text-property (point-min) (point) 'original-date date)))
3743 ;; (defun article-show-all ()
3744 ;; "Show all hidden text in the article buffer."
3747 ;; (let ((inhibit-read-only t))
3748 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3750 (defun article-remove-leading-whitespace ()
3751 "Remove excessive whitespace from all headers."
3755 (let ((inhibit-read-only t))
3756 (article-narrow-to-head)
3757 (goto-char (point-min))
3758 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3759 (delete-region (match-beginning 1) (match-end 1)))))))
3761 (defun article-emphasize (&optional arg)
3762 "Emphasize text according to `gnus-emphasis-alist'."
3763 (interactive (gnus-article-hidden-arg))
3764 (unless (gnus-article-check-hidden-text 'emphasis arg)
3768 (with-current-buffer gnus-summary-buffer
3769 gnus-article-emphasis-alist)
3771 gnus-emphasis-alist))
3772 (inhibit-read-only t)
3773 (props (append '(article-type emphasis)
3774 gnus-hidden-properties))
3775 regexp elem beg invisible visible face)
3778 (while (setq elem (pop alist))
3780 (setq regexp (car elem)
3781 invisible (nth 1 elem)
3782 visible (nth 2 elem)
3784 (while (re-search-forward regexp nil t)
3785 (when (and (match-beginning visible) (match-beginning invisible))
3786 (gnus-article-hide-text
3787 (match-beginning invisible) (match-end invisible) props)
3788 (gnus-article-unhide-text-type
3789 (match-beginning visible) (match-end visible) 'emphasis)
3790 (gnus-put-overlay-excluding-newlines
3791 (match-beginning visible) (match-end visible) 'face face)
3792 (gnus-add-wash-type 'emphasis)
3793 (goto-char (match-end invisible)))))))))
3795 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3796 "Setup newsgroup emphasis alist."
3797 (unless gnus-article-emphasis-alist
3798 (let ((name (and gnus-newsgroup-name
3799 (gnus-group-real-name gnus-newsgroup-name))))
3800 (make-local-variable 'gnus-article-emphasis-alist)
3801 (setq gnus-article-emphasis-alist
3803 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3804 (while (setq elem (pop alist))
3805 (when (and name (string-match (car elem) name))
3807 highlight (copy-sequence (cdr elem)))))
3809 (copy-sequence highlight-words)
3810 (if gnus-newsgroup-name
3811 (copy-sequence (gnus-group-find-parameter
3812 gnus-newsgroup-name 'highlight-words t)))
3813 gnus-emphasis-alist)))))
3815 (defvar gnus-summary-article-menu)
3816 (defvar gnus-summary-post-menu)
3818 ;;; Saving functions.
3820 (defun gnus-article-save (save-buffer file &optional num)
3821 "Save the currently selected article."
3822 (when (or (get gnus-default-article-saver :headers)
3823 (not gnus-save-all-headers))
3824 ;; Remove headers according to `gnus-saved-headers' or the value
3825 ;; of the `:headers' property that the saver function might have.
3826 (let ((gnus-visible-headers
3827 (or (symbol-value (get gnus-default-article-saver :headers))
3828 gnus-saved-headers gnus-visible-headers))
3829 ;; Ignore group parameter. See `article-hide-headers'.
3830 (gnus-summary-buffer nil))
3831 (with-current-buffer save-buffer
3832 (article-hide-headers 1 t))))
3833 (save-window-excursion
3834 (if (not gnus-default-article-saver)
3835 (error "No default saver is defined")
3836 ;; !!! Magic! The saving functions all save
3837 ;; `gnus-save-article-buffer' (or so they think), but we
3838 ;; bind that variable to our save-buffer.
3839 (set-buffer gnus-article-buffer)
3840 (let* ((gnus-save-article-buffer save-buffer)
3843 ((not gnus-prompt-before-saving) 'default)
3844 ((eq gnus-prompt-before-saving 'always) nil)
3846 (gnus-number-of-articles-to-be-saved
3847 (when (eq gnus-prompt-before-saving t)
3849 (set-buffer gnus-article-current-summary)
3850 (funcall gnus-default-article-saver filename)))))
3852 (defun gnus-read-save-file-name (prompt &optional filename
3853 function group headers variable
3856 (funcall function group headers (symbol-value variable)))
3861 ((eq filename 'default)
3867 (when (symbol-value dir-var)
3868 (setq default-name (expand-file-name
3869 (file-name-nondirectory default-name)
3870 (symbol-value dir-var))))
3871 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3874 (if (and gnus-number-of-articles-to-be-saved
3875 (> gnus-number-of-articles-to-be-saved 1))
3876 (format "these %d articles"
3877 gnus-number-of-articles-to-be-saved)
3880 ;; Let the split methods have their say.
3882 ;; No split name was found.
3885 (concat prompt " (default "
3886 (file-name-nondirectory default-name) "): ")
3887 (file-name-directory default-name)
3889 ;; A single group name is returned.
3890 ((stringp split-name)
3892 (funcall function split-name headers
3893 (symbol-value variable)))
3895 (concat prompt " (default "
3896 (file-name-nondirectory default-name) "): ")
3897 (file-name-directory default-name)
3899 ;; A single split name was found
3900 ((= 1 (length split-name))
3901 (let* ((name (expand-file-name
3903 gnus-article-save-directory))
3904 (dir (cond ((file-directory-p name)
3905 (file-name-as-directory name))
3906 ((file-exists-p name) name)
3907 (t gnus-article-save-directory))))
3909 (concat prompt " (default " name "): ")
3911 ;; A list of splits was found.
3913 (setq split-name (nreverse split-name))
3915 (let ((file-name-history
3916 (nconc split-name file-name-history)))
3920 (concat prompt " (`M-p' for defaults): ")
3921 gnus-article-save-directory
3923 gnus-article-save-directory)))
3924 (car (push result file-name-history)))))))
3925 ;; Create the directory.
3926 (gnus-make-directory (file-name-directory file))
3927 ;; If we have read a directory, we append the default file name.
3928 (when (file-directory-p file)
3929 (setq file (expand-file-name (file-name-nondirectory
3931 (file-name-as-directory file))))
3932 ;; Possibly translate some characters.
3933 (nnheader-translate-file-chars file))))))
3934 (gnus-make-directory (file-name-directory result))
3936 (set variable result))
3938 (set dir-var (file-name-directory result)))
3941 (defun gnus-article-archive-name (group)
3942 "Return the first instance of an \"Archive-name\" in the current buffer."
3943 (let ((case-fold-search t))
3944 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3945 (nnheader-concat gnus-article-save-directory
3946 (match-string 1)))))
3948 (defun gnus-article-nndoc-name (group)
3949 "If GROUP is an nndoc group, return the name of the parent group."
3950 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3951 (gnus-group-get-parameter group 'save-article-group)))
3953 (defun gnus-summary-save-in-rmail (&optional filename)
3954 "Append this article to Rmail file.
3955 Optional argument FILENAME specifies file name.
3956 Directory to save to is default to `gnus-article-save-directory'."
3957 (setq filename (gnus-read-save-file-name
3958 "Save %s in rmail file" filename
3959 gnus-rmail-save-name gnus-newsgroup-name
3960 gnus-current-headers 'gnus-newsgroup-last-rmail))
3961 (with-current-buffer gnus-save-article-buffer
3965 ;; Note that unlike gnus-summary-save-in-mail, there is no
3966 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3968 (gnus-output-to-rmail filename))))
3971 (defun gnus-summary-save-in-mail (&optional filename)
3972 "Append this article to Unix mail file.
3973 Optional argument FILENAME specifies file name.
3974 Directory to save to is default to `gnus-article-save-directory'."
3975 (setq filename (gnus-read-save-file-name
3976 "Save %s in Unix mail file" filename
3977 gnus-mail-save-name gnus-newsgroup-name
3978 gnus-current-headers 'gnus-newsgroup-last-mail))
3979 (with-current-buffer gnus-save-article-buffer
3983 (if (and (file-readable-p filename)
3984 (file-regular-p filename)
3985 (mail-file-babyl-p filename))
3986 (gnus-output-to-rmail filename)
3987 (gnus-output-to-mail filename)))))
3990 (put 'gnus-summary-save-in-file :decode t)
3991 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3992 (defun gnus-summary-save-in-file (&optional filename overwrite)
3993 "Append this article to file.
3994 Optional argument FILENAME specifies file name.
3995 Directory to save to is default to `gnus-article-save-directory'."
3996 (setq filename (gnus-read-save-file-name
3997 "Save %s in file" filename
3998 gnus-file-save-name gnus-newsgroup-name
3999 gnus-current-headers 'gnus-newsgroup-last-file))
4000 (with-current-buffer gnus-save-article-buffer
4004 (when (and overwrite
4005 (file-exists-p filename))
4006 (delete-file filename))
4007 (gnus-output-to-file filename))))
4010 (put 'gnus-summary-write-to-file :decode t)
4011 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4012 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4013 (defun gnus-summary-write-to-file (&optional filename)
4014 "Write this article to a file, overwriting it if the file exists.
4015 Optional argument FILENAME specifies file name.
4016 The directory to save in defaults to `gnus-article-save-directory'."
4017 (setq filename (gnus-read-save-file-name
4018 "Save %s in file" filename
4019 gnus-file-save-name gnus-newsgroup-name
4020 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4021 (gnus-summary-save-in-file filename t))
4023 (put 'gnus-summary-save-body-in-file :decode t)
4024 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4025 "Append this article body to a file.
4026 Optional argument FILENAME specifies file name.
4027 The directory to save in defaults to `gnus-article-save-directory'."
4028 (setq filename (gnus-read-save-file-name
4029 "Save %s body in file" filename
4030 gnus-file-save-name gnus-newsgroup-name
4031 gnus-current-headers 'gnus-newsgroup-last-file))
4032 (with-current-buffer gnus-save-article-buffer
4036 (when (article-goto-body)
4037 (narrow-to-region (point) (point-max)))
4038 (when (and overwrite
4039 (file-exists-p filename))
4040 (delete-file filename))
4041 (gnus-output-to-file filename))))
4044 (put 'gnus-summary-write-body-to-file :decode t)
4045 (put 'gnus-summary-write-body-to-file
4046 :function 'gnus-summary-save-body-in-file)
4047 (defun gnus-summary-write-body-to-file (&optional filename)
4048 "Write this article body to a file, overwriting it if the file exists.
4049 Optional argument FILENAME specifies file name.
4050 The directory to save in defaults to `gnus-article-save-directory'."
4051 (setq filename (gnus-read-save-file-name
4052 "Save %s body in file" filename
4053 gnus-file-save-name gnus-newsgroup-name
4054 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4055 (gnus-summary-save-body-in-file filename t))
4057 (put 'gnus-summary-save-in-pipe :decode t)
4058 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4059 (defun gnus-summary-save-in-pipe (&optional command raw)
4060 "Pipe this article to subprocess COMMAND.
4061 Valid values for COMMAND include:
4063 The executable command name and possibly arguments.
4065 You will be prompted for the command in the minibuffer.
4066 the symbol `default'
4067 It will be replaced with the command which the variable
4068 `gnus-summary-pipe-output-default-command' holds or the command
4069 last used for saving.
4070 Non-nil value for RAW overrides `:decode' and `:headers' properties
4071 and the raw article including all headers will be piped."
4072 (let ((article (gnus-summary-article-number))
4074 (get 'gnus-summary-save-in-pipe :decode)))
4075 save-buffer default)
4077 (if (vectorp (gnus-summary-article-header article))
4078 (save-current-buffer
4079 (gnus-summary-select-article decode decode nil article)
4080 (insert-buffer-substring
4084 gnus-original-article-buffer)
4086 (nnheader-set-temp-buffer " *Gnus Save*"))))
4087 ;; Remove unwanted headers.
4088 (when (and (not raw)
4089 (or (get 'gnus-summary-save-in-pipe :headers)
4090 (not gnus-save-all-headers)))
4091 (let ((gnus-visible-headers
4092 (or (symbol-value (get 'gnus-summary-save-in-pipe
4094 gnus-saved-headers gnus-visible-headers))
4095 (gnus-summary-buffer nil))
4096 (article-hide-headers 1 t))))
4097 (error "%d is not a real article" article))
4098 (error "No article to pipe"))
4099 (setq default (or gnus-summary-pipe-output-default-command
4100 gnus-last-shell-command))
4101 (unless (stringp command)
4103 (if (and (eq command 'default) default)
4105 (gnus-read-shell-command "Shell command on this article: "
4107 (when (string-equal command "")
4109 (setq command default)
4110 (error "A command is required")))
4111 (with-current-buffer save-buffer
4114 (shell-command-on-region (point-min) (point-max) command nil)))
4115 (gnus-kill-buffer save-buffer))
4116 (setq gnus-summary-pipe-output-default-command command))
4118 (defun gnus-summary-pipe-to-muttprint (&optional command)
4119 "Pipe this article to muttprint."
4120 (unless (stringp command)
4121 (setq command (read-string
4122 "Print using command: " gnus-summary-muttprint-program
4123 nil gnus-summary-muttprint-program)))
4124 (let ((gnus-summary-pipe-output-default-command
4125 gnus-summary-pipe-output-default-command))
4126 (gnus-summary-save-in-pipe command))
4127 (setq gnus-summary-muttprint-program command))
4129 ;;; Article file names when saving.
4131 (defun gnus-capitalize-newsgroup (newsgroup)
4132 "Capitalize NEWSGROUP name."
4133 (when (not (zerop (length newsgroup)))
4134 (concat (char-to-string (upcase (aref newsgroup 0)))
4135 (substring newsgroup 1))))
4137 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4138 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4139 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4140 Otherwise, it is like ~/News/news/group/num."
4143 (concat (if (gnus-use-long-file-name 'not-save)
4144 (gnus-capitalize-newsgroup newsgroup)
4145 (gnus-newsgroup-directory-form newsgroup))
4146 "/" (int-to-string (mail-header-number headers)))
4147 gnus-article-save-directory)))
4149 (string-equal (file-name-directory default)
4150 (file-name-directory last-file))
4151 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4153 (or last-file default))))
4155 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4156 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4157 If variable `gnus-use-long-file-name' is non-nil, it is
4158 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4161 (concat (if (gnus-use-long-file-name 'not-save)
4163 (gnus-newsgroup-directory-form newsgroup))
4164 "/" (int-to-string (mail-header-number headers)))
4165 gnus-article-save-directory)))
4167 (string-equal (file-name-directory default)
4168 (file-name-directory last-file))
4169 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4171 (or last-file default))))
4173 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4174 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4175 If variable `gnus-use-long-file-name' is non-nil, it is
4176 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4179 (if (gnus-use-long-file-name 'not-save)
4182 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4184 gnus-article-save-directory)))
4186 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4187 "Generate file name from sender."
4188 (let ((from (mail-header-from headers)))
4190 (if (and from (string-match "\\([^ <]+\\)@" from))
4191 (match-string 1 from)
4193 gnus-article-save-directory)))
4195 (defun article-verify-x-pgp-sig ()
4197 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4199 (if (gnus-buffer-live-p gnus-original-article-buffer)
4200 (let ((sig (with-current-buffer gnus-original-article-buffer
4201 (gnus-fetch-field "X-PGP-Sig")))
4205 (mml2015-clear-verify-function))
4207 (insert-buffer-substring gnus-original-article-buffer)
4208 (setq items (split-string sig))
4209 (message-narrow-to-head)
4210 (let ((inhibit-point-motion-hooks t)
4211 (case-fold-search t))
4212 ;; Don't verify multiple headers.
4213 (setq headers (mapconcat (lambda (header)
4215 (mail-fetch-field header)
4217 (split-string (nth 1 items) ",") "")))
4218 (delete-region (point-min) (point-max))
4219 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4220 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4225 (if (looking-at "^-")
4228 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4229 (insert "Version: " (car items) "\n\n")
4230 (insert (mapconcat 'identity (cddr items) "\n"))
4231 (insert "\n-----END PGP SIGNATURE-----\n")
4232 (let ((mm-security-handle (list (format "multipart/signed"))))
4233 (mml2015-clean-buffer)
4234 (let ((coding-system-for-write (or gnus-newsgroup-charset
4236 (funcall (mml2015-clear-verify-function)))
4238 (or (mm-handle-multipart-ctl-parameter
4239 mm-security-handle 'gnus-details)
4240 (mm-handle-multipart-ctl-parameter
4241 mm-security-handle 'gnus-info)))))
4243 (let ((inhibit-read-only t) bface eface)
4245 (message-narrow-to-head)
4246 (goto-char (point-max))
4248 (setq bface (get-text-property (point-at-bol) 'face)
4249 eface (get-text-property (1- (point-at-eol)) 'face))
4250 (message-remove-header "X-Gnus-PGP-Verify")
4251 (if (re-search-forward "^X-PGP-Sig:" nil t)
4253 (goto-char (point-max)))
4254 (narrow-to-region (point) (point))
4255 (insert "X-Gnus-PGP-Verify: " info "\n")
4256 (goto-char (point-min))
4259 (if (not (looking-at "^[ \t]"))
4263 (goto-char (point-min))
4264 (when (looking-at "\\([^:]+\\): *")
4265 (put-text-property (match-beginning 1) (1+ (match-end 1))
4267 (put-text-property (match-end 0) (point-max)
4268 'face eface)))))))))
4270 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4272 (defun article-verify-cancel-lock ()
4273 "Verify Cancel-Lock header."
4275 (if (gnus-buffer-live-p gnus-original-article-buffer)
4276 (canlock-verify gnus-original-article-buffer)))
4283 (setq afunc (car func)
4286 gfunc (intern (format "gnus-%s" func))))
4288 (when (fboundp afunc)
4289 `(lambda (&optional interactive &rest args)
4290 ,(documentation afunc t)
4291 (interactive (list t))
4292 (with-current-buffer gnus-article-buffer
4294 (call-interactively ',afunc)
4295 (apply ',afunc args))))))))
4296 '(article-hide-headers
4297 article-verify-x-pgp-sig
4298 article-verify-cancel-lock
4299 article-hide-boring-headers
4300 article-treat-overstrike
4301 article-treat-ansi-sequences
4302 article-fill-long-lines
4303 article-capitalize-sentences
4305 article-remove-leading-whitespace
4306 article-display-x-face
4307 article-display-face
4308 article-de-quoted-unreadable
4309 article-de-base64-unreadable
4312 article-unsplit-urls
4313 article-hide-list-identifiers
4314 article-strip-banner
4317 article-hide-signature
4318 article-strip-headers-in-body
4319 article-remove-trailing-blank-lines
4320 article-strip-leading-blank-lines
4321 article-strip-multiple-blank-lines
4322 article-strip-leading-space
4323 article-strip-trailing-space
4324 article-strip-blank-lines
4325 article-strip-all-blank-lines
4327 article-date-english
4328 article-date-iso8601
4329 article-date-original
4331 article-decode-mime-words
4332 article-decode-charset
4333 article-decode-encoded-words
4336 article-date-combined-lapsed
4338 article-treat-dumbquotes
4339 article-treat-non-ascii
4340 article-normalize-headers
4341 ;;(article-show-all . gnus-article-show-all-headers)
4345 ;;; Gnus article mode
4348 (put 'gnus-article-mode 'mode-class 'special)
4350 (set-keymap-parent gnus-article-mode-map widget-keymap)
4352 (gnus-define-keys gnus-article-mode-map
4353 " " gnus-article-goto-next-page
4354 "\177" gnus-article-goto-prev-page
4355 [delete] gnus-article-goto-prev-page
4356 [backspace] gnus-article-goto-prev-page
4357 "\C-c^" gnus-article-refer-article
4358 "h" gnus-article-show-summary
4359 "s" gnus-article-show-summary
4360 "\C-c\C-m" gnus-article-mail
4361 "?" gnus-article-describe-briefly
4362 "<" beginning-of-buffer
4364 "\C-c\C-i" gnus-info-find-node
4366 "R" gnus-article-reply-with-original
4367 "F" gnus-article-followup-with-original
4368 "\C-hk" gnus-article-describe-key
4369 "\C-hc" gnus-article-describe-key-briefly
4370 "\C-hb" gnus-article-describe-bindings
4372 "e" gnus-article-read-summary-keys
4373 "\C-d" gnus-article-read-summary-keys
4374 "\M-*" gnus-article-read-summary-keys
4375 "\M-#" gnus-article-read-summary-keys
4376 "\M-^" gnus-article-read-summary-keys
4377 "\M-g" gnus-article-read-summary-keys)
4379 (substitute-key-definition
4380 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4382 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4383 "W" gnus-article-wide-reply-with-original)
4384 (if (featurep 'xemacs)
4385 (set-keymap-default-binding gnus-article-send-map
4386 'gnus-article-read-summary-send-keys)
4387 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4389 (defun gnus-article-make-menu-bar ()
4390 (unless (boundp 'gnus-article-commands-menu)
4391 (gnus-summary-make-menu-bar))
4392 (unless (boundp 'gnus-article-article-menu)
4394 gnus-article-article-menu gnus-article-mode-map ""
4396 ["Scroll forwards" gnus-article-goto-next-page t]
4397 ["Scroll backwards" gnus-article-goto-prev-page t]
4398 ["Show summary" gnus-article-show-summary t]
4399 ["Fetch Message-ID at point" gnus-article-refer-article t]
4400 ["Mail to address at point" gnus-article-mail t]
4401 ["Send a bug report" gnus-bug t]))
4404 gnus-article-treatment-menu gnus-article-mode-map ""
4405 ;; Fixme: this should use :active (and maybe :visible).
4407 ["Hide headers" gnus-article-hide-headers t]
4408 ["Hide signature" gnus-article-hide-signature t]
4409 ["Hide citation" gnus-article-hide-citation t]
4410 ["Treat overstrike" gnus-article-treat-overstrike t]
4411 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4412 ["Remove carriage return" gnus-article-remove-cr t]
4413 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4414 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4415 ["Remove base64" gnus-article-de-base64-unreadable t]
4416 ["Treat html" gnus-article-wash-html t]
4417 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4418 ["Decode HZ" gnus-article-decode-HZ t]))
4420 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4422 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4424 (gnus-run-hooks 'gnus-article-menu-hook)))
4426 (defvar bookmark-make-record-function)
4428 (defun gnus-article-mode ()
4429 "Major mode for displaying an article.
4431 All normal editing commands are switched off.
4433 The following commands are available in addition to all summary mode
4435 \\<gnus-article-mode-map>
4436 \\[gnus-article-next-page]\t Scroll the article one page forwards
4437 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4438 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4439 \\[gnus-article-show-summary]\t Display the summary buffer
4440 \\[gnus-article-mail]\t Send a reply to the address near point
4441 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4442 \\[gnus-info-find-node]\t Go to the Gnus info node"
4444 (kill-all-local-variables)
4445 (gnus-simplify-mode-line)
4446 (setq mode-name "Article")
4447 (setq major-mode 'gnus-article-mode)
4448 (make-local-variable 'minor-mode-alist)
4449 (use-local-map gnus-article-mode-map)
4450 (when (gnus-visual-p 'article-menu 'menu)
4451 (gnus-article-make-menu-bar)
4452 (when gnus-summary-tool-bar-map
4453 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4454 (gnus-update-format-specifications nil 'article-mode)
4455 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4456 (set (make-local-variable 'gnus-page-broken) nil)
4457 (make-local-variable 'gnus-article-current-summary)
4458 (make-local-variable 'gnus-article-mime-handles)
4459 (make-local-variable 'gnus-article-decoded-p)
4460 (make-local-variable 'gnus-article-mime-handle-alist)
4461 (make-local-variable 'gnus-article-wash-types)
4462 (make-local-variable 'gnus-article-image-alist)
4463 (make-local-variable 'gnus-article-charset)
4464 (make-local-variable 'gnus-article-ignored-charsets)
4465 (set (make-local-variable 'bookmark-make-record-function)
4466 'gnus-summary-bookmark-make-record)
4467 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4469 (set (make-local-variable 'nobreak-char-display) nil)
4470 (setq cursor-in-non-selected-windows nil)
4471 (gnus-set-default-directory)
4472 (buffer-disable-undo)
4473 (setq buffer-read-only t
4474 show-trailing-whitespace nil)
4475 (set-syntax-table gnus-article-mode-syntax-table)
4476 (mm-enable-multibyte)
4477 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4479 (defun gnus-article-setup-buffer ()
4480 "Initialize the article buffer."
4481 (let* ((name (if gnus-single-article-buffer "*Article*"
4482 (concat "*Article " gnus-newsgroup-name "*")))
4484 (progn (string-match "\\*Article" name)
4485 (concat " *Original Article"
4486 (substring name (match-end 0))))))
4487 (setq gnus-article-buffer name)
4488 (setq gnus-original-article-buffer original)
4489 (setq gnus-article-mime-handle-alist nil)
4490 (with-current-buffer gnus-summary-buffer
4491 ;; This might be a variable local to the summary buffer.
4492 (unless gnus-single-article-buffer
4493 (setq gnus-article-buffer name)
4494 (setq gnus-original-article-buffer original)
4495 (gnus-set-global-variables)))
4496 (gnus-article-setup-highlight-words)
4497 ;; Init original article buffer.
4498 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4499 (mm-enable-multibyte)
4500 (setq major-mode 'gnus-original-article-mode)
4501 (make-local-variable 'gnus-original-article))
4502 (if (and (get-buffer name)
4503 (with-current-buffer name
4504 (if gnus-article-edit-mode
4505 (if (y-or-n-p "Article mode edit in progress; discard? ")
4507 (set-buffer-modified-p nil)
4508 (gnus-kill-buffer name)
4511 (error "Action aborted"))
4513 (with-current-buffer name
4514 (set (make-local-variable 'gnus-article-edit-mode) nil)
4515 (when gnus-article-mime-handles
4516 (mm-destroy-parts gnus-article-mime-handles)
4517 (setq gnus-article-mime-handles nil))
4518 ;; Set it to nil in article-buffer!
4519 (setq gnus-article-mime-handle-alist nil)
4520 (buffer-disable-undo)
4521 (setq buffer-read-only t)
4522 (unless (eq major-mode 'gnus-article-mode)
4523 (gnus-article-mode))
4524 (setq truncate-lines gnus-article-truncate-lines)
4526 (with-current-buffer (gnus-get-buffer-create name)
4528 (setq truncate-lines gnus-article-truncate-lines)
4529 (make-local-variable 'gnus-summary-buffer)
4530 (setq gnus-summary-buffer
4531 (gnus-summary-buffer-name gnus-newsgroup-name))
4532 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4533 (when (and gnus-article-update-lapsed-header
4534 (not article-lapsed-timer))
4535 (gnus-start-date-timer gnus-article-update-lapsed-header))
4536 (current-buffer)))))
4538 ;; Set article window start at LINE, where LINE is the number of lines
4539 ;; from the head of the article.
4540 (defun gnus-article-set-window-start (&optional line)
4541 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4542 (when article-window
4545 (with-current-buffer gnus-article-buffer
4546 (goto-char (point-min))
4549 (gnus-message 6 "Moved to bookmark")
4550 (search-forward "\n\n" nil t)
4554 (defun gnus-article-prepare (article &optional all-headers header)
4555 "Prepare ARTICLE in article mode buffer.
4556 ARTICLE should either be an article number or a Message-ID.
4557 If ARTICLE is an id, HEADER should be the article headers.
4558 If ALL-HEADERS is non-nil, no headers are hidden."
4560 ;; Make sure we start in a summary buffer.
4561 (unless (eq major-mode 'gnus-summary-mode)
4562 (set-buffer gnus-summary-buffer))
4563 (setq gnus-summary-buffer (current-buffer))
4564 (let* ((gnus-article (if header (mail-header-number header) article))
4565 (summary-buffer (current-buffer))
4566 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4567 (group gnus-newsgroup-name)
4570 (gnus-article-setup-buffer)
4571 (set-buffer gnus-article-buffer)
4572 ;; Deactivate active regions.
4573 (when (and (boundp 'transient-mark-mode)
4574 transient-mark-mode)
4575 (setq mark-active nil))
4576 (if (not (setq result (let ((inhibit-read-only t))
4577 (gnus-request-article-this-buffer
4579 ;; There is no such article.
4581 (when (and (numberp article)
4582 (not (memq article gnus-newsgroup-sparse)))
4583 (setq gnus-article-current
4584 (cons gnus-newsgroup-name article))
4585 (set-buffer gnus-summary-buffer)
4586 (setq gnus-current-article article)
4587 (if (and (memq article gnus-newsgroup-undownloaded)
4588 (not (gnus-online (gnus-find-method-for-group
4589 gnus-newsgroup-name))))
4591 (gnus-summary-set-agent-mark article)
4592 (message "Message marked for downloading"))
4593 (gnus-summary-mark-article article gnus-canceled-mark)
4594 (unless (memq article gnus-newsgroup-sparse)
4595 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4596 (if (or (eq result 'pseudo)
4597 (eq result 'nneething))
4599 (with-current-buffer summary-buffer
4600 (push article gnus-newsgroup-history)
4601 (setq gnus-last-article gnus-current-article
4602 gnus-current-article 0
4603 gnus-current-headers nil
4604 gnus-article-current nil)
4605 (if (eq result 'nneething)
4606 (gnus-configure-windows 'summary)
4607 (gnus-configure-windows 'article))
4608 (gnus-set-global-variables))
4609 (let ((gnus-article-mime-handle-alist-1
4610 gnus-article-mime-handle-alist))
4611 (gnus-set-mode-line 'article)))
4612 ;; The result from the `request' was an actual article -
4613 ;; or at least some text that is now displayed in the
4615 (when (and (numberp article)
4616 (not (eq article gnus-current-article)))
4617 ;; Seems like a new article has been selected.
4618 ;; `gnus-current-article' must be an article number.
4619 (with-current-buffer summary-buffer
4620 (push article gnus-newsgroup-history)
4621 (setq gnus-last-article gnus-current-article
4622 gnus-current-article article
4623 gnus-current-headers
4624 (gnus-summary-article-header gnus-current-article)
4625 gnus-article-current
4626 (cons gnus-newsgroup-name gnus-current-article))
4627 (unless (vectorp gnus-current-headers)
4628 (setq gnus-current-headers nil))
4629 (gnus-summary-goto-subject gnus-current-article)
4630 (when (gnus-summary-show-thread)
4631 ;; If the summary buffer really was folded, the
4632 ;; previous goto may not actually have gone to
4633 ;; the right article, but the thread root instead.
4635 (gnus-summary-goto-subject gnus-current-article))
4636 (gnus-run-hooks 'gnus-mark-article-hook)
4637 (gnus-set-mode-line 'summary)
4638 (when (gnus-visual-p 'article-highlight 'highlight)
4639 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4640 ;; Set the global newsgroup variables here.
4641 (gnus-set-global-variables)
4642 (setq gnus-have-all-headers
4643 (or all-headers gnus-show-all-headers))))
4645 (gnus-configure-windows 'article))
4646 (when (or (numberp article)
4648 (gnus-article-prepare-display)
4650 (goto-char (point-min))
4651 (when gnus-break-pages
4652 (gnus-narrow-to-page)))
4653 (let ((gnus-article-mime-handle-alist-1
4654 gnus-article-mime-handle-alist))
4655 (gnus-set-mode-line 'article))
4659 (set-window-point (get-buffer-window (current-buffer)) (point))
4660 (gnus-configure-windows 'article)
4664 (defun gnus-article-prepare-display ()
4665 "Make the current buffer look like a nice article."
4666 ;; Hooks for getting information from the article.
4667 ;; This hook must be called before being narrowed.
4668 (let ((gnus-article-buffer (current-buffer))
4670 (inhibit-read-only t))
4671 (unless (eq major-mode 'gnus-article-mode)
4672 (gnus-article-mode))
4673 (setq buffer-read-only nil
4674 gnus-article-wash-types nil
4675 gnus-article-image-alist nil)
4676 (gnus-run-hooks 'gnus-tmp-internal-hook)
4677 (when gnus-display-mime-function
4678 (funcall gnus-display-mime-function))
4679 (gnus-run-hooks 'gnus-article-prepare-hook)))
4682 ;;; Gnus Sticky Article Mode
4685 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4686 "Mode for sticky articles."
4687 ;; Release bindings that won't work.
4688 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4689 gnus-sticky-article-mode-map)
4690 (substitute-key-definition 'gnus-article-refer-article 'undefined
4691 gnus-sticky-article-mode-map)
4692 (dolist (k '("e" "h" "s" "F" "R"))
4693 (define-key gnus-sticky-article-mode-map k nil))
4694 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4695 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4696 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4697 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4699 (defun gnus-sticky-article (arg)
4700 "Make the current article sticky.
4701 If a prefix ARG is given, ask for a name for this sticky article buffer."
4703 (gnus-summary-show-thread)
4704 (gnus-summary-select-article nil nil 'pseudo)
4705 (let (new-art-buf-name)
4706 (gnus-eval-in-buffer-window gnus-article-buffer
4707 (setq new-art-buf-name
4711 (read-from-minibuffer "Sticky article buffer name: ")
4712 (gnus-with-article-headers
4713 (gnus-article-goto-header "subject")
4714 (setq new-art-buf-name
4715 (buffer-substring-no-properties
4716 (line-beginning-position) (line-end-position)))
4717 (goto-char (point-min))
4718 (gnus-article-goto-header "from")
4719 (setq new-art-buf-name
4721 new-art-buf-name ", "
4722 (buffer-substring-no-properties
4723 (line-beginning-position) (line-end-position))))
4724 (goto-char (point-min))
4725 (gnus-article-goto-header "date")
4726 (setq new-art-buf-name
4728 new-art-buf-name ", "
4729 (buffer-substring-no-properties
4730 (line-beginning-position) (line-end-position))))))
4732 (if (and (gnus-buffer-live-p new-art-buf-name)
4733 (with-current-buffer new-art-buf-name
4734 (eq major-mode 'gnus-sticky-article-mode)))
4735 (switch-to-buffer new-art-buf-name)
4736 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4737 (gnus-sticky-article-mode))
4738 (setq gnus-article-buffer new-art-buf-name))
4739 (gnus-summary-recenter)
4740 (gnus-summary-position-point))
4742 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4743 "Kill the given sticky article BUFFER.
4744 If none is given, assume the current buffer and kill it if it has
4745 `gnus-sticky-article-mode'."
4748 (setq buffer (current-buffer)))
4749 (with-current-buffer buffer
4750 (when (eq major-mode 'gnus-sticky-article-mode)
4751 (gnus-kill-buffer buffer))))
4753 (defun gnus-kill-sticky-article-buffers (arg)
4754 "Kill all sticky article buffers.
4755 If a prefix ARG is given, ask for confirmation."
4757 (dolist (buf (gnus-buffers))
4758 (with-current-buffer buf
4759 (when (eq major-mode 'gnus-sticky-article-mode)
4761 (gnus-kill-buffer buf)
4762 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4763 (gnus-kill-buffer buf)))))))
4766 ;;; Gnus MIME viewing functions
4769 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4770 "Format of the MIME buttons.
4772 Valid specifiers include:
4774 %T MIME type, along with additional info
4775 %n The `name' parameter
4776 %d The description, if any
4777 %l The length of the encoded part
4778 %p The part identifier number
4779 %e Dots if the part isn't displayed
4781 General format specifiers can also be used. See Info node
4782 `(gnus)Formatting Variables'.")
4784 (defvar gnus-mime-button-line-format-alist
4785 '((?t gnus-tmp-type ?s)
4786 (?T gnus-tmp-type-long ?s)
4787 (?n gnus-tmp-name ?s)
4788 (?d gnus-tmp-description ?s)
4790 (?l gnus-tmp-length ?d)
4791 (?e gnus-tmp-dots ?s)))
4793 (defvar gnus-mime-button-commands
4794 '((gnus-article-press-button "\r" "Toggle Display")
4795 (gnus-mime-view-part "v" "View Interactively...")
4796 (gnus-mime-view-part-as-type "t" "View As Type...")
4797 (gnus-mime-view-part-as-charset "C" "View As charset...")
4798 (gnus-mime-save-part "o" "Save...")
4799 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4800 (gnus-mime-replace-part "r" "Replace part")
4801 (gnus-mime-delete-part "d" "Delete part")
4802 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4803 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4804 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4805 (gnus-mime-view-part-externally "e" "View Externally")
4806 (gnus-mime-print-part "p" "Print")
4807 (gnus-mime-pipe-part "|" "Pipe To Command...")
4808 (gnus-mime-action-on-part "." "Take action on the part...")))
4810 (defun gnus-article-mime-part-status ()
4811 (if gnus-article-mime-handle-alist-1
4812 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4814 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4817 (defvar gnus-mime-button-map
4818 (let ((map (make-sparse-keymap)))
4819 (define-key map gnus-mouse-2 'gnus-article-push-button)
4820 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4821 (dolist (c gnus-mime-button-commands)
4822 (define-key map (cadr c) (car c)))
4826 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4828 ,@(mapcar (lambda (c)
4829 (vector (caddr c) (car c) :active t))
4830 gnus-mime-button-commands)))
4832 (defvar gnus-url-button-commands
4833 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4835 (defvar gnus-url-button-map
4836 (let ((map (make-sparse-keymap)))
4837 (dolist (c gnus-url-button-commands)
4838 (define-key map (cadr c) (car c)))
4842 gnus-url-button-menu gnus-url-button-map "URL button menu."
4844 ,@(mapcar (lambda (c)
4845 (vector (caddr c) (car c) :active t))
4846 gnus-url-button-commands)))
4848 (defmacro gnus-bind-safe-url-regexp (&rest body)
4849 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4850 `(let ((mm-w3m-safe-url-regexp
4851 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4853 gnus-article-current-summary))
4854 (with-current-buffer gnus-article-current-summary
4855 gnus-newsgroup-name)
4856 gnus-newsgroup-name)))
4857 (if (cond ((not group)
4858 ;; Maybe we're in a mml-preview buffer
4859 ;; and no group is selected.
4861 ((stringp gnus-safe-html-newsgroups)
4862 (string-match gnus-safe-html-newsgroups group))
4863 ((consp gnus-safe-html-newsgroups)
4864 (member group gnus-safe-html-newsgroups)))
4866 mm-w3m-safe-url-regexp))))
4869 (defun gnus-mime-button-menu (event prefix)
4870 "Construct a context-sensitive menu of MIME commands."
4871 (interactive "e\nP")
4872 (save-window-excursion
4873 (let ((pos (event-start event)))
4874 (select-window (posn-window pos))
4875 (goto-char (posn-point pos))
4876 (gnus-article-check-buffer)
4877 (popup-menu gnus-mime-button-menu nil prefix))))
4879 (defun gnus-mime-view-all-parts (&optional handles)
4880 "View all the MIME parts."
4882 (with-current-buffer gnus-article-buffer
4883 (let ((handles (or handles gnus-article-mime-handles))
4884 (mail-parse-charset gnus-newsgroup-charset)
4885 (mail-parse-ignored-charsets
4886 (with-current-buffer gnus-summary-buffer
4887 gnus-newsgroup-ignored-charsets)))
4889 (mm-remove-parts handles)
4890 (goto-char (point-min))
4891 (or (search-forward "\n\n") (goto-char (point-max)))
4892 (let ((inhibit-read-only t))
4893 (delete-region (point) (point-max))
4894 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4896 (defun gnus-article-jump-to-part (n)
4897 "Jump to MIME part N."
4899 (let ((parts (with-current-buffer gnus-article-buffer
4900 (length gnus-article-mime-handle-alist))))
4902 (error "No such part"))
4903 (pop-to-buffer gnus-article-buffer)
4904 ;; FIXME: why is it necessary?
4907 (setq n (if (= parts 1)
4909 (read-number (format "Jump to part (1..%s): " parts)))))
4910 (unless (and (integerp n) (<= n parts) (>= n 1))
4913 (gnus-message 7 "Invalid part `%s', using %s instead."
4916 (gnus-message 9 "Jumping to part %s." n)
4917 (cond ((>= gnus-auto-select-part 1)
4918 (while (and (<= n parts)
4919 (not (gnus-article-goto-part n)))
4921 ((< gnus-auto-select-part 0)
4922 (while (and (>= n 1)
4923 (not (gnus-article-goto-part n)))
4926 (gnus-article-goto-part n)))))
4928 (defvar gnus-mime-buttonized-part-id nil
4929 "ID of a mime part that should be buttonized.
4930 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4933 (defsubst gnus-article-edit-part (handles &optional current-id)
4934 "Edit an article in order to delete a mime part.
4935 This function is exclusively used by `gnus-mime-save-part-and-strip'
4936 and `gnus-mime-delete-part', and not provided at run-time normally."
4937 (gnus-article-edit-article
4939 (buffer-disable-undo)
4941 (let ((mail-parse-charset (or gnus-article-charset
4942 ',gnus-newsgroup-charset))
4943 (mail-parse-ignored-charsets
4944 (or gnus-article-ignored-charsets
4945 ',gnus-newsgroup-ignored-charsets))
4946 (mbl mml-buffer-list))
4947 (setq mml-buffer-list nil)
4948 (insert-buffer-substring gnus-original-article-buffer)
4949 (mime-to-mml ',handles)
4950 (setq gnus-article-mime-handles nil)
4951 (let ((mbl1 mml-buffer-list))
4952 (setq mml-buffer-list mbl)
4953 (set (make-local-variable 'mml-buffer-list) mbl1))
4954 (gnus-make-local-hook 'kill-buffer-hook)
4955 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4956 `(lambda (no-highlight)
4957 (let ((mail-parse-charset (or gnus-article-charset
4958 ',gnus-newsgroup-charset))
4959 (message-options message-options)
4960 (message-options-set-recipient)
4961 (mail-parse-ignored-charsets
4962 (or gnus-article-ignored-charsets
4963 ',gnus-newsgroup-ignored-charsets)))
4965 (mml-destroy-buffers)
4966 (remove-hook 'kill-buffer-hook
4967 'mml-destroy-buffers t)
4968 (kill-local-variable 'mml-buffer-list))
4969 (gnus-summary-edit-article-done
4970 ,(or (mail-header-references gnus-current-headers) "")
4971 ,(gnus-group-read-only-p)
4972 ,gnus-summary-buffer no-highlight))
4974 ;; Force buttonizing this part.
4975 (let ((gnus-mime-buttonized-part-id current-id))
4976 (gnus-article-edit-done))
4977 (gnus-configure-windows 'article)
4978 (when (and current-id (integerp gnus-auto-select-part))
4979 (gnus-article-jump-to-part
4980 (min (max (+ current-id gnus-auto-select-part) 1)
4981 (with-current-buffer gnus-article-buffer
4982 (length gnus-article-mime-handle-alist)))))))
4984 (defun gnus-mime-replace-part (file)
4985 "Replace MIME part under point with an external body."
4986 ;; Useful if file has already been saved to disk
4989 (read-file-name "Replace MIME part with file: "
4990 (or mm-default-directory default-directory)
4992 (gnus-mime-save-part-and-strip file))
4994 (defun gnus-mime-save-part-and-strip (&optional file)
4995 "Save the MIME part under point then replace it with an external body.
4996 If FILE is given, use it for the external part."
4998 (gnus-article-check-buffer)
4999 (when (gnus-group-read-only-p)
5000 (error "The current group does not support deleting of parts"))
5001 (when (mm-complicated-handles gnus-article-mime-handles)
5003 The current article has a complicated MIME structure, giving up..."))
5004 (let* ((data (get-text-property (point) 'gnus-data))
5005 (id (get-text-property (point) 'gnus-part))
5007 (handles gnus-article-mime-handles))
5010 (and data (mm-save-part data "Delete MIME part and save to: "))))
5012 (with-current-buffer (mm-handle-buffer data)
5014 (insert "Content-Type: " (mm-handle-media-type data))
5015 (mml-insert-parameter-string (cdr (mm-handle-type data))
5017 ;; Add a filename for the sake of saving the part again.
5018 (mml-insert-parameter
5019 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5021 (insert "Content-ID: " (message-make-message-id) "\n")
5022 (insert "Content-Transfer-Encoding: binary\n")
5025 (cdr (mm-make-handle nil
5026 `("message/external-body"
5027 (access-type . "LOCAL-FILE")
5029 ;; (set-buffer gnus-summary-buffer)
5030 (gnus-article-edit-part handles id))))
5032 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5033 ;; parts...>') but with stripping would be nice.
5035 (defun gnus-mime-delete-part ()
5036 "Delete the MIME part under point.
5037 Replace it with some information about the removed part."
5039 (gnus-article-check-buffer)
5040 (when (gnus-group-read-only-p)
5041 (error "The current group does not support deleting of parts"))
5042 (when (mm-complicated-handles gnus-article-mime-handles)
5044 The current article has a complicated MIME structure, giving up..."))
5045 (when (or gnus-expert-user
5046 (gnus-yes-or-no-p "\
5047 Deleting parts may malfunction or destroy the article; continue? "))
5048 (let* ((data (get-text-property (point) 'gnus-data))
5049 (id (get-text-property (point) 'gnus-part))
5050 (handles gnus-article-mime-handles)
5053 (let ((desc (mm-handle-description data)))
5055 (mail-decode-encoded-word-string desc))))
5057 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5059 (type (mm-handle-media-type data)))
5061 (error "No MIME part under point"))
5062 (with-current-buffer (mm-handle-buffer data)
5063 (let ((bsize (buffer-size)))
5068 "| The following attachment has been deleted:\n"
5070 "| Type: " type "\n"
5071 "| Filename: " filename "\n"
5072 "| Size (encoded): " (format "%s byte%s\n"
5073 bsize (if (= bsize 1)
5077 (concat "| Description: " description "\n"))
5080 (cdr (mm-make-handle
5081 nil `("text/plain" (charset . gnus-decoded)) nil nil
5083 (format "Deleted attachment (%s bytes)" bsize))))))
5084 ;; (set-buffer gnus-summary-buffer)
5085 (gnus-article-edit-part handles id))))
5087 (defun gnus-mime-save-part ()
5088 "Save the MIME part under point."
5090 (gnus-article-check-buffer)
5091 (let ((data (get-text-property (point) 'gnus-data)))
5093 (mm-save-part data))))
5095 (defun gnus-mime-pipe-part (&optional cmd)
5096 "Pipe the MIME part under point to a process.
5097 Use CMD as the process."
5099 (gnus-article-check-buffer)
5100 (let ((data (get-text-property (point) 'gnus-data)))
5102 (mm-pipe-part data cmd))))
5104 (defun gnus-mime-view-part ()
5105 "Interactively choose a viewing method for the MIME part under point."
5107 (gnus-article-check-buffer)
5108 (let ((data (get-text-property (point) 'gnus-data)))
5110 (setq gnus-article-mime-handles
5112 gnus-article-mime-handles (setq data (copy-sequence data))))
5113 (mm-interactively-view-part data))))
5115 (defun gnus-mime-view-part-as-type-internal ()
5116 (gnus-article-check-buffer)
5117 (let* ((handle (get-text-property (point) 'gnus-data))
5119 ;; Content-Type: foo/bar; name=...
5120 (mail-content-type-get (mm-handle-type handle) 'name)
5121 ;; Content-Disposition: attachment; filename=...
5122 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5123 (def-type (and name (mm-default-file-encoding name))))
5124 (or (and def-type (cons def-type 0))
5126 (equal (mm-handle-media-supertype handle) "text")
5127 '("text/plain" . 0))
5128 '("application/octet-stream" . 0))))
5130 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5131 "Choose a MIME media type, and view the part as such.
5132 If non-nil, PRED is a predicate to use during completion to limit the
5133 available media-types."
5137 (let ((default (gnus-mime-view-part-as-type-internal)))
5138 (gnus-completing-read
5141 (gnus-remove-if-not pred (mailcap-mime-types))
5142 (mailcap-mime-types))
5145 (gnus-article-check-buffer)
5146 (let ((handle (get-text-property (point) 'gnus-data)))
5148 (when (equal (mm-handle-media-type handle) "message/external-body")
5149 (unless (mm-handle-cache handle)
5150 (mm-extern-cache-contents handle))
5151 (setq handle (mm-handle-cache handle)))
5153 (mm-make-handle (mm-handle-buffer handle)
5154 (cons mime-type (cdr (mm-handle-type handle)))
5155 (mm-handle-encoding handle)
5156 (mm-handle-undisplayer handle)
5157 (mm-handle-disposition handle)
5158 (mm-handle-description handle)
5160 (mm-handle-id handle)))
5161 (setq gnus-article-mime-handles
5162 (mm-merge-handles gnus-article-mime-handles handle))
5163 (when (mm-handle-displayed-p handle)
5164 (mm-remove-part handle))
5165 (gnus-mm-display-part handle))))
5167 (defun gnus-mime-copy-part (&optional handle arg)
5168 "Put the MIME part under point into a new buffer.
5169 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5171 (interactive (list nil current-prefix-arg))
5172 (gnus-article-check-buffer)
5174 (setq handle (get-text-property (point) 'gnus-data)))
5176 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5178 (mail-content-type-get (mm-handle-disposition handle)
5180 contents dont-decode charset coding-system)
5181 (mm-with-unibyte-buffer
5182 (mm-insert-part handle)
5183 (setq contents (or (condition-case nil
5184 (mm-decompress-buffer filename nil 'sig)
5186 (setq dont-decode t)
5189 (setq filename (cond (filename (file-name-nondirectory filename))
5190 (dont-decode "*raw data*")
5195 (unless (setq charset (mail-content-type-get
5196 (mm-handle-type handle) 'charset))
5197 (unless (setq coding-system (mm-with-unibyte-buffer
5199 (mm-find-buffer-file-coding-system)))
5200 (setq charset gnus-newsgroup-charset))))
5202 (setq charset (or (cdr (assq arg
5203 gnus-summary-show-article-charset-alist))
5204 (mm-read-coding-system "Charset: ")))))
5205 (switch-to-buffer (generate-new-buffer filename))
5206 (if (or coding-system
5208 (setq coding-system (mm-charset-to-coding-system charset))
5209 (not (eq coding-system 'ascii))))
5211 (mm-enable-multibyte)
5212 (insert (mm-decode-coding-string contents coding-system))
5213 (setq buffer-file-coding-system
5214 (if (boundp 'last-coding-system-used)
5215 (symbol-value 'last-coding-system-used)
5217 (mm-disable-multibyte)
5219 (setq buffer-file-coding-system mm-binary-coding-system))
5220 ;; We do it this way to make `normal-mode' set the appropriate mode.
5223 (setq buffer-file-name (expand-file-name filename))
5225 (setq buffer-file-name nil))
5226 (goto-char (point-min)))))
5228 (defun gnus-mime-print-part (&optional handle filename)
5229 "Print the MIME part under point."
5230 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5231 (gnus-article-check-buffer)
5232 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5233 (contents (and handle (mm-get-part handle)))
5234 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5235 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5240 (mm-save-part-to-file handle file)
5241 (call-process shell-file-name nil
5242 (generate-new-buffer " *mm*")
5244 shell-command-switch
5246 printer file (mm-handle-type handle))))
5250 (gnus-print-buffer))
5251 (ps-despool filename)))))
5253 (defun gnus-mime-inline-part (&optional handle arg)
5254 "Insert the MIME part under point into the current buffer.
5255 Compressed files like .gz and .bz2 are decompressed."
5256 (interactive (list nil current-prefix-arg))
5257 (gnus-article-check-buffer)
5259 (setq handle (get-text-property (point) 'gnus-data)))
5262 (inhibit-read-only t)
5263 contents charset coding-system)
5264 (if (and (not arg) (mm-handle-undisplayer handle))
5265 (mm-remove-part handle)
5266 (mm-with-unibyte-buffer
5267 (mm-insert-part handle)
5269 (or (mm-decompress-buffer
5270 (or (mail-content-type-get (mm-handle-type handle)
5272 (mail-content-type-get (mm-handle-disposition handle)
5278 (unless (setq charset (mail-content-type-get
5279 (mm-handle-type handle) 'charset))
5280 (unless (setq coding-system
5281 (mm-with-unibyte-buffer
5283 (mm-find-buffer-file-coding-system)))
5284 (setq charset gnus-newsgroup-charset))))
5286 (if (mm-handle-undisplayer handle)
5287 (mm-remove-part handle))
5290 gnus-summary-show-article-charset-alist))
5291 (mm-read-coding-system "Charset: "))))
5293 (if (mm-handle-undisplayer handle)
5294 (mm-remove-part handle))))
5296 (mm-display-inline handle)
5299 (defun gnus-mime-set-charset-parameters (handle charset)
5300 "Set CHARSET to parameters in HANDLE.
5301 CHARSET may either be a string or a symbol."
5302 (unless (stringp charset)
5303 (setq charset (symbol-name charset)))
5304 (if (stringp (car handle))
5305 (dolist (h (cdr handle))
5306 (gnus-mime-set-charset-parameters h charset))
5307 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5308 "message/external-body")
5310 (unless (mm-handle-cache handle)
5311 (mm-extern-cache-contents handle))
5312 (mm-handle-cache handle))
5314 (param (assq 'charset (cdr type))))
5316 (setcdr param charset)
5317 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5319 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5320 "Insert the MIME part under point into the current buffer using the
5322 (interactive (list nil current-prefix-arg))
5323 (gnus-article-check-buffer)
5324 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5325 (fun (get-text-property (point) 'gnus-callback))
5326 (gnus-newsgroup-ignored-charsets 'gnus-all)
5327 charset form preferred parts)
5334 gnus-summary-show-article-charset-alist))
5335 (mm-read-coding-system "Charset: "))))
5336 (if (mm-handle-undisplayer handle)
5337 (mm-remove-part handle)))
5338 (gnus-mime-set-charset-parameters handle charset)
5339 (when (and (consp (setq form (cdr-safe fun)))
5340 (setq form (ignore-errors
5341 (assq 'gnus-mime-display-alternative form)))
5342 (setq preferred (caddr form))
5344 (when (eq (car preferred) 'quote)
5345 (setq preferred (cadr preferred)))
5346 (not (equal preferred
5347 (get-text-property (point) 'gnus-data))))
5348 (setq parts (get-text-property (point) 'gnus-part))
5349 (setq parts (cdr (assq parts
5350 gnus-article-mime-handle-alist)))
5351 (equal (mm-handle-media-type parts) "multipart/alternative")
5352 (setq parts (reverse (cdr parts))))
5354 (list 'quote (or (cadr (member preferred parts))
5356 (funcall fun handle)))))
5358 (defun gnus-mime-view-part-externally (&optional handle)
5359 "View the MIME part under point with an external viewer."
5361 (gnus-article-check-buffer)
5362 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5363 (mm-user-display-methods nil)
5364 (mm-inlined-types nil)
5365 (mail-parse-charset gnus-newsgroup-charset)
5366 (mail-parse-ignored-charsets
5367 (with-current-buffer gnus-summary-buffer
5368 gnus-newsgroup-ignored-charsets))
5369 (type (mm-handle-media-type handle))
5370 (method (mailcap-mime-info type))
5371 (mm-enable-external t))
5372 (if (not (stringp method))
5373 (gnus-mime-view-part-as-type
5374 nil (lambda (type) (stringp (mailcap-mime-info type))))
5376 (mm-display-part handle nil t)))))
5378 (defun gnus-mime-view-part-internally (&optional handle)
5379 "View the MIME part under point with an internal viewer.
5380 If no internal viewer is available, use an external viewer."
5382 (gnus-article-check-buffer)
5383 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5384 (mm-inlined-types '(".*"))
5385 (mm-inline-large-images t)
5386 (mail-parse-charset gnus-newsgroup-charset)
5387 (mail-parse-ignored-charsets
5388 (with-current-buffer gnus-summary-buffer
5389 gnus-newsgroup-ignored-charsets))
5390 (inhibit-read-only t))
5391 (if (not (mm-inlinable-p handle))
5392 (gnus-mime-view-part-as-type
5393 nil (lambda (type) (mm-inlinable-p handle type)))
5395 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5397 (defun gnus-mime-action-on-part (&optional action)
5398 "Do something with the MIME attachment at \(point\)."
5400 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5401 (gnus-article-check-buffer)
5402 (let ((action-pair (assoc action gnus-mime-action-alist)))
5404 (funcall (cdr action-pair)))))
5406 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5407 "Call FUNCTION on MIME part N.
5408 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5409 If INTERACTIVE, call FUNCTION interactivly."
5411 ;; Check whether the article is displayed.
5412 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5413 (setq window (get-buffer-window gnus-article-buffer t))
5414 (frame-visible-p (setq frame (window-frame window))))
5415 (error "No article is displayed"))
5416 (with-current-buffer gnus-article-buffer
5417 ;; Check whether the article displays the right contents.
5418 (unless (with-current-buffer gnus-summary-buffer
5419 (eq gnus-current-article (gnus-summary-article-number)))
5420 (error "You should select the right article first"))
5422 (setq n (prefix-numeric-value n))
5424 (setq n (or (get-text-property pt 'gnus-part)
5426 (get-text-property (1- pt) 'gnus-part))
5427 (get-text-property (prog2
5433 (or (and (setq pt (previous-single-property-change
5436 (next-single-property-change (point) 'gnus-part)
5440 ;; Check whether the specified part exists.
5441 (when (> n (length gnus-article-mime-handle-alist))
5442 (error "No such part")))
5445 ;; To select the window is needed so that the cursor
5446 ;; might be visible on the MIME button.
5447 (select-window (prog1
5449 (setq window (selected-window))
5450 ;; Article may be displayed in the other frame.
5451 (gnus-select-frame-set-input-focus
5454 (setq frame (selected-frame))))))
5455 (when (gnus-article-goto-part n)
5456 ;; We point the cursor and the arrow at the MIME button
5457 ;; when the `function' prompt the user for something.
5458 (unless (and (pos-visible-in-window-p)
5459 (> (count-lines (point) (window-end))
5460 (/ (1- (window-height)) 3)))
5461 (recenter (/ (1- (window-height)) 3)))
5462 (let ((cursor-in-non-selected-windows t)
5463 (overlay-arrow-string "=>")
5464 (overlay-arrow-position (point-marker)))
5467 ((and no-handle interactive)
5468 (call-interactively function))
5473 function (get-text-property (point) 'gnus-data)))
5476 (get-text-property (point) 'gnus-data))))
5477 (set-marker overlay-arrow-position nil)
5478 (unless gnus-auto-select-part
5479 (gnus-select-frame-set-input-focus frame)
5480 (select-window window))))
5482 (if gnus-inhibit-mime-unbuttonizing
5483 ;; This is the default though the program shouldn't reach here.
5484 (error "No such part")
5485 ;; The part which doesn't have the MIME button is selected.
5486 ;; So, we display all the buttons and redo it.
5487 (let ((gnus-inhibit-mime-unbuttonizing t))
5488 (gnus-summary-show-article)
5489 (gnus-article-part-wrapper n function no-handle))))))
5491 (defun gnus-article-pipe-part (n)
5492 "Pipe MIME part N, which is the numerical prefix."
5494 (gnus-article-part-wrapper n 'mm-pipe-part))
5496 (defun gnus-article-save-part (n)
5497 "Save MIME part N, which is the numerical prefix."
5499 (gnus-article-part-wrapper n 'mm-save-part))
5501 (defun gnus-article-interactively-view-part (n)
5502 "View MIME part N interactively, which is the numerical prefix."
5504 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5506 (defun gnus-article-copy-part (n)
5507 "Copy MIME part N, which is the numerical prefix."
5509 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5511 (defun gnus-article-view-part-as-charset (n)
5512 "View MIME part N using a specified charset.
5513 N is the numerical prefix."
5515 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5517 (defun gnus-article-view-part-externally (n)
5518 "View MIME part N externally, which is the numerical prefix."
5520 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5522 (defun gnus-article-inline-part (n)
5523 "Inline MIME part N, which is the numerical prefix."
5525 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5527 (defun gnus-article-save-part-and-strip (n)
5528 "Save MIME part N and replace it with an external body.
5529 N is the numerical prefix."
5531 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5533 (defun gnus-article-replace-part (n)
5534 "Replace MIME part N with an external body.
5535 N is the numerical prefix."
5537 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5539 (defun gnus-article-delete-part (n)
5540 "Delete MIME part N and add some information about the removed part.
5541 N is the numerical prefix."
5543 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5545 (defun gnus-article-view-part-as-type (n)
5546 "Choose a MIME media type, and view part N as such.
5547 N is the numerical prefix."
5549 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5551 (defun gnus-article-mime-match-handle-first (condition)
5554 (dolist (ihandle gnus-article-mime-handle-alist)
5556 ((functionp condition)
5557 (funcall condition (cdr ihandle)))
5558 ((eq condition 'undisplayed)
5559 (not (or (mm-handle-undisplayer (cdr ihandle))
5560 (equal (mm-handle-media-type (cdr ihandle))
5561 "multipart/alternative"))))
5562 ((eq condition 'undisplayed-alternative)
5563 (not (mm-handle-undisplayer (cdr ihandle))))
5565 (gnus-article-goto-part (car ihandle))
5566 (or (not n) (< (car ihandle) n)))
5567 (setq n (car ihandle))))
5571 (defun gnus-article-view-part (&optional n)
5572 "View MIME part N, which is the numerical prefix.
5573 If the part is already shown, hide the part. If N is nil, view
5576 (with-current-buffer gnus-article-buffer
5577 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5578 gnus-article-mime-match-handle-function)))
5579 (when (> n (length gnus-article-mime-handle-alist))
5580 (error "No such part"))
5581 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5582 (when (gnus-article-goto-part n)
5583 (if (equal (car handle) "multipart/alternative")
5584 (gnus-article-press-button)
5585 (when (eq (gnus-mm-display-part handle) 'internal)
5586 (gnus-set-window-start)))))))
5588 (defsubst gnus-article-mime-total-parts ()
5589 (if (bufferp (car gnus-article-mime-handles))
5591 (1- (length gnus-article-mime-handles))))
5593 (defun gnus-mm-display-part (handle)
5594 "Display HANDLE and fix MIME button."
5595 (let ((id (get-text-property (point) 'gnus-part))
5597 (inhibit-read-only t))
5600 (let ((window (selected-window))
5601 (mail-parse-charset gnus-newsgroup-charset)
5602 (mail-parse-ignored-charsets
5603 (if (gnus-buffer-live-p gnus-summary-buffer)
5604 (with-current-buffer gnus-summary-buffer
5605 gnus-newsgroup-ignored-charsets)
5609 (let ((win (gnus-get-buffer-window (current-buffer) t))
5612 (select-window win))
5615 (if (mm-handle-displayed-p handle)
5616 ;; This will remove the part.
5617 (mm-display-part handle)
5619 (narrow-to-region (point)
5620 (if (eobp) (point) (1+ (point))))
5621 (gnus-bind-safe-url-regexp (mm-display-part handle))
5622 ;; We narrow to the part itself and
5623 ;; then call the treatment functions.
5624 (goto-char (point-min))
5626 (narrow-to-region (point) (point-max))
5629 (gnus-article-mime-total-parts)
5630 (mm-handle-media-type handle)))))
5631 (if (window-live-p window)
5632 (select-window window)))))
5635 (gnus-insert-mime-button
5636 handle id (list (mm-handle-displayed-p handle)))
5637 (goto-char point))))
5639 (defun gnus-article-goto-part (n)
5640 "Go to MIME part N."
5641 (when gnus-break-pages
5644 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5645 part handle end next handles)
5648 (if (setq handle (get-text-property start 'gnus-data))
5650 ;; Go to the displayed subpart, assuming this is
5651 ;; multipart/alternative.
5654 (while (and (not handle)
5657 (setq next (text-property-not-all part end
5660 handle (get-text-property part 'gnus-data))
5661 (push (cons handle part) handles)
5662 (unless (mm-handle-displayed-p handle)
5664 part (text-property-any part end 'gnus-data nil))))
5666 ;; No subpart is displayed, so we find preferred one.
5668 (cdr (assq (mm-preferred-alternative
5669 (nreverse (mapcar 'car handles)))
5672 (goto-char (1+ part))
5674 (when gnus-break-pages
5675 (gnus-narrow-to-page))))
5677 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5678 (let ((gnus-tmp-name
5679 (or (mail-content-type-get (mm-handle-type handle) 'name)
5680 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5681 (mail-content-type-get (mm-handle-type handle) 'url)
5683 (gnus-tmp-type (mm-handle-media-type handle))
5684 (gnus-tmp-description (or (mm-handle-description handle) ""))
5686 (if (if displayed (car displayed)
5687 (mm-handle-displayed-p handle))
5689 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5691 gnus-tmp-type-long b e)
5692 (when (string-match ".*/" gnus-tmp-name)
5693 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5694 (setq gnus-tmp-type-long (concat gnus-tmp-type
5695 (and (not (equal gnus-tmp-name ""))
5696 (concat "; " gnus-tmp-name))))
5697 (unless (equal gnus-tmp-description "")
5698 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5703 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5704 `(keymap ,gnus-mime-button-map
5705 gnus-callback gnus-mm-display-part
5706 gnus-part ,gnus-tmp-id
5707 article-type annotation
5710 ;; Exclude a newline.
5713 (when gnus-article-button-face
5714 (gnus-overlay-put (gnus-make-overlay b e nil t)
5715 'face gnus-article-button-face))
5716 (widget-convert-button
5719 :action 'gnus-widget-press-button
5720 :button-keymap gnus-mime-button-map
5723 ;; Needed to properly clear the message due to a bug in
5724 ;; wid-edit (XEmacs only).
5725 (if (boundp 'help-echo-owns-message)
5726 (setq help-echo-owns-message t))
5728 "%S: %s the MIME part; %S: more options"
5729 (aref gnus-mouse-2 0)
5730 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5732 (aref gnus-down-mouse-3 0))))))
5734 (defun gnus-widget-press-button (elems el)
5735 (goto-char (widget-get elems :from))
5736 (gnus-article-press-button))
5738 (defvar gnus-displaying-mime nil)
5740 (defun gnus-display-mime (&optional ihandles)
5741 "Display the MIME parts."
5743 (save-selected-window
5744 (let ((window (get-buffer-window gnus-article-buffer))
5747 (select-window window)
5748 ;; We have to do this since selecting the window
5749 ;; may change the point. So we set the window point.
5750 (set-window-point window point)))
5751 (let ((handles ihandles)
5752 (inhibit-read-only t)
5755 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5756 (when gnus-article-emulate-mime
5757 (mm-uu-dissect-text-parts handles)))
5758 (gnus-article-emulate-mime
5759 (setq handles (mm-uu-dissect))))
5760 (when (and (not ihandles)
5761 (not gnus-displaying-mime))
5762 ;; Top-level call; we clean up.
5763 (when gnus-article-mime-handles
5764 (mm-destroy-parts gnus-article-mime-handles)
5765 (setq gnus-article-mime-handle-alist nil));; A trick.
5766 (setq gnus-article-mime-handles handles)
5767 ;; We allow users to glean info from the handles.
5768 (when gnus-article-mime-part-function
5769 (gnus-mime-part-function handles)))
5771 (or (not (stringp (car handles)))
5774 (when (and (not ihandles)
5775 (not gnus-displaying-mime))
5776 ;; Clean up for mime parts.
5778 (delete-region (point) (point-max)))
5779 (let ((gnus-displaying-mime t))
5780 (gnus-mime-display-part handles)))
5783 (narrow-to-region (point) (point-max))
5784 (gnus-treat-article nil 1 1 "text/plain")
5787 ;; Highlight the headers.
5791 (narrow-to-region (point-min) (point))
5792 (gnus-article-save-original-date
5793 (gnus-treat-article 'head)))))))
5794 ;; Cope with broken MIME messages.
5795 (goto-char (point-max))
5799 (defcustom gnus-mime-display-multipart-as-mixed nil
5800 "Display \"multipart\" parts as \"multipart/mixed\".
5802 If t, it overrides nil values of
5803 `gnus-mime-display-multipart-alternative-as-mixed' and
5804 `gnus-mime-display-multipart-related-as-mixed'."
5805 :group 'gnus-article-mime
5808 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5809 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5811 :group 'gnus-article-mime
5814 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5815 "Display \"multipart/related\" parts as \"multipart/mixed\".
5817 If displaying \"text/html\" is discouraged \(see
5818 `mm-discouraged-alternatives'\) images or other material inside a
5819 \"multipart/related\" part might be overlooked when this variable is nil."
5821 :group 'gnus-article-mime
5824 (defun gnus-mime-display-part (handle)
5826 ;; Maybe a broken MIME message.
5829 ((not (stringp (car handle)))
5830 (gnus-mime-display-single handle))
5831 ;; User-defined multipart
5832 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5833 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5835 ;; multipart/alternative
5836 ((and (equal (car handle) "multipart/alternative")
5837 (not (or gnus-mime-display-multipart-as-mixed
5838 gnus-mime-display-multipart-alternative-as-mixed)))
5839 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5840 (push (cons id handle) gnus-article-mime-handle-alist)
5841 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5842 ;; multipart/related
5843 ((and (equal (car handle) "multipart/related")
5844 (not (or gnus-mime-display-multipart-as-mixed
5845 gnus-mime-display-multipart-related-as-mixed)))
5846 ;;;!!!We should find the start part, but we just default
5847 ;;;!!!to the first part.
5848 ;;(gnus-mime-display-part (cadr handle))
5849 ;;;!!! Most multipart/related is an HTML message plus images.
5850 ;;;!!! Unfortunately we are unable to let W3 display those
5851 ;;;!!! included images, so we just display it as a mixed multipart.
5852 ;;(gnus-mime-display-mixed (cdr handle))
5853 ;;;!!! No, w3 can display everything just fine.
5854 (gnus-mime-display-part (cadr handle)))
5855 ((equal (car handle) "multipart/signed")
5856 (gnus-add-wash-type 'signed)
5857 (gnus-mime-display-security handle))
5858 ((equal (car handle) "multipart/encrypted")
5859 (gnus-add-wash-type 'encrypted)
5860 (gnus-mime-display-security handle))
5861 ;; Other multiparts are handled like multipart/mixed.
5863 (gnus-mime-display-mixed (cdr handle)))))
5865 (defun gnus-mime-part-function (handles)
5866 (if (stringp (car handles))
5867 (mapcar 'gnus-mime-part-function (cdr handles))
5868 (funcall gnus-article-mime-part-function handles)))
5870 (defun gnus-mime-display-mixed (handles)
5871 (mapcar 'gnus-mime-display-part handles))
5873 (defun gnus-mime-display-single (handle)
5874 (let ((type (mm-handle-media-type handle))
5875 (ignored gnus-ignored-mime-types)
5882 (when (string-match (pop ignored) type)
5883 (throw 'ignored nil)))
5884 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
5885 (with-current-buffer gnus-summary-buffer
5886 gnus-inhibit-images)
5887 gnus-inhibit-images)
5888 (string-match "\\`image/" type)))
5889 (setq not-attachment
5890 (and (not (mm-inline-override-p handle))
5891 (or (not (mm-handle-disposition handle))
5892 (equal (car (mm-handle-disposition handle))
5894 (mm-attachment-override-p handle))))
5895 (mm-automatic-display-p handle)
5897 (mm-inlinable-p handle)
5898 (mm-inlined-p handle))
5899 (mm-automatic-external-display-p type)))
5901 (when (equal (mm-handle-media-supertype handle) "text")
5903 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5905 (push (cons id handle) gnus-article-mime-handle-alist)
5907 (equal (mm-handle-media-supertype handle) "message"))
5910 (cond ((not (bolp)) 2)
5911 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5913 (when (or (not display)
5914 (not (gnus-unbuttonized-mime-type-p type))
5915 (eq id gnus-mime-buttonized-part-id))
5916 (gnus-insert-mime-button
5917 handle id (list (or display (and not-attachment text))))
5918 (gnus-article-insert-newline)
5919 ;; Remember modify the number of forward lines.
5927 (let ((mail-parse-charset gnus-newsgroup-charset)
5928 (mail-parse-ignored-charsets
5929 (save-excursion (condition-case ()
5930 (set-buffer gnus-summary-buffer)
5932 gnus-newsgroup-ignored-charsets)))
5933 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5934 (goto-char (point-max)))
5935 ((and text not-attachment)
5939 (gnus-article-insert-newline)
5940 (mm-display-inline handle)
5941 (goto-char (point-max))))
5945 (narrow-to-region beg (point))
5946 (if (eq handle gnus-article-mime-handles)
5947 ;; The format=flowed case.
5948 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5949 ;; Don't count signature parts that are never displayed.
5950 ;; The part number should be re-calculated supposing this
5951 ;; might be a message/rfc822 part.
5953 (dolist (part gnus-article-mime-handles)
5954 (unless (or (stringp part)
5955 (equal (car (mm-handle-type part))
5956 "application/pgp-signature"))
5957 (push part handles)))
5959 nil (length (memq handle handles)) (length handles)
5960 (mm-handle-media-type handle)))))))))))
5962 (defun gnus-unbuttonized-mime-type-p (type)
5963 "Say whether TYPE is to be unbuttonized."
5964 (unless gnus-inhibit-mime-unbuttonizing
5966 (let ((types gnus-unbuttonized-mime-types))
5968 (when (string-match (pop types) type)
5969 (throw 'found t)))))
5971 (let ((types gnus-buttonized-mime-types))
5973 (when (string-match (pop types) type)
5974 (throw 'found t)))))))))
5976 (defun gnus-article-insert-newline ()
5977 "Insert a newline, but mark it as undeletable."
5978 (gnus-put-text-property
5979 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5981 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5982 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5985 handle (inhibit-read-only t) from props begend not-pref)
5986 (save-window-excursion
5989 (narrow-to-region (car ibegend)
5992 (goto-char (car ibegend))
5995 (delete-region (point-min) (point-max))
5996 (mm-remove-parts handles))
5997 (setq begend (list (point-marker)))
5999 (unless (setq not-pref (cadr (member preferred ihandles)))
6000 (setq not-pref (car ihandles)))
6003 (not (gnus-unbuttonized-mime-type-p
6004 "multipart/alternative")))
6005 (gnus-add-text-properties
6008 (insert (format "%d. " id))
6012 (unless ,(not ibegend)
6013 (setq gnus-article-mime-handle-alist
6014 ',gnus-article-mime-handle-alist))
6015 (gnus-mime-display-alternative
6016 ',ihandles ',not-pref ',begend ,id))
6017 keymap ,gnus-mime-button-map
6018 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6019 face ,gnus-article-button-face
6021 article-type multipart))
6022 (widget-convert-button 'link from (point)
6023 :action 'gnus-widget-press-button
6024 :button-keymap gnus-widget-button-keymap)
6026 (while (setq handle (pop handles))
6027 (gnus-add-text-properties
6030 (insert (format "(%c) %-18s"
6031 (if (equal handle preferred) ?* ? )
6032 (mm-handle-media-type handle)))
6036 (unless ,(not ibegend)
6037 (setq gnus-article-mime-handle-alist
6038 ',gnus-article-mime-handle-alist))
6039 (gnus-mime-display-alternative
6040 ',ihandles ',handle ',begend ,id))
6041 keymap ,gnus-mime-button-map
6042 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6043 face ,gnus-article-button-face
6046 (widget-convert-button 'link from (point)
6047 :action 'gnus-widget-press-button
6048 :button-keymap gnus-widget-button-keymap)
6052 (if (stringp (car preferred))
6053 (gnus-display-mime preferred)
6054 (let ((mail-parse-charset gnus-newsgroup-charset)
6055 (mail-parse-ignored-charsets
6056 (with-current-buffer gnus-summary-buffer
6057 gnus-newsgroup-ignored-charsets)))
6058 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6062 (narrow-to-region (car begend) (point-max))
6064 nil (length gnus-article-mime-handle-alist)
6065 (gnus-article-mime-total-parts)
6066 (mm-handle-media-type preferred))))))
6067 (goto-char (point-max))
6068 (setcdr begend (point-marker)))))
6070 (goto-char point))))
6072 (defconst gnus-article-wash-status-strings
6073 (let ((alist '((cite "c" "Possible hidden citation text"
6074 " " "All citation text visible")
6075 (headers "h" "Hidden headers"
6076 " " "All headers visible.")
6077 (pgp "p" "Encrypted or signed message status hidden"
6078 " " "No hidden encryption nor digital signature status")
6079 (signature "s" "Signature has been hidden"
6080 " " "Signature is visible")
6081 (overstrike "o" "Overstrike (^H) characters applied"
6082 " " "No overstrike characters applied")
6083 (emphasis "e" "/*_Emphasis_*/ characters applied"
6084 " " "No /*_emphasis_*/ characters applied")))
6086 (dolist (entry alist result)
6087 (let ((key (nth 0 entry))
6088 (on (copy-sequence (nth 1 entry)))
6089 (on-help (nth 2 entry))
6090 (off (copy-sequence (nth 3 entry)))
6091 (off-help (nth 4 entry)))
6092 (put-text-property 0 1 'help-echo on-help on)
6093 (put-text-property 0 1 'help-echo off-help off)
6094 (push (list key on off) result))))
6095 "Alist of strings describing wash status in the mode line.
6096 Each entry has the form (KEY ON OF), where the KEY is a symbol
6097 representing the particular washing function, ON is the string to use
6098 in the article mode line when the washing function is active, and OFF
6099 is the string to use when it is inactive.")
6101 (defun gnus-article-wash-status-entry (key value)
6102 (let ((entry (assoc key gnus-article-wash-status-strings)))
6103 (if value (nth 1 entry) (nth 2 entry))))
6105 (defun gnus-article-wash-status ()
6106 "Return a string which display status of article washing."
6107 (with-current-buffer gnus-article-buffer
6108 (let ((cite (memq 'cite gnus-article-wash-types))
6109 (headers (memq 'headers gnus-article-wash-types))
6110 (boring (memq 'boring-headers gnus-article-wash-types))
6111 (pgp (memq 'pgp gnus-article-wash-types))
6112 (pem (memq 'pem gnus-article-wash-types))
6113 (signed (memq 'signed gnus-article-wash-types))
6114 (encrypted (memq 'encrypted gnus-article-wash-types))
6115 (signature (memq 'signature gnus-article-wash-types))
6116 (overstrike (memq 'overstrike gnus-article-wash-types))
6117 (emphasis (memq 'emphasis gnus-article-wash-types)))
6119 (gnus-article-wash-status-entry 'cite cite)
6120 (gnus-article-wash-status-entry 'headers (or headers boring))
6121 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6122 (gnus-article-wash-status-entry 'signature signature)
6123 (gnus-article-wash-status-entry 'overstrike overstrike)
6124 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6126 (defun gnus-add-wash-type (type)
6127 "Add a washing of TYPE to the current status."
6128 (add-to-list 'gnus-article-wash-types type))
6130 (defun gnus-delete-wash-type (type)
6131 "Add a washing of TYPE to the current status."
6132 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6134 (defun gnus-add-image (category image)
6135 "Add IMAGE of CATEGORY to the list of displayed images."
6136 (let ((entry (assq category gnus-article-image-alist)))
6138 (setq entry (list category))
6139 (push entry gnus-article-image-alist))
6140 (nconc entry (list image))))
6142 (defun gnus-delete-images (category)
6143 "Delete all images in CATEGORY."
6144 (let ((entry (assq category gnus-article-image-alist)))
6145 (dolist (image (cdr entry))
6146 (gnus-remove-image image category))
6147 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6148 (gnus-delete-wash-type category)))
6150 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6152 (defun gnus-article-maybe-hide-headers ()
6153 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6154 Provided for backwards compatibility."
6155 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6156 (not (with-current-buffer gnus-summary-buffer
6157 gnus-have-all-headers)))
6158 (not gnus-inhibit-hiding))
6159 (gnus-article-hide-headers)))
6163 (defun gnus-output-to-file (file-name)
6164 "Append the current article to a file named FILE-NAME.
6165 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6166 text and used as the value of the coding cookie which is added to the
6167 top of a file. Otherwise, this function saves a raw article without
6169 (let* ((artbuf (current-buffer))
6170 (file-name-coding-system nnmail-pathname-coding-system)
6171 (coding gnus-article-save-coding-system)
6172 (coding-system-for-read (if coding
6173 nil ;; Rely on the coding cookie.
6174 mm-text-coding-system))
6175 (coding-system-for-write (or coding
6176 mm-text-coding-system-for-write
6177 mm-text-coding-system))
6178 (exists (file-exists-p file-name)))
6181 (insert-file-contents file-name)
6182 (goto-char (point-min))
6183 ;; Remove the existing coding cookie.
6184 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6185 (delete-region (match-beginning 0) (match-end 0))))
6186 (goto-char (point-max))
6187 (insert-buffer-substring artbuf)
6188 ;; Append newline at end of the buffer as separator, and then
6190 (goto-char (point-max))
6193 ;; If the coding system is not suitable to encode the text,
6194 ;; ask a user for a proper one.
6195 (when (fboundp 'select-safe-coding-system)
6196 (setq coding (coding-system-base
6197 (save-window-excursion
6198 (select-safe-coding-system (point-min) (point-max)
6200 (setq coding-system-for-write
6201 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6203 (goto-char (point-min))
6204 ;; Add the coding cookie.
6205 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6206 coding-system-for-write)))
6209 (write-region (point-min) (point-max) file-name nil 'no-message)
6210 (message "Appended to %s" file-name))
6211 (write-region (point-min) (point-max) file-name))))
6214 (defun gnus-narrow-to-page (&optional arg)
6215 "Narrow the article buffer to a page.
6216 If given a numerical ARG, move forward ARG pages."
6218 (setq arg (if arg (prefix-numeric-value arg) 0))
6219 (with-current-buffer gnus-article-buffer
6221 ;; Remove any old next/prev buttons.
6222 (when (gnus-visual-p 'page-marker)
6223 (let ((inhibit-read-only t))
6224 (gnus-remove-text-with-property 'gnus-prev)
6225 (gnus-remove-text-with-property 'gnus-next)))
6227 (when (save-excursion
6229 (if (re-search-backward page-delimiter nil 'move (abs arg))
6231 (setq nd (match-beginning 0)
6233 (when (re-search-backward page-delimiter nil t)
6234 (setq st (match-end 0))))
6235 (when (re-search-forward page-delimiter nil t)
6236 (setq nd (match-beginning 0)
6239 (if (re-search-forward page-delimiter nil 'move arg)
6241 (setq st (match-end 0)
6243 (when (re-search-forward page-delimiter nil t)
6244 (setq nd (match-beginning 0))))
6245 (when (re-search-backward page-delimiter nil t)
6246 (setq st (match-end 0)
6249 (when (re-search-backward page-delimiter nil t)
6250 (goto-char (setq st (match-end 0))))
6251 (when (re-search-forward page-delimiter nil t)
6252 (setq nd (match-beginning 0)))
6254 (setq gnus-page-broken t)
6255 (when pt (goto-char pt))
6256 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6257 (when (gnus-visual-p 'page-marker)
6261 (gnus-insert-next-page-button))
6264 (gnus-insert-prev-page-button))))))))
6266 ;; Article mode commands
6268 (defun gnus-article-goto-next-page ()
6269 "Show the next page of the article."
6271 (when (gnus-article-next-page)
6272 (goto-char (point-min))
6273 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6276 (defun gnus-article-goto-prev-page ()
6277 "Show the previous page of the article."
6279 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6280 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6281 (gnus-article-prev-page nil)))
6283 ;; This is cleaner but currently breaks `gnus-pick-mode':
6285 ;; (defun gnus-article-goto-next-page ()
6286 ;; "Show the next page of the article."
6288 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6289 ;; (gnus-summary-next-page)))
6291 ;; (defun gnus-article-goto-prev-page ()
6292 ;; "Show the next page of the article."
6294 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6295 ;; (gnus-summary-prev-page)))
6297 (defun gnus-article-next-page (&optional lines)
6298 "Show the next page of the current article.
6299 If end of article, return non-nil. Otherwise return nil.
6300 Argument LINES specifies lines to be scrolled up."
6302 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6303 (if (and (not (and gnus-article-over-scroll
6304 (> (count-lines (window-start) (point-max))
6305 (if (featurep 'xemacs)
6306 (or lines (1- (window-height)))
6307 (+ (or lines (1- (window-height))) scroll-margin)))))
6310 (and (pos-visible-in-window-p) ;Not continuation line.
6311 (>= (point) (point-max)))))
6312 ;; Nothing in this page.
6313 (if (or (not gnus-page-broken)
6318 (eobp)))) ;Real end-of-buffer?
6320 (when gnus-article-over-scroll
6321 (gnus-article-next-page-1 lines))
6323 (gnus-narrow-to-page 1) ;Go to next page.
6325 ;; More in this page.
6326 (gnus-article-next-page-1 lines)
6329 (defun gnus-article-beginning-of-window ()
6330 "Move point to the beginning of the window.
6331 In Emacs, the point is placed at the line number which `scroll-margin'
6333 (if (featurep 'xemacs)
6334 (move-to-window-line 0)
6335 ;; There is an obscure bug in Emacs that makes it impossible to
6336 ;; scroll past big pictures in the article buffer. Try to fix
6337 ;; this by adding a sanity check by counting the lines visible.
6338 (when (> (count-lines (window-start) (window-end)) 30)
6339 (move-to-window-line
6340 (min (max 0 scroll-margin)
6341 (max 1 (- (window-height)
6342 (if mode-line-format 1 0)
6343 (if header-line-format 1 0)
6346 (defun gnus-article-next-page-1 (lines)
6348 (let ((scroll-in-place nil))
6351 ;; Long lines may cause an end-of-buffer error.
6352 (goto-char (point-max))))
6353 (gnus-article-beginning-of-window))
6355 (defun gnus-article-prev-page (&optional lines)
6356 "Show previous page of current article.
6357 Argument LINES specifies lines to be scrolled down."
6359 (move-to-window-line 0)
6360 (if (and gnus-page-broken
6362 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6364 (gnus-narrow-to-page -1) ;Go to previous page.
6365 (goto-char (point-max))
6366 (recenter (if gnus-article-over-scroll
6368 (max (if (featurep 'xemacs)
6370 (+ lines scroll-margin))
6372 (- (window-height) 2))
6376 (let ((scroll-in-place nil))
6377 (scroll-down lines))
6378 (beginning-of-buffer
6379 (goto-char (point-min))))
6380 (gnus-article-beginning-of-window))))
6382 (defun gnus-article-only-boring-p ()
6383 "Decide whether there is only boring text remaining in the article.
6384 Something \"interesting\" is a word of at least two letters that does
6385 not have a face in `gnus-article-boring-faces'."
6386 (when (and gnus-article-skip-boring
6387 (boundp 'gnus-article-boring-faces)
6388 (symbol-value 'gnus-article-boring-faces))
6390 (let ((inhibit-point-motion-hooks t))
6392 (while (re-search-forward "\\b\\w\\w" nil t)
6394 (when (not (gnus-intersection
6395 (gnus-faces-at (point))
6396 (symbol-value 'gnus-article-boring-faces)))
6397 (throw 'only-boring nil)))
6398 (throw 'only-boring t))))))
6400 (defun gnus-article-refer-article ()
6401 "Read article specified by message-id around point."
6404 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6405 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6406 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6407 (let ((msg-id (concat "<" (match-string 0) ">")))
6408 (set-buffer gnus-summary-buffer)
6409 (gnus-summary-refer-article msg-id))
6410 (error "No references around point"))))
6412 (defun gnus-article-show-summary ()
6413 "Reconfigure windows to show summary buffer."
6415 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6416 (error "There is no summary buffer for this article buffer")
6417 (gnus-article-set-globals)
6418 (gnus-configure-windows 'article)
6419 (gnus-summary-goto-subject gnus-current-article)
6420 (gnus-summary-position-point)))
6422 (defun gnus-article-describe-briefly ()
6423 "Describe article mode commands briefly."
6425 (gnus-message 6 "%s" (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
6427 (defun gnus-article-check-buffer ()
6428 "Beep if not in an article buffer."
6429 (unless (equal major-mode 'gnus-article-mode)
6430 (error "Command invoked outside of a Gnus article buffer")))
6432 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6433 "Read a summary buffer key sequence and execute it from the article buffer."
6435 (gnus-article-check-buffer)
6437 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6438 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6439 "=" "^" "\M-^" "|"))
6441 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6442 "An" "Ap" [?A (meta return)] [?A delete]))
6446 '("n" "Gn" "p" "Gp"))
6448 (with-current-buffer gnus-article-current-summary
6449 (let (gnus-pick-mode)
6450 (setq unread-command-events (nconc unread-command-events
6451 (list (or key last-command-event)))
6452 keys (if (featurep 'xemacs)
6453 (events-to-keys (read-key-sequence nil t))
6454 (read-key-sequence nil t)))))
6459 ((eq (aref keys (1- (length keys))) ?\C-h)
6460 (gnus-article-describe-bindings (substring keys 0 -1)))
6461 ((or (member keys nosaves)
6462 (member keys nosave-but-article)
6463 (member keys nosave-in-article))
6465 (save-window-excursion
6466 (pop-to-buffer gnus-article-current-summary)
6467 ;; We disable the pick minor mode commands.
6468 (let (gnus-pick-mode)
6469 (setq func (key-binding keys t))))
6473 (unless (member keys nosave-in-article)
6474 (set-buffer gnus-article-current-summary))
6475 (when (get func 'disabled)
6476 (error "Function %s disabled" func))
6477 (call-interactively func)
6478 (setq new-sum-point (point)))
6479 (when (member keys nosave-but-article)
6480 (pop-to-buffer gnus-article-buffer))))
6482 ;; These commands should restore window configuration.
6483 (let ((obuf (current-buffer))
6484 (owin (current-window-configuration))
6485 win func in-buffer selected new-sum-start new-sum-hscroll err)
6486 (cond (not-restore-window
6487 (pop-to-buffer gnus-article-current-summary)
6488 (setq win (selected-window)))
6489 ((setq win (get-buffer-window gnus-article-current-summary))
6490 (select-window win))
6492 (let ((summary-buffer gnus-article-current-summary))
6493 (gnus-configure-windows 'article)
6494 (unless (setq win (get-buffer-window summary-buffer 'visible))
6495 (let ((gnus-buffer-configuration
6496 '((article ((vertical 1.0
6497 (summary 0.25 point)
6499 (gnus-configure-windows 'article))
6500 (setq win (get-buffer-window summary-buffer 'visible)))
6501 (gnus-select-frame-set-input-focus (window-frame win))
6502 (select-window win))))
6503 (setq in-buffer (current-buffer))
6504 ;; We disable the pick minor mode commands.
6505 (setq func (let (gnus-pick-mode)
6506 (key-binding keys t)))
6507 (when (get func 'disabled)
6508 (error "Function %s disabled" func))
6511 (condition-case code
6513 (call-interactively func)
6519 (when (eq win (selected-window))
6520 (setq new-sum-point (point)
6521 new-sum-start (window-start win)
6522 new-sum-hscroll (window-hscroll win)))
6523 (when (or (eq in-buffer (current-buffer))
6524 (when (eq obuf (current-buffer))
6525 (set-buffer in-buffer)
6527 (setq selected (gnus-summary-select-article))
6529 (unless not-restore-window
6530 (set-window-configuration owin))
6531 (when (and (eq selected 'old)
6533 (set-window-start (get-buffer-window (current-buffer))
6535 (set-window-point (get-buffer-window (current-buffer))
6536 (if (article-goto-body)
6539 (when (and (not not-restore-window)
6542 (with-current-buffer (window-buffer win)
6543 (eq major-mode 'gnus-summary-mode)))
6544 (set-window-point win new-sum-point)
6545 (set-window-start win new-sum-start)
6546 (set-window-hscroll win new-sum-hscroll))))
6547 (set-window-configuration owin)
6549 (signal (car err) (cdr err))
6552 (defun gnus-article-read-summary-send-keys ()
6554 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6555 (gnus-article-read-summary-keys)))
6557 (defun gnus-article-describe-key (key)
6558 "Display documentation of the function invoked by KEY.
6559 KEY is a string or a vector."
6560 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6561 (read-key-sequence "Describe key: "))))
6562 (gnus-article-check-buffer)
6563 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6564 gnus-article-read-summary-send-keys))
6565 (with-current-buffer gnus-article-current-summary
6566 (setq unread-command-events
6567 (if (featurep 'xemacs)
6569 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6570 (list 'meta (- x 128))
6573 (let ((cursor-in-echo-area t)
6575 (describe-key (read-key-sequence nil t))))
6576 (describe-key key)))
6578 (defun gnus-article-describe-key-briefly (key &optional insert)
6579 "Display documentation of the function invoked by KEY.
6580 KEY is a string or a vector."
6581 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6582 (read-key-sequence "Describe key: "))
6583 current-prefix-arg))
6584 (gnus-article-check-buffer)
6585 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6586 gnus-article-read-summary-send-keys))
6587 (with-current-buffer gnus-article-current-summary
6588 (setq unread-command-events
6589 (if (featurep 'xemacs)
6591 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6592 (list 'meta (- x 128))
6595 (let ((cursor-in-echo-area t)
6597 (describe-key-briefly (read-key-sequence nil t) insert)))
6598 (describe-key-briefly key insert)))
6600 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6601 (defvar gnus-agent-summary-mode)
6602 (defvar gnus-draft-mode)
6603 ;; Calling help-buffer will autoload help-mode.
6604 (defvar help-xref-stack-item)
6605 ;; Emacs 22 doesn't load it in the batch mode.
6607 (autoload 'help-buffer "help-mode"))
6609 (defun gnus-article-describe-bindings (&optional prefix)
6610 "Show a list of all defined keys, and their definitions.
6611 The optional argument PREFIX, if non-nil, should be a key sequence;
6612 then we display only bindings that start with that prefix."
6614 (gnus-article-check-buffer)
6615 (let ((keymap (copy-keymap gnus-article-mode-map))
6616 (map (copy-keymap gnus-article-send-map))
6617 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6619 (define-key keymap "S" map)
6620 (define-key map [t] nil)
6621 (with-current-buffer gnus-article-current-summary
6624 (if (setq parent (keymap-parent gnus-article-mode-map))
6626 (setq parent (copy-keymap parent))
6627 (set-keymap-parent parent (current-local-map)))
6628 (current-local-map)))
6629 (set-keymap-parent map (key-binding "S"))
6630 (let (key def gnus-pick-mode)
6632 (setq key (pop sumkeys))
6633 (cond ((and (vectorp key) (= (length key) 1)
6634 (consp (setq def (aref key 0)))
6635 (numberp (car def)) (numberp (cdr def)))
6636 (when (< (max (car def) (cdr def)) 128)
6640 (nreverse (gnus-uncompress-range def)))
6642 ((setq def (key-binding key))
6643 (unless (eq def 'undefined)
6644 (define-key keymap key def))))))
6645 (when (boundp 'gnus-agent-summary-mode)
6646 (setq agent gnus-agent-summary-mode))
6647 (when (boundp 'gnus-draft-mode)
6648 (setq draft gnus-draft-mode)))
6650 (use-local-map keymap)
6651 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6652 (set (make-local-variable 'gnus-draft-mode) draft)
6653 (describe-bindings prefix))
6654 (let ((item `((lambda (prefix)
6655 (with-current-buffer ,(current-buffer)
6656 (gnus-article-describe-bindings prefix)))
6658 (with-current-buffer (let (help-xref-following) (help-buffer))
6659 (setq help-xref-stack-item item)))))
6661 (defun gnus-article-reply-with-original (&optional wide)
6662 "Start composing a reply mail to the current message.
6663 The text in the region will be yanked. If the region isn't active,
6664 the entire article will be yanked."
6666 (let ((article (cdr gnus-article-current))
6668 (if (not (gnus-region-active-p))
6669 (with-current-buffer gnus-summary-buffer
6670 (gnus-summary-reply (list (list article)) wide))
6671 (setq contents (buffer-substring (point) (mark t)))
6672 ;; Deactivate active regions.
6673 (when (and (boundp 'transient-mark-mode)
6674 transient-mark-mode)
6675 (setq mark-active nil))
6676 (with-current-buffer gnus-summary-buffer
6678 (list (list article contents)) wide)))))
6680 (defun gnus-article-wide-reply-with-original ()
6681 "Start composing a wide reply mail to the current message.
6682 The text in the region will be yanked. If the region isn't active,
6683 the entire article will be yanked."
6685 (gnus-article-reply-with-original t))
6687 (defun gnus-article-followup-with-original ()
6688 "Compose a followup to the current article.
6689 The text in the region will be yanked. If the region isn't active,
6690 the entire article will be yanked."
6692 (let ((article (cdr gnus-article-current))
6694 (if (not (gnus-region-active-p))
6695 (with-current-buffer gnus-summary-buffer
6696 (gnus-summary-followup (list (list article))))
6697 (setq contents (buffer-substring (point) (mark t)))
6698 ;; Deactivate active regions.
6699 (when (and (boundp 'transient-mark-mode)
6700 transient-mark-mode)
6701 (setq mark-active nil))
6702 (with-current-buffer gnus-summary-buffer
6703 (gnus-summary-followup
6704 (list (list article contents)))))))
6706 (defun gnus-article-hide (&optional arg force)
6707 "Hide all the gruft in the current article.
6708 This means that signatures, cited text and (some) headers will be
6710 If given a prefix, show the hidden text instead."
6711 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6712 (gnus-article-hide-headers arg)
6713 (gnus-article-hide-list-identifiers arg)
6714 (gnus-article-hide-citation-maybe arg force)
6715 (gnus-article-hide-signature arg))
6717 (defun gnus-article-maybe-highlight ()
6718 "Do some article highlighting if article highlighting is requested."
6719 (when (gnus-visual-p 'article-highlight 'highlight)
6720 (gnus-article-highlight-some)))
6722 (defun gnus-check-group-server ()
6723 ;; Make sure the connection to the server is alive.
6724 (unless (gnus-server-opened
6725 (gnus-find-method-for-group gnus-newsgroup-name))
6726 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6727 (gnus-request-group gnus-newsgroup-name t)))
6730 (autoload 'nneething-get-file-name "nneething"))
6732 (defun gnus-request-article-this-buffer (article group)
6733 "Get an article and insert it into this buffer."
6734 (let (do-update-line sparse-header)
6738 (gnus-kill-all-overlays)
6739 (setq group (or group gnus-newsgroup-name))
6741 ;; Using `gnus-request-article' directly will insert the article into
6742 ;; `nntp-server-buffer' - so we'll save some time by not having to
6743 ;; copy it from the server buffer into the article buffer.
6745 ;; We only request an article by message-id when we do not have the
6746 ;; headers for it, so we'll have to get those.
6747 (when (stringp article)
6748 (gnus-read-header article))
6750 ;; If the article number is negative, that means that this article
6751 ;; doesn't belong in this newsgroup (possibly), so we find its
6752 ;; message-id and request it by id instead of number.
6753 (when (and (numberp article)
6755 (get-buffer gnus-summary-buffer)
6756 (gnus-buffer-exists-p gnus-summary-buffer))
6757 (with-current-buffer gnus-summary-buffer
6758 (let ((header (gnus-summary-article-header article)))
6761 ((memq article gnus-newsgroup-sparse)
6762 ;; This is a sparse gap article.
6763 (setq do-update-line article)
6764 (setq article (mail-header-id header))
6765 (setq sparse-header (gnus-read-header article))
6766 (setq gnus-newsgroup-sparse
6767 (delq article gnus-newsgroup-sparse)))
6769 ;; It's a real article.
6770 (setq article (mail-header-id header)))
6772 ;; It is an extracted pseudo-article.
6773 (setq article 'pseudo)
6774 (gnus-request-pseudo-article header))))
6776 (let ((method (gnus-find-method-for-group
6777 gnus-newsgroup-name)))
6778 (when (and (eq (car method) 'nneething)
6780 (let ((dir (nneething-get-file-name
6781 (mail-header-id header))))
6782 (when (and (stringp dir)
6783 (file-directory-p dir))
6784 (setq article 'nneething)
6785 (gnus-group-enter-directory dir))))))))
6788 ;; Refuse to select canceled articles.
6789 ((and (numberp article)
6791 (get-buffer gnus-summary-buffer)
6792 (gnus-buffer-exists-p gnus-summary-buffer)
6793 (eq (cdr (with-current-buffer gnus-summary-buffer
6794 (assq article gnus-newsgroup-reads)))
6795 gnus-canceled-mark))
6797 ;; We first check `gnus-original-article-buffer'.
6798 ((and (get-buffer gnus-original-article-buffer)
6800 (with-current-buffer gnus-original-article-buffer
6801 (and (equal (car gnus-original-article) group)
6802 (eq (cdr gnus-original-article) article))))
6803 ;; `insert-buffer-substring' would incorrectly use the
6804 ;; equivalent of string-make-multibyte which amount to decoding
6805 ;; with locale-coding-system, causing failure of
6806 ;; subsequent decoding.
6807 (insert (mm-string-to-multibyte
6808 (with-current-buffer gnus-original-article-buffer
6809 (buffer-substring (point-min) (point-max)))))
6811 ;; Check the backlog.
6812 ((and gnus-keep-backlog
6813 (gnus-backlog-request-article group article (current-buffer)))
6815 ;; Check asynchronous pre-fetch.
6816 ((gnus-async-request-fetched-article group article (current-buffer))
6817 (gnus-async-prefetch-next group article gnus-summary-buffer)
6818 (when (and (numberp article) gnus-keep-backlog)
6819 (gnus-backlog-enter-article group article (current-buffer)))
6822 ((and gnus-use-cache
6824 (gnus-cache-request-article article group))
6826 ;; Check the agent cache.
6827 ((gnus-agent-request-article article group)
6829 ;; Get the article and put into the article buffer.
6830 ((or (stringp article)
6832 (let ((gnus-override-method gnus-override-method)
6833 (methods (and (stringp article)
6834 gnus-refer-article-method))
6835 (backend (car (gnus-find-method-for-group
6836 gnus-newsgroup-name)))
6838 (inhibit-read-only t))
6839 (if (or (not (listp methods))
6840 (and (symbolp (car methods))
6841 (assq (car methods) nnoo-definition-alist)))
6842 (setq methods (list methods)))
6843 (when (and (null gnus-override-method)
6845 (setq gnus-override-method (pop methods)))
6847 (when (eq gnus-override-method 'current)
6848 (setq gnus-override-method
6849 (with-current-buffer gnus-summary-buffer
6850 gnus-current-select-method)))
6852 (gnus-kill-all-overlays)
6853 (let ((gnus-newsgroup-name group))
6854 (gnus-check-group-server))
6856 ((gnus-request-article article group (current-buffer))
6857 (when (numberp article)
6858 (gnus-async-prefetch-next group article
6859 gnus-summary-buffer)
6860 (when gnus-keep-backlog
6861 (gnus-backlog-enter-article
6862 group article (current-buffer))))
6863 (setq result 'article))
6865 (setq gnus-override-method (pop methods)))
6866 ((not (string-match "^400 "
6867 (nnheader-get-report backend)))
6868 ;; If we get 400 server disconnect, reconnect and
6869 ;; retry; otherwise, assume the article has expired.
6870 (setq result 'done))))
6871 (and (eq result 'article) 'article)))
6875 ;; Associate this article with the current summary buffer.
6876 (setq gnus-article-current-summary gnus-summary-buffer)
6878 ;; Take the article from the original article buffer
6879 ;; and place it in the buffer it's supposed to be in.
6880 (when (and (get-buffer gnus-article-buffer)
6881 (equal (buffer-name (current-buffer))
6882 (buffer-name (get-buffer gnus-article-buffer))))
6884 (if (get-buffer gnus-original-article-buffer)
6885 (set-buffer gnus-original-article-buffer)
6886 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6887 (buffer-disable-undo)
6888 (setq major-mode 'gnus-original-article-mode)
6889 (setq buffer-read-only t))
6890 (let ((inhibit-read-only t))
6892 (insert-buffer-substring gnus-article-buffer))
6893 (setq gnus-original-article (cons group article)))
6896 (run-hooks 'gnus-article-decode-hook)
6897 ;; Mark article as decoded or not.
6898 (setq gnus-article-decoded-p gnus-article-decode-hook))
6900 ;; Update sparse articles.
6901 (when (and do-update-line
6902 (or (numberp article)
6904 (let ((buf (current-buffer)))
6905 (set-buffer gnus-summary-buffer)
6906 (gnus-summary-update-article do-update-line sparse-header)
6907 (gnus-summary-goto-subject do-update-line nil t)
6908 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6910 (set-buffer buf))))))
6912 (defun gnus-block-private-groups (group)
6913 (if (gnus-news-group-p group)
6914 ;; Block nothing in news groups.
6916 ;; Block everything anywhere else.
6919 (defun gnus-blocked-images ()
6920 (if (functionp gnus-blocked-images)
6921 (funcall gnus-blocked-images gnus-newsgroup-name)
6922 gnus-blocked-images))
6928 (defcustom gnus-article-edit-mode-hook nil
6929 "Hook run in article edit mode buffers."
6930 :group 'gnus-article-various
6933 (defvar gnus-article-edit-done-function nil)
6935 (defvar gnus-article-edit-mode-map nil)
6937 ;; Should we be using derived.el for this?
6938 (unless gnus-article-edit-mode-map
6939 (setq gnus-article-edit-mode-map (make-keymap))
6940 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6942 (gnus-define-keys gnus-article-edit-mode-map
6943 "\C-c?" describe-mode
6944 "\C-c\C-c" gnus-article-edit-done
6945 "\C-c\C-k" gnus-article-edit-exit
6946 "\C-c\C-f\C-t" message-goto-to
6947 "\C-c\C-f\C-o" message-goto-from
6948 "\C-c\C-f\C-b" message-goto-bcc
6949 ;;"\C-c\C-f\C-w" message-goto-fcc
6950 "\C-c\C-f\C-c" message-goto-cc
6951 "\C-c\C-f\C-s" message-goto-subject
6952 "\C-c\C-f\C-r" message-goto-reply-to
6953 "\C-c\C-f\C-n" message-goto-newsgroups
6954 "\C-c\C-f\C-d" message-goto-distribution
6955 "\C-c\C-f\C-f" message-goto-followup-to
6956 "\C-c\C-f\C-m" message-goto-mail-followup-to
6957 "\C-c\C-f\C-k" message-goto-keywords
6958 "\C-c\C-f\C-u" message-goto-summary
6959 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6960 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6961 "\C-c\C-b" message-goto-body
6962 "\C-c\C-i" message-goto-signature
6964 "\C-c\C-t" message-insert-to
6965 "\C-c\C-n" message-insert-newsgroups
6966 "\C-c\C-o" message-sort-headers
6967 "\C-c\C-e" message-elide-region
6968 "\C-c\C-v" message-delete-not-region
6969 "\C-c\C-z" message-kill-to-signature
6970 "\M-\r" message-newline-and-reformat
6971 "\C-c\C-a" mml-attach-file
6972 "\C-a" message-beginning-of-line
6974 "\M-;" comment-region)
6976 (gnus-define-keys (gnus-article-edit-wash-map
6977 "\C-c\C-w" gnus-article-edit-mode-map)
6978 "f" gnus-article-edit-full-stops))
6981 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6983 ["Fetch To" message-insert-to t]
6984 ["Fetch Newsgroups" message-insert-newsgroups t]
6986 ["To" message-goto-to t]
6987 ["From" message-goto-from t]
6988 ["Subject" message-goto-subject t]
6989 ["Cc" message-goto-cc t]
6990 ["Reply-To" message-goto-reply-to t]
6991 ["Summary" message-goto-summary t]
6992 ["Keywords" message-goto-keywords t]
6993 ["Newsgroups" message-goto-newsgroups t]
6994 ["Followup-To" message-goto-followup-to t]
6995 ["Mail-Followup-To" message-goto-mail-followup-to t]
6996 ["Distribution" message-goto-distribution t]
6997 ["Body" message-goto-body t]
6998 ["Signature" message-goto-signature t]))
7000 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7001 "Major mode for editing articles.
7002 This is an extended text-mode.
7004 \\{gnus-article-edit-mode-map}"
7005 (make-local-variable 'gnus-article-edit-done-function)
7006 (make-local-variable 'gnus-prev-winconf)
7007 (set (make-local-variable 'font-lock-defaults)
7008 '(message-font-lock-keywords t))
7009 (set (make-local-variable 'mail-header-separator) "")
7010 (set (make-local-variable 'gnus-article-edit-mode) t)
7011 (easy-menu-add message-mode-field-menu message-mode-map)
7013 (setq buffer-read-only nil)
7014 (buffer-enable-undo)
7017 (defun gnus-article-edit (&optional force)
7018 "Edit the current article.
7019 This will have permanent effect only in mail groups.
7020 If FORCE is non-nil, allow editing of articles even in read-only
7023 (when (and (not force)
7024 (gnus-group-read-only-p))
7025 (error "The current newsgroup does not support article editing"))
7026 (gnus-article-date-original)
7027 (gnus-article-edit-article
7029 `(lambda (no-highlight)
7031 (gnus-summary-edit-article-done
7032 ,(or (mail-header-references gnus-current-headers) "")
7033 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7035 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7036 "Start editing the contents of the current article buffer."
7037 (let ((winconf (current-window-configuration)))
7038 (set-buffer gnus-article-buffer)
7039 (let ((message-auto-save-directory
7040 ;; Don't associate the article buffer with a draft file.
7042 (gnus-article-edit-mode))
7043 (funcall start-func)
7044 (set-buffer-modified-p nil)
7045 (gnus-configure-windows 'edit-article)
7046 (setq gnus-article-edit-done-function exit-func)
7047 (setq gnus-prev-winconf winconf)
7049 (gnus-message 6 "C-c C-c to end edits"))))
7051 (defun gnus-article-edit-done (&optional arg)
7052 "Update the article edits and exit."
7054 (let ((func gnus-article-edit-done-function)
7055 (buf (current-buffer))
7056 (start (window-start))
7058 (winconf gnus-prev-winconf))
7059 (widen) ;; Widen it in case that users narrowed the buffer.
7062 ;; The cache and backlog have to be flushed somewhat.
7063 (when gnus-keep-backlog
7064 (gnus-backlog-remove-article
7065 (car gnus-article-current) (cdr gnus-article-current)))
7066 ;; Flush original article as well.
7067 (gnus-flush-original-article-buffer)
7068 (when gnus-use-cache
7069 (gnus-cache-update-article
7070 (car gnus-article-current) (cdr gnus-article-current)))
7071 ;; We remove all text props from the article buffer.
7072 (kill-all-local-variables)
7073 (set-text-properties (point-min) (point-max) nil)
7075 (set-window-configuration winconf)
7077 (set-window-start (get-buffer-window buf) start)
7078 (set-window-point (get-buffer-window buf) (point)))
7079 (gnus-summary-show-article))
7081 (defun gnus-flush-original-article-buffer ()
7082 (when (get-buffer gnus-original-article-buffer)
7083 (with-current-buffer gnus-original-article-buffer
7084 (setq gnus-original-article nil))))
7086 (defun gnus-article-edit-exit ()
7087 "Exit the article editing without updating."
7089 (when (or (not (buffer-modified-p))
7090 (yes-or-no-p "Article modified; kill anyway? "))
7091 (let ((curbuf (current-buffer))
7093 (window-start (window-start)))
7095 (if (gnus-buffer-live-p gnus-original-article-buffer)
7096 (insert-buffer-substring gnus-original-article-buffer))
7097 (let ((winconf gnus-prev-winconf))
7098 (kill-all-local-variables)
7100 (set-window-configuration winconf)
7101 ;; Tippy-toe some to make sure that point remains where it was.
7102 (save-current-buffer
7104 (set-window-start (get-buffer-window (current-buffer)) window-start)
7106 (gnus-summary-show-article)))
7108 (defun gnus-article-edit-full-stops ()
7109 "Interactively repair spacing at end of sentences."
7112 (goto-char (point-min))
7113 (search-forward-regexp "^$" nil t)
7114 (let ((case-fold-search nil))
7115 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7118 ;;; Article highlights
7121 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7123 ;;; Internal Variables:
7125 (defcustom gnus-button-url-regexp
7127 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7128 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7129 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7130 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7131 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7135 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7136 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7137 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7139 "[" chars punct "]+" "[" chars "]"
7141 (concat ;; XEmacs 21.4 doesn't support POSIX.
7142 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7143 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7145 "Regular expression that matches URLs."
7146 :group 'gnus-article-buttons
7149 (defcustom gnus-button-valid-fqdn-regexp
7150 message-valid-fqdn-regexp
7151 "Regular expression that matches a valid FQDN."
7153 :group 'gnus-article-buttons
7156 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7157 (defcustom gnus-button-valid-localpart-regexp
7158 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7159 "Regular expression that matches a localpart of mail addresses or MIDs."
7161 :group 'gnus-article-buttons
7164 (defcustom gnus-button-man-handler 'manual-entry
7165 "Function to use for displaying man pages.
7166 The function must take at least one argument with a string naming the
7169 :type '(choice (function-item :tag "Man" manual-entry)
7170 (function-item :tag "Woman" woman)
7171 (function :tag "Other"))
7172 :group 'gnus-article-buttons)
7174 (defcustom gnus-button-mid-or-mail-regexp
7175 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7176 gnus-button-valid-fqdn-regexp
7178 "Regular expression that matches a message ID or a mail address."
7180 :group 'gnus-article-buttons
7183 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7184 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7185 Strings like this can be either a message ID or a mail address. If it is one
7186 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7187 message ID or a mail address, respectively. If this variable is set to the
7188 symbol `ask', always query the user what do do. If it is a function, this
7189 function will be called with the string as its only argument. The function
7190 must return `mid', `mail', `invalid' or `ask'."
7192 :group 'gnus-article-buttons
7193 :type '(choice (function-item :tag "Heuristic function"
7194 gnus-button-mid-or-mail-heuristic)
7199 (defcustom gnus-button-mid-or-mail-heuristic-alist
7200 '((-10.0 . ".+\\$.+@")
7203 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7204 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7205 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7206 (-1.0 . "^[^a-z]+@")
7208 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7209 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7210 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7211 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7214 (-1.0 . "^[0-9][0-9]")
7216 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7217 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7218 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7219 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7221 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7222 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7225 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7227 ;; compensation for TDMA dated mail addresses:
7228 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7230 (-20.0 . "\\.fsf@") ;; Gnus
7233 (-20.0 . "^alpine\\.")
7234 (-20.0 . "_-_") ;; Subject change in thread
7236 (-20.0 . "\\.ln@") ;; leafnode
7237 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7238 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7240 ;; (5.0 . "") ;; $local_part_len <= 7
7241 (10.0 . "^[^0-9]+@")
7242 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7243 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7246 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7248 (0.5 . "^[A-Z][a-z]")
7249 (0.5 . "^[A-Z][a-z][a-z]")
7250 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7251 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7252 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7254 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7255 address. The REGEXP is processed with `case-fold-search' set to nil."
7257 :group 'gnus-article-buttons
7258 :type '(repeat (cons (number :tag "Rate")
7259 (regexp :tag "Regexp"))))
7261 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7262 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7263 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7264 address, `ask' if unsure and `invalid' if the string is invalid."
7265 (let ((case-fold-search nil)
7266 (list gnus-button-mid-or-mail-heuristic-alist)
7267 (result 0) rate regexp lpartlen elem)
7269 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7270 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7271 ;; Certain special cases...
7274 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7275 "^[0-9]+\\.[0-9]+@compuserve\\|"
7276 "@public\\.gmane\\.org")
7278 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7279 (setq result 'mail))
7280 (when (string-match "@.*@\\| " mid-or-mail)
7281 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7282 (setq result 'invalid))
7283 ;; Nothing more to do, if result is not a number here...
7284 (when (numberp result)
7286 (setq elem (car list)
7290 (when (string-match regexp mid-or-mail)
7291 (setq result (+ result rate))
7293 9 "`%s' matched `%s', rate `%s', result `%s'."
7294 mid-or-mail regexp rate result)))
7295 (when (<= lpartlen 7)
7296 (setq result (+ result 5.0))
7297 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7298 mid-or-mail result))
7299 (when (>= lpartlen 12)
7300 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7302 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7303 ;; Long local part should contain realname if e-mail address,
7304 ;; too many digits: message-id.
7305 ;; $score -= 5.0 + 0.1 * $local_part_len;
7306 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7307 (setq result (+ result rate))
7309 9 "Many digits in `%s', rate `%s', result `%s'."
7310 mid-or-mail rate result))
7311 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7313 ;; Too few vowels [^aeiouy]{4,}.*\@
7314 (setq result (+ result -5.0))
7316 9 "Few vowels in `%s', rate `%s', result `%s'."
7317 mid-or-mail -5.0 result))
7319 (setq result (+ result 5.0))
7321 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7322 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7323 ;; Maybe we should make this a customizable alist: (condition . 'result)
7325 ((symbolp result) result)
7326 ;; Now convert number into proper results:
7327 ((< result -10.0) 'mid)
7328 ((> result 10.0) 'mail)
7331 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7332 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7333 (url-mid (concat "news" ":" mid-or-mail))
7334 (url-mailto (concat "mailto" ":" mid-or-mail)))
7335 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7336 (when (fboundp pref)
7338 ;; get rid of surrounding angles...
7340 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7341 (if (or (eq 'mid guessed) (eq 'mail guessed))
7345 (save-window-excursion
7346 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7349 (cond ((eq pref 'mid)
7350 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7351 (gnus-button-handle-news url-mid))
7353 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7354 (gnus-url-mailto url-mailto))
7355 (t (gnus-message 3 "Invalid string.")))))
7357 (defun gnus-button-handle-custom (fun arg)
7358 "Call function FUN on argument ARG.
7359 Both FUN and ARG are supposed to be strings. ARG will be passed
7360 as a symbol to FUN."
7361 (funcall (intern fun)
7362 (if (string-match "^customize-apropos" fun)
7366 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7368 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7371 (defun gnus-button-handle-describe-function (url)
7372 "Call `describe-function' when pushing the corresponding URL button."
7375 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7377 (defun gnus-button-handle-describe-variable (url)
7378 "Call `describe-variable' when pushing the corresponding URL button."
7381 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7383 (defun gnus-button-handle-symbol (url)
7384 "Display help on variable or function.
7385 Calls `describe-variable' or `describe-function'."
7386 (let ((sym (intern url)))
7388 ((fboundp sym) (describe-function sym))
7389 ((boundp sym) (describe-variable sym))
7390 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7392 (defun gnus-button-handle-describe-key (url)
7393 "Call `describe-key' when pushing the corresponding URL button."
7395 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7396 (keys (ignore-errors (eval `(kbd ,key-string)))))
7399 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7401 (defun gnus-button-handle-apropos (url)
7402 "Call `apropos' when pushing the corresponding URL button."
7403 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7405 (defun gnus-button-handle-apropos-command (url)
7406 "Call `apropos' when pushing the corresponding URL button."
7408 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7410 (defun gnus-button-handle-apropos-variable (url)
7411 "Call `apropos' when pushing the corresponding URL button."
7413 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7414 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7416 (defun gnus-button-handle-apropos-documentation (url)
7417 "Call `apropos' when pushing the corresponding URL button."
7419 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7420 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7422 (defun gnus-button-handle-library (url)
7423 "Call `locate-library' when pushing the corresponding URL button."
7424 (gnus-message 9 "url=`%s'" url)
7425 (let* ((lib (locate-library url))
7426 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7428 (gnus-message 1 "Cannot locale library `%s'." url)
7429 (find-file-read-only file))))
7431 (defcustom gnus-button-man-level 5
7432 "*Integer that says how many man-related buttons Gnus will show.
7433 The higher the number, the more buttons will appear and the more false
7434 positives are possible. Note that you can set this variable local to
7435 specific groups. Setting it higher in Unix groups is probably a good idea.
7436 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7437 how to set variables in specific groups."
7439 :group 'gnus-article-buttons
7440 :link '(custom-manual "(gnus)Group Parameters")
7443 (defcustom gnus-button-emacs-level 5
7444 "*Integer that says how many emacs-related buttons Gnus will show.
7445 The higher the number, the more buttons will appear and the more false
7446 positives are possible. Note that you can set this variable local to
7447 specific groups. Setting it higher in Emacs or Gnus related groups is
7448 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7449 `gnus-parameters' on how to set variables in specific groups."
7451 :group 'gnus-article-buttons
7452 :link '(custom-manual "(gnus)Group Parameters")
7455 (defcustom gnus-button-message-level 5
7456 "*Integer that says how many buttons for news or mail messages will appear.
7457 The higher the number, the more buttons will appear and the more false
7458 positives are possible."
7459 ;; mail addresses, MIDs, URLs for news, ...
7461 :group 'gnus-article-buttons
7464 (defcustom gnus-button-browse-level 5
7465 "*Integer that says how many buttons for browsing will appear.
7466 The higher the number, the more buttons will appear and the more false
7467 positives are possible."
7468 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7470 :group 'gnus-article-buttons
7473 (defcustom gnus-button-alist
7474 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7475 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7476 ((concat "\\b\\(nntp\\|news\\):\\("
7477 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7478 0 t gnus-button-handle-news 2)
7479 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7480 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7481 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7482 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7483 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7484 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7485 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7486 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7487 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7488 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7489 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7490 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7491 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7492 ;; RFC 2368 (The mailto URL scheme)
7493 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7494 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7495 ("\\bmailto:\\([^ \n\t]+\\)"
7496 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7497 ;; Info Konqueror style <info:/foo/bar baz>.
7498 ;; Must come before " Gnus home-grown style".
7499 ("\\binfo://?\\([^'\">\n\t]+\\)"
7500 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7501 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7502 ("\\binfo://\\([^'\">\n\t ]+\\)"
7503 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7504 ;; Info GNOME style <info:foo#bar_baz>
7505 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7506 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7507 ;; Info KDE style <info:(foo)bar baz>
7508 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7509 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7510 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7511 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7512 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7513 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7514 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7516 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7517 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7518 ;; Emacs help commands
7519 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7520 ;; regexp doesn't match arguments containing ` '.
7521 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7522 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7523 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7524 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7525 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7526 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7527 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7528 ;; The following entries may lead to many false positives so don't enable
7529 ;; them by default (use a high button level).
7530 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7531 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7532 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7533 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7534 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7535 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7536 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7537 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7538 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7539 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7540 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7541 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7542 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7543 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7544 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7545 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7546 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7547 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7548 ;; Unlike the other regexps we really have to require quoting
7549 ;; here to determine where it ends.
7550 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7551 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7552 ("<URL: *\\([^\n<>]*\\)>"
7553 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7554 ;; RFC 2396 (2.4.3., delims) ...
7555 ("\"URL: *\\([^\n\"]*\\)\""
7556 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7558 (gnus-button-url-regexp
7559 0 (>= gnus-button-browse-level 0) browse-url 0)
7561 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7562 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7563 gnus-button-handle-man 1)
7564 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7565 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7566 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7567 gnus-button-handle-man 1)
7568 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7569 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7570 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7571 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7572 ;; Recognizing patches to .el files. This is somewhat obscure,
7573 ;; but considering the percentage of Gnus users who hack Emacs
7575 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7576 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7577 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7578 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7579 ;; MID or mail: To avoid too many false positives we don't try to catch
7580 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7581 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7582 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7583 ;; so that non-ambiguous entries (see above) match first.
7584 (gnus-button-mid-or-mail-regexp
7585 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7586 "*Alist of regexps matching buttons in article bodies.
7588 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7589 REGEXP: is the string (case insensitive) matching text around the button (can
7590 also be Lisp expression evaluating to a string),
7591 BUTTON: is the number of the regexp grouping actually matching the button,
7592 FORM: is a Lisp expression which must eval to true for the button to
7594 CALLBACK: is the function to call when the user push this button, and each
7595 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7597 CALLBACK can also be a variable, in that case the value of that
7598 variable it the real callback function."
7599 :group 'gnus-article-buttons
7600 :type '(repeat (list (choice regexp variable sexp)
7601 (integer :tag "Button")
7603 (function :tag "Callback")
7606 (integer :tag "Regexp group")))))
7607 (put 'gnus-button-alist 'risky-local-variable t)
7609 (defcustom gnus-header-button-alist
7610 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7611 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7612 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7613 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7614 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7615 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7616 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7617 0 (>= gnus-button-browse-level 0) browse-url 0)
7618 ("^Subject:" gnus-button-url-regexp
7619 0 (>= gnus-button-browse-level 0) browse-url 0)
7620 ("^[^:]+:" gnus-button-url-regexp
7621 0 (>= gnus-button-browse-level 0) browse-url 0)
7622 ("^OpenPGP:.*url=" gnus-button-url-regexp
7623 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7624 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7625 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7626 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7627 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7628 "*Alist of headers and regexps to match buttons in article heads.
7630 This alist is very similar to `gnus-button-alist', except that each
7631 alist has an additional HEADER element first in each entry:
7633 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7635 HEADER is a regexp to match a header. For a fuller explanation, see
7636 `gnus-button-alist'."
7637 :group 'gnus-article-buttons
7638 :group 'gnus-article-headers
7639 :type '(repeat (list (regexp :tag "Header")
7640 (choice regexp variable)
7641 (integer :tag "Button")
7643 (function :tag "Callback")
7646 (integer :tag "Regexp group")))))
7647 (put 'gnus-header-button-alist 'risky-local-variable t)
7651 (defun gnus-article-push-button (event)
7652 "Check text under the mouse pointer for a callback function.
7653 If the text under the mouse pointer has a `gnus-callback' property,
7654 call it with the value of the `gnus-data' text property."
7656 (set-buffer (window-buffer (posn-window (event-start event))))
7657 (let* ((pos (posn-point (event-start event)))
7658 (data (get-text-property pos 'gnus-data))
7659 (fun (get-text-property pos 'gnus-callback)))
7662 (funcall fun data))))
7664 (defun gnus-article-press-button ()
7665 "Check text at point for a callback function.
7666 If the text at point has a `gnus-callback' property,
7667 call it with the value of the `gnus-data' text property."
7669 (let ((data (get-text-property (point) 'gnus-data))
7670 (fun (get-text-property (point) 'gnus-callback)))
7672 (funcall fun data))))
7674 (defun gnus-article-highlight (&optional force)
7675 "Highlight current article.
7676 This function calls `gnus-article-highlight-headers',
7677 `gnus-article-highlight-citation',
7678 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7679 do the highlighting. See the documentation for those functions."
7680 (interactive (list 'force))
7681 (gnus-article-highlight-headers)
7682 (gnus-article-highlight-citation force)
7683 (gnus-article-highlight-signature)
7684 (gnus-article-add-buttons)
7685 (gnus-article-add-buttons-to-head))
7687 (defun gnus-article-highlight-some (&optional force)
7688 "Highlight current article.
7689 This function calls `gnus-article-highlight-headers',
7690 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7691 do the highlighting. See the documentation for those functions."
7692 (interactive (list 'force))
7693 (gnus-article-highlight-headers)
7694 (gnus-article-highlight-signature)
7695 (gnus-article-add-buttons))
7697 (defun gnus-article-highlight-headers ()
7698 "Highlight article headers as specified by `gnus-header-face-alist'."
7700 (gnus-with-article-headers
7701 (let (regexp header-face field-face from hpoints fpoints)
7702 (dolist (entry gnus-header-face-alist)
7703 (goto-char (point-min))
7704 (setq regexp (concat "^\\("
7705 (if (string-equal "" (nth 0 entry))
7709 header-face (nth 1 entry)
7710 field-face (nth 2 entry))
7711 (while (and (re-search-forward regexp nil t)
7715 (unless (search-forward ":" nil t)
7717 (when (and header-face
7718 (not (memq (point) hpoints)))
7719 (push (point) hpoints)
7720 (gnus-put-text-property from (point) 'face header-face))
7721 (when (and field-face
7722 (not (memq (setq from (point)) fpoints)))
7724 (if (re-search-forward "^[^ \t]" nil t)
7726 (goto-char (point-max)))
7727 (gnus-put-text-property from (point) 'face field-face)))))))
7729 (defun gnus-article-highlight-signature ()
7730 "Highlight the signature in an article.
7731 It does this by highlighting everything after
7732 `gnus-signature-separator' using the face `gnus-signature'."
7734 (gnus-with-article-buffer
7735 (let ((inhibit-point-motion-hooks t))
7737 (when (and gnus-signature-face
7738 (gnus-article-narrow-to-signature))
7739 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7740 'face gnus-signature-face)
7742 (gnus-article-search-signature)
7743 (let ((start (match-beginning 0))
7744 (end (set-marker (make-marker) (1+ (match-end 0)))))
7745 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7748 (defun gnus-button-in-region-p (b e prop)
7749 "Say whether PROP exists in the region."
7750 (text-property-not-all b e prop nil))
7752 (defun gnus-article-add-buttons ()
7753 "Find external references in the article and make buttons of them.
7754 \"External references\" are things like Message-IDs and URLs, as
7755 specified by `gnus-button-alist'."
7757 (gnus-with-article-buffer
7758 (let ((inhibit-point-motion-hooks t)
7759 (case-fold-search t)
7760 (alist gnus-button-alist)
7762 ;; We skip the headers.
7765 (while (setq entry (pop alist))
7766 (setq regexp (eval (car entry)))
7768 (while (re-search-forward regexp nil t)
7769 (let ((start (match-beginning (nth 1 entry)))
7770 (end (match-end (nth 1 entry)))
7771 (from (match-beginning 0)))
7772 (when (and (eval (nth 2 entry))
7773 (not (gnus-button-in-region-p
7774 start end 'gnus-callback)))
7775 ;; That optional form returned non-nil, so we add the
7777 (setq from (set-marker (make-marker) from))
7778 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7779 (gnus-article-extend-url-button from start end))
7780 (gnus-article-add-button start end
7781 'gnus-button-push (list from entry))
7782 (gnus-put-text-property
7784 'gnus-string (buffer-substring-no-properties
7787 (defun gnus-article-extend-url-button (beg start end)
7788 "Extend url button if url is folded into two or more lines.
7789 Return non-nil if button is extended. BEG is a marker that points to
7790 the beginning position of a text containing url. START and END are
7791 the endpoints of a url button before it is extended. The concatenated
7792 url is put as the `gnus-button-url' overlay property on the button."
7793 (let ((opoint (point))
7794 (points (list start end))
7799 (not (looking-at "[\t ]*[\">]")))
7803 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7804 (buffer-substring (point-at-bol) start)))
7806 (setq url (list (buffer-substring start end))
7807 delim (if (match-beginning 1) ">" "\""))
7809 (setq regexp (concat
7810 (when (and (looking-at
7811 message-cite-prefix-regexp)
7812 (< (match-end 0) start))
7813 (regexp-quote (match-string 0)))
7815 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7819 (and (looking-at regexp)
7822 (push (or (match-string 2)
7825 (push (setq end (or (match-end 2)
7828 (push (or (match-beginning 2)
7829 (match-beginning 1))
7831 (match-beginning 2)))
7832 (let (gnus-article-mouse-face widget-mouse-face)
7834 (gnus-article-add-button (pop points) (pop points)
7835 'gnus-button-push beg)))
7836 (let ((overlay (gnus-make-overlay start end)))
7837 (gnus-overlay-put overlay 'evaporate t)
7838 (gnus-overlay-put overlay 'gnus-button-url
7839 (list (mapconcat 'identity (nreverse url) "")))
7840 (when gnus-article-mouse-face
7841 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7843 (goto-char opoint))))
7845 ;; Add buttons to the head of an article.
7846 (defun gnus-article-add-buttons-to-head ()
7847 "Add buttons to the head of the article."
7849 (gnus-with-article-headers
7851 (dolist (entry gnus-header-button-alist)
7852 ;; Each alist entry.
7853 (goto-char (point-min))
7854 (while (re-search-forward (car entry) nil t)
7855 ;; Each header matching the entry.
7856 (setq beg (match-beginning 0))
7857 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7858 (match-beginning 0))
7861 (while (re-search-forward (eval (nth 1 entry)) end t)
7862 ;; Each match within a header.
7863 (let* ((entry (cdr entry))
7864 (start (match-beginning (nth 1 entry)))
7865 (end (match-end (nth 1 entry)))
7866 (form (nth 2 entry)))
7867 (goto-char (match-end 0))
7869 (gnus-article-add-button
7870 start end (nth 3 entry)
7871 (buffer-substring (match-beginning (nth 4 entry))
7872 (match-end (nth 4 entry)))))))
7873 (goto-char end))))))
7875 ;;; External functions:
7877 (defun gnus-article-add-button (from to fun &optional data text)
7878 "Create a button between FROM and TO with callback FUN and data DATA."
7879 (when gnus-article-button-face
7880 (gnus-overlay-put (gnus-make-overlay from to nil t)
7881 'face gnus-article-button-face))
7882 (gnus-add-text-properties
7884 (nconc (and gnus-article-mouse-face
7885 (list gnus-mouse-face-prop gnus-article-mouse-face))
7886 (list 'gnus-callback fun)
7887 (and data (list 'gnus-data data))))
7888 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7889 :help-echo (or text "Follow the link")
7890 :keymap gnus-url-button-map
7891 :button-keymap gnus-widget-button-keymap))
7893 (defun gnus-article-copy-string ()
7894 "Copy the string in the button to the kill ring."
7896 (gnus-article-check-buffer)
7897 (let ((data (get-text-property (point) 'gnus-string)))
7901 (copy-region-as-kill (point-min) (point-max))
7902 (message "Copied %s" data)))))
7904 ;;; Internal functions:
7906 (defun gnus-article-set-globals ()
7907 (with-current-buffer gnus-summary-buffer
7908 (gnus-set-global-variables)))
7910 (defun gnus-signature-toggle (end)
7911 (gnus-with-article-buffer
7912 (let ((inhibit-point-motion-hooks t))
7913 (if (text-property-any end (point-max) 'article-type 'signature)
7915 (gnus-delete-wash-type 'signature)
7916 (gnus-remove-text-properties-when
7917 'article-type 'signature end (point-max)
7918 (cons 'article-type (cons 'signature
7919 gnus-hidden-properties))))
7920 (gnus-add-wash-type 'signature)
7921 (gnus-add-text-properties-when
7922 'article-type nil end (point-max)
7923 (cons 'article-type (cons 'signature
7924 gnus-hidden-properties)))))
7925 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7926 (gnus-set-mode-line 'article))))
7928 (defun gnus-button-push (marker-and-entry)
7929 ;; Push button starting at MARKER.
7931 (let* ((marker (car marker-and-entry))
7932 (entry (cadr marker-and-entry))
7933 (regexp (car entry))
7934 (inhibit-point-motion-hooks t))
7936 ;; This is obviously true, or something bad is happening :)
7937 ;; But we need it to have the match-data
7938 (when (looking-at (or (if (symbolp regexp)
7939 (symbol-value regexp)
7941 (let ((fun (nth 3 entry))
7942 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7943 (get-char-property marker 'gnus-button-url))
7944 (mapcar (lambda (group)
7945 (let ((string (match-string group)))
7946 (set-text-properties
7947 0 (length string) nil string)
7949 (nthcdr 4 entry)))))
7955 (fboundp (symbol-value fun)))
7956 (apply (symbol-value fun) args))
7958 (gnus-message 1 "You must define `%S' to use this button"
7959 (cons fun args)))))))))
7961 (defun gnus-parse-news-url (url)
7962 (let (scheme server port group message-id articles)
7965 (goto-char (point-min))
7966 (when (looking-at "\\([A-Za-z]+\\):")
7967 (setq scheme (match-string 1))
7968 (goto-char (match-end 0)))
7969 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7970 (setq server (match-string 1))
7971 (setq port (if (stringp (match-string 3))
7972 (string-to-number (match-string 3))
7974 (goto-char (match-end 0)))
7977 ((looking-at "\\(.*@.*\\)")
7978 (setq message-id (match-string 1)))
7979 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7980 (setq group (match-string 1)
7981 articles (split-string (match-string 2) "-")))
7982 ((looking-at "\\([^/]+\\)/?")
7983 (setq group (match-string 1)))
7985 (error "Unknown news URL syntax"))))
7986 (list scheme server port group message-id articles)))
7988 (defun gnus-button-handle-news (url)
7990 (destructuring-bind (scheme server port group message-id articles)
7991 (gnus-parse-news-url url)
7994 (with-current-buffer gnus-summary-buffer
7996 (let ((gnus-refer-article-method
7997 (nconc (list (list 'nntp server))
7998 gnus-refer-article-method))
7999 (nntp-port-number (or port "nntp")))
8000 (gnus-message 7 "Fetching %s with %s"
8001 message-id gnus-refer-article-method)
8002 (gnus-summary-refer-article message-id))
8003 (gnus-summary-refer-article message-id))))
8005 (gnus-button-fetch-group url)))))
8007 (defun gnus-button-patch (library line)
8008 "Visit an Emacs Lisp library LIBRARY on line LINE."
8010 (let ((file (locate-library (file-name-nondirectory library))))
8012 (error "Couldn't find library %s" library))
8014 (goto-char (point-min))
8015 (forward-line (1- (string-to-number line)))))
8017 (defun gnus-button-handle-man (url)
8019 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8020 (when (eq gnus-button-man-handler 'woman)
8021 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8022 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8023 (funcall gnus-button-man-handler url))
8025 (defun gnus-button-handle-info-url (url)
8026 "Fetch an info URL."
8027 (setq url (mm-subst-char-in-string ?+ ?\ url))
8029 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8030 (gnus-info-find-node
8031 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8033 ")" (gnus-url-unhex-string (match-string 2 url)))))
8034 ((string-match "([^)\"]+)[^\"]+" url)
8036 (gnus-replace-in-string
8037 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8038 (gnus-info-find-node url))
8039 (t (error "Can't parse %s" url))))
8041 (defun gnus-button-handle-info-url-gnome (url)
8042 "Fetch GNOME style info URL."
8043 (setq url (mm-subst-char-in-string ?_ ?\ url))
8044 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8045 (gnus-info-find-node
8047 (gnus-url-unhex-string
8048 (match-string 1 url))
8050 (or (gnus-url-unhex-string
8051 (match-string 2 url))
8053 (error "Can't parse %s" url)))
8055 (defun gnus-button-handle-info-url-kde (url)
8056 "Fetch KDE style info URL."
8057 (gnus-info-find-node (gnus-url-unhex-string url)))
8059 ;; (info) will autoload info.el
8060 (declare-function Info-menu "info" (menu-item &optional fork))
8061 (declare-function Info-index-next "info" (num))
8063 (defun gnus-button-handle-info-keystrokes (url)
8064 "Call `info' when pushing the corresponding URL button."
8065 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8066 (let (node indx comma)
8068 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8069 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8070 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8071 "\\(?:[ \t\n,]*\\)\\)?")
8073 (setq node (match-string 2 url)
8074 indx (match-string 3 url))
8075 (error "Can't parse %s" url))
8079 (when (> (length indx) 0)
8080 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8083 (setq comma (match-string 2 indx))
8084 (setq indx (match-string 1 indx))
8087 (dotimes (i (with-temp-buffer
8089 ;; Note: the XEmacs version of `how-many' takes
8090 ;; no optional argument.
8091 (goto-char (point-min))
8093 (Info-index-next 1)))
8096 (autoload 'pgg-snarf-keys-region "pgg")
8097 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8098 (declare-function pgg-display-output-buffer "pgg" (start end status))
8100 (defun gnus-button-openpgp (url)
8101 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8103 (mm-url-insert-file-contents-external url)
8104 (pgg-snarf-keys-region (point-min) (point-max))
8105 (pgg-display-output-buffer nil nil nil)))
8107 (defun gnus-button-message-id (message-id)
8109 (with-current-buffer gnus-summary-buffer
8110 (gnus-summary-refer-article message-id)))
8112 (defun gnus-button-fetch-group (address &rest ignore)
8113 "Fetch GROUP specified by ADDRESS."
8114 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8116 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8117 ;; for nntp:// and news://
8118 (setq address (match-string 3 address)))
8119 (if (not (string-match "[:/]" address))
8120 ;; This is just a simple group url.
8121 (gnus-group-read-ephemeral-group address gnus-select-method)
8124 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8126 (error "Can't parse %s" address)
8127 (gnus-group-read-ephemeral-group
8128 (match-string 4 address)
8129 `(nntp ,(match-string 1 address)
8130 (nntp-address ,(match-string 1 address))
8131 (nntp-port-number ,(if (match-end 3)
8132 (match-string 3 address)
8135 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8137 (defun gnus-url-parse-query-string (query &optional downcase)
8138 (let (retval pairs cur key val)
8139 (setq pairs (split-string query "&"))
8141 (setq cur (car pairs)
8143 (if (not (string-match "=" cur))
8145 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8146 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8148 (setq key (downcase key)))
8149 (setq cur (assoc key retval))
8151 (setcdr cur (cons val (cdr cur)))
8152 (setq retval (cons (list key val) retval)))))
8155 (defun gnus-url-mailto (url)
8156 ;; Send mail to someone
8157 (setq url (replace-regexp-in-string "\n" " " url))
8158 (when (string-match "mailto:/*\\(.*\\)" url)
8159 (setq url (substring url (match-beginning 1) nil)))
8160 (let (to args subject func)
8161 (setq args (gnus-url-parse-query-string
8162 (if (string-match "^\\?" url)
8164 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8165 (concat "to=" (match-string 1 url) "&"
8166 (match-string 2 url))
8167 (concat "to=" url))))
8168 subject (cdr-safe (assoc "subject" args)))
8171 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8174 (message-position-on-field (caar args)))
8175 (insert (gnus-replace-in-string
8176 (mapconcat 'identity (reverse (cdar args)) ", ")
8178 (setq args (cdr args)))
8181 (message-goto-subject))))
8183 (defun gnus-button-embedded-url (address)
8184 "Activate ADDRESS with `browse-url'."
8185 (browse-url (gnus-strip-whitespace address)))
8187 ;;; Next/prev buttons in the article buffer.
8189 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8190 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8192 (defvar gnus-prev-page-map
8193 (let ((map (make-sparse-keymap)))
8194 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8195 (define-key map "\r" 'gnus-button-prev-page)
8198 (defvar gnus-next-page-map
8199 (let ((map (make-sparse-keymap)))
8200 (define-key map gnus-mouse-2 'gnus-button-next-page)
8201 (define-key map "\r" 'gnus-button-next-page)
8204 (defun gnus-insert-prev-page-button ()
8206 (inhibit-read-only t))
8208 gnus-prev-page-line-format nil
8209 `(keymap ,gnus-prev-page-map
8211 gnus-callback gnus-article-button-prev-page
8212 article-type annotation))
8214 ;; Exclude a newline.
8217 (when gnus-article-button-face
8218 (gnus-overlay-put (gnus-make-overlay b e nil t)
8219 'face gnus-article-button-face))
8220 (widget-convert-button
8222 :action 'gnus-button-prev-page
8223 :button-keymap gnus-prev-page-map)))
8225 (defun gnus-button-next-page (&optional args more-args)
8226 "Go to the next page."
8228 (let ((win (selected-window)))
8229 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8230 (gnus-article-next-page)
8231 (select-window win)))
8233 (defun gnus-button-prev-page (&optional args more-args)
8234 "Go to the prev page."
8236 (let ((win (selected-window)))
8237 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8238 (gnus-article-prev-page)
8239 (select-window win)))
8241 (defun gnus-insert-next-page-button ()
8243 (inhibit-read-only t))
8244 (gnus-eval-format gnus-next-page-line-format nil
8245 `(keymap ,gnus-next-page-map
8247 gnus-callback gnus-article-button-next-page
8248 article-type annotation))
8250 ;; Exclude a newline.
8253 (when gnus-article-button-face
8254 (gnus-overlay-put (gnus-make-overlay b e nil t)
8255 'face gnus-article-button-face))
8256 (widget-convert-button
8258 :action 'gnus-button-next-page
8259 :button-keymap gnus-next-page-map)))
8261 (defun gnus-article-button-next-page (arg)
8262 "Go to the next page."
8264 (let ((win (selected-window)))
8265 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8266 (gnus-article-next-page)
8267 (select-window win)))
8269 (defun gnus-article-button-prev-page (arg)
8270 "Go to the prev page."
8272 (let ((win (selected-window)))
8273 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8274 (gnus-article-prev-page)
8275 (select-window win)))
8277 (defvar gnus-decode-header-methods
8278 '(mail-decode-encoded-word-region)
8279 "List of methods used to decode headers.
8281 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8282 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8283 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8284 whose names match REGEXP.
8287 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8288 mail-decode-encoded-word-region
8289 (\"chinese\" . rfc1843-decode-region))
8292 (defvar gnus-decode-header-methods-cache nil)
8294 (defun gnus-multi-decode-header (start end)
8295 "Apply the functions from `gnus-encoded-word-methods' that match."
8296 (unless (and gnus-decode-header-methods-cache
8297 (eq gnus-newsgroup-name
8298 (car gnus-decode-header-methods-cache)))
8299 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8300 (dolist (x gnus-decode-header-methods)
8302 (nconc gnus-decode-header-methods-cache (list x))
8303 (if (and gnus-newsgroup-name
8304 (string-match (car x) gnus-newsgroup-name))
8305 (nconc gnus-decode-header-methods-cache
8307 (let ((xlist gnus-decode-header-methods-cache))
8310 (narrow-to-region start end)
8312 (funcall (pop xlist) (point-min) (point-max))))))
8315 ;;; Treatment top-level handling.
8318 (defvar gnus-inhibit-article-treatments nil)
8320 (defun gnus-treat-article (gnus-treat-condition
8321 &optional part-number total-parts gnus-treat-type)
8322 (let ((gnus-treat-length (- (point-max) (point-min)))
8323 (alist gnus-treatment-function-alist)
8324 (article-goto-body-goes-to-point-min-p t)
8326 (or (not gnus-treat-type)
8328 (let ((list gnus-article-treat-types))
8330 (when (string-match (pop list) gnus-treat-type)
8331 (throw 'found t)))))))
8332 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8334 (gnus-run-hooks 'gnus-part-display-hook)
8335 (dolist (elem alist)
8338 (when (gnus-buffer-live-p gnus-summary-buffer)
8339 (set-buffer gnus-summary-buffer))
8340 (symbol-value (car elem))))
8341 (when (and (or (consp val)
8343 (or (not gnus-inhibit-article-treatments)
8344 (eq gnus-treat-condition 'head))
8345 (gnus-treat-predicate val)
8346 (or (not (get (car elem) 'highlight))
8349 (funcall (cadr elem)))))))
8351 ;; Dynamic variables.
8352 (defvar part-number)
8353 (defvar total-parts)
8354 (defvar gnus-treat-type)
8355 (defvar gnus-treat-condition)
8356 (defvar gnus-treat-length)
8358 (defun gnus-treat-predicate (val)
8362 (gnus-treat-condition
8363 (eq gnus-treat-condition val))
8365 (stringp (car val)))
8366 (apply 'gnus-or (mapcar `(lambda (s)
8367 (string-match s ,(or gnus-newsgroup-name "")))
8370 (let ((pred (pop val)))
8373 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8375 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8377 (not (gnus-treat-predicate (car val))))
8379 (equal (car val) gnus-treat-type))
8381 (error "%S is not a valid predicate" pred)))))
8389 (eq part-number total-parts))
8391 (< gnus-treat-length val))
8393 (error "%S is not a valid value" val))))
8395 (defun gnus-article-encrypt-body (protocol &optional n)
8396 "Encrypt the article body."
8399 (or gnus-article-encrypt-protocol
8400 (gnus-completing-read "Encrypt protocol"
8401 (mapcar 'car gnus-article-encrypt-protocol-alist)
8403 current-prefix-arg))
8404 ;; User might hit `K E' instead of `K e', so prompt once.
8405 (when (and gnus-article-encrypt-protocol
8407 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8408 (error "Encrypt aborted")))
8409 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8411 (error "Can't find the encrypt protocol %s" protocol))
8412 (if (member gnus-newsgroup-name '("nndraft:delayed"
8415 (error "Can't encrypt the article in group %s"
8416 gnus-newsgroup-name))
8417 (gnus-summary-iterate n
8418 (with-current-buffer gnus-summary-buffer
8419 (let ((mail-parse-charset gnus-newsgroup-charset)
8420 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8421 (summary-buffer gnus-summary-buffer)
8423 (gnus-set-global-variables)
8424 (when (gnus-group-read-only-p)
8425 (error "The current newsgroup does not support article encrypt"))
8426 (gnus-summary-show-article t)
8428 (or (mail-header-references gnus-current-headers) ""))
8429 (set-buffer gnus-article-buffer)
8430 (let* ((inhibit-read-only t)
8432 (mapcar (lambda (field)
8433 (and (save-restriction
8434 (message-narrow-to-head)
8435 (goto-char (point-min))
8436 (search-forward field nil t))
8438 (message-narrow-to-field)
8440 (delete-region (point-min) (point-max))
8442 '("Content-Type:" "Content-Transfer-Encoding:"
8443 "Content-Disposition:"))))
8444 (message-narrow-to-head)
8445 (message-remove-header "MIME-Version")
8446 (goto-char (point-max))
8447 (setq point (point))
8448 (insert (apply 'concat headers))
8450 (narrow-to-region point (point-max))
8451 (let ((message-options message-options))
8452 (message-options-set 'message-sender user-mail-address)
8453 (message-options-set 'message-recipients user-mail-address)
8454 (message-options-set 'message-sign-encrypt 'not)
8456 (goto-char (point-min))
8457 (insert "MIME-Version: 1.0\n")
8459 (gnus-summary-edit-article-done
8460 references nil summary-buffer t))
8461 (when gnus-keep-backlog
8462 (gnus-backlog-remove-article
8463 (car gnus-article-current) (cdr gnus-article-current)))
8464 (gnus-flush-original-article-buffer)
8465 (when gnus-use-cache
8466 (gnus-cache-update-article
8467 (car gnus-article-current) (cdr gnus-article-current))))))))
8469 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8470 "The following specs can be used:
8471 %t The security MIME type
8474 %D Details if button is pressed")
8476 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8477 "The following specs can be used:
8478 %t The security MIME type
8481 %D Details if button is pressed")
8483 (defvar gnus-mime-security-button-line-format-alist
8484 '((?t gnus-tmp-type ?s)
8485 (?i gnus-tmp-info ?s)
8486 (?d gnus-tmp-details ?s)
8487 (?D gnus-tmp-pressed-details ?s)))
8489 (defvar gnus-mime-security-button-commands
8490 '((gnus-article-press-button "\r" "Show Detail")
8494 (gnus-mime-security-save-part "o" "Save...")
8503 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8506 (defvar gnus-mime-security-button-map
8507 (let ((map (make-sparse-keymap)))
8508 (define-key map gnus-mouse-2 'gnus-article-push-button)
8509 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8510 (dolist (c gnus-mime-security-button-commands)
8511 (define-key map (cadr c) (car c)))
8515 gnus-mime-security-button-menu gnus-mime-security-button-map
8516 "Security button menu."
8520 (unless (eq (car c) 'undefined)
8521 (vector (caddr c) (car c) :active t)))
8522 gnus-mime-security-button-commands))))
8524 (defun gnus-mime-security-button-menu (event prefix)
8525 "Construct a context-sensitive menu of security commands."
8526 (interactive "e\nP")
8527 (save-window-excursion
8528 (let ((pos (event-start event)))
8529 (select-window (posn-window pos))
8530 (goto-char (posn-point pos))
8531 (gnus-article-check-buffer)
8532 (popup-menu gnus-mime-security-button-menu nil prefix))))
8534 (defvar gnus-mime-security-details-buffer nil)
8536 (defvar gnus-mime-security-button-pressed nil)
8538 (defvar gnus-mime-security-show-details-inline t
8539 "If non-nil, show details in the article buffer.")
8541 (defun gnus-mime-security-verify-or-decrypt (handle)
8542 (mm-remove-parts (cdr handle))
8543 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8544 point (inhibit-read-only t))
8546 (goto-char (car region)))
8547 (setq point (point))
8548 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8549 (let* ((mm-verify-option 'known)
8550 (mm-decrypt-option 'known)
8551 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8552 (unless (eq nparts (cdr handle))
8553 (mm-destroy-parts (cdr handle))
8554 (setcdr handle nparts))))
8555 (gnus-mime-display-security handle)
8557 (delete-region (point) (cdr region))
8558 (set-marker (car region) nil)
8559 (set-marker (cdr region) nil))
8562 (defun gnus-mime-security-show-details (handle)
8563 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8565 (gnus-message 5 "No details.")
8566 (if gnus-mime-security-show-details-inline
8567 (let ((gnus-mime-security-button-pressed
8568 (not (get-text-property (point) 'gnus-mime-details)))
8569 (gnus-mime-security-button-line-format
8570 (get-text-property (point) 'gnus-line-format))
8571 (inhibit-read-only t))
8573 (while (eq (get-text-property (point) 'gnus-line-format)
8574 gnus-mime-security-button-line-format)
8578 (narrow-to-region (point) (point))
8579 (gnus-insert-mime-security-button handle))
8580 (delete-region (point)
8581 (or (text-property-not-all
8584 gnus-mime-security-button-line-format)
8587 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8588 (with-current-buffer gnus-mime-security-details-buffer
8591 (setq gnus-mime-security-details-buffer
8592 (gnus-get-buffer-create "*MIME Security Details*")))
8593 (with-current-buffer gnus-mime-security-details-buffer
8595 (goto-char (point-min)))
8596 (pop-to-buffer gnus-mime-security-details-buffer)))))
8598 (defun gnus-mime-security-press-button (handle)
8600 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8601 (gnus-mime-security-show-details handle)
8602 (gnus-mime-security-verify-or-decrypt handle))))
8604 (defun gnus-insert-mime-security-button (handle &optional displayed)
8605 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8608 (or (nth 2 (assoc protocol mm-verify-function-alist))
8609 (nth 2 (assoc protocol mm-decrypt-function-alist))
8611 (if (equal (car handle) "multipart/signed")
8612 " Signed" " Encrypted")
8615 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8618 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8619 gnus-tmp-pressed-details
8621 (setq gnus-tmp-details
8622 (if gnus-tmp-details
8623 (concat "\n" gnus-tmp-details)
8625 (setq gnus-tmp-pressed-details
8626 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8631 gnus-mime-security-button-line-format
8632 gnus-mime-security-button-line-format-alist
8633 `(keymap ,gnus-mime-security-button-map
8634 gnus-callback gnus-mime-security-press-button
8635 gnus-line-format ,gnus-mime-security-button-line-format
8636 gnus-mime-details ,gnus-mime-security-button-pressed
8637 article-type annotation
8640 ;; Exclude a newline.
8643 (when gnus-article-button-face
8644 (gnus-overlay-put (gnus-make-overlay b e nil t)
8645 'face gnus-article-button-face))
8646 (widget-convert-button
8649 :action 'gnus-widget-press-button
8650 :button-keymap gnus-mime-security-button-map
8653 ;; Needed to properly clear the message due to a bug in
8654 ;; wid-edit (XEmacs only).
8655 (when (boundp 'help-echo-owns-message)
8656 (setq help-echo-owns-message t))
8658 "%S: show detail; %S: more options"
8659 (aref gnus-mouse-2 0)
8660 (aref gnus-down-mouse-3 0))))))
8662 (defun gnus-mime-display-security (handle)
8664 (narrow-to-region (point) (point))
8665 (unless (gnus-unbuttonized-mime-type-p (car handle))
8666 (gnus-insert-mime-security-button handle))
8667 (gnus-mime-display-part (cadr handle))
8670 (unless (gnus-unbuttonized-mime-type-p (car handle))
8671 (let ((gnus-mime-security-button-line-format
8672 gnus-mime-security-button-end-line-format))
8673 (gnus-insert-mime-security-button handle)))
8674 (mm-set-handle-multipart-parameter
8676 (cons (set-marker (make-marker) (point-min))
8677 (set-marker (make-marker) (point-max))))
8678 (goto-char (point-max))))
8680 (defun gnus-mime-security-run-function (function)
8681 "Run FUNCTION with the security part under point."
8682 (gnus-article-check-buffer)
8683 (let ((data (get-text-property (point) 'gnus-data))
8685 (when (and (stringp (car-safe data))
8686 (setq buffer (mm-handle-multipart-original-buffer data))
8687 (setq handle (cadr data)))
8688 (if (bufferp (mm-handle-buffer handle))
8690 (setq handle (cons buffer (copy-sequence (cdr handle))))
8691 (mm-handle-set-undisplayer handle nil))
8692 (setq handle (mm-make-handle
8694 (mm-handle-multipart-ctl-parameter handle 'protocol)
8695 nil nil nil nil nil nil)))
8696 (funcall function handle))))
8698 (defun gnus-mime-security-save-part ()
8699 "Save the security part under point."
8701 (gnus-mime-security-run-function 'mm-save-part))
8703 (defun gnus-mime-security-pipe-part ()
8704 "Pipe the security part under point to a process."
8706 (gnus-mime-security-run-function 'mm-pipe-part))
8712 (run-hooks 'gnus-art-load-hook)
8714 ;;; gnus-art.el ends here