1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
34 (defvar w3m-minor-mode-map)
49 (autoload 'gnus-msg-mail "gnus-msg" nil t)
50 (autoload 'gnus-button-mailto "gnus-msg")
51 (autoload 'gnus-button-reply "gnus-msg" nil t)
52 (autoload 'parse-time-string "parse-time" nil nil)
53 (autoload 'ansi-color-apply-on-region "ansi-color")
54 (autoload 'mm-url-insert-file-contents-external "mm-url")
55 (autoload 'mm-extern-cache-contents "mm-extern")
57 (defgroup gnus-article nil
59 :link '(custom-manual "(gnus)Article Buffer")
62 (defgroup gnus-article-treat nil
63 "Treating article parts."
64 :link '(custom-manual "(gnus)Article Hiding")
67 (defgroup gnus-article-hiding nil
68 "Hiding article parts."
69 :link '(custom-manual "(gnus)Article Hiding")
72 (defgroup gnus-article-highlight nil
73 "Article highlighting."
74 :link '(custom-manual "(gnus)Article Highlighting")
78 (defgroup gnus-article-signature nil
80 :link '(custom-manual "(gnus)Article Signature")
83 (defgroup gnus-article-headers nil
85 :link '(custom-manual "(gnus)Hiding Headers")
88 (defgroup gnus-article-washing nil
89 "Special commands on articles."
90 :link '(custom-manual "(gnus)Article Washing")
93 (defgroup gnus-article-emphasis nil
94 "Fontisizing articles."
95 :link '(custom-manual "(gnus)Article Fontisizing")
98 (defgroup gnus-article-saving nil
100 :link '(custom-manual "(gnus)Saving Articles")
101 :group 'gnus-article)
103 (defgroup gnus-article-mime nil
104 "Worshiping the MIME wonder."
105 :link '(custom-manual "(gnus)Using MIME")
106 :group 'gnus-article)
108 (defgroup gnus-article-buttons nil
109 "Pushable buttons in the article buffer."
110 :link '(custom-manual "(gnus)Article Buttons")
111 :group 'gnus-article)
113 (defgroup gnus-article-various nil
114 "Other article options."
115 :link '(custom-manual "(gnus)Misc Article")
116 :group 'gnus-article)
118 (defcustom gnus-ignored-headers
121 (concat "^" header ":"))
122 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
123 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
124 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
125 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
126 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
127 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
128 "X-Attribution" "X-Originating-IP" "Delivered-To"
129 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
130 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
131 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
132 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
133 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
134 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
135 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
136 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
137 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
138 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
139 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
140 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
141 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
142 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
143 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
144 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
145 "List-[A-Za-z]+" "X-Listprocessor-Version"
146 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
147 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
148 "X-Received" "Content-length" "X-precedence"
149 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
150 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
151 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
152 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
153 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
154 "X-Content-length" "X-Posting-Agent" "Original-Received"
155 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
156 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
157 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
158 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
159 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
160 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
161 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
162 "Envelope-Sender" "Envelope-Recipients"))
163 "*All headers that start with this regexp will be hidden.
164 This variable can also be a list of regexps of headers to be ignored.
165 If `gnus-visible-headers' is non-nil, this variable will be ignored."
166 :type '(choice :custom-show nil
169 :group 'gnus-article-hiding)
171 (defcustom gnus-visible-headers
172 "^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:"
173 "*All headers that do not match this regexp will be hidden.
174 This variable can also be a list of regexp of headers to remain visible.
175 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
177 (repeat :value-to-internal (lambda (widget value)
178 (custom-split-regexp-maybe value))
179 :match (lambda (widget value)
181 (widget-editable-list-match widget value)))
183 (const :tag "Use gnus-ignored-headers" nil)
185 :group 'gnus-article-hiding)
187 (defcustom gnus-sorted-header-list
188 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
189 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
190 "*This variable is a list of regular expressions.
191 If it is non-nil, headers that match the regular expressions will
192 be placed first in the article buffer in the sequence specified by
194 :type '(repeat regexp)
195 :group 'gnus-article-hiding)
197 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
198 "Headers that are only to be displayed if they have interesting data.
199 Possible values in this list are:
201 'empty Headers with no content.
202 'newsgroups Newsgroup identical to Gnus group.
203 'to-address To identical to To-address.
204 'to-list To identical to To-list.
205 'cc-list CC identical to To-list.
206 'followup-to Followup-to identical to Newsgroups.
207 'reply-to Reply-to identical to From.
208 'date Date less than four days old.
209 'long-to To and/or Cc longer than 1024 characters.
210 'many-to Multiple To and/or Cc."
211 :type '(set (const :tag "Headers with no content." empty)
212 (const :tag "Newsgroups identical to Gnus group." newsgroups)
213 (const :tag "To identical to To-address." to-address)
214 (const :tag "To identical to To-list." to-list)
215 (const :tag "CC identical to To-list." cc-list)
216 (const :tag "Followup-to identical to Newsgroups." followup-to)
217 (const :tag "Reply-to identical to From." reply-to)
218 (const :tag "Date less than four days old." date)
219 (const :tag "To and/or Cc longer than 1024 characters." long-to)
220 (const :tag "Multiple To and/or Cc headers." many-to))
221 :group 'gnus-article-hiding)
223 (defcustom gnus-article-skip-boring nil
224 "Skip over text that is not worth reading.
225 By default, if you set this t, then Gnus will display citations and
226 signatures, but will never scroll down to show you a page consisting
227 only of boring text. Boring text is controlled by
228 `gnus-article-boring-faces'."
231 :group 'gnus-article-hiding)
233 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
234 "Regexp matching signature separator.
235 This can also be a list of regexps. In that case, it will be checked
236 from head to tail looking for a separator. Searches will be done from
237 the end of the buffer."
238 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
240 (repeat :tag "List of regexp" regexp))
241 :group 'gnus-article-signature)
243 (defcustom gnus-signature-limit nil
244 "Provide a limit to what is considered a signature.
245 If it is a number, no signature may not be longer (in characters) than
246 that number. If it is a floating point number, no signature may be
247 longer (in lines) than that number. If it is a function, the function
248 will be called without any parameters, and if it returns nil, there is
249 no signature in the buffer. If it is a string, it will be used as a
250 regexp. If it matches, the text in question is not a signature.
252 This can also be a list of the above values."
253 :type '(choice (const nil)
257 (regexp :value ".*"))
258 :group 'gnus-article-signature)
260 (defcustom gnus-fetch-partial-articles nil
261 "If non-nil, Gnus will fetch partial articles.
262 If t, nnimap will fetch only the first part. If a string, it
263 will fetch all parts that have types that match that string. A
264 likely value would be \"text/\" to automatically fetch all
267 Currently only the nnimap backend actually supports partial
268 article fetching. If the backend doesn't support it, it has no
271 :type '(choice (const nil)
274 :group 'gnus-article)
276 (defcustom gnus-hidden-properties '(invisible t intangible t)
277 "Property list to use for hiding text."
279 :group 'gnus-article-hiding)
281 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
282 ;; frames in a session.
283 (defcustom gnus-article-x-face-command
284 (if (featurep 'xemacs)
285 (if (or (gnus-image-type-available-p 'xface)
286 (gnus-image-type-available-p 'pbm))
287 'gnus-display-x-face-in-from
288 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
289 (if (gnus-image-type-available-p 'pbm)
290 'gnus-display-x-face-in-from
291 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
293 "*String or function to be executed to display an X-Face header.
294 If it is a string, the command will be executed in a sub-shell
295 asynchronously. The compressed face will be piped to this command."
296 :type `(choice string
297 (function-item gnus-display-x-face-in-from)
301 :group 'gnus-article-washing)
303 (defcustom gnus-article-x-face-too-ugly nil
304 "Regexp matching posters whose face shouldn't be shown automatically."
305 :type '(choice regexp (const nil))
306 :group 'gnus-article-washing)
308 (defcustom gnus-article-banner-alist nil
309 "Banner alist for stripping.
311 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
313 :type '(repeat (cons symbol regexp))
314 :group 'gnus-article-washing)
316 (gnus-define-group-parameter
319 "Alist of regexps (to match group names) and banner."
320 :variable-group gnus-article-washing
322 '(choice :tag "Banner"
324 (const :tag "Remove signature" signature)
325 (symbol :tag "Item in `gnus-article-banner-alist'" none)
327 (const :tag "None" nil))
329 "If non-nil, specify how to remove `banners' from articles.
331 Symbol `signature' means to remove signatures delimited by
332 `gnus-signature-separator'. Any other symbol is used to look up a
333 regular expression to match the banner in `gnus-article-banner-alist'.
334 A string is used as a regular expression to match the banner
337 (defcustom gnus-article-address-banner-alist nil
338 "Alist of mail addresses and banners.
339 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
340 to match a mail address in the From: header, BANNER is one of a symbol
341 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
342 If ADDRESS matches author's mail address, it will remove things like
343 advertisements. For example:
345 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
349 (regexp :tag "Address")
350 (choice :tag "Banner" :value nil
351 (const :tag "Remove signature" signature)
352 (symbol :tag "Item in `gnus-article-banner-alist'" none)
354 (const :tag "None" nil))))
356 :group 'gnus-article-washing)
358 (defmacro gnus-emphasis-custom-with-format (&rest body)
360 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
361 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
364 (defun gnus-emphasis-custom-value-to-external (value)
365 (gnus-emphasis-custom-with-format
366 (if (consp (car value))
367 (list (format format (car (car value)) (cdr (car value)))
369 (if (nth 1 value) 2 3)
373 (defun gnus-emphasis-custom-value-to-internal (value)
374 (gnus-emphasis-custom-with-format
375 (let ((regexp (concat "\\`"
376 (format (regexp-quote format)
377 "\\([^()]+\\)" "\\([^()]+\\)")
380 (if (string-match regexp (setq pattern (car value)))
381 (list (cons (match-string 1 pattern) (match-string 2 pattern))
386 (defcustom gnus-emphasis-alist
388 '(("\\*" "\\*" bold nil 2)
391 ("_/" "/_" underline-italic)
392 ("_\\*" "\\*_" underline-bold)
393 ("\\*/" "/\\*" bold-italic)
394 ("_\\*/" "/\\*_" underline-bold-italic))))
396 (gnus-emphasis-custom-with-format
397 (mapcar (lambda (spec)
398 (list (format format (car spec) (cadr spec))
401 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
403 '(;; I've never seen anyone use this strikethru convention whereas I've
404 ;; several times seen it triggered by normal text. --Stef
405 ;; Miles suggests that this form is sometimes used but for italics,
406 ;; so maybe we should map it to `italic'.
407 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
408 ;; 2 3 gnus-emphasis-strikethru)
409 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
410 2 3 gnus-emphasis-underline))))
411 "*Alist that says how to fontify certain phrases.
412 Each item looks like this:
414 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
416 The first element is a regular expression to be matched. The second
417 is a number that says what regular expression grouping used to find
418 the entire emphasized word. The third is a number that says what
419 regexp grouping should be displayed and highlighted. The fourth
420 is the face used for highlighting."
424 :format "%[Customizing Style%]\n%v"
426 (group :tag "Default"
427 :value ("" 0 0 default)
430 (let ((value (widget-get
431 (cadr (widget-get (widget-get widget :parent)
434 (if (not (eq (nth 2 value) 'default))
438 (gnus-emphasis-custom-value-to-external value))))
439 (widget-group-value-create widget))
441 (integer :format "Match group: %v")
442 (integer :format "Emphasize group: %v")
445 :value (("_" . "_") nil default)
447 (regexp :format "Start regexp: %v")
448 (regexp :format "End regexp: %v"))
449 (boolean :format "Show start and end patterns: %[%v%]\n"
450 :on " On " :off " Off ")
452 :get (lambda (symbol)
453 (mapcar 'gnus-emphasis-custom-value-to-internal
454 (default-value symbol)))
455 :set (lambda (symbol value)
456 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
458 :group 'gnus-article-emphasis)
460 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
461 "A regexp to describe whitespace which should not be emphasized.
462 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
463 The former avoids underlining of leading and trailing whitespace,
464 and the latter avoids underlining any whitespace at all."
466 :group 'gnus-article-emphasis
469 (defface gnus-emphasis-bold '((t (:bold t)))
470 "Face used for displaying strong emphasized text (*word*)."
471 :group 'gnus-article-emphasis)
473 (defface gnus-emphasis-italic '((t (:italic t)))
474 "Face used for displaying italic emphasized text (/word/)."
475 :group 'gnus-article-emphasis)
477 (defface gnus-emphasis-underline '((t (:underline t)))
478 "Face used for displaying underlined emphasized text (_word_)."
479 :group 'gnus-article-emphasis)
481 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
482 "Face used for displaying underlined bold emphasized text (_*word*_)."
483 :group 'gnus-article-emphasis)
485 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
486 "Face used for displaying underlined italic emphasized text (_/word/_)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
490 "Face used for displaying bold italic emphasized text (/*word*/)."
491 :group 'gnus-article-emphasis)
493 (defface gnus-emphasis-underline-bold-italic
494 '((t (:bold t :italic t :underline t)))
495 "Face used for displaying underlined bold italic emphasized text.
496 Example: (_/*word*/_)."
497 :group 'gnus-article-emphasis)
499 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
500 '((t (:strikethru t)))
501 '((t (:strike-through t))))
502 "Face used for displaying strike-through text (-word-)."
503 :group 'gnus-article-emphasis)
505 (defface gnus-emphasis-highlight-words
506 '((t (:background "black" :foreground "yellow")))
507 "Face used for displaying highlighted words."
508 :group 'gnus-article-emphasis)
510 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
511 "Format for display of Date headers in article bodies.
512 See `format-time-string' for the possible values.
514 The variable can also be function, which should return a complete Date
515 header. The function is called with one argument, the time, which can
516 be fed to `format-time-string'."
517 :type '(choice string function)
518 :link '(custom-manual "(gnus)Article Date")
519 :group 'gnus-article-washing)
521 (defcustom gnus-save-all-headers t
522 "*If non-nil, don't remove any headers before saving.
523 This will be overridden by the `:headers' property that the symbol of
524 the saver function, which is specified by `gnus-default-article-saver',
526 :group 'gnus-article-saving
529 (defcustom gnus-prompt-before-saving 'always
530 "*This variable says how much prompting is to be done when saving articles.
531 If it is nil, no prompting will be done, and the articles will be
532 saved to the default files. If this variable is `always', each and
533 every article that is saved will be preceded by a prompt, even when
534 saving large batches of articles. If this variable is neither nil not
535 `always', there the user will be prompted once for a file name for
536 each invocation of the saving commands."
537 :group 'gnus-article-saving
538 :type '(choice (item always)
539 (item :tag "never" nil)
540 (sexp :tag "once" :format "%t\n" :value t)))
542 (defcustom gnus-saved-headers gnus-visible-headers
543 "Headers to keep if `gnus-save-all-headers' is nil.
544 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
545 If that variable is nil, however, all headers that match this regexp
546 will be kept while the rest will be deleted before saving. This and
547 `gnus-save-all-headers' will be overridden by the `:headers' property
548 that the symbol of the saver function, which is specified by
549 `gnus-default-article-saver', might have."
550 :group 'gnus-article-saving
553 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
554 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
555 "A function to save articles in your favourite format.
556 The function will be called by way of the `gnus-summary-save-article'
557 command, and friends such as `gnus-summary-save-article-rmail'.
559 Gnus provides the following functions:
561 * gnus-summary-save-in-rmail (Rmail format)
562 * gnus-summary-save-in-mail (Unix mail format)
563 * gnus-summary-save-in-folder (MH folder)
564 * gnus-summary-save-in-file (article format)
565 * gnus-summary-save-body-in-file (article body)
566 * gnus-summary-save-in-vm (use VM's folder format)
567 * gnus-summary-write-to-file (article format -- overwrite)
568 * gnus-summary-write-body-to-file (article body -- overwrite)
569 * gnus-summary-save-in-pipe (article format)
571 The symbol of each function may have the following properties:
574 The value non-nil means save decoded articles. This is meaningful
575 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
576 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
577 `gnus-summary-save-in-pipe'.
580 The value specifies an alternative function which appends, not
581 overwrites, articles to a file. This implies that when saving many
582 articles at a time, `gnus-prompt-before-saving' is bound to t and all
583 articles are saved in a single file. This is meaningful only with
584 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
587 The value specifies the symbol of a variable of which the value
588 specifies headers to be saved. If it is omitted,
589 `gnus-save-all-headers' and `gnus-saved-headers' control what
590 headers should be saved."
591 :group 'gnus-article-saving
592 :type '(radio (function-item gnus-summary-save-in-rmail)
593 (function-item gnus-summary-save-in-mail)
594 (function-item gnus-summary-save-in-folder)
595 (function-item gnus-summary-save-in-file)
596 (function-item gnus-summary-save-body-in-file)
597 (function-item gnus-summary-save-in-vm)
598 (function-item gnus-summary-write-to-file)
599 (function-item gnus-summary-write-body-to-file)
600 (function-item gnus-summary-save-in-pipe)
603 (defcustom gnus-article-save-coding-system
604 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
605 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
606 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
607 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
608 "Coding system used to save decoded articles to a file.
610 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
611 which can safely encode any characters in text. This is used by the
614 * gnus-summary-save-article-file
615 * gnus-summary-save-article-body-file
616 * gnus-summary-write-article-file
617 * gnus-summary-write-article-body-file
619 and the functions to which you may set `gnus-default-article-saver':
621 * gnus-summary-save-in-file
622 * gnus-summary-save-body-in-file
623 * gnus-summary-write-to-file
624 * gnus-summary-write-body-to-file
626 Those commands and functions save just text displayed in the article
627 buffer to a file if the value of this variable is non-nil. Note that
628 buttonized MIME parts will be lost in a saved file in that case.
629 Otherwise, raw articles will be saved."
630 :group 'gnus-article-saving
632 :format "%{%t%}:\n %[Value Menu%] %v"
633 (const :tag "Save raw articles" nil)
636 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
637 '((const :tag "UTF-8" utf-8)
638 (const :tag "iso-2022-7bit" iso-2022-7bit)
639 (const :tag "Emacs internal" emacs-mule)
640 (const :tag "escape-quoted" escape-quoted))))
641 (symbol :tag "Coding system")))
643 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
644 "A function generating a file name to save articles in Rmail format.
645 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
646 :group 'gnus-article-saving
649 (defcustom gnus-mail-save-name 'gnus-plain-save-name
650 "A function generating a file name to save articles in Unix mail format.
651 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
652 :group 'gnus-article-saving
655 (defcustom gnus-folder-save-name 'gnus-folder-save-name
656 "A function generating a file name to save articles in MH folder.
657 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
658 :group 'gnus-article-saving
661 (defcustom gnus-file-save-name 'gnus-numeric-save-name
662 "A function generating a file name to save articles in article format.
663 The function is called with NEWSGROUP, HEADERS, and optional
665 :group 'gnus-article-saving
668 (defcustom gnus-split-methods
669 '((gnus-article-archive-name)
670 (gnus-article-nndoc-name))
671 "*Variable used to suggest where articles are to be saved.
672 For instance, if you would like to save articles related to Gnus in
673 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
674 you could set this variable to something like:
676 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
677 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
679 This variable is an alist where the key is the match and the
680 value is a list of possible files to save in if the match is
683 If the match is a string, it is used as a regexp match on the
684 article. If the match is a symbol, that symbol will be funcalled
685 from the buffer of the article to be saved with the newsgroup as the
686 parameter. If it is a list, it will be evaled in the same buffer.
688 If this form or function returns a string, this string will be used as a
689 possible file name; and if it returns a non-nil list, that list will be
690 used as possible file names."
691 :group 'gnus-article-saving
692 :type '(repeat (choice (list :value (fun) function)
693 (cons :value ("" "") regexp (repeat string))
696 (defcustom gnus-page-delimiter "^\^L"
697 "*Regexp describing what to use as article page delimiters.
698 The default value is \"^\^L\", which is a form linefeed at the
699 beginning of a line."
701 :group 'gnus-article-various)
703 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
704 "*The format specification for the article mode line.
705 See `gnus-summary-mode-line-format' for a closer description.
707 The following additional specs are available:
709 %w The article washing status.
710 %m The number of MIME parts in the article."
712 :group 'gnus-article-various)
714 (defcustom gnus-article-mode-hook nil
715 "*A hook for Gnus article mode."
717 :group 'gnus-article-various)
719 (when (featurep 'xemacs)
720 ;; Extracted from gnus-xmas-define in order to preserve user settings
721 (when (fboundp 'turn-off-scroll-in-place)
722 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
723 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
724 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
726 (defcustom gnus-article-menu-hook nil
727 "*Hook run after the creation of the article mode menu."
729 :group 'gnus-article-various)
731 (defcustom gnus-article-prepare-hook nil
732 "*A hook called after an article has been prepared in the article buffer."
734 :group 'gnus-article-various)
736 (defcustom gnus-copy-article-ignored-headers nil
737 "List of headers to be removed when copying an article.
738 Each element is a regular expression."
739 :version "23.1" ;; No Gnus
740 :type '(repeat regexp)
741 :group 'gnus-article-various)
743 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
744 "Gnus 5.10 (Emacs-22.1)")
747 '((t (:weight bold)))
748 "Face used for highlighting a button in the article buffer."
749 :group 'gnus-article-buttons)
751 (defcustom gnus-article-button-face 'gnus-button
752 "Face used for highlighting buttons in the article buffer.
754 An article button is a piece of text that you can activate by pressing
755 `RET' or `mouse-2' above it."
757 :group 'gnus-article-buttons)
759 (defcustom gnus-article-mouse-face 'highlight
760 "Face used for mouse highlighting in the article buffer.
762 Article buttons will be displayed in this face when the cursor is
765 :group 'gnus-article-buttons)
767 (defcustom gnus-signature-face 'gnus-signature
768 "Face used for highlighting a signature in the article buffer.
769 Obsolete; use the face `gnus-signature' for customizations instead."
771 :group 'gnus-article-highlight
772 :group 'gnus-article-signature)
774 (defface gnus-signature
777 "Face used for highlighting a signature in the article buffer."
778 :group 'gnus-article-highlight
779 :group 'gnus-article-signature)
780 ;; backward-compatibility alias
781 (put 'gnus-signature-face 'face-alias 'gnus-signature)
782 (put 'gnus-signature-face 'obsolete-face "22.1")
784 (defface gnus-header-from
787 (:foreground "PaleGreen1"))
790 (:foreground "red3"))
793 "Face used for displaying from headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
798 (put 'gnus-header-from-face 'obsolete-face "22.1")
800 (defface gnus-header-subject
803 (:foreground "SeaGreen1"))
806 (:foreground "red4"))
808 (:bold t :italic t)))
809 "Face used for displaying subject headers."
810 :group 'gnus-article-headers
811 :group 'gnus-article-highlight)
812 ;; backward-compatibility alias
813 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
814 (put 'gnus-header-subject-face 'obsolete-face "22.1")
816 (defface gnus-header-newsgroups
819 (:foreground "yellow" :italic t))
822 (:foreground "MidnightBlue" :italic t))
825 "Face used for displaying newsgroups headers.
826 In the default setup this face is only used for crossposted
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
832 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
834 (defface gnus-header-name
837 (:foreground "SpringGreen2"))
840 (:foreground "maroon"))
843 "Face used for displaying header names."
844 :group 'gnus-article-headers
845 :group 'gnus-article-highlight)
846 ;; backward-compatibility alias
847 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
848 (put 'gnus-header-name-face 'obsolete-face "22.1")
850 (defface gnus-header-content
853 (:foreground "SpringGreen1" :italic t))
856 (:foreground "indianred4" :italic t))
858 (:italic t))) "Face used for displaying header content."
859 :group 'gnus-article-headers
860 :group 'gnus-article-highlight)
861 ;; backward-compatibility alias
862 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
863 (put 'gnus-header-content-face 'obsolete-face "22.1")
865 (defcustom gnus-header-face-alist
866 '(("From" nil gnus-header-from)
867 ("Subject" nil gnus-header-subject)
868 ("Newsgroups:.*," nil gnus-header-newsgroups)
869 ("" gnus-header-name gnus-header-content))
870 "*Controls highlighting of article headers.
872 An alist of the form (HEADER NAME CONTENT).
874 HEADER is a regular expression which should match the name of a
875 header and NAME and CONTENT are either face names or nil.
877 The name of each header field will be displayed using the face
878 specified by the first element in the list where HEADER matches
879 the header name and NAME is non-nil. Similarly, the content will
880 be displayed by the first non-nil matching CONTENT face."
881 :group 'gnus-article-headers
882 :group 'gnus-article-highlight
883 :type '(repeat (list (regexp :tag "Header")
885 (item :tag "skip" nil)
886 (face :value default))
887 (choice :tag "Content"
888 (item :tag "skip" nil)
889 (face :value default)))))
891 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
892 '((xface . (:face gnus-x-face)))
893 '((pbm . (:face gnus-x-face))
895 "Alist of image types and properties applied to Face and X-Face images.
898 ;; Specify the altitude of Face images in the From header.
899 \(setq gnus-face-properties-alist
900 '((pbm . (:face gnus-x-face :ascent 80))
901 (png . (:ascent 80))))
903 ;; Show Face images as pressed buttons.
904 \(setq gnus-face-properties-alist
905 '((pbm . (:face gnus-x-face :relief -2))
906 (png . (:relief -2))))
908 See the manual for the valid properties for various image types.
909 Currently, `pbm' is used for X-Face images and `png' is used for Face
910 images in Emacs. Only the `:face' property is effective on the `xface'
911 image type in XEmacs if it is built with the libcompface library."
912 :version "23.1" ;; No Gnus
913 :group 'gnus-article-headers
914 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
916 (defcustom gnus-article-decode-hook
917 '(article-decode-charset article-decode-encoded-words
918 article-decode-group-name article-decode-idna-rhs)
919 "*Hook run to decode charsets in articles."
920 :group 'gnus-article-headers
923 (defcustom gnus-display-mime-function 'gnus-display-mime
924 "Function to display MIME articles."
925 :group 'gnus-article-mime
928 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
929 "Function used to decode headers.")
931 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
932 "Function used to decode addresses.")
934 (defvar gnus-article-dumbquotes-map
954 "Table for MS-to-Latin1 translation.")
956 (defcustom gnus-ignored-mime-types nil
957 "List of MIME types that should be ignored by Gnus."
959 :group 'gnus-article-mime
960 :type '(repeat regexp))
962 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
963 "List of MIME types that should not be given buttons when rendered inline.
964 See also `gnus-buttonized-mime-types' which may override this variable.
965 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
967 :group 'gnus-article-mime
968 :type '(repeat regexp))
970 (defcustom gnus-buttonized-mime-types nil
971 "List of MIME types that should be given buttons when rendered inline.
972 If set, this variable overrides `gnus-unbuttonized-mime-types'.
973 To see e.g. security buttons you could set this to
974 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
975 this list to display radio buttons that allow you to choose one of two
976 media types those mails include. See also `mm-discouraged-alternatives'.
977 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
979 :group 'gnus-article-mime
980 :type '(repeat regexp))
982 (defcustom gnus-inhibit-mime-unbuttonizing nil
983 "If non-nil, all MIME parts get buttons.
984 When nil (the default value), then some MIME parts do not get buttons,
985 as described by the variables `gnus-buttonized-mime-types' and
986 `gnus-unbuttonized-mime-types'."
988 :group 'gnus-article-mime
991 (defcustom gnus-body-boundary-delimiter "_"
992 "String used to delimit header and body.
993 This variable is used by `gnus-article-treat-body-boundary' which can
994 be controlled by `gnus-treat-body-boundary'."
996 :group 'gnus-article-various
997 :type '(choice (item :tag "None" :value nil)
1000 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
1001 "/usr/share/picons")
1002 "Defines the location of the faces database.
1003 For information on obtaining this database of pretty pictures, please
1004 see http://www.cs.indiana.edu/picons/ftp/index.html"
1006 :type '(repeat directory)
1007 :link '(url-link :tag "download"
1008 "http://www.cs.indiana.edu/picons/ftp/index.html")
1009 :link '(custom-manual "(gnus)Picons")
1012 (defun gnus-picons-installed-p ()
1013 "Say whether picons are installed on your machine."
1014 (let ((installed nil))
1015 (dolist (database gnus-picon-databases)
1016 (when (file-exists-p database)
1017 (setq installed t)))
1020 (defcustom gnus-article-mime-part-function nil
1021 "Function called with a MIME handle as the argument.
1022 This is meant for people who want to do something automatic based
1023 on parts -- for instance, adding Vcard info to a database."
1024 :group 'gnus-article-mime
1025 :type '(choice (const nil)
1028 (defcustom gnus-mime-multipart-functions nil
1029 "An alist of MIME types to functions to display them."
1031 :group 'gnus-article-mime
1032 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1034 (defcustom gnus-article-date-lapsed-new-header nil
1035 "Whether the X-Sent and Date headers can coexist.
1036 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1037 either replace the old \"Date:\" header (if this variable is nil), or
1038 be added below it (otherwise)."
1040 :group 'gnus-article-headers
1043 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1044 "Function called with a MIME handle as the argument.
1045 This is meant for people who want to view first matched part.
1046 For `undisplayed-alternative' (default), the first undisplayed
1047 part or alternative part is used. For `undisplayed', the first
1048 undisplayed part is used. For a function, the first part which
1049 the function return t is used. For nil, the first part is
1052 :group 'gnus-article-mime
1054 (item :tag "first" :value nil)
1055 (item :tag "undisplayed" :value undisplayed)
1056 (item :tag "undisplayed or alternative"
1057 :value undisplayed-alternative)
1060 (defcustom gnus-mime-action-alist
1061 '(("save to file" . gnus-mime-save-part)
1062 ("save and strip" . gnus-mime-save-part-and-strip)
1063 ("replace with file" . gnus-mime-replace-part)
1064 ("delete part" . gnus-mime-delete-part)
1065 ("display as text" . gnus-mime-inline-part)
1066 ("view the part" . gnus-mime-view-part)
1067 ("pipe to command" . gnus-mime-pipe-part)
1068 ("toggle display" . gnus-article-press-button)
1069 ("toggle display" . gnus-article-view-part-as-charset)
1070 ("view as type" . gnus-mime-view-part-as-type)
1071 ("view internally" . gnus-mime-view-part-internally)
1072 ("view externally" . gnus-mime-view-part-externally))
1073 "An alist of actions that run on the MIME attachment."
1074 :group 'gnus-article-mime
1075 :type '(repeat (cons (string :tag "name")
1078 (defcustom gnus-auto-select-part 1
1079 "Advance to next MIME part when deleting or stripping parts.
1081 When 0, point will be placed on the same part as before. When
1082 positive (negative), move point forward (backwards) this many
1083 parts. When nil, redisplay article."
1084 :version "23.1" ;; No Gnus
1085 :group 'gnus-article-mime
1086 :type '(choice (const nil :tag "Redisplay article.")
1087 (const 1 :tag "Next part.")
1088 (const 0 :tag "Current part.")
1092 ;;; The treatment variables
1095 (defvar gnus-part-display-hook nil
1096 "Hook called on parts that are to receive treatment.")
1098 (defvar gnus-article-treat-custom
1099 '(choice (const :tag "Off" nil)
1101 (const :tag "Header" head)
1102 (const :tag "First" first)
1103 (const :tag "Last" last)
1104 (integer :tag "Less")
1105 (repeat :tag "Groups" regexp)
1106 (sexp :tag "Predicate")))
1108 (defvar gnus-article-treat-head-custom
1109 '(choice (const :tag "Off" nil)
1110 (const :tag "Header" head)))
1112 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1116 (defvar gnus-inhibit-treatment nil
1117 "Whether to inhibit treatment.")
1119 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1120 "Highlight the signature.
1121 Valid values are nil, t, `head', `first', `last', an integer or a
1122 predicate. See Info node `(gnus)Customizing Articles'."
1123 :group 'gnus-article-treat
1124 :link '(custom-manual "(gnus)Customizing Articles")
1125 :type gnus-article-treat-custom)
1126 (put 'gnus-treat-highlight-signature 'highlight t)
1128 (defcustom gnus-treat-buttonize 100000
1130 Valid values are nil, t, `head', `first', `last', an integer or a
1131 predicate. See Info node `(gnus)Customizing Articles'."
1132 :group 'gnus-article-treat
1133 :link '(custom-manual "(gnus)Customizing Articles")
1134 :type gnus-article-treat-custom)
1135 (put 'gnus-treat-buttonize 'highlight t)
1137 (defcustom gnus-treat-buttonize-head 'head
1138 "Add buttons to the head.
1139 Valid values are nil, t, `head', `first', `last', an integer or a
1140 predicate. See Info node `(gnus)Customizing Articles'."
1141 :group 'gnus-article-treat
1142 :link '(custom-manual "(gnus)Customizing Articles")
1143 :type gnus-article-treat-head-custom)
1144 (put 'gnus-treat-buttonize-head 'highlight t)
1146 (defcustom gnus-treat-emphasize 50000
1148 Valid values are nil, t, `head', `first', `last', an integer or a
1149 predicate. See Info node `(gnus)Customizing Articles'."
1150 :group 'gnus-article-treat
1151 :link '(custom-manual "(gnus)Customizing Articles")
1152 :type gnus-article-treat-custom)
1153 (put 'gnus-treat-emphasize 'highlight t)
1155 (defcustom gnus-treat-strip-cr nil
1156 "Remove carriage returns.
1157 Valid values are nil, t, `head', `first', `last', an integer or a
1158 predicate. See Info node `(gnus)Customizing Articles'."
1160 :group 'gnus-article-treat
1161 :link '(custom-manual "(gnus)Customizing Articles")
1162 :type gnus-article-treat-custom)
1164 (defcustom gnus-treat-unsplit-urls nil
1165 "Remove newlines from within URLs.
1166 Valid values are nil, t, `head', `first', `last', an integer or a
1167 predicate. See Info node `(gnus)Customizing Articles'."
1169 :group 'gnus-article-treat
1170 :link '(custom-manual "(gnus)Customizing Articles")
1171 :type gnus-article-treat-custom)
1173 (defcustom gnus-treat-leading-whitespace nil
1174 "Remove leading whitespace in headers.
1175 Valid values are nil, t, `head', `first', `last', an integer or a
1176 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-custom)
1182 (defcustom gnus-treat-hide-headers 'head
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-head-custom)
1190 (defcustom gnus-treat-hide-boring-headers nil
1191 "Hide boring headers.
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-head-custom)
1198 (defcustom gnus-treat-hide-signature nil
1199 "Hide the signature.
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1206 (defcustom gnus-treat-fill-article nil
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1210 :group 'gnus-article-treat
1211 :link '(custom-manual "(gnus)Customizing Articles")
1212 :type gnus-article-treat-custom)
1214 (defcustom gnus-treat-hide-citation nil
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1218 :group 'gnus-article-treat
1219 :link '(custom-manual "(gnus)Customizing Articles")
1220 :type gnus-article-treat-custom)
1222 (defcustom gnus-treat-hide-citation-maybe nil
1224 Valid values are nil, t, `head', `first', `last', an integer or a
1225 predicate. See Info node `(gnus)Customizing Articles'."
1226 :group 'gnus-article-treat
1227 :link '(custom-manual "(gnus)Customizing Articles")
1228 :type gnus-article-treat-custom)
1230 (defcustom gnus-treat-strip-list-identifiers 'head
1231 "Strip list identifiers from `gnus-list-identifiers`.
1232 Valid values are nil, t, `head', `first', `last', an integer or a
1233 predicate. See Info node `(gnus)Customizing Articles'."
1235 :group 'gnus-article-treat
1236 :link '(custom-manual "(gnus)Customizing Articles")
1237 :type gnus-article-treat-custom)
1239 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1240 "Gnus 5.10 (Emacs 22.1)")
1242 (defcustom gnus-treat-strip-pem nil
1243 "Strip PEM signatures.
1244 Valid values are nil, t, `head', `first', `last', an integer or a
1245 predicate. See Info node `(gnus)Customizing Articles'."
1246 :group 'gnus-article-treat
1247 :link '(custom-manual "(gnus)Customizing Articles")
1248 :type gnus-article-treat-custom)
1250 (defcustom gnus-treat-strip-banner t
1251 "Strip banners from articles.
1252 The banner to be stripped is specified in the `banner' group parameter.
1253 Valid values are nil, t, `head', `first', `last', an integer or a
1254 predicate. See Info node `(gnus)Customizing Articles'."
1255 :group 'gnus-article-treat
1256 :link '(custom-manual "(gnus)Customizing Articles")
1257 :type gnus-article-treat-custom)
1259 (defcustom gnus-treat-highlight-headers 'head
1260 "Highlight the headers.
1261 Valid values are nil, t, `head', `first', `last', an integer or a
1262 predicate. See Info node `(gnus)Customizing Articles'."
1263 :group 'gnus-article-treat
1264 :link '(custom-manual "(gnus)Customizing Articles")
1265 :type gnus-article-treat-head-custom)
1266 (put 'gnus-treat-highlight-headers 'highlight t)
1268 (defcustom gnus-treat-highlight-citation t
1269 "Highlight cited text.
1270 Valid values are nil, t, `head', `first', `last', an integer or a
1271 predicate. See Info node `(gnus)Customizing Articles'."
1272 :group 'gnus-article-treat
1273 :link '(custom-manual "(gnus)Customizing Articles")
1274 :type gnus-article-treat-custom)
1275 (put 'gnus-treat-highlight-citation 'highlight t)
1277 (defcustom gnus-treat-date-ut nil
1278 "Display the Date in UT (GMT).
1279 Valid values are nil, t, `head', `first', `last', an integer or a
1280 predicate. See Info node `(gnus)Customizing Articles'."
1281 :group 'gnus-article-treat
1282 :link '(custom-manual "(gnus)Customizing Articles")
1283 :type gnus-article-treat-head-custom)
1285 (defcustom gnus-treat-date-local nil
1286 "Display the Date in the local timezone.
1287 Valid values are nil, t, `head', `first', `last', an integer or a
1288 predicate. See Info node `(gnus)Customizing Articles'."
1289 :group 'gnus-article-treat
1290 :link '(custom-manual "(gnus)Customizing Articles")
1291 :type gnus-article-treat-head-custom)
1293 (defcustom gnus-treat-date-english nil
1294 "Display the Date in a format that can be read aloud in English.
1295 Valid values are nil, t, `head', `first', `last', an integer or a
1296 predicate. See Info node `(gnus)Customizing Articles'."
1298 :group 'gnus-article-treat
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :type gnus-article-treat-head-custom)
1302 (defcustom gnus-treat-date-lapsed nil
1303 "Display the Date header in a way that says how much time has elapsed.
1304 Valid values are nil, t, `head', `first', `last', an integer or a
1305 predicate. See Info node `(gnus)Customizing Articles'."
1306 :group 'gnus-article-treat
1307 :link '(custom-manual "(gnus)Customizing Articles")
1308 :type gnus-article-treat-head-custom)
1310 (defcustom gnus-treat-date-original nil
1311 "Display the date in the original timezone.
1312 Valid values are nil, t, `head', `first', `last', an integer or a
1313 predicate. See Info node `(gnus)Customizing Articles'."
1314 :group 'gnus-article-treat
1315 :link '(custom-manual "(gnus)Customizing Articles")
1316 :type gnus-article-treat-head-custom)
1318 (defcustom gnus-treat-date-iso8601 nil
1319 "Display the date in the ISO8601 format.
1320 Valid values are nil, t, `head', `first', `last', an integer or a
1321 predicate. See Info node `(gnus)Customizing Articles'."
1323 :group 'gnus-article-treat
1324 :link '(custom-manual "(gnus)Customizing Articles")
1325 :type gnus-article-treat-head-custom)
1327 (defcustom gnus-treat-date-user-defined nil
1328 "Display the date in a user-defined format.
1329 The format is defined by the `gnus-article-time-format' variable.
1330 Valid values are nil, t, `head', `first', `last', an integer or a
1331 predicate. See Info node `(gnus)Customizing Articles'."
1332 :group 'gnus-article-treat
1333 :link '(custom-manual "(gnus)Customizing Articles")
1334 :type gnus-article-treat-head-custom)
1336 (defcustom gnus-treat-strip-headers-in-body t
1337 "Strip the X-No-Archive header line from the beginning of the body.
1338 Valid values are nil, t, `head', `first', `last', an integer or a
1339 predicate. See Info node `(gnus)Customizing Articles'."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-trailing-blank-lines nil
1346 "Strip trailing blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'.
1350 When set to t, it also strips trailing blanks in all MIME parts.
1351 Consider to use `last' instead."
1352 :group 'gnus-article-treat
1353 :link '(custom-manual "(gnus)Customizing Articles")
1354 :type gnus-article-treat-custom)
1356 (defcustom gnus-treat-strip-leading-blank-lines nil
1357 "Strip leading blank lines.
1358 Valid values are nil, t, `head', `first', `last', an integer or a
1359 predicate. See Info node `(gnus)Customizing Articles'.
1361 When set to t, it also strips trailing blanks in all MIME parts."
1362 :group 'gnus-article-treat
1363 :link '(custom-manual "(gnus)Customizing Articles")
1364 :type gnus-article-treat-custom)
1366 (defcustom gnus-treat-strip-multiple-blank-lines nil
1367 "Strip multiple blank lines.
1368 Valid values are nil, t, `head', `first', `last', an integer or a
1369 predicate. See Info node `(gnus)Customizing Articles'."
1370 :group 'gnus-article-treat
1371 :link '(custom-manual "(gnus)Customizing Articles")
1372 :type gnus-article-treat-custom)
1374 (defcustom gnus-treat-unfold-headers 'head
1375 "Unfold folded header lines.
1376 Valid values are nil, t, `head', `first', `last', an integer or a
1377 predicate. See Info node `(gnus)Customizing Articles'."
1379 :group 'gnus-article-treat
1380 :link '(custom-manual "(gnus)Customizing Articles")
1381 :type gnus-article-treat-custom)
1383 (defcustom gnus-article-unfold-long-headers nil
1384 "If non-nil, allow unfolding headers even if the header is long.
1385 If it is a regexp, only long headers matching this regexp are unfolded.
1386 If it is t, all long headers are unfolded.
1388 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1389 :version "23.1" ;; No Gnus
1390 :group 'gnus-article-treat
1391 :type '(choice (const nil)
1392 (const :tag "all" t)
1395 (defcustom gnus-treat-fold-headers nil
1397 Valid values are nil, t, `head', `first', `last', an integer or a
1398 predicate. See Info node `(gnus)Customizing Articles'."
1400 :group 'gnus-article-treat
1401 :link '(custom-manual "(gnus)Customizing Articles")
1402 :type gnus-article-treat-custom)
1404 (defcustom gnus-treat-fold-newsgroups 'head
1405 "Fold the Newsgroups and Followup-To headers.
1406 Valid values are nil, t, `head', `first', `last', an integer or a
1407 predicate. See Info node `(gnus)Customizing Articles'."
1409 :group 'gnus-article-treat
1410 :link '(custom-manual "(gnus)Customizing Articles")
1411 :type gnus-article-treat-custom)
1413 (defcustom gnus-treat-overstrike t
1414 "Treat overstrike highlighting.
1415 Valid values are nil, t, `head', `first', `last', an integer or a
1416 predicate. See Info node `(gnus)Customizing Articles'."
1417 :group 'gnus-article-treat
1418 :link '(custom-manual "(gnus)Customizing Articles")
1419 :type gnus-article-treat-custom)
1420 (put 'gnus-treat-overstrike 'highlight t)
1422 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1423 "Treat ANSI SGR control sequences.
1424 Valid values are nil, t, `head', `first', `last', an integer or a
1425 predicate. See Info node `(gnus)Customizing Articles'."
1426 :group 'gnus-article-treat
1427 :link '(custom-manual "(gnus)Customizing Articles")
1428 :type gnus-article-treat-custom)
1430 (make-obsolete-variable 'gnus-treat-display-xface
1431 'gnus-treat-display-x-face "22.1")
1433 (defcustom gnus-treat-display-x-face
1434 (and (not noninteractive)
1435 (gnus-image-type-available-p 'xbm)
1436 (if (featurep 'xemacs)
1439 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1440 (executable-find "icontopbm"))
1441 ;; shell-command-to-string may signal an error, e.g. if
1442 ;; shell-file-name is not found.
1445 "Display X-Face headers.
1446 Valid values are nil and `head'.
1447 See Info node `(gnus)Customizing Articles' and Info node
1448 `(gnus)X-Face' for details."
1449 :group 'gnus-article-treat
1451 :link '(custom-manual "(gnus)Customizing Articles")
1452 :link '(custom-manual "(gnus)X-Face")
1453 :type gnus-article-treat-head-custom
1454 :set (lambda (symbol value)
1457 (cond ((or (boundp symbol) (get symbol 'saved-value))
1459 ((boundp 'gnus-treat-display-xface)
1461 ** gnus-treat-display-xface is an obsolete variable;\
1462 use gnus-treat-display-x-face instead")
1463 (default-value 'gnus-treat-display-xface))
1464 ((get 'gnus-treat-display-xface 'saved-value)
1466 ** gnus-treat-display-xface is an obsolete variable;\
1467 use gnus-treat-display-x-face instead")
1468 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1471 (put 'gnus-treat-display-x-face 'highlight t)
1473 (defcustom gnus-treat-display-face
1474 (and (not noninteractive)
1475 (gnus-image-type-available-p 'png)
1477 "Display Face headers.
1478 Valid values are nil, t, `head', `first', `last', an integer or a
1479 predicate. See Info node `(gnus)Customizing Articles' and Info
1480 node `(gnus)Face' for details."
1481 :group 'gnus-article-treat
1483 :link '(custom-manual "(gnus)Customizing Articles")
1484 :link '(custom-manual "(gnus)X-Face")
1485 :type gnus-article-treat-head-custom)
1486 (put 'gnus-treat-display-face 'highlight t)
1488 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1490 Valid values are nil, t, `head', `first', `last', an integer or a
1491 predicate. See Info node `(gnus)Customizing Articles' and Info
1492 node `(gnus)Smileys' for details."
1493 :group 'gnus-article-treat
1495 :link '(custom-manual "(gnus)Customizing Articles")
1496 :link '(custom-manual "(gnus)Smileys")
1497 :type gnus-article-treat-custom)
1498 (put 'gnus-treat-display-smileys 'highlight t)
1500 (defcustom gnus-treat-from-picon
1501 (if (and (gnus-image-type-available-p 'xpm)
1502 (gnus-picons-installed-p))
1504 "Display picons in the From header.
1505 Valid values are nil, t, `head', `first', `last', an integer or a
1506 predicate. See Info node `(gnus)Customizing Articles' and Info
1507 node `(gnus)Picons' for details."
1509 :group 'gnus-article-treat
1511 :link '(custom-manual "(gnus)Customizing Articles")
1512 :link '(custom-manual "(gnus)Picons")
1513 :type gnus-article-treat-head-custom)
1514 (put 'gnus-treat-from-picon 'highlight t)
1516 (defcustom gnus-treat-mail-picon
1517 (if (and (gnus-image-type-available-p 'xpm)
1518 (gnus-picons-installed-p))
1520 "Display picons in To and Cc headers.
1521 Valid values are nil, t, `head', `first', `last', an integer or a
1522 predicate. See Info node `(gnus)Customizing Articles' and Info
1523 node `(gnus)Picons' for details."
1525 :group 'gnus-article-treat
1527 :link '(custom-manual "(gnus)Customizing Articles")
1528 :link '(custom-manual "(gnus)Picons")
1529 :type gnus-article-treat-head-custom)
1530 (put 'gnus-treat-mail-picon 'highlight t)
1532 (defcustom gnus-treat-newsgroups-picon
1533 (if (and (gnus-image-type-available-p 'xpm)
1534 (gnus-picons-installed-p))
1536 "Display picons in the Newsgroups and Followup-To headers.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles' and Info
1539 node `(gnus)Picons' for details."
1541 :group 'gnus-article-treat
1543 :link '(custom-manual "(gnus)Customizing Articles")
1544 :link '(custom-manual "(gnus)Picons")
1545 :type gnus-article-treat-head-custom)
1546 (put 'gnus-treat-newsgroups-picon 'highlight t)
1548 (defcustom gnus-treat-from-gravatar nil
1549 "Display gravatars in the From header.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate. See Info node `(gnus)Customizing Articles' and Info
1552 node `(gnus)Gravatars' for details."
1554 :group 'gnus-article-treat
1555 :group 'gnus-gravatar
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :link '(custom-manual "(gnus)Gravatars")
1558 :type gnus-article-treat-head-custom)
1559 (put 'gnus-treat-from-gravatar 'highlight t)
1561 (defcustom gnus-treat-mail-gravatar nil
1562 "Display gravatars in To and Cc headers.
1563 Valid values are nil, t, `head', `first', `last', an integer or a
1564 predicate. See Info node `(gnus)Customizing Articles' and Info
1565 node `(gnus)Gravatars' for details."
1567 :group 'gnus-article-treat
1568 :group 'gnus-gravatar
1569 :link '(custom-manual "(gnus)Customizing Articles")
1570 :link '(custom-manual "(gnus)Gravatars")
1571 :type gnus-article-treat-head-custom)
1572 (put 'gnus-treat-mail-gravatar 'highlight t)
1574 (defcustom gnus-treat-body-boundary
1575 (if (or gnus-treat-newsgroups-picon
1576 gnus-treat-mail-picon
1577 gnus-treat-from-picon
1578 gnus-treat-from-gravatar
1579 gnus-treat-mail-gravatar)
1580 ;; If there's much decoration, the user might prefer a boundery.
1583 "Draw a boundary at the end of the headers.
1584 Valid values are nil and `head'.
1585 See Info node `(gnus)Customizing Articles' for details."
1587 :group 'gnus-article-treat
1588 :link '(custom-manual "(gnus)Customizing Articles")
1589 :type gnus-article-treat-head-custom)
1591 (defcustom gnus-treat-capitalize-sentences nil
1592 "Capitalize sentence-starting words.
1593 Valid values are nil, t, `head', `first', `last', an integer or a
1594 predicate. See Info node `(gnus)Customizing Articles'."
1596 :group 'gnus-article-treat
1597 :link '(custom-manual "(gnus)Customizing Articles")
1598 :type gnus-article-treat-custom)
1600 (defcustom gnus-treat-wash-html nil
1602 Valid values are nil, t, `head', `first', `last', an integer or a
1603 predicate. See Info node `(gnus)Customizing Articles'."
1605 :group 'gnus-article-treat
1606 :link '(custom-manual "(gnus)Customizing Articles")
1607 :type gnus-article-treat-custom)
1609 (defcustom gnus-treat-fill-long-lines nil
1611 Valid values are nil, t, `head', `first', `last', an integer or a
1612 predicate. See Info node `(gnus)Customizing Articles'."
1613 :group 'gnus-article-treat
1614 :link '(custom-manual "(gnus)Customizing Articles")
1615 :type gnus-article-treat-custom)
1617 (defcustom gnus-treat-play-sounds nil
1619 Valid values are nil, t, `head', `first', `last', an integer or a
1620 predicate. See Info node `(gnus)Customizing Articles'."
1622 :group 'gnus-article-treat
1623 :link '(custom-manual "(gnus)Customizing Articles")
1624 :type gnus-article-treat-custom)
1626 (defcustom gnus-treat-x-pgp-sig nil
1628 To automatically treat X-PGP-Sig, set it to head.
1629 Valid values are nil, t, `head', `first', `last', an integer or a
1630 predicate. See Info node `(gnus)Customizing Articles'."
1632 :group 'gnus-article-treat
1633 :group 'mime-security
1634 :link '(custom-manual "(gnus)Customizing Articles")
1635 :type gnus-article-treat-custom)
1637 (defvar gnus-article-encrypt-protocol-alist
1638 '(("PGP" . mml2015-self-encrypt)))
1640 ;; Set to nil if more than one protocol added to
1641 ;; gnus-article-encrypt-protocol-alist.
1642 (defcustom gnus-article-encrypt-protocol "PGP"
1643 "The protocol used for encrypt articles.
1644 It is a string, such as \"PGP\". If nil, ask user."
1647 :group 'mime-security)
1649 (defvar gnus-article-wash-function nil
1650 "Function used for converting HTML into text.")
1652 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1653 (mm-coding-system-p 'utf-8)
1654 (executable-find idna-program))
1655 "Whether IDNA decoding of headers is used when viewing messages.
1656 This requires GNU Libidn, and by default only enabled if it is found."
1658 :group 'gnus-article-headers
1661 (defcustom gnus-article-over-scroll nil
1662 "If non-nil, allow scrolling the article buffer even when there no more text."
1664 :group 'gnus-article
1667 ;;; Internal variables
1669 (defvar gnus-english-month-names
1670 '("January" "February" "March" "April" "May" "June" "July" "August"
1671 "September" "October" "November" "December"))
1673 (defvar article-goto-body-goes-to-point-min-p nil)
1674 (defvar gnus-article-wash-types nil)
1675 (defvar gnus-article-emphasis-alist nil)
1676 (defvar gnus-article-image-alist nil)
1678 (defvar gnus-article-mime-handle-alist-1 nil)
1679 (defvar gnus-treatment-function-alist
1680 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1681 (gnus-treat-strip-banner gnus-article-strip-banner)
1682 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1683 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1684 (gnus-treat-buttonize gnus-article-add-buttons)
1685 (gnus-treat-fill-article gnus-article-fill-cited-article)
1686 (gnus-treat-fill-long-lines gnus-article-fill-long-lines)
1687 (gnus-treat-strip-cr gnus-article-remove-cr)
1688 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1689 (gnus-treat-date-ut gnus-article-date-ut)
1690 (gnus-treat-date-local gnus-article-date-local)
1691 (gnus-treat-date-english gnus-article-date-english)
1692 (gnus-treat-date-original gnus-article-date-original)
1693 (gnus-treat-date-user-defined gnus-article-date-user)
1694 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1695 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1696 (gnus-treat-display-x-face gnus-article-display-x-face)
1697 (gnus-treat-display-face gnus-article-display-face)
1698 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1699 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1700 (gnus-treat-hide-signature gnus-article-hide-signature)
1701 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1702 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1703 (gnus-treat-strip-pem gnus-article-hide-pem)
1704 (gnus-treat-from-picon gnus-treat-from-picon)
1705 (gnus-treat-mail-picon gnus-treat-mail-picon)
1706 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1707 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1708 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1709 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1710 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1711 (gnus-treat-strip-trailing-blank-lines
1712 gnus-article-remove-trailing-blank-lines)
1713 (gnus-treat-strip-leading-blank-lines
1714 gnus-article-strip-leading-blank-lines)
1715 (gnus-treat-strip-multiple-blank-lines
1716 gnus-article-strip-multiple-blank-lines)
1717 (gnus-treat-overstrike gnus-article-treat-overstrike)
1718 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1719 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1720 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1721 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1722 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1723 (gnus-treat-display-smileys gnus-treat-smiley)
1724 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1725 (gnus-treat-wash-html gnus-article-wash-html)
1726 (gnus-treat-emphasize gnus-article-emphasize)
1727 (gnus-treat-hide-citation gnus-article-hide-citation)
1728 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1729 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1730 (gnus-treat-body-boundary gnus-article-treat-body-boundary)
1731 (gnus-treat-play-sounds gnus-earcon-display)))
1733 (defvar gnus-article-mime-handle-alist nil)
1734 (defvar article-lapsed-timer nil)
1735 (defvar gnus-article-current-summary nil)
1737 (defvar gnus-article-mode-syntax-table
1738 (let ((table (copy-syntax-table text-mode-syntax-table)))
1739 ;; This causes the citation match run O(2^n).
1740 ;; (modify-syntax-entry ?- "w" table)
1741 (modify-syntax-entry ?> ")<" table)
1742 (modify-syntax-entry ?< "(>" table)
1743 ;; make M-. in article buffers work for `foo' strings
1744 (modify-syntax-entry ?' " " table)
1745 (modify-syntax-entry ?` " " table)
1747 "Syntax table used in article mode buffers.
1748 Initialized from `text-mode-syntax-table.")
1750 (defvar gnus-save-article-buffer nil)
1752 (defvar gnus-number-of-articles-to-be-saved nil)
1754 (defvar gnus-inhibit-hiding nil)
1756 (defvar gnus-article-edit-mode nil)
1758 ;;; Macros for dealing with the article buffer.
1760 (defmacro gnus-with-article-headers (&rest forms)
1761 `(with-current-buffer gnus-article-buffer
1763 (let ((inhibit-read-only t)
1764 (inhibit-point-motion-hooks t)
1765 (case-fold-search t))
1766 (article-narrow-to-head)
1769 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1770 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1772 (defmacro gnus-with-article-buffer (&rest forms)
1773 `(with-current-buffer gnus-article-buffer
1774 (let ((inhibit-read-only t))
1777 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1778 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1780 (defun gnus-article-goto-header (header)
1781 "Go to HEADER, which is a regular expression."
1782 (re-search-forward (concat "^\\(" header "\\):") nil t))
1784 (defsubst gnus-article-hide-text (b e props)
1785 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1786 (gnus-add-text-properties-when 'article-type nil b e props)
1787 (when (memq 'intangible props)
1789 (max (1- b) (point-min))
1790 b 'intangible (cddr (memq 'intangible props)))))
1792 (defsubst gnus-article-unhide-text (b e)
1793 "Remove hidden text properties from region between B and E."
1794 (remove-text-properties b e gnus-hidden-properties)
1795 (when (memq 'intangible gnus-hidden-properties)
1796 (put-text-property (max (1- b) (point-min))
1797 b 'intangible nil)))
1799 (defun gnus-article-hide-text-type (b e type)
1800 "Hide text of TYPE between B and E."
1801 (gnus-add-wash-type type)
1802 (gnus-article-hide-text
1803 b e (cons 'article-type (cons type gnus-hidden-properties))))
1805 (defun gnus-article-unhide-text-type (b e type)
1806 "Unhide text of TYPE between B and E."
1807 (gnus-delete-wash-type type)
1808 (remove-text-properties
1809 b e (cons 'article-type (cons type gnus-hidden-properties)))
1810 (when (memq 'intangible gnus-hidden-properties)
1811 (put-text-property (max (1- b) (point-min))
1812 b 'intangible nil)))
1814 (defun gnus-article-hide-text-of-type (type)
1815 "Hide text of TYPE in the current buffer."
1817 (let ((b (point-min))
1819 (while (setq b (text-property-any b e 'article-type type))
1820 (add-text-properties b (incf b) gnus-hidden-properties)))))
1822 (defun gnus-article-delete-text-of-type (type)
1823 "Delete text of TYPE in the current buffer."
1825 (let ((b (point-min)))
1826 (if (eq type 'multipart)
1827 ;; Remove MIME buttons associated with multipart/alternative parts.
1830 (while (if (get-text-property (point) 'gnus-part)
1832 (when (setq b (next-single-property-change (point)
1837 (skip-chars-forward "\n")
1838 (when (eq (get-text-property b 'article-type) 'multipart)
1839 (delete-region b (point)))))
1840 (while (setq b (text-property-any b (point-max) 'article-type type))
1842 b (or (text-property-not-all b (point-max) 'article-type type)
1845 (defun gnus-article-delete-invisible-text ()
1846 "Delete all invisible text in the current buffer."
1848 (let ((b (point-min)))
1849 (while (setq b (text-property-any b (point-max) 'invisible t))
1851 b (or (text-property-not-all b (point-max) 'invisible t)
1854 (defun gnus-article-text-type-exists-p (type)
1855 "Say whether any text of type TYPE exists in the buffer."
1856 (text-property-any (point-min) (point-max) 'article-type type))
1858 (defsubst gnus-article-header-rank ()
1859 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1860 (let ((list gnus-sorted-header-list)
1863 (if (looking-at (car list))
1865 (setq list (cdr list))
1869 (defun article-hide-headers (&optional arg delete)
1870 "Hide unwanted headers and possibly sort them as well."
1872 ;; This function might be inhibited.
1873 (unless gnus-inhibit-hiding
1874 (let ((inhibit-read-only t)
1875 (case-fold-search t)
1876 (max (1+ (length gnus-sorted-header-list)))
1877 (inhibit-point-motion-hooks t)
1878 (cur (current-buffer))
1879 ignored visible beg)
1881 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1882 ;; group parameters, so we should go to the summary buffer.
1885 (progn (set-buffer gnus-summary-buffer) t)
1887 (setq ignored (when (not gnus-visible-headers)
1888 (cond ((stringp gnus-ignored-headers)
1889 gnus-ignored-headers)
1890 ((listp gnus-ignored-headers)
1891 (mapconcat 'identity
1892 gnus-ignored-headers
1894 visible (cond ((stringp gnus-visible-headers)
1895 gnus-visible-headers)
1896 ((and gnus-visible-headers
1897 (listp gnus-visible-headers))
1898 (mapconcat 'identity
1899 gnus-visible-headers
1903 ;; First we narrow to just the headers.
1904 (article-narrow-to-head)
1905 ;; Hide any "From " lines at the beginning of (mail) articles.
1906 (while (looking-at "From ")
1909 (delete-region (point-min) (point)))
1910 ;; Then treat the rest of the header lines.
1911 ;; Then we use the two regular expressions
1912 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1913 ;; select which header lines is to remain visible in the
1915 (while (re-search-forward "^[^ \t:]*:" nil t)
1917 ;; Mark the rank of the header.
1919 (point) (1+ (point)) 'message-rank
1920 (if (or (and visible (looking-at visible))
1922 (not (looking-at ignored))))
1923 (gnus-article-header-rank)
1926 (message-sort-headers-1)
1927 (when (setq beg (text-property-any
1928 (point-min) (point-max) 'message-rank (+ 2 max)))
1929 ;; We delete the unwanted headers.
1930 (gnus-add-wash-type 'headers)
1931 (add-text-properties (point-min) (+ 5 (point-min))
1932 '(article-type headers dummy-invisible t))
1933 (delete-region beg (point-max))))))))
1935 (defun article-hide-boring-headers (&optional arg)
1936 "Toggle hiding of headers that aren't very interesting.
1937 If given a negative prefix, always show; if given a positive prefix,
1939 (interactive (gnus-article-hidden-arg))
1940 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1941 (not gnus-show-all-headers))
1944 (let ((inhibit-read-only t)
1945 (inhibit-point-motion-hooks t))
1946 (article-narrow-to-head)
1947 (dolist (elem gnus-boring-article-headers)
1948 (goto-char (point-min))
1950 ;; Hide empty headers.
1952 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1954 (gnus-article-hide-text-type
1958 (if (re-search-forward "^[^ \t]" nil t)
1962 ;; Hide boring Newsgroups header.
1963 ((eq elem 'newsgroups)
1964 (when (gnus-string-equal
1965 (gnus-fetch-field "newsgroups")
1966 (gnus-group-real-name
1967 (if (boundp 'gnus-newsgroup-name)
1970 (gnus-article-hide-header "newsgroups")))
1971 ((eq elem 'to-address)
1972 (let ((to (message-fetch-field "to"))
1974 (gnus-parameter-to-address
1975 (if (boundp 'gnus-newsgroup-name)
1976 gnus-newsgroup-name ""))))
1977 (when (and to to-address
1980 ;; only one address in To
1981 (nth 1 (mail-extract-address-components to))
1983 (gnus-article-hide-header "to"))))
1985 (let ((to (message-fetch-field "to"))
1987 (gnus-parameter-to-list
1988 (if (boundp 'gnus-newsgroup-name)
1989 gnus-newsgroup-name ""))))
1990 (when (and to to-list
1993 ;; only one address in To
1994 (nth 1 (mail-extract-address-components to))
1996 (gnus-article-hide-header "to"))))
1998 (let ((cc (message-fetch-field "cc"))
2000 (gnus-parameter-to-list
2001 (if (boundp 'gnus-newsgroup-name)
2002 gnus-newsgroup-name ""))))
2003 (when (and cc to-list
2006 ;; only one address in CC
2007 (nth 1 (mail-extract-address-components cc))
2009 (gnus-article-hide-header "cc"))))
2010 ((eq elem 'followup-to)
2011 (when (gnus-string-equal
2012 (message-fetch-field "followup-to")
2013 (message-fetch-field "newsgroups"))
2014 (gnus-article-hide-header "followup-to")))
2015 ((eq elem 'reply-to)
2016 (if (gnus-group-find-parameter
2017 gnus-newsgroup-name 'broken-reply-to)
2018 (gnus-article-hide-header "reply-to")
2019 (let ((from (message-fetch-field "from"))
2020 (reply-to (message-fetch-field "reply-to")))
2027 (lambda (x) (downcase (cadr x)))
2028 (mail-extract-address-components from t))
2031 (lambda (x) (downcase (cadr x)))
2032 (mail-extract-address-components reply-to t))
2034 (gnus-article-hide-header "reply-to")))))
2036 (let ((date (with-current-buffer gnus-original-article-buffer
2037 ;; If date in `gnus-article-buffer' is localized
2038 ;; (`gnus-treat-date-user-defined'),
2039 ;; `days-between' might fail.
2040 (message-fetch-field "date"))))
2042 (< (days-between (current-time-string) date)
2044 (gnus-article-hide-header "date"))))
2046 (let ((to (message-fetch-field "to"))
2047 (cc (message-fetch-field "cc")))
2048 (when (> (length to) 1024)
2049 (gnus-article-hide-header "to"))
2050 (when (> (length cc) 1024)
2051 (gnus-article-hide-header "cc"))))
2055 (goto-char (point-min))
2056 (while (re-search-forward "^to:" nil t)
2057 (setq to-count (1+ to-count)))
2058 (when (> to-count 1)
2059 (while (> to-count 0)
2060 (goto-char (point-min))
2062 (re-search-forward "^to:" nil nil to-count)
2064 (narrow-to-region (point) (point-max))
2065 (gnus-article-hide-header "to"))
2066 (setq to-count (1- to-count))))
2067 (goto-char (point-min))
2068 (while (re-search-forward "^cc:" nil t)
2069 (setq cc-count (1+ cc-count)))
2070 (when (> cc-count 1)
2071 (while (> cc-count 0)
2072 (goto-char (point-min))
2074 (re-search-forward "^cc:" nil nil cc-count)
2076 (narrow-to-region (point) (point-max))
2077 (gnus-article-hide-header "cc"))
2078 (setq cc-count (1- cc-count)))))))))))))
2080 (defun gnus-article-hide-header (header)
2082 (goto-char (point-min))
2083 (when (re-search-forward (concat "^" header ":") nil t)
2084 (gnus-article-hide-text-type
2088 (if (re-search-forward "^[^ \t]" nil t)
2093 (defvar gnus-article-normalized-header-length 40
2094 "Length of normalized headers.")
2096 (defun article-normalize-headers ()
2097 "Make all header lines 40 characters long."
2099 (let ((inhibit-read-only t)
2103 (article-narrow-to-head)
2106 ((< (setq column (- (point-at-eol) (point)))
2107 gnus-article-normalized-header-length)
2109 (insert (make-string
2110 (- gnus-article-normalized-header-length column)
2112 ((> column gnus-article-normalized-header-length)
2113 (gnus-put-text-property
2115 (forward-char gnus-article-normalized-header-length)
2122 (forward-line 1))))))
2124 (defun article-treat-dumbquotes ()
2125 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2126 Note that this function guesses whether a character is a sm*rtq**t* or
2127 not, so it should only be used interactively.
2129 Sm*rtq**t*s are M****s***'s unilateral extension to the
2130 iso-8859-1 character map in an attempt to provide more quoting
2131 characters. If you see something like \\222 or \\264 where
2132 you're expecting some kind of apostrophe or quotation mark, then
2135 (article-translate-strings gnus-article-dumbquotes-map))
2137 (defun article-translate-characters (from to)
2138 "Translate all characters in the body of the article according to FROM and TO.
2139 FROM is a string of characters to translate from; to is a string of
2140 characters to translate to."
2142 (when (article-goto-body)
2143 (let ((inhibit-read-only t)
2144 (x (make-string 225 ?x))
2146 (while (< (incf i) (length x))
2149 (while (< i (length from))
2150 (aset x (aref from i) (aref to i))
2152 (translate-region (point) (point-max) x)))))
2154 (defun article-translate-strings (map)
2155 "Translate all string in the body of the article according to MAP.
2156 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2158 (when (article-goto-body)
2159 (let ((inhibit-read-only t))
2162 (while (search-forward (car elem) nil t)
2163 (replace-match (cadr elem)))))))))
2165 (defun article-treat-overstrike ()
2166 "Translate overstrikes into bold text."
2169 (when (article-goto-body)
2170 (let ((inhibit-read-only t))
2171 (while (search-forward "\b" nil t)
2172 (let ((next (char-after))
2173 (previous (char-after (- (point) 2))))
2174 ;; We do the boldification/underlining by hiding the
2175 ;; overstrikes and putting the proper text property
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2180 (put-text-property (point) (1+ (point)) 'face 'bold))
2182 (gnus-article-hide-text-type
2183 (1- (point)) (1+ (point)) 'overstrike)
2185 (- (point) 2) (1- (point)) 'face 'underline))
2187 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2189 (point) (1+ (point)) 'face 'underline)))))))))
2191 (defun article-treat-ansi-sequences ()
2192 "Translate ANSI SGR control sequences into overlays or extents."
2195 (when (article-goto-body)
2196 (let ((inhibit-read-only t))
2197 (ansi-color-apply-on-region (point) (point-max))))))
2199 (defun gnus-article-treat-unfold-headers ()
2200 "Unfold folded message headers.
2201 Only the headers that fit into the current window width will be
2204 (gnus-with-article-headers
2208 (mail-header-narrow-to-field)
2209 (let* ((header (buffer-string))
2211 (or (equal gnus-article-unfold-long-headers t)
2212 (and (stringp gnus-article-unfold-long-headers)
2213 (string-match gnus-article-unfold-long-headers header)))))
2216 (goto-char (point-min))
2217 (while (re-search-forward "\n[\t ]" nil t)
2218 (replace-match " " t t)))
2219 (setq length (- (point-max) (point-min) 1))
2220 (when (or unfoldable
2221 (< length (window-width)))
2222 (while (re-search-forward "\n[\t ]" nil t)
2223 (replace-match " " t t))))
2224 (goto-char (point-max)))))))
2226 (defun gnus-article-treat-fold-headers ()
2227 "Fold message headers."
2229 (gnus-with-article-headers
2232 (mail-header-narrow-to-field)
2233 (mail-header-fold-field)
2234 (goto-char (point-max))))))
2236 (defun gnus-treat-smiley ()
2237 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2239 (gnus-with-article-buffer
2240 (if (memq 'smiley gnus-article-wash-types)
2241 (gnus-delete-images 'smiley)
2243 (let ((images (smiley-region (point) (point-max))))
2245 (gnus-add-wash-type 'smiley)
2246 (dolist (image images)
2247 (gnus-add-image 'smiley image)))))))
2249 (defun gnus-article-remove-images ()
2250 "Remove all images from the article buffer."
2252 (gnus-with-article-buffer
2253 (dolist (elem gnus-article-image-alist)
2254 (gnus-delete-images (car elem)))))
2256 (defun gnus-article-treat-fold-newsgroups ()
2257 "Unfold folded message headers.
2258 Only the headers that fit into the current window width will be
2261 (gnus-with-article-headers
2262 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2264 (mail-header-narrow-to-field)
2265 (while (re-search-forward ", *" nil t)
2266 (replace-match ", " t t))
2267 (mail-header-fold-field)
2268 (goto-char (point-max))))))
2270 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2271 "Value of `truncate-lines' in Gnus Article buffer.
2272 Valid values are nil, t, `head', `first', `last', an integer or a
2273 predicate. See Info node `(gnus)Customizing Articles'."
2274 :version "23.1" ;; No Gnus
2275 :group 'gnus-article
2276 ;; :link '(custom-manual "(gnus)Customizing Articles")
2279 (defun gnus-article-toggle-truncate-lines (&optional arg)
2280 "Toggle whether to fold or truncate long lines in article the buffer.
2281 If ARG is non-nil and not a number, toggle
2282 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2283 long lines if and only if arg is positive."
2286 ((and (numberp arg) (> arg 0))
2287 (setq gnus-article-truncate-lines t))
2289 (setq gnus-article-truncate-lines nil))
2291 (setq gnus-article-truncate-lines
2292 (not gnus-article-truncate-lines))))
2293 (gnus-with-article-buffer
2295 ((and (numberp arg) (> arg 0))
2296 (setq truncate-lines nil))
2298 (setq truncate-lines t)))
2299 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2300 ;; `toggle-truncate-lines' needs an argument.
2301 (toggle-truncate-lines)))
2303 (defun gnus-article-treat-body-boundary ()
2304 "Place a boundary line at the end of the headers."
2306 (when (and gnus-body-boundary-delimiter
2307 (> (length gnus-body-boundary-delimiter) 0))
2308 (gnus-with-article-headers
2309 (goto-char (point-max))
2310 (let ((start (point)))
2311 (insert "X-Boundary: ")
2312 (gnus-add-text-properties start (point) '(invisible t intangible t))
2314 (while (>= (1- (window-width)) (length str))
2315 (setq str (concat str gnus-body-boundary-delimiter)))
2316 (substring str 0 (1- (window-width))))
2318 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2320 (defun article-fill-long-lines ()
2321 "Fill lines that are wider than the window width."
2324 (let ((inhibit-read-only t)
2325 (width (window-width (get-buffer-window (current-buffer)))))
2328 (let ((adaptive-fill-mode nil)) ;Why? -sm
2331 (when (>= (current-column) (min fill-column width))
2332 (narrow-to-region (min (1+ (point)) (point-max))
2334 (let ((goback (point-marker)))
2335 (fill-paragraph nil)
2336 (goto-char (marker-position goback)))
2338 (forward-line 1)))))))
2340 (defun article-capitalize-sentences ()
2341 "Capitalize the first word in each sentence."
2344 (let ((inhibit-read-only t)
2345 (paragraph-start "^[\n\^L]"))
2349 (forward-sentence)))))
2351 (defun article-remove-cr ()
2352 "Remove trailing CRs and then translate remaining CRs into LFs."
2355 (let ((inhibit-read-only t))
2356 (goto-char (point-min))
2357 (while (re-search-forward "\r+$" nil t)
2358 (replace-match "" t t))
2359 (goto-char (point-min))
2360 (while (search-forward "\r" nil t)
2361 (replace-match "\n" t t)))))
2363 (defun article-remove-trailing-blank-lines ()
2364 "Remove all trailing blank lines from the article."
2367 (let ((inhibit-read-only t))
2368 (goto-char (point-max))
2372 (while (and (not (bobp))
2373 (looking-at "^[ \t]*$")
2374 (not (gnus-annotation-in-region-p
2375 (point) (point-at-eol))))
2380 (defvar gnus-face-properties-alist)
2382 (defun article-display-face (&optional force)
2383 "Display any Face headers in the header."
2384 (interactive (list 'force))
2385 (let ((wash-face-p buffer-read-only))
2386 (gnus-with-article-headers
2387 ;; When displaying parts, this function can be called several times on
2388 ;; the same article, without any intended toggle semantic (as typing `W
2389 ;; D d' would have). So face deletion must occur only when we come from
2390 ;; an interactive command, that is when the *Article* buffer is
2392 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2393 (gnus-delete-images 'face)
2394 (let ((from (message-fetch-field "from"))
2396 (save-current-buffer
2397 (when (and wash-face-p
2398 (gnus-buffer-live-p gnus-original-article-buffer)
2399 (not (re-search-forward "^Face:[\t ]*" nil t)))
2400 (set-buffer gnus-original-article-buffer))
2402 (mail-narrow-to-head)
2404 ;; Check whether this face is censored.
2405 (not (and gnus-article-x-face-too-ugly
2407 (setq from (message-fetch-field "from")))
2408 (string-match gnus-article-x-face-too-ugly
2410 (while (gnus-article-goto-header "Face")
2411 (push (mail-header-field-value) faces)))))
2413 (goto-char (point-min))
2415 (unless (setq from (gnus-article-goto-header "from"))
2418 (insert " [no `from' set]\n"))
2420 (when (setq png (gnus-convert-face-to-png (pop faces)))
2422 (apply 'gnus-create-image png 'png t
2423 (cdr (assq 'png gnus-face-properties-alist))))
2425 (gnus-add-wash-type 'face)
2426 (gnus-add-image 'face image)
2427 (gnus-put-image image nil 'face))))))))))
2429 (defun article-display-x-face (&optional force)
2430 "Look for an X-Face header and display it if present."
2431 (interactive (list 'force))
2432 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2433 (gnus-with-article-headers
2434 ;; Delete the old process, if any.
2435 (when (process-status "article-x-face")
2436 (delete-process "article-x-face"))
2437 ;; See the comment in `article-display-face'.
2438 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2439 ;; We have already displayed X-Faces, so we remove them
2441 (gnus-delete-images 'xface)
2443 (let ((from (message-fetch-field "from"))
2445 (save-current-buffer
2446 (when (and wash-face-p
2447 (gnus-buffer-live-p gnus-original-article-buffer)
2448 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2449 ;; If type `W f', use gnus-original-article-buffer,
2450 ;; otherwise use the current buffer because displaying
2451 ;; RFC822 parts calls this function too.
2452 (set-buffer gnus-original-article-buffer))
2454 (mail-narrow-to-head)
2455 (and gnus-article-x-face-command
2457 ;; Check whether this face is censored.
2458 (not (and gnus-article-x-face-too-ugly
2460 (setq from (message-fetch-field "from")))
2461 (string-match gnus-article-x-face-too-ugly
2463 (while (gnus-article-goto-header "X-Face")
2464 (push (mail-header-field-value) x-faces)))))
2466 ;; We display the face.
2467 (cond ((functionp gnus-article-x-face-command)
2468 ;; The command is a lisp function, so we call it.
2469 (mapc gnus-article-x-face-command x-faces))
2470 ((stringp gnus-article-x-face-command)
2471 ;; The command is a string, so we interpret the command
2472 ;; as a, well, command, and fork it off.
2473 (let ((process-connection-type nil))
2474 (gnus-set-process-query-on-exit-flag
2476 "article-x-face" nil shell-file-name
2477 shell-command-switch gnus-article-x-face-command)
2479 ;; Sending multiple EOFs to xv doesn't work,
2480 ;; so we only do a single external face.
2482 (insert (car x-faces))
2483 (process-send-region "article-x-face"
2484 (point-min) (point-max)))
2485 (process-send-eof "article-x-face")))
2487 (error "`%s' set to `%s' is not a function"
2488 gnus-article-x-face-command
2489 'gnus-article-x-face-command)))))))))
2491 (defun article-decode-mime-words ()
2492 "Decode all MIME-encoded words in the article."
2494 (gnus-with-article-buffer
2495 (let ((inhibit-point-motion-hooks t)
2496 (mail-parse-charset gnus-newsgroup-charset)
2497 (mail-parse-ignored-charsets
2498 (with-current-buffer gnus-summary-buffer
2499 gnus-newsgroup-ignored-charsets)))
2500 (mail-decode-encoded-word-region (point-min) (point-max)))))
2502 (defun article-decode-charset (&optional prompt)
2503 "Decode charset-encoded text in the article.
2504 If PROMPT (the prefix), prompt for a coding system to use."
2506 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2507 (inhibit-read-only t)
2508 (mail-parse-charset gnus-newsgroup-charset)
2509 (mail-parse-ignored-charsets
2510 (save-excursion (condition-case nil
2511 (set-buffer gnus-summary-buffer)
2513 gnus-newsgroup-ignored-charsets))
2514 ct cte ctl charset format)
2517 (article-narrow-to-head)
2518 (setq ct (message-fetch-field "Content-Type" t)
2519 cte (message-fetch-field "Content-Transfer-Encoding" t)
2520 ctl (and ct (mail-header-parse-content-type ct))
2523 (mm-read-coding-system "Charset to decode: "))
2525 (mail-content-type-get ctl 'charset)))
2526 format (and ctl (mail-content-type-get ctl 'format)))
2528 (setq cte (mail-header-strip cte)))
2529 (if (and ctl (not (string-match "/" (car ctl))))
2531 (goto-char (point-max)))
2534 (narrow-to-region (point) (point-max))
2535 (when (and (eq mail-parse-charset 'gnus-decoded)
2536 (eq (mm-body-7-or-8) '8bit))
2537 ;; The text code could have been decoded.
2538 (setq charset mail-parse-charset))
2539 (when (and (or (not ctl)
2540 (equal (car ctl) "text/plain"))
2541 (not format)) ;; article with format will decode later.
2543 charset (and cte (intern (downcase
2544 (gnus-strip-whitespace cte))))
2547 (defun article-decode-encoded-words ()
2548 "Remove encoded-word encoding from headers."
2549 (let ((inhibit-point-motion-hooks t)
2550 (mail-parse-charset gnus-newsgroup-charset)
2551 (mail-parse-ignored-charsets
2552 (save-excursion (condition-case nil
2553 (set-buffer gnus-summary-buffer)
2555 gnus-newsgroup-ignored-charsets))
2556 (inhibit-read-only t)
2558 (goto-char (point-min))
2559 (when (search-forward "\n\n" nil 'move)
2566 (memq (char-after) '(?\t ? )))))
2567 (setq start (point))
2569 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2570 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2571 (funcall gnus-decode-address-function start end)
2572 (funcall gnus-decode-header-function start end))
2573 (goto-char (setq end start)))))
2575 (defun article-decode-group-name ()
2576 "Decode group names in Newsgroups, Followup-To and Xref headers."
2577 (let ((inhibit-point-motion-hooks t)
2578 (inhibit-read-only t)
2579 (method (gnus-find-method-for-group gnus-newsgroup-name))
2581 (when (and (or gnus-group-name-charset-method-alist
2582 gnus-group-name-charset-group-alist)
2583 (gnus-buffer-live-p gnus-original-article-buffer))
2585 (article-narrow-to-head)
2586 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2587 (with-current-buffer gnus-original-article-buffer
2588 (goto-char (point-min)))
2589 (setq regexp (concat "^" header
2590 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2591 (while (re-search-forward regexp nil t)
2592 (replace-match (save-match-data
2593 (gnus-decode-newsgroups
2594 ;; XXX how to use data in article buffer?
2595 (with-current-buffer gnus-original-article-buffer
2596 (re-search-forward regexp nil t)
2598 gnus-newsgroup-name method))
2600 (goto-char (point-min)))))))
2602 (autoload 'idna-to-unicode "idna")
2604 (defun article-decode-idna-rhs ()
2605 "Decode IDNA strings in RHS in various headers in current buffer.
2606 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2607 Mail-Reply-To: and Mail-Followup-To:."
2610 (let ((inhibit-point-motion-hooks t)
2611 (inhibit-read-only t))
2612 (article-narrow-to-head)
2613 (goto-char (point-min))
2614 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2616 (when (save-match-data
2617 (and (setq ace (match-string 1))
2619 (and (re-search-backward "^[^ \t]" nil t)
2620 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2621 (setq unicode (idna-to-unicode ace))))
2622 (unless (string= ace unicode)
2623 (replace-match unicode nil nil nil 1)))))))))
2625 (defun article-de-quoted-unreadable (&optional force read-charset)
2626 "Translate a quoted-printable-encoded article.
2627 If FORCE, decode the article whether it is marked as quoted-printable
2629 If READ-CHARSET, ask for a coding system."
2630 (interactive (list 'force current-prefix-arg))
2632 (let ((inhibit-read-only t) type charset)
2633 (if (gnus-buffer-live-p gnus-original-article-buffer)
2634 (with-current-buffer gnus-original-article-buffer
2636 (gnus-fetch-field "content-transfer-encoding"))
2637 (let* ((ct (gnus-fetch-field "content-type"))
2638 (ctl (and ct (mail-header-parse-content-type ct))))
2639 (setq charset (and ctl
2640 (mail-content-type-get ctl 'charset)))
2641 (if (stringp charset)
2642 (setq charset (intern (downcase charset)))))))
2644 (setq charset (mm-read-coding-system "Charset: " charset)))
2646 (setq charset gnus-newsgroup-charset))
2648 (and type (let ((case-fold-search t))
2649 (string-match "quoted-printable" type))))
2651 (quoted-printable-decode-region
2652 (point) (point-max) (mm-charset-to-coding-system charset))))))
2654 (defun article-de-base64-unreadable (&optional force read-charset)
2655 "Translate a base64 article.
2656 If FORCE, decode the article whether it is marked as base64 not.
2657 If READ-CHARSET, ask for a coding system."
2658 (interactive (list 'force current-prefix-arg))
2660 (let ((inhibit-read-only t) type charset)
2661 (if (gnus-buffer-live-p gnus-original-article-buffer)
2662 (with-current-buffer gnus-original-article-buffer
2664 (gnus-fetch-field "content-transfer-encoding"))
2665 (let* ((ct (gnus-fetch-field "content-type"))
2666 (ctl (and ct (mail-header-parse-content-type ct))))
2667 (setq charset (and ctl
2668 (mail-content-type-get ctl 'charset)))
2669 (if (stringp charset)
2670 (setq charset (intern (downcase charset)))))))
2672 (setq charset (mm-read-coding-system "Charset: " charset)))
2674 (setq charset gnus-newsgroup-charset))
2676 (and type (let ((case-fold-search t))
2677 (string-match "base64" type))))
2680 (narrow-to-region (point) (point-max))
2681 (base64-decode-region (point-min) (point-max))
2682 (mm-decode-coding-region
2683 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2688 (defun article-decode-HZ ()
2689 "Translate a HZ-encoded article."
2693 (let ((inhibit-read-only t))
2694 (rfc1843-decode-region (point-min) (point-max)))))
2696 (defun article-unsplit-urls ()
2697 "Remove the newlines that some other mailers insert into URLs."
2700 (let ((inhibit-read-only t))
2701 (goto-char (point-min))
2702 (while (re-search-forward
2703 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2704 (replace-match "\\1\\3" t)))
2705 (when (interactive-p)
2706 (gnus-treat-article nil))))
2709 (defun article-wash-html (&optional read-charset)
2710 "Format an HTML article.
2711 If READ-CHARSET, ask for a coding system. If it is a number, the
2712 charset defined in `gnus-summary-show-article-charset-alist' is used."
2715 (let ((inhibit-read-only t)
2718 (if (or (and (numberp read-charset)
2722 gnus-summary-show-article-charset-alist))))
2723 (setq charset (mm-read-coding-system "Charset: ")))
2724 (let ((gnus-summary-show-article-charset-alist
2725 (list (cons 1 charset))))
2726 (with-current-buffer gnus-summary-buffer
2727 (gnus-summary-show-article 1)))
2728 (error "No charset is given"))
2729 (when (gnus-buffer-live-p gnus-original-article-buffer)
2730 (with-current-buffer gnus-original-article-buffer
2731 (let* ((ct (gnus-fetch-field "content-type"))
2732 (ctl (and ct (mail-header-parse-content-type ct))))
2733 (setq charset (and ctl
2734 (mail-content-type-get ctl 'charset)))
2735 (when (stringp charset)
2736 (setq charset (intern (downcase charset)))))))
2738 (setq charset gnus-newsgroup-charset)))
2740 (save-window-excursion
2742 (narrow-to-region (point) (point-max))
2743 (let* ((func (or gnus-article-wash-function mm-text-html-renderer))
2744 (entry (assq func mm-text-html-washer-alist)))
2746 (setq func (cdr entry)))
2751 (apply (car func) (cdr func))))))))))
2754 (declare-function w3-region "ext:w3-display" (st nd))
2756 (defun gnus-article-wash-html-with-w3 ()
2757 "Wash the current buffer with w3."
2759 (let ((w3-strict-width (window-width))
2760 (url-standalone-mode t)
2761 (url-gateway-unplugged t)
2762 (w3-honor-stylesheets nil))
2764 (w3-region (point-min) (point-max))
2768 (declare-function w3m-region "ext:w3m" (start end &optional url charset))
2770 (defun gnus-article-wash-html-with-w3m ()
2771 "Wash the current buffer with emacs-w3m."
2773 (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
2774 w3m-force-redisplay)
2775 (w3m-region (point-min) (point-max)))
2776 ;; Put the mark meaning this part was rendered by emacs-w3m.
2777 (put-text-property (point-min) (point-max) 'mm-inline-text-html-with-w3m t)
2778 (when (and mm-inline-text-html-with-w3m-keymap
2779 (boundp 'w3m-minor-mode-map)
2781 (if (and (boundp 'w3m-link-map)
2783 (let* ((start (point-min))
2785 (on (get-text-property start 'w3m-href-anchor))
2786 (map (copy-keymap w3m-link-map))
2788 (set-keymap-parent map w3m-minor-mode-map)
2789 (while (< start end)
2792 (setq next (or (text-property-any start end
2793 'w3m-href-anchor nil)
2795 (put-text-property start next 'keymap map))
2796 (setq next (or (text-property-not-all start end
2797 'w3m-href-anchor nil)
2799 (put-text-property start next 'keymap w3m-minor-mode-map))
2802 (put-text-property (point-min) (point-max) 'keymap w3m-minor-mode-map))))
2804 (defvar charset) ;; Bound by `article-wash-html'.
2806 (defun gnus-article-wash-html-with-w3m-standalone ()
2807 "Wash the current buffer with w3m."
2808 (if (mm-w3m-standalone-supports-m17n-p)
2810 (unless (mm-coding-system-p charset) ;; Bound by `article-wash-html'.
2812 (setq charset 'iso-8859-1))
2813 (let ((coding-system-for-write charset)
2814 (coding-system-for-read charset))
2815 (call-process-region
2816 (point-min) (point-max)
2817 "w3m" t t nil "-dump" "-T" "text/html"
2818 "-I" (symbol-name charset) "-O" (symbol-name charset))))
2819 (mm-inline-wash-with-stdin nil "w3m" "-dump" "-T" "text/html")))
2821 (defvar gnus-article-browse-html-temp-list nil
2822 "List of temporary files created by `gnus-article-browse-html-parts'.
2823 Internal variable.")
2825 (defcustom gnus-article-browse-delete-temp 'ask
2826 "What to do with temporary files from `gnus-article-browse-html-parts'.
2827 If nil, don't delete temporary files. If it is t, delete them on
2828 exit from the summary buffer. If it is the symbol `file', query
2829 on each file, if it is `ask' ask once when exiting from the
2831 :group 'gnus-article
2832 :version "23.1" ;; No Gnus
2833 :type '(choice (const :tag "Don't delete" nil)
2834 (const :tag "Don't ask" t)
2835 (const :tag "Ask" ask)
2836 (const :tag "Ask for each file" file)))
2838 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2840 (defun gnus-article-browse-delete-temp-files (&optional how)
2841 "Delete temp-files created by `gnus-article-browse-html-parts'."
2842 (when (and gnus-article-browse-html-temp-list
2844 (or how (setq how gnus-article-browse-delete-temp))
2846 (let ((files (length gnus-article-browse-html-temp-list)))
2847 (gnus-y-or-n-p (format
2848 "Delete all %s temporary HTML file%s? "
2850 (if (> files 1) "s" ""))))
2852 (dolist (file gnus-article-browse-html-temp-list)
2853 (cond ((file-directory-p file)
2854 (when (or (not (eq how 'file))
2857 "Delete temporary HTML file(s) in directory `%s'? "
2858 (file-name-as-directory file))))
2859 (gnus-delete-directory file)))
2860 ((file-exists-p file)
2861 (when (or (not (eq how 'file))
2863 (format "Delete temporary HTML file `%s'? " file)))
2864 (delete-file file)))))
2865 ;; Also remove file from the list when not deleted or if file doesn't
2867 (setq gnus-article-browse-html-temp-list nil))
2868 gnus-article-browse-html-temp-list)
2870 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2871 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2876 (dolist (handle handles)
2878 ((not (listp handle)))
2879 ((equal (mm-handle-media-supertype handle) "multipart")
2880 (when (setq file (gnus-article-browse-html-save-cid-content
2881 cid handle directory))
2882 (throw 'found file)))
2883 ((equal (concat "<" cid ">") (mm-handle-id handle))
2886 (or (mail-content-type-get
2887 (mm-handle-disposition handle) 'filename)
2888 (mail-content-type-get
2889 (setq type (mm-handle-type handle)) 'name)
2891 (make-temp-name "cid")
2892 (car (rassoc (car type) mailcap-mime-extensions))))
2894 (mm-save-part-to-file handle file)
2895 (throw 'found file))))))))
2897 (defun gnus-article-browse-html-parts (list &optional header)
2898 "View all \"text/html\" parts from LIST.
2899 Recurse into multiparts. The optional HEADER that should be a decoded
2900 message header will be added to the bodies of the \"text/html\" parts."
2901 ;; Internal function used by `gnus-article-browse-html-article'.
2902 (let (type file charset content cid-dir tmp-file showed)
2903 ;; Find and show the html-parts.
2904 (dolist (handle list)
2905 ;; If HTML, show it:
2906 (cond ((not (listp handle)))
2907 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2908 (and (equal (car type) "message/external-body")
2910 (setq file (or (mail-content-type-get type 'name)
2911 (mail-content-type-get
2912 (mm-handle-disposition handle)
2914 (or (mm-handle-cache handle)
2915 (condition-case code
2916 (progn (mm-extern-cache-contents handle) t)
2918 (gnus-message 3 "%s" (error-message-string code))
2919 (when (>= gnus-verbose 3) (sit-for 2))
2922 (setq handle (mm-handle-cache handle)
2923 type (mm-handle-type handle))
2924 (equal (car type) "text/html"))))
2925 (setq charset (mail-content-type-get type 'charset)
2926 content (mm-get-part handle))
2928 (if (eq charset 'gnus-decoded)
2929 (mm-enable-multibyte)
2930 (mm-disable-multibyte))
2932 ;; resolve cid contents
2933 (let ((case-fold-search t)
2935 (goto-char (point-min))
2936 (while (re-search-forward "\
2937 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2940 (setq cid-dir (mm-make-temp-file "cid" t))
2941 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2944 (when (setq cid-file
2945 (gnus-article-browse-html-save-cid-content
2947 (with-current-buffer gnus-article-buffer
2948 gnus-article-mime-handles)
2950 (replace-match (concat "file://" cid-file)
2952 (unless content (setq content (buffer-string))))
2953 (when (or charset header (not file))
2954 (setq tmp-file (mm-make-temp-file
2955 ;; Do we need to care for 8.3 filenames?
2956 "mm-" nil ".html")))
2957 ;; Add a meta html tag to specify charset and a header.
2960 (let (title eheader body hcharset coding force-charset)
2962 (mm-enable-multibyte)
2963 (setq case-fold-search t)
2964 (insert header "\n")
2965 (setq title (message-fetch-field "subject"))
2966 (goto-char (point-min))
2967 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2968 (replace-match (cond ((match-beginning 1) "<")
2969 ((match-beginning 2) ">")
2971 (goto-char (point-min))
2973 (goto-char (point-max))
2974 (insert "</pre>\n<hr>\n")
2975 ;; We have to examine charset one by one since
2976 ;; charset specified in parts might be different.
2977 (if (eq charset 'gnus-decoded)
2978 (setq charset 'utf-8
2979 eheader (mm-encode-coding-string (buffer-string)
2982 (mm-encode-coding-string title charset))
2983 body (mm-encode-coding-string content charset)
2985 (setq hcharset (mm-find-mime-charset-region (point-min)
2987 (cond ((= (length hcharset) 1)
2988 (setq hcharset (car hcharset)
2989 coding (mm-charset-to-coding-system
2991 ((> (length hcharset) 1)
2992 (setq hcharset 'utf-8
2998 (mm-charset-to-coding-system charset))
2999 (if (eq coding body)
3000 (setq eheader (mm-encode-coding-string
3001 (buffer-string) coding)
3003 (mm-encode-coding-string
3006 (setq charset 'utf-8
3007 eheader (mm-encode-coding-string
3008 (buffer-string) charset)
3010 (mm-encode-coding-string
3012 body (mm-encode-coding-string
3013 (mm-decode-coding-string
3017 (setq charset hcharset
3018 eheader (mm-encode-coding-string
3019 (buffer-string) coding)
3021 (mm-encode-coding-string
3024 (setq eheader (mm-string-as-unibyte (buffer-string))
3027 (mm-disable-multibyte)
3030 (mm-add-meta-html-tag handle charset force-charset))
3032 (goto-char (point-min))
3033 (unless (search-forward "<title>" nil t)
3034 (re-search-forward "<head>\\s-*" nil t)
3035 (insert "<title>" title "</title>\n")))
3036 (goto-char (point-min))
3037 (or (re-search-forward
3038 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
3040 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
3042 (mm-write-region (point-min) (point-max)
3043 tmp-file nil nil nil 'binary t))))
3045 (mm-with-unibyte-buffer
3046 (insert (if (eq charset 'gnus-decoded)
3047 (mm-encode-coding-string content
3048 (setq charset 'utf-8))
3050 (if (or (mm-add-meta-html-tag handle charset)
3052 (mm-write-region (point-min) (point-max)
3053 tmp-file nil nil nil 'binary t)
3054 (setq tmp-file nil))))
3056 (mm-save-part-to-file handle tmp-file)))
3058 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3059 (add-hook 'gnus-summary-prepare-exit-hook
3060 'gnus-article-browse-delete-temp-files)
3061 (add-hook 'gnus-exit-gnus-hook
3063 (gnus-article-browse-delete-temp-files t)))
3064 ;; FIXME: Warn if there's an <img> tag?
3065 (browse-url-of-file (or tmp-file (expand-file-name file)))
3067 ;; If multipart, recurse
3068 ((equal (mm-handle-media-supertype handle) "multipart")
3069 (when (gnus-article-browse-html-parts handle header)
3071 ((equal (mm-handle-media-type handle) "message/rfc822")
3072 (mm-with-multibyte-buffer
3073 (mm-insert-part handle)
3074 (setq handle (mm-dissect-buffer t t))
3075 (when (and (bufferp (car handle))
3076 (stringp (car (mm-handle-type handle))))
3077 (setq handle (list handle)))
3079 (article-decode-encoded-words)
3080 (let ((gnus-visible-headers
3081 (or (get 'gnus-visible-headers 'standard-value)
3082 gnus-visible-headers)))
3083 (article-hide-headers))
3084 (goto-char (point-min))
3085 (search-forward "\n\n" nil 'move)
3086 (skip-chars-backward "\t\n ")
3087 (setq header (buffer-substring (point-min) (point)))))
3089 (gnus-article-browse-html-parts handle header)
3090 (mm-destroy-parts handle))
3094 (defun gnus-article-browse-html-article (&optional arg)
3095 "View \"text/html\" parts of the current article with a WWW browser.
3096 Inline images embedded in a message using the cid scheme, as they are
3097 generally considered to be safe, will be processed properly.
3098 The message header is added to the beginning of every html part unless
3099 the prefix argument ARG is given.
3101 Warning: Spammers use links to images (using the http scheme) in HTML
3102 articles to verify whether you have read the message. As
3103 `gnus-article-browse-html-article' passes the HTML content to the
3104 browser without eliminating these \"web bugs\" you should only
3105 use it for mails from trusted senders.
3107 If you always want to display HTML parts in the browser, set
3108 `mm-text-html-renderer' to nil.
3110 This command creates temporary files to pass HTML contents including
3111 images if any to the browser, and deletes them when exiting the group
3113 ;; Cf. `mm-w3m-safe-url-regexp'
3116 (gnus-summary-show-article)
3117 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3118 gnus-visible-headers))
3119 ;; As we insert a <hr>, there's no need for the body boundary.
3120 (gnus-treat-body-boundary nil))
3121 (gnus-summary-show-article)))
3122 (with-current-buffer gnus-article-buffer
3123 (let ((header (unless arg
3126 (buffer-substring-no-properties
3127 (goto-char (point-min))
3128 (if (search-forward "\n\n" nil t)
3130 (goto-char (point-max))
3131 (skip-chars-backward "\t\n ")
3134 (set-buffer gnus-original-article-buffer)
3135 (setq parts (mm-dissect-buffer t t))
3136 ;; If singlepart, enforce a list.
3137 (when (and (bufferp (car parts))
3138 (stringp (car (mm-handle-type parts))))
3139 (setq parts (list parts)))
3141 (unless (gnus-article-browse-html-parts parts header)
3142 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3143 (mm-destroy-parts parts)
3145 (gnus-summary-show-article)))))
3147 (defun article-hide-list-identifiers ()
3148 "Remove list identifies from the Subject header.
3149 The `gnus-list-identifiers' variable specifies what to do."
3151 (let ((inhibit-point-motion-hooks t)
3152 (regexp (if (consp gnus-list-identifiers)
3153 (mapconcat 'identity gnus-list-identifiers " *\\|")
3154 gnus-list-identifiers))
3155 (inhibit-read-only t))
3159 (article-narrow-to-head)
3160 (goto-char (point-min))
3161 (while (re-search-forward
3162 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3164 (delete-region (match-beginning 2) (match-end 0))
3165 (beginning-of-line))
3166 (when (re-search-forward
3167 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3168 (delete-region (match-beginning 1) (match-end 1))))))))
3170 (defun article-hide-pem (&optional arg)
3171 "Toggle hiding of any PEM headers and signatures in the current article.
3172 If given a negative prefix, always show; if given a positive prefix,
3174 (interactive (gnus-article-hidden-arg))
3175 (unless (gnus-article-check-hidden-text 'pem arg)
3177 (let ((inhibit-read-only t) end)
3178 (goto-char (point-min))
3179 ;; Hide the horrendously ugly "header".
3180 (when (and (search-forward
3181 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3183 (setq end (1+ (match-beginning 0))))
3184 (gnus-add-wash-type 'pem)
3185 (gnus-article-hide-text-type
3187 (if (search-forward "\n\n" nil t)
3191 ;; Hide the trailer as well
3192 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3194 (gnus-article-hide-text-type
3195 (match-beginning 0) (match-end 0) 'pem)))))))
3197 (defun article-strip-banner ()
3198 "Strip the banners specified by the `banner' group parameter and by
3199 `gnus-article-address-banner-alist'."
3203 (let ((inhibit-point-motion-hooks t))
3204 (when (gnus-parameter-banner gnus-newsgroup-name)
3205 (article-really-strip-banner
3206 (gnus-parameter-banner gnus-newsgroup-name)))
3207 (when gnus-article-address-banner-alist
3208 ;; Note that the From header is decoded here, so it is
3209 ;; required that the *-extract-address-components function
3210 ;; supports non-ASCII text.
3211 (let ((from (save-restriction
3213 (article-narrow-to-head)
3214 (mail-fetch-field "from"))))
3217 (cadr (funcall gnus-extract-address-components
3220 (dolist (pair gnus-article-address-banner-alist)
3221 (when (string-match (car pair) from)
3223 (article-really-strip-banner (cdr pair)))))))))))))
3225 (defun article-really-strip-banner (banner)
3226 "Strip the banner specified by the argument."
3229 (let ((inhibit-point-motion-hooks t)
3230 (gnus-signature-limit nil)
3231 (inhibit-read-only t))
3234 ((eq banner 'signature)
3235 (when (gnus-article-narrow-to-signature)
3238 (delete-region (point) (point-max))))
3240 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3241 (while (re-search-forward banner nil t)
3242 (delete-region (match-beginning 0) (match-end 0)))))
3244 (while (re-search-forward banner nil t)
3245 (delete-region (match-beginning 0) (match-end 0)))))))))
3247 (defun article-babel ()
3248 "Translate article using an online translation service."
3251 (gnus-with-article-buffer
3252 (when (article-goto-body)
3253 (let* ((start (point))
3255 (orig (buffer-substring start end))
3256 (trans (babel-as-string orig)))
3258 (narrow-to-region start end)
3259 (delete-region start end)
3262 (defun article-hide-signature (&optional arg)
3263 "Hide the signature in the current article.
3264 If given a negative prefix, always show; if given a positive prefix,
3266 (interactive (gnus-article-hidden-arg))
3267 (unless (gnus-article-check-hidden-text 'signature arg)
3270 (let ((inhibit-read-only t))
3271 (when (gnus-article-narrow-to-signature)
3272 (gnus-article-hide-text-type
3273 (point-min) (point-max) 'signature))))))
3274 (gnus-set-mode-line 'article))
3276 (defun article-strip-headers-in-body ()
3277 "Strip offensive headers from bodies."
3281 (let ((case-fold-search t))
3282 (when (looking-at "x-no-archive:")
3283 (gnus-delete-line)))))
3285 (defun article-strip-leading-blank-lines ()
3286 "Remove all blank lines from the beginning of the article."
3289 (let ((inhibit-point-motion-hooks t)
3290 (inhibit-read-only t))
3291 (when (article-goto-body)
3292 (while (and (not (eobp))
3293 (looking-at "[ \t]*$"))
3294 (gnus-delete-line))))))
3296 (defun article-narrow-to-head ()
3297 "Narrow the buffer to the head of the message.
3298 Point is left at the beginning of the narrowed-to region."
3300 (goto-char (point-min))
3301 (if (search-forward "\n\n" nil 1)
3304 (goto-char (point-min)))
3306 (defun article-goto-body ()
3307 "Place point at the start of the body."
3308 (goto-char (point-min))
3310 ;; This variable is only bound when dealing with separate
3312 (article-goto-body-goes-to-point-min-p
3314 ((search-forward "\n\n" nil t)
3317 (goto-char (point-max))
3320 (defun article-strip-multiple-blank-lines ()
3321 "Replace consecutive blank lines with one empty line."
3324 (let ((inhibit-point-motion-hooks t)
3325 (inhibit-read-only t))
3326 ;; First make all blank lines empty.
3328 (while (re-search-forward "^[ \t]+$" nil t)
3329 (unless (gnus-annotation-in-region-p
3330 (match-beginning 0) (match-end 0))
3331 (replace-match "" nil t)))
3332 ;; Then replace multiple empty lines with a single empty line.
3334 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3335 (unless (gnus-annotation-in-region-p
3336 (match-beginning 0) (match-end 0))
3337 (delete-region (match-beginning 1) (match-end 1)))))))
3339 (defun article-strip-leading-space ()
3340 "Remove all white space from the beginning of the lines in the article."
3343 (let ((inhibit-point-motion-hooks t)
3344 (inhibit-read-only t))
3346 (while (re-search-forward "^[ \t]+" nil t)
3347 (replace-match "" t t)))))
3349 (defun article-strip-trailing-space ()
3350 "Remove all white space from the end of the lines in the article."
3353 (let ((inhibit-point-motion-hooks t)
3354 (inhibit-read-only t))
3356 (while (re-search-forward "[ \t]+$" nil t)
3357 (replace-match "" t t)))))
3359 (defun article-strip-blank-lines ()
3360 "Strip leading, trailing and multiple blank lines."
3362 (article-strip-leading-blank-lines)
3363 (article-remove-trailing-blank-lines)
3364 (article-strip-multiple-blank-lines))
3366 (defun article-strip-all-blank-lines ()
3367 "Strip all blank lines."
3370 (let ((inhibit-point-motion-hooks t)
3371 (inhibit-read-only t))
3373 (while (re-search-forward "^[ \t]*\n" nil t)
3374 (replace-match "" t t)))))
3376 (defun gnus-article-narrow-to-signature ()
3377 "Narrow to the signature; return t if a signature is found, else nil."
3378 (let ((inhibit-point-motion-hooks t))
3379 (when (gnus-article-search-signature)
3381 ;; Check whether we have some limits to what we consider
3382 ;; to be a signature.
3383 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3384 (list gnus-signature-limit)))
3386 (while (setq limit (pop limits))
3387 (if (or (and (integerp limit)
3388 (< (- (point-max) (point)) limit))
3390 (< (count-lines (point) (point-max)) limit))
3391 (and (functionp limit)
3393 (and (stringp limit)
3394 (not (re-search-forward limit nil t))))
3395 () ; This limit did not succeed.
3399 (narrow-to-region (point) (point-max))
3402 (defun gnus-article-search-signature ()
3403 "Search the current buffer for the signature separator.
3404 Put point at the beginning of the signature separator."
3405 (let ((cur (point)))
3406 (goto-char (point-max))
3407 (if (if (stringp gnus-signature-separator)
3408 (re-search-backward gnus-signature-separator nil t)
3409 (let ((seps gnus-signature-separator))
3411 (not (re-search-backward (car seps) nil t)))
3418 (defun gnus-article-hidden-arg ()
3419 "Return the current prefix arg as a number, or 0 if no prefix."
3420 (list (if current-prefix-arg
3421 (prefix-numeric-value current-prefix-arg)
3424 (defun gnus-article-check-hidden-text (type arg)
3425 "Return nil if hiding is necessary.
3426 Arg can be nil or a number. nil and positive means hide, negative
3427 means show, 0 means toggle."
3430 (let ((hide (gnus-article-hidden-text-p type)))
3436 (gnus-article-show-hidden-text type)
3439 (if (eq hide 'hidden)
3441 (gnus-article-show-hidden-text type)
3445 (defun gnus-article-hidden-text-p (type)
3446 "Say whether the current buffer contains hidden text of type TYPE."
3447 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3449 (not (get-text-property pos 'invisible))
3450 (not (get-text-property pos 'dummy-invisible)))
3452 (text-property-any (1+ pos) (point-max) 'article-type type)))
3457 (defun gnus-article-show-hidden-text (type &optional dummy)
3458 "Show all hidden text of type TYPE.
3459 Originally it is hide instead of DUMMY."
3460 (let ((inhibit-read-only t)
3461 (inhibit-point-motion-hooks t))
3462 (gnus-remove-text-properties-when
3464 (point-min) (point-max)
3465 (cons 'article-type (cons type
3466 gnus-hidden-properties)))
3467 (gnus-delete-wash-type type)))
3469 (defconst article-time-units
3470 `((year . ,(* 365.25 24 60 60))
3471 (week . ,(* 7 24 60 60))
3472 (day . ,(* 24 60 60))
3476 "Mapping from time units to seconds.")
3478 (defun gnus-article-forward-header ()
3479 "Move point to the start of the next header.
3480 If the current header is a continuation header, this can be several
3485 (if (looking-at "[ \t]+[^ \t]")
3489 (defun article-date-ut (&optional type highlight)
3490 "Convert DATE date to universal time in the current article.
3491 If TYPE is `local', convert to local time; if it is `lapsed', output
3492 how much time has lapsed since DATE. For `lapsed', the value of
3493 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3494 should replace the \"Date:\" one, or should be added below it."
3495 (interactive (list 'ut t))
3496 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3497 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3501 (article-lapsed-timer
3505 (case-fold-search t)
3506 (inhibit-read-only t)
3507 (inhibit-point-motion-hooks t)
3508 pos date bface eface)
3512 (goto-char (point-min))
3513 (while (or (setq date (get-text-property (setq pos (point))
3515 (when (setq pos (next-single-property-change
3516 (point) 'original-date))
3517 (setq date (get-text-property pos 'original-date))
3520 pos (if (setq pos (text-property-any pos (point-max)
3521 'original-date nil))
3524 (if (or (bolp) (eobp))
3528 (goto-char (point-min))
3529 (when (re-search-forward tdate-regexp nil t)
3530 (setq bface (get-text-property (point-at-bol) 'face)
3531 eface (get-text-property (1- (point-at-eol)) 'face)))
3532 (goto-char (point-min))
3534 ;; Delete any old Date headers.
3535 (while (re-search-forward date-regexp nil t)
3537 (delete-region (point-at-bol) (progn
3538 (gnus-article-forward-header)
3540 (delete-region (point-at-bol) (progn
3541 (gnus-article-forward-header)
3544 (setq pos (point))))
3545 (when (and (not pos)
3546 (re-search-forward tdate-regexp nil t))
3548 (gnus-goto-char pos)
3549 (insert (article-make-date-line date (or type 'ut)))
3555 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3556 (put-text-property (match-beginning 1) (1+ (match-end 1))
3558 (put-text-property (match-beginning 2) (match-end 2)
3560 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3561 (goto-char (point-max))
3564 (defun article-make-date-line (date type)
3565 "Return a DATE line of TYPE."
3566 (unless (memq type '(local ut original user iso8601 lapsed english))
3567 (error "Unknown conversion type: %s" type))
3569 (let ((time (date-to-time date)))
3571 ;; Convert to the local timezone.
3573 (concat "Date: " (message-make-date time)))
3574 ;; Convert to Universal Time.
3579 (let* ((e (parse-time-string date))
3580 (tm (apply 'encode-time e))
3582 (ls (- (cadr tm) (car (current-time-zone time)))))
3583 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3584 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3588 ;; Get the original date from the article.
3589 ((eq type 'original)
3590 (concat "Date: " (if (string-match "\n+$" date)
3591 (substring date 0 (match-beginning 0))
3593 ;; Let the user define the format.
3595 (let ((format (or (condition-case nil
3596 (with-current-buffer gnus-summary-buffer
3597 gnus-article-time-format)
3599 gnus-article-time-format)))
3600 (if (functionp format)
3601 (funcall format time)
3602 (concat "Date: " (format-time-string format time)))))
3605 (let ((tz (car (current-time-zone time))))
3608 (format-time-string "%Y%m%dT%H%M%S" time)
3609 (format "%s%02d%02d"
3610 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3611 (/ (% (abs tz) 3600) 60)))))
3612 ;; Do an X-Sent lapsed format.
3614 ;; If the date is seriously mangled, the timezone functions are
3615 ;; liable to bug out, so we ignore all errors.
3616 (let* ((now (current-time))
3617 (real-time (subtract-time now time))
3618 (real-sec (and real-time
3619 (+ (* (float (car real-time)) 65536)
3621 (sec (and real-time (abs real-sec)))
3631 ;; This is a bit convoluted, but basically we go
3632 ;; through the time units for years, weeks, etc,
3633 ;; and divide things to see whether that results
3634 ;; in positive answers.
3637 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3638 ;; The (remaining) seconds are too few to
3639 ;; be divided into this time unit.
3641 ;; It's big enough, so we output it.
3642 (setq sec (- sec (* num (cdr unit))))
3644 (concat (if prev ", " "") (int-to-string
3646 " " (symbol-name (car unit))
3647 (if (> num 1) "s" ""))
3649 article-time-units "")
3650 ;; If dates are odd, then it might appear like the
3651 ;; article was sent in the future.
3654 " in the future"))))))
3655 ;; Display the date in proper English
3657 (let ((dtime (decode-time time)))
3660 (number-to-string (nth 3 dtime))
3661 (let ((digit (% (nth 3 dtime) 10)))
3663 ((memq (nth 3 dtime) '(11 12 13)) "th")
3669 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3671 (number-to-string (nth 5 dtime))
3673 (format "%02d" (nth 2 dtime))
3675 (format "%02d" (nth 1 dtime)))))))
3677 (format "Date: %s (from Gnus)" date))))
3679 (defun article-date-local (&optional highlight)
3680 "Convert the current article date to the local timezone."
3681 (interactive (list t))
3682 (article-date-ut 'local highlight))
3684 (defun article-date-english (&optional highlight)
3685 "Convert the current article date to something that is proper English."
3686 (interactive (list t))
3687 (article-date-ut 'english highlight))
3689 (defun article-date-original (&optional highlight)
3690 "Convert the current article date to what it was originally.
3691 This is only useful if you have used some other date conversion
3692 function and want to see what the date was before converting."
3693 (interactive (list t))
3694 (article-date-ut 'original highlight))
3696 (defun article-date-lapsed (&optional highlight)
3697 "Convert the current article date to time lapsed since it was sent."
3698 (interactive (list t))
3699 (article-date-ut 'lapsed highlight))
3701 (defun article-update-date-lapsed ()
3702 "Function to be run from a timer to update the lapsed time line."
3704 (let (deactivate-mark)
3709 (set-buffer (window-buffer w))
3710 (when (eq major-mode 'gnus-article-mode)
3711 (let ((mark (point-marker)))
3712 (goto-char (point-min))
3713 (when (re-search-forward "^X-Sent:" nil t)
3714 (article-date-lapsed t))
3715 (goto-char (marker-position mark))
3716 (move-marker mark nil))))
3719 (defun gnus-start-date-timer (&optional n)
3720 "Start a timer to update the X-Sent header in the article buffers.
3721 The numerical prefix says how frequently (in seconds) the function
3726 (gnus-stop-date-timer)
3727 (setq article-lapsed-timer
3728 (run-at-time 1 n 'article-update-date-lapsed)))
3730 (defun gnus-stop-date-timer ()
3731 "Stop the X-Sent timer."
3733 (when article-lapsed-timer
3734 (nnheader-cancel-timer article-lapsed-timer)
3735 (setq article-lapsed-timer nil)))
3737 (defun article-date-user (&optional highlight)
3738 "Convert the current article date to the user-defined format.
3739 This format is defined by the `gnus-article-time-format' variable."
3740 (interactive (list t))
3741 (article-date-ut 'user highlight))
3743 (defun article-date-iso8601 (&optional highlight)
3744 "Convert the current article date to ISO8601."
3745 (interactive (list t))
3746 (article-date-ut 'iso8601 highlight))
3748 (defmacro gnus-article-save-original-date (&rest forms)
3749 "Save the original date as a text property and evaluate FORMS."
3750 `(let* ((case-fold-search t)
3752 (goto-char (point-min))
3753 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3756 (date (when (and start
3757 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3759 (buffer-substring-no-properties start
3760 (match-beginning 0)))))
3761 (goto-char (point-max))
3762 (skip-chars-backward "\n")
3763 (put-text-property (point-min) (point) 'original-date date)
3765 (goto-char (point-max))
3766 (skip-chars-backward "\n")
3767 (put-text-property (point-min) (point) 'original-date date)))
3769 ;; (defun article-show-all ()
3770 ;; "Show all hidden text in the article buffer."
3773 ;; (let ((inhibit-read-only t))
3774 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3776 (defun article-remove-leading-whitespace ()
3777 "Remove excessive whitespace from all headers."
3781 (let ((inhibit-read-only t))
3782 (article-narrow-to-head)
3783 (goto-char (point-min))
3784 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3785 (delete-region (match-beginning 1) (match-end 1)))))))
3787 (defun article-emphasize (&optional arg)
3788 "Emphasize text according to `gnus-emphasis-alist'."
3789 (interactive (gnus-article-hidden-arg))
3790 (unless (gnus-article-check-hidden-text 'emphasis arg)
3794 (with-current-buffer gnus-summary-buffer
3795 gnus-article-emphasis-alist)
3797 gnus-emphasis-alist))
3798 (inhibit-read-only t)
3799 (props (append '(article-type emphasis)
3800 gnus-hidden-properties))
3801 regexp elem beg invisible visible face)
3804 (while (setq elem (pop alist))
3806 (setq regexp (car elem)
3807 invisible (nth 1 elem)
3808 visible (nth 2 elem)
3810 (while (re-search-forward regexp nil t)
3811 (when (and (match-beginning visible) (match-beginning invisible))
3812 (gnus-article-hide-text
3813 (match-beginning invisible) (match-end invisible) props)
3814 (gnus-article-unhide-text-type
3815 (match-beginning visible) (match-end visible) 'emphasis)
3816 (gnus-put-overlay-excluding-newlines
3817 (match-beginning visible) (match-end visible) 'face face)
3818 (gnus-add-wash-type 'emphasis)
3819 (goto-char (match-end invisible)))))))))
3821 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3822 "Setup newsgroup emphasis alist."
3823 (unless gnus-article-emphasis-alist
3824 (let ((name (and gnus-newsgroup-name
3825 (gnus-group-real-name gnus-newsgroup-name))))
3826 (make-local-variable 'gnus-article-emphasis-alist)
3827 (setq gnus-article-emphasis-alist
3829 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3830 (while (setq elem (pop alist))
3831 (when (and name (string-match (car elem) name))
3833 highlight (copy-sequence (cdr elem)))))
3835 (copy-sequence highlight-words)
3836 (if gnus-newsgroup-name
3837 (copy-sequence (gnus-group-find-parameter
3838 gnus-newsgroup-name 'highlight-words t)))
3839 gnus-emphasis-alist)))))
3841 (defvar gnus-summary-article-menu)
3842 (defvar gnus-summary-post-menu)
3844 ;;; Saving functions.
3846 (defun gnus-article-save (save-buffer file &optional num)
3847 "Save the currently selected article."
3848 (when (or (get gnus-default-article-saver :headers)
3849 (not gnus-save-all-headers))
3850 ;; Remove headers according to `gnus-saved-headers' or the value
3851 ;; of the `:headers' property that the saver function might have.
3852 (let ((gnus-visible-headers
3853 (or (symbol-value (get gnus-default-article-saver :headers))
3854 gnus-saved-headers gnus-visible-headers))
3855 ;; Ignore group parameter. See `article-hide-headers'.
3856 (gnus-summary-buffer nil))
3857 (with-current-buffer save-buffer
3858 (article-hide-headers 1 t))))
3859 (save-window-excursion
3860 (if (not gnus-default-article-saver)
3861 (error "No default saver is defined")
3862 ;; !!! Magic! The saving functions all save
3863 ;; `gnus-save-article-buffer' (or so they think), but we
3864 ;; bind that variable to our save-buffer.
3865 (set-buffer gnus-article-buffer)
3866 (let* ((gnus-save-article-buffer save-buffer)
3869 ((not gnus-prompt-before-saving) 'default)
3870 ((eq gnus-prompt-before-saving 'always) nil)
3872 (gnus-number-of-articles-to-be-saved
3873 (when (eq gnus-prompt-before-saving t)
3875 (set-buffer gnus-article-current-summary)
3876 (funcall gnus-default-article-saver filename)))))
3878 (defun gnus-read-save-file-name (prompt &optional filename
3879 function group headers variable
3882 (funcall function group headers (symbol-value variable)))
3887 ((eq filename 'default)
3893 (when (symbol-value dir-var)
3894 (setq default-name (expand-file-name
3895 (file-name-nondirectory default-name)
3896 (symbol-value dir-var))))
3897 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3900 (if (and gnus-number-of-articles-to-be-saved
3901 (> gnus-number-of-articles-to-be-saved 1))
3902 (format "these %d articles"
3903 gnus-number-of-articles-to-be-saved)
3906 ;; Let the split methods have their say.
3908 ;; No split name was found.
3911 (concat prompt " (default "
3912 (file-name-nondirectory default-name) "): ")
3913 (file-name-directory default-name)
3915 ;; A single group name is returned.
3916 ((stringp split-name)
3918 (funcall function split-name headers
3919 (symbol-value variable)))
3921 (concat prompt " (default "
3922 (file-name-nondirectory default-name) "): ")
3923 (file-name-directory default-name)
3925 ;; A single split name was found
3926 ((= 1 (length split-name))
3927 (let* ((name (expand-file-name
3929 gnus-article-save-directory))
3930 (dir (cond ((file-directory-p name)
3931 (file-name-as-directory name))
3932 ((file-exists-p name) name)
3933 (t gnus-article-save-directory))))
3935 (concat prompt " (default " name "): ")
3937 ;; A list of splits was found.
3939 (setq split-name (nreverse split-name))
3941 (let ((file-name-history
3942 (nconc split-name file-name-history)))
3946 (concat prompt " (`M-p' for defaults): ")
3947 gnus-article-save-directory
3949 gnus-article-save-directory)))
3950 (car (push result file-name-history)))))))
3951 ;; Create the directory.
3952 (gnus-make-directory (file-name-directory file))
3953 ;; If we have read a directory, we append the default file name.
3954 (when (file-directory-p file)
3955 (setq file (expand-file-name (file-name-nondirectory
3957 (file-name-as-directory file))))
3958 ;; Possibly translate some characters.
3959 (nnheader-translate-file-chars file))))))
3960 (gnus-make-directory (file-name-directory result))
3962 (set variable result))
3964 (set dir-var (file-name-directory result)))
3967 (defun gnus-article-archive-name (group)
3968 "Return the first instance of an \"Archive-name\" in the current buffer."
3969 (let ((case-fold-search t))
3970 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3971 (nnheader-concat gnus-article-save-directory
3972 (match-string 1)))))
3974 (defun gnus-article-nndoc-name (group)
3975 "If GROUP is an nndoc group, return the name of the parent group."
3976 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3977 (gnus-group-get-parameter group 'save-article-group)))
3979 (defun gnus-summary-save-in-rmail (&optional filename)
3980 "Append this article to Rmail file.
3981 Optional argument FILENAME specifies file name.
3982 Directory to save to is default to `gnus-article-save-directory'."
3983 (setq filename (gnus-read-save-file-name
3984 "Save %s in rmail file" filename
3985 gnus-rmail-save-name gnus-newsgroup-name
3986 gnus-current-headers 'gnus-newsgroup-last-rmail))
3987 (gnus-eval-in-buffer-window gnus-save-article-buffer
3991 ;; Note that unlike gnus-summary-save-in-mail, there is no
3992 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3994 (gnus-output-to-rmail filename))))
3997 (defun gnus-summary-save-in-mail (&optional filename)
3998 "Append this article to Unix mail file.
3999 Optional argument FILENAME specifies file name.
4000 Directory to save to is default to `gnus-article-save-directory'."
4001 (setq filename (gnus-read-save-file-name
4002 "Save %s in Unix mail file" filename
4003 gnus-mail-save-name gnus-newsgroup-name
4004 gnus-current-headers 'gnus-newsgroup-last-mail))
4005 (gnus-eval-in-buffer-window gnus-save-article-buffer
4009 (if (and (file-readable-p filename)
4010 (file-regular-p filename)
4011 (mail-file-babyl-p filename))
4012 (gnus-output-to-rmail filename)
4013 (gnus-output-to-mail filename)))))
4016 (put 'gnus-summary-save-in-file :decode t)
4017 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4018 (defun gnus-summary-save-in-file (&optional filename overwrite)
4019 "Append this article to file.
4020 Optional argument FILENAME specifies file name.
4021 Directory to save to is default to `gnus-article-save-directory'."
4022 (setq filename (gnus-read-save-file-name
4023 "Save %s in file" filename
4024 gnus-file-save-name gnus-newsgroup-name
4025 gnus-current-headers 'gnus-newsgroup-last-file))
4026 (gnus-eval-in-buffer-window gnus-save-article-buffer
4030 (when (and overwrite
4031 (file-exists-p filename))
4032 (delete-file filename))
4033 (gnus-output-to-file filename))))
4036 (put 'gnus-summary-write-to-file :decode t)
4037 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4038 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4039 (defun gnus-summary-write-to-file (&optional filename)
4040 "Write this article to a file, overwriting it if the file exists.
4041 Optional argument FILENAME specifies file name.
4042 The directory to save in defaults to `gnus-article-save-directory'."
4043 (setq filename (gnus-read-save-file-name
4044 "Save %s in file" filename
4045 gnus-file-save-name gnus-newsgroup-name
4046 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4047 (gnus-summary-save-in-file filename t))
4049 (put 'gnus-summary-save-body-in-file :decode t)
4050 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4051 "Append this article body to a file.
4052 Optional argument FILENAME specifies file name.
4053 The directory to save in defaults to `gnus-article-save-directory'."
4054 (setq filename (gnus-read-save-file-name
4055 "Save %s body in file" filename
4056 gnus-file-save-name gnus-newsgroup-name
4057 gnus-current-headers 'gnus-newsgroup-last-file))
4058 (gnus-eval-in-buffer-window gnus-save-article-buffer
4062 (when (article-goto-body)
4063 (narrow-to-region (point) (point-max)))
4064 (when (and overwrite
4065 (file-exists-p filename))
4066 (delete-file filename))
4067 (gnus-output-to-file filename))))
4070 (put 'gnus-summary-write-body-to-file :decode t)
4071 (put 'gnus-summary-write-body-to-file
4072 :function 'gnus-summary-save-body-in-file)
4073 (defun gnus-summary-write-body-to-file (&optional filename)
4074 "Write this article body to a file, overwriting it if the file exists.
4075 Optional argument FILENAME specifies file name.
4076 The directory to save in defaults to `gnus-article-save-directory'."
4077 (setq filename (gnus-read-save-file-name
4078 "Save %s body in file" filename
4079 gnus-file-save-name gnus-newsgroup-name
4080 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4081 (gnus-summary-save-body-in-file filename t))
4083 (put 'gnus-summary-save-in-pipe :decode t)
4084 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4085 (defun gnus-summary-save-in-pipe (&optional command raw)
4086 "Pipe this article to subprocess COMMAND.
4087 Valid values for COMMAND include:
4089 The executable command name and possibly arguments.
4091 You will be prompted for the command in the minibuffer.
4092 the symbol `default'
4093 It will be replaced with the command which the variable
4094 `gnus-summary-pipe-output-default-command' holds or the command
4095 last used for saving.
4096 Non-nil value for RAW overrides `:decode' and `:headers' properties
4097 and the raw article including all headers will be piped."
4098 (let ((article (gnus-summary-article-number))
4100 (get 'gnus-summary-save-in-pipe :decode)))
4101 save-buffer default)
4103 (if (vectorp (gnus-summary-article-header article))
4104 (save-current-buffer
4105 (gnus-summary-select-article decode decode nil article)
4106 (insert-buffer-substring
4110 gnus-original-article-buffer)
4112 (nnheader-set-temp-buffer " *Gnus Save*"))))
4113 ;; Remove unwanted headers.
4114 (when (and (not raw)
4115 (or (get 'gnus-summary-save-in-pipe :headers)
4116 (not gnus-save-all-headers)))
4117 (let ((gnus-visible-headers
4118 (or (symbol-value (get 'gnus-summary-save-in-pipe
4120 gnus-saved-headers gnus-visible-headers))
4121 (gnus-summary-buffer nil))
4122 (article-hide-headers 1 t))))
4123 (error "%d is not a real article" article))
4124 (error "No article to pipe"))
4125 (setq default (or gnus-summary-pipe-output-default-command
4126 gnus-last-shell-command))
4127 (unless (stringp command)
4129 (if (and (eq command 'default) default)
4131 (gnus-read-shell-command "Shell command on this article: "
4133 (when (string-equal command "")
4135 (setq command default)
4136 (error "A command is required")))
4137 (gnus-eval-in-buffer-window save-buffer
4140 (shell-command-on-region (point-min) (point-max) command nil)))
4141 (gnus-kill-buffer save-buffer))
4142 (setq gnus-summary-pipe-output-default-command command))
4144 (defun gnus-summary-pipe-to-muttprint (&optional command)
4145 "Pipe this article to muttprint."
4146 (unless (stringp command)
4147 (setq command (read-string
4148 "Print using command: " gnus-summary-muttprint-program
4149 nil gnus-summary-muttprint-program)))
4150 (let ((gnus-summary-pipe-output-default-command
4151 gnus-summary-pipe-output-default-command))
4152 (gnus-summary-save-in-pipe command))
4153 (setq gnus-summary-muttprint-program command))
4155 ;;; Article file names when saving.
4157 (defun gnus-capitalize-newsgroup (newsgroup)
4158 "Capitalize NEWSGROUP name."
4159 (when (not (zerop (length newsgroup)))
4160 (concat (char-to-string (upcase (aref newsgroup 0)))
4161 (substring newsgroup 1))))
4163 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4164 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4165 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4166 Otherwise, it is like ~/News/news/group/num."
4169 (concat (if (gnus-use-long-file-name 'not-save)
4170 (gnus-capitalize-newsgroup newsgroup)
4171 (gnus-newsgroup-directory-form newsgroup))
4172 "/" (int-to-string (mail-header-number headers)))
4173 gnus-article-save-directory)))
4175 (string-equal (file-name-directory default)
4176 (file-name-directory last-file))
4177 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4179 (or last-file default))))
4181 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4182 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4183 If variable `gnus-use-long-file-name' is non-nil, it is
4184 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4187 (concat (if (gnus-use-long-file-name 'not-save)
4189 (gnus-newsgroup-directory-form newsgroup))
4190 "/" (int-to-string (mail-header-number headers)))
4191 gnus-article-save-directory)))
4193 (string-equal (file-name-directory default)
4194 (file-name-directory last-file))
4195 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4197 (or last-file default))))
4199 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4200 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4201 If variable `gnus-use-long-file-name' is non-nil, it is
4202 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4205 (if (gnus-use-long-file-name 'not-save)
4208 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4210 gnus-article-save-directory)))
4212 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4213 "Generate file name from sender."
4214 (let ((from (mail-header-from headers)))
4216 (if (and from (string-match "\\([^ <]+\\)@" from))
4217 (match-string 1 from)
4219 gnus-article-save-directory)))
4221 (defun article-verify-x-pgp-sig ()
4223 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4225 (if (gnus-buffer-live-p gnus-original-article-buffer)
4226 (let ((sig (with-current-buffer gnus-original-article-buffer
4227 (gnus-fetch-field "X-PGP-Sig")))
4231 (mml2015-clear-verify-function))
4233 (insert-buffer-substring gnus-original-article-buffer)
4234 (setq items (split-string sig))
4235 (message-narrow-to-head)
4236 (let ((inhibit-point-motion-hooks t)
4237 (case-fold-search t))
4238 ;; Don't verify multiple headers.
4239 (setq headers (mapconcat (lambda (header)
4241 (mail-fetch-field header)
4243 (split-string (nth 1 items) ",") "")))
4244 (delete-region (point-min) (point-max))
4245 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4246 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4251 (if (looking-at "^-")
4254 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4255 (insert "Version: " (car items) "\n\n")
4256 (insert (mapconcat 'identity (cddr items) "\n"))
4257 (insert "\n-----END PGP SIGNATURE-----\n")
4258 (let ((mm-security-handle (list (format "multipart/signed"))))
4259 (mml2015-clean-buffer)
4260 (let ((coding-system-for-write (or gnus-newsgroup-charset
4262 (funcall (mml2015-clear-verify-function)))
4264 (or (mm-handle-multipart-ctl-parameter
4265 mm-security-handle 'gnus-details)
4266 (mm-handle-multipart-ctl-parameter
4267 mm-security-handle 'gnus-info)))))
4269 (let ((inhibit-read-only t) bface eface)
4271 (message-narrow-to-head)
4272 (goto-char (point-max))
4274 (setq bface (get-text-property (point-at-bol) 'face)
4275 eface (get-text-property (1- (point-at-eol)) 'face))
4276 (message-remove-header "X-Gnus-PGP-Verify")
4277 (if (re-search-forward "^X-PGP-Sig:" nil t)
4279 (goto-char (point-max)))
4280 (narrow-to-region (point) (point))
4281 (insert "X-Gnus-PGP-Verify: " info "\n")
4282 (goto-char (point-min))
4285 (if (not (looking-at "^[ \t]"))
4289 (goto-char (point-min))
4290 (when (looking-at "\\([^:]+\\): *")
4291 (put-text-property (match-beginning 1) (1+ (match-end 1))
4293 (put-text-property (match-end 0) (point-max)
4294 'face eface)))))))))
4296 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4298 (defun article-verify-cancel-lock ()
4299 "Verify Cancel-Lock header."
4301 (if (gnus-buffer-live-p gnus-original-article-buffer)
4302 (canlock-verify gnus-original-article-buffer)))
4309 (setq afunc (car func)
4312 gfunc (intern (format "gnus-%s" func))))
4314 (when (fboundp afunc)
4315 `(lambda (&optional interactive &rest args)
4316 ,(documentation afunc t)
4317 (interactive (list t))
4318 (with-current-buffer gnus-article-buffer
4320 (call-interactively ',afunc)
4321 (apply ',afunc args))))))))
4322 '(article-hide-headers
4323 article-verify-x-pgp-sig
4324 article-verify-cancel-lock
4325 article-hide-boring-headers
4326 article-treat-overstrike
4327 article-treat-ansi-sequences
4328 article-fill-long-lines
4329 article-capitalize-sentences
4331 article-remove-leading-whitespace
4332 article-display-x-face
4333 article-display-face
4334 article-de-quoted-unreadable
4335 article-de-base64-unreadable
4338 article-unsplit-urls
4339 article-hide-list-identifiers
4340 article-strip-banner
4343 article-hide-signature
4344 article-strip-headers-in-body
4345 article-remove-trailing-blank-lines
4346 article-strip-leading-blank-lines
4347 article-strip-multiple-blank-lines
4348 article-strip-leading-space
4349 article-strip-trailing-space
4350 article-strip-blank-lines
4351 article-strip-all-blank-lines
4353 article-date-english
4354 article-date-iso8601
4355 article-date-original
4357 article-decode-mime-words
4358 article-decode-charset
4359 article-decode-encoded-words
4363 article-treat-dumbquotes
4364 article-normalize-headers
4365 ;;(article-show-all . gnus-article-show-all-headers)
4369 ;;; Gnus article mode
4372 (put 'gnus-article-mode 'mode-class 'special)
4374 (set-keymap-parent gnus-article-mode-map widget-keymap)
4376 (gnus-define-keys gnus-article-mode-map
4377 " " gnus-article-goto-next-page
4378 "\177" gnus-article-goto-prev-page
4379 [delete] gnus-article-goto-prev-page
4380 [backspace] gnus-article-goto-prev-page
4381 "\C-c^" gnus-article-refer-article
4382 "h" gnus-article-show-summary
4383 "s" gnus-article-show-summary
4384 "\C-c\C-m" gnus-article-mail
4385 "?" gnus-article-describe-briefly
4386 "<" beginning-of-buffer
4388 "\C-c\C-i" gnus-info-find-node
4390 "R" gnus-article-reply-with-original
4391 "F" gnus-article-followup-with-original
4392 "\C-hk" gnus-article-describe-key
4393 "\C-hc" gnus-article-describe-key-briefly
4394 "\C-hb" gnus-article-describe-bindings
4396 "e" gnus-article-read-summary-keys
4397 "\C-d" gnus-article-read-summary-keys
4398 "\M-*" gnus-article-read-summary-keys
4399 "\M-#" gnus-article-read-summary-keys
4400 "\M-^" gnus-article-read-summary-keys
4401 "\M-g" gnus-article-read-summary-keys)
4403 (substitute-key-definition
4404 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4406 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4407 "W" gnus-article-wide-reply-with-original)
4408 (if (featurep 'xemacs)
4409 (set-keymap-default-binding gnus-article-send-map
4410 'gnus-article-read-summary-send-keys)
4411 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4413 (defun gnus-article-make-menu-bar ()
4414 (unless (boundp 'gnus-article-commands-menu)
4415 (gnus-summary-make-menu-bar))
4416 (gnus-turn-off-edit-menu 'article)
4417 (unless (boundp 'gnus-article-article-menu)
4419 gnus-article-article-menu gnus-article-mode-map ""
4421 ["Scroll forwards" gnus-article-goto-next-page t]
4422 ["Scroll backwards" gnus-article-goto-prev-page t]
4423 ["Show summary" gnus-article-show-summary t]
4424 ["Fetch Message-ID at point" gnus-article-refer-article t]
4425 ["Mail to address at point" gnus-article-mail t]
4426 ["Send a bug report" gnus-bug t]))
4429 gnus-article-treatment-menu gnus-article-mode-map ""
4430 ;; Fixme: this should use :active (and maybe :visible).
4432 ["Hide headers" gnus-article-hide-headers t]
4433 ["Hide signature" gnus-article-hide-signature t]
4434 ["Hide citation" gnus-article-hide-citation t]
4435 ["Treat overstrike" gnus-article-treat-overstrike t]
4436 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4437 ["Remove carriage return" gnus-article-remove-cr t]
4438 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4439 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4440 ["Remove base64" gnus-article-de-base64-unreadable t]
4441 ["Treat html" gnus-article-wash-html t]
4442 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4443 ["Decode HZ" gnus-article-decode-HZ t]))
4445 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4447 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4449 (gnus-run-hooks 'gnus-article-menu-hook)))
4451 (defvar bookmark-make-record-function)
4453 (defun gnus-article-mode ()
4454 "Major mode for displaying an article.
4456 All normal editing commands are switched off.
4458 The following commands are available in addition to all summary mode
4460 \\<gnus-article-mode-map>
4461 \\[gnus-article-next-page]\t Scroll the article one page forwards
4462 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4463 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4464 \\[gnus-article-show-summary]\t Display the summary buffer
4465 \\[gnus-article-mail]\t Send a reply to the address near point
4466 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4467 \\[gnus-info-find-node]\t Go to the Gnus info node"
4469 (kill-all-local-variables)
4470 (gnus-simplify-mode-line)
4471 (setq mode-name "Article")
4472 (setq major-mode 'gnus-article-mode)
4473 (make-local-variable 'minor-mode-alist)
4474 (use-local-map gnus-article-mode-map)
4475 (when (gnus-visual-p 'article-menu 'menu)
4476 (gnus-article-make-menu-bar)
4477 (when gnus-summary-tool-bar-map
4478 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4479 (gnus-update-format-specifications nil 'article-mode)
4480 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4481 (set (make-local-variable 'gnus-page-broken) nil)
4482 (make-local-variable 'gnus-button-marker-list)
4483 (make-local-variable 'gnus-article-current-summary)
4484 (make-local-variable 'gnus-article-mime-handles)
4485 (make-local-variable 'gnus-article-decoded-p)
4486 (make-local-variable 'gnus-article-mime-handle-alist)
4487 (make-local-variable 'gnus-article-wash-types)
4488 (make-local-variable 'gnus-article-image-alist)
4489 (make-local-variable 'gnus-article-charset)
4490 (make-local-variable 'gnus-article-ignored-charsets)
4491 (set (make-local-variable 'bookmark-make-record-function)
4492 'gnus-summary-bookmark-make-record)
4493 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4495 (set (make-local-variable 'nobreak-char-display) nil)
4496 (setq cursor-in-non-selected-windows nil)
4497 (setq truncate-lines gnus-article-truncate-lines)
4498 (gnus-set-default-directory)
4499 (buffer-disable-undo)
4500 (setq buffer-read-only t
4501 show-trailing-whitespace nil)
4502 (set-syntax-table gnus-article-mode-syntax-table)
4503 (mm-enable-multibyte)
4504 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4506 (defvar gnus-button-marker-list nil
4507 "Regexp matching any of the regexps from `gnus-button-alist'.
4508 Internal variable.")
4510 (defun gnus-article-setup-buffer ()
4511 "Initialize the article buffer."
4512 (let* ((name (if gnus-single-article-buffer "*Article*"
4513 (concat "*Article " gnus-newsgroup-name "*")))
4515 (progn (string-match "\\*Article" name)
4516 (concat " *Original Article"
4517 (substring name (match-end 0))))))
4518 (setq gnus-article-buffer name)
4519 (setq gnus-original-article-buffer original)
4520 (setq gnus-article-mime-handle-alist nil)
4521 (with-current-buffer gnus-summary-buffer
4522 ;; This might be a variable local to the summary buffer.
4523 (unless gnus-single-article-buffer
4524 (setq gnus-article-buffer name)
4525 (setq gnus-original-article-buffer original)
4526 (gnus-set-global-variables)))
4527 (gnus-article-setup-highlight-words)
4528 ;; Init original article buffer.
4529 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4530 (mm-enable-multibyte)
4531 (setq major-mode 'gnus-original-article-mode)
4532 (make-local-variable 'gnus-original-article))
4533 (if (and (get-buffer name)
4534 (with-current-buffer name
4535 (if gnus-article-edit-mode
4536 (if (y-or-n-p "Article mode edit in progress; discard? ")
4538 (set-buffer-modified-p nil)
4539 (gnus-kill-buffer name)
4542 (error "Action aborted"))
4544 (with-current-buffer name
4545 (set (make-local-variable 'gnus-article-edit-mode) nil)
4546 (when gnus-article-mime-handles
4547 (mm-destroy-parts gnus-article-mime-handles)
4548 (setq gnus-article-mime-handles nil))
4549 ;; Set it to nil in article-buffer!
4550 (setq gnus-article-mime-handle-alist nil)
4551 (buffer-disable-undo)
4552 (setq buffer-read-only t)
4553 ;; This list just keeps growing if we don't reset it.
4554 (setq gnus-button-marker-list nil)
4555 (unless (eq major-mode 'gnus-article-mode)
4556 (gnus-article-mode))
4558 (with-current-buffer (gnus-get-buffer-create name)
4560 (make-local-variable 'gnus-summary-buffer)
4561 (setq gnus-summary-buffer
4562 (gnus-summary-buffer-name gnus-newsgroup-name))
4563 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4564 (current-buffer)))))
4566 ;; Set article window start at LINE, where LINE is the number of lines
4567 ;; from the head of the article.
4568 (defun gnus-article-set-window-start (&optional line)
4569 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4570 (when article-window
4573 (with-current-buffer gnus-article-buffer
4574 (goto-char (point-min))
4577 (gnus-message 6 "Moved to bookmark")
4578 (search-forward "\n\n" nil t)
4582 (defun gnus-article-prepare (article &optional all-headers header)
4583 "Prepare ARTICLE in article mode buffer.
4584 ARTICLE should either be an article number or a Message-ID.
4585 If ARTICLE is an id, HEADER should be the article headers.
4586 If ALL-HEADERS is non-nil, no headers are hidden."
4588 ;; Make sure we start in a summary buffer.
4589 (unless (eq major-mode 'gnus-summary-mode)
4590 (set-buffer gnus-summary-buffer))
4591 (setq gnus-summary-buffer (current-buffer))
4592 (let* ((gnus-article (if header (mail-header-number header) article))
4593 (summary-buffer (current-buffer))
4594 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4595 (group gnus-newsgroup-name)
4598 (gnus-article-setup-buffer)
4599 (set-buffer gnus-article-buffer)
4600 ;; Deactivate active regions.
4601 (when (and (boundp 'transient-mark-mode)
4602 transient-mark-mode)
4603 (setq mark-active nil))
4604 (if (not (setq result (let ((inhibit-read-only t))
4605 (gnus-request-article-this-buffer
4607 ;; There is no such article.
4609 (when (and (numberp article)
4610 (not (memq article gnus-newsgroup-sparse)))
4611 (setq gnus-article-current
4612 (cons gnus-newsgroup-name article))
4613 (set-buffer gnus-summary-buffer)
4614 (setq gnus-current-article article)
4615 (if (and (memq article gnus-newsgroup-undownloaded)
4616 (not (gnus-online (gnus-find-method-for-group
4617 gnus-newsgroup-name))))
4619 (gnus-summary-set-agent-mark article)
4620 (message "Message marked for downloading"))
4621 (gnus-summary-mark-article article gnus-canceled-mark)
4622 (unless (memq article gnus-newsgroup-sparse)
4623 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4624 (if (or (eq result 'pseudo)
4625 (eq result 'nneething))
4627 (with-current-buffer summary-buffer
4628 (push article gnus-newsgroup-history)
4629 (setq gnus-last-article gnus-current-article
4630 gnus-current-article 0
4631 gnus-current-headers nil
4632 gnus-article-current nil)
4633 (if (eq result 'nneething)
4634 (gnus-configure-windows 'summary)
4635 (gnus-configure-windows 'article))
4636 (gnus-set-global-variables))
4637 (let ((gnus-article-mime-handle-alist-1
4638 gnus-article-mime-handle-alist))
4639 (gnus-set-mode-line 'article)))
4640 ;; The result from the `request' was an actual article -
4641 ;; or at least some text that is now displayed in the
4643 (when (and (numberp article)
4644 (not (eq article gnus-current-article)))
4645 ;; Seems like a new article has been selected.
4646 ;; `gnus-current-article' must be an article number.
4647 (with-current-buffer summary-buffer
4648 (push article gnus-newsgroup-history)
4649 (setq gnus-last-article gnus-current-article
4650 gnus-current-article article
4651 gnus-current-headers
4652 (gnus-summary-article-header gnus-current-article)
4653 gnus-article-current
4654 (cons gnus-newsgroup-name gnus-current-article))
4655 (unless (vectorp gnus-current-headers)
4656 (setq gnus-current-headers nil))
4657 (gnus-summary-goto-subject gnus-current-article)
4658 (when (gnus-summary-show-thread)
4659 ;; If the summary buffer really was folded, the
4660 ;; previous goto may not actually have gone to
4661 ;; the right article, but the thread root instead.
4663 (gnus-summary-goto-subject gnus-current-article))
4664 (gnus-run-hooks 'gnus-mark-article-hook)
4665 (gnus-set-mode-line 'summary)
4666 (when (gnus-visual-p 'article-highlight 'highlight)
4667 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4668 ;; Set the global newsgroup variables here.
4669 (gnus-set-global-variables)
4670 (setq gnus-have-all-headers
4671 (or all-headers gnus-show-all-headers))))
4673 (gnus-configure-windows 'article))
4674 (when (or (numberp article)
4676 (gnus-article-prepare-display)
4678 (goto-char (point-min))
4679 (when gnus-break-pages
4680 (gnus-narrow-to-page)))
4681 (let ((gnus-article-mime-handle-alist-1
4682 gnus-article-mime-handle-alist))
4683 (gnus-set-mode-line 'article))
4687 (set-window-point (get-buffer-window (current-buffer)) (point))
4688 (gnus-configure-windows 'article)
4692 (defun gnus-article-prepare-display ()
4693 "Make the current buffer look like a nice article."
4694 ;; Hooks for getting information from the article.
4695 ;; This hook must be called before being narrowed.
4696 (let ((gnus-article-buffer (current-buffer))
4698 (inhibit-read-only t))
4699 (unless (eq major-mode 'gnus-article-mode)
4700 (gnus-article-mode))
4701 (setq buffer-read-only nil
4702 gnus-article-wash-types nil
4703 gnus-article-image-alist nil)
4704 (gnus-run-hooks 'gnus-tmp-internal-hook)
4705 (when gnus-display-mime-function
4706 (funcall gnus-display-mime-function))
4707 (gnus-run-hooks 'gnus-article-prepare-hook)))
4710 ;;; Gnus Sticky Article Mode
4713 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4714 "Mode for sticky articles."
4715 ;; Release bindings that won't work.
4716 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4717 gnus-sticky-article-mode-map)
4718 (substitute-key-definition 'gnus-article-refer-article 'undefined
4719 gnus-sticky-article-mode-map)
4720 (dolist (k '("e" "h" "s" "F" "R"))
4721 (define-key gnus-sticky-article-mode-map k nil))
4722 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4723 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4724 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4725 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4727 (defun gnus-sticky-article (arg)
4728 "Make the current article sticky.
4729 If a prefix ARG is given, ask for a name for this sticky article buffer."
4731 (gnus-summary-show-thread)
4732 (gnus-summary-select-article nil nil 'pseudo)
4733 (let (new-art-buf-name)
4734 (gnus-eval-in-buffer-window gnus-article-buffer
4735 (setq new-art-buf-name
4739 (read-from-minibuffer "Sticky article buffer name: ")
4740 (gnus-with-article-headers
4741 (gnus-article-goto-header "subject")
4742 (setq new-art-buf-name
4743 (buffer-substring-no-properties
4744 (line-beginning-position) (line-end-position)))
4745 (goto-char (point-min))
4746 (gnus-article-goto-header "from")
4747 (setq new-art-buf-name
4749 new-art-buf-name ", "
4750 (buffer-substring-no-properties
4751 (line-beginning-position) (line-end-position))))
4752 (goto-char (point-min))
4753 (gnus-article-goto-header "date")
4754 (setq new-art-buf-name
4756 new-art-buf-name ", "
4757 (buffer-substring-no-properties
4758 (line-beginning-position) (line-end-position))))))
4760 (if (and (gnus-buffer-live-p new-art-buf-name)
4761 (with-current-buffer new-art-buf-name
4762 (eq major-mode 'gnus-sticky-article-mode)))
4763 (switch-to-buffer new-art-buf-name)
4764 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4765 (gnus-sticky-article-mode))
4766 (setq gnus-article-buffer new-art-buf-name))
4767 (gnus-summary-recenter)
4768 (gnus-summary-position-point))
4770 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4771 "Kill the given sticky article BUFFER.
4772 If none is given, assume the current buffer and kill it if it has
4773 `gnus-sticky-article-mode'."
4776 (setq buffer (current-buffer)))
4777 (with-current-buffer buffer
4778 (when (eq major-mode 'gnus-sticky-article-mode)
4779 (gnus-kill-buffer buffer))))
4781 (defun gnus-kill-sticky-article-buffers (arg)
4782 "Kill all sticky article buffers.
4783 If a prefix ARG is given, ask for confirmation."
4785 (dolist (buf (gnus-buffers))
4786 (with-current-buffer buf
4787 (when (eq major-mode 'gnus-sticky-article-mode)
4789 (gnus-kill-buffer buf)
4790 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4791 (gnus-kill-buffer buf)))))))
4794 ;;; Gnus MIME viewing functions
4797 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4798 "Format of the MIME buttons.
4800 Valid specifiers include:
4802 %T MIME type, along with additional info
4803 %n The `name' parameter
4804 %d The description, if any
4805 %l The length of the encoded part
4806 %p The part identifier number
4807 %e Dots if the part isn't displayed
4809 General format specifiers can also be used. See Info node
4810 `(gnus)Formatting Variables'.")
4812 (defvar gnus-mime-button-line-format-alist
4813 '((?t gnus-tmp-type ?s)
4814 (?T gnus-tmp-type-long ?s)
4815 (?n gnus-tmp-name ?s)
4816 (?d gnus-tmp-description ?s)
4818 (?l gnus-tmp-length ?d)
4819 (?e gnus-tmp-dots ?s)))
4821 (defvar gnus-mime-button-commands
4822 '((gnus-article-press-button "\r" "Toggle Display")
4823 (gnus-mime-view-part "v" "View Interactively...")
4824 (gnus-mime-view-part-as-type "t" "View As Type...")
4825 (gnus-mime-view-part-as-charset "C" "View As charset...")
4826 (gnus-mime-save-part "o" "Save...")
4827 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4828 (gnus-mime-replace-part "r" "Replace part")
4829 (gnus-mime-delete-part "d" "Delete part")
4830 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4831 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4832 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4833 (gnus-mime-view-part-externally "e" "View Externally")
4834 (gnus-mime-print-part "p" "Print")
4835 (gnus-mime-pipe-part "|" "Pipe To Command...")
4836 (gnus-mime-action-on-part "." "Take action on the part...")))
4838 (defun gnus-article-mime-part-status ()
4839 (if gnus-article-mime-handle-alist-1
4840 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4842 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4845 (defvar gnus-mime-button-map
4846 (let ((map (make-sparse-keymap)))
4847 (define-key map gnus-mouse-2 'gnus-article-push-button)
4848 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4849 (dolist (c gnus-mime-button-commands)
4850 (define-key map (cadr c) (car c)))
4854 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4856 ,@(mapcar (lambda (c)
4857 (vector (caddr c) (car c) :active t))
4858 gnus-mime-button-commands)))
4860 (defvar gnus-url-button-commands
4861 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4863 (defvar gnus-url-button-map
4864 (let ((map (make-sparse-keymap)))
4865 (dolist (c gnus-url-button-commands)
4866 (define-key map (cadr c) (car c)))
4870 gnus-url-button-menu gnus-url-button-map "URL button menu."
4872 ,@(mapcar (lambda (c)
4873 (vector (caddr c) (car c) :active t))
4874 gnus-url-button-commands)))
4876 (defmacro gnus-bind-safe-url-regexp (&rest body)
4877 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4878 `(let ((mm-w3m-safe-url-regexp
4879 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4881 gnus-article-current-summary))
4882 (with-current-buffer gnus-article-current-summary
4883 gnus-newsgroup-name)
4884 gnus-newsgroup-name)))
4885 (if (cond ((not group)
4886 ;; Maybe we're in a mml-preview buffer
4887 ;; and no group is selected.
4889 ((stringp gnus-safe-html-newsgroups)
4890 (string-match gnus-safe-html-newsgroups group))
4891 ((consp gnus-safe-html-newsgroups)
4892 (member group gnus-safe-html-newsgroups)))
4894 mm-w3m-safe-url-regexp))))
4897 (defun gnus-mime-button-menu (event prefix)
4898 "Construct a context-sensitive menu of MIME commands."
4899 (interactive "e\nP")
4900 (save-window-excursion
4901 (let ((pos (event-start event)))
4902 (select-window (posn-window pos))
4903 (goto-char (posn-point pos))
4904 (gnus-article-check-buffer)
4905 (popup-menu gnus-mime-button-menu nil prefix))))
4907 (defun gnus-mime-view-all-parts (&optional handles)
4908 "View all the MIME parts."
4910 (with-current-buffer gnus-article-buffer
4911 (let ((handles (or handles gnus-article-mime-handles))
4912 (mail-parse-charset gnus-newsgroup-charset)
4913 (mail-parse-ignored-charsets
4914 (with-current-buffer gnus-summary-buffer
4915 gnus-newsgroup-ignored-charsets)))
4917 (mm-remove-parts handles)
4918 (goto-char (point-min))
4919 (or (search-forward "\n\n") (goto-char (point-max)))
4920 (let ((inhibit-read-only t))
4921 (delete-region (point) (point-max))
4922 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4924 (defun gnus-article-jump-to-part (n)
4925 "Jump to MIME part N."
4927 (pop-to-buffer gnus-article-buffer)
4928 ;; FIXME: why is it necessary?
4930 (let ((parts (length gnus-article-mime-handle-alist)))
4931 (or n (setq n (read-number (format "Jump to part (2..%s): " parts))))
4932 (unless (and (integerp n) (<= n parts) (>= n 1))
4935 (gnus-message 7 "Invalid part `%s', using %s instead."
4938 (gnus-message 9 "Jumping to part %s." n)
4939 (cond ((>= gnus-auto-select-part 1)
4940 (while (and (<= n parts)
4941 (not (gnus-article-goto-part n)))
4943 ((< gnus-auto-select-part 0)
4944 (while (and (>= n 1)
4945 (not (gnus-article-goto-part n)))
4948 (gnus-article-goto-part n)))))
4950 (defvar gnus-mime-buttonized-part-id nil
4951 "ID of a mime part that should be buttonized.
4952 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4955 (defsubst gnus-article-edit-part (handles &optional current-id)
4956 "Edit an article in order to delete a mime part.
4957 This function is exclusively used by `gnus-mime-save-part-and-strip'
4958 and `gnus-mime-delete-part', and not provided at run-time normally."
4959 (gnus-article-edit-article
4961 (buffer-disable-undo)
4963 (let ((mail-parse-charset (or gnus-article-charset
4964 ',gnus-newsgroup-charset))
4965 (mail-parse-ignored-charsets
4966 (or gnus-article-ignored-charsets
4967 ',gnus-newsgroup-ignored-charsets))
4968 (mbl mml-buffer-list))
4969 (setq mml-buffer-list nil)
4970 (insert-buffer-substring gnus-original-article-buffer)
4971 (mime-to-mml ',handles)
4972 (setq gnus-article-mime-handles nil)
4973 (let ((mbl1 mml-buffer-list))
4974 (setq mml-buffer-list mbl)
4975 (set (make-local-variable 'mml-buffer-list) mbl1))
4976 (gnus-make-local-hook 'kill-buffer-hook)
4977 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4978 `(lambda (no-highlight)
4979 (let ((mail-parse-charset (or gnus-article-charset
4980 ',gnus-newsgroup-charset))
4981 (message-options message-options)
4982 (message-options-set-recipient)
4983 (mail-parse-ignored-charsets
4984 (or gnus-article-ignored-charsets
4985 ',gnus-newsgroup-ignored-charsets)))
4987 (mml-destroy-buffers)
4988 (remove-hook 'kill-buffer-hook
4989 'mml-destroy-buffers t)
4990 (kill-local-variable 'mml-buffer-list))
4991 (gnus-summary-edit-article-done
4992 ,(or (mail-header-references gnus-current-headers) "")
4993 ,(gnus-group-read-only-p)
4994 ,gnus-summary-buffer no-highlight))
4996 ;; Force buttonizing this part.
4997 (let ((gnus-mime-buttonized-part-id current-id))
4998 (gnus-article-edit-done))
4999 (gnus-configure-windows 'article)
5000 (when (and current-id (integerp gnus-auto-select-part))
5001 (gnus-article-jump-to-part
5002 (min (max (+ current-id gnus-auto-select-part) 1)
5003 (with-current-buffer gnus-article-buffer
5004 (length gnus-article-mime-handle-alist)))))))
5006 (defun gnus-mime-replace-part (file)
5007 "Replace MIME part under point with an external body."
5008 ;; Useful if file has already been saved to disk
5011 (read-file-name "Replace MIME part with file: "
5012 (or mm-default-directory default-directory)
5014 (gnus-mime-save-part-and-strip file))
5016 (defun gnus-mime-save-part-and-strip (&optional file)
5017 "Save the MIME part under point then replace it with an external body.
5018 If FILE is given, use it for the external part."
5020 (gnus-article-check-buffer)
5021 (when (gnus-group-read-only-p)
5022 (error "The current group does not support deleting of parts"))
5023 (when (mm-complicated-handles gnus-article-mime-handles)
5025 The current article has a complicated MIME structure, giving up..."))
5026 (let* ((data (get-text-property (point) 'gnus-data))
5027 (id (get-text-property (point) 'gnus-part))
5029 (handles gnus-article-mime-handles))
5032 (and data (mm-save-part data "Delete MIME part and save to: "))))
5034 (with-current-buffer (mm-handle-buffer data)
5036 (insert "Content-Type: " (mm-handle-media-type data))
5037 (mml-insert-parameter-string (cdr (mm-handle-type data))
5039 ;; Add a filename for the sake of saving the part again.
5040 (mml-insert-parameter
5041 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5043 (insert "Content-ID: " (message-make-message-id) "\n")
5044 (insert "Content-Transfer-Encoding: binary\n")
5047 (cdr (mm-make-handle nil
5048 `("message/external-body"
5049 (access-type . "LOCAL-FILE")
5051 ;; (set-buffer gnus-summary-buffer)
5052 (gnus-article-edit-part handles id))))
5054 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5055 ;; parts...>') but with stripping would be nice.
5057 (defun gnus-mime-delete-part ()
5058 "Delete the MIME part under point.
5059 Replace it with some information about the removed part."
5061 (gnus-article-check-buffer)
5062 (when (gnus-group-read-only-p)
5063 (error "The current group does not support deleting of parts"))
5064 (when (mm-complicated-handles gnus-article-mime-handles)
5066 The current article has a complicated MIME structure, giving up..."))
5067 (when (or gnus-expert-user
5068 (gnus-yes-or-no-p "\
5069 Deleting parts may malfunction or destroy the article; continue? "))
5070 (let* ((data (get-text-property (point) 'gnus-data))
5071 (id (get-text-property (point) 'gnus-part))
5072 (handles gnus-article-mime-handles)
5075 (let ((desc (mm-handle-description data)))
5077 (mail-decode-encoded-word-string desc))))
5079 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5081 (type (mm-handle-media-type data)))
5083 (error "No MIME part under point"))
5084 (with-current-buffer (mm-handle-buffer data)
5085 (let ((bsize (format "%s" (buffer-size))))
5090 "| The following attachment has been deleted:\n"
5092 "| Type: " type "\n"
5093 "| Filename: " filename "\n"
5094 "| Size (encoded): " bsize (format " byte%s\n"
5099 (concat "| Description: " description "\n"))
5102 (cdr (mm-make-handle
5103 nil `("text/plain" (charset . gnus-decoded)) nil nil
5105 (format "Deleted attachment (%s bytes)" bsize))))))
5106 ;; (set-buffer gnus-summary-buffer)
5107 (gnus-article-edit-part handles id))))
5109 (defun gnus-mime-save-part ()
5110 "Save the MIME part under point."
5112 (gnus-article-check-buffer)
5113 (let ((data (get-text-property (point) 'gnus-data)))
5115 (mm-save-part data))))
5117 (defun gnus-mime-pipe-part (&optional cmd)
5118 "Pipe the MIME part under point to a process.
5119 Use CMD as the process."
5121 (gnus-article-check-buffer)
5122 (let ((data (get-text-property (point) 'gnus-data)))
5124 (mm-pipe-part data cmd))))
5126 (defun gnus-mime-view-part ()
5127 "Interactively choose a viewing method for the MIME part under point."
5129 (gnus-article-check-buffer)
5130 (let ((data (get-text-property (point) 'gnus-data)))
5132 (setq gnus-article-mime-handles
5134 gnus-article-mime-handles (setq data (copy-sequence data))))
5135 (mm-interactively-view-part data))))
5137 (defun gnus-mime-view-part-as-type-internal ()
5138 (gnus-article-check-buffer)
5139 (let* ((handle (get-text-property (point) 'gnus-data))
5141 ;; Content-Type: foo/bar; name=...
5142 (mail-content-type-get (mm-handle-type handle) 'name)
5143 ;; Content-Disposition: attachment; filename=...
5144 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5145 (def-type (and name (mm-default-file-encoding name))))
5146 (or (and def-type (cons def-type 0))
5148 (equal (mm-handle-media-supertype handle) "text")
5149 '("text/plain" . 0))
5150 '("application/octet-stream" . 0))))
5152 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5153 "Choose a MIME media type, and view the part as such.
5154 If non-nil, PRED is a predicate to use during completion to limit the
5155 available media-types."
5159 (let ((default (gnus-mime-view-part-as-type-internal)))
5161 (format "View as MIME type (default %s): "
5163 (mapcar #'list (mailcap-mime-types))
5166 (gnus-article-check-buffer)
5167 (let ((handle (get-text-property (point) 'gnus-data)))
5169 (when (equal (mm-handle-media-type handle) "message/external-body")
5170 (unless (mm-handle-cache handle)
5171 (mm-extern-cache-contents handle))
5172 (setq handle (mm-handle-cache handle)))
5174 (mm-make-handle (mm-handle-buffer handle)
5175 (cons mime-type (cdr (mm-handle-type handle)))
5176 (mm-handle-encoding handle)
5177 (mm-handle-undisplayer handle)
5178 (mm-handle-disposition handle)
5179 (mm-handle-description handle)
5181 (mm-handle-id handle)))
5182 (setq gnus-article-mime-handles
5183 (mm-merge-handles gnus-article-mime-handles handle))
5184 (when (mm-handle-displayed-p handle)
5185 (mm-remove-part handle))
5186 (gnus-mm-display-part handle))))
5188 (defun gnus-mime-copy-part (&optional handle arg)
5189 "Put the MIME part under point into a new buffer.
5190 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5192 (interactive (list nil current-prefix-arg))
5193 (gnus-article-check-buffer)
5195 (setq handle (get-text-property (point) 'gnus-data)))
5197 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5199 (mail-content-type-get (mm-handle-disposition handle)
5201 contents dont-decode charset coding-system)
5202 (mm-with-unibyte-buffer
5203 (mm-insert-part handle)
5204 (setq contents (or (condition-case nil
5205 (mm-decompress-buffer filename nil 'sig)
5207 (setq dont-decode t)
5210 (setq filename (cond (filename (file-name-nondirectory filename))
5211 (dont-decode "*raw data*")
5216 (unless (setq charset (mail-content-type-get
5217 (mm-handle-type handle) 'charset))
5218 (unless (setq coding-system (mm-with-unibyte-buffer
5220 (mm-find-buffer-file-coding-system)))
5221 (setq charset gnus-newsgroup-charset))))
5223 (setq charset (or (cdr (assq arg
5224 gnus-summary-show-article-charset-alist))
5225 (mm-read-coding-system "Charset: ")))))
5226 (switch-to-buffer (generate-new-buffer filename))
5227 (if (or coding-system
5229 (setq coding-system (mm-charset-to-coding-system charset))
5230 (not (eq charset 'ascii))))
5232 (mm-enable-multibyte)
5233 (insert (mm-decode-coding-string contents coding-system))
5234 (setq buffer-file-coding-system
5235 (if (boundp 'last-coding-system-used)
5236 (symbol-value 'last-coding-system-used)
5238 (mm-disable-multibyte)
5240 (setq buffer-file-coding-system mm-binary-coding-system))
5241 ;; We do it this way to make `normal-mode' set the appropriate mode.
5244 (setq buffer-file-name (expand-file-name filename))
5246 (setq buffer-file-name nil))
5247 (goto-char (point-min)))))
5249 (defun gnus-mime-print-part (&optional handle filename)
5250 "Print the MIME part under point."
5251 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5252 (gnus-article-check-buffer)
5253 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5254 (contents (and handle (mm-get-part handle)))
5255 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5256 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5261 (mm-save-part-to-file handle file)
5262 (call-process shell-file-name nil
5263 (generate-new-buffer " *mm*")
5265 shell-command-switch
5267 printer file (mm-handle-type handle))))
5271 (gnus-print-buffer))
5272 (ps-despool filename)))))
5274 (defun gnus-mime-inline-part (&optional handle arg)
5275 "Insert the MIME part under point into the current buffer.
5276 Compressed files like .gz and .bz2 are decompressed."
5277 (interactive (list nil current-prefix-arg))
5278 (gnus-article-check-buffer)
5280 (setq handle (get-text-property (point) 'gnus-data)))
5283 (inhibit-read-only t)
5284 contents charset coding-system)
5285 (if (and (not arg) (mm-handle-undisplayer handle))
5286 (mm-remove-part handle)
5287 (mm-with-unibyte-buffer
5288 (mm-insert-part handle)
5290 (or (mm-decompress-buffer
5291 (or (mail-content-type-get (mm-handle-type handle)
5293 (mail-content-type-get (mm-handle-disposition handle)
5299 (unless (setq charset (mail-content-type-get
5300 (mm-handle-type handle) 'charset))
5301 (unless (setq coding-system
5302 (mm-with-unibyte-buffer
5304 (mm-find-buffer-file-coding-system)))
5305 (setq charset gnus-newsgroup-charset))))
5307 (if (mm-handle-undisplayer handle)
5308 (mm-remove-part handle))
5311 gnus-summary-show-article-charset-alist))
5312 (mm-read-coding-system "Charset: "))))
5314 (if (mm-handle-undisplayer handle)
5315 (mm-remove-part handle))))
5319 (if (or coding-system
5322 (mm-charset-to-coding-system charset))
5323 (not (eq coding-system 'ascii))))
5324 (mm-decode-coding-string contents coding-system)
5325 (mm-string-to-multibyte contents)))
5328 (defun gnus-mime-set-charset-parameters (handle charset)
5329 "Set CHARSET to parameters in HANDLE.
5330 CHARSET may either be a string or a symbol."
5331 (unless (stringp charset)
5332 (setq charset (symbol-name charset)))
5333 (if (stringp (car handle))
5334 (dolist (h (cdr handle))
5335 (gnus-mime-set-charset-parameters h charset))
5336 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5337 "message/external-body")
5339 (unless (mm-handle-cache handle)
5340 (mm-extern-cache-contents handle))
5341 (mm-handle-cache handle))
5343 (param (assq 'charset (cdr type))))
5345 (setcdr param charset)
5346 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5348 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5349 "Insert the MIME part under point into the current buffer using the
5351 (interactive (list nil current-prefix-arg))
5352 (gnus-article-check-buffer)
5353 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5354 (fun (get-text-property (point) 'gnus-callback))
5355 (gnus-newsgroup-ignored-charsets 'gnus-all)
5356 charset form preferred parts)
5363 gnus-summary-show-article-charset-alist))
5364 (mm-read-coding-system "Charset: "))))
5365 (if (mm-handle-undisplayer handle)
5366 (mm-remove-part handle)))
5367 (gnus-mime-set-charset-parameters handle charset)
5368 (when (and (consp (setq form (cdr-safe fun)))
5369 (setq form (ignore-errors
5370 (assq 'gnus-mime-display-alternative form)))
5371 (setq preferred (caddr form))
5373 (when (eq (car preferred) 'quote)
5374 (setq preferred (cadr preferred)))
5375 (not (equal preferred
5376 (get-text-property (point) 'gnus-data))))
5377 (setq parts (get-text-property (point) 'gnus-part))
5378 (setq parts (cdr (assq parts
5379 gnus-article-mime-handle-alist)))
5380 (equal (mm-handle-media-type parts) "multipart/alternative")
5381 (setq parts (reverse (cdr parts))))
5383 (list 'quote (or (cadr (member preferred parts))
5385 (funcall fun handle)))))
5387 (defun gnus-mime-view-part-externally (&optional handle)
5388 "View the MIME part under point with an external viewer."
5390 (gnus-article-check-buffer)
5391 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5392 (mm-user-display-methods nil)
5393 (mm-inlined-types nil)
5394 (mail-parse-charset gnus-newsgroup-charset)
5395 (mail-parse-ignored-charsets
5396 (with-current-buffer gnus-summary-buffer
5397 gnus-newsgroup-ignored-charsets))
5398 (type (mm-handle-media-type handle))
5399 (method (mailcap-mime-info type))
5400 (mm-enable-external t))
5401 (if (not (stringp method))
5402 (gnus-mime-view-part-as-type
5403 nil (lambda (types) (stringp (mailcap-mime-info (car types)))))
5405 (if (mm-handle-undisplayer handle)
5406 (mm-remove-part handle)
5407 (mm-display-part handle))))))
5409 (defun gnus-mime-view-part-internally (&optional handle)
5410 "View the MIME part under point with an internal viewer.
5411 If no internal viewer is available, use an external viewer."
5413 (gnus-article-check-buffer)
5414 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5415 (mm-inlined-types '(".*"))
5416 (mm-inline-large-images t)
5417 (mail-parse-charset gnus-newsgroup-charset)
5418 (mail-parse-ignored-charsets
5419 (with-current-buffer gnus-summary-buffer
5420 gnus-newsgroup-ignored-charsets))
5421 (inhibit-read-only t))
5422 (if (not (mm-inlinable-p handle))
5423 (gnus-mime-view-part-as-type
5424 nil (lambda (types) (mm-inlinable-p handle (car types))))
5426 (if (mm-handle-undisplayer handle)
5427 (mm-remove-part handle)
5428 (gnus-bind-safe-url-regexp (mm-display-part handle)))))))
5430 (defun gnus-mime-action-on-part (&optional action)
5431 "Do something with the MIME attachment at \(point\)."
5433 (list (completing-read "Action: " gnus-mime-action-alist nil t)))
5434 (gnus-article-check-buffer)
5435 (let ((action-pair (assoc action gnus-mime-action-alist)))
5437 (funcall (cdr action-pair)))))
5439 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5440 "Call FUNCTION on MIME part N.
5441 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5442 If INTERACTIVE, call FUNCTION interactivly."
5444 ;; Check whether the article is displayed.
5445 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5446 (setq window (get-buffer-window gnus-article-buffer t))
5447 (frame-visible-p (setq frame (window-frame window))))
5448 (error "No article is displayed"))
5449 (with-current-buffer gnus-article-buffer
5450 ;; Check whether the article displays the right contents.
5451 (unless (with-current-buffer gnus-summary-buffer
5452 (eq gnus-current-article (gnus-summary-article-number)))
5453 (error "You should select the right article first"))
5455 (setq n (prefix-numeric-value n))
5457 (setq n (or (get-text-property pt 'gnus-part)
5459 (get-text-property (1- pt) 'gnus-part))
5460 (get-text-property (prog2
5466 (or (and (setq pt (previous-single-property-change
5469 (next-single-property-change (point) 'gnus-part)
5473 ;; Check whether the specified part exists.
5474 (when (> n (length gnus-article-mime-handle-alist))
5475 (error "No such part")))
5478 ;; To select the window is needed so that the cursor
5479 ;; might be visible on the MIME button.
5480 (select-window (prog1
5482 (setq window (selected-window))
5483 ;; Article may be displayed in the other frame.
5484 (gnus-select-frame-set-input-focus
5487 (setq frame (selected-frame))))))
5488 (when (gnus-article-goto-part n)
5489 ;; We point the cursor and the arrow at the MIME button
5490 ;; when the `function' prompt the user for something.
5491 (let ((cursor-in-non-selected-windows t)
5492 (overlay-arrow-string "=>")
5493 (overlay-arrow-position (point-marker)))
5496 ((and no-handle interactive)
5497 (call-interactively function))
5503 (cdr (assq n gnus-article-mime-handle-alist))))
5506 (cdr (assq n gnus-article-mime-handle-alist)))))
5507 (set-marker overlay-arrow-position nil)
5508 (unless gnus-auto-select-part
5509 (gnus-select-frame-set-input-focus frame)
5510 (select-window window))))
5512 (if gnus-inhibit-mime-unbuttonizing
5513 ;; This is the default though the program shouldn't reach here.
5514 (error "No such part")
5515 ;; The part which doesn't have the MIME button is selected.
5516 ;; So, we display all the buttons and redo it.
5517 (let ((gnus-inhibit-mime-unbuttonizing t))
5518 (gnus-summary-show-article)
5519 (gnus-article-part-wrapper n function no-handle))))))
5521 (defun gnus-article-pipe-part (n)
5522 "Pipe MIME part N, which is the numerical prefix."
5524 (gnus-article-part-wrapper n 'mm-pipe-part))
5526 (defun gnus-article-save-part (n)
5527 "Save MIME part N, which is the numerical prefix."
5529 (gnus-article-part-wrapper n 'mm-save-part))
5531 (defun gnus-article-interactively-view-part (n)
5532 "View MIME part N interactively, which is the numerical prefix."
5534 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5536 (defun gnus-article-copy-part (n)
5537 "Copy MIME part N, which is the numerical prefix."
5539 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5541 (defun gnus-article-view-part-as-charset (n)
5542 "View MIME part N using a specified charset.
5543 N is the numerical prefix."
5545 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5547 (defun gnus-article-view-part-externally (n)
5548 "View MIME part N externally, which is the numerical prefix."
5550 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5552 (defun gnus-article-inline-part (n)
5553 "Inline MIME part N, which is the numerical prefix."
5555 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5557 (defun gnus-article-save-part-and-strip (n)
5558 "Save MIME part N and replace it with an external body.
5559 N is the numerical prefix."
5561 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5563 (defun gnus-article-replace-part (n)
5564 "Replace MIME part N with an external body.
5565 N is the numerical prefix."
5567 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5569 (defun gnus-article-delete-part (n)
5570 "Delete MIME part N and add some information about the removed part.
5571 N is the numerical prefix."
5573 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5575 (defun gnus-article-view-part-as-type (n)
5576 "Choose a MIME media type, and view part N as such.
5577 N is the numerical prefix."
5579 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5581 (defun gnus-article-mime-match-handle-first (condition)
5584 (dolist (ihandle gnus-article-mime-handle-alist)
5586 ((functionp condition)
5587 (funcall condition (cdr ihandle)))
5588 ((eq condition 'undisplayed)
5589 (not (or (mm-handle-undisplayer (cdr ihandle))
5590 (equal (mm-handle-media-type (cdr ihandle))
5591 "multipart/alternative"))))
5592 ((eq condition 'undisplayed-alternative)
5593 (not (mm-handle-undisplayer (cdr ihandle))))
5595 (gnus-article-goto-part (car ihandle))
5596 (or (not n) (< (car ihandle) n)))
5597 (setq n (car ihandle))))
5601 (defun gnus-article-view-part (&optional n)
5602 "View MIME part N, which is the numerical prefix.
5603 If the part is already shown, hide the part. If N is nil, view
5606 (with-current-buffer gnus-article-buffer
5607 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5608 gnus-article-mime-match-handle-function)))
5609 (when (> n (length gnus-article-mime-handle-alist))
5610 (error "No such part"))
5611 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5612 (when (gnus-article-goto-part n)
5613 (if (equal (car handle) "multipart/alternative")
5614 (gnus-article-press-button)
5615 (when (eq (gnus-mm-display-part handle) 'internal)
5616 (gnus-set-window-start)))))))
5618 (defsubst gnus-article-mime-total-parts ()
5619 (if (bufferp (car gnus-article-mime-handles))
5621 (1- (length gnus-article-mime-handles))))
5623 (defun gnus-mm-display-part (handle)
5624 "Display HANDLE and fix MIME button."
5625 (let ((id (get-text-property (point) 'gnus-part))
5627 (inhibit-read-only t))
5630 (let ((window (selected-window))
5631 (mail-parse-charset gnus-newsgroup-charset)
5632 (mail-parse-ignored-charsets
5633 (if (gnus-buffer-live-p gnus-summary-buffer)
5634 (with-current-buffer gnus-summary-buffer
5635 gnus-newsgroup-ignored-charsets)
5639 (let ((win (gnus-get-buffer-window (current-buffer) t))
5642 (select-window win))
5645 (if (mm-handle-displayed-p handle)
5646 ;; This will remove the part.
5647 (mm-display-part handle)
5649 (narrow-to-region (point)
5650 (if (eobp) (point) (1+ (point))))
5651 (gnus-bind-safe-url-regexp (mm-display-part handle))
5652 ;; We narrow to the part itself and
5653 ;; then call the treatment functions.
5654 (goto-char (point-min))
5656 (narrow-to-region (point) (point-max))
5659 (gnus-article-mime-total-parts)
5660 (mm-handle-media-type handle)))))
5661 (if (window-live-p window)
5662 (select-window window)))))
5665 (gnus-insert-mime-button
5666 handle id (list (mm-handle-displayed-p handle)))
5667 (goto-char point))))
5669 (defun gnus-article-goto-part (n)
5670 "Go to MIME part N."
5671 (gnus-goto-char (text-property-any (point-min) (point-max) 'gnus-part n)))
5673 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5674 (let ((gnus-tmp-name
5675 (or (mail-content-type-get (mm-handle-type handle) 'name)
5676 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5677 (mail-content-type-get (mm-handle-type handle) 'url)
5679 (gnus-tmp-type (mm-handle-media-type handle))
5680 (gnus-tmp-description (or (mm-handle-description handle) ""))
5682 (if (if displayed (car displayed)
5683 (mm-handle-displayed-p handle))
5685 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5687 gnus-tmp-type-long b e)
5688 (when (string-match ".*/" gnus-tmp-name)
5689 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5690 (setq gnus-tmp-type-long (concat gnus-tmp-type
5691 (and (not (equal gnus-tmp-name ""))
5692 (concat "; " gnus-tmp-name))))
5693 (unless (equal gnus-tmp-description "")
5694 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5699 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5700 `(keymap ,gnus-mime-button-map
5701 gnus-callback gnus-mm-display-part
5702 gnus-part ,gnus-tmp-id
5703 article-type annotation
5706 ;; Exclude a newline.
5709 (when gnus-article-button-face
5710 (gnus-overlay-put (gnus-make-overlay b e nil t)
5711 'face gnus-article-button-face))
5712 (widget-convert-button
5715 :action 'gnus-widget-press-button
5716 :button-keymap gnus-mime-button-map
5719 ;; Needed to properly clear the message due to a bug in
5720 ;; wid-edit (XEmacs only).
5721 (if (boundp 'help-echo-owns-message)
5722 (setq help-echo-owns-message t))
5724 "%S: %s the MIME part; %S: more options"
5725 (aref gnus-mouse-2 0)
5726 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5728 (aref gnus-down-mouse-3 0))))))
5730 (defun gnus-widget-press-button (elems el)
5731 (goto-char (widget-get elems :from))
5732 (gnus-article-press-button))
5734 (defvar gnus-displaying-mime nil)
5736 (defun gnus-display-mime (&optional ihandles)
5737 "Display the MIME parts."
5739 (save-selected-window
5740 (let ((window (get-buffer-window gnus-article-buffer))
5743 (select-window window)
5744 ;; We have to do this since selecting the window
5745 ;; may change the point. So we set the window point.
5746 (set-window-point window point)))
5747 (let ((handles ihandles)
5748 (inhibit-read-only t)
5751 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5752 (when gnus-article-emulate-mime
5753 (mm-uu-dissect-text-parts handles)))
5754 (gnus-article-emulate-mime
5755 (setq handles (mm-uu-dissect))))
5756 (when (and (not ihandles)
5757 (not gnus-displaying-mime))
5758 ;; Top-level call; we clean up.
5759 (when gnus-article-mime-handles
5760 (mm-destroy-parts gnus-article-mime-handles)
5761 (setq gnus-article-mime-handle-alist nil));; A trick.
5762 (setq gnus-article-mime-handles handles)
5763 ;; We allow users to glean info from the handles.
5764 (when gnus-article-mime-part-function
5765 (gnus-mime-part-function handles)))
5767 (or (not (stringp (car handles)))
5770 (when (and (not ihandles)
5771 (not gnus-displaying-mime))
5772 ;; Clean up for mime parts.
5774 (delete-region (point) (point-max)))
5775 (let ((gnus-displaying-mime t))
5776 (gnus-mime-display-part handles)))
5779 (narrow-to-region (point) (point-max))
5780 (gnus-treat-article nil 1 1)
5783 ;; Highlight the headers.
5787 (narrow-to-region (point-min) (point))
5788 (gnus-article-save-original-date
5789 (gnus-treat-article 'head)))))))
5790 ;; Cope with broken MIME messages.
5791 (goto-char (point-max))
5795 (defcustom gnus-mime-display-multipart-as-mixed nil
5796 "Display \"multipart\" parts as \"multipart/mixed\".
5798 If t, it overrides nil values of
5799 `gnus-mime-display-multipart-alternative-as-mixed' and
5800 `gnus-mime-display-multipart-related-as-mixed'."
5801 :group 'gnus-article-mime
5804 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5805 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5807 :group 'gnus-article-mime
5810 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5811 "Display \"multipart/related\" parts as \"multipart/mixed\".
5813 If displaying \"text/html\" is discouraged \(see
5814 `mm-discouraged-alternatives'\) images or other material inside a
5815 \"multipart/related\" part might be overlooked when this variable is nil."
5817 :group 'gnus-article-mime
5820 (defun gnus-mime-display-part (handle)
5822 ;; Maybe a broken MIME message.
5825 ((not (stringp (car handle)))
5826 (gnus-mime-display-single handle))
5827 ;; User-defined multipart
5828 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5829 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5831 ;; multipart/alternative
5832 ((and (equal (car handle) "multipart/alternative")
5833 (not (or gnus-mime-display-multipart-as-mixed
5834 gnus-mime-display-multipart-alternative-as-mixed)))
5835 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5836 (push (cons id handle) gnus-article-mime-handle-alist)
5837 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5838 ;; multipart/related
5839 ((and (equal (car handle) "multipart/related")
5840 (not (or gnus-mime-display-multipart-as-mixed
5841 gnus-mime-display-multipart-related-as-mixed)))
5842 ;;;!!!We should find the start part, but we just default
5843 ;;;!!!to the first part.
5844 ;;(gnus-mime-display-part (cadr handle))
5845 ;;;!!! Most multipart/related is an HTML message plus images.
5846 ;;;!!! Unfortunately we are unable to let W3 display those
5847 ;;;!!! included images, so we just display it as a mixed multipart.
5848 ;;(gnus-mime-display-mixed (cdr handle))
5849 ;;;!!! No, w3 can display everything just fine.
5850 (gnus-mime-display-part (cadr handle)))
5851 ((equal (car handle) "multipart/signed")
5852 (gnus-add-wash-type 'signed)
5853 (gnus-mime-display-security handle))
5854 ((equal (car handle) "multipart/encrypted")
5855 (gnus-add-wash-type 'encrypted)
5856 (gnus-mime-display-security handle))
5857 ;; Other multiparts are handled like multipart/mixed.
5859 (gnus-mime-display-mixed (cdr handle)))))
5861 (defun gnus-mime-part-function (handles)
5862 (if (stringp (car handles))
5863 (mapcar 'gnus-mime-part-function (cdr handles))
5864 (funcall gnus-article-mime-part-function handles)))
5866 (defun gnus-mime-display-mixed (handles)
5867 (mapcar 'gnus-mime-display-part handles))
5869 (defun gnus-mime-display-single (handle)
5870 (let ((type (mm-handle-media-type handle))
5871 (ignored gnus-ignored-mime-types)
5878 (when (string-match (pop ignored) type)
5879 (throw 'ignored nil)))
5880 (if (and (setq not-attachment
5881 (and (not (mm-inline-override-p handle))
5882 (or (not (mm-handle-disposition handle))
5883 (equal (car (mm-handle-disposition handle))
5885 (mm-attachment-override-p handle))))
5886 (mm-automatic-display-p handle)
5888 (mm-inlinable-p handle)
5889 (mm-inlined-p handle))
5890 (mm-automatic-external-display-p type)))
5892 (when (equal (mm-handle-media-supertype handle) "text")
5894 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5896 (push (cons id handle) gnus-article-mime-handle-alist)
5898 (equal (mm-handle-media-supertype handle) "message"))
5901 (cond ((not (bolp)) 2)
5902 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5904 (when (or (not display)
5905 (not (gnus-unbuttonized-mime-type-p type))
5906 (eq id gnus-mime-buttonized-part-id))
5907 (gnus-insert-mime-button
5908 handle id (list (or display (and not-attachment text))))
5909 (gnus-article-insert-newline)
5910 ;; Remember modify the number of forward lines.
5918 (let ((mail-parse-charset gnus-newsgroup-charset)
5919 (mail-parse-ignored-charsets
5920 (save-excursion (condition-case ()
5921 (set-buffer gnus-summary-buffer)
5923 gnus-newsgroup-ignored-charsets)))
5924 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5925 (goto-char (point-max)))
5926 ((and text not-attachment)
5930 (gnus-article-insert-newline)
5933 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5935 (and (equal type "text/calendar") 'utf-8))))
5936 (cond ((not charset)
5937 (mm-string-as-multibyte (mm-get-part handle)))
5938 ((eq charset 'gnus-decoded)
5939 (with-current-buffer (mm-handle-buffer handle)
5942 (mm-decode-string (mm-get-part handle) charset)))))
5943 (goto-char (point-max))))
5947 (narrow-to-region beg (point))
5948 (if (eq handle gnus-article-mime-handles)
5949 ;; The format=flowed case.
5950 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5951 ;; Don't count signature parts that are never displayed.
5952 ;; The part number should be re-calculated supposing this
5953 ;; might be a message/rfc822 part.
5955 (dolist (part gnus-article-mime-handles)
5956 (unless (or (stringp part)
5957 (equal (car (mm-handle-type part))
5958 "application/pgp-signature"))
5959 (push part handles)))
5961 nil (length (memq handle handles)) (length handles)
5962 (mm-handle-media-type handle)))))))))))
5964 (defun gnus-unbuttonized-mime-type-p (type)
5965 "Say whether TYPE is to be unbuttonized."
5966 (unless gnus-inhibit-mime-unbuttonizing
5968 (let ((types gnus-unbuttonized-mime-types))
5970 (when (string-match (pop types) type)
5971 (throw 'found t)))))
5973 (let ((types gnus-buttonized-mime-types))
5975 (when (string-match (pop types) type)
5976 (throw 'found t)))))))))
5978 (defun gnus-article-insert-newline ()
5979 "Insert a newline, but mark it as undeletable."
5980 (gnus-put-text-property
5981 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5983 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5984 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5987 handle (inhibit-read-only t) from props begend not-pref)
5988 (save-window-excursion
5991 (narrow-to-region (car ibegend)
5994 (goto-char (car ibegend))
5997 (delete-region (point-min) (point-max))
5998 (mm-remove-parts handles))
5999 (setq begend (list (point-marker)))
6001 (unless (setq not-pref (cadr (member preferred ihandles)))
6002 (setq not-pref (car ihandles)))
6005 (not (gnus-unbuttonized-mime-type-p
6006 "multipart/alternative")))
6007 (gnus-add-text-properties
6010 (insert (format "%d. " id))
6014 (unless ,(not ibegend)
6015 (setq gnus-article-mime-handle-alist
6016 ',gnus-article-mime-handle-alist))
6017 (gnus-mime-display-alternative
6018 ',ihandles ',not-pref ',begend ,id))
6019 keymap ,gnus-mime-button-map
6020 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6021 face ,gnus-article-button-face
6023 article-type multipart))
6024 (widget-convert-button 'link from (point)
6025 :action 'gnus-widget-press-button
6026 :button-keymap gnus-widget-button-keymap)
6028 (while (setq handle (pop handles))
6029 (gnus-add-text-properties
6032 (insert (format "(%c) %-18s"
6033 (if (equal handle preferred) ?* ? )
6034 (mm-handle-media-type handle)))
6038 (unless ,(not ibegend)
6039 (setq gnus-article-mime-handle-alist
6040 ',gnus-article-mime-handle-alist))
6041 (gnus-mime-display-alternative
6042 ',ihandles ',handle ',begend ,id))
6043 keymap ,gnus-mime-button-map
6044 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6045 face ,gnus-article-button-face
6048 (widget-convert-button 'link from (point)
6049 :action 'gnus-widget-press-button
6050 :button-keymap gnus-widget-button-keymap)
6054 (if (stringp (car preferred))
6055 (gnus-display-mime preferred)
6056 (let ((mail-parse-charset gnus-newsgroup-charset)
6057 (mail-parse-ignored-charsets
6058 (with-current-buffer gnus-summary-buffer
6059 gnus-newsgroup-ignored-charsets)))
6060 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6064 (narrow-to-region (car begend) (point-max))
6066 nil (length gnus-article-mime-handle-alist)
6067 (gnus-article-mime-total-parts)
6068 (mm-handle-media-type handle))))))
6069 (goto-char (point-max))
6070 (setcdr begend (point-marker)))))
6072 (goto-char point))))
6074 (defconst gnus-article-wash-status-strings
6075 (let ((alist '((cite "c" "Possible hidden citation text"
6076 " " "All citation text visible")
6077 (headers "h" "Hidden headers"
6078 " " "All headers visible.")
6079 (pgp "p" "Encrypted or signed message status hidden"
6080 " " "No hidden encryption nor digital signature status")
6081 (signature "s" "Signature has been hidden"
6082 " " "Signature is visible")
6083 (overstrike "o" "Overstrike (^H) characters applied"
6084 " " "No overstrike characters applied")
6085 (emphasis "e" "/*_Emphasis_*/ characters applied"
6086 " " "No /*_emphasis_*/ characters applied")))
6088 (dolist (entry alist result)
6089 (let ((key (nth 0 entry))
6090 (on (copy-sequence (nth 1 entry)))
6091 (on-help (nth 2 entry))
6092 (off (copy-sequence (nth 3 entry)))
6093 (off-help (nth 4 entry)))
6094 (put-text-property 0 1 'help-echo on-help on)
6095 (put-text-property 0 1 'help-echo off-help off)
6096 (push (list key on off) result))))
6097 "Alist of strings describing wash status in the mode line.
6098 Each entry has the form (KEY ON OF), where the KEY is a symbol
6099 representing the particular washing function, ON is the string to use
6100 in the article mode line when the washing function is active, and OFF
6101 is the string to use when it is inactive.")
6103 (defun gnus-article-wash-status-entry (key value)
6104 (let ((entry (assoc key gnus-article-wash-status-strings)))
6105 (if value (nth 1 entry) (nth 2 entry))))
6107 (defun gnus-article-wash-status ()
6108 "Return a string which display status of article washing."
6109 (with-current-buffer gnus-article-buffer
6110 (let ((cite (memq 'cite gnus-article-wash-types))
6111 (headers (memq 'headers gnus-article-wash-types))
6112 (boring (memq 'boring-headers gnus-article-wash-types))
6113 (pgp (memq 'pgp gnus-article-wash-types))
6114 (pem (memq 'pem gnus-article-wash-types))
6115 (signed (memq 'signed gnus-article-wash-types))
6116 (encrypted (memq 'encrypted gnus-article-wash-types))
6117 (signature (memq 'signature gnus-article-wash-types))
6118 (overstrike (memq 'overstrike gnus-article-wash-types))
6119 (emphasis (memq 'emphasis gnus-article-wash-types)))
6121 (gnus-article-wash-status-entry 'cite cite)
6122 (gnus-article-wash-status-entry 'headers (or headers boring))
6123 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6124 (gnus-article-wash-status-entry 'signature signature)
6125 (gnus-article-wash-status-entry 'overstrike overstrike)
6126 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6128 (defun gnus-add-wash-type (type)
6129 "Add a washing of TYPE to the current status."
6130 (add-to-list 'gnus-article-wash-types type))
6132 (defun gnus-delete-wash-type (type)
6133 "Add a washing of TYPE to the current status."
6134 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6136 (defun gnus-add-image (category image)
6137 "Add IMAGE of CATEGORY to the list of displayed images."
6138 (let ((entry (assq category gnus-article-image-alist)))
6140 (setq entry (list category))
6141 (push entry gnus-article-image-alist))
6142 (nconc entry (list image))))
6144 (defun gnus-delete-images (category)
6145 "Delete all images in CATEGORY."
6146 (let ((entry (assq category gnus-article-image-alist)))
6147 (dolist (image (cdr entry))
6148 (gnus-remove-image image category))
6149 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6150 (gnus-delete-wash-type category)))
6152 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6154 (defun gnus-article-maybe-hide-headers ()
6155 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6156 Provided for backwards compatibility."
6157 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6158 (not (with-current-buffer gnus-summary-buffer
6159 gnus-have-all-headers)))
6160 (not gnus-inhibit-hiding))
6161 (gnus-article-hide-headers)))
6165 (defun gnus-output-to-file (file-name)
6166 "Append the current article to a file named FILE-NAME.
6167 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6168 text and used as the value of the coding cookie which is added to the
6169 top of a file. Otherwise, this function saves a raw article without
6171 (let* ((artbuf (current-buffer))
6172 (file-name-coding-system nnmail-pathname-coding-system)
6173 (coding gnus-article-save-coding-system)
6174 (coding-system-for-read (if coding
6175 nil ;; Rely on the coding cookie.
6176 mm-text-coding-system))
6177 (coding-system-for-write (or coding
6178 mm-text-coding-system-for-write
6179 mm-text-coding-system))
6180 (exists (file-exists-p file-name)))
6183 (insert-file-contents file-name)
6184 (goto-char (point-min))
6185 ;; Remove the existing coding cookie.
6186 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6187 (delete-region (match-beginning 0) (match-end 0))))
6188 (goto-char (point-max))
6189 (insert-buffer-substring artbuf)
6190 ;; Append newline at end of the buffer as separator, and then
6192 (goto-char (point-max))
6195 ;; If the coding system is not suitable to encode the text,
6196 ;; ask a user for a proper one.
6197 (when (fboundp 'select-safe-coding-system)
6198 (setq coding (coding-system-base
6199 (save-window-excursion
6200 (select-safe-coding-system (point-min) (point-max)
6202 (setq coding-system-for-write
6203 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6205 (goto-char (point-min))
6206 ;; Add the coding cookie.
6207 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6208 coding-system-for-write)))
6211 (write-region (point-min) (point-max) file-name nil 'no-message)
6212 (message "Appended to %s" file-name))
6213 (write-region (point-min) (point-max) file-name))))
6216 (defun gnus-narrow-to-page (&optional arg)
6217 "Narrow the article buffer to a page.
6218 If given a numerical ARG, move forward ARG pages."
6220 (setq arg (if arg (prefix-numeric-value arg) 0))
6221 (with-current-buffer gnus-article-buffer
6223 ;; Remove any old next/prev buttons.
6224 (when (gnus-visual-p 'page-marker)
6225 (let ((inhibit-read-only t))
6226 (gnus-remove-text-with-property 'gnus-prev)
6227 (gnus-remove-text-with-property 'gnus-next)))
6229 (when (save-excursion
6231 (if (re-search-backward page-delimiter nil 'move (abs arg))
6233 (setq nd (match-beginning 0)
6235 (when (re-search-backward page-delimiter nil t)
6236 (setq st (match-end 0))))
6237 (when (re-search-forward page-delimiter nil t)
6238 (setq nd (match-beginning 0)
6241 (if (re-search-forward page-delimiter nil 'move arg)
6243 (setq st (match-end 0)
6245 (when (re-search-forward page-delimiter nil t)
6246 (setq nd (match-beginning 0))))
6247 (when (re-search-backward page-delimiter nil t)
6248 (setq st (match-end 0)
6251 (when (re-search-backward page-delimiter nil t)
6252 (goto-char (setq st (match-end 0))))
6253 (when (re-search-forward page-delimiter nil t)
6254 (setq nd (match-beginning 0)))
6256 (setq gnus-page-broken t)
6257 (when pt (goto-char pt))
6258 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6259 (when (gnus-visual-p 'page-marker)
6263 (gnus-insert-next-page-button))
6266 (gnus-insert-prev-page-button))))))))
6268 ;; Article mode commands
6270 (defun gnus-article-goto-next-page ()
6271 "Show the next page of the article."
6273 (when (gnus-article-next-page)
6274 (goto-char (point-min))
6275 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6278 (defun gnus-article-goto-prev-page ()
6279 "Show the previous page of the article."
6281 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6282 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6283 (gnus-article-prev-page nil)))
6285 ;; This is cleaner but currently breaks `gnus-pick-mode':
6287 ;; (defun gnus-article-goto-next-page ()
6288 ;; "Show the next page of the article."
6290 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6291 ;; (gnus-summary-next-page)))
6293 ;; (defun gnus-article-goto-prev-page ()
6294 ;; "Show the next page of the article."
6296 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6297 ;; (gnus-summary-prev-page)))
6299 (defun gnus-article-next-page (&optional lines)
6300 "Show the next page of the current article.
6301 If end of article, return non-nil. Otherwise return nil.
6302 Argument LINES specifies lines to be scrolled up."
6304 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6305 (if (and (not (and gnus-article-over-scroll
6306 (> (count-lines (window-start) (point-max))
6307 (if (featurep 'xemacs)
6308 (or lines (1- (window-height)))
6309 (+ (or lines (1- (window-height))) scroll-margin)))))
6312 (and (pos-visible-in-window-p) ;Not continuation line.
6313 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
6314 ;; Nothing in this page.
6315 (if (or (not gnus-page-broken)
6320 (eobp)))) ;Real end-of-buffer?
6322 (when gnus-article-over-scroll
6323 (gnus-article-next-page-1 lines))
6325 (gnus-narrow-to-page 1) ;Go to next page.
6327 ;; More in this page.
6328 (gnus-article-next-page-1 lines)
6331 (defun gnus-article-beginning-of-window ()
6332 "Move point to the beginning of the window.
6333 In Emacs, the point is placed at the line number which `scroll-margin'
6335 (if (featurep 'xemacs)
6336 (move-to-window-line 0)
6337 ;; There is an obscure bug in Emacs that makes it impossible to
6338 ;; scroll past big pictures in the article buffer. Try to fix
6339 ;; this by adding a sanity check by counting the lines visible.
6340 (when (> (count-lines (window-start) (window-end)) 30)
6341 (move-to-window-line
6342 (min (max 0 scroll-margin)
6343 (max 1 (- (window-height)
6344 (if mode-line-format 1 0)
6345 (if header-line-format 1 0)
6348 (defun gnus-article-next-page-1 (lines)
6350 (let ((scroll-in-place nil))
6353 ;; Long lines may cause an end-of-buffer error.
6354 (goto-char (point-max))))
6355 (gnus-article-beginning-of-window))
6357 (defun gnus-article-prev-page (&optional lines)
6358 "Show previous page of current article.
6359 Argument LINES specifies lines to be scrolled down."
6361 (move-to-window-line 0)
6362 (if (and gnus-page-broken
6364 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6366 (gnus-narrow-to-page -1) ;Go to previous page.
6367 (goto-char (point-max))
6368 (recenter (if gnus-article-over-scroll
6370 (max (if (featurep 'xemacs)
6372 (+ lines scroll-margin))
6374 (- (window-height) 2))
6378 (let ((scroll-in-place nil))
6379 (scroll-down lines))
6380 (beginning-of-buffer
6381 (goto-char (point-min))))
6382 (gnus-article-beginning-of-window))))
6384 (defun gnus-article-only-boring-p ()
6385 "Decide whether there is only boring text remaining in the article.
6386 Something \"interesting\" is a word of at least two letters that does
6387 not have a face in `gnus-article-boring-faces'."
6388 (when (and gnus-article-skip-boring
6389 (boundp 'gnus-article-boring-faces)
6390 (symbol-value 'gnus-article-boring-faces))
6392 (let ((inhibit-point-motion-hooks t))
6394 (while (re-search-forward "\\b\\w\\w" nil t)
6396 (when (not (gnus-intersection
6397 (gnus-faces-at (point))
6398 (symbol-value 'gnus-article-boring-faces)))
6399 (throw 'only-boring nil)))
6400 (throw 'only-boring t))))))
6402 (defun gnus-article-refer-article ()
6403 "Read article specified by message-id around point."
6406 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6407 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6408 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6409 (let ((msg-id (concat "<" (match-string 0) ">")))
6410 (set-buffer gnus-summary-buffer)
6411 (gnus-summary-refer-article msg-id))
6412 (error "No references around point"))))
6414 (defun gnus-article-show-summary ()
6415 "Reconfigure windows to show summary buffer."
6417 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6418 (error "There is no summary buffer for this article buffer")
6419 (gnus-article-set-globals)
6420 (gnus-configure-windows 'article)
6421 (gnus-summary-goto-subject gnus-current-article)
6422 (gnus-summary-position-point)))
6424 (defun gnus-article-describe-briefly ()
6425 "Describe article mode commands briefly."
6427 (gnus-message 6 "%s" (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
6429 (defun gnus-article-check-buffer ()
6430 "Beep if not in an article buffer."
6431 (unless (equal major-mode 'gnus-article-mode)
6432 (error "Command invoked outside of a Gnus article buffer")))
6434 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6435 "Read a summary buffer key sequence and execute it from the article buffer."
6437 (gnus-article-check-buffer)
6439 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6440 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6441 "=" "^" "\M-^" "|"))
6443 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6444 "An" "Ap" [?A (meta return)] [?A delete]))
6448 '("n" "Gn" "p" "Gp"))
6450 (with-current-buffer gnus-article-current-summary
6451 (let (gnus-pick-mode)
6452 (setq unread-command-events (nconc unread-command-events
6453 (list (or key last-command-event)))
6454 keys (if (featurep 'xemacs)
6455 (events-to-keys (read-key-sequence nil t))
6456 (read-key-sequence nil t)))))
6461 ((eq (aref keys (1- (length keys))) ?\C-h)
6462 (gnus-article-describe-bindings (substring keys 0 -1)))
6463 ((or (member keys nosaves)
6464 (member keys nosave-but-article)
6465 (member keys nosave-in-article))
6467 (save-window-excursion
6468 (pop-to-buffer gnus-article-current-summary)
6469 ;; We disable the pick minor mode commands.
6470 (let (gnus-pick-mode)
6471 (setq func (key-binding keys t))))
6475 (unless (member keys nosave-in-article)
6476 (set-buffer gnus-article-current-summary))
6477 (call-interactively func)
6478 (setq new-sum-point (point)))
6479 (when (member keys nosave-but-article)
6480 (pop-to-buffer gnus-article-buffer))))
6482 ;; These commands should restore window configuration.
6483 (let ((obuf (current-buffer))
6484 (owin (current-window-configuration))
6485 win func in-buffer selected new-sum-start new-sum-hscroll err)
6486 (cond (not-restore-window
6487 (pop-to-buffer gnus-article-current-summary)
6488 (setq win (selected-window)))
6489 ((setq win (get-buffer-window gnus-article-current-summary))
6490 (select-window win))
6492 (let ((summary-buffer gnus-article-current-summary))
6493 (gnus-configure-windows 'article)
6494 (unless (setq win (get-buffer-window summary-buffer 'visible))
6495 (let ((gnus-buffer-configuration
6496 '((article ((vertical 1.0
6497 (summary 0.25 point)
6499 (gnus-configure-windows 'article))
6500 (setq win (get-buffer-window summary-buffer 'visible)))
6501 (gnus-select-frame-set-input-focus (window-frame win))
6502 (select-window win))))
6503 (setq in-buffer (current-buffer))
6504 ;; We disable the pick minor mode commands.
6505 (if (and (setq func (let (gnus-pick-mode)
6506 (key-binding keys t)))
6508 (condition-case code
6510 (call-interactively func)
6516 (when (eq win (selected-window))
6517 (setq new-sum-point (point)
6518 new-sum-start (window-start win)
6519 new-sum-hscroll (window-hscroll win)))
6520 (when (or (eq in-buffer (current-buffer))
6521 (when (eq obuf (current-buffer))
6522 (set-buffer in-buffer)
6524 (setq selected (gnus-summary-select-article))
6526 (unless not-restore-window
6527 (set-window-configuration owin))
6528 (when (and (eq selected 'old)
6530 (set-window-start (get-buffer-window (current-buffer))
6532 (set-window-point (get-buffer-window (current-buffer))
6533 (if (article-goto-body)
6536 (when (and (not not-restore-window)
6539 (with-current-buffer (window-buffer win)
6540 (eq major-mode 'gnus-summary-mode)))
6541 (set-window-point win new-sum-point)
6542 (set-window-start win new-sum-start)
6543 (set-window-hscroll win new-sum-hscroll))))
6544 (set-window-configuration owin)
6546 (signal (car err) (cdr err))
6549 (defun gnus-article-read-summary-send-keys ()
6551 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6552 (gnus-article-read-summary-keys)))
6554 (defun gnus-article-describe-key (key)
6555 "Display documentation of the function invoked by KEY.
6556 KEY is a string or a vector."
6557 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6558 (read-key-sequence "Describe key: "))))
6559 (gnus-article-check-buffer)
6560 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6561 gnus-article-read-summary-send-keys))
6562 (with-current-buffer gnus-article-current-summary
6563 (setq unread-command-events
6564 (if (featurep 'xemacs)
6566 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6567 (list 'meta (- x 128))
6570 (let ((cursor-in-echo-area t)
6572 (describe-key (read-key-sequence nil t))))
6573 (describe-key key)))
6575 (defun gnus-article-describe-key-briefly (key &optional insert)
6576 "Display documentation of the function invoked by KEY.
6577 KEY is a string or a vector."
6578 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6579 (read-key-sequence "Describe key: "))
6580 current-prefix-arg))
6581 (gnus-article-check-buffer)
6582 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6583 gnus-article-read-summary-send-keys))
6584 (with-current-buffer gnus-article-current-summary
6585 (setq unread-command-events
6586 (if (featurep 'xemacs)
6588 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6589 (list 'meta (- x 128))
6592 (let ((cursor-in-echo-area t)
6594 (describe-key-briefly (read-key-sequence nil t) insert)))
6595 (describe-key-briefly key insert)))
6597 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6598 (defvar gnus-agent-summary-mode)
6599 (defvar gnus-draft-mode)
6600 ;; Calling help-buffer will autoload help-mode.
6601 (defvar help-xref-stack-item)
6602 ;; Emacs 22 doesn't load it in the batch mode.
6604 (autoload 'help-buffer "help-mode"))
6606 (defun gnus-article-describe-bindings (&optional prefix)
6607 "Show a list of all defined keys, and their definitions.
6608 The optional argument PREFIX, if non-nil, should be a key sequence;
6609 then we display only bindings that start with that prefix."
6611 (gnus-article-check-buffer)
6612 (let ((keymap (copy-keymap gnus-article-mode-map))
6613 (map (copy-keymap gnus-article-send-map))
6614 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6616 (define-key keymap "S" map)
6617 (define-key map [t] nil)
6618 (with-current-buffer gnus-article-current-summary
6621 (if (setq parent (keymap-parent gnus-article-mode-map))
6623 (setq parent (copy-keymap parent))
6624 (set-keymap-parent parent (current-local-map)))
6625 (current-local-map)))
6626 (set-keymap-parent map (key-binding "S"))
6627 (let (key def gnus-pick-mode)
6629 (setq key (pop sumkeys))
6630 (cond ((and (vectorp key) (= (length key) 1)
6631 (consp (setq def (aref key 0)))
6632 (numberp (car def)) (numberp (cdr def)))
6633 (when (< (max (car def) (cdr def)) 128)
6637 (nreverse (gnus-uncompress-range def)))
6639 ((setq def (key-binding key))
6640 (unless (eq def 'undefined)
6641 (define-key keymap key def))))))
6642 (when (boundp 'gnus-agent-summary-mode)
6643 (setq agent gnus-agent-summary-mode))
6644 (when (boundp 'gnus-draft-mode)
6645 (setq draft gnus-draft-mode)))
6647 (use-local-map keymap)
6648 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6649 (set (make-local-variable 'gnus-draft-mode) draft)
6650 (describe-bindings prefix))
6651 (let ((item `((lambda (prefix)
6652 (with-current-buffer ,(current-buffer)
6653 (gnus-article-describe-bindings prefix)))
6655 (with-current-buffer (let (help-xref-following) (help-buffer))
6656 (setq help-xref-stack-item item)))))
6658 (defun gnus-article-reply-with-original (&optional wide)
6659 "Start composing a reply mail to the current message.
6660 The text in the region will be yanked. If the region isn't active,
6661 the entire article will be yanked."
6663 (let ((article (cdr gnus-article-current))
6665 (if (not (gnus-region-active-p))
6666 (with-current-buffer gnus-summary-buffer
6667 (gnus-summary-reply (list (list article)) wide))
6668 (setq contents (buffer-substring (point) (mark t)))
6669 ;; Deactivate active regions.
6670 (when (and (boundp 'transient-mark-mode)
6671 transient-mark-mode)
6672 (setq mark-active nil))
6673 (with-current-buffer gnus-summary-buffer
6675 (list (list article contents)) wide)))))
6677 (defun gnus-article-wide-reply-with-original ()
6678 "Start composing a wide reply mail to the current message.
6679 The text in the region will be yanked. If the region isn't active,
6680 the entire article will be yanked."
6682 (gnus-article-reply-with-original t))
6684 (defun gnus-article-followup-with-original ()
6685 "Compose a followup to the current article.
6686 The text in the region will be yanked. If the region isn't active,
6687 the entire article will be yanked."
6689 (let ((article (cdr gnus-article-current))
6691 (if (not (gnus-region-active-p))
6692 (with-current-buffer gnus-summary-buffer
6693 (gnus-summary-followup (list (list article))))
6694 (setq contents (buffer-substring (point) (mark t)))
6695 ;; Deactivate active regions.
6696 (when (and (boundp 'transient-mark-mode)
6697 transient-mark-mode)
6698 (setq mark-active nil))
6699 (with-current-buffer gnus-summary-buffer
6700 (gnus-summary-followup
6701 (list (list article contents)))))))
6703 (defun gnus-article-hide (&optional arg force)
6704 "Hide all the gruft in the current article.
6705 This means that signatures, cited text and (some) headers will be
6707 If given a prefix, show the hidden text instead."
6708 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6709 (gnus-article-hide-headers arg)
6710 (gnus-article-hide-list-identifiers arg)
6711 (gnus-article-hide-citation-maybe arg force)
6712 (gnus-article-hide-signature arg))
6714 (defun gnus-article-maybe-highlight ()
6715 "Do some article highlighting if article highlighting is requested."
6716 (when (gnus-visual-p 'article-highlight 'highlight)
6717 (gnus-article-highlight-some)))
6719 (defun gnus-check-group-server ()
6720 ;; Make sure the connection to the server is alive.
6721 (unless (gnus-server-opened
6722 (gnus-find-method-for-group gnus-newsgroup-name))
6723 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6724 (gnus-request-group gnus-newsgroup-name t)))
6727 (autoload 'nneething-get-file-name "nneething"))
6729 (defun gnus-request-article-this-buffer (article group)
6730 "Get an article and insert it into this buffer."
6731 (let (do-update-line sparse-header)
6735 (gnus-kill-all-overlays)
6736 (setq group (or group gnus-newsgroup-name))
6738 ;; Using `gnus-request-article' directly will insert the article into
6739 ;; `nntp-server-buffer' - so we'll save some time by not having to
6740 ;; copy it from the server buffer into the article buffer.
6742 ;; We only request an article by message-id when we do not have the
6743 ;; headers for it, so we'll have to get those.
6744 (when (stringp article)
6745 (gnus-read-header article))
6747 ;; If the article number is negative, that means that this article
6748 ;; doesn't belong in this newsgroup (possibly), so we find its
6749 ;; message-id and request it by id instead of number.
6750 (when (and (numberp article)
6752 (get-buffer gnus-summary-buffer)
6753 (gnus-buffer-exists-p gnus-summary-buffer))
6754 (with-current-buffer gnus-summary-buffer
6755 (let ((header (gnus-summary-article-header article)))
6758 ((memq article gnus-newsgroup-sparse)
6759 ;; This is a sparse gap article.
6760 (setq do-update-line article)
6761 (setq article (mail-header-id header))
6762 (setq sparse-header (gnus-read-header article))
6763 (setq gnus-newsgroup-sparse
6764 (delq article gnus-newsgroup-sparse)))
6766 ;; It's a real article.
6767 (setq article (mail-header-id header)))
6769 ;; It is an extracted pseudo-article.
6770 (setq article 'pseudo)
6771 (gnus-request-pseudo-article header))))
6773 (let ((method (gnus-find-method-for-group
6774 gnus-newsgroup-name)))
6775 (when (and (eq (car method) 'nneething)
6777 (let ((dir (nneething-get-file-name
6778 (mail-header-id header))))
6779 (when (and (stringp dir)
6780 (file-directory-p dir))
6781 (setq article 'nneething)
6782 (gnus-group-enter-directory dir))))))))
6785 ;; Refuse to select canceled articles.
6786 ((and (numberp article)
6788 (get-buffer gnus-summary-buffer)
6789 (gnus-buffer-exists-p gnus-summary-buffer)
6790 (eq (cdr (with-current-buffer gnus-summary-buffer
6791 (assq article gnus-newsgroup-reads)))
6792 gnus-canceled-mark))
6794 ;; We first check `gnus-original-article-buffer'.
6795 ((and (get-buffer gnus-original-article-buffer)
6797 (with-current-buffer gnus-original-article-buffer
6798 (and (equal (car gnus-original-article) group)
6799 (eq (cdr gnus-original-article) article))))
6800 ;; `insert-buffer-substring' would incorrectly use the
6801 ;; equivalent of string-make-multibyte which amount to decoding
6802 ;; with locale-coding-system, causing failure of
6803 ;; subsequent decoding.
6804 (insert (mm-string-to-multibyte
6805 (with-current-buffer gnus-original-article-buffer
6806 (buffer-substring (point-min) (point-max)))))
6808 ;; Check the backlog.
6809 ((and gnus-keep-backlog
6810 (gnus-backlog-request-article group article (current-buffer)))
6812 ;; Check asynchronous pre-fetch.
6813 ((gnus-async-request-fetched-article group article (current-buffer))
6814 (gnus-async-prefetch-next group article gnus-summary-buffer)
6815 (when (and (numberp article) gnus-keep-backlog)
6816 (gnus-backlog-enter-article group article (current-buffer)))
6819 ((and gnus-use-cache
6821 (gnus-cache-request-article article group))
6823 ;; Check the agent cache.
6824 ((gnus-agent-request-article article group)
6826 ;; Get the article and put into the article buffer.
6827 ((or (stringp article)
6829 (let ((gnus-override-method gnus-override-method)
6830 (methods (and (stringp article)
6831 gnus-refer-article-method))
6832 (backend (car (gnus-find-method-for-group
6833 gnus-newsgroup-name)))
6835 (inhibit-read-only t))
6836 (if (or (not (listp methods))
6837 (and (symbolp (car methods))
6838 (assq (car methods) nnoo-definition-alist)))
6839 (setq methods (list methods)))
6840 (when (and (null gnus-override-method)
6842 (setq gnus-override-method (pop methods)))
6844 (when (eq gnus-override-method 'current)
6845 (setq gnus-override-method
6846 (with-current-buffer gnus-summary-buffer
6847 gnus-current-select-method)))
6849 (gnus-kill-all-overlays)
6850 (let ((gnus-newsgroup-name group))
6851 (gnus-check-group-server))
6853 ((gnus-request-article article group (current-buffer))
6854 (when (numberp article)
6855 (gnus-async-prefetch-next group article
6856 gnus-summary-buffer)
6857 (when gnus-keep-backlog
6858 (gnus-backlog-enter-article
6859 group article (current-buffer))))
6860 (setq result 'article))
6862 (setq gnus-override-method (pop methods)))
6863 ((not (string-match "^400 "
6864 (nnheader-get-report backend)))
6865 ;; If we get 400 server disconnect, reconnect and
6866 ;; retry; otherwise, assume the article has expired.
6867 (setq result 'done))))
6868 (and (eq result 'article) 'article)))
6872 ;; Associate this article with the current summary buffer.
6873 (setq gnus-article-current-summary gnus-summary-buffer)
6875 ;; Take the article from the original article buffer
6876 ;; and place it in the buffer it's supposed to be in.
6877 (when (and (get-buffer gnus-article-buffer)
6878 (equal (buffer-name (current-buffer))
6879 (buffer-name (get-buffer gnus-article-buffer))))
6881 (if (get-buffer gnus-original-article-buffer)
6882 (set-buffer gnus-original-article-buffer)
6883 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6884 (buffer-disable-undo)
6885 (setq major-mode 'gnus-original-article-mode)
6886 (setq buffer-read-only t))
6887 (let ((inhibit-read-only t))
6889 (insert-buffer-substring gnus-article-buffer))
6890 (setq gnus-original-article (cons group article)))
6893 (run-hooks 'gnus-article-decode-hook)
6894 ;; Mark article as decoded or not.
6895 (setq gnus-article-decoded-p gnus-article-decode-hook))
6897 ;; Update sparse articles.
6898 (when (and do-update-line
6899 (or (numberp article)
6901 (let ((buf (current-buffer)))
6902 (set-buffer gnus-summary-buffer)
6903 (gnus-summary-update-article do-update-line sparse-header)
6904 (gnus-summary-goto-subject do-update-line nil t)
6905 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6907 (set-buffer buf))))))
6913 (defcustom gnus-article-edit-mode-hook nil
6914 "Hook run in article edit mode buffers."
6915 :group 'gnus-article-various
6918 (defvar gnus-article-edit-done-function nil)
6920 (defvar gnus-article-edit-mode-map nil)
6922 ;; Should we be using derived.el for this?
6923 (unless gnus-article-edit-mode-map
6924 (setq gnus-article-edit-mode-map (make-keymap))
6925 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6927 (gnus-define-keys gnus-article-edit-mode-map
6928 "\C-c?" describe-mode
6929 "\C-c\C-c" gnus-article-edit-done
6930 "\C-c\C-k" gnus-article-edit-exit
6931 "\C-c\C-f\C-t" message-goto-to
6932 "\C-c\C-f\C-o" message-goto-from
6933 "\C-c\C-f\C-b" message-goto-bcc
6934 ;;"\C-c\C-f\C-w" message-goto-fcc
6935 "\C-c\C-f\C-c" message-goto-cc
6936 "\C-c\C-f\C-s" message-goto-subject
6937 "\C-c\C-f\C-r" message-goto-reply-to
6938 "\C-c\C-f\C-n" message-goto-newsgroups
6939 "\C-c\C-f\C-d" message-goto-distribution
6940 "\C-c\C-f\C-f" message-goto-followup-to
6941 "\C-c\C-f\C-m" message-goto-mail-followup-to
6942 "\C-c\C-f\C-k" message-goto-keywords
6943 "\C-c\C-f\C-u" message-goto-summary
6944 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6945 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6946 "\C-c\C-b" message-goto-body
6947 "\C-c\C-i" message-goto-signature
6949 "\C-c\C-t" message-insert-to
6950 "\C-c\C-n" message-insert-newsgroups
6951 "\C-c\C-o" message-sort-headers
6952 "\C-c\C-e" message-elide-region
6953 "\C-c\C-v" message-delete-not-region
6954 "\C-c\C-z" message-kill-to-signature
6955 "\M-\r" message-newline-and-reformat
6956 "\C-c\C-a" mml-attach-file
6957 "\C-a" message-beginning-of-line
6959 "\M-;" comment-region)
6961 (gnus-define-keys (gnus-article-edit-wash-map
6962 "\C-c\C-w" gnus-article-edit-mode-map)
6963 "f" gnus-article-edit-full-stops))
6966 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6968 ["Fetch To" message-insert-to t]
6969 ["Fetch Newsgroups" message-insert-newsgroups t]
6971 ["To" message-goto-to t]
6972 ["From" message-goto-from t]
6973 ["Subject" message-goto-subject t]
6974 ["Cc" message-goto-cc t]
6975 ["Reply-To" message-goto-reply-to t]
6976 ["Summary" message-goto-summary t]
6977 ["Keywords" message-goto-keywords t]
6978 ["Newsgroups" message-goto-newsgroups t]
6979 ["Followup-To" message-goto-followup-to t]
6980 ["Mail-Followup-To" message-goto-mail-followup-to t]
6981 ["Distribution" message-goto-distribution t]
6982 ["Body" message-goto-body t]
6983 ["Signature" message-goto-signature t]))
6985 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6986 "Major mode for editing articles.
6987 This is an extended text-mode.
6989 \\{gnus-article-edit-mode-map}"
6990 (make-local-variable 'gnus-article-edit-done-function)
6991 (make-local-variable 'gnus-prev-winconf)
6992 (set (make-local-variable 'font-lock-defaults)
6993 '(message-font-lock-keywords t))
6994 (set (make-local-variable 'mail-header-separator) "")
6995 (set (make-local-variable 'gnus-article-edit-mode) t)
6996 (easy-menu-add message-mode-field-menu message-mode-map)
6998 (setq buffer-read-only nil)
6999 (buffer-enable-undo)
7002 (defun gnus-article-edit (&optional force)
7003 "Edit the current article.
7004 This will have permanent effect only in mail groups.
7005 If FORCE is non-nil, allow editing of articles even in read-only
7008 (when (and (not force)
7009 (gnus-group-read-only-p))
7010 (error "The current newsgroup does not support article editing"))
7011 (gnus-article-date-original)
7012 (gnus-article-edit-article
7014 `(lambda (no-highlight)
7016 (gnus-summary-edit-article-done
7017 ,(or (mail-header-references gnus-current-headers) "")
7018 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7020 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7021 "Start editing the contents of the current article buffer."
7022 (let ((winconf (current-window-configuration)))
7023 (set-buffer gnus-article-buffer)
7024 (let ((message-auto-save-directory
7025 ;; Don't associate the article buffer with a draft file.
7027 (gnus-article-edit-mode))
7028 (funcall start-func)
7029 (set-buffer-modified-p nil)
7030 (gnus-configure-windows 'edit-article)
7031 (setq gnus-article-edit-done-function exit-func)
7032 (setq gnus-prev-winconf winconf)
7034 (gnus-message 6 "C-c C-c to end edits"))))
7036 (defun gnus-article-edit-done (&optional arg)
7037 "Update the article edits and exit."
7039 (let ((func gnus-article-edit-done-function)
7040 (buf (current-buffer))
7041 (start (window-start))
7043 (winconf gnus-prev-winconf))
7044 (widen) ;; Widen it in case that users narrowed the buffer.
7047 ;; The cache and backlog have to be flushed somewhat.
7048 (when gnus-keep-backlog
7049 (gnus-backlog-remove-article
7050 (car gnus-article-current) (cdr gnus-article-current)))
7051 ;; Flush original article as well.
7052 (gnus-flush-original-article-buffer)
7053 (when gnus-use-cache
7054 (gnus-cache-update-article
7055 (car gnus-article-current) (cdr gnus-article-current)))
7056 ;; We remove all text props from the article buffer.
7057 (kill-all-local-variables)
7058 (set-text-properties (point-min) (point-max) nil)
7060 (set-window-configuration winconf)
7062 (set-window-start (get-buffer-window buf) start)
7063 (set-window-point (get-buffer-window buf) (point)))
7064 (gnus-summary-show-article))
7066 (defun gnus-flush-original-article-buffer ()
7067 (when (get-buffer gnus-original-article-buffer)
7068 (with-current-buffer gnus-original-article-buffer
7069 (setq gnus-original-article nil))))
7071 (defun gnus-article-edit-exit ()
7072 "Exit the article editing without updating."
7074 (when (or (not (buffer-modified-p))
7075 (yes-or-no-p "Article modified; kill anyway? "))
7076 (let ((curbuf (current-buffer))
7078 (window-start (window-start)))
7080 (if (gnus-buffer-live-p gnus-original-article-buffer)
7081 (insert-buffer-substring gnus-original-article-buffer))
7082 (let ((winconf gnus-prev-winconf))
7083 (kill-all-local-variables)
7085 (set-window-configuration winconf)
7086 ;; Tippy-toe some to make sure that point remains where it was.
7087 (save-current-buffer
7089 (set-window-start (get-buffer-window (current-buffer)) window-start)
7091 (gnus-summary-show-article)))
7093 (defun gnus-article-edit-full-stops ()
7094 "Interactively repair spacing at end of sentences."
7097 (goto-char (point-min))
7098 (search-forward-regexp "^$" nil t)
7099 (let ((case-fold-search nil))
7100 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7103 ;;; Article highlights
7106 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7108 ;;; Internal Variables:
7110 (defcustom gnus-button-url-regexp
7112 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7113 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7114 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7115 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7116 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7120 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7121 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7122 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7124 "[" chars punct "]+" "[" chars "]"
7126 (concat ;; XEmacs 21.4 doesn't support POSIX.
7127 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7128 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7130 "Regular expression that matches URLs."
7131 :group 'gnus-article-buttons
7134 (defcustom gnus-button-valid-fqdn-regexp
7135 message-valid-fqdn-regexp
7136 "Regular expression that matches a valid FQDN."
7138 :group 'gnus-article-buttons
7141 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7142 (defcustom gnus-button-valid-localpart-regexp
7143 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7144 "Regular expression that matches a localpart of mail addresses or MIDs."
7146 :group 'gnus-article-buttons
7149 (defcustom gnus-button-man-handler 'manual-entry
7150 "Function to use for displaying man pages.
7151 The function must take at least one argument with a string naming the
7154 :type '(choice (function-item :tag "Man" manual-entry)
7155 (function-item :tag "Woman" woman)
7156 (function :tag "Other"))
7157 :group 'gnus-article-buttons)
7159 (defcustom gnus-ctan-url "http://tug.ctan.org/tex-archive/"
7160 "Top directory of a CTAN \(Comprehensive TeX Archive Network\) archive.
7161 If the default site is too slow, try to find a CTAN mirror, see
7162 <URL:http://tug.ctan.org/tex-archive/CTAN.sites?action=/index.html>. See also
7163 the variable `gnus-button-handle-ctan'."
7165 :group 'gnus-article-buttons
7166 :link '(custom-manual "(gnus)Group Parameters")
7167 :type '(choice (const "http://www.tex.ac.uk/tex-archive/")
7168 (const "http://tug.ctan.org/tex-archive/")
7169 (const "http://www.dante.de/CTAN/")
7170 (string :tag "Other")))
7172 (defcustom gnus-button-ctan-handler 'browse-url
7173 "Function to use for displaying CTAN links.
7174 The function must take one argument, the string naming the URL."
7176 :type '(choice (function-item :tag "Browse Url" browse-url)
7177 (function :tag "Other"))
7178 :group 'gnus-article-buttons)
7180 (defcustom gnus-button-handle-ctan-bogus-regexp "^/?tex-archive/\\|^/"
7181 "Bogus strings removed from CTAN URLs."
7183 :group 'gnus-article-buttons
7184 :type '(choice (const "^/?tex-archive/\\|/")
7185 (regexp :tag "Other")))
7187 (defcustom gnus-button-ctan-directory-regexp
7189 (list "archive-tools" "biblio" "bibliography" "digests" "documentation"
7190 "dviware" "fonts" "graphics" "help" "indexing" "info" "language"
7191 "languages" "macros" "nonfree" "obsolete" "support" "systems"
7192 "tds" "tools" "usergrps" "web") t)
7193 "Regular expression for ctan directories.
7194 It should match all directories in the top level of `gnus-ctan-url'."
7196 :group 'gnus-article-buttons
7199 (defcustom gnus-button-mid-or-mail-regexp
7200 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7201 gnus-button-valid-fqdn-regexp
7203 "Regular expression that matches a message ID or a mail address."
7205 :group 'gnus-article-buttons
7208 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7209 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7210 Strings like this can be either a message ID or a mail address. If it is one
7211 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7212 message ID or a mail address, respectively. If this variable is set to the
7213 symbol `ask', always query the user what do do. If it is a function, this
7214 function will be called with the string as its only argument. The function
7215 must return `mid', `mail', `invalid' or `ask'."
7217 :group 'gnus-article-buttons
7218 :type '(choice (function-item :tag "Heuristic function"
7219 gnus-button-mid-or-mail-heuristic)
7224 (defcustom gnus-button-mid-or-mail-heuristic-alist
7225 '((-10.0 . ".+\\$.+@")
7228 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7229 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7230 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7231 (-1.0 . "^[^a-z]+@")
7233 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7234 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7235 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7236 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7239 (-1.0 . "^[0-9][0-9]")
7241 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7242 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7243 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7244 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7246 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7247 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7250 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7252 ;; compensation for TDMA dated mail addresses:
7253 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7255 (-20.0 . "\\.fsf@") ;; Gnus
7258 (-20.0 . "^alpine\\.")
7259 (-20.0 . "_-_") ;; Subject change in thread
7261 (-20.0 . "\\.ln@") ;; leafnode
7262 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7263 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7265 ;; (5.0 . "") ;; $local_part_len <= 7
7266 (10.0 . "^[^0-9]+@")
7267 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7268 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7271 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7273 (0.5 . "^[A-Z][a-z]")
7274 (0.5 . "^[A-Z][a-z][a-z]")
7275 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7276 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7277 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7279 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7280 address. The REGEXP is processed with `case-fold-search' set to nil."
7282 :group 'gnus-article-buttons
7283 :type '(repeat (cons (number :tag "Rate")
7284 (regexp :tag "Regexp"))))
7286 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7287 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7288 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7289 address, `ask' if unsure and `invalid' if the string is invalid."
7290 (let ((case-fold-search nil)
7291 (list gnus-button-mid-or-mail-heuristic-alist)
7292 (result 0) rate regexp lpartlen elem)
7294 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7295 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7296 ;; Certain special cases...
7299 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7300 "^[0-9]+\\.[0-9]+@compuserve\\|"
7301 "@public\\.gmane\\.org")
7303 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7304 (setq result 'mail))
7305 (when (string-match "@.*@\\| " mid-or-mail)
7306 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7307 (setq result 'invalid))
7308 ;; Nothing more to do, if result is not a number here...
7309 (when (numberp result)
7311 (setq elem (car list)
7315 (when (string-match regexp mid-or-mail)
7316 (setq result (+ result rate))
7318 9 "`%s' matched `%s', rate `%s', result `%s'."
7319 mid-or-mail regexp rate result)))
7320 (when (<= lpartlen 7)
7321 (setq result (+ result 5.0))
7322 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7323 mid-or-mail result))
7324 (when (>= lpartlen 12)
7325 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7327 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7328 ;; Long local part should contain realname if e-mail address,
7329 ;; too many digits: message-id.
7330 ;; $score -= 5.0 + 0.1 * $local_part_len;
7331 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7332 (setq result (+ result rate))
7334 9 "Many digits in `%s', rate `%s', result `%s'."
7335 mid-or-mail rate result))
7336 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7338 ;; Too few vowels [^aeiouy]{4,}.*\@
7339 (setq result (+ result -5.0))
7341 9 "Few vowels in `%s', rate `%s', result `%s'."
7342 mid-or-mail -5.0 result))
7344 (setq result (+ result 5.0))
7346 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7347 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7348 ;; Maybe we should make this a customizable alist: (condition . 'result)
7350 ((symbolp result) result)
7351 ;; Now convert number into proper results:
7352 ((< result -10.0) 'mid)
7353 ((> result 10.0) 'mail)
7356 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7357 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7358 (url-mid (concat "news" ":" mid-or-mail))
7359 (url-mailto (concat "mailto" ":" mid-or-mail)))
7360 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7361 (when (fboundp pref)
7363 ;; get rid of surrounding angles...
7365 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7366 (if (or (eq 'mid guessed) (eq 'mail guessed))
7370 (save-window-excursion
7371 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7374 (cond ((eq pref 'mid)
7375 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7376 (gnus-button-handle-news url-mid))
7378 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7379 (gnus-url-mailto url-mailto))
7380 (t (gnus-message 3 "Invalid string.")))))
7382 (defun gnus-button-handle-custom (fun arg)
7383 "Call function FUN on argument ARG.
7384 Both FUN and ARG are supposed to be strings. ARG will be passed
7385 as a symbol to FUN."
7386 (funcall (intern fun)
7387 (if (string-match "^customize-apropos" fun)
7391 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7393 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7396 (defun gnus-button-handle-describe-function (url)
7397 "Call `describe-function' when pushing the corresponding URL button."
7400 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7402 (defun gnus-button-handle-describe-variable (url)
7403 "Call `describe-variable' when pushing the corresponding URL button."
7406 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7408 (defun gnus-button-handle-symbol (url)
7409 "Display help on variable or function.
7410 Calls `describe-variable' or `describe-function'."
7411 (let ((sym (intern url)))
7413 ((fboundp sym) (describe-function sym))
7414 ((boundp sym) (describe-variable sym))
7415 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7417 (defun gnus-button-handle-describe-key (url)
7418 "Call `describe-key' when pushing the corresponding URL button."
7420 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7421 (keys (ignore-errors (eval `(kbd ,key-string)))))
7424 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7426 (defun gnus-button-handle-apropos (url)
7427 "Call `apropos' when pushing the corresponding URL button."
7428 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7430 (defun gnus-button-handle-apropos-command (url)
7431 "Call `apropos' when pushing the corresponding URL button."
7433 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7435 (defun gnus-button-handle-apropos-variable (url)
7436 "Call `apropos' when pushing the corresponding URL button."
7438 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7439 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7441 (defun gnus-button-handle-apropos-documentation (url)
7442 "Call `apropos' when pushing the corresponding URL button."
7444 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7445 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7447 (defun gnus-button-handle-library (url)
7448 "Call `locate-library' when pushing the corresponding URL button."
7449 (gnus-message 9 "url=`%s'" url)
7450 (let* ((lib (locate-library url))
7451 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7453 (gnus-message 1 "Cannot locale library `%s'." url)
7454 (find-file-read-only file))))
7456 (defun gnus-button-handle-ctan (url)
7457 "Call `browse-url' when pushing a CTAN URL button."
7459 gnus-button-ctan-handler
7462 (gnus-replace-in-string url gnus-button-handle-ctan-bogus-regexp ""))))
7464 (defcustom gnus-button-tex-level 5
7465 "*Integer that says how many TeX-related buttons Gnus will show.
7466 The higher the number, the more buttons will appear and the more false
7467 positives are possible. Note that you can set this variable local to
7468 specific groups. Setting it higher in TeX groups is probably a good idea.
7469 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7470 how to set variables in specific groups."
7472 :group 'gnus-article-buttons
7473 :link '(custom-manual "(gnus)Group Parameters")
7476 (defcustom gnus-button-man-level 5
7477 "*Integer that says how many man-related buttons Gnus will show.
7478 The higher the number, the more buttons will appear and the more false
7479 positives are possible. Note that you can set this variable local to
7480 specific groups. Setting it higher in Unix groups is probably a good idea.
7481 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7482 how to set variables in specific groups."
7484 :group 'gnus-article-buttons
7485 :link '(custom-manual "(gnus)Group Parameters")
7488 (defcustom gnus-button-emacs-level 5
7489 "*Integer that says how many emacs-related buttons Gnus will show.
7490 The higher the number, the more buttons will appear and the more false
7491 positives are possible. Note that you can set this variable local to
7492 specific groups. Setting it higher in Emacs or Gnus related groups is
7493 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7494 `gnus-parameters' on how to set variables in specific groups."
7496 :group 'gnus-article-buttons
7497 :link '(custom-manual "(gnus)Group Parameters")
7500 (defcustom gnus-button-message-level 5
7501 "*Integer that says how many buttons for news or mail messages will appear.
7502 The higher the number, the more buttons will appear and the more false
7503 positives are possible."
7504 ;; mail addresses, MIDs, URLs for news, ...
7506 :group 'gnus-article-buttons
7509 (defcustom gnus-button-browse-level 5
7510 "*Integer that says how many buttons for browsing will appear.
7511 The higher the number, the more buttons will appear and the more false
7512 positives are possible."
7513 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7515 :group 'gnus-article-buttons
7518 (defcustom gnus-button-alist
7519 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7520 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7521 ((concat "\\b\\(nntp\\|news\\):\\("
7522 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7523 0 t gnus-button-handle-news 2)
7524 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7525 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7526 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7527 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7528 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7529 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7530 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7531 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7532 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7533 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7534 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7535 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7536 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7537 ;; RFC 2368 (The mailto URL scheme)
7538 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7539 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7540 ("\\bmailto:\\([^ \n\t]+\\)"
7541 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7543 ((concat "\\bCTAN:[ \t\n]?[^>)!;:,'\n\t ]*\\("
7544 gnus-button-ctan-directory-regexp
7545 "[^][>)!;:,'\n\t ]+\\)")
7546 0 (>= gnus-button-tex-level 1) gnus-button-handle-ctan 1)
7547 ((concat "\\btex-archive/\\("
7548 gnus-button-ctan-directory-regexp
7549 "/[-_.a-z0-9/]+[-_./a-z0-9]+[/a-z0-9]\\)")
7550 1 (>= gnus-button-tex-level 6) gnus-button-handle-ctan 1)
7553 gnus-button-ctan-directory-regexp
7554 "/[-_.a-z0-9]+/[-_./a-z0-9]+[/a-z0-9]\\)")
7555 1 (>= gnus-button-tex-level 8) gnus-button-handle-ctan 1)
7556 ;; Info Konqueror style <info:/foo/bar baz>.
7557 ;; Must come before " Gnus home-grown style".
7558 ("\\binfo://?\\([^'\">\n\t]+\\)"
7559 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7560 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7561 ("\\binfo://\\([^'\">\n\t ]+\\)"
7562 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7563 ;; Info GNOME style <info:foo#bar_baz>
7564 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7565 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7566 ;; Info KDE style <info:(foo)bar baz>
7567 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7568 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7569 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7570 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7571 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
7572 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7573 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7575 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7576 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7577 ;; Emacs help commands
7578 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7579 ;; regexp doesn't match arguments containing ` '.
7580 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7581 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7582 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7583 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7584 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7585 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7586 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7587 ;; The following entries may lead to many false positives so don't enable
7588 ;; them by default (use a high button level).
7589 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7590 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7591 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7592 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7593 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7594 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7595 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7596 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7597 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7598 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7599 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7600 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7601 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7602 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7603 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7604 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7605 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7606 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7607 ;; Unlike the other regexps we really have to require quoting
7608 ;; here to determine where it ends.
7609 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7610 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7611 ("<URL: *\\([^\n<>]*\\)>"
7612 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7613 ;; RFC 2396 (2.4.3., delims) ...
7614 ("\"URL: *\\([^\n\"]*\\)\""
7615 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7617 (gnus-button-url-regexp
7618 0 (>= gnus-button-browse-level 0) browse-url 0)
7620 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7621 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7622 gnus-button-handle-man 1)
7623 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7624 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7625 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7626 gnus-button-handle-man 1)
7627 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7628 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7629 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7630 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7631 ;; Recognizing patches to .el files. This is somewhat obscure,
7632 ;; but considering the percentage of Gnus users who hack Emacs
7634 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7635 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7636 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7637 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7638 ;; MID or mail: To avoid too many false positives we don't try to catch
7639 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7640 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7641 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7642 ;; so that non-ambiguous entries (see above) match first.
7643 (gnus-button-mid-or-mail-regexp
7644 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7645 "*Alist of regexps matching buttons in article bodies.
7647 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7648 REGEXP: is the string (case insensitive) matching text around the button (can
7649 also be Lisp expression evaluating to a string),
7650 BUTTON: is the number of the regexp grouping actually matching the button,
7651 FORM: is a Lisp expression which must eval to true for the button to
7653 CALLBACK: is the function to call when the user push this button, and each
7654 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7656 CALLBACK can also be a variable, in that case the value of that
7657 variable it the real callback function."
7658 :group 'gnus-article-buttons
7659 :type '(repeat (list (choice regexp variable sexp)
7660 (integer :tag "Button")
7662 (function :tag "Callback")
7665 (integer :tag "Regexp group")))))
7666 (put 'gnus-button-alist 'risky-local-variable t)
7668 (defcustom gnus-header-button-alist
7669 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7670 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7671 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7672 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7673 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7674 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7675 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7676 0 (>= gnus-button-browse-level 0) browse-url 0)
7677 ("^Subject:" gnus-button-url-regexp
7678 0 (>= gnus-button-browse-level 0) browse-url 0)
7679 ("^[^:]+:" gnus-button-url-regexp
7680 0 (>= gnus-button-browse-level 0) browse-url 0)
7681 ("^OpenPGP:.*url=" gnus-button-url-regexp
7682 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7683 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7684 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7685 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7686 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7687 "*Alist of headers and regexps to match buttons in article heads.
7689 This alist is very similar to `gnus-button-alist', except that each
7690 alist has an additional HEADER element first in each entry:
7692 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7694 HEADER is a regexp to match a header. For a fuller explanation, see
7695 `gnus-button-alist'."
7696 :group 'gnus-article-buttons
7697 :group 'gnus-article-headers
7698 :type '(repeat (list (regexp :tag "Header")
7699 (choice regexp variable)
7700 (integer :tag "Button")
7702 (function :tag "Callback")
7705 (integer :tag "Regexp group")))))
7706 (put 'gnus-header-button-alist 'risky-local-variable t)
7710 (defun gnus-article-push-button (event)
7711 "Check text under the mouse pointer for a callback function.
7712 If the text under the mouse pointer has a `gnus-callback' property,
7713 call it with the value of the `gnus-data' text property."
7715 (set-buffer (window-buffer (posn-window (event-start event))))
7716 (let* ((pos (posn-point (event-start event)))
7717 (data (get-text-property pos 'gnus-data))
7718 (fun (get-text-property pos 'gnus-callback)))
7721 (funcall fun data))))
7723 (defun gnus-article-press-button ()
7724 "Check text at point for a callback function.
7725 If the text at point has a `gnus-callback' property,
7726 call it with the value of the `gnus-data' text property."
7728 (let ((data (get-text-property (point) 'gnus-data))
7729 (fun (get-text-property (point) 'gnus-callback)))
7731 (funcall fun data))))
7733 (defun gnus-article-highlight (&optional force)
7734 "Highlight current article.
7735 This function calls `gnus-article-highlight-headers',
7736 `gnus-article-highlight-citation',
7737 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7738 do the highlighting. See the documentation for those functions."
7739 (interactive (list 'force))
7740 (gnus-article-highlight-headers)
7741 (gnus-article-highlight-citation force)
7742 (gnus-article-highlight-signature)
7743 (gnus-article-add-buttons force)
7744 (gnus-article-add-buttons-to-head))
7746 (defun gnus-article-highlight-some (&optional force)
7747 "Highlight current article.
7748 This function calls `gnus-article-highlight-headers',
7749 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7750 do the highlighting. See the documentation for those functions."
7751 (interactive (list 'force))
7752 (gnus-article-highlight-headers)
7753 (gnus-article-highlight-signature)
7754 (gnus-article-add-buttons))
7756 (defun gnus-article-highlight-headers ()
7757 "Highlight article headers as specified by `gnus-header-face-alist'."
7759 (gnus-with-article-headers
7760 (let (regexp header-face field-face from hpoints fpoints)
7761 (dolist (entry gnus-header-face-alist)
7762 (goto-char (point-min))
7763 (setq regexp (concat "^\\("
7764 (if (string-equal "" (nth 0 entry))
7768 header-face (nth 1 entry)
7769 field-face (nth 2 entry))
7770 (while (and (re-search-forward regexp nil t)
7774 (unless (search-forward ":" nil t)
7776 (when (and header-face
7777 (not (memq (point) hpoints)))
7778 (push (point) hpoints)
7779 (gnus-put-text-property from (point) 'face header-face))
7780 (when (and field-face
7781 (not (memq (setq from (point)) fpoints)))
7783 (if (re-search-forward "^[^ \t]" nil t)
7785 (goto-char (point-max)))
7786 (gnus-put-text-property from (point) 'face field-face)))))))
7788 (defun gnus-article-highlight-signature ()
7789 "Highlight the signature in an article.
7790 It does this by highlighting everything after
7791 `gnus-signature-separator' using the face `gnus-signature'."
7793 (gnus-with-article-buffer
7794 (let ((inhibit-point-motion-hooks t))
7796 (when (and gnus-signature-face
7797 (gnus-article-narrow-to-signature))
7798 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7799 'face gnus-signature-face)
7801 (gnus-article-search-signature)
7802 (let ((start (match-beginning 0))
7803 (end (set-marker (make-marker) (1+ (match-end 0)))))
7804 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7807 (defun gnus-button-in-region-p (b e prop)
7808 "Say whether PROP exists in the region."
7809 (text-property-not-all b e prop nil))
7811 (defun gnus-article-add-buttons (&optional force)
7812 "Find external references in the article and make buttons of them.
7813 \"External references\" are things like Message-IDs and URLs, as
7814 specified by `gnus-button-alist'."
7815 (interactive (list 'force))
7816 (gnus-with-article-buffer
7817 (let ((inhibit-point-motion-hooks t)
7818 (case-fold-search t)
7819 (alist gnus-button-alist)
7821 ;; Remove all old markers.
7822 (let (marker entry new-list)
7823 (while (setq marker (pop gnus-button-marker-list))
7824 (if (or (< marker (point-min)) (>= marker (point-max)))
7825 (push marker new-list)
7827 (when (setq entry (gnus-button-entry))
7828 (put-text-property (match-beginning (nth 1 entry))
7829 (match-end (nth 1 entry))
7830 'gnus-callback nil))
7831 (set-marker marker nil)))
7832 (setq gnus-button-marker-list new-list))
7833 ;; We skip the headers.
7836 (while (setq entry (pop alist))
7837 (setq regexp (eval (car entry)))
7839 (while (re-search-forward regexp nil t)
7840 (let ((start (match-beginning (nth 1 entry)))
7841 (end (match-end (nth 1 entry)))
7842 (from (match-beginning 0)))
7843 (when (and (or (eq t (nth 2 entry))
7844 (eval (nth 2 entry)))
7845 (not (gnus-button-in-region-p
7846 start end 'gnus-callback)))
7847 ;; That optional form returned non-nil, so we add the
7849 (setq from (set-marker (make-marker) from))
7850 (push from gnus-button-marker-list)
7851 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7852 (gnus-article-extend-url-button from start end))
7853 (gnus-article-add-button start end
7854 'gnus-button-push from)
7855 (gnus-put-text-property
7857 'gnus-string (buffer-substring-no-properties
7860 (defun gnus-article-extend-url-button (beg start end)
7861 "Extend url button if url is folded into two or more lines.
7862 Return non-nil if button is extended. BEG is a marker that points to
7863 the beginning position of a text containing url. START and END are
7864 the endpoints of a url button before it is extended. The concatenated
7865 url is put as the `gnus-button-url' overlay property on the button."
7866 (let ((opoint (point))
7867 (points (list start end))
7872 (not (looking-at "[\t ]*[\">]")))
7876 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7877 (buffer-substring (point-at-bol) start)))
7879 (setq url (list (buffer-substring start end))
7880 delim (if (match-beginning 1) ">" "\""))
7882 (setq regexp (concat
7883 (when (and (looking-at
7884 message-cite-prefix-regexp)
7885 (< (match-end 0) start))
7886 (regexp-quote (match-string 0)))
7888 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7892 (and (looking-at regexp)
7895 (push (or (match-string 2)
7898 (push (setq end (or (match-end 2)
7901 (push (or (match-beginning 2)
7902 (match-beginning 1))
7904 (match-beginning 2)))
7905 (let (gnus-article-mouse-face widget-mouse-face)
7907 (gnus-article-add-button (pop points) (pop points)
7908 'gnus-button-push beg)))
7909 (let ((overlay (gnus-make-overlay start end)))
7910 (gnus-overlay-put overlay 'evaporate t)
7911 (gnus-overlay-put overlay 'gnus-button-url
7912 (list (mapconcat 'identity (nreverse url) "")))
7913 (when gnus-article-mouse-face
7914 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7916 (goto-char opoint))))
7918 ;; Add buttons to the head of an article.
7919 (defun gnus-article-add-buttons-to-head ()
7920 "Add buttons to the head of the article."
7922 (gnus-with-article-headers
7924 (dolist (entry gnus-header-button-alist)
7925 ;; Each alist entry.
7926 (goto-char (point-min))
7927 (while (re-search-forward (car entry) nil t)
7928 ;; Each header matching the entry.
7929 (setq beg (match-beginning 0))
7930 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7931 (match-beginning 0))
7934 (while (re-search-forward (eval (nth 1 entry)) end t)
7935 ;; Each match within a header.
7936 (let* ((entry (cdr entry))
7937 (start (match-beginning (nth 1 entry)))
7938 (end (match-end (nth 1 entry)))
7939 (form (nth 2 entry)))
7940 (goto-char (match-end 0))
7942 (gnus-article-add-button
7943 start end (nth 3 entry)
7944 (buffer-substring (match-beginning (nth 4 entry))
7945 (match-end (nth 4 entry)))))))
7946 (goto-char end))))))
7948 ;;; External functions:
7950 (defun gnus-article-add-button (from to fun &optional data text)
7951 "Create a button between FROM and TO with callback FUN and data DATA."
7952 (when gnus-article-button-face
7953 (gnus-overlay-put (gnus-make-overlay from to nil t)
7954 'face gnus-article-button-face))
7955 (gnus-add-text-properties
7957 (nconc (and gnus-article-mouse-face
7958 (list gnus-mouse-face-prop gnus-article-mouse-face))
7959 (list 'gnus-callback fun)
7960 (and data (list 'gnus-data data))))
7961 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7962 :help-echo (or text "Follow the link")
7963 :keymap gnus-url-button-map
7964 :button-keymap gnus-widget-button-keymap))
7966 (defun gnus-article-copy-string ()
7967 "Copy the string in the button to the kill ring."
7969 (gnus-article-check-buffer)
7970 (let ((data (get-text-property (point) 'gnus-string)))
7974 (copy-region-as-kill (point-min) (point-max))
7975 (message "Copied %s" data)))))
7977 ;;; Internal functions:
7979 (defun gnus-article-set-globals ()
7980 (with-current-buffer gnus-summary-buffer
7981 (gnus-set-global-variables)))
7983 (defun gnus-signature-toggle (end)
7984 (gnus-with-article-buffer
7985 (let ((inhibit-point-motion-hooks t))
7986 (if (text-property-any end (point-max) 'article-type 'signature)
7988 (gnus-delete-wash-type 'signature)
7989 (gnus-remove-text-properties-when
7990 'article-type 'signature end (point-max)
7991 (cons 'article-type (cons 'signature
7992 gnus-hidden-properties))))
7993 (gnus-add-wash-type 'signature)
7994 (gnus-add-text-properties-when
7995 'article-type nil end (point-max)
7996 (cons 'article-type (cons 'signature
7997 gnus-hidden-properties)))))
7998 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7999 (gnus-set-mode-line 'article))))
8001 (defun gnus-button-entry ()
8002 ;; Return the first entry in `gnus-button-alist' matching this place.
8003 (let ((alist gnus-button-alist)
8006 (setq entry (pop alist))
8007 (if (looking-at (eval (car entry)))
8012 (defun gnus-button-push (marker)
8013 ;; Push button starting at MARKER.
8016 (let* ((entry (gnus-button-entry))
8017 (inhibit-point-motion-hooks t)
8019 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8020 (get-char-property marker 'gnus-button-url))
8021 (mapcar (lambda (group)
8022 (let ((string (match-string group)))
8023 (set-text-properties
8024 0 (length string) nil string)
8026 (nthcdr 4 entry)))))
8031 (fboundp (symbol-value fun)))
8032 (apply (symbol-value fun) args))
8034 (gnus-message 1 "You must define `%S' to use this button"
8035 (cons fun args)))))))
8037 (defun gnus-parse-news-url (url)
8038 (let (scheme server port group message-id articles)
8041 (goto-char (point-min))
8042 (when (looking-at "\\([A-Za-z]+\\):")
8043 (setq scheme (match-string 1))
8044 (goto-char (match-end 0)))
8045 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8046 (setq server (match-string 1))
8047 (setq port (if (stringp (match-string 3))
8048 (string-to-number (match-string 3))
8050 (goto-char (match-end 0)))
8053 ((looking-at "\\(.*@.*\\)")
8054 (setq message-id (match-string 1)))
8055 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8056 (setq group (match-string 1)
8057 articles (split-string (match-string 2) "-")))
8058 ((looking-at "\\([^/]+\\)/?")
8059 (setq group (match-string 1)))
8061 (error "Unknown news URL syntax"))))
8062 (list scheme server port group message-id articles)))
8064 (defun gnus-button-handle-news (url)
8066 (destructuring-bind (scheme server port group message-id articles)
8067 (gnus-parse-news-url url)
8070 (with-current-buffer gnus-summary-buffer
8072 (let ((gnus-refer-article-method
8073 (nconc (list (list 'nntp server))
8074 gnus-refer-article-method))
8075 (nntp-port-number (or port "nntp")))
8076 (gnus-message 7 "Fetching %s with %s"
8077 message-id gnus-refer-article-method)
8078 (gnus-summary-refer-article message-id))
8079 (gnus-summary-refer-article message-id))))
8081 (gnus-button-fetch-group url)))))
8083 (defun gnus-button-patch (library line)
8084 "Visit an Emacs Lisp library LIBRARY on line LINE."
8086 (let ((file (locate-library (file-name-nondirectory library))))
8088 (error "Couldn't find library %s" library))
8090 (goto-char (point-min))
8091 (forward-line (1- (string-to-number line)))))
8093 (defun gnus-button-handle-man (url)
8095 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8096 (when (eq gnus-button-man-handler 'woman)
8097 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8098 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8099 (funcall gnus-button-man-handler url))
8101 (defun gnus-button-handle-info-url (url)
8102 "Fetch an info URL."
8103 (setq url (mm-subst-char-in-string ?+ ?\ url))
8105 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8106 (gnus-info-find-node
8107 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8109 ")" (gnus-url-unhex-string (match-string 2 url)))))
8110 ((string-match "([^)\"]+)[^\"]+" url)
8112 (gnus-replace-in-string
8113 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8114 (gnus-info-find-node url))
8115 (t (error "Can't parse %s" url))))
8117 (defun gnus-button-handle-info-url-gnome (url)
8118 "Fetch GNOME style info URL."
8119 (setq url (mm-subst-char-in-string ?_ ?\ url))
8120 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8121 (gnus-info-find-node
8123 (gnus-url-unhex-string
8124 (match-string 1 url))
8126 (or (gnus-url-unhex-string
8127 (match-string 2 url))
8129 (error "Can't parse %s" url)))
8131 (defun gnus-button-handle-info-url-kde (url)
8132 "Fetch KDE style info URL."
8133 (gnus-info-find-node (gnus-url-unhex-string url)))
8135 ;; (info) will autoload info.el
8136 (declare-function Info-menu "info" (menu-item &optional fork))
8137 (declare-function Info-index-next "info" (num))
8139 (defun gnus-button-handle-info-keystrokes (url)
8140 "Call `info' when pushing the corresponding URL button."
8141 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8142 (let (node indx comma)
8144 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8145 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8146 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
8147 "\\(?:[ \t\n,]*\\)\\)?")
8149 (setq node (match-string 2 url)
8150 indx (match-string 3 url))
8151 (error "Can't parse %s" url))
8155 (when (> (length indx) 0)
8156 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8159 (setq comma (match-string 2 indx))
8160 (setq indx (match-string 1 indx))
8163 (dotimes (i (with-temp-buffer
8165 ;; Note: the XEmacs version of `how-many' takes
8166 ;; no optional argument.
8167 (goto-char (point-min))
8169 (Info-index-next 1)))
8172 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8173 (declare-function pgg-display-output-buffer "pgg" (start end status))
8175 (defun gnus-button-openpgp (url)
8176 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8178 (mm-url-insert-file-contents-external url)
8179 (pgg-snarf-keys-region (point-min) (point-max))
8180 (pgg-display-output-buffer nil nil nil)))
8182 (defun gnus-button-message-id (message-id)
8184 (with-current-buffer gnus-summary-buffer
8185 (gnus-summary-refer-article message-id)))
8187 (defun gnus-button-fetch-group (address &rest ignore)
8188 "Fetch GROUP specified by ADDRESS."
8189 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8191 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8192 ;; for nntp:// and news://
8193 (setq address (match-string 3 address)))
8194 (if (not (string-match "[:/]" address))
8195 ;; This is just a simple group url.
8196 (gnus-group-read-ephemeral-group address gnus-select-method)
8199 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8201 (error "Can't parse %s" address)
8202 (gnus-group-read-ephemeral-group
8203 (match-string 4 address)
8204 `(nntp ,(match-string 1 address)
8205 (nntp-address ,(match-string 1 address))
8206 (nntp-port-number ,(if (match-end 3)
8207 (match-string 3 address)
8210 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8212 (defun gnus-url-parse-query-string (query &optional downcase)
8213 (let (retval pairs cur key val)
8214 (setq pairs (split-string query "&"))
8216 (setq cur (car pairs)
8218 (if (not (string-match "=" cur))
8220 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8221 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8223 (setq key (downcase key)))
8224 (setq cur (assoc key retval))
8226 (setcdr cur (cons val (cdr cur)))
8227 (setq retval (cons (list key val) retval)))))
8230 (defun gnus-url-mailto (url)
8231 ;; Send mail to someone
8232 (when (string-match "mailto:/*\\(.*\\)" url)
8233 (setq url (substring url (match-beginning 1) nil)))
8234 (let (to args subject func)
8235 (setq args (gnus-url-parse-query-string
8236 (if (string-match "^\\?" url)
8238 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8239 (concat "to=" (match-string 1 url) "&"
8240 (match-string 2 url))
8241 (concat "to=" url)))
8243 subject (cdr-safe (assoc "subject" args)))
8246 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8249 (message-position-on-field (caar args)))
8250 (insert (gnus-replace-in-string
8251 (mapconcat 'identity (reverse (cdar args)) ", ")
8253 (setq args (cdr args)))
8256 (message-goto-subject))))
8258 (defun gnus-button-embedded-url (address)
8259 "Activate ADDRESS with `browse-url'."
8260 (browse-url (gnus-strip-whitespace address)))
8262 ;;; Next/prev buttons in the article buffer.
8264 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8265 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8267 (defvar gnus-prev-page-map
8268 (let ((map (make-sparse-keymap)))
8269 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8270 (define-key map "\r" 'gnus-button-prev-page)
8273 (defvar gnus-next-page-map
8274 (let ((map (make-sparse-keymap)))
8275 (unless (>= emacs-major-version 21)
8276 ;; XEmacs doesn't care.
8277 (set-keymap-parent map gnus-article-mode-map))
8278 (define-key map gnus-mouse-2 'gnus-button-next-page)
8279 (define-key map "\r" 'gnus-button-next-page)
8282 (defun gnus-insert-prev-page-button ()
8284 (inhibit-read-only t))
8286 gnus-prev-page-line-format nil
8287 `(keymap ,gnus-prev-page-map
8289 gnus-callback gnus-article-button-prev-page
8290 article-type annotation))
8292 ;; Exclude a newline.
8295 (when gnus-article-button-face
8296 (gnus-overlay-put (gnus-make-overlay b e nil t)
8297 'face gnus-article-button-face))
8298 (widget-convert-button
8300 :action 'gnus-button-prev-page
8301 :button-keymap gnus-prev-page-map)))
8303 (defun gnus-button-next-page (&optional args more-args)
8304 "Go to the next page."
8306 (let ((win (selected-window)))
8307 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8308 (gnus-article-next-page)
8309 (select-window win)))
8311 (defun gnus-button-prev-page (&optional args more-args)
8312 "Go to the prev page."
8314 (let ((win (selected-window)))
8315 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8316 (gnus-article-prev-page)
8317 (select-window win)))
8319 (defun gnus-insert-next-page-button ()
8321 (inhibit-read-only t))
8322 (gnus-eval-format gnus-next-page-line-format nil
8323 `(keymap ,gnus-next-page-map
8325 gnus-callback gnus-article-button-next-page
8326 article-type annotation))
8328 ;; Exclude a newline.
8331 (when gnus-article-button-face
8332 (gnus-overlay-put (gnus-make-overlay b e nil t)
8333 'face gnus-article-button-face))
8334 (widget-convert-button
8336 :action 'gnus-button-next-page
8337 :button-keymap gnus-next-page-map)))
8339 (defun gnus-article-button-next-page (arg)
8340 "Go to the next page."
8342 (let ((win (selected-window)))
8343 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8344 (gnus-article-next-page)
8345 (select-window win)))
8347 (defun gnus-article-button-prev-page (arg)
8348 "Go to the prev page."
8350 (let ((win (selected-window)))
8351 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8352 (gnus-article-prev-page)
8353 (select-window win)))
8355 (defvar gnus-decode-header-methods
8356 '(mail-decode-encoded-word-region)
8357 "List of methods used to decode headers.
8359 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8360 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8361 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8362 whose names match REGEXP.
8365 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8366 mail-decode-encoded-word-region
8367 (\"chinese\" . rfc1843-decode-region))
8370 (defvar gnus-decode-header-methods-cache nil)
8372 (defun gnus-multi-decode-header (start end)
8373 "Apply the functions from `gnus-encoded-word-methods' that match."
8374 (unless (and gnus-decode-header-methods-cache
8375 (eq gnus-newsgroup-name
8376 (car gnus-decode-header-methods-cache)))
8377 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8378 (dolist (x gnus-decode-header-methods)
8380 (nconc gnus-decode-header-methods-cache (list x))
8381 (if (and gnus-newsgroup-name
8382 (string-match (car x) gnus-newsgroup-name))
8383 (nconc gnus-decode-header-methods-cache
8385 (let ((xlist gnus-decode-header-methods-cache))
8388 (narrow-to-region start end)
8390 (funcall (pop xlist) (point-min) (point-max))))))
8393 ;;; Treatment top-level handling.
8396 (defun gnus-treat-article (condition &optional part-number total-parts type)
8397 (let ((length (- (point-max) (point-min)))
8398 (alist gnus-treatment-function-alist)
8399 (article-goto-body-goes-to-point-min-p t)
8403 (let ((list gnus-article-treat-types))
8405 (when (string-match (pop list) type)
8406 (throw 'found t)))))))
8407 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8409 (gnus-run-hooks 'gnus-part-display-hook)
8410 (dolist (elem alist)
8413 (when (gnus-buffer-live-p gnus-summary-buffer)
8414 (set-buffer gnus-summary-buffer))
8415 (symbol-value (car elem))))
8416 (when (and (or (consp val)
8418 (gnus-treat-predicate val)
8419 (or (not (get (car elem) 'highlight))
8422 (funcall (cadr elem)))))))
8424 ;; Dynamic variables.
8425 (defvar part-number)
8426 (defvar total-parts)
8431 (defun gnus-treat-predicate (val)
8438 (stringp (car val)))
8439 (apply 'gnus-or (mapcar `(lambda (s)
8440 (string-match s ,(or gnus-newsgroup-name "")))
8443 (let ((pred (pop val)))
8446 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8448 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8450 (not (gnus-treat-predicate (car val))))
8452 (equal (car val) type))
8454 (error "%S is not a valid predicate" pred)))))
8462 (eq part-number total-parts))
8466 (error "%S is not a valid value" val))))
8468 (defun gnus-article-encrypt-body (protocol &optional n)
8469 "Encrypt the article body."
8472 (or gnus-article-encrypt-protocol
8473 (completing-read "Encrypt protocol: "
8474 gnus-article-encrypt-protocol-alist
8476 current-prefix-arg))
8477 ;; User might hit `K E' instead of `K e', so prompt once.
8478 (when (and gnus-article-encrypt-protocol
8480 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8481 (error "Encrypt aborted")))
8482 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8484 (error "Can't find the encrypt protocol %s" protocol))
8485 (if (member gnus-newsgroup-name '("nndraft:delayed"
8488 (error "Can't encrypt the article in group %s"
8489 gnus-newsgroup-name))
8490 (gnus-summary-iterate n
8491 (with-current-buffer gnus-summary-buffer
8492 (let ((mail-parse-charset gnus-newsgroup-charset)
8493 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8494 (summary-buffer gnus-summary-buffer)
8496 (gnus-set-global-variables)
8497 (when (gnus-group-read-only-p)
8498 (error "The current newsgroup does not support article encrypt"))
8499 (gnus-summary-show-article t)
8501 (or (mail-header-references gnus-current-headers) ""))
8502 (set-buffer gnus-article-buffer)
8503 (let* ((inhibit-read-only t)
8505 (mapcar (lambda (field)
8506 (and (save-restriction
8507 (message-narrow-to-head)
8508 (goto-char (point-min))
8509 (search-forward field nil t))
8511 (message-narrow-to-field)
8513 (delete-region (point-min) (point-max))
8515 '("Content-Type:" "Content-Transfer-Encoding:"
8516 "Content-Disposition:"))))
8517 (message-narrow-to-head)
8518 (message-remove-header "MIME-Version")
8519 (goto-char (point-max))
8520 (setq point (point))
8521 (insert (apply 'concat headers))
8523 (narrow-to-region point (point-max))
8524 (let ((message-options message-options))
8525 (message-options-set 'message-sender user-mail-address)
8526 (message-options-set 'message-recipients user-mail-address)
8527 (message-options-set 'message-sign-encrypt 'not)
8529 (goto-char (point-min))
8530 (insert "MIME-Version: 1.0\n")
8532 (gnus-summary-edit-article-done
8533 references nil summary-buffer t))
8534 (when gnus-keep-backlog
8535 (gnus-backlog-remove-article
8536 (car gnus-article-current) (cdr gnus-article-current)))
8537 (gnus-flush-original-article-buffer)
8538 (when gnus-use-cache
8539 (gnus-cache-update-article
8540 (car gnus-article-current) (cdr gnus-article-current))))))))
8542 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8543 "The following specs can be used:
8544 %t The security MIME type
8547 %D Details if button is pressed")
8549 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8550 "The following specs can be used:
8551 %t The security MIME type
8554 %D Details if button is pressed")
8556 (defvar gnus-mime-security-button-line-format-alist
8557 '((?t gnus-tmp-type ?s)
8558 (?i gnus-tmp-info ?s)
8559 (?d gnus-tmp-details ?s)
8560 (?D gnus-tmp-pressed-details ?s)))
8562 (defvar gnus-mime-security-button-commands
8563 '((gnus-article-press-button "\r" "Show Detail")
8567 (gnus-mime-security-save-part "o" "Save...")
8576 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8579 (defvar gnus-mime-security-button-map
8580 (let ((map (make-sparse-keymap)))
8581 (define-key map gnus-mouse-2 'gnus-article-push-button)
8582 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8583 (dolist (c gnus-mime-security-button-commands)
8584 (define-key map (cadr c) (car c)))
8588 gnus-mime-security-button-menu gnus-mime-security-button-map
8589 "Security button menu."
8593 (unless (eq (car c) 'undefined)
8594 (vector (caddr c) (car c) :active t)))
8595 gnus-mime-security-button-commands))))
8597 (defun gnus-mime-security-button-menu (event prefix)
8598 "Construct a context-sensitive menu of security commands."
8599 (interactive "e\nP")
8600 (save-window-excursion
8601 (let ((pos (event-start event)))
8602 (select-window (posn-window pos))
8603 (goto-char (posn-point pos))
8604 (gnus-article-check-buffer)
8605 (popup-menu gnus-mime-security-button-menu nil prefix))))
8607 (defvar gnus-mime-security-details-buffer nil)
8609 (defvar gnus-mime-security-button-pressed nil)
8611 (defvar gnus-mime-security-show-details-inline t
8612 "If non-nil, show details in the article buffer.")
8614 (defun gnus-mime-security-verify-or-decrypt (handle)
8615 (mm-remove-parts (cdr handle))
8616 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8617 point (inhibit-read-only t))
8619 (goto-char (car region)))
8620 (setq point (point))
8621 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8622 (let* ((mm-verify-option 'known)
8623 (mm-decrypt-option 'known)
8624 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8625 (unless (eq nparts (cdr handle))
8626 (mm-destroy-parts (cdr handle))
8627 (setcdr handle nparts))))
8628 (gnus-mime-display-security handle)
8630 (delete-region (point) (cdr region))
8631 (set-marker (car region) nil)
8632 (set-marker (cdr region) nil))
8635 (defun gnus-mime-security-show-details (handle)
8636 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8638 (gnus-message 5 "No details.")
8639 (if gnus-mime-security-show-details-inline
8640 (let ((gnus-mime-security-button-pressed
8641 (not (get-text-property (point) 'gnus-mime-details)))
8642 (gnus-mime-security-button-line-format
8643 (get-text-property (point) 'gnus-line-format))
8644 (inhibit-read-only t))
8646 (while (eq (get-text-property (point) 'gnus-line-format)
8647 gnus-mime-security-button-line-format)
8651 (narrow-to-region (point) (point))
8652 (gnus-insert-mime-security-button handle))
8653 (delete-region (point)
8654 (or (text-property-not-all
8657 gnus-mime-security-button-line-format)
8660 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8661 (with-current-buffer gnus-mime-security-details-buffer
8664 (setq gnus-mime-security-details-buffer
8665 (gnus-get-buffer-create "*MIME Security Details*")))
8666 (with-current-buffer gnus-mime-security-details-buffer
8668 (goto-char (point-min)))
8669 (pop-to-buffer gnus-mime-security-details-buffer)))))
8671 (defun gnus-mime-security-press-button (handle)
8673 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8674 (gnus-mime-security-show-details handle)
8675 (gnus-mime-security-verify-or-decrypt handle))))
8677 (defun gnus-insert-mime-security-button (handle &optional displayed)
8678 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8681 (or (nth 2 (assoc protocol mm-verify-function-alist))
8682 (nth 2 (assoc protocol mm-decrypt-function-alist))
8684 (if (equal (car handle) "multipart/signed")
8685 " Signed" " Encrypted")
8688 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8691 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8692 gnus-tmp-pressed-details
8694 (setq gnus-tmp-details
8695 (if gnus-tmp-details
8696 (concat "\n" gnus-tmp-details)
8698 (setq gnus-tmp-pressed-details
8699 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8704 gnus-mime-security-button-line-format
8705 gnus-mime-security-button-line-format-alist
8706 `(keymap ,gnus-mime-security-button-map
8707 gnus-callback gnus-mime-security-press-button
8708 gnus-line-format ,gnus-mime-security-button-line-format
8709 gnus-mime-details ,gnus-mime-security-button-pressed
8710 article-type annotation
8713 ;; Exclude a newline.
8716 (when gnus-article-button-face
8717 (gnus-overlay-put (gnus-make-overlay b e nil t)
8718 'face gnus-article-button-face))
8719 (widget-convert-button
8722 :action 'gnus-widget-press-button
8723 :button-keymap gnus-mime-security-button-map
8726 ;; Needed to properly clear the message due to a bug in
8727 ;; wid-edit (XEmacs only).
8728 (when (boundp 'help-echo-owns-message)
8729 (setq help-echo-owns-message t))
8731 "%S: show detail; %S: more options"
8732 (aref gnus-mouse-2 0)
8733 (aref gnus-down-mouse-3 0))))))
8735 (defun gnus-mime-display-security (handle)
8737 (narrow-to-region (point) (point))
8738 (unless (gnus-unbuttonized-mime-type-p (car handle))
8739 (gnus-insert-mime-security-button handle))
8740 (gnus-mime-display-part (cadr handle))
8743 (unless (gnus-unbuttonized-mime-type-p (car handle))
8744 (let ((gnus-mime-security-button-line-format
8745 gnus-mime-security-button-end-line-format))
8746 (gnus-insert-mime-security-button handle)))
8747 (mm-set-handle-multipart-parameter
8749 (cons (set-marker (make-marker) (point-min))
8750 (set-marker (make-marker) (point-max))))
8751 (goto-char (point-max))))
8753 (defun gnus-mime-security-run-function (function)
8754 "Run FUNCTION with the security part under point."
8755 (gnus-article-check-buffer)
8756 (let ((data (get-text-property (point) 'gnus-data))
8758 (when (and (stringp (car-safe data))
8759 (setq buffer (mm-handle-multipart-original-buffer data))
8760 (setq handle (cadr data)))
8761 (if (bufferp (mm-handle-buffer handle))
8763 (setq handle (cons buffer (copy-sequence (cdr handle))))
8764 (mm-handle-set-undisplayer handle nil))
8765 (setq handle (mm-make-handle
8767 (mm-handle-multipart-ctl-parameter handle 'protocol)
8768 nil nil nil nil nil nil)))
8769 (funcall function handle))))
8771 (defun gnus-mime-security-save-part ()
8772 "Save the security part under point."
8774 (gnus-mime-security-run-function 'mm-save-part))
8776 (defun gnus-mime-security-pipe-part ()
8777 "Pipe the security part under point to a process."
8779 (gnus-mime-security-run-function 'mm-pipe-part))
8785 (run-hooks 'gnus-art-load-hook)
8787 ;;; gnus-art.el ends here