1 ;;; gnus-art.el --- article mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
31 (defvar tool-bar-map))
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (defgroup gnus-article nil
53 :link '(custom-manual "(gnus)Article Buffer")
56 (defgroup gnus-article-treat nil
57 "Treating article parts."
58 :link '(custom-manual "(gnus)Article Hiding")
61 (defgroup gnus-article-hiding nil
62 "Hiding article parts."
63 :link '(custom-manual "(gnus)Article Hiding")
66 (defgroup gnus-article-highlight nil
67 "Article highlighting."
68 :link '(custom-manual "(gnus)Article Highlighting")
72 (defgroup gnus-article-signature nil
74 :link '(custom-manual "(gnus)Article Signature")
77 (defgroup gnus-article-headers nil
79 :link '(custom-manual "(gnus)Hiding Headers")
82 (defgroup gnus-article-washing nil
83 "Special commands on articles."
84 :link '(custom-manual "(gnus)Article Washing")
87 (defgroup gnus-article-emphasis nil
88 "Fontisizing articles."
89 :link '(custom-manual "(gnus)Article Fontisizing")
92 (defgroup gnus-article-saving nil
94 :link '(custom-manual "(gnus)Saving Articles")
97 (defgroup gnus-article-mime nil
98 "Worshiping the MIME wonder."
99 :link '(custom-manual "(gnus)Using MIME")
100 :group 'gnus-article)
102 (defgroup gnus-article-buttons nil
103 "Pushable buttons in the article buffer."
104 :link '(custom-manual "(gnus)Article Buttons")
105 :group 'gnus-article)
107 (defgroup gnus-article-various nil
108 "Other article options."
109 :link '(custom-manual "(gnus)Misc Article")
110 :group 'gnus-article)
112 (defcustom gnus-ignored-headers
115 (concat "^" header ":"))
116 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
117 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
118 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
119 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
120 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
121 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
122 "X-Attribution" "X-Originating-IP" "Delivered-To"
123 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
124 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
125 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
126 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
127 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
128 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
129 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
130 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
131 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
132 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
133 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
134 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
135 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
136 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
137 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
138 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
139 "List-[A-Za-z]+" "X-Listprocessor-Version"
140 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
141 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
142 "X-Received" "Content-length" "X-precedence"
143 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
144 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
145 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
146 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
147 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
148 "X-Content-length" "X-Posting-Agent" "Original-Received"
149 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
150 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
151 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
152 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
153 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"))
154 "*All headers that start with this regexp will be hidden.
155 This variable can also be a list of regexps of headers to be ignored.
156 If `gnus-visible-headers' is non-nil, this variable will be ignored."
157 :type '(choice :custom-show nil
160 :group 'gnus-article-hiding)
162 (defcustom gnus-visible-headers
163 "^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:"
164 "*All headers that do not match this regexp will be hidden.
165 This variable can also be a list of regexp of headers to remain visible.
166 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
167 :type '(repeat :value-to-internal (lambda (widget value)
168 (custom-split-regexp-maybe value))
169 :match (lambda (widget value)
171 (widget-editable-list-match widget value)))
173 :group 'gnus-article-hiding)
175 (defcustom gnus-sorted-header-list
176 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
177 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
178 "*This variable is a list of regular expressions.
179 If it is non-nil, headers that match the regular expressions will
180 be placed first in the article buffer in the sequence specified by
182 :type '(repeat regexp)
183 :group 'gnus-article-hiding)
185 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
186 "Headers that are only to be displayed if they have interesting data.
187 Possible values in this list are:
189 'empty Headers with no content.
190 'newsgroups Newsgroup identical to Gnus group.
191 'to-address To identical to To-address.
192 'to-list To identical to To-list.
193 'cc-list CC identical to To-list.
194 'followup-to Followup-to identical to Newsgroups.
195 'reply-to Reply-to identical to From.
196 'date Date less than four days old.
197 'long-to To and/or Cc longer than 1024 characters.
198 'many-to Multiple To and/or Cc."
199 :type '(set (const :tag "Headers with no content." empty)
200 (const :tag "Newsgroups identical to Gnus group." newsgroups)
201 (const :tag "To identical to To-address." to-address)
202 (const :tag "To identical to To-list." to-list)
203 (const :tag "CC identical to To-list." cc-list)
204 (const :tag "Followup-to identical to Newsgroups." followup-to)
205 (const :tag "Reply-to identical to From." reply-to)
206 (const :tag "Date less than four days old." date)
207 (const :tag "To and/or Cc longer than 1024 characters." long-to)
208 (const :tag "Multiple To and/or Cc headers." many-to))
209 :group 'gnus-article-hiding)
211 (defcustom gnus-article-skip-boring nil
212 "Skip over text that is not worth reading.
213 By default, if you set this t, then Gnus will display citations and
214 signatures, but will never scroll down to show you a page consisting
215 only of boring text. Boring text is controlled by
216 `gnus-article-boring-faces'."
219 :group 'gnus-article-hiding)
221 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
222 "Regexp matching signature separator.
223 This can also be a list of regexps. In that case, it will be checked
224 from head to tail looking for a separator. Searches will be done from
225 the end of the buffer."
226 :type '(repeat string)
227 :group 'gnus-article-signature)
229 (defcustom gnus-signature-limit nil
230 "Provide a limit to what is considered a signature.
231 If it is a number, no signature may not be longer (in characters) than
232 that number. If it is a floating point number, no signature may be
233 longer (in lines) than that number. If it is a function, the function
234 will be called without any parameters, and if it returns nil, there is
235 no signature in the buffer. If it is a string, it will be used as a
236 regexp. If it matches, the text in question is not a signature.
238 This can also be a list of the above values."
239 :type '(choice (integer :value 200)
241 (function :value fun)
242 (regexp :value ".*"))
243 :group 'gnus-article-signature)
245 (defcustom gnus-hidden-properties '(invisible t intangible t)
246 "Property list to use for hiding text."
248 :group 'gnus-article-hiding)
250 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
251 ;; frames in a session.
252 (defcustom gnus-article-x-face-command
253 (if (featurep 'xemacs)
254 (if (or (gnus-image-type-available-p 'xface)
255 (gnus-image-type-available-p 'pbm))
256 'gnus-display-x-face-in-from
257 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
258 (if (gnus-image-type-available-p 'pbm)
259 'gnus-display-x-face-in-from
260 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
262 "*String or function to be executed to display an X-Face header.
263 If it is a string, the command will be executed in a sub-shell
264 asynchronously. The compressed face will be piped to this command."
265 :type `(choice string
266 (function-item gnus-display-x-face-in-from)
270 :group 'gnus-article-washing)
272 (defcustom gnus-article-x-face-too-ugly nil
273 "Regexp matching posters whose face shouldn't be shown automatically."
274 :type '(choice regexp (const nil))
275 :group 'gnus-article-washing)
277 (defcustom gnus-article-banner-alist nil
278 "Banner alist for stripping.
280 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
282 :type '(repeat (cons symbol regexp))
283 :group 'gnus-article-washing)
285 (gnus-define-group-parameter
288 "Alist of regexps (to match group names) and banner."
289 :variable-group gnus-article-washing
291 '(choice :tag "Banner"
293 (const :tag "Remove signature" signature)
294 (symbol :tag "Item in `gnus-article-banner-alist'" none)
296 (const :tag "None" nil))
298 "If non-nil, specify how to remove `banners' from articles.
300 Symbol `signature' means to remove signatures delimited by
301 `gnus-signature-separator'. Any other symbol is used to look up a
302 regular expression to match the banner in `gnus-article-banner-alist'.
303 A string is used as a regular expression to match the banner
306 (defcustom gnus-article-address-banner-alist nil
307 "Alist of mail addresses and banners.
308 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
309 to match a mail address in the From: header, BANNER is one of a symbol
310 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
311 If ADDRESS matches author's mail address, it will remove things like
312 advertisements. For example:
314 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
318 (regexp :tag "Address")
319 (choice :tag "Banner" :value nil
320 (const :tag "Remove signature" signature)
321 (symbol :tag "Item in `gnus-article-banner-alist'" none)
323 (const :tag "None" nil))))
325 :group 'gnus-article-washing)
327 (defmacro gnus-emphasis-custom-with-format (&rest body)
329 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
330 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
333 (defun gnus-emphasis-custom-value-to-external (value)
334 (gnus-emphasis-custom-with-format
335 (if (consp (car value))
336 (list (format format (car (car value)) (cdr (car value)))
338 (if (nth 1 value) 2 3)
342 (defun gnus-emphasis-custom-value-to-internal (value)
343 (gnus-emphasis-custom-with-format
344 (let ((regexp (concat "\\`"
345 (format (regexp-quote format)
346 "\\([^()]+\\)" "\\([^()]+\\)")
349 (if (string-match regexp (setq pattern (car value)))
350 (list (cons (match-string 1 pattern) (match-string 2 pattern))
355 (defcustom gnus-emphasis-alist
357 '(("\\*" "\\*" bold nil 2)
360 ("_/" "/_" underline-italic)
361 ("_\\*" "\\*_" underline-bold)
362 ("\\*/" "/\\*" bold-italic)
363 ("_\\*/" "/\\*_" underline-bold-italic))))
365 (gnus-emphasis-custom-with-format
366 (mapcar (lambda (spec)
367 (list (format format (car spec) (cadr spec))
370 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
372 '(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
373 2 3 gnus-emphasis-underline))))
374 "*Alist that says how to fontify certain phrases.
375 Each item looks like this:
377 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
379 The first element is a regular expression to be matched. The second
380 is a number that says what regular expression grouping used to find
381 the entire emphasized word. The third is a number that says what
382 regexp grouping should be displayed and highlighted. The fourth
383 is the face used for highlighting."
387 :format "%[Customizing Style%]\n%v"
389 (group :tag "Default"
390 :value ("" 0 0 default)
393 (let ((value (widget-get
394 (cadr (widget-get (widget-get widget :parent)
397 (if (not (eq (nth 2 value) 'default))
401 (gnus-emphasis-custom-value-to-external value))))
402 (widget-group-value-create widget))
403 (regexp :format "%t: %v\n" :size 1)
404 (integer :format "Match group: %v\n" :size 0)
405 (integer :format "Emphasize group: %v\n" :size 0)
408 :value (("_" . "_") nil default)
410 (regexp :format "Start regexp: %v\n" :size 0)
411 (regexp :format "End regexp: %v\n" :size 0))
412 (boolean :format "Show start and end patterns: %[%v%]\n"
413 :on " On " :off " Off ")
415 :get (lambda (symbol)
416 (mapcar 'gnus-emphasis-custom-value-to-internal
417 (default-value symbol)))
418 :set (lambda (symbol value)
419 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
421 :group 'gnus-article-emphasis)
423 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
424 "A regexp to describe whitespace which should not be emphasized.
425 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
426 The former avoids underlining of leading and trailing whitespace,
427 and the latter avoids underlining any whitespace at all."
429 :group 'gnus-article-emphasis
432 (defface gnus-emphasis-bold '((t (:bold t)))
433 "Face used for displaying strong emphasized text (*word*)."
434 :group 'gnus-article-emphasis)
436 (defface gnus-emphasis-italic '((t (:italic t)))
437 "Face used for displaying italic emphasized text (/word/)."
438 :group 'gnus-article-emphasis)
440 (defface gnus-emphasis-underline '((t (:underline t)))
441 "Face used for displaying underlined emphasized text (_word_)."
442 :group 'gnus-article-emphasis)
444 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
445 "Face used for displaying underlined bold emphasized text (_*word*_)."
446 :group 'gnus-article-emphasis)
448 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
449 "Face used for displaying underlined italic emphasized text (_/word/_)."
450 :group 'gnus-article-emphasis)
452 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
453 "Face used for displaying bold italic emphasized text (/*word*/)."
454 :group 'gnus-article-emphasis)
456 (defface gnus-emphasis-underline-bold-italic
457 '((t (:bold t :italic t :underline t)))
458 "Face used for displaying underlined bold italic emphasized text.
459 Example: (_/*word*/_)."
460 :group 'gnus-article-emphasis)
462 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
463 '((t (:strikethru t)))
464 '((t (:strike-through t))))
465 "Face used for displaying strike-through text (-word-)."
466 :group 'gnus-article-emphasis)
468 (defface gnus-emphasis-highlight-words
469 '((t (:background "black" :foreground "yellow")))
470 "Face used for displaying highlighted words."
471 :group 'gnus-article-emphasis)
473 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
474 "Format for display of Date headers in article bodies.
475 See `format-time-string' for the possible values.
477 The variable can also be function, which should return a complete Date
478 header. The function is called with one argument, the time, which can
479 be fed to `format-time-string'."
480 :type '(choice string function)
481 :link '(custom-manual "(gnus)Article Date")
482 :group 'gnus-article-washing)
485 (autoload 'mail-extract-address-components "mail-extr"))
487 (defcustom gnus-save-all-headers t
488 "*If non-nil, don't remove any headers before saving."
489 :group 'gnus-article-saving
492 (defcustom gnus-prompt-before-saving 'always
493 "*This variable says how much prompting is to be done when saving articles.
494 If it is nil, no prompting will be done, and the articles will be
495 saved to the default files. If this variable is `always', each and
496 every article that is saved will be preceded by a prompt, even when
497 saving large batches of articles. If this variable is neither nil not
498 `always', there the user will be prompted once for a file name for
499 each invocation of the saving commands."
500 :group 'gnus-article-saving
501 :type '(choice (item always)
502 (item :tag "never" nil)
503 (sexp :tag "once" :format "%t\n" :value t)))
505 (defcustom gnus-saved-headers gnus-visible-headers
506 "Headers to keep if `gnus-save-all-headers' is nil.
507 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
508 If that variable is nil, however, all headers that match this regexp
509 will be kept while the rest will be deleted before saving."
510 :group 'gnus-article-saving
513 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
514 "A function to save articles in your favourite format.
515 The function must be interactively callable (in other words, it must
516 be an Emacs command).
518 Gnus provides the following functions:
520 * gnus-summary-save-in-rmail (Rmail format)
521 * gnus-summary-save-in-mail (Unix mail format)
522 * gnus-summary-save-in-folder (MH folder)
523 * gnus-summary-save-in-file (article format)
524 * gnus-summary-save-body-in-file (article body)
525 * gnus-summary-save-in-vm (use VM's folder format)
526 * gnus-summary-write-to-file (article format -- overwrite)."
527 :group 'gnus-article-saving
528 :type '(radio (function-item gnus-summary-save-in-rmail)
529 (function-item gnus-summary-save-in-mail)
530 (function-item gnus-summary-save-in-folder)
531 (function-item gnus-summary-save-in-file)
532 (function-item gnus-summary-save-body-in-file)
533 (function-item gnus-summary-save-in-vm)
534 (function-item gnus-summary-write-to-file)))
536 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
537 "A function generating a file name to save articles in Rmail format.
538 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
539 :group 'gnus-article-saving
542 (defcustom gnus-mail-save-name 'gnus-plain-save-name
543 "A function generating a file name to save articles in Unix mail format.
544 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
545 :group 'gnus-article-saving
548 (defcustom gnus-folder-save-name 'gnus-folder-save-name
549 "A function generating a file name to save articles in MH folder.
550 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
551 :group 'gnus-article-saving
554 (defcustom gnus-file-save-name 'gnus-numeric-save-name
555 "A function generating a file name to save articles in article format.
556 The function is called with NEWSGROUP, HEADERS, and optional
558 :group 'gnus-article-saving
561 (defcustom gnus-split-methods
562 '((gnus-article-archive-name)
563 (gnus-article-nndoc-name))
564 "*Variable used to suggest where articles are to be saved.
565 For instance, if you would like to save articles related to Gnus in
566 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
567 you could set this variable to something like:
569 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
570 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
572 This variable is an alist where the where the key is the match and the
573 value is a list of possible files to save in if the match is non-nil.
575 If the match is a string, it is used as a regexp match on the
576 article. If the match is a symbol, that symbol will be funcalled
577 from the buffer of the article to be saved with the newsgroup as the
578 parameter. If it is a list, it will be evaled in the same buffer.
580 If this form or function returns a string, this string will be used as
581 a possible file name; and if it returns a non-nil list, that list will
582 be used as possible file names."
583 :group 'gnus-article-saving
584 :type '(repeat (choice (list :value (fun) function)
585 (cons :value ("" "") regexp (repeat string))
588 (defcustom gnus-page-delimiter "^\^L"
589 "*Regexp describing what to use as article page delimiters.
590 The default value is \"^\^L\", which is a form linefeed at the
591 beginning of a line."
593 :group 'gnus-article-various)
595 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
596 "*The format specification for the article mode line.
597 See `gnus-summary-mode-line-format' for a closer description.
599 The following additional specs are available:
601 %w The article washing status.
602 %m The number of MIME parts in the article."
604 :group 'gnus-article-various)
606 (defcustom gnus-article-mode-hook nil
607 "*A hook for Gnus article mode."
609 :group 'gnus-article-various)
611 (when (featurep 'xemacs)
612 ;; Extracted from gnus-xmas-define in order to preserve user settings
613 (when (fboundp 'turn-off-scroll-in-place)
614 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
615 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
616 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
618 (defcustom gnus-article-menu-hook nil
619 "*Hook run after the creation of the article mode menu."
621 :group 'gnus-article-various)
623 (defcustom gnus-article-prepare-hook nil
624 "*A hook called after an article has been prepared in the article buffer."
626 :group 'gnus-article-various)
628 (defcustom gnus-copy-article-ignored-headers nil
629 "List of headers to be removed when copying an article.
630 Each element is a regular expression."
631 :version "22.0" ;; No Gnus
632 :type '(repeat regexp)
633 :group 'gnus-article-various)
635 (make-obsolete-variable 'gnus-article-hide-pgp-hook
636 "This variable is obsolete in Gnus 5.10.")
638 (defcustom gnus-article-button-face 'bold
639 "Face used for highlighting buttons in the article buffer.
641 An article button is a piece of text that you can activate by pressing
642 `RET' or `mouse-2' above it."
644 :group 'gnus-article-buttons)
646 (defcustom gnus-article-mouse-face 'highlight
647 "Face used for mouse highlighting in the article buffer.
649 Article buttons will be displayed in this face when the cursor is
652 :group 'gnus-article-buttons)
654 (defcustom gnus-signature-face 'gnus-signature-face
655 "Face used for highlighting a signature in the article buffer.
656 Obsolete; use the face `gnus-signature-face' for customizations instead."
658 :group 'gnus-article-highlight
659 :group 'gnus-article-signature)
661 (defface gnus-signature-face
664 "Face used for highlighting a signature in the article buffer."
665 :group 'gnus-article-highlight
666 :group 'gnus-article-signature)
668 (defface gnus-header-from-face
671 (:foreground "spring green"))
674 (:foreground "red3"))
677 "Face used for displaying from headers."
678 :group 'gnus-article-headers
679 :group 'gnus-article-highlight)
681 (defface gnus-header-subject-face
684 (:foreground "SeaGreen3"))
687 (:foreground "red4"))
689 (:bold t :italic t)))
690 "Face used for displaying subject headers."
691 :group 'gnus-article-headers
692 :group 'gnus-article-highlight)
694 (defface gnus-header-newsgroups-face
697 (:foreground "yellow" :italic t))
700 (:foreground "MidnightBlue" :italic t))
703 "Face used for displaying newsgroups headers.
704 In the default setup this face is only used for crossposted
706 :group 'gnus-article-headers
707 :group 'gnus-article-highlight)
709 (defface gnus-header-name-face
712 (:foreground "SeaGreen"))
715 (:foreground "maroon"))
718 "Face used for displaying header names."
719 :group 'gnus-article-headers
720 :group 'gnus-article-highlight)
722 (defface gnus-header-content-face
725 (:foreground "forest green" :italic t))
728 (:foreground "indianred4" :italic t))
730 (:italic t))) "Face used for displaying header content."
731 :group 'gnus-article-headers
732 :group 'gnus-article-highlight)
734 (defcustom gnus-header-face-alist
735 '(("From" nil gnus-header-from-face)
736 ("Subject" nil gnus-header-subject-face)
737 ("Newsgroups:.*," nil gnus-header-newsgroups-face)
738 ("" gnus-header-name-face gnus-header-content-face))
739 "*Controls highlighting of article headers.
741 An alist of the form (HEADER NAME CONTENT).
743 HEADER is a regular expression which should match the name of a
744 header and NAME and CONTENT are either face names or nil.
746 The name of each header field will be displayed using the face
747 specified by the first element in the list where HEADER matches
748 the header name and NAME is non-nil. Similarly, the content will
749 be displayed by the first non-nil matching CONTENT face."
750 :group 'gnus-article-headers
751 :group 'gnus-article-highlight
752 :type '(repeat (list (regexp :tag "Header")
754 (item :tag "skip" nil)
755 (face :value default))
756 (choice :tag "Content"
757 (item :tag "skip" nil)
758 (face :value default)))))
760 (defcustom gnus-article-decode-hook
761 '(article-decode-charset article-decode-encoded-words
762 article-decode-group-name article-decode-idna-rhs)
763 "*Hook run to decode charsets in articles."
764 :group 'gnus-article-headers
767 (defcustom gnus-display-mime-function 'gnus-display-mime
768 "Function to display MIME articles."
769 :group 'gnus-article-mime
772 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
773 "Function used to decode headers.")
775 (defvar gnus-article-dumbquotes-map
795 "Table for MS-to-Latin1 translation.")
797 (defcustom gnus-ignored-mime-types nil
798 "List of MIME types that should be ignored by Gnus."
800 :group 'gnus-article-mime
801 :type '(repeat regexp))
803 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
804 "List of MIME types that should not be given buttons when rendered inline.
805 See also `gnus-buttonized-mime-types' which may override this variable.
806 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
808 :group 'gnus-article-mime
809 :type '(repeat regexp))
811 (defcustom gnus-buttonized-mime-types nil
812 "List of MIME types that should be given buttons when rendered inline.
813 If set, this variable overrides `gnus-unbuttonized-mime-types'.
814 To see e.g. security buttons you could set this to
815 `(\"multipart/signed\")'.
816 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
818 :group 'gnus-article-mime
819 :type '(repeat regexp))
821 (defcustom gnus-inhibit-mime-unbuttonizing nil
822 "If non-nil, all MIME parts get buttons.
823 When nil (the default value), then some MIME parts do not get buttons,
824 as described by the variables `gnus-buttonized-mime-types' and
825 `gnus-unbuttonized-mime-types'."
827 :group 'gnus-article-mime
830 (defcustom gnus-body-boundary-delimiter "_"
831 "String used to delimit header and body.
832 This variable is used by `gnus-article-treat-body-boundary' which can
833 be controlled by `gnus-treat-body-boundary'."
835 :group 'gnus-article-various
836 :type '(choice (item :tag "None" :value nil)
839 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
841 "Defines the location of the faces database.
842 For information on obtaining this database of pretty pictures, please
843 see http://www.cs.indiana.edu/picons/ftp/index.html"
845 :type '(repeat directory)
846 :link '(url-link :tag "download"
847 "http://www.cs.indiana.edu/picons/ftp/index.html")
848 :link '(custom-manual "(gnus)Picons")
851 (defun gnus-picons-installed-p ()
852 "Say whether picons are installed on your machine."
853 (let ((installed nil))
854 (dolist (database gnus-picon-databases)
855 (when (file-exists-p database)
859 (defcustom gnus-article-mime-part-function nil
860 "Function called with a MIME handle as the argument.
861 This is meant for people who want to do something automatic based
862 on parts -- for instance, adding Vcard info to a database."
863 :group 'gnus-article-mime
866 (defcustom gnus-mime-multipart-functions nil
867 "An alist of MIME types to functions to display them."
869 :group 'gnus-article-mime
870 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
872 (defcustom gnus-article-date-lapsed-new-header nil
873 "Whether the X-Sent and Date headers can coexist.
874 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
875 either replace the old \"Date:\" header (if this variable is nil), or
876 be added below it (otherwise)."
878 :group 'gnus-article-headers
881 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
882 "Function called with a MIME handle as the argument.
883 This is meant for people who want to view first matched part.
884 For `undisplayed-alternative' (default), the first undisplayed
885 part or alternative part is used. For `undisplayed', the first
886 undisplayed part is used. For a function, the first part which
887 the function return t is used. For nil, the first part is
890 :group 'gnus-article-mime
892 (item :tag "first" :value nil)
893 (item :tag "undisplayed" :value undisplayed)
894 (item :tag "undisplayed or alternative"
895 :value undisplayed-alternative)
898 (defcustom gnus-mime-action-alist
899 '(("save to file" . gnus-mime-save-part)
900 ("save and strip" . gnus-mime-save-part-and-strip)
901 ("delete part" . gnus-mime-delete-part)
902 ("display as text" . gnus-mime-inline-part)
903 ("view the part" . gnus-mime-view-part)
904 ("pipe to command" . gnus-mime-pipe-part)
905 ("toggle display" . gnus-article-press-button)
906 ("toggle display" . gnus-article-view-part-as-charset)
907 ("view as type" . gnus-mime-view-part-as-type)
908 ("view internally" . gnus-mime-view-part-internally)
909 ("view externally" . gnus-mime-view-part-externally))
910 "An alist of actions that run on the MIME attachment."
911 :group 'gnus-article-mime
912 :type '(repeat (cons (string :tag "name")
916 ;;; The treatment variables
919 (defvar gnus-part-display-hook nil
920 "Hook called on parts that are to receive treatment.")
922 (defvar gnus-article-treat-custom
923 '(choice (const :tag "Off" nil)
925 (const :tag "Header" head)
926 (const :tag "Last" last)
927 (integer :tag "Less")
928 (repeat :tag "Groups" regexp)
929 (sexp :tag "Predicate")))
931 (defvar gnus-article-treat-head-custom
932 '(choice (const :tag "Off" nil)
933 (const :tag "Header" head)))
935 (defvar gnus-article-treat-types '("text/plain")
938 (defvar gnus-inhibit-treatment nil
939 "Whether to inhibit treatment.")
941 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
942 "Highlight the signature.
943 Valid values are nil, t, `head', `last', an integer or a predicate.
944 See Info node `(gnus)Customizing Articles'."
945 :group 'gnus-article-treat
946 :link '(custom-manual "(gnus)Customizing Articles")
947 :type gnus-article-treat-custom)
948 (put 'gnus-treat-highlight-signature 'highlight t)
950 (defcustom gnus-treat-buttonize 100000
952 Valid values are nil, t, `head', `last', an integer or a predicate.
953 See Info node `(gnus)Customizing Articles'."
954 :group 'gnus-article-treat
955 :link '(custom-manual "(gnus)Customizing Articles")
956 :type gnus-article-treat-custom)
957 (put 'gnus-treat-buttonize 'highlight t)
959 (defcustom gnus-treat-buttonize-head 'head
960 "Add buttons to the head.
961 Valid values are nil, t, `head', `last', an integer or a predicate.
962 See Info node `(gnus)Customizing Articles' for details."
963 :group 'gnus-article-treat
964 :link '(custom-manual "(gnus)Customizing Articles")
965 :type gnus-article-treat-head-custom)
966 (put 'gnus-treat-buttonize-head 'highlight t)
968 (defcustom gnus-treat-emphasize
969 (and (or window-system
973 Valid values are nil, t, `head', `last', an integer or a predicate.
974 See Info node `(gnus)Customizing Articles' for details."
975 :group 'gnus-article-treat
976 :link '(custom-manual "(gnus)Customizing Articles")
977 :type gnus-article-treat-custom)
978 (put 'gnus-treat-emphasize 'highlight t)
980 (defcustom gnus-treat-strip-cr nil
981 "Remove carriage returns.
982 Valid values are nil, t, `head', `last', an integer or a predicate.
983 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-unsplit-urls nil
990 "Remove newlines from within URLs.
991 Valid values are nil, t, `head', `last', an integer or a predicate.
992 See Info node `(gnus)Customizing Articles' for details."
994 :group 'gnus-article-treat
995 :link '(custom-manual "(gnus)Customizing Articles")
996 :type gnus-article-treat-custom)
998 (defcustom gnus-treat-leading-whitespace nil
999 "Remove leading whitespace in headers.
1000 Valid values are nil, t, `head', `last', an integer or a predicate.
1001 See Info node `(gnus)Customizing Articles' for details."
1003 :group 'gnus-article-treat
1004 :link '(custom-manual "(gnus)Customizing Articles")
1005 :type gnus-article-treat-custom)
1007 (defcustom gnus-treat-hide-headers 'head
1009 Valid values are nil, t, `head', `last', an integer or a predicate.
1010 See Info node `(gnus)Customizing Articles' for details."
1011 :group 'gnus-article-treat
1012 :link '(custom-manual "(gnus)Customizing Articles")
1013 :type gnus-article-treat-head-custom)
1015 (defcustom gnus-treat-hide-boring-headers nil
1016 "Hide boring headers.
1017 Valid values are nil, t, `head', `last', an integer or a predicate.
1018 See Info node `(gnus)Customizing Articles' for details."
1019 :group 'gnus-article-treat
1020 :link '(custom-manual "(gnus)Customizing Articles")
1021 :type gnus-article-treat-head-custom)
1023 (defcustom gnus-treat-hide-signature nil
1024 "Hide the signature.
1025 Valid values are nil, t, `head', `last', an integer or a predicate.
1026 See Info node `(gnus)Customizing Articles' for details."
1027 :group 'gnus-article-treat
1028 :link '(custom-manual "(gnus)Customizing Articles")
1029 :type gnus-article-treat-custom)
1031 (defcustom gnus-treat-fill-article nil
1033 Valid values are nil, t, `head', `last', an integer or a predicate.
1034 See Info node `(gnus)Customizing Articles' for details."
1035 :group 'gnus-article-treat
1036 :link '(custom-manual "(gnus)Customizing Articles")
1037 :type gnus-article-treat-custom)
1039 (defcustom gnus-treat-hide-citation nil
1041 Valid values are nil, t, `head', `last', an integer or a predicate.
1042 See Info node `(gnus)Customizing Articles' for details."
1043 :group 'gnus-article-treat
1044 :link '(custom-manual "(gnus)Customizing Articles")
1045 :type gnus-article-treat-custom)
1047 (defcustom gnus-treat-hide-citation-maybe nil
1049 Valid values are nil, t, `head', `last', an integer or a predicate.
1050 See Info node `(gnus)Customizing Articles' for details."
1051 :group 'gnus-article-treat
1052 :link '(custom-manual "(gnus)Customizing Articles")
1053 :type gnus-article-treat-custom)
1055 (defcustom gnus-treat-strip-list-identifiers 'head
1056 "Strip list identifiers from `gnus-list-identifiers`.
1057 Valid values are nil, t, `head', `last', an integer or a predicate.
1058 See Info node `(gnus)Customizing Articles' for details."
1060 :group 'gnus-article-treat
1061 :link '(custom-manual "(gnus)Customizing Articles")
1062 :type gnus-article-treat-custom)
1064 (make-obsolete-variable 'gnus-treat-strip-pgp
1065 "This option is obsolete in Gnus 5.10.")
1067 (defcustom gnus-treat-strip-pem nil
1068 "Strip PEM signatures.
1069 Valid values are nil, t, `head', `last', an integer or a predicate.
1070 See Info node `(gnus)Customizing Articles' for details."
1071 :group 'gnus-article-treat
1072 :link '(custom-manual "(gnus)Customizing Articles")
1073 :type gnus-article-treat-custom)
1075 (defcustom gnus-treat-strip-banner t
1076 "Strip banners from articles.
1077 The banner to be stripped is specified in the `banner' group parameter.
1078 Valid values are nil, t, `head', `last', an integer or a predicate.
1079 See Info node `(gnus)Customizing Articles' for details."
1080 :group 'gnus-article-treat
1081 :link '(custom-manual "(gnus)Customizing Articles")
1082 :type gnus-article-treat-custom)
1084 (defcustom gnus-treat-highlight-headers 'head
1085 "Highlight the headers.
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)
1091 (put 'gnus-treat-highlight-headers 'highlight t)
1093 (defcustom gnus-treat-highlight-citation t
1094 "Highlight cited text.
1095 Valid values are nil, t, `head', `last', an integer or a predicate.
1096 See Info node `(gnus)Customizing Articles' for details."
1097 :group 'gnus-article-treat
1098 :link '(custom-manual "(gnus)Customizing Articles")
1099 :type gnus-article-treat-custom)
1100 (put 'gnus-treat-highlight-citation 'highlight t)
1102 (defcustom gnus-treat-date-ut nil
1103 "Display the Date in UT (GMT).
1104 Valid values are nil, t, `head', `last', an integer or a predicate.
1105 See Info node `(gnus)Customizing Articles' for details."
1106 :group 'gnus-article-treat
1107 :link '(custom-manual "(gnus)Customizing Articles")
1108 :type gnus-article-treat-head-custom)
1110 (defcustom gnus-treat-date-local nil
1111 "Display the Date in the local timezone.
1112 Valid values are nil, t, `head', `last', an integer or a predicate.
1113 See Info node `(gnus)Customizing Articles' for details."
1114 :group 'gnus-article-treat
1115 :link '(custom-manual "(gnus)Customizing Articles")
1116 :type gnus-article-treat-head-custom)
1118 (defcustom gnus-treat-date-english nil
1119 "Display the Date in a format that can be read aloud in English.
1120 Valid values are nil, t, `head', `last', an integer or a predicate.
1121 See Info node `(gnus)Customizing Articles' for details."
1123 :group 'gnus-article-treat
1124 :link '(custom-manual "(gnus)Customizing Articles")
1125 :type gnus-article-treat-head-custom)
1127 (defcustom gnus-treat-date-lapsed nil
1128 "Display the Date header in a way that says how much time has elapsed.
1129 Valid values are nil, t, `head', `last', an integer or a predicate.
1130 See Info node `(gnus)Customizing Articles' for details."
1131 :group 'gnus-article-treat
1132 :link '(custom-manual "(gnus)Customizing Articles")
1133 :type gnus-article-treat-head-custom)
1135 (defcustom gnus-treat-date-original nil
1136 "Display the date in the original timezone.
1137 Valid values are nil, t, `head', `last', an integer or a predicate.
1138 See Info node `(gnus)Customizing Articles' for details."
1139 :group 'gnus-article-treat
1140 :link '(custom-manual "(gnus)Customizing Articles")
1141 :type gnus-article-treat-head-custom)
1143 (defcustom gnus-treat-date-iso8601 nil
1144 "Display the date in the ISO8601 format.
1145 Valid values are nil, t, `head', `last', an integer or a predicate.
1146 See Info node `(gnus)Customizing Articles' for details."
1148 :group 'gnus-article-treat
1149 :link '(custom-manual "(gnus)Customizing Articles")
1150 :type gnus-article-treat-head-custom)
1152 (defcustom gnus-treat-date-user-defined nil
1153 "Display the date in a user-defined format.
1154 The format is defined by the `gnus-article-time-format' variable.
1155 Valid values are nil, t, `head', `last', an integer or a predicate.
1156 See Info node `(gnus)Customizing Articles' for details."
1157 :group 'gnus-article-treat
1158 :link '(custom-manual "(gnus)Customizing Articles")
1159 :type gnus-article-treat-head-custom)
1161 (defcustom gnus-treat-strip-headers-in-body t
1162 "Strip the X-No-Archive header line from the beginning of the body.
1163 Valid values are nil, t, `head', `last', an integer or a predicate.
1164 See Info node `(gnus)Customizing Articles' for details."
1166 :group 'gnus-article-treat
1167 :link '(custom-manual "(gnus)Customizing Articles")
1168 :type gnus-article-treat-custom)
1170 (defcustom gnus-treat-strip-trailing-blank-lines nil
1171 "Strip trailing blank lines.
1172 Valid values are nil, t, `head', `last', an integer or a predicate.
1173 See Info node `(gnus)Customizing Articles' for details."
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1178 (defcustom gnus-treat-strip-leading-blank-lines nil
1179 "Strip leading blank lines.
1180 Valid values are nil, t, `head', `last', an integer or a predicate.
1181 See Info node `(gnus)Customizing Articles' for details."
1182 :group 'gnus-article-treat
1183 :link '(custom-manual "(gnus)Customizing Articles")
1184 :type gnus-article-treat-custom)
1186 (defcustom gnus-treat-strip-multiple-blank-lines nil
1187 "Strip multiple blank lines.
1188 Valid values are nil, t, `head', `last', an integer or a predicate.
1189 See Info node `(gnus)Customizing Articles' for details."
1190 :group 'gnus-article-treat
1191 :link '(custom-manual "(gnus)Customizing Articles")
1192 :type gnus-article-treat-custom)
1194 (defcustom gnus-treat-unfold-headers 'head
1195 "Unfold folded header lines.
1196 Valid values are nil, t, `head', `last', an integer or a predicate.
1197 See Info node `(gnus)Customizing Articles' for details."
1199 :group 'gnus-article-treat
1200 :link '(custom-manual "(gnus)Customizing Articles")
1201 :type gnus-article-treat-custom)
1203 (defcustom gnus-treat-fold-headers nil
1205 Valid values are nil, t, `head', `last', an integer or a predicate.
1206 See Info node `(gnus)Customizing Articles' for details."
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
1210 :type gnus-article-treat-custom)
1212 (defcustom gnus-treat-fold-newsgroups 'head
1213 "Fold the Newsgroups and Followup-To headers.
1214 Valid values are nil, t, `head', `last', an integer or a predicate.
1215 See Info node `(gnus)Customizing Articles' for details."
1217 :group 'gnus-article-treat
1218 :link '(custom-manual "(gnus)Customizing Articles")
1219 :type gnus-article-treat-custom)
1221 (defcustom gnus-treat-overstrike t
1222 "Treat overstrike highlighting.
1223 Valid values are nil, t, `head', `last', an integer or a predicate.
1224 See Info node `(gnus)Customizing Articles' for details."
1225 :group 'gnus-article-treat
1226 :link '(custom-manual "(gnus)Customizing Articles")
1227 :type gnus-article-treat-custom)
1228 (put 'gnus-treat-overstrike 'highlight t)
1230 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1231 "Treat ANSI SGR control sequences.
1232 Valid values are nil, t, `head', `last', an integer or a predicate.
1233 See Info node `(gnus)Customizing Articles' for details."
1234 :group 'gnus-article-treat
1235 :link '(custom-manual "(gnus)Customizing Articles")
1236 :type gnus-article-treat-custom)
1238 (make-obsolete-variable 'gnus-treat-display-xface
1239 'gnus-treat-display-x-face)
1241 (defcustom gnus-treat-display-x-face
1242 (and (not noninteractive)
1243 (or (and (fboundp 'image-type-available-p)
1244 (image-type-available-p 'xbm)
1245 (string-match "^0x" (shell-command-to-string "uncompface"))
1246 (executable-find "icontopbm"))
1247 (and (featurep 'xemacs)
1250 "Display X-Face headers.
1251 Valid values are nil, t, `head', `last', an integer or a predicate.
1252 See Info node `(gnus)Customizing Articles' and Info node
1253 `(gnus)X-Face' for details."
1254 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :link '(custom-manual "(gnus)X-Face")
1258 :type gnus-article-treat-head-custom
1259 :set (lambda (symbol value)
1262 (cond ((or (boundp symbol) (get symbol 'saved-value))
1264 ((boundp 'gnus-treat-display-xface)
1266 ** gnus-treat-display-xface is an obsolete variable;\
1267 use gnus-treat-display-x-face instead")
1268 (default-value 'gnus-treat-display-xface))
1269 ((get 'gnus-treat-display-xface 'saved-value)
1271 ** gnus-treat-display-xface is an obsolete variable;\
1272 use gnus-treat-display-x-face instead")
1273 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1276 (put 'gnus-treat-display-x-face 'highlight t)
1278 (defcustom gnus-treat-display-face
1279 (and (not noninteractive)
1280 (or (and (fboundp 'image-type-available-p)
1281 (image-type-available-p 'png))
1282 (and (featurep 'xemacs)
1285 "Display Face headers.
1286 Valid values are nil, t, `head', `last', an integer or a predicate.
1287 See Info node `(gnus)Customizing Articles' and Info node
1288 `(gnus)X-Face' for details."
1289 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :link '(custom-manual "(gnus)X-Face")
1293 :type gnus-article-treat-head-custom)
1294 (put 'gnus-treat-display-face 'highlight t)
1296 (defcustom gnus-treat-display-smileys
1297 (if (or (and (featurep 'xemacs)
1299 (and (fboundp 'image-type-available-p)
1300 (image-type-available-p 'pbm)))
1303 Valid values are nil, t, `head', `last', an integer or a predicate.
1304 See Info node `(gnus)Customizing Articles' and Info node
1305 `(gnus)Smileys' for details."
1306 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :link '(custom-manual "(gnus)Smileys")
1310 :type gnus-article-treat-custom)
1311 (put 'gnus-treat-display-smileys 'highlight t)
1313 (defcustom gnus-treat-from-picon
1314 (if (and (gnus-image-type-available-p 'xpm)
1315 (gnus-picons-installed-p))
1317 "Display picons in the From header.
1318 Valid values are nil, t, `head', `last', an integer or a predicate.
1319 See Info node `(gnus)Customizing Articles' and Info node
1320 `(gnus)Picons' for details."
1322 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :link '(custom-manual "(gnus)Picons")
1326 :type gnus-article-treat-head-custom)
1327 (put 'gnus-treat-from-picon 'highlight t)
1329 (defcustom gnus-treat-mail-picon
1330 (if (and (gnus-image-type-available-p 'xpm)
1331 (gnus-picons-installed-p))
1333 "Display picons in To and Cc headers.
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."
1338 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :link '(custom-manual "(gnus)Picons")
1342 :type gnus-article-treat-head-custom)
1343 (put 'gnus-treat-mail-picon 'highlight t)
1345 (defcustom gnus-treat-newsgroups-picon
1346 (if (and (gnus-image-type-available-p 'xpm)
1347 (gnus-picons-installed-p))
1349 "Display picons in the Newsgroups and Followup-To headers.
1350 Valid values are nil, t, `head', `last', an integer or a predicate.
1351 See Info node `(gnus)Customizing Articles' and Info node
1352 `(gnus)Picons' for details."
1354 :group 'gnus-article-treat
1356 :link '(custom-manual "(gnus)Customizing Articles")
1357 :link '(custom-manual "(gnus)Picons")
1358 :type gnus-article-treat-head-custom)
1359 (put 'gnus-treat-newsgroups-picon 'highlight t)
1361 (defcustom gnus-treat-body-boundary
1362 (if (and (eq window-system 'x)
1363 (or gnus-treat-newsgroups-picon
1364 gnus-treat-mail-picon
1365 gnus-treat-from-picon))
1367 "Draw a boundary at the end of the headers.
1368 Valid values are nil and `head'.
1369 See Info node `(gnus)Customizing Articles' for details."
1371 :group 'gnus-article-treat
1372 :link '(custom-manual "(gnus)Customizing Articles")
1373 :type gnus-article-treat-head-custom)
1375 (defcustom gnus-treat-capitalize-sentences nil
1376 "Capitalize sentence-starting words.
1377 Valid values are nil, t, `head', `last', an integer or a predicate.
1378 See Info node `(gnus)Customizing Articles' for details."
1380 :group 'gnus-article-treat
1381 :link '(custom-manual "(gnus)Customizing Articles")
1382 :type gnus-article-treat-custom)
1384 (defcustom gnus-treat-wash-html nil
1386 Valid values are nil, t, `head', `last', an integer or a predicate.
1387 See Info node `(gnus)Customizing Articles' for details."
1389 :group 'gnus-article-treat
1390 :link '(custom-manual "(gnus)Customizing Articles")
1391 :type gnus-article-treat-custom)
1393 (defcustom gnus-treat-fill-long-lines nil
1395 Valid values are nil, t, `head', `last', an integer or a predicate.
1396 See Info node `(gnus)Customizing Articles' for details."
1397 :group 'gnus-article-treat
1398 :link '(custom-manual "(gnus)Customizing Articles")
1399 :type gnus-article-treat-custom)
1401 (defcustom gnus-treat-play-sounds nil
1403 Valid values are nil, t, `head', `last', an integer or a predicate.
1404 See Info node `(gnus)Customizing Articles' for details."
1406 :group 'gnus-article-treat
1407 :link '(custom-manual "(gnus)Customizing Articles")
1408 :type gnus-article-treat-custom)
1410 (defcustom gnus-treat-translate nil
1411 "Translate articles from one language to another.
1412 Valid values are nil, t, `head', `last', an integer or a predicate.
1413 See Info node `(gnus)Customizing Articles' for details."
1415 :group 'gnus-article-treat
1416 :link '(custom-manual "(gnus)Customizing Articles")
1417 :type gnus-article-treat-custom)
1419 (defcustom gnus-treat-x-pgp-sig nil
1421 To automatically treat X-PGP-Sig, set it to head.
1422 Valid values are nil, t, `head', `last', an integer or a predicate.
1423 See Info node `(gnus)Customizing Articles' for details."
1425 :group 'gnus-article-treat
1426 :group 'mime-security
1427 :link '(custom-manual "(gnus)Customizing Articles")
1428 :type gnus-article-treat-custom)
1430 (defvar gnus-article-encrypt-protocol-alist
1431 '(("PGP" . mml2015-self-encrypt)))
1433 ;; Set to nil if more than one protocol added to
1434 ;; gnus-article-encrypt-protocol-alist.
1435 (defcustom gnus-article-encrypt-protocol "PGP"
1436 "The protocol used for encrypt articles.
1437 It is a string, such as \"PGP\". If nil, ask user."
1440 :group 'mime-security)
1442 (defvar gnus-article-wash-function nil
1443 "Function used for converting HTML into text.")
1445 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1446 (mm-coding-system-p 'utf-8)
1447 (executable-find idna-program))
1448 "Whether IDNA decoding of headers is used when viewing messages.
1449 This requires GNU Libidn, and by default only enabled if it is found."
1451 :group 'gnus-article-headers
1454 (defcustom gnus-article-over-scroll nil
1455 "If non-nil, allow scrolling the article buffer even when there no more text."
1457 :group 'gnus-article
1460 ;;; Internal variables
1462 (defvar gnus-english-month-names
1463 '("January" "February" "March" "April" "May" "June" "July" "August"
1464 "September" "October" "November" "December"))
1466 (defvar gnus-button-regexp nil)
1467 (defvar gnus-button-marker-list nil)
1468 ;; Regexp matching any of the regexps from `gnus-button-alist'.
1470 (defvar gnus-button-last nil)
1471 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
1473 (defvar article-goto-body-goes-to-point-min-p nil)
1474 (defvar gnus-article-wash-types nil)
1475 (defvar gnus-article-emphasis-alist nil)
1476 (defvar gnus-article-image-alist nil)
1478 (defvar gnus-article-mime-handle-alist-1 nil)
1479 (defvar gnus-treatment-function-alist
1480 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1481 (gnus-treat-strip-banner gnus-article-strip-banner)
1482 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1483 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1484 (gnus-treat-buttonize gnus-article-add-buttons)
1485 (gnus-treat-fill-article gnus-article-fill-cited-article)
1486 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1487 (gnus-treat-strip-cr gnus-article-remove-cr)
1488 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1489 (gnus-treat-date-ut gnus-article-date-ut)
1490 (gnus-treat-date-local gnus-article-date-local)
1491 (gnus-treat-date-english gnus-article-date-english)
1492 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1493 (gnus-treat-date-original gnus-article-date-original)
1494 (gnus-treat-date-user-defined gnus-article-date-user)
1495 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1496 (gnus-treat-display-x-face gnus-article-display-x-face)
1497 (gnus-treat-display-face gnus-article-display-face)
1498 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1499 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1500 (gnus-treat-hide-signature gnus-article-hide-signature)
1501 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1502 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1503 (gnus-treat-strip-pem gnus-article-hide-pem)
1504 (gnus-treat-from-picon gnus-treat-from-picon)
1505 (gnus-treat-mail-picon gnus-treat-mail-picon)
1506 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1507 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1508 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1509 (gnus-treat-strip-trailing-blank-lines
1510 gnus-article-remove-trailing-blank-lines)
1511 (gnus-treat-strip-leading-blank-lines
1512 gnus-article-strip-leading-blank-lines)
1513 (gnus-treat-strip-multiple-blank-lines
1514 gnus-article-strip-multiple-blank-lines)
1515 (gnus-treat-overstrike gnus-article-treat-overstrike)
1516 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1517 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1518 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1519 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1520 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1521 (gnus-treat-display-smileys gnus-treat-smiley)
1522 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1523 (gnus-treat-wash-html gnus-article-wash-html)
1524 (gnus-treat-emphasize gnus-article-emphasize)
1525 (gnus-treat-hide-citation gnus-article-hide-citation)
1526 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1527 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1528 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1529 (gnus-treat-play-sounds gnus-earcon-display)))
1531 (defvar gnus-article-mime-handle-alist nil)
1532 (defvar article-lapsed-timer nil)
1533 (defvar gnus-article-current-summary nil)
1535 (defvar gnus-article-mode-syntax-table
1536 (let ((table (copy-syntax-table text-mode-syntax-table)))
1537 ;; This causes the citation match run O(2^n).
1538 ;; (modify-syntax-entry ?- "w" table)
1539 (modify-syntax-entry ?> ")<" table)
1540 (modify-syntax-entry ?< "(>" table)
1541 ;; make M-. in article buffers work for `foo' strings
1542 (modify-syntax-entry ?' " " table)
1543 (modify-syntax-entry ?` " " table)
1545 "Syntax table used in article mode buffers.
1546 Initialized from `text-mode-syntax-table.")
1548 (defvar gnus-save-article-buffer nil)
1550 (defvar gnus-article-mode-line-format-alist
1551 (nconc '((?w (gnus-article-wash-status) ?s)
1552 (?m (gnus-article-mime-part-status) ?s))
1553 gnus-summary-mode-line-format-alist))
1555 (defvar gnus-number-of-articles-to-be-saved nil)
1557 (defvar gnus-inhibit-hiding nil)
1559 (defvar gnus-article-edit-mode nil)
1561 ;;; Macros for dealing with the article buffer.
1563 (defmacro gnus-with-article-headers (&rest forms)
1565 (set-buffer gnus-article-buffer)
1567 (let ((inhibit-read-only t)
1568 (inhibit-point-motion-hooks t)
1569 (case-fold-search t))
1570 (article-narrow-to-head)
1573 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1574 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1576 (defmacro gnus-with-article-buffer (&rest forms)
1578 (set-buffer gnus-article-buffer)
1579 (let ((inhibit-read-only t))
1582 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1583 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1585 (defun gnus-article-goto-header (header)
1586 "Go to HEADER, which is a regular expression."
1587 (re-search-forward (concat "^\\(" header "\\):") nil t))
1589 (defsubst gnus-article-hide-text (b e props)
1590 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1591 (gnus-add-text-properties-when 'article-type nil b e props)
1592 (when (memq 'intangible props)
1594 (max (1- b) (point-min))
1595 b 'intangible (cddr (memq 'intangible props)))))
1597 (defsubst gnus-article-unhide-text (b e)
1598 "Remove hidden text properties from region between B and E."
1599 (remove-text-properties b e gnus-hidden-properties)
1600 (when (memq 'intangible gnus-hidden-properties)
1601 (put-text-property (max (1- b) (point-min))
1602 b 'intangible nil)))
1604 (defun gnus-article-hide-text-type (b e type)
1605 "Hide text of TYPE between B and E."
1606 (gnus-add-wash-type type)
1607 (gnus-article-hide-text
1608 b e (cons 'article-type (cons type gnus-hidden-properties))))
1610 (defun gnus-article-unhide-text-type (b e type)
1611 "Unhide text of TYPE between B and E."
1612 (gnus-delete-wash-type type)
1613 (remove-text-properties
1614 b e (cons 'article-type (cons type gnus-hidden-properties)))
1615 (when (memq 'intangible gnus-hidden-properties)
1616 (put-text-property (max (1- b) (point-min))
1617 b 'intangible nil)))
1619 (defun gnus-article-hide-text-of-type (type)
1620 "Hide text of TYPE in the current buffer."
1622 (let ((b (point-min))
1624 (while (setq b (text-property-any b e 'article-type type))
1625 (add-text-properties b (incf b) gnus-hidden-properties)))))
1627 (defun gnus-article-delete-text-of-type (type)
1628 "Delete text of TYPE in the current buffer."
1630 (let ((b (point-min)))
1631 (while (setq b (text-property-any b (point-max) 'article-type type))
1633 b (or (text-property-not-all b (point-max) 'article-type type)
1636 (defun gnus-article-delete-invisible-text ()
1637 "Delete all invisible text in the current buffer."
1639 (let ((b (point-min)))
1640 (while (setq b (text-property-any b (point-max) 'invisible t))
1642 b (or (text-property-not-all b (point-max) 'invisible t)
1645 (defun gnus-article-text-type-exists-p (type)
1646 "Say whether any text of type TYPE exists in the buffer."
1647 (text-property-any (point-min) (point-max) 'article-type type))
1649 (defsubst gnus-article-header-rank ()
1650 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1651 (let ((list gnus-sorted-header-list)
1654 (if (looking-at (car list))
1656 (setq list (cdr list))
1660 (defun article-hide-headers (&optional arg delete)
1661 "Hide unwanted headers and possibly sort them as well."
1663 ;; This function might be inhibited.
1664 (unless gnus-inhibit-hiding
1665 (let ((inhibit-read-only nil)
1666 (case-fold-search t)
1667 (max (1+ (length gnus-sorted-header-list)))
1668 (inhibit-point-motion-hooks t)
1669 (cur (current-buffer))
1670 ignored visible beg)
1672 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1673 ;; group parameters, so we should go to the summary buffer.
1676 (progn (set-buffer gnus-summary-buffer) t)
1678 (setq ignored (when (not gnus-visible-headers)
1679 (cond ((stringp gnus-ignored-headers)
1680 gnus-ignored-headers)
1681 ((listp gnus-ignored-headers)
1682 (mapconcat 'identity
1683 gnus-ignored-headers
1685 visible (cond ((stringp gnus-visible-headers)
1686 gnus-visible-headers)
1687 ((and gnus-visible-headers
1688 (listp gnus-visible-headers))
1689 (mapconcat 'identity
1690 gnus-visible-headers
1694 ;; First we narrow to just the headers.
1695 (article-narrow-to-head)
1696 ;; Hide any "From " lines at the beginning of (mail) articles.
1697 (while (looking-at "From ")
1700 (delete-region (point-min) (point)))
1701 ;; Then treat the rest of the header lines.
1702 ;; Then we use the two regular expressions
1703 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1704 ;; select which header lines is to remain visible in the
1706 (while (re-search-forward "^[^ \t:]*:" nil t)
1708 ;; Mark the rank of the header.
1710 (point) (1+ (point)) 'message-rank
1711 (if (or (and visible (looking-at visible))
1713 (not (looking-at ignored))))
1714 (gnus-article-header-rank)
1717 (message-sort-headers-1)
1718 (when (setq beg (text-property-any
1719 (point-min) (point-max) 'message-rank (+ 2 max)))
1720 ;; We delete the unwanted headers.
1721 (gnus-add-wash-type 'headers)
1722 (add-text-properties (point-min) (+ 5 (point-min))
1723 '(article-type headers dummy-invisible t))
1724 (delete-region beg (point-max))))))))
1726 (defun article-hide-boring-headers (&optional arg)
1727 "Toggle hiding of headers that aren't very interesting.
1728 If given a negative prefix, always show; if given a positive prefix,
1730 (interactive (gnus-article-hidden-arg))
1731 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1732 (not gnus-show-all-headers))
1735 (let ((inhibit-read-only t)
1736 (inhibit-point-motion-hooks t))
1737 (article-narrow-to-head)
1738 (dolist (elem gnus-boring-article-headers)
1739 (goto-char (point-min))
1741 ;; Hide empty headers.
1743 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1745 (gnus-article-hide-text-type
1749 (if (re-search-forward "^[^ \t]" nil t)
1753 ;; Hide boring Newsgroups header.
1754 ((eq elem 'newsgroups)
1755 (when (gnus-string-equal
1756 (gnus-fetch-field "newsgroups")
1757 (gnus-group-real-name
1758 (if (boundp 'gnus-newsgroup-name)
1761 (gnus-article-hide-header "newsgroups")))
1762 ((eq elem 'to-address)
1763 (let ((to (message-fetch-field "to"))
1765 (gnus-parameter-to-address
1766 (if (boundp 'gnus-newsgroup-name)
1767 gnus-newsgroup-name ""))))
1768 (when (and to to-address
1771 ;; only one address in To
1772 (nth 1 (mail-extract-address-components to))
1774 (gnus-article-hide-header "to"))))
1776 (let ((to (message-fetch-field "to"))
1778 (gnus-parameter-to-list
1779 (if (boundp 'gnus-newsgroup-name)
1780 gnus-newsgroup-name ""))))
1781 (when (and to to-list
1784 ;; only one address in To
1785 (nth 1 (mail-extract-address-components to))
1787 (gnus-article-hide-header "to"))))
1789 (let ((cc (message-fetch-field "cc"))
1791 (gnus-parameter-to-list
1792 (if (boundp 'gnus-newsgroup-name)
1793 gnus-newsgroup-name ""))))
1794 (when (and cc to-list
1797 ;; only one address in CC
1798 (nth 1 (mail-extract-address-components cc))
1800 (gnus-article-hide-header "cc"))))
1801 ((eq elem 'followup-to)
1802 (when (gnus-string-equal
1803 (message-fetch-field "followup-to")
1804 (message-fetch-field "newsgroups"))
1805 (gnus-article-hide-header "followup-to")))
1806 ((eq elem 'reply-to)
1807 (if (gnus-group-find-parameter
1808 gnus-newsgroup-name 'broken-reply-to)
1809 (gnus-article-hide-header "reply-to")
1810 (let ((from (message-fetch-field "from"))
1811 (reply-to (message-fetch-field "reply-to")))
1818 (lambda (x) (downcase (cadr x)))
1819 (mail-extract-address-components from t))
1822 (lambda (x) (downcase (cadr x)))
1823 (mail-extract-address-components reply-to t))
1825 (gnus-article-hide-header "reply-to")))))
1827 (let ((date (message-fetch-field "date")))
1829 (< (days-between (current-time-string) date)
1831 (gnus-article-hide-header "date"))))
1833 (let ((to (message-fetch-field "to"))
1834 (cc (message-fetch-field "cc")))
1835 (when (> (length to) 1024)
1836 (gnus-article-hide-header "to"))
1837 (when (> (length cc) 1024)
1838 (gnus-article-hide-header "cc"))))
1842 (goto-char (point-min))
1843 (while (re-search-forward "^to:" nil t)
1844 (setq to-count (1+ to-count)))
1845 (when (> to-count 1)
1846 (while (> to-count 0)
1847 (goto-char (point-min))
1849 (re-search-forward "^to:" nil nil to-count)
1851 (narrow-to-region (point) (point-max))
1852 (gnus-article-hide-header "to"))
1853 (setq to-count (1- to-count))))
1854 (goto-char (point-min))
1855 (while (re-search-forward "^cc:" nil t)
1856 (setq cc-count (1+ cc-count)))
1857 (when (> cc-count 1)
1858 (while (> cc-count 0)
1859 (goto-char (point-min))
1861 (re-search-forward "^cc:" nil nil cc-count)
1863 (narrow-to-region (point) (point-max))
1864 (gnus-article-hide-header "cc"))
1865 (setq cc-count (1- cc-count)))))))))))))
1867 (defun gnus-article-hide-header (header)
1869 (goto-char (point-min))
1870 (when (re-search-forward (concat "^" header ":") nil t)
1871 (gnus-article-hide-text-type
1875 (if (re-search-forward "^[^ \t]" nil t)
1880 (defvar gnus-article-normalized-header-length 40
1881 "Length of normalized headers.")
1883 (defun article-normalize-headers ()
1884 "Make all header lines 40 characters long."
1886 (let ((inhibit-read-only t)
1890 (article-narrow-to-head)
1893 ((< (setq column (- (point-at-eol) (point)))
1894 gnus-article-normalized-header-length)
1896 (insert (make-string
1897 (- gnus-article-normalized-header-length column)
1899 ((> column gnus-article-normalized-header-length)
1900 (gnus-put-text-property
1902 (forward-char gnus-article-normalized-header-length)
1909 (forward-line 1))))))
1911 (defun article-treat-dumbquotes ()
1912 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
1913 Note that this function guesses whether a character is a sm*rtq**t* or
1914 not, so it should only be used interactively.
1916 Sm*rtq**t*s are M****s***'s unilateral extension to the
1917 iso-8859-1 character map in an attempt to provide more quoting
1918 characters. If you see something like \\222 or \\264 where
1919 you're expecting some kind of apostrophe or quotation mark, then
1922 (article-translate-strings gnus-article-dumbquotes-map))
1924 (defun article-translate-characters (from to)
1925 "Translate all characters in the body of the article according to FROM and TO.
1926 FROM is a string of characters to translate from; to is a string of
1927 characters to translate to."
1929 (when (article-goto-body)
1930 (let ((inhibit-read-only t)
1931 (x (make-string 225 ?x))
1933 (while (< (incf i) (length x))
1936 (while (< i (length from))
1937 (aset x (aref from i) (aref to i))
1939 (translate-region (point) (point-max) x)))))
1941 (defun article-translate-strings (map)
1942 "Translate all string in the body of the article according to MAP.
1943 MAP is an alist where the elements are on the form (\"from\" \"to\")."
1945 (when (article-goto-body)
1946 (let ((inhibit-read-only t))
1949 (while (search-forward (car elem) nil t)
1950 (replace-match (cadr elem)))))))))
1952 (defun article-treat-overstrike ()
1953 "Translate overstrikes into bold text."
1956 (when (article-goto-body)
1957 (let ((inhibit-read-only t))
1958 (while (search-forward "\b" nil t)
1959 (let ((next (char-after))
1960 (previous (char-after (- (point) 2))))
1961 ;; We do the boldification/underlining by hiding the
1962 ;; overstrikes and putting the proper text property
1966 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1967 (put-text-property (point) (1+ (point)) 'face 'bold))
1969 (gnus-article-hide-text-type
1970 (1- (point)) (1+ (point)) 'overstrike)
1972 (- (point) 2) (1- (point)) 'face 'underline))
1974 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
1976 (point) (1+ (point)) 'face 'underline)))))))))
1978 (defun article-treat-ansi-sequences ()
1979 "Translate ANSI SGR control sequences into overlays or extents."
1982 (when (article-goto-body)
1983 (let ((inhibit-read-only t))
1984 (ansi-color-apply-on-region (point) (point-max))))))
1986 (defun gnus-article-treat-unfold-headers ()
1987 "Unfold folded message headers.
1988 Only the headers that fit into the current window width will be
1991 (gnus-with-article-headers
1995 (mail-header-narrow-to-field)
1996 (let ((header (buffer-string)))
1999 (goto-char (point-min))
2000 (while (re-search-forward "\n[\t ]" nil t)
2001 (replace-match " " t t)))
2002 (setq length (- (point-max) (point-min) 1)))
2003 (when (< length (window-width))
2004 (while (re-search-forward "\n[\t ]" nil t)
2005 (replace-match " " t t)))
2006 (goto-char (point-max)))))))
2008 (defun gnus-article-treat-fold-headers ()
2009 "Fold message headers."
2011 (gnus-with-article-headers
2014 (mail-header-narrow-to-field)
2015 (mail-header-fold-field)
2016 (goto-char (point-max))))))
2018 (defun gnus-treat-smiley ()
2019 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2021 (gnus-with-article-buffer
2022 (if (memq 'smiley gnus-article-wash-types)
2023 (gnus-delete-images 'smiley)
2025 (let ((images (smiley-region (point) (point-max))))
2027 (gnus-add-wash-type 'smiley)
2028 (dolist (image images)
2029 (gnus-add-image 'smiley image)))))))
2031 (defun gnus-article-remove-images ()
2032 "Remove all images from the article buffer."
2034 (gnus-with-article-buffer
2035 (dolist (elem gnus-article-image-alist)
2036 (gnus-delete-images (car elem)))))
2038 (defun gnus-article-treat-fold-newsgroups ()
2039 "Unfold folded message headers.
2040 Only the headers that fit into the current window width will be
2043 (gnus-with-article-headers
2044 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2046 (mail-header-narrow-to-field)
2047 (while (re-search-forward ", *" nil t)
2048 (replace-match ", " t t))
2049 (mail-header-fold-field)
2050 (goto-char (point-max))))))
2052 (defun gnus-article-treat-body-boundary ()
2053 "Place a boundary line at the end of the headers."
2055 (when (and gnus-body-boundary-delimiter
2056 (> (length gnus-body-boundary-delimiter) 0))
2057 (gnus-with-article-headers
2058 (goto-char (point-max))
2059 (let ((start (point)))
2060 (insert "X-Boundary: ")
2061 (gnus-add-text-properties start (point) '(invisible t intangible t))
2063 (while (>= (1- (window-width)) (length str))
2064 (setq str (concat str gnus-body-boundary-delimiter)))
2065 (substring str 0 (1- (window-width))))
2067 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2069 (defun article-fill-long-lines ()
2070 "Fill lines that are wider than the window width."
2073 (let ((inhibit-read-only t)
2074 (width (window-width (get-buffer-window (current-buffer)))))
2077 (let ((adaptive-fill-mode nil)) ;Why? -sm
2080 (when (>= (current-column) (min fill-column width))
2081 (narrow-to-region (min (1+ (point)) (point-max))
2083 (let ((goback (point-marker)))
2084 (fill-paragraph nil)
2085 (goto-char (marker-position goback)))
2087 (forward-line 1)))))))
2089 (defun article-capitalize-sentences ()
2090 "Capitalize the first word in each sentence."
2093 (let ((inhibit-read-only t)
2094 (paragraph-start "^[\n\^L]"))
2098 (forward-sentence)))))
2100 (defun article-remove-cr ()
2101 "Remove trailing CRs and then translate remaining CRs into LFs."
2104 (let ((inhibit-read-only t))
2105 (goto-char (point-min))
2106 (while (re-search-forward "\r+$" nil t)
2107 (replace-match "" t t))
2108 (goto-char (point-min))
2109 (while (search-forward "\r" nil t)
2110 (replace-match "\n" t t)))))
2112 (defun article-remove-trailing-blank-lines ()
2113 "Remove all trailing blank lines from the article."
2116 (let ((inhibit-read-only t))
2117 (goto-char (point-max))
2121 (while (and (not (bobp))
2122 (looking-at "^[ \t]*$")
2123 (not (gnus-annotation-in-region-p
2124 (point) (point-at-eol))))
2130 (defvar gnus-face-properties-alist))
2132 (defun article-display-face ()
2133 "Display any Face headers in the header."
2135 (let ((wash-face-p buffer-read-only))
2136 (gnus-with-article-headers
2137 ;; When displaying parts, this function can be called several times on
2138 ;; the same article, without any intended toggle semantic (as typing `W
2139 ;; D d' would have). So face deletion must occur only when we come from
2140 ;; an interactive command, that is when the *Article* buffer is
2142 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2143 (gnus-delete-images 'face)
2146 (when (and wash-face-p
2148 (goto-char (point-min))
2149 (not (re-search-forward "^Face:[\t ]*" nil t)))
2150 (gnus-buffer-live-p gnus-original-article-buffer))
2151 (set-buffer gnus-original-article-buffer))
2153 (mail-narrow-to-head)
2154 (while (gnus-article-goto-header "Face")
2155 (setq faces (nconc faces (list (mail-header-field-value)))))))
2156 (dolist (face faces)
2157 (let ((png (gnus-convert-face-to-png face))
2161 (apply 'gnus-create-image png 'png t
2162 (cdr (assq 'png gnus-face-properties-alist))))
2163 (gnus-article-goto-header "from")
2165 (insert "From: [no `from' set]\n")
2167 (gnus-add-wash-type 'face)
2168 (gnus-add-image 'face image)
2169 (gnus-put-image image nil 'face))))))
2172 (defun article-display-x-face (&optional force)
2173 "Look for an X-Face header and display it if present."
2174 (interactive (list 'force))
2175 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2176 (gnus-with-article-headers
2177 ;; Delete the old process, if any.
2178 (when (process-status "article-x-face")
2179 (delete-process "article-x-face"))
2180 ;; See the comment in `article-display-face'.
2181 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2182 ;; We have already displayed X-Faces, so we remove them
2184 (gnus-delete-images 'xface)
2186 (let (x-faces from face)
2188 (when (and wash-face-p
2190 (goto-char (point-min))
2191 (not (re-search-forward
2192 "^X-Face\\(-[0-9]+\\)?:[\t ]*" nil t)))
2193 (gnus-buffer-live-p gnus-original-article-buffer))
2194 ;; If type `W f', use gnus-original-article-buffer,
2195 ;; otherwise use the current buffer because displaying
2196 ;; RFC822 parts calls this function too.
2197 (set-buffer gnus-original-article-buffer))
2199 (mail-narrow-to-head)
2200 (while (gnus-article-goto-header "X-Face")
2201 (push (mail-header-field-value) x-faces))
2202 (setq from (message-fetch-field "from"))))
2203 ;; Sending multiple EOFs to xv doesn't work, so we only do a
2204 ;; single external face.
2205 (when (stringp gnus-article-x-face-command)
2206 (setq x-faces (list (car x-faces))))
2207 (while (and (setq face (pop x-faces))
2208 gnus-article-x-face-command
2210 ;; Check whether this face is censored.
2211 (not gnus-article-x-face-too-ugly)
2212 (and gnus-article-x-face-too-ugly from
2213 (not (string-match gnus-article-x-face-too-ugly
2215 ;; We display the face.
2216 (cond ((stringp gnus-article-x-face-command)
2217 ;; The command is a string, so we interpret the command
2218 ;; as a, well, command, and fork it off.
2219 (let ((process-connection-type nil))
2220 (process-kill-without-query
2222 "article-x-face" nil shell-file-name
2223 shell-command-switch gnus-article-x-face-command))
2226 (process-send-region "article-x-face"
2227 (point-min) (point-max)))
2228 (process-send-eof "article-x-face")))
2229 ((functionp gnus-article-x-face-command)
2230 ;; The command is a lisp function, so we call it.
2231 (funcall gnus-article-x-face-command face))
2233 (error "%s is not a function"
2234 gnus-article-x-face-command)))))))))
2236 (defun article-decode-mime-words ()
2237 "Decode all MIME-encoded words in the article."
2239 (gnus-with-article-buffer
2240 (let ((inhibit-point-motion-hooks t)
2241 (mail-parse-charset gnus-newsgroup-charset)
2242 (mail-parse-ignored-charsets
2243 (with-current-buffer gnus-summary-buffer
2244 gnus-newsgroup-ignored-charsets)))
2245 (mail-decode-encoded-word-region (point-min) (point-max)))))
2247 (defun article-decode-charset (&optional prompt)
2248 "Decode charset-encoded text in the article.
2249 If PROMPT (the prefix), prompt for a coding system to use."
2251 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2252 (inhibit-read-only t)
2253 (mail-parse-charset gnus-newsgroup-charset)
2254 (mail-parse-ignored-charsets
2255 (save-excursion (condition-case nil
2256 (set-buffer gnus-summary-buffer)
2258 gnus-newsgroup-ignored-charsets))
2259 ct cte ctl charset format)
2262 (article-narrow-to-head)
2263 (setq ct (message-fetch-field "Content-Type" t)
2264 cte (message-fetch-field "Content-Transfer-Encoding" t)
2265 ctl (and ct (ignore-errors
2266 (mail-header-parse-content-type ct)))
2269 (mm-read-coding-system "Charset to decode: "))
2271 (mail-content-type-get ctl 'charset)))
2272 format (and ctl (mail-content-type-get ctl 'format)))
2274 (setq cte (mail-header-strip cte)))
2275 (if (and ctl (not (string-match "/" (car ctl))))
2277 (goto-char (point-max)))
2280 (narrow-to-region (point) (point-max))
2281 (when (and (eq mail-parse-charset 'gnus-decoded)
2282 (eq (mm-body-7-or-8) '8bit))
2283 ;; The text code could have been decoded.
2284 (setq charset mail-parse-charset))
2285 (when (and (or (not ctl)
2286 (equal (car ctl) "text/plain"))
2287 (not format)) ;; article with format will decode later.
2289 charset (and cte (intern (downcase
2290 (gnus-strip-whitespace cte))))
2293 (defun article-decode-encoded-words ()
2294 "Remove encoded-word encoding from headers."
2295 (let ((inhibit-point-motion-hooks t)
2296 (mail-parse-charset gnus-newsgroup-charset)
2297 (mail-parse-ignored-charsets
2298 (save-excursion (condition-case nil
2299 (set-buffer gnus-summary-buffer)
2301 gnus-newsgroup-ignored-charsets))
2302 (inhibit-read-only t))
2304 (article-narrow-to-head)
2305 (funcall gnus-decode-header-function (point-min) (point-max)))))
2307 (defun article-decode-group-name ()
2308 "Decode group names in `Newsgroups:'."
2309 (let ((inhibit-point-motion-hooks t)
2310 (inhibit-read-only t)
2311 (method (gnus-find-method-for-group gnus-newsgroup-name)))
2312 (when (and (or gnus-group-name-charset-method-alist
2313 gnus-group-name-charset-group-alist)
2314 (gnus-buffer-live-p gnus-original-article-buffer))
2316 (article-narrow-to-head)
2317 (with-current-buffer gnus-original-article-buffer
2318 (goto-char (point-min)))
2319 (while (re-search-forward
2320 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2321 (replace-match (save-match-data
2322 (gnus-decode-newsgroups
2323 ;; XXX how to use data in article buffer?
2324 (with-current-buffer gnus-original-article-buffer
2326 "^Newsgroups:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2329 gnus-newsgroup-name method))
2331 (goto-char (point-min))
2332 (with-current-buffer gnus-original-article-buffer
2333 (goto-char (point-min)))
2334 (while (re-search-forward
2335 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]" nil t)
2336 (replace-match (save-match-data
2337 (gnus-decode-newsgroups
2338 ;; XXX how to use data in article buffer?
2339 (with-current-buffer gnus-original-article-buffer
2341 "^Followup-To:\\(\\(.\\|\n[\t ]\\)*\\)\n[^\t ]"
2344 gnus-newsgroup-name method))
2347 (autoload 'idna-to-unicode "idna")
2349 (defun article-decode-idna-rhs ()
2350 "Decode IDNA strings in RHS in From:, To: and Cc: headers in current buffer."
2353 (let ((inhibit-point-motion-hooks t)
2354 (inhibit-read-only t))
2355 (article-narrow-to-head)
2356 (goto-char (point-min))
2357 (while (re-search-forward "@.*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2359 (when (save-match-data
2360 (and (setq ace (match-string 1))
2362 (and (re-search-backward "^[^ \t]" nil t)
2363 (looking-at "From\\|To\\|Cc")))
2364 (setq unicode (idna-to-unicode ace))))
2365 (unless (string= ace unicode)
2366 (replace-match unicode nil nil nil 1)))))))))
2368 (defun article-de-quoted-unreadable (&optional force read-charset)
2369 "Translate a quoted-printable-encoded article.
2370 If FORCE, decode the article whether it is marked as quoted-printable
2372 If READ-CHARSET, ask for a coding system."
2373 (interactive (list 'force current-prefix-arg))
2375 (let ((inhibit-read-only t) type charset)
2376 (if (gnus-buffer-live-p gnus-original-article-buffer)
2377 (with-current-buffer gnus-original-article-buffer
2379 (gnus-fetch-field "content-transfer-encoding"))
2380 (let* ((ct (gnus-fetch-field "content-type"))
2383 (mail-header-parse-content-type ct)))))
2384 (setq charset (and ctl
2385 (mail-content-type-get ctl 'charset)))
2386 (if (stringp charset)
2387 (setq charset (intern (downcase charset)))))))
2389 (setq charset (mm-read-coding-system "Charset: " charset)))
2391 (setq charset gnus-newsgroup-charset))
2393 (and type (let ((case-fold-search t))
2394 (string-match "quoted-printable" type))))
2396 (quoted-printable-decode-region
2397 (point) (point-max) (mm-charset-to-coding-system charset))))))
2399 (defun article-de-base64-unreadable (&optional force read-charset)
2400 "Translate a base64 article.
2401 If FORCE, decode the article whether it is marked as base64 not.
2402 If READ-CHARSET, ask for a coding system."
2403 (interactive (list 'force current-prefix-arg))
2405 (let ((inhibit-read-only t) type charset)
2406 (if (gnus-buffer-live-p gnus-original-article-buffer)
2407 (with-current-buffer gnus-original-article-buffer
2409 (gnus-fetch-field "content-transfer-encoding"))
2410 (let* ((ct (gnus-fetch-field "content-type"))
2413 (mail-header-parse-content-type ct)))))
2414 (setq charset (and ctl
2415 (mail-content-type-get ctl 'charset)))
2416 (if (stringp charset)
2417 (setq charset (intern (downcase charset)))))))
2419 (setq charset (mm-read-coding-system "Charset: " charset)))
2421 (setq charset gnus-newsgroup-charset))
2423 (and type (let ((case-fold-search t))
2424 (string-match "base64" type))))
2427 (narrow-to-region (point) (point-max))
2428 (base64-decode-region (point-min) (point-max))
2429 (mm-decode-coding-region
2430 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2435 (defun article-decode-HZ ()
2436 "Translate a HZ-encoded article."
2440 (let ((inhibit-read-only t))
2441 (rfc1843-decode-region (point-min) (point-max)))))
2443 (defun article-unsplit-urls ()
2444 "Remove the newlines that some other mailers insert into URLs."
2447 (let ((inhibit-read-only t))
2448 (goto-char (point-min))
2449 (while (re-search-forward
2450 "^\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2451 (replace-match "\\1\\3" t)))
2452 (when (interactive-p)
2453 (gnus-treat-article nil))))
2456 (defun article-wash-html (&optional read-charset)
2457 "Format an HTML article.
2458 If READ-CHARSET, ask for a coding system."
2461 (let ((inhibit-read-only t)
2463 (when (gnus-buffer-live-p gnus-original-article-buffer)
2464 (with-current-buffer gnus-original-article-buffer
2465 (let* ((ct (gnus-fetch-field "content-type"))
2468 (mail-header-parse-content-type ct)))))
2469 (setq charset (and ctl
2470 (mail-content-type-get ctl 'charset)))
2471 (when (stringp charset)
2472 (setq charset (intern (downcase charset)))))))
2474 (setq charset (mm-read-coding-system "Charset: " charset)))
2476 (setq charset gnus-newsgroup-charset))
2478 (save-window-excursion
2480 (narrow-to-region (point) (point-max))
2481 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2482 (entry (assq func mm-text-html-washer-alist)))
2484 (setq func (cdr entry)))
2489 (apply (car func) (cdr func))))))))))
2491 (defun gnus-article-wash-html-with-w3 ()
2492 "Wash the current buffer with w3."
2494 (let ((w3-strict-width (window-width))
2495 (url-standalone-mode t)
2496 (url-gateway-unplugged t)
2497 (w3-honor-stylesheets nil))
2499 (w3-region (point-min) (point-max))
2502 (defun gnus-article-wash-html-with-w3m ()
2503 "Wash the current buffer with emacs-w3m."
2506 (narrow-to-region (point) (point-max))
2507 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2508 w3m-force-redisplay)
2509 (w3m-region (point-min) (point-max)))
2510 (when (and mm-inline-text-html-with-w3m-keymap
2511 (boundp 'w3m-minor-mode-map)
2513 (add-text-properties
2514 (point-min) (point-max)
2515 (list 'keymap w3m-minor-mode-map
2516 ;; Put the mark meaning this part was rendered by emacs-w3m.
2517 'mm-inline-text-html-with-w3m t)))))
2519 (defun article-hide-list-identifiers ()
2520 "Remove list identifies from the Subject header.
2521 The `gnus-list-identifiers' variable specifies what to do."
2523 (let ((inhibit-point-motion-hooks t)
2524 (regexp (if (consp gnus-list-identifiers)
2525 (mapconcat 'identity gnus-list-identifiers " *\\|")
2526 gnus-list-identifiers))
2527 (inhibit-read-only t))
2531 (article-narrow-to-head)
2532 (goto-char (point-min))
2533 (while (re-search-forward
2534 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
2536 (delete-region (match-beginning 2) (match-end 0))
2537 (beginning-of-line))
2538 (when (re-search-forward
2539 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
2540 (delete-region (match-beginning 1) (match-end 1))))))))
2542 (defun article-hide-pem (&optional arg)
2543 "Toggle hiding of any PEM headers and signatures in the current article.
2544 If given a negative prefix, always show; if given a positive prefix,
2546 (interactive (gnus-article-hidden-arg))
2547 (unless (gnus-article-check-hidden-text 'pem arg)
2549 (let ((inhibit-read-only t) end)
2550 (goto-char (point-min))
2551 ;; Hide the horrendously ugly "header".
2552 (when (and (search-forward
2553 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
2555 (setq end (1+ (match-beginning 0))))
2556 (gnus-add-wash-type 'pem)
2557 (gnus-article-hide-text-type
2559 (if (search-forward "\n\n" nil t)
2563 ;; Hide the trailer as well
2564 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
2566 (gnus-article-hide-text-type
2567 (match-beginning 0) (match-end 0) 'pem)))))))
2569 (defun article-strip-banner ()
2570 "Strip the banners specified by the `banner' group parameter and by
2571 `gnus-article-address-banner-alist'."
2575 (let ((inhibit-point-motion-hooks t))
2576 (when (gnus-parameter-banner gnus-newsgroup-name)
2577 (article-really-strip-banner
2578 (gnus-parameter-banner gnus-newsgroup-name)))
2579 (when gnus-article-address-banner-alist
2580 ;; It is necessary to encode from fields before checking,
2581 ;; because `mail-header-parse-addresses' does not work
2582 ;; (reliably) on decoded headers. And more, it is
2583 ;; impossible to use `gnus-fetch-original-field' here,
2584 ;; because `article-strip-banner' may be called in draft
2585 ;; buffers to preview them.
2586 (let ((from (save-restriction
2588 (article-narrow-to-head)
2589 (mail-fetch-field "from"))))
2592 (caar (mail-header-parse-addresses
2593 (mail-encode-encoded-word-string from)))))
2595 (dolist (pair gnus-article-address-banner-alist)
2596 (when (string-match (car pair) from)
2598 (article-really-strip-banner (cdr pair)))))))))))))
2600 (defun article-really-strip-banner (banner)
2601 "Strip the banner specified by the argument."
2604 (let ((inhibit-point-motion-hooks t)
2605 (gnus-signature-limit nil)
2606 (inhibit-read-only t))
2609 ((eq banner 'signature)
2610 (when (gnus-article-narrow-to-signature)
2613 (delete-region (point) (point-max))))
2615 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
2616 (while (re-search-forward banner nil t)
2617 (delete-region (match-beginning 0) (match-end 0)))))
2619 (while (re-search-forward banner nil t)
2620 (delete-region (match-beginning 0) (match-end 0)))))))))
2622 (defun article-babel ()
2623 "Translate article using an online translation service."
2626 (gnus-with-article-buffer
2627 (when (article-goto-body)
2628 (let* ((start (point))
2630 (orig (buffer-substring start end))
2631 (trans (babel-as-string orig)))
2633 (narrow-to-region start end)
2634 (delete-region start end)
2637 (defun article-hide-signature (&optional arg)
2638 "Hide the signature in the current article.
2639 If given a negative prefix, always show; if given a positive prefix,
2641 (interactive (gnus-article-hidden-arg))
2642 (unless (gnus-article-check-hidden-text 'signature arg)
2645 (let ((inhibit-read-only t))
2646 (when (gnus-article-narrow-to-signature)
2647 (gnus-article-hide-text-type
2648 (point-min) (point-max) 'signature))))))
2649 (gnus-set-mode-line 'article))
2651 (defun article-strip-headers-in-body ()
2652 "Strip offensive headers from bodies."
2656 (let ((case-fold-search t))
2657 (when (looking-at "x-no-archive:")
2658 (gnus-delete-line)))))
2660 (defun article-strip-leading-blank-lines ()
2661 "Remove all blank lines from the beginning of the article."
2664 (let ((inhibit-point-motion-hooks t)
2665 (inhibit-read-only t))
2666 (when (article-goto-body)
2667 (while (and (not (eobp))
2668 (looking-at "[ \t]*$"))
2669 (gnus-delete-line))))))
2671 (defun article-narrow-to-head ()
2672 "Narrow the buffer to the head of the message.
2673 Point is left at the beginning of the narrowed-to region."
2675 (goto-char (point-min))
2676 (if (search-forward "\n\n" nil 1)
2679 (goto-char (point-min)))
2681 (defun article-goto-body ()
2682 "Place point at the start of the body."
2683 (goto-char (point-min))
2685 ;; This variable is only bound when dealing with separate
2687 (article-goto-body-goes-to-point-min-p
2689 ((search-forward "\n\n" nil t)
2692 (goto-char (point-max))
2695 (defun article-strip-multiple-blank-lines ()
2696 "Replace consecutive blank lines with one empty line."
2699 (let ((inhibit-point-motion-hooks t)
2700 (inhibit-read-only t))
2701 ;; First make all blank lines empty.
2703 (while (re-search-forward "^[ \t]+$" nil t)
2704 (unless (gnus-annotation-in-region-p
2705 (match-beginning 0) (match-end 0))
2706 (replace-match "" nil t)))
2707 ;; Then replace multiple empty lines with a single empty line.
2709 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
2710 (unless (gnus-annotation-in-region-p
2711 (match-beginning 0) (match-end 0))
2712 (delete-region (match-beginning 1) (match-end 1)))))))
2714 (defun article-strip-leading-space ()
2715 "Remove all white space from the beginning of the lines in the article."
2718 (let ((inhibit-point-motion-hooks t)
2719 (inhibit-read-only t))
2721 (while (re-search-forward "^[ \t]+" nil t)
2722 (replace-match "" t t)))))
2724 (defun article-strip-trailing-space ()
2725 "Remove all white space from the end of the lines in the article."
2728 (let ((inhibit-point-motion-hooks t)
2729 (inhibit-read-only t))
2731 (while (re-search-forward "[ \t]+$" nil t)
2732 (replace-match "" t t)))))
2734 (defun article-strip-blank-lines ()
2735 "Strip leading, trailing and multiple blank lines."
2737 (article-strip-leading-blank-lines)
2738 (article-remove-trailing-blank-lines)
2739 (article-strip-multiple-blank-lines))
2741 (defun article-strip-all-blank-lines ()
2742 "Strip all blank lines."
2745 (let ((inhibit-point-motion-hooks t)
2746 (inhibit-read-only t))
2748 (while (re-search-forward "^[ \t]*\n" nil t)
2749 (replace-match "" t t)))))
2751 (defun gnus-article-narrow-to-signature ()
2752 "Narrow to the signature; return t if a signature is found, else nil."
2753 (let ((inhibit-point-motion-hooks t))
2754 (when (gnus-article-search-signature)
2756 ;; Check whether we have some limits to what we consider
2757 ;; to be a signature.
2758 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
2759 (list gnus-signature-limit)))
2761 (while (setq limit (pop limits))
2762 (if (or (and (integerp limit)
2763 (< (- (point-max) (point)) limit))
2765 (< (count-lines (point) (point-max)) limit))
2766 (and (functionp limit)
2768 (and (stringp limit)
2769 (not (re-search-forward limit nil t))))
2770 () ; This limit did not succeed.
2774 (narrow-to-region (point) (point-max))
2777 (defun gnus-article-search-signature ()
2778 "Search the current buffer for the signature separator.
2779 Put point at the beginning of the signature separator."
2780 (let ((cur (point)))
2781 (goto-char (point-max))
2782 (if (if (stringp gnus-signature-separator)
2783 (re-search-backward gnus-signature-separator nil t)
2784 (let ((seps gnus-signature-separator))
2786 (not (re-search-backward (car seps) nil t)))
2793 (defun gnus-article-hidden-arg ()
2794 "Return the current prefix arg as a number, or 0 if no prefix."
2795 (list (if current-prefix-arg
2796 (prefix-numeric-value current-prefix-arg)
2799 (defun gnus-article-check-hidden-text (type arg)
2800 "Return nil if hiding is necessary.
2801 Arg can be nil or a number. nil and positive means hide, negative
2802 means show, 0 means toggle."
2805 (let ((hide (gnus-article-hidden-text-p type)))
2811 (gnus-article-show-hidden-text type)
2814 (if (eq hide 'hidden)
2816 (gnus-article-show-hidden-text type)
2820 (defun gnus-article-hidden-text-p (type)
2821 "Say whether the current buffer contains hidden text of type TYPE."
2822 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
2824 (not (get-text-property pos 'invisible))
2825 (not (get-text-property pos 'dummy-invisible)))
2827 (text-property-any (1+ pos) (point-max) 'article-type type)))
2832 (defun gnus-article-show-hidden-text (type &optional dummy)
2833 "Show all hidden text of type TYPE.
2834 Originally it is hide instead of DUMMY."
2835 (let ((inhibit-read-only t)
2836 (inhibit-point-motion-hooks t))
2837 (gnus-remove-text-properties-when
2839 (point-min) (point-max)
2840 (cons 'article-type (cons type
2841 gnus-hidden-properties)))
2842 (gnus-delete-wash-type type)))
2844 (defconst article-time-units
2845 `((year . ,(* 365.25 24 60 60))
2846 (week . ,(* 7 24 60 60))
2847 (day . ,(* 24 60 60))
2851 "Mapping from time units to seconds.")
2853 (defun gnus-article-forward-header ()
2854 "Move point to the start of the next header.
2855 If the current header is a continuation header, this can be several
2860 (if (looking-at "[ \t]+[^ \t]")
2864 (defun article-date-ut (&optional type highlight header)
2865 "Convert DATE date to universal time in the current article.
2866 If TYPE is `local', convert to local time; if it is `lapsed', output
2867 how much time has lapsed since DATE. For `lapsed', the value of
2868 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
2869 should replace the \"Date:\" one, or should be added below it."
2870 (interactive (list 'ut t))
2871 (let* ((header (or header
2872 (message-fetch-field "date")
2874 (tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
2877 ((not gnus-article-date-lapsed-new-header)
2883 (date (if (vectorp header) (mail-header-date header)
2885 (inhibit-point-motion-hooks t)
2890 (article-narrow-to-head)
2891 (when (re-search-forward tdate-regexp nil t)
2892 (setq bface (get-text-property (point-at-bol) 'face)
2893 date (or (get-text-property (point-at-bol)
2896 eface (get-text-property (1- (point-at-eol)) 'face))
2898 (when (and date (not (string= date "")))
2899 (goto-char (point-min))
2900 (let ((inhibit-read-only t))
2901 ;; Delete any old Date headers.
2902 (while (re-search-forward date-regexp nil t)
2904 (delete-region (point-at-bol)
2905 (progn (gnus-article-forward-header)
2907 (delete-region (point-at-bol)
2908 (progn (gnus-article-forward-header)
2911 (setq pos (point))))
2912 (when (and (not pos)
2913 (re-search-forward tdate-regexp nil t))
2915 (gnus-goto-char pos)
2916 (insert (article-make-date-line date (or type 'ut)))
2922 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
2923 (add-text-properties (match-beginning 1) (1+ (match-end 1))
2924 (list 'original-date date 'face bface))
2925 (put-text-property (match-beginning 2) (match-end 2)
2928 (defun article-make-date-line (date type)
2929 "Return a DATE line of TYPE."
2930 (unless (memq type '(local ut original user iso8601 lapsed english))
2931 (error "Unknown conversion type: %s" type))
2933 (let ((time (date-to-time date)))
2935 ;; Convert to the local timezone.
2937 (concat "Date: " (message-make-date time)))
2938 ;; Convert to Universal Time.
2943 (let* ((e (parse-time-string date))
2944 (tm (apply 'encode-time e))
2946 (ls (- (cadr tm) (car (current-time-zone time)))))
2947 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
2948 ((> ls 65535) (list (1+ ms) (- ls 65536)))
2952 ;; Get the original date from the article.
2953 ((eq type 'original)
2954 (concat "Date: " (if (string-match "\n+$" date)
2955 (substring date 0 (match-beginning 0))
2957 ;; Let the user define the format.
2959 (let ((format (or (condition-case nil
2960 (with-current-buffer gnus-summary-buffer
2961 gnus-article-time-format)
2963 gnus-article-time-format)))
2964 (if (functionp format)
2965 (funcall format time)
2966 (concat "Date: " (format-time-string format time)))))
2969 (let ((tz (car (current-time-zone time))))
2972 (format-time-string "%Y%m%dT%H%M%S" time)
2973 (format "%s%02d%02d"
2974 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
2975 (/ (% (abs tz) 3600) 60)))))
2976 ;; Do an X-Sent lapsed format.
2978 ;; If the date is seriously mangled, the timezone functions are
2979 ;; liable to bug out, so we ignore all errors.
2980 (let* ((now (current-time))
2981 (real-time (subtract-time now time))
2982 (real-sec (and real-time
2983 (+ (* (float (car real-time)) 65536)
2985 (sec (and real-time (abs real-sec)))
2995 ;; This is a bit convoluted, but basically we go
2996 ;; through the time units for years, weeks, etc,
2997 ;; and divide things to see whether that results
2998 ;; in positive answers.
3001 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3002 ;; The (remaining) seconds are too few to
3003 ;; be divided into this time unit.
3005 ;; It's big enough, so we output it.
3006 (setq sec (- sec (* num (cdr unit))))
3008 (concat (if prev ", " "") (int-to-string
3010 " " (symbol-name (car unit))
3011 (if (> num 1) "s" ""))
3013 article-time-units "")
3014 ;; If dates are odd, then it might appear like the
3015 ;; article was sent in the future.
3018 " in the future"))))))
3019 ;; Display the date in proper English
3021 (let ((dtime (decode-time time)))
3024 (number-to-string (nth 3 dtime))
3025 (let ((digit (% (nth 3 dtime) 10)))
3027 ((memq (nth 3 dtime) '(11 12 13)) "th")
3033 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3035 (number-to-string (nth 5 dtime))
3037 (format "%02d" (nth 2 dtime))
3039 (format "%02d" (nth 1 dtime)))))))
3041 (format "Date: %s (from Gnus)" date))))
3043 (defun article-date-local (&optional highlight)
3044 "Convert the current article date to the local timezone."
3045 (interactive (list t))
3046 (article-date-ut 'local highlight))
3048 (defun article-date-english (&optional highlight)
3049 "Convert the current article date to something that is proper English."
3050 (interactive (list t))
3051 (article-date-ut 'english highlight))
3053 (defun article-date-original (&optional highlight)
3054 "Convert the current article date to what it was originally.
3055 This is only useful if you have used some other date conversion
3056 function and want to see what the date was before converting."
3057 (interactive (list t))
3058 (article-date-ut 'original highlight))
3060 (defun article-date-lapsed (&optional highlight)
3061 "Convert the current article date to time lapsed since it was sent."
3062 (interactive (list t))
3063 (article-date-ut 'lapsed highlight))
3065 (defun article-update-date-lapsed ()
3066 "Function to be run from a timer to update the lapsed time line."
3067 (let (deactivate-mark)
3072 (set-buffer (window-buffer w))
3073 (when (eq major-mode 'gnus-article-mode)
3074 (let ((mark (point-marker)))
3075 (goto-char (point-min))
3076 (when (re-search-forward "^X-Sent:" nil t)
3077 (article-date-lapsed t))
3078 (goto-char (marker-position mark))
3079 (move-marker mark nil))))
3082 (defun gnus-start-date-timer (&optional n)
3083 "Start a timer to update the X-Sent header in the article buffers.
3084 The numerical prefix says how frequently (in seconds) the function
3089 (gnus-stop-date-timer)
3090 (setq article-lapsed-timer
3091 (run-at-time 1 n 'article-update-date-lapsed)))
3093 (defun gnus-stop-date-timer ()
3094 "Stop the X-Sent timer."
3096 (when article-lapsed-timer
3097 (nnheader-cancel-timer article-lapsed-timer)
3098 (setq article-lapsed-timer nil)))
3100 (defun article-date-user (&optional highlight)
3101 "Convert the current article date to the user-defined format.
3102 This format is defined by the `gnus-article-time-format' variable."
3103 (interactive (list t))
3104 (article-date-ut 'user highlight))
3106 (defun article-date-iso8601 (&optional highlight)
3107 "Convert the current article date to ISO8601."
3108 (interactive (list t))
3109 (article-date-ut 'iso8601 highlight))
3111 ;; (defun article-show-all ()
3112 ;; "Show all hidden text in the article buffer."
3115 ;; (let ((inhibit-read-only t))
3116 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3118 (defun article-remove-leading-whitespace ()
3119 "Remove excessive whitespace from all headers."
3123 (let ((inhibit-read-only t))
3124 (article-narrow-to-head)
3125 (goto-char (point-min))
3126 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3127 (delete-region (match-beginning 1) (match-end 1)))))))
3129 (defun article-emphasize (&optional arg)
3130 "Emphasize text according to `gnus-emphasis-alist'."
3131 (interactive (gnus-article-hidden-arg))
3132 (unless (gnus-article-check-hidden-text 'emphasis arg)
3136 (with-current-buffer gnus-summary-buffer
3137 gnus-article-emphasis-alist)
3139 gnus-emphasis-alist))
3140 (inhibit-read-only t)
3141 (props (append '(article-type emphasis)
3142 gnus-hidden-properties))
3143 regexp elem beg invisible visible face)
3146 (while (setq elem (pop alist))
3148 (setq regexp (car elem)
3149 invisible (nth 1 elem)
3150 visible (nth 2 elem)
3152 (while (re-search-forward regexp nil t)
3153 (when (and (match-beginning visible) (match-beginning invisible))
3154 (gnus-article-hide-text
3155 (match-beginning invisible) (match-end invisible) props)
3156 (gnus-article-unhide-text-type
3157 (match-beginning visible) (match-end visible) 'emphasis)
3158 (gnus-put-overlay-excluding-newlines
3159 (match-beginning visible) (match-end visible) 'face face)
3160 (gnus-add-wash-type 'emphasis)
3161 (goto-char (match-end invisible)))))))))
3163 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3164 "Setup newsgroup emphasis alist."
3165 (unless gnus-article-emphasis-alist
3166 (let ((name (and gnus-newsgroup-name
3167 (gnus-group-real-name gnus-newsgroup-name))))
3168 (make-local-variable 'gnus-article-emphasis-alist)
3169 (setq gnus-article-emphasis-alist
3171 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3172 (while (setq elem (pop alist))
3173 (when (and name (string-match (car elem) name))
3175 highlight (copy-sequence (cdr elem)))))
3177 (copy-sequence highlight-words)
3178 (if gnus-newsgroup-name
3179 (copy-sequence (gnus-group-find-parameter
3180 gnus-newsgroup-name 'highlight-words t)))
3181 gnus-emphasis-alist)))))
3184 (defvar gnus-summary-article-menu)
3185 (defvar gnus-summary-post-menu))
3187 ;;; Saving functions.
3189 (defun gnus-article-save (save-buffer file &optional num)
3190 "Save the currently selected article."
3191 (unless gnus-save-all-headers
3192 ;; Remove headers according to `gnus-saved-headers'.
3193 (let ((gnus-visible-headers
3194 (or gnus-saved-headers gnus-visible-headers))
3195 (gnus-article-buffer save-buffer))
3197 (set-buffer save-buffer)
3198 (article-hide-headers 1 t))))
3199 (save-window-excursion
3200 (if (not gnus-default-article-saver)
3201 (error "No default saver is defined")
3202 ;; !!! Magic! The saving functions all save
3203 ;; `gnus-save-article-buffer' (or so they think), but we
3204 ;; bind that variable to our save-buffer.
3205 (set-buffer gnus-article-buffer)
3206 (let* ((gnus-save-article-buffer save-buffer)
3209 ((not gnus-prompt-before-saving) 'default)
3210 ((eq gnus-prompt-before-saving 'always) nil)
3212 (gnus-number-of-articles-to-be-saved
3213 (when (eq gnus-prompt-before-saving t)
3215 (set-buffer gnus-article-current-summary)
3216 (funcall gnus-default-article-saver filename)))))
3218 (defun gnus-read-save-file-name (prompt &optional filename
3219 function group headers variable)
3221 (funcall function group headers (symbol-value variable)))
3226 ((eq filename 'default)
3232 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3235 (if (and gnus-number-of-articles-to-be-saved
3236 (> gnus-number-of-articles-to-be-saved 1))
3237 (format "these %d articles"
3238 gnus-number-of-articles-to-be-saved)
3241 ;; Let the split methods have their say.
3243 ;; No split name was found.
3246 (concat prompt " (default "
3247 (file-name-nondirectory default-name) ") ")
3248 (file-name-directory default-name)
3250 ;; A single group name is returned.
3251 ((stringp split-name)
3253 (funcall function split-name headers
3254 (symbol-value variable)))
3256 (concat prompt " (default "
3257 (file-name-nondirectory default-name) ") ")
3258 (file-name-directory default-name)
3260 ;; A single split name was found
3261 ((= 1 (length split-name))
3262 (let* ((name (expand-file-name
3264 gnus-article-save-directory))
3265 (dir (cond ((file-directory-p name)
3266 (file-name-as-directory name))
3267 ((file-exists-p name) name)
3268 (t gnus-article-save-directory))))
3270 (concat prompt " (default " name ") ")
3272 ;; A list of splits was found.
3274 (setq split-name (nreverse split-name))
3276 (let ((file-name-history
3277 (nconc split-name file-name-history)))
3281 (concat prompt " (`M-p' for defaults) ")
3282 gnus-article-save-directory
3284 gnus-article-save-directory)))
3285 (car (push result file-name-history)))))))
3286 ;; Create the directory.
3287 (gnus-make-directory (file-name-directory file))
3288 ;; If we have read a directory, we append the default file name.
3289 (when (file-directory-p file)
3290 (setq file (expand-file-name (file-name-nondirectory
3292 (file-name-as-directory file))))
3293 ;; Possibly translate some characters.
3294 (nnheader-translate-file-chars file))))))
3295 (gnus-make-directory (file-name-directory result))
3296 (set variable result)))
3298 (defun gnus-article-archive-name (group)
3299 "Return the first instance of an \"Archive-name\" in the current buffer."
3300 (let ((case-fold-search t))
3301 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3302 (nnheader-concat gnus-article-save-directory
3303 (match-string 1)))))
3305 (defun gnus-article-nndoc-name (group)
3306 "If GROUP is an nndoc group, return the name of the parent group."
3307 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3308 (gnus-group-get-parameter group 'save-article-group)))
3310 (defun gnus-summary-save-in-rmail (&optional filename)
3311 "Append this article to Rmail file.
3312 Optional argument FILENAME specifies file name.
3313 Directory to save to is default to `gnus-article-save-directory'."
3314 (setq filename (gnus-read-save-file-name
3315 "Save %s in rmail file:" filename
3316 gnus-rmail-save-name gnus-newsgroup-name
3317 gnus-current-headers 'gnus-newsgroup-last-rmail))
3318 (gnus-eval-in-buffer-window gnus-save-article-buffer
3322 (gnus-output-to-rmail filename))))
3325 (defun gnus-summary-save-in-mail (&optional filename)
3326 "Append this article to Unix mail file.
3327 Optional argument FILENAME specifies file name.
3328 Directory to save to is default to `gnus-article-save-directory'."
3329 (setq filename (gnus-read-save-file-name
3330 "Save %s in Unix mail file:" filename
3331 gnus-mail-save-name gnus-newsgroup-name
3332 gnus-current-headers 'gnus-newsgroup-last-mail))
3333 (gnus-eval-in-buffer-window gnus-save-article-buffer
3337 (if (and (file-readable-p filename)
3338 (file-regular-p filename)
3339 (mail-file-babyl-p filename))
3340 (rmail-output-to-rmail-file filename t)
3341 (gnus-output-to-mail filename)))))
3344 (defun gnus-summary-save-in-file (&optional filename overwrite)
3345 "Append this article to file.
3346 Optional argument FILENAME specifies file name.
3347 Directory to save to is default to `gnus-article-save-directory'."
3348 (setq filename (gnus-read-save-file-name
3349 "Save %s in file:" filename
3350 gnus-file-save-name gnus-newsgroup-name
3351 gnus-current-headers 'gnus-newsgroup-last-file))
3352 (gnus-eval-in-buffer-window gnus-save-article-buffer
3356 (when (and overwrite
3357 (file-exists-p filename))
3358 (delete-file filename))
3359 (gnus-output-to-file filename))))
3362 (defun gnus-summary-write-to-file (&optional filename)
3363 "Write this article to a file, overwriting it if the file exists.
3364 Optional argument FILENAME specifies file name.
3365 The directory to save in defaults to `gnus-article-save-directory'."
3366 (gnus-summary-save-in-file nil t))
3368 (defun gnus-summary-save-body-in-file (&optional filename)
3369 "Append this article body to a file.
3370 Optional argument FILENAME specifies file name.
3371 The directory to save in defaults to `gnus-article-save-directory'."
3372 (setq filename (gnus-read-save-file-name
3373 "Save %s body in file:" filename
3374 gnus-file-save-name gnus-newsgroup-name
3375 gnus-current-headers 'gnus-newsgroup-last-file))
3376 (gnus-eval-in-buffer-window gnus-save-article-buffer
3380 (when (article-goto-body)
3381 (narrow-to-region (point) (point-max)))
3382 (gnus-output-to-file filename))))
3385 (defun gnus-summary-save-in-pipe (&optional command)
3386 "Pipe this article to subprocess."
3388 (cond ((and (eq command 'default)
3389 gnus-last-shell-command)
3390 gnus-last-shell-command)
3395 "Shell command on %s: "
3396 (if (and gnus-number-of-articles-to-be-saved
3397 (> gnus-number-of-articles-to-be-saved 1))
3398 (format "these %d articles"
3399 gnus-number-of-articles-to-be-saved)
3401 gnus-last-shell-command))))
3402 (when (string-equal command "")
3403 (if gnus-last-shell-command
3404 (setq command gnus-last-shell-command)
3405 (error "A command is required")))
3406 (gnus-eval-in-buffer-window gnus-article-buffer
3409 (shell-command-on-region (point-min) (point-max) command nil)))
3410 (setq gnus-last-shell-command command))
3412 (defun gnus-summary-pipe-to-muttprint (&optional command)
3413 "Pipe this article to muttprint."
3414 (setq command (read-string
3415 "Print using command: " gnus-summary-muttprint-program
3416 nil gnus-summary-muttprint-program))
3417 (gnus-summary-save-in-pipe command))
3419 ;;; Article file names when saving.
3421 (defun gnus-capitalize-newsgroup (newsgroup)
3422 "Capitalize NEWSGROUP name."
3423 (when (not (zerop (length newsgroup)))
3424 (concat (char-to-string (upcase (aref newsgroup 0)))
3425 (substring newsgroup 1))))
3427 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
3428 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3429 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
3430 Otherwise, it is like ~/News/news/group/num."
3433 (concat (if (gnus-use-long-file-name 'not-save)
3434 (gnus-capitalize-newsgroup newsgroup)
3435 (gnus-newsgroup-directory-form newsgroup))
3436 "/" (int-to-string (mail-header-number headers)))
3437 gnus-article-save-directory)))
3439 (string-equal (file-name-directory default)
3440 (file-name-directory last-file))
3441 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3443 (or last-file default))))
3445 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
3446 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3447 If variable `gnus-use-long-file-name' is non-nil, it is
3448 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
3451 (concat (if (gnus-use-long-file-name 'not-save)
3453 (gnus-newsgroup-directory-form newsgroup))
3454 "/" (int-to-string (mail-header-number headers)))
3455 gnus-article-save-directory)))
3457 (string-equal (file-name-directory default)
3458 (file-name-directory last-file))
3459 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
3461 (or last-file default))))
3463 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
3464 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
3465 If variable `gnus-use-long-file-name' is non-nil, it is
3466 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
3469 (if (gnus-use-long-file-name 'not-save)
3472 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
3474 gnus-article-save-directory)))
3476 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
3477 "Generate file name from sender."
3478 (let ((from (mail-header-from headers)))
3480 (if (and from (string-match "\\([^ <]+\\)@" from))
3481 (match-string 1 from)
3483 gnus-article-save-directory)))
3485 (defun article-verify-x-pgp-sig ()
3488 (if (gnus-buffer-live-p gnus-original-article-buffer)
3489 (let ((sig (with-current-buffer gnus-original-article-buffer
3490 (gnus-fetch-field "X-PGP-Sig")))
3494 (mml2015-clear-verify-function))
3496 (insert-buffer-substring gnus-original-article-buffer)
3497 (setq items (split-string sig))
3498 (message-narrow-to-head)
3499 (let ((inhibit-point-motion-hooks t)
3500 (case-fold-search t))
3501 ;; Don't verify multiple headers.
3502 (setq headers (mapconcat (lambda (header)
3504 (mail-fetch-field header)
3506 (split-string (nth 1 items) ",") "")))
3507 (delete-region (point-min) (point-max))
3508 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
3509 (insert "X-Signed-Headers: " (nth 1 items) "\n")
3514 (if (looking-at "^-")
3517 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
3518 (insert "Version: " (car items) "\n\n")
3519 (insert (mapconcat 'identity (cddr items) "\n"))
3520 (insert "\n-----END PGP SIGNATURE-----\n")
3521 (let ((mm-security-handle (list (format "multipart/signed"))))
3522 (mml2015-clean-buffer)
3523 (let ((coding-system-for-write (or gnus-newsgroup-charset
3525 (funcall (mml2015-clear-verify-function)))
3527 (or (mm-handle-multipart-ctl-parameter
3528 mm-security-handle 'gnus-details)
3529 (mm-handle-multipart-ctl-parameter
3530 mm-security-handle 'gnus-info)))))
3532 (let ((inhibit-read-only t) bface eface)
3534 (message-narrow-to-head)
3535 (goto-char (point-max))
3537 (setq bface (get-text-property (point-at-bol) 'face)
3538 eface (get-text-property (1- (point-at-eol)) 'face))
3539 (message-remove-header "X-Gnus-PGP-Verify")
3540 (if (re-search-forward "^X-PGP-Sig:" nil t)
3542 (goto-char (point-max)))
3543 (narrow-to-region (point) (point))
3544 (insert "X-Gnus-PGP-Verify: " info "\n")
3545 (goto-char (point-min))
3548 (if (not (looking-at "^[ \t]"))
3552 (goto-char (point-min))
3553 (when (looking-at "\\([^:]+\\): *")
3554 (put-text-property (match-beginning 1) (1+ (match-end 1))
3556 (put-text-property (match-end 0) (point-max)
3557 'face eface)))))))))
3559 (defun article-verify-cancel-lock ()
3560 "Verify Cancel-Lock header."
3562 (if (gnus-buffer-live-p gnus-original-article-buffer)
3563 (canlock-verify gnus-original-article-buffer)))
3570 (setq afunc (car func)
3573 gfunc (intern (format "gnus-%s" func))))
3575 (when (fboundp afunc)
3576 `(lambda (&optional interactive &rest args)
3577 ,(documentation afunc t)
3578 (interactive (list t))
3580 (set-buffer gnus-article-buffer)
3582 (call-interactively ',afunc)
3583 (apply ',afunc args))))))))
3584 '(article-hide-headers
3585 article-verify-x-pgp-sig
3586 article-verify-cancel-lock
3587 article-hide-boring-headers
3588 article-treat-overstrike
3589 article-treat-ansi-sequences
3590 article-fill-long-lines
3591 article-capitalize-sentences
3593 article-remove-leading-whitespace
3594 article-display-x-face
3595 article-display-face
3596 article-de-quoted-unreadable
3597 article-de-base64-unreadable
3600 article-unsplit-urls
3601 article-hide-list-identifiers
3602 article-strip-banner
3605 article-hide-signature
3606 article-strip-headers-in-body
3607 article-remove-trailing-blank-lines
3608 article-strip-leading-blank-lines
3609 article-strip-multiple-blank-lines
3610 article-strip-leading-space
3611 article-strip-trailing-space
3612 article-strip-blank-lines
3613 article-strip-all-blank-lines
3615 article-date-english
3616 article-date-iso8601
3617 article-date-original
3619 article-decode-mime-words
3620 article-decode-charset
3621 article-decode-encoded-words
3625 article-treat-dumbquotes
3626 article-normalize-headers
3627 ;; (article-show-all . gnus-article-show-all-headers)
3631 ;;; Gnus article mode
3634 (put 'gnus-article-mode 'mode-class 'special)
3636 (set-keymap-parent gnus-article-mode-map widget-keymap)
3638 (gnus-define-keys gnus-article-mode-map
3639 " " gnus-article-goto-next-page
3640 "\177" gnus-article-goto-prev-page
3641 [delete] gnus-article-goto-prev-page
3642 [backspace] gnus-article-goto-prev-page
3643 "\C-c^" gnus-article-refer-article
3644 "h" gnus-article-show-summary
3645 "s" gnus-article-show-summary
3646 "\C-c\C-m" gnus-article-mail
3647 "?" gnus-article-describe-briefly
3648 "e" gnus-summary-edit-article
3649 "<" beginning-of-buffer
3651 "\C-c\C-i" gnus-info-find-node
3653 "R" gnus-article-reply-with-original
3654 "F" gnus-article-followup-with-original
3655 "\C-hk" gnus-article-describe-key
3656 "\C-hc" gnus-article-describe-key-briefly
3658 "\C-d" gnus-article-read-summary-keys
3659 "\M-*" gnus-article-read-summary-keys
3660 "\M-#" gnus-article-read-summary-keys
3661 "\M-^" gnus-article-read-summary-keys
3662 "\M-g" gnus-article-read-summary-keys)
3664 (substitute-key-definition
3665 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
3667 (defun gnus-article-make-menu-bar ()
3668 (unless (boundp 'gnus-article-commands-menu)
3669 (gnus-summary-make-menu-bar))
3670 (gnus-turn-off-edit-menu 'article)
3671 (unless (boundp 'gnus-article-article-menu)
3673 gnus-article-article-menu gnus-article-mode-map ""
3675 ["Scroll forwards" gnus-article-goto-next-page t]
3676 ["Scroll backwards" gnus-article-goto-prev-page t]
3677 ["Show summary" gnus-article-show-summary t]
3678 ["Fetch Message-ID at point" gnus-article-refer-article t]
3679 ["Mail to address at point" gnus-article-mail t]
3680 ["Send a bug report" gnus-bug t]))
3683 gnus-article-treatment-menu gnus-article-mode-map ""
3684 ;; Fixme: this should use :active (and maybe :visible).
3686 ["Hide headers" gnus-article-hide-headers t]
3687 ["Hide signature" gnus-article-hide-signature t]
3688 ["Hide citation" gnus-article-hide-citation t]
3689 ["Treat overstrike" gnus-article-treat-overstrike t]
3690 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
3691 ["Remove carriage return" gnus-article-remove-cr t]
3692 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
3693 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
3694 ["Remove base64" gnus-article-de-base64-unreadable t]
3695 ["Treat html" gnus-article-wash-html t]
3696 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
3697 ["Decode HZ" gnus-article-decode-HZ t]))
3699 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
3701 ;; Note "Post" menu is defined in gnus-sum.el for consistency
3703 (gnus-run-hooks 'gnus-article-menu-hook)))
3705 (defun gnus-article-mode ()
3706 "Major mode for displaying an article.
3708 All normal editing commands are switched off.
3710 The following commands are available in addition to all summary mode
3712 \\<gnus-article-mode-map>
3713 \\[gnus-article-next-page]\t Scroll the article one page forwards
3714 \\[gnus-article-prev-page]\t Scroll the article one page backwards
3715 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
3716 \\[gnus-article-show-summary]\t Display the summary buffer
3717 \\[gnus-article-mail]\t Send a reply to the address near point
3718 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
3719 \\[gnus-info-find-node]\t Go to the Gnus info node"
3721 (gnus-simplify-mode-line)
3722 (setq mode-name "Article")
3723 (setq major-mode 'gnus-article-mode)
3724 (make-local-variable 'minor-mode-alist)
3725 (use-local-map gnus-article-mode-map)
3726 (when (gnus-visual-p 'article-menu 'menu)
3727 (gnus-article-make-menu-bar)
3728 (when gnus-summary-tool-bar-map
3729 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
3730 (gnus-update-format-specifications nil 'article-mode)
3731 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
3732 (set (make-local-variable 'gnus-page-broken) nil)
3733 (make-local-variable 'gnus-button-marker-list)
3734 (make-local-variable 'gnus-article-current-summary)
3735 (make-local-variable 'gnus-article-mime-handles)
3736 (make-local-variable 'gnus-article-decoded-p)
3737 (make-local-variable 'gnus-article-mime-handle-alist)
3738 (make-local-variable 'gnus-article-wash-types)
3739 (make-local-variable 'gnus-article-image-alist)
3740 (make-local-variable 'gnus-article-charset)
3741 (make-local-variable 'gnus-article-ignored-charsets)
3742 (gnus-set-default-directory)
3743 (buffer-disable-undo)
3744 (setq buffer-read-only t
3745 show-trailing-whitespace nil)
3746 (set-syntax-table gnus-article-mode-syntax-table)
3747 (mm-enable-multibyte)
3748 (gnus-run-hooks 'gnus-article-mode-hook))
3750 (defun gnus-article-setup-buffer ()
3751 "Initialize the article buffer."
3752 (let* ((name (if gnus-single-article-buffer "*Article*"
3753 (concat "*Article " gnus-newsgroup-name "*")))
3755 (progn (string-match "\\*Article" name)
3756 (concat " *Original Article"
3757 (substring name (match-end 0))))))
3758 (setq gnus-article-buffer name)
3759 (setq gnus-original-article-buffer original)
3760 (setq gnus-article-mime-handle-alist nil)
3761 ;; This might be a variable local to the summary buffer.
3762 (unless gnus-single-article-buffer
3764 (set-buffer gnus-summary-buffer)
3765 (setq gnus-article-buffer name)
3766 (setq gnus-original-article-buffer original)
3767 (gnus-set-global-variables)))
3768 (gnus-article-setup-highlight-words)
3769 ;; Init original article buffer.
3771 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
3772 (mm-enable-multibyte)
3773 (setq major-mode 'gnus-original-article-mode)
3774 (make-local-variable 'gnus-original-article))
3775 (if (get-buffer name)
3778 (when (and gnus-article-edit-mode
3781 (y-or-n-p "Article mode edit in progress; discard? ")))
3782 (error "Action aborted"))
3783 (set (make-local-variable 'gnus-article-edit-mode) nil)
3784 (when gnus-article-mime-handles
3785 (mm-destroy-parts gnus-article-mime-handles)
3786 (setq gnus-article-mime-handles nil))
3787 ;; Set it to nil in article-buffer!
3788 (setq gnus-article-mime-handle-alist nil)
3789 (buffer-disable-undo)
3790 (setq buffer-read-only t)
3791 ;; This list just keeps growing if we don't reset it.
3792 (setq gnus-button-marker-list nil)
3793 (unless (eq major-mode 'gnus-article-mode)
3794 (gnus-article-mode))
3797 (set-buffer (gnus-get-buffer-create name))
3799 (make-local-variable 'gnus-summary-buffer)
3800 (gnus-summary-set-local-parameters gnus-newsgroup-name)
3801 (current-buffer)))))
3803 ;; Set article window start at LINE, where LINE is the number of lines
3804 ;; from the head of the article.
3805 (defun gnus-article-set-window-start (&optional line)
3807 (gnus-get-buffer-window gnus-article-buffer t)
3809 (set-buffer gnus-article-buffer)
3810 (goto-char (point-min))
3813 (gnus-message 6 "Moved to bookmark")
3814 (search-forward "\n\n" nil t)
3818 (defun gnus-article-prepare (article &optional all-headers header)
3819 "Prepare ARTICLE in article mode buffer.
3820 ARTICLE should either be an article number or a Message-ID.
3821 If ARTICLE is an id, HEADER should be the article headers.
3822 If ALL-HEADERS is non-nil, no headers are hidden."
3824 ;; Make sure we start in a summary buffer.
3825 (unless (eq major-mode 'gnus-summary-mode)
3826 (set-buffer gnus-summary-buffer))
3827 (setq gnus-summary-buffer (current-buffer))
3828 (let* ((gnus-article (if header (mail-header-number header) article))
3829 (summary-buffer (current-buffer))
3830 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
3831 (group gnus-newsgroup-name)
3834 (gnus-article-setup-buffer)
3835 (set-buffer gnus-article-buffer)
3836 ;; Deactivate active regions.
3837 (when (and (boundp 'transient-mark-mode)
3838 transient-mark-mode)
3839 (setq mark-active nil))
3840 (if (not (setq result (let ((inhibit-read-only t))
3841 (gnus-request-article-this-buffer
3843 ;; There is no such article.
3845 (when (and (numberp article)
3846 (not (memq article gnus-newsgroup-sparse)))
3847 (setq gnus-article-current
3848 (cons gnus-newsgroup-name article))
3849 (set-buffer gnus-summary-buffer)
3850 (setq gnus-current-article article)
3851 (if (and (memq article gnus-newsgroup-undownloaded)
3852 (not (gnus-online (gnus-find-method-for-group
3853 gnus-newsgroup-name))))
3855 (gnus-summary-set-agent-mark article)
3856 (message "Message marked for downloading"))
3857 (gnus-summary-mark-article article gnus-canceled-mark)
3858 (unless (memq article gnus-newsgroup-sparse)
3859 (gnus-error 1 "No such article (may have expired or been canceled)")))))
3860 (if (or (eq result 'pseudo)
3861 (eq result 'nneething))
3864 (set-buffer summary-buffer)
3865 (push article gnus-newsgroup-history)
3866 (setq gnus-last-article gnus-current-article
3867 gnus-current-article 0
3868 gnus-current-headers nil
3869 gnus-article-current nil)
3870 (if (eq result 'nneething)
3871 (gnus-configure-windows 'summary)
3872 (gnus-configure-windows 'article))
3873 (gnus-set-global-variables))
3874 (let ((gnus-article-mime-handle-alist-1
3875 gnus-article-mime-handle-alist))
3876 (gnus-set-mode-line 'article)))
3877 ;; The result from the `request' was an actual article -
3878 ;; or at least some text that is now displayed in the
3880 (when (and (numberp article)
3881 (not (eq article gnus-current-article)))
3882 ;; Seems like a new article has been selected.
3883 ;; `gnus-current-article' must be an article number.
3885 (set-buffer summary-buffer)
3886 (push article gnus-newsgroup-history)
3887 (setq gnus-last-article gnus-current-article
3888 gnus-current-article article
3889 gnus-current-headers
3890 (gnus-summary-article-header gnus-current-article)
3891 gnus-article-current
3892 (cons gnus-newsgroup-name gnus-current-article))
3893 (unless (vectorp gnus-current-headers)
3894 (setq gnus-current-headers nil))
3895 (gnus-summary-goto-subject gnus-current-article)
3896 (when (gnus-summary-show-thread)
3897 ;; If the summary buffer really was folded, the
3898 ;; previous goto may not actually have gone to
3899 ;; the right article, but the thread root instead.
3901 (gnus-summary-goto-subject gnus-current-article))
3902 (gnus-run-hooks 'gnus-mark-article-hook)
3903 (gnus-set-mode-line 'summary)
3904 (when (gnus-visual-p 'article-highlight 'highlight)
3905 (gnus-run-hooks 'gnus-visual-mark-article-hook))
3906 ;; Set the global newsgroup variables here.
3907 (gnus-set-global-variables)
3908 (setq gnus-have-all-headers
3909 (or all-headers gnus-show-all-headers))))
3911 (gnus-configure-windows 'article))
3912 (when (or (numberp article)
3914 (gnus-article-prepare-display)
3916 (goto-char (point-min))
3917 (when gnus-break-pages
3918 (gnus-narrow-to-page)))
3919 (let ((gnus-article-mime-handle-alist-1
3920 gnus-article-mime-handle-alist))
3921 (gnus-set-mode-line 'article))
3925 (set-window-point (get-buffer-window (current-buffer)) (point))
3926 (gnus-configure-windows 'article)
3930 (defun gnus-article-prepare-display ()
3931 "Make the current buffer look like a nice article."
3932 ;; Hooks for getting information from the article.
3933 ;; This hook must be called before being narrowed.
3934 (let ((gnus-article-buffer (current-buffer))
3936 (inhibit-read-only t))
3937 (unless (eq major-mode 'gnus-article-mode)
3938 (gnus-article-mode))
3939 (setq buffer-read-only nil
3940 gnus-article-wash-types nil
3941 gnus-article-image-alist nil)
3942 (gnus-run-hooks 'gnus-tmp-internal-hook)
3943 (when gnus-display-mime-function
3944 (funcall gnus-display-mime-function))
3945 (gnus-run-hooks 'gnus-article-prepare-hook)))
3948 ;;; Gnus MIME viewing functions
3951 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
3952 "Format of the MIME buttons.
3954 Valid specifiers include:
3956 %T MIME type, along with additional info
3957 %n The `name' parameter
3958 %d The description, if any
3959 %l The length of the encoded part
3960 %p The part identifier number
3961 %e Dots if the part isn't displayed
3963 General format specifiers can also be used. See Info node
3964 `(gnus)Formatting Variables'.")
3966 (defvar gnus-mime-button-line-format-alist
3967 '((?t gnus-tmp-type ?s)
3968 (?T gnus-tmp-type-long ?s)
3969 (?n gnus-tmp-name ?s)
3970 (?d gnus-tmp-description ?s)
3972 (?l gnus-tmp-length ?d)
3973 (?e gnus-tmp-dots ?s)))
3975 (defvar gnus-mime-button-commands
3976 '((gnus-article-press-button "\r" "Toggle Display")
3977 (gnus-mime-view-part "v" "View Interactively...")
3978 (gnus-mime-view-part-as-type "t" "View As Type...")
3979 (gnus-mime-view-part-as-charset "C" "View As charset...")
3980 (gnus-mime-save-part "o" "Save...")
3981 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
3982 (gnus-mime-delete-part "d" "Delete part")
3983 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
3984 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
3985 (gnus-mime-view-part-internally "E" "View Internally")
3986 (gnus-mime-view-part-externally "e" "View Externally")
3987 (gnus-mime-print-part "p" "Print")
3988 (gnus-mime-pipe-part "|" "Pipe To Command...")
3989 (gnus-mime-action-on-part "." "Take action on the part...")))
3991 (defun gnus-article-mime-part-status ()
3992 (if gnus-article-mime-handle-alist-1
3993 (if (eq 1 (length gnus-article-mime-handle-alist-1))
3995 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
3998 (defvar gnus-mime-button-map
3999 (let ((map (make-sparse-keymap)))
4000 (define-key map gnus-mouse-2 'gnus-article-push-button)
4001 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4002 (dolist (c gnus-mime-button-commands)
4003 (define-key map (cadr c) (car c)))
4007 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4009 ,@(mapcar (lambda (c)
4010 (vector (caddr c) (car c) :enable t))
4011 gnus-mime-button-commands)))
4013 (defun gnus-mime-button-menu (event prefix)
4014 "Construct a context-sensitive menu of MIME commands."
4015 (interactive "e\nP")
4016 (save-window-excursion
4017 (let ((pos (event-start event)))
4018 (select-window (posn-window pos))
4019 (goto-char (posn-point pos))
4020 (gnus-article-check-buffer)
4021 (popup-menu gnus-mime-button-menu nil prefix))))
4023 (defun gnus-mime-view-all-parts (&optional handles)
4024 "View all the MIME parts."
4026 (with-current-buffer gnus-article-buffer
4027 (let ((handles (or handles gnus-article-mime-handles))
4028 (mail-parse-charset gnus-newsgroup-charset)
4029 (mail-parse-ignored-charsets
4030 (with-current-buffer gnus-summary-buffer
4031 gnus-newsgroup-ignored-charsets)))
4033 (mm-remove-parts handles)
4034 (goto-char (point-min))
4035 (or (search-forward "\n\n") (goto-char (point-max)))
4036 (let ((inhibit-read-only t))
4037 (delete-region (point) (point-max))
4038 (mm-display-parts handles))))))
4041 (defsubst gnus-article-edit-part (handles)
4042 "Edit an article in order to delete a mime part.
4043 This function is exclusively used by `gnus-mime-save-part-and-strip'
4044 and `gnus-mime-delete-part', and not provided at run-time normally."
4045 (gnus-article-edit-article
4048 (let ((mail-parse-charset (or gnus-article-charset
4049 ',gnus-newsgroup-charset))
4050 (mail-parse-ignored-charsets
4051 (or gnus-article-ignored-charsets
4052 ',gnus-newsgroup-ignored-charsets))
4053 (mbl mml-buffer-list))
4054 (setq mml-buffer-list nil)
4055 (insert-buffer gnus-original-article-buffer)
4056 (mime-to-mml ',handles)
4057 (setq gnus-article-mime-handles nil)
4058 (let ((mbl1 mml-buffer-list))
4059 (setq mml-buffer-list mbl)
4060 (set (make-local-variable 'mml-buffer-list) mbl1))
4061 (gnus-make-local-hook 'kill-buffer-hook)
4062 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4063 `(lambda (no-highlight)
4064 (let ((mail-parse-charset (or gnus-article-charset
4065 ',gnus-newsgroup-charset))
4066 (message-options message-options)
4067 (message-options-set-recipient)
4068 (mail-parse-ignored-charsets
4069 (or gnus-article-ignored-charsets
4070 ',gnus-newsgroup-ignored-charsets)))
4072 (mml-destroy-buffers)
4073 (remove-hook 'kill-buffer-hook
4074 'mml-destroy-buffers t)
4075 (kill-local-variable 'mml-buffer-list))
4076 (gnus-summary-edit-article-done
4077 ,(or (mail-header-references gnus-current-headers) "")
4078 ,(gnus-group-read-only-p)
4079 ,gnus-summary-buffer no-highlight)))
4080 (gnus-article-edit-done)
4081 (gnus-summary-expand-window)
4082 (gnus-summary-show-article)))
4084 (defun gnus-mime-save-part-and-strip ()
4085 "Save the MIME part under point then replace it with an external body."
4087 (gnus-article-check-buffer)
4088 (when (gnus-group-read-only-p)
4089 (error "The current group does not support deleting of parts"))
4090 (when (mm-complicated-handles gnus-article-mime-handles)
4092 The current article has a complicated MIME structure, giving up..."))
4093 (when (gnus-yes-or-no-p "\
4094 Deleting parts may malfunction or destroy the article; continue? ")
4095 (let* ((data (get-text-property (point) 'gnus-data))
4097 (handles gnus-article-mime-handles))
4098 (setq file (and data (mm-save-part data)))
4100 (with-current-buffer (mm-handle-buffer data)
4102 (insert "Content-Type: " (mm-handle-media-type data))
4103 (mml-insert-parameter-string (cdr (mm-handle-type data))
4106 (insert "Content-ID: " (message-make-message-id) "\n")
4107 (insert "Content-Transfer-Encoding: binary\n")
4110 (cdr (mm-make-handle nil
4111 `("message/external-body"
4112 (access-type . "LOCAL-FILE")
4114 (set-buffer gnus-summary-buffer)
4115 (gnus-article-edit-part handles)))))
4117 (defun gnus-mime-delete-part ()
4118 "Delete the MIME part under point.
4119 Replace it with some information about the removed part."
4121 (gnus-article-check-buffer)
4122 (when (gnus-group-read-only-p)
4123 (error "The current group does not support deleting of parts"))
4124 (when (mm-complicated-handles gnus-article-mime-handles)
4126 The current article has a complicated MIME structure, giving up..."))
4127 (when (gnus-yes-or-no-p "\
4128 Deleting parts may malfunction or destroy the article; continue? ")
4129 (let* ((data (get-text-property (point) 'gnus-data))
4130 (handles gnus-article-mime-handles)
4134 (mail-decode-encoded-word-string (or (mm-handle-description data)
4137 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
4139 (type (mm-handle-media-type data)))
4141 (error "No MIME part under point"))
4142 (with-current-buffer (mm-handle-buffer data)
4143 (let ((bsize (format "%s" (buffer-size))))
4148 "| The following attachment has been deleted:\n"
4150 "| Type: " type "\n"
4151 "| Filename: " filename "\n"
4152 "| Size (encoded): " bsize " Byte\n"
4153 "| Description: " description "\n"
4156 (cdr (mm-make-handle
4157 nil `("text/plain") nil nil
4159 (format "Deleted attachment (%s bytes)" bsize))))))
4160 (set-buffer gnus-summary-buffer)
4161 (gnus-article-edit-part handles))))
4163 (defun gnus-mime-save-part ()
4164 "Save the MIME part under point."
4166 (gnus-article-check-buffer)
4167 (let ((data (get-text-property (point) 'gnus-data)))
4169 (mm-save-part data))))
4171 (defun gnus-mime-pipe-part ()
4172 "Pipe the MIME part under point to a process."
4174 (gnus-article-check-buffer)
4175 (let ((data (get-text-property (point) 'gnus-data)))
4177 (mm-pipe-part data))))
4179 (defun gnus-mime-view-part ()
4180 "Interactively choose a viewing method for the MIME part under point."
4182 (gnus-article-check-buffer)
4183 (let ((data (get-text-property (point) 'gnus-data)))
4185 (setq gnus-article-mime-handles
4187 gnus-article-mime-handles (setq data (copy-sequence data))))
4188 (mm-interactively-view-part data))))
4190 (defun gnus-mime-view-part-as-type-internal ()
4191 (gnus-article-check-buffer)
4192 (let* ((name (mail-content-type-get
4193 (mm-handle-type (get-text-property (point) 'gnus-data))
4195 (def-type (and name (mm-default-file-encoding name))))
4196 (and def-type (cons def-type 0))))
4198 (defun gnus-mime-view-part-as-type (&optional mime-type)
4199 "Choose a MIME media type, and view the part as such."
4202 (setq mime-type (completing-read
4203 "View as MIME type: "
4204 (mapcar #'list (mailcap-mime-types))
4206 (gnus-mime-view-part-as-type-internal))))
4207 (gnus-article-check-buffer)
4208 (let ((handle (get-text-property (point) 'gnus-data)))
4211 (mm-make-handle (mm-handle-buffer handle)
4212 (cons mime-type (cdr (mm-handle-type handle)))
4213 (mm-handle-encoding handle)
4214 (mm-handle-undisplayer handle)
4215 (mm-handle-disposition handle)
4216 (mm-handle-description handle)
4218 (mm-handle-id handle)))
4219 (setq gnus-article-mime-handles
4220 (mm-merge-handles gnus-article-mime-handles handle))
4221 (gnus-mm-display-part handle))))
4224 (require 'jka-compr))
4226 ;; jka-compr.el uses a "sh -c" to direct stderr to err-file, but these days
4227 ;; emacs can do that itself.
4229 (defun gnus-mime-jka-compr-maybe-uncompress ()
4230 "Uncompress the current buffer if `auto-compression-mode' is enabled.
4231 The uncompress method used is derived from `buffer-file-name'."
4232 (when (and (fboundp 'jka-compr-installed-p)
4233 (jka-compr-installed-p))
4234 (let ((info (jka-compr-get-compression-info buffer-file-name)))
4236 (let ((basename (file-name-nondirectory buffer-file-name))
4237 (args (jka-compr-info-uncompress-args info))
4238 (prog (jka-compr-info-uncompress-program info))
4239 (message (jka-compr-info-uncompress-message info))
4240 (err-file (jka-compr-make-temp-name)))
4242 (message "%s %s..." message basename))
4244 (unless (memq (apply 'call-process-region
4245 (point-min) (point-max)
4247 t (list t err-file) nil
4249 jka-compr-acceptable-retval-list)
4250 (jka-compr-error prog args basename message err-file))
4251 (jka-compr-delete-temp-file err-file)))))))
4253 (defun gnus-mime-copy-part (&optional handle)
4254 "Put the MIME part under point into a new buffer.
4255 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
4258 (gnus-article-check-buffer)
4259 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4260 (contents (and handle (mm-get-part handle)))
4262 (file-name-nondirectory
4264 (mail-content-type-get (mm-handle-type handle) 'name)
4265 (mail-content-type-get (mm-handle-disposition handle)
4268 (buffer (and base (generate-new-buffer base))))
4270 (switch-to-buffer buffer)
4272 ;; We do it this way to make `normal-mode' set the appropriate mode.
4275 (setq buffer-file-name (expand-file-name base))
4276 (gnus-mime-jka-compr-maybe-uncompress)
4278 (setq buffer-file-name nil))
4279 (goto-char (point-min)))))
4281 (defun gnus-mime-print-part (&optional handle filename)
4282 "Print the MIME part under point."
4283 (interactive (list nil (ps-print-preprint current-prefix-arg)))
4284 (gnus-article-check-buffer)
4285 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4286 (contents (and handle (mm-get-part handle)))
4287 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
4288 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
4293 (mm-save-part-to-file handle file)
4294 (call-process shell-file-name nil
4295 (generate-new-buffer " *mm*")
4297 shell-command-switch
4299 printer file (mm-handle-type handle))))
4303 (gnus-print-buffer))
4304 (ps-despool filename)))))
4306 (defun gnus-mime-inline-part (&optional handle arg)
4307 "Insert the MIME part under point into the current buffer."
4308 (interactive (list nil current-prefix-arg))
4309 (gnus-article-check-buffer)
4310 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4313 (inhibit-read-only t))
4315 (if (and (not arg) (mm-handle-undisplayer handle))
4316 (mm-remove-part handle)
4317 (setq contents (mm-get-part handle))
4320 (setq charset (or (mail-content-type-get
4321 (mm-handle-type handle) 'charset)
4322 gnus-newsgroup-charset)))
4324 (if (mm-handle-undisplayer handle)
4325 (mm-remove-part handle))
4328 gnus-summary-show-article-charset-alist))
4329 (mm-read-coding-system "Charset: ")))))
4331 (mm-insert-inline handle
4333 (setq charset (mm-charset-to-coding-system
4335 (not (eq charset 'ascii)))
4336 (mm-decode-coding-string contents charset)
4340 (defun gnus-mime-view-part-as-charset (&optional handle arg)
4341 "Insert the MIME part under point into the current buffer using the
4343 (interactive (list nil current-prefix-arg))
4344 (gnus-article-check-buffer)
4345 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4348 (inhibit-read-only t))
4350 (if (mm-handle-undisplayer handle)
4351 (mm-remove-part handle))
4352 (let ((gnus-newsgroup-charset
4354 gnus-summary-show-article-charset-alist))
4355 (mm-read-coding-system "Charset: ")))
4356 (gnus-newsgroup-ignored-charsets 'gnus-all))
4357 (gnus-article-press-button)))))
4359 (defun gnus-mime-view-part-externally (&optional handle)
4360 "View the MIME part under point with an external viewer."
4362 (gnus-article-check-buffer)
4363 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4364 (mm-user-display-methods nil)
4365 (mm-inlined-types nil)
4366 (mail-parse-charset gnus-newsgroup-charset)
4367 (mail-parse-ignored-charsets
4368 (with-current-buffer gnus-summary-buffer
4369 gnus-newsgroup-ignored-charsets)))
4371 (if (mm-handle-undisplayer handle)
4372 (mm-remove-part handle)
4373 (mm-display-part handle)))))
4375 (defun gnus-mime-view-part-internally (&optional handle)
4376 "View the MIME part under point with an internal viewer.
4377 If no internal viewer is available, use an external viewer."
4379 (gnus-article-check-buffer)
4380 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
4381 (mm-inlined-types '(".*"))
4382 (mm-inline-large-images t)
4383 (mail-parse-charset gnus-newsgroup-charset)
4384 (mail-parse-ignored-charsets
4385 (with-current-buffer gnus-summary-buffer
4386 gnus-newsgroup-ignored-charsets))
4387 (inhibit-read-only t))
4389 (if (mm-handle-undisplayer handle)
4390 (mm-remove-part handle)
4391 (mm-display-part handle)))))
4393 (defun gnus-mime-action-on-part (&optional action)
4394 "Do something with the MIME attachment at \(point\)."
4396 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
4397 (gnus-article-check-buffer)
4398 (let ((action-pair (assoc action gnus-mime-action-alist)))
4400 (funcall (cdr action-pair)))))
4402 (defun gnus-article-part-wrapper (n function)
4403 (with-current-buffer gnus-article-buffer
4404 (when (> n (length gnus-article-mime-handle-alist))
4405 (error "No such part"))
4406 (gnus-article-goto-part n)
4407 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4408 (funcall function handle))))
4410 (defun gnus-article-pipe-part (n)
4411 "Pipe MIME part N, which is the numerical prefix."
4413 (gnus-article-part-wrapper n 'mm-pipe-part))
4415 (defun gnus-article-save-part (n)
4416 "Save MIME part N, which is the numerical prefix."
4418 (gnus-article-part-wrapper n 'mm-save-part))
4420 (defun gnus-article-interactively-view-part (n)
4421 "View MIME part N interactively, which is the numerical prefix."
4423 (gnus-article-part-wrapper n 'mm-interactively-view-part))
4425 (defun gnus-article-copy-part (n)
4426 "Copy MIME part N, which is the numerical prefix."
4428 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
4430 (defun gnus-article-view-part-as-charset (n)
4431 "View MIME part N using a specified charset.
4432 N is the numerical prefix."
4434 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
4436 (defun gnus-article-view-part-externally (n)
4437 "View MIME part N externally, which is the numerical prefix."
4439 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
4441 (defun gnus-article-inline-part (n)
4442 "Inline MIME part N, which is the numerical prefix."
4444 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
4446 (defun gnus-article-mime-match-handle-first (condition)
4449 (dolist (ihandle gnus-article-mime-handle-alist)
4451 ((functionp condition)
4452 (funcall condition (cdr ihandle)))
4453 ((eq condition 'undisplayed)
4454 (not (or (mm-handle-undisplayer (cdr ihandle))
4455 (equal (mm-handle-media-type (cdr ihandle))
4456 "multipart/alternative"))))
4457 ((eq condition 'undisplayed-alternative)
4458 (not (mm-handle-undisplayer (cdr ihandle))))
4460 (gnus-article-goto-part (car ihandle))
4461 (or (not n) (< (car ihandle) n)))
4462 (setq n (car ihandle))))
4466 (defun gnus-article-view-part (&optional n)
4467 "View MIME part N, which is the numerical prefix."
4469 (with-current-buffer gnus-article-buffer
4470 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
4471 gnus-article-mime-match-handle-function)))
4472 (when (> n (length gnus-article-mime-handle-alist))
4473 (error "No such part"))
4474 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
4475 (when (gnus-article-goto-part n)
4476 (if (equal (car handle) "multipart/alternative")
4477 (gnus-article-press-button)
4478 (when (eq (gnus-mm-display-part handle) 'internal)
4479 (gnus-set-window-start)))))))
4481 (defsubst gnus-article-mime-total-parts ()
4482 (if (bufferp (car gnus-article-mime-handles))
4484 (1- (length gnus-article-mime-handles))))
4486 (defun gnus-mm-display-part (handle)
4487 "Display HANDLE and fix MIME button."
4488 (let ((id (get-text-property (point) 'gnus-part))
4490 (inhibit-read-only t))
4493 (let ((window (selected-window))
4494 (mail-parse-charset gnus-newsgroup-charset)
4495 (mail-parse-ignored-charsets
4496 (if (gnus-buffer-live-p gnus-summary-buffer)
4497 (with-current-buffer gnus-summary-buffer
4498 gnus-newsgroup-ignored-charsets)
4502 (let ((win (gnus-get-buffer-window (current-buffer) t))
4505 (select-window win))
4508 (if (mm-handle-displayed-p handle)
4509 ;; This will remove the part.
4510 (mm-display-part handle)
4512 (narrow-to-region (point)
4513 (if (eobp) (point) (1+ (point))))
4514 (mm-display-part handle)
4515 ;; We narrow to the part itself and
4516 ;; then call the treatment functions.
4517 (goto-char (point-min))
4519 (narrow-to-region (point) (point-max))
4522 (gnus-article-mime-total-parts)
4523 (mm-handle-media-type handle)))))
4524 (if (window-live-p window)
4525 (select-window window)))))
4528 (gnus-insert-mime-button
4529 handle id (list (mm-handle-displayed-p handle)))
4530 (goto-char point))))
4532 (defun gnus-article-goto-part (n)
4533 "Go to MIME part N."
4534 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
4536 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
4537 (let ((gnus-tmp-name
4538 (or (mail-content-type-get (mm-handle-type handle) 'name)
4539 (mail-content-type-get (mm-handle-disposition handle) 'filename)
4540 (mail-content-type-get (mm-handle-type handle) 'url)
4542 (gnus-tmp-type (mm-handle-media-type handle))
4543 (gnus-tmp-description
4544 (mail-decode-encoded-word-string (or (mm-handle-description handle)
4547 (if (if displayed (car displayed)
4548 (mm-handle-displayed-p handle))
4550 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
4552 gnus-tmp-type-long b e)
4553 (when (string-match ".*/" gnus-tmp-name)
4554 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
4555 (setq gnus-tmp-type-long (concat gnus-tmp-type
4556 (and (not (equal gnus-tmp-name ""))
4557 (concat "; " gnus-tmp-name))))
4558 (unless (equal gnus-tmp-description "")
4559 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
4564 gnus-mime-button-line-format gnus-mime-button-line-format-alist
4565 `(keymap ,gnus-mime-button-map
4566 gnus-callback gnus-mm-display-part
4567 gnus-part ,gnus-tmp-id
4568 article-type annotation
4571 ;; Exclude a newline.
4574 (widget-convert-button
4577 :action 'gnus-widget-press-button
4578 :button-keymap gnus-mime-button-map
4580 (lambda (widget/window &optional overlay pos)
4581 ;; Needed to properly clear the message due to a bug in
4582 ;; wid-edit (XEmacs only).
4583 (if (boundp 'help-echo-owns-message)
4584 (setq help-echo-owns-message t))
4586 "%S: %s the MIME part; %S: more options"
4587 (aref gnus-mouse-2 0)
4588 ;; XEmacs will get a single widget arg; Emacs 21 will get
4589 ;; window, overlay, position.
4590 (if (mm-handle-displayed-p
4592 (with-current-buffer (gnus-overlay-buffer overlay)
4593 (widget-get (widget-at (gnus-overlay-start overlay))
4595 (widget-get widget/window :mime-handle)))
4597 (aref gnus-down-mouse-3 0))))))
4599 (defun gnus-widget-press-button (elems el)
4600 (goto-char (widget-get elems :from))
4601 (gnus-article-press-button))
4603 (defvar gnus-displaying-mime nil)
4605 (defun gnus-display-mime (&optional ihandles)
4606 "Display the MIME parts."
4608 (save-selected-window
4609 (let ((window (get-buffer-window gnus-article-buffer))
4612 (select-window window)
4613 ;; We have to do this since selecting the window
4614 ;; may change the point. So we set the window point.
4615 (set-window-point window point)))
4616 (let ((handles ihandles)
4617 (inhibit-read-only t)
4618 handle name type b e display)
4620 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
4621 (when gnus-article-emulate-mime
4622 (mm-uu-dissect-text-parts handles)))
4623 (gnus-article-emulate-mime
4624 (setq handles (mm-uu-dissect))))
4625 (when (and (not ihandles)
4626 (not gnus-displaying-mime))
4627 ;; Top-level call; we clean up.
4628 (when gnus-article-mime-handles
4629 (mm-destroy-parts gnus-article-mime-handles)
4630 (setq gnus-article-mime-handle-alist nil));; A trick.
4631 (setq gnus-article-mime-handles handles)
4632 ;; We allow users to glean info from the handles.
4633 (when gnus-article-mime-part-function
4634 (gnus-mime-part-function handles)))
4636 (or (not (stringp (car handles)))
4639 (when (and (not ihandles)
4640 (not gnus-displaying-mime))
4641 ;; Clean up for mime parts.
4643 (delete-region (point) (point-max)))
4644 (let ((gnus-displaying-mime t))
4645 (gnus-mime-display-part handles)))
4648 (narrow-to-region (point) (point-max))
4649 (gnus-treat-article nil 1 1)
4652 ;; Highlight the headers.
4656 (narrow-to-region (point-min) (point))
4657 (gnus-treat-article 'head))))))))
4659 (defcustom gnus-mime-display-multipart-as-mixed nil
4660 "Display \"multipart\" parts as \"multipart/mixed\".
4662 If t, it overrides nil values of
4663 `gnus-mime-display-multipart-alternative-as-mixed' and
4664 `gnus-mime-display-multipart-related-as-mixed'."
4665 :group 'gnus-article-mime
4668 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
4669 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
4671 :group 'gnus-article-mime
4674 (defcustom gnus-mime-display-multipart-related-as-mixed nil
4675 "Display \"multipart/related\" parts as \"multipart/mixed\".
4677 If displaying \"text/html\" is discouraged \(see
4678 `mm-discouraged-alternatives'\) images or other material inside a
4679 \"multipart/related\" part might be overlooked when this variable is nil."
4681 :group 'gnus-article-mime
4684 (defun gnus-mime-display-part (handle)
4687 ((not (stringp (car handle)))
4688 (gnus-mime-display-single handle))
4689 ;; User-defined multipart
4690 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
4691 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
4693 ;; multipart/alternative
4694 ((and (equal (car handle) "multipart/alternative")
4695 (not (or gnus-mime-display-multipart-as-mixed
4696 gnus-mime-display-multipart-alternative-as-mixed)))
4697 (let ((id (1+ (length gnus-article-mime-handle-alist))))
4698 (push (cons id handle) gnus-article-mime-handle-alist)
4699 (gnus-mime-display-alternative (cdr handle) nil nil id)))
4700 ;; multipart/related
4701 ((and (equal (car handle) "multipart/related")
4702 (not (or gnus-mime-display-multipart-as-mixed
4703 gnus-mime-display-multipart-related-as-mixed)))
4704 ;;;!!!We should find the start part, but we just default
4705 ;;;!!!to the first part.
4706 ;;(gnus-mime-display-part (cadr handle))
4707 ;;;!!! Most multipart/related is an HTML message plus images.
4708 ;;;!!! Unfortunately we are unable to let W3 display those
4709 ;;;!!! included images, so we just display it as a mixed multipart.
4710 ;;(gnus-mime-display-mixed (cdr handle))
4711 ;;;!!! No, w3 can display everything just fine.
4712 (gnus-mime-display-part (cadr handle)))
4713 ((equal (car handle) "multipart/signed")
4714 (gnus-add-wash-type 'signed)
4715 (gnus-mime-display-security handle))
4716 ((equal (car handle) "multipart/encrypted")
4717 (gnus-add-wash-type 'encrypted)
4718 (gnus-mime-display-security handle))
4719 ;; Other multiparts are handled like multipart/mixed.
4721 (gnus-mime-display-mixed (cdr handle)))))
4723 (defun gnus-mime-part-function (handles)
4724 (if (stringp (car handles))
4725 (mapcar 'gnus-mime-part-function (cdr handles))
4726 (funcall gnus-article-mime-part-function handles)))
4728 (defun gnus-mime-display-mixed (handles)
4729 (mapcar 'gnus-mime-display-part handles))
4731 (defun gnus-mime-display-single (handle)
4732 (let ((type (mm-handle-media-type handle))
4733 (ignored gnus-ignored-mime-types)
4740 (when (string-match (pop ignored) type)
4741 (throw 'ignored nil)))
4742 (if (and (setq not-attachment
4743 (and (not (mm-inline-override-p handle))
4744 (or (not (mm-handle-disposition handle))
4745 (equal (car (mm-handle-disposition handle))
4747 (mm-attachment-override-p handle))))
4748 (mm-automatic-display-p handle)
4750 (mm-inlinable-p handle)
4751 (mm-inlined-p handle))
4752 (mm-automatic-external-display-p type)))
4754 (when (equal (mm-handle-media-supertype handle) "text")
4756 (let ((id (1+ (length gnus-article-mime-handle-alist)))
4758 (push (cons id handle) gnus-article-mime-handle-alist)
4759 (when (or (not display)
4760 (not (gnus-unbuttonized-mime-type-p type)))
4761 (gnus-insert-mime-button
4762 handle id (list (or display (and not-attachment text))))
4763 (gnus-article-insert-newline)
4764 ;; Remember modify the number of forward lines.
4772 (let ((mail-parse-charset gnus-newsgroup-charset)
4773 (mail-parse-ignored-charsets
4774 (save-excursion (condition-case ()
4775 (set-buffer gnus-summary-buffer)
4777 gnus-newsgroup-ignored-charsets)))
4778 (mm-display-part handle t))
4779 (goto-char (point-max)))
4780 ((and text not-attachment)
4784 (gnus-article-insert-newline)
4785 (mm-display-inline handle)
4786 (goto-char (point-max))))
4790 (narrow-to-region beg (point))
4793 (gnus-article-mime-total-parts)
4794 (mm-handle-media-type handle)))))))))
4796 (defun gnus-unbuttonized-mime-type-p (type)
4797 "Say whether TYPE is to be unbuttonized."
4798 (unless gnus-inhibit-mime-unbuttonizing
4800 (let ((types gnus-unbuttonized-mime-types))
4802 (when (string-match (pop types) type)
4803 (throw 'found t)))))
4805 (let ((types gnus-buttonized-mime-types))
4807 (when (string-match (pop types) type)
4808 (throw 'found t)))))))))
4810 (defun gnus-article-insert-newline ()
4811 "Insert a newline, but mark it as undeletable."
4812 (gnus-put-text-property
4813 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
4815 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
4816 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
4819 handle (inhibit-read-only t) from props begend not-pref)
4820 (save-window-excursion
4823 (narrow-to-region (car ibegend)
4826 (goto-char (car ibegend))
4829 (delete-region (point-min) (point-max))
4830 (mm-remove-parts handles))
4831 (setq begend (list (point-marker)))
4833 (unless (setq not-pref (cadr (member preferred ihandles)))
4834 (setq not-pref (car ihandles)))
4837 (not (gnus-unbuttonized-mime-type-p
4838 "multipart/alternative")))
4839 (gnus-add-text-properties
4842 (insert (format "%d. " id))
4846 (unless ,(not ibegend)
4847 (setq gnus-article-mime-handle-alist
4848 ',gnus-article-mime-handle-alist))
4849 (gnus-mime-display-alternative
4850 ',ihandles ',not-pref ',begend ,id))
4851 keymap ,gnus-mime-button-map
4852 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4853 face ,gnus-article-button-face
4856 (widget-convert-button 'link from (point)
4857 :action 'gnus-widget-press-button
4858 :button-keymap gnus-widget-button-keymap)
4860 (while (setq handle (pop handles))
4861 (gnus-add-text-properties
4864 (insert (format "(%c) %-18s"
4865 (if (equal handle preferred) ?* ? )
4866 (mm-handle-media-type handle)))
4870 (unless ,(not ibegend)
4871 (setq gnus-article-mime-handle-alist
4872 ',gnus-article-mime-handle-alist))
4873 (gnus-mime-display-alternative
4874 ',ihandles ',handle ',begend ,id))
4875 keymap ,gnus-mime-button-map
4876 ,gnus-mouse-face-prop ,gnus-article-mouse-face
4877 face ,gnus-article-button-face
4880 (widget-convert-button 'link from (point)
4881 :action 'gnus-widget-press-button
4882 :button-keymap gnus-widget-button-keymap)
4886 (if (stringp (car preferred))
4887 (gnus-display-mime preferred)
4888 (let ((mail-parse-charset gnus-newsgroup-charset)
4889 (mail-parse-ignored-charsets
4890 (with-current-buffer gnus-summary-buffer
4891 gnus-newsgroup-ignored-charsets)))
4892 (mm-display-part preferred)
4896 (narrow-to-region (car begend) (point-max))
4898 nil (length gnus-article-mime-handle-alist)
4899 (gnus-article-mime-total-parts)
4900 (mm-handle-media-type handle))))))
4901 (goto-char (point-max))
4902 (setcdr begend (point-marker)))))
4904 (goto-char point))))
4906 (defconst gnus-article-wash-status-strings
4907 (let ((alist '((cite "c" "Possible hidden citation text"
4908 " " "All citation text visible")
4909 (headers "h" "Hidden headers"
4910 " " "All headers visible.")
4911 (pgp "p" "Encrypted or signed message status hidden"
4912 " " "No hidden encryption nor digital signature status")
4913 (signature "s" "Signature has been hidden"
4914 " " "Signature is visible")
4915 (overstrike "o" "Overstrike (^H) characters applied"
4916 " " "No overstrike characters applied")
4917 (emphasis "e" "/*_Emphasis_*/ characters applied"
4918 " " "No /*_emphasis_*/ characters applied")))
4920 (dolist (entry alist result)
4921 (let ((key (nth 0 entry))
4922 (on (copy-sequence (nth 1 entry)))
4923 (on-help (nth 2 entry))
4924 (off (copy-sequence (nth 3 entry)))
4925 (off-help (nth 4 entry)))
4926 (put-text-property 0 1 'help-echo on-help on)
4927 (put-text-property 0 1 'help-echo off-help off)
4928 (push (list key on off) result))))
4929 "Alist of strings describing wash status in the mode line.
4930 Each entry has the form (KEY ON OF), where the KEY is a symbol
4931 representing the particular washing function, ON is the string to use
4932 in the article mode line when the washing function is active, and OFF
4933 is the string to use when it is inactive.")
4935 (defun gnus-article-wash-status-entry (key value)
4936 (let ((entry (assoc key gnus-article-wash-status-strings)))
4937 (if value (nth 1 entry) (nth 2 entry))))
4939 (defun gnus-article-wash-status ()
4940 "Return a string which display status of article washing."
4941 (with-current-buffer gnus-article-buffer
4942 (let ((cite (memq 'cite gnus-article-wash-types))
4943 (headers (memq 'headers gnus-article-wash-types))
4944 (boring (memq 'boring-headers gnus-article-wash-types))
4945 (pgp (memq 'pgp gnus-article-wash-types))
4946 (pem (memq 'pem gnus-article-wash-types))
4947 (signed (memq 'signed gnus-article-wash-types))
4948 (encrypted (memq 'encrypted gnus-article-wash-types))
4949 (signature (memq 'signature gnus-article-wash-types))
4950 (overstrike (memq 'overstrike gnus-article-wash-types))
4951 (emphasis (memq 'emphasis gnus-article-wash-types)))
4953 (gnus-article-wash-status-entry 'cite cite)
4954 (gnus-article-wash-status-entry 'headers (or headers boring))
4955 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
4956 (gnus-article-wash-status-entry 'signature signature)
4957 (gnus-article-wash-status-entry 'overstrike overstrike)
4958 (gnus-article-wash-status-entry 'emphasis emphasis)))))
4960 (defun gnus-add-wash-type (type)
4961 "Add a washing of TYPE to the current status."
4962 (add-to-list 'gnus-article-wash-types type))
4964 (defun gnus-delete-wash-type (type)
4965 "Add a washing of TYPE to the current status."
4966 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
4968 (defun gnus-add-image (category image)
4969 "Add IMAGE of CATEGORY to the list of displayed images."
4970 (let ((entry (assq category gnus-article-image-alist)))
4972 (setq entry (list category))
4973 (push entry gnus-article-image-alist))
4974 (nconc entry (list image))))
4976 (defun gnus-delete-images (category)
4977 "Delete all images in CATEGORY."
4978 (let ((entry (assq category gnus-article-image-alist)))
4979 (dolist (image (cdr entry))
4980 (gnus-remove-image image category))
4981 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
4982 (gnus-delete-wash-type category)))
4984 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
4986 (defun gnus-article-maybe-hide-headers ()
4987 "Hide unwanted headers if `gnus-have-all-headers' is nil.
4988 Provided for backwards compatibility."
4989 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
4990 (not (with-current-buffer gnus-summary-buffer
4991 gnus-have-all-headers)))
4992 (not gnus-inhibit-hiding))
4993 (gnus-article-hide-headers)))
4997 (defun gnus-output-to-file (file-name)
4998 "Append the current article to a file named FILE-NAME."
4999 (let ((artbuf (current-buffer)))
5001 (insert-buffer-substring artbuf)
5002 ;; Append newline at end of the buffer as separator, and then
5004 (goto-char (point-max))
5006 (let ((file-name-coding-system nnmail-pathname-coding-system))
5007 (mm-append-to-file (point-min) (point-max) file-name))
5010 (defun gnus-narrow-to-page (&optional arg)
5011 "Narrow the article buffer to a page.
5012 If given a numerical ARG, move forward ARG pages."
5014 (setq arg (if arg (prefix-numeric-value arg) 0))
5016 (set-buffer gnus-article-buffer)
5017 (goto-char (point-min))
5019 ;; Remove any old next/prev buttons.
5020 (when (gnus-visual-p 'page-marker)
5021 (let ((inhibit-read-only t))
5022 (gnus-remove-text-with-property 'gnus-prev)
5023 (gnus-remove-text-with-property 'gnus-next)))
5026 (re-search-backward page-delimiter nil 'move (1+ (abs arg))))
5028 (re-search-forward page-delimiter nil 'move arg)))
5029 (goto-char (match-end 0))
5031 (goto-char (point-min))
5032 (setq gnus-page-broken
5033 (and (re-search-forward page-delimiter nil t) t))))
5034 (when gnus-page-broken
5037 (if (re-search-forward page-delimiter nil 'move)
5040 (when (and (gnus-visual-p 'page-marker)
5041 (> (point-min) (save-restriction (widen) (point-min))))
5043 (goto-char (point-min))
5044 (gnus-insert-prev-page-button)))
5045 (when (and (gnus-visual-p 'page-marker)
5046 (< (+ (point-max) 2) (buffer-size)))
5048 (goto-char (point-max))
5049 (gnus-insert-next-page-button))))))
5051 ;; Article mode commands
5053 (defun gnus-article-goto-next-page ()
5054 "Show the next page of the article."
5056 (when (gnus-article-next-page)
5057 (goto-char (point-min))
5058 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
5061 (defun gnus-article-goto-prev-page ()
5062 "Show the previous page of the article."
5065 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
5066 (gnus-article-prev-page nil)))
5068 ;; This is cleaner but currently breaks `gnus-pick-mode':
5070 ;; (defun gnus-article-goto-next-page ()
5071 ;; "Show the next page of the article."
5073 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5074 ;; (gnus-summary-next-page)))
5076 ;; (defun gnus-article-goto-prev-page ()
5077 ;; "Show the next page of the article."
5079 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
5080 ;; (gnus-summary-prev-page)))
5082 (defun gnus-article-next-page (&optional lines)
5083 "Show the next page of the current article.
5084 If end of article, return non-nil. Otherwise return nil.
5085 Argument LINES specifies lines to be scrolled up."
5087 (move-to-window-line -1)
5090 (and (pos-visible-in-window-p) ;Not continuation line.
5091 (>= (1+ (point)) (point-max)))) ;Allow for trailing newline.
5092 ;; Nothing in this page.
5093 (if (or (not gnus-page-broken)
5098 (eobp)))) ;Real end-of-buffer?
5100 (when gnus-article-over-scroll
5101 (gnus-article-next-page-1 lines))
5103 (gnus-narrow-to-page 1) ;Go to next page.
5105 ;; More in this page.
5106 (gnus-article-next-page-1 lines)
5109 (defun gnus-article-next-page-1 (lines)
5110 (let ((scroll-in-place nil))
5114 ;; Long lines may cause an end-of-buffer error.
5115 (goto-char (point-max)))))
5116 (move-to-window-line 0))
5118 (defun gnus-article-prev-page (&optional lines)
5119 "Show previous page of current article.
5120 Argument LINES specifies lines to be scrolled down."
5122 (move-to-window-line 0)
5123 (if (and gnus-page-broken
5125 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
5127 (gnus-narrow-to-page -1) ;Go to previous page.
5128 (goto-char (point-max))
5130 (let ((scroll-in-place nil))
5134 (beginning-of-buffer
5135 (goto-char (point-min))))
5136 (move-to-window-line 0)))))
5138 (defun gnus-article-only-boring-p ()
5139 "Decide whether there is only boring text remaining in the article.
5140 Something \"interesting\" is a word of at least two letters that does
5141 not have a face in `gnus-article-boring-faces'."
5142 (when (and gnus-article-skip-boring
5143 (boundp 'gnus-article-boring-faces)
5144 (symbol-value 'gnus-article-boring-faces))
5147 (while (re-search-forward "\\b\\w\\w" nil t)
5149 (when (not (gnus-intersection
5150 (gnus-faces-at (point))
5151 (symbol-value 'gnus-article-boring-faces)))
5152 (throw 'only-boring nil)))
5153 (throw 'only-boring t)))))
5155 (defun gnus-article-refer-article ()
5156 "Read article specified by message-id around point."
5159 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
5160 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
5161 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
5162 (let ((msg-id (concat "<" (match-string 0) ">")))
5163 (set-buffer gnus-summary-buffer)
5164 (gnus-summary-refer-article msg-id))
5165 (error "No references around point"))))
5167 (defun gnus-article-show-summary ()
5168 "Reconfigure windows to show summary buffer."
5170 (if (not (gnus-buffer-live-p gnus-summary-buffer))
5171 (error "There is no summary buffer for this article buffer")
5172 (gnus-article-set-globals)
5173 (gnus-configure-windows 'article)
5174 (gnus-summary-goto-subject gnus-current-article)
5175 (gnus-summary-position-point)))
5177 (defun gnus-article-describe-briefly ()
5178 "Describe article mode commands briefly."
5180 (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")))
5182 (defun gnus-article-summary-command ()
5183 "Execute the last keystroke in the summary buffer."
5185 (let ((obuf (current-buffer))
5186 (owin (current-window-configuration))
5188 (switch-to-buffer gnus-article-current-summary 'norecord)
5189 (setq func (lookup-key (current-local-map) (this-command-keys)))
5190 (call-interactively func)
5192 (set-window-configuration owin)
5193 (set-window-point (get-buffer-window (current-buffer)) (point))))
5195 (defun gnus-article-summary-command-nosave ()
5196 "Execute the last keystroke in the summary buffer."
5199 (pop-to-buffer gnus-article-current-summary 'norecord)
5200 (setq func (lookup-key (current-local-map) (this-command-keys)))
5201 (call-interactively func)))
5203 (defun gnus-article-check-buffer ()
5204 "Beep if not in an article buffer."
5205 (unless (equal major-mode 'gnus-article-mode)
5206 (error "Command invoked outside of a Gnus article buffer")))
5208 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
5209 "Read a summary buffer key sequence and execute it from the article buffer."
5211 (gnus-article-check-buffer)
5213 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
5214 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
5215 "=" "^" "\M-^" "|"))
5221 '("n" "Gn" "p" "Gp"))
5224 (set-buffer gnus-article-current-summary)
5225 (let (gnus-pick-mode)
5226 (push (or key last-command-event) unread-command-events)
5227 (setq keys (if (featurep 'xemacs)
5228 (events-to-keys (read-key-sequence nil))
5229 (read-key-sequence nil)))))
5233 (if (or (member keys nosaves)
5234 (member keys nosave-but-article)
5235 (member keys nosave-in-article))
5237 (save-window-excursion
5238 (pop-to-buffer gnus-article-current-summary 'norecord)
5239 ;; We disable the pick minor mode commands.
5240 (let (gnus-pick-mode)
5241 (setq func (lookup-key (current-local-map) keys))))
5245 (unless (member keys nosave-in-article)
5246 (set-buffer gnus-article-current-summary))
5247 (call-interactively func)
5248 (setq new-sum-point (point)))
5249 (when (member keys nosave-but-article)
5250 (pop-to-buffer gnus-article-buffer 'norecord)))
5251 ;; These commands should restore window configuration.
5252 (let ((obuf (current-buffer))
5253 (owin (current-window-configuration))
5255 win func in-buffer selected new-sum-start new-sum-hscroll)
5256 (cond (not-restore-window
5257 (pop-to-buffer gnus-article-current-summary 'norecord))
5258 ((setq win (get-buffer-window gnus-article-current-summary))
5259 (select-window win))
5261 (switch-to-buffer gnus-article-current-summary 'norecord)))
5262 (setq in-buffer (current-buffer))
5263 ;; We disable the pick minor mode commands.
5264 (if (and (setq func (let (gnus-pick-mode)
5265 (lookup-key (current-local-map) keys)))
5268 (call-interactively func)
5269 (when (eq win (selected-window))
5270 (setq new-sum-point (point)
5271 new-sum-start (window-start win)
5272 new-sum-hscroll (window-hscroll win))
5273 (when (eq in-buffer (current-buffer))
5274 (setq selected (gnus-summary-select-article))
5276 (unless not-restore-window
5277 (set-window-configuration owin))
5278 (when (eq selected 'old)
5280 (set-window-start (get-buffer-window (current-buffer))
5282 (set-window-point (get-buffer-window (current-buffer))
5284 (when (and (not not-restore-window)
5286 (set-window-point win new-sum-point)
5287 (set-window-start win new-sum-start)
5288 (set-window-hscroll win new-sum-hscroll)))))
5289 (set-window-configuration owin)
5292 (defun gnus-article-describe-key (key)
5293 "Display documentation of the function invoked by KEY. KEY is a string."
5294 (interactive "kDescribe key: ")
5295 (gnus-article-check-buffer)
5296 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5298 (set-buffer gnus-article-current-summary)
5299 (let (gnus-pick-mode)
5300 (if (featurep 'xemacs)
5302 (push (elt key 0) unread-command-events)
5303 (setq key (events-to-keys
5304 (read-key-sequence "Describe key: "))))
5305 (setq unread-command-events
5307 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5308 (string-to-list key)))
5309 (setq key (read-key-sequence "Describe key: "))))
5311 (describe-key key)))
5313 (defun gnus-article-describe-key-briefly (key &optional insert)
5314 "Display documentation of the function invoked by KEY. KEY is a string."
5315 (interactive "kDescribe key: \nP")
5316 (gnus-article-check-buffer)
5317 (if (eq (key-binding key) 'gnus-article-read-summary-keys)
5319 (set-buffer gnus-article-current-summary)
5320 (let (gnus-pick-mode)
5321 (if (featurep 'xemacs)
5323 (push (elt key 0) unread-command-events)
5324 (setq key (events-to-keys
5325 (read-key-sequence "Describe key: "))))
5326 (setq unread-command-events
5328 (lambda (x) (if (>= x 128) (list 'meta (- x 128)) x))
5329 (string-to-list key)))
5330 (setq key (read-key-sequence "Describe key: "))))
5331 (describe-key-briefly key insert))
5332 (describe-key-briefly key insert)))
5334 (defun gnus-article-reply-with-original (&optional wide)
5335 "Start composing a reply mail to the current message.
5336 The text in the region will be yanked. If the region isn't active,
5337 the entire article will be yanked."
5339 (let ((article (cdr gnus-article-current))
5341 (if (not (gnus-region-active-p))
5342 (with-current-buffer gnus-summary-buffer
5343 (gnus-summary-reply (list (list article)) wide))
5344 (setq contents (buffer-substring (point) (mark t)))
5345 ;; Deactivate active regions.
5346 (when (and (boundp 'transient-mark-mode)
5347 transient-mark-mode)
5348 (setq mark-active nil))
5349 (with-current-buffer gnus-summary-buffer
5351 (list (list article contents)) wide)))))
5353 (defun gnus-article-followup-with-original ()
5354 "Compose a followup to the current article.
5355 The text in the region will be yanked. If the region isn't active,
5356 the entire article will be yanked."
5358 (let ((article (cdr gnus-article-current))
5360 (if (not (gnus-region-active-p))
5361 (with-current-buffer gnus-summary-buffer
5362 (gnus-summary-followup (list (list article))))
5363 (setq contents (buffer-substring (point) (mark t)))
5364 ;; Deactivate active regions.
5365 (when (and (boundp 'transient-mark-mode)
5366 transient-mark-mode)
5367 (setq mark-active nil))
5368 (with-current-buffer gnus-summary-buffer
5369 (gnus-summary-followup
5370 (list (list article contents)))))))
5372 (defun gnus-article-hide (&optional arg force)
5373 "Hide all the gruft in the current article.
5374 This means that signatures, cited text and (some) headers will be
5376 If given a prefix, show the hidden text instead."
5377 (interactive (append (gnus-article-hidden-arg) (list 'force)))
5378 (gnus-article-hide-headers arg)
5379 (gnus-article-hide-list-identifiers arg)
5380 (gnus-article-hide-citation-maybe arg force)
5381 (gnus-article-hide-signature arg))
5383 (defun gnus-article-maybe-highlight ()
5384 "Do some article highlighting if article highlighting is requested."
5385 (when (gnus-visual-p 'article-highlight 'highlight)
5386 (gnus-article-highlight-some)))
5388 (defun gnus-check-group-server ()
5389 ;; Make sure the connection to the server is alive.
5390 (unless (gnus-server-opened
5391 (gnus-find-method-for-group gnus-newsgroup-name))
5392 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
5393 (gnus-request-group gnus-newsgroup-name t)))
5396 (autoload 'nneething-get-file-name "nneething"))
5398 (defun gnus-request-article-this-buffer (article group)
5399 "Get an article and insert it into this buffer."
5400 (let (do-update-line sparse-header)
5404 (gnus-kill-all-overlays)
5405 (setq group (or group gnus-newsgroup-name))
5407 ;; Using `gnus-request-article' directly will insert the article into
5408 ;; `nntp-server-buffer' - so we'll save some time by not having to
5409 ;; copy it from the server buffer into the article buffer.
5411 ;; We only request an article by message-id when we do not have the
5412 ;; headers for it, so we'll have to get those.
5413 (when (stringp article)
5414 (gnus-read-header article))
5416 ;; If the article number is negative, that means that this article
5417 ;; doesn't belong in this newsgroup (possibly), so we find its
5418 ;; message-id and request it by id instead of number.
5419 (when (and (numberp article)
5421 (get-buffer gnus-summary-buffer)
5422 (gnus-buffer-exists-p gnus-summary-buffer))
5424 (set-buffer gnus-summary-buffer)
5425 (let ((header (gnus-summary-article-header article)))
5428 ((memq article gnus-newsgroup-sparse)
5429 ;; This is a sparse gap article.
5430 (setq do-update-line article)
5431 (setq article (mail-header-id header))
5432 (setq sparse-header (gnus-read-header article))
5433 (setq gnus-newsgroup-sparse
5434 (delq article gnus-newsgroup-sparse)))
5436 ;; It's a real article.
5437 (setq article (mail-header-id header)))
5439 ;; It is an extracted pseudo-article.
5440 (setq article 'pseudo)
5441 (gnus-request-pseudo-article header))))
5443 (let ((method (gnus-find-method-for-group
5444 gnus-newsgroup-name)))
5445 (when (and (eq (car method) 'nneething)
5447 (let ((dir (nneething-get-file-name
5448 (mail-header-id header))))
5449 (when (and (stringp dir)
5450 (file-directory-p dir))
5451 (setq article 'nneething)
5452 (gnus-group-enter-directory dir))))))))
5455 ;; Refuse to select canceled articles.
5456 ((and (numberp article)
5458 (get-buffer gnus-summary-buffer)
5459 (gnus-buffer-exists-p gnus-summary-buffer)
5460 (eq (cdr (with-current-buffer gnus-summary-buffer
5461 (assq article gnus-newsgroup-reads)))
5462 gnus-canceled-mark))
5464 ;; We first check `gnus-original-article-buffer'.
5465 ((and (get-buffer gnus-original-article-buffer)
5467 (with-current-buffer gnus-original-article-buffer
5468 (and (equal (car gnus-original-article) group)
5469 (eq (cdr gnus-original-article) article))))
5470 (insert-buffer-substring gnus-original-article-buffer)
5472 ;; Check the backlog.
5473 ((and gnus-keep-backlog
5474 (gnus-backlog-request-article group article (current-buffer)))
5476 ;; Check asynchronous pre-fetch.
5477 ((gnus-async-request-fetched-article group article (current-buffer))
5478 (gnus-async-prefetch-next group article gnus-summary-buffer)
5479 (when (and (numberp article) gnus-keep-backlog)
5480 (gnus-backlog-enter-article group article (current-buffer)))
5483 ((and gnus-use-cache
5485 (gnus-cache-request-article article group))
5487 ;; Check the agent cache.
5488 ((gnus-agent-request-article article group)
5490 ;; Get the article and put into the article buffer.
5491 ((or (stringp article)
5493 (let ((gnus-override-method gnus-override-method)
5494 (methods (and (stringp article)
5495 gnus-refer-article-method))
5496 (backend (car (gnus-find-method-for-group
5497 gnus-newsgroup-name)))
5499 (inhibit-read-only t))
5500 (if (or (not (listp methods))
5501 (and (symbolp (car methods))
5502 (assq (car methods) nnoo-definition-alist)))
5503 (setq methods (list methods)))
5504 (when (and (null gnus-override-method)
5506 (setq gnus-override-method (pop methods)))
5508 (when (eq gnus-override-method 'current)
5509 (setq gnus-override-method
5510 (with-current-buffer gnus-summary-buffer
5511 gnus-current-select-method)))
5513 (gnus-kill-all-overlays)
5514 (let ((gnus-newsgroup-name group))
5515 (gnus-check-group-server))
5517 ((gnus-request-article article group (current-buffer))
5518 (when (numberp article)
5519 (gnus-async-prefetch-next group article
5520 gnus-summary-buffer)
5521 (when gnus-keep-backlog
5522 (gnus-backlog-enter-article
5523 group article (current-buffer))))
5524 (setq result 'article))
5526 (setq gnus-override-method (pop methods)))
5527 ((not (string-match "^400 "
5528 (nnheader-get-report backend)))
5529 ;; If we get 400 server disconnect, reconnect and
5530 ;; retry; otherwise, assume the article has expired.
5531 (setq result 'done))))
5532 (and (eq result 'article) 'article)))
5536 ;; Associate this article with the current summary buffer.
5537 (setq gnus-article-current-summary gnus-summary-buffer)
5539 ;; Take the article from the original article buffer
5540 ;; and place it in the buffer it's supposed to be in.
5541 (when (and (get-buffer gnus-article-buffer)
5542 (equal (buffer-name (current-buffer))
5543 (buffer-name (get-buffer gnus-article-buffer))))
5545 (if (get-buffer gnus-original-article-buffer)
5546 (set-buffer gnus-original-article-buffer)
5547 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
5548 (buffer-disable-undo)
5549 (setq major-mode 'gnus-original-article-mode)
5550 (setq buffer-read-only t))
5551 (let ((inhibit-read-only t))
5553 (insert-buffer-substring gnus-article-buffer))
5554 (setq gnus-original-article (cons group article)))
5557 (run-hooks 'gnus-article-decode-hook)
5558 ;; Mark article as decoded or not.
5559 (setq gnus-article-decoded-p gnus-article-decode-hook))
5561 ;; Update sparse articles.
5562 (when (and do-update-line
5563 (or (numberp article)
5565 (let ((buf (current-buffer)))
5566 (set-buffer gnus-summary-buffer)
5567 (gnus-summary-update-article do-update-line sparse-header)
5568 (gnus-summary-goto-subject do-update-line nil t)
5569 (set-window-point (gnus-get-buffer-window (current-buffer) t)
5571 (set-buffer buf))))))
5577 (defcustom gnus-article-edit-mode-hook nil
5578 "Hook run in article edit mode buffers."
5579 :group 'gnus-article-various
5582 (defvar gnus-article-edit-done-function nil)
5584 (defvar gnus-article-edit-mode-map nil)
5586 ;; Should we be using derived.el for this?
5587 (unless gnus-article-edit-mode-map
5588 (setq gnus-article-edit-mode-map (make-keymap))
5589 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
5591 (gnus-define-keys gnus-article-edit-mode-map
5592 "\C-c?" describe-mode
5593 "\C-c\C-c" gnus-article-edit-done
5594 "\C-c\C-k" gnus-article-edit-exit
5595 "\C-c\C-f\C-t" message-goto-to
5596 "\C-c\C-f\C-o" message-goto-from
5597 "\C-c\C-f\C-b" message-goto-bcc
5598 ;;"\C-c\C-f\C-w" message-goto-fcc
5599 "\C-c\C-f\C-c" message-goto-cc
5600 "\C-c\C-f\C-s" message-goto-subject
5601 "\C-c\C-f\C-r" message-goto-reply-to
5602 "\C-c\C-f\C-n" message-goto-newsgroups
5603 "\C-c\C-f\C-d" message-goto-distribution
5604 "\C-c\C-f\C-f" message-goto-followup-to
5605 "\C-c\C-f\C-m" message-goto-mail-followup-to
5606 "\C-c\C-f\C-k" message-goto-keywords
5607 "\C-c\C-f\C-u" message-goto-summary
5608 "\C-c\C-f\C-i" message-insert-or-toggle-importance
5609 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
5610 "\C-c\C-b" message-goto-body
5611 "\C-c\C-i" message-goto-signature
5613 "\C-c\C-t" message-insert-to
5614 "\C-c\C-n" message-insert-newsgroups
5615 "\C-c\C-o" message-sort-headers
5616 "\C-c\C-e" message-elide-region
5617 "\C-c\C-v" message-delete-not-region
5618 "\C-c\C-z" message-kill-to-signature
5619 "\M-\r" message-newline-and-reformat
5620 "\C-c\C-a" mml-attach-file
5621 "\C-a" message-beginning-of-line
5623 "\M-;" comment-region)
5625 (gnus-define-keys (gnus-article-edit-wash-map
5626 "\C-c\C-w" gnus-article-edit-mode-map)
5627 "f" gnus-article-edit-full-stops))
5630 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
5632 ["Fetch To" message-insert-to t]
5633 ["Fetch Newsgroups" message-insert-newsgroups t]
5635 ["To" message-goto-to t]
5636 ["From" message-goto-from t]
5637 ["Subject" message-goto-subject t]
5638 ["Cc" message-goto-cc t]
5639 ["Reply-To" message-goto-reply-to t]
5640 ["Summary" message-goto-summary t]
5641 ["Keywords" message-goto-keywords t]
5642 ["Newsgroups" message-goto-newsgroups t]
5643 ["Followup-To" message-goto-followup-to t]
5644 ["Mail-Followup-To" message-goto-mail-followup-to t]
5645 ["Distribution" message-goto-distribution t]
5646 ["Body" message-goto-body t]
5647 ["Signature" message-goto-signature t]))
5649 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
5650 "Major mode for editing articles.
5651 This is an extended text-mode.
5653 \\{gnus-article-edit-mode-map}"
5654 (make-local-variable 'gnus-article-edit-done-function)
5655 (make-local-variable 'gnus-prev-winconf)
5656 (set (make-local-variable 'font-lock-defaults)
5657 '(message-font-lock-keywords t))
5658 (set (make-local-variable 'mail-header-separator) "")
5659 (set (make-local-variable 'gnus-article-edit-mode) t)
5660 (easy-menu-add message-mode-field-menu message-mode-map)
5662 (setq buffer-read-only nil)
5663 (buffer-enable-undo)
5666 (defun gnus-article-edit (&optional force)
5667 "Edit the current article.
5668 This will have permanent effect only in mail groups.
5669 If FORCE is non-nil, allow editing of articles even in read-only
5672 (when (and (not force)
5673 (gnus-group-read-only-p))
5674 (error "The current newsgroup does not support article editing"))
5675 (gnus-article-date-original)
5676 (gnus-article-edit-article
5678 `(lambda (no-highlight)
5680 (gnus-summary-edit-article-done
5681 ,(or (mail-header-references gnus-current-headers) "")
5682 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
5684 (defun gnus-article-edit-article (start-func exit-func)
5685 "Start editing the contents of the current article buffer."
5686 (let ((winconf (current-window-configuration)))
5687 (set-buffer gnus-article-buffer)
5688 (let ((message-auto-save-directory
5689 ;; Don't associate the article buffer with a draft file.
5691 (gnus-article-edit-mode))
5692 (funcall start-func)
5693 (set-buffer-modified-p nil)
5694 (gnus-configure-windows 'edit-article)
5695 (setq gnus-article-edit-done-function exit-func)
5696 (setq gnus-prev-winconf winconf)
5697 (gnus-message 6 "C-c C-c to end edits")))
5699 (defun gnus-article-edit-done (&optional arg)
5700 "Update the article edits and exit."
5702 (let ((func gnus-article-edit-done-function)
5703 (buf (current-buffer))
5704 (start (window-start))
5706 (winconf gnus-prev-winconf))
5707 (widen) ;; Widen it in case that users narrowed the buffer.
5710 ;; The cache and backlog have to be flushed somewhat.
5711 (when gnus-keep-backlog
5712 (gnus-backlog-remove-article
5713 (car gnus-article-current) (cdr gnus-article-current)))
5714 ;; Flush original article as well.
5716 (when (get-buffer gnus-original-article-buffer)
5717 (set-buffer gnus-original-article-buffer)
5718 (setq gnus-original-article nil)))
5719 (when gnus-use-cache
5720 (gnus-cache-update-article
5721 (car gnus-article-current) (cdr gnus-article-current)))
5722 ;; We remove all text props from the article buffer.
5723 (kill-all-local-variables)
5724 (set-text-properties (point-min) (point-max) nil)
5726 (set-window-configuration winconf)
5728 (set-window-start (get-buffer-window buf) start)
5729 (set-window-point (get-buffer-window buf) (point)))
5730 (gnus-summary-show-article))
5732 (defun gnus-article-edit-exit ()
5733 "Exit the article editing without updating."
5735 (when (or (not (buffer-modified-p))
5736 (yes-or-no-p "Article modified; kill anyway? "))
5737 (let ((curbuf (current-buffer))
5739 (window-start (window-start)))
5741 (if (gnus-buffer-live-p gnus-original-article-buffer)
5742 (insert-buffer gnus-original-article-buffer))
5743 (let ((winconf gnus-prev-winconf))
5744 (kill-all-local-variables)
5746 (set-window-configuration winconf)
5747 ;; Tippy-toe some to make sure that point remains where it was.
5748 (save-current-buffer
5750 (set-window-start (get-buffer-window (current-buffer)) window-start)
5752 (gnus-summary-show-article)))
5754 (defun gnus-article-edit-full-stops ()
5755 "Interactively repair spacing at end of sentences."
5758 (goto-char (point-min))
5759 (search-forward-regexp "^$" nil t)
5760 (let ((case-fold-search nil))
5761 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
5764 ;;; Article highlights
5767 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
5769 ;;; Internal Variables:
5771 (defcustom gnus-button-url-regexp
5772 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
5773 "\\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:]]\\)"
5774 "\\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\\)\\)")
5775 "Regular expression that matches URLs."
5776 :group 'gnus-article-buttons
5779 (defcustom gnus-button-valid-fqdn-regexp
5780 message-valid-fqdn-regexp
5781 "Regular expression that matches a valid FQDN."
5783 :group 'gnus-article-buttons
5786 (defcustom gnus-button-man-handler 'manual-entry
5787 "Function to use for displaying man pages.
5788 The function must take at least one argument with a string naming the
5791 :type '(choice (function-item :tag "Man" manual-entry)
5792 (function-item :tag "Woman" woman)
5793 (function :tag "Other"))
5794 :group 'gnus-article-buttons)
5796 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
5797 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
5798 If the default site is too slow, try to find a CTAN mirror, see
5799 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
5800 the variable `gnus-button-handle-ctan'."
5802 :group 'gnus-article-buttons
5803 :link '(custom-manual "(gnus)Group Parameters")
5804 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
5805 (const "http://tug.ctan.org/tex-archive/")
5806 (const "http://www.dante.de/CTAN/")
5807 (string :tag "Other")))
5809 (defcustom gnus-button-ctan-handler 'browse-url
5810 "Function to use for displaying CTAN links.
5811 The function must take one argument, the string naming the URL."
5813 :type '(choice (function-item :tag "Browse Url" browse-url)
5814 (function :tag "Other"))
5815 :group 'gnus-article-buttons)
5817 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
5818 "Bogus strings removed from CTAN URLs."
5820 :group 'gnus-article-buttons
5821 :type '(choice (const "^/?tex-archive/\\|/")
5822 (regexp :tag "Other")))
5824 (defcustom gnus-button-ctan-directory-regexp
5827 "biblio\\|digests\\|dviware\\|fonts\\|graphics\\|help\\|"
5828 "indexing\\|info\\|language\\|macros\\|support\\|systems\\|"
5829 "tds\\|tools\\|usergrps\\|web\\|nonfree\\|obsolete"
5831 "Regular expression for ctan directories.
5832 It should match all directories in the top level of `gnus-ctan-url'."
5834 :group 'gnus-article-buttons
5837 (defcustom gnus-button-mid-or-mail-regexp
5838 (concat "\\b\\(<?[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t ]*@"
5839 ;; Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
5840 gnus-button-valid-fqdn-regexp
5842 "Regular expression that matches a message ID or a mail address."
5844 :group 'gnus-article-buttons
5847 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
5848 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
5849 Strings like this can be either a message ID or a mail address. If it is one
5850 of the symbols `mid' or `mail', Gnus will always assume that the string is a
5851 message ID or a mail address, respectively. If this variable is set to the
5852 symbol `ask', always query the user what do do. If it is a function, this
5853 function will be called with the string as it's only argument. The function
5854 must return `mid', `mail', `invalid' or `ask'."
5856 :group 'gnus-article-buttons
5857 :type '(choice (function-item :tag "Heuristic function"
5858 gnus-button-mid-or-mail-heuristic)
5863 (defcustom gnus-button-mid-or-mail-heuristic-alist
5864 '((-10.0 . ".+\\$.+@")
5867 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
5868 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
5869 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
5870 (-1.0 . "^[^a-z]+@")
5872 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
5873 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
5874 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
5875 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
5878 (-1.0 . "^[0-9][0-9]")
5880 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
5881 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5882 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
5883 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
5885 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
5886 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
5889 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
5891 ;; compensation for TDMA dated mail addresses:
5892 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
5894 (-20.0 . "\\.fsf@") ;; Gnus
5897 (-20.0 . "_-_") ;; Subject change in thread
5899 (-20.0 . "\\.ln@") ;; leafnode
5900 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
5901 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
5903 ;; (5.0 . "") ;; $local_part_len <= 7
5904 (10.0 . "^[^0-9]+@")
5905 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
5906 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
5909 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
5911 (0.5 . "^[A-Z][a-z]")
5912 (0.5 . "^[A-Z][a-z][a-z]")
5913 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
5914 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
5915 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
5917 A negative RATE indicates a message IDs, whereas a positive indicates a mail
5918 address. The REGEXP is processed with `case-fold-search' set to nil."
5920 :group 'gnus-article-buttons
5921 :type '(repeat (cons (number :tag "Rate")
5922 (regexp :tag "Regexp"))))
5924 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
5925 "Guess whether MID-OR-MAIL is a message ID or a mail address.
5926 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
5927 address, `ask' if unsure and `invalid' if the string is invalid."
5928 (let ((case-fold-search nil)
5929 (list gnus-button-mid-or-mail-heuristic-alist)
5930 (result 0) rate regexp lpartlen elem)
5932 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
5933 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
5934 ;; Certain special cases...
5937 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
5938 "^[0-9]+\\.[0-9]+@compuserve\\|"
5939 "@public\\.gmane\\.org")
5941 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
5942 (setq result 'mail))
5943 (when (string-match "@.*@\\| " mid-or-mail)
5944 (gnus-message 8 "`%s' is invalid." mid-or-mail)
5945 (setq result 'invalid))
5946 ;; Nothing more to do, if result is not a number here...
5947 (when (numberp result)
5949 (setq elem (car list)
5953 (when (string-match regexp mid-or-mail)
5954 (setq result (+ result rate))
5956 9 "`%s' matched `%s', rate `%s', result `%s'."
5957 mid-or-mail regexp rate result)))
5958 (when (<= lpartlen 7)
5959 (setq result (+ result 5.0))
5960 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
5961 mid-or-mail result))
5962 (when (>= lpartlen 12)
5963 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
5965 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
5966 ;; Long local part should contain realname if e-mail address,
5967 ;; too many digits: message-id.
5968 ;; $score -= 5.0 + 0.1 * $local_part_len;
5969 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
5970 (setq result (+ result rate))
5972 9 "Many digits in `%s', rate `%s', result `%s'."
5973 mid-or-mail rate result))
5974 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
5976 ;; Too few vowels [^aeiouy]{4,}.*\@
5977 (setq result (+ result -5.0))
5979 9 "Few vowels in `%s', rate `%s', result `%s'."
5980 mid-or-mail -5.0 result))
5982 (setq result (+ result 5.0))
5984 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
5985 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
5986 ;; Maybe we should make this a customizable alist: (condition . 'result)
5988 ((symbolp result) result)
5989 ;; Now convert number into proper results:
5990 ((< result -10.0) 'mid)
5991 ((> result 10.0) 'mail)
5994 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
5995 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
5996 (url-mid (concat "news" ":" mid-or-mail))
5997 (url-mailto (concat "mailto" ":" mid-or-mail)))
5998 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
5999 (when (fboundp pref)
6001 ;; get rid of surrounding angles...
6003 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
6004 (if (or (eq 'mid guessed) (eq 'mail guessed))
6008 (save-window-excursion
6009 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
6012 (cond ((eq pref 'mid)
6013 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
6014 (gnus-button-handle-news url-mid))
6016 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
6017 (gnus-url-mailto url-mailto))
6018 (t (gnus-message 3 "Invalid string.")))))
6020 (defun gnus-button-handle-custom (url)
6021 "Follow a Custom URL."
6022 (customize-apropos (gnus-url-unhex-string url)))
6024 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
6026 ;; FIXME: Maybe we should merge some of the functions that do quite similar
6029 (defun gnus-button-handle-describe-function (url)
6030 "Call `describe-function' when pushing the corresponding URL button."
6033 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6035 (defun gnus-button-handle-describe-variable (url)
6036 "Call `describe-variable' when pushing the corresponding URL button."
6039 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
6041 (defun gnus-button-handle-symbol (url)
6042 "Display help on variable or function.
6043 Calls `describe-variable' or `describe-function'."
6044 (let ((sym (intern url)))
6046 ((fboundp sym) (describe-function sym))
6047 ((boundp sym) (describe-variable sym))
6048 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
6050 (defun gnus-button-handle-describe-key (url)
6051 "Call `describe-key' when pushing the corresponding URL button."
6053 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
6054 (keys (ignore-errors (eval `(kbd ,key-string)))))
6057 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
6059 (defun gnus-button-handle-apropos (url)
6060 "Call `apropos' when pushing the corresponding URL button."
6061 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6063 (defun gnus-button-handle-apropos-command (url)
6064 "Call `apropos' when pushing the corresponding URL button."
6066 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6068 (defun gnus-button-handle-apropos-variable (url)
6069 "Call `apropos' when pushing the corresponding URL button."
6071 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
6072 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6074 (defun gnus-button-handle-apropos-documentation (url)
6075 "Call `apropos' when pushing the corresponding URL button."
6077 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
6078 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
6080 (defun gnus-button-handle-library (url)
6081 "Call `locate-library' when pushing the corresponding URL button."
6082 (gnus-message 9 "url=`%s'" url)
6083 (let* ((lib (locate-library url))
6084 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
6086 (gnus-message 1 "Cannot locale library `%s'." url)
6087 (find-file-read-only file))))
6089 (defun gnus-button-handle-ctan (url)
6090 "Call `browse-url' when pushing a CTAN URL button."
6092 gnus-button-ctan-handler
6095 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
6097 (defcustom gnus-button-tex-level 5
6098 "*Integer that says how many TeX-related buttons Gnus will show.
6099 The higher the number, the more buttons will appear and the more false
6100 positives are possible. Note that you can set this variable local to
6101 specific groups. Setting it higher in TeX groups is probably a good idea.
6102 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6103 how to set variables in specific groups."
6105 :group 'gnus-article-buttons
6106 :link '(custom-manual "(gnus)Group Parameters")
6109 (defcustom gnus-button-man-level 5
6110 "*Integer that says how many man-related buttons Gnus will show.
6111 The higher the number, the more buttons will appear and the more false
6112 positives are possible. Note that you can set this variable local to
6113 specific groups. Setting it higher in Unix groups is probably a good idea.
6114 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
6115 how to set variables in specific groups."
6117 :group 'gnus-article-buttons
6118 :link '(custom-manual "(gnus)Group Parameters")
6121 (defcustom gnus-button-emacs-level 5
6122 "*Integer that says how many emacs-related buttons Gnus will show.
6123 The higher the number, the more buttons will appear and the more false
6124 positives are possible. Note that you can set this variable local to
6125 specific groups. Setting it higher in Emacs or Gnus related groups is
6126 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
6127 `gnus-parameters' on how to set variables in specific groups."
6129 :group 'gnus-article-buttons
6130 :link '(custom-manual "(gnus)Group Parameters")
6133 (defcustom gnus-button-message-level 5
6134 "*Integer that says how many buttons for news or mail messages will appear.
6135 The higher the number, the more buttons will appear and the more false
6136 positives are possible."
6137 ;; mail addresses, MIDs, URLs for news, ...
6139 :group 'gnus-article-buttons
6142 (defcustom gnus-button-browse-level 5
6143 "*Integer that says how many buttons for browsing will appear.
6144 The higher the number, the more buttons will appear and the more false
6145 positives are possible."
6146 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
6148 :group 'gnus-article-buttons
6151 (defcustom gnus-button-alist
6152 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
6153 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
6154 ("\\b\\(nntp\\|news\\):\\([^>\n\t ]*@[^>)!;:,\n\t ]*\\)" 0 t
6155 gnus-button-handle-news 2)
6156 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
6157 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
6158 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
6159 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
6160 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
6161 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
6162 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
6163 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
6164 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
6165 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
6166 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
6167 ;; RFC 2368 (The mailto URL scheme)
6168 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6169 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6170 ("\\bmailto:\\([^ \n\t]+\\)"
6171 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6173 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
6174 gnus-button-ctan-directory-regexp
6175 "[^][>)!;:,'\n\t ]+\\)")
6176 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
6177 ((concat "\\btex-archive/\\("
6178 gnus-button-ctan-directory-regexp
6179 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
6180 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
6183 gnus-button-ctan-directory-regexp
6184 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
6185 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
6186 ;; This is info (home-grown style) <info://foo/bar+baz>
6187 ("\\binfo://\\([^'\">\n\t ]+\\)"
6188 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
6189 ;; Info GNOME style <info:foo#bar_baz>
6190 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
6191 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
6192 ;; Info KDE style <info:(foo)bar baz>
6193 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
6194 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
6195 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
6196 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
6197 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
6198 ;; Info links like `C-h i d m CC Mode RET'
6199 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 2)
6201 ("\\bcustom:\\(//\\)?\\([^'\">\n\t ]+\\)"
6202 0 (>= gnus-button-emacs-level 5) gnus-button-handle-custom 2)
6203 ("M-x[ \t\n]customize-[^ ]+[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
6204 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1)
6205 ;; Emacs help commands
6206 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6207 ;; regexp doesn't match arguments containing ` '.
6208 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
6209 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6210 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
6211 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6212 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
6213 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6214 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
6215 ;; The following entries may lead to many false positives so don't enable
6216 ;; them by default (use a high button level).
6217 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
6218 ;; Exclude [.?] for URLs in gmane.emacs.cvs
6219 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6220 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
6221 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
6222 ("`\\([a-z][a-z0-9]+-[a-z]+-[-a-z]+\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
6223 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
6224 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
6225 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
6226 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
6227 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
6228 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6229 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
6230 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6231 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
6232 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
6233 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
6234 ("`\\(\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
6235 ;; Unlike the other regexps we really have to require quoting
6236 ;; here to determine where it ends.
6237 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
6238 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
6239 ("<URL: *\\([^<>]*\\)>"
6240 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6241 ;; RFC 2396 (2.4.3., delims) ...
6242 ("\"URL: *\\([^\"]*\\)\""
6243 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6244 ;; RFC 2396 (2.4.3., delims) ...
6245 ("\"URL: *\\([^\"]*\\)\""
6246 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
6248 (gnus-button-url-regexp
6249 0 (>= gnus-button-browse-level 0) browse-url 0)
6251 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
6252 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
6253 gnus-button-handle-man 1)
6254 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
6255 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
6256 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
6257 gnus-button-handle-man 1)
6258 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
6259 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
6260 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
6261 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
6262 ;; MID or mail: To avoid too many false positives we don't try to catch
6263 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
6264 ;; at least one dot. TLD must contain two or three chars or be a know TLD
6265 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
6266 ;; so that non-ambiguous entries (see above) match first.
6267 (gnus-button-mid-or-mail-regexp
6268 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
6269 "*Alist of regexps matching buttons in article bodies.
6271 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
6272 REGEXP: is the string (case insensitive) matching text around the button (can
6273 also be Lisp expression evaluating to a string),
6274 BUTTON: is the number of the regexp grouping actually matching the button,
6275 FORM: is a Lisp expression which must eval to true for the button to
6277 CALLBACK: is the function to call when the user push this button, and each
6278 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
6280 CALLBACK can also be a variable, in that case the value of that
6281 variable it the real callback function."
6282 :group 'gnus-article-buttons
6283 :type '(repeat (list (choice regexp variable sexp)
6284 (integer :tag "Button")
6286 (function :tag "Callback")
6289 (integer :tag "Regexp group")))))
6291 (defcustom gnus-header-button-alist
6292 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
6293 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
6294 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
6295 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
6296 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
6297 0 (>= gnus-button-message-level 0) gnus-button-mailto 0)
6298 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
6299 0 (>= gnus-button-browse-level 0) browse-url 0)
6300 ("^Subject:" gnus-button-url-regexp
6301 0 (>= gnus-button-browse-level 0) browse-url 0)
6302 ("^[^:]+:" gnus-button-url-regexp
6303 0 (>= gnus-button-browse-level 0) browse-url 0)
6304 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
6305 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
6306 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
6307 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
6308 "*Alist of headers and regexps to match buttons in article heads.
6310 This alist is very similar to `gnus-button-alist', except that each
6311 alist has an additional HEADER element first in each entry:
6313 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
6315 HEADER is a regexp to match a header. For a fuller explanation, see
6316 `gnus-button-alist'."
6317 :group 'gnus-article-buttons
6318 :group 'gnus-article-headers
6319 :type '(repeat (list (regexp :tag "Header")
6320 (choice regexp variable)
6321 (integer :tag "Button")
6323 (function :tag "Callback")
6326 (integer :tag "Regexp group")))))
6330 (defun gnus-article-push-button (event)
6331 "Check text under the mouse pointer for a callback function.
6332 If the text under the mouse pointer has a `gnus-callback' property,
6333 call it with the value of the `gnus-data' text property."
6335 (set-buffer (window-buffer (posn-window (event-start event))))
6336 (let* ((pos (posn-point (event-start event)))
6337 (data (get-text-property pos 'gnus-data))
6338 (fun (get-text-property pos 'gnus-callback)))
6341 (funcall fun data))))
6343 (defun gnus-article-press-button ()
6344 "Check text at point for a callback function.
6345 If the text at point has a `gnus-callback' property,
6346 call it with the value of the `gnus-data' text property."
6348 (let ((data (get-text-property (point) 'gnus-data))
6349 (fun (get-text-property (point) 'gnus-callback)))
6351 (funcall fun data))))
6353 (defun gnus-article-highlight (&optional force)
6354 "Highlight current article.
6355 This function calls `gnus-article-highlight-headers',
6356 `gnus-article-highlight-citation',
6357 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6358 do the highlighting. See the documentation for those functions."
6359 (interactive (list 'force))
6360 (gnus-article-highlight-headers)
6361 (gnus-article-highlight-citation force)
6362 (gnus-article-highlight-signature)
6363 (gnus-article-add-buttons force)
6364 (gnus-article-add-buttons-to-head))
6366 (defun gnus-article-highlight-some (&optional force)
6367 "Highlight current article.
6368 This function calls `gnus-article-highlight-headers',
6369 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
6370 do the highlighting. See the documentation for those functions."
6371 (interactive (list 'force))
6372 (gnus-article-highlight-headers)
6373 (gnus-article-highlight-signature)
6374 (gnus-article-add-buttons))
6376 (defun gnus-article-highlight-headers ()
6377 "Highlight article headers as specified by `gnus-header-face-alist'."
6379 (gnus-with-article-headers
6380 (let (regexp header-face field-face from hpoints fpoints)
6381 (dolist (entry gnus-header-face-alist)
6382 (goto-char (point-min))
6383 (setq regexp (concat "^\\("
6384 (if (string-equal "" (nth 0 entry))
6388 header-face (nth 1 entry)
6389 field-face (nth 2 entry))
6390 (while (and (re-search-forward regexp nil t)
6394 (unless (search-forward ":" nil t)
6396 (when (and header-face
6397 (not (memq (point) hpoints)))
6398 (push (point) hpoints)
6399 (gnus-put-text-property from (point) 'face header-face))
6400 (when (and field-face
6401 (not (memq (setq from (point)) fpoints)))
6403 (if (re-search-forward "^[^ \t]" nil t)
6405 (goto-char (point-max)))
6406 (gnus-put-text-property from (point) 'face field-face)))))))
6408 (defun gnus-article-highlight-signature ()
6409 "Highlight the signature in an article.
6410 It does this by highlighting everything after
6411 `gnus-signature-separator' using `gnus-signature-face'."
6413 (gnus-with-article-buffer
6414 (let ((inhibit-point-motion-hooks t))
6416 (when (and gnus-signature-face
6417 (gnus-article-narrow-to-signature))
6418 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max))
6419 'face gnus-signature-face)
6421 (gnus-article-search-signature)
6422 (let ((start (match-beginning 0))
6423 (end (set-marker (make-marker) (1+ (match-end 0)))))
6424 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
6427 (defun gnus-button-in-region-p (b e prop)
6428 "Say whether PROP exists in the region."
6429 (text-property-not-all b e prop nil))
6431 (defun gnus-article-add-buttons (&optional force)
6432 "Find external references in the article and make buttons of them.
6433 \"External references\" are things like Message-IDs and URLs, as
6434 specified by `gnus-button-alist'."
6435 (interactive (list 'force))
6436 (gnus-with-article-buffer
6437 (let ((inhibit-point-motion-hooks t)
6438 (case-fold-search t)
6439 (alist gnus-button-alist)
6441 ;; Remove all old markers.
6442 (let (marker entry new-list)
6443 (while (setq marker (pop gnus-button-marker-list))
6444 (if (or (< marker (point-min)) (>= marker (point-max)))
6445 (push marker new-list)
6447 (when (setq entry (gnus-button-entry))
6448 (put-text-property (match-beginning (nth 1 entry))
6449 (match-end (nth 1 entry))
6450 'gnus-callback nil))
6451 (set-marker marker nil)))
6452 (setq gnus-button-marker-list new-list))
6453 ;; We skip the headers.
6456 (while (setq entry (pop alist))
6457 (setq regexp (eval (car entry)))
6459 (while (re-search-forward regexp nil t)
6460 (let* ((start (and entry (match-beginning (nth 1 entry))))
6461 (end (and entry (match-end (nth 1 entry))))
6462 (from (match-beginning 0)))
6463 (when (and (or (eq t (nth 2 entry))
6464 (eval (nth 2 entry)))
6465 (not (gnus-button-in-region-p
6466 start end 'gnus-callback)))
6467 ;; That optional form returned non-nil, so we add the
6469 (gnus-article-add-button
6470 start end 'gnus-button-push
6471 (car (push (set-marker (make-marker) from)
6472 gnus-button-marker-list))))))))))
6474 ;; Add buttons to the head of an article.
6475 (defun gnus-article-add-buttons-to-head ()
6476 "Add buttons to the head of the article."
6478 (gnus-with-article-headers
6480 (dolist (entry gnus-header-button-alist)
6481 ;; Each alist entry.
6482 (goto-char (point-min))
6483 (while (re-search-forward (car entry) nil t)
6484 ;; Each header matching the entry.
6485 (setq beg (match-beginning 0))
6486 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
6487 (match-beginning 0))
6490 (while (re-search-forward (eval (nth 1 entry)) end t)
6491 ;; Each match within a header.
6492 (let* ((entry (cdr entry))
6493 (start (match-beginning (nth 1 entry)))
6494 (end (match-end (nth 1 entry)))
6495 (form (nth 2 entry)))
6496 (goto-char (match-end 0))
6498 (gnus-article-add-button
6499 start end (nth 3 entry)
6500 (buffer-substring (match-beginning (nth 4 entry))
6501 (match-end (nth 4 entry)))))))
6502 (goto-char end))))))
6504 ;;; External functions:
6506 (defun gnus-article-add-button (from to fun &optional data)
6507 "Create a button between FROM and TO with callback FUN and data DATA."
6508 (when gnus-article-button-face
6509 (gnus-overlay-put (gnus-make-overlay from to)
6510 'face gnus-article-button-face))
6511 (gnus-add-text-properties
6513 (nconc (and gnus-article-mouse-face
6514 (list gnus-mouse-face-prop gnus-article-mouse-face))
6515 (list 'gnus-callback fun)
6516 (and data (list 'gnus-data data))))
6517 (widget-convert-button 'link from to :action 'gnus-widget-press-button
6518 :button-keymap gnus-widget-button-keymap))
6520 ;;; Internal functions:
6522 (defun gnus-article-set-globals ()
6523 (with-current-buffer gnus-summary-buffer
6524 (gnus-set-global-variables)))
6526 (defun gnus-signature-toggle (end)
6527 (gnus-with-article-buffer
6528 (let ((inhibit-point-motion-hooks t))
6529 (if (text-property-any end (point-max) 'article-type 'signature)
6531 (gnus-delete-wash-type 'signature)
6532 (gnus-remove-text-properties-when
6533 'article-type 'signature end (point-max)
6534 (cons 'article-type (cons 'signature
6535 gnus-hidden-properties))))
6536 (gnus-add-wash-type 'signature)
6537 (gnus-add-text-properties-when
6538 'article-type nil end (point-max)
6539 (cons 'article-type (cons 'signature
6540 gnus-hidden-properties)))))
6541 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
6542 (gnus-set-mode-line 'article))))
6544 (defun gnus-button-entry ()
6545 ;; Return the first entry in `gnus-button-alist' matching this place.
6546 (let ((alist gnus-button-alist)
6549 (setq entry (pop alist))
6550 (if (looking-at (eval (car entry)))
6555 (defun gnus-button-push (marker)
6556 ;; Push button starting at MARKER.
6559 (let* ((entry (gnus-button-entry))
6560 (inhibit-point-motion-hooks t)
6562 (args (mapcar (lambda (group)
6563 (let ((string (match-string group)))
6564 (set-text-properties
6565 0 (length string) nil string)
6572 (fboundp (symbol-value fun)))
6573 (apply (symbol-value fun) args))
6575 (gnus-message 1 "You must define `%S' to use this button"
6576 (cons fun args)))))))
6578 (defun gnus-parse-news-url (url)
6579 (let (scheme server group message-id articles)
6582 (goto-char (point-min))
6583 (when (looking-at "\\([A-Za-z]+\\):")
6584 (setq scheme (match-string 1))
6585 (goto-char (match-end 0)))
6586 (when (looking-at "//\\([^/]+\\)/")
6587 (setq server (match-string 1))
6588 (goto-char (match-end 0)))
6591 ((looking-at "\\(.*@.*\\)")
6592 (setq message-id (match-string 1)))
6593 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
6594 (setq group (match-string 1)
6595 articles (split-string (match-string 2) "-")))
6596 ((looking-at "\\([^/]+\\)/?")
6597 (setq group (match-string 1)))
6599 (error "Unknown news URL syntax"))))
6600 (list scheme server group message-id articles)))
6602 (defun gnus-button-handle-news (url)
6604 (destructuring-bind (scheme server group message-id articles)
6605 (gnus-parse-news-url url)
6609 (set-buffer gnus-summary-buffer)
6611 (let ((gnus-refer-article-method (list (list 'nntp server))))
6612 (gnus-summary-refer-article message-id))
6613 (gnus-summary-refer-article message-id))))
6615 (gnus-button-fetch-group url)))))
6617 (defun gnus-button-handle-man (url)
6619 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6620 (when (eq gnus-button-man-handler 'woman)
6621 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
6622 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
6623 (funcall gnus-button-man-handler url))
6625 (defun gnus-button-handle-info-url (url)
6626 "Fetch an info URL."
6627 (setq url (mm-subst-char-in-string ?+ ?\ url))
6629 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
6630 (gnus-info-find-node
6631 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
6633 ")" (gnus-url-unhex-string (match-string 2 url)))))
6634 ((string-match "([^)\"]+)[^\"]+" url)
6636 (gnus-replace-in-string
6637 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
6638 (gnus-info-find-node url))
6639 (t (error "Can't parse %s" url))))
6641 (defun gnus-button-handle-info-url-gnome (url)
6642 "Fetch GNOME style info URL."
6643 (setq url (mm-subst-char-in-string ?_ ?\ url))
6644 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
6645 (gnus-info-find-node
6647 (gnus-url-unhex-string
6648 (match-string 1 url))
6650 (or (gnus-url-unhex-string
6651 (match-string 2 url))
6653 (error "Can't parse %s" url)))
6655 (defun gnus-button-handle-info-url-kde (url)
6656 "Fetch KDE style info URL."
6657 (gnus-info-find-node (gnus-url-unhex-string url)))
6659 (defun gnus-button-handle-info-keystrokes (url)
6660 "Call `info' when pushing the corresponding URL button."
6661 ;; For links like `C-h i d m gnus RET', `C-h i d m CC Mode RET'.
6666 (defun gnus-button-message-id (message-id)
6668 (with-current-buffer gnus-summary-buffer
6669 (gnus-summary-refer-article message-id)))
6671 (defun gnus-button-fetch-group (address)
6672 "Fetch GROUP specified by ADDRESS."
6673 (if (not (string-match "[:/]" address))
6674 ;; This is just a simple group url.
6675 (gnus-group-read-ephemeral-group address gnus-select-method)
6678 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
6680 (error "Can't parse %s" address)
6681 (gnus-group-read-ephemeral-group
6682 (match-string 4 address)
6683 `(nntp ,(match-string 1 address)
6684 (nntp-address ,(match-string 1 address))
6685 (nntp-port-number ,(if (match-end 3)
6686 (match-string 3 address)
6689 (and (match-end 6) (list (string-to-int (match-string 6 address))))))))
6691 (defun gnus-url-parse-query-string (query &optional downcase)
6692 (let (retval pairs cur key val)
6693 (setq pairs (split-string query "&"))
6695 (setq cur (car pairs)
6697 (if (not (string-match "=" cur))
6699 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
6700 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
6702 (setq key (downcase key)))
6703 (setq cur (assoc key retval))
6705 (setcdr cur (cons val (cdr cur)))
6706 (setq retval (cons (list key val) retval)))))
6709 (defun gnus-url-mailto (url)
6710 ;; Send mail to someone
6711 (when (string-match "mailto:/*\\(.*\\)" url)
6712 (setq url (substring url (match-beginning 1) nil)))
6713 (let (to args subject func)
6714 (setq args (gnus-url-parse-query-string
6715 (if (string-match "^\\?" url)
6717 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
6718 (concat "to=" (match-string 1 url) "&"
6719 (match-string 2 url))
6720 (concat "to=" url)))
6722 subject (cdr-safe (assoc "subject" args)))
6725 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
6728 (message-position-on-field (caar args)))
6729 (insert (gnus-replace-in-string
6730 (mapconcat 'identity (reverse (cdar args)) ", ")
6732 (setq args (cdr args)))
6735 (message-goto-subject))))
6737 (defun gnus-button-embedded-url (address)
6738 "Activate ADDRESS with `browse-url'."
6739 (browse-url (gnus-strip-whitespace address)))
6741 ;;; Next/prev buttons in the article buffer.
6743 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
6744 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
6746 (defvar gnus-prev-page-map
6747 (let ((map (make-sparse-keymap)))
6748 (define-key map gnus-mouse-2 'gnus-button-prev-page)
6749 (define-key map "\r" 'gnus-button-prev-page)
6752 (defvar gnus-next-page-map
6753 (let ((map (make-sparse-keymap)))
6754 (unless (>= emacs-major-version 21)
6755 ;; XEmacs doesn't care.
6756 (set-keymap-parent map gnus-article-mode-map))
6757 (define-key map gnus-mouse-2 'gnus-button-next-page)
6758 (define-key map "\r" 'gnus-button-next-page)
6761 (defun gnus-insert-prev-page-button ()
6763 (inhibit-read-only t))
6765 gnus-prev-page-line-format nil
6766 `(keymap ,gnus-prev-page-map
6768 gnus-callback gnus-article-button-prev-page
6769 article-type annotation))
6770 (widget-convert-button
6772 ;; Exclude a newline.
6775 :action 'gnus-button-prev-page
6776 :button-keymap gnus-prev-page-map)))
6778 (defun gnus-button-next-page (&optional args more-args)
6779 "Go to the next page."
6781 (let ((win (selected-window)))
6782 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6783 (gnus-article-next-page)
6784 (select-window win)))
6786 (defun gnus-button-prev-page (&optional args more-args)
6787 "Go to the prev page."
6789 (let ((win (selected-window)))
6790 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6791 (gnus-article-prev-page)
6792 (select-window win)))
6794 (defun gnus-insert-next-page-button ()
6796 (inhibit-read-only t))
6797 (gnus-eval-format gnus-next-page-line-format nil
6798 `(keymap ,gnus-next-page-map
6800 gnus-callback gnus-article-button-next-page
6801 article-type annotation))
6802 (widget-convert-button
6804 ;; Exclude a newline.
6807 :action 'gnus-button-next-page
6808 :button-keymap gnus-next-page-map)))
6810 (defun gnus-article-button-next-page (arg)
6811 "Go to the next page."
6813 (let ((win (selected-window)))
6814 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6815 (gnus-article-next-page)
6816 (select-window win)))
6818 (defun gnus-article-button-prev-page (arg)
6819 "Go to the prev page."
6821 (let ((win (selected-window)))
6822 (select-window (gnus-get-buffer-window gnus-article-buffer t))
6823 (gnus-article-prev-page)
6824 (select-window win)))
6826 (defvar gnus-decode-header-methods
6827 '(mail-decode-encoded-word-region)
6828 "List of methods used to decode headers.
6830 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
6831 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
6832 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
6833 whose names match REGEXP.
6836 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
6837 mail-decode-encoded-word-region
6838 (\"chinese\" . rfc1843-decode-region))
6841 (defvar gnus-decode-header-methods-cache nil)
6843 (defun gnus-multi-decode-header (start end)
6844 "Apply the functions from `gnus-encoded-word-methods' that match."
6845 (unless (and gnus-decode-header-methods-cache
6846 (eq gnus-newsgroup-name
6847 (car gnus-decode-header-methods-cache)))
6848 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
6851 (nconc gnus-decode-header-methods-cache (list x))
6852 (if (and gnus-newsgroup-name
6853 (string-match (car x) gnus-newsgroup-name))
6854 (nconc gnus-decode-header-methods-cache
6856 gnus-decode-header-methods))
6857 (let ((xlist gnus-decode-header-methods-cache))
6860 (narrow-to-region start end)
6862 (funcall (pop xlist) (point-min) (point-max))))))
6865 ;;; Treatment top-level handling.
6868 (defun gnus-treat-article (condition &optional part-number total-parts type)
6869 (let ((length (- (point-max) (point-min)))
6870 (alist gnus-treatment-function-alist)
6871 (article-goto-body-goes-to-point-min-p t)
6875 (let ((list gnus-article-treat-types))
6877 (when (string-match (pop list) type)
6878 (throw 'found t)))))))
6879 (highlightp (gnus-visual-p 'article-highlight 'highlight))
6881 (gnus-run-hooks 'gnus-part-display-hook)
6882 (dolist (elem alist)
6885 (when (gnus-buffer-live-p gnus-summary-buffer)
6886 (set-buffer gnus-summary-buffer))
6887 (symbol-value (car elem))))
6888 (when (and (or (consp val)
6890 (gnus-treat-predicate val)
6891 (or (not (get (car elem) 'highlight))
6894 (funcall (cadr elem)))))))
6896 ;; Dynamic variables.
6898 (defvar part-number)
6899 (defvar total-parts)
6904 (defun gnus-treat-predicate (val)
6911 (stringp (car val)))
6912 (apply 'gnus-or (mapcar `(lambda (s)
6913 (string-match s ,(or gnus-newsgroup-name "")))
6916 (let ((pred (pop val)))
6919 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
6921 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
6923 (not (gnus-treat-predicate (car val))))
6925 (equal (car val) type))
6927 (error "%S is not a valid predicate" pred)))))
6933 (eq part-number total-parts))
6937 (error "%S is not a valid value" val))))
6939 (defun gnus-article-encrypt-body (protocol &optional n)
6940 "Encrypt the article body."
6943 (or gnus-article-encrypt-protocol
6944 (completing-read "Encrypt protocol: "
6945 gnus-article-encrypt-protocol-alist
6947 current-prefix-arg))
6948 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
6950 (error (format "Can't find the encrypt protocol %s" protocol)))
6951 (if (member gnus-newsgroup-name '("nndraft:delayed"
6954 (error "Can't encrypt the article in group %s"
6955 gnus-newsgroup-name))
6956 (gnus-summary-iterate n
6958 (set-buffer gnus-summary-buffer)
6959 (let ((mail-parse-charset gnus-newsgroup-charset)
6960 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6961 (summary-buffer gnus-summary-buffer)
6963 (gnus-set-global-variables)
6964 (when (gnus-group-read-only-p)
6965 (error "The current newsgroup does not support article encrypt"))
6966 (gnus-summary-show-article t)
6968 (or (mail-header-references gnus-current-headers) ""))
6969 (set-buffer gnus-article-buffer)
6970 (let* ((inhibit-read-only t)
6972 (mapcar (lambda (field)
6973 (and (save-restriction
6974 (message-narrow-to-head)
6975 (goto-char (point-min))
6976 (search-forward field nil t))
6978 (message-narrow-to-field)
6980 (delete-region (point-min) (point-max))
6982 '("Content-Type:" "Content-Transfer-Encoding:"
6983 "Content-Disposition:"))))
6984 (message-narrow-to-head)
6985 (message-remove-header "MIME-Version")
6986 (goto-char (point-max))
6987 (setq point (point))
6988 (insert (apply 'concat headers))
6990 (narrow-to-region point (point-max))
6991 (let ((message-options message-options))
6992 (message-options-set 'message-sender user-mail-address)
6993 (message-options-set 'message-recipients user-mail-address)
6994 (message-options-set 'message-sign-encrypt 'not)
6996 (goto-char (point-min))
6997 (insert "MIME-Version: 1.0\n")
6999 (gnus-summary-edit-article-done
7000 references nil summary-buffer t))
7001 (when gnus-keep-backlog
7002 (gnus-backlog-remove-article
7003 (car gnus-article-current) (cdr gnus-article-current)))
7005 (when (get-buffer gnus-original-article-buffer)
7006 (set-buffer gnus-original-article-buffer)
7007 (setq gnus-original-article nil)))
7008 (when gnus-use-cache
7009 (gnus-cache-update-article
7010 (car gnus-article-current) (cdr gnus-article-current))))))))
7012 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
7013 "The following specs can be used:
7014 %t The security MIME type
7017 %D Details if button is pressed")
7019 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
7020 "The following specs can be used:
7021 %t The security MIME type
7024 %D Details if button is pressed")
7026 (defvar gnus-mime-security-button-line-format-alist
7027 '((?t gnus-tmp-type ?s)
7028 (?i gnus-tmp-info ?s)
7029 (?d gnus-tmp-details ?s)
7030 (?D gnus-tmp-pressed-details ?s)))
7032 (defvar gnus-mime-security-button-map
7033 (let ((map (make-sparse-keymap)))
7034 (define-key map gnus-mouse-2 'gnus-article-push-button)
7035 (define-key map "\r" 'gnus-article-press-button)
7038 (defvar gnus-mime-security-details-buffer nil)
7040 (defvar gnus-mime-security-button-pressed nil)
7042 (defvar gnus-mime-security-show-details-inline t
7043 "If non-nil, show details in the article buffer.")
7045 (defun gnus-mime-security-verify-or-decrypt (handle)
7046 (mm-remove-parts (cdr handle))
7047 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
7048 point (inhibit-read-only t))
7050 (goto-char (car region)))
7052 (narrow-to-region (point) (point))
7053 (with-current-buffer (mm-handle-multipart-original-buffer handle)
7054 (let* ((mm-verify-option 'known)
7055 (mm-decrypt-option 'known)
7056 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
7057 (unless (eq nparts (cdr handle))
7058 (mm-destroy-parts (cdr handle))
7059 (setcdr handle nparts))))
7060 (setq point (point))
7061 (gnus-mime-display-security handle)
7062 (goto-char (point-max)))
7064 (delete-region (point) (cdr region))
7065 (set-marker (car region) nil)
7066 (set-marker (cdr region) nil))
7069 (defun gnus-mime-security-show-details (handle)
7070 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
7072 (gnus-message 5 "No details.")
7073 (if gnus-mime-security-show-details-inline
7074 (let ((gnus-mime-security-button-pressed
7075 (not (get-text-property (point) 'gnus-mime-details)))
7076 (gnus-mime-security-button-line-format
7077 (get-text-property (point) 'gnus-line-format))
7078 (inhibit-read-only t))
7080 (while (eq (get-text-property (point) 'gnus-line-format)
7081 gnus-mime-security-button-line-format)
7085 (narrow-to-region (point) (point))
7086 (gnus-insert-mime-security-button handle))
7087 (delete-region (point)
7088 (or (text-property-not-all
7091 gnus-mime-security-button-line-format)
7094 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
7095 (with-current-buffer gnus-mime-security-details-buffer
7098 (setq gnus-mime-security-details-buffer
7099 (gnus-get-buffer-create "*MIME Security Details*")))
7100 (with-current-buffer gnus-mime-security-details-buffer
7102 (goto-char (point-min)))
7103 (pop-to-buffer gnus-mime-security-details-buffer)))))
7105 (defun gnus-mime-security-press-button (handle)
7107 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7108 (gnus-mime-security-show-details handle)
7109 (gnus-mime-security-verify-or-decrypt handle))))
7111 (defun gnus-insert-mime-security-button (handle &optional displayed)
7112 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
7115 (or (nth 2 (assoc protocol mm-verify-function-alist))
7116 (nth 2 (assoc protocol mm-decrypt-function-alist))
7118 (if (equal (car handle) "multipart/signed")
7119 " Signed" " Encrypted")
7122 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
7125 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
7126 gnus-tmp-pressed-details
7128 (setq gnus-tmp-details
7129 (if gnus-tmp-details
7130 (concat "\n" gnus-tmp-details)
7132 (setq gnus-tmp-pressed-details
7133 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
7138 gnus-mime-security-button-line-format
7139 gnus-mime-security-button-line-format-alist
7140 `(keymap ,gnus-mime-security-button-map
7141 gnus-callback gnus-mime-security-press-button
7142 gnus-line-format ,gnus-mime-security-button-line-format
7143 gnus-mime-details ,gnus-mime-security-button-pressed
7144 article-type annotation
7147 ;; Exclude a newline.
7150 (widget-convert-button
7153 :action 'gnus-widget-press-button
7154 :button-keymap gnus-mime-security-button-map
7156 (lambda (widget/window &optional overlay pos)
7157 ;; Needed to properly clear the message due to a bug in
7158 ;; wid-edit (XEmacs only).
7159 (when (boundp 'help-echo-owns-message)
7160 (setq help-echo-owns-message t))
7163 (aref gnus-mouse-2 0))))))
7165 (defun gnus-mime-display-security (handle)
7167 (narrow-to-region (point) (point))
7168 (unless (gnus-unbuttonized-mime-type-p (car handle))
7169 (gnus-insert-mime-security-button handle))
7170 (gnus-mime-display-mixed (cdr handle))
7173 (unless (gnus-unbuttonized-mime-type-p (car handle))
7174 (let ((gnus-mime-security-button-line-format
7175 gnus-mime-security-button-end-line-format))
7176 (gnus-insert-mime-security-button handle)))
7177 (mm-set-handle-multipart-parameter
7179 (cons (set-marker (make-marker) (point-min))
7180 (set-marker (make-marker) (point-max))))))
7186 (run-hooks 'gnus-art-load-hook)
7188 ;;; arch-tag: 2654516f-6279-48f9-a83b-05c1fa450c33
7189 ;;; gnus-art.el ends here