1 ;;; gnus-art.el --- article mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
34 (defvar tool-bar-map))
44 (when (static-if (featurep 'xemacs)
45 (console-on-window-system-p)
47 (require 'mime-image))
50 ;; Avoid byte-compile warnings.
60 (autoload 'gnus-msg-mail "gnus-msg" nil t)
61 (autoload 'gnus-button-mailto "gnus-msg")
62 (autoload 'gnus-button-reply "gnus-msg" nil t)
63 (autoload 'ansi-color-apply-on-region "ansi-color")
65 (defgroup gnus-article nil
67 :link '(custom-manual "(gnus)The Article Buffer")
70 (defgroup gnus-article-treat nil
71 "Treating article parts."
72 :link '(custom-manual "(gnus)Article Hiding")
75 (defgroup gnus-article-hiding nil
76 "Hiding article parts."
77 :link '(custom-manual "(gnus)Article Hiding")
80 (defgroup gnus-article-highlight nil
81 "Article highlighting."
82 :link '(custom-manual "(gnus)Article Highlighting")
86 (defgroup gnus-article-signature nil
88 :link '(custom-manual "(gnus)Article Signature")
91 (defgroup gnus-article-headers nil
93 :link '(custom-manual "(gnus)Hiding Headers")
96 (defgroup gnus-article-washing nil
97 "Special commands on articles."
98 :link '(custom-manual "(gnus)Article Washing")
101 (defgroup gnus-article-emphasis nil
102 "Fontisizing articles."
103 :link '(custom-manual "(gnus)Article Fontisizing")
104 :group 'gnus-article)
106 (defgroup gnus-article-saving nil
108 :link '(custom-manual "(gnus)Saving Articles")
109 :group 'gnus-article)
111 (defgroup gnus-article-mime nil
112 "Worshiping the MIME wonder."
113 :link '(custom-manual "(gnus)Using MIME")
114 :group 'gnus-article)
116 (defgroup gnus-article-buttons nil
117 "Pushable buttons in the article buffer."
118 :link '(custom-manual "(gnus)Article Buttons")
119 :group 'gnus-article)
121 (defgroup gnus-article-various nil
122 "Other article options."
123 :link '(custom-manual "(gnus)Misc Article")
124 :group 'gnus-article)
126 (defcustom gnus-ignored-headers
129 (concat "^" header ":"))
130 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
131 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
132 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
133 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
134 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
135 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
136 "X-Attribution" "X-Originating-IP" "Delivered-To"
137 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
138 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
139 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
140 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
141 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
142 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
143 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
144 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
145 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
146 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
147 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
148 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
149 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
150 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
151 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
152 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
153 "List-[A-Za-z]+" "X-Listprocessor-Version"
154 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
155 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
156 "X-Received" "Content-length" "X-precedence"
157 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
158 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
159 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
160 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
161 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
162 "X-Content-length" "X-Posting-Agent" "Original-Received"
163 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
164 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
165 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
166 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
167 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
168 "*All headers that start with this regexp will be hidden.
169 This variable can also be a list of regexps of headers to be ignored.
170 If `gnus-visible-headers' is non-nil, this variable will be ignored."
171 :type '(choice :custom-show nil
174 :group 'gnus-article-hiding)
176 (defcustom gnus-visible-headers
177 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:"
178 "*All headers that do not match this regexp will be hidden.
179 This variable can also be a list of regexp of headers to remain visible.
180 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
181 :type '(repeat :value-to-internal (lambda (widget value)
182 (custom-split-regexp-maybe value))
183 :match (lambda (widget value)
185 (widget-editable-list-match widget value)))
187 :group 'gnus-article-hiding)
189 (defcustom gnus-sorted-header-list
190 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
191 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
192 "*This variable is a list of regular expressions.
193 If it is non-nil, headers that match the regular expressions will
194 be placed first in the article buffer in the sequence specified by
196 :type '(repeat regexp)
197 :group 'gnus-article-hiding)
199 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
200 "Headers that are only to be displayed if they have interesting data.
201 Possible values in this list are:
203 'empty Headers with no content.
204 'newsgroups Newsgroup identical to Gnus group.
205 'to-address To identical to To-address.
206 'to-list To identical to To-list.
207 'cc-list CC identical to To-list.
208 'followup-to Followup-to identical to Newsgroups.
209 'reply-to Reply-to identical to From.
210 'date Date less than four days old.
211 'long-to To and/or Cc longer than 1024 characters.
212 'many-to Multiple To and/or Cc."
213 :type '(set (const :tag "Headers with no content." empty)
214 (const :tag "Newsgroups identical to Gnus group." newsgroups)
215 (const :tag "To identical to To-address." to-address)
216 (const :tag "To identical to To-list." to-list)
217 (const :tag "CC identical to To-list." cc-list)
218 (const :tag "Followup-to identical to Newsgroups." followup-to)
219 (const :tag "Reply-to identical to From." reply-to)
220 (const :tag "Date less than four days old." date)
221 (const :tag "To and/or Cc longer than 1024 characters." long-to)
222 (const :tag "Multiple To and/or Cc headers." many-to))
223 :group 'gnus-article-hiding)
225 (defcustom gnus-article-skip-boring nil
226 "Skip over text that is not worth reading.
227 By default, if you set this t, then Gnus will display citations and
228 signatures, but will never scroll down to show you a page consisting
229 only of boring text. Boring text is controlled by
230 `gnus-article-boring-faces'."
232 :group 'gnus-article-hiding)
234 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
235 "Regexp matching signature separator.
236 This can also be a list of regexps. In that case, it will be checked
237 from head to tail looking for a separator. Searches will be done from
238 the end of the buffer."
239 :type '(repeat string)
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."
250 :type '(choice (integer :value 200)
252 (function :value fun)
253 (regexp :value ".*"))
254 :group 'gnus-article-signature)
256 (defcustom gnus-hidden-properties '(invisible t intangible t)
257 "Property list to use for hiding text."
259 :group 'gnus-article-hiding)
261 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
262 ;; frames in a session.
263 (defcustom gnus-article-x-face-command
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 ((and (fboundp 'image-type-available-p)
273 (module-installed-p 'x-face-e21))
274 'x-face-decode-message-header)
275 ((gnus-image-type-available-p 'pbm)
276 'gnus-display-x-face-in-from)
278 (module-installed-p 'x-face-mule))
279 'x-face-mule-gnus-article-display-x-face)
281 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
283 "*String or function to be executed to display an X-Face header.
284 If it is a string, the command will be executed in a sub-shell
285 asynchronously. The compressed face will be piped to this command."
287 ,@(let (x-face-e21 x-face-mule)
288 (if (featurep 'xemacs)
290 (setq x-face-e21 (module-installed-p 'x-face-e21)
291 x-face-mule (module-installed-p 'x-face-mule)))
295 (if (or (gnus-image-type-available-p 'xface)
296 (gnus-image-type-available-p 'pbm))
297 '(function-item gnus-display-x-face-in-from))
299 (fboundp 'image-type-available-p))
301 :tag "x-face-decode-message-header (x-face-e21)"
302 x-face-decode-message-header))
305 x-face-mule-gnus-article-display-x-face))
309 :group 'gnus-article-washing)
311 (defcustom gnus-article-x-face-too-ugly nil
312 "Regexp matching posters whose face shouldn't be shown automatically."
313 :type '(choice regexp (const nil))
314 :group 'gnus-article-washing)
316 (defcustom gnus-article-banner-alist nil
317 "Banner alist for stripping.
319 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
321 :type '(repeat (cons symbol regexp))
322 :group 'gnus-article-washing)
324 (gnus-define-group-parameter
327 "Alist of regexps (to match group names) and banner."
328 :variable-group gnus-article-washing
330 '(choice :tag "Banner"
332 (const :tag "Remove signature" signature)
333 (symbol :tag "Item in `gnus-article-banner-alist'" none)
335 (const :tag "None" nil))
337 "If non-nil, specify how to remove `banners' from articles.
339 Symbol `signature' means to remove signatures delimited by
340 `gnus-signature-separator'. Any other symbol is used to look up a
341 regular expression to match the banner in `gnus-article-banner-alist'.
342 A string is used as a regular expression to match the banner
345 (defcustom gnus-article-address-banner-alist nil
346 "Alist of mail addresses and banners.
347 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
348 to match a mail address in the From: header, BANNER is one of a symbol
349 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
350 If ADDRESS matches author's mail address, it will remove things like
351 advertisements. For example:
353 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
357 (regexp :tag "Address")
358 (choice :tag "Banner" :value nil
359 (const :tag "Remove signature" signature)
360 (symbol :tag "Item in `gnus-article-banner-alist'" none)
362 (const :tag "None" nil))))
363 :group 'gnus-article-washing)
365 (defcustom gnus-emphasis-alist
367 "\\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")
372 ("_/" "/_" underline-italic)
373 ("_\\*" "\\*_" underline-bold)
374 ("\\*/" "/\\*" bold-italic)
375 ("_\\*/" "/\\*_" underline-bold-italic))))
379 (format format (car spec) (car (cdr spec)))
380 2 3 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
382 ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
383 2 3 gnus-emphasis-strikethru)
384 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
385 2 3 gnus-emphasis-underline)))
386 "*Alist that says how to fontify certain phrases.
387 Each item looks like this:
389 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
391 The first element is a regular expression to be matched. The second
392 is a number that says what regular expression grouping used to find
393 the entire emphasized word. The third is a number that says what
394 regexp grouping should be displayed and highlighted. The fourth
395 is the face used for highlighting."
396 :type '(repeat (list :value ("" 0 0 default)
398 (integer :tag "Match group")
399 (integer :tag "Emphasize group")
401 :group 'gnus-article-emphasis)
403 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
404 "A regexp to describe whitespace which should not be emphasized.
405 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
406 The former avoids underlining of leading and trailing whitespace,
407 and the latter avoids underlining any whitespace at all."
409 :group 'gnus-article-emphasis
412 (defface gnus-emphasis-bold '((t (:bold t)))
413 "Face used for displaying strong emphasized text (*word*)."
414 :group 'gnus-article-emphasis)
416 (defface gnus-emphasis-italic '((t (:italic t)))
417 "Face used for displaying italic emphasized text (/word/)."
418 :group 'gnus-article-emphasis)
420 (defface gnus-emphasis-underline '((t (:underline t)))
421 "Face used for displaying underlined emphasized text (_word_)."
422 :group 'gnus-article-emphasis)
424 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
425 "Face used for displaying underlined bold emphasized text (_*word*_)."
426 :group 'gnus-article-emphasis)
428 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
429 "Face used for displaying underlined italic emphasized text (_/word/_)."
430 :group 'gnus-article-emphasis)
432 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
433 "Face used for displaying bold italic emphasized text (/*word*/)."
434 :group 'gnus-article-emphasis)
436 (defface gnus-emphasis-underline-bold-italic
437 '((t (:bold t :italic t :underline t)))
438 "Face used for displaying underlined bold italic emphasized text.
439 Example: (_/*word*/_)."
440 :group 'gnus-article-emphasis)
442 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
443 '((t (:strikethru t)))
444 '((t (:strike-through t))))
445 "Face used for displaying strike-through text (-word-)."
446 :group 'gnus-article-emphasis)
448 (defface gnus-emphasis-highlight-words
449 '((t (:background "black" :foreground "yellow")))
450 "Face used for displaying highlighted words."
451 :group 'gnus-article-emphasis)
453 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z"
454 "Format for display of Date headers in article bodies.
455 See `format-time-string' for the possible values.
457 The variable can also be function, which should return a complete Date
458 header. The function is called with one argument, the time, which can
459 be fed to `format-time-string'."
460 :type '(choice string symbol)
461 :link '(custom-manual "(gnus)Article Date")
462 :group 'gnus-article-washing)
465 (autoload 'mail-extract-address-components "mail-extr"))
467 (defcustom gnus-save-all-headers t
468 "*If non-nil, don't remove any headers before saving."
469 :group 'gnus-article-saving
472 (defcustom gnus-prompt-before-saving 'always
473 "*This variable says how much prompting is to be done when saving articles.
474 If it is nil, no prompting will be done, and the articles will be
475 saved to the default files. If this variable is `always', each and
476 every article that is saved will be preceded by a prompt, even when
477 saving large batches of articles. If this variable is neither nil not
478 `always', there the user will be prompted once for a file name for
479 each invocation of the saving commands."
480 :group 'gnus-article-saving
481 :type '(choice (item always)
482 (item :tag "never" nil)
483 (sexp :tag "once" :format "%t\n" :value t)))
485 (defcustom gnus-saved-headers gnus-visible-headers
486 "Headers to keep if `gnus-save-all-headers' is nil.
487 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
488 If that variable is nil, however, all headers that match this regexp
489 will be kept while the rest will be deleted before saving."
490 :group 'gnus-article-saving
493 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
494 "A function to save articles in your favourite format.
495 The function must be interactively callable (in other words, it must
496 be an Emacs command).
498 Gnus provides the following functions:
500 * gnus-summary-save-in-rmail (Rmail format)
501 * gnus-summary-save-in-mail (Unix mail format)
502 * gnus-summary-save-in-folder (MH folder)
503 * gnus-summary-save-in-file (article format)
504 * gnus-summary-save-body-in-file (article body)
505 * gnus-summary-save-in-vm (use VM's folder format)
506 * gnus-summary-write-to-file (article format -- overwrite)."
507 :group 'gnus-article-saving
508 :type '(radio (function-item gnus-summary-save-in-rmail)
509 (function-item gnus-summary-save-in-mail)
510 (function-item gnus-summary-save-in-folder)
511 (function-item gnus-summary-save-in-file)
512 (function-item gnus-summary-save-body-in-file)
513 (function-item gnus-summary-save-in-vm)
514 (function-item gnus-summary-write-to-file)))
516 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
517 "A function generating a file name to save articles in Rmail format.
518 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
519 :group 'gnus-article-saving
522 (defcustom gnus-mail-save-name 'gnus-plain-save-name
523 "A function generating a file name to save articles in Unix mail format.
524 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
525 :group 'gnus-article-saving
528 (defcustom gnus-folder-save-name 'gnus-folder-save-name
529 "A function generating a file name to save articles in MH folder.
530 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
531 :group 'gnus-article-saving
534 (defcustom gnus-file-save-name 'gnus-numeric-save-name
535 "A function generating a file name to save articles in article format.
536 The function is called with NEWSGROUP, HEADERS, and optional
538 :group 'gnus-article-saving
541 (defcustom gnus-split-methods
542 '((gnus-article-archive-name)
543 (gnus-article-nndoc-name))
544 "*Variable used to suggest where articles are to be saved.
545 For instance, if you would like to save articles related to Gnus in
546 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
547 you could set this variable to something like:
549 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
550 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
552 This variable is an alist where the where the key is the match and the
553 value is a list of possible files to save in if the match is non-nil.
555 If the match is a string, it is used as a regexp match on the
556 article. If the match is a symbol, that symbol will be funcalled
557 from the buffer of the article to be saved with the newsgroup as the
558 parameter. If it is a list, it will be evaled in the same buffer.
560 If this form or function returns a string, this string will be used as
561 a possible file name; and if it returns a non-nil list, that list will
562 be used as possible file names."
563 :group 'gnus-article-saving
564 :type '(repeat (choice (list :value (fun) function)
565 (cons :value ("" "") regexp (repeat string))
568 (defcustom gnus-article-display-method-for-mime
569 'gnus-article-display-mime-message
570 "Function to display a MIME message.
571 The function is called from the article buffer."
572 :group 'gnus-article-mime
575 (defcustom gnus-article-display-method-for-traditional
576 'gnus-article-display-traditional-message
577 "*Function to display a traditional message.
578 The function is called from the article buffer."
579 :group 'gnus-article-mime
582 (defcustom gnus-page-delimiter "^\^L"
583 "*Regexp describing what to use as article page delimiters.
584 The default value is \"^\^L\", which is a form linefeed at the
585 beginning of a line."
587 :group 'gnus-article-various)
589 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
590 "*The format specification for the article mode line.
591 See `gnus-summary-mode-line-format' for a closer description.
593 The following additional specs are available:
595 %w The article washing status.
596 %m The number of MIME parts in the article."
598 :group 'gnus-article-various)
600 (defcustom gnus-article-mode-hook nil
601 "*A hook for Gnus article mode."
603 :group 'gnus-article-various)
605 (when (featurep 'xemacs)
606 ;; Extracted from gnus-xmas-define in order to preserve user settings
607 (when (fboundp 'turn-off-scroll-in-place)
608 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
609 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
610 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
612 (defcustom gnus-article-menu-hook nil
613 "*Hook run after the creation of the article mode menu."
615 :group 'gnus-article-various)
617 (defcustom gnus-article-prepare-hook nil
618 "*A hook called after an article has been prepared in the article buffer."
620 :group 'gnus-article-various)
622 (make-obsolete-variable 'gnus-article-hide-pgp-hook
623 "This variable is obsolete in Gnus 5.10.")
625 (defcustom gnus-article-button-face 'bold
626 "Face used for highlighting buttons in the article buffer.
628 An article button is a piece of text that you can activate by pressing
629 `RET' or `mouse-2' above it."
631 :group 'gnus-article-buttons)
633 (defcustom gnus-article-mouse-face 'highlight
634 "Face used for mouse highlighting in the article buffer.
636 Article buttons will be displayed in this face when the cursor is
639 :group 'gnus-article-buttons)
641 (defcustom gnus-signature-face 'gnus-signature-face
642 "Face used for highlighting a signature in the article buffer.
643 Obsolete; use the face `gnus-signature-face' for customizations instead."
645 :group 'gnus-article-highlight
646 :group 'gnus-article-signature)
648 (defface gnus-signature-face
651 "Face used for highlighting a signature in the article buffer."
652 :group 'gnus-article-highlight
653 :group 'gnus-article-signature)
655 (defface gnus-header-from-face
658 (:foreground "spring green"))
661 (:foreground "red3"))
664 "Face used for displaying from headers."
665 :group 'gnus-article-headers
666 :group 'gnus-article-highlight)
668 (defface gnus-header-subject-face
671 (:foreground "SeaGreen3"))
674 (:foreground "red4"))
676 (:bold t :italic t)))
677 "Face used for displaying subject headers."
678 :group 'gnus-article-headers
679 :group 'gnus-article-highlight)
681 (defface gnus-header-newsgroups-face
684 (:foreground "yellow" :italic t))
687 (:foreground "MidnightBlue" :italic t))
690 "Face used for displaying newsgroups headers.
691 In the default setup this face is only used for crossposted
693 :group 'gnus-article-headers
694 :group 'gnus-article-highlight)
696 (defface gnus-header-name-face
699 (:foreground "SeaGreen"))
702 (:foreground "maroon"))
705 "Face used for displaying header names."
706 :group 'gnus-article-headers
707 :group 'gnus-article-highlight)
709 (defface gnus-header-content-face
712 (:foreground "forest green" :italic t))
715 (:foreground "indianred4" :italic t))
718 "Face used for displaying header content."
719 :group 'gnus-article-headers
720 :group 'gnus-article-highlight)
722 (defcustom gnus-header-face-alist
723 '(("From" nil gnus-header-from-face)
724 ("Subject" nil gnus-header-subject-face)
725 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
726 ("" gnus-header-name-face gnus-header-content-face))
727 "*Controls highlighting of article headers.
729 An alist of the form (HEADER NAME CONTENT).
731 HEADER is a regular expression which should match the name of a
732 header and NAME and CONTENT are either face names or nil.
734 The name of each header field will be displayed using the face
735 specified by the first element in the list where HEADER matches
736 the header name and NAME is non-nil. Similarly, the content will
737 be displayed by the first non-nil matching CONTENT face."
738 :group 'gnus-article-headers
739 :group 'gnus-article-highlight
740 :type '(repeat (list (regexp :tag "Header")
742 (item :tag "skip" nil)
743 (face :value default))
744 (choice :tag "Content"
745 (item :tag "skip" nil)
746 (face :value default)))))
748 (defcustom gnus-article-decode-hook
749 '(article-decode-group-name article-decode-idna-rhs)
750 "*Hook run to decode charsets in articles."
751 :group 'gnus-article-headers
754 (defcustom gnus-display-mime-function 'gnus-display-mime
755 "Function to display MIME articles."
756 :group 'gnus-article-mime
759 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
760 "Function used to decode headers.")
762 (defvar gnus-article-dumbquotes-map
782 "Table for MS-to-Latin1 translation.")
784 (defcustom gnus-ignored-mime-types nil
785 "List of MIME types that should be ignored by Gnus."
787 :group 'gnus-article-mime
788 :type '(repeat regexp))
790 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
791 "List of MIME types that should not be given buttons when rendered inline.
792 See also `gnus-buttonized-mime-types' which may override this variable.
793 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
795 :group 'gnus-article-mime
796 :type '(repeat regexp))
798 (defcustom gnus-buttonized-mime-types nil
799 "List of MIME types that should be given buttons when rendered inline.
800 If set, this variable overrides `gnus-unbuttonized-mime-types'.
801 To see e.g. security buttons you could set this to
802 `(\"multipart/signed\")'.
803 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
805 :group 'gnus-article-mime
806 :type '(repeat regexp))
808 (defcustom gnus-inhibit-mime-unbuttonizing nil
809 "If non-nil, all MIME parts get buttons.
810 When nil (the default value), then some MIME parts do not get buttons,
811 as described by the variables `gnus-buttonized-mime-types' and
812 `gnus-unbuttonized-mime-types'."
816 (defcustom gnus-body-boundary-delimiter "_"
817 "String used to delimit header and body.
818 This variable is used by `gnus-article-treat-body-boundary' which can
819 be controlled by `gnus-treat-body-boundary'."
820 :group 'gnus-article-various
821 :type '(choice (item :tag "None" :value nil)
824 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces")
825 "Defines the location of the faces database.
826 For information on obtaining this database of pretty pictures, please
827 see http://www.cs.indiana.edu/picons/ftp/index.html"
828 :type '(repeat directory)
829 :link '(url-link :tag "download"
830 "http://www.cs.indiana.edu/picons/ftp/index.html")
831 :link '(custom-manual "(gnus)Picons")
834 (defun gnus-picons-installed-p ()
835 "Say whether picons are installed on your machine."
836 (let ((installed nil))
837 (dolist (database gnus-picon-databases)
838 (when (file-exists-p database)
842 (defcustom gnus-article-mime-part-function nil
843 "Function called with a MIME handle as the argument.
844 This is meant for people who want to do something automatic based
845 on parts -- for instance, adding Vcard info to a database."
846 :group 'gnus-article-mime
849 (defcustom gnus-mime-multipart-functions nil
850 "An alist of MIME types to functions to display them."
852 :group 'gnus-article-mime
855 (defcustom gnus-article-date-lapsed-new-header nil
856 "Whether the X-Sent and Date headers can coexist.
857 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
858 either replace the old \"Date:\" header (if this variable is nil), or
859 be added below it (otherwise)."
861 :group 'gnus-article-headers
864 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
865 "Function called with a MIME handle as the argument.
866 This is meant for people who want to view first matched part.
867 For `undisplayed-alternative' (default), the first undisplayed
868 part or alternative part is used. For `undisplayed', the first
869 undisplayed part is used. For a function, the first part which
870 the function return t is used. For nil, the first part is
873 :group 'gnus-article-mime
875 (item :tag "first" :value nil)
876 (item :tag "undisplayed" :value undisplayed)
877 (item :tag "undisplayed or alternative"
878 :value undisplayed-alternative)
881 (defcustom gnus-mime-action-alist
882 '(("save to file" . gnus-mime-save-part)
883 ("save and strip" . gnus-mime-save-part-and-strip)
884 ("delete part" . gnus-mime-delete-part)
885 ("display as text" . gnus-mime-inline-part)
886 ("view the part" . gnus-mime-view-part)
887 ("pipe to command" . gnus-mime-pipe-part)
888 ("toggle display" . gnus-article-press-button)
889 ("toggle display" . gnus-article-view-part-as-charset)
890 ("view as type" . gnus-mime-view-part-as-type)
891 ("view internally" . gnus-mime-view-part-internally)
892 ("view externally" . gnus-mime-view-part-externally))
893 "An alist of actions that run on the MIME attachment."
894 :group 'gnus-article-mime
895 :type '(repeat (cons (string :tag "name")
899 ;;; The treatment variables
902 (defvar gnus-part-display-hook nil
903 "Hook called on parts that are to receive treatment.")
905 (defvar gnus-article-treat-custom
906 '(choice (const :tag "Off" nil)
908 (const :tag "Header" head)
909 (const :tag "Last" last)
910 (const :tag "Mime" mime)
911 (integer :tag "Less")
912 (repeat :tag "Groups" regexp)
913 (sexp :tag "Predicate")))
915 (defvar gnus-article-treat-head-custom
916 '(choice (const :tag "Off" nil)
917 (const :tag "Header" head)))
919 (defvar gnus-article-treat-types '("text/plain")
922 (defvar gnus-inhibit-treatment nil
923 "Whether to inhibit treatment.")
925 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
926 "Highlight the signature.
927 Valid values are nil, t, `head', `last', an integer or a predicate.
928 See Info node `(gnus)Customizing Articles'."
929 :group 'gnus-article-treat
930 :link '(custom-manual "(gnus)Customizing Articles")
931 :type gnus-article-treat-custom)
932 (put 'gnus-treat-highlight-signature 'highlight t)
934 (defcustom gnus-treat-buttonize 100000
936 Valid values are nil, t, `head', `last', an integer or a predicate.
937 See Info node `(gnus)Customizing Articles'."
938 :group 'gnus-article-treat
939 :link '(custom-manual "(gnus)Customizing Articles")
940 :type gnus-article-treat-custom)
941 (put 'gnus-treat-buttonize 'highlight t)
943 (defcustom gnus-treat-buttonize-head 'head
944 "Add buttons to the head.
945 Valid values are nil, t, `head', `last', an integer or a predicate.
946 See Info node `(gnus)Customizing Articles' for details."
947 :group 'gnus-article-treat
948 :link '(custom-manual "(gnus)Customizing Articles")
949 :type gnus-article-treat-head-custom)
950 (put 'gnus-treat-buttonize-head 'highlight t)
952 (defcustom gnus-treat-emphasize
953 (and (or window-system
955 (>= (string-to-number emacs-version) 21))
958 Valid values are nil, t, `head', `last', an integer or a predicate.
959 See Info node `(gnus)Customizing Articles' for details."
960 :group 'gnus-article-treat
961 :link '(custom-manual "(gnus)Customizing Articles")
962 :type gnus-article-treat-custom)
963 (put 'gnus-treat-emphasize 'highlight t)
965 (defcustom gnus-treat-strip-cr nil
966 "Remove carriage returns.
967 Valid values are nil, t, `head', `last', an integer or a predicate.
968 See Info node `(gnus)Customizing Articles' for details."
969 :group 'gnus-article-treat
970 :link '(custom-manual "(gnus)Customizing Articles")
971 :type gnus-article-treat-custom)
973 (defcustom gnus-treat-unsplit-urls nil
974 "Remove newlines from within URLs.
975 Valid values are nil, t, `head', `last', an integer or a predicate.
976 See Info node `(gnus)Customizing Articles' for details."
977 :group 'gnus-article-treat
978 :link '(custom-manual "(gnus)Customizing Articles")
979 :type gnus-article-treat-custom)
981 (defcustom gnus-treat-leading-whitespace nil
982 "Remove leading whitespace in headers.
983 Valid values are nil, t, `head', `last', an integer or a predicate.
984 See Info node `(gnus)Customizing Articles' for details."
985 :group 'gnus-article-treat
986 :link '(custom-manual "(gnus)Customizing Articles")
987 :type gnus-article-treat-custom)
989 (defcustom gnus-treat-hide-headers 'head
991 Valid values are nil, t, `head', `last', an integer or a predicate.
992 See Info node `(gnus)Customizing Articles' for details."
993 :group 'gnus-article-treat
994 :link '(custom-manual "(gnus)Customizing Articles")
995 :type gnus-article-treat-head-custom)
997 (defcustom gnus-treat-hide-boring-headers nil
998 "Hide boring headers.
999 Valid values are nil, t, `head', `last', an integer or a predicate.
1000 See Info node `(gnus)Customizing Articles' for details."
1001 :group 'gnus-article-treat
1002 :link '(custom-manual "(gnus)Customizing Articles")
1003 :type gnus-article-treat-head-custom)
1005 (defcustom gnus-treat-hide-signature nil
1006 "Hide the signature.
1007 Valid values are nil, t, `head', `last', an integer or a predicate.
1008 See Info node `(gnus)Customizing Articles' for details."
1009 :group 'gnus-article-treat
1010 :link '(custom-manual "(gnus)Customizing Articles")
1011 :type gnus-article-treat-custom)
1013 (defcustom gnus-treat-fill-article nil
1015 Valid values are nil, t, `head', `last', an integer or a predicate.
1016 See Info node `(gnus)Customizing Articles' for details."
1017 :group 'gnus-article-treat
1018 :link '(custom-manual "(gnus)Customizing Articles")
1019 :type gnus-article-treat-custom)
1021 (defcustom gnus-treat-hide-citation nil
1023 Valid values are nil, t, `head', `last', an integer or a predicate.
1024 See Info node `(gnus)Customizing Articles' for details."
1025 :group 'gnus-article-treat
1026 :link '(custom-manual "(gnus)Customizing Articles")
1027 :type gnus-article-treat-custom)
1029 (defcustom gnus-treat-hide-citation-maybe nil
1031 Valid values are nil, t, `head', `last', an integer or a predicate.
1032 See Info node `(gnus)Customizing Articles' for details."
1033 :group 'gnus-article-treat
1034 :link '(custom-manual "(gnus)Customizing Articles")
1035 :type gnus-article-treat-custom)
1037 (defcustom gnus-treat-strip-list-identifiers 'head
1038 "Strip list identifiers from `gnus-list-identifiers`.
1039 Valid values are nil, t, `head', `last', an integer or a predicate.
1040 See Info node `(gnus)Customizing Articles' for details."
1042 :group 'gnus-article-treat
1043 :link '(custom-manual "(gnus)Customizing Articles")
1044 :type gnus-article-treat-custom)
1046 (make-obsolete-variable 'gnus-treat-strip-pgp
1047 "This option is obsolete in Gnus 5.10.")
1049 (defcustom gnus-treat-strip-pem nil
1050 "Strip PEM signatures.
1051 Valid values are nil, t, `head', `last', an integer or a predicate.
1052 See Info node `(gnus)Customizing Articles' for details."
1053 :group 'gnus-article-treat
1054 :link '(custom-manual "(gnus)Customizing Articles")
1055 :type gnus-article-treat-custom)
1057 (defcustom gnus-treat-strip-banner t
1058 "Strip banners from articles.
1059 The banner to be stripped is specified in the `banner' group parameter.
1060 Valid values are nil, t, `head', `last', an integer or a predicate.
1061 See Info node `(gnus)Customizing Articles' for details."
1062 :group 'gnus-article-treat
1063 :link '(custom-manual "(gnus)Customizing Articles")
1064 :type gnus-article-treat-custom)
1066 (defcustom gnus-treat-highlight-headers 'head
1067 "Highlight the headers.
1068 Valid values are nil, t, `head', `last', an integer or a predicate.
1069 See Info node `(gnus)Customizing Articles' for details."
1070 :group 'gnus-article-treat
1071 :link '(custom-manual "(gnus)Customizing Articles")
1072 :type gnus-article-treat-head-custom)
1073 (put 'gnus-treat-highlight-headers 'highlight t)
1075 (defcustom gnus-treat-highlight-citation t
1076 "Highlight cited text.
1077 Valid values are nil, t, `head', `last', an integer or a predicate.
1078 See Info node `(gnus)Customizing Articles' for details."
1079 :group 'gnus-article-treat
1080 :link '(custom-manual "(gnus)Customizing Articles")
1081 :type gnus-article-treat-custom)
1082 (put 'gnus-treat-highlight-citation 'highlight t)
1084 (defcustom gnus-treat-date-ut nil
1085 "Display the Date in UT (GMT).
1086 Valid values are nil, t, `head', `last', an integer or a predicate.
1087 See Info node `(gnus)Customizing Articles' for details."
1088 :group 'gnus-article-treat
1089 :link '(custom-manual "(gnus)Customizing Articles")
1090 :type gnus-article-treat-head-custom)
1092 (defcustom gnus-treat-date-local nil
1093 "Display the Date in the local timezone.
1094 Valid values are nil, t, `head', `last', an integer or a predicate.
1095 See Info node `(gnus)Customizing Articles' for details."
1096 :group 'gnus-article-treat
1097 :link '(custom-manual "(gnus)Customizing Articles")
1098 :type gnus-article-treat-head-custom)
1100 (defcustom gnus-treat-date-english nil
1101 "Display the Date in a format that can be read aloud in English.
1102 Valid values are nil, t, `head', `last', an integer or a predicate.
1103 See Info node `(gnus)Customizing Articles' for details."
1104 :group 'gnus-article-treat
1105 :link '(custom-manual "(gnus)Customizing Articles")
1106 :type gnus-article-treat-head-custom)
1108 (defcustom gnus-treat-date-lapsed nil
1109 "Display the Date header in a way that says how much time has elapsed.
1110 Valid values are nil, t, `head', `last', an integer or a predicate.
1111 See Info node `(gnus)Customizing Articles' for details."
1112 :group 'gnus-article-treat
1113 :link '(custom-manual "(gnus)Customizing Articles")
1114 :type gnus-article-treat-head-custom)
1116 (defcustom gnus-treat-date-original nil
1117 "Display the date in the original timezone.
1118 Valid values are nil, t, `head', `last', an integer or a predicate.
1119 See Info node `(gnus)Customizing Articles' for details."
1120 :group 'gnus-article-treat
1121 :link '(custom-manual "(gnus)Customizing Articles")
1122 :type gnus-article-treat-head-custom)
1124 (defcustom gnus-treat-date-iso8601 nil
1125 "Display the date in the ISO8601 format.
1126 Valid values are nil, t, `head', `last', an integer or a predicate.
1127 See Info node `(gnus)Customizing Articles' for details."
1129 :group 'gnus-article-treat
1130 :link '(custom-manual "(gnus)Customizing Articles")
1131 :type gnus-article-treat-head-custom)
1133 (defcustom gnus-treat-date-user-defined nil
1134 "Display the date in a user-defined format.
1135 The format is defined by the `gnus-article-time-format' variable.
1136 Valid values are nil, t, `head', `last', an integer or a predicate.
1137 See Info node `(gnus)Customizing Articles' for details."
1138 :group 'gnus-article-treat
1139 :link '(custom-manual "(gnus)Customizing Articles")
1140 :type gnus-article-treat-head-custom)
1142 (defcustom gnus-treat-strip-headers-in-body t
1143 "Strip the X-No-Archive header line from the beginning of the body.
1144 Valid values are nil, t, `head', `last', an integer or a predicate.
1145 See Info node `(gnus)Customizing Articles' for details."
1147 :group 'gnus-article-treat
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-custom)
1151 (defcustom gnus-treat-strip-trailing-blank-lines nil
1152 "Strip trailing blank lines.
1153 Valid values are nil, t, `head', `last', an integer or a predicate.
1154 See Info node `(gnus)Customizing Articles' for details."
1155 :group 'gnus-article-treat
1156 :link '(custom-manual "(gnus)Customizing Articles")
1157 :type gnus-article-treat-custom)
1159 (defcustom gnus-treat-strip-leading-blank-lines nil
1160 "Strip leading blank lines.
1161 Valid values are nil, t, `head', `last', an integer or a predicate.
1162 See Info node `(gnus)Customizing Articles' for details."
1163 :group 'gnus-article-treat
1164 :link '(custom-manual "(gnus)Customizing Articles")
1165 :type gnus-article-treat-custom)
1167 (defcustom gnus-treat-strip-multiple-blank-lines nil
1168 "Strip multiple blank lines.
1169 Valid values are nil, t, `head', `last', an integer or a predicate.
1170 See Info node `(gnus)Customizing Articles' for details."
1171 :group 'gnus-article-treat
1172 :link '(custom-manual "(gnus)Customizing Articles")
1173 :type gnus-article-treat-custom)
1175 (defcustom gnus-treat-unfold-headers 'head
1176 "Unfold folded header lines.
1177 Valid values are nil, t, `head', `last', an integer or a predicate.
1178 See Info node `(gnus)Customizing Articles' for details."
1179 :group 'gnus-article-treat
1180 :link '(custom-manual "(gnus)Customizing Articles")
1181 :type gnus-article-treat-custom)
1183 (defcustom gnus-treat-fold-headers nil
1185 Valid values are nil, t, `head', `last', an integer or a predicate.
1186 See Info node `(gnus)Customizing Articles' for details."
1187 :group 'gnus-article-treat
1188 :link '(custom-manual "(gnus)Customizing Articles")
1189 :type gnus-article-treat-custom)
1191 (defcustom gnus-treat-fold-newsgroups 'head
1192 "Fold the Newsgroups and Followup-To headers.
1193 Valid values are nil, t, `head', `last', an integer or a predicate.
1194 See Info node `(gnus)Customizing Articles' for details."
1195 :group 'gnus-article-treat
1196 :link '(custom-manual "(gnus)Customizing Articles")
1197 :type gnus-article-treat-custom)
1199 (defcustom gnus-treat-overstrike t
1200 "Treat overstrike highlighting.
1201 Valid values are nil, t, `head', `last', an integer or a predicate.
1202 See Info node `(gnus)Customizing Articles' for details."
1203 :group 'gnus-article-treat
1204 :link '(custom-manual "(gnus)Customizing Articles")
1205 :type gnus-article-treat-custom)
1206 (put 'gnus-treat-overstrike 'highlight t)
1208 (defcustom gnus-treat-ansi-sequences t
1209 "Treat ANSI SGR control sequences.
1210 Valid values are nil, t, `head', `last', an integer or a predicate.
1211 See Info node `(gnus)Customizing Articles' for details."
1212 :group 'gnus-article-treat
1213 :link '(custom-manual "(gnus)Customizing Articles")
1214 :type gnus-article-treat-custom)
1216 (make-obsolete-variable 'gnus-treat-display-xface
1217 'gnus-treat-display-x-face)
1219 (defcustom gnus-treat-display-x-face
1220 (and (not noninteractive)
1221 (or (memq gnus-article-x-face-command
1222 '(x-face-decode-message-header
1223 x-face-mule-gnus-article-display-x-face))
1224 (and (fboundp 'image-type-available-p)
1225 (image-type-available-p 'xbm)
1226 (string-match "^0x" (shell-command-to-string "uncompface"))
1227 (executable-find "icontopbm"))
1228 (and (featurep 'xemacs)
1231 "Display X-Face headers.
1232 Valid values are nil, t, `head', `last', an integer or a predicate.
1233 See Info node `(gnus)Customizing Articles' and Info node
1234 `(gnus)X-Face' for details."
1235 :group 'gnus-article-treat
1237 :link '(custom-manual "(gnus)Customizing Articles")
1238 :link '(custom-manual "(gnus)X-Face")
1239 :type gnus-article-treat-head-custom
1240 :set (lambda (symbol value)
1243 (cond ((or (boundp symbol) (get symbol 'saved-value))
1245 ((boundp 'gnus-treat-display-xface)
1247 ** gnus-treat-display-xface is an obsolete variable;\
1248 use gnus-treat-display-x-face instead")
1249 (default-value 'gnus-treat-display-xface))
1250 ((get 'gnus-treat-display-xface 'saved-value)
1252 ** gnus-treat-display-xface is an obsolete variable;\
1253 use gnus-treat-display-x-face instead")
1254 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1257 (put 'gnus-treat-display-x-face 'highlight t)
1259 (defcustom gnus-article-should-use-smiley-mule
1260 (not (or (featurep 'xemacs)
1261 (gnus-image-type-available-p 'xpm)
1262 (gnus-image-type-available-p 'pbm)))
1263 "If non-nil, gnus uses `smiley-mule' for displaying smileys rather than
1264 `smiley'. It defaults to t when Emacs 20 or earlier is running.
1265 `smiley-mule' is boundled in BITMAP-MULE package. You can set it to t
1266 even if you are using Emacs 21+. It has no effect on XEmacs."
1267 :group 'gnus-article-various
1269 :get (lambda (symbol)
1270 (and (not noninteractive)
1271 (default-value symbol)
1272 (not (featurep 'xemacs))
1273 (module-installed-p 'smiley-mule)
1275 :set (lambda (symbol value)
1276 (set-default symbol (and (not noninteractive)
1278 (not (featurep 'xemacs))
1279 (module-installed-p 'smiley-mule)
1282 (defvar gnus-article-smiley-mule-loaded-p nil
1283 "Internal variable used to say whether `smiley-mule' is loaded (whether
1284 smiley functions are not overridden by `smiley').")
1286 (defcustom gnus-treat-display-face
1287 (and (not noninteractive)
1288 ;; x-face-e21 handles both X-Face and Face headers.
1289 (not (and (eq gnus-article-x-face-command 'x-face-decode-message-header)
1290 (module-installed-p 'x-face-e21)))
1291 (or (and (fboundp 'image-type-available-p)
1292 (image-type-available-p 'png))
1293 (and (featurep 'xemacs)
1296 "Display Face headers.
1297 Valid values are nil, t, `head', `last', an integer or a predicate.
1298 See Info node `(gnus)Customizing Articles' and Info node
1299 `(gnus)X-Face' for details."
1300 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :link '(custom-manual "(gnus)X-Face")
1304 :type gnus-article-treat-head-custom)
1305 (put 'gnus-treat-display-face 'highlight t)
1307 (defcustom gnus-treat-display-smileys
1308 (if (and (not noninteractive)
1309 (or (and (featurep 'xemacs)
1311 (gnus-image-type-available-p 'xpm)
1312 (gnus-image-type-available-p 'pbm)
1313 (and (not (featurep 'xemacs))
1315 (module-installed-p 'smiley-mule))))
1319 Valid values are nil, t, `head', `last', an integer or a predicate.
1320 See Info node `(gnus)Customizing Articles' and Info node
1321 `(gnus)Smileys' for details."
1322 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :link '(custom-manual "(gnus)Smileys")
1326 :type gnus-article-treat-custom)
1327 (put 'gnus-treat-display-smileys 'highlight t)
1329 (defcustom gnus-treat-from-picon
1330 (if (and (gnus-image-type-available-p 'xpm)
1331 (gnus-picons-installed-p))
1333 "Display picons in the From header.
1334 Valid values are nil, t, `head', `last', an integer or a predicate.
1335 See Info node `(gnus)Customizing Articles' and Info node
1336 `(gnus)Picons' for details."
1337 :group 'gnus-article-treat
1339 :link '(custom-manual "(gnus)Customizing Articles")
1340 :link '(custom-manual "(gnus)Picons")
1341 :type gnus-article-treat-head-custom)
1342 (put 'gnus-treat-from-picon 'highlight t)
1344 (defcustom gnus-treat-mail-picon
1345 (if (and (gnus-image-type-available-p 'xpm)
1346 (gnus-picons-installed-p))
1348 "Display picons in To and Cc headers.
1349 Valid values are nil, t, `head', `last', an integer or a predicate.
1350 See Info node `(gnus)Customizing Articles' and Info node
1351 `(gnus)Picons' for details."
1352 :group 'gnus-article-treat
1354 :link '(custom-manual "(gnus)Customizing Articles")
1355 :link '(custom-manual "(gnus)Picons")
1356 :type gnus-article-treat-head-custom)
1357 (put 'gnus-treat-mail-picon 'highlight t)
1359 (defcustom gnus-treat-newsgroups-picon
1360 (if (and (gnus-image-type-available-p 'xpm)
1361 (gnus-picons-installed-p))
1363 "Display picons in the Newsgroups and Followup-To headers.
1364 Valid values are nil, t, `head', `last', an integer or a predicate.
1365 See Info node `(gnus)Customizing Articles' and Info node
1366 `(gnus)Picons' for details."
1367 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :link '(custom-manual "(gnus)Picons")
1371 :type gnus-article-treat-head-custom)
1372 (put 'gnus-treat-newsgroups-picon 'highlight t)
1374 (defcustom gnus-treat-body-boundary
1375 (if (or gnus-treat-newsgroups-picon
1376 gnus-treat-mail-picon
1377 gnus-treat-from-picon)
1379 "Draw a boundary at the end of the headers.
1380 Valid values are nil and `head'.
1381 See Info node `(gnus)Customizing Articles' for details."
1383 :group 'gnus-article-treat
1384 :link '(custom-manual "(gnus)Customizing Articles")
1385 :type gnus-article-treat-head-custom)
1387 (defcustom gnus-treat-capitalize-sentences nil
1388 "Capitalize sentence-starting words.
1389 Valid values are nil, t, `head', `last', an integer or a predicate.
1390 See Info node `(gnus)Customizing Articles' for details."
1392 :group 'gnus-article-treat
1393 :link '(custom-manual "(gnus)Customizing Articles")
1394 :type gnus-article-treat-custom)
1396 (defcustom gnus-treat-wash-html nil
1398 Valid values are nil, t, `head', `last', an integer or a predicate.
1399 See Info node `(gnus)Customizing Articles' for details."
1400 :group 'gnus-article-treat
1401 :link '(custom-manual "(gnus)Customizing Articles")
1402 :type gnus-article-treat-custom)
1404 (defcustom gnus-treat-fill-long-lines nil
1406 Valid values are nil, t, `head', `last', an integer or a predicate.
1407 See Info node `(gnus)Customizing Articles' for details."
1408 :group 'gnus-article-treat
1409 :link '(custom-manual "(gnus)Customizing Articles")
1410 :type gnus-article-treat-custom)
1412 (defcustom gnus-treat-play-sounds nil
1414 Valid values are nil, t, `head', `last', an integer or a predicate.
1415 See Info node `(gnus)Customizing Articles' for details."
1417 :group 'gnus-article-treat
1418 :link '(custom-manual "(gnus)Customizing Articles")
1419 :type gnus-article-treat-custom)
1421 (defcustom gnus-treat-decode-article-as-default-mime-charset nil
1422 "Decode an article as `default-mime-charset'. For instance, if you want to
1423 attempt to decode an article even if the value of `gnus-show-mime' is nil,
1424 you could set this variable to something like: nil for don't decode, t for
1425 decode the body, '(or header t) for the whole article, etc."
1426 :group 'gnus-article-treat
1427 :type '(radio (const :tag "Off" nil)
1428 (const :tag "Decode body" t)
1429 (const :tag "Decode all" (or head t))))
1431 (defcustom gnus-treat-translate nil
1432 "Translate articles from one language to another.
1433 Valid values are nil, t, `head', `last', an integer or a predicate.
1434 See Info node `(gnus)Customizing Articles' for details."
1436 :group 'gnus-article-treat
1437 :link '(custom-manual "(gnus)Customizing Articles")
1438 :type gnus-article-treat-custom)
1440 (defcustom gnus-treat-x-pgp-sig nil
1442 To automatically treat X-PGP-Sig, set it to head.
1443 Valid values are nil, t, `head', `last', an integer or a predicate.
1444 See Info node `(gnus)Customizing Articles' for details."
1445 :group 'gnus-article-treat
1446 :group 'mime-security
1447 :type gnus-article-treat-custom)
1449 (defcustom gnus-treat-monafy nil
1450 "Display body part with mona font.
1451 Valid values are nil, t, `head', `last', an integer or a predicate.
1452 See Info node `(gnus)Customizing Articles' for details."
1453 :group 'gnus-article-treat
1454 :group 'mime-security
1455 :link '(custom-manual "(gnus)Customizing Articles")
1456 :type gnus-article-treat-custom)
1458 (defvar gnus-article-encrypt-protocol-alist
1459 '(("PGP" . mml2015-self-encrypt)))
1461 ;; Set to nil if more than one protocol added to
1462 ;; gnus-article-encrypt-protocol-alist.
1463 (defcustom gnus-article-encrypt-protocol "PGP"
1464 "The protocol used for encrypt articles.
1465 It is a string, such as \"PGP\". If nil, ask user."
1467 :group 'mime-security)
1469 (defvar gnus-article-wash-function nil
1470 "Function used for converting HTML into text.")
1472 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1473 (mm-coding-system-p 'utf-8)
1474 (executable-find idna-program))
1475 "Whether IDNA decoding of headers is used when viewing messages.
1476 This requires GNU Libidn, and by default only enabled if it is found."
1477 :group 'gnus-article-headers
1480 (defcustom gnus-article-over-scroll nil
1481 "If non-nil, allow scrolling the article buffer even when there no more text."
1482 :group 'gnus-article
1485 ;;; Internal variables
1487 (defvar gnus-english-month-names
1488 '("January" "February" "March" "April" "May" "June" "July" "August"
1489 "September" "October" "November" "December"))
1491 (defvar article-goto-body-goes-to-point-min-p nil)
1492 (defvar gnus-article-wash-types nil)
1493 (defvar gnus-article-emphasis-alist nil)
1494 (defvar gnus-article-image-alist nil)
1496 (defvar gnus-article-mime-handle-alist-1 nil)
1497 (defvar gnus-treatment-function-alist
1498 '((gnus-treat-decode-article-as-default-mime-charset
1499 gnus-article-decode-article-as-default-mime-charset)
1500 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1501 (gnus-treat-monafy gnus-article-monafy)
1502 (gnus-treat-strip-banner gnus-article-strip-banner)
1503 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1504 (gnus-treat-buttonize gnus-article-add-buttons)
1505 (gnus-treat-fill-article gnus-article-fill-cited-article)
1506 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1507 (gnus-treat-strip-cr gnus-article-remove-cr)
1508 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1509 (gnus-treat-date-ut gnus-article-date-ut)
1510 (gnus-treat-date-local gnus-article-date-local)
1511 (gnus-treat-date-english gnus-article-date-english)
1512 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1513 (gnus-treat-date-original gnus-article-date-original)
1514 (gnus-treat-date-user-defined gnus-article-date-user)
1515 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1516 (gnus-treat-display-face gnus-article-display-face)
1517 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1518 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1519 (gnus-treat-hide-signature gnus-article-hide-signature)
1520 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1521 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1522 (gnus-treat-strip-pem gnus-article-hide-pem)
1523 (gnus-treat-from-picon gnus-treat-from-picon)
1524 (gnus-treat-mail-picon gnus-treat-mail-picon)
1525 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1526 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1527 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1528 (gnus-treat-strip-trailing-blank-lines
1529 gnus-article-remove-trailing-blank-lines)
1530 (gnus-treat-strip-leading-blank-lines
1531 gnus-article-strip-leading-blank-lines)
1532 (gnus-treat-strip-multiple-blank-lines
1533 gnus-article-strip-multiple-blank-lines)
1534 (gnus-treat-overstrike gnus-article-treat-overstrike)
1535 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1536 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1537 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1538 ;; Displaying X-Face should be done after unfolding headers
1539 ;; to protect bitmap lines.
1540 (gnus-treat-display-x-face gnus-article-display-x-face)
1541 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1542 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1543 (gnus-treat-display-smileys gnus-treat-smiley)
1544 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1545 (gnus-treat-wash-html gnus-article-wash-html)
1546 (gnus-treat-emphasize gnus-article-emphasize)
1547 (gnus-treat-hide-citation gnus-article-hide-citation)
1548 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1549 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1550 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1551 (gnus-treat-play-sounds gnus-earcon-display)))
1553 (defvar gnus-article-mime-handle-alist nil)
1554 (defvar article-lapsed-timer nil)
1555 (defvar gnus-article-current-summary nil)
1557 (defvar gnus-article-mode-syntax-table
1558 (let ((table (copy-syntax-table text-mode-syntax-table)))
1559 ;; This causes the citation match run O(2^n).
1560 ;; (modify-syntax-entry ?- "w" table)
1561 (modify-syntax-entry ?> ")<" table)
1562 (modify-syntax-entry ?< "(>" table)
1563 ;; make M-. in article buffers work for `foo' strings
1564 (modify-syntax-entry ?' " " table)
1565 (modify-syntax-entry ?` " " table)
1567 "Syntax table used in article mode buffers.
1568 Initialized from `text-mode-syntax-table.")
1570 (defvar gnus-save-article-buffer nil)
1572 (defvar gnus-article-mode-line-format-alist
1573 (nconc '((?w (gnus-article-wash-status) ?s)
1574 (?m (gnus-article-mime-part-status) ?s))
1575 gnus-summary-mode-line-format-alist))
1577 (defvar gnus-number-of-articles-to-be-saved nil)
1579 (defvar gnus-inhibit-hiding nil)
1581 ;;; Macros for dealing with the article buffer.
1583 (defmacro gnus-with-article-headers (&rest forms)
1585 (set-buffer gnus-article-buffer)
1587 (let ((buffer-read-only nil)
1588 (inhibit-point-motion-hooks t)
1589 (case-fold-search t))
1590 (article-narrow-to-head)
1593 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1594 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1596 (defmacro gnus-with-article-buffer (&rest forms)
1598 (set-buffer gnus-article-buffer)
1599 (let ((buffer-read-only nil))
1602 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1603 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1605 (defun gnus-article-goto-header (header)
1606 "Go to HEADER, which is a regular expression."
1607 (re-search-forward (concat "^\\(" header "\\):") nil t))
1609 (defsubst gnus-article-hide-text (b e props)
1610 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1611 (gnus-add-text-properties-when 'article-type nil b e props)
1612 (when (memq 'intangible props)
1614 (max (1- b) (point-min))
1615 b 'intangible (cddr (memq 'intangible props)))))
1617 (defsubst gnus-article-unhide-text (b e)
1618 "Remove hidden text properties from region between B and E."
1619 (remove-text-properties b e gnus-hidden-properties)
1620 (when (memq 'intangible gnus-hidden-properties)
1621 (put-text-property (max (1- b) (point-min))
1622 b 'intangible nil)))
1624 (defun gnus-article-hide-text-type (b e type)
1625 "Hide text of TYPE between B and E."
1626 (gnus-add-wash-type type)
1627 (gnus-article-hide-text
1628 b e (cons 'article-type (cons type gnus-hidden-properties))))
1630 (defun gnus-article-unhide-text-type (b e type)
1631 "Unhide text of TYPE between B and E."
1632 (gnus-delete-wash-type type)
1633 (remove-text-properties
1634 b e (cons 'article-type (cons type gnus-hidden-properties)))
1635 (when (memq 'intangible gnus-hidden-properties)
1636 (put-text-property (max (1- b) (point-min))
1637 b 'intangible nil)))
1639 (defun gnus-article-hide-text-of-type (type)
1640 "Hide text of TYPE in the current buffer."
1642 (let ((b (point-min))
1644 (while (setq b (text-property-any b e 'article-type type))
1645 (add-text-properties b (incf b) gnus-hidden-properties)))))
1647 (defun gnus-article-delete-text-of-type (type)
1648 "Delete text of TYPE in the current buffer."
1650 (let ((b (point-min)))
1651 (while (setq b (text-property-any b (point-max) 'article-type type))
1653 b (or (text-property-not-all b (point-max) 'article-type type)
1656 (defun gnus-article-delete-invisible-text ()
1657 "Delete all invisible text in the current buffer."
1659 (let ((b (point-min)))
1660 (while (setq b (text-property-any b (point-max) 'invisible t))
1662 b (or (text-property-not-all b (point-max) 'invisible t)
1665 (defun gnus-article-text-type-exists-p (type)
1666 "Say whether any text of type TYPE exists in the buffer."
1667 (text-property-any (point-min) (point-max) 'article-type type))
1669 (defsubst gnus-article-header-rank ()
1670 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1671 (let ((list gnus-sorted-header-list)
1674 (if (looking-at (car list))
1676 (setq list (cdr list))
1680 (defun article-hide-headers (&optional arg delete)
1681 "Hide unwanted headers and possibly sort them as well."
1682 (interactive (gnus-article-hidden-arg))
1683 ;; Lars said that this function might be inhibited.
1684 (if (gnus-article-check-hidden-text 'headers arg)
1686 ;; Show boring headers as well.
1687 (gnus-article-show-hidden-text 'boring-headers)
1688 (when (eq 1 (point-min))
1689 (set-window-start (get-buffer-window (current-buffer)) 1)))
1690 (unless gnus-inhibit-hiding
1693 (let ((inhibit-read-only t)
1694 (case-fold-search t)
1695 (max (1+ (length gnus-sorted-header-list)))
1696 (ignored (when (not gnus-visible-headers)
1697 (cond ((stringp gnus-ignored-headers)
1698 gnus-ignored-headers)
1699 ((listp gnus-ignored-headers)
1700 (mapconcat 'identity gnus-ignored-headers
1703 (cond ((stringp gnus-visible-headers)
1704 gnus-visible-headers)
1705 ((and gnus-visible-headers
1706 (listp gnus-visible-headers))
1707 (mapconcat 'identity gnus-visible-headers "\\|"))))
1708 (inhibit-point-motion-hooks t)
1710 ;; First we narrow to just the headers.
1711 (article-narrow-to-head)
1712 ;; Hide any "From " lines at the beginning of (mail) articles.
1713 (while (looking-at "From ")
1717 (delete-region (point-min) (point))
1718 (gnus-article-hide-text (point-min) (point)
1719 (nconc (list 'article-type 'headers)
1720 gnus-hidden-properties))))
1721 ;; Then treat the rest of the header lines.
1722 ;; Then we use the two regular expressions
1723 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1724 ;; select which header lines is to remain visible in the
1726 (while (re-search-forward "^[^ \t:]*:" nil t)
1728 ;; Mark the rank of the header.
1730 (point) (1+ (point)) 'message-rank
1731 (if (or (and visible (looking-at visible))
1733 (not (looking-at ignored))))
1734 (gnus-article-header-rank)
1737 (message-sort-headers-1)
1738 (when (setq beg (text-property-any
1739 (point-min) (point-max) 'message-rank (+ 2 max)))
1740 ;; We delete or make invisible the unwanted headers.
1741 (gnus-add-wash-type 'headers)
1744 (add-text-properties
1745 (point-min) (+ 5 (point-min))
1746 '(article-type headers dummy-invisible t))
1747 (delete-region beg (point-max)))
1748 (gnus-article-hide-text-type beg (point-max) 'headers)))))))))
1750 (defun article-hide-boring-headers (&optional arg)
1751 "Toggle hiding of headers that aren't very interesting.
1752 If given a negative prefix, always show; if given a positive prefix,
1754 (interactive (gnus-article-hidden-arg))
1755 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1756 (not gnus-show-all-headers))
1759 (let ((buffer-read-only nil)
1760 (list gnus-boring-article-headers)
1761 (inhibit-point-motion-hooks t)
1763 (article-narrow-to-head)
1765 (setq elem (pop list))
1766 (goto-char (point-min))
1768 ;; Hide empty headers.
1770 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1772 (gnus-article-hide-text-type
1776 (if (re-search-forward "^[^ \t]" nil t)
1780 ;; Hide boring Newsgroups header.
1781 ((eq elem 'newsgroups)
1782 (when (gnus-string-equal
1783 (gnus-fetch-field "newsgroups")
1784 (gnus-group-real-name
1785 (if (boundp 'gnus-newsgroup-name)
1788 (gnus-article-hide-header "newsgroups")))
1789 ((eq elem 'to-address)
1790 (let ((to (message-fetch-field "to"))
1792 (gnus-parameter-to-address
1793 (if (boundp 'gnus-newsgroup-name)
1794 gnus-newsgroup-name ""))))
1795 (when (and to to-address
1798 ;; only one address in To
1799 (nth 1 (mail-extract-address-components to))
1801 (gnus-article-hide-header "to"))))
1803 (let ((to (message-fetch-field "to"))
1805 (gnus-parameter-to-list
1806 (if (boundp 'gnus-newsgroup-name)
1807 gnus-newsgroup-name ""))))
1808 (when (and to to-list
1811 ;; only one address in To
1812 (nth 1 (mail-extract-address-components to))
1814 (gnus-article-hide-header "to"))))
1816 (let ((cc (message-fetch-field "cc"))
1818 (gnus-parameter-to-list
1819 (if (boundp 'gnus-newsgroup-name)
1820 gnus-newsgroup-name ""))))
1821 (when (and cc to-list
1824 ;; only one address in CC
1825 (nth 1 (mail-extract-address-components cc))
1827 (gnus-article-hide-header "cc"))))
1828 ((eq elem 'followup-to)
1829 (when (gnus-string-equal
1830 (message-fetch-field "followup-to")
1831 (message-fetch-field "newsgroups"))
1832 (gnus-article-hide-header "followup-to")))
1833 ((eq elem 'reply-to)
1834 (if (gnus-group-find-parameter
1835 gnus-newsgroup-name 'broken-reply-to)
1836 (gnus-article-hide-header "reply-to")
1837 (let ((from (message-fetch-field "from"))
1838 (reply-to (message-fetch-field "reply-to")))
1845 (lambda (x) (downcase (cadr x)))
1846 (mail-extract-address-components from t))
1849 (lambda (x) (downcase (cadr x)))
1850 (mail-extract-address-components reply-to t))
1852 (gnus-article-hide-header "reply-to")))))
1854 (let ((date (message-fetch-field "date")))
1856 (< (days-between (current-time-string) date)
1858 (gnus-article-hide-header "date"))))
1860 (let ((to (message-fetch-field "to"))
1861 (cc (message-fetch-field "cc")))
1862 (when (> (length to) 1024)
1863 (gnus-article-hide-header "to"))
1864 (when (> (length cc) 1024)
1865 (gnus-article-hide-header "cc"))))
1869 (goto-char (point-min))
1870 (while (re-search-forward "^to:" nil t)
1871 (setq to-count (1+ to-count)))
1872 (when (> to-count 1)
1873 (while (> to-count 0)
1874 (goto-char (point-min))
1876 (re-search-forward "^to:" nil nil to-count)
1878 (narrow-to-region (point) (point-max))
1879 (gnus-article-hide-header "to"))
1880 (setq to-count (1- to-count))))
1881 (goto-char (point-min))
1882 (while (re-search-forward "^cc:" nil t)
1883 (setq cc-count (1+ cc-count)))
1884 (when (> cc-count 1)
1885 (while (> cc-count 0)
1886 (goto-char (point-min))
1888 (re-search-forward "^cc:" nil nil cc-count)
1890 (narrow-to-region (point) (point-max))
1891 (gnus-article-hide-header "cc"))
1892 (setq cc-count (1- cc-count)))))))))))))
1894 (defun gnus-article-hide-header (header)
1896 (goto-char (point-min))
1897 (when (re-search-forward (concat "^" header ":") nil t)
1898 (gnus-article-hide-text-type
1902 (if (re-search-forward "^[^ \t]" nil t)
1907 (defvar gnus-article-normalized-header-length 40
1908 "Length of normalized headers.")
1910 (defun article-normalize-headers ()
1911 "Make all header lines 40 characters long."
1913 (let ((buffer-read-only nil)
1917 (article-narrow-to-head)
1920 ((< (setq column (- (point-at-eol) (point)))
1921 gnus-article-normalized-header-length)
1923 (insert (make-string
1924 (- gnus-article-normalized-header-length column)
1926 ((> column gnus-article-normalized-header-length)
1927 (gnus-put-text-property
1929 (forward-char gnus-article-normalized-header-length)
1936 (forward-line 1))))))
1938 (defun article-treat-dumbquotes ()
1939 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1940 Note that this function guesses whether a character is a sm*rtq**t* or
1941 not, so it should only be used interactively.
1943 Sm*rtq**t*s are M****s***'s unilateral extension to the
1944 iso-8859-1 character map in an attempt to provide more quoting
1945 characters. If you see something like \\222 or \\264 where
1946 you're expecting some kind of apostrophe or quotation mark, then
1949 (article-translate-strings gnus-article-dumbquotes-map))
1951 (defun article-translate-characters (from to)
1952 "Translate all characters in the body of the article according to FROM and TO.
1953 FROM is a string of characters to translate from; to is a string of
1954 characters to translate to."
1956 (when (article-goto-body)
1957 (let ((buffer-read-only nil)
1958 (x (make-string 225 ?x))
1960 (while (< (incf i) (length x))
1963 (while (< i (length from))
1964 (aset x (aref from i) (aref to i))
1966 (translate-region (point) (point-max) x)))))
1968 (defun article-translate-strings (map)
1969 "Translate all string in the body of the article according to MAP.
1970 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1972 (when (article-goto-body)
1973 (let ((buffer-read-only nil)
1975 (while (setq elem (pop map))
1977 (while (search-forward (car elem) nil t)
1978 (replace-match (cadr elem)))))))))
1980 (defun article-treat-overstrike ()
1981 "Translate overstrikes into bold text."
1984 (when (article-goto-body)
1985 (let ((buffer-read-only nil))
1986 (while (search-forward "\b" nil t)
1987 (let ((next (char-after))
1991 previous (char-after))
1995 ;; We do the boldification/underlining by hiding the
1996 ;; overstrikes and putting the proper text property
2000 (gnus-article-hide-text-type start (point) 'overstrike)
2001 (put-text-property (point) end 'face 'bold))
2003 (gnus-article-hide-text-type
2004 (1- (point)) (1+ (point)) 'overstrike)
2006 start (1- (point)) 'face 'underline))
2008 (gnus-article-hide-text-type start (point) 'overstrike)
2010 (point) end 'face 'underline)))))))))
2012 (defun article-treat-ansi-sequences ()
2013 "Translate ANSI SGR control sequences into overlays or extents."
2016 (when (article-goto-body)
2017 (let ((buffer-read-only nil))
2018 (ansi-color-apply-on-region (point) (point-max))))))
2020 (defun gnus-article-treat-unfold-headers ()
2021 "Unfold folded message headers.
2022 Only the headers that fit into the current window width will be
2025 (gnus-with-article-headers
2029 (mail-header-narrow-to-field)
2030 (let ((header (buffer-string)))
2033 (goto-char (point-min))
2034 (while (re-search-forward "\n[\t ]" nil t)
2035 (replace-match " " t t)))
2036 (setq length (- (point-max) (point-min) 1)))
2037 (when (< length (window-width))
2038 (while (re-search-forward "\n[\t ]" nil t)
2039 (replace-match " " t t)))
2040 (goto-char (point-max)))))))
2042 (defun gnus-article-treat-fold-headers ()
2043 "Fold message headers."
2045 (gnus-with-article-headers
2048 (mail-header-narrow-to-field)
2049 (mail-header-fold-field)
2050 (goto-char (point-max))))))
2052 (defun gnus-treat-smiley ()
2053 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2055 (unless (featurep 'xemacs)
2056 (when (and (>= emacs-major-version 21)
2057 (not gnus-article-should-use-smiley-mule)
2058 gnus-article-smiley-mule-loaded-p)
2059 (load "smiley" nil t)
2060 (setq gnus-article-smiley-mule-loaded-p nil))
2061 (when (and gnus-article-should-use-smiley-mule
2062 (not gnus-article-smiley-mule-loaded-p))
2063 (load "smiley-mule" nil t)
2064 (setq gnus-article-smiley-mule-loaded-p t)))
2065 (gnus-with-article-buffer
2066 (if (memq 'smiley gnus-article-wash-types)
2067 (gnus-delete-images 'smiley)
2069 (let ((images (smiley-region (point) (point-max))))
2071 (gnus-add-wash-type 'smiley)
2072 (dolist (image images)
2073 (gnus-add-image 'smiley image)))))))
2075 (defun gnus-article-remove-images ()
2076 "Remove all images from the article buffer."
2078 (gnus-with-article-buffer
2079 (dolist (elem gnus-article-image-alist)
2080 (gnus-delete-images (car elem)))))
2082 (defun gnus-article-treat-fold-newsgroups ()
2083 "Unfold folded message headers.
2084 Only the headers that fit into the current window width will be
2087 (gnus-with-article-headers
2088 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2090 (mail-header-narrow-to-field)
2091 (while (re-search-forward ", *" nil t)
2092 (replace-match ", " t t))
2093 (mail-header-fold-field)
2094 (goto-char (point-max))))))
2096 (defun gnus-article-treat-body-boundary ()
2097 "Place a boundary line at the end of the headers."
2099 (when (and gnus-body-boundary-delimiter
2100 (> (length gnus-body-boundary-delimiter) 0))
2101 (gnus-with-article-headers
2102 (goto-char (point-max))
2103 (let ((start (point)))
2104 (insert "X-Boundary: ")
2105 (gnus-add-text-properties start (point) '(invisible t intangible t))
2107 (while (>= (1- (window-width)) (length str))
2108 (setq str (concat str gnus-body-boundary-delimiter)))
2109 (substring str 0 (1- (window-width))))
2111 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2113 (defun article-fill-long-lines ()
2114 "Fill lines that are wider than the window width."
2117 (let ((buffer-read-only nil)
2118 (width (window-width (get-buffer-window (current-buffer)))))
2121 (let ((adaptive-fill-mode nil)) ;Why? -sm
2124 (when (>= (current-column) (min fill-column width))
2125 (narrow-to-region (min (1+ (point)) (point-max))
2127 (let ((goback (point-marker)))
2128 (fill-paragraph nil)
2129 (goto-char (marker-position goback)))
2131 (forward-line 1)))))))
2133 (defun article-capitalize-sentences ()
2134 "Capitalize the first word in each sentence."
2137 (let ((buffer-read-only nil)
2138 (paragraph-start "^[\n\^L]"))
2142 (forward-sentence)))))
2144 (defun article-remove-cr ()
2145 "Remove trailing CRs and then translate remaining CRs into LFs."
2148 (let ((buffer-read-only nil))
2149 (goto-char (point-min))
2150 (while (re-search-forward "\r+$" nil t)
2151 (replace-match "" t t))
2152 (goto-char (point-min))
2153 (while (search-forward "\r" nil t)
2154 (replace-match "\n" t t)))))
2156 (defun article-remove-trailing-blank-lines ()
2157 "Remove all trailing blank lines from the article."
2160 (let ((buffer-read-only nil))
2161 (goto-char (point-max))
2165 (while (and (not (bobp))
2166 (looking-at "^[ \t]*$")
2167 (not (gnus-annotation-in-region-p
2168 (point) (point-at-eol))))
2173 (defun article-display-face ()
2174 "Display any Face headers in the header."
2176 (let ((wash-face-p buffer-read-only))
2177 (gnus-with-article-headers
2178 ;; When displaying parts, this function can be called several times on
2179 ;; the same article, without any intended toggle semantic (as typing `W
2180 ;; D d' would have). So face deletion must occur only when we come from
2181 ;; an interactive command, that is when the *Article* buffer is
2183 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2184 (gnus-delete-images 'face)
2187 (when (and wash-face-p
2189 (goto-char (point-min))
2190 (not (re-search-forward "^Face:[\t ]*" nil t)))
2191 (gnus-buffer-live-p gnus-original-article-buffer))
2192 (set-buffer gnus-original-article-buffer))
2194 (mail-narrow-to-head)
2195 (while (gnus-article-goto-header "Face")
2196 (push (mail-header-field-value) faces))))
2197 (while (setq face (pop faces))
2198 (let ((png (gnus-convert-face-to-png face))
2201 (setq image (gnus-create-image png 'png t))
2202 (gnus-article-goto-header "from")
2204 (insert "From: [no `from' set]\n")
2206 (gnus-add-wash-type 'face)
2207 (gnus-add-image 'face image)
2208 (gnus-put-image image nil 'face))))))
2211 (defun article-display-x-face (&optional force)
2212 "Look for an X-Face header and display it if present."
2213 (interactive (list 'force))
2214 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2215 (gnus-with-article-headers
2216 ;; Delete the old process, if any.
2217 (when (process-status "article-x-face")
2218 (delete-process "article-x-face"))
2219 ;; See the comment in `article-display-face'.
2220 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2221 ;; We have already displayed X-Faces, so we remove them
2223 (gnus-delete-images 'xface)
2225 (let (x-faces from face)
2227 (when (and wash-face-p
2229 (goto-char (point-min))
2230 (not (re-search-forward
2231 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2232 (gnus-buffer-live-p gnus-original-article-buffer))
2233 ;; If type `W f', use gnus-original-article-buffer,
2234 ;; otherwise use the current buffer because displaying
2235 ;; RFC822 parts calls this function too.
2236 (set-buffer gnus-original-article-buffer))
2238 (mail-narrow-to-head)
2239 (while (gnus-article-goto-header "X-Face")
2240 (push (mail-header-field-value) x-faces))
2241 (setq from (message-fetch-field "from"))))
2242 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2243 ;; single external face.
2244 (when (stringp gnus-article-x-face-command)
2245 (setq x-faces (list (car x-faces))))
2246 (while (and (setq face (pop x-faces))
2247 gnus-article-x-face-command
2249 ;; Check whether this face is censored.
2250 (not gnus-article-x-face-too-ugly)
2251 (and gnus-article-x-face-too-ugly from
2252 (not (string-match gnus-article-x-face-too-ugly
2254 ;; We display the face.
2255 (cond ((stringp gnus-article-x-face-command)
2256 ;; The command is a string, so we interpret the command
2257 ;; as a, well, command, and fork it off.
2258 (let ((process-connection-type nil))
2259 (process-kill-without-query
2261 "article-x-face" nil shell-file-name
2262 shell-command-switch gnus-article-x-face-command))
2265 (process-send-region "article-x-face"
2266 (point-min) (point-max)))
2267 (process-send-eof "article-x-face")))
2268 ((functionp gnus-article-x-face-command)
2269 ;; The command is a lisp function, so we call it.
2270 (funcall gnus-article-x-face-command face))
2272 (error "%s is not a function"
2273 gnus-article-x-face-command)))))))))
2275 (defun article-decode-mime-words ()
2276 "Decode all MIME-encoded words in the article."
2279 (set-buffer gnus-article-buffer)
2280 (let ((inhibit-point-motion-hooks t)
2282 (mail-parse-charset gnus-newsgroup-charset)
2283 (mail-parse-ignored-charsets
2284 (save-excursion (set-buffer gnus-summary-buffer)
2285 gnus-newsgroup-ignored-charsets)))
2286 (mail-decode-encoded-word-region (point-min) (point-max)))))
2288 (defun article-decode-charset (&optional prompt)
2289 "Decode charset-encoded text in the article.
2290 If PROMPT (the prefix), prompt for a coding system to use."
2292 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2294 (mail-parse-charset gnus-newsgroup-charset)
2295 (mail-parse-ignored-charsets
2296 (save-excursion (condition-case nil
2297 (set-buffer gnus-summary-buffer)
2299 gnus-newsgroup-ignored-charsets))
2300 ct cte ctl charset format)
2303 (article-narrow-to-head)
2304 (setq ct (message-fetch-field "Content-Type" t)
2305 cte (message-fetch-field "Content-Transfer-Encoding" t)
2306 ctl (and ct (ignore-errors
2307 (mail-header-parse-content-type ct)))
2310 (mm-read-coding-system "Charset to decode: "))
2312 (mail-content-type-get ctl 'charset)))
2313 format (and ctl (mail-content-type-get ctl 'format)))
2315 (setq cte (mail-header-strip cte)))
2316 (if (and ctl (not (string-match "/" (car ctl))))
2318 (goto-char (point-max)))
2321 (narrow-to-region (point) (point-max))
2322 (when (and (eq mail-parse-charset 'gnus-decoded)
2323 (eq (mm-body-7-or-8) '8bit))
2324 ;; The text code could have been decoded.
2325 (setq charset mail-parse-charset))
2326 (when (and (or (not ctl)
2327 (equal (car ctl) "text/plain"))
2328 (not format)) ;; article with format will decode later.
2330 charset (and cte (intern (downcase
2331 (gnus-strip-whitespace cte))))
2334 (defun article-decode-encoded-words ()
2335 "Remove encoded-word encoding from headers."
2336 (let (buffer-read-only)
2337 (let ((charset (save-excursion
2338 (set-buffer gnus-summary-buffer)
2339 default-mime-charset)))
2340 (mime-decode-header-in-buffer charset))))
2342 (defun article-decode-group-name ()
2343 "Decode group names in `Newsgroups:'."
2344 (let ((inhibit-point-motion-hooks t)
2346 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2347 (when (and (or gnus-group-name-charset-method-alist
2348 gnus-group-name-charset-group-alist)
2349 (gnus-buffer-live-p gnus-original-article-buffer))
2351 (article-narrow-to-head)
2352 (with-current-buffer gnus-original-article-buffer
2353 (goto-char (point-min)))
2354 (while (re-search-forward
2355 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2356 (replace-match (save-match-data
2357 (gnus-decode-newsgroups
2358 ;; XXX how to use data in article buffer?
2359 (with-current-buffer gnus-original-article-buffer
2361 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2364 gnus-newsgroup-name method))
2366 (goto-char (point-min))
2367 (with-current-buffer gnus-original-article-buffer
2368 (goto-char (point-min)))
2369 (while (re-search-forward
2370 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2371 (replace-match (save-match-data
2372 (gnus-decode-newsgroups
2373 ;; XXX how to use data in article buffer?
2374 (with-current-buffer gnus-original-article-buffer
2376 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2379 gnus-newsgroup-name method))
2382 (autoload 'idna-to-unicode "idna")
2384 (defun article-decode-idna-rhs ()
2385 "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2388 (let ((inhibit-point-motion-hooks t)
2390 (article-narrow-to-head)
2391 (goto-char (point-min))
2392 (while (re-search-forward "\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2394 (when (save-match-data
2395 (and (setq ace (match-string 1))
2397 (and (re-search-backward "^[^ \t]" nil t)
2398 (looking-at "From\\|To\\|Cc")))
2399 (save-excursion (backward-char)
2400 (message-idna-inside-rhs-p))
2401 (setq unicode (idna-to-unicode ace))))
2402 (unless (string= ace unicode)
2403 (replace-match unicode nil nil nil 1)))))))))
2405 (defun article-de-quoted-unreadable (&optional force read-charset)
2406 "Translate a quoted-printable-encoded article.
2407 If FORCE, decode the article whether it is marked as quoted-printable
2409 If READ-CHARSET, ask for a coding system."
2410 (interactive (list 'force current-prefix-arg))
2412 (let ((buffer-read-only nil) type charset)
2413 (if (gnus-buffer-live-p gnus-original-article-buffer)
2414 (with-current-buffer gnus-original-article-buffer
2416 (gnus-fetch-field "content-transfer-encoding"))
2417 (let* ((ct (gnus-fetch-field "content-type"))
2420 (mail-header-parse-content-type ct)))))
2421 (setq charset (and ctl
2422 (mail-content-type-get ctl 'charset)))
2423 (if (stringp charset)
2424 (setq charset (intern (downcase charset)))))))
2426 (setq charset (mm-read-coding-system "Charset: " charset)))
2428 (setq charset gnus-newsgroup-charset))
2430 (and type (let ((case-fold-search t))
2431 (string-match "quoted-printable" type))))
2433 (quoted-printable-decode-region
2434 (point) (point-max) (mm-charset-to-coding-system charset))))))
2436 (defun article-de-base64-unreadable (&optional force read-charset)
2437 "Translate a base64 article.
2438 If FORCE, decode the article whether it is marked as base64 not.
2439 If READ-CHARSET, ask for a coding system."
2440 (interactive (list 'force current-prefix-arg))
2442 (let ((buffer-read-only nil) type charset)
2443 (if (gnus-buffer-live-p gnus-original-article-buffer)
2444 (with-current-buffer gnus-original-article-buffer
2446 (gnus-fetch-field "content-transfer-encoding"))
2447 (let* ((ct (gnus-fetch-field "content-type"))
2450 (mail-header-parse-content-type ct)))))
2451 (setq charset (and ctl
2452 (mail-content-type-get ctl 'charset)))
2453 (if (stringp charset)
2454 (setq charset (intern (downcase charset)))))))
2456 (setq charset (mm-read-coding-system "Charset: " charset)))
2458 (setq charset gnus-newsgroup-charset))
2460 (and type (let ((case-fold-search t))
2461 (string-match "base64" type))))
2464 (narrow-to-region (point) (point-max))
2465 (base64-decode-region (point-min) (point-max))
2466 (mm-decode-coding-region
2467 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2472 (defun article-decode-HZ ()
2473 "Translate a HZ-encoded article."
2477 (let ((buffer-read-only nil))
2478 (rfc1843-decode-region (point-min) (point-max)))))
2480 (defun article-unsplit-urls ()
2481 "Remove the newlines that some other mailers insert into URLs."
2484 (let ((buffer-read-only nil))
2485 (goto-char (point-min))
2486 (while (re-search-forward
2487 "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2488 (replace-match "\\1\\3" t)))
2489 (when (interactive-p)
2490 (gnus-treat-article nil))))
2493 (defun article-wash-html (&optional read-charset)
2494 "Format an HTML article.
2495 If READ-CHARSET, ask for a coding system."
2498 (let ((buffer-read-only nil)
2500 (when (gnus-buffer-live-p gnus-original-article-buffer)
2501 (with-current-buffer gnus-original-article-buffer
2502 (let* ((ct (gnus-fetch-field "content-type"))
2505 (mail-header-parse-content-type ct)))))
2506 (setq charset (and ctl
2507 (mail-content-type-get ctl 'charset)))
2508 (when (stringp charset)
2509 (setq charset (intern (downcase charset)))))))
2511 (setq charset (mm-read-coding-system "Charset: " charset)))
2513 (setq charset gnus-newsgroup-charset))
2515 (save-window-excursion
2517 (narrow-to-region (point) (point-max))
2518 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2519 (entry (assq func mm-text-html-washer-alist)))
2521 (setq func (cdr entry)))
2526 (apply (car func) (cdr func))))))))))
2528 (defun gnus-article-wash-html-with-w3 ()
2529 "Wash the current buffer with w3."
2531 (let ((w3-strict-width (window-width))
2532 (url-standalone-mode t)
2533 (url-gateway-unplugged t)
2534 (w3-honor-stylesheets nil))
2536 (w3-region (point-min) (point-max))
2539 (defun gnus-article-wash-html-with-w3m ()
2540 "Wash the current buffer with emacs-w3m."
2543 (narrow-to-region (point) (point-max))
2544 (let ((w3m-safe-url-regexp (if mm-inline-text-html-with-images
2547 w3m-force-redisplay)
2548 (w3m-region (point-min) (point-max)))
2549 (when (and mm-inline-text-html-with-w3m-keymap
2550 (boundp 'w3m-minor-mode-map)
2552 (add-text-properties
2553 (point-min) (point-max)
2554 (list 'keymap w3m-minor-mode-map
2555 ;; Put the mark meaning this part was rendered by emacs-w3m.
2556 'mm-inline-text-html-with-w3m t)))))
2558 (defun article-hide-list-identifiers ()
2559 "Remove list identifies from the Subject header.
2560 The `gnus-list-identifiers' variable specifies what to do."
2562 (let ((inhibit-point-motion-hooks t)
2563 (regexp (if (consp gnus-list-identifiers)
2564 (mapconcat 'identity gnus-list-identifiers " *\\|")
2565 gnus-list-identifiers))
2570 (article-narrow-to-head)
2571 (goto-char (point-min))
2572 (while (re-search-forward
2573 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2575 (delete-region (match-beginning 2) (match-end 0))
2576 (beginning-of-line))
2577 (when (re-search-forward
2578 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2579 (delete-region (match-beginning 1) (match-end 1))))))))
2581 (defun article-hide-pem (&optional arg)
2582 "Toggle hiding of any PEM headers and signatures in the current article.
2583 If given a negative prefix, always show; if given a positive prefix,
2585 (interactive (gnus-article-hidden-arg))
2586 (unless (gnus-article-check-hidden-text 'pem arg)
2588 (let (buffer-read-only end)
2589 (goto-char (point-min))
2590 ;; Hide the horrendously ugly "header".
2591 (when (and (search-forward
2592 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2594 (setq end (1+ (match-beginning 0))))
2595 (gnus-add-wash-type 'pem)
2596 (gnus-article-hide-text-type
2598 (if (search-forward "\n\n" nil t)
2602 ;; Hide the trailer as well
2603 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2605 (gnus-article-hide-text-type
2606 (match-beginning 0) (match-end 0) 'pem)))))))
2608 (defun article-strip-banner ()
2609 "Strip the banners specified by the `banner' group parameter and by
2610 `gnus-article-address-banner-alist'."
2614 (let ((inhibit-point-motion-hooks t))
2615 (when (gnus-parameter-banner gnus-newsgroup-name)
2616 (article-really-strip-banner
2617 (gnus-parameter-banner gnus-newsgroup-name)))
2618 (when gnus-article-address-banner-alist
2619 (article-really-strip-banner
2620 (let ((from (save-restriction
2622 (article-narrow-to-head)
2623 (mail-fetch-field "from"))))
2626 (caar (mail-header-parse-addresses from))))
2628 (dolist (pair gnus-article-address-banner-alist)
2629 (when (string-match (car pair) from)
2630 (throw 'found (cdr pair)))))))))))))
2632 (defun article-really-strip-banner (banner)
2633 "Strip the banner specified by the argument."
2636 (let ((inhibit-point-motion-hooks t)
2637 (gnus-signature-limit nil)
2641 ((eq banner 'signature)
2642 (when (gnus-article-narrow-to-signature)
2645 (delete-region (point) (point-max))))
2647 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2648 (while (re-search-forward banner nil t)
2649 (delete-region (match-beginning 0) (match-end 0)))))
2651 (while (re-search-forward banner nil t)
2652 (delete-region (match-beginning 0) (match-end 0)))))))))
2654 (defun article-babel ()
2655 "Translate article using an online translation service."
2659 (set-buffer gnus-article-buffer)
2660 (when (article-goto-body)
2661 (let* ((buffer-read-only nil)
2664 (orig (buffer-substring start end))
2665 (trans (babel-as-string orig)))
2667 (narrow-to-region start end)
2668 (delete-region start end)
2671 (defun article-hide-signature (&optional arg)
2672 "Hide the signature in the current article.
2673 If given a negative prefix, always show; if given a positive prefix,
2675 (interactive (gnus-article-hidden-arg))
2681 (article-goto-body))
2682 (goto-char (point-min)))
2683 (unless (gnus-article-check-hidden-text 'signature arg)
2684 (let ((buffer-read-only nil)
2686 (while (setq button (text-property-any button (point-max)
2688 'gnus-signature-toggle))
2689 (setq button (text-property-not-all button (point-max)
2691 'gnus-signature-toggle))
2692 (when (and button (not (eobp)))
2693 (gnus-article-hide-text-type
2695 (next-single-property-change (1+ button) 'mime-view-entity
2698 (gnus-set-mode-line 'article))
2700 (defun article-strip-headers-in-body ()
2701 "Strip offensive headers from bodies."
2705 (let ((case-fold-search t))
2706 (when (looking-at "x-no-archive:")
2707 (gnus-delete-line)))))
2709 (defun article-strip-leading-blank-lines ()
2710 "Remove all blank lines from the beginning of the article."
2713 (let ((inhibit-point-motion-hooks t)
2715 (when (article-goto-body)
2716 (while (and (not (eobp))
2717 (looking-at "[ \t]*$"))
2718 (gnus-delete-line))))))
2720 (defun article-narrow-to-head ()
2721 "Narrow the buffer to the head of the message.
2722 Point is left at the beginning of the narrowed-to region."
2724 (goto-char (point-min))
2725 (if (search-forward "\n\n" nil 1)
2728 (goto-char (point-min)))
2730 (defun article-goto-body ()
2731 "Place point at the start of the body."
2732 (goto-char (point-min))
2734 ;; This variable is only bound when dealing with separate
2736 (article-goto-body-goes-to-point-min-p
2738 ((search-forward "\n\n" nil t)
2741 (goto-char (point-max))
2744 (defun article-strip-multiple-blank-lines ()
2745 "Replace consecutive blank lines with one empty line."
2748 (let ((inhibit-point-motion-hooks t)
2750 ;; First make all blank lines empty.
2752 (while (re-search-forward "^[ \t]+$" nil t)
2753 (unless (gnus-annotation-in-region-p
2754 (match-beginning 0) (match-end 0))
2755 (replace-match "" nil t)))
2756 ;; Then replace multiple empty lines with a single empty line.
2758 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2759 (unless (gnus-annotation-in-region-p
2760 (match-beginning 0) (match-end 0))
2761 (delete-region (match-beginning 1) (match-end 1)))))))
2763 (defun article-strip-leading-space ()
2764 "Remove all white space from the beginning of the lines in the article."
2767 (let ((inhibit-point-motion-hooks t)
2770 (while (re-search-forward "^[ \t]+" nil t)
2771 (replace-match "" t t)))))
2773 (defun article-strip-trailing-space ()
2774 "Remove all white space from the end of the lines in the article."
2777 (let ((inhibit-point-motion-hooks t)
2780 (while (re-search-forward "[ \t]+$" nil t)
2781 (replace-match "" t t)))))
2783 (defun article-strip-blank-lines ()
2784 "Strip leading, trailing and multiple blank lines."
2786 (article-strip-leading-blank-lines)
2787 (article-remove-trailing-blank-lines)
2788 (article-strip-multiple-blank-lines))
2790 (defun article-strip-all-blank-lines ()
2791 "Strip all blank lines."
2794 (let ((inhibit-point-motion-hooks t)
2797 (while (re-search-forward "^[ \t]*\n" nil t)
2798 (replace-match "" t t)))))
2800 (defun gnus-article-narrow-to-signature ()
2801 "Narrow to the signature; return t if a signature is found, else nil."
2802 (let ((inhibit-point-motion-hooks t))
2803 (when (gnus-article-search-signature)
2805 ;; Check whether we have some limits to what we consider
2806 ;; to be a signature.
2807 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2808 (list gnus-signature-limit)))
2810 (while (setq limit (pop limits))
2811 (if (or (and (integerp limit)
2812 (< (- (point-max) (point)) limit))
2814 (< (count-lines (point) (point-max)) limit))
2815 (and (functionp limit)
2817 (and (stringp limit)
2818 (not (re-search-forward limit nil t))))
2819 () ; This limit did not succeed.
2823 (narrow-to-region (point) (point-max))
2826 (defun gnus-article-search-signature ()
2827 "Search the current buffer for the signature separator.
2828 Put point at the beginning of the signature separator."
2829 (let ((cur (point)))
2830 (goto-char (point-max))
2831 (if (if (stringp gnus-signature-separator)
2832 (re-search-backward gnus-signature-separator nil t)
2833 (let ((seps gnus-signature-separator))
2835 (not (re-search-backward (car seps) nil t)))
2842 (defun gnus-article-hidden-arg ()
2843 "Return the current prefix arg as a number, or 0 if no prefix."
2844 (list (if current-prefix-arg
2845 (prefix-numeric-value current-prefix-arg)
2848 (defun gnus-article-check-hidden-text (type arg)
2849 "Return nil if hiding is necessary.
2850 Arg can be nil or a number. nil and positive means hide, negative
2851 means show, 0 means toggle."
2854 (let ((hide (gnus-article-hidden-text-p type)))
2860 (gnus-article-show-hidden-text type)
2863 (if (eq hide 'hidden)
2865 (gnus-article-show-hidden-text type)
2869 (defun gnus-article-hidden-text-p (type)
2870 "Say whether the current buffer contains hidden text of type TYPE."
2871 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2873 (not (get-text-property pos 'invisible))
2874 (not (get-text-property pos 'dummy-invisible)))
2876 (text-property-any (1+ pos) (point-max) 'article-type type)))
2881 (defun gnus-article-show-hidden-text (type &optional dummy)
2882 "Show all hidden text of type TYPE.
2883 Originally it is hide instead of DUMMY."
2884 (let ((buffer-read-only nil)
2885 (inhibit-point-motion-hooks t))
2886 (gnus-remove-text-properties-when
2888 (point-min) (point-max)
2889 (cons 'article-type (cons type
2890 gnus-hidden-properties)))
2891 (gnus-delete-wash-type type)))
2893 (defconst article-time-units
2894 `((year . ,(* 365.25 24 60 60))
2895 (week . ,(* 7 24 60 60))
2896 (day . ,(* 24 60 60))
2900 "Mapping from time units to seconds.")
2902 (defun gnus-article-forward-header ()
2903 "Move point to the start of the next header.
2904 If the current header is a continuation header, this can be several
2909 (if (looking-at "[ \t]+[^ \t]")
2913 (defun article-date-ut (&optional type highlight header)
2914 "Convert DATE date to universal time in the current article.
2915 If TYPE is `local', convert to local time; if it is `lapsed', output
2916 how much time has lapsed since DATE. For `lapsed', the value of
2917 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2918 should replace the \"Date:\" one, or should be added below it."
2919 (interactive (list 'ut t))
2920 (let* ((header (or header
2921 (and (eq 1 (point-min))
2922 (mail-header-date (save-excursion
2923 (set-buffer gnus-summary-buffer)
2924 gnus-current-headers)))
2925 (message-fetch-field "date")
2927 (date (if (vectorp header) (mail-header-date header)
2929 (inhibit-point-motion-hooks t)
2930 bface eface date-pos)
2931 (when (and date (not (string= date "")))
2934 (article-narrow-to-head)
2935 (when (or (and (eq type 'lapsed)
2936 gnus-article-date-lapsed-new-header
2937 ;; Attempt to get the face of X-Sent first.
2938 (re-search-forward "^X-Sent:[ \t]" nil t))
2939 (re-search-forward "^Date:[ \t]" nil t)
2940 ;; If Date is missing, try again for X-Sent.
2941 (re-search-forward "^X-Sent:[ \t]" nil t))
2942 (setq bface (get-text-property (point-at-bol) 'face)
2943 date (or (get-text-property (point-at-bol)
2946 eface (get-text-property (1- (point-at-eol))
2948 (let ((buffer-read-only nil))
2949 ;; Delete any old X-Sent headers.
2950 (when (setq date-pos
2951 (text-property-any (point-min) (point-max)
2952 'article-date-lapsed t))
2953 (goto-char (setq date-pos (set-marker (make-marker) date-pos)))
2954 (delete-region (match-beginning 0)
2955 (progn (forward-line 1) (point))))
2956 (goto-char (point-min))
2957 ;; Delete any old Date headers.
2958 (while (re-search-forward "^Date:[ \t]" nil t)
2960 (setq date-pos (match-beginning 0)))
2961 (unless (and (eq type 'lapsed)
2962 gnus-article-date-lapsed-new-header)
2963 (delete-region (match-beginning 0)
2964 (progn (message-next-header) (point)))))
2967 (goto-char date-pos)
2969 ;; Possibly, Date has been deleted.
2971 (when (and (eq type 'lapsed)
2972 gnus-article-date-lapsed-new-header
2973 (looking-at "Date:"))
2975 (goto-char (point-min)))
2976 (insert (article-make-date-line date type))
2977 (when (eq type 'lapsed)
2978 (put-text-property (point-at-bol) (point)
2979 'article-date-lapsed t))
2983 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2984 (put-text-property (match-beginning 1) (1+ (match-end 1))
2985 'original-date date)
2986 (put-text-property (match-beginning 1) (1+ (match-end 1))
2988 (put-text-property (match-beginning 2) (match-end 2)
2991 (defun article-make-date-line (date type)
2992 "Return a DATE line of TYPE."
2993 (unless (memq type '(local ut original user iso8601 lapsed english))
2994 (error "Unknown conversion type: %s" type))
2996 (let ((time (date-to-time date)))
2998 ;; Convert to the local timezone.
3000 (let ((tz (car (current-time-zone time))))
3001 (format "Date: %s %s%02d%02d" (current-time-string time)
3002 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3003 (/ (% (abs tz) 3600) 60))))
3004 ;; Convert to Universal Time.
3007 (current-time-string
3008 (let* ((e (parse-time-string date))
3009 (tm (apply 'encode-time e))
3011 (ls (- (cadr tm) (car (current-time-zone time)))))
3012 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3013 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3016 ;; Get the original date from the article.
3017 ((eq type 'original)
3018 (concat "Date: " (if (string-match "\n+$" date)
3019 (substring date 0 (match-beginning 0))
3021 ;; Let the user define the format.
3023 (let ((format (or (condition-case nil
3024 (with-current-buffer gnus-summary-buffer
3025 gnus-article-time-format)
3027 gnus-article-time-format)))
3028 (if (functionp format)
3029 (funcall format time)
3030 (concat "Date: " (format-time-string format time)))))
3033 (let ((tz (car (current-time-zone time))))
3036 (format-time-string "%Y%m%dT%H%M%S" time)
3037 (format "%s%02d%02d"
3038 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3039 (/ (% (abs tz) 3600) 60)))))
3040 ;; Do an X-Sent lapsed format.
3042 ;; If the date is seriously mangled, the timezone functions are
3043 ;; liable to bug out, so we ignore all errors.
3044 (let* ((now (current-time))
3045 (real-time (subtract-time now time))
3046 (real-sec (and real-time
3047 (+ (* (float (car real-time)) 65536)
3049 (sec (and real-time (abs real-sec)))
3059 ;; This is a bit convoluted, but basically we go
3060 ;; through the time units for years, weeks, etc,
3061 ;; and divide things to see whether that results
3062 ;; in positive answers.
3065 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3066 ;; The (remaining) seconds are too few to
3067 ;; be divided into this time unit.
3069 ;; It's big enough, so we output it.
3070 (setq sec (- sec (* num (cdr unit))))
3072 (concat (if prev ", " "") (int-to-string
3074 " " (symbol-name (car unit))
3075 (if (> num 1) "s" ""))
3077 article-time-units "")
3078 ;; If dates are odd, then it might appear like the
3079 ;; article was sent in the future.
3082 " in the future"))))))
3083 ;; Display the date in proper English
3085 (let ((dtime (decode-time time)))
3088 (number-to-string (nth 3 dtime))
3089 (let ((digit (% (nth 3 dtime) 10)))
3091 ((memq (nth 3 dtime) '(11 12 13)) "th")
3097 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3099 (number-to-string (nth 5 dtime))
3101 (format "%02d" (nth 2 dtime))
3103 (format "%02d" (nth 1 dtime)))))))
3105 (format "Date: %s (from T-gnus)" date))))
3107 (defun article-date-local (&optional highlight)
3108 "Convert the current article date to the local timezone."
3109 (interactive (list t))
3110 (article-date-ut 'local highlight))
3112 (defun article-date-english (&optional highlight)
3113 "Convert the current article date to something that is proper English."
3114 (interactive (list t))
3115 (article-date-ut 'english highlight))
3117 (defun article-date-original (&optional highlight)
3118 "Convert the current article date to what it was originally.
3119 This is only useful if you have used some other date conversion
3120 function and want to see what the date was before converting."
3121 (interactive (list t))
3122 (article-date-ut 'original highlight))
3124 (defun article-date-lapsed (&optional highlight)
3125 "Convert the current article date to time lapsed since it was sent."
3126 (interactive (list t))
3127 (article-date-ut 'lapsed highlight))
3129 (defun article-update-date-lapsed ()
3130 "Function to be run from a timer to update the lapsed time line."
3131 (let (deactivate-mark)
3136 (set-buffer (window-buffer w))
3137 (when (eq major-mode 'gnus-article-mode)
3138 (let ((mark (point-marker)))
3139 (goto-char (point-min))
3140 (when (re-search-forward "^X-Sent:" nil t)
3141 (article-date-lapsed t))
3142 (goto-char (marker-position mark))
3143 (move-marker mark nil))))
3146 (defun gnus-start-date-timer (&optional n)
3147 "Start a timer to update the X-Sent header in the article buffers.
3148 The numerical prefix says how frequently (in seconds) the function
3153 (gnus-stop-date-timer)
3154 (setq article-lapsed-timer
3155 (run-at-time 1 n 'article-update-date-lapsed)))
3157 (defun gnus-stop-date-timer ()
3158 "Stop the X-Sent timer."
3160 (when article-lapsed-timer
3161 (nnheader-cancel-timer article-lapsed-timer)
3162 (setq article-lapsed-timer nil)))
3164 (defun article-date-user (&optional highlight)
3165 "Convert the current article date to the user-defined format.
3166 This format is defined by the `gnus-article-time-format' variable."
3167 (interactive (list t))
3168 (article-date-ut 'user highlight))
3170 (defun article-date-iso8601 (&optional highlight)
3171 "Convert the current article date to ISO8601."
3172 (interactive (list t))
3173 (article-date-ut 'iso8601 highlight))
3175 ;; (defun article-show-all ()
3176 ;; "Show all hidden text in the article buffer."
3180 ;; (let ((buffer-read-only nil))
3181 ;; (gnus-article-unhide-text (point-min) (point-max))
3182 ;; (gnus-remove-text-with-property 'gnus-prev)
3183 ;; (gnus-remove-text-with-property 'gnus-next))))
3185 (defun article-show-all-headers ()
3186 "Show all hidden headers in the article buffer."
3191 (article-narrow-to-head)
3192 (let ((buffer-read-only nil))
3193 (gnus-article-unhide-text (point-min) (point-max))))))
3195 (defun article-remove-leading-whitespace ()
3196 "Remove excessive whitespace from all headers."
3200 (let ((buffer-read-only nil))
3201 (article-narrow-to-head)
3202 (goto-char (point-min))
3203 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3204 (delete-region (match-beginning 1) (match-end 1)))))))
3206 (defun article-emphasize (&optional arg)
3207 "Emphasize text according to `gnus-emphasis-alist'."
3208 (interactive (gnus-article-hidden-arg))
3209 (unless (gnus-article-check-hidden-text 'emphasis arg)
3213 (with-current-buffer gnus-summary-buffer
3214 gnus-article-emphasis-alist)
3216 gnus-emphasis-alist))
3217 (buffer-read-only nil)
3218 (props (append '(article-type emphasis)
3219 gnus-hidden-properties))
3220 regexp elem beg invisible visible face)
3223 (while (setq elem (pop alist))
3225 (setq regexp (car elem)
3226 invisible (nth 1 elem)
3227 visible (nth 2 elem)
3229 (while (re-search-forward regexp nil t)
3230 (when (and (match-beginning visible) (match-beginning invisible))
3231 (gnus-article-hide-text
3232 (match-beginning invisible) (match-end invisible) props)
3233 (gnus-article-unhide-text-type
3234 (match-beginning visible) (match-end visible) 'emphasis)
3235 (gnus-put-overlay-excluding-newlines
3236 (match-beginning visible) (match-end visible) 'face face)
3237 (gnus-add-wash-type 'emphasis)
3238 (goto-char (match-end invisible)))))))))
3240 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3241 "Setup newsgroup emphasis alist."
3242 (unless gnus-article-emphasis-alist
3243 (let ((name (and gnus-newsgroup-name
3244 (gnus-group-real-name gnus-newsgroup-name))))
3245 (make-local-variable 'gnus-article-emphasis-alist)
3246 (setq gnus-article-emphasis-alist
3248 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3249 (while (setq elem (pop alist))
3250 (when (and name (string-match (car elem) name))
3252 highlight (copy-sequence (cdr elem)))))
3254 (copy-sequence highlight-words)
3255 (if gnus-newsgroup-name
3256 (copy-sequence (gnus-group-find-parameter
3257 gnus-newsgroup-name 'highlight-words t)))
3258 gnus-emphasis-alist)))))
3261 (defvar gnus-summary-article-menu)
3262 (defvar gnus-summary-post-menu))
3264 ;;; Saving functions.
3266 (defun gnus-article-save (save-buffer file &optional num)
3267 "Save the currently selected article."
3268 (unless gnus-save-all-headers
3269 ;; Remove headers according to `gnus-saved-headers'.
3270 (let ((gnus-visible-headers
3271 (or gnus-saved-headers gnus-visible-headers))
3272 (gnus-article-buffer save-buffer))
3274 (set-buffer save-buffer)
3275 (article-hide-headers 1 t))))
3276 (save-window-excursion
3277 (if (not gnus-default-article-saver)
3278 (error "No default saver is defined")
3279 ;; !!! Magic! The saving functions all save
3280 ;; `gnus-save-article-buffer' (or so they think), but we
3281 ;; bind that variable to our save-buffer.
3282 (set-buffer gnus-article-buffer)
3283 (let* ((gnus-save-article-buffer save-buffer)
3286 ((not gnus-prompt-before-saving) 'default)
3287 ((eq gnus-prompt-before-saving 'always) nil)
3289 (gnus-number-of-articles-to-be-saved
3290 (when (eq gnus-prompt-before-saving t)
3292 (set-buffer gnus-article-current-summary)
3293 (funcall gnus-default-article-saver filename)))))
3295 (defun gnus-read-save-file-name (prompt &optional filename
3296 function group headers variable)
3298 (funcall function group headers (symbol-value variable)))
3303 ((eq filename 'default)
3309 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3312 (if (and gnus-number-of-articles-to-be-saved
3313 (> gnus-number-of-articles-to-be-saved 1))
3314 (format "these %d articles"
3315 gnus-number-of-articles-to-be-saved)
3318 ;; Let the split methods have their say.
3320 ;; No split name was found.
3323 (concat prompt " (default "
3324 (file-name-nondirectory default-name) ") ")
3325 (file-name-directory default-name)
3327 ;; A single group name is returned.
3328 ((stringp split-name)
3330 (funcall function split-name headers
3331 (symbol-value variable)))
3333 (concat prompt " (default "
3334 (file-name-nondirectory default-name) ") ")
3335 (file-name-directory default-name)
3337 ;; A single split name was found
3338 ((= 1 (length split-name))
3339 (let* ((name (expand-file-name
3341 gnus-article-save-directory))
3342 (dir (cond ((file-directory-p name)
3343 (file-name-as-directory name))
3344 ((file-exists-p name) name)
3345 (t gnus-article-save-directory))))
3347 (concat prompt " (default " name ") ")
3349 ;; A list of splits was found.
3351 (setq split-name (nreverse split-name))
3353 (let ((file-name-history
3354 (nconc split-name file-name-history)))
3358 (concat prompt " (`M-p' for defaults) ")
3359 gnus-article-save-directory
3361 gnus-article-save-directory)))
3362 (car (push result file-name-history)))))))
3363 ;; Create the directory.
3364 (gnus-make-directory (file-name-directory file))
3365 ;; If we have read a directory, we append the default file name.
3366 (when (file-directory-p file)
3367 (setq file (expand-file-name (file-name-nondirectory
3369 (file-name-as-directory file))))
3370 ;; Possibly translate some characters.
3371 (nnheader-translate-file-chars file))))))
3372 (gnus-make-directory (file-name-directory result))
3373 (set variable result)))
3375 (defun gnus-article-archive-name (group)
3376 "Return the first instance of an \"Archive-name\" in the current buffer."
3377 (let ((case-fold-search t))
3378 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3379 (nnheader-concat gnus-article-save-directory
3380 (match-string 1)))))
3382 (defun gnus-article-nndoc-name (group)
3383 "If GROUP is an nndoc group, return the name of the parent group."
3384 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3385 (gnus-group-get-parameter group 'save-article-group)))
3387 (defun gnus-summary-save-in-rmail (&optional filename)
3388 "Append this article to Rmail file.
3389 Optional argument FILENAME specifies file name.
3390 Directory to save to is default to `gnus-article-save-directory'."
3391 (setq filename (gnus-read-save-file-name
3392 "Save %s in rmail file:" filename
3393 gnus-rmail-save-name gnus-newsgroup-name
3394 gnus-current-headers 'gnus-newsgroup-last-rmail))
3395 (gnus-eval-in-buffer-window gnus-save-article-buffer
3399 (gnus-output-to-rmail filename))))
3402 (defun gnus-summary-save-in-mail (&optional filename)
3403 "Append this article to Unix mail file.
3404 Optional argument FILENAME specifies file name.
3405 Directory to save to is default to `gnus-article-save-directory'."
3406 (setq filename (gnus-read-save-file-name
3407 "Save %s in Unix mail file:" filename
3408 gnus-mail-save-name gnus-newsgroup-name
3409 gnus-current-headers 'gnus-newsgroup-last-mail))
3410 (gnus-eval-in-buffer-window gnus-save-article-buffer
3414 (if (and (file-readable-p filename)
3415 (file-regular-p filename)
3416 (mail-file-babyl-p filename))
3417 (rmail-output-to-rmail-file filename t)
3418 (gnus-output-to-mail filename)))))
3421 (defun gnus-summary-save-in-file (&optional filename overwrite)
3422 "Append this article to file.
3423 Optional argument FILENAME specifies file name.
3424 Directory to save to is default to `gnus-article-save-directory'."
3425 (setq filename (gnus-read-save-file-name
3426 "Save %s in file:" filename
3427 gnus-file-save-name gnus-newsgroup-name
3428 gnus-current-headers 'gnus-newsgroup-last-file))
3429 (gnus-eval-in-buffer-window gnus-save-article-buffer
3433 (when (and overwrite
3434 (file-exists-p filename))
3435 (delete-file filename))
3436 (gnus-output-to-file filename))))
3439 (defun gnus-summary-write-to-file (&optional filename)
3440 "Write this article to a file, overwriting it if the file exists.
3441 Optional argument FILENAME specifies file name.
3442 The directory to save in defaults to `gnus-article-save-directory'."
3443 (gnus-summary-save-in-file nil t))
3445 (defun gnus-summary-save-body-in-file (&optional filename)
3446 "Append this article body to a file.
3447 Optional argument FILENAME specifies file name.
3448 The directory to save in defaults to `gnus-article-save-directory'."
3449 (setq filename (gnus-read-save-file-name
3450 "Save %s body in file:" filename
3451 gnus-file-save-name gnus-newsgroup-name
3452 gnus-current-headers 'gnus-newsgroup-last-file))
3453 (gnus-eval-in-buffer-window gnus-save-article-buffer
3457 (when (article-goto-body)
3458 (narrow-to-region (point) (point-max)))
3459 (gnus-output-to-file filename))))
3462 (defun gnus-summary-save-in-pipe (&optional command)
3463 "Pipe this article to subprocess."
3465 (cond ((and (eq command 'default)
3466 gnus-last-shell-command)
3467 gnus-last-shell-command)
3472 "Shell command on %s: "
3473 (if (and gnus-number-of-articles-to-be-saved
3474 (> gnus-number-of-articles-to-be-saved 1))
3475 (format "these %d articles"
3476 gnus-number-of-articles-to-be-saved)
3478 gnus-last-shell-command))))
3479 (when (string-equal command "")
3480 (if gnus-last-shell-command
3481 (setq command gnus-last-shell-command)
3482 (error "A command is required")))
3483 (gnus-eval-in-buffer-window gnus-article-buffer
3486 (shell-command-on-region (point-min) (point-max) command nil)))
3487 (setq gnus-last-shell-command command))
3489 (defun gnus-summary-pipe-to-muttprint (&optional command)
3490 "Pipe this article to muttprint."
3491 (setq command (read-string
3492 "Print using command: " gnus-summary-muttprint-program
3493 nil gnus-summary-muttprint-program))
3494 (gnus-summary-save-in-pipe command))
3496 ;;; Article file names when saving.
3498 (defun gnus-capitalize-newsgroup (newsgroup)
3499 "Capitalize NEWSGROUP name."
3500 (when (not (zerop (length newsgroup)))
3501 (concat (char-to-string (upcase (aref newsgroup 0)))
3502 (substring newsgroup 1))))
3504 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3505 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3506 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3507 Otherwise, it is like ~/News/news/group/num."
3510 (concat (if (gnus-use-long-file-name 'not-save)
3511 (gnus-capitalize-newsgroup newsgroup)
3512 (gnus-newsgroup-directory-form newsgroup))
3513 "/" (int-to-string (mail-header-number headers)))
3514 gnus-article-save-directory)))
3516 (string-equal (file-name-directory default)
3517 (file-name-directory last-file))
3518 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3520 (or last-file default))))
3522 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3523 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3524 If variable `gnus-use-long-file-name' is non-nil, it is
3525 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3528 (concat (if (gnus-use-long-file-name 'not-save)
3530 (gnus-newsgroup-directory-form newsgroup))
3531 "/" (int-to-string (mail-header-number headers)))
3532 gnus-article-save-directory)))
3534 (string-equal (file-name-directory default)
3535 (file-name-directory last-file))
3536 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3538 (or last-file default))))
3540 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3541 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3542 If variable `gnus-use-long-file-name' is non-nil, it is
3543 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3546 (if (gnus-use-long-file-name 'not-save)
3549 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3551 gnus-article-save-directory)))
3553 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3554 "Generate file name from sender."
3555 (let ((from (mail-header-from headers)))
3557 (if (and from (string-match "\\([^ <]+\\)@" from))
3558 (match-string 1 from)
3560 gnus-article-save-directory)))
3562 (defun article-verify-x-pgp-sig ()
3565 (if (gnus-buffer-live-p gnus-original-article-buffer)
3566 (let ((sig (with-current-buffer gnus-original-article-buffer
3567 (gnus-fetch-field "X-PGP-Sig")))
3571 (mml2015-clear-verify-function))
3573 (insert-buffer-substring gnus-original-article-buffer)
3574 (setq items (split-string sig))
3575 (message-narrow-to-head)
3576 (let ((inhibit-point-motion-hooks t)
3577 (case-fold-search t))
3578 ;; Don't verify multiple headers.
3579 (setq headers (mapconcat (lambda (header)
3581 (mail-fetch-field header)
3583 (split-string (nth 1 items) ",") "")))
3584 (delete-region (point-min) (point-max))
3585 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3586 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3591 (if (looking-at "^-")
3594 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3595 (insert "Version: " (car items) "\n\n")
3596 (insert (mapconcat 'identity (cddr items) "\n"))
3597 (insert "\n-----END PGP SIGNATURE-----\n")
3598 (let ((mm-security-handle (list (format "multipart/signed"))))
3599 (mml2015-clean-buffer)
3600 (let ((coding-system-for-write (or gnus-newsgroup-charset
3602 (funcall (mml2015-clear-verify-function)))
3604 (or (mm-handle-multipart-ctl-parameter
3605 mm-security-handle 'gnus-details)
3606 (mm-handle-multipart-ctl-parameter
3607 mm-security-handle 'gnus-info)))))
3609 (let (buffer-read-only bface eface)
3611 (message-narrow-to-head)
3612 (goto-char (point-max))
3614 (setq bface (get-text-property (point-at-bol) 'face)
3615 eface (get-text-property (1- (point-at-eol)) 'face))
3616 (message-remove-header "X-Gnus-PGP-Verify")
3617 (if (re-search-forward "^X-PGP-Sig:" nil t)
3619 (goto-char (point-max)))
3620 (narrow-to-region (point) (point))
3621 (insert "X-Gnus-PGP-Verify: " info "\n")
3622 (goto-char (point-min))
3625 (if (not (looking-at "^[ \t]"))
3629 (goto-char (point-min))
3630 (when (looking-at "\\([^:]+\\): *")
3631 (put-text-property (match-beginning 1) (1+ (match-end 1))
3633 (put-text-property (match-end 0) (point-max)
3634 'face eface)))))))))
3636 (defun article-verify-cancel-lock ()
3637 "Verify Cancel-Lock header."
3639 (if (gnus-buffer-live-p gnus-original-article-buffer)
3640 (canlock-verify gnus-original-article-buffer)))
3642 (defun article-monafy ()
3643 "Display body part with mona font."
3645 (unless (if (featurep 'xemacs)
3646 (find-face 'gnus-mona-face)
3647 (facep 'gnus-mona-face))
3648 (require 'navi2ch-mona)
3649 (set-face-font (make-face 'gnus-mona-face) navi2ch-mona-font))
3651 (let ((buffer-read-only nil))
3654 (gnus-make-overlay (point) (point-max))
3655 'face 'gnus-mona-face))))
3662 (setq afunc (car func)
3665 gfunc (intern (format "gnus-%s" func))))
3667 (when (fboundp afunc)
3668 `(lambda (&optional interactive &rest args)
3669 ,(documentation afunc t)
3670 (interactive (list t))
3672 (set-buffer gnus-article-buffer)
3674 (call-interactively ',afunc)
3675 (apply ',afunc args))))))))
3676 '(article-hide-headers
3677 article-verify-x-pgp-sig
3678 article-verify-cancel-lock
3680 article-hide-boring-headers
3681 article-treat-overstrike
3682 article-treat-ansi-sequences
3683 article-fill-long-lines
3684 article-capitalize-sentences
3686 article-remove-leading-whitespace
3687 article-display-x-face
3688 article-display-face
3689 article-de-quoted-unreadable
3690 article-de-base64-unreadable
3693 article-unsplit-urls
3694 article-hide-list-identifiers
3695 article-strip-banner
3698 article-hide-signature
3699 article-strip-headers-in-body
3700 article-remove-trailing-blank-lines
3701 article-strip-leading-blank-lines
3702 article-strip-multiple-blank-lines
3703 article-strip-leading-space
3704 article-strip-trailing-space
3705 article-strip-blank-lines
3706 article-strip-all-blank-lines
3708 article-date-english
3709 article-date-iso8601
3710 article-date-original
3712 article-decode-mime-words
3713 article-decode-charset
3714 article-decode-encoded-words
3718 article-treat-dumbquotes
3719 article-normalize-headers
3720 (article-show-all-headers . gnus-article-show-all-headers)
3721 ;; (article-show-all . gnus-article-show-all)
3725 ;;; Gnus article mode
3728 (put 'gnus-article-mode 'mode-class 'special)
3730 (gnus-define-keys gnus-article-mode-map
3731 " " gnus-article-goto-next-page
3732 "\177" gnus-article-goto-prev-page
3733 [delete] gnus-article-goto-prev-page
3734 [backspace] gnus-article-goto-prev-page
3735 "\C-c^" gnus-article-refer-article
3736 "h" gnus-article-show-summary
3737 "s" gnus-article-show-summary
3738 "\C-c\C-m" gnus-article-mail
3739 "?" gnus-article-describe-briefly
3740 "e" gnus-summary-edit-article
3741 "<" beginning-of-buffer
3743 "\C-c\C-i" gnus-info-find-node
3745 "R" gnus-article-reply-with-original
3746 "F" gnus-article-followup-with-original
3747 "\C-hk" gnus-article-describe-key
3748 "\C-hc" gnus-article-describe-key-briefly
3750 "\C-d" gnus-article-read-summary-keys
3751 "\M-*" gnus-article-read-summary-keys
3752 "\M-#" gnus-article-read-summary-keys
3753 "\M-^" gnus-article-read-summary-keys
3754 "\M-g" gnus-article-read-summary-keys)
3756 ;; Define almost undefined keys to `gnus-article-read-summary-keys'.
3760 (push (char-to-string key) keys)
3762 (dolist (elem (accessible-keymaps gnus-summary-mode-map))
3763 (setq key (car elem))
3764 (when (and (> (length key) 0)
3765 (not (eq 'menu-bar (aref key 0)))
3766 (symbolp (lookup-key gnus-summary-mode-map key)))
3769 (unless (lookup-key gnus-article-mode-map key)
3770 (define-key gnus-article-mode-map key 'gnus-article-read-summary-keys))))
3772 (defun gnus-article-make-menu-bar ()
3773 (unless (boundp 'gnus-article-commands-menu)
3774 (gnus-summary-make-menu-bar))
3775 (gnus-turn-off-edit-menu 'article)
3776 (unless (boundp 'gnus-article-article-menu)
3778 gnus-article-article-menu gnus-article-mode-map ""
3780 ["Scroll forwards" gnus-article-goto-next-page t]
3781 ["Scroll backwards" gnus-article-goto-prev-page t]
3782 ["Show summary" gnus-article-show-summary t]
3783 ["Fetch Message-ID at point" gnus-article-refer-article t]
3784 ["Mail to address at point" gnus-article-mail t]
3785 ["Send a bug report" gnus-bug t]))
3788 gnus-article-treatment-menu gnus-article-mode-map ""
3789 ;; Fixme: this should use :active (and maybe :visible).
3791 ["Hide headers" gnus-article-hide-headers t]
3792 ["Hide signature" gnus-article-hide-signature t]
3793 ["Hide citation" gnus-article-hide-citation t]
3794 ["Treat overstrike" gnus-article-treat-overstrike t]
3795 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3796 ["Remove carriage return" gnus-article-remove-cr t]
3797 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3798 ["Treat html" gnus-article-wash-html t]
3799 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3800 ["Decode HZ" gnus-article-decode-HZ t]))
3802 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3804 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3806 (gnus-run-hooks 'gnus-article-menu-hook)))
3808 (defun gnus-article-mode ()
3809 "Major mode for displaying an article.
3811 All normal editing commands are switched off.
3813 The following commands are available in addition to all summary mode
3815 \\<gnus-article-mode-map>
3816 \\[gnus-article-next-page]\t Scroll the article one page forwards
3817 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3818 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3819 \\[gnus-article-show-summary]\t Display the summary buffer
3820 \\[gnus-article-mail]\t Send a reply to the address near point
3821 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3822 \\[gnus-info-find-node]\t Go to the Gnus info node"
3824 (gnus-simplify-mode-line)
3825 (setq mode-name "Article")
3826 (setq major-mode 'gnus-article-mode)
3827 (make-local-variable 'minor-mode-alist)
3828 (unless (assq 'gnus-show-mime minor-mode-alist)
3829 (push (list 'gnus-show-mime " MIME") minor-mode-alist))
3830 (use-local-map gnus-article-mode-map)
3831 (when (gnus-visual-p 'article-menu 'menu)
3832 (gnus-article-make-menu-bar)
3833 (when gnus-summary-tool-bar-map
3834 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3835 (gnus-update-format-specifications nil 'article-mode)
3836 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3837 (set (make-local-variable 'gnus-page-broken) nil)
3838 (make-local-variable 'gnus-button-marker-list)
3839 (make-local-variable 'gnus-article-current-summary)
3840 (make-local-variable 'gnus-article-mime-handles)
3841 (make-local-variable 'gnus-article-decoded-p)
3842 (make-local-variable 'gnus-article-mime-handle-alist)
3843 (make-local-variable 'gnus-article-wash-types)
3844 (make-local-variable 'gnus-article-image-alist)
3845 (make-local-variable 'gnus-article-charset)
3846 (make-local-variable 'gnus-article-ignored-charsets)
3847 (gnus-set-default-directory)
3848 (buffer-disable-undo)
3849 (setq buffer-read-only t)
3850 (set-syntax-table gnus-article-mode-syntax-table)
3851 (gnus-run-hooks 'gnus-article-mode-hook))
3853 (defun gnus-article-setup-buffer ()
3854 "Initialize the article buffer."
3855 (let* ((name (if gnus-single-article-buffer "*Article*"
3856 (concat "*Article " gnus-newsgroup-name "*")))
3858 (progn (string-match "\\*Article" name)
3859 (concat " *Original Article"
3860 (substring name (match-end 0))))))
3861 (setq gnus-article-buffer name)
3862 (setq gnus-original-article-buffer original)
3863 (setq gnus-article-mime-handle-alist nil)
3864 ;; This might be a variable local to the summary buffer.
3865 (unless gnus-single-article-buffer
3867 (set-buffer gnus-summary-buffer)
3868 (setq gnus-article-buffer name)
3869 (setq gnus-original-article-buffer original)
3870 (gnus-set-global-variables)))
3871 (gnus-article-setup-highlight-words)
3872 ;; Init original article buffer.
3874 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3875 (set-buffer-multibyte t)
3876 (setq major-mode 'gnus-original-article-mode)
3877 (make-local-variable 'gnus-original-article))
3878 (if (get-buffer name)
3881 (when (and gnus-article-edit-mode
3884 (y-or-n-p "Article mode edit in progress; discard? ")))
3885 (error "Action aborted"))
3886 (set (make-local-variable 'gnus-article-edit-mode) nil)
3887 (buffer-disable-undo)
3888 (setq buffer-read-only t)
3889 ;; This list just keeps growing if we don't reset it.
3890 (setq gnus-button-marker-list nil)
3891 (unless (eq major-mode 'gnus-article-mode)
3892 (gnus-article-mode))
3895 (set-buffer (gnus-get-buffer-create name))
3897 (make-local-variable 'gnus-summary-buffer)
3898 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3899 (current-buffer)))))
3901 ;; Set article window start at LINE, where LINE is the number of lines
3902 ;; from the head of the article.
3903 (defun gnus-article-set-window-start (&optional line)
3905 (gnus-get-buffer-window gnus-article-buffer t)
3907 (set-buffer gnus-article-buffer)
3908 (goto-char (point-min))
3911 (gnus-message 6 "Moved to bookmark")
3912 (search-forward "\n\n" nil t)
3916 ;;; @@ article filters
3919 (defun gnus-article-display-mime-message ()
3920 "Article display method for MIME message."
3921 ;; called from `gnus-original-article-buffer'.
3922 (let (charset all-headers)
3923 (with-current-buffer gnus-summary-buffer
3924 (setq charset default-mime-charset
3925 all-headers gnus-have-all-headers))
3926 (make-local-variable 'default-mime-charset)
3927 (setq default-mime-charset charset)
3928 (with-current-buffer (get-buffer-create gnus-article-buffer)
3929 (make-local-variable 'default-mime-charset)
3930 (setq default-mime-charset charset))
3931 (mime-display-message mime-message-structure
3932 gnus-article-buffer nil gnus-article-mode-map)
3934 (gnus-article-hide-headers nil -1)))
3935 (run-hooks 'gnus-mime-article-prepare-hook))
3937 (defun gnus-article-display-traditional-message ()
3938 "Article display method for traditional message."
3939 (set-buffer gnus-article-buffer)
3940 (let (buffer-read-only)
3942 (insert-buffer-substring gnus-original-article-buffer)))
3944 (defun gnus-article-make-full-mail-header (&optional number charset)
3945 "Create a new mail header structure in a raw article buffer."
3946 (unless (and number charset)
3947 (save-current-buffer
3948 (set-buffer gnus-summary-buffer)
3950 (setq number (or (cdr gnus-article-current) 0)))
3952 (setq charset (or default-mime-charset 'x-ctext)))))
3953 (goto-char (point-min))
3954 (let ((header-end (if (search-forward "\n\n" nil t)
3956 (goto-char (point-max))))
3957 (chars (- (point-max) (point)))
3958 (lines (count-lines (point) (point-max)))
3959 (default-mime-charset charset)
3961 (narrow-to-region (point-min) header-end)
3962 (setq xref (std11-fetch-field "xref"))
3964 (make-full-mail-header
3966 (std11-fetch-field "subject")
3967 (std11-fetch-field "from")
3968 (std11-fetch-field "date")
3969 (std11-fetch-field "message-id")
3970 (std11-fetch-field "references")
3973 (when xref (concat "Xref: " xref)))
3976 (defun gnus-article-prepare (article &optional all-headers header)
3977 "Prepare ARTICLE in article mode buffer.
3978 ARTICLE should either be an article number or a Message-ID.
3979 If ARTICLE is an id, HEADER should be the article headers.
3980 If ALL-HEADERS is non-nil, no headers are hidden."
3982 ;; Make sure we start in a summary buffer.
3983 (unless (eq major-mode 'gnus-summary-mode)
3984 (set-buffer gnus-summary-buffer))
3985 (setq gnus-summary-buffer (current-buffer))
3986 (let* ((gnus-article (if header (mail-header-number header) article))
3987 (summary-buffer (current-buffer))
3988 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3989 (group gnus-newsgroup-name)
3992 (gnus-article-setup-buffer)
3993 (set-buffer gnus-article-buffer)
3994 ;; Deactivate active regions.
3995 (when (and (boundp 'transient-mark-mode)
3996 transient-mark-mode)
3997 (setq mark-active nil))
3998 (if (not (setq result (let ((buffer-read-only nil))
3999 (gnus-request-article-this-buffer
4001 ;; There is no such article.
4003 (when (and (numberp article)
4004 (not (memq article gnus-newsgroup-sparse)))
4005 (setq gnus-article-current
4006 (cons gnus-newsgroup-name article))
4007 (set-buffer gnus-summary-buffer)
4008 (setq gnus-current-article article)
4009 (if (and (memq article gnus-newsgroup-undownloaded)
4010 (not (gnus-online (gnus-find-method-for-group
4011 gnus-newsgroup-name))))
4013 (gnus-summary-set-agent-mark article)
4014 (message "Message marked for downloading"))
4015 (gnus-summary-mark-article article gnus-canceled-mark)
4016 (unless (memq article gnus-newsgroup-sparse)
4017 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4018 (if (or (eq result 'pseudo)
4019 (eq result 'nneething))
4022 (set-buffer summary-buffer)
4023 (push article gnus-newsgroup-history)
4024 (setq gnus-last-article gnus-current-article
4025 gnus-current-article 0
4026 gnus-current-headers nil
4027 gnus-article-current nil)
4028 (if (eq result 'nneething)
4029 (gnus-configure-windows 'summary)
4030 (gnus-configure-windows 'article))
4031 (gnus-set-global-variables))
4032 (let ((gnus-article-mime-handle-alist-1
4033 gnus-article-mime-handle-alist))
4034 (gnus-set-mode-line 'article)))
4035 ;; The result from the `request' was an actual article -
4036 ;; or at least some text that is now displayed in the
4038 (when (and (numberp article)
4039 (not (eq article gnus-current-article)))
4040 ;; Seems like a new article has been selected.
4041 ;; `gnus-current-article' must be an article number.
4043 (set-buffer summary-buffer)
4044 (push article gnus-newsgroup-history)
4045 (setq gnus-last-article gnus-current-article
4046 gnus-current-article article
4047 gnus-current-headers
4048 (gnus-summary-article-header gnus-current-article)
4049 gnus-article-current
4050 (cons gnus-newsgroup-name gnus-current-article))
4051 (unless (vectorp gnus-current-headers)
4052 (setq gnus-current-headers nil))
4053 (gnus-summary-goto-subject gnus-current-article)
4054 (when (gnus-summary-show-thread)
4055 ;; If the summary buffer really was folded, the
4056 ;; previous goto may not actually have gone to
4057 ;; the right article, but the thread root instead.
4059 (gnus-summary-goto-subject gnus-current-article))
4060 (gnus-run-hooks 'gnus-mark-article-hook)
4061 (gnus-set-mode-line 'summary)
4062 (when (gnus-visual-p 'article-highlight 'highlight)
4063 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4064 ;; Set the global newsgroup variables here.
4065 (gnus-set-global-variables)
4066 (setq gnus-have-all-headers
4067 (or all-headers gnus-show-all-headers))))
4069 (gnus-configure-windows 'article))
4070 (when (or (numberp article)
4072 (gnus-article-prepare-display)
4074 (goto-char (point-min))
4075 (when gnus-break-pages
4076 (gnus-narrow-to-page)))
4077 (let ((gnus-article-mime-handle-alist-1
4078 gnus-article-mime-handle-alist))
4079 (gnus-set-mode-line 'article))
4083 (set-window-point (get-buffer-window (current-buffer)) (point))
4084 (gnus-configure-windows 'article)
4087 (defun gnus-article-prepare-mime-display (&optional number)
4088 (goto-char (point-min))
4089 (when (re-search-forward "^[^\t ]+:" nil t)
4090 (goto-char (match-beginning 0)))
4091 (let ((entity (if (eq 1 (point-min))
4092 (get-text-property 1 'mime-view-entity)
4093 (get-text-property (point) 'mime-view-entity)))
4094 last-entity child-entity next type)
4095 (setq child-entity (mime-entity-children entity))
4097 (setq last-entity (nth (1- (length child-entity))
4099 (setq last-entity entity))
4101 (narrow-to-region (point)
4102 (if (search-forward "\n\n" nil t)
4105 (gnus-treat-article 'head)
4106 (put-text-property (point-min) (point-max) 'article-treated-header t)
4107 (goto-char (point-max)))
4108 (while (and (not (eobp)) entity)
4109 (setq next (set-marker
4111 (next-single-property-change (point) 'mime-view-entity
4113 (let ((types (mime-entity-content-type entity)))
4114 (while (eq 'multipart (mime-content-type-primary-type types))
4115 (setq entity (car (mime-entity-children entity))
4116 types (mime-entity-content-type entity)))
4118 (setq type (format "%s/%s"
4119 (mime-content-type-primary-type types)
4120 (mime-content-type-subtype types)))))
4121 (if (string-equal type "message/rfc822")
4124 (let ((children (mime-entity-children entity))
4127 (setq last-children (nth (1- (length children)) children))
4130 (not (eq last-children
4131 (get-text-property next 'mime-view-entity)))
4133 (next-single-property-change next
4135 nil (point-max)))))))
4136 (setq next (next-single-property-change next 'mime-view-entity
4139 (narrow-to-region (point) next)
4140 (gnus-article-prepare-mime-display)
4141 (goto-char (point-max)))
4142 (setq entity (get-text-property (point) 'mime-view-entity)))
4144 (narrow-to-region (point) next)
4145 ;; Kludge. We have to count true number, but for now,
4146 ;; part number is here only to achieve `last'.
4147 (gnus-treat-article nil 1
4148 (if (eq entity last-entity)
4151 (goto-char (point-max)))
4152 (setq entity (get-text-property next 'mime-view-entity))))))
4155 (defun gnus-article-prepare-display ()
4156 "Make the current buffer look like a nice article."
4157 (let ((gnus-article-buffer (current-buffer))
4159 (unless (eq major-mode 'gnus-article-mode)
4160 (gnus-article-mode))
4161 (setq buffer-read-only nil
4162 gnus-button-marker-list nil
4163 gnus-article-wash-types nil
4164 gnus-article-image-alist nil)
4167 (static-if (featurep 'xemacs)
4168 (map-extents (lambda (extent maparg) (delete-extent extent)))
4169 (let ((lists (overlay-lists)))
4170 (dolist (overlay (nconc (car lists) (cdr lists)))
4171 (delete-overlay overlay)))))
4172 (gnus-run-hooks 'gnus-tmp-internal-hook))
4173 (let ((show-mime (unless (member gnus-newsgroup-name '("nndraft:delayed"
4176 (inhibit-read-only t))
4177 (set-buffer gnus-original-article-buffer)
4179 (setq mime-message-structure gnus-current-headers)
4180 (mime-buffer-entity-set-buffer-internal mime-message-structure
4181 gnus-original-article-buffer)
4182 (mime-entity-set-representation-type-internal mime-message-structure
4183 'mime-buffer-entity)
4184 (luna-send mime-message-structure 'initialize-instance
4185 mime-message-structure)
4187 (let (mime-display-header-hook mime-display-text/plain-hook)
4188 (funcall gnus-article-display-method-for-mime))
4189 (funcall gnus-article-display-method-for-traditional))
4190 ;; Call the treatment functions.
4194 (gnus-article-prepare-mime-display)
4195 (narrow-to-region (goto-char (point-min))
4196 (if (search-forward "\n\n" nil t)
4199 (gnus-treat-article 'head)
4200 (put-text-property (point-min) (point-max) 'article-treated-header t)
4201 (goto-char (point-max))
4203 (narrow-to-region (point) (point-max))
4204 (gnus-treat-article nil))
4205 (put-text-property (point-min) (point-max) 'read-only nil)))
4206 (gnus-run-hooks 'gnus-article-prepare-hook))
4208 (defun gnus-article-decode-article-as-default-mime-charset ()
4209 "Decode an article as `default-mime-charset'. It won't work if the
4210 value of the variable `gnus-show-mime' is non-nil."
4211 (unless (or gnus-show-mime
4212 (member gnus-newsgroup-name '("nndraft:delayed"
4214 (set (make-local-variable 'default-mime-charset)
4215 (with-current-buffer gnus-summary-buffer
4216 default-mime-charset))
4217 (decode-mime-charset-region (point-min) (point-max)
4218 default-mime-charset)))
4221 ;;; Gnus MIME viewing functions
4224 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4225 "Format of the MIME buttons.
4227 Valid specifiers include:
4229 %T MIME type, along with additional info
4230 %n The `name' parameter
4231 %d The description, if any
4232 %l The length of the encoded part
4233 %p The part identifier number
4234 %e Dots if the part isn't displayed
4236 General format specifiers can also be used. See Info node
4237 `(gnus)Formatting Variables'.")
4239 (defvar gnus-mime-button-line-format-alist
4240 '((?t gnus-tmp-type ?s)
4241 (?T gnus-tmp-type-long ?s)
4242 (?n gnus-tmp-name ?s)
4243 (?d gnus-tmp-description ?s)
4245 (?l gnus-tmp-length ?d)
4246 (?e gnus-tmp-dots ?s)))
4248 (defvar gnus-mime-button-commands
4249 '((gnus-article-press-button "\r" "Toggle Display")
4250 (gnus-mime-view-part "v" "View Interactively...")
4251 (gnus-mime-view-part-as-type "t" "View As Type...")
4252 (gnus-mime-view-part-as-charset "C" "View As charset...")
4253 (gnus-mime-save-part "o" "Save...")
4254 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4255 (gnus-mime-delete-part "d" "Delete part")
4256 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4257 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4258 (gnus-mime-view-part-internally "E" "View Internally")
4259 (gnus-mime-view-part-externally "e" "View Externally")
4260 (gnus-mime-print-part "p" "Print")
4261 (gnus-mime-pipe-part "|" "Pipe To Command...")
4262 (gnus-mime-action-on-part "." "Take action on the part...")))
4264 (defun gnus-article-mime-part-status ()
4265 (with-current-buffer gnus-article-buffer
4266 (let ((entity (get-text-property (point-min) 'mime-view-entity))
4269 (setq children (mime-entity-children entity))
4270 (setq children (length children)))
4273 (format " (%d parts)" children))
4276 (defvar gnus-mime-button-map
4277 (let ((map (make-sparse-keymap)))
4278 (unless (>= (string-to-number emacs-version) 21)
4279 ;; XEmacs doesn't care.
4280 (set-keymap-parent map gnus-article-mode-map))
4281 (define-key map gnus-mouse-2 'gnus-article-push-button)
4282 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4283 (dolist (c gnus-mime-button-commands)
4284 (define-key map (cadr c) (car c)))
4288 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4290 ,@(mapcar (lambda (c)
4291 (vector (caddr c) (car c) :enable t))
4292 gnus-mime-button-commands)))
4294 (defun gnus-mime-button-menu (event prefix)
4295 "Construct a context-sensitive menu of MIME commands."
4296 (interactive "e\nP")
4297 (save-window-excursion
4298 (let ((pos (event-start event)))
4299 (select-window (posn-window pos))
4300 (goto-char (posn-point pos))
4301 (gnus-article-check-buffer)
4302 (popup-menu gnus-mime-button-menu nil prefix))))
4304 (defun gnus-mime-view-all-parts (&optional handles)
4305 "View all the MIME parts."
4307 (save-current-buffer
4308 (set-buffer gnus-article-buffer)
4309 (let ((handles (or handles gnus-article-mime-handles))
4310 (mail-parse-charset gnus-newsgroup-charset)
4311 (mail-parse-ignored-charsets
4312 (with-current-buffer gnus-summary-buffer
4313 gnus-newsgroup-ignored-charsets)))
4315 (mm-remove-parts handles)
4316 (goto-char (point-min))
4317 (or (search-forward "\n\n") (goto-char (point-max)))
4318 (let (buffer-read-only)
4319 (delete-region (point) (point-max))
4320 (mm-display-parts handles))))))
4322 (defun gnus-mime-save-part-and-strip ()
4323 "Save the MIME part under point then replace it with an external body."
4325 (gnus-article-check-buffer)
4326 (let* ((data (get-text-property (point) 'gnus-data))
4328 (handles gnus-article-mime-handles))
4329 (if (mm-multiple-handles gnus-article-mime-handles)
4330 (error "This function is not implemented"))
4331 (setq file (and data (mm-save-part data)))
4333 (with-current-buffer (mm-handle-buffer data)
4335 (insert "Content-Type: " (mm-handle-media-type data))
4336 (mml-insert-parameter-string (cdr (mm-handle-type data))
4339 (insert "Content-ID: " (message-make-message-id) "\n")
4340 (insert "Content-Transfer-Encoding: binary\n")
4343 (cdr (mm-make-handle nil
4344 `("message/external-body"
4345 (access-type . "LOCAL-FILE")
4347 (set-buffer gnus-summary-buffer)
4348 (gnus-article-edit-article
4351 (let ((mail-parse-charset (or gnus-article-charset
4352 ',gnus-newsgroup-charset))
4353 (mail-parse-ignored-charsets
4354 (or gnus-article-ignored-charsets
4355 ',gnus-newsgroup-ignored-charsets))
4356 (mbl mml-buffer-list))
4357 (setq mml-buffer-list nil)
4358 (insert-buffer gnus-original-article-buffer)
4359 (mime-to-mml ',handles)
4360 (setq gnus-article-mime-handles nil)
4361 (let ((mbl1 mml-buffer-list))
4362 (setq mml-buffer-list mbl)
4363 (set (make-local-variable 'mml-buffer-list) mbl1))
4364 (gnus-make-local-hook 'kill-buffer-hook)
4365 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4366 `(lambda (no-highlight)
4367 (let ((mail-parse-charset (or gnus-article-charset
4368 ',gnus-newsgroup-charset))
4369 (message-options message-options)
4370 (message-options-set-recipient)
4371 (mail-parse-ignored-charsets
4372 (or gnus-article-ignored-charsets
4373 ',gnus-newsgroup-ignored-charsets)))
4375 (mml-destroy-buffers)
4376 (remove-hook 'kill-buffer-hook
4377 'mml-destroy-buffers t)
4378 (kill-local-variable 'mml-buffer-list))
4379 (gnus-summary-edit-article-done
4380 ,(or (mail-header-references gnus-current-headers) "")
4381 ,(gnus-group-read-only-p)
4382 ,gnus-summary-buffer no-highlight))))))
4384 (defun gnus-mime-delete-part ()
4385 "Delete the MIME part under point.
4386 Replace it with some information about the removed part."
4388 (gnus-article-check-buffer)
4389 (unless (and gnus-novice-user
4390 (not (gnus-yes-or-no-p
4391 "Really delete attachment forever? ")))
4392 (let* ((data (get-text-property (point) 'gnus-data))
4393 (handles gnus-article-mime-handles)
4397 (mail-decode-encoded-word-string (or (mm-handle-description data)
4400 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4402 (type (mm-handle-media-type data)))
4403 (if (mm-multiple-handles gnus-article-mime-handles)
4404 (error "This function is not implemented"))
4405 (with-current-buffer (mm-handle-buffer data)
4406 (let ((bsize (format "%s" (buffer-size))))
4411 "| The following attachment has been deleted:\n"
4413 "| Type: " type "\n"
4414 "| Filename: " filename "\n"
4415 "| Size (encoded): " bsize " Byte\n"
4416 "| Description: " description "\n"
4419 (cdr (mm-make-handle
4420 nil `("text/plain") nil nil
4422 (format "Deleted attachment (%s bytes)" bsize))))))
4423 (set-buffer gnus-summary-buffer)
4424 ;; FIXME: maybe some of the following code (borrowed from
4425 ;; `gnus-mime-save-part-and-strip') isn't necessary?
4426 (gnus-article-edit-article
4429 (let ((mail-parse-charset (or gnus-article-charset
4430 ',gnus-newsgroup-charset))
4431 (mail-parse-ignored-charsets
4432 (or gnus-article-ignored-charsets
4433 ',gnus-newsgroup-ignored-charsets))
4434 (mbl mml-buffer-list))
4435 (setq mml-buffer-list nil)
4436 (insert-buffer gnus-original-article-buffer)
4437 (mime-to-mml ',handles)
4438 (setq gnus-article-mime-handles nil)
4439 (let ((mbl1 mml-buffer-list))
4440 (setq mml-buffer-list mbl)
4441 (set (make-local-variable 'mml-buffer-list) mbl1))
4442 (gnus-make-local-hook 'kill-buffer-hook)
4443 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4444 `(lambda (no-highlight)
4445 (let ((mail-parse-charset (or gnus-article-charset
4446 ',gnus-newsgroup-charset))
4447 (message-options message-options)
4448 (message-options-set-recipient)
4449 (mail-parse-ignored-charsets
4450 (or gnus-article-ignored-charsets
4451 ',gnus-newsgroup-ignored-charsets)))
4453 (mml-destroy-buffers)
4454 (remove-hook 'kill-buffer-hook
4455 'mml-destroy-buffers t)
4456 (kill-local-variable 'mml-buffer-list))
4457 (gnus-summary-edit-article-done
4458 ,(or (mail-header-references gnus-current-headers) "")
4459 ,(gnus-group-read-only-p)
4460 ,gnus-summary-buffer no-highlight)))))
4461 ;; Not in `gnus-mime-save-part-and-strip':
4462 (gnus-article-edit-done)
4463 (gnus-summary-expand-window)
4464 (gnus-summary-show-article))
4466 (defun gnus-mime-save-part ()
4467 "Save the MIME part under point."
4469 (gnus-article-check-buffer)
4470 (let ((data (get-text-property (point) 'gnus-data)))
4472 (mm-save-part data))))
4474 (defun gnus-mime-pipe-part ()
4475 "Pipe the MIME part under point to a process."
4477 (gnus-article-check-buffer)
4478 (let ((data (get-text-property (point) 'gnus-data)))
4480 (mm-pipe-part data))))
4482 (defun gnus-mime-view-part ()
4483 "Interactively choose a viewing method for the MIME part under point."
4485 (gnus-article-check-buffer)
4486 (let ((data (get-text-property (point) 'gnus-data)))
4488 (setq gnus-article-mime-handles
4490 gnus-article-mime-handles (setq data (copy-sequence data))))
4491 (mm-interactively-view-part data))))
4493 (defun gnus-mime-view-part-as-type-internal ()
4494 (gnus-article-check-buffer)
4495 (let* ((name (mail-content-type-get
4496 (mm-handle-type (get-text-property (point) 'gnus-data))
4498 (def-type (and name (mm-default-file-encoding name))))
4499 (and def-type (cons def-type 0))))
4501 (defun gnus-mime-view-part-as-type (&optional mime-type)
4502 "Choose a MIME media type, and view the part as such."
4505 (setq mime-type (completing-read
4506 "View as MIME type: "
4507 (mapcar #'list (mailcap-mime-types))
4509 (gnus-mime-view-part-as-type-internal))))
4510 (gnus-article-check-buffer)
4511 (let ((handle (get-text-property (point) 'gnus-data)))
4514 (mm-make-handle (mm-handle-buffer handle)
4515 (cons mime-type (cdr (mm-handle-type handle)))
4516 (mm-handle-encoding handle)
4517 (mm-handle-undisplayer handle)
4518 (mm-handle-disposition handle)
4519 (mm-handle-description handle)
4521 (mm-handle-id handle)))
4522 (setq gnus-article-mime-handles
4523 (mm-merge-handles gnus-article-mime-handles handle))
4524 (gnus-mm-display-part handle))))
4527 (require 'jka-compr))
4529 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4530 ;; emacs can do that itself.
4532 (defun gnus-mime-jka-compr-maybe-uncompress ()
4533 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4534 The uncompress method used is derived from `buffer-file-name'."
4535 (when (and (fboundp 'jka-compr-installed-p)
4536 (jka-compr-installed-p))
4537 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4539 (let ((basename (file-name-nondirectory buffer-file-name))
4540 (args (jka-compr-info-uncompress-args info))
4541 (prog (jka-compr-info-uncompress-program info))
4542 (message (jka-compr-info-uncompress-message info))
4543 (err-file (jka-compr-make-temp-name)))
4545 (message "%s %s..." message basename))
4547 (unless (memq (apply 'call-process-region
4548 (point-min) (point-max)
4550 t (list t err-file) nil
4552 jka-compr-acceptable-retval-list)
4553 (jka-compr-error prog args basename message err-file))
4554 (jka-compr-delete-temp-file err-file)))))))
4556 (defun gnus-mime-copy-part (&optional handle)
4557 "Put the MIME part under point into a new buffer.
4558 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4561 (gnus-article-check-buffer)
4562 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4563 (contents (and handle (mm-get-part handle)))
4565 (file-name-nondirectory
4567 (mail-content-type-get (mm-handle-type handle) 'name)
4568 (mail-content-type-get (mm-handle-disposition handle)
4571 (buffer (and base (generate-new-buffer base))))
4573 (switch-to-buffer buffer)
4575 ;; We do it this way to make `normal-mode' set the appropriate mode.
4578 (setq buffer-file-name (expand-file-name base))
4579 (gnus-mime-jka-compr-maybe-uncompress)
4581 (setq buffer-file-name nil))
4582 (goto-char (point-min)))))
4584 (defun gnus-mime-print-part (&optional handle filename)
4585 "Print the MIME part under point."
4586 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4587 (gnus-article-check-buffer)
4588 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4589 (contents (and handle (mm-get-part handle)))
4590 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4591 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4596 (mm-save-part-to-file handle file)
4597 (call-process shell-file-name nil
4598 (generate-new-buffer " *mm*")
4600 shell-command-switch
4602 printer file (mm-handle-type handle))))
4606 (gnus-print-buffer))
4607 (ps-despool filename)))))
4609 (defun gnus-mime-inline-part (&optional handle arg)
4610 "Insert the MIME part under point into the current buffer."
4611 (interactive (list nil current-prefix-arg))
4612 (gnus-article-check-buffer)
4613 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4618 (if (and (not arg) (mm-handle-undisplayer handle))
4619 (mm-remove-part handle)
4620 (setq contents (mm-get-part handle))
4623 (setq charset (or (mail-content-type-get
4624 (mm-handle-type handle) 'charset)
4625 gnus-newsgroup-charset)))
4627 (if (mm-handle-undisplayer handle)
4628 (mm-remove-part handle))
4631 gnus-summary-show-article-charset-alist))
4632 (mm-read-coding-system "Charset: ")))))
4634 (mm-insert-inline handle
4636 (setq charset (mm-charset-to-coding-system
4638 (not (eq charset 'ascii)))
4639 (mm-decode-coding-string contents charset)
4643 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4644 "Insert the MIME part under point into the current buffer using the
4646 (interactive (list nil current-prefix-arg))
4647 (gnus-article-check-buffer)
4648 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4653 (if (mm-handle-undisplayer handle)
4654 (mm-remove-part handle))
4655 (let ((gnus-newsgroup-charset
4657 gnus-summary-show-article-charset-alist))
4658 (mm-read-coding-system "Charset: ")))
4659 (gnus-newsgroup-ignored-charsets 'gnus-all))
4660 (gnus-article-press-button)))))
4662 (defun gnus-mime-view-part-externally (&optional handle)
4663 "View the MIME part under point with an external viewer."
4665 (gnus-article-check-buffer)
4666 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4667 (mm-user-display-methods nil)
4668 (mm-inlined-types nil)
4669 (mail-parse-charset gnus-newsgroup-charset)
4670 (mail-parse-ignored-charsets
4671 (save-excursion (set-buffer gnus-summary-buffer)
4672 gnus-newsgroup-ignored-charsets)))
4674 (if (mm-handle-undisplayer handle)
4675 (mm-remove-part handle)
4676 (mm-display-part handle)))))
4678 (defun gnus-mime-view-part-internally (&optional handle)
4679 "View the MIME part under point with an internal viewer.
4680 If no internal viewer is available, use an external viewer."
4682 (gnus-article-check-buffer)
4683 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4684 (mm-inlined-types '(".*"))
4685 (mm-inline-large-images t)
4686 (mail-parse-charset gnus-newsgroup-charset)
4687 (mail-parse-ignored-charsets
4688 (save-excursion (set-buffer gnus-summary-buffer)
4689 gnus-newsgroup-ignored-charsets))
4692 (if (mm-handle-undisplayer handle)
4693 (mm-remove-part handle)
4694 (mm-display-part handle)))))
4696 (defun gnus-mime-action-on-part (&optional action)
4697 "Do something with the MIME attachment at \(point\)."
4699 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4700 (gnus-article-check-buffer)
4701 (let ((action-pair (assoc action gnus-mime-action-alist)))
4703 (funcall (cdr action-pair)))))
4705 (defun gnus-article-part-wrapper (n function)
4706 (save-current-buffer
4707 (set-buffer gnus-article-buffer)
4708 (when (> n (length gnus-article-mime-handle-alist))
4709 (error "No such part"))
4710 (gnus-article-goto-part n)
4711 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4712 (funcall function handle))))
4714 (defun gnus-article-pipe-part (n)
4715 "Pipe MIME part N, which is the numerical prefix."
4717 (gnus-article-part-wrapper n 'mm-pipe-part))
4719 (defun gnus-article-save-part (n)
4720 "Save MIME part N, which is the numerical prefix."
4722 (gnus-article-part-wrapper n 'mm-save-part))
4724 (defun gnus-article-interactively-view-part (n)
4725 "View MIME part N interactively, which is the numerical prefix."
4727 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4729 (defun gnus-article-copy-part (n)
4730 "Copy MIME part N, which is the numerical prefix."
4732 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4734 (defun gnus-article-view-part-as-charset (n)
4735 "View MIME part N using a specified charset.
4736 N is the numerical prefix."
4738 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4740 (defun gnus-article-view-part-externally (n)
4741 "View MIME part N externally, which is the numerical prefix."
4743 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4745 (defun gnus-article-inline-part (n)
4746 "Inline MIME part N, which is the numerical prefix."
4748 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4750 (defun gnus-article-mime-match-handle-first (condition)
4752 (let ((alist gnus-article-mime-handle-alist) ihandle n)
4753 (while (setq ihandle (pop alist))
4755 ((functionp condition)
4756 (funcall condition (cdr ihandle)))
4757 ((eq condition 'undisplayed)
4758 (not (or (mm-handle-undisplayer (cdr ihandle))
4759 (equal (mm-handle-media-type (cdr ihandle))
4760 "multipart/alternative"))))
4761 ((eq condition 'undisplayed-alternative)
4762 (not (mm-handle-undisplayer (cdr ihandle))))
4764 (gnus-article-goto-part (car ihandle))
4765 (or (not n) (< (car ihandle) n)))
4766 (setq n (car ihandle))))
4770 (defun gnus-article-view-part (&optional n)
4771 "View MIME part N, which is the numerical prefix."
4773 (save-current-buffer
4774 (set-buffer gnus-article-buffer)
4775 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4776 gnus-article-mime-match-handle-function)))
4777 (when (> n (length gnus-article-mime-handle-alist))
4778 (error "No such part"))
4779 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4780 (when (gnus-article-goto-part n)
4781 (if (equal (car handle) "multipart/alternative")
4782 (gnus-article-press-button)
4783 (when (eq (gnus-mm-display-part handle) 'internal)
4784 (gnus-set-window-start)))))))
4786 (defsubst gnus-article-mime-total-parts ()
4787 (if (bufferp (car gnus-article-mime-handles))
4789 (1- (length gnus-article-mime-handles))))
4791 (defun gnus-mm-display-part (handle)
4792 "Display HANDLE and fix MIME button."
4793 (let ((id (get-text-property (point) 'gnus-part))
4798 (let ((window (selected-window))
4799 (mail-parse-charset gnus-newsgroup-charset)
4800 (mail-parse-ignored-charsets
4801 (if (gnus-buffer-live-p gnus-summary-buffer)
4803 (set-buffer gnus-summary-buffer)
4804 gnus-newsgroup-ignored-charsets)
4808 (let ((win (gnus-get-buffer-window (current-buffer) t))
4811 (select-window win))
4814 (if (mm-handle-displayed-p handle)
4815 ;; This will remove the part.
4816 (mm-display-part handle)
4818 (narrow-to-region (point)
4819 (if (eobp) (point) (1+ (point))))
4820 (mm-display-part handle)
4821 ;; We narrow to the part itself and
4822 ;; then call the treatment functions.
4823 (goto-char (point-min))
4825 (narrow-to-region (point) (point-max))
4828 (gnus-article-mime-total-parts)
4829 (mm-handle-media-type handle)))))
4830 (if (window-live-p window)
4831 (select-window window)))))
4834 (gnus-insert-mime-button
4835 handle id (list (mm-handle-displayed-p handle)))
4836 (goto-char point))))
4838 (defun gnus-article-goto-part (n)
4839 "Go to MIME part N."
4840 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4842 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4843 (let ((gnus-tmp-name
4844 (or (mail-content-type-get (mm-handle-type handle) 'name)
4845 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4846 (mail-content-type-get (mm-handle-type handle) 'url)
4848 (gnus-tmp-type (mm-handle-media-type handle))
4849 (gnus-tmp-description
4850 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4853 (if (if displayed (car displayed)
4854 (mm-handle-displayed-p handle))
4856 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4858 gnus-tmp-type-long b e)
4859 (when (string-match ".*/" gnus-tmp-name)
4860 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4861 (setq gnus-tmp-type-long (concat gnus-tmp-type
4862 (and (not (equal gnus-tmp-name ""))
4863 (concat "; " gnus-tmp-name))))
4864 (unless (equal gnus-tmp-description "")
4865 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4870 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4871 `(keymap ,gnus-mime-button-map
4872 gnus-callback gnus-mm-display-part
4873 gnus-part ,gnus-tmp-id
4874 article-type annotation
4877 ;; Exclude a newline.
4880 (widget-convert-button
4883 :action 'gnus-widget-press-button
4884 :button-keymap gnus-mime-button-map
4886 (lambda (widget/window &optional overlay pos)
4887 ;; Needed to properly clear the message due to a bug in
4888 ;; wid-edit (XEmacs only).
4889 (if (boundp 'help-echo-owns-message)
4890 (setq help-echo-owns-message t))
4892 "%S: %s the MIME part; %S: more options"
4893 (aref gnus-mouse-2 0)
4894 ;; XEmacs will get a single widget arg; Emacs 21 will get
4895 ;; window, overlay, position.
4896 (if (mm-handle-displayed-p
4898 (with-current-buffer (gnus-overlay-buffer overlay)
4899 (widget-get (widget-at (gnus-overlay-start overlay))
4901 (widget-get widget/window :mime-handle)))
4903 (aref gnus-down-mouse-3 0))))))
4905 (defun gnus-widget-press-button (elems el)
4906 (goto-char (widget-get elems :from))
4907 (gnus-article-press-button))
4909 (defvar gnus-displaying-mime nil)
4911 (defun gnus-display-mime (&optional ihandles)
4912 "Display the MIME parts."
4914 (save-selected-window
4915 (let ((window (get-buffer-window gnus-article-buffer))
4918 (select-window window)
4919 ;; We have to do this since selecting the window
4920 ;; may change the point. So we set the window point.
4921 (set-window-point window point)))
4922 (let* ((handles (or ihandles
4923 (mm-dissect-buffer nil gnus-article-loose-mime)
4924 (and gnus-article-emulate-mime
4926 buffer-read-only handle name type b e display)
4927 (when (and (not ihandles)
4928 (not gnus-displaying-mime))
4929 ;; Top-level call; we clean up.
4930 (when gnus-article-mime-handles
4931 (mm-destroy-parts gnus-article-mime-handles)
4932 (setq gnus-article-mime-handle-alist nil));; A trick.
4933 (setq gnus-article-mime-handles handles)
4934 ;; We allow users to glean info from the handles.
4935 (when gnus-article-mime-part-function
4936 (gnus-mime-part-function handles)))
4938 (or (not (stringp (car handles)))
4941 (when (and (not ihandles)
4942 (not gnus-displaying-mime))
4943 ;; Clean up for mime parts.
4945 (delete-region (point) (point-max)))
4946 (let ((gnus-displaying-mime t))
4947 (gnus-mime-display-part handles)))
4950 (narrow-to-region (point) (point-max))
4951 (gnus-treat-article nil 1 1)
4954 ;; Highlight the headers.
4958 (narrow-to-region (point-min) (point))
4959 (gnus-treat-article 'head))))))))
4961 (defcustom gnus-mime-display-multipart-as-mixed nil
4962 "Display \"multipart\" parts as \"multipart/mixed\".
4964 If t, it overrides nil values of
4965 `gnus-mime-display-multipart-alternative-as-mixed' and
4966 `gnus-mime-display-multipart-related-as-mixed'."
4967 :group 'gnus-article-mime
4970 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4971 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4972 :group 'gnus-article-mime
4975 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4976 "Display \"multipart/related\" parts as \"multipart/mixed\".
4978 If displaying \"text/html\" is discouraged \(see
4979 `mm-discouraged-alternatives'\) images or other material inside a
4980 \"multipart/related\" part might be overlooked when this variable is nil."
4981 :group 'gnus-article-mime
4984 (defun gnus-mime-display-part (handle)
4987 ((not (stringp (car handle)))
4988 (gnus-mime-display-single handle))
4989 ;; User-defined multipart
4990 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4991 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4993 ;; multipart/alternative
4994 ((and (equal (car handle) "multipart/alternative")
4995 (not (or gnus-mime-display-multipart-as-mixed
4996 gnus-mime-display-multipart-alternative-as-mixed)))
4997 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4998 (push (cons id handle) gnus-article-mime-handle-alist)
4999 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5000 ;; multipart/related
5001 ((and (equal (car handle) "multipart/related")
5002 (not (or gnus-mime-display-multipart-as-mixed
5003 gnus-mime-display-multipart-related-as-mixed)))
5004 ;;;!!!We should find the start part, but we just default
5005 ;;;!!!to the first part.
5006 ;;(gnus-mime-display-part (cadr handle))
5007 ;;;!!! Most multipart/related is an HTML message plus images.
5008 ;;;!!! Unfortunately we are unable to let W3 display those
5009 ;;;!!! included images, so we just display it as a mixed multipart.
5010 ;;(gnus-mime-display-mixed (cdr handle))
5011 ;;;!!! No, w3 can display everything just fine.
5012 (gnus-mime-display-part (cadr handle)))
5013 ((equal (car handle) "multipart/signed")
5014 (gnus-add-wash-type 'signed)
5015 (gnus-mime-display-security handle))
5016 ((equal (car handle) "multipart/encrypted")
5017 (gnus-add-wash-type 'encrypted)
5018 (gnus-mime-display-security handle))
5019 ;; Other multiparts are handled like multipart/mixed.
5021 (gnus-mime-display-mixed (cdr handle)))))
5023 (defun gnus-mime-part-function (handles)
5024 (if (stringp (car handles))
5025 (mapcar 'gnus-mime-part-function (cdr handles))
5026 (funcall gnus-article-mime-part-function handles)))
5028 (defun gnus-mime-display-mixed (handles)
5029 (mapcar 'gnus-mime-display-part handles))
5031 (defun gnus-mime-display-single (handle)
5032 (let ((type (mm-handle-media-type handle))
5033 (ignored gnus-ignored-mime-types)
5040 (when (string-match (pop ignored) type)
5041 (throw 'ignored nil)))
5042 (if (and (setq not-attachment
5043 (and (not (mm-inline-override-p handle))
5044 (or (not (mm-handle-disposition handle))
5045 (equal (car (mm-handle-disposition handle))
5047 (mm-attachment-override-p handle))))
5048 (mm-automatic-display-p handle)
5050 (mm-inlinable-p handle)
5051 (mm-inlined-p handle))
5052 (mm-automatic-external-display-p type)))
5054 (when (equal (mm-handle-media-supertype handle) "text")
5056 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5058 (push (cons id handle) gnus-article-mime-handle-alist)
5059 (when (or (not display)
5060 (not (gnus-unbuttonized-mime-type-p type)))
5061 ;(gnus-article-insert-newline)
5062 (gnus-insert-mime-button
5063 handle id (list (or display (and not-attachment text))))
5064 (gnus-article-insert-newline)
5065 ;(gnus-article-insert-newline)
5066 ;; Remember modify the number of forward lines.
5074 (let ((mail-parse-charset gnus-newsgroup-charset)
5075 (mail-parse-ignored-charsets
5076 (save-excursion (condition-case ()
5077 (set-buffer gnus-summary-buffer)
5079 gnus-newsgroup-ignored-charsets)))
5080 (mm-display-part handle t))
5081 (goto-char (point-max)))
5082 ((and text not-attachment)
5086 (gnus-article-insert-newline)
5087 (mm-insert-inline handle (mm-get-part handle))
5088 (goto-char (point-max))))
5092 (narrow-to-region beg (point))
5095 (gnus-article-mime-total-parts)
5096 (mm-handle-media-type handle)))))))))
5098 (defun gnus-unbuttonized-mime-type-p (type)
5099 "Say whether TYPE is to be unbuttonized."
5100 (unless gnus-inhibit-mime-unbuttonizing
5102 (let ((types gnus-unbuttonized-mime-types))
5104 (when (string-match (pop types) type)
5105 (throw 'found t)))))
5107 (let ((types gnus-buttonized-mime-types))
5109 (when (string-match (pop types) type)
5110 (throw 'found t)))))))))
5112 (defun gnus-article-insert-newline ()
5113 "Insert a newline, but mark it as undeletable."
5114 (gnus-put-text-property
5115 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5117 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5118 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5121 handle buffer-read-only from props begend not-pref)
5122 (save-window-excursion
5125 (narrow-to-region (car ibegend)
5128 (goto-char (car ibegend))
5131 (delete-region (point-min) (point-max))
5132 (mm-remove-parts handles))
5133 (setq begend (list (point-marker)))
5135 (unless (setq not-pref (cadr (member preferred ihandles)))
5136 (setq not-pref (car ihandles)))
5139 (not (gnus-unbuttonized-mime-type-p
5140 "multipart/alternative")))
5141 (gnus-add-text-properties
5144 (insert (format "%d. " id))
5148 (unless ,(not ibegend)
5149 (setq gnus-article-mime-handle-alist
5150 ',gnus-article-mime-handle-alist))
5151 (gnus-mime-display-alternative
5152 ',ihandles ',not-pref ',begend ,id))
5153 keymap ,gnus-mime-button-map
5154 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5155 face ,gnus-article-button-face
5158 (widget-convert-button 'link from (point)
5159 :action 'gnus-widget-press-button
5160 :button-keymap gnus-widget-button-keymap)
5162 (while (setq handle (pop handles))
5163 (gnus-add-text-properties
5166 (insert (format "(%c) %-18s"
5167 (if (equal handle preferred) ?* ? )
5168 (mm-handle-media-type handle)))
5172 (unless ,(not ibegend)
5173 (setq gnus-article-mime-handle-alist
5174 ',gnus-article-mime-handle-alist))
5175 (gnus-mime-display-alternative
5176 ',ihandles ',handle ',begend ,id))
5177 keymap ,gnus-mime-button-map
5178 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5179 face ,gnus-article-button-face
5182 (widget-convert-button 'link from (point)
5183 :action 'gnus-widget-press-button
5184 :button-keymap gnus-widget-button-keymap)
5188 (if (stringp (car preferred))
5189 (gnus-display-mime preferred)
5190 (let ((mail-parse-charset gnus-newsgroup-charset)
5191 (mail-parse-ignored-charsets
5192 (save-excursion (set-buffer gnus-summary-buffer)
5193 gnus-newsgroup-ignored-charsets)))
5194 (mm-display-part preferred)
5198 (narrow-to-region (car begend) (point-max))
5200 nil (length gnus-article-mime-handle-alist)
5201 (gnus-article-mime-total-parts)
5202 (mm-handle-media-type handle))))))
5203 (goto-char (point-max))
5204 (setcdr begend (point-marker)))))
5206 (goto-char point))))
5208 (defconst gnus-article-wash-status-strings
5209 (let ((alist '((cite "c" "Possible hidden citation text"
5210 " " "All citation text visible")
5211 (headers "h" "Hidden headers"
5212 " " "All headers visible.")
5213 (pgp "p" "Encrypted or signed message status hidden"
5214 " " "No hidden encryption nor digital signature status")
5215 (signature "s" "Signature has been hidden"
5216 " " "Signature is visible")
5217 (overstrike "o" "Overstrike (^H) characters applied"
5218 " " "No overstrike characters applied")
5219 (gnus-show-mime "m" "Mime processing is activated"
5220 " " "Mime processing is not activated")
5221 (emphasis "e" "/*_Emphasis_*/ characters applied"
5222 " " "No /*_emphasis_*/ characters applied")))
5224 (dolist (entry alist result)
5225 (let ((key (nth 0 entry))
5226 (on (copy-sequence (nth 1 entry)))
5227 (on-help (nth 2 entry))
5228 (off (copy-sequence (nth 3 entry)))
5229 (off-help (nth 4 entry)))
5230 (put-text-property 0 1 'help-echo on-help on)
5231 (put-text-property 0 1 'help-echo off-help off)
5232 (push (list key on off) result))))
5233 "Alist of strings describing wash status in the mode line.
5234 Each entry has the form (KEY ON OF), where the KEY is a symbol
5235 representing the particular washing function, ON is the string to use
5236 in the article mode line when the washing function is active, and OFF
5237 is the string to use when it is inactive.")
5239 (defun gnus-article-wash-status-entry (key value)
5240 (let ((entry (assoc key gnus-article-wash-status-strings)))
5241 (if value (nth 1 entry) (nth 2 entry))))
5243 (defun gnus-article-wash-status ()
5244 "Return a string which display status of article washing."
5246 (set-buffer gnus-article-buffer)
5247 (let ((cite (memq 'cite gnus-article-wash-types))
5248 (headers (memq 'headers gnus-article-wash-types))
5249 (boring (memq 'boring-headers gnus-article-wash-types))
5250 (pgp (memq 'pgp gnus-article-wash-types))
5251 (pem (memq 'pem gnus-article-wash-types))
5252 (signed (memq 'signed gnus-article-wash-types))
5253 (encrypted (memq 'encrypted gnus-article-wash-types))
5254 (signature (memq 'signature gnus-article-wash-types))
5255 (overstrike (memq 'overstrike gnus-article-wash-types))
5256 (emphasis (memq 'emphasis gnus-article-wash-types)))
5258 (gnus-article-wash-status-entry 'cite cite)
5259 (gnus-article-wash-status-entry 'headers (or headers boring))
5260 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
5261 (gnus-article-wash-status-entry 'signature signature)
5262 (gnus-article-wash-status-entry 'overstrike overstrike)
5263 (gnus-article-wash-status-entry 'gnus-show-mime gnus-show-mime)
5264 (gnus-article-wash-status-entry 'emphasis emphasis)))))
5266 (defun gnus-add-wash-type (type)
5267 "Add a washing of TYPE to the current status."
5268 (add-to-list 'gnus-article-wash-types type))
5270 (defun gnus-delete-wash-type (type)
5271 "Add a washing of TYPE to the current status."
5272 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
5274 (defun gnus-add-image (category image)
5275 "Add IMAGE of CATEGORY to the list of displayed images."
5276 (let ((entry (assq category gnus-article-image-alist)))
5278 (setq entry (list category))
5279 (push entry gnus-article-image-alist))
5280 (nconc entry (list image))))
5282 (defun gnus-delete-images (category)
5283 "Delete all images in CATEGORY."
5284 (let ((entry (assq category gnus-article-image-alist)))
5285 (dolist (image (cdr entry))
5286 (gnus-remove-image image category))
5287 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
5288 (gnus-delete-wash-type category)))
5290 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
5292 (defun gnus-article-maybe-hide-headers ()
5293 "Hide unwanted headers if `gnus-have-all-headers' is nil.
5294 Provided for backwards compatibility."
5295 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
5296 (not (save-excursion (set-buffer gnus-summary-buffer)
5297 gnus-have-all-headers)))
5298 (not gnus-inhibit-hiding))
5299 (gnus-article-hide-headers)))
5303 (defun gnus-output-to-file (file-name)
5304 "Append the current article to a file named FILE-NAME."
5305 (let ((artbuf (current-buffer)))
5307 (insert-buffer-substring artbuf)
5308 ;; Append newline at end of the buffer as separator, and then
5310 (goto-char (point-max))
5312 (let ((file-name-coding-system nnmail-pathname-coding-system))
5313 (write-region-as-binary (point-min) (point-max) file-name 'append))
5316 (defun gnus-narrow-to-page (&optional arg)
5317 "Narrow the article buffer to a page.
5318 If given a numerical ARG, move forward ARG pages."
5320 (setq arg (if arg (prefix-numeric-value arg) 0))
5322 (set-buffer gnus-article-buffer)
5323 (goto-char (point-min))
5325 ;; Remove any old next/prev buttons.
5326 (when (gnus-visual-p 'page-marker)
5327 (let ((buffer-read-only nil))
5328 (gnus-remove-text-with-property 'gnus-prev)
5329 (gnus-remove-text-with-property 'gnus-next)))
5332 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5334 (re-search-forward page-delimiter nil 'move arg)))
5335 (goto-char (match-end 0))
5337 (goto-char (point-min))
5338 (setq gnus-page-broken
5339 (and (re-search-forward page-delimiter nil t) t))))
5340 (when gnus-page-broken
5343 (if (re-search-forward page-delimiter nil 'move)
5346 (when (and (gnus-visual-p 'page-marker)
5347 (not (= (point-min) 1)))
5349 (goto-char (point-min))
5350 (gnus-insert-prev-page-button)))
5351 (when (and (gnus-visual-p 'page-marker)
5352 (< (+ (point-max) 2) (buffer-size)))
5354 (goto-char (point-max))
5355 (gnus-insert-next-page-button))))))
5357 ;; Article mode commands
5359 (defun gnus-article-goto-next-page ()
5360 "Show the next page of the article."
5362 (when (gnus-article-next-page)
5363 (goto-char (point-min))
5364 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5367 (defun gnus-article-goto-prev-page ()
5368 "Show the previous page of the article."
5371 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5372 (gnus-article-prev-page nil)))
5374 ;; This is cleaner but currently breaks `gnus-pick-mode':
5376 ;; (defun gnus-article-goto-next-page ()
5377 ;; "Show the next page of the article."
5379 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5380 ;; (gnus-summary-next-page)))
5382 ;; (defun gnus-article-goto-prev-page ()
5383 ;; "Show the next page of the article."
5385 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5386 ;; (gnus-summary-prev-page)))
5388 (defun gnus-article-next-page (&optional lines)
5389 "Show the next page of the current article.
5390 If end of article, return non-nil. Otherwise return nil.
5391 Argument LINES specifies lines to be scrolled up."
5393 (move-to-window-line -1)
5396 (and (pos-visible-in-window-p) ;Not continuation line.
5397 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5398 ;; Nothing in this page.
5399 (if (or (not gnus-page-broken)
5403 (eobp)))) ;Real end-of-buffer?
5405 (when gnus-article-over-scroll
5406 (gnus-article-next-page-1 lines))
5408 (gnus-narrow-to-page 1) ;Go to next page.
5410 ;; More in this page.
5411 (gnus-article-next-page-1 lines)
5414 (defun gnus-article-next-page-1 (lines)
5415 (let ((scroll-in-place nil))
5419 ;; Long lines may cause an end-of-buffer error.
5420 (goto-char (point-max)))))
5421 (move-to-window-line 0))
5423 (defun gnus-article-prev-page (&optional lines)
5424 "Show previous page of current article.
5425 Argument LINES specifies lines to be scrolled down."
5427 (move-to-window-line 0)
5428 (if (and gnus-page-broken
5430 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5432 (gnus-narrow-to-page -1) ;Go to previous page.
5433 (goto-char (point-max))
5435 (let ((scroll-in-place nil))
5439 (beginning-of-buffer
5440 (goto-char (point-min))))
5441 (move-to-window-line 0)))))
5443 (defun gnus-article-only-boring-p ()
5444 "Decide whether there is only boring text remaining in the article.
5445 Something \"interesting\" is a word of at least two letters that does
5446 not have a face in `gnus-article-boring-faces'."
5447 (when (and gnus-article-skip-boring
5448 (boundp 'gnus-article-boring-faces)
5449 (symbol-value 'gnus-article-boring-faces))
5452 (while (re-search-forward "\\b\\w\\w" nil t)
5454 (when (not (gnus-intersection
5455 (gnus-faces-at (point))
5456 (symbol-value 'gnus-article-boring-faces)))
5457 (throw 'only-boring nil)))
5458 (throw 'only-boring t)))))
5460 (defun gnus-article-refer-article ()
5461 "Read article specified by message-id around point."
5464 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5465 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5466 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5467 (let ((msg-id (concat "<" (match-string 0) ">")))
5468 (set-buffer gnus-summary-buffer)
5469 (gnus-summary-refer-article msg-id))
5470 (error "No references around point"))))
5472 (defun gnus-article-show-summary ()
5473 "Reconfigure windows to show summary buffer."
5475 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5476 (error "There is no summary buffer for this article buffer")
5477 (gnus-article-set-globals)
5478 (gnus-configure-windows 'article)
5479 (gnus-summary-goto-subject gnus-current-article)
5480 (gnus-summary-position-point)))
5482 (defun gnus-article-describe-briefly ()
5483 "Describe article mode commands briefly."
5485 (gnus-message 6 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
5487 (defun gnus-article-summary-command ()
5488 "Execute the last keystroke in the summary buffer."
5490 (let ((obuf (current-buffer))
5491 (owin (current-window-configuration))
5493 (switch-to-buffer gnus-article-current-summary 'norecord)
5494 (setq func (lookup-key (current-local-map) (this-command-keys)))
5495 (call-interactively func)
5497 (set-window-configuration owin)
5498 (set-window-point (get-buffer-window (current-buffer)) (point))))
5500 (defun gnus-article-summary-command-nosave ()
5501 "Execute the last keystroke in the summary buffer."
5504 (pop-to-buffer gnus-article-current-summary 'norecord)
5505 (setq func (lookup-key (current-local-map) (this-command-keys)))
5506 (call-interactively func)))
5508 (defun gnus-article-check-buffer ()
5509 "Beep if not in an article buffer."
5510 (unless (eq (get-buffer gnus-article-buffer) (current-buffer))
5511 (error "Command invoked outside of a Gnus article buffer")))
5513 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5514 "Read a summary buffer key sequence and execute it from the article buffer."
5516 (gnus-article-check-buffer)
5518 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5519 "Zc" "ZC" "ZE" "ZJ" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5520 "=" "^" "\M-^" "|"))
5526 '("n" "Gn" "p" "Gp"))
5529 (set-buffer gnus-article-current-summary)
5530 (let (gnus-pick-mode)
5531 (push (or key last-command-event) unread-command-events)
5532 (setq keys (static-if (featurep 'xemacs)
5533 (events-to-keys (read-key-sequence nil))
5534 (read-key-sequence nil)))))
5537 (if (or (member keys nosaves)
5538 (member keys nosave-but-article)
5539 (member keys nosave-in-article))
5541 (save-window-excursion
5542 (pop-to-buffer gnus-article-current-summary 'norecord)
5543 ;; We disable the pick minor mode commands.
5544 (let (gnus-pick-mode)
5545 (setq func (lookup-key (current-local-map) keys))))
5549 (unless (member keys nosave-in-article)
5550 (set-buffer gnus-article-current-summary))
5551 (call-interactively func)
5552 (setq new-sum-point (point)))
5553 (when (member keys nosave-but-article)
5554 (pop-to-buffer gnus-article-buffer 'norecord)))
5555 ;; These commands should restore window configuration.
5556 (let ((obuf (current-buffer))
5557 (owin (current-window-configuration))
5559 (summary gnus-article-current-summary)
5560 func in-buffer selected)
5561 (if not-restore-window
5562 (pop-to-buffer summary 'norecord)
5563 (switch-to-buffer summary 'norecord))
5564 (setq in-buffer (current-buffer))
5565 ;; We disable the pick minor mode commands.
5566 (if (and (setq func (let (gnus-pick-mode)
5567 (lookup-key (current-local-map) keys)))
5570 (call-interactively func)
5571 (setq new-sum-point (point))
5572 (when (eq in-buffer (current-buffer))
5573 (setq selected (gnus-summary-select-article))
5575 (unless not-restore-window
5576 (set-window-configuration owin))
5577 (when (eq selected 'old)
5579 (set-window-start (get-buffer-window (current-buffer))
5581 (set-window-point (get-buffer-window (current-buffer))
5583 (let ((win (get-buffer-window gnus-article-current-summary)))
5585 (set-window-point win new-sum-point)))) )
5586 (switch-to-buffer gnus-article-buffer)
5589 (defun gnus-article-describe-key (key)
5590 "Display documentation of the function invoked by KEY. KEY is a string."
5591 (interactive "kDescribe key: ")
5592 (gnus-article-check-buffer)
5593 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5595 (set-buffer gnus-article-current-summary)
5596 (let (gnus-pick-mode)
5597 (if (featurep 'xemacs)
5599 (push (elt key 0) unread-command-events)
5600 (setq key (events-to-keys
5601 (read-key-sequence "Describe key: "))))
5602 (setq unread-command-events
5604 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5606 (setq key (read-key-sequence "Describe key: "))))
5608 (describe-key key)))
5610 (defun gnus-article-describe-key-briefly (key &optional insert)
5611 "Display documentation of the function invoked by KEY. KEY is a string."
5612 (interactive "kDescribe key: \nP")
5613 (gnus-article-check-buffer)
5614 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5616 (set-buffer gnus-article-current-summary)
5617 (let (gnus-pick-mode)
5618 (if (featurep 'xemacs)
5620 (push (elt key 0) unread-command-events)
5621 (setq key (events-to-keys
5622 (read-key-sequence "Describe key: "))))
5623 (setq unread-command-events
5625 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5627 (setq key (read-key-sequence "Describe key: "))))
5628 (describe-key-briefly key insert))
5629 (describe-key-briefly key insert)))
5631 (defun gnus-article-reply-with-original (&optional wide)
5632 "Start composing a reply mail to the current message.
5633 The text in the region will be yanked. If the region isn't active,
5634 the entire article will be yanked."
5636 (let ((article (cdr gnus-article-current))
5638 (if (not (gnus-mark-active-p))
5639 (with-current-buffer gnus-summary-buffer
5640 (gnus-summary-reply (list (list article)) wide))
5641 (setq contents (buffer-substring (point) (mark t)))
5642 ;; Deactivate active regions.
5643 (when (and (boundp 'transient-mark-mode)
5644 transient-mark-mode)
5645 (setq mark-active nil))
5646 (with-current-buffer gnus-summary-buffer
5648 (list (list article contents)) wide)))))
5650 (defun gnus-article-followup-with-original ()
5651 "Compose a followup to the current article.
5652 The text in the region will be yanked. If the region isn't active,
5653 the entire article will be yanked."
5655 (let ((article (cdr gnus-article-current))
5657 (if (not (gnus-mark-active-p))
5658 (with-current-buffer gnus-summary-buffer
5659 (gnus-summary-followup (list (list article))))
5660 (setq contents (buffer-substring (point) (mark t)))
5661 ;; Deactivate active regions.
5662 (when (and (boundp 'transient-mark-mode)
5663 transient-mark-mode)
5664 (setq mark-active nil))
5665 (with-current-buffer gnus-summary-buffer
5666 (gnus-summary-followup
5667 (list (list article contents)))))))
5669 (defun gnus-article-hide (&optional arg force)
5670 "Hide all the gruft in the current article.
5671 This means that signatures, cited text and (some) headers will be
5673 If given a prefix, show the hidden text instead."
5674 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5675 (gnus-article-hide-headers arg)
5676 (gnus-article-hide-list-identifiers arg)
5677 (gnus-article-hide-citation-maybe arg force)
5678 (gnus-article-hide-signature arg))
5680 (defun gnus-article-maybe-highlight ()
5681 "Do some article highlighting if article highlighting is requested."
5682 (when (gnus-visual-p 'article-highlight 'highlight)
5683 (gnus-article-highlight-some)))
5685 (defun gnus-check-group-server ()
5686 ;; Make sure the connection to the server is alive.
5687 (unless (gnus-server-opened
5688 (gnus-find-method-for-group gnus-newsgroup-name))
5689 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5690 (gnus-request-group gnus-newsgroup-name t)))
5693 (autoload 'nneething-get-file-name "nneething"))
5695 (defun gnus-request-article-this-buffer (article group)
5696 "Get an article and insert it into this buffer."
5697 (let (do-update-line sparse-header)
5701 (gnus-kill-all-overlays)
5702 (setq group (or group gnus-newsgroup-name))
5704 ;; Using `gnus-request-article' directly will insert the article into
5705 ;; `nntp-server-buffer' - so we'll save some time by not having to
5706 ;; copy it from the server buffer into the article buffer.
5708 ;; We only request an article by message-id when we do not have the
5709 ;; headers for it, so we'll have to get those.
5710 (when (stringp article)
5711 (gnus-read-header article))
5713 ;; If the article number is negative, that means that this article
5714 ;; doesn't belong in this newsgroup (possibly), so we find its
5715 ;; message-id and request it by id instead of number.
5716 (when (and (numberp article)
5718 (get-buffer gnus-summary-buffer)
5719 (gnus-buffer-exists-p gnus-summary-buffer))
5721 (set-buffer gnus-summary-buffer)
5722 (let ((header (gnus-summary-article-header article)))
5725 ((memq article gnus-newsgroup-sparse)
5726 ;; This is a sparse gap article.
5727 (setq do-update-line article)
5728 (setq article (mail-header-id header))
5729 (setq sparse-header (gnus-read-header article))
5730 (setq gnus-newsgroup-sparse
5731 (delq article gnus-newsgroup-sparse)))
5733 ;; It's a real article.
5734 (setq article (mail-header-id header)))
5736 ;; It is an extracted pseudo-article.
5737 (setq article 'pseudo)
5738 (gnus-request-pseudo-article header))))
5740 (let ((method (gnus-find-method-for-group
5741 gnus-newsgroup-name)))
5742 (when (and (eq (car method) 'nneething)
5744 (let ((dir (nneething-get-file-name
5745 (mail-header-id header))))
5746 (when (and (stringp dir)
5747 (file-directory-p dir))
5748 (setq article 'nneething)
5749 (gnus-group-enter-directory dir))))))))
5752 ;; Refuse to select canceled articles.
5753 ((and (numberp article)
5755 (get-buffer gnus-summary-buffer)
5756 (gnus-buffer-exists-p gnus-summary-buffer)
5757 (eq (cdr (save-excursion
5758 (set-buffer gnus-summary-buffer)
5759 (assq article gnus-newsgroup-reads)))
5760 gnus-canceled-mark))
5762 ;; We first check `gnus-original-article-buffer'.
5763 ((and (get-buffer gnus-original-article-buffer)
5766 (set-buffer gnus-original-article-buffer)
5767 (and (equal (car gnus-original-article) group)
5768 (eq (cdr gnus-original-article) article))))
5769 (insert-buffer-substring gnus-original-article-buffer)
5771 ;; Check the backlog.
5772 ((and gnus-keep-backlog
5773 (gnus-backlog-request-article group article (current-buffer)))
5775 ;; Check asynchronous pre-fetch.
5776 ((gnus-async-request-fetched-article group article (current-buffer))
5777 (gnus-async-prefetch-next group article gnus-summary-buffer)
5778 (when (and (numberp article) gnus-keep-backlog)
5779 (gnus-backlog-enter-article group article (current-buffer)))
5782 ((and gnus-use-cache
5784 (gnus-cache-request-article article group))
5786 ;; Check the agent cache.
5787 ((gnus-agent-request-article article group)
5789 ;; Get the article and put into the article buffer.
5790 ((or (stringp article)
5792 (let ((gnus-override-method gnus-override-method)
5793 (methods (and (stringp article)
5794 gnus-refer-article-method))
5795 (backend (car (gnus-find-method-for-group
5796 gnus-newsgroup-name)))
5798 (buffer-read-only nil))
5799 (if (or (not (listp methods))
5800 (and (symbolp (car methods))
5801 (assq (car methods) nnoo-definition-alist)))
5802 (setq methods (list methods)))
5803 (when (and (null gnus-override-method)
5805 (setq gnus-override-method (pop methods)))
5807 (when (eq gnus-override-method 'current)
5808 (setq gnus-override-method
5809 (with-current-buffer gnus-summary-buffer
5810 gnus-current-select-method)))
5812 (gnus-kill-all-overlays)
5813 (let ((gnus-newsgroup-name group))
5814 (gnus-check-group-server))
5816 ((gnus-request-article article group (current-buffer))
5817 (when (numberp article)
5818 (gnus-async-prefetch-next group article
5819 gnus-summary-buffer)
5820 (when gnus-keep-backlog
5821 (gnus-backlog-enter-article
5822 group article (current-buffer))))
5823 (setq result 'article))
5825 (setq gnus-override-method (pop methods)))
5826 ((not (string-match "^400 "
5827 (nnheader-get-report backend)))
5828 ;; If we get 400 server disconnect, reconnect and
5829 ;; retry; otherwise, assume the article has expired.
5830 (setq result 'done))))
5831 (and (eq result 'article) 'article)))
5835 ;; Associate this article with the current summary buffer.
5836 (setq gnus-article-current-summary gnus-summary-buffer)
5838 ;; Take the article from the original article buffer
5839 ;; and place it in the buffer it's supposed to be in.
5840 (when (and (get-buffer gnus-article-buffer)
5841 (equal (buffer-name (current-buffer))
5842 (buffer-name (get-buffer gnus-article-buffer))))
5844 (if (get-buffer gnus-original-article-buffer)
5845 (set-buffer gnus-original-article-buffer)
5846 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5847 (buffer-disable-undo)
5848 (setq major-mode 'gnus-original-article-mode)
5849 (setq buffer-read-only t))
5850 (let (buffer-read-only)
5852 (insert-buffer-substring gnus-article-buffer))
5853 (setq gnus-original-article (cons group article)))
5856 (run-hooks 'gnus-article-decode-hook)
5857 ;; Mark article as decoded or not.
5858 (setq gnus-article-decoded-p gnus-article-decode-hook))
5860 ;; Update sparse articles.
5861 (when (and do-update-line
5862 (or (numberp article)
5864 (let ((buf (current-buffer)))
5865 (set-buffer gnus-summary-buffer)
5866 (gnus-summary-update-article do-update-line sparse-header)
5867 (gnus-summary-goto-subject do-update-line nil t)
5868 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5870 (set-buffer buf))))))
5876 (defcustom gnus-article-edit-mode-hook nil
5877 "Hook run in article edit mode buffers."
5878 :group 'gnus-article-various
5881 (defcustom gnus-article-edit-article-setup-function
5882 'gnus-article-mime-edit-article-setup
5883 "Function called to setup an editing article buffer."
5884 :group 'gnus-article-various
5887 (defvar gnus-article-edit-done-function nil)
5889 (defvar gnus-article-edit-mode-map nil)
5890 (defvar gnus-article-edit-mode nil)
5892 ;; Should we be using derived.el for this?
5893 (unless gnus-article-edit-mode-map
5894 (setq gnus-article-edit-mode-map (make-keymap))
5895 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5897 (gnus-define-keys gnus-article-edit-mode-map
5898 "\C-c?" describe-mode
5899 "\C-c\C-c" gnus-article-edit-done
5900 "\C-c\C-k" gnus-article-edit-exit
5901 "\C-c\C-f\C-t" message-goto-to
5902 "\C-c\C-f\C-o" message-goto-from
5903 "\C-c\C-f\C-b" message-goto-bcc
5904 ;;"\C-c\C-f\C-w" message-goto-fcc
5905 "\C-c\C-f\C-c" message-goto-cc
5906 "\C-c\C-f\C-s" message-goto-subject
5907 "\C-c\C-f\C-r" message-goto-reply-to
5908 "\C-c\C-f\C-n" message-goto-newsgroups
5909 "\C-c\C-f\C-d" message-goto-distribution
5910 "\C-c\C-f\C-f" message-goto-followup-to
5911 "\C-c\C-f\C-m" message-goto-mail-followup-to
5912 "\C-c\C-f\C-k" message-goto-keywords
5913 "\C-c\C-f\C-u" message-goto-summary
5914 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5915 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5916 "\C-c\C-b" message-goto-body
5917 "\C-c\C-i" message-goto-signature
5919 "\C-c\C-t" message-insert-to
5920 "\C-c\C-n" message-insert-newsgroups
5921 "\C-c\C-o" message-sort-headers
5922 "\C-c\C-e" message-elide-region
5923 "\C-c\C-v" message-delete-not-region
5924 "\C-c\C-z" message-kill-to-signature
5925 "\M-\r" message-newline-and-reformat
5926 "\C-c\C-a" mml-attach-file
5927 "\C-a" message-beginning-of-line
5929 "\M-;" comment-region)
5931 (gnus-define-keys (gnus-article-edit-wash-map
5932 "\C-c\C-w" gnus-article-edit-mode-map)
5933 "f" gnus-article-edit-full-stops))
5936 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5938 ["Fetch To" message-insert-to t]
5939 ["Fetch Newsgroups" message-insert-newsgroups t]
5941 ["To" message-goto-to t]
5942 ["From" message-goto-from t]
5943 ["Subject" message-goto-subject t]
5944 ["Cc" message-goto-cc t]
5945 ["Reply-To" message-goto-reply-to t]
5946 ["Summary" message-goto-summary t]
5947 ["Keywords" message-goto-keywords t]
5948 ["Newsgroups" message-goto-newsgroups t]
5949 ["Followup-To" message-goto-followup-to t]
5950 ["Mail-Followup-To" message-goto-mail-followup-to t]
5951 ["Distribution" message-goto-distribution t]
5952 ["Body" message-goto-body t]
5953 ["Signature" message-goto-signature t]))
5955 (define-derived-mode gnus-article-edit-mode text-mode "Article Edit"
5956 "Major mode for editing articles.
5957 This is an extended text-mode.
5959 \\{gnus-article-edit-mode-map}"
5960 (make-local-variable 'gnus-article-edit-done-function)
5961 (make-local-variable 'gnus-prev-winconf)
5962 (set (make-local-variable 'font-lock-defaults)
5963 '(message-font-lock-keywords t))
5964 (set (make-local-variable 'mail-header-separator) "")
5965 (set (make-local-variable 'gnus-article-edit-mode) t)
5966 (easy-menu-add message-mode-field-menu message-mode-map)
5967 (setq buffer-read-only nil)
5968 (buffer-enable-undo)
5971 (defun gnus-article-edit (&optional force)
5972 "Edit the current article.
5973 This will have permanent effect only in mail groups.
5974 If FORCE is non-nil, allow editing of articles even in read-only
5977 (when (and (not force)
5978 (gnus-group-read-only-p))
5979 (error "The current newsgroup does not support article editing"))
5980 (gnus-article-date-original)
5981 (gnus-article-edit-article
5983 `(lambda (no-highlight)
5985 (gnus-summary-edit-article-done
5986 ,(or (mail-header-references gnus-current-headers) "")
5987 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5989 (defun gnus-article-edit-article (start-func exit-func)
5990 "Start editing the contents of the current article buffer."
5991 (let ((winconf (current-window-configuration)))
5992 (set-buffer gnus-article-buffer)
5993 (gnus-article-edit-mode)
5994 (funcall start-func)
5995 (set-buffer-modified-p nil)
5996 (gnus-configure-windows 'edit-article)
5997 (setq gnus-article-edit-done-function exit-func)
5998 (setq gnus-prev-winconf winconf)
5999 (when gnus-article-edit-article-setup-function
6000 (funcall gnus-article-edit-article-setup-function))
6001 (gnus-message 6 "C-c C-c to end edits; C-c C-k to exit")))
6003 (defun gnus-article-edit-done (&optional arg)
6004 "Update the article edits and exit."
6006 (let ((func gnus-article-edit-done-function)
6007 (buf (current-buffer))
6008 (start (window-start))
6010 (winconf gnus-prev-winconf))
6011 (remove-hook 'gnus-article-mode-hook
6012 'gnus-article-mime-edit-article-unwind)
6013 (widen) ;; Widen it in case that users narrowed the buffer.
6016 ;; The cache and backlog have to be flushed somewhat.
6017 (when gnus-keep-backlog
6018 (gnus-backlog-remove-article
6019 (car gnus-article-current) (cdr gnus-article-current)))
6020 ;; Flush original article as well.
6022 (when (get-buffer gnus-original-article-buffer)
6023 (set-buffer gnus-original-article-buffer)
6024 (setq gnus-original-article nil)))
6025 (when gnus-use-cache
6026 (gnus-cache-update-article
6027 (car gnus-article-current) (cdr gnus-article-current)))
6028 ;; We remove all text props from the article buffer.
6029 (kill-all-local-variables)
6030 (set-text-properties (point-min) (point-max) nil)
6032 (set-window-configuration winconf)
6034 (set-window-start (get-buffer-window buf) start)
6035 (set-window-point (get-buffer-window buf) (point)))
6036 (gnus-summary-show-article))
6038 (defun gnus-article-edit-exit ()
6039 "Exit the article editing without updating."
6041 (when (or (not (buffer-modified-p))
6042 (yes-or-no-p "Article modified; kill anyway? "))
6043 (let ((curbuf (current-buffer))
6045 (window-start (window-start)))
6047 (if (gnus-buffer-live-p gnus-original-article-buffer)
6048 (insert-buffer-substring gnus-original-article-buffer))
6049 (let ((winconf gnus-prev-winconf))
6050 (kill-all-local-variables)
6052 (set-window-configuration winconf)
6053 ;; Tippy-toe some to make sure that point remains where it was.
6054 (save-current-buffer
6056 (set-window-start (get-buffer-window (current-buffer)) window-start)
6058 (gnus-summary-show-article)))
6060 (defun gnus-article-edit-full-stops ()
6061 "Interactively repair spacing at end of sentences."
6064 (goto-char (point-min))
6065 (search-forward-regexp "^$" nil t)
6066 (let ((case-fold-search nil))
6067 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
6070 ;;; Article editing with MIME-Edit
6073 (defcustom gnus-article-mime-edit-article-setup-hook nil
6074 "Hook run after setting up a MIME editing article buffer."
6075 :group 'gnus-article-various
6078 (defun gnus-article-mime-edit-article-unwind ()
6079 "Unwind `gnus-article-buffer' if article editing was given up."
6080 (remove-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6081 (when (featurep 'font-lock)
6082 (setq font-lock-defaults nil)
6083 (font-lock-mode -1))
6084 (when mime-edit-mode-flag
6085 (mime-edit-exit 'nomime 'no-error)
6088 (defun gnus-article-mime-edit-article-setup ()
6089 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode
6090 after replacing with the original article."
6091 (setq gnus-show-mime t)
6092 (setq gnus-article-edit-done-function
6093 `(lambda (&rest args)
6094 (when mime-edit-mode-flag
6095 (let (mime-edit-insert-user-agent-field)
6098 (goto-char (point-min))
6099 (let (case-fold-search)
6100 (when (re-search-forward
6101 (format "^%s$" (regexp-quote mail-header-separator))
6103 (replace-match "")))
6104 (apply ,gnus-article-edit-done-function args)
6107 (buffer-substring-no-properties (point-min) (point-max))
6108 (set-buffer (get-buffer-create gnus-original-article-buffer))
6110 (setq gnus-current-headers (gnus-article-make-full-mail-header))
6111 (set-buffer gnus-article-buffer)
6112 (gnus-article-prepare-display)))
6113 (substitute-key-definition 'gnus-article-edit-done
6114 'gnus-article-mime-edit-done
6115 gnus-article-edit-mode-map)
6116 (substitute-key-definition 'gnus-article-edit-exit
6117 'gnus-article-mime-edit-exit
6118 gnus-article-edit-mode-map)
6120 (insert-buffer-substring gnus-original-article-buffer)
6121 (unless (member (with-current-buffer gnus-summary-buffer
6122 gnus-newsgroup-name)
6123 '("nndraft:delayed" "nndraft:drafts"))
6124 (let ((ofn (symbol-function 'mime-edit-decode-single-part-in-buffer)))
6125 (fset 'mime-edit-decode-single-part-in-buffer
6126 (lambda (&rest args)
6127 (if (let ((content-type (car args)))
6128 (and (eq 'message (mime-content-type-primary-type
6130 (eq 'rfc822 (mime-content-type-subtype
6132 (setcar (cdr args) 'not-decode-text))
6136 (fset 'mime-edit-decode-single-part-in-buffer ofn))))
6137 (when (featurep 'font-lock)
6138 (set (make-local-variable 'font-lock-defaults)
6139 '(message-font-lock-keywords t))
6140 (font-lock-set-defaults)
6141 (turn-on-font-lock))
6142 (set-buffer-modified-p nil)
6143 (delete-other-windows)
6144 (add-hook 'gnus-article-mode-hook 'gnus-article-mime-edit-article-unwind)
6145 (gnus-run-hooks 'gnus-article-mime-edit-article-setup-hook))
6147 (defun gnus-article-mime-edit-done (&optional arg)
6148 "Update the article MIME edits and exit."
6150 (when (featurep 'font-lock)
6151 (setq font-lock-defaults nil)
6152 (font-lock-mode -1))
6153 (let ((inhibit-read-only t))
6154 (gnus-article-edit-done arg)))
6156 (defun gnus-article-mime-edit-exit ()
6157 "Exit the article MIME editing without updating."
6159 (when (or (not (buffer-modified-p))
6160 (yes-or-no-p "Article modified; kill anyway? "))
6161 (when (featurep 'font-lock)
6162 (setq font-lock-defaults nil)
6163 (font-lock-mode -1))
6164 (when mime-edit-mode-flag
6165 (let (mime-edit-insert-user-agent-field)
6168 (goto-char (point-min))
6169 (let (case-fold-search)
6170 (when (re-search-forward
6171 (format "^%s$" (regexp-quote mail-header-separator)) nil t)
6172 (replace-match "")))
6173 (let ((winconf gnus-prev-winconf))
6175 (buffer-substring-no-properties (point-min) (point-max))
6176 (set-buffer (get-buffer-create gnus-original-article-buffer))
6178 (setq gnus-current-headers (gnus-article-make-full-mail-header))
6179 (set-buffer gnus-article-buffer)
6180 (gnus-article-prepare-display)
6181 (set-window-configuration winconf))))
6184 ;;; Article highlights
6187 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
6189 ;;; Internal Variables:
6191 (defcustom gnus-button-url-regexp
6192 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
6193 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?[-a-z0-9_=!?#$@~%&*+\\/:;.,[:word:]]+[-a-z0-9_=#$@~%&*+\\/[:word:]]\\)"
6194 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)\\(//[-a-z0-9_.]+:[0-9]*\\)?\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)\\)")
6195 "Regular expression that matches URLs."
6196 :group 'gnus-article-buttons
6199 (defcustom gnus-button-valid-fqdn-regexp
6200 message-valid-fqdn-regexp
6201 "Regular expression that matches a valid FQDN."
6202 :group 'gnus-article-buttons
6205 (defcustom gnus-button-man-handler 'manual-entry
6206 "Function to use for displaying man pages.
6207 The function must take at least one argument with a string naming the
6209 :type '(choice (function-item :tag "Man" manual-entry)
6210 (function-item :tag "Woman" woman)
6211 (function :tag "Other"))
6212 :group 'gnus-article-buttons)
6214 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
6215 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
6216 If the default site is too slow, try to find a CTAN mirror, see
6217 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
6218 the variable `gnus-button-handle-ctan'."
6219 :group 'gnus-article-buttons
6220 :link '(custom-manual "(gnus)Group Parameters")
6221 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
6222 (const "http://tug.ctan.org/tex-archive/")
6223 (const "http://www.dante.de/CTAN/")
6224 (string :tag "Other")))
6226 (defcustom gnus-button-ctan-handler 'browse-url
6227 "Function to use for displaying CTAN links.
6228 The function must take one argument, the string naming the URL."
6229 :type '(choice (function-item :tag "Browse Url" browse-url)
6230 (function :tag "Other"))
6231 :group 'gnus-article-buttons)
6233 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
6234 "Bogus strings removed from CTAN URLs."
6235 :group 'gnus-article-buttons
6236 :type '(choice (const "^/?tex-archive/\\|/")
6237 (regexp :tag "Other")))
6239 (defcustom gnus-button-ctan-directory-regexp
6241 "\\("; Cannot use `\(?: ... \)' (compatibility with Emacs 20).
6242 "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
6243 "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
6244 "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
6246 "Regular expression for ctan directories.
6247 It should match all directories in the top level of `gnus-ctan-url'."
6248 :group 'gnus-article-buttons
6251 (defcustom gnus-button-mid-or-mail-regexp
6252 (concat "\\b\\(<?[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*@"
6253 ;; Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
6254 gnus-button-valid-fqdn-regexp
6256 "Regular expression that matches a message ID or a mail address."
6257 :group 'gnus-article-buttons
6260 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
6261 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
6262 Strings like this can be either a message ID or a mail address. If it is one
6263 of the symbols `mid' or `mail', Gnus will always assume that the string is a
6264 message ID or a mail address, respectively. If this variable is set to the
6265 symbol `ask', always query the user what do do. If it is a function, this
6266 function will be called with the string as it's only argument. The function
6267 must return `mid', `mail', `invalid' or `ask'."
6268 :group 'gnus-article-buttons
6269 :type '(choice (function-item :tag "Heuristic function"
6270 gnus-button-mid-or-mail-heuristic)
6275 (defcustom gnus-button-mid-or-mail-heuristic-alist
6276 '((-10.0 . ".+\\$.+@")
6279 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
6280 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
6281 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
6282 (-1.0 . "^[^a-z]+@")
6284 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
6285 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
6286 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
6287 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
6290 (-1.0 . "^[0-9][0-9]")
6292 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
6293 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6294 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
6295 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
6297 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
6298 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
6301 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
6303 ;; compensation for TDMA dated mail addresses:
6304 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
6306 (-20.0 . "\\.fsf@") ;; Gnus
6309 (-20.0 . "_-_") ;; Subject change in thread
6311 (-20.0 . "\\.ln@") ;; leafnode
6312 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
6313 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
6315 ;; (5.0 . "") ;; $local_part_len <= 7
6316 (10.0 . "^[^0-9]+@")
6317 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
6318 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
6321 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
6323 (0.5 . "^[A-Z][a-z]")
6324 (0.5 . "^[A-Z][a-z][a-z]")
6325 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
6326 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
6327 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
6329 A negative RATE indicates a message IDs, whereas a positive indicates a mail
6330 address. The REGEXP is processed with `case-fold-search' set to nil."
6331 :group 'gnus-article-buttons
6332 :type '(repeat (cons (number :tag "Rate")
6333 (regexp :tag "Regexp"))))
6335 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
6336 "Guess whether MID-OR-MAIL is a message ID or a mail address.
6337 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
6338 address, `ask' if unsure and `invalid' if the string is invalid."
6339 (let ((case-fold-search nil)
6340 (list gnus-button-mid-or-mail-heuristic-alist)
6341 (result 0) rate regexp lpartlen elem)
6343 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
6344 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
6345 ;; Certain special cases...
6348 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
6349 "^[0-9]+\\.[0-9]+@compuserve\\|"
6350 "@public\\.gmane\\.org")
6352 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
6353 (setq result 'mail))
6354 (when (string-match "@.*@\\| " mid-or-mail)
6355 (gnus-message 8 "`%s' is invalid." mid-or-mail)
6356 (setq result 'invalid))
6357 ;; Nothing more to do, if result is not a number here...
6358 (when (numberp result)
6360 (setq elem (car list)
6364 (when (string-match regexp mid-or-mail)
6365 (setq result (+ result rate))
6367 9 "`%s' matched `%s', rate `%s', result `%s'."
6368 mid-or-mail regexp rate result)))
6369 (when (<= lpartlen 7)
6370 (setq result (+ result 5.0))
6371 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
6372 mid-or-mail result))
6373 (when (>= lpartlen 12)
6374 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
6376 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
6377 ;; Long local part should contain realname if e-mail address,
6378 ;; too many digits: message-id.
6379 ;; $score -= 5.0 + 0.1 * $local_part_len;
6380 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
6381 (setq result (+ result rate))
6383 9 "Many digits in `%s', rate `%s', result `%s'."
6384 mid-or-mail rate result))
6385 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
6387 ;; Too few vowels [^aeiouy]{4,}.*\@
6388 (setq result (+ result -5.0))
6390 9 "Few vowels in `%s', rate `%s', result `%s'."
6391 mid-or-mail -5.0 result))
6393 (setq result (+ result 5.0))
6395 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
6396 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
6397 ;; Maybe we should make this a customizable alist: (condition . 'result)
6399 ((symbolp result) result)
6400 ;; Now convert number into proper results:
6401 ((< result -10.0) 'mid)
6402 ((> result 10.0) 'mail)
6405 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
6406 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
6407 (url-mid (concat "news" ":" mid-or-mail))
6408 (url-mailto (concat "mailto" ":" mid-or-mail)))
6409 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
6410 (when (fboundp pref)
6412 ;; get rid of surrounding angles...
6414 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6415 (if (or (eq 'mid guessed) (eq 'mail guessed))
6419 (save-window-excursion
6420 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6423 (cond ((eq pref 'mid)
6424 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6425 (gnus-button-handle-news url-mid))
6427 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6428 (gnus-url-mailto url-mailto))
6429 (t (gnus-message 3 "Invalid string.")))))
6431 (defun gnus-button-handle-custom (url)
6432 "Follow a Custom URL."
6433 (customize-apropos (gnus-url-unhex-string url)))
6435 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6437 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6440 (defun gnus-button-handle-describe-function (url)
6441 "Call `describe-function' when pushing the corresponding URL button."
6444 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6446 (defun gnus-button-handle-describe-variable (url)
6447 "Call `describe-variable' when pushing the corresponding URL button."
6450 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6452 (defun gnus-button-handle-symbol (url)
6453 "Display help on variable or function.
6454 Calls `describe-variable' or `describe-function'."
6455 (let ((sym (intern url)))
6457 ((fboundp sym) (describe-function sym))
6458 ((boundp sym) (describe-variable sym))
6459 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6461 (defun gnus-button-handle-describe-key (url)
6462 "Call `describe-key' when pushing the corresponding URL button."
6464 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6465 (keys (ignore-errors (eval `(kbd ,key-string)))))
6468 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6470 (defun gnus-button-handle-apropos (url)
6471 "Call `apropos' when pushing the corresponding URL button."
6472 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6474 (defun gnus-button-handle-apropos-command (url)
6475 "Call `apropos' when pushing the corresponding URL button."
6477 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6479 (defun gnus-button-handle-apropos-variable (url)
6480 "Call `apropos' when pushing the corresponding URL button."
6482 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6483 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6485 (defun gnus-button-handle-apropos-documentation (url)
6486 "Call `apropos' when pushing the corresponding URL button."
6488 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6489 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6491 (defun gnus-button-handle-library (url)
6492 "Call `locate-library' when pushing the corresponding URL button."
6493 (gnus-message 9 "url=`%s'" url)
6494 (let* ((lib (locate-library url))
6495 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6497 (gnus-message 1 "Cannot locale library `%s'." url)
6498 (find-file-read-only file))))
6500 (defun gnus-button-handle-ctan (url)
6501 "Call `browse-url' when pushing a CTAN URL button."
6503 gnus-button-ctan-handler
6506 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6508 (defcustom gnus-button-tex-level 5
6509 "*Integer that says how many TeX-related buttons Gnus will show.
6510 The higher the number, the more buttons will appear and the more false
6511 positives are possible. Note that you can set this variable local to
6512 specific groups. Setting it higher in TeX groups is probably a good idea.
6513 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6514 how to set variables in specific groups."
6515 :group 'gnus-article-buttons
6516 :link '(custom-manual "(gnus)Group Parameters")
6519 (defcustom gnus-button-man-level 5
6520 "*Integer that says how many man-related buttons Gnus will show.
6521 The higher the number, the more buttons will appear and the more false
6522 positives are possible. Note that you can set this variable local to
6523 specific groups. Setting it higher in Unix groups is probably a good idea.
6524 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6525 how to set variables in specific groups."
6526 :group 'gnus-article-buttons
6527 :link '(custom-manual "(gnus)Group Parameters")
6530 (defcustom gnus-button-emacs-level 5
6531 "*Integer that says how many emacs-related buttons Gnus will show.
6532 The higher the number, the more buttons will appear and the more false
6533 positives are possible. Note that you can set this variable local to
6534 specific groups. Setting it higher in Emacs or Gnus related groups is
6535 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6536 `gnus-parameters' on how to set variables in specific groups."
6537 :group 'gnus-article-buttons
6538 :link '(custom-manual "(gnus)Group Parameters")
6541 (defcustom gnus-button-message-level 5
6542 "*Integer that says how many buttons for news or mail messages will appear.
6543 The higher the number, the more buttons will appear and the more false
6544 positives are possible."
6545 ;; mail addresses, MIDs, URLs for news, ...
6546 :group 'gnus-article-buttons
6549 (defcustom gnus-button-browse-level 5
6550 "*Integer that says how many buttons for browsing will appear.
6551 The higher the number, the more buttons will appear and the more false
6552 positives are possible."
6553 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6554 :group 'gnus-article-buttons
6557 (defcustom gnus-button-alist
6558 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6559 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6560 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6561 gnus-button-handle-news 2)
6562 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6563 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6564 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6565 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6566 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6567 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6568 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6569 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6570 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6571 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6572 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6573 ;; RFC 2368 (The mailto URL scheme)
6574 ("mailto:\\([-a-z.@_+0-9%=?&]+\\)"
6575 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6576 ("\\bmailto:\\([^ \n\t]+\\)"
6577 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6579 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6580 gnus-button-ctan-directory-regexp
6581 "[^][>)!;:,'\n\t ]+\\)")
6582 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6583 ((concat "\\btex-archive/\\("
6584 gnus-button-ctan-directory-regexp
6585 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6586 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6589 gnus-button-ctan-directory-regexp
6590 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6591 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6592 ;; This is info (home-grown style) <info://foo/bar+baz>
6593 ("\\binfo://\\([^'\">\n\t ]+\\)"
6594 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6595 ;; Info GNOME style <info:foo#bar_baz>
6596 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6597 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6598 ;; Info KDE style <info:(foo)bar baz>
6599 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6600 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6601 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6602 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6603 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6604 ;; Info links like `C-h i d m CC Mode RET'
6605 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6607 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6608 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6609 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6610 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6611 ;; Emacs help commands
6612 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6613 ;; regexp doesn't match arguments containing ` '.
6614 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6615 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6616 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6617 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6618 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6619 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6620 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6621 ;; The following entries may lead to many false positives so don't enable
6622 ;; them by default (use a high button level):
6623 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>"
6624 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6625 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6626 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6627 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6628 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6629 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6630 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6631 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6632 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6633 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6634 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6635 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6636 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6637 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6638 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6639 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6640 ;; Unlike the other regexps we really have to require quoting
6641 ;; here to determine where it ends.
6642 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6643 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6644 ("<URL: *\\([^<>]*\\)>"
6645 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6646 ;; RFC 2396 (2.4.3., delims) ...
6647 ("\"URL: *\\([^\"]*\\)\""
6648 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6649 ;; RFC 2396 (2.4.3., delims) ...
6650 ("\"URL: *\\([^\"]*\\)\""
6651 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6653 (gnus-button-url-regexp
6654 0 (>= gnus-button-browse-level 0) browse-url 0)
6656 ("\\b\\([a-z][a-z]+\\)([1-9])\\W"
6657 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6658 gnus-button-handle-man 1)
6659 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6660 ("\\b\\([a-z][-_.a-z0-9]+\\)([1-9])\\W"
6661 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6662 gnus-button-handle-man 1)
6663 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6664 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6665 ("\\b\\([a-z][-+_.:a-z0-9]+\\)([1-9][X1a-z]*)\\W\\|\\b\\(X\\)([1-9])\\W"
6666 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6667 ;; MID or mail: To avoid too many false positives we don't try to catch
6668 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6669 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6670 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6671 ;; so that non-ambiguous entries (see above) match first.
6672 (gnus-button-mid-or-mail-regexp
6673 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6674 "*Alist of regexps matching buttons in article bodies.
6676 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6677 REGEXP: is the string (case insensitive) matching text around the button (can
6678 also be Lisp expression evaluating to a string),
6679 BUTTON: is the number of the regexp grouping actually matching the button,
6680 FORM: is a Lisp expression which must eval to true for the button to
6682 CALLBACK: is the function to call when the user push this button, and each
6683 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6685 CALLBACK can also be a variable, in that case the value of that
6686 variable it the real callback function."
6687 :group 'gnus-article-buttons
6688 :type '(repeat (list (choice regexp variable sexp)
6689 (integer :tag "Button")
6691 (function :tag "Callback")
6694 (integer :tag "Regexp group")))))
6696 (defcustom gnus-header-button-alist
6697 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6698 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6699 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6700 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6701 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6702 0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6703 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6704 0 (>= gnus-button-browse-level 0) browse-url 0)
6705 ("^Subject:" gnus-button-url-regexp
6706 0 (>= gnus-button-browse-level 0) browse-url 0)
6707 ("^[^:]+:" gnus-button-url-regexp
6708 0 (>= gnus-button-browse-level 0) browse-url 0)
6709 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&]+\\)"
6710 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6711 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6712 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6713 "*Alist of headers and regexps to match buttons in article heads.
6715 This alist is very similar to `gnus-button-alist', except that each
6716 alist has an additional HEADER element first in each entry:
6718 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6720 HEADER is a regexp to match a header. For a fuller explanation, see
6721 `gnus-button-alist'."
6722 :group 'gnus-article-buttons
6723 :group 'gnus-article-headers
6724 :type '(repeat (list (regexp :tag "Header")
6725 (choice regexp variable)
6726 (integer :tag "Button")
6728 (function :tag "Callback")
6731 (integer :tag "Regexp group")))))
6733 (defvar gnus-button-regexp nil)
6734 (defvar gnus-button-marker-list nil)
6735 ;; Regexp matching any of the regexps from `gnus-button-alist'.
6737 (defvar gnus-button-last nil)
6738 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
6742 (defun gnus-article-push-button (event)
6743 "Check text under the mouse pointer for a callback function.
6744 If the text under the mouse pointer has a `gnus-callback' property,
6745 call it with the value of the `gnus-data' text property."
6747 (set-buffer (window-buffer (posn-window (event-start event))))
6748 (let* ((pos (posn-point (event-start event)))
6749 (data (get-text-property pos 'gnus-data))
6750 (fun (get-text-property pos 'gnus-callback)))
6753 (funcall fun data))))
6755 (defun gnus-article-press-button ()
6756 "Check text at point for a callback function.
6757 If the text at point has a `gnus-callback' property,
6758 call it with the value of the `gnus-data' text property."
6760 (let ((data (get-text-property (point) 'gnus-data))
6761 (fun (get-text-property (point) 'gnus-callback)))
6763 (funcall fun data))))
6765 (defun gnus-article-prev-button (n)
6766 "Move point to N buttons backward.
6767 If N is negative, move forward instead."
6769 (gnus-article-next-button (- n)))
6771 (defun gnus-article-next-button (n)
6772 "Move point to N buttons forward.
6773 If N is negative, move backward instead."
6775 (let ((function (if (< n 0) 'previous-single-property-change
6776 'next-single-property-change))
6777 (inhibit-point-motion-hooks t)
6779 (limit (if (< n 0) (point-min) (point-max))))
6781 (while (and (not (= limit (point)))
6783 ;; Skip past the current button.
6784 (when (get-text-property (point) 'gnus-callback)
6785 (goto-char (funcall function (point) 'gnus-callback nil limit)))
6786 ;; Go to the next (or previous) button.
6787 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit))
6788 ;; Put point at the start of the button.
6789 (when (and backward (not (get-text-property (point) 'gnus-callback)))
6790 (goto-char (funcall function (point) 'gnus-callback nil limit)))
6791 ;; Skip past intangible buttons.
6792 (when (get-text-property (point) 'intangible)
6796 (gnus-message 5 "No more buttons"))
6799 (defun gnus-article-highlight (&optional force)
6800 "Highlight current article.
6801 This function calls `gnus-article-highlight-headers',
6802 `gnus-article-highlight-citation',
6803 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6804 do the highlighting. See the documentation for those functions."
6805 (interactive (list 'force))
6806 (gnus-article-highlight-headers)
6807 (gnus-article-highlight-citation force)
6808 (gnus-article-highlight-signature)
6809 (gnus-article-add-buttons force)
6810 (gnus-article-add-buttons-to-head))
6812 (defun gnus-article-highlight-some (&optional force)
6813 "Highlight current article.
6814 This function calls `gnus-article-highlight-headers',
6815 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6816 do the highlighting. See the documentation for those functions."
6817 (interactive (list 'force))
6818 (gnus-article-highlight-headers)
6819 (gnus-article-highlight-signature)
6820 (gnus-article-add-buttons))
6822 (defun gnus-article-highlight-headers ()
6823 "Highlight article headers as specified by `gnus-header-face-alist'."
6826 (set-buffer gnus-article-buffer)
6828 (let ((alist gnus-header-face-alist)
6829 (buffer-read-only nil)
6830 (case-fold-search t)
6831 (inhibit-point-motion-hooks t)
6832 entry regexp header-face field-face from hpoints fpoints)
6833 (article-narrow-to-head)
6834 (while (setq entry (pop alist))
6835 (goto-char (point-min))
6836 (setq regexp (concat "^\\("
6837 (if (string-equal "" (nth 0 entry))
6841 header-face (nth 1 entry)
6842 field-face (nth 2 entry))
6843 (while (and (re-search-forward regexp nil t)
6847 (unless (search-forward ":" nil t)
6849 (when (and header-face
6850 (not (memq (point) hpoints)))
6851 (push (point) hpoints)
6852 (gnus-put-text-property from (point) 'face header-face))
6853 (when (and field-face
6854 (not (memq (setq from (point)) fpoints)))
6856 (if (re-search-forward "^[^ \t]" nil t)
6858 (goto-char (point-max)))
6859 (gnus-put-text-property from (point) 'face field-face))))))))
6861 (defun gnus-article-highlight-signature ()
6862 "Highlight the signature in an article.
6863 It does this by highlighting everything after
6864 `gnus-signature-separator' using `gnus-signature-face'."
6866 (when gnus-signature-face
6868 (set-buffer gnus-article-buffer)
6869 (let ((buffer-read-only nil)
6870 (inhibit-point-motion-hooks t))
6872 (when (gnus-article-narrow-to-signature)
6873 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6874 'face gnus-signature-face)))))))
6876 (defun gnus-article-buttonize-signature ()
6877 "Add button to the signature."
6880 (set-buffer gnus-article-buffer)
6881 (let ((buffer-read-only nil)
6882 (inhibit-point-motion-hooks t))
6883 (when (gnus-article-search-signature)
6884 (gnus-article-add-button (match-beginning 0) (match-end 0)
6885 'gnus-signature-toggle
6886 (set-marker (make-marker)
6887 (1+ (match-end 0))))))))
6889 (defun gnus-button-in-region-p (b e prop)
6890 "Say whether PROP exists in the region."
6891 (text-property-not-all b e prop nil))
6893 (defun gnus-article-add-buttons (&optional force)
6894 "Find external references in the article and make buttons of them.
6895 \"External references\" are things like Message-IDs and URLs, as
6896 specified by `gnus-button-alist'."
6897 (interactive (list 'force))
6899 (set-buffer gnus-article-buffer)
6900 (let ((buffer-read-only nil)
6901 (inhibit-point-motion-hooks t)
6902 (case-fold-search t)
6903 (alist gnus-button-alist)
6905 ;; Remove all old markers.
6906 (let (marker entry new-list)
6907 (while (setq marker (pop gnus-button-marker-list))
6908 (if (or (< marker (point-min)) (>= marker (point-max)))
6909 (push marker new-list)
6911 (when (setq entry (gnus-button-entry))
6912 (put-text-property (match-beginning (nth 1 entry))
6913 (match-end (nth 1 entry))
6914 'gnus-callback nil))
6915 (set-marker marker nil)))
6916 (setq gnus-button-marker-list new-list))
6917 ;; We skip the headers.
6920 (while (setq entry (pop alist))
6921 (setq regexp (eval (car entry)))
6923 (while (re-search-forward regexp nil t)
6924 (let* ((start (and entry (match-beginning (nth 1 entry))))
6925 (end (and entry (match-end (nth 1 entry))))
6926 (from (match-beginning 0)))
6927 (when (and (or (eq t (nth 2 entry))
6928 (eval (nth 2 entry)))
6929 (not (gnus-button-in-region-p
6930 start end 'gnus-callback)))
6931 ;; That optional form returned non-nil, so we add the
6933 (gnus-article-add-button
6934 start end 'gnus-button-push
6935 (car (push (set-marker (make-marker) from)
6936 gnus-button-marker-list))))))))))
6938 ;; Add buttons to the head of an article.
6939 (defun gnus-article-add-buttons-to-head ()
6940 "Add buttons to the head of the article."
6943 (set-buffer gnus-article-buffer)
6945 (let ((buffer-read-only nil)
6946 (inhibit-point-motion-hooks t)
6947 (case-fold-search t)
6948 (alist gnus-header-button-alist)
6950 (article-narrow-to-head)
6952 ;; Each alist entry.
6953 (setq entry (car alist)
6955 (goto-char (point-min))
6956 (while (re-search-forward (car entry) nil t)
6957 ;; Each header matching the entry.
6958 (setq beg (match-beginning 0))
6959 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6960 (match-beginning 0))
6963 (while (re-search-forward (eval (nth 1 entry)) end t)
6964 ;; Each match within a header.
6965 (let* ((entry (cdr entry))
6966 (start (match-beginning (nth 1 entry)))
6967 (end (match-end (nth 1 entry)))
6968 (form (nth 2 entry)))
6969 (goto-char (match-end 0))
6971 (gnus-article-add-button
6972 start end (nth 3 entry)
6973 (buffer-substring (match-beginning (nth 4 entry))
6974 (match-end (nth 4 entry)))))))
6975 (goto-char end)))))))
6977 ;;; External functions:
6979 (defun gnus-article-add-button (from to fun &optional data)
6980 "Create a button between FROM and TO with callback FUN and data DATA."
6981 (when gnus-article-button-face
6982 (gnus-overlay-put (gnus-make-overlay from to)
6983 'face gnus-article-button-face))
6984 (gnus-add-text-properties
6986 (nconc (and gnus-article-mouse-face
6987 (list gnus-mouse-face-prop gnus-article-mouse-face))
6988 (list 'gnus-callback fun)
6989 (and data (list 'gnus-data data))))
6990 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6991 ;; Quote `:button-keymap' for Mule 2.3
6992 ;; but it won't work.
6993 ':button-keymap gnus-widget-button-keymap))
6995 ;;; Internal functions:
6997 (defun gnus-article-set-globals ()
6999 (set-buffer gnus-summary-buffer)
7000 (gnus-set-global-variables)))
7002 (defun gnus-signature-toggle (end)
7004 (set-buffer gnus-article-buffer)
7005 (let ((buffer-read-only nil)
7006 (inhibit-point-motion-hooks t)
7007 (limit (next-single-property-change end 'mime-view-entity
7009 (if (text-property-any end limit 'article-type 'signature)
7011 (gnus-delete-wash-type 'signature)
7012 (gnus-remove-text-properties-when
7013 'article-type 'signature end limit
7014 (cons 'article-type (cons 'signature
7015 gnus-hidden-properties))))
7016 (gnus-add-wash-type 'signature)
7017 (gnus-add-text-properties-when
7018 'article-type nil end limit
7019 (cons 'article-type (cons 'signature
7020 gnus-hidden-properties)))))
7021 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7022 (gnus-set-mode-line 'article))))
7024 (defun gnus-button-entry ()
7025 ;; Return the first entry in `gnus-button-alist' matching this place.
7026 (let ((alist gnus-button-alist)
7029 (setq entry (pop alist))
7030 (if (looking-at (eval (car entry)))
7035 (defun gnus-button-push (marker)
7036 ;; Push button starting at MARKER.
7039 (let* ((entry (gnus-button-entry))
7040 (inhibit-point-motion-hooks t)
7042 (args (mapcar (lambda (group)
7043 (let ((string (match-string group)))
7044 (set-text-properties
7045 0 (length string) nil string)
7052 (fboundp (symbol-value fun)))
7053 (apply (symbol-value fun) args))
7055 (gnus-message 1 "You must define `%S' to use this button"
7056 (cons fun args)))))))
7058 (defun gnus-parse-news-url (url)
7059 (let (scheme server group message-id articles)
7062 (goto-char (point-min))
7063 (when (looking-at "\\([A-Za-z]+\\):")
7064 (setq scheme (match-string 1))
7065 (goto-char (match-end 0)))
7066 (when (looking-at "//\\([^/]+\\)/")
7067 (setq server (match-string 1))
7068 (goto-char (match-end 0)))
7071 ((looking-at "\\(.*@.*\\)")
7072 (setq message-id (match-string 1)))
7073 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7074 (setq group (match-string 1)
7075 articles (split-string (match-string 2) "-")))
7076 ((looking-at "\\([^/]+\\)/?")
7077 (setq group (match-string 1)))
7079 (error "Unknown news URL syntax"))))
7080 (list scheme server group message-id articles)))
7082 (defun gnus-button-handle-news (url)
7084 (destructuring-bind (scheme server group message-id articles)
7085 (gnus-parse-news-url url)
7089 (set-buffer gnus-summary-buffer)
7091 (let ((gnus-refer-article-method (list (list 'nntp server))))
7092 (gnus-summary-refer-article message-id))
7093 (gnus-summary-refer-article message-id))))
7095 (gnus-button-fetch-group url)))))
7097 (defun gnus-button-handle-man (url)
7099 (funcall gnus-button-man-handler url))
7101 (defun gnus-button-handle-info-url (url)
7102 "Fetch an info URL."
7103 (setq url (mm-subst-char-in-string ?+ ?\ url))
7105 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
7106 (gnus-info-find-node
7107 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
7109 ")" (gnus-url-unhex-string (match-string 2 url)))))
7110 ((string-match "([^)\"]+)[^\"]+" url)
7112 (gnus-replace-in-string
7113 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
7114 (gnus-info-find-node url))
7115 (t (error "Can't parse %s" url))))
7117 (defun gnus-button-handle-info-url-gnome (url)
7118 "Fetch GNOME style info URL."
7119 (setq url (mm-subst-char-in-string ?_ ?\ url))
7120 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
7121 (gnus-info-find-node
7123 (gnus-url-unhex-string
7124 (match-string 1 url))
7126 (or (gnus-url-unhex-string
7127 (match-string 2 url))
7129 (error "Can't parse %s" url)))
7131 (defun gnus-button-handle-info-url-kde (url)
7132 "Fetch KDE style info URL."
7133 (gnus-info-find-node (gnus-url-unhex-string url)))
7135 (defun gnus-button-handle-info-keystrokes (url)
7136 "Call `info' when pushing the corresponding URL button."
7137 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
7142 (defun gnus-button-message-id (message-id)
7145 (set-buffer gnus-summary-buffer)
7146 (gnus-summary-refer-article message-id)))
7148 (defun gnus-button-fetch-group (address)
7149 "Fetch GROUP specified by ADDRESS."
7150 (if (not (string-match "[:/]" address))
7151 ;; This is just a simple group url.
7152 (gnus-group-read-ephemeral-group address gnus-select-method)
7155 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
7157 (error "Can't parse %s" address)
7158 (gnus-group-read-ephemeral-group
7159 (match-string 4 address)
7160 `(nntp ,(match-string 1 address)
7161 (nntp-address ,(match-string 1 address))
7162 (nntp-port-number ,(if (match-end 3)
7163 (match-string 3 address)
7166 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
7168 (defun gnus-url-parse-query-string (query &optional downcase)
7169 (let (retval pairs cur key val)
7170 (setq pairs (split-string query "&"))
7172 (setq cur (car pairs)
7174 (if (not (string-match "=" cur))
7176 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
7177 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
7179 (setq key (downcase key)))
7180 (setq cur (assoc key retval))
7182 (setcdr cur (cons val (cdr cur)))
7183 (setq retval (cons (list key val) retval)))))
7186 (defun gnus-url-mailto (url)
7187 ;; Send mail to someone
7188 (when (string-match "mailto:/*\\(.*\\)" url)
7189 (setq url (substring url (match-beginning 1) nil)))
7190 (let (to args subject func)
7191 (setq args (gnus-url-parse-query-string
7192 (if (string-match "^\\?" url)
7194 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
7195 (concat "to=" (match-string 1 url) "&"
7196 (match-string 2 url))
7197 (concat "to=" url)))
7199 subject (cdr-safe (assoc "subject" args)))
7202 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
7205 (message-position-on-field (caar args)))
7206 (insert (gnus-replace-in-string
7207 (mapconcat 'identity (reverse (cdar args)) ", ")
7209 (setq args (cdr args)))
7212 (message-goto-subject))))
7214 (defun gnus-button-embedded-url (address)
7215 "Activate ADDRESS with `browse-url'."
7216 (browse-url (gnus-strip-whitespace address)))
7218 ;;; Next/prev buttons in the article buffer.
7220 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
7221 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
7223 (defvar gnus-prev-page-map
7224 (let ((map (make-sparse-keymap)))
7225 (unless (>= emacs-major-version 21)
7226 ;; XEmacs doesn't care.
7227 (set-keymap-parent map gnus-article-mode-map))
7228 (define-key map gnus-mouse-2 'gnus-button-prev-page)
7229 (define-key map "\r" 'gnus-button-prev-page)
7232 (defun gnus-insert-prev-page-button ()
7234 (buffer-read-only nil)
7235 (situation (get-text-property (point-min) 'mime-view-situation)))
7237 gnus-prev-page-line-format nil
7238 `(keymap ,gnus-prev-page-map
7240 gnus-callback gnus-article-button-prev-page
7241 article-type annotation
7242 mime-view-situation ,situation))
7243 (widget-convert-button
7245 ;; Exclude a newline.
7248 :action 'gnus-button-prev-page
7249 :button-keymap gnus-prev-page-map)))
7251 (defvar gnus-next-page-map
7252 (let ((map (make-sparse-keymap)))
7253 (unless (>= emacs-major-version 21)
7254 ;; XEmacs doesn't care.
7255 (set-keymap-parent map gnus-article-mode-map))
7256 (define-key map gnus-mouse-2 'gnus-button-next-page)
7257 (define-key map "\r" 'gnus-button-next-page)
7260 (defun gnus-button-next-page (&optional args more-args)
7261 "Go to the next page."
7263 (let ((win (selected-window)))
7264 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7265 (gnus-article-next-page)
7266 (select-window win)))
7268 (defun gnus-button-prev-page (&optional args more-args)
7269 "Go to the prev page."
7271 (let ((win (selected-window)))
7272 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7273 (gnus-article-prev-page)
7274 (select-window win)))
7276 (defun gnus-insert-next-page-button ()
7278 (buffer-read-only nil)
7279 (situation (get-text-property (point-min) 'mime-view-situation)))
7280 (gnus-eval-format gnus-next-page-line-format nil
7281 `(keymap ,gnus-next-page-map
7283 gnus-callback gnus-article-button-next-page
7284 article-type annotation
7285 mime-view-situation ,situation))
7286 (widget-convert-button
7288 ;; Exclude a newline.
7291 :action 'gnus-button-next-page
7292 :button-keymap gnus-next-page-map)))
7294 (defun gnus-article-button-next-page (arg)
7295 "Go to the next page."
7297 (let ((win (selected-window)))
7298 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7299 (gnus-article-next-page)
7300 (select-window win)))
7302 (defun gnus-article-button-prev-page (arg)
7303 "Go to the prev page."
7305 (let ((win (selected-window)))
7306 (select-window (gnus-get-buffer-window gnus-article-buffer t))
7307 (gnus-article-prev-page)
7308 (select-window win)))
7310 (defvar gnus-decode-header-methods
7311 '(mail-decode-encoded-word-region)
7312 "List of methods used to decode headers.
7314 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
7315 is FUNCTION, FUNCTION will be apply to all newsgroups. If item is a
7316 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
7317 whose names match REGEXP.
7320 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
7321 mail-decode-encoded-word-region
7322 (\"chinese\" . rfc1843-decode-region))
7325 (defvar gnus-decode-header-methods-cache nil)
7327 (defun gnus-multi-decode-header (start end)
7328 "Apply the functions from `gnus-encoded-word-methods' that match."
7329 (unless (and gnus-decode-header-methods-cache
7330 (eq gnus-newsgroup-name
7331 (car gnus-decode-header-methods-cache)))
7332 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
7335 (nconc gnus-decode-header-methods-cache (list x))
7336 (if (and gnus-newsgroup-name
7337 (string-match (car x) gnus-newsgroup-name))
7338 (nconc gnus-decode-header-methods-cache
7340 gnus-decode-header-methods))
7341 (let ((xlist gnus-decode-header-methods-cache))
7344 (narrow-to-region start end)
7346 (funcall (pop xlist) (point-min) (point-max))))))
7349 ;;; Treatment top-level handling.
7352 (defun gnus-treat-article (condition &optional part-number total-parts type)
7353 (let ((length (- (point-max) (point-min)))
7354 (alist gnus-treatment-function-alist)
7355 (article-goto-body-goes-to-point-min-p t)
7359 (let ((list gnus-article-treat-types))
7361 (when (string-match (pop list) type)
7362 (throw 'found t)))))))
7363 (highlightp (gnus-visual-p 'article-highlight 'highlight))
7364 (entity (static-unless (featurep 'xemacs)
7365 (when (eq 'head condition)
7366 (get-text-property (point-min) 'mime-view-entity))))
7367 val elem buttonized)
7368 (gnus-run-hooks 'gnus-part-display-hook)
7369 (unless gnus-inhibit-treatment
7370 (dolist (elem alist)
7373 (when (gnus-buffer-live-p gnus-summary-buffer)
7374 (set-buffer gnus-summary-buffer))
7375 (symbol-value (car elem))))
7376 (when (and (or (consp val)
7378 (gnus-treat-predicate val)
7379 (or (not (get (car elem) 'highlight))
7381 (when (and (not buttonized)
7383 '(gnus-treat-hide-signature
7384 gnus-treat-highlight-signature)))
7385 (gnus-article-buttonize-signature)
7386 (setq buttonized t))
7388 (funcall (cadr elem)))))
7389 ;; FSF Emacsen does not inherit the existing text properties
7390 ;; in the new text, so we should do it for `mime-view-entity'.
7391 (static-unless (featurep 'xemacs)
7393 (put-text-property (point-min) (point-max)
7394 'mime-view-entity entity))))))
7396 ;; Dynamic variables.
7398 (defvar part-number)
7399 (defvar total-parts)
7404 (defun gnus-treat-predicate (val)
7409 (stringp (car val)))
7410 (apply 'gnus-or (mapcar `(lambda (s)
7411 (string-match s ,(or gnus-newsgroup-name "")))
7414 (let ((pred (pop val)))
7417 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
7419 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
7421 (not (gnus-treat-predicate (car val))))
7423 (equal (car val) type))
7425 (error "%S is not a valid predicate" pred)))))
7435 (eq part-number total-parts))
7439 (error "%S is not a valid value" val))))
7441 (defun gnus-article-encrypt-body (protocol &optional n)
7442 "Encrypt the article body."
7445 (or gnus-article-encrypt-protocol
7446 (completing-read "Encrypt protocol: "
7447 gnus-article-encrypt-protocol-alist
7449 current-prefix-arg))
7450 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
7452 (error (format "Can't find the encrypt protocol %s" protocol)))
7453 (if (member gnus-newsgroup-name '("nndraft:delayed"
7456 (error "Can't encrypt the article in group %s"
7457 gnus-newsgroup-name))
7458 (gnus-summary-iterate n
7460 (set-buffer gnus-summary-buffer)
7461 (let ((mail-parse-charset gnus-newsgroup-charset)
7462 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
7463 (summary-buffer gnus-summary-buffer)
7465 (gnus-set-global-variables)
7466 (when (gnus-group-read-only-p)
7467 (error "The current newsgroup does not support article encrypt"))
7468 (gnus-summary-show-article t)
7470 (or (mail-header-references gnus-current-headers) ""))
7471 (set-buffer gnus-article-buffer)
7472 (let* ((buffer-read-only nil)
7474 (mapcar (lambda (field)
7475 (and (save-restriction
7476 (message-narrow-to-head)
7477 (goto-char (point-min))
7478 (search-forward field nil t))
7480 (message-narrow-to-field)
7482 (delete-region (point-min) (point-max))
7484 '("Content-Type:" "Content-Transfer-Encoding:"
7485 "Content-Disposition:"))))
7486 (message-narrow-to-head)
7487 (message-remove-header "MIME-Version")
7488 (goto-char (point-max))
7489 (setq point (point))
7490 (insert (apply 'concat headers))
7492 (narrow-to-region point (point-max))
7493 (let ((message-options message-options))
7494 (message-options-set 'message-sender user-mail-address)
7495 (message-options-set 'message-recipients user-mail-address)
7496 (message-options-set 'message-sign-encrypt 'not)
7498 (goto-char (point-min))
7499 (insert "MIME-Version: 1.0\n")
7501 (gnus-summary-edit-article-done
7502 references nil summary-buffer t))
7503 (when gnus-keep-backlog
7504 (gnus-backlog-remove-article
7505 (car gnus-article-current) (cdr gnus-article-current)))
7507 (when (get-buffer gnus-original-article-buffer)
7508 (set-buffer gnus-original-article-buffer)
7509 (setq gnus-original-article nil)))
7510 (when gnus-use-cache
7511 (gnus-cache-update-article
7512 (car gnus-article-current) (cdr gnus-article-current))))))))
7514 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7515 "The following specs can be used:
7516 %t The security MIME type
7519 %D Details if button is pressed")
7521 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7522 "The following specs can be used:
7523 %t The security MIME type
7526 %D Details if button is pressed")
7528 (defvar gnus-mime-security-button-line-format-alist
7529 '((?t gnus-tmp-type ?s)
7530 (?i gnus-tmp-info ?s)
7531 (?d gnus-tmp-details ?s)
7532 (?D gnus-tmp-pressed-details ?s)))
7534 (defvar gnus-mime-security-button-map
7535 (let ((map (make-sparse-keymap)))
7536 (unless (>= (string-to-number emacs-version) 21)
7537 (set-keymap-parent map gnus-article-mode-map))
7538 (define-key map gnus-mouse-2 'gnus-article-push-button)
7539 (define-key map "\r" 'gnus-article-press-button)
7542 (defvar gnus-mime-security-details-buffer nil)
7544 (defvar gnus-mime-security-button-pressed nil)
7546 (defvar gnus-mime-security-show-details-inline t
7547 "If non-nil, show details in the article buffer.")
7549 (defun gnus-mime-security-verify-or-decrypt (handle)
7550 (mm-remove-parts (cdr handle))
7551 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7552 point buffer-read-only)
7554 (goto-char (car region)))
7556 (narrow-to-region (point) (point))
7557 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7558 (let* ((mm-verify-option 'known)
7559 (mm-decrypt-option 'known)
7560 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7561 (unless (eq nparts (cdr handle))
7562 (mm-destroy-parts (cdr handle))
7563 (setcdr handle nparts))))
7564 (setq point (point))
7565 (gnus-mime-display-security handle)
7566 (goto-char (point-max)))
7568 (delete-region (point) (cdr region))
7569 (set-marker (car region) nil)
7570 (set-marker (cdr region) nil))
7573 (defun gnus-mime-security-show-details (handle)
7574 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7576 (gnus-message 5 "No details.")
7577 (if gnus-mime-security-show-details-inline
7578 (let ((gnus-mime-security-button-pressed
7579 (not (get-text-property (point) 'gnus-mime-details)))
7580 (gnus-mime-security-button-line-format
7581 (get-text-property (point) 'gnus-line-format))
7584 (while (eq (get-text-property (point) 'gnus-line-format)
7585 gnus-mime-security-button-line-format)
7589 (narrow-to-region (point) (point))
7590 (gnus-insert-mime-security-button handle))
7591 (delete-region (point)
7592 (or (text-property-not-all
7595 gnus-mime-security-button-line-format)
7598 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7599 (with-current-buffer gnus-mime-security-details-buffer
7602 (setq gnus-mime-security-details-buffer
7603 (gnus-get-buffer-create "*MIME Security Details*")))
7604 (with-current-buffer gnus-mime-security-details-buffer
7606 (goto-char (point-min)))
7607 (pop-to-buffer gnus-mime-security-details-buffer)))))
7609 (defun gnus-mime-security-press-button (handle)
7611 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7612 (gnus-mime-security-show-details handle)
7613 (gnus-mime-security-verify-or-decrypt handle))))
7615 (defun gnus-insert-mime-security-button (handle &optional displayed)
7616 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7619 (or (nth 2 (assoc protocol mm-verify-function-alist))
7620 (nth 2 (assoc protocol mm-decrypt-function-alist))
7622 (if (equal (car handle) "multipart/signed")
7623 " Signed" " Encrypted")
7626 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7629 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7630 gnus-tmp-pressed-details
7632 (setq gnus-tmp-details
7633 (if gnus-tmp-details
7634 (concat "\n" gnus-tmp-details)
7636 (setq gnus-tmp-pressed-details
7637 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7642 gnus-mime-security-button-line-format
7643 gnus-mime-security-button-line-format-alist
7644 `(keymap ,gnus-mime-security-button-map
7645 gnus-callback gnus-mime-security-press-button
7646 gnus-line-format ,gnus-mime-security-button-line-format
7647 gnus-mime-details ,gnus-mime-security-button-pressed
7648 article-type annotation
7651 ;; Exclude a newline.
7654 (widget-convert-button
7657 :action 'gnus-widget-press-button
7658 :button-keymap gnus-mime-security-button-map
7660 (lambda (widget/window &optional overlay pos)
7661 ;; Needed to properly clear the message due to a bug in
7662 ;; wid-edit (XEmacs only).
7663 (when (boundp 'help-echo-owns-message)
7664 (setq help-echo-owns-message t))
7667 (aref gnus-mouse-2 0))))))
7669 (defun gnus-mime-display-security (handle)
7671 (narrow-to-region (point) (point))
7672 (unless (gnus-unbuttonized-mime-type-p (car handle))
7673 (gnus-insert-mime-security-button handle))
7674 (gnus-mime-display-mixed (cdr handle))
7677 (unless (gnus-unbuttonized-mime-type-p (car handle))
7678 (let ((gnus-mime-security-button-line-format
7679 gnus-mime-security-button-end-line-format))
7680 (gnus-insert-mime-security-button handle)))
7681 (mm-set-handle-multipart-parameter
7683 (cons (set-marker (make-marker) (point-min))
7684 (set-marker (make-marker) (point-max))))))
7690 (defun gnus-article-header-presentation-method (entity situation)
7691 (mime-insert-header entity)
7692 (article-decode-group-name))
7694 (set-alist 'mime-header-presentation-method-alist
7695 'gnus-original-article-mode
7696 #'gnus-article-header-presentation-method)
7698 (defun gnus-mime-preview-quitting-method ()
7699 (mime-preview-kill-buffer)
7700 (delete-other-windows)
7701 (gnus-article-show-summary)
7702 (gnus-summary-select-article gnus-show-all-headers t))
7704 (set-alist 'mime-preview-quitting-method-alist
7705 'gnus-original-article-mode #'gnus-mime-preview-quitting-method)
7707 (set-alist 'mime-preview-following-method-alist
7708 'gnus-original-article-mode #'gnus-following-method)
7710 (set-alist 'mime-preview-over-to-previous-method-alist
7711 'gnus-original-article-mode
7713 (if (> (point-min) 1)
7714 (gnus-article-prev-page)
7715 (gnus-article-read-summary-keys
7716 nil (gnus-character-to-event ?P)))))
7718 (set-alist 'mime-preview-over-to-next-method-alist
7719 'gnus-original-article-mode'
7721 (if (< (point-max) (buffer-size))
7722 (gnus-article-next-page)
7723 (gnus-article-read-summary-keys
7724 nil (gnus-character-to-event ?N)))))
7734 (run-hooks 'gnus-art-load-hook)
7736 ;;; gnus-art.el ends here